Class BaseSrc
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
BaseSrc.BaseSrcImpl
,PushSrc
- random access sources like files
- seekable sources
- live sources
The source can be configured to operate in any GstFormat
with the
gst_base_src_set_format() method. The currently set format determines
the format of the internal GstSegment
and any EventType.SEGMENT
events. The default format for GstBaseSrc
is Format.BYTES
.
GstBaseSrc
always supports push mode scheduling. If the following
conditions are met, it also supports pull mode scheduling:
- The format is set to
Format.BYTES
(default). GstBaseSrcClass
::is_seekable returnstrue
.
If all the conditions are met for operating in pull mode, GstBaseSrc
is
automatically seekable in push mode as well. The following conditions must
be met to make the element seekable in push mode when the format is not
Format.BYTES
:
GstBaseSrcClass
::is_seekable returnstrue
.GstBaseSrcClass
::query can convert all supported seek formats to the internal format as set with gst_base_src_set_format().GstBaseSrcClass
::do_seek is implemented, performs the seek and returnstrue
.
When the element does not meet the requirements to operate in pull mode, the
offset and length in the GstBaseSrcClass
::create method should be ignored.
It is recommended to subclass GstPushSrc
instead, in this situation. If the
element can operate in pull mode but only with specific offsets and
lengths, it is allowed to generate an error when the wrong values are passed
to the GstBaseSrcClass
::create function.
GstBaseSrc
has support for live sources. Live sources are sources that when
paused discard data, such as audio or video capture devices. A typical live
source also produces data at a fixed rate and thus provides a clock to publish
this rate.
Use gst_base_src_set_live() to activate the live source mode.
A live source does not produce data in the PAUSED state. This means that the
GstBaseSrcClass
::create method will not be called in PAUSED but only in
PLAYING. To signal the pipeline that the element will not produce data, the
return value from the READY to PAUSED state will be
StateChangeReturn.NO_PREROLL
.
A typical live source will timestamp the buffers it creates with the current running time of the pipeline. This is one reason why a live source can only produce data in the PLAYING state, when the clock is actually distributed and running.
Live sources that synchronize and block on the clock (an audio source, for
example) can use gst_base_src_wait_playing() when the
GstBaseSrcClass
::create function was interrupted by a state change to
PAUSED.
The GstBaseSrcClass
::get_times method can be used to implement pseudo-live
sources. It only makes sense to implement the GstBaseSrcClass
::get_times
function if the source is a live source. The GstBaseSrcClass
::get_times
function should return timestamps starting from 0, as if it were a non-live
source. The base class will make sure that the timestamps are transformed
into the current running_time. The base source will then wait for the
calculated running_time before pushing out the buffer.
For live sources, the base class will by default report a latency of 0. For pseudo live sources, the base class will by default measure the difference between the first buffer timestamp and the start time of get_times and will report this value as the latency. Subclasses should override the query function when this behaviour is not acceptable.
There is only support in GstBaseSrc
for exactly one source pad, which
should be named "src". A source implementation (subclass of GstBaseSrc
)
should install a pad template in its class_init function, like so:
static void
my_element_class_init (GstMyElementClass *klass)
{
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
// srctemplate should be a #GstStaticPadTemplate with direction
// %GST_PAD_SRC and name "src"
gst_element_class_add_static_pad_template (gstelement_class, &srctemplate);
gst_element_class_set_static_metadata (gstelement_class,
"Source name",
"Source",
"My Source element",
"The author <my.sink@my.email>");
}
Controlled shutdown of live sources in applications
Applications that record from a live source may want to stop recording
in a controlled way, so that the recording is stopped, but the data
already in the pipeline is processed to the end (remember that many live
sources would go on recording forever otherwise). For that to happen the
application needs to make the source stop recording and send an EOS
event down the pipeline. The application would then wait for an
EOS message posted on the pipeline's bus to know when all data has
been processed and the pipeline can safely be stopped.
An application may send an EOS event to a source element to make it
perform the EOS logic (send EOS event downstream or post a
MessageType.SEGMENT_DONE
on the bus). This can typically be done
with the gst_element_send_event() function on the element or its parent bin.
After the EOS has been sent to the element, the application should wait for an EOS message to be posted on the pipeline's bus. Once this EOS message is received, it may safely shut down the entire pipeline.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Subclasses can override any of the available virtual methods or not, as needed.static class
The BaseSrcImpl type represents a native instance of the abstract BaseSrc class.static class
BaseSrc.Builder<B extends BaseSrc.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.Element
Element.ElementClass, Element.ElementImpl, Element.NoMorePadsCallback, Element.PadAddedCallback, Element.PadRemovedCallback
Nested classes/interfaces inherited from class org.freedesktop.gstreamer.gst.GstObject
GstObject.DeepNotifyCallback, GstObject.ObjectClass, GstObject.ObjectImpl
Nested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback
-
Constructor Summary
ConstructorDescriptionBaseSrc
(MemorySegment address) Create a BaseSrc proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected FlowReturn
Ask the subclass to allocate an output buffer withoffset
andsize
, the default implementation will use the negotiated allocator.protected BaseSrc
asParent()
Returns this instance as if it were its parent type.static BaseSrc.Builder
<? extends BaseSrc.Builder> builder()
ABaseSrc.Builder
object constructs aBaseSrc
with the specified properties.protected FlowReturn
Ask the subclass to create a buffer withoffset
andsize
, the default implementation will call alloc if no allocatedbuf
is provided and then call fill.protected boolean
decideAllocation
(Query query) configure the allocation queryprotected boolean
Perform seeking on the resource to the indicated segment.protected boolean
Override this to implement custom event handling.protected FlowReturn
Ask the subclass to fill the buffer with data for offset and size.protected Caps
Called if, in negotiation, caps need fixating.void
getAllocator
(@Nullable Out<Allocator> allocator, @Nullable AllocationParams params) LetsGstBaseSrc
sub-classes to know the memoryallocator
used by the base class and itsparams
.int
Get the number of bytes that this BaseSrc will push out with each buffer.protected Caps
Called to get the caps to report.boolean
Query if this BaseSrc timestamps outgoing buffers based on the current running_time.static MemoryLayout
The memory layout of the native struct.protected boolean
Get the total size of the resource in the format set by gst_base_src_set_format().protected void
Givenbuffer
, returnstart
andend
time when it should be pushed out.static Type
getType()
Get the GType of the BaseSrc classboolean
isAsync()
Get the current async behaviour of this BaseSrc.boolean
isLive()
Check if an element is in live mode.protected boolean
Check if the source can seekboolean
Negotiates src pad caps with downstream elements.boolean
newSeamlessSegment
(long start, long stop, long time) Deprecated.Use gst_base_src_new_segment()boolean
newSegment
(Segment segment) Prepare a new segment for emission downstream.protected boolean
prepareSeekSegment
(Event seek, Segment segment) Prepare theGstSegment
that will be passed to theGstBaseSrcClass
::do_seek vmethod for executing a seek request.boolean
pushSegment
(Segment segment) Send a new segment downstream.boolean
Handle a requested query.boolean
queryLatency
(@Nullable Out<Boolean> live, @Nullable ClockTime minLatency, @Nullable ClockTime maxLatency) Query the source for the latency parameters.void
setAsync
(boolean async) Configure async behaviour in this BaseSrc, no state change will block.void
setAutomaticEos
(boolean automaticEos) IfautomaticEos
istrue
, this BaseSrc will automatically go EOS if a buffer after the total size is returned.void
setBlocksize
(int blocksize) Set the number of bytes that this BaseSrc will push out with each buffer.boolean
Set new caps on the basesrc source pad.void
setDoTimestamp
(boolean timestamp) Configure this BaseSrc to automatically timestamp outgoing buffers based on the current running_time of the pipeline.void
setDynamicSize
(boolean dynamic) If notdynamic
, size is only updated when needed, such as when trying to read past current tracked size.void
Sets the default format of the source.void
setLive
(boolean live) If the element listens to a live source,live
should be set totrue
.protected boolean
start()
Start processing.void
startComplete
(FlowReturn ret) Complete an asynchronous start operation.Wait until the start operation completes.protected boolean
stop()
Stop processing.void
submitBufferList
(BufferList bufferList) Subclasses can call this from their create virtual method implementation to submit a buffer list to be pushed out later.protected boolean
unlock()
Unlock any pending access to the resource.protected boolean
Clear the previous unlock request.If theGstBaseSrcClass
::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.Methods 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, unlinkPads
Methods 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, unref
Methods 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
BaseSrc
Create a BaseSrc proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
-
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 Javasuper
keyword, 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. -
getAllocator
public void getAllocator(@Nullable @Nullable Out<Allocator> allocator, @Nullable @Nullable AllocationParams params) LetsGstBaseSrc
sub-classes to know the memoryallocator
used by the base class and itsparams
.Unref the
allocator
after usage.- Parameters:
allocator
- theGstAllocator
usedparams
- theGstAllocationParams
ofallocator
-
getBlocksize
public int getBlocksize()Get the number of bytes that this BaseSrc will push out with each buffer.- Returns:
- the number of bytes pushed with each buffer.
-
getBufferPool
-
getDoTimestamp
public boolean getDoTimestamp()Query if this BaseSrc timestamps outgoing buffers based on the current running_time.- Returns:
true
if the base class will automatically timestamp outgoing buffers.
-
isAsync
public boolean isAsync()Get the current async behaviour of this BaseSrc. See also gst_base_src_set_async().- Returns:
true
if this BaseSrc is operating in async mode.
-
isLive
public boolean isLive()Check if an element is in live mode.- Returns:
true
if element is in live mode.
-
negotiate
public boolean negotiate()Negotiates src pad caps with downstream elements. Unmarks GST_PAD_FLAG_NEED_RECONFIGURE in any case. But marks it again ifGstBaseSrcClass
::negotiate fails.Do not call this in the
GstBaseSrcClass
::fill vmethod. Call this inGstBaseSrcClass
::create or inGstBaseSrcClass
::alloc, _before_ any buffer is allocated.- Returns:
true
if the negotiation succeeded, elsefalse
.
-
newSeamlessSegment
Deprecated.Use gst_base_src_new_segment()Prepare a new seamless segment for emission downstream. This function must only be called by derived sub-classes, and only from theGstBaseSrcClass
::create function, as the stream-lock needs to be held.The format for the new segment will be the current format of the source, as configured with gst_base_src_set_format()
- Parameters:
start
- The new start value for the segmentstop
- Stop value for the new segmenttime
- The new time value for the start of the new segment- Returns:
true
if preparation of the seamless segment succeeded.
-
newSegment
Prepare a new segment for emission downstream. This function must only be called by derived sub-classes, and only from theGstBaseSrcClass
::create function, as the stream-lock needs to be held.The format for the
segment
must be identical with the current format of the source, as configured with gst_base_src_set_format().The format of this BaseSrc must not be
Format.UNDEFINED
and the format should be configured via gst_base_src_set_format() before calling this method.- Parameters:
segment
- a pointer to aGstSegment
- Returns:
true
if preparation of new segment succeeded.
-
pushSegment
Send a new segment downstream. This function must only be called by derived sub-classes, and only from theGstBaseSrcClass
::create function, as the stream-lock needs to be held. This method also requires that an out caps has been configured, so gst_base_src_set_caps() needs to have been called before.The format for the
segment
must be identical with the current format of the source, as configured with gst_base_src_set_format().The format of this BaseSrc must not be
Format.UNDEFINED
and the format should be configured via gst_base_src_set_format() before calling this method.This is a variant of gst_base_src_new_segment() sending the segment right away, which can be useful to ensure events ordering.
- Parameters:
segment
- a pointer to aGstSegment
- Returns:
true
if sending of new segment succeeded.
-
queryLatency
public boolean queryLatency(@Nullable @Nullable Out<Boolean> live, @Nullable @Nullable ClockTime minLatency, @Nullable @Nullable ClockTime maxLatency) Query the source for the latency parameters.live
will betrue
when this BaseSrc is configured as a live source.minLatency
andmaxLatency
will be set to the difference between the running time and the timestamp of the first buffer.This function is mostly used by subclasses.
- Parameters:
live
- if the source is liveminLatency
- the min latency of the sourcemaxLatency
- the max latency of the source- Returns:
true
if the query succeeded.
-
setAsync
public void setAsync(boolean async) Configure async behaviour in this BaseSrc, 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.- Parameters:
async
- new async mode
-
setAutomaticEos
public void setAutomaticEos(boolean automaticEos) IfautomaticEos
istrue
, this BaseSrc will automatically go EOS if a buffer after the total size is returned. By default this istrue
but sources that can't return an authoritative size and only know that they're EOS when trying to read more should set this tofalse
.When this BaseSrc operates in
Format.TIME
,GstBaseSrc
will send an EOS when a buffer outside of the currently configured segment is pushed ifautomaticEos
istrue
. Since 1.16, ifautomaticEos
isfalse
an EOS will be pushed only when theGstBaseSrcClass
::create implementation returnsFlowReturn.EOS
.- Parameters:
automaticEos
- automatic eos
-
setBlocksize
public void setBlocksize(int blocksize) Set the number of bytes that this BaseSrc will push out with each buffer. Whenblocksize
is set to -1, a default length will be used.- Parameters:
blocksize
- the new blocksize in bytes
-
setCaps
Set new caps on the basesrc source pad.- Parameters:
caps
- aGstCaps
- Returns:
true
if the caps could be set
-
setDoTimestamp
public void setDoTimestamp(boolean timestamp) Configure this BaseSrc to automatically timestamp outgoing buffers based on the current running_time of the pipeline. This property is mostly useful for live sources.- Parameters:
timestamp
- enable or disable timestamping
-
setDynamicSize
public void setDynamicSize(boolean dynamic) If notdynamic
, size is only updated when needed, such as when trying to read past current tracked size. Otherwise, size is checked for upon each read.- Parameters:
dynamic
- new dynamic size mode
-
setFormat
Sets the default format of the source. This will be the format used for sending SEGMENT events and for performing seeks.If a format of GST_FORMAT_BYTES is set, the element will be able to operate in pull mode if the
GstBaseSrcClass
::is_seekable returnstrue
.This function must only be called in states <
State.PAUSED
.- Parameters:
format
- the format to use
-
setLive
public void setLive(boolean live) If the element listens to a live source,live
should be set totrue
.A live source will not produce data in the PAUSED state and will therefore not be able to participate in the PREROLL phase of a pipeline. To signal this fact to the application and the pipeline, the state change return value of the live source will be GST_STATE_CHANGE_NO_PREROLL.
- Parameters:
live
- new live-mode
-
startComplete
Complete an asynchronous start operation. When the subclass overrides the start method, it should call gst_base_src_start_complete() when the start operation completes either from the same thread or from an asynchronous helper thread.- Parameters:
ret
- aGstFlowReturn
-
startWait
-
submitBufferList
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 aGstBufferList
, 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).Subclasses that use this function from their create function must return
FlowReturn.OK
and no buffer from their create virtual method implementation. If a buffer is returned after a buffer list has also been submitted via this function the behaviour is undefined.Subclasses must only call this function once per create function call and subclasses must only call this function when the source operates in push mode.
- Parameters:
bufferList
- aGstBufferList
-
waitPlaying
If theGstBaseSrcClass
::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.This function will block until a state change to PLAYING happens (in which case this function returns
FlowReturn.OK
) or the processing must be stopped due to a state change to READY or a FLUSH event (in which case this function returnsFlowReturn.FLUSHING
).- Returns:
FlowReturn.OK
if this BaseSrc is PLAYING and processing can continue. Any other return value should be returned from the create vmethod.
-
alloc
Ask the subclass to allocate an output buffer withoffset
andsize
, the default implementation will use the negotiated allocator. -
create
Ask the subclass to create a buffer withoffset
andsize
, the default implementation will call alloc if no allocatedbuf
is provided and then call fill. -
decideAllocation
configure the allocation query -
doSeek
Perform seeking on the resource to the indicated segment. -
event
Override this to implement custom event handling. -
fill
Ask the subclass to fill the buffer with data for offset and size. The passed buffer is guaranteed to hold the requested amount of bytes. -
fixate
-
getCaps
-
getSize
-
getTimes
-
isSeekable
protected boolean isSeekable()Check if the source can seek -
prepareSeekSegment
Prepare theGstSegment
that will be passed to theGstBaseSrcClass
::do_seek vmethod for executing a seek request. Sub-classes should override this if they support seeking in formats other than the configured native format. By default, it tries to convert the seek arguments to the configured native format and prepare a segment in that format. -
query
-
start
protected boolean start()Start processing. Subclasses should open resources and prepare to produce data. Implementation should call gst_base_src_start_complete() when the operation completes, either from the current thread or any other thread that finishes the start operation asynchronously. -
stop
protected boolean stop()Stop processing. Subclasses should use this to close resources. -
unlock
protected boolean unlock()Unlock any pending access to the resource. Subclasses should unblock any blocked function ASAP. In particular, anycreate()
function in progress should be unblocked and should return GST_FLOW_FLUSHING. Any futureGstBaseSrcClass
::create function call should also return GST_FLOW_FLUSHING until theGstBaseSrcClass
::unlock_stop function has been called. -
unlockStop
protected boolean unlockStop()Clear the previous unlock request. Subclasses should clear any state they set duringGstBaseSrcClass
::unlock, such as clearing command queues. -
builder
ABaseSrc.Builder
object constructs aBaseSrc
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withBaseSrc.Builder.build()
.
-