[FFmpeg-cvslog] dashdec: Correct seeking behaviour
sfan5
git at videolan.org
Sun Jan 14 16:58:17 EET 2018
ffmpeg | branch: master | sfan5 <sfan5 at live.de> | Sun Jan 14 22:36:02 2018 +0800| [74b143d81fa38cd4f05a0db889a19a2cb7ff226c] | committer: Steven Liu
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.
Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=74b143d81fa38cd4f05a0db889a19a2cb7ff226c
---
libavformat/dashdec.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index f1012d51b5..05b6021474 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -1826,19 +1826,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);
}
@@ -1883,14 +1886,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,
@@ -1899,16 +1902,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;
More information about the ffmpeg-cvslog
mailing list