summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2020-05-20 13:17:13 +0300
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>2020-05-20 18:46:41 +0000
commit2c278bb2ab498216ef444a9b22ea85631ad43f0f (patch)
tree1f51046f4c4588521d74b6ad0084cf77618b351d
parent0bb9880b36053411dd37dc3cc822331eb01ee675 (diff)
flvdemux: Send gap events if one of the streams falls behind the other by more than 3s
Same mechanism and threshold as in other demuxers. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/597>
-rw-r--r--gst/flv/gstflvdemux.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/gst/flv/gstflvdemux.c b/gst/flv/gstflvdemux.c
index 6607990096..e71e3367b9 100644
--- a/gst/flv/gstflvdemux.c
+++ b/gst/flv/gstflvdemux.c
@@ -1028,6 +1028,51 @@ gst_flv_demux_update_resync (GstFlvDemux * demux, guint32 dts, gboolean discont,
return ret;
}
+static void
+gst_flv_demux_sync_streams (GstFlvDemux * demux)
+{
+ /* Check if the audio or video stream are more than 3s behind the other
+ * stream, and if so send a gap event accordingly */
+
+ if (demux->audio_pad && GST_CLOCK_TIME_IS_VALID (demux->segment.position) &&
+ demux->last_audio_pts * GST_MSECOND + demux->audio_time_offset +
+ 3 * GST_SECOND < demux->segment.position) {
+ GstEvent *event;
+ guint64 start =
+ demux->last_audio_pts * GST_MSECOND + demux->audio_time_offset;
+ guint64 stop = demux->segment.position - 3 * GST_SECOND;
+
+ GST_DEBUG_OBJECT (demux,
+ "Synchronizing audio stream with video stream by advancing time from %"
+ GST_TIME_FORMAT " to %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
+ GST_TIME_ARGS (stop));
+
+ demux->last_audio_pts = (stop - demux->audio_time_offset) / GST_MSECOND;
+
+ event = gst_event_new_gap (start, stop - start);
+ gst_pad_push_event (demux->audio_pad, event);
+ }
+
+ if (demux->video_pad && GST_CLOCK_TIME_IS_VALID (demux->segment.position) &&
+ demux->last_video_dts * GST_MSECOND + demux->video_time_offset +
+ 3 * GST_SECOND < demux->segment.position) {
+ GstEvent *event;
+ guint64 start =
+ demux->last_video_dts * GST_MSECOND + demux->video_time_offset;
+ guint64 stop = demux->segment.position - 3 * GST_SECOND;
+
+ GST_DEBUG_OBJECT (demux,
+ "Synchronizing video stream with audio stream by advancing time from %"
+ GST_TIME_FORMAT " to %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
+ GST_TIME_ARGS (stop));
+
+ demux->last_video_dts = (stop - demux->video_time_offset) / GST_MSECOND;
+
+ event = gst_event_new_gap (start, stop - start);
+ gst_pad_push_event (demux->video_pad, event);
+ }
+}
+
static GstFlowReturn
gst_flv_demux_parse_tag_audio (GstFlvDemux * demux, GstBuffer * buffer)
{
@@ -1325,6 +1370,10 @@ gst_flv_demux_parse_tag_audio (GstFlvDemux * demux, GstBuffer * buffer)
ret = gst_flow_combiner_update_pad_flow (demux->flowcombiner,
demux->audio_pad, ret);
+ if (ret == GST_FLOW_OK) {
+ gst_flv_demux_sync_streams (demux);
+ }
+
beach:
gst_buffer_unmap (buffer, &map);
@@ -1760,6 +1809,10 @@ gst_flv_demux_parse_tag_video (GstFlvDemux * demux, GstBuffer * buffer)
ret = gst_flow_combiner_update_pad_flow (demux->flowcombiner,
demux->video_pad, ret);
+ if (ret == GST_FLOW_OK) {
+ gst_flv_demux_sync_streams (demux);
+ }
+
beach:
gst_buffer_unmap (buffer, &map);
return ret;