file: Add an option for following a file that is being written
Using this requires setting the rw_timeout option to make it terminate, alternatively using the interrupt callback (if used via the API). Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
parent
ccea588f83
commit
933dec0e29
@ -69,6 +69,17 @@ The av* tools default to the file protocol, that is a resource
|
|||||||
specified with the name "FILE.mpeg" is interpreted as the URL
|
specified with the name "FILE.mpeg" is interpreted as the URL
|
||||||
"file:FILE.mpeg".
|
"file:FILE.mpeg".
|
||||||
|
|
||||||
|
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
|
@section gopher
|
||||||
|
|
||||||
Gopher protocol.
|
Gopher protocol.
|
||||||
|
@ -42,10 +42,12 @@ typedef struct FileContext {
|
|||||||
const AVClass *class;
|
const AVClass *class;
|
||||||
int fd;
|
int fd;
|
||||||
int trunc;
|
int trunc;
|
||||||
|
int follow;
|
||||||
} FileContext;
|
} FileContext;
|
||||||
|
|
||||||
static const AVOption file_options[] = {
|
static const AVOption file_options[] = {
|
||||||
{ "truncate", "Truncate existing files on write", offsetof(FileContext, trunc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
|
{ "truncate", "Truncate existing files on write", offsetof(FileContext, trunc), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, 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 }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -60,6 +62,8 @@ static int file_read(URLContext *h, unsigned char *buf, int size)
|
|||||||
{
|
{
|
||||||
FileContext *c = h->priv_data;
|
FileContext *c = h->priv_data;
|
||||||
int ret = read(c->fd, buf, size);
|
int ret = read(c->fd, buf, size);
|
||||||
|
if (ret == 0 && c->follow)
|
||||||
|
return AVERROR(EAGAIN);
|
||||||
return (ret == -1) ? AVERROR(errno) : ret;
|
return (ret == -1) ? AVERROR(errno) : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
#define LIBAVFORMAT_VERSION_MAJOR 57
|
#define LIBAVFORMAT_VERSION_MAJOR 57
|
||||||
#define LIBAVFORMAT_VERSION_MINOR 5
|
#define LIBAVFORMAT_VERSION_MINOR 5
|
||||||
#define LIBAVFORMAT_VERSION_MICRO 1
|
#define LIBAVFORMAT_VERSION_MICRO 2
|
||||||
|
|
||||||
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
|
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
|
||||||
LIBAVFORMAT_VERSION_MINOR, \
|
LIBAVFORMAT_VERSION_MINOR, \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user