Ticket #6455: libavformat-aviobuf-dont-treat-0-from-read_packet-as-EOF.patch

File libavformat-aviobuf-dont-treat-0-from-read_packet-as-EOF.patch, 4.9 KB (added by danman, 9 years ago)
  • libavformat/avio.c

    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,  
    394394                av_usleep(1000);
    395395            }
    396396        } else if (ret < 1)
    397             return (ret < 0 && ret != AVERROR_EOF) ? ret : len;
     397            return (ret < 0) ? ret : len;
    398398        if (ret) {
    399399            fast_retries = FFMAX(fast_retries, 2);
    400400            wait_since = 0;
  • libavformat/aviobuf.c

    diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c
    index 1667e9f08b..3705e406d9 100644
    a b static void fill_buffer(AVIOContext *s)  
    556556    if (s->read_packet)
    557557        len = s->read_packet(s->opaque, dst, len);
    558558    else
    559         len = 0;
    560     if (len <= 0) {
     559        len = AVERROR_EOF;
     560    if (len == AVERROR_EOF) {
    561561        /* do not modify buffer if EOF reached so that a seek back can
    562562           be done without rereading data */
    563563        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;
    566567    } else {
    567568        s->pos += len;
    568569        s->buf_ptr = dst;
    int avio_read(AVIOContext *s, unsigned char *buf, int size)  
    630631                // bypass the buffer and read data directly into buf
    631632                if(s->read_packet)
    632633                    len = s->read_packet(s->opaque, buf, size);
    633 
    634                 if (len <= 0) {
     634                else
     635                    len = AVERROR_EOF;
     636                if (len == AVERROR_EOF) {
    635637                    /* do not modify buffer if EOF reached so that a seek back can
    636638                    be done without rereading data */
    637639                    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;
    640644                    break;
    641645                } else {
    642646                    s->pos += len;
  • libavformat/cache.c

    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)  
    201201    }
    202202
    203203    r = ffurl_read(c->inner, buf, size);
    204     if (r == 0 && size>0) {
     204    if (r == AVERROR_EOF && size>0) {
    205205        c->is_true_eof = 1;
    206206        av_assert0(c->end >= c->logical_pos);
    207207    }
    resolve_eof:  
    263263                if (whence == SEEK_SET)
    264264                    size = FFMIN(sizeof(tmp), pos - c->logical_pos);
    265265                ret = cache_read(h, tmp, size);
    266                 if (ret == 0 && whence == SEEK_END) {
     266                if (ret == AVERROR_EOF && whence == SEEK_END) {
    267267                    av_assert0(c->is_true_eof);
    268268                    goto resolve_eof;
    269269                }
  • libavformat/file.c

    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)  
    112112    ret = read(c->fd, buf, size);
    113113    if (ret == 0 && c->follow)
    114114        return AVERROR(EAGAIN);
     115    if (ret == 0)
     116        return AVERROR_EOF;
    115117    return (ret == -1) ? AVERROR(errno) : ret;
    116118}
    117119
  • libavformat/subfile.c

    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)  
    102102    int ret;
    103103
    104104    if (rest <= 0)
    105         return 0;
     105        return AVERROR_EOF;
    106106    size = FFMIN(size, rest);
    107107    ret = ffurl_read(c->h, buf, size);
    108108    if (ret >= 0)
  • libavformat/wtvdec.c

    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)  
    6565}
    6666
    6767/**
    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
    6969 */
    7070static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)
    7171{
    static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size)  
    7676    if (wf->error || pb->error)
    7777        return -1;
    7878    if (wf->position >= wf->length || avio_feof(pb))
    79         return 0;
     79        return AVERROR_EOF;
    8080
    8181    buf_size = FFMIN(buf_size, wf->length - wf->position);
    8282    while(nread < buf_size) {