audiobuffersplit: Unset DISCONT flag if not discontinuous
authorSebastian Dröge <sebastian@centricular.com>
Mon, 25 May 2020 12:36:38 +0000 (15:36 +0300)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 25 May 2020 12:41:32 +0000 (12:41 +0000)
And also set/unset the RESYNC flag accordingly.

It can happen that the flag is preserved by GstAdapter from the input
buffer. For example if a big input buffer is split into many small ones,
each of the small ones would have the flag set.

All other buffer flags seem safe to keep here if they were set,
including the GAP flag.

Also ensure that the buffer is actually writable before changing any
flags or metadata on it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1298>

gst/audiobuffersplit/gstaudiobuffersplit.c

index bd66e9e..7d2738a 100644 (file)
@@ -379,10 +379,15 @@ gst_audio_buffer_split_output (GstAudioBufferSplit * self, gboolean force,
 
     size = MIN (size, avail);
     buffer = gst_adapter_take_buffer (self->adapter, size);
+    buffer = gst_buffer_make_writable (buffer);
 
     /* After a reset we have to set the discont flag */
     if (self->current_offset == 0)
-      GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
+      GST_BUFFER_FLAG_SET (buffer,
+          GST_BUFFER_FLAG_DISCONT | GST_BUFFER_FLAG_RESYNC);
+    else
+      GST_BUFFER_FLAG_UNSET (buffer,
+          GST_BUFFER_FLAG_DISCONT | GST_BUFFER_FLAG_RESYNC);
 
     resync_time_diff =
         gst_util_uint64_scale (self->current_offset, GST_SECOND, rate);