flac: Make buffers created during seek act like normal buffers.
authorJan Schmidt <thaytan@noraisin.net>
Mon, 20 Apr 2009 17:33:09 +0000 (18:33 +0100)
committerJan Schmidt <thaytan@noraisin.net>
Wed, 6 May 2009 13:24:20 +0000 (14:24 +0100)
Store the offset and caps when allocating a buffer during seeking, and then
allocate a new buffer with buffer_alloc before we push it out. This ensures
that in all respects the first buffer decoded during seeking behaves like
all other buffers, including allowing downstream re-negotiation.

ext/flac/gstflacdec.c

index 5f6c82c..f8eb818 100644 (file)
@@ -931,8 +931,18 @@ gst_flac_dec_write (GstFlacDec * flacdec, const FLAC__Frame * frame,
         GST_BUFFER_OFFSET (flacdec->pending),
         GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (flacdec->pending)),
         GST_TIME_ARGS (GST_BUFFER_DURATION (flacdec->pending)));
-    gst_pad_push (flacdec->srcpad, flacdec->pending);
-    flacdec->pending = NULL;
+    /* Pending buffer was always allocated from the seeking thread,
+     * which means it wasn't gst_buffer_alloc'd. Do so now to let
+     * downstream negotiation work on older basetransform */
+    ret = gst_pad_alloc_buffer_and_set_caps (flacdec->srcpad,
+        GST_BUFFER_OFFSET (flacdec->pending),
+        GST_BUFFER_SIZE (flacdec->pending),
+        GST_BUFFER_CAPS (flacdec->pending), &outbuf);
+    if (ret == GST_FLOW_OK)
+      gst_pad_push (flacdec->srcpad, outbuf);
+
+    gst_buffer_unref (flacdec->pending);
+    outbuf = flacdec->pending = NULL;
     flacdec->segment.last_stop += flacdec->pending_samples;
     flacdec->pending_samples = 0;
   }
@@ -940,7 +950,8 @@ gst_flac_dec_write (GstFlacDec * flacdec, const FLAC__Frame * frame,
   if (flacdec->seeking) {
     GST_DEBUG_OBJECT (flacdec, "a pad_alloc would block here, do normal alloc");
     outbuf = gst_buffer_new_and_alloc (samples * channels * (width / 8));
-    outbuf->offset = flacdec->segment.last_stop;
+    gst_buffer_set_caps (outbuf, GST_PAD_CAPS (flacdec->srcpad));
+    GST_BUFFER_OFFSET (outbuf) = flacdec->segment.last_stop;
   } else {
     GST_LOG_OBJECT (flacdec, "alloc_buffer_and_set_caps");
     ret = gst_pad_alloc_buffer_and_set_caps (flacdec->srcpad,