diff mbox series

[FFmpeg-devel,GSoC,v3,4/7] avformat/hls allow crypto works as ffabr's subprotocol

Message ID 20200823122355.188611-4-sj.hc_Zhong@sjtu.edu.cn
State New
Headers show
Series [FFmpeg-devel,GSoC,v3,1/7] avformat/abr: Adaptive Bitrate support | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Hongcheng Zhong Aug. 23, 2020, 12:23 p.m. UTC
From: spartazhc <spartazhc@gmail.com>

For example, ffabr:crypto+http://xxx.m3u8

Signed-off-by: spartazhc <spartazhc@gmail.com>
---
 libavformat/hls.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

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);