From e2a6573c7d5f274e2c0d17e2612100e9582975c5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 3 Apr 2017 16:47:58 +0300 Subject: [PATCH] dashdemux: Smooth out skip distances in keyframe-only trick modes This ensures smoother playback. It looks weird if we first do a big jump, then play a couple of consecutive frames, just to again skip ahead quite a bit because we ran late again. --- ext/dash/gstdashdemux.c | 29 ++++++++++++++++++++++++++++- ext/dash/gstdashdemux.h | 2 ++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ext/dash/gstdashdemux.c b/ext/dash/gstdashdemux.c index 869ffc6482..a3f4c0e84f 100644 --- a/ext/dash/gstdashdemux.c +++ b/ext/dash/gstdashdemux.c @@ -1886,7 +1886,7 @@ gst_dash_demux_stream_get_target_time (GstDashDemux * dashdemux, "Advancing to %" GST_TIME_FORMAT " (was %" GST_TIME_FORMAT ")", GST_TIME_ARGS (ret), GST_TIME_ARGS (min_position)); - return ret; + goto out; } /* Figure out the difference, in running time, between where we are and @@ -1926,6 +1926,31 @@ gst_dash_demux_stream_get_target_time (GstDashDemux * dashdemux, GST_TIME_ARGS (ret), GST_TIME_ARGS (min_position)); } +out: + + { + GstClockTime cur_skip = + (cur_position < ret) ? ret - cur_position : cur_position - ret; + + if (dashstream->average_skip_size == 0) { + dashstream->average_skip_size = cur_skip; + } else { + dashstream->average_skip_size = + (cur_skip + 3 * dashstream->average_skip_size) / 4; + } + + if (dashstream->average_skip_size > + cur_skip + dashstream->keyframe_average_distance + && dashstream->average_skip_size > min_skip) { + if (stream->segment.rate > 0) + ret = cur_position + dashstream->average_skip_size; + else if (cur_position > dashstream->average_skip_size) + ret = cur_position - dashstream->average_skip_size; + else + ret = 0; + } + } + return ret; } @@ -2320,7 +2345,9 @@ gst_dash_demux_seek (GstAdaptiveDemux * demux, GstEvent * seek) /* Update the current sequence on all streams */ for (iter = streams; iter; iter = g_list_next (iter)) { GstAdaptiveDemuxStream *stream = iter->data; + GstDashDemuxStream *dashstream = iter->data; + dashstream->average_skip_size = 0; if (gst_dash_demux_stream_seek (stream, rate >= 0, 0, target_pos, NULL) != GST_FLOW_OK) return FALSE; diff --git a/ext/dash/gstdashdemux.h b/ext/dash/gstdashdemux.h index 6d65ea31aa..bcd073fb3c 100644 --- a/ext/dash/gstdashdemux.h +++ b/ext/dash/gstdashdemux.h @@ -110,6 +110,8 @@ struct _GstDashDemuxStream GstClockTime average_download_time; /* Cached target time (only in trickmode-key-units) */ GstClockTime target_time; + /* Average skip-ahead time (only in trickmode-key-units) */ + GstClockTime average_skip_size; }; /** -- 2.34.1