AppSink

Appsink is a sink plugin that supports many different methods for making the application get a handle on the GStreamer data in a pipeline. Unlike most GStreamer elements, Appsink provides external API functions.

appsink can be used by linking to the gstappsink.h header file to access the methods or by using the appsink action signals and properties.

The normal way of retrieving samples from appsink is by using the AppSink.pullSample and AppSink.pullPreroll methods. These methods block until a sample becomes available in the sink or when the sink is shut down or reaches EOS. There are also timed variants of these methods, AppSink.tryPullSample and AppSink.tryPullPreroll, which accept a timeout parameter to limit the amount of time to wait.

Appsink will internally use a queue to collect buffers from the streaming thread. If the application is not pulling samples fast enough, this queue will consume a lot of memory over time. The "max-buffers" property can be used to limit the queue size. The "drop" property controls whether the streaming thread blocks or if older buffers are dropped when the maximum queue size is reached. Note that blocking the streaming thread can negatively affect real-time performance and should be avoided.

If a blocking behaviour is not desirable, setting the "emit-signals" property to TRUE will make appsink emit the "new-sample" and "new-preroll" signals when a sample can be pulled without blocking.

The "caps" property on appsink can be used to control the formats that appsink can receive. This property can contain non-fixed caps, the format of the pulled samples can be obtained by getting the sample caps.

If one of the pull-preroll or pull-sample methods return NULL, the appsink is stopped or in the EOS state. You can check for the EOS state with the "eos" property or with the AppSink.isEos method.

The eos signal can also be used to be informed when the EOS state is reached to avoid polling.

Constructors

this
this(GstAppSink* gstAppSink, bool ownedRef)

Sets our main struct and passes it to the parent class.

Members

Functions

addOnEos
gulong addOnEos(void delegate(AppSink) dlg, ConnectFlags connectFlags)

Signal that the end-of-stream has been reached. This signal is emitted from the streaming thread.

addOnNewPreroll
gulong addOnNewPreroll(GstFlowReturn delegate(AppSink) dlg, ConnectFlags connectFlags)

Signal that a new preroll sample is available.

addOnNewSample
gulong addOnNewSample(GstFlowReturn delegate(AppSink) dlg, ConnectFlags connectFlags)

Signal that a new sample is available.

addOnPullPreroll
gulong addOnPullPreroll(Sample delegate(AppSink) dlg, ConnectFlags connectFlags)

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state.

addOnPullSample
gulong addOnPullSample(Sample delegate(AppSink) dlg, ConnectFlags connectFlags)

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/NULL state.

addOnTryPullPreroll
gulong addOnTryPullPreroll(Sample delegate(ulong, AppSink) dlg, ConnectFlags connectFlags)

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state.

addOnTryPullSample
gulong addOnTryPullSample(Sample delegate(ulong, AppSink) dlg, ConnectFlags connectFlags)

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/NULL state or the timeout expires.

getAppSinkStruct
GstAppSink* getAppSinkStruct(bool transferOwnership)

Get the main Gtk struct

getBufferListSupport
bool getBufferListSupport()

Check if appsink supports buffer lists.

getCaps
Caps getCaps()

Get the configured caps on appsink.

getDrop
bool getDrop()

Check if appsink will drop old buffers when the maximum amount of queued buffers is reached.

getEmitSignals
bool getEmitSignals()

Check if appsink will emit the "new-preroll" and "new-sample" signals.

getMaxBuffers
uint getMaxBuffers()

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

getStruct
void* getStruct()

the main Gtk struct as a void*

getWaitOnEos
bool getWaitOnEos()

Check if appsink will wait for all buffers to be consumed when an EOS is received.

isEos
bool isEos()

Check if appsink is EOS, which is when no more samples can be pulled because an EOS event was received.

pullPreroll
Sample pullPreroll()

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state.

pullSample
Sample pullSample()

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/NULL state.

setBufferListSupport
void setBufferListSupport(bool enableLists)

Instruct appsink to enable or disable buffer list support.

setCallbacks
void setCallbacks(GstAppSinkCallbacks* callbacks, void* userData, GDestroyNotify notify)

Set callbacks which will be executed for each new preroll, new sample and eos. This is an alternative to using the signals, it has lower overhead and is thus less expensive, but also less flexible.

setCaps
void setCaps(Caps caps)

Set the capabilities on the appsink element. This function takes a copy of the caps structure. After calling this method, the sink will only accept caps that match caps. If caps is non-fixed, or incomplete, you must check the caps on the samples to get the actual used caps.

setDrop
void setDrop(bool drop)

Instruct appsink to drop old buffers when the maximum amount of queued buffers is reached.

setEmitSignals
void setEmitSignals(bool emit)

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

setMaxBuffers
void setMaxBuffers(uint max)

Set the maximum amount of buffers that can be queued in appsink. After this amount of buffers are queued in appsink, any more buffers will block upstream elements until a sample is pulled from appsink.

setWaitOnEos
void setWaitOnEos(bool wait)

Instruct appsink to wait for all buffers to be consumed when an EOS is received.

tryPullPreroll
Sample tryPullPreroll(GstClockTime timeout)

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state.

tryPullSample
Sample tryPullSample(GstClockTime timeout)

This function blocks until a sample or EOS becomes available or the appsink element is set to the READY/NULL state or the timeout expires.

Static functions

getType
GType getType()

Variables

gstAppSink
GstAppSink* gstAppSink;

the main Gtk struct

Inherited Members

From BaseSink

gstBaseSink
GstBaseSink* gstBaseSink;

the main Gtk struct

getBaseSinkStruct
GstBaseSink* getBaseSinkStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
doPreroll
GstFlowReturn doPreroll(MiniObject obj)

If the sink spawns its own thread for pulling buffers from upstream it should call this method after it has pulled a buffer. If the element needed to preroll, this function will perform the preroll and will then block until the element state is changed.

getBlocksize
uint getBlocksize()

Get the number of bytes that the sink will pull when it is operating in pull mode.

getDropOutOfSegment
bool getDropOutOfSegment()

Checks if sink is currently configured to drop buffers which are outside the current segment

getLastSample
Sample getLastSample()

Get the last sample that arrived in the sink and was used for preroll or for rendering. This property can be used to generate thumbnails.

getLatency
GstClockTime getLatency()

Get the currently configured latency.

getMaxBitrate
ulong getMaxBitrate()

Get the maximum amount of bits per second that the sink will render.

getMaxLateness
long getMaxLateness()

Gets the max lateness value. See BaseSink.setMaxLateness for more details.

getProcessingDeadline
GstClockTime getProcessingDeadline()

Get the processing deadline of sink. see BaseSink.setProcessingDeadline for more information about the processing deadline.

getRenderDelay
GstClockTime getRenderDelay()

Get the render delay of sink. see BaseSink.setRenderDelay for more information about the render delay.

getSync
bool getSync()

Checks if sink is currently configured to synchronize against the clock.

getThrottleTime
ulong getThrottleTime()

Get the time that will be inserted between frames to control the maximum buffers per second.

getTsOffset
GstClockTimeDiff getTsOffset()

Get the synchronisation offset of sink.

isAsyncEnabled
bool isAsyncEnabled()

Checks if sink is currently configured to perform asynchronous state changes to PAUSED.

isLastSampleEnabled
bool isLastSampleEnabled()

Checks if sink is currently configured to store the last received sample in the last-sample property.

isQosEnabled
bool isQosEnabled()

Checks if sink is currently configured to send Quality-of-Service events upstream.

queryLatency
bool queryLatency(bool live, bool upstreamLive, GstClockTime minLatency, GstClockTime maxLatency)

Query the sink for the latency parameters. The latency will be queried from the upstream elements. live will be TRUE if sink is configured to synchronize against the clock. upstream_live will be TRUE if an upstream element is live.

setAsyncEnabled
void setAsyncEnabled(bool enabled)

Configures sink to perform all state changes asynchronously. When async is disabled, the sink will immediately go to PAUSED instead of waiting for a preroll buffer. This feature is useful if the sink does not synchronize against the clock or when it is dealing with sparse streams.

setBlocksize
void setBlocksize(uint blocksize)

Set the number of bytes that the sink will pull when it is operating in pull mode.

setDropOutOfSegment
void setDropOutOfSegment(bool dropOutOfSegment)

Configure sink to drop buffers which are outside the current segment

setLastSampleEnabled
void setLastSampleEnabled(bool enabled)

Configures sink to store the last received sample in the last-sample property.

setMaxBitrate
void setMaxBitrate(ulong maxBitrate)

Set the maximum amount of bits per second that the sink will render.

setMaxLateness
void setMaxLateness(long maxLateness)

Sets the new max lateness value to max_lateness. This value is used to decide if a buffer should be dropped or not based on the buffer timestamp and the current clock time. A value of -1 means an unlimited time.

setProcessingDeadline
void setProcessingDeadline(GstClockTime processingDeadline)

Maximum amount of time (in nanoseconds) that the pipeline can take for processing the buffer. This is added to the latency of live pipelines.

setQosEnabled
void setQosEnabled(bool enabled)

Configures sink to send Quality-of-Service events upstream.

setRenderDelay
void setRenderDelay(GstClockTime delay)

Set the render delay in sink to delay. The render delay is the time between actual rendering of a buffer and its synchronisation time. Some devices might delay media rendering which can be compensated for with this function.

setSync
void setSync(bool sync)

Configures sink to synchronize on the clock or not. When sync is FALSE, incoming samples will be played as fast as possible. If sync is TRUE, the timestamps of the incoming buffers will be used to schedule the exact render time of its contents.

setThrottleTime
void setThrottleTime(ulong throttle)

Set the time that will be inserted between rendered buffers. This can be used to control the maximum buffers per second that the sink will render.

setTsOffset
void setTsOffset(GstClockTimeDiff offset)

Adjust the synchronisation of sink with offset. A negative value will render buffers earlier than their timestamp. A positive value will delay rendering. This function can be used to fix playback of badly timestamped buffers.

wait
GstFlowReturn wait(GstClockTime time, GstClockTimeDiff jitter)

This function will wait for preroll to complete and will then block until time is reached. It is usually called by subclasses that use their own internal synchronisation but want to let some synchronization (like EOS) be handled by the base class.

waitClock
GstClockReturn waitClock(GstClockTime time, GstClockTimeDiff jitter)

This function will block until time is reached. It is usually called by subclasses that use their own internal synchronisation.

waitPreroll
GstFlowReturn waitPreroll()

If the GstBaseSinkClas.render|GstBaseSinkClas.renders 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 render the remaining data.

From URIHandlerIF

getURIHandlerStruct
GstURIHandler* getURIHandlerStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
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
GstURIType getUriType()

Gets the type of the given URI handler

setUri
bool setUri(string uri)

Tries to set the URI of the given handler.