Subject: [PATCH] libavformat/aviobuf.c: don't treat 0 from read_packet as EOF
Signed-off-by: Daniel Kucera <daniel.kucera@gmail.com>
---
libavformat/avio.c | 2 +-
libavformat/aviobuf.c | 20 ++++++++++++--------
libavformat/cache.c | 4 ++--
libavformat/file.c | 2 ++
libavformat/subfile.c | 2 +-
libavformat/wtvdec.c | 4 ++--
6 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/libavformat/avio.c b/libavformat/avio.c
index 1e79c9dd5c..bf803016b7 100644
|
a
|
b
|
static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf,
|
| 394 | 394 | av_usleep(1000); |
| 395 | 395 | } |
| 396 | 396 | } else if (ret < 1) |
| 397 | | return (ret < 0 && ret != AVERROR_EOF) ? ret : len; |
| | 397 | return (ret < 0) ? ret : len; |
| 398 | 398 | if (ret) { |
| 399 | 399 | fast_retries = FFMAX(fast_retries, 2); |
| 400 | 400 | wait_since = 0; |
diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
index 1667e9f08b..3705e406d9 100644
|
a
|
b
|
static void fill_buffer(AVIOContext *s)
|
| 556 | 556 | if (s->read_packet) |
| 557 | 557 | len = s->read_packet(s->opaque, dst, len); |
| 558 | 558 | else |
| 559 | | len = 0; |
| 560 | | if (len <= 0) { |
| | 559 | len = AVERROR_EOF; |
| | 560 | if (len == AVERROR_EOF) { |
| 561 | 561 | /* do not modify buffer if EOF reached so that a seek back can |
| 562 | 562 | be done without rereading data */ |
| 563 | 563 | s->eof_reached = 1; |
| 564 | | if (len < 0) |
| 565 | | s->error = len; |
| | 564 | } else if (len < 0) { |
| | 565 | s->eof_reached = 1; |
| | 566 | s->error= len; |
| 566 | 567 | } else { |
| 567 | 568 | s->pos += len; |
| 568 | 569 | s->buf_ptr = dst; |
| … |
… |
int avio_read(AVIOContext *s, unsigned char *buf, int size)
|
| 630 | 631 | // bypass the buffer and read data directly into buf |
| 631 | 632 | if(s->read_packet) |
| 632 | 633 | len = s->read_packet(s->opaque, buf, size); |
| 633 | | |
| 634 | | if (len <= 0) { |
| | 634 | else |
| | 635 | len = AVERROR_EOF; |
| | 636 | if (len == AVERROR_EOF) { |
| 635 | 637 | /* do not modify buffer if EOF reached so that a seek back can |
| 636 | 638 | be done without rereading data */ |
| 637 | 639 | s->eof_reached = 1; |
| 638 | | if(len<0) |
| 639 | | s->error= len; |
| | 640 | break; |
| | 641 | } else if (len < 0) { |
| | 642 | s->eof_reached = 1; |
| | 643 | s->error= len; |
| 640 | 644 | break; |
| 641 | 645 | } else { |
| 642 | 646 | s->pos += len; |
diff --git a/libavformat/cache.c b/libavformat/cache.c
index 6aabca2e78..66bbbf54c9 100644
|
a
|
b
|
static int cache_read(URLContext *h, unsigned char *buf, int size)
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | r = ffurl_read(c->inner, buf, size); |
| 204 | | if (r == 0 && size>0) { |
| | 204 | if (r == AVERROR_EOF && size>0) { |
| 205 | 205 | c->is_true_eof = 1; |
| 206 | 206 | av_assert0(c->end >= c->logical_pos); |
| 207 | 207 | } |
| … |
… |
resolve_eof:
|
| 263 | 263 | if (whence == SEEK_SET) |
| 264 | 264 | size = FFMIN(sizeof(tmp), pos - c->logical_pos); |
| 265 | 265 | ret = cache_read(h, tmp, size); |
| 266 | | if (ret == 0 && whence == SEEK_END) { |
| | 266 | if (ret == AVERROR_EOF && whence == SEEK_END) { |
| 267 | 267 | av_assert0(c->is_true_eof); |
| 268 | 268 | goto resolve_eof; |
| 269 | 269 | } |
diff --git a/libavformat/file.c b/libavformat/file.c
index 264542a36a..1fb83851c0 100644
|
a
|
b
|
static int file_read(URLContext *h, unsigned char *buf, int size)
|
| 112 | 112 | ret = read(c->fd, buf, size); |
| 113 | 113 | if (ret == 0 && c->follow) |
| 114 | 114 | return AVERROR(EAGAIN); |
| | 115 | if (ret == 0) |
| | 116 | return AVERROR_EOF; |
| 115 | 117 | return (ret == -1) ? AVERROR(errno) : ret; |
| 116 | 118 | } |
| 117 | 119 | |
diff --git a/libavformat/subfile.c b/libavformat/subfile.c
index fa971e1902..497cf85211 100644
|
a
|
b
|
static int subfile_read(URLContext *h, unsigned char *buf, int size)
|
| 102 | 102 | int ret; |
| 103 | 103 | |
| 104 | 104 | if (rest <= 0) |
| 105 | | return 0; |
| | 105 | return AVERROR_EOF; |
| 106 | 106 | size = FFMIN(size, rest); |
| 107 | 107 | ret = ffurl_read(c->h, buf, size); |
| 108 | 108 | if (ret >= 0) |
diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c
index 3ac4501306..ee19fd84da 100644
|
a
|
b
|
static int64_t seek_by_sector(AVIOContext *pb, int64_t sector, int64_t offset)
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | | * @return bytes read, 0 on end of file, or <0 on error |
| | 68 | * @return bytes read, AVERROR_EOF on end of file, or <0 on error |
| 69 | 69 | */ |
| 70 | 70 | static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size) |
| 71 | 71 | { |
| … |
… |
static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)
|
| 76 | 76 | if (wf->error || pb->error) |
| 77 | 77 | return -1; |
| 78 | 78 | if (wf->position >= wf->length || avio_feof(pb)) |
| 79 | | return 0; |
| | 79 | return AVERROR_EOF; |
| 80 | 80 | |
| 81 | 81 | buf_size = FFMIN(buf_size, wf->length - wf->position); |
| 82 | 82 | while(nread < buf_size) { |