From patchwork Fri Dec 9 11:54:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PHILIP DE NIER X-Patchwork-Id: 1729 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.86 with SMTP id o83csp260229vsa; Fri, 9 Dec 2016 03:57:45 -0800 (PST) X-Received: by 10.28.68.195 with SMTP id r186mr6352565wma.105.1481284665143; Fri, 09 Dec 2016 03:57:45 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id qj8si33625176wjb.165.2016.12.09.03.57.44; Fri, 09 Dec 2016 03:57:45 -0800 (PST) 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=@btinternet.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 dis=NONE) header.from=btinternet.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6625068A10B; Fri, 9 Dec 2016 13:57:39 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nm35-vm6.bullet.mail.gq1.yahoo.com (nm35-vm6.bullet.mail.gq1.yahoo.com [98.136.216.189]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E0C7368A0EA for ; Fri, 9 Dec 2016 13:57:32 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com; s=s2048; t=1481284654; bh=sfzhjhYEyEb2IxpJyNajqZRkNZxHTcsTIR2vsgP7Ysw=; h=Date:From:Reply-To:To:Subject:References:From:Subject; b=g8Mkr1XtJ/078kGrBTGVXti8/VsOSbVTRkVDl02IVbdT27YtLuXn+G5NeqFby8Sktj/TnlQD/b7sAuT+K+FcYgkrPFOvi0+/mGai64aaJNYN1CJoV9sSLXxwbAUN5gwDehcVrgq8lXyMDCLencD/FbgYayW3HwgjACxYdcfncKKyYuwspMG4W7OeY3DkS2JMSs5XmXkXZnGTqoTFJqTIyTuili1nVSRyY5PUwYaXeyQD6ShBXZOqqcEGSLHmMzO+aAivyB2pBzL9zRTCOEAhctT4oqyJD3KBt5hRnfO+e44hEC962boTYpsX9HK+Ii/fSG8GvjngLCmXYK7w8r6/cw== Received: from [127.0.0.1] by nm35.bullet.mail.gq1.yahoo.com with NNFMP; 09 Dec 2016 11:57:34 -0000 Received: from [98.137.12.191] by nm35.bullet.mail.gq1.yahoo.com with NNFMP; 09 Dec 2016 11:54:43 -0000 Received: from [212.82.98.56] by tm12.bullet.mail.gq1.yahoo.com with NNFMP; 09 Dec 2016 11:54:43 -0000 Received: from [212.82.98.65] by tm9.bullet.mail.ir2.yahoo.com with NNFMP; 09 Dec 2016 11:54:43 -0000 Received: from [127.0.0.1] by omp1002.mail.ir2.yahoo.com with NNFMP; 09 Dec 2016 11:54:43 -0000 X-Yahoo-Newman-Property: ymail-4 X-Yahoo-Newman-Id: 141523.17532.bm@omp1002.mail.ir2.yahoo.com X-YMail-OSG: cCKp2YAVM1n6v0Qcni74kvUZ..dFmGC7iVTUjg7OMyIvpICfcvap0_aUINzyTyb KpXORJ2Rqb4uROovy4nOpvMSBGwJUBKzfaLcZKnKkMZz5_ANt3m6dxiU3lX.2eifSezEf7gxj01z GJwggY.621IGkVjXee6MRlfxhLFyiMs0IrMFOanjkQorUJUv6YEPa7tcYwHSnb4jVMds23FcrJw. Ne5p3Vibzg9XmYyWiQY.Y3lkCnDI51NT3Qj863TVyUWdjoZ_k49MGhvDwQsts8Y.jiI27vyTs_7n Wixqj2AfO84muihRdL5f.hvznrad3xqJVEg_Ro_E2A6e80SiceVuSIecMr8svn5KKcSmOR_Um38J VBrEtLPd5M8CY1weDgVFNjwFBEMW2Al2FfxG4v.eL7q1viPQJ0Ikmt6fyf.n3G6q9MxUVsrNskPV LUCvvRymJ9N2igQHbz138il82Y2pF0lz4FBvIJFRLzOFhbBiNi0JZiv4OPjzmfUwZW_vIdSGjnHr sITeFC.6VgT3FzUZp6rDh1Ui7GVHjSFstoDH4nnbSv5qEaZXl6C_TSsw- Received: from jws700057.mail.ir2.yahoo.com by sendmailws163.mail.ir2.yahoo.com; Fri, 09 Dec 2016 11:54:42 +0000; 1481284482.598 Date: Fri, 9 Dec 2016 11:54:42 +0000 (UTC) From: PHILIP DE NIER To: "ffmpeg-devel@ffmpeg.org" Message-ID: <661340250.1596155.1481284482287@mail.yahoo.com> MIME-Version: 1.0 References: <661340250.1596155.1481284482287.ref@mail.yahoo.com> X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] avformat/http: allow content range to set filesize 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi, Attached patch fixes issue #6007 for me. I think it could improved / extended because the "if (s->seekable == -1 && (!s->is_akamai || s->content_range_len != 2147483647))" is probably better placed http_read_header along with the similar is_mediagateway workaround. I wasn't sure whether the is_akamai should only be triggered if the filesize was read from the Content-Range header. Philip From 0ac79d03981e823a1922e7e1f58af7f3b02dca7d Mon Sep 17 00:00:00 2001 From: Philip de Nier Date: Wed, 7 Dec 2016 15:09:09 +0000 Subject: [PATCH] http: allow content range to set filesize Set filesize to Content-Length if present and Transfer-Encoding is not chunked. Otherwise set to Content-Range instance length if present. Solves issue where filesize is set to unknown when using byte range requests in combination with chunked transfers. Fixes issue #6007 --- libavformat/http.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 944a6cf..8dfaa5d 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -63,6 +63,7 @@ typedef struct HTTPContext { int http_code; /* Used if "Transfer-Encoding: chunked" otherwise -1. */ uint64_t chunksize; + uint64_t content_len, content_range_len; uint64_t off, end_off, filesize; char *location; HTTPAuthState auth_state; @@ -618,9 +619,9 @@ static void parse_content_range(URLContext *h, const char *p) p += 6; s->off = strtoull(p, NULL, 10); if ((slash = strchr(p, '/')) && strlen(slash) > 0) - s->filesize = strtoull(slash + 1, NULL, 10); + s->content_range_len = strtoull(slash + 1, NULL, 10); } - if (s->seekable == -1 && (!s->is_akamai || s->filesize != 2147483647)) + if (s->seekable == -1 && (!s->is_akamai || s->content_range_len != 2147483647)) h->is_streamed = 0; /* we _can_ in fact seek */ } @@ -810,7 +811,7 @@ static int process_line(URLContext *h, char *line, int line_count, *new_location = 1; } else if (!av_strcasecmp(tag, "Content-Length") && s->filesize == UINT64_MAX) { - s->filesize = strtoull(p, NULL, 10); + s->content_len = strtoull(p, NULL, 10); } else if (!av_strcasecmp(tag, "Content-Range")) { parse_content_range(h, p); } else if (!av_strcasecmp(tag, "Accept-Ranges") && @@ -819,7 +820,6 @@ static int process_line(URLContext *h, char *line, int line_count, h->is_streamed = 0; } else if (!av_strcasecmp(tag, "Transfer-Encoding") && !av_strncasecmp(p, "chunked", 7)) { - s->filesize = UINT64_MAX; s->chunksize = 0; } else if (!av_strcasecmp(tag, "WWW-Authenticate")) { ff_http_auth_handle_header(&s->auth_state, tag, p); @@ -974,6 +974,8 @@ static int http_read_header(URLContext *h, int *new_location) int err = 0; s->chunksize = UINT64_MAX; + s->content_range_len = UINT64_MAX; + s->content_len = UINT64_MAX; for (;;) { if ((err = http_get_line(s, line, sizeof(line))) < 0) @@ -989,6 +991,13 @@ static int http_read_header(URLContext *h, int *new_location) s->line_count++; } + if (s->filesize == UINT64_MAX) { + if (s->chunksize == UINT64_MAX && s->content_len != UINT64_MAX) + s->filesize = s->content_len; + else if (s->content_range_len != UINT64_MAX) + s->filesize = s->content_range_len; + } + if (s->seekable == -1 && s->is_mediagateway && s->filesize == 2000000000) h->is_streamed = 1; /* we can in fact _not_ seek */ -- 1.9.1