:right-sidebar: True BaseSink =================================================================== .. currentmodule:: gi.repository.GstBase .. class:: BaseSink(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.Gst.Element`, :class:`~gi.repository.Gst.Object`, :class:`~gi.repository.GObject.InitiallyUnowned`, :class:`~gi.repository.GObject.Object` :obj:`~gi.repository.GstBase.BaseSink` is the base class for sink elements in GStreamer, such as xvimagesink or filesink. It is a layer on top of :obj:`~gi.repository.Gst.Element` that provides a simplified interface to plugin writers. :obj:`~gi.repository.GstBase.BaseSink` handles many details for you, for example: preroll, clock synchronization, state changes, activation in push or pull mode, and queries. In most cases, when writing sink elements, there is no need to implement class methods from :obj:`~gi.repository.Gst.Element` or to set functions on pads, because the :obj:`~gi.repository.GstBase.BaseSink` infrastructure should be sufficient. :obj:`~gi.repository.GstBase.BaseSink` provides support for exactly one sink pad, which should be named "sink". A sink implementation (subclass of :obj:`~gi.repository.GstBase.BaseSink`\) should install a pad template in its class_init function, like so: .. code-block:: C :dedent: static void my_element_class_init (GstMyElementClass *klass) { GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass); // sinktemplate should be a #GstStaticPadTemplate with direction // %GST_PAD_SINK and name "sink" gst_element_class_add_static_pad_template (gstelement_class, &sinktemplate); gst_element_class_set_static_metadata (gstelement_class, "Sink name", "Sink", "My Sink element", "The author "); } :obj:`~gi.repository.GstBase.BaseSink` will handle the prerolling correctly. This means that it will return %GST_STATE_CHANGE_ASYNC from a state change to PAUSED until the first buffer arrives in this element. The base class will call the ``GstBaseSinkClass``::preroll vmethod with this preroll buffer and will then commit the state change to the next asynchronously pending state. When the element is set to PLAYING, :obj:`~gi.repository.GstBase.BaseSink` will synchronise on the clock using the times returned from ``GstBaseSinkClass``::get_times. If this function returns %GST_CLOCK_TIME_NONE for the start time, no synchronisation will be done. Synchronisation can be disabled entirely by setting the object :obj:`~gi.repository.GstBase.BaseSink`\:sync property to :const:`False`. After synchronisation the virtual method ``GstBaseSinkClass``::render will be called. Subclasses should minimally implement this method. Subclasses that synchronise on the clock in the ``GstBaseSinkClass``::render method are supported as well. These classes typically receive a buffer in the render method and can then potentially block on the clock while rendering. A typical example is an audiosink. These subclasses can use :func:`~gi.repository.GstBase.BaseSink.wait_preroll` to perform the blocking wait. Upon receiving the EOS event in the PLAYING state, :obj:`~gi.repository.GstBase.BaseSink` will wait for the clock to reach the time indicated by the stop time of the last ``GstBaseSinkClass``::get_times call before posting an EOS message. When the element receives EOS in PAUSED, preroll completes, the event is queued and an EOS message is posted when going to PLAYING. :obj:`~gi.repository.GstBase.BaseSink` will internally use the %GST_EVENT_SEGMENT events to schedule synchronisation and clipping of buffers. Buffers that fall completely outside of the current segment are dropped. Buffers that fall partially in the segment are rendered (and prerolled). Subclasses should do any subbuffer clipping themselves when needed. :obj:`~gi.repository.GstBase.BaseSink` will by default report the current playback position in %GST_FORMAT_TIME based on the current clock time and segment information. If no clock has been set on the element, the query will be forwarded upstream. The ``GstBaseSinkClass``::set_caps function will be called when the subclass should configure itself to process a specific media type. The ``GstBaseSinkClass``::start and ``GstBaseSinkClass``::stop virtual methods will be called when resources should be allocated. Any ``GstBaseSinkClass``::preroll, ``GstBaseSinkClass``::render and ``GstBaseSinkClass``::set_caps function will be called between the ``GstBaseSinkClass``::start and ``GstBaseSinkClass``::stop calls. The ``GstBaseSinkClass``::event virtual method will be called when an event is received by :obj:`~gi.repository.GstBase.BaseSink`\. Normally this method should only be overridden by very specific elements (such as file sinks) which need to handle the newsegment event specially. The ``GstBaseSinkClass``::unlock method is called when the elements should unblock any blocking operations they perform in the ``GstBaseSinkClass``::render method. This is mostly useful when the ``GstBaseSinkClass``::render method performs a blocking write on a file descriptor, for example. The :obj:`~gi.repository.GstBase.BaseSink`\:max-lateness property affects how the sink deals with buffers that arrive too late in the sink. A buffer arrives too late in the sink when the presentation time (as a combination of the last segment, buffer timestamp and element base_time) plus the duration is before the current time of the clock. If the frame is later than max-lateness, the sink will drop the buffer without calling the render method. This feature is disabled if sync is disabled, the ``GstBaseSinkClass``::get_times method does not return a valid start time or max-lateness is set to -1 (the default). Subclasses can use :func:`~gi.repository.GstBase.BaseSink.set_max_lateness` to configure the max-lateness value. The :obj:`~gi.repository.GstBase.BaseSink`\:qos property will enable the quality-of-service features of the basesink which gather statistics about the real-time performance of the clock synchronisation. For each buffer received in the sink, statistics are gathered and a QOS event is sent upstream with these numbers. This information can then be used by upstream elements to reduce their processing rate, for example. The :obj:`~gi.repository.GstBase.BaseSink`\:async property can be used to instruct the sink to never perform an ASYNC state change. This feature is mostly usable when dealing with non-synchronized streams or sparse streams. Methods ------- .. rst-class:: interim-class .. class:: BaseSink :no-index: .. method:: do_activate_pull(self, active: bool) -> bool :param active: .. method:: do_event(self, event: ~gi.repository.Gst.Event) -> bool :param event: .. method:: do_fixate(self, caps: ~gi.repository.Gst.Caps) -> ~gi.repository.Gst.Caps :param caps: .. method:: do_get_caps(self, filter: ~gi.repository.Gst.Caps | None = None) -> ~gi.repository.Gst.Caps :param filter: .. method:: do_get_times(self, buffer: ~gi.repository.Gst.Buffer) -> ~typing.Tuple[int, int] :param buffer: .. method:: do_prepare(self, buffer: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn :param buffer: .. method:: do_prepare_list(self, buffer_list: ~gi.repository.Gst.BufferList) -> ~gi.repository.Gst.FlowReturn :param buffer_list: .. method:: do_preroll(self, buffer: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn If the ``sink`` spawns its own thread for pulling buffers from upstream it should call this method after it has pulled a buffer. If the element needed to preroll, this function will perform the preroll and will then block until the element state is changed. This function should be called with the PREROLL_LOCK held. :param buffer: .. method:: do_propose_allocation(self, query: ~gi.repository.Gst.Query) -> bool :param query: .. method:: do_query(self, query: ~gi.repository.Gst.Query) -> bool :param query: .. method:: do_render(self, buffer: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn :param buffer: .. method:: do_render_list(self, buffer_list: ~gi.repository.Gst.BufferList) -> ~gi.repository.Gst.FlowReturn :param buffer_list: .. method:: do_set_caps(self, caps: ~gi.repository.Gst.Caps) -> bool :param caps: .. method:: do_start(self) -> bool .. method:: do_stop(self) -> bool .. method:: do_unlock(self) -> bool .. method:: do_unlock_stop(self) -> bool .. method:: do_wait_event(self, event: ~gi.repository.Gst.Event) -> ~gi.repository.Gst.FlowReturn :param event: .. method:: get_blocksize() -> int Get the number of bytes that the sink will pull when it is operating in pull mode. .. method:: get_drop_out_of_segment() -> bool Checks if ``sink`` is currently configured to drop buffers which are outside the current segment .. versionadded:: 1.12 .. method:: get_last_sample() -> ~gi.repository.Gst.Sample | None Get the last sample that arrived in the sink and was used for preroll or for rendering. This property can be used to generate thumbnails. The :obj:`~gi.repository.Gst.Caps` on the sample can be used to determine the type of the buffer. Free-function: gst_sample_unref .. method:: get_latency() -> int Get the currently configured latency. .. method:: get_max_bitrate() -> int Get the maximum amount of bits per second that the sink will render. .. versionadded:: 1.2 .. method:: get_max_lateness() -> int Gets the max lateness value. See :func:`~gi.repository.GstBase.BaseSink.set_max_lateness` for more details. .. method:: get_processing_deadline() -> int Get the processing deadline of ``sink``\. see :func:`~gi.repository.GstBase.BaseSink.set_processing_deadline` for more information about the processing deadline. .. versionadded:: 1.16 .. method:: get_render_delay() -> int Get the render delay of ``sink``\. see :func:`~gi.repository.GstBase.BaseSink.set_render_delay` for more information about the render delay. .. method:: get_stats() -> ~gi.repository.Gst.Structure Return various :obj:`~gi.repository.GstBase.BaseSink` statistics. This function returns a :obj:`~gi.repository.Gst.Structure` with name ``application/x-gst-base-sink-stats`` with the following fields: - "average-rate" G_TYPE_DOUBLE average frame rate - "dropped" G_TYPE_UINT64 Number of dropped frames - "rendered" G_TYPE_UINT64 Number of rendered frames .. versionadded:: 1.18 .. method:: get_sync() -> bool Checks if ``sink`` is currently configured to synchronize against the clock. .. method:: get_throttle_time() -> int Get the time that will be inserted between frames to control the maximum buffers per second. .. method:: get_ts_offset() -> int Get the synchronisation offset of ``sink``\. .. method:: is_async_enabled() -> bool Checks if ``sink`` is currently configured to perform asynchronous state changes to PAUSED. .. method:: is_last_sample_enabled() -> bool Checks if ``sink`` is currently configured to store the last received sample in the last-sample property. .. method:: is_qos_enabled() -> bool Checks if ``sink`` is currently configured to send Quality-of-Service events upstream. .. method:: query_latency() -> ~typing.Tuple[bool, bool, bool, int, int] Query the sink for the latency parameters. The latency will be queried from the upstream elements. ``live`` will be :const:`True` if ``sink`` is configured to synchronize against the clock. ``upstream_live`` will be :const:`True` if an upstream element is live. If both ``live`` and ``upstream_live`` are :const:`True`, the sink will want to compensate for the latency introduced by the upstream elements by setting the ``min_latency`` to a strictly positive value. This function is mostly used by subclasses. .. method:: set_async_enabled(enabled: bool) -> None Configures ``sink`` to perform all state changes asynchronously. When async is disabled, the sink will immediately go to PAUSED instead of waiting for a preroll buffer. This feature is useful if the sink does not synchronize against the clock or when it is dealing with sparse streams. :param enabled: the new async value. .. method:: set_blocksize(blocksize: int) -> None Set the number of bytes that the sink will pull when it is operating in pull mode. :param blocksize: the blocksize in bytes .. method:: set_drop_out_of_segment(drop_out_of_segment: bool) -> None Configure ``sink`` to drop buffers which are outside the current segment .. versionadded:: 1.12 :param drop_out_of_segment: drop buffers outside the segment .. method:: set_last_sample_enabled(enabled: bool) -> None Configures ``sink`` to store the last received sample in the last-sample property. :param enabled: the new enable-last-sample value. .. method:: set_max_bitrate(max_bitrate: int) -> None Set the maximum amount of bits per second that the sink will render. .. versionadded:: 1.2 :param max_bitrate: the max_bitrate in bits per second .. method:: set_max_lateness(max_lateness: int) -> None Sets the new max lateness value to ``max_lateness``\. This value is used to decide if a buffer should be dropped or not based on the buffer timestamp and the current clock time. A value of -1 means an unlimited time. :param max_lateness: the new max lateness value. .. method:: set_processing_deadline(processing_deadline: int) -> None Maximum amount of time (in nanoseconds) that the pipeline can take for processing the buffer. This is added to the latency of live pipelines. This function is usually called by subclasses. .. versionadded:: 1.16 :param processing_deadline: the new processing deadline in nanoseconds. .. method:: set_qos_enabled(enabled: bool) -> None Configures ``sink`` to send Quality-of-Service events upstream. :param enabled: the new qos value. .. method:: set_render_delay(delay: int) -> None Set the render delay in ``sink`` to ``delay``\. The render delay is the time between actual rendering of a buffer and its synchronisation time. Some devices might delay media rendering which can be compensated for with this function. After calling this function, this sink will report additional latency and other sinks will adjust their latency to delay the rendering of their media. This function is usually called by subclasses. :param delay: the new delay .. method:: set_sync(sync: bool) -> None Configures ``sink`` to synchronize on the clock or not. When ``sync`` is :const:`False`, incoming samples will be played as fast as possible. If ``sync`` is :const:`True`, the timestamps of the incoming buffers will be used to schedule the exact render time of its contents. :param sync: the new sync value. .. method:: set_throttle_time(throttle: int) -> None Set the time that will be inserted between rendered buffers. This can be used to control the maximum buffers per second that the sink will render. :param throttle: the throttle time in nanoseconds .. method:: set_ts_offset(offset: int) -> None Adjust the synchronisation of ``sink`` with ``offset``\. A negative value will render buffers earlier than their timestamp. A positive value will delay rendering. This function can be used to fix playback of badly timestamped buffers. :param offset: the new offset .. method:: wait(time: int) -> ~typing.Tuple[~gi.repository.Gst.FlowReturn, int] This function will wait for preroll to complete and will then block until ``time`` is reached. It is usually called by subclasses that use their own internal synchronisation but want to let some synchronization (like EOS) be handled by the base class. This function should only be called with the PREROLL_LOCK held (like when receiving an EOS event in the ::event vmethod or when handling buffers in ::render). The ``time`` argument should be the running_time of when the timeout should happen and will be adjusted with any latency and offset configured in the sink. :param time: the running_time to be reached .. method:: wait_clock(time: int) -> ~typing.Tuple[~gi.repository.Gst.ClockReturn, int] This function will block until ``time`` is reached. It is usually called by subclasses that use their own internal synchronisation. If ``time`` is not valid, no synchronisation is done and %GST_CLOCK_BADTIME is returned. Likewise, if synchronisation is disabled in the element or there is no clock, no synchronisation is done and %GST_CLOCK_BADTIME is returned. This function should only be called with the PREROLL_LOCK held, like when receiving an EOS event in the ``GstBaseSinkClass``::event vmethod or when receiving a buffer in the ``GstBaseSinkClass``::render vmethod. The ``time`` argument should be the running_time of when this method should return and is not adjusted with any latency or offset configured in the sink. :param time: the running_time to be reached .. method:: wait_preroll() -> ~gi.repository.Gst.FlowReturn If the ``GstBaseSinkClass``::render method performs its own synchronisation against the clock it must unblock when going from PLAYING to the PAUSED state and call this method before continuing to render the remaining data. If the ``GstBaseSinkClass``::render method can block on something else than the clock, it must also be ready to unblock immediately on the ``GstBaseSinkClass``::unlock method and cause the ``GstBaseSinkClass``::render method to immediately call this function. In this case, the subclass must be prepared to continue rendering where it left off if this function returns %GST_FLOW_OK. This function will block until a state change to PLAYING happens (in which case this function returns %GST_FLOW_OK) or the processing must be stopped due to a state change to READY or a FLUSH event (in which case this function returns %GST_FLOW_FLUSHING). This function should only be called with the PREROLL_LOCK held, like in the render function. Properties ---------- .. rst-class:: interim-class .. class:: BaseSink :no-index: .. attribute:: props.async_ :type: bool The type of the None singleton. .. attribute:: props.blocksize :type: int The type of the None singleton. .. attribute:: props.enable_last_sample :type: bool The type of the None singleton. .. attribute:: props.last_sample :type: ~gi.repository.Gst.Sample The type of the None singleton. .. attribute:: props.max_bitrate :type: int The type of the None singleton. .. versionadded:: 1.2 .. attribute:: props.max_lateness :type: int The type of the None singleton. .. attribute:: props.processing_deadline :type: int The type of the None singleton. .. versionadded:: 1.16 .. attribute:: props.qos :type: bool The type of the None singleton. .. attribute:: props.render_delay :type: int The type of the None singleton. .. attribute:: props.stats :type: ~gi.repository.Gst.Structure The type of the None singleton. .. versionadded:: 1.18 .. attribute:: props.sync :type: bool .. attribute:: props.throttle_time :type: int The type of the None singleton. .. attribute:: props.ts_offset :type: int The type of the None singleton. Virtual Methods --------------- .. rst-class:: interim-class .. class:: BaseSink :no-index: .. method:: do_activate_pull(active: bool) -> bool The type of the None singleton. :param active: .. method:: do_event(event: ~gi.repository.Gst.Event) -> bool The type of the None singleton. :param event: .. method:: do_fixate(caps: ~gi.repository.Gst.Caps) -> ~gi.repository.Gst.Caps The type of the None singleton. :param caps: .. method:: do_get_caps(filter: ~gi.repository.Gst.Caps | None = None) -> ~gi.repository.Gst.Caps The type of the None singleton. :param filter: .. method:: do_get_times(buffer: ~gi.repository.Gst.Buffer) -> ~typing.Tuple[int, int] The type of the None singleton. :param buffer: .. method:: do_prepare(buffer: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn The type of the None singleton. :param buffer: .. method:: do_prepare_list(buffer_list: ~gi.repository.Gst.BufferList) -> ~gi.repository.Gst.FlowReturn The type of the None singleton. :param buffer_list: .. method:: do_preroll(buffer: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn The type of the None singleton. :param buffer: .. method:: do_propose_allocation(query: ~gi.repository.Gst.Query) -> bool The type of the None singleton. :param query: .. method:: do_query(query: ~gi.repository.Gst.Query) -> bool perform a :obj:`~gi.repository.Gst.Query` on the element. :param query: .. method:: do_render(buffer: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn The type of the None singleton. :param buffer: .. method:: do_render_list(buffer_list: ~gi.repository.Gst.BufferList) -> ~gi.repository.Gst.FlowReturn The type of the None singleton. :param buffer_list: .. method:: do_set_caps(caps: ~gi.repository.Gst.Caps) -> bool The type of the None singleton. :param caps: .. method:: do_start() -> bool The type of the None singleton. .. method:: do_stop() -> bool The type of the None singleton. .. method:: do_unlock() -> bool The type of the None singleton. .. method:: do_unlock_stop() -> bool The type of the None singleton. .. method:: do_wait_event(event: ~gi.repository.Gst.Event) -> ~gi.repository.Gst.FlowReturn The type of the None singleton. :param event: Fields ------ .. rst-class:: interim-class .. class:: BaseSink :no-index: .. attribute:: can_activate_pull .. attribute:: can_activate_push .. attribute:: clock_id .. attribute:: element .. attribute:: eos .. attribute:: flushing .. attribute:: have_newsegment .. attribute:: have_preroll .. attribute:: max_lateness .. attribute:: need_preroll .. attribute:: offset .. attribute:: pad_mode .. attribute:: playing_async .. attribute:: preroll_cond .. attribute:: preroll_lock .. attribute:: priv .. attribute:: running .. attribute:: segment .. attribute:: sinkpad .. attribute:: sync