GstApp.AppSrc¶
Subclasses: | None |
---|
Methods¶
Inherited: | GstBase.BaseSrc (22), Gst.Element (79), Gst.Object (27), GObject.Object (37), Gst.URIHandler (4) |
---|---|
Structs: | Gst.ElementClass (10), GObject.ObjectClass (5) |
end_of_stream () |
|
get_caps () |
|
get_current_level_bytes () |
|
get_duration () |
|
get_emit_signals () |
|
get_latency () |
|
get_max_bytes () |
|
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_max_bytes (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-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 |
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 |
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 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
()[source]¶ 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
()[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
) – aGst.Buffer
to pushReturns: 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)[source]¶ Parameters: buffer_list ( Gst.BufferList
) – aGst.BufferList
to pushReturns: 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)[source]¶ Parameters: sample ( Gst.Sample
) – aGst.Sample
from which buffer and caps may be extractedReturns: 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)[source]¶ Parameters: caps ( Gst.Caps
orNone
) – caps to setSet 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 setSet 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 stateMake 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: 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 queueSet 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 setSet 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 stateSet 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_push_buffer
(buffer) virtual¶ Parameters: buffer ( Gst.Buffer
) – aGst.Buffer
to pushReturns: 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
) – aGst.BufferList
to pushReturns: 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
) – aGst.Sample
from which buffer and caps may be extractedReturns: 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.
-
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 signalReturn 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 signalSignal 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: 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.
- app_src (
-
GstApp.AppSrc.signals.
push_buffer
(app_src, buffer)¶ Signal Name: push-buffer
Flags: Parameters: - app_src (
GstApp.AppSrc
) – The object which received the signal - buffer (
Gst.Buffer
) – a buffer to push
Return type: 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.- app_src (
-
GstApp.AppSrc.signals.
push_buffer_list
(app_src, buffer_list)¶ Signal Name: push-buffer-list
Flags: Parameters: - app_src (
GstApp.AppSrc
) – The object which received the signal - buffer_list (
Gst.BufferList
) – a buffer list to push
Return type: 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.
- app_src (
-
GstApp.AppSrc.signals.
push_sample
(app_src, sample)¶ Signal Name: push-sample
Flags: Parameters: - app_src (
GstApp.AppSrc
) – The object which received the signal - sample (
Gst.Sample
) – a sample from which extract buffer to push
Return type: 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.
- app_src (
-
GstApp.AppSrc.signals.
seek_data
(app_src, offset)¶ Signal Name: seek-data
Flags: 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: 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.
- app_src (
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_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.
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
inGst.Sample
which was pushed viaGstApp.AppSrc.push_sample
() or “push-sample” signal action. If aGst.Segment
is changed, corresponding segment event will be followed by next data flow.FIXME: currently only
Gst.Format.TIME
format is supported and thereforeGstApp.AppSrc
::format
should be time. However, possiblyGstApp.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.
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.
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.