summaryrefslogtreecommitdiffstats
path: root/demux
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-08-05 23:41:29 +0200
committerwm4 <wm4@nowhere>2015-08-05 23:41:29 +0200
commitbeb4f8316aca2f206ce1ea743498b4241670c37d (patch)
treeda40098d6ea48641c6e3cf375971e2a66488984b /demux
parent775d81609627e4c6e091ae3761cdb1235f789276 (diff)
downloadmpv-beb4f8316aca2f206ce1ea743498b4241670c37d.tar.bz2
mpv-beb4f8316aca2f206ce1ea743498b4241670c37d.tar.xz
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.
Diffstat (limited to 'demux')
-rw-r--r--demux/demux.c6
-rw-r--r--demux/demux.h5
2 files changed, 5 insertions, 6 deletions
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);
diff --git a/demux/demux.h b/demux/demux.h
index 22c7323ef1..710073d26c 100644
--- a/demux/demux.h
+++ b/demux/demux.h
@@ -30,11 +30,6 @@
#include "packet.h"
#include "stheader.h"
-// Maximum total size of packets queued - if larger, no new packets are read,
-// and the demuxer pretends EOF was reached.
-#define MAX_PACKS 16000
-#define MAX_PACK_BYTES (400 * 1024 * 1024)
-
// DEMUXER control commands/answers
#define DEMUXER_CTRL_NOTIMPL -1
#define DEMUXER_CTRL_DONTKNOW 0