Merge remote-tracking branch 'origin/master' into 0.11
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 9 Oct 2011 15:08:36 +0000 (16:08 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 9 Oct 2011 15:08:36 +0000 (16:08 +0100)
Conflicts:
tests/check/pipelines/vorbisdec.c
tests/check/pipelines/vorbisenc.c

gst-libs/gst/audio/gstaudiodecoder.c
gst-libs/gst/audio/gstaudioencoder.c
tests/check/elements/vorbisdec.c
tests/check/pipelines/vorbisdec.c
tests/check/pipelines/vorbisenc.c

index caf8d1a..183def7 100644 (file)
@@ -580,7 +580,7 @@ gst_audio_decoder_setup (GstAudioDecoder * dec)
   gst_query_unref (query);
 
   /* normalize to bool */
-  dec->priv->agg = ! !res;
+  dec->priv->agg = !!res;
 }
 
 /* mini aggregator combining output buffers into fewer larger ones,
@@ -816,17 +816,18 @@ gst_audio_decoder_finish_frame (GstAudioDecoder * dec, GstBuffer * buf,
 
       g_assert (GST_CLOCK_TIME_IS_VALID (priv->base_ts));
       next_ts = priv->base_ts +
-          gst_util_uint64_scale (samples, GST_SECOND, ctx->info.rate);
-      GST_LOG_OBJECT (dec, "buffer is %d samples past base_ts %" GST_TIME_FORMAT
-          ", expected ts %" GST_TIME_FORMAT, samples,
+          gst_util_uint64_scale (priv->samples, GST_SECOND, ctx->info.rate);
+      GST_LOG_OBJECT (dec,
+          "buffer is %" G_GUINT64_FORMAT " samples past base_ts %"
+          GST_TIME_FORMAT ", expected ts %" GST_TIME_FORMAT, priv->samples,
           GST_TIME_ARGS (priv->base_ts), GST_TIME_ARGS (next_ts));
       diff = GST_CLOCK_DIFF (next_ts, ts);
       GST_LOG_OBJECT (dec, "ts diff %d ms", (gint) (diff / GST_MSECOND));
       /* if within tolerance,
        * discard buffer ts and carry on producing perfect stream,
        * otherwise resync to ts */
-      if (G_UNLIKELY (diff < -dec->priv->tolerance ||
-              diff > dec->priv->tolerance)) {
+      if (G_UNLIKELY (diff < (gint64) - dec->priv->tolerance ||
+              diff > (gint64) dec->priv->tolerance)) {
         GST_DEBUG_OBJECT (dec, "base_ts resync");
         priv->base_ts = ts;
         priv->samples = 0;
@@ -1088,7 +1089,14 @@ gst_audio_decoder_flush (GstAudioDecoder * dec, gboolean hard)
 static GstFlowReturn
 gst_audio_decoder_chain_forward (GstAudioDecoder * dec, GstBuffer * buffer)
 {
-  GstFlowReturn ret;
+  GstFlowReturn ret = GST_FLOW_OK;
+
+  /* discard silly case, though maybe ts may be of value ?? */
+  if (G_UNLIKELY (GST_BUFFER_SIZE (buffer) == 0)) {
+    GST_DEBUG_OBJECT (dec, "discarding empty buffer");
+    gst_buffer_unref (buffer);
+    goto exit;
+  }
 
   /* grab buffer */
   gst_adapter_push (dec->priv->adapter, buffer);
@@ -1099,6 +1107,7 @@ gst_audio_decoder_chain_forward (GstAudioDecoder * dec, GstBuffer * buffer)
   /* hand to subclass */
   ret = gst_audio_decoder_push_buffers (dec, FALSE);
 
+exit:
   GST_LOG_OBJECT (dec, "chain-done");
   return ret;
 }
index 99d9c77..2a7a1af 100644 (file)
@@ -963,10 +963,12 @@ gst_audio_encoder_chain (GstPad * pad, GstBuffer * buffer)
         gst_audio_encoder_drain (enc);
       }
     }
-    /* now re-sync ts */
-    priv->base_ts += diff;
-    gst_audio_encoder_set_base_gp (enc);
-    priv->discont |= discont;
+    if (discont) {
+      /* now re-sync ts */
+      priv->base_ts += diff;
+      gst_audio_encoder_set_base_gp (enc);
+      priv->discont |= discont;
+    }
   }
 
   gst_adapter_push (enc->priv->adapter, buffer);
index ecdc329..e2db8c2 100644 (file)
@@ -94,42 +94,6 @@ cleanup_vorbisdec (GstElement * vorbisdec)
   gst_check_teardown_element (vorbisdec);
 }
 
-GST_START_TEST (test_empty_identification_header)
-{
-  GstElement *vorbisdec;
-  GstBuffer *inbuffer;
-  GstBus *bus;
-  GstMessage *message;
-
-  vorbisdec = setup_vorbisdec ();
-  bus = gst_bus_new ();
-
-  fail_unless (gst_element_set_state (vorbisdec,
-          GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
-      "could not set to playing");
-
-  inbuffer = gst_buffer_new_and_alloc (0);
-  ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
-
-  /* set a bus here so we avoid getting state change messages */
-  gst_element_set_bus (vorbisdec, bus);
-
-  fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_ERROR);
-  /* ... but it ends up being collected on the global buffer list */
-  fail_unless_equals_int (g_list_length (buffers), 0);
-
-  fail_if ((message = gst_bus_pop (bus)) == NULL);
-  fail_unless_message_error (message, STREAM, DECODE);
-  gst_message_unref (message);
-  gst_element_set_bus (vorbisdec, NULL);
-
-  /* cleanup */
-  gst_object_unref (GST_OBJECT (bus));
-  cleanup_vorbisdec (vorbisdec);
-}
-
-GST_END_TEST;
-
 /* FIXME: also tests comment header */
 GST_START_TEST (test_identification_header)
 {
@@ -329,7 +293,6 @@ vorbisdec_suite (void)
   TCase *tc_chain = tcase_create ("general");
 
   suite_add_tcase (s, tc_chain);
-  tcase_add_test (tc_chain, test_empty_identification_header);
   tcase_add_test (tc_chain, test_identification_header);
   tcase_add_test (tc_chain, test_empty_vorbis_packet);
 
index 1df6741..fd66e51 100644 (file)
@@ -54,8 +54,11 @@ GST_START_TEST (test_timestamps)
   GstBus *bus;
   GError *error = NULL;
 
+  /* allowing some tolerance permits audiodecoder to come up with
+   * perfect timestamps rather than sticking to upstream ts */
   pipe_str = g_strdup_printf ("audiotestsrc num-buffers=100"
-      " ! audio/x-raw,rate=44100 ! audioconvert ! vorbisenc ! vorbisdec"
+      " ! audio/x-raw,rate=44100 ! audioconvert ! vorbisenc "
+      " ! vorbisdec tolerance=10000000 "
       " ! identity check-imperfect-timestamp=TRUE ! fakesink");
 
   pipeline = gst_parse_launch (pipe_str, &error);
index a172479..18e1f4e 100644 (file)
@@ -267,7 +267,7 @@ drop_second_data_buffer (GstPad * droppad, GstProbeType type,
 {
   GstProbeReturn res = GST_PROBE_OK;
 
-  if (GST_BUFFER_OFFSET (buffer) == 1024)
+  if (GST_BUFFER_OFFSET (buffer) == 4096)
     res = GST_PROBE_DROP;
 
   GST_DEBUG ("dropping %d", res);
@@ -284,8 +284,10 @@ GST_START_TEST (test_discontinuity)
   GError *error = NULL;
   guint drop_id;
 
+  /* make audioencoder act sufficiently pedantic */
   pipe_str = g_strdup_printf ("audiotestsrc samplesperbuffer=1024"
-      " ! audio/x-raw,rate=44100" " ! audioconvert ! vorbisenc ! fakesink");
+      " ! audio/x-raw,rate=44100" " ! audioconvert "
+      " ! vorbisenc tolerance=10000000 ! fakesink");
 
   bin = gst_parse_launch (pipe_str, &error);
   fail_unless (bin != NULL, "Error parsing pipeline: %s",
@@ -338,38 +340,27 @@ GST_START_TEST (test_discontinuity)
   check_buffer_granulepos (buffer, 0);
   gst_buffer_unref (buffer);
 
-  /* two phases: continuous granulepos values up to 1024, then a first
-     discontinuous granulepos whose granulepos corresponds to a gap ending at
-     2048. */
   {
     GstClockTime next_timestamp = 0;
-    gint64 last_granulepos = 0;
+    gint64 last_granulepos = 0, granulepos;
+    gint i;
 
-    while (last_granulepos < 1024) {
+    for (i = 0; i < 10; i++) {
       buffer = gst_buffer_straw_get_buffer (bin, pad);
-      last_granulepos = GST_BUFFER_OFFSET_END (buffer);
+      granulepos = GST_BUFFER_OFFSET_END (buffer);
+      /* discont is either at start, or following gap */
+      if (GST_BUFFER_IS_DISCONT (buffer)) {
+        if (next_timestamp) {
+          fail_unless (granulepos - last_granulepos > 1024,
+              "expected discont of at least 1024 samples");
+          next_timestamp = GST_BUFFER_TIMESTAMP (buffer);
+        }
+      }
       check_buffer_timestamp (buffer, next_timestamp);
-      fail_if (GST_BUFFER_IS_DISCONT (buffer), "expected continuous buffer");
       next_timestamp += GST_BUFFER_DURATION (buffer);
+      last_granulepos = granulepos;
       gst_buffer_unref (buffer);
     }
-
-    fail_unless (last_granulepos == 1024,
-        "unexpected granulepos: %" G_GUINT64_FORMAT, last_granulepos);
-  }
-
-  {
-    buffer = gst_buffer_straw_get_buffer (bin, pad);
-    /* The first buffer after the discontinuity will produce zero output
-     * samples (because of the overlap/add), so it won't increment the 
-     * granulepos, which should be 2048 after the discontinuity.
-     */
-    fail_unless (GST_BUFFER_IS_DISCONT (buffer),
-        "expected discontinuous buffer");
-    fail_unless (GST_BUFFER_OFFSET_END (buffer) == 2048,
-        "expected granulepos after gap: %" G_GUINT64_FORMAT,
-        GST_BUFFER_OFFSET_END (buffer));
-    gst_buffer_unref (buffer);
   }
 
   gst_buffer_straw_stop_pipeline (bin, pad);