Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-04-25 04:47:47 +0400
committerMichael Niedermayer <michaelni@gmx.at>2011-04-25 05:49:47 +0400
commit2ebd47841f16d1d521d7dd9b5ae0b8015443b690 (patch)
tree5e32bef0eda02346d15fa212326806ab58e9103b /libavformat/applehttp.c
parent9d7244c4c60d9f85f58b3770065a394c71fdce3f (diff)
parent989fb05fe344d9666db858e0577c44969625184e (diff)
Merge branch 'master' into oldabi
* master: (172 commits) Check mmap() return against correct value Signed-off-by: Michael Niedermayer <michaelni@gmx.at> vorbisdec: Employ proper printf format specifiers for uint_fast32_t. Support fourcc MMJP. Support fourcc XVIX. Support fourcc M263. Support fourcc auv2. Fix indentation. Support PARSER_FLAG_COMPLETE_FRAMES for h261 and h263 parsers. ffplay: avoid SIGFPE exception in SDL_DisplayYUVOverlay avi: try to synchronize the points in time of the starts of streams after seeking. Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Add flag to force demuxers to sort more strictly by dts. This enables non interleaved AVI mode for example. Players that are picky on strict interleaving can set this. Patches to only switch to non intereaved AVI mode when the index is not strictly correctly interleaved are welcome. Signed-off-by: Michael Niedermayer <michaelni@gmx.at> applehttp: Don't export variant_bitrate if it isn't known crypto: Use av_freep instead of av_free CrystalHD: Add AVOption to configure hardware downscaling. Check for malloc failures in fraps decoder. Use av_fast_malloc instead of av_realloc in fraps decoder. general.texi: document libcelt decoder. Fix some passing argument from incompatible pointer type warnings. Signed-off-by: Michael Niedermayer <michaelni@gmx.at> configure: Add missing libm library dependencies to .pc files. oggdec: reindent after 8f3eebd6 ... Conflicts: libavcodec/version.h Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/applehttp.c')
-rw-r--r--libavformat/applehttp.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/libavformat/applehttp.c b/libavformat/applehttp.c
index 7e6d2d79e5..a6cdad1f29 100644
--- a/libavformat/applehttp.c
+++ b/libavformat/applehttp.c
@@ -27,6 +27,8 @@
#define _XOPEN_SOURCE 600
#include "libavutil/avstring.h"
+#include "libavutil/intreadwrite.h"
+#include "libavutil/opt.h"
#include "avformat.h"
#include "internal.h"
#include <unistd.h>
@@ -47,9 +49,17 @@
* one anonymous toplevel variant for this, to maintain the structure.
*/
+enum KeyType {
+ KEY_NONE,
+ KEY_AES_128,
+};
+
struct segment {
int duration;
char url[MAX_URL_SIZE];
+ char key[MAX_URL_SIZE];
+ enum KeyType key_type;
+ uint8_t iv[16];
};
/*
@@ -77,6 +87,9 @@ struct variant {
int needed, cur_needed;
int cur_seq_no;
int64_t last_load_time;
+
+ char key_url[MAX_URL_SIZE];
+ uint8_t key[16];
};
typedef struct AppleHTTPContext {
@@ -160,10 +173,35 @@ static void handle_variant_args(struct variant_info *info, const char *key,
}
}
+struct key_info {
+ char uri[MAX_URL_SIZE];
+ char method[10];
+ char iv[35];
+};
+
+static void handle_key_args(struct key_info *info, const char *key,
+ int key_len, char **dest, int *dest_len)
+{
+ if (!strncmp(key, "METHOD=", key_len)) {
+ *dest = info->method;
+ *dest_len = sizeof(info->method);
+ } else if (!strncmp(key, "URI=", key_len)) {
+ *dest = info->uri;
+ *dest_len = sizeof(info->uri);
+ } else if (!strncmp(key, "IV=", key_len)) {
+ *dest = info->iv;
+ *dest_len = sizeof(info->iv);
+ }
+}
+
static int parse_playlist(AppleHTTPContext *c, const char *url,
struct variant *var, AVIOContext *in)
{
int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0;
+ enum KeyType key_type = KEY_NONE;
+ uint8_t iv[16] = "";
+ int has_iv = 0;
+ char key[MAX_URL_SIZE];
char line[1024];
const char *ptr;
int close_in = 0;
@@ -192,6 +230,19 @@ static int parse_playlist(AppleHTTPContext *c, const char *url,
ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args,
&info);
bandwidth = atoi(info.bandwidth);
+ } else if (av_strstart(line, "#EXT-X-KEY:", &ptr)) {
+ struct key_info info = {{0}};
+ ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_key_args,
+ &info);
+ key_type = KEY_NONE;
+ has_iv = 0;
+ if (!strcmp(info.method, "AES-128"))
+ key_type = KEY_AES_128;
+ if (!strncmp(info.iv, "0x", 2) || !strncmp(info.iv, "0X", 2)) {
+ ff_hex_to_data(iv, info.iv + 2);
+ has_iv = 1;
+ }
+ av_strlcpy(key, info.uri, sizeof(key));
} else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) {
if (!var) {
var = new_variant(c, 0, url, NULL);
@@ -242,6 +293,15 @@ static int parse_playlist(AppleHTTPContext *c, const char *url,
goto fail;
}
seg->duration = duration;
+ seg->key_type = key_type;
+ if (has_iv) {
+ memcpy(seg->iv, iv, sizeof(iv));
+ } else {
+ int seq = var->start_seq_no + var->n_segments;
+ memset(seg->iv, 0, sizeof(seg->iv));
+ AV_WB32(seg->iv + 12, seq);
+ }
+ ff_make_absolute_url(seg->key, sizeof(seg->key), url, key);
ff_make_absolute_url(seg->url, sizeof(seg->url), url, line);
dynarray_add(&var->segments, &var->n_segments, seg);
is_segment = 0;
@@ -257,6 +317,50 @@ fail:
return ret;
}
+static int open_input(struct variant *var)
+{
+ struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no];
+ if (seg->key_type == KEY_NONE) {
+ return ffurl_open(&var->input, seg->url, AVIO_RDONLY);
+ } else if (seg->key_type == KEY_AES_128) {
+ char iv[33], key[33], url[MAX_URL_SIZE];
+ int ret;
+ if (strcmp(seg->key, var->key_url)) {
+ URLContext *uc;
+ if (ffurl_open(&uc, seg->key, AVIO_RDONLY) == 0) {
+ if (ffurl_read_complete(uc, var->key, sizeof(var->key))
+ != sizeof(var->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);
+ }
+ av_strlcpy(var->key_url, seg->key, sizeof(var->key_url));
+ }
+ ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0);
+ ff_data_to_hex(key, var->key, sizeof(var->key), 0);
+ iv[32] = key[32] = '\0';
+ if (strstr(seg->url, "://"))
+ snprintf(url, sizeof(url), "crypto+%s", seg->url);
+ else
+ snprintf(url, sizeof(url), "crypto:%s", seg->url);
+ if ((ret = ffurl_alloc(&var->input, url, AVIO_RDONLY)) < 0)
+ return ret;
+ av_set_string3(var->input->priv_data, "key", key, 0, NULL);
+ av_set_string3(var->input->priv_data, "iv", iv, 0, NULL);
+ if ((ret = ffurl_connect(var->input)) < 0) {
+ ffurl_close(var->input);
+ var->input = NULL;
+ return ret;
+ }
+ return 0;
+ }
+ return AVERROR(ENOSYS);
+}
+
static int read_data(void *opaque, uint8_t *buf, int buf_size)
{
struct variant *v = opaque;
@@ -367,6 +471,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
for (i = 0; i < c->n_variants; i++) {
struct variant *v = c->variants[i];
AVInputFormat *in_fmt = NULL;
+ char bitrate_str[20];
if (v->n_segments == 0)
continue;
@@ -393,6 +498,7 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
if (ret < 0)
goto fail;
v->stream_offset = stream_offset;
+ snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth);
/* Create new AVStreams for each stream in this variant */
for (j = 0; j < v->ctx->nb_streams; j++) {
AVStream *st = av_new_stream(s, i);
@@ -401,6 +507,9 @@ static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap)
goto fail;
}
avcodec_copy_context(st->codec, v->ctx->streams[j]->codec);
+ if (v->bandwidth)
+ av_metadata_set2(&st->metadata, "variant_bitrate", bitrate_str,
+ 0);
}
stream_offset += v->ctx->nb_streams;
}