From beb4f8316aca2f206ce1ea743498b4241670c37d Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 5 Aug 2015 23:41:29 +0200 Subject: demux: add options to control maximum queue size Add --demuxer-max-packets and --demuxer-max-bytes, which control the maximum size of the packet queue. These can be helpful to avoid excessive memory usage. Memory usage is the reason why there's a limit in the first place. If a file is more or less broken, and audio and video don't line up, the decoders will fill up the packet queue trying to read more audio or video, and the maximum sizes are required to avoid unbounded memory allocation. Being able to override the maximum sizes is useful; either for restricting memory usage further, or enlarging the sizes when attempting to play various broken files. --- demux/demux.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'demux/demux.c') diff --git a/demux/demux.c b/demux/demux.c index 55dfd259da..fedc533926 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -112,6 +112,8 @@ struct demux_internal { bool idle; bool autoselect; double min_secs; + int max_packs; + int max_bytes; bool tracks_switched; // thread needs to inform demuxer of this @@ -391,7 +393,7 @@ static bool read_packet(struct demux_internal *in) } MP_DBG(in, "packets=%zd, bytes=%zd, active=%d, more=%d\n", packs, bytes, active, read_more); - if (packs >= MAX_PACKS || bytes >= MAX_PACK_BYTES) { + if (packs >= in->max_packs || bytes >= in->max_bytes) { if (!in->warned_queue_overflow) { in->warned_queue_overflow = true; MP_ERR(in, "Too many packets in the demuxer packet queues:\n"); @@ -957,6 +959,8 @@ static struct demuxer *open_given_type(struct mpv_global *global, .d_buffer = talloc(demuxer, struct demuxer), .d_user = demuxer, .min_secs = demuxer->opts->demuxer_min_secs, + .max_packs = demuxer->opts->demuxer_max_packs, + .max_bytes = demuxer->opts->demuxer_max_bytes, }; pthread_mutex_init(&in->lock, NULL); pthread_cond_init(&in->wakeup, NULL); -- cgit v1.2.3