Class AppSrc
- All Implemented Interfaces:
URIHandler,Proxy
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 gst_app_src_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", "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 gst_app_src_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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classAppSrc.Builder<B extends AppSrc.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theEndOfStreamCallbackcallback.static interfaceFunctional interface declaration of theEnoughDataCallbackcallback.static interfaceFunctional interface declaration of theNeedDataCallbackcallback.static interfaceFunctional interface declaration of thePushBufferCallbackcallback.static interfaceFunctional interface declaration of thePushBufferListCallbackcallback.static interfaceFunctional interface declaration of thePushSampleCallbackcallback.static interfaceFunctional interface declaration of theSeekDataCallbackcallback.Nested classes/interfaces inherited from class org.freedesktop.gstreamer.base.BaseSrc
BaseSrc.BaseSrc$Impl, BaseSrc.BaseSrcClassNested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.Element
Element.Element$Impl, Element.ElementClass, Element.NoMorePadsCallback, Element.PadAddedCallback, Element.PadRemovedCallbackNested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.GstObject
GstObject.DeepNotifyCallback, GstObject.Object$Impl, GstObject.ObjectClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallbackNested classes/interfaces inherited from interface org.freedesktop.gstreamer.gst.URIHandler
URIHandler.URIHandler$Impl, URIHandler.URIHandlerInterface -
Constructor Summary
ConstructorsConstructorDescriptionAppSrc()Creates a new AppSrc.AppSrc(MemorySegment address) Create a AppSrc proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected AppSrcasParent()Returns this instance as if it were its parent type.static AppSrc.Builder<? extends AppSrc.Builder> builder()AAppSrc.Builderobject constructs aAppSrcwith the specified properties.Emits the "end-of-stream" signal.voidEmits the "enough-data" signal.voidemitNeedData(int length) Emits the "need-data" signal.emitPushBuffer(@Nullable Buffer buffer) Emits the "push-buffer" signal.emitPushBufferList(@Nullable BufferList bufferList) Emits the "push-buffer-list" signal.emitPushSample(@Nullable Sample sample) Emits the "push-sample" signal.booleanemitSeekData(long offset) Emits the "seek-data" signal.Indicates to the appsrc element that the last buffer queued in the element is the last buffer of the stream.protected void@Nullable CapsgetCaps()Get the configured caps onappsrc.longGet the number of currently queued buffers insideappsrc.longGet the number of currently queued bytes insideappsrc.Get the amount of currently queued time insideappsrc.Get the duration of the stream in nanoseconds.booleanCheck if appsrc will emit the "new-preroll" and "new-buffer" signals.voidgetLatency(Out<Long> min, Out<Long> max) Retrieve the min and max latencies inminandmaxrespectively.Returns the currently setGstAppLeakyType.longGet the maximum amount of buffers that can be queued inappsrc.longGet the maximum amount of bytes that can be queued inappsrc.Get the maximum amount of time that can be queued inappsrc.static MemoryLayoutThe memory layout of the native struct.longgetSize()Get the size of the stream in bytes.Get the stream type.static @Nullable TypegetType()Get the GType of the AppSrc classprotected voidneedData(int length) onEndOfStream(AppSrc.EndOfStreamCallback handler) Notifyappsrcthat no more buffer are available.onEnoughData(AppSrc.EnoughDataCallback handler) Signal that the source has enough data.onNeedData(AppSrc.NeedDataCallback handler) Signal that the source needs more data.onPushBuffer(AppSrc.PushBufferCallback handler) Adds a buffer to the queue of buffers that the appsrc element will push to its source pad.Adds a buffer list to the queue of buffers and buffer lists that the appsrc element will push to its source pad.onPushSample(AppSrc.PushSampleCallback handler) 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.onSeekData(AppSrc.SeekDataCallback handler) Seek to the given offset.pushBuffer(Buffer buffer) Adds a buffer to the queue of buffers that the appsrc element will push to its source pad.pushBufferList(BufferList bufferList) Adds a buffer list to the queue of buffers and buffer lists that the appsrc element will push to its source pad.pushSample(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.protected booleanseekData(long offset) voidsetCallbacks(AppSrcCallbacks callbacks, @Nullable MemorySegment userData) Set callbacks which will be executed when data is needed, enough data has been collected or when a seek should be performed.voidsetCapabilities(@Nullable Caps caps) Set the capabilities on the appsrc element.voidsetDuration(ClockTime duration) Set the duration of the stream in nanoseconds.voidsetEmitSignals(boolean emit) Make appsrc emit the "new-preroll" and "new-buffer" signals.voidsetLatency(long min, long max) Configure theminandmaxlatency insrc.Ifminis set to -1, the default latency calculations for pseudo-live sources will be used.voidsetLeakyType(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.voidsetMaxBuffers(long max) Set the maximum amount of buffers that can be queued inappsrc.After the maximum amount of buffers are queued, this AppSrc will emit the "enough-data" signal.voidsetMaxBytes(long max) Set the maximum amount of bytes that can be queued inappsrc.After the maximum amount of bytes are queued, this AppSrc will emit the "enough-data" signal.voidsetMaxTime(ClockTime max) Set the maximum amount of time that can be queued inappsrc.After the maximum amount of time are queued, this AppSrc will emit the "enough-data" signal.voidsetSize(long size) Set the size of the stream in bytes.voidsetStreamType(AppStreamType type) Set the stream type onappsrc.For seekable streams, the "seek" signal must be connected to.Methods inherited from class org.freedesktop.gstreamer.base.BaseSrc
alloc, create, decideAllocation, doSeek, event, fill, fixate, getAllocator, getBlocksize, getBufferPool, getCaps, getDoTimestamp, getSize, getTimes, isAsync, isLive, isSeekable, negotiate, newSeamlessSegment, newSegment, prepareSeekSegment, pushSegment, query, queryLatency, setAsync, setAutomaticEos, setBlocksize, setCaps, setDoTimestamp, setDynamicSize, setFormat, setLive, start, startComplete, startWait, stop, submitBufferList, unlock, unlockStop, waitPlayingMethods inherited from class org.freedesktop.gstreamer.gst.Element
abortState, addPad, addPropertyDeepNotifyWatch, addPropertyNotifyWatch, callAsync, changeState, continueState, createAllPads, decorateStreamId, decorateStreamIdPrintf, emitNoMorePads, emitPadAdded, emitPadRemoved, foreachPad, foreachSinkPad, foreachSrcPad, getBaseTime, getBus, getClock, getCompatiblePad, getCompatiblePadTemplate, getContext, getContexts, getContextUnlocked, getCurrentClockTime, getCurrentRunningTime, getFactory, getMetadata, getPadTemplate, getPadTemplateList, getRequestPad, getStartTime, getState, getStaticPad, isLockedState, iteratePads, iterateSinkPads, iterateSrcPads, link, linkFiltered, linkMany, linkPads, linkPadsFiltered, linkPadsFull, linkPadsFull, lostState, makeFromUri, messageFull, messageFull, messageFullWithDetails, messageFullWithDetails, noMorePads, onNoMorePads, onPadAdded, onPadRemoved, padAdded, padRemoved, postMessage, provideClock, queryConvert, queryDuration, queryPosition, register, releasePad, releaseRequestPad, removePad, removePropertyNotifyWatch, requestPad, requestPadSimple, seek, seek, seekSimple, seekSimple, sendEvent, setBaseTime, setBus, setClock, setContext, setLockedState, setStartTime, setState, stateChanged, stateChangeReturnGetName, stateGetName, syncStateWithParent, typeSetSkipDocumentation, unlink, unlinkMany, unlinkPadsMethods inherited from class org.freedesktop.gstreamer.gst.GstObject
addControlBinding, checkUniqueness, deepNotify, defaultDeepNotify, defaultError, emitDeepNotify, getControlBinding, getControlRate, getGValueArray, getName, getParent, getPathString, getValue, getValueArray, hasActiveControlBindings, hasAncestor, hasAsAncestor, hasAsParent, onDeepNotify, ref, refSink, removeControlBinding, replace, setControlBindingDisabled, setControlBindingsDisabled, setControlRate, setName, setParent, suggestNextSync, syncValues, unparent, unrefMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.freedesktop.gstreamer.gst.URIHandler
getProtocols, getUri, getUriType, setUri
-
Constructor Details
-
AppSrc
Create a AppSrc proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
AppSrc
public AppSrc()Creates a new AppSrc.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
endOfStream
Indicates to the appsrc element that the last buffer queued in the element is the last buffer of the stream.- Returns:
GST_FLOW_OKwhen the EOS was successfully queued.GST_FLOW_FLUSHINGwhen this AppSrc is not PAUSED or PLAYING.
-
getCaps
Get the configured caps onappsrc.- Returns:
- the
GstCapsproduced by the source. gst_caps_unref() after usage.
-
getCurrentLevelBuffers
public long getCurrentLevelBuffers()Get the number of currently queued buffers insideappsrc.- Returns:
- The number of currently queued buffers.
- Since:
- 1.20
-
getCurrentLevelBytes
public long getCurrentLevelBytes()Get the number of currently queued bytes insideappsrc.- Returns:
- The number of currently queued bytes.
- Since:
- 1.2
-
getCurrentLevelTime
Get the amount of currently queued time insideappsrc.- Returns:
- The amount of currently queued time.
- Since:
- 1.20
-
getDuration
Get the duration of the stream in nanoseconds. A value of GST_CLOCK_TIME_NONE means that the duration is not known.- Returns:
- the duration of the stream previously set with gst_app_src_set_duration();
- Since:
- 1.10
-
getEmitSignals
public boolean getEmitSignals()Check if appsrc will emit the "new-preroll" and "new-buffer" signals.- Returns:
trueif this AppSrc is emitting the "new-preroll" and "new-buffer" signals.
-
getLatency
-
getLeakyType
Returns the currently setGstAppLeakyType. See gst_app_src_set_leaky_type() for more details.- Returns:
- The currently set
GstAppLeakyType. - Since:
- 1.20
-
getMaxBuffers
public long getMaxBuffers()Get the maximum amount of buffers that can be queued inappsrc.- Returns:
- The maximum amount of buffers that can be queued.
- Since:
- 1.20
-
getMaxBytes
public long getMaxBytes()Get the maximum amount of bytes that can be queued inappsrc.- Returns:
- The maximum amount of bytes that can be queued.
-
getMaxTime
Get the maximum amount of time that can be queued inappsrc.- Returns:
- The maximum amount of time that can be queued.
- Since:
- 1.20
-
getSize
public long getSize()Get the size of the stream in bytes. A value of -1 means that the size is not known.- Returns:
- the size of the stream previously set with gst_app_src_set_size();
-
getStreamType
Get the stream type. Control the stream type of this AppSrc with gst_app_src_set_stream_type().- Returns:
- the stream type.
-
pushBuffer
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.
- Parameters:
buffer- aGstBufferto push- Returns:
GST_FLOW_OKwhen the buffer was successfully queued.GST_FLOW_FLUSHINGwhen this AppSrc is not PAUSED or PLAYING.GST_FLOW_EOSwhen EOS occurred.
-
pushBufferList
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 ofbufferList.When the block property is TRUE, this function can block until free space becomes available in the queue.
- Parameters:
bufferList- aGstBufferListto push- Returns:
GST_FLOW_OKwhen the buffer list was successfully queued.GST_FLOW_FLUSHINGwhen this AppSrc is not PAUSED or PLAYING.GST_FLOW_EOSwhen EOS occurred.- Since:
- 1.14
-
pushSample
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.
- Parameters:
sample- aGstSamplefrom which buffer and caps may be extracted- Returns:
GST_FLOW_OKwhen the buffer was successfully queued.GST_FLOW_FLUSHINGwhen this AppSrc is not PAUSED or PLAYING.GST_FLOW_EOSwhen EOS occurred.- Since:
- 1.6
-
setCallbacks
Set callbacks which will be executed when data is needed, enough data has been collected or when a seek should be performed. This is an alternative to using the signals, it has lower overhead and is thus less expensive, but also less flexible.If callbacks are installed, no signals will be emitted for performance reasons.
Before 1.16.3 it was not possible to change the callbacks in a thread-safe way.
- Parameters:
callbacks- the callbacksuserData- a user_data argument for the callbacks
-
setCapabilities
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 matchcaps.capsmust be fixed and the caps on the buffers must match the caps or left NULL.- Parameters:
caps- caps to set
-
setDuration
Set the duration of the stream in nanoseconds. A value of GST_CLOCK_TIME_NONE means that the duration is not known.- Parameters:
duration- the duration to set- Since:
- 1.10
-
setEmitSignals
public void setEmitSignals(boolean 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.- Parameters:
emit- the new state
-
setLatency
public void setLatency(long min, long max) Configure theminandmaxlatency insrc.Ifminis set to -1, the default latency calculations for pseudo-live sources will be used.- Parameters:
min- the min latencymax- the max latency
-
setLeakyType
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.- Parameters:
leaky- theGstAppLeakyType- Since:
- 1.20
-
setMaxBuffers
public void setMaxBuffers(long max) Set the maximum amount of buffers that can be queued inappsrc.After the maximum amount of buffers are queued, this AppSrc will emit the "enough-data" signal.- Parameters:
max- the maximum number of buffers to queue- Since:
- 1.20
-
setMaxBytes
public void setMaxBytes(long max) Set the maximum amount of bytes that can be queued inappsrc.After the maximum amount of bytes are queued, this AppSrc will emit the "enough-data" signal.- Parameters:
max- the maximum number of bytes to queue
-
setMaxTime
Set the maximum amount of time that can be queued inappsrc.After the maximum amount of time are queued, this AppSrc will emit the "enough-data" signal.- Parameters:
max- the maximum amonut of time to queue- Since:
- 1.20
-
setSize
public void setSize(long size) Set the size of the stream in bytes. A value of -1 means that the size is not known.- Parameters:
size- the size to set
-
setStreamType
Set the stream type onappsrc.For seekable streams, the "seek" signal must be connected to.A stream_type stream
- Parameters:
type- the new state
-
enoughData
protected void enoughData() -
needData
protected void needData(int length) -
seekData
protected boolean seekData(long offset) -
onEndOfStream
public SignalConnection<AppSrc.EndOfStreamCallback> onEndOfStream(AppSrc.EndOfStreamCallback handler) Notifyappsrcthat no more buffer are available.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitEndOfStream
Emits the "end-of-stream" signal. SeeonEndOfStream(org.freedesktop.gstreamer.app.AppSrc.EndOfStreamCallback). -
onEnoughData
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.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitEnoughData
public void emitEnoughData()Emits the "enough-data" signal. SeeonEnoughData(org.freedesktop.gstreamer.app.AppSrc.EnoughDataCallback). -
onNeedData
Signal that the source needs more data. In the callback or from another thread you should call push-buffer or end-of-stream.lengthis just a hint and when it is set to -1, any number of bytes can be pushed intoappsrc.You can call push-buffer multiple times until the enough-data signal is fired.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitNeedData
public void emitNeedData(int length) Emits the "need-data" signal. SeeonNeedData(org.freedesktop.gstreamer.app.AppSrc.NeedDataCallback). -
onPushBuffer
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, but it takes a reference so the buffer can be unreffed at any time after calling this function.
When the block property is TRUE, this function can block until free space becomes available in the queue.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPushBuffer
Emits the "push-buffer" signal. SeeonPushBuffer(org.freedesktop.gstreamer.app.AppSrc.PushBufferCallback). -
onPushBufferList
public SignalConnection<AppSrc.PushBufferListCallback> onPushBufferList(AppSrc.PushBufferListCallback handler) 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, but it takes a reference so the buffer list can be unreffed at any time after calling this function.
When the block property is TRUE, this function can block until free space becomes available in the queue.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 1.14
- See Also:
-
emitPushBufferList
Emits the "push-buffer-list" signal. SeeonPushBufferList(org.freedesktop.gstreamer.app.AppSrc.PushBufferListCallback). -
onPushSample
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, but it takes a reference so the sample can be unreffed at any time after calling this function.
When the block property is TRUE, this function can block until free space becomes available in the queue.
- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 1.6
- See Also:
-
emitPushSample
Emits the "push-sample" signal. SeeonPushSample(org.freedesktop.gstreamer.app.AppSrc.PushSampleCallback). -
onSeekData
Seek to the given offset. The next push-buffer should produce buffers from the newoffset.This callback is only called for seekable stream types.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitSeekData
public boolean emitSeekData(long offset) Emits the "seek-data" signal. SeeonSeekData(org.freedesktop.gstreamer.app.AppSrc.SeekDataCallback). -
builder
AAppSrc.Builderobject constructs aAppSrcwith the specified properties. Use the variousset...()methods to set properties, and finish construction withAppSrc.Builder.build().- Returns:
- the builder object
-