From patchwork Fri Mar 31 02:27:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timothy Lee X-Patchwork-Id: 3211 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp1837201vss; Thu, 30 Mar 2017 19:27:26 -0700 (PDT) X-Received: by 10.223.161.220 with SMTP id v28mr491889wrv.54.1490927246440; Thu, 30 Mar 2017 19:27:26 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w73si6022702wrb.205.2017.03.30.19.27.25; Thu, 30 Mar 2017 19:27:26 -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; 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 5894368973B; Fri, 31 Mar 2017 05:27:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f44.google.com (mail-pg0-f44.google.com [74.125.83.44]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 45B81680875 for ; Fri, 31 Mar 2017 05:27:16 +0300 (EEST) Received: by mail-pg0-f44.google.com with SMTP id 81so56429373pgh.2 for ; Thu, 30 Mar 2017 19:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version; bh=oCxvn+l7aXEizAYXwxDTP9Qaot70zq4KJRtd7sfE7xI=; b=foxueoax2GA/h+9uktXcwj4wYXYQwapFJ0AACFJqkYekgcIB7C4OvkR+uihYIpztsX XHQQuVEF4oJpXMyDhaPfIdGI3JFEaO2mGasWaij0fHDOCGQSW0tqQIcBP19BEax04i9Q QodpmoWQwaesg6Akbpmt2Beilj7BM9by6sarUW/VzzevwvMpDoK6UVpzxZc+GO15Fdf9 GqK0h+oPRuzS91RNDZnciDbafSixujSeDN5IdsQUymhfrIOuO8oMTfs1cYA94LOzG2ry QgwkBKdqDXMnzfKLBhzpzMLd/muRpVamc1BEqyrXbTkAu9XnjHcQT/MXQNuk+i1rZlru Hkvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=oCxvn+l7aXEizAYXwxDTP9Qaot70zq4KJRtd7sfE7xI=; b=hv4d73/jt2+zlCRGzaIjBulzMA5wb8u2SdFzop95XwbDbJ4ZU4kz5tWbhEJh5k3sSg f8/ak18kPZYqcxGjlhHvNIfTewnPpJhyNI0N3rN+Jr9wwVL5mD/zh47P67Re/FTV2LrI yF0FoA5SXHmBgiK3JceHnjFc3qp8Vf/sbn3eCOJuZO9CI5VupR0/P96LbErYEfGBOite kNiz5gcPUZ5LBK0A+8GzuIBqW5xmiWzQCTj2Cizn30wold2nmv1Xvvlw3truVVZhns+H GOWadMdeQasC0O5C6W1qLulawuC+KAKF1uv/1hnyizFv7rA5/KO8trSerbEPpWi+tHz3 elzw== X-Gm-Message-State: AFeK/H1iQpiBV6yEvhI8ksWn3dXkHv9bl6Tu6SmXlgy8Mfw3VBDZjd7Le0iPYllfKOZfbQ== X-Received: by 10.98.159.149 with SMTP id v21mr496160pfk.57.1490927234679; Thu, 30 Mar 2017 19:27:14 -0700 (PDT) Received: from archlinxu1.uavvision.com.au (59-100-13-146.mel.static-ipl.aapt.com.au. [59.100.13.146]) by smtp.gmail.com with ESMTPSA id w14sm6780989pgo.37.2017.03.30.19.27.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 19:27:13 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org From: Timothy Lee Message-ID: Date: Fri, 31 Mar 2017 13:27:11 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] cache protocol: allow cache files to be retained 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi, This patch allows the name of the cache file to be specified, and retains the file after use. This was marked as a TODO item inside cache.c If the filename is not specified, the cache protocol reverts back to the original behavior of using a temporary file. Regards, Timothy From 762ca838ecd60e007285bd30df0a3f95c07cfae4 Mon Sep 17 00:00:00 2001 From: Timothy Lee Date: Fri, 31 Mar 2017 11:34:33 +1100 Subject: [PATCH 1/2] cache protocol: allow cache files to be retained A 'cache_file' option is added to the cache protocol handler, which when specified allows the named cache file to be used and kept around. --- libavformat/cache.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libavformat/cache.c b/libavformat/cache.c index 6aabca2e78..555c18d2fd 100644 --- a/libavformat/cache.c +++ b/libavformat/cache.c @@ -23,7 +23,6 @@ /** * @TODO - * support keeping files * support filling with a background thread */ @@ -45,6 +44,10 @@ #include "os_support.h" #include "url.h" +#ifndef O_BINARY +# define O_BINARY 0 +#endif + typedef struct CacheEntry { int64_t logical_pos; int64_t physical_pos; @@ -63,6 +66,7 @@ typedef struct Context { URLContext *inner; int64_t cache_hit, cache_miss; int read_ahead_limit; + const char *cache_file; } Context; static int cmp(const void *key, const void *node) @@ -77,15 +81,20 @@ static int cache_open(URLContext *h, const char *arg, int flags, AVDictionary ** av_strstart(arg, "cache:", &arg); - c->fd = avpriv_tempfile("ffcache", &buffername, 0, h); + if (c->cache_file) { + // Cache to a specific file if a filename is given + c->fd = avpriv_open(c->cache_file, O_RDWR | O_BINARY | O_CREAT, 0666); + } else { + // Otherwise use a temporary file + c->fd = avpriv_tempfile("ffcache", &buffername, 0, h); + unlink(buffername); + av_freep(&buffername); + } if (c->fd < 0){ av_log(h, AV_LOG_ERROR, "Failed to create tempfile\n"); return c->fd; } - unlink(buffername); - av_freep(&buffername); - return ffurl_open_whitelist(&c->inner, arg, flags, &h->interrupt_callback, options, h->protocol_whitelist, h->protocol_blacklist, h); } @@ -309,6 +318,7 @@ static int cache_close(URLContext *h) static const AVOption options[] = { { "read_ahead_limit", "Amount in bytes that may be read ahead when seeking isn't supported, -1 for unlimited", OFFSET(read_ahead_limit), AV_OPT_TYPE_INT, { .i64 = 65536 }, -1, INT_MAX, D }, + { "cache_file", "Name of cache file to keep after use", OFFSET(cache_file), AV_OPT_TYPE_STRING, { .str = NULL }, CHAR_MIN, CHAR_MAX, D }, {NULL}, }; -- 2.12.1