diff options
author | Nicolas George <george@nsup.org> | 2017-10-27 20:46:28 +0200 |
---|---|---|
committer | Jan Ekström <jeebjp@gmail.com> | 2017-10-29 19:40:52 +0200 |
commit | a606f27f4c610708fa96e35eed7b7537d3d8f712 (patch) | |
tree | c89f447c93c6fa613aae2e34a933f86079109b8e /libavformat/aviobuf.c | |
parent | bfb1a946255f9b12dccc6b12f5a865852f487a87 (diff) |
lavf/avio: temporarily accept 0 as EOF.
Print a warning to let applicatios fix their use.
After a deprecation period, check with a low-level assert.
Also make the constraint explicit in the doxygen comment.
Signed-off-by: Nicolas George <george@nsup.org>
Diffstat (limited to 'libavformat/aviobuf.c')
-rw-r--r-- | libavformat/aviobuf.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 3e9d774a13..bfd40f5097 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -524,6 +524,24 @@ void avio_write_marker(AVIOContext *s, int64_t time, enum AVIODataMarkerType typ s->last_time = time; } +static int read_packet_wrapper(AVIOContext *s, uint8_t *buf, int size) +{ + int ret; + + if (!s->read_packet) + return AVERROR_EOF; + ret = s->read_packet(s->opaque, buf, size); +#if FF_API_OLD_AVIO_EOF_0 + if (!ret && !s->max_packet_size) { + av_log(NULL, AV_LOG_WARNING, "Invalid return value 0 for stream protocol\n"); + ret = AVERROR_EOF; + } +#else + av_assert2(ret || s->max_packet_size); +#endif + return ret; +} + /* Input stream */ static void fill_buffer(AVIOContext *s) @@ -562,10 +580,7 @@ static void fill_buffer(AVIOContext *s) len = s->orig_buffer_size; } - if (s->read_packet) - len = s->read_packet(s->opaque, dst, len); - else - len = AVERROR_EOF; + len = read_packet_wrapper(s, dst, len); if (len == AVERROR_EOF) { /* do not modify buffer if EOF reached so that a seek back can be done without rereading data */ @@ -638,10 +653,7 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size) if (len == 0 || s->write_flag) { if((s->direct || size > s->buffer_size) && !s->update_checksum) { // bypass the buffer and read data directly into buf - if(s->read_packet) - len = s->read_packet(s->opaque, buf, size); - else - len = AVERROR_EOF; + len = read_packet_wrapper(s, buf, size); if (len == AVERROR_EOF) { /* do not modify buffer if EOF reached so that a seek back can be done without rereading data */ @@ -708,7 +720,7 @@ int avio_read_partial(AVIOContext *s, unsigned char *buf, int size) return -1; if (s->read_packet && s->write_flag) { - len = s->read_packet(s->opaque, buf, size); + len = read_packet_wrapper(s, buf, size); if (len > 0) s->pos += len; return len; |