From patchwork Fri Oct 21 20:54:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Artyom V. Poptsov" X-Patchwork-Id: 1129 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.140.133 with SMTP id o127csp1350426vsd; Fri, 21 Oct 2016 22:09:10 -0700 (PDT) X-Received: by 10.194.94.39 with SMTP id cz7mr3602994wjb.141.1477112950453; Fri, 21 Oct 2016 22:09:10 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z62si1485811wmb.145.2016.10.21.22.09.10; Fri, 21 Oct 2016 22:09:10 -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; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C8AE6689A48; Sat, 22 Oct 2016 08:09:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f68.google.com (mail-lf0-f68.google.com [209.85.215.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 40ADF6891DA for ; Sat, 22 Oct 2016 00:08:06 +0300 (EEST) Received: by mail-lf0-f68.google.com with SMTP id x23so6568204lfi.1 for ; Fri, 21 Oct 2016 14:08:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version; bh=SgvG78Fkl2e/yeZNNOiT2pkev2LKPT+zzPp4VUqPhzI=; b=T0xQfaZlFmJD4hqfIYncSYsEwTzifhufjfoqIX4biZAmJqhPtKuX/e4WU3H1t/De2s rUggEseCA8+dpDTm4HlEyIj0IdYTxee1/uBkuN93pYX2EbZoJp8Q7zestkNUdzkQe7Jg 5TgPS/aIdqvVZ3+g2Os1dyfF7qVXLsBfQTuNo29sDz4ISHbFUyS7nQVodOvcHdFnYrsb axK2VY3sgA9U7/yjU37ArGou2O7Z1cjbiMsWEsMs8BtfgRdhXjA5puAT5KmSTpuVm3Ti Hmo+1eX/ln9jJZMAjOyAZJmcRym3AhalOMEaeYXwfq+iMBuDYiBffmzgiO504DCWMxSX Q+Rw== X-Gm-Message-State: ABUngve2Sub5GatMHUM9ReYOmtOBgV3RSvSfk8FfS+AV+XejQJtGeGqWS9N/G0A3rnRY6g== X-Received: by 10.25.133.198 with SMTP id h189mr1279228lfd.95.1477083318621; Fri, 21 Oct 2016 13:55:18 -0700 (PDT) Received: from elephant.savannah (93-120-179-209.dynamic.mts-nn.ru. [93.120.179.209]) by smtp.gmail.com with ESMTPSA id x23sm750012lfa.4.2016.10.21.13.55.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 21 Oct 2016 13:55:17 -0700 (PDT) From: Artyom V. Poptsov To: ffmpeg Developers Mailing List Date: Fri, 21 Oct 2016 23:54:17 +0300 Message-ID: <87lgxhjudi.fsf@elephant.savannah> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 22 Oct 2016 08:09:03 +0300 Subject: [FFmpeg-devel] [PATCH] libavformat/segment.c: Handle custom HTTP headers 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" Hello everybody, as far as I could see ffmpeg from the 'master' branch doesn't add custom HTTP headers (specified by means of '-headers' option) to the requests when 'segment' format is used (checked on August 31st.) I prepared a patch that allows to use custom headers along with 'segment' format. The patch is based on commit a13a81a0dc98a35293f3f2603db9b01bf76b6a05 from the 'master' branch. The changes were tested on x86 and ARM platforms and it seems that it works quite well. I'm hoping that the attached patch could be of some use for others as it's quite common to use some kind of HTTP authentication mechanism which requires additional headers. Please let me know if there any problems with the patch; it's my first contribution to ffmpeg project and I'd love to get any feedback. Thanks, - Artyom From 9ab977b521ef9221bc44655872a301eb67f85d7a Mon Sep 17 00:00:00 2001 From: "Artyom V. Poptsov" Date: Wed, 31 Aug 2016 20:56:11 +0400 Subject: [PATCH] libavformat/segment.c: Handle custom HTTP headers * libavformat/segment.c: Handle custom HTTP headers. (SegmentContext): Add 'headers' field. (segment_start): Append the headers; send the headers. (segment_list_open): Likewise. (seg_init): Likewise. (options): Add 'headers' option. --- libavformat/segment.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libavformat/segment.c b/libavformat/segment.c index bf29ef8..9b1448e 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2011, Luca Barbato + * Copyright (c) 2016, Artyom V. Poptsov * * This file is part of FFmpeg. * @@ -112,6 +113,7 @@ typedef struct SegmentContext { int individual_header_trailer; /**< Set by a private option. */ int write_header_trailer; /**< Set by a private option. */ char *header_filename; ///< filename to write the output header to + char *headers; ///< HTTP headers int reset_timestamps; ///< reset timestamps at the begin of each segment int64_t initial_offset; ///< initial timestamps offset, expressed in microseconds @@ -247,7 +249,10 @@ static int segment_start(AVFormatContext *s, int write_header) if ((err = set_segment_filename(s)) < 0) return err; - if ((err = s->io_open(s, &oc->pb, oc->filename, AVIO_FLAG_WRITE, NULL)) < 0) { + AVDictionary *d = NULL; + av_dict_set(&d, "headers", seg->headers, 0); + + if ((err = s->io_open(s, &oc->pb, oc->filename, AVIO_FLAG_WRITE, &d)) < 0) { av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", oc->filename); return err; } @@ -276,7 +281,9 @@ static int segment_list_open(AVFormatContext *s) int ret; snprintf(seg->temp_list_filename, sizeof(seg->temp_list_filename), seg->use_rename ? "%s.tmp" : "%s", seg->list); - ret = s->io_open(s, &seg->list_pb, seg->temp_list_filename, AVIO_FLAG_WRITE, NULL); + AVDictionary *d = NULL; + av_dict_set(&d, "headers", seg->headers, 0); + ret = s->io_open(s, &seg->list_pb, seg->temp_list_filename, AVIO_FLAG_WRITE, &d); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Failed to open segment list '%s'\n", seg->list); return ret; @@ -738,10 +745,13 @@ static int seg_init(AVFormatContext *s) goto fail; oc = seg->avf; + AVDictionary *d = NULL; + av_dict_set(&d, "headers", seg->headers, 0); + if (seg->write_header_trailer) { if ((ret = s->io_open(s, &oc->pb, seg->header_filename ? seg->header_filename : oc->filename, - AVIO_FLAG_WRITE, NULL)) < 0) { + AVIO_FLAG_WRITE, &d)) < 0) { av_log(s, AV_LOG_ERROR, "Failed to open segment '%s'\n", oc->filename); goto fail; } @@ -784,7 +794,7 @@ static int seg_init(AVFormatContext *s) } else { close_null_ctxp(&oc->pb); } - if ((ret = oc->io_open(oc, &oc->pb, oc->filename, AVIO_FLAG_WRITE, NULL)) < 0) + if ((ret = oc->io_open(oc, &oc->pb, oc->filename, AVIO_FLAG_WRITE, &d)) < 0) goto fail; if (!seg->individual_header_trailer) oc->pb->seekable = 0; @@ -1000,6 +1010,7 @@ static const AVOption options[] = { { "reset_timestamps", "reset timestamps at the begin of each segment", OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E }, { "initial_offset", "set initial timestamp offset", OFFSET(initial_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E }, { "write_empty_segments", "allow writing empty 'filler' segments", OFFSET(write_empty), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E }, + { "headers", "set custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E }, { NULL }, }; -- 2.7.3