Top |
struct | GstAudioRingBuffer |
struct | GstAudioRingBufferClass |
struct | GstAudioRingBufferSpec |
enum | GstAudioRingBufferState |
enum | GstAudioRingBufferFormatType |
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.
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.
#define GST_AUDIO_RING_BUFFER_BROADCAST(buf)(g_cond_broadcast (GST_AUDIO_RING_BUFFER_GET_COND (buf)))
#define GST_AUDIO_RING_BUFFER_GET_COND(buf) (&(((GstAudioRingBuffer *)buf)->cond))
#define GST_AUDIO_RING_BUFFER_SIGNAL(buf) (g_cond_signal (GST_AUDIO_RING_BUFFER_GET_COND (buf)))
#define GST_AUDIO_RING_BUFFER_WAIT(buf) (g_cond_wait (GST_AUDIO_RING_BUFFER_GET_COND (buf), GST_OBJECT_GET_LOCK (buf)))
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.
buf |
the GstAudioRingBuffer to set the callback on |
|
cb |
the callback to set. |
[scope async] |
user_data |
user data passed to the callback |
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.
gboolean
gst_audio_ring_buffer_release (GstAudioRingBuffer *buf
);
Free the resources of the ringbuffer.
gboolean
gst_audio_ring_buffer_is_acquired (GstAudioRingBuffer *buf
);
Check if the ringbuffer is acquired and ready to use.
gboolean gst_audio_ring_buffer_activate (GstAudioRingBuffer *buf
,gboolean active
);
Activate buf
to start or stop pulling data.
MT safe.
gboolean
gst_audio_ring_buffer_is_active (GstAudioRingBuffer *buf
);
Check if buf
is activated.
MT safe.
gboolean
gst_audio_ring_buffer_start (GstAudioRingBuffer *buf
);
Start processing samples from the ringbuffer.
gboolean
gst_audio_ring_buffer_pause (GstAudioRingBuffer *buf
);
Pause processing samples from the ringbuffer.
gboolean
gst_audio_ring_buffer_stop (GstAudioRingBuffer *buf
);
Stop processing samples from the ringbuffer.
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.
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()
).
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.
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.
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. |
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
.
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.
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 |
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.
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 |
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.
void
gst_audio_ring_buffer_clear_all (GstAudioRingBuffer *buf
);
Fill the ringbuffer with silence.
MT safe.
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.
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()
.
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.
gboolean
gst_audio_ring_buffer_device_is_open (GstAudioRingBuffer *buf
);
Checks the status of the device associated with the ring buffer.
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.
gboolean gst_audio_ring_buffer_parse_caps (GstAudioRingBufferSpec *spec
,GstCaps *caps
);
Parse caps
into spec
.
void gst_audio_ring_buffer_set_flushing (GstAudioRingBuffer *buf
,gboolean flushing
);
Set the ringbuffer to flushing mode or normal mode.
MT safe.
gboolean
gst_audio_ring_buffer_is_flushing (GstAudioRingBuffer *buf
);
Check if buf
is flushing.
MT safe.
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.
void gst_audio_ring_buffer_set_timestamp (GstAudioRingBuffer *buf
,gint readseg
,GstClockTime timestamp
);
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.
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 { 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.
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 { /* 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.
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 |
The state of the ringbuffer.
The format of the samples in the ringbuffer.
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 format |
||
samples in MPEG-4 AAC format |