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.
This commit is contained in:
wm4 2019-05-24 02:03:12 +02:00
parent a3ac2019ed
commit e2ae3676c2
1 changed files with 14 additions and 16 deletions

View File

@ -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)