diff --git a/doc/protocols.texi b/doc/protocols.texi index cfd7be7cf3..a1084bd8a7 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -224,6 +224,17 @@ it, unless special care is taken (tests, customized server configuration etc.). Different FTP servers behave in different way during seek operation. ff* tools may produce incomplete content due to server limitations. +This protocol accepts the following options: + +@table @option +@item follow +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). + +@end table + @section gopher Gopher protocol. diff --git a/libavformat/file.c b/libavformat/file.c index f37db1a88d..5765ce7e48 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -72,6 +72,7 @@ typedef struct FileContext { int fd; int trunc; int blocksize; + int follow; #if HAVE_DIRENT_H DIR *dir; #endif @@ -80,6 +81,7 @@ typedef struct FileContext { 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 }, { NULL } }; @@ -108,6 +110,8 @@ static int file_read(URLContext *h, unsigned char *buf, int size) int ret; size = FFMIN(size, c->blocksize); ret = read(c->fd, buf, size); + if (ret == 0 && c->follow) + return AVERROR(EAGAIN); return (ret == -1) ? AVERROR(errno) : ret; } diff --git a/libavformat/version.h b/libavformat/version.h index 93b87ebe0e..5141b5b16f 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MINOR 34 -#define LIBAVFORMAT_VERSION_MICRO 102 +#define LIBAVFORMAT_VERSION_MICRO 103 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \