Merge commit '933dec0e29ec4d2cb83474279a6c52d62fdb7310'

* commit '933dec0e29ec4d2cb83474279a6c52d62fdb7310':
  file: Add an option for following a file that is being written

Merged-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
This commit is contained in:
Derek Buitenhuis 2016-04-19 14:41:19 +01:00
commit 90eb249969
3 changed files with 16 additions and 1 deletions

View File

@ -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.

View File

@ -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;
}

View File

@ -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, \