Class AudioRingBuffer
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
AudioRingBuffer.AudioRingBuffer$Impl
The ringbuffer abstracts a circular buffer of data. One reader and one writer can operate on the data from different threads in a lockfree manner. The base class is sufficiently flexible to be used as an abstraction for DMA based ringbuffers as well as a pure software implementations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe AudioRingBuffer$Impl type represents a native instance of the abstract AudioRingBuffer class.static classThe vmethods that subclasses can override to implement the ringbuffer.static classAudioRingBuffer.Builder<B extends AudioRingBuffer.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.Nested 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.NotifyCallback -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new AudioRingBuffer.AudioRingBuffer(MemorySegment address) Create a AudioRingBuffer proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanacquire(AudioRingBufferSpec spec) Allocate the resources for the ringbuffer.booleanactivate(boolean active) Activate this AudioRingBuffer to start or stop pulling data.voidadvance(int advance) Subclasses should call this function to notify the fact thatadvancesegments are now processed by the device.protected AudioRingBufferasParent()Returns this instance as if it were its parent type.voidclear(int segment) Clear the given segment of the buffer with silence samples.voidclearAll()Clear all samples from the ringbuffer.booleanClose the audio device associated with the ring buffer.intcommit(Out<Long> sample, @org.jspecify.annotations.Nullable byte @Nullable [] data, int outSamples, Out<Integer> accum) CommitinSamplessamples pointed to bydatato the ringbufferbuf.booleanConvertsrcValinsrcFmtto the equivalent value indestFmt.The result will be put indestVal.static voidPrint debug info about the buffer sized inspecto the debug log.static voidPrint debug info about the parsed caps inspecto the debug log.intdelay()Get the number of samples queued in the audio device.booleanChecks the status of the device associated with the ring buffer.static MemoryLayoutThe memory layout of the native struct.longGets the current segment base number of the ringbuffer.longGets the current segment number of the ringbuffer.static @Nullable TypegetType()Get the GType of the AudioRingBuffer classbooleanCheck if the ringbuffer is acquired and ready to use.booleanisActive()Check if this AudioRingBuffer is activated.booleanCheck if this AudioRingBuffer is flushing.voidmayStart(boolean allowed) Tell the ringbuffer that it is allowed to start playback when the ringbuffer is filled with samples.booleanOpen the audio device associated with the ring buffer.static booleanparseCaps(AudioRingBufferSpec spec, Caps caps) Parsecapsintospec.booleanpause()Pause processing samples from the ringbuffer.booleanprepareRead(Out<Integer> segment, @Nullable Out<byte[]> readptr) Returns a pointer to memory where the data from segmentsegmentcan be found.intReadlensamples from the ringbuffer into the memory pointed to bydata.The first sample should be read from positionsamplein the ringbuffer.booleanrelease()Free the resources of the ringbuffer.protected booleanresume()resume processing of samples after pauselongGet the number of samples that were processed by the ringbuffer since it was last started.voidsetCallback(@Nullable AudioRingBufferCallback cb) Sets the given callback function on the buffer.voidsetChannelPositions(@Nullable AudioChannelPosition @Nullable [] position) Tell the ringbuffer about the device's channel positions.voidMark the ringbuffer as errored after it has started.voidsetFlushing(boolean flushing) Set the ringbuffer to flushing mode or normal mode.voidsetSample(long sample) Make sure that the next sample written to the device is accounted for as being thesamplesample written to the device.voidsetSegdone(long segdone) Sets the current segment number of the ringbuffer.voidsetTimestamp(int readseg, ClockTime timestamp) booleanstart()Start processing samples from the ringbuffer.booleanstop()Stop processing samples from the ringbuffer.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, unrefMethods inherited from class org.gnome.gobject.InitiallyUnowned
builderMethods 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, hashCode
-
Constructor Details
-
AudioRingBuffer
Create a AudioRingBuffer proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
AudioRingBuffer
public AudioRingBuffer()Creates a new AudioRingBuffer.
-
-
Method Details
-
getType
Get the GType of the AudioRingBuffer class- Returns:
- the GType
-
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. -
debugSpecBuff
Print debug info about the buffer sized inspecto the debug log.- Parameters:
spec- the spec to debug
-
debugSpecCaps
Print debug info about the parsed caps inspecto the debug log.- Parameters:
spec- the spec to debug
-
parseCaps
Parsecapsintospec.- Parameters:
spec- a speccaps- aGstCaps- Returns:
- TRUE if the caps could be parsed.
-
acquire
Allocate the resources for the ringbuffer. This function fills in the data pointer of the ring buffer with a validGstBufferto which samples can be written.- Parameters:
spec- the specs of the buffer- Returns:
- TRUE if the device could be acquired, FALSE on error.
MT safe.
-
activate
public boolean activate(boolean active) Activate this AudioRingBuffer to start or stop pulling data.MT safe.
- Parameters:
active- the new mode- Returns:
- TRUE if the device could be activated in the requested mode, FALSE on error.
-
advance
public void advance(int advance) Subclasses should call this function to notify the fact thatadvancesegments are now processed by the device.MT safe.
- Parameters:
advance- the number of segments written
-
clear
public void clear(int segment) Clear the given segment of the buffer with silence samples. This function is used by subclasses.MT safe.
- Parameters:
segment- the segment to clear
-
clearAll
public void clearAll()Clear all samples from the ringbuffer.MT safe.
-
closeDevice
public boolean closeDevice()Close the audio device associated with the ring buffer. The ring buffer should already have been released via gst_audio_ring_buffer_release().- Returns:
- TRUE if the device could be closed, FALSE on error.
MT safe.
-
commit
public int commit(Out<Long> sample, @org.jspecify.annotations.Nullable byte @Nullable [] data, int outSamples, Out<Integer> accum) CommitinSamplessamples pointed to bydatato the ringbufferbuf.inSamplesandoutSamplesdefine the rate conversion to perform on the samples indata.For negative rates,outSamplesmust be negative andinSamplespositive.When
outSamplesis positive, the first sample will be written at positionsamplein the ringbuffer. WhenoutSamplesis negative, the last sample will be written tosamplein reverse order.outSamplesdoes not need to be a multiple of the segment size of the ringbuffer although it is recommended for optimal performance.accumwill hold a temporary accumulator used in rate conversion and should be set to 0 when this function is first called. In case the commit operation is interrupted, one can resume the processing by passing the previously returnedaccumvalue back to this function.MT safe.
- Parameters:
sample- the sample position of the datadata- the data to commitoutSamples- the number of samples to write to the ringbufferaccum- accumulator for rate conversion.- Returns:
- The number of samples written to the ringbuffer or -1 on error. The
number of samples written can be less than
outSampleswhen this AudioRingBuffer was interrupted with a flush or stop.
-
convert
ConvertsrcValinsrcFmtto the equivalent value indestFmt.The result will be put indestVal.- Parameters:
srcFmt- the source formatsrcVal- the source valuedestFmt- the destination formatdestVal- a location to store the converted value- Returns:
- TRUE if the conversion succeeded.
-
delay
public int delay()Get the number of samples queued in the audio device. This is usually less than the segment size but can be bigger when the implementation uses another internal buffer between the audio device.For playback ringbuffers this is the amount of samples transferred from the ringbuffer to the device but still not played.
For capture ringbuffers this is the amount of samples in the device that are not yet transferred to the ringbuffer.
- Returns:
- The number of samples queued in the audio device.
MT safe.
-
deviceIsOpen
public boolean deviceIsOpen()Checks the status of the device associated with the ring buffer.- Returns:
- TRUE if the device was open, FALSE if it was closed.
MT safe.
-
getSegbase
public long getSegbase()Gets the current segment base number of the ringbuffer.MT safe.
- Returns:
- Current segment base number of the ringbuffer.
- Since:
- 1.26
-
getSegdone
public long getSegdone()Gets the current segment number of the ringbuffer.MT safe.
- Returns:
- Current segment number of the ringbuffer.
- Since:
- 1.26
-
isAcquired
public boolean isAcquired()Check if the ringbuffer is acquired and ready to use.- Returns:
- TRUE if the ringbuffer is acquired, FALSE on error.
MT safe.
-
isActive
public boolean isActive()Check if this AudioRingBuffer is activated.MT safe.
- Returns:
- TRUE if the device is active.
-
isFlushing
public boolean isFlushing()Check if this AudioRingBuffer is flushing.MT safe.
- Returns:
- TRUE if the device is flushing.
-
mayStart
public void mayStart(boolean allowed) Tell the ringbuffer that it is allowed to start playback when the ringbuffer is filled with samples.MT safe.
- Parameters:
allowed- the new value
-
openDevice
public boolean openDevice()Open the audio device associated with the ring buffer. Does not perform any setup on the device. You must open the device before acquiring the ring buffer.- Returns:
- TRUE if the device could be opened, FALSE on error.
MT safe.
-
pause
public boolean pause()Pause processing samples from the ringbuffer.- Returns:
- TRUE if the device could be paused, FALSE on error.
MT safe.
-
prepareRead
Returns a pointer to memory where the data from segmentsegmentcan be found. This function is mostly used by subclasses.- Parameters:
segment- the segment to readreadptr- the pointer to the memory where samples can be read- Returns:
- FALSE if the buffer is not started.
MT safe.
-
read
public int read(long sample, @org.jspecify.annotations.Nullable byte @Nullable [] data, ClockTime timestamp) Readlensamples from the ringbuffer into the memory pointed to bydata.The first sample should be read from positionsamplein the ringbuffer.lenshould not be a multiple of the segment size of the ringbuffer although it is recommended.timestampwill return the timestamp associated with the data returned.- Parameters:
sample- the sample position of the datadata- where the data should be readtimestamp- where the timestamp is returned- Returns:
- The number of samples read from the ringbuffer or -1 on
error.
MT safe.
-
release
public boolean release()Free the resources of the ringbuffer.- Returns:
- TRUE if the device could be released, FALSE on error.
MT safe.
-
samplesDone
public long samplesDone()Get the number of samples that were processed by the ringbuffer since it was last started. This does not include the number of samples not yet processed (see gst_audio_ring_buffer_delay()).- Returns:
- The number of samples processed by the ringbuffer.
MT safe.
-
setCallback
Sets the given callback function on the buffer. This function will be called every time a segment has been written to a device.MT safe.
- Parameters:
cb- the callback to set- Since:
- 1.12
-
setChannelPositions
Tell the ringbuffer about the device's channel positions. This must be called in when the ringbuffer is acquired.- Parameters:
position- the device channel positions
-
setErrored
public void setErrored()Mark the ringbuffer as errored after it has started.MT safe.
- Since:
- 1.24
-
setFlushing
public void setFlushing(boolean flushing) Set the ringbuffer to flushing mode or normal mode.MT safe.
- Parameters:
flushing- the new mode
-
setSample
public void setSample(long sample) Make sure that the next sample written to the device is accounted for as being thesamplesample written to the device. This value will be used in reporting the current sample position of the ringbuffer.This function will also clear the buffer with silence.
MT safe.
- Parameters:
sample- the sample number to set
-
setSegdone
public void setSegdone(long segdone) Sets the current segment number of the ringbuffer.MT safe.
- Parameters:
segdone- the segment number to set- Since:
- 1.26
-
setTimestamp
-
start
public boolean start()Start processing samples from the ringbuffer.- Returns:
- TRUE if the device could be started, FALSE on error.
MT safe.
-
stop
public boolean stop()Stop processing samples from the ringbuffer.- Returns:
- TRUE if the device could be stopped, FALSE on error.
MT safe.
-
resume
protected boolean resume()resume processing of samples after pause
-