GstBase.BaseSrc¶
- Subclasses:
Methods¶
- Inherited:
- Structs:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r/w |
Automatically EOS when the segment is done |
||
r/w |
Size in bytes to read per buffer (-1 = default) |
||
r/w |
Apply current stream time to buffers |
||
r/w |
Number of buffers to output before sending EOS (-1 = unlimited) |
||
d/r/w |
Run typefind before negotiating (deprecated, non-functional) |
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
blocksize |
r |
||
can_activate_push |
r |
||
clock_id |
r |
||
element |
r |
||
live_cond |
r |
||
live_lock |
r |
||
live_running |
r |
||
need_newsegment |
r |
||
num_buffers |
r |
||
num_buffers_left |
r |
||
pending_seek |
r |
||
random_access |
r |
||
running |
r |
||
segment |
r |
||
srcpad |
r |
||
typefind |
r |
Class Details¶
- class GstBase.BaseSrc(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
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
Gst.Format
with theGstBase.BaseSrc.set_format
() method. The currently set format determines the format of the internalGst.Segment
and anyGst.EventType.SEGMENT
events. The default format forGstBase.BaseSrc
isGst.Format.BYTES
.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).#GstBaseSrcClass::is_seekable returns
True
.
If all the conditions are met for operating in pull mode,
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 notGst.Format.BYTES
:#GstBaseSrcClass::is_seekable returns
True
.#GstBaseSrcClass::query can convert all supported seek formats to the internal format as set with
GstBase.BaseSrc.set_format
().#GstBaseSrcClass::do_seek is implemented, performs the seek and returns
True
.
When the element does not meet the requirements to operate in pull mode, the offset and length in the #GstBaseSrcClass::create method should be ignored. It is recommended to subclass
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 #GstBaseSrcClass::create function.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. UseGstBase.BaseSrc.set_live
() to activate the live source mode.A live source does not produce data in the PAUSED state. This means that the #GstBaseSrcClass::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.StateChangeReturn.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
GstBase.BaseSrc.wait_playing
() when the #GstBaseSrcClass::create function was interrupted by a state change to PAUSED.The #GstBaseSrcClass::get_times method can be used to implement pseudo-live sources. It only makes sense to implement the #GstBaseSrcClass::get_times function if the source is a live source. The #GstBaseSrcClass::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
GstBase.BaseSrc
for exactly one source pad, which should be named “src”. A source implementation (subclass ofGstBase.BaseSrc
) should install a pad template in its class_init function, like so: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 <my.sink@my.email>"); }
- 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.MessageType.SEGMENT_DONE
on the bus). This can typically be done with theGst.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.
- get_allocator()[source]¶
- Returns:
- allocator:
the
Gst.Allocator
used- params:
the
Gst.AllocationParams
of allocator
- Return type:
(allocator:
Gst.Allocator
orNone
, params:Gst.AllocationParams
)
Lets
GstBase.BaseSrc
sub-classes to know the memory allocator used by the base class and its params.Unref the allocator after usage.
- get_blocksize()[source]¶
- Returns:
the number of bytes pushed with each buffer.
- Return type:
Get the number of bytes that self will push out with each buffer.
- get_buffer_pool()[source]¶
- Returns:
the instance of the
Gst.BufferPool
used by the src; unref it after usage.- Return type:
- get_do_timestamp()[source]¶
-
Query if self timestamps outgoing buffers based on the current running_time.
- is_async()[source]¶
-
Get the current async behaviour of self. See also
GstBase.BaseSrc.set_async
().
- negotiate()[source]¶
-
Negotiates src pad caps with downstream elements. Unmarks
Gst.PadFlags.NEED_RECONFIGURE
in any case. But marks it again if #GstBaseSrcClass::negotiate fails.Do not call this in the #GstBaseSrcClass::fill vmethod. Call this in #GstBaseSrcClass::create or in #GstBaseSrcClass::alloc, _before_ any buffer is allocated.
New in version 1.18.
- new_seamless_segment(start, stop, time)[source]¶
- Parameters:
- Returns:
True
if preparation of the seamless segment succeeded.- Return type:
Prepare a new seamless segment for emission downstream. This function must only be called by derived sub-classes, and only from the #GstBaseSrcClass::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
GstBase.BaseSrc.set_format
()Deprecated since version 1.18: Use
GstBase.BaseSrc.new_segment
()
- new_segment(segment)[source]¶
- Parameters:
segment (
Gst.Segment
) – a pointer to aGst.Segment
- Returns:
True
if preparation of new segment succeeded.- Return type:
Prepare a new segment for emission downstream. This function must only be called by derived sub-classes, and only from the #GstBaseSrcClass::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
GstBase.BaseSrc.set_format
().The format of self must not be
Gst.Format.UNDEFINED
and the format should be configured viaGstBase.BaseSrc.set_format
() before calling this method.New in version 1.18.
- push_segment(segment)[source]¶
- Parameters:
segment (
Gst.Segment
) – a pointer to aGst.Segment
- Returns:
True
if sending of new segment succeeded.- Return type:
Send a new segment downstream. This function must only be called by derived sub-classes, and only from the #GstBaseSrcClass::create function, as the stream-lock needs to be held. This method also requires that an out caps has been configured, so
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
GstBase.BaseSrc.set_format
().The format of self must not be
Gst.Format.UNDEFINED
and the format should be configured viaGstBase.BaseSrc.set_format
() before calling this method.This is a variant of
GstBase.BaseSrc.new_segment
() sending the segment right away, which can be useful to ensure events ordering.New in version 1.24.
- query_latency()[source]¶
- Returns:
True
if the query succeeded.- live:
if the source is live
- min_latency:
the min latency of the source
- max_latency:
the max latency of the source
- Return type:
Query the source for the latency parameters. live will be
True
when self 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.
- set_async(async_)[source]¶
- Parameters:
async (
bool
) – new async mode
Configure async behaviour in self, 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.
- set_automatic_eos(automatic_eos)[source]¶
- Parameters:
automatic_eos (
bool
) – automatic eos
If automatic_eos is
True
, self will automatically go EOS if a buffer after the total size is returned. By default this isTrue
but sources that can’t return an authoritative size and only know that they’re EOS when trying to read more should set this toFalse
.When self operates in
Gst.Format.TIME
,GstBase.BaseSrc
will send an EOS when a buffer outside of the currently configured segment is pushed if automatic_eos isTrue
. Since 1.16, if automatic_eos isFalse
an EOS will be pushed only when the #GstBaseSrcClass::create implementation returnsGst.FlowReturn.EOS
.New in version 1.4.
- set_blocksize(blocksize)[source]¶
- Parameters:
blocksize (
int
) – the new blocksize in bytes
Set the number of bytes that self will push out with each buffer. When blocksize is set to -1, a default length will be used.
- set_do_timestamp(timestamp)[source]¶
- Parameters:
timestamp (
bool
) – enable or disable timestamping
Configure self to automatically timestamp outgoing buffers based on the current running_time of the pipeline. This property is mostly useful for live sources.
- set_dynamic_size(dynamic)[source]¶
- Parameters:
dynamic (
bool
) – new dynamic size mode
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.
- set_format(format)[source]¶
- Parameters:
format (
Gst.Format
) – the format to use
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 #GstBaseSrcClass::is_seekable returnsTrue
.This function must only be called in states <
Gst.State.PAUSED
.
- set_live(live)[source]¶
- Parameters:
live (
bool
) – new live-mode
If the element listens to a live source, live should be set to
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.StateChangeReturn.NO_PREROLL
.
- start_complete(ret)[source]¶
- Parameters:
ret (
Gst.FlowReturn
) – aGst.FlowReturn
Complete an asynchronous start operation. When the subclass overrides the start method, it should call
GstBase.BaseSrc.start_complete
() when the start operation completes either from the same thread or from an asynchronous helper thread.
- submit_buffer_list(buffer_list)[source]¶
- Parameters:
buffer_list (
Gst.BufferList
) – aGst.BufferList
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
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.FlowReturn.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.
New in version 1.14.
- wait_playing()[source]¶
- Returns:
Gst.FlowReturn.OK
if self is PLAYING and processing can continue. Any other return value should be returned from the create vmethod.- Return type:
If the #GstBaseSrcClass::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.FlowReturn.OK
) or the processing must be stopped due to a state change to READY or a FLUSH event (in which case this function returnsGst.FlowReturn.FLUSHING
).
- do_alloc(offset, size) virtual¶
- Parameters:
- Return type:
(
Gst.FlowReturn
, buf:Gst.Buffer
orNone
)
Ask the subclass to allocate an output buffer with offset and size, the default implementation will use the negotiated allocator.
- do_create(offset, size, buf) virtual¶
- Parameters:
offset (
int
) –size (
int
) –buf (
Gst.Buffer
orNone
) –
- Return type:
(
Gst.FlowReturn
, buf:Gst.Buffer
orNone
)
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.
- do_decide_allocation(query) virtual¶
-
configure the allocation query
- do_do_seek(segment) virtual¶
- Parameters:
segment (
Gst.Segment
) –- Return type:
Perform seeking on the resource to the indicated segment.
- do_event(event) virtual¶
-
Override this to implement custom event handling.
- do_fill(offset, size, buf) virtual¶
- Parameters:
offset (
int
) –size (
int
) –buf (
Gst.Buffer
) –
- Return type:
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.
- do_fixate(caps) virtual¶
-
Called if, in negotiation, caps need fixating.
- do_get_caps(filter) virtual¶
-
Called to get the caps to report.
- do_get_size() virtual¶
-
Get the total size of the resource in the format set by
GstBase.BaseSrc.set_format
().
- do_get_times(buffer) virtual¶
- Parameters:
buffer (
Gst.Buffer
) –- Return type:
Given buffer, return start and end time when it should be pushed out. The base class will sync on the clock using these times.
- do_negotiate() virtual¶
-
Negotiates src pad caps with downstream elements. Unmarks
Gst.PadFlags.NEED_RECONFIGURE
in any case. But marks it again if #GstBaseSrcClass::negotiate fails.Do not call this in the #GstBaseSrcClass::fill vmethod. Call this in #GstBaseSrcClass::create or in #GstBaseSrcClass::alloc, _before_ any buffer is allocated.
New in version 1.18.
- do_prepare_seek_segment(seek, segment) virtual¶
- Parameters:
seek (
Gst.Event
) –segment (
Gst.Segment
) –
- Return type:
Prepare the
Gst.Segment
that will be passed to the #GstBaseSrcClass::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.
- do_query(query) virtual¶
-
Handle a requested query.
- do_set_caps(caps) virtual¶
-
Set new caps on the basesrc source pad.
- do_start() virtual¶
- Return type:
Start processing. Subclasses should open resources and prepare to produce data. Implementation should call
GstBase.BaseSrc.start_complete
() when the operation completes, either from the current thread or any other thread that finishes the start operation asynchronously.
- do_stop() virtual¶
- Return type:
Stop processing. Subclasses should use this to close resources.
- do_unlock() virtual¶
- Return type:
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 returnGst.FlowReturn.FLUSHING
. Any future #GstBaseSrcClass::create function call should also returnGst.FlowReturn.FLUSHING
until the #GstBaseSrcClass::unlock_stop function has been called.
Property Details¶
- GstBase.BaseSrc.props.automatic_eos¶
-
See
GstBase.BaseSrc.set_automatic_eos
()New in version 1.24.
- GstBase.BaseSrc.props.blocksize¶
-
Size in bytes to read per buffer (-1 = default)
- GstBase.BaseSrc.props.do_timestamp¶
-
Apply current stream time to buffers
- GstBase.BaseSrc.props.num_buffers¶
-
Number of buffers to output before sending EOS (-1 = unlimited)