From f15a79d14467d8c30dcaffa53d8871ef01b9328e Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 18 Jan 2016 18:25:14 +0100 Subject: demux: fix interleaved subtitle reading in unthreaded mode Meh. Why are there even two code paths. This adds an additional check; the big function is only moved. --- demux/demux.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'demux/demux.c') diff --git a/demux/demux.c b/demux/demux.c index 4fedc69e60..de59a6dc28 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -667,6 +667,21 @@ static struct demux_packet *dequeue_packet(struct demux_stream *ds) return pkt; } +// Sparse packets (Subtitles) interleaved with other non-sparse packets (video, +// audio) should never be read actively, meaning the demuxer thread does not +// try to exceed default readahead in order to find a new packet. +static bool use_lazy_subtitle_reading(struct demux_stream *ds) +{ + if (ds->type != STREAM_SUB) + return false; + for (int n = 0; n < ds->in->num_streams; n++) { + struct demux_stream *s = ds->in->streams[n]->ds; + if (s->type != STREAM_SUB && s->selected && !s->eof) + return true; + } + return false; +} + // Read a packet from the given stream. The returned packet belongs to the // caller, who has to free it with talloc_free(). Might block. Returns NULL // on EOF. @@ -676,7 +691,8 @@ struct demux_packet *demux_read_packet(struct sh_stream *sh) struct demux_packet *pkt = NULL; if (ds) { pthread_mutex_lock(&ds->in->lock); - ds_get_packets(ds); + if (!use_lazy_subtitle_reading(ds)) + ds_get_packets(ds); pkt = dequeue_packet(ds); pthread_cond_signal(&ds->in->wakeup); // possibly read more pthread_mutex_unlock(&ds->in->lock); @@ -684,21 +700,6 @@ struct demux_packet *demux_read_packet(struct sh_stream *sh) return pkt; } -// Sparse packets (Subtitles) interleaved with other non-sparse packets (video, -// audio) should never be read actively, meaning the demuxer thread does not -// try to exceed default readahead in order to find a new packet. -static bool use_lazy_subtitle_reading(struct demux_stream *ds) -{ - if (ds->type != STREAM_SUB) - return false; - for (int n = 0; n < ds->in->num_streams; n++) { - struct demux_stream *s = ds->in->streams[n]->ds; - if (s->type != STREAM_SUB && s->selected && !s->eof) - return true; - } - return false; -} - // 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 // least one packet, call the wakeup callback. -- cgit v1.2.3