From 58383229756a8871fb312c0897914e45e5824fc1 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 1 Nov 2016 14:28:36 +0100 Subject: demux: improve buffer estimation in a corner case This deals with the estimation of buffered packets, which is used mostly for display, but also things like pausing on low buffer levels. If a stream is fully EOF (no more packets), we don't want to include it in the total buffer amount. This also means we should make ds->eof less flaky and more stable, so don't reset it in ds_get_packets() (this function reset ds->eof just to retrigger a packet read attempt - we can have this slightly simpler). This somewhat fixes buffering display when e.g. issuing a refresh seek after re-enabling audio/video when playing with subtitles only. --- demux/demux.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'demux') diff --git a/demux/demux.c b/demux/demux.c index 5072eb9f05..8aa9989de3 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -681,8 +681,7 @@ static void ds_get_packets(struct demux_stream *ds) struct demux_internal *in = ds->in; MP_DBG(in, "reading packet for %s\n", t); in->eof = false; // force retry - ds->eof = false; - while (ds->selected && !ds->head && !ds->eof) { + while (ds->selected && !ds->head) { ds->active = true; // Note: the following code marks EOF if it can't continue if (in->threading) { @@ -692,6 +691,8 @@ static void ds_get_packets(struct demux_stream *ds) } else { read_packet(in); } + if (ds->eof) + break; } } @@ -1662,7 +1663,7 @@ static int cached_demux_control(struct demux_internal *in, int cmd, void *arg) int num_packets = 0; for (int n = 0; n < in->num_streams; n++) { struct demux_stream *ds = in->streams[n]->ds; - if (ds->active) { + if (ds->active && !(!ds->head && ds->eof)) { r->underrun |= !ds->head && !ds->eof; 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); -- cgit v1.2.3