From patchwork Thu Feb 16 00:34:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Steven X-Patchwork-Id: 2572 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp2226083vsb; Wed, 15 Feb 2017 16:35:04 -0800 (PST) X-Received: by 10.223.136.168 with SMTP id f37mr2954715wrf.98.1487205304604; Wed, 15 Feb 2017 16:35:04 -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 d13si6864218wra.226.2017.02.15.16.35.04; Wed, 15 Feb 2017 16:35:04 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 944B2689748; Thu, 16 Feb 2017 02:34:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtpbgbr2.qq.com (smtpbgbr2.qq.com [54.207.22.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7B213689748 for ; Thu, 16 Feb 2017 02:34:47 +0200 (EET) X-QQ-mid: bizesmtp16t1487205260tsxxemru Received: from localhost (unknown [47.90.47.25]) by esmtp4.qq.com (ESMTP) with id ; Thu, 16 Feb 2017 08:34:19 +0800 (CST) X-QQ-SSF: 01100000003000F0F820B00A0000000 X-QQ-FEAT: R/yWRekfFcrBqHSnuHhXA1PNMrktGNq119Bgxzi8s1NttbOk+uSupTnNhFAIX bETu+Ou42TIPgfxMofGnpEjWIY3BKBT2zVaA+YnsTy4jbaH6TXRs0IyzBQqwDSJohY/ndDN fZ7tFNOHzb0X3HMgchkkbdkY2QqduuoUsd98Hq4bYXUkwTZd2yEsPB5HEhplZ3UifIkPYQc f98xxx4a4OpSEn98JvCSzhNZWrTC5THx+YAy7NI/feYHZZ/mI3JTpAPJKoIN/TbkJWC/MpV uJabBQ30nVi7LM X-QQ-GoodBg: 0 From: Steven Liu To: ffmpeg-devel@ffmpeg.org Date: Thu, 16 Feb 2017 08:34:18 +0800 Message-Id: <20170216003418.7223-1-lq@chinaffmpeg.org> X-Mailer: git-send-email 2.10.1.382.ga23ca1b.dirty X-QQ-SENDSIZE: 520 X-QQ-Bgrelay: 1 Subject: [FFmpeg-devel] [PATCH v2] avformat/hlsenc: set default http method to PUT when method is null 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: Steven Liu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" When the http method is not set, the method will use POST for ts, PUT for m3u8, it is not unify, now set it unify. This ticket id: 5315 Reviewed-by: Moritz Barsnick Signed-off-by: Steven Liu --- libavformat/hlsenc.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index 930e94b..c8401ec 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -242,7 +242,7 @@ fail: return -1; } -static int hls_delete_old_segments(HLSContext *hls) { +static int hls_delete_old_segments(AVFormatContext *s, HLSContext *hls) { HLSSegment *segment, *previous_segment = NULL; float playlist_duration = 0.0f; @@ -251,6 +251,7 @@ static int hls_delete_old_segments(HLSContext *hls) { char *path = NULL; AVDictionary *options = NULL; AVIOContext *out = NULL; + const char *proto = NULL; segment = hls->segments; while (segment) { @@ -300,7 +301,8 @@ static int hls_delete_old_segments(HLSContext *hls) { av_strlcat(path, segment->filename, path_size); } - if (hls->method) { + proto = avio_find_protocol_name(s->filename); + if (hls->method || (proto && !av_strcasecmp(proto, "http"))) { av_dict_set(&options, "method", "DELETE", 0); if ((ret = hls->avf->io_open(hls->avf, &out, path, AVIO_FLAG_WRITE, &options)) < 0) goto fail; @@ -321,7 +323,7 @@ static int hls_delete_old_segments(HLSContext *hls) { av_strlcpy(sub_path, dirname, sub_path_size); av_strlcat(sub_path, segment->sub_filename, sub_path_size); - if (hls->method) { + if (hls->method || (proto && !av_strcasecmp(proto, "http"))) { av_dict_set(&options, "method", "DELETE", 0); if ((ret = hls->avf->io_open(hls->avf, &out, sub_path, AVIO_FLAG_WRITE, &options)) < 0) { av_free(sub_path); @@ -576,7 +578,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, double #endif en->next = hls->old_segments; hls->old_segments = en; - if ((ret = hls_delete_old_segments(hls)) < 0) + if ((ret = hls_delete_old_segments(s, hls)) < 0) return ret; } else av_free(en); @@ -663,10 +665,17 @@ static void hls_free_segments(HLSSegment *p) } } -static void set_http_options(AVDictionary **options, HLSContext *c) +static void set_http_options(AVFormatContext *s, AVDictionary **options, HLSContext *c) { - if (c->method) + const char *proto = avio_find_protocol_name(s->filename); + int http_base_proto = !av_strcasecmp(proto, "http") || !av_strcasecmp(proto, "https"); + + if (c->method) { av_dict_set(options, "method", c->method, 0); + } else if (proto && http_base_proto) { + av_log(c, AV_LOG_WARNING, "No HTTP method set, hls muxer defaulting to method PUT.\n"); + av_dict_set(options, "method", "PUT", 0); + } } static void write_m3u8_head_block(HLSContext *hls, AVIOContext *out, int version, @@ -710,7 +719,7 @@ static int hls_window(AVFormatContext *s, int last) if (!use_rename && !warned_non_file++) av_log(s, AV_LOG_ERROR, "Cannot use rename on non file protocol, this may lead to races and temporary partial files\n"); - set_http_options(&options, hls); + set_http_options(s, &options, hls); snprintf(temp_filename, sizeof(temp_filename), use_rename ? "%s.tmp" : "%s", s->filename); if ((ret = s->io_open(s, &out, temp_filename, AVIO_FLAG_WRITE, &options)) < 0) goto fail; @@ -947,7 +956,7 @@ static int hls_start(AVFormatContext *s) } c->number++; - set_http_options(&options, c); + set_http_options(s, &options, c); if (c->flags & HLS_TEMP_FILE) { av_strlcat(oc->filename, ".tmp", sizeof(oc->filename)); @@ -979,7 +988,7 @@ static int hls_start(AVFormatContext *s) if ((err = s->io_open(s, &oc->pb, oc->filename, AVIO_FLAG_WRITE, &options)) < 0) goto fail; if (c->vtt_basename) { - set_http_options(&options, c); + set_http_options(s, &options, c); if ((err = s->io_open(s, &vtt_oc->pb, vtt_oc->filename, AVIO_FLAG_WRITE, &options)) < 0) goto fail; }