diff mbox

[FFmpeg-devel,PATCHv2] avformat/file: add seekable option to disallow seeking

Message ID 20190407191358.31216-1-cus@passwd.hu
State New
Headers show

Commit Message

Marton Balint April 7, 2019, 7:13 p.m. UTC
v2: Disallow positive override of seekability as requested by Hendrik Leppkes.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 doc/protocols.texi | 8 ++++++++
 libavformat/file.c | 5 +++++
 2 files changed, 13 insertions(+)

Comments

Marton Balint April 9, 2019, 7:23 p.m. UTC | #1
On Sun, 7 Apr 2019, Marton Balint wrote:

> v2: Disallow positive override of seekability as requested by Hendrik Leppkes.

Ping, will apply soon.

Thanks,
Marton

>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> doc/protocols.texi | 8 ++++++++
> libavformat/file.c | 5 +++++
> 2 files changed, 13 insertions(+)
>
> diff --git a/doc/protocols.texi b/doc/protocols.texi
> index e1caa049a5..3e4e7af3d4 100644
> --- a/doc/protocols.texi
> +++ b/doc/protocols.texi
> @@ -199,6 +199,14 @@ 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. 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..08c7f8e6dd 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, 0, 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;
> }
> 
> -- 
> 2.16.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Marton Balint April 11, 2019, 7:49 p.m. UTC | #2
On Tue, 9 Apr 2019, Marton Balint wrote:
>
> On Sun, 7 Apr 2019, Marton Balint wrote:
>
>> v2: Disallow positive override of seekability as requested by Hendrik 
> Leppkes.
>
> Ping, will apply soon.

Applied.

Regards,
Marton
diff mbox

Patch

diff --git a/doc/protocols.texi b/doc/protocols.texi
index e1caa049a5..3e4e7af3d4 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -199,6 +199,14 @@  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. 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..08c7f8e6dd 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, 0, 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;
 }