GstApp.AppSrc

g GObject.GInterface GObject.GInterface Gst.URIHandler Gst.URIHandler GObject.GInterface->Gst.URIHandler 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 GstApp.AppSrc GstApp.AppSrc Gst.URIHandler->GstApp.AppSrc GstBase.BaseSrc->GstApp.AppSrc

Subclasses:

None

Methods

Inherited:

GstBase.BaseSrc (22), Gst.Element (81), Gst.Object (27), GObject.Object (37), Gst.URIHandler (4)

Structs:

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

end_of_stream ()

get_caps ()

get_current_level_buffers ()

get_current_level_bytes ()

get_current_level_time ()

get_duration ()

get_emit_signals ()

get_latency ()

get_leaky_type ()

get_max_buffers ()

get_max_bytes ()

get_max_time ()

get_size ()

get_stream_type ()

push_buffer (buffer)

push_buffer_list (buffer_list)

push_sample (sample)

set_caps (caps)

set_duration (duration)

set_emit_signals (emit)

set_latency (min, max)

set_leaky_type (leaky)

set_max_buffers (max)

set_max_bytes (max)

set_max_time (max)

set_size (size)

set_stream_type (type)

Virtual Methods

Inherited:

GstBase.BaseSrc (19), Gst.Element (16), Gst.Object (1), GObject.Object (7), Gst.URIHandler (2)

do_end_of_stream ()

do_enough_data ()

do_need_data (length)

do_push_buffer (buffer)

do_push_buffer_list (buffer_list)

do_push_sample (sample)

do_seek_data (offset)

Properties

Inherited:

GstBase.BaseSrc (4), Gst.Object (2)

Name

Type

Flags

Short Description

block

bool

r/w

Block push-buffer when max-bytes are queued

caps

Gst.Caps

r/w

The allowed caps for the src pad

current-level-buffers

int

r

The number of currently queued buffers

current-level-bytes

int

r

The number of currently queued bytes

current-level-time

int

r

The amount of currently queued time

duration

int

r/w

The duration of the data stream in nanoseconds (Gst.CLOCK_TIME_NONE if unknown)

emit-signals

bool

r/w

Emit need-data, enough-data and seek-data signals

format

Gst.Format

r/w

The format of the segment events and seek

handle-segment-change

bool

r/w

Whether to detect and handle changed time format Gst.Segment in Gst.Sample. User should set valid Gst.Segment in Gst.Sample. Must set format property as “time” to enable this property

is-live

bool

r/w

Whether to act as a live source

leaky-type

GstApp.AppLeakyType

r/w

Whether to drop buffers once the internal queue is full

max-buffers

int

r/w

The maximum number of buffers to queue internally (0 = unlimited)

max-bytes

int

r/w

The maximum number of bytes to queue internally (0 = unlimited)

max-latency

int

r/w

The maximum latency (-1 = unlimited)

max-time

int

r/w

The maximum amount of time to queue internally (0 = unlimited)

min-latency

int

r/w

The minimum latency (-1 = default)

min-percent

int

r/w

Emit need-data when queued bytes drops below this percent of max-bytes

size

int

r/w

The size of the data stream in bytes (-1 if unknown)

stream-type

GstApp.AppStreamType

r/w

the type of the stream

Signals

Inherited:

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

Name

Short Description

end-of-stream

Notify appsrc that no more buffer are available.

enough-data

Signal that the source has enough data.

need-data

Signal that the source needs more data.

push-buffer

Adds a buffer to the queue of buffers that the appsrc element will push to its source pad.

push-buffer-list

Adds a buffer list to the queue of buffers and buffer lists that the appsrc element will push to its source pad.

push-sample

Extract a buffer from the provided sample and adds the extracted buffer to the queue of buffers that the appsrc element will push to its source pad.

seek-data

Seek to the given offset.

Fields

Inherited:

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

Name

Type

Access

Description

basesrc

GstBase.BaseSrc

r

Class Details

class GstApp.AppSrc(**kwargs)
Bases:

GstBase.BaseSrc, Gst.URIHandler

Abstract:

No

Structure:

GstApp.AppSrcClass

The appsrc element can be used by applications to insert data into a GStreamer pipeline. Unlike most GStreamer elements, appsrc provides external API functions.

appsrc can be used by linking with the libgstapp library to access the methods directly or by using the appsrc action signals.

Before operating appsrc, the caps property must be set to fixed caps describing the format of the data that will be pushed with appsrc. An exception to this is when pushing buffers with unknown caps, in which case no caps should be set. This is typically true of file-like sources that push raw byte buffers. If you don’t want to explicitly set the caps, you can use GstApp.AppSrc.push_sample. This method gets the caps associated with the sample and sets them on the appsrc replacing any previously set caps (if different from sample’s caps).

The main way of handing data to the appsrc element is by calling the GstApp.AppSrc.push_buffer() method or by emitting the push-buffer action signal. This will put the buffer onto a queue from which appsrc will read from in its streaming thread. It is important to note that data transport will not happen from the thread that performed the push-buffer call.

The “max-bytes”, “max-buffers” and “max-time” properties control how much data can be queued in appsrc before appsrc considers the queue full. A filled internal queue will always signal the “enough-data” signal, which signals the application that it should stop pushing data into appsrc. The “block” property will cause appsrc to block the push-buffer method until free data becomes available again.

When the internal queue is running out of data, the “need-data” signal is emitted, which signals the application that it should start pushing more data into appsrc.

In addition to the “need-data” and “enough-data” signals, appsrc can emit the “seek-data” signal when the “stream-mode” property is set to “seekable” or “random-access”. The signal argument will contain the new desired position in the stream expressed in the unit set with the “format” property. After receiving the seek-data signal, the application should push-buffers from the new position.

These signals allow the application to operate the appsrc in two different ways:

The push mode, in which the application repeatedly calls the push-buffer/push-sample method with a new buffer/sample. Optionally, the queue size in the appsrc can be controlled with the enough-data and need-data signals by respectively stopping/starting the push-buffer/push-sample calls. This is a typical mode of operation for the stream-type “stream” and “seekable”. Use this mode when implementing various network protocols or hardware devices.

The pull mode, in which the need-data signal triggers the next push-buffer call. This mode is typically used in the “random-access” stream-type. Use this mode for file access or other randomly accessible sources. In this mode, a buffer of exactly the amount of bytes given by the need-data signal should be pushed into appsrc.

In all modes, the size property on appsrc should contain the total stream size in bytes. Setting this property is mandatory in the random-access mode. For the stream and seekable modes, setting this property is optional but recommended.

When the application has finished pushing data into appsrc, it should call GstApp.AppSrc.end_of_stream() or emit the end-of-stream action signal. After this call, no more buffers can be pushed into appsrc until a flushing seek occurs or the state of the appsrc has gone through READY.

end_of_stream()
Returns:

Gst.FlowReturn.OK when the EOS was successfully queued. Gst.FlowReturn.FLUSHING when self is not PAUSED or PLAYING.

Return type:

Gst.FlowReturn

Indicates to the appsrc element that the last buffer queued in the element is the last buffer of the stream.

get_caps()
Returns:

the Gst.Caps produced by the source. gst_caps_unref() after usage.

Return type:

Gst.Caps or None

Get the configured caps on self.

get_current_level_buffers()
Returns:

The number of currently queued buffers.

Return type:

int

Get the number of currently queued buffers inside self.

New in version 1.20.

get_current_level_bytes()
Returns:

The number of currently queued bytes.

Return type:

int

Get the number of currently queued bytes inside self.

New in version 1.2.

get_current_level_time()
Returns:

The amount of currently queued time.

Return type:

int

Get the amount of currently queued time inside self.

New in version 1.20.

get_duration()
Returns:

the duration of the stream previously set with GstApp.AppSrc.set_duration();

Return type:

int

Get the duration of the stream in nanoseconds. A value of Gst.CLOCK_TIME_NONE means that the duration is not known.

New in version 1.10.

get_emit_signals()
Returns:

True if self is emitting the “new-preroll” and “new-buffer” signals.

Return type:

bool

Check if appsrc will emit the “new-preroll” and “new-buffer” signals.

get_latency()
Returns:

min:

the min latency

max:

the max latency

Return type:

(min: int, max: int)

Retrieve the min and max latencies in min and max respectively.

get_leaky_type()
Returns:

The currently set GstApp.AppLeakyType.

Return type:

GstApp.AppLeakyType

Returns the currently set GstApp.AppLeakyType. See GstApp.AppSrc.set_leaky_type() for more details.

New in version 1.20.

get_max_buffers()
Returns:

The maximum amount of buffers that can be queued.

Return type:

int

Get the maximum amount of buffers that can be queued in self.

New in version 1.20.

get_max_bytes()
Returns:

The maximum amount of bytes that can be queued.

Return type:

int

Get the maximum amount of bytes that can be queued in self.

get_max_time()
Returns:

The maximum amount of time that can be queued.

Return type:

int

Get the maximum amount of time that can be queued in self.

New in version 1.20.

get_size()
Returns:

the size of the stream previously set with GstApp.AppSrc.set_size();

Return type:

int

Get the size of the stream in bytes. A value of -1 means that the size is not known.

get_stream_type()
Returns:

the stream type.

Return type:

GstApp.AppStreamType

Get the stream type. Control the stream type of self with GstApp.AppSrc.set_stream_type().

push_buffer(buffer)
Parameters:

buffer (Gst.Buffer) – a Gst.Buffer to push

Returns:

Gst.FlowReturn.OK when the buffer was successfully queued. Gst.FlowReturn.FLUSHING when self is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occurred.

Return type:

Gst.FlowReturn

Adds a buffer to the queue of buffers that the appsrc element will push to its source pad. This function takes ownership of the buffer.

When the block property is True, this function can block until free space becomes available in the queue.

push_buffer_list(buffer_list)
Parameters:

buffer_list (Gst.BufferList) – a Gst.BufferList to push

Returns:

Gst.FlowReturn.OK when the buffer list was successfully queued. Gst.FlowReturn.FLUSHING when self is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occurred.

Return type:

Gst.FlowReturn

Adds a buffer list to the queue of buffers and buffer lists that the appsrc element will push to its source pad. This function takes ownership of buffer_list.

When the block property is True, this function can block until free space becomes available in the queue.

New in version 1.14.

push_sample(sample)
Parameters:

sample (Gst.Sample) – a Gst.Sample from which buffer and caps may be extracted

Returns:

Gst.FlowReturn.OK when the buffer was successfully queued. Gst.FlowReturn.FLUSHING when self is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occurred.

Return type:

Gst.FlowReturn

Extract a buffer from the provided sample and adds it to the queue of buffers that the appsrc element will push to its source pad. Any previous caps that were set on appsrc will be replaced by the caps associated with the sample if not equal.

This function does not take ownership of the sample so the sample needs to be unreffed after calling this function.

When the block property is True, this function can block until free space becomes available in the queue.

New in version 1.6.

set_caps(caps)
Parameters:

caps (Gst.Caps or None) – caps to set

Set the capabilities on the appsrc element. This function takes a copy of the caps structure. After calling this method, the source will only produce caps that match caps. caps must be fixed and the caps on the buffers must match the caps or left None.

set_duration(duration)
Parameters:

duration (int) – the duration to set

Set the duration of the stream in nanoseconds. A value of Gst.CLOCK_TIME_NONE means that the duration is not known.

New in version 1.10.

set_emit_signals(emit)
Parameters:

emit (bool) – the new state

Make appsrc emit the “new-preroll” and “new-buffer” signals. This option is by default disabled because signal emission is expensive and unneeded when the application prefers to operate in pull mode.

set_latency(min, max)
Parameters:
  • min (int) – the min latency

  • max (int) – the max latency

Configure the min and max latency in src. If min is set to -1, the default latency calculations for pseudo-live sources will be used.

set_leaky_type(leaky)
Parameters:

leaky (GstApp.AppLeakyType) – the GstApp.AppLeakyType

When set to any other value than GstApp.AppLeakyType.NONE then the appsrc will drop any buffers that are pushed into it once its internal queue is full. The selected type defines whether to drop the oldest or new buffers.

New in version 1.20.

set_max_buffers(max)
Parameters:

max (int) – the maximum number of buffers to queue

Set the maximum amount of buffers that can be queued in self. After the maximum amount of buffers are queued, self will emit the “enough-data” signal.

New in version 1.20.

set_max_bytes(max)
Parameters:

max (int) – the maximum number of bytes to queue

Set the maximum amount of bytes that can be queued in self. After the maximum amount of bytes are queued, self will emit the “enough-data” signal.

set_max_time(max)
Parameters:

max (int) – the maximum amonut of time to queue

Set the maximum amount of time that can be queued in self. After the maximum amount of time are queued, self will emit the “enough-data” signal.

New in version 1.20.

set_size(size)
Parameters:

size (int) – the size to set

Set the size of the stream in bytes. A value of -1 means that the size is not known.

set_stream_type(type)
Parameters:

type (GstApp.AppStreamType) – the new state

Set the stream type on self. For seekable streams, the “seek” signal must be connected to.

A stream_type stream

do_end_of_stream() virtual
Returns:

Gst.FlowReturn.OK when the EOS was successfully queued. Gst.FlowReturn.FLUSHING when appsrc is not PAUSED or PLAYING.

Return type:

Gst.FlowReturn

Indicates to the appsrc element that the last buffer queued in the element is the last buffer of the stream.

do_enough_data() virtual
do_need_data(length) virtual
Parameters:

length (int) –

do_push_buffer(buffer) virtual
Parameters:

buffer (Gst.Buffer) – a Gst.Buffer to push

Returns:

Gst.FlowReturn.OK when the buffer was successfully queued. Gst.FlowReturn.FLUSHING when appsrc is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occurred.

Return type:

Gst.FlowReturn

Adds a buffer to the queue of buffers that the appsrc element will push to its source pad. This function takes ownership of the buffer.

When the block property is True, this function can block until free space becomes available in the queue.

do_push_buffer_list(buffer_list) virtual
Parameters:

buffer_list (Gst.BufferList) – a Gst.BufferList to push

Returns:

Gst.FlowReturn.OK when the buffer list was successfully queued. Gst.FlowReturn.FLUSHING when appsrc is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occurred.

Return type:

Gst.FlowReturn

Adds a buffer list to the queue of buffers and buffer lists that the appsrc element will push to its source pad. This function takes ownership of buffer_list.

When the block property is True, this function can block until free space becomes available in the queue.

New in version 1.14.

do_push_sample(sample) virtual
Parameters:

sample (Gst.Sample) – a Gst.Sample from which buffer and caps may be extracted

Returns:

Gst.FlowReturn.OK when the buffer was successfully queued. Gst.FlowReturn.FLUSHING when appsrc is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occurred.

Return type:

Gst.FlowReturn

Extract a buffer from the provided sample and adds it to the queue of buffers that the appsrc element will push to its source pad. Any previous caps that were set on appsrc will be replaced by the caps associated with the sample if not equal.

This function does not take ownership of the sample so the sample needs to be unreffed after calling this function.

When the block property is True, this function can block until free space becomes available in the queue.

New in version 1.6.

do_seek_data(offset) virtual
Parameters:

offset (int) –

Return type:

bool

Signal Details

GstApp.AppSrc.signals.end_of_stream(app_src)
Signal Name:

end-of-stream

Flags:

RUN_LAST, ACTION

Parameters:

app_src (GstApp.AppSrc) – The object which received the signal

Return type:

Gst.FlowReturn

Notify appsrc that no more buffer are available.

GstApp.AppSrc.signals.enough_data(app_src)
Signal Name:

enough-data

Flags:

RUN_LAST

Parameters:

app_src (GstApp.AppSrc) – The object which received the signal

Signal that the source has enough data. It is recommended that the application stops calling push-buffer until the need-data signal is emitted again to avoid excessive buffer queueing.

GstApp.AppSrc.signals.need_data(app_src, length)
Signal Name:

need-data

Flags:

RUN_LAST

Parameters:
  • app_src (GstApp.AppSrc) – The object which received the signal

  • length (int) – the amount of bytes needed.

Signal that the source needs more data. In the callback or from another thread you should call push-buffer or end-of-stream.

length is just a hint and when it is set to -1, any number of bytes can be pushed into appsrc.

You can call push-buffer multiple times until the enough-data signal is fired.

GstApp.AppSrc.signals.push_buffer(app_src, buffer)
Signal Name:

push-buffer

Flags:

RUN_LAST, ACTION

Parameters:
Return type:

Gst.FlowReturn

Adds a buffer to the queue of buffers that the appsrc element will push to its source pad.

This function does not take ownership of the buffer, but it takes a reference so the buffer can be unreffed at any time after calling this function.

When the block property is True, this function can block until free space becomes available in the queue.

GstApp.AppSrc.signals.push_buffer_list(app_src, buffer_list)
Signal Name:

push-buffer-list

Flags:

RUN_LAST, ACTION

Parameters:
Return type:

Gst.FlowReturn

Adds a buffer list to the queue of buffers and buffer lists that the appsrc element will push to its source pad.

This function does not take ownership of the buffer list, but it takes a reference so the buffer list can be unreffed at any time after calling this function.

When the block property is True, this function can block until free space becomes available in the queue.

New in version 1.14.

GstApp.AppSrc.signals.push_sample(app_src, sample)
Signal Name:

push-sample

Flags:

RUN_LAST, ACTION

Parameters:
  • app_src (GstApp.AppSrc) – The object which received the signal

  • sample (Gst.Sample) – a sample from which extract buffer to push

Return type:

Gst.FlowReturn

Extract a buffer from the provided sample and adds the extracted buffer to the queue of buffers that the appsrc element will push to its source pad. This function set the appsrc caps based on the caps in the sample and reset the caps if they change. Only the caps and the buffer of the provided sample are used and not for example the segment in the sample.

This function does not take ownership of the sample, but it takes a reference so the sample can be unreffed at any time after calling this function.

When the block property is True, this function can block until free space becomes available in the queue.

New in version 1.6.

GstApp.AppSrc.signals.seek_data(app_src, offset)
Signal Name:

seek-data

Flags:

RUN_LAST

Parameters:
  • app_src (GstApp.AppSrc) – The object which received the signal

  • offset (int) – the offset to seek to

Returns:

True if the seek succeeded.

Return type:

bool

Seek to the given offset. The next push-buffer should produce buffers from the new offset. This callback is only called for seekable stream types.

Property Details

GstApp.AppSrc.props.block
Name:

block

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

When max-bytes are queued and after the enough-data signal has been emitted, block any further push-buffer calls until the amount of queued bytes drops below the max-bytes limit.

GstApp.AppSrc.props.caps
Name:

caps

Type:

Gst.Caps

Default Value:

None

Flags:

READABLE, WRITABLE

The Gst.Caps that will negotiated downstream and will be put on outgoing buffers.

GstApp.AppSrc.props.current_level_buffers
Name:

current-level-buffers

Type:

int

Default Value:

0

Flags:

READABLE

The number of currently queued buffers inside appsrc.

New in version 1.20.

GstApp.AppSrc.props.current_level_bytes
Name:

current-level-bytes

Type:

int

Default Value:

0

Flags:

READABLE

The number of currently queued bytes inside appsrc.

New in version 1.2.

GstApp.AppSrc.props.current_level_time
Name:

current-level-time

Type:

int

Default Value:

0

Flags:

READABLE

The amount of currently queued time inside appsrc.

New in version 1.20.

GstApp.AppSrc.props.duration
Name:

duration

Type:

int

Default Value:

18446744073709551615

Flags:

READABLE, WRITABLE

The total duration in nanoseconds of the data stream. If the total duration is known, it is recommended to configure it with this property.

New in version 1.10.

GstApp.AppSrc.props.emit_signals
Name:

emit-signals

Type:

bool

Default Value:

True

Flags:

READABLE, WRITABLE

Make appsrc emit the “need-data”, “enough-data” and “seek-data” signals. This option is by default enabled for backwards compatibility reasons but can disabled when needed because signal emission is expensive.

GstApp.AppSrc.props.format
Name:

format

Type:

Gst.Format

Default Value:

Gst.Format.BYTES

Flags:

READABLE, WRITABLE

The format to use for segment events. When the source is producing timestamped buffers this property should be set to Gst.Format.TIME.

GstApp.AppSrc.props.handle_segment_change
Name:

handle-segment-change

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

When enabled, appsrc will check Gst.Segment in Gst.Sample which was pushed via GstApp.AppSrc.push_sample() or “push-sample” signal action. If a Gst.Segment is changed, corresponding segment event will be followed by next data flow.

FIXME: currently only Gst.Format.TIME format is supported and therefore GstApp.AppSrc ::format should be time. However, possibly GstApp.AppSrc can support other formats.

New in version 1.18.

GstApp.AppSrc.props.is_live
Name:

is-live

Type:

bool

Default Value:

False

Flags:

READABLE, WRITABLE

Instruct the source to behave like a live source. This includes that it will only push out buffers in the PLAYING state.

GstApp.AppSrc.props.leaky_type
Name:

leaky-type

Type:

GstApp.AppLeakyType

Default Value:

GstApp.AppLeakyType.NONE

Flags:

READABLE, WRITABLE

When set to any other value than GstApp.AppLeakyType.NONE then the appsrc will drop any buffers that are pushed into it once its internal queue is full. The selected type defines whether to drop the oldest or new buffers.

New in version 1.20.

GstApp.AppSrc.props.max_buffers
Name:

max-buffers

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

The maximum amount of buffers that can be queued internally. After the maximum amount of buffers are queued, appsrc will emit the “enough-data” signal.

New in version 1.20.

GstApp.AppSrc.props.max_bytes
Name:

max-bytes

Type:

int

Default Value:

200000

Flags:

READABLE, WRITABLE

The maximum amount of bytes that can be queued internally. After the maximum amount of bytes are queued, appsrc will emit the “enough-data” signal.

GstApp.AppSrc.props.max_latency
Name:

max-latency

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE

The maximum latency (-1 = unlimited)

GstApp.AppSrc.props.max_time
Name:

max-time

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

The maximum amount of time that can be queued internally. After the maximum amount of time are queued, appsrc will emit the “enough-data” signal.

New in version 1.20.

GstApp.AppSrc.props.min_latency
Name:

min-latency

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE

The minimum latency of the source. A value of -1 will use the default latency calculations of GstBase.BaseSrc.

GstApp.AppSrc.props.min_percent
Name:

min-percent

Type:

int

Default Value:

0

Flags:

READABLE, WRITABLE

Make appsrc emit the “need-data” signal when the amount of bytes in the queue drops below this percentage of max-bytes.

GstApp.AppSrc.props.size
Name:

size

Type:

int

Default Value:

-1

Flags:

READABLE, WRITABLE

The total size in bytes of the data stream. If the total size is known, it is recommended to configure it with this property.

GstApp.AppSrc.props.stream_type
Name:

stream-type

Type:

GstApp.AppStreamType

Default Value:

GstApp.AppStreamType.STREAM

Flags:

READABLE, WRITABLE

The type of stream that this source is producing. For seekable streams the application should connect to the seek-data signal.