summaryrefslogtreecommitdiffstats
path: root/demux/demux.c
diff options
context:
space:
mode:
Diffstat (limited to 'demux/demux.c')
-rw-r--r--demux/demux.c33
1 files changed, 17 insertions, 16 deletions
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.