From 1316dd9c653dc8e6e6eff23ba922549745e4daf3 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Thu, 17 Sep 2020 22:56:01 +1000 Subject: [PATCH] splitmuxsink: Never start a new fragment with no reference buffers 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: --- gst/multifile/gstsplitmuxsink.c | 11 +++++++++-- gst/multifile/gstsplitmuxsink.h | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/gst/multifile/gstsplitmuxsink.c b/gst/multifile/gstsplitmuxsink.c index e59f568..2154ead 100644 --- a/gst/multifile/gstsplitmuxsink.c +++ b/gst/multifile/gstsplitmuxsink.c @@ -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; diff --git a/gst/multifile/gstsplitmuxsink.h b/gst/multifile/gstsplitmuxsink.h index 67df4d4..bd629bd 100644 --- a/gst/multifile/gstsplitmuxsink.h +++ b/gst/multifile/gstsplitmuxsink.h @@ -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; -- 2.7.4