From patchwork Sun Aug 23 12:23:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hongcheng Zhong X-Patchwork-Id: 21841 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 10CBB449B15 for ; Sun, 23 Aug 2020 15:24:26 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DD40C6899A8; Sun, 23 Aug 2020 15:24:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from smtp181.sjtu.edu.cn (smtp181.sjtu.edu.cn [202.120.2.181]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 832B968827C for ; Sun, 23 Aug 2020 15:24:18 +0300 (EEST) Received: from proxy02.sjtu.edu.cn (smtp188.sjtu.edu.cn [202.120.2.188]) by smtp181.sjtu.edu.cn (Postfix) with ESMTPS id D74261008CBCE; Sun, 23 Aug 2020 20:24:15 +0800 (CST) Received: from localhost (localhost.localdomain [127.0.0.1]) by proxy02.sjtu.edu.cn (Postfix) with ESMTP id E0311200B44A4; Sun, 23 Aug 2020 20:24:14 +0800 (CST) X-Virus-Scanned: amavisd-new at Received: from proxy02.sjtu.edu.cn ([127.0.0.1]) by localhost (proxy02.sjtu.edu.cn [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id tRW8siZiBNGc; Sun, 23 Aug 2020 20:24:14 +0800 (CST) Received: from localhost.localdomain (unknown [10.162.157.92]) (Authenticated sender: sj.hc_Zhong@sjtu.edu.cn) by proxy02.sjtu.edu.cn (Postfix) with ESMTPSA id DD107200A4B0C; Sun, 23 Aug 2020 20:24:10 +0800 (CST) From: Hongcheng Zhong To: ffmpeg-devel@ffmpeg.org Date: Sun, 23 Aug 2020 20:23:52 +0800 Message-Id: <20200823122355.188611-4-sj.hc_Zhong@sjtu.edu.cn> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200823122355.188611-1-sj.hc_Zhong@sjtu.edu.cn> References: <20200823122355.188611-1-sj.hc_Zhong@sjtu.edu.cn> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] [GSoC v3 4/7] avformat/hls allow crypto works as ffabr's subprotocol 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: spartazhc Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: spartazhc For example, ffabr:crypto+http://xxx.m3u8 Signed-off-by: spartazhc --- libavformat/hls.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libavformat/hls.c b/libavformat/hls.c index 4e760f8e8a..37a5a017b1 100644 --- a/libavformat/hls.c +++ b/libavformat/hls.c @@ -765,6 +765,8 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, is_http = 1; } else if (av_strstart(proto_name, "data", NULL)) { ; + } else if (av_strstart(proto_name, "crypto", NULL)) { + ; } else return AVERROR_INVALIDDATA; @@ -774,7 +776,8 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, const char *url, ; else if (av_strstart(url, "data", NULL) && !strncmp(proto_name, url + 5, strlen(proto_name)) && url[5 + strlen(proto_name)] == ':') ; - else if (av_strstart(url, "ffabr", NULL) && !strncmp(proto_name, url + 6, strlen(proto_name)) && url[6 + strlen(proto_name)] == ':') + else if (av_strstart(url, "ffabr", NULL) && !strncmp(proto_name, url + 6, strlen(proto_name)) + && (url[6 + strlen(proto_name)] == ':' || url[6 + strlen(proto_name)] == '+')) ; else if (strcmp(proto_name, "file") || !strncmp(url, "file,", 5)) return AVERROR_INVALIDDATA; @@ -1455,7 +1458,7 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, ret = open_url(pls->parent, in, seg->url, c->avio_opts, opts, &is_http); } } else if (seg->key_type == KEY_AES_128) { - char iv[33], key[33], url[MAX_URL_SIZE]; + char iv[33], key[33], url[MAX_URL_SIZE], prefix[13]; if (strcmp(seg->key, pls->key_url)) { AVIOContext *pb = NULL; if (open_url(pls->parent, &pb, seg->key, c->avio_opts, opts, NULL) == 0) { @@ -1474,10 +1477,15 @@ static int open_input(HLSContext *c, struct playlist *pls, struct segment *seg, ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0); ff_data_to_hex(key, pls->key, sizeof(pls->key), 0); iv[32] = key[32] = '\0'; + if (c->abr) + sprintf(prefix, "ffabr:crypto"); + else + sprintf(prefix, "crypto"); + if (strstr(seg->url, "://")) - snprintf(url, sizeof(url), "crypto+%s", seg->url); + snprintf(url, sizeof(url), "%s+%s", prefix, seg->url); else - snprintf(url, sizeof(url), "crypto:%s", seg->url); + snprintf(url, sizeof(url), "%s:%s", prefix, seg->url); av_dict_set(&opts, "key", key, 0); av_dict_set(&opts, "iv", iv, 0);