diff mbox

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

Message ID 1506008200-23043-1-git-send-email-jjsuwa.sys3175@gmail.com
State New
Headers show

Commit Message

Takayuki 'January June' Suwa Sept. 21, 2017, 3:36 p.m. UTC
---
 doc/protocols.texi  | 6 ++++++
 libavformat/async.c | 7 ++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Sept. 22, 2017, 12:53 a.m. UTC | #1
On Fri, Sep 22, 2017 at 12:36:40AM +0900, Takayuki 'January June' Suwa wrote:
> ---
>  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:
> +@table @option
> +@item asyncbufsize
> +Set asynchronous data buffer size, in bytes. Default value is 8 MiB.
> +@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);

READ_BACK_CAPACITY is unused after this patch

[...]
diff mbox

Patch

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:
+@table @option
+@item asyncbufsize
+Set asynchronous data buffer size, in bytes. Default value is 8 MiB.
+@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},
 };