mirror of https://github.com/mpv-player/mpv
demux: ensure demux_read_packet_async() always reads
In corner cases, it might be possible that a demux_read_packet_async() call fails to make the demuxer thread to read more packets. If a packet is queued, the function will simply return a packet, without marking the stream as active. As a consequence, read_packet() might decide not to read any further packets, and the demuxer will never read a packet and wake up the playback thread. This was originally done to align it with demux_read_packet() semantics; just drop this.
This commit is contained in:
parent
24efaa3ad7
commit
cfdb1312da
|
@ -462,6 +462,8 @@ struct demux_packet *demux_read_packet(struct sh_stream *sh)
|
||||||
// Poll the demuxer queue, and if there's a packet, return it. Otherwise, just
|
// Poll the demuxer queue, and if there's a packet, return it. Otherwise, just
|
||||||
// make the demuxer thread read packets for this stream, and if there's at
|
// make the demuxer thread read packets for this stream, and if there's at
|
||||||
// least one packet, call the wakeup callback.
|
// least one packet, call the wakeup callback.
|
||||||
|
// Unlike demux_read_packet(), this always enables readahead (which means you
|
||||||
|
// must not use it on interleaved subtitle streams).
|
||||||
// Returns:
|
// Returns:
|
||||||
// < 0: EOF was reached, *out_pkt=NULL
|
// < 0: EOF was reached, *out_pkt=NULL
|
||||||
// == 0: no new packet yet, but maybe later, *out_pkt=NULL
|
// == 0: no new packet yet, but maybe later, *out_pkt=NULL
|
||||||
|
@ -476,8 +478,7 @@ int demux_read_packet_async(struct sh_stream *sh, struct demux_packet **out_pkt)
|
||||||
pthread_mutex_lock(&ds->in->lock);
|
pthread_mutex_lock(&ds->in->lock);
|
||||||
*out_pkt = dequeue_packet(ds);
|
*out_pkt = dequeue_packet(ds);
|
||||||
r = *out_pkt ? 1 : (ds->eof ? -1 : 0);
|
r = *out_pkt ? 1 : (ds->eof ? -1 : 0);
|
||||||
if (r < 1 && ds->selected)
|
ds->active = ds->selected; // enable readahead
|
||||||
ds->active = true;
|
|
||||||
ds->in->eof = false; // force retry
|
ds->in->eof = false; // force retry
|
||||||
pthread_cond_signal(&ds->in->wakeup); // possibly read more
|
pthread_cond_signal(&ds->in->wakeup); // possibly read more
|
||||||
pthread_mutex_unlock(&ds->in->lock);
|
pthread_mutex_unlock(&ds->in->lock);
|
||||||
|
|
Loading…
Reference in New Issue