From patchwork Fri Sep 22 07:25:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takayuki 'January June' Suwa X-Patchwork-Id: 5234 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.36.26 with SMTP id f26csp2875813jaa; Fri, 22 Sep 2017 00:32:10 -0700 (PDT) X-Received: by 10.28.103.195 with SMTP id b186mr3244999wmc.86.1506065530570; Fri, 22 Sep 2017 00:32:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506065530; cv=none; d=google.com; s=arc-20160816; b=iPFLkzuJb6KHHvHEiiF/tzgA3js932/mXzVA0zlViClSBH8JtWbT0qTEHZpLqRooUl GhjEFjJjWuI5onaX7ZJSUTVai0mAHsZFdHQa3UCLXcRWU13zQ1qle4Vj68XFvpPhPloz W5nGk6AUYGN733+p33ZwABwBIfpCpXwlgSkHzv6ng8qVZml3yHjgU+dmBQzeU6zO2kbt DItX7q4vTq7eVs7bk7CdJnDRpHXRYIVgKccaZTHUnEiVCZuFfF9Gfy90PddAnQrdvy1J j0o7Lg/VYzlnikvMjNOAiQ1RpXKD/D4aAuoO/PzbjokaHgw/AQdXou9U56FwLpZtescU 6bPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=h9RlHOGIiWZ2OIOX7bxL2KfK7Yfyp1qhm8OoKd69dLc=; b=tonqmlyM7SwAQ+iEyw8pRcOt2I44XY/vCLNhf/49yyi2Cb0wvmFx889uK9RoXo97Wc yw1F7Rsqx3YSMxoun21msAR0r2W+8TVW6aTF174AfnX5FNn1Guk3NKCPRTmUIw9izZHr rX54Ra/n3evxyPfL0Cs/j6SR/1LGw/uk7aIXnquaNvX9S21lxL8PskQbfBFdmS4M5YjV 5huvKZfQS7EjJRrwPduH81Lb2ncq335ziZYwKDEGZyBhVRUH4V9k2KhlUIkcVvE3qwpn 3pp1AVAWeoBYkGi0IQTsdxIVHfIBaANoJtsqa8Bvw/oReSDLufO79qUo2rkSo+6gVJs8 Nn8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=mqNG6pXP; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b133si2524187wmc.53.2017.09.22.00.32.09; Fri, 22 Sep 2017 00:32:10 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=mqNG6pXP; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1D0856882BA; Fri, 22 Sep 2017 10:31:58 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f66.google.com (mail-pg0-f66.google.com [74.125.83.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E9B7E680D29 for ; Fri, 22 Sep 2017 10:31:50 +0300 (EEST) Received: by mail-pg0-f66.google.com with SMTP id m30so199498pgn.5 for ; Fri, 22 Sep 2017 00:32:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=3feRXwxc5RQGqzx5OY71Tppw3UnCoJnK15k6kZxHLOM=; b=mqNG6pXPWXXY89Fp01Bu+znXw16TBUXnowLOAmVEhr0jylAq5F+k8uJGxsP9w85+6J Y552+x+RDIqsGuoTlo4VJ3YwyYg6coRM0GuHIaxajAQ8+nuDWXIHH74p8YfrYkgICY4V B8mc1MJ+5xh2b9Ysky4gZn6V6vxKCnj5ni2cTL3N+vZJCs7W+BFhLD68q05l+3vnv0yL ZE/ISm+iKxl2ZwaSXhXalyejmWN2fLTlPqOQKG39b6f4C2cr6vKG9l78juqD7TrzXg84 8m3yu8CpA2ePG9MkF8MANvYq4705aA+7VuPS09HWJlzlvt9SghfwQtpdtM3olO2q9iMJ VdUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3feRXwxc5RQGqzx5OY71Tppw3UnCoJnK15k6kZxHLOM=; b=NuOQU2lhP1bTN6zvmIZay+SU7OEc/7XoKeLJnkAHFBE9jW9byN/Y0fVgGovfTGqR0v FTOLsOwHA61eIAfyQfU1js+txjFa2QLa+8O1vwmRGorJ9kWeZL/Q0mr6bflBZfbM5YUE T9CfR41W218xgAdx1h+lN/bUn9PsIzAMtONeiZknOXAy27PazFP98ADD1R/iFa2sy8Ff e5NjCPMq46Ii74ICcv65CGR+WFqEEu6tuHKM07IxhIWech5I238cQo1t8WoQXyQLrvob zgk28HMkGHGoJqXUlozgeB+Rz5UBFbQkiuxaUI1LDnNkc2IFKOm9dpIB9vEU2T0Qx4PP tpiw== X-Gm-Message-State: AHPjjUgyEkPaz/ZOj0Qz10R3biZWfVwmApuBI7BHTGCy13GTM4Nb+D0q 2XNCdxtU9b6AGI0Vo4bmNj7s+w== X-Google-Smtp-Source: AOwi7QDqBHm+Bu+vp8m0t752kDnqnxl5LUqLBfhwEubhAKG6C7cwkpCtQJUL+7TLRe5aj0MPv4y00Q== X-Received: by 10.84.238.142 with SMTP id v14mr8174293plk.388.1506065139594; Fri, 22 Sep 2017 00:25:39 -0700 (PDT) Received: from localhost.localdomain (h175-177-005-157.catv02.itscom.jp. [175.177.5.157]) by smtp.gmail.com with ESMTPSA id m5sm6186871pfg.12.2017.09.22.00.25.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Sep 2017 00:25:38 -0700 (PDT) From: Takayuki 'January June' Suwa To: ffmpeg-devel@ffmpeg.org Date: Fri, 22 Sep 2017 16:25:33 +0900 Message-Id: <1506065133-9805-1-git-send-email-jjsuwa.sys3175@gmail.com> X-Mailer: git-send-email 2.1.4 Subject: [FFmpeg-devel] [PATCH] avformat/async: allow to set buffer size [v2] X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Takayuki 'January June' Suwa MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" - add "-asyncbufsize" option to async: - refactor async.c - remove READ_BACK_CAPACITY and the 3rd arg of ring_init() - replace some magicnums with symconst macros --- doc/protocols.texi | 6 ++++++ libavformat/async.c | 18 +++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) 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..28fda66fdd0 100644 --- a/libavformat/async.c +++ b/libavformat/async.c @@ -41,8 +41,9 @@ #include #endif -#define BUFFER_CAPACITY (4 * 1024 * 1024) -#define READ_BACK_CAPACITY (4 * 1024 * 1024) +#define BUFFER_CAPACITY (8 * 1024 * 1024) +#define BUFFER_CAPACITY_MIN 4096 +#define BUFFER_FETCH_SIZE 4096 #define SHORT_SEEK_THRESHOLD (256 * 1024) typedef struct RingBuffer @@ -78,16 +79,18 @@ 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) +static int ring_init(RingBuffer *ring, int capacity) { memset(ring, 0, sizeof(RingBuffer)); - ring->fifo = av_fifo_alloc(capacity + read_back_capacity); + ring->fifo = av_fifo_alloc(capacity); if (!ring->fifo) return AVERROR(ENOMEM); - ring->read_back_capacity = read_back_capacity; + ring->read_back_capacity = capacity / 2; return 0; } @@ -220,7 +223,7 @@ static void *async_buffer_task(void *arg) } pthread_mutex_unlock(&c->mutex); - to_copy = FFMIN(4096, fifo_space); + to_copy = FFMIN(BUFFER_FETCH_SIZE, fifo_space); ret = ring_generic_write(ring, (void *)h, to_copy, wrapped_url_read); pthread_mutex_lock(&c->mutex); @@ -245,7 +248,7 @@ static int async_open(URLContext *h, const char *arg, int flags, AVDictionary ** av_strstart(arg, "async:", &arg); - ret = ring_init(&c->ring, BUFFER_CAPACITY, READ_BACK_CAPACITY); + ret = ring_init(&c->ring, FFMAX(BUFFER_CAPACITY_MIN, c->asyncbufsize)); if (ret < 0) goto fifo_fail; @@ -466,6 +469,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 }, 0, INT_MAX, D }, {NULL}, };