GstAudio.AudioRingBuffer¶
- Subclasses:
None
Methods¶
- Inherited:
- Structs:
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Properties¶
- Inherited:
Signals¶
- Inherited:
Fields¶
- Inherited:
Name |
Type |
Access |
Description |
---|---|---|---|
acquired |
r |
boolean indicating that the ringbuffer is acquired |
|
active |
r |
||
callback |
r |
||
cb_data |
r |
||
cb_data_notify |
r |
||
channel_reorder_map |
[ |
r |
|
cond |
r |
used to signal start/stop/pause/resume actions |
|
empty_seg |
r |
pointer to memory holding one segment of silence samples |
|
flushing |
r |
||
memory |
r |
data in the ringbuffer |
|
need_reorder |
r |
||
object |
r |
||
open |
r |
boolean indicating that the ringbuffer is open |
|
samples_per_seg |
r |
number of samples in one segment |
|
segbase |
r |
segment corresponding to segment 0 (unused) |
|
segdone |
r |
readpointer in the ringbuffer |
|
size |
r |
size of data in the ringbuffer |
|
spec |
r |
format and layout of the ringbuffer data |
|
state |
r |
state of the buffer |
|
timestamps |
r |
||
waiting |
r |
is a reader or writer waiting for a free segment |
Class Details¶
- class GstAudio.AudioRingBuffer(**kwargs)¶
- Bases:
- Abstract:
Yes
- Structure:
This object is the base class for audio ringbuffers used by the base audio source and sink classes.
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.
- classmethod debug_spec_buff(spec)[source]¶
- Parameters:
spec (
GstAudio.AudioRingBufferSpec
) – the spec to debug
Print debug info about the buffer sized in spec to the debug log.
- classmethod debug_spec_caps(spec)[source]¶
- Parameters:
spec (
GstAudio.AudioRingBufferSpec
) – the spec to debug
Print debug info about the parsed caps in spec to the debug log.
- classmethod parse_caps(spec, caps)[source]¶
- Parameters:
spec (
GstAudio.AudioRingBufferSpec
) – a spec
- Returns:
True
if the caps could be parsed.- Return type:
Parse caps into spec.
- acquire(spec)[source]¶
- Parameters:
spec (
GstAudio.AudioRingBufferSpec
) – the specs of the buffer- Returns:
True
if the device could be acquired,False
on error.MT safe.
- Return type:
Allocate the resources for the ringbuffer. This function fills in the data pointer of the ring buffer with a valid
Gst.Buffer
to which samples can be written.
- activate(active)[source]¶
- Parameters:
active (
bool
) – the new mode- Returns:
True
if the device could be activated in the requested mode,False
on error.- Return type:
Activate self to start or stop pulling data.
MT safe.
- advance(advance)[source]¶
- Parameters:
advance (
int
) – the number of segments written
Subclasses should call this function to notify the fact that advance segments are now processed by the device.
MT safe.
- clear(segment)[source]¶
- Parameters:
segment (
int
) – the segment to clear
Clear the given segment of the buffer with silence samples. This function is used by subclasses.
MT safe.
- close_device()[source]¶
-
Close the audio device associated with the ring buffer. The ring buffer should already have been released via
GstAudio.AudioRingBuffer.release
().
- commit(sample, data, out_samples, accum)[source]¶
- Parameters:
- Returns:
The number of samples written to the ringbuffer or -1 on error. The number of samples written can be less than out_samples when self was interrupted with a flush or stop.
- sample:
the sample position of the data
- accum:
accumulator for rate conversion.
- Return type:
Commit in_samples samples pointed to by data to the ringbuffer self.
in_samples and out_samples define the rate conversion to perform on the samples in data. For negative rates, out_samples must be negative and in_samples positive.
When out_samples is positive, the first sample will be written at position sample in the ringbuffer. When out_samples is negative, the last sample will be written to sample in reverse order.
out_samples 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 returned accum value back to this function.
MT safe.
- convert(src_fmt, src_val, dest_fmt)[source]¶
- Parameters:
src_fmt (
Gst.Format
) – the source formatsrc_val (
int
) – the source valuedest_fmt (
Gst.Format
) – the destination format
- Returns:
True
if the conversion succeeded.- dest_val:
a location to store the converted value
- Return type:
Convert src_val in src_fmt to the equivalent value in dest_fmt. The result will be put in dest_val.
- delay()[source]¶
- Returns:
The number of samples queued in the audio device.
MT safe.
- Return type:
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.
- may_start(allowed)[source]¶
- Parameters:
allowed (
bool
) – the new value
Tell the ringbuffer that it is allowed to start playback when the ringbuffer is filled with samples.
MT safe.
- open_device()[source]¶
-
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.
- prepare_read()[source]¶
- Returns:
False
if the buffer is not started.MT safe.
- segment:
the segment to read
- readptr:
the pointer to the memory where samples can be read
- Return type:
Returns a pointer to memory where the data from segment segment can be found. This function is mostly used by subclasses.
- read(sample, data)[source]¶
- Parameters:
- Returns:
The number of samples read from the ringbuffer or -1 on error.
MT safe.
- timestamp:
where the timestamp is returned
- Return type:
Read len samples from the ringbuffer into the memory pointed to by data. The first sample should be read from position sample 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.
- samples_done()[source]¶
- Returns:
The number of samples processed by the ringbuffer.
MT safe.
- Return type:
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
GstAudio.AudioRingBuffer.delay
()).
- set_callback(cb, *user_data)[source]¶
- Parameters:
cb (
GstAudio.AudioRingBufferCallback
orNone
) – the callback to setuser_data (
object
orNone
) – user data passed to the callback
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.
New in version 1.12.
- set_channel_positions(position)[source]¶
- Parameters:
position ([
GstAudio.AudioChannelPosition
]) – the device channel positions
Tell the ringbuffer about the device’s channel positions. This must be called in when the ringbuffer is acquired.
- set_errored()[source]¶
Mark the ringbuffer as errored after it has started.
MT safe.
New in version 1.24.
- set_flushing(flushing)[source]¶
- Parameters:
flushing (
bool
) – the new mode
Set the ringbuffer to flushing mode or normal mode.
MT safe.
- set_sample(sample)[source]¶
- Parameters:
sample (
int
) – the sample number to set
Make sure that the next sample written to the device is accounted for as being the sample 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.
- do_acquire(spec) virtual¶
- Parameters:
spec (
GstAudio.AudioRingBufferSpec
) – the specs of the buffer- Returns:
True
if the device could be acquired,False
on error.MT safe.
- Return type:
Allocate the resources for the ringbuffer. This function fills in the data pointer of the ring buffer with a valid
Gst.Buffer
to which samples can be written.
- do_activate(active) virtual¶
- Parameters:
active (
bool
) – the new mode- Returns:
True
if the device could be activated in the requested mode,False
on error.- Return type:
Activate buf to start or stop pulling data.
MT safe.
- do_clear_all() virtual¶
Clear all samples from the ringbuffer.
MT safe.
- do_close_device() virtual¶
-
Close the audio device associated with the ring buffer. The ring buffer should already have been released via
GstAudio.AudioRingBuffer.release
().
- do_commit(sample, data, out_samples, accum) virtual¶
- Parameters:
- Returns:
The number of samples written to the ringbuffer or -1 on error. The number of samples written can be less than out_samples when buf was interrupted with a flush or stop.
- sample:
the sample position of the data
- accum:
accumulator for rate conversion.
- Return type:
Commit in_samples samples pointed to by data to the ringbuffer buf.
in_samples and out_samples define the rate conversion to perform on the samples in data. For negative rates, out_samples must be negative and in_samples positive.
When out_samples is positive, the first sample will be written at position sample in the ringbuffer. When out_samples is negative, the last sample will be written to sample in reverse order.
out_samples 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 returned accum value back to this function.
MT safe.
- do_delay() virtual¶
- Returns:
The number of samples queued in the audio device.
MT safe.
- Return type:
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.
- do_open_device() virtual¶
-
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.
- do_pause() virtual¶
-
Pause processing samples from the ringbuffer.
- do_release() virtual¶
-
Free the resources of the ringbuffer.
- do_start() virtual¶
-
Start processing samples from the ringbuffer.