Top |
Functions
Types and Values
struct | GstAudioRingBuffer |
struct | GstAudioRingBufferClass |
struct | GstAudioRingBufferSpec |
enum | GstAudioRingBufferState |
enum | GstAudioRingBufferFormatType |
Description
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.
Functions
GstAudioRingBufferCallback ()
void (*GstAudioRingBufferCallback) (GstAudioRingBuffer *rbuf
,guint8 *data
,guint len
,gpointer user_data
);
This function is set with gst_audio_ring_buffer_set_callback()
and is
called to fill the memory at data
with len
bytes of samples.
GST_AUDIO_RING_BUFFER_BROADCAST()
#define GST_AUDIO_RING_BUFFER_BROADCAST(buf)(g_cond_broadcast (GST_AUDIO_RING_BUFFER_GET_COND (buf)))
GST_AUDIO_RING_BUFFER_GET_COND()
#define GST_AUDIO_RING_BUFFER_GET_COND(buf) (&(((GstAudioRingBuffer *)buf)->cond))
GST_AUDIO_RING_BUFFER_SIGNAL()
#define GST_AUDIO_RING_BUFFER_SIGNAL(buf) (g_cond_signal (GST_AUDIO_RING_BUFFER_GET_COND (buf)))
GST_AUDIO_RING_BUFFER_WAIT()
#define GST_AUDIO_RING_BUFFER_WAIT(buf) (g_cond_wait (GST_AUDIO_RING_BUFFER_GET_COND (buf), GST_OBJECT_GET_LOCK (buf)))
gst_audio_ring_buffer_set_callback ()
void gst_audio_ring_buffer_set_callback (GstAudioRingBuffer *buf
,GstAudioRingBufferCallback cb
,gpointer user_data
);
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.
[skip]
Parameters
buf |
the GstAudioRingBuffer to set the callback on |
|
cb |
the callback to set. |
[allow-none] |
user_data |
user data passed to the callback |
gst_audio_ring_buffer_set_callback_full ()
void gst_audio_ring_buffer_set_callback_full (GstAudioRingBuffer *buf
,GstAudioRingBufferCallback cb
,gpointer user_data
,GDestroyNotify notify
);
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.
[rename-to gst_audio_ring_buffer_set_callback]
Parameters
buf |
the GstAudioRingBuffer to set the callback on |
|
cb |
the callback to set. |
[allow-none] |
user_data |
user data passed to the callback |
|
notify |
function to be called when |
Since: 1.12
gst_audio_ring_buffer_acquire ()
gboolean gst_audio_ring_buffer_acquire (GstAudioRingBuffer *buf
,GstAudioRingBufferSpec *spec
);
Allocate the resources for the ringbuffer. This function fills in the data pointer of the ring buffer with a valid GstBuffer to which samples can be written.
gst_audio_ring_buffer_release ()
gboolean
gst_audio_ring_buffer_release (GstAudioRingBuffer *buf
);
Free the resources of the ringbuffer.
gst_audio_ring_buffer_is_acquired ()
gboolean
gst_audio_ring_buffer_is_acquired (GstAudioRingBuffer *buf
);
Check if the ringbuffer is acquired and ready to use.
gst_audio_ring_buffer_activate ()
gboolean gst_audio_ring_buffer_activate (GstAudioRingBuffer *buf
,gboolean active
);
Activate buf
to start or stop pulling data.
MT safe.
gst_audio_ring_buffer_is_active ()
gboolean
gst_audio_ring_buffer_is_active (GstAudioRingBuffer *buf
);
Check if buf
is activated.
MT safe.
gst_audio_ring_buffer_start ()
gboolean
gst_audio_ring_buffer_start (GstAudioRingBuffer *buf
);
Start processing samples from the ringbuffer.
gst_audio_ring_buffer_pause ()
gboolean
gst_audio_ring_buffer_pause (GstAudioRingBuffer *buf
);
Pause processing samples from the ringbuffer.
gst_audio_ring_buffer_stop ()
gboolean
gst_audio_ring_buffer_stop (GstAudioRingBuffer *buf
);
Stop processing samples from the ringbuffer.
gst_audio_ring_buffer_delay ()
guint
gst_audio_ring_buffer_delay (GstAudioRingBuffer *buf
);
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 transfered 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 transfered to the ringbuffer.
gst_audio_ring_buffer_samples_done ()
guint64
gst_audio_ring_buffer_samples_done (GstAudioRingBuffer *buf
);
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()
).
gst_audio_ring_buffer_set_sample ()
void gst_audio_ring_buffer_set_sample (GstAudioRingBuffer *buf
,guint64 sample
);
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.
gst_audio_ring_buffer_commit ()
guint gst_audio_ring_buffer_commit (GstAudioRingBuffer *buf
,guint64 *sample
,guint8 *data
,gint in_samples
,gint out_samples
,gint *accum
);
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.
Parameters
buf |
the GstAudioRingBuffer to commit |
|
sample |
the sample position of the data |
|
data |
the data to commit |
|
in_samples |
the number of samples in the data to commit |
|
out_samples |
the number of samples to write to the ringbuffer |
|
accum |
accumulator for rate conversion. |
gst_audio_ring_buffer_convert ()
gboolean gst_audio_ring_buffer_convert (GstAudioRingBuffer *buf
,GstFormat src_fmt
,gint64 src_val
,GstFormat dest_fmt
,gint64 *dest_val
);
Convert src_val
in src_fmt
to the equivalent value in dest_fmt
. The result
will be put in dest_val
.
gst_audio_ring_buffer_prepare_read ()
gboolean gst_audio_ring_buffer_prepare_read (GstAudioRingBuffer *buf
,gint *segment
,guint8 **readptr
,gint *len
);
Returns a pointer to memory where the data from segment segment
can be found. This function is mostly used by subclasses.
Parameters
buf |
the GstAudioRingBuffer to read from |
|
segment |
the segment to read |
|
readptr |
the pointer to the memory where samples can be read |
|
len |
the number of bytes to read |
gst_audio_ring_buffer_read ()
guint gst_audio_ring_buffer_read (GstAudioRingBuffer *buf
,guint64 sample
,guint8 *data
,guint len
,GstClockTime *timestamp
);
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.
Parameters
buf |
the GstAudioRingBuffer to read from |
|
sample |
the sample position of the data |
|
data |
where the data should be read |
|
len |
the number of samples in data to read |
|
timestamp |
where the timestamp is returned |
gst_audio_ring_buffer_clear ()
void gst_audio_ring_buffer_clear (GstAudioRingBuffer *buf
,gint segment
);
Clear the given segment of the buffer with silence samples. This function is used by subclasses.
MT safe.
gst_audio_ring_buffer_clear_all ()
void
gst_audio_ring_buffer_clear_all (GstAudioRingBuffer *buf
);
Fill the ringbuffer with silence.
MT safe.
gst_audio_ring_buffer_advance ()
void gst_audio_ring_buffer_advance (GstAudioRingBuffer *buf
,guint advance
);
Subclasses should call this function to notify the fact that
advance
segments are now processed by the device.
MT safe.
gst_audio_ring_buffer_close_device ()
gboolean
gst_audio_ring_buffer_close_device (GstAudioRingBuffer *buf
);
Close the audio device associated with the ring buffer. The ring buffer
should already have been released via gst_audio_ring_buffer_release()
.
gst_audio_ring_buffer_open_device ()
gboolean
gst_audio_ring_buffer_open_device (GstAudioRingBuffer *buf
);
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.
gst_audio_ring_buffer_device_is_open ()
gboolean
gst_audio_ring_buffer_device_is_open (GstAudioRingBuffer *buf
);
Checks the status of the device associated with the ring buffer.
gst_audio_ring_buffer_may_start ()
void gst_audio_ring_buffer_may_start (GstAudioRingBuffer *buf
,gboolean allowed
);
Tell the ringbuffer that it is allowed to start playback when the ringbuffer is filled with samples.
MT safe.
gst_audio_ring_buffer_parse_caps ()
gboolean gst_audio_ring_buffer_parse_caps (GstAudioRingBufferSpec *spec
,GstCaps *caps
);
Parse caps
into spec
.
gst_audio_ring_buffer_set_flushing ()
void gst_audio_ring_buffer_set_flushing (GstAudioRingBuffer *buf
,gboolean flushing
);
Set the ringbuffer to flushing mode or normal mode.
MT safe.
gst_audio_ring_buffer_is_flushing ()
gboolean
gst_audio_ring_buffer_is_flushing (GstAudioRingBuffer *buf
);
Check if buf
is flushing.
MT safe.
gst_audio_ring_buffer_set_channel_positions ()
void gst_audio_ring_buffer_set_channel_positions (GstAudioRingBuffer *buf
,const GstAudioChannelPosition *position
);
Tell the ringbuffer about the device's channel positions. This must be called in when the ringbuffer is acquired.
gst_audio_ring_buffer_set_timestamp ()
void gst_audio_ring_buffer_set_timestamp (GstAudioRingBuffer *buf
,gint readseg
,GstClockTime timestamp
);
Types and Values
struct GstAudioRingBuffer
struct GstAudioRingBuffer { GCond cond; gboolean open; gboolean acquired; guint8 *memory; gsize size; GstClockTime *timestamps; GstAudioRingBufferSpec spec; gint samples_per_seg; guint8 *empty_seg; gint state; gint segdone; gint segbase; gint waiting; };
The ringbuffer base class structure.
Members
GCond |
used to signal start/stop/pause/resume actions |
|
gboolean |
boolean indicating that the ringbuffer is open |
|
gboolean |
boolean indicating that the ringbuffer is acquired |
|
guint8 * |
data in the ringbuffer |
|
gsize |
size of data in the ringbuffer |
|
GstClockTime * |
||
GstAudioRingBufferSpec |
format and layout of the ringbuffer data |
|
gint |
number of samples in one segment |
|
guint8 * |
pointer to memory holding one segment of silence samples |
|
gint |
state of the buffer |
|
gint |
readpointer in the ringbuffer |
|
gint |
segment corresponding to segment 0 (unused) |
|
gint |
is a reader or writer waiting for a free segment |
struct GstAudioRingBufferClass
struct GstAudioRingBufferClass { GstObjectClass parent_class; gboolean (*open_device) (GstAudioRingBuffer *buf); gboolean (*acquire) (GstAudioRingBuffer *buf, GstAudioRingBufferSpec *spec); gboolean (*release) (GstAudioRingBuffer *buf); gboolean (*close_device) (GstAudioRingBuffer *buf); gboolean (*start) (GstAudioRingBuffer *buf); gboolean (*pause) (GstAudioRingBuffer *buf); gboolean (*resume) (GstAudioRingBuffer *buf); gboolean (*stop) (GstAudioRingBuffer *buf); guint (*delay) (GstAudioRingBuffer *buf); /* ABI added */ gboolean (*activate) (GstAudioRingBuffer *buf, gboolean active); guint (*commit) (GstAudioRingBuffer * buf, guint64 *sample, guint8 * data, gint in_samples, gint out_samples, gint * accum); void (*clear_all) (GstAudioRingBuffer * buf); };
The vmethods that subclasses can override to implement the ringbuffer.
Members
open the device, don't set any params or allocate anything |
||
allocate the resources for the ringbuffer using the given spec |
||
free resources of the ringbuffer |
||
close the device |
||
start processing of samples |
||
pause processing of samples |
||
resume processing of samples after pause |
||
stop processing of samples |
||
get number of frames queued in device |
||
activate the thread that starts pulling and monitoring the consumed segments in the device. |
||
write samples into the ringbuffer |
||
clear the entire ringbuffer. |
struct GstAudioRingBufferSpec
struct GstAudioRingBufferSpec { /* in */ GstCaps *caps; /* the caps of the buffer */ /* in/out */ GstAudioRingBufferFormatType type; GstAudioInfo info; guint64 latency_time; /* the required/actual latency time, this is the * actual the size of one segment and the * minimum possible latency we can achieve. */ guint64 buffer_time; /* the required/actual time of the buffer, this is * the total size of the buffer and maximum * latency we can compensate for. */ gint segsize; /* size of one buffer segment in bytes, this value * should be chosen to match latency_time as * well as possible. */ gint segtotal; /* total number of segments, this value is the * number of segments of @segsize and should be * chosen so that it matches buffer_time as * close as possible. */ /* ABI added 0.10.20 */ gint seglatency; /* number of segments queued in the lower * level device, defaults to segtotal. */ };
The structure containing the format specification of the ringbuffer.
Members
GstCaps * |
The caps that generated the Spec. |
|
the sample type |
||
GstAudioInfo |
the GstAudioInfo |
|
guint64 |
the latency in microseconds |
|
guint64 |
the total buffer size in microseconds |
|
gint |
the size of one segment in bytes |
|
gint |
the total number of segments |
|
gint |
number of segments queued in the lower level device, defaults to segtotal |
enum GstAudioRingBufferState
The state of the ringbuffer.
enum GstAudioRingBufferFormatType
The format of the samples in the ringbuffer.
Members
samples in linear or float |
||
samples in mulaw |
||
samples in alaw |
||
samples in ima adpcm |
||
samples in mpeg audio (but not AAC) format |
||
samples in gsm format |
||
samples in IEC958 frames (e.g. AC3) |
||
samples in AC3 format |
||
samples in EAC3 format |
||
samples in DTS format |
||
samples in MPEG-2 AAC ADTS format |
||
samples in MPEG-4 AAC ADTS format |
||
samples in MPEG-2 AAC raw format (Since 1.12) |
||
samples in MPEG-4 AAC raw format (Since 1.12) |
||
samples in FLAC format (Since 1.12) |