diff mbox

[FFmpeg-devel,4/6] dashdec: Correct seeking behaviour

Message ID 47CF0C07-7CCC-4DB6-819E-8C444A891D60@chinaffmpeg.org
State Accepted
Commit 74b143d81fa38cd4f05a0db889a19a2cb7ff226c
Headers show

Commit Message

Liu Steven Jan. 8, 2018, 2:57 a.m. UTC
> On 8 Jan 2018, at 02:46, Stefan _ <sfan5@live.de> wrote:
> 
> 
> <0004-dashdec-Correct-seeking-behaviour.patch>_______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

>From bdf3557a400620fce66ca0237f1ff172c227609b Mon Sep 17 00:00:00 2001
From: sfan5 <sfan5@live.de>
Date: Fri, 5 Jan 2018 00:51:32 +0100
Subject: [PATCH 4/6] dashdec: Correct seeking behaviour

dash_read_seek() is called only once to issue a seek
of *all* streams to the specified timestamp. But to
avoid reopening each stream, do a "dry run" for streams
that are in a discarded state.
---
 libavformat/dashdec.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
diff mbox

Patch

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index ac0e6c6f9..1252d4156 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -1828,19 +1828,22 @@  static int dash_close(AVFormatContext *s)
     return 0;
 }
 
-static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags)
+static int dash_seek(AVFormatContext *s, struct representation *pls, int64_t seek_pos_msec, int flags, int dry_run)
 {
     int ret = 0;
     int i = 0;
     int j = 0;
     int64_t duration = 0;
 
-    av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms], playlist %d\n", seek_pos_msec, pls->rep_idx);
+    av_log(pls->parent, AV_LOG_VERBOSE, "DASH seek pos[%"PRId64"ms], playlist %d%s\n",
+            seek_pos_msec, pls->rep_idx, dry_run ? " (dry)" : "");
 
     // single fragment mode
     if (pls->n_fragments == 1) {
         pls->cur_timestamp = 0;
         pls->cur_seg_offset = 0;
+        if (dry_run)
+            return 0;
         ff_read_frame_flush(pls->ctx);
         return av_seek_frame(pls->ctx, -1, seek_pos_msec * 1000, flags);
     }
@@ -1885,14 +1888,14 @@  set_seq_num:
     pls->cur_timestamp = 0;
     pls->cur_seg_offset = 0;
     pls->init_sec_buf_read_offset = 0;
-    ret = reopen_demux_for_component(s, pls);
+    ret = dry_run ? 0 : reopen_demux_for_component(s, pls);
 
     return ret;
 }
 
 static int dash_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
 {
-    int ret, i;
+    int ret = 0, i;
     DASHContext *c = s->priv_data;
     int64_t seek_pos_msec = av_rescale_rnd(timestamp, 1000,
                                            s->streams[stream_index]->time_base.den,
@@ -1901,16 +1904,14 @@  static int dash_read_seek(AVFormatContext *s, int stream_index, int64_t timestam
     if ((flags & AVSEEK_FLAG_BYTE) || c->is_live)
         return AVERROR(ENOSYS);
 
-    ret = AVERROR_EOF;
+    /* Seek in discarded streams with dry_run=1 to avoid reopening them */
     for (i = 0; i < c->n_videos; i++) {
-        if (c->videos[i]->stream_index == stream_index) {
-            ret = dash_seek(s, c->videos[i], seek_pos_msec, flags);
-        }
+        if (!ret)
+            ret = dash_seek(s, c->videos[i], seek_pos_msec, flags, !c->videos[i]->ctx);
     }
     for (i = 0; i < c->n_audios; i++) {
-        if (c->audios[i]->stream_index == stream_index) {
-            ret = dash_seek(s, c->audios[i], seek_pos_msec, flags);
-        }
+        if (!ret)
+            ret = dash_seek(s, c->audios[i], seek_pos_msec, flags, !c->audios[i]->ctx);
     }
 
     return ret;