Class AudioRingBuffer
- All Implemented Interfaces:
Proxy
- Direct Known Subclasses:
AudioRingBuffer.AudioRingBufferImpl
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
Modifier and TypeClassDescriptionstatic class
The vmethods that subclasses can override to implement the ringbuffer.static class
The AudioRingBufferImpl type represents a native instance of the abstract AudioRingBuffer class.static class
AudioRingBuffer.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.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
ConstructorDescriptionAudioRingBuffer
(MemorySegment address) Create a AudioRingBuffer proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionboolean
acquire
(AudioRingBufferSpec spec) Allocate the resources for the ringbuffer.boolean
activate
(boolean active) Activate this AudioRingBuffer to start or stop pulling data.void
advance
(int advance) Subclasses should call this function to notify the fact thatadvance
segments are now processed by the device.protected AudioRingBuffer
asParent()
Returns this instance as if it were its parent type.static AudioRingBuffer.Builder
<? extends AudioRingBuffer.Builder> builder()
AAudioRingBuffer.Builder
object constructs aAudioRingBuffer
with the specified properties.void
clear
(int segment) Clear the given segment of the buffer with silence samples.void
clearAll()
Clear all samples from the ringbuffer.boolean
Close the audio device associated with the ring buffer.int
CommitinSamples
samples pointed to bydata
to the ringbuffer this AudioRingBuffer.boolean
ConvertsrcVal
insrcFmt
to the equivalent value indestFmt
.static void
Print debug info about the buffer sized inspec
to the debug log.static void
Print debug info about the parsed caps inspec
to the debug log.int
delay()
Get the number of samples queued in the audio device.boolean
Checks the status of the device associated with the ring buffer.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the AudioRingBuffer classboolean
Check if the ringbuffer is acquired and ready to use.boolean
isActive()
Check if this AudioRingBuffer is activated.boolean
Check if this AudioRingBuffer is flushing.void
mayStart
(boolean allowed) Tell the ringbuffer that it is allowed to start playback when the ringbuffer is filled with samples.boolean
Open the audio device associated with the ring buffer.static boolean
parseCaps
(AudioRingBufferSpec spec, Caps caps) Parsecaps
intospec
.boolean
pause()
Pause processing samples from the ringbuffer.boolean
prepareRead
(Out<Integer> segment, Out<byte[]> readptr) Returns a pointer to memory where the data from segmentsegment
can be found.int
Readlen
samples from the ringbuffer into the memory pointed to bydata
.boolean
release()
Free the resources of the ringbuffer.protected boolean
resume()
resume processing of samples after pauselong
Get the number of samples that were processed by the ringbuffer since it was last started.void
setCallback
(@Nullable AudioRingBufferCallback cb) Sets the given callback function on the buffer.void
setChannelPositions
(AudioChannelPosition[] position) Tell the ringbuffer about the device's channel positions.void
Mark the ringbuffer as errored after it has started.void
setFlushing
(boolean flushing) Set the ringbuffer to flushing mode or normal mode.void
setSample
(long sample) Make sure that the next sample written to the device is accounted for as being thesample
sample written to the device.void
setTimestamp
(int readseg, ClockTime timestamp) boolean
start()
Start processing samples from the ringbuffer.boolean
stop()
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, 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
-
AudioRingBuffer
Create a AudioRingBuffer 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. -
debugSpecBuff
Print debug info about the buffer sized inspec
to the debug log.- Parameters:
spec
- the spec to debug
-
debugSpecCaps
Print debug info about the parsed caps inspec
to the debug log.- Parameters:
spec
- the spec to debug
-
parseCaps
Parsecaps
intospec
.- 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 validGstBuffer
to 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 thatadvance
segments 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
CommitinSamples
samples pointed to bydata
to the ringbuffer this AudioRingBuffer.inSamples
andoutSamples
define the rate conversion to perform on the samples indata
. For negative rates,outSamples
must be negative andinSamples
positive.When
outSamples
is positive, the first sample will be written at positionsample
in the ringbuffer. WhenoutSamples
is negative, the last sample will be written tosample
in reverse order.outSamples
does not need to be a multiple of the segment size of the ringbuffer although it is recommended for optimal performance.accum
will 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 returnedaccum
value 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
outSamples
when this AudioRingBuffer was interrupted with a flush or stop.
-
convert
ConvertsrcVal
insrcFmt
to 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.
-
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 segmentsegment
can 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
Readlen
samples from the ringbuffer into the memory pointed to bydata
. The first sample should be read from positionsample
in the ringbuffer.len
should not be a multiple of the segment size of the ringbuffer although it is recommended.timestamp
will 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
-
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.
-
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 thesample
sample 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
-
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 -
builder
AAudioRingBuffer.Builder
object constructs aAudioRingBuffer
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withAudioRingBuffer.Builder.build()
.
-