splitmuxsink: Never start a new fragment with no reference buffers
authorJan Schmidt <jan@centricular.com>
Thu, 17 Sep 2020 12:56:01 +0000 (22:56 +1000)
committerJan Schmidt <thaytan@noraisin.net>
Sat, 31 Oct 2020 02:50:50 +0000 (02:50 +0000)
If there has been no bytes from the reference stream muxed into
the current fragment, then time can't have advanced, there's no
GOP... this fragment would be broken or empty, so wait for some
data on the reference buffer.

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

gst/multifile/gstsplitmuxsink.c
gst/multifile/gstsplitmuxsink.h

index e59f568..2154ead 100644 (file)
@@ -2186,8 +2186,10 @@ need_new_fragment (GstSplitMuxSink * splitmux,
       && splitmux->muxer_has_reserved_props;
   GST_OBJECT_UNLOCK (splitmux);
 
-  /* Have we muxed anything into the new file at all? */
-  if (splitmux->fragment_total_bytes <= 0)
+  /* Have we muxed at least one thing from the reference
+   * stream into the file? If not, no other streams can have
+   * either */
+  if (splitmux->fragment_reference_bytes <= 0)
     return FALSE;
 
   /* User told us to split now */
@@ -2361,6 +2363,7 @@ handle_gathered_gop (GstSplitMuxSink * splitmux)
     new_out_ts = splitmux->reference_ctx->in_running_time;
     splitmux->fragment_start_time = splitmux->gop_start_time;
     splitmux->fragment_total_bytes = 0;
+    splitmux->fragment_reference_bytes = 0;
 
     if (splitmux->tc_interval) {
       video_time_code_replace (&splitmux->fragment_start_tc,
@@ -2800,6 +2803,9 @@ handle_mq_input (GstPad * pad, GstPadProbeInfo * info, MqStreamCtx * ctx)
 
   /* Update total input byte counter for overflow detect */
   splitmux->gop_total_bytes += buf_info->buf_size;
+  if (ctx->is_reference) {
+    splitmux->fragment_reference_bytes += buf_info->buf_size;
+  }
 
   /* Now add this buffer to the queue just before returning */
   g_queue_push_head (&ctx->queued_bufs, buf_info);
@@ -3494,6 +3500,7 @@ gst_splitmux_sink_reset (GstSplitMuxSink * splitmux)
       GST_CLOCK_STIME_NONE;
   splitmux->max_out_running_time = 0;
   splitmux->fragment_total_bytes = 0;
+  splitmux->fragment_reference_bytes = 0;
   splitmux->gop_total_bytes = 0;
   splitmux->muxed_out_bytes = 0;
   splitmux->ready_for_output = FALSE;
index 67df4d4..bd629bd 100644 (file)
@@ -144,6 +144,10 @@ struct _GstSplitMuxSink
   /* Number of bytes sent to the
    * current fragment */
   guint64 fragment_total_bytes;
+  /* Number of bytes for the reference
+   * stream in this fragment */
+  guint64 fragment_reference_bytes;
+
   /* Number of bytes we've collected into
    * the GOP that's being collected */
   guint64 gop_total_bytes;