GstBase.BaseSrc

g GObject.InitiallyUnowned GObject.InitiallyUnowned Gst.Object Gst.Object GObject.InitiallyUnowned->Gst.Object GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gst.Element Gst.Element GstBase.BaseSrc GstBase.BaseSrc Gst.Element->GstBase.BaseSrc Gst.Object->Gst.Element

Subclasses:

GstBase.PushSrc

Methods

Inherited:

Gst.Element (81), Gst.Object (27), GObject.Object (37)

Structs:

Gst.ElementClass (10), GObject.ObjectClass (5)

get_allocator ()

get_blocksize ()

get_buffer_pool ()

get_do_timestamp ()

is_async ()

is_live ()

negotiate ()

new_seamless_segment (start, stop, time)

new_segment (segment)

query_latency ()

set_async (async_)

set_automatic_eos (automatic_eos)

set_blocksize (blocksize)

set_caps (caps)

set_do_timestamp (timestamp)

set_dynamic_size (dynamic)

set_format (format)

set_live (live)

start_complete (ret)

start_wait ()

submit_buffer_list (buffer_list)

wait_playing ()

Virtual Methods

Inherited:

Gst.Element (16), Gst.Object (1), GObject.Object (7)

do_alloc (offset, size)

do_create (offset, size, buf)

do_decide_allocation (query)

do_do_seek (segment)

do_event (event)

do_fill (offset, size, buf)

do_fixate (caps)

do_get_caps (filter)

do_get_size ()

do_get_times (buffer)

do_is_seekable ()

do_negotiate ()

do_prepare_seek_segment (seek, segment)

do_query (query)

do_set_caps (caps)

do_start ()

do_stop ()

do_unlock ()

do_unlock_stop ()

Properties

Inherited:

Gst.Object (2)

Name

Type

Flags

Short Description

blocksize

int

r/w

Size in bytes to read per buffer (-1 = default)

do-timestamp

bool

r/w

Apply current stream time to buffers

num-buffers

int

r/w

Number of buffers to output before sending EOS (-1 = unlimited)

typefind

bool

d/r/w

Run typefind before negotiating (deprecated, non-functional) deprecated

Signals

Inherited:

Gst.Element (3), Gst.Object (1), GObject.Object (1)

Fields

Inherited:

Gst.Element (3), Gst.Object (1), GObject.Object (1)

Name

Type

Access

Description

blocksize

int

r

can_activate_push

bool

r

clock_id

object

r

element

Gst.Element

r

live_cond

GLib.Cond

r

live_lock

GLib.Mutex

r

live_running

bool

r

need_newsegment

bool

r

num_buffers

int

r

num_buffers_left

int

r

pending_seek

Gst.Event

r

random_access

bool

r

running

bool

r

segment

Gst.Segment

r

srcpad

Gst.Pad

r

typefind

bool

r

Class Details

class GstBase.BaseSrc(**kwargs)
Bases:

Gst.Element

Abstract:

Yes

Structure:

GstBase.BaseSrcClass

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 the GstBase.BaseSrc.set_format() method. The currently set format determines the format of the internal Gst.Segment and any Gst.EventType.SEGMENT events. The default format for GstBase.BaseSrc is Gst.Format.BYTES.

GstBase.BaseSrc always supports push mode scheduling. If the following conditions are met, it also supports pull mode scheduling:

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 not Gst.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. Use 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 #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 of GstBase.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 the 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.

get_allocator()
Returns:

allocator:

the Gst.Allocator used

params:

the Gst.AllocationParams of allocator

Return type:

(allocator: Gst.Allocator or None, 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()
Returns:

the number of bytes pushed with each buffer.

Return type:

int

Get the number of bytes that self will push out with each buffer.

get_buffer_pool()
Returns:

the instance of the Gst.BufferPool used by the src; unref it after usage.

Return type:

Gst.BufferPool or None

get_do_timestamp()
Returns:

True if the base class will automatically timestamp outgoing buffers.

Return type:

bool

Query if self timestamps outgoing buffers based on the current running_time.

is_async()
Returns:

True if self is operating in async mode.

Return type:

bool

Get the current async behaviour of self. See also GstBase.BaseSrc.set_async().

is_live()
Returns:

True if element is in live mode.

Return type:

bool

Check if an element is in live mode.

negotiate()
Returns:

True if the negotiation succeeded, else False.

Return type:

bool

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)
Parameters:
  • start (int) – The new start value for the segment

  • stop (int) – Stop value for the new segment

  • time (int) – The new time value for the start of the new segment

Returns:

True if preparation of the seamless segment succeeded.

Return type:

bool

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)
Parameters:

segment (Gst.Segment) – a pointer to a Gst.Segment

Returns:

True if preparation of new segment succeeded.

Return type:

bool

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 via GstBase.BaseSrc.set_format() before calling this method.

New in version 1.18.

query_latency()
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:

(bool, live: bool, min_latency: int, max_latency: int)

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_)
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)
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 is 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 False.

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 is True. Since 1.16, if automatic_eos is False an EOS will be pushed only when the #GstBaseSrcClass::create implementation returns Gst.FlowReturn.EOS.

New in version 1.4.

set_blocksize(blocksize)
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_caps(caps)
Parameters:

caps (Gst.Caps) – a Gst.Caps

Returns:

True if the caps could be set

Return type:

bool

Set new caps on the basesrc source pad.

set_do_timestamp(timestamp)
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)
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)
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 returns True.

This function must only be called in states < Gst.State.PAUSED.

set_live(live)
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)
Parameters:

ret (Gst.FlowReturn) – a Gst.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.

start_wait()
Returns:

a Gst.FlowReturn.

Return type:

Gst.FlowReturn

Wait until the start operation completes.

submit_buffer_list(buffer_list)
Parameters:

buffer_list (Gst.BufferList) – a Gst.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()
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:

Gst.FlowReturn

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 returns Gst.FlowReturn.FLUSHING).

do_alloc(offset, size) virtual
Parameters:
  • offset (int) –

  • size (int) –

Return type:

(Gst.FlowReturn, buf: Gst.Buffer or None)

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:
Return type:

(Gst.FlowReturn, buf: Gst.Buffer or None)

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
Parameters:

query (Gst.Query) –

Return type:

bool

do_do_seek(segment) virtual
Parameters:

segment (Gst.Segment) –

Return type:

bool

do_event(event) virtual
Parameters:

event (Gst.Event) –

Return type:

bool

do_fill(offset, size, buf) virtual
Parameters:
Return type:

Gst.FlowReturn

do_fixate(caps) virtual
Parameters:

caps (Gst.Caps) –

Returns:

the fixated caps

Return type:

Gst.Caps

Called if, in negotiation, caps need fixating.

do_get_caps(filter) virtual
Parameters:

filter (Gst.Caps or None) –

Return type:

Gst.Caps

Called to get the caps to report.

do_get_size() virtual
Returns:

True if the size is available and has been set.

Return type:

(bool, size: int)

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:

(start: int, end: 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.

do_is_seekable() virtual
Return type:

bool

do_negotiate() virtual
Returns:

True if the negotiation succeeded, else False.

Return type:

bool

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:
Return type:

bool

do_query(query) virtual
Parameters:

query (Gst.Query) –

Return type:

bool

do_set_caps(caps) virtual
Parameters:

caps (Gst.Caps) – a Gst.Caps

Returns:

True if the caps could be set

Return type:

bool

Set new caps on the basesrc source pad.

do_start() virtual
Return type:

bool

do_stop() virtual
Return type:

bool

do_unlock() virtual
Return type:

bool

do_unlock_stop() virtual
Return type:

bool

Property Details

GstBase.BaseSrc.props.blocksize
Name:

blocksize

Type:

int

Default Value:

4096

Flags:

READABLE, WRITABLE

Size in bytes to read per buffer (-1 = default)

GstBase.BaseSrc.props.do_timestamp
Name:

do-timestamp

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Apply current stream time to buffers

GstBase.BaseSrc.props.num_buffers
Name:

num-buffers

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE

Number of buffers to output before sending EOS (-1 = unlimited)

GstBase.BaseSrc.props.typefind
Name:

typefind

Type:

bool

Default Value:

False

Flags:

DEPRECATED, READABLE, WRITABLE

Run typefind before negotiating (deprecated, non-functional)

Deprecated since version ???.