matroska-mux: Warn on late caps arrival
authorJan Schmidt <jan@centricular.com>
Wed, 1 Jul 2020 06:13:27 +0000 (16:13 +1000)
committerJan Schmidt <jan@centricular.com>
Wed, 1 Jul 2020 06:13:27 +0000 (16:13 +1000)
As well as warning when caps change after the headers
were already written, make sure to warn if the *first* caos
arrive late too.

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

gst/matroska/matroska-mux.c

index b365ebf..be76bf0 100644 (file)
@@ -977,6 +977,11 @@ gst_matroska_mux_video_pad_setcaps (GstPad * pad, GstCaps * caps)
       goto refuse_caps;
     }
     gst_caps_unref (old_caps);
+  } else if (mux->state >= GST_MATROSKA_MUX_STATE_HEADER) {
+    GST_ELEMENT_ERROR (mux, STREAM, MUX, (NULL),
+        ("Caps on pad %" GST_PTR_FORMAT
+            " arrived late. Headers were already written", pad));
+    goto refuse_caps;
   }
 
   /* find context */
@@ -1834,6 +1839,11 @@ gst_matroska_mux_audio_pad_setcaps (GstPad * pad, GstCaps * caps)
       goto refuse_caps;
     }
     gst_caps_unref (old_caps);
+  } else if (mux->state >= GST_MATROSKA_MUX_STATE_HEADER) {
+    GST_ELEMENT_ERROR (mux, STREAM, MUX, (NULL),
+        ("Caps on pad %" GST_PTR_FORMAT
+            " arrived late. Headers were already written", pad));
+    goto refuse_caps;
   }
 
   /* find context */
@@ -2270,6 +2280,11 @@ gst_matroska_mux_subtitle_pad_setcaps (GstPad * pad, GstCaps * caps)
       goto refuse_caps;
     }
     gst_caps_unref (old_caps);
+  } else if (mux->state >= GST_MATROSKA_MUX_STATE_HEADER) {
+    GST_ELEMENT_ERROR (mux, STREAM, MUX, (NULL),
+        ("Caps on pad %" GST_PTR_FORMAT
+            " arrived late. Headers were already written", pad));
+    goto refuse_caps;
   }
 
   /* find context */
@@ -2779,6 +2794,8 @@ gst_matroska_mux_track_header (GstMatroskaMux * mux,
       break;
   }
 
+  GST_DEBUG_OBJECT (mux, "Wrote track header. Codec %s", context->codec_id);
+
   gst_ebml_write_ascii (ebml, GST_MATROSKA_ID_CODECID, context->codec_id);
   if (context->codec_priv)
     gst_ebml_write_binary (ebml, GST_MATROSKA_ID_CODECPRIVATE,