From patchwork Sat Jun 3 08:16:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kucera X-Patchwork-Id: 3815 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp537228vsk; Sat, 3 Jun 2017 01:17:19 -0700 (PDT) X-Received: by 10.28.54.204 with SMTP id y73mr1095854wmh.53.1496477839470; Sat, 03 Jun 2017 01:17:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496477839; cv=none; d=google.com; s=arc-20160816; b=GirnvMJYGPCmJGTnpGJLul05xR+ObfX4BdhS6z3bZqTvKsv+uZozeuWSCotxmPRmZW CGQ8O/FlaVpma73lXU8T9h4BZy2yPEc57DcLlE1qNDbdhhshr/R7TUftcNW/iT15qhRl rgk0/h5FqwaPhKjaNtHAS4EVVEc6Vkw79qkLIeSKkaVlb5J9gU+pCMA4keQvBGYbL5v+ EsQYjE3YcZ+Gx3xWnYqZmrnuyLUGDIRWWoBiEU2js2mcaSVl8eXQEZW6RCfW+kntciP9 HETAzjcHKqvsGYtCVGbMn31huogjqPjnac64G8SJ0JDkXpfQrh6Q1OrQIxwrA7ODcKVl fEqA== 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=1idlLtnM0mIuBYSlWc2mB/0oPKLv3kUawXnGEvnqzHA=; b=edx3/GN5rc4zFKyrGMVBFVmlWLf5ajb8GbJw4qPoNAgrgU5EpD+mLKN/V/EtQIQh3j MWd9SiJKvyO3K8gT1tLE6T32DLediIhXQex7V31B1FQSb5oRaLE+kEJ8OXxogAlNvkjv yBDTBUR/bohebsEWfbICv7uDTZYSWSjHov0Dkf2puJFwUCvVG1vNcS+RHZGne+jLFMcy 7TdOZT6Ra1naHz/LRYnwKn2/QrJ5YYeP36yFtLcAJxvwNPuFMHS2orUbifAjw7ctG8Eq +Km1ed3MvK3lAOYG8SIDws9V06pk2m5TPoaEJdIA0NBy+kqm6Zx1PTQBmmEI01l/ZQpj EmEA== 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 r134si201036wmf.79.2017.06.03.01.17.19; Sat, 03 Jun 2017 01:17:19 -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 109A1689AE9; Sat, 3 Jun 2017 11:17:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 493FA688338 for ; Sat, 3 Jun 2017 11:17:05 +0300 (EEST) Received: by mail-wr0-f195.google.com with SMTP id v104so3028904wrb.0 for ; Sat, 03 Jun 2017 01:17:11 -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=R+0svQk0EMn36WMDprwe51C8cqO9rtm9zP3tGb//5/M=; b=KzPBIQXPE10utG29crSSzZbEJ1NykYmZ5YTAmS2LlESzc3409ticDVLaxGZ4keTSeg j6fBflNDlGOI+VHXCghGVV88wYPE5v9ZVdJFOdFUdyxRtI/Ko1fbS3qUWhSETO4kvXE4 BvK+ObqNmYwrHN+mIhrcI7w+XGdm7+EB4an3JfAuVZVuwJxRisw/AV3LT+fnNTXh3wpr KmrjmVfbh1+IAwrS04DuUE3PkhzLUP4g7X/E+3Yix4kPDjImJjT5auKFlPbuh0teFp6M LKo1ur8mMeHlZDPXQPDEhCgymoXaoXgefdI+9J70HLy5GrwX//69eLmlZbbV0Rrj5aui 8p5w== 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=R+0svQk0EMn36WMDprwe51C8cqO9rtm9zP3tGb//5/M=; b=D8vBVwlWHfDnL/+d130RxvyktGMumt0w8OkOD7jedU62myMeM0AksFNI0ilvFGzM7p lxqRJxKzQ6irnXhBCDX+xx26OaPNqzuXuvaeNWmfj4m/+4JgK0I/ru96li4E4EW6Je/t jZFPMcgglTrDRNq6ThDvoFCaOap4hKemLRfwfmK3f4/IBmF6bbII+YLacU977BYbI/J4 7r71WbHtn8gTHXLD8/wNPNuklw+el6fUaTLPK/f2jpXgidGnA3nHpbsG+gYT+V4o4GUl JehewrSeQRj/ApKRbkon9/v0OwKbhwz/YIh9W3ZoSEEo7cHK0c2xLotbsJ4U2rknxe8c yTWw== X-Gm-Message-State: AODbwcBJnXTe4fO4CUsgCMGswlxLzFMivZ1Ez+4VdMdcxYLdPEWs9lTX 4uS1ajv1JijGnGMc X-Received: by 10.223.136.131 with SMTP id f3mr9023116wrf.151.1496477830761; Sat, 03 Jun 2017 01:17:10 -0700 (PDT) Received: from localhost.localdomain (ip-89-177-134-12.net.upcbroadband.cz. [89.177.134.12]) by smtp.gmail.com with ESMTPSA id k7sm29741637wrk.45.2017.06.03.01.17.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 03 Jun 2017 01:17:09 -0700 (PDT) From: Daniel Kucera To: ffmpeg-devel@ffmpeg.org Date: Sat, 3 Jun 2017 10:16:59 +0200 Message-Id: <20170603081659.7882-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 | 18 ++++++++++-------- libavformat/cache.c | 2 +- libavformat/file.c | 2 ++ libavformat/subfile.c | 2 +- libavformat/wtvdec.c | 4 ++-- 6 files changed, 17 insertions(+), 13 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..40cff4dc56 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,14 @@ 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) { + 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..54a40d018b 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); } 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) {