From patchwork Tue Oct 17 08:29:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kucera X-Patchwork-Id: 5593 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp4627126jah; Tue, 17 Oct 2017 01:29:46 -0700 (PDT) X-Received: by 10.223.184.15 with SMTP id h15mr2571200wrf.11.1508228985958; Tue, 17 Oct 2017 01:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508228985; cv=none; d=google.com; s=arc-20160816; b=jEugGut0fXh2zB0MicuAgcPpIuGCTLxb/ZTgYD5NysvkULGqQyOm4ulOa51mNVdk5a MjmVhGBBEfl94IOWfrM1K9P2Pr7fXQOermuH+I+eGGHoQvWQ5MuUpvjRvnl2+vi1urTD oBfFWJnhB/5lA0aWRT6BXbcAhMN8xW3WgmAVZnp83Cs+NiGV1WWsirOQf4zXICL+/zZk kVQ/Q/QvxSFRYnc+5Zx2eOpfq+0idEassOkeM5Pqfocf204Rzaq3RdtGXgUqQ35g9vfU XB3232bkaJK7ngBTM1sGPflQKJ+BGDPTam6nqfOtGygcJdY16VUZO4jR8pO4dSSBoXvN dCvw== 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=yq45xvum4RVK/W45YnpxZGO9tV4kCohSWR7u9c0OPn4=; b=vKNFxnqdmNw4S6ECA6c28M09MWGoib712ggDT3tA22D6/ASGotgOHqulttnhkFtY6D hN69WvbJ2D1PCHZjs9b3497AMD6Rezg1rrR+7LlxanLVImzlV2E2OR5xR1lUoGCQxuno Ia2d0rTqZw/BNAFEgvFZz1ZD5McXg4h9qz1+5YZNrCrfFS5GQYwYIjTqS1W8z88LDsDt BbHNFND2tbY5ecfkbAMkv4cewNYtw3EgoVYr1FjVLCMDp+L+y5FWbJUGl01abAFA57VN TIGkE6JxpVOCYKKzCe2dgqdgdZyTLbNC32dawhifhVXHf+6iNc7B0DZCQW1kx9ionMHf Nzsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=hYxn2EGJ; 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 f132si6369579wmf.10.2017.10.17.01.29.45; Tue, 17 Oct 2017 01:29:45 -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 header.s=20161025 header.b=hYxn2EGJ; 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 4A0A7689D7D; Tue, 17 Oct 2017 11:29:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BCAF7689BC5 for ; Tue, 17 Oct 2017 11:29:32 +0300 (EEST) Received: by mail-wm0-f66.google.com with SMTP id q124so2183513wmb.0 for ; Tue, 17 Oct 2017 01:29:37 -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=fRQ8mB3Us5LNhWGsMFoHg8y0nWNrynzTVpc/NNKhHjA=; b=hYxn2EGJcXCmUlnnCopclSaGSX60s/cI3bo0I/K5e/2D5Zl6c+GLrWfPAZtVttKZGM DnMMvCXCk1BrvYnFemLalmUS5QmxtSN9s/vZGQgL296lefcvA9y+UcLbsQn8qDixhMZ6 Eh2AYxEmhUAX8VeSJdq6dXTN7hh14K2IpVMq0KVg7+bUs++1MnGDIAluQF40Ej5a7nZ2 EwYF9QOa6qyqnkFeNYBO047d/fEh0yjvRAkfPjQgJw82iRTmIb/zFjgn82Y7wifoO1VM HWr79rc/YjQmKOvgDMvp6jjed9EnkXc1YUjrXG4Pid3dqHsNLRr0KRiPfXGY+mV6Figw v4NQ== 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=fRQ8mB3Us5LNhWGsMFoHg8y0nWNrynzTVpc/NNKhHjA=; b=Fe3PQNaXUvy9lx2MO/NWMX9+rZmMliUn8/gcr1RElf+eCvj2G5yNzhHT0Bh7VG9U/e +c2bWo9uP0g+2bhUjrKuHJyXQfg5zuIP9r7OY/973JkYc7gkf/WdjK0vqm4wNBWPB48t iCIfeFrxbOxT4Stg4heIfls/B6q8EsIhIq2EkBYm9y20hAAjMDZjWCVPGpP2brps303a ETYV+03sR/bpIWnEh2R/ehuQ5pindIMddg641W+UEaQlmwr6YiAojMYO4FdvwNOT1CaO CL9cI6HKkDfuCkHzdTH5lfE6pvDwbZjvblGzYL1V1m0uqRo0m+cakiwspxEz8YMWNVSo Ge7g== X-Gm-Message-State: AMCzsaVbtbTWab0ntKh1g1cN3vPJXzjOjal5JOpvdBtNTZdbLs/8lVBC 3gvMqDroXuvpMhkIg63mnb8q+A== X-Google-Smtp-Source: ABhQp+QmawFWwFfiwaJ7SrPs6fy5MTY+Tx+FYYBucajjqxHia1O5IXkMVvtyiQTRB3K78P+CIyFN2Q== X-Received: by 10.28.10.132 with SMTP id 126mr2976261wmk.111.1508228976799; Tue, 17 Oct 2017 01:29:36 -0700 (PDT) Received: from speedy.danman.eu (mail.danman.eu. [185.98.208.20]) by smtp.gmail.com with ESMTPSA id v78sm6317613wmv.48.2017.10.17.01.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Oct 2017 01:29:36 -0700 (PDT) From: Daniel Kucera To: ffmpeg-devel@ffmpeg.org Date: Tue, 17 Oct 2017 10:29:30 +0200 Message-Id: <20171017082930.12869-1-daniel.kucera@gmail.com> X-Mailer: git-send-email 2.11.0 Subject: [FFmpeg-devel] [PATCH] libavformat: not treat 0 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" transfer_func variable passed to retry_transfer_wrapper are h->prot->url_read and h->prot->url_write functions. These need to return EOF or other error properly. In case of returning >= 0, url_read/url_write is retried until error is returned. Signed-off-by: Daniel Kucera --- libavformat/avio.c | 6 ++++-- libavformat/aviobuf.c | 20 ++++++++++++-------- libavformat/cache.c | 4 ++-- libavformat/concat.c | 9 +++++---- libavformat/http.c | 5 ++++- 5 files changed, 27 insertions(+), 17 deletions(-) diff --git a/libavformat/avio.c b/libavformat/avio.c index 64248e098b..4718753b7b 100644 --- a/libavformat/avio.c +++ b/libavformat/avio.c @@ -391,8 +391,10 @@ 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; + } else if (ret == AVERROR_EOF) + return (len > 0) ? len : AVERROR_EOF; + else if (ret < 0) + return ret; if (ret) { fast_retries = FFMAX(fast_retries, 2); wait_since = 0; diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 636cb46161..0d4eb051e1 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -572,13 +572,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; @@ -646,13 +647,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/concat.c b/libavformat/concat.c index 46b520fe80..19c83c309a 100644 --- a/libavformat/concat.c +++ b/libavformat/concat.c @@ -135,19 +135,20 @@ static int concat_read(URLContext *h, unsigned char *buf, int size) while (size > 0) { result = ffurl_read(nodes[i].uc, buf, size); - if (result < 0) - return total ? total : result; - if (!result) { + if (result == AVERROR_EOF) { if (i + 1 == data->length || ffurl_seek(nodes[++i].uc, 0, SEEK_SET) < 0) break; + result = 0; } + if (result < 0) + return total ? total : result; total += result; buf += result; size -= result; } data->current = i; - return total; + return total ? total : result; } static int64_t concat_seek(URLContext *h, int64_t pos, int whence) diff --git a/libavformat/http.c b/libavformat/http.c index 668cd51986..bd9148f45d 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -1296,8 +1296,11 @@ static int http_buf_read(URLContext *h, uint8_t *buf, int size) "Chunked encoding data size: %"PRIu64"'\n", s->chunksize); - if (!s->chunksize) + if (!s->chunksize) { + av_log(h, AV_LOG_DEBUG, "Last chunk received, closing conn\n"); + ffurl_closep(&s->hd); return 0; + } else if (s->chunksize == UINT64_MAX) { av_log(h, AV_LOG_ERROR, "Invalid chunk size %"PRIu64"\n", s->chunksize);