AppSrc

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 gst_app_src_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.app_src.AppSrc.pushBuffer 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.app_src.AppSrc.endOfStream 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.

Members

Functions

connectEndOfStream
ulong connectEndOfStream(T callback, Flag!"After" after)

Connect to EndOfStream signal.

connectEnoughData
ulong connectEnoughData(T callback, Flag!"After" after)

Connect to EnoughData signal.

connectNeedData
ulong connectNeedData(T callback, Flag!"After" after)

Connect to NeedData signal.

connectPushBuffer
ulong connectPushBuffer(T callback, Flag!"After" after)

Connect to PushBuffer signal.

connectPushBufferList
ulong connectPushBufferList(T callback, Flag!"After" after)

Connect to PushBufferList signal.

connectPushSample
ulong connectPushSample(T callback, Flag!"After" after)

Connect to PushSample signal.

connectSeekData
ulong connectSeekData(T callback, Flag!"After" after)

Connect to SeekData signal.

endOfStream
gst.types.FlowReturn endOfStream()

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

getCaps
gst.caps.Caps getCaps()

Get the configured caps on appsrc.

getCurrentLevelBuffers
ulong getCurrentLevelBuffers()

Get the number of currently queued buffers inside appsrc.

getCurrentLevelBytes
ulong getCurrentLevelBytes()

Get the number of currently queued bytes inside appsrc.

getCurrentLevelTime
gst.types.ClockTime getCurrentLevelTime()

Get the amount of currently queued time inside appsrc.

getDuration
gst.types.ClockTime getDuration()

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

getEmitSignals
bool getEmitSignals()

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

getLatency
void getLatency(ulong min, ulong max)

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

getLeakyType
gstapp.types.AppLeakyType getLeakyType()

Returns the currently set #GstAppLeakyType. See gstapp.app_src.AppSrc.setLeakyType for more details.

getMaxBuffers
ulong getMaxBuffers()

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

getMaxBytes
ulong getMaxBytes()

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

getMaxTime
gst.types.ClockTime getMaxTime()

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

getSize
long getSize()

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

getStreamType
gstapp.types.AppStreamType getStreamType()

Get the stream type. Control the stream type of appsrc with gstapp.app_src.AppSrc.setStreamType.

pushBuffer
gst.types.FlowReturn pushBuffer(gst.buffer.Buffer buffer)

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.

pushBufferList
gst.types.FlowReturn pushBufferList(gst.buffer_list.BufferList bufferList)

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.

pushSample
gst.types.FlowReturn pushSample(gst.sample.Sample sample)

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.

setCaps
void setCaps(gst.caps.Caps caps)

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 NULL.

setDuration
void setDuration(gst.types.ClockTime duration)

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

setEmitSignals
void setEmitSignals(bool emit)

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.

setLatency
void setLatency(ulong min, ulong max)

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.

setLeakyType
void setLeakyType(gstapp.types.AppLeakyType leaky)

When set to any other value than GST_APP_LEAKY_TYPE_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.

setMaxBuffers
void setMaxBuffers(ulong max)

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

setMaxBytes
void setMaxBytes(ulong max)

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

setMaxTime
void setMaxTime(gst.types.ClockTime max)

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

setSize
void setSize(long size)

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

setStreamType
void setStreamType(gstapp.types.AppStreamType type)

Set the stream type on appsrc. For seekable streams, the "seek" signal must be connected to.

Mixed In Members

From mixin URIHandlerT!()

getProtocols
string[] getProtocols()

Gets the list of protocols supported by handler. This list may not be modified.

getUri
string getUri()

Gets the currently handled URI.

getUriType
gst.types.URIType getUriType()

Gets the type of the given URI handler

setUri
bool setUri(string uri)

Tries to set the URI of the given handler.

Inherited Members

From BaseSrc

getAllocator
void getAllocator(gst.allocator.Allocator allocator, gst.allocation_params.AllocationParams params)

Lets #GstBaseSrc sub-classes to know the memory allocator used by the base class and its params.

getBlocksize
uint getBlocksize()

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

getBufferPool
gst.buffer_pool.BufferPool getBufferPool()
getDoTimestamp
bool getDoTimestamp()

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

isAsync
bool isAsync()

Get the current async behaviour of src. See also gstbase.base_src.BaseSrc.setAsync.

isLive
bool isLive()

Check if an element is in live mode.

negotiate
bool negotiate()

Negotiates src pad caps with downstream elements. Unmarks GST_PAD_FLAG_NEED_RECONFIGURE in any case. But marks it again if #GstBaseSrcClass::negotiate fails.

newSeamlessSegment
bool newSeamlessSegment(long start, long stop, long time)

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.

newSegment
bool newSegment(gst.segment.Segment segment)

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.

pushSegment
bool pushSegment(gst.segment.Segment segment)

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.base_src.BaseSrc.setCaps needs to have been called before.

queryLatency
bool queryLatency(bool live, gst.types.ClockTime minLatency, gst.types.ClockTime maxLatency)

Query the source for the latency parameters. live will be true when src 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.

setAsync
void setAsync(bool async)

Configure async behaviour in src, 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.

setAutomaticEos
void setAutomaticEos(bool automaticEos)

If automatic_eos is true, src 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.

setBlocksize
void setBlocksize(uint blocksize)

Set the number of bytes that src will push out with each buffer. When blocksize is set to -1, a default length will be used.

setCaps
bool setCaps(gst.caps.Caps caps)

Set new caps on the basesrc source pad.

setDoTimestamp
void setDoTimestamp(bool timestamp)

Configure src to automatically timestamp outgoing buffers based on the current running_time of the pipeline. This property is mostly useful for live sources.

setDynamicSize
void setDynamicSize(bool dynamic)

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.

setFormat
void setFormat(gst.types.Format format)

Sets the default format of the source. This will be the format used for sending SEGMENT events and for performing seeks.

setLive
void setLive(bool live)

If the element listens to a live source, live should be set to true.

startComplete
void startComplete(gst.types.FlowReturn ret)

Complete an asynchronous start operation. When the subclass overrides the start method, it should call gstbase.base_src.BaseSrc.startComplete when the start operation completes either from the same thread or from an asynchronous helper thread.

startWait
gst.types.FlowReturn startWait()

Wait until the start operation completes.

submitBufferList
void submitBufferList(gst.buffer_list.BufferList 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 #GstBufferList, 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).

waitPlaying
gst.types.FlowReturn waitPlaying()

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.

From URIHandler

getProtocols
string[] getProtocols()

Gets the list of protocols supported by handler. This list may not be modified.

getUri
string getUri()

Gets the currently handled URI.

getUriType
gst.types.URIType getUriType()

Gets the type of the given URI handler

setUri
bool setUri(string uri)

Tries to set the URI of the given handler.