From patchwork Sat Aug 24 20:40:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 14696 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1CABF448C7F for ; Sat, 24 Aug 2019 23:41:08 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F335D689D06; Sat, 24 Aug 2019 23:41:07 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 66389680114 for ; Sat, 24 Aug 2019 23:41:02 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 3AC97E3285; Sat, 24 Aug 2019 22:41:02 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sYer2nl6UPfp; Sat, 24 Aug 2019 22:41:00 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 337A1E23B1; Sat, 24 Aug 2019 22:41:00 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Aug 2019 22:40:51 +0200 Message-Id: <20190824204051.21226-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190823140805.GY3219@michaelspb> References: <20190823140805.GY3219@michaelspb> Subject: [FFmpeg-devel] [PATCH] avformat/utils: return pending IO error on EOF in av_read_frame() 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" avio_feof() returns true both in case of actual EOF and in case of IO errors. Some demuxers (matroska) have special handling to be able to return the proper error for this exact reason, e.g.: if (avio_feof(pb)) { if (pb->error) { return pb->error; } else { return AVERROR_EOF; } } However, most of the demuxers do not, and they simply return AVERROR_EOF if avio_feof() is true, so there is a real chance that IO errors are mistaken for EOF. We might just say that the API user should always check the IO context error attribute on EOF to make sure no IO errors happened, but not even ffmpeg.c does this. It should be more intuitive to the API user if we simply return the IO error as the return value of av_read_frame() instead of AVERROR_EOF. Signed-off-by: Marton Balint --- libavformat/utils.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/utils.c b/libavformat/utils.c index b57e680089..b83a740500 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1762,6 +1762,11 @@ FF_ENABLE_DEPRECATION_WARNINGS av_ts2str(pkt->dts), pkt->size, pkt->duration, pkt->flags); + /* A demuxer might have returned EOF because of an IO error, let's + * propagate this back to the user. */ + if (ret == AVERROR_EOF && s->pb && s->pb->error < 0 && s->pb->error != AVERROR(EAGAIN)) + ret = s->pb->error; + return ret; }