: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` :Constructors: :: BaseSrc(**properties) Methods ------- .. rst-class:: interim-class .. class:: BaseSrc :no-index: .. method:: get_allocator() -> tuple[~gi.repository.Gst.Allocator, ~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() -> 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 See :func:`~gi.repository.GstBase.BaseSrc.set_automatic_eos` .. versionadded:: 1.24 .. attribute:: props.blocksize :type: int .. attribute:: props.do_timestamp :type: bool .. attribute:: props.num_buffers :type: int .. attribute:: props.typefind :type: bool Virtual Methods --------------- .. rst-class:: interim-class .. class:: BaseSrc :no-index: .. method:: do_alloc(offset: int, size: int) -> tuple[~gi.repository.Gst.FlowReturn, ~gi.repository.Gst.Buffer] Ask the subclass to allocate an output buffer with ``offset`` and ``size``, the default implementation will use the negotiated allocator. :param offset: :param size: .. method:: do_create(offset: int, size: int) -> tuple[~gi.repository.Gst.FlowReturn, ~gi.repository.Gst.Buffer] Ask the subclass to create a buffer with ``offset`` and ``size``, the default implementation will call alloc if no allocated ``buf`` is provided and then call fill. :param offset: :param size: .. method:: do_decide_allocation(query: ~gi.repository.Gst.Query) -> bool configure the allocation query :param query: .. method:: do_do_seek(segment: ~gi.repository.Gst.Segment) -> bool Perform seeking on the resource to the indicated segment. :param segment: .. method:: do_event(event: ~gi.repository.Gst.Event) -> bool Override this to implement custom event handling. :param event: .. method:: do_fill(offset: int, size: int, buf: ~gi.repository.Gst.Buffer) -> ~gi.repository.Gst.FlowReturn Ask the subclass to fill the buffer with data for offset and size. The passed buffer is guaranteed to hold the requested amount of bytes. :param offset: :param size: :param buf: .. method:: do_fixate(caps: ~gi.repository.Gst.Caps) -> ~gi.repository.Gst.Caps Called if, in negotiation, caps need fixating. :param caps: .. method:: do_get_caps(filter: ~gi.repository.Gst.Caps | None = None) -> ~gi.repository.Gst.Caps Called to get the caps to report. :param filter: .. method:: do_get_size() -> tuple[bool, int] Get the total size of the resource in the format set by :func:`~gi.repository.GstBase.BaseSrc.set_format`. .. method:: do_get_times(buffer: ~gi.repository.Gst.Buffer) -> tuple[int, int] Given ``buffer``, return ``start`` and ``end`` time when it should be pushed out. The base class will sync on the clock using these times. :param buffer: .. method:: do_is_seekable() -> bool Check if the source can seek .. 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 Prepare the :obj:`~gi.repository.Gst.Segment` that will be passed to the :obj:`~gi.repository.GstBase.BaseSrcClass`::do_seek vmethod for executing a seek request. Sub-classes should override this if they support seeking in formats other than the configured native format. By default, it tries to convert the seek arguments to the configured native format and prepare a segment in that format. :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 Start processing. Subclasses should open resources and prepare to produce data. Implementation should call :func:`~gi.repository.GstBase.BaseSrc.start_complete` when the operation completes, either from the current thread or any other thread that finishes the start operation asynchronously. .. method:: do_stop() -> bool Stop processing. Subclasses should use this to close resources. .. method:: do_unlock() -> bool Unlock any pending access to the resource. Subclasses should unblock any blocked function ASAP. In particular, any ``create()`` function in progress should be unblocked and should return GST_FLOW_FLUSHING. Any future :obj:`~gi.repository.GstBase.BaseSrcClass`::create function call should also return GST_FLOW_FLUSHING until the :obj:`~gi.repository.GstBase.BaseSrcClass`::unlock_stop function has been called. .. method:: do_unlock_stop() -> bool Clear the previous unlock request. Subclasses should clear any state they set during :obj:`~gi.repository.GstBase.BaseSrcClass`::unlock, such as clearing command queues. 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