gst-libs/gst/audio/: Document better the fact that latency_time and buffer_time are...
authorJan Schmidt <thaytan@mad.scientist.com>
Sat, 3 Jun 2006 21:06:49 +0000 (21:06 +0000)
committerJan Schmidt <thaytan@mad.scientist.com>
Sat, 3 Jun 2006 21:06:49 +0000 (21:06 +0000)
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
gst-libs/gst/audio/gstbaseaudiosink.c
gst-libs/gst/audio/gstbaseaudiosink.h
gst-libs/gst/audio/gstringbuffer.c
gst-libs/gst/audio/gstringbuffer.h

index 1502bb6..2fea98a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2006-06-03  Jan Schmidt  <thaytan@mad.scientist.com>
+
+       * 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  <msmith@fluendo.com>
 
        * tests/check/elements/audioconvert.c: (set_channel_positions),
index 6f54981..d8627d1 100644 (file)
@@ -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);
 
index 3c15741..4e0c554 100644 (file)
@@ -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;
index 14f7c09..99ee587 100644 (file)
@@ -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);
index 8dfb5a1..38652e1 100644 (file)
@@ -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 */