From patchwork Sun Jun 4 06:00:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kucera X-Patchwork-Id: 3829 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp851193vsk; Sat, 3 Jun 2017 23:00:37 -0700 (PDT) X-Received: by 10.223.129.183 with SMTP id 52mr9544550wra.185.1496556037318; Sat, 03 Jun 2017 23:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496556037; cv=none; d=google.com; s=arc-20160816; b=ckpcj4jphiIhGPjRpFpTfyzOR1rMSI/OdZ9lOf/VTtVJAZFQd+N4Aq41+Q3+Gc3T0p vxZmkYx53TNXo3soTVUUG5LDpGhvv6EK37L2rhOQtv3ct78p7Rn1Kx4A0KQwMUpxChUE c/uwWglsD/ZR7WJtMnErXs3JHigV4A+JmQ7iHKhusDsvmcCKszlx0Tm78M6SjV/kxwey BPLEmWyaDU5AXHmBOJwwDLkPMTVuyl9cza0JAAcqx6t6cWviHW2bPhq3ep3Seg7pw6xQ kttSClgELf0jy4GYTBJCxBpI59wT1LRcJ6mVeHvEWR6vArHWEa5X/t2bAkE6RZ4VX9mc y9jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=MG/CzzaRvcDucSXdmP4dcWR2uPN2xvcGIrVIqmKJVM4=; b=qi/iMlV5IObfQUWScXuQnFSlP0+REaIlOH1OFn0iSGXRs9w+4qfeG5/qfm7RagxUQO PrxBasm+4FPFCfYi6lcX1+in3iRQqW0QPYsPfY0mnRcW2a8b2rQ4nqWCeRiZu8FFWMr2 WYFKICnZYPoQs+MV+rFehqt4w8CNLZHjYB9kjYFc/yvzfKvQFDQBF3VVyVfKoajuNo47 pFgHSEZdRUiv1sySXyEo2M96oAecVSgGHKZiJ1YscoLlq4UD/2jiDyH32B/S+TFhNG6R yWw0K1m2L1plPn4xaWqudh2hv4CWSS4Tl2P7nMGigk23mbsIoR5RZHhrf1UX+iRFJ54F 777w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h23si2756177wmi.137.2017.06.03.23.00.36; Sat, 03 Jun 2017 23:00:37 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EC3AC689D50; Sun, 4 Jun 2017 09:00:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0D9E0689AD9 for ; Sun, 4 Jun 2017 09:00:20 +0300 (EEST) Received: by mail-wr0-f194.google.com with SMTP id g76so4585599wrd.2 for ; Sat, 03 Jun 2017 23:00:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=SREGS9lk3W54jyAAAwRA7AoUTacaycYZs40vHhDUfZU=; b=qhb0e2GhDM4uO6SdmfNCaRzyMYo40pVRRT+/ijgBCcEFTa9a1mH602fT8I8e8MDQ8L PixcnFTfQTjvC+ihpZmxQ7fRd3/a+BR+1Go5iUmBBE9gH5ep+PzC+SFlyZdrNTHsOqQb TFeDTCaZqGSr6gr6WG9bbv3gLC1IT8Q2tJHfbSIg+M6N8/CCbAgiQi+/8baRpIrQdI3C dtYa2CxM2njLmggoqbUW1/1E/QZ5g9dK3QMRK2Z6FvCjnc/Vhn7LndaWcHvq9+xvlfqp GliuQoPIcNaZhxcnc+SghZchjvqXeE3Mpf+JfG7Khao+TvSsuZ8+UuPV5XspExHDo88m 7mtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SREGS9lk3W54jyAAAwRA7AoUTacaycYZs40vHhDUfZU=; b=CIYVc019m4qzhvAb6k9Rg2POKEdh3lnHXlCV746LdysTqbrsZg4110CIv9gfFk00+Q 78/4Nad7vqyOqzTn6aMu6L7RBNINn21MCVqR7Akhtw1TtcOmzWgcpunifp+3ZGb113Yb 5KjIHdHpY6H3kyNE2BQj+C9WmZQovSWwmx04DPtxcqXlQBb5nZD3IvmRJVQjHSeTnejn iYRKZC6Kepcka9neGGtBcPhzIkqn6jjapIgNzU7hjEcY5j3fjpL4UlA4z4htIYvovOAX Fp79nJmtEaARxtu6654ZRFY2LHtVDcTtkb6lxuGYU6uKLbmYfENmbAqA3yK7dl9m4sqS 4fnA== X-Gm-Message-State: AODbwcBNujcgVMoQeaADDMzLOSlgoxlqIndJcQj5EBpKagtiiIp84/Mb BAlM9d9lCLZDUHe+ X-Received: by 10.223.164.137 with SMTP id g9mr9390150wrb.128.1496556026765; Sat, 03 Jun 2017 23:00:26 -0700 (PDT) Received: from localhost.localdomain (ip-86-49-3-62.net.upcbroadband.cz. [86.49.3.62]) by smtp.gmail.com with ESMTPSA id 97sm21911602wrc.5.2017.06.03.23.00.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Jun 2017 23:00:25 -0700 (PDT) From: Daniel Kucera To: ffmpeg-devel@ffmpeg.org Date: Sun, 4 Jun 2017 08:00:16 +0200 Message-Id: <20170604060016.11482-1-daniel.kucera@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] libavformat/aviobuf.c: don't treat 0 from read_packet as EOF X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Daniel Kucera MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Daniel Kucera --- 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/libavformat/avio.c +++ b/libavformat/avio.c @@ -394,7 +394,7 @@ static inline int retry_transfer_wrapper(URLContext *h, uint8_t *buf, av_usleep(1000); } } else if (ret < 1) - return (ret < 0 && ret != AVERROR_EOF) ? ret : len; + return (ret < 0) ? ret : len; if (ret) { fast_retries = FFMAX(fast_retries, 2); wait_since = 0; diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 1667e9f08b..3705e406d9 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -556,13 +556,14 @@ static void fill_buffer(AVIOContext *s) if (s->read_packet) len = s->read_packet(s->opaque, dst, len); else - len = 0; - if (len <= 0) { + len = AVERROR_EOF; + if (len == AVERROR_EOF) { /* do not modify buffer if EOF reached so that a seek back can be done without rereading data */ s->eof_reached = 1; - if (len < 0) - s->error = len; + } else if (len < 0) { + s->eof_reached = 1; + s->error= len; } else { s->pos += len; s->buf_ptr = dst; @@ -630,13 +631,16 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size) // bypass the buffer and read data directly into buf if(s->read_packet) len = s->read_packet(s->opaque, buf, size); - - if (len <= 0) { + else + len = AVERROR_EOF; + if (len == AVERROR_EOF) { /* do not modify buffer if EOF reached so that a seek back can be done without rereading data */ s->eof_reached = 1; - if(len<0) - s->error= len; + break; + } else if (len < 0) { + s->eof_reached = 1; + s->error= len; break; } else { s->pos += len; diff --git a/libavformat/cache.c b/libavformat/cache.c index 6aabca2e78..66bbbf54c9 100644 --- a/libavformat/cache.c +++ b/libavformat/cache.c @@ -201,7 +201,7 @@ static int cache_read(URLContext *h, unsigned char *buf, int size) } r = ffurl_read(c->inner, buf, size); - if (r == 0 && size>0) { + if (r == AVERROR_EOF && size>0) { c->is_true_eof = 1; av_assert0(c->end >= c->logical_pos); } @@ -263,7 +263,7 @@ resolve_eof: if (whence == SEEK_SET) size = FFMIN(sizeof(tmp), pos - c->logical_pos); ret = cache_read(h, tmp, size); - if (ret == 0 && whence == SEEK_END) { + if (ret == AVERROR_EOF && whence == SEEK_END) { av_assert0(c->is_true_eof); goto resolve_eof; } diff --git a/libavformat/file.c b/libavformat/file.c index 264542a36a..1fb83851c0 100644 --- a/libavformat/file.c +++ b/libavformat/file.c @@ -112,6 +112,8 @@ static int file_read(URLContext *h, unsigned char *buf, int size) ret = read(c->fd, buf, size); if (ret == 0 && c->follow) return AVERROR(EAGAIN); + if (ret == 0) + return AVERROR_EOF; return (ret == -1) ? AVERROR(errno) : ret; } diff --git a/libavformat/subfile.c b/libavformat/subfile.c index fa971e1902..497cf85211 100644 --- a/libavformat/subfile.c +++ b/libavformat/subfile.c @@ -102,7 +102,7 @@ static int subfile_read(URLContext *h, unsigned char *buf, int size) int ret; if (rest <= 0) - return 0; + return AVERROR_EOF; size = FFMIN(size, rest); ret = ffurl_read(c->h, buf, size); if (ret >= 0) diff --git a/libavformat/wtvdec.c b/libavformat/wtvdec.c index 3ac4501306..ee19fd84da 100644 --- a/libavformat/wtvdec.c +++ b/libavformat/wtvdec.c @@ -65,7 +65,7 @@ static int64_t seek_by_sector(AVIOContext *pb, int64_t sector, int64_t offset) } /** - * @return bytes read, 0 on end of file, or <0 on error + * @return bytes read, AVERROR_EOF on end of file, or <0 on error */ static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size) { @@ -76,7 +76,7 @@ static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size) if (wf->error || pb->error) return -1; if (wf->position >= wf->length || avio_feof(pb)) - return 0; + return AVERROR_EOF; buf_size = FFMIN(buf_size, wf->length - wf->position); while(nread < buf_size) {