diff options
author | wm4 <wm4@nowhere> | 2019-05-24 02:03:12 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2019-09-19 20:37:04 +0200 |
commit | e2ae3676c2e30a7665642f9f7912544cc2dd44f1 (patch) | |
tree | 808c057827d8020a48608d1bc0c90da37bb887ad /demux | |
parent | a3ac2019eddbfa7d763c6da808c1cf0ebda18c53 (diff) | |
download | mpv-e2ae3676c2e30a7665642f9f7912544cc2dd44f1.tar.bz2 mpv-e2ae3676c2e30a7665642f9f7912544cc2dd44f1.tar.xz |
demux: remove minor code duplication
This code used to be simpler, but now it's enough that it should be
factored into a single function.
Both uses of the new function are annoyingly different. The first use is
the special case when a decoder tries to read packets, but the demuxer
doesn't see any (like mp4 files with sparse video packets, which
actually turned out to be chapter thumbnail "tracks"). Then the other
stream queues will overflow, and the stream with no packets is marked
EOF to avoid stalling playback.
The second case is when the demxuer returns global EOF.
It would be more awkward to have the loop iterating the streams in the
function, because then you'd need a weird parameter to control the
behavior.
Diffstat (limited to 'demux')
-rw-r--r-- | demux/demux.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/demux/demux.c b/demux/demux.c index 6711920811..703ddb6ad7 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -1903,6 +1903,16 @@ static void add_packet_locked(struct sh_stream *stream, demux_packet_t *dp) wakeup_ds(ds); } +static void mark_stream_eof(struct demux_stream *ds) +{ + if (!ds->eof) { + ds->eof = true; + adjust_seek_range_on_packet(ds, NULL); + back_demux_see_packets(ds); + wakeup_ds(ds); + } +} + // Returns true if there was "progress" (lock was released temporarily). static bool read_packet(struct demux_internal *in) { @@ -1955,13 +1965,8 @@ static bool read_packet(struct demux_internal *in) } for (int n = 0; n < in->num_streams; n++) { struct demux_stream *ds = in->streams[n]->ds; - bool eof = !ds->reader_head; - if (!ds->eof && eof) { - ds->eof = true; - adjust_seek_range_on_packet(ds, NULL); - back_demux_see_packets(ds); - wakeup_ds(ds); - } + if (!ds->reader_head) + mark_stream_eof(ds); } return false; } @@ -1998,15 +2003,8 @@ static bool read_packet(struct demux_internal *in) if (!in->seeking) { if (eof) { - for (int n = 0; n < in->num_streams; n++) { - struct demux_stream *ds = in->streams[n]->ds; - if (!ds->eof) { - ds->eof = true; - adjust_seek_range_on_packet(ds, NULL); - back_demux_see_packets(ds); - wakeup_ds(ds); - } - } + for (int n = 0; n < in->num_streams; n++) + mark_stream_eof(in->streams[n]->ds); // If we had EOF previously, then don't wakeup (avoids wakeup loop) if (!in->last_eof) { if (in->wakeup_cb) |