interaudiosink: Ensure adapters don't store buffers with audio meta
authorPhilippe Normand <philn@igalia.com>
Wed, 27 Sep 2023 10:33:39 +0000 (12:33 +0200)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 28 Sep 2023 13:14:38 +0000 (15:14 +0200)
The interaudiosrc might take buffers of different sizes from the audio adapter,
so keeping metas consistency would be an issue. So the sink now strips the audio
metas away and the src adds them back (for non-interleaved layouts only) when
taking buffers from the adapter.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5416>

subprojects/gst-integration-testsuites/testsuites/validate.testslist
subprojects/gst-integration-testsuites/testsuites/validate/inter/audio-planar.validatetest [new file with mode: 0644]
subprojects/gst-plugins-bad/gst/inter/gstinteraudiosink.c

index c5e5438..02f22cc 100644 (file)
@@ -936,6 +936,7 @@ validate.test.h264.parse.trickmode_predicted.seek_trickmode_predicted
 validate.test.h264.x264enc_youtube_bitrate.fullhd_lowframerate
 validate.test.h265parse.alternate
 validate.test.h265parse.trickmode_predicted.seek_trickmode_predicted
+validate.test.inter.audio-planar
 validate.test.interlace.interlace_deinterlace
 validate.test.interlace.interlace_deinterlace_alternate
 validate.test.matroska.demux_flush_within_cluster.default
diff --git a/subprojects/gst-integration-testsuites/testsuites/validate/inter/audio-planar.validatetest b/subprojects/gst-integration-testsuites/testsuites/validate/inter/audio-planar.validatetest
new file mode 100644 (file)
index 0000000..42e2c48
--- /dev/null
@@ -0,0 +1,4 @@
+meta,
+  args = {
+       "audiotestsrc num-buffers=10 ! audio/x-raw,format=S16LE,channels=2,layout=non-interleaved ! interaudiosink interaudiosrc num-buffers=10 ! audioconvert ! audio/x-raw,layout=interleaved,format=S16LE,channels=2 ! queue ! fakeaudiosink",
+  }
index a33fe81..6c654e8 100644 (file)
@@ -293,6 +293,7 @@ gst_inter_audio_sink_render (GstBaseSink * sink, GstBuffer * buffer)
   guint n, bpf;
   guint64 period_time, buffer_time;
   guint64 period_samples, buffer_samples;
+  GstBuffer *tmp;
 
   GST_DEBUG_OBJECT (interaudiosink, "render %" G_GSIZE_FORMAT,
       gst_buffer_get_size (buffer));
@@ -330,16 +331,26 @@ gst_inter_audio_sink_render (GstBaseSink * sink, GstBuffer * buffer)
 
   n = gst_adapter_available (interaudiosink->input_adapter);
   if (period_samples * bpf > gst_buffer_get_size (buffer) + n) {
-    gst_adapter_push (interaudiosink->input_adapter, gst_buffer_ref (buffer));
+    GstAudioMeta *audio_meta = NULL;
+
+    tmp = gst_buffer_copy_deep (buffer);
+    audio_meta = gst_buffer_get_audio_meta (tmp);
+    if (audio_meta != NULL)
+      gst_buffer_remove_meta (tmp, GST_META_CAST (audio_meta));
+
+    gst_adapter_push (interaudiosink->input_adapter, tmp);
   } else {
-    GstBuffer *tmp;
+    GstAudioMeta *audio_meta = NULL;
 
     if (n > 0) {
       tmp = gst_adapter_take_buffer (interaudiosink->input_adapter, n);
       gst_adapter_push (interaudiosink->surface->audio_adapter, tmp);
     }
-    gst_adapter_push (interaudiosink->surface->audio_adapter,
-        gst_buffer_ref (buffer));
+    tmp = gst_buffer_copy_deep (buffer);
+    audio_meta = gst_buffer_get_audio_meta (tmp);
+    if (audio_meta != NULL)
+      gst_buffer_remove_meta (tmp, GST_META_CAST (audio_meta));
+    gst_adapter_push (interaudiosink->surface->audio_adapter, tmp);
   }
   g_mutex_unlock (&interaudiosink->surface->mutex);