:right-sidebar: True BaseSrc =================================================================== .. currentmodule:: gi.repository.GstBase .. class:: BaseSrc(**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` Subclasses: :class:`~gi.repository.GstBase.PushSrc` This is a generic base class for source elements. The following types of sources are supported: - random access sources like files - seekable sources - live sources The source can be configured to operate in any :obj:`~gi.repository.Gst.Format` with the :func:`~gi.repository.GstBase.BaseSrc.set_format` method. The currently set format determines the format of the internal :obj:`~gi.repository.Gst.Segment` and any %GST_EVENT_SEGMENT events. The default format for :obj:`~gi.repository.GstBase.BaseSrc` is %GST_FORMAT_BYTES. :obj:`~gi.repository.GstBase.BaseSrc` always supports push mode scheduling. If the following conditions are met, it also supports pull mode scheduling: - The format is set to %GST_FORMAT_BYTES (default). - :obj:`~gi.repository.GstBase.BaseSrcClass`\::is_seekable returns :const:`True`. If all the conditions are met for operating in pull mode, :obj:`~gi.repository.GstBase.BaseSrc` is automatically seekable in push mode as well. The following conditions must be met to make the element seekable in push mode when the format is not %GST_FORMAT_BYTES: - :obj:`~gi.repository.GstBase.BaseSrcClass`\::is_seekable returns :const:`True`. - :obj:`~gi.repository.GstBase.BaseSrcClass`\::query can convert all supported seek formats to the internal format as set with :func:`~gi.repository.GstBase.BaseSrc.set_format`. - :obj:`~gi.repository.GstBase.BaseSrcClass`\::do_seek is implemented, performs the seek and returns :const:`True`. When the element does not meet the requirements to operate in pull mode, the offset and length in the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create method should be ignored. It is recommended to subclass :obj:`~gi.repository.GstBase.PushSrc` instead, in this situation. If the element can operate in pull mode but only with specific offsets and lengths, it is allowed to generate an error when the wrong values are passed to the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create function. :obj:`~gi.repository.GstBase.BaseSrc` has support for live sources. Live sources are sources that when paused discard data, such as audio or video capture devices. A typical live source also produces data at a fixed rate and thus provides a clock to publish this rate. Use :func:`~gi.repository.GstBase.BaseSrc.set_live` to activate the live source mode. A live source does not produce data in the PAUSED state. This means that the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create method will not be called in PAUSED but only in PLAYING. To signal the pipeline that the element will not produce data, the return value from the READY to PAUSED state will be %GST_STATE_CHANGE_NO_PREROLL. A typical live source will timestamp the buffers it creates with the current running time of the pipeline. This is one reason why a live source can only produce data in the PLAYING state, when the clock is actually distributed and running. Live sources that synchronize and block on the clock (an audio source, for example) can use :func:`~gi.repository.GstBase.BaseSrc.wait_playing` when the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create function was interrupted by a state change to PAUSED. The :obj:`~gi.repository.GstBase.BaseSrcClass`\::get_times method can be used to implement pseudo-live sources. It only makes sense to implement the :obj:`~gi.repository.GstBase.BaseSrcClass`\::get_times function if the source is a live source. The :obj:`~gi.repository.GstBase.BaseSrcClass`\::get_times function should return timestamps starting from 0, as if it were a non-live source. The base class will make sure that the timestamps are transformed into the current running_time. The base source will then wait for the calculated running_time before pushing out the buffer. For live sources, the base class will by default report a latency of 0. For pseudo live sources, the base class will by default measure the difference between the first buffer timestamp and the start time of get_times and will report this value as the latency. Subclasses should override the query function when this behaviour is not acceptable. There is only support in :obj:`~gi.repository.GstBase.BaseSrc` for exactly one source pad, which should be named "src". A source implementation (subclass of :obj:`~gi.repository.GstBase.BaseSrc`\) 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); // srctemplate should be a #GstStaticPadTemplate with direction // %GST_PAD_SRC and name "src" gst_element_class_add_static_pad_template (gstelement_class, &srctemplate); gst_element_class_set_static_metadata (gstelement_class, "Source name", "Source", "My Source element", "The author "); } Controlled shutdown of live sources in applications -------------------------------------------------------------------------------- Applications that record from a live source may want to stop recording in a controlled way, so that the recording is stopped, but the data already in the pipeline is processed to the end (remember that many live sources would go on recording forever otherwise). For that to happen the application needs to make the source stop recording and send an EOS event down the pipeline. The application would then wait for an EOS message posted on the pipeline's bus to know when all data has been processed and the pipeline can safely be stopped. An application may send an EOS event to a source element to make it perform the EOS logic (send EOS event downstream or post a %GST_MESSAGE_SEGMENT_DONE on the bus). This can typically be done with the :func:`~gi.repository.Gst.Gst.Element.send_event` function on the element or its parent bin. After the EOS has been sent to the element, the application should wait for an EOS message to be posted on the pipeline's bus. Once this EOS message is received, it may safely shut down the entire pipeline. Methods ------- .. rst-class:: interim-class .. class:: BaseSrc :no-index: .. method:: do_alloc(self, offset: int, size: int) -> ~typing.Tuple[~gi.repository.Gst.FlowReturn, ~gi.repository.Gst.Buffer | None] :param offset: :param size: .. method:: do_create(self, offset: int, size: int, buf: ~gi.repository.Gst.Buffer | None = None) -> ~typing.Tuple[~gi.repository.Gst.FlowReturn, ~gi.repository.Gst.Buffer | None] :param offset: :param size: :param buf: .. method:: do_decide_allocation(self, query: ~gi.repository.Gst.Query) -> bool :param query: .. method:: do_do_seek(self, segment: ~gi.repository.Gst.Segment) -> bool :param segment: .. method:: do_event(self, event: ~gi.repository.Gst.Event) -> bool :param event: .. method:: do_fill(self, offset: int, size: int, buf: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn :param offset: :param size: :param buf: .. 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_size(self) -> ~typing.Tuple[bool, int] .. method:: do_get_times(self, buffer: ~gi.repository.Gst.Buffer) -> ~typing.Tuple[int, int] :param buffer: .. method:: do_is_seekable(self) -> bool .. method:: do_negotiate(self) -> bool .. method:: do_prepare_seek_segment(self, seek: ~gi.repository.Gst.Event, segment: ~gi.repository.Gst.Segment) -> bool :param seek: :param segment: .. method:: do_query(self, query: ~gi.repository.Gst.Query) -> bool :param query: .. 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:: get_allocator() -> ~typing.Tuple[~gi.repository.Gst.Allocator | None, ~gi.repository.Gst.AllocationParams] Lets :obj:`~gi.repository.GstBase.BaseSrc` sub-classes to know the memory ``allocator`` used by the base class and its ``params``\. Unref the ``allocator`` after usage. .. method:: get_blocksize() -> int Get the number of bytes that ``src`` will push out with each buffer. .. method:: get_buffer_pool() -> ~gi.repository.Gst.BufferPool | None .. method:: get_do_timestamp() -> bool Query if ``src`` timestamps outgoing buffers based on the current running_time. .. method:: is_async() -> bool Get the current async behaviour of ``src``\. See also :func:`~gi.repository.GstBase.BaseSrc.set_async`. .. method:: negotiate() -> bool Negotiates src pad caps with downstream elements. Unmarks GST_PAD_FLAG_NEED_RECONFIGURE in any case. But marks it again if :obj:`~gi.repository.GstBase.BaseSrcClass`\::negotiate fails. Do not call this in the :obj:`~gi.repository.GstBase.BaseSrcClass`\::fill vmethod. Call this in :obj:`~gi.repository.GstBase.BaseSrcClass`\::create or in :obj:`~gi.repository.GstBase.BaseSrcClass`\::alloc, *before* any buffer is allocated. .. versionadded:: 1.18 .. method:: new_seamless_segment(start: int, stop: int, time: int) -> bool Prepare a new seamless segment for emission downstream. This function must only be called by derived sub-classes, and only from the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create function, as the stream-lock needs to be held. The format for the new segment will be the current format of the source, as configured with :func:`~gi.repository.GstBase.BaseSrc.set_format` .. deprecated:: 1.18 Use :func:`~gi.repository.GstBase.BaseSrc.new_segment` :param start: The new start value for the segment :param stop: Stop value for the new segment :param time: The new time value for the start of the new segment .. method:: new_segment(segment: ~gi.repository.Gst.Segment) -> bool Prepare a new segment for emission downstream. This function must only be called by derived sub-classes, and only from the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create function, as the stream-lock needs to be held. The format for the ``segment`` must be identical with the current format of the source, as configured with :func:`~gi.repository.GstBase.BaseSrc.set_format`. The format of ``src`` must not be %GST_FORMAT_UNDEFINED and the format should be configured via :func:`~gi.repository.GstBase.BaseSrc.set_format` before calling this method. .. versionadded:: 1.18 :param segment: a pointer to a :obj:`~gi.repository.Gst.Segment` .. method:: push_segment(segment: ~gi.repository.Gst.Segment) -> bool Send a new segment downstream. This function must only be called by derived sub-classes, and only from the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create function, as the stream-lock needs to be held. This method also requires that an out caps has been configured, so :func:`~gi.repository.GstBase.BaseSrc.set_caps` needs to have been called before. The format for the ``segment`` must be identical with the current format of the source, as configured with :func:`~gi.repository.GstBase.BaseSrc.set_format`. The format of ``src`` must not be %GST_FORMAT_UNDEFINED and the format should be configured via :func:`~gi.repository.GstBase.BaseSrc.set_format` before calling this method. This is a variant of :func:`~gi.repository.GstBase.BaseSrc.new_segment` sending the segment right away, which can be useful to ensure events ordering. .. versionadded:: 1.24 :param segment: a pointer to a :obj:`~gi.repository.Gst.Segment` .. method:: query_latency() -> ~typing.Tuple[bool, bool, int, int] Query the source for the latency parameters. ``live`` will be :const:`True` when ``src`` is configured as a live source. ``min_latency`` and ``max_latency`` will be set to the difference between the running time and the timestamp of the first buffer. This function is mostly used by subclasses. .. method:: set_async(async_: bool) -> None Configure async behaviour in ``src``\, no state change will block. The open, close, start, stop, play and pause virtual methods will be executed in a different thread and are thus allowed to perform blocking operations. Any blocking operation should be unblocked with the unlock vmethod. :param async_: .. method:: set_automatic_eos(automatic_eos: bool) -> None If ``automatic_eos`` is :const:`True`, ``src`` will automatically go EOS if a buffer after the total size is returned. By default this is :const:`True` but sources that can't return an authoritative size and only know that they're EOS when trying to read more should set this to :const:`False`. When ``src`` operates in %GST_FORMAT_TIME, :obj:`~gi.repository.GstBase.BaseSrc` will send an EOS when a buffer outside of the currently configured segment is pushed if ``automatic_eos`` is :const:`True`. Since 1.16, if ``automatic_eos`` is :const:`False` an EOS will be pushed only when the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create implementation returns %GST_FLOW_EOS. .. versionadded:: 1.4 :param automatic_eos: automatic eos .. method:: set_blocksize(blocksize: int) -> None Set the number of bytes that ``src`` will push out with each buffer. When ``blocksize`` is set to -1, a default length will be used. :param blocksize: the new blocksize in bytes .. method:: set_caps(caps: ~gi.repository.Gst.Caps) -> bool Set new caps on the basesrc source pad. :param caps: a :obj:`~gi.repository.Gst.Caps` .. method:: set_do_timestamp(timestamp: bool) -> None Configure ``src`` to automatically timestamp outgoing buffers based on the current running_time of the pipeline. This property is mostly useful for live sources. :param timestamp: enable or disable timestamping .. method:: set_dynamic_size(dynamic: bool) -> None If not ``dynamic``\, size is only updated when needed, such as when trying to read past current tracked size. Otherwise, size is checked for upon each read. :param dynamic: new dynamic size mode .. method:: set_format(format: ~gi.repository.Gst.Format) -> None Sets the default format of the source. This will be the format used for sending SEGMENT events and for performing seeks. If a format of GST_FORMAT_BYTES is set, the element will be able to operate in pull mode if the :obj:`~gi.repository.GstBase.BaseSrcClass`\::is_seekable returns :const:`True`. This function must only be called in states < %GST_STATE_PAUSED. :param format: the format to use .. method:: set_live(live: bool) -> None If the element listens to a live source, ``live`` should be set to :const:`True`. A live source will not produce data in the PAUSED state and will therefore not be able to participate in the PREROLL phase of a pipeline. To signal this fact to the application and the pipeline, the state change return value of the live source will be GST_STATE_CHANGE_NO_PREROLL. :param live: new live-mode .. method:: start_complete(ret: ~gi.repository.Gst.FlowReturn) -> None Complete an asynchronous start operation. When the subclass overrides the start method, it should call :func:`~gi.repository.GstBase.BaseSrc.start_complete` when the start operation completes either from the same thread or from an asynchronous helper thread. :param ret: a :obj:`~gi.repository.Gst.FlowReturn` .. method:: start_wait() -> ~gi.repository.Gst.FlowReturn Wait until the start operation completes. .. method:: submit_buffer_list(buffer_list: ~gi.repository.Gst.BufferList) -> None Subclasses can call this from their create virtual method implementation to submit a buffer list to be pushed out later. This is useful in cases where the create function wants to produce multiple buffers to be pushed out in one go in form of a :obj:`~gi.repository.Gst.BufferList`\, which can reduce overhead drastically, especially for packetised inputs (for data streams where the packetisation/chunking is not important it is usually more efficient to return larger buffers instead). Subclasses that use this function from their create function must return %GST_FLOW_OK and no buffer from their create virtual method implementation. If a buffer is returned after a buffer list has also been submitted via this function the behaviour is undefined. Subclasses must only call this function once per create function call and subclasses must only call this function when the source operates in push mode. .. versionadded:: 1.14 :param buffer_list: a :obj:`~gi.repository.Gst.BufferList` .. method:: wait_playing() -> ~gi.repository.Gst.FlowReturn If the :obj:`~gi.repository.GstBase.BaseSrcClass`\::create 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 produce the remaining data. 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). Properties ---------- .. rst-class:: interim-class .. class:: BaseSrc :no-index: .. attribute:: props.automatic_eos :type: bool The type of the None singleton. .. versionadded:: 1.24 .. attribute:: props.blocksize :type: int .. attribute:: props.do_timestamp :type: bool The type of the None singleton. .. attribute:: props.num_buffers :type: int The type of the None singleton. .. attribute:: props.typefind :type: bool Virtual Methods --------------- .. rst-class:: interim-class .. class:: BaseSrc :no-index: .. method:: do_alloc(offset: int, size: int) -> ~typing.Tuple[~gi.repository.Gst.FlowReturn, ~gi.repository.Gst.Buffer | None] The type of the None singleton. :param offset: :param size: .. method:: do_create(offset: int, size: int, buf: ~gi.repository.Gst.Buffer | None = None) -> ~typing.Tuple[~gi.repository.Gst.FlowReturn, ~gi.repository.Gst.Buffer | None] The type of the None singleton. :param offset: :param size: :param buf: .. method:: do_decide_allocation(query: ~gi.repository.Gst.Query) -> bool The type of the None singleton. :param query: .. method:: do_do_seek(segment: ~gi.repository.Gst.Segment) -> bool The type of the None singleton. :param segment: .. method:: do_event(event: ~gi.repository.Gst.Event) -> bool The type of the None singleton. :param event: .. method:: do_fill(offset: int, size: int, buf: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn The type of the None singleton. :param offset: :param size: :param buf: .. 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_size() -> ~typing.Tuple[bool, int] The type of the None singleton. .. method:: do_get_times(buffer: ~gi.repository.Gst.Buffer) -> ~typing.Tuple[int, int] The type of the None singleton. :param buffer: .. method:: do_is_seekable() -> bool The type of the None singleton. .. method:: do_negotiate() -> bool Negotiates src pad caps with downstream elements. Unmarks GST_PAD_FLAG_NEED_RECONFIGURE in any case. But marks it again if :obj:`~gi.repository.GstBase.BaseSrcClass`\::negotiate fails. Do not call this in the :obj:`~gi.repository.GstBase.BaseSrcClass`\::fill vmethod. Call this in :obj:`~gi.repository.GstBase.BaseSrcClass`\::create or in :obj:`~gi.repository.GstBase.BaseSrcClass`\::alloc, *before* any buffer is allocated. .. versionadded:: 1.18 .. method:: do_prepare_seek_segment(seek: ~gi.repository.Gst.Event, segment: ~gi.repository.Gst.Segment) -> bool The type of the None singleton. :param seek: :param segment: .. method:: do_query(query: ~gi.repository.Gst.Query) -> bool Handle a requested query. :param query: .. method:: do_set_caps(caps: ~gi.repository.Gst.Caps) -> bool Set new caps on the basesrc source pad. :param caps: a :obj:`~gi.repository.Gst.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. Fields ------ .. rst-class:: interim-class .. class:: BaseSrc :no-index: .. attribute:: blocksize .. attribute:: can_activate_push .. attribute:: clock_id .. attribute:: element .. attribute:: is_live .. attribute:: live_cond .. attribute:: live_lock .. attribute:: live_running .. attribute:: need_newsegment .. attribute:: num_buffers .. attribute:: num_buffers_left .. attribute:: pending_seek .. attribute:: priv .. attribute:: random_access .. attribute:: running .. attribute:: segment .. attribute:: srcpad .. attribute:: typefind