matroskamux: Consider audio buffers as keyframes when writing out simpleblocks
authorSebastian Dröge <sebastian@centricular.com>
Tue, 31 Dec 2024 09:49:21 +0000 (11:49 +0200)
committerSebastian Dröge <sebastian@centricular.com>
Mon, 6 Jan 2025 15:29:26 +0000 (17:29 +0200)
Otherwise mpv complains and considers the file broken.

Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/4142

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

subprojects/gst-plugins-good/gst/matroska/matroska-mux.c
subprojects/gst-plugins-good/tests/check/elements/matroskamux.c

index e66a6becb2df5206c44f6ce2ef4edef9c4313905..0fccd55a5fcf6bfaa004156564395b5dcf8f90a2 100644 (file)
@@ -4023,7 +4023,7 @@ gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad,
   guint64 block_duration, duration_diff = 0;
   gboolean is_video_keyframe = FALSE;
   gboolean is_video_invisible = FALSE;
-  gboolean is_audio_only = FALSE;
+  gboolean is_audio_only = FALSE, is_audio = FALSE;
   gboolean is_min_duration_reached = FALSE;
   gboolean is_max_duration_exceeded = FALSE;
   GstMatroskamuxPad *pad;
@@ -4110,6 +4110,7 @@ gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad,
   buffer_timestamp += mux->cluster_timestamp_offset;
 
   is_audio_only = gst_matroska_pads_is_audio_only (mux);
+  is_audio = collect_pad->track->type == GST_MATROSKA_TRACK_TYPE_AUDIO;
 
   is_min_duration_reached = (mux->min_cluster_duration == 0
       || (buffer_timestamp > mux->cluster_time
@@ -4271,7 +4272,7 @@ gst_matroska_mux_write_data (GstMatroskaMux * mux, GstMatroskaPad * collect_pad,
     flags |= 0x08;
 
   if (mux->doctype_version > 1 && !write_duration && !cmeta) {
-    if (is_video_keyframe)
+    if (is_video_keyframe || is_audio)
       flags |= 0x80;
 
     hdr =
index fa53c7ad6878b53489227f9a877679e73977a12f..c6ac0ef8a65ff62caa78d969d0b888188eef8f81 100644 (file)
@@ -59,8 +59,8 @@ seekable_sinkpad_query (GstPad * pad, GstObject * parent, GstQuery * query)
 
 #define compare_buffer_to_data(buffer, data, data_size)             \
 G_STMT_START {                                                      \
-fail_unless_equals_int (data_size, gst_buffer_get_size (buffer));   \
-fail_unless (gst_buffer_memcmp (buffer, 0, data, data_size) == 0);  \
+  fail_unless_equals_int (data_size, gst_buffer_get_size (buffer)); \
+  fail_unless (gst_buffer_memcmp (buffer, 0, data, data_size) == 0);\
 } G_STMT_END
 
 static void
@@ -227,7 +227,7 @@ GST_END_TEST;
 
 GST_START_TEST (test_block_group_v2)
 {
-  guint8 data0_v2[] = { 0xa3, 0x85, 0x81, 0x00, 0x01, 0x00 };
+  guint8 data0_v2[] = { 0xa3, 0x85, 0x81, 0x00, 0x01, 0x80 };
 
   test_block_group_with_version (2, data0_v2, sizeof (data0_v2));
 }
@@ -307,10 +307,10 @@ GST_START_TEST (test_timecodescale)
 {
   GstBuffer *inbuffer, *outbuffer;
   guint8 data_h0[] = {
-    0xa3, 0x85, 0x81, 0x00, 0x00, 0x00,
+    0xa3, 0x85, 0x81, 0x00, 0x00, 0x80,
   };
   guint8 data_h1[] = {
-    0xa3, 0x85, 0x81, 0x00, 0x01, 0x00,
+    0xa3, 0x85, 0x81, 0x00, 0x01, 0x80,
   };
 
   GstHarness *h = setup_matroskamux_harness (AC3_CAPS_STRING);