QtGStreamer  1.2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
Public Member Functions | Protected Member Functions | List of all members
QGst::Utils::ApplicationSink Class Reference

#include <QGst/Utils/ApplicationSink>

Public Member Functions

ElementPtr element () const
 
void setElement (const ElementPtr &appsink)
 
CapsPtr caps () const
 
void setCaps (const CapsPtr &caps)
 
bool isEos () const
 
uint maxBuffers () const
 
void setMaxBuffers (uint maxbuffers)
 
bool dropEnabled () const
 
void enableDrop (bool enable)
 
SamplePtr pullPreroll ()
 
SamplePtr pullSample ()
 
BufferListPtr pullBufferList ()
 

Protected Member Functions

virtual void eos ()
 
virtual FlowReturn newPreroll ()
 
virtual FlowReturn newSample ()
 

Detailed Description

Helper class for using a GstAppSink.

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. This class exports those API functions in the bindings and makes it easy to implement a custom sink.

The normal way of retrieving sample from appsink is by using the pullSample() and pullPreroll() methods. These methods block until a sample becomes available in the sink or when the sink is shut down or reaches EOS.

Appsink will internally use a queue to collect samples from the streaming thread. If the application is not pulling samples fast enough, this queue will consume a lot of memory over time. setMaxBuffers() can be used to limit the queue size. enableDrop() controls whether the streaming thread blocks or if older samples 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, you can subclass this class and implement the newPreroll(), newSample() and newBufferList() which will be called to notify you when a new sample is available.

setCaps() 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 pullPreroll() or pullSample() methods return NULL, the appsink is stopped or in the EOS state. You can check for the EOS state with isEos(). The eos() virtual method can also be reimplemented to be informed when the EOS state is reached to avoid polling.

The actuall appsink element can be retrieved with element() and set with setElement(). It is not necessary to set an appsink, as this class will create one as soon as it is needed.

Note
It is not necessary to use this class in order to use GstAppSink. GstAppSink also provides signals and properties that fully substitute the functionality of this class.
See also
ApplicationSource
Examples:
examples/appsink-src/main.cpp.

Definition at line 66 of file applicationsink.h.

Member Function Documentation

ElementPtr QGst::Utils::ApplicationSink::element ( ) const
Returns
the appsink element

Definition at line 107 of file applicationsink.cpp.

void QGst::Utils::ApplicationSink::setElement ( const ElementPtr appsink)

Sets the appsink element that will be used by this class

Definition at line 113 of file applicationsink.cpp.

CapsPtr QGst::Utils::ApplicationSink::caps ( ) const
Returns
the caps that the appsink is configured to accept

Definition at line 121 of file applicationsink.cpp.

void QGst::Utils::ApplicationSink::setCaps ( const CapsPtr caps)

Sets the caps that appsink will accept

Definition at line 130 of file applicationsink.cpp.

bool QGst::Utils::ApplicationSink::isEos ( ) const
Returns
true if the appsink has received an End Of Stream event or if it is not in PAUSED or PLAYING state.

Definition at line 138 of file applicationsink.cpp.

uint QGst::Utils::ApplicationSink::maxBuffers ( ) const
Returns
the maximum number of buffers that the sink is configured to hold in its internal queue. 0 means unlimited.

Definition at line 143 of file applicationsink.cpp.

void QGst::Utils::ApplicationSink::setMaxBuffers ( uint  maxbuffers)

Sets the maximum number of buffers that the sink will hold in its queue. After this amount of buffers are queued in appsink, any more buffers will block upstream elements until a buffer is pulled from appsink.

Definition at line 148 of file applicationsink.cpp.

bool QGst::Utils::ApplicationSink::dropEnabled ( ) const
Returns
whether the sink is configured to drop old buffers when the maximum amount of queued buffers is reached.

Definition at line 156 of file applicationsink.cpp.

void QGst::Utils::ApplicationSink::enableDrop ( bool  enable)

Enables dropping old buffers when the maximum amount of queued buffers is reached.

Definition at line 161 of file applicationsink.cpp.

SamplePtr QGst::Utils::ApplicationSink::pullPreroll ( )

Get the last preroll sample in appsink. This was the sample that caused the appsink to preroll in the PAUSED state. This sample can be pulled many times and remains available to the application even after EOS.

This function is typically used when dealing with a pipeline in the PAUSED state. Calling this function after doing a seek will give the sample right after the seek position.

Note that the preroll sample will also be returned as the first sample when calling pullSample().

If an EOS event was received before any samples, this function returns a null SamplePtr. Use isEos() to check for the EOS condition.

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

Definition at line 169 of file applicationsink.cpp.

SamplePtr QGst::Utils::ApplicationSink::pullSample ( )

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

This function will only return samples when the appsink is in the PLAYING state. All rendered samples will be put in a queue so that the application can pull samples at its own rate. Note that when the application does not pull samples fast enough, the queued samples could consume a lot of memory, especially when dealing with raw video frames.

If an EOS event was received before any samples, this function returns a null SamplePtr. Use isEos() to check for the EOS condition.

Examples:
examples/appsink-src/main.cpp.

Definition at line 178 of file applicationsink.cpp.

BufferListPtr QGst::Utils::ApplicationSink::pullBufferList ( )

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

This function will only return sample lists when the appsink is in the PLAYING state. All rendered sample lists will be put in a queue so that the application can pull sample lists at its own rate. Note that when the application does not pull sample lists fast enough, the queued sample lists could consume a lot of memory, especially when dealing with raw video frames.

If an EOS event was received before any sample lists, this function returns a null SampleListPtr. Use isEos() to check for the EOS condition.

void QGst::Utils::ApplicationSink::eos ( )
protectedvirtual

Called when the end-of-stream has been reached.

Note
This function is called from the steaming thread.
Examples:
examples/appsink-src/main.cpp.

Definition at line 187 of file applicationsink.cpp.

FlowReturn QGst::Utils::ApplicationSink::newPreroll ( )
protectedvirtual

Called when a new preroll sample is available. The new preroll sample can be retrieved with pullPreroll() either from this function or from any other thread.

Note
This function is called from the steaming thread.

Definition at line 191 of file applicationsink.cpp.

FlowReturn QGst::Utils::ApplicationSink::newSample ( )
protectedvirtual

Called when a new sample is available. The new sample can be retrieved with pullSample() either from this function or from any other thread.

Note
This function is called from the steaming thread.
Examples:
examples/appsink-src/main.cpp.

Definition at line 196 of file applicationsink.cpp.


The documentation for this class was generated from the following files: