[FFmpeg-devel] [PATCH] Allow HLS to decrypt stream when using a data url for the key
Simon Black
sblack at omnifone.com
Thu Mar 13 11:00:46 CET 2014
If HLS is trying to play an encrypted stream where the key is a data URL rather
than a file based key HLS will not work.
a data url within the key is one such as:
#EXT-X-KEY:METHOD=AES-128,URI="data:;base64,dKbarMNMRSmPPEXQ3dDCNA=="
The error message is reported as:
[https @ 0x7f9eb00120c0] HTTP error 404 Not Found
Unable to open key file
https://BASE.URL.HERE/data:;base64,dKbarMNMRSmPPEXQ3dDCNA
==
This is caused as the URL is created with the value in URI field of the
EXT-X-KEY tag using
ff_make_absolute_url(seg->key, sizeof(seg->key), url, key);
the data: schema is ignored.
Signed-off-by: Simon Black <sblack at omnifone.com>
---
libavformat/hls.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/libavformat/hls.c b/libavformat/hls.c
index e291950..cba6cce 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -30,6 +30,7 @@
#include "libavutil/mathematics.h"
#include "libavutil/opt.h"
#include "libavutil/dict.h"
+#include "libavutil/base64.h"
#include "libavutil/time.h"
#include "avformat.h"
#include "internal.h"
@@ -367,7 +368,11 @@ static int parse_playlist(HLSContext *c, const char *url,
memset(seg->iv, 0, sizeof(seg->iv));
AV_WB32(seg->iv + 12, seq);
}
- ff_make_absolute_url(seg->key, sizeof(seg->key), url, key);
+ if (key==strstr (key,"data:")) {
+ av_strlcpy(seg->key, key, sizeof(seg->key));
+ } else {
+ ff_make_absolute_url(seg->key, sizeof(seg->key), url, key);
+ }
ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
dynarray_add(&pls->segments, &pls->n_segments, seg);
is_segment = 0;
@@ -408,17 +413,26 @@ static int open_input(HLSContext *c, struct playlist *pls)
char iv[33], key[33], url[MAX_URL_SIZE];
if (strcmp(seg->key, pls->key_url)) {
URLContext *uc;
- if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ,
+ if (seg->key==strstr (seg->key,"data:")) {
+ if (strstr(seg->key,"data:;base64,")) {
+ av_base64_decode(pls->key, &seg->key[13], sizeof(pls->key));
+ } else {
+ av_log(NULL, AV_LOG_ERROR, "Unable to use data key %s\n", seg->key);
+ }
+ } else {
+ if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ,
&pls->parent->interrupt_callback, &opts2) == 0) {
- if (ffurl_read_complete(uc, pls->key, sizeof(pls->key))
- != sizeof(pls->key)) {
- av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n",
+ if (ffurl_read_complete(uc, pls->key, sizeof(pls->key))
+ != sizeof(pls->key)) {
+ av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n",
+ seg->key);
+ }
+ ffurl_close(uc);
+ } else {
+ av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n",
seg->key);
}
- ffurl_close(uc);
- } else {
- av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n",
- seg->key);
+ ffurl_close(uc);
}
av_strlcpy(pls->key_url, seg->key, sizeof(pls->key_url));
}
--
1.8.5.2 (Apple Git-48)
______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________
More information about the ffmpeg-devel
mailing list