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

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-bytes int r The number of currently queued bytes
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
is-live bool r/w Whether to act as a live source
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)
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” property controls 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 accessable 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()[source]
Returns:Gst.FlowReturn.OK when the EOS was successfuly 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()[source]
Returns:the Gst.Caps produced by the source. gst_caps_unref() after usage.
Return type:Gst.Caps

Get the configured caps on self.

get_current_level_bytes()[source]
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_duration()[source]
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()[source]
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()[source]
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_max_bytes()[source]
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_size()[source]
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()[source]
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)[source]
Parameters:buffer (Gst.Buffer) – a Gst.Buffer to push
Returns:Gst.FlowReturn.OK when the buffer was successfuly queued. Gst.FlowReturn.FLUSHING when self is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occured.
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)[source]
Parameters:buffer_list (Gst.BufferList) – a Gst.BufferList to push
Returns:Gst.FlowReturn.OK when the buffer list was successfuly queued. Gst.FlowReturn.FLUSHING when self is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occured.
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)[source]
Parameters:sample (Gst.Sample) – a Gst.Sample from which buffer and caps may be extracted
Returns:Gst.FlowReturn.OK when the buffer was successfuly queued. Gst.FlowReturn.FLUSHING when self is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occured.
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)[source]
Parameters:caps (Gst.Caps) – 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)[source]
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)[source]
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)[source]
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_max_bytes(max)[source]
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_size(size)[source]
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)[source]
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 successfuly 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 successfuly queued. Gst.FlowReturn.FLUSHING when appsrc is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occured.
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 successfuly queued. Gst.FlowReturn.FLUSHING when appsrc is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occured.
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 successfuly queued. Gst.FlowReturn.FLUSHING when appsrc is not PAUSED or PLAYING. Gst.FlowReturn.EOS when EOS occured.
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 so the buffer 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.

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 so the buffer list 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.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 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.

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

Block push-buffer when max-bytes are queued

GstApp.AppSrc.props.caps
Name:caps
Type:Gst.Caps
Default Value:None
Flags:READABLE, WRITABLE

The allowed caps for the src pad

GstApp.AppSrc.props.current_level_bytes
Name:current-level-bytes
Type:int
Default Value:0
Flags:READABLE

The number of currently queued bytes

GstApp.AppSrc.props.duration
Name:duration
Type:int
Default Value:18446744073709551615
Flags:READABLE, WRITABLE

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

GstApp.AppSrc.props.emit_signals
Name:emit-signals
Type:bool
Default Value:True
Flags:READABLE, WRITABLE

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

GstApp.AppSrc.props.format
Name:format
Type:Gst.Format
Default Value:Gst.Format.BYTES
Flags:READABLE, WRITABLE

The format of the segment events and seek

GstApp.AppSrc.props.is_live
Name:is-live
Type:bool
Default Value:False
Flags:READABLE, WRITABLE

Whether to act as a live source

GstApp.AppSrc.props.max_bytes
Name:max-bytes
Type:int
Default Value:200000
Flags:READABLE, WRITABLE

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

GstApp.AppSrc.props.max_latency
Name:max-latency
Type:int
Default Value:-1
Flags:READABLE, WRITABLE

The maximum latency (-1 = unlimited)

GstApp.AppSrc.props.min_latency
Name:min-latency
Type:int
Default Value:-1
Flags:READABLE, WRITABLE

The minimum latency (-1 = default)

GstApp.AppSrc.props.min_percent
Name:min-percent
Type:int
Default Value:0
Flags:READABLE, WRITABLE

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

GstApp.AppSrc.props.size
Name:size
Type:int
Default Value:-1
Flags:READABLE, WRITABLE

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

GstApp.AppSrc.props.stream_type
Name:stream-type
Type:GstApp.AppStreamType
Default Value:GstApp.AppStreamType.STREAM
Flags:READABLE, WRITABLE

the type of the stream