From patchwork Wed Apr 3 20:41:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 12607 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E81FA447D83 for ; Wed, 3 Apr 2019 23:41:59 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C840C68ADF1; Wed, 3 Apr 2019 23:41:59 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 721BD68ADC4 for ; Wed, 3 Apr 2019 23:41:53 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 50974E1356; Wed, 3 Apr 2019 22:41:53 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C70EQ9Y_baVY; Wed, 3 Apr 2019 22:41:52 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 16CA4E131E; Wed, 3 Apr 2019 22:41:52 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Wed, 3 Apr 2019 22:41:46 +0200 Message-Id: <20190403204146.12634-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH] avformat/file: add seekable option to disallow seeking 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Marton Balint --- doc/protocols.texi | 9 +++++++++ libavformat/file.c | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/doc/protocols.texi b/doc/protocols.texi index e1caa049a5..34967ff5e2 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -199,6 +199,15 @@ If set to 1, the protocol will retry reading at the end of the file, allowing reading files that still are being written. In order for this to terminate, you either need to use the rw_timeout option, or use the interrupt callback (for API users). + +@item seekable +Controls if seekability is advertised on the file. 1 means seekable, 0 means +non-seekable, -1 means auto (seekable for normal files, non-seekable for named +pipes). + +Many demuxers handle seekable and non-seekable resources differently, +overriding this might speed up opening certain files at the cost of losing some +features (e.g. accurate seeking). @end table @section ftp diff --git a/libavformat/file.c b/libavformat/file.c index e613b91010..e46596fed1 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -73,6 +73,7 @@ typedef struct FileContext { int trunc; int blocksize; int follow; + int seekable; #if HAVE_DIRENT_H DIR *dir; #endif @@ -82,6 +83,7 @@ static const AVOption file_options[] = { { "truncate", "truncate existing files on write", offsetof(FileContext, trunc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM }, { "blocksize", "set I/O operation maximum block size", offsetof(FileContext, blocksize), AV_OPT_TYPE_INT, { .i64 = INT_MAX }, 1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, { "follow", "Follow a file as it is being written", offsetof(FileContext, follow), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, + { "seekable", "Sets if the file is seekable", offsetof(FileContext, seekable), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1, AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, { NULL } }; @@ -238,6 +240,9 @@ static int file_open(URLContext *h, const char *filename, int flags) if (!h->is_streamed && flags & AVIO_FLAG_WRITE) h->min_packet_size = h->max_packet_size = 262144; + if (c->seekable >= 0) + h->is_streamed = !c->seekable; + return 0; }