[FFmpeg-devel] [PATCH] avformat/async: allow to set buffer size

Takayuki 'January June' Suwa jjsuwa.sys3175 at gmail.com
Thu Sep 21 18:36:40 EEST 2017


---
 doc/protocols.texi  | 6 ++++++
 libavformat/async.c | 7 ++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index a7968ff56e3..f321664d7bf 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -57,6 +57,12 @@ Asynchronous data filling wrapper for input stream.
 
 Fill data in a background thread, to decouple I/O operation from demux thread.
 
+The accepted options are:
+ at table @option
+ at item asyncbufsize
+Set asynchronous data buffer size, in bytes. Default value is 8 MiB.
+ at end table
+
 @example
 async:@var{URL}
 async:http://host/resource
diff --git a/libavformat/async.c b/libavformat/async.c
index 54dbd2312a2..f8ac12c7aa0 100644
--- a/libavformat/async.c
+++ b/libavformat/async.c
@@ -78,6 +78,8 @@ typedef struct Context {
 
     int             abort_request;
     AVIOInterruptCB interrupt_callback;
+
+    int             asyncbufsize;
 } Context;
 
 static int ring_init(RingBuffer *ring, unsigned int capacity, int read_back_capacity)
@@ -242,10 +244,12 @@ static int async_open(URLContext *h, const char *arg, int flags, AVDictionary **
     Context         *c = h->priv_data;
     int              ret;
     AVIOInterruptCB  interrupt_callback = {.callback = async_check_interrupt, .opaque = h};
+    int              capacity;
 
     av_strstart(arg, "async:", &arg);
 
-    ret = ring_init(&c->ring, BUFFER_CAPACITY, READ_BACK_CAPACITY);
+    capacity = FFMAX(4096, c->asyncbufsize / 2);
+    ret = ring_init(&c->ring, capacity, capacity);
     if (ret < 0)
         goto fifo_fail;
 
@@ -466,6 +470,7 @@ static int64_t async_seek(URLContext *h, int64_t pos, int whence)
 #define D AV_OPT_FLAG_DECODING_PARAM
 
 static const AVOption options[] = {
+    { "asyncbufsize", "Amount in bytes that may be used for asynchronous data buffering", OFFSET(asyncbufsize), AV_OPT_TYPE_INT, { .i64 = BUFFER_CAPACITY * 2 }, 0, INT_MAX, D },
     {NULL},
 };
 


More information about the ffmpeg-devel mailing list