From a821e72b81029767414ed8c661532f41350cbce7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 5 Nov 2014 03:03:27 +0100 Subject: demux: report 0s readahead time as fallback in some situations If no packets are queued, the readahead time is obviously 0. If the end time is smaller than the start time, the problem is probably that audio and video start at slightly different times - report 0 in this case too. Do this because seeing "???" as readahead time is a bit annoying. --- demux/demux.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/demux/demux.c b/demux/demux.c index b170b731c0..d3e9b43903 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1218,6 +1218,7 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg) .ts_range = {MP_NOPTS_VALUE, MP_NOPTS_VALUE}, .ts_duration = -1, }; + int num_packets = 0; for (int n = 0; n < in->d_user->num_streams; n++) { struct demux_stream *ds = in->d_user->streams[n]->ds; if (ds->active) { @@ -1226,12 +1227,15 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg) r->ts_range[0] = MP_PTS_MAX(r->ts_range[0], ds->base_ts); r->ts_range[1] = MP_PTS_MIN(r->ts_range[1], ds->last_ts); } + num_packets += ds->packs; } } r->idle = (in->idle && !r->underrun) || r->eof; r->underrun &= !r->idle; if (r->ts_range[0] != MP_NOPTS_VALUE && r->ts_range[1] != MP_NOPTS_VALUE) - r->ts_duration = r->ts_range[1] - r->ts_range[0]; + r->ts_duration = MPMAX(0, r->ts_range[1] - r->ts_range[0]); + if (!num_packets || in->seeking) + r->ts_duration = 0; return DEMUXER_CTRL_OK; } } -- cgit v1.2.3