From cccfac47a423cbaeda04f9864c4676ed1c9d5002 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 4 Aug 2013 23:25:54 +0200 Subject: demux_lavf: make avio buffer configurable Perhaps not very useful, but reserved for situations when a user reports awful latency and experimentation/debugging might be required to find out why or to fix it (happens often). --- DOCS/man/en/options.rst | 6 ++++++ core/options.h | 1 + demux/demux_lavf.c | 14 ++++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/DOCS/man/en/options.rst b/DOCS/man/en/options.rst index 7f5faa88fb..14cb2ace67 100644 --- a/DOCS/man/en/options.rst +++ b/DOCS/man/en/options.rst @@ -614,6 +614,12 @@ case of MPEG-TS this value identifies the maximum number of TS packets to scan. +``--demuxer-lavf-buffersize=`` + Size of the stream read buffer allocated for libavformat in bytes + (default: 32768). Lowering the size could lower latency. Note that + libavformat might reallocate the buffer internally, or not fully use all + of it. + ``--demuxer-lavf-cryptokey=`` Encryption key the demuxer should use. This is the raw binary data of the key converted to a hexadecimal string. diff --git a/core/options.h b/core/options.h index 2037d6da4b..9a8deb9e4d 100644 --- a/core/options.h +++ b/core/options.h @@ -216,6 +216,7 @@ typedef struct MPOpts { int probesize; int probescore; float analyzeduration; + int buffersize; int allow_mimetype; char *format; char *cryptokey; diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 11e17f949f..1654562bd9 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -51,10 +51,16 @@ #define OPT_BASE_STRUCT struct MPOpts +// Should correspond to IO_BUFFER_SIZE in libavformat/aviobuf.c (not public) +// libavformat (almost) always reads data in blocks of this size. +#define BIO_BUFFER_SIZE 32768 + const m_option_t lavfdopts_conf[] = { OPT_INTRANGE("probesize", lavfdopts.probesize, 0, 32, INT_MAX), OPT_STRING("format", lavfdopts.format, 0), OPT_FLOATRANGE("analyzeduration", lavfdopts.analyzeduration, 0, 0, 3600), + OPT_INTRANGE("buffersize", lavfdopts.buffersize, 0, 1, 10 * 1024 * 1024, + OPTDEF_INT(BIO_BUFFER_SIZE)), OPT_FLAG("allow-mimetype", lavfdopts.allow_mimetype, 0), OPT_INTRANGE("probescore", lavfdopts.probescore, 0, 0, 100), OPT_STRING("cryptokey", lavfdopts.cryptokey, 0), @@ -64,10 +70,6 @@ const m_option_t lavfdopts_conf[] = { {NULL, NULL, 0, 0, 0, 0, NULL} }; -// Should correspond to IO_BUFFER_SIZE in libavformat/aviobuf.c (not public) -// libavformat (almost) always reads data in blocks of this size. -#define BIO_BUFFER_SIZE 32768 - #define MAX_PKT_QUEUE 50 typedef struct lavf_priv { @@ -570,10 +572,10 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) if (!(priv->avif->flags & AVFMT_NOFILE) && demuxer->stream->type != STREAMTYPE_AVDEVICE) { - void *buffer = av_malloc(BIO_BUFFER_SIZE); + void *buffer = av_malloc(lavfdopts->buffersize); if (!buffer) return -1; - priv->pb = avio_alloc_context(buffer, BIO_BUFFER_SIZE, 0, + priv->pb = avio_alloc_context(buffer, lavfdopts->buffersize, 0, demuxer, mp_read, NULL, mp_seek); if (!priv->pb) { av_free(buffer); -- cgit v1.2.3