From 45e06fe7043de83e8db56c161a2d01b5816596f4 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Sat, 3 Jun 2006 21:06:49 +0000 Subject: [PATCH] gst-libs/gst/audio/: Document better the fact that latency_time and buffer_time are values stored in microseconds, an... Original commit message from CVS: * gst-libs/gst/audio/gstbaseaudiosink.c: (gst_base_audio_sink_class_init), (gst_base_audio_sink_setcaps): * gst-libs/gst/audio/gstbaseaudiosink.h: * gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_parse_caps), (gst_ring_buffer_samples_done): * gst-libs/gst/audio/gstringbuffer.h: Document better the fact that latency_time and buffer_time are values stored in microseconds, and not the usual GStreamer nanoseconds. Change the variables (compatibly) that store them from GstClockTime to guint64 to make it more clear that they're not storing clock times. Also, remove the bogus property description that says the user can specify -1 to get the default value, since that's never been the case. When computing the default segment size for the ring buffer, make it an integer number of samples. When the sub-class indicates a delay greater than the number of samples we've written return 0 from the audio sink get_time method. --- ChangeLog | 21 +++++++++++++++ gst-libs/gst/audio/gstbaseaudiosink.c | 38 +++++++++++---------------- gst-libs/gst/audio/gstbaseaudiosink.h | 6 ++--- gst-libs/gst/audio/gstringbuffer.c | 13 ++++++--- gst-libs/gst/audio/gstringbuffer.h | 8 +++--- 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1502bb6067..2fea98aada 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2006-06-03 Jan Schmidt + + * gst-libs/gst/audio/gstbaseaudiosink.c: + (gst_base_audio_sink_class_init), (gst_base_audio_sink_setcaps): + * gst-libs/gst/audio/gstbaseaudiosink.h: + * gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_parse_caps), + (gst_ring_buffer_samples_done): + * gst-libs/gst/audio/gstringbuffer.h: + Document better the fact that latency_time and buffer_time are values + stored in microseconds, and not the usual GStreamer nanoseconds. + Change the variables (compatibly) that store them from GstClockTime + to guint64 to make it more clear that they're not storing clock times. + Also, remove the bogus property description that says the user can + specify -1 to get the default value, since that's never been the case. + + When computing the default segment size for the ring buffer, make it + an integer number of samples. + + When the sub-class indicates a delay greater than the number of + samples we've written return 0 from the audio sink get_time method. + 2006-06-02 Michael Smith * tests/check/elements/audioconvert.c: (set_channel_positions), diff --git a/gst-libs/gst/audio/gstbaseaudiosink.c b/gst-libs/gst/audio/gstbaseaudiosink.c index 6f54981d27..d8627d146f 100644 --- a/gst-libs/gst/audio/gstbaseaudiosink.c +++ b/gst-libs/gst/audio/gstbaseaudiosink.c @@ -39,12 +39,13 @@ enum * and sample offset position. * This is an emergency resync fallback since buffers marked as DISCONT will * always lock to the correct timestamp immediatly and buffers not marked as - * DISCONT are contiguous bu definition. + * DISCONT are contiguous by definition. */ #define DIFF_TOLERANCE 2 -#define DEFAULT_BUFFER_TIME 200 * GST_USECOND -#define DEFAULT_LATENCY_TIME 10 * GST_USECOND +/* FIXME: 0.11, store the buffer_time and latency_time in nanoseconds */ +#define DEFAULT_BUFFER_TIME ((200 * GST_MSECOND) / GST_USECOND) +#define DEFAULT_LATENCY_TIME ((10 * GST_MSECOND) / GST_USECOND) #define DEFAULT_PROVIDE_CLOCK TRUE enum @@ -100,8 +101,6 @@ gst_base_audio_sink_base_init (gpointer g_class) static void gst_base_audio_sink_class_init (GstBaseAudioSinkClass * klass) { - gchar *longdesc; - GObjectClass *gobject_class; GstElementClass *gstelement_class; GstBaseSinkClass *gstbasesink_class; @@ -116,21 +115,16 @@ gst_base_audio_sink_class_init (GstBaseAudioSinkClass * klass) GST_DEBUG_FUNCPTR (gst_base_audio_sink_get_property); gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_base_audio_sink_dispose); - longdesc = - g_strdup_printf - ("Size of audio buffer in microseconds (use -1 for default of %" - G_GUINT64_FORMAT " us)", DEFAULT_BUFFER_TIME / GST_USECOND); g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_BUFFER_TIME, - g_param_spec_int64 ("buffer-time", "Buffer Time", longdesc, -1, + g_param_spec_int64 ("buffer-time", "Buffer Time", + "Size of audio buffer in microseconds", 1, G_MAXINT64, DEFAULT_BUFFER_TIME, G_PARAM_READWRITE)); - g_free (longdesc); - longdesc = - g_strdup_printf ("Audio latency in microseconds (use -1 for default of %" - G_GUINT64_FORMAT " us)", DEFAULT_LATENCY_TIME / GST_USECOND); + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_LATENCY_TIME, - g_param_spec_int64 ("latency-time", "Latency Time", longdesc, -1, + g_param_spec_int64 ("latency-time", "Latency Time", + "Audio latency in microseconds", 1, G_MAXINT64, DEFAULT_LATENCY_TIME, G_PARAM_READWRITE)); - g_free (longdesc); + g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_PROVIDE_CLOCK, g_param_spec_boolean ("provide-clock", "Provide Clock", "Provide a clock to be used as the global pipeline clock", @@ -318,12 +312,12 @@ gst_base_audio_sink_setcaps (GstBaseSink * bsink, GstCaps * caps) if (!gst_ring_buffer_acquire (sink->ringbuffer, spec)) goto acquire_error; - /* calculate actual latency and buffer times */ - spec->latency_time = - spec->segsize * GST_MSECOND / (spec->rate * spec->bytes_per_sample); - spec->buffer_time = - spec->segtotal * spec->segsize * GST_MSECOND / (spec->rate * - spec->bytes_per_sample); + /* calculate actual latency and buffer times. + * FIXME: In 0.11, store the latency_time internally in ns */ + spec->latency_time = gst_util_uint64_scale (spec->segsize, + (GST_SECOND / GST_USECOND), spec->rate * spec->bytes_per_sample); + + spec->buffer_time = spec->segtotal * spec->latency_time; gst_ring_buffer_debug_spec_buff (spec); diff --git a/gst-libs/gst/audio/gstbaseaudiosink.h b/gst-libs/gst/audio/gstbaseaudiosink.h index 3c157413ce..4e0c554b1b 100644 --- a/gst-libs/gst/audio/gstbaseaudiosink.h +++ b/gst-libs/gst/audio/gstbaseaudiosink.h @@ -76,9 +76,9 @@ struct _GstBaseAudioSink { /* our ringbuffer */ GstRingBuffer *ringbuffer; - /* required buffer and latency */ - GstClockTime buffer_time; - GstClockTime latency_time; + /* required buffer and latency in microseconds */ + guint64 buffer_time; + guint64 latency_time; /* the next sample to write */ guint64 next_sample; diff --git a/gst-libs/gst/audio/gstringbuffer.c b/gst-libs/gst/audio/gstringbuffer.c index 14f7c09719..99ee587a72 100644 --- a/gst-libs/gst/audio/gstringbuffer.c +++ b/gst-libs/gst/audio/gstringbuffer.c @@ -341,9 +341,14 @@ gst_ring_buffer_parse_caps (GstRingBufferSpec * spec, GstCaps * caps) g_return_val_if_fail (spec->latency_time != 0, FALSE); - /* calculate suggested segsize and segtotal */ - spec->segsize = - spec->rate * spec->bytes_per_sample * spec->latency_time / GST_MSECOND; + /* calculate suggested segsize and segtotal. segsize should be one unit + * of 'latency_time' samples, scaling for the fact that latency_time is + * currently stored in microseconds (FIXME: in 0.11) */ + spec->segsize = gst_util_uint64_scale (spec->rate * spec->bytes_per_sample, + spec->latency_time, GST_SECOND / GST_USECOND); + /* Round to an integer number of samples */ + spec->segsize -= spec->segsize % spec->bytes_per_sample; + spec->segtotal = spec->buffer_time / spec->latency_time; gst_ring_buffer_debug_spec_caps (spec); @@ -1003,6 +1008,8 @@ gst_ring_buffer_samples_done (GstRingBuffer * buf) if (G_LIKELY (samples >= delay)) samples -= delay; + else + samples = 0; GST_DEBUG_OBJECT (buf, "processed samples: raw %llu, delay %u, real %llu", raw, delay, samples); diff --git a/gst-libs/gst/audio/gstringbuffer.h b/gst-libs/gst/audio/gstringbuffer.h index 8dfb5a1a40..38652e1a0e 100644 --- a/gst-libs/gst/audio/gstringbuffer.h +++ b/gst-libs/gst/audio/gstringbuffer.h @@ -156,8 +156,8 @@ typedef enum * @depth: th depth of the samples * @rate: the samplerate * @channels: the number of channels - * @latency_time: the latency in time units - * @buffer_time: the total buffer size in time units + * @latency_time: the latency in microseconds + * @buffer_time: the total buffer size in microseconds * @segsize: the size of one segment in bytes * @segtotal: the total number of segments * @bytes_per_sample: number of bytes in one sample @@ -181,8 +181,8 @@ struct _GstRingBufferSpec gint rate; gint channels; - GstClockTime latency_time; /* the required/actual latency time */ - GstClockTime buffer_time; /* the required/actual time of the buffer */ + guint64 latency_time; /* the required/actual latency time */ + guint64 buffer_time; /* the required/actual time of the buffer */ gint segsize; /* size of one buffer segement */ gint segtotal; /* total number of segments */