Signed-off-by: Jacob Trimble <modma...@google.com> --- libavformat/matroskadec.c | 43 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-)
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 1ded431b80..bfef329e59 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2080,7 +2080,8 @@ static int matroska_parse_tracks(AVFormatContext *s) int extradata_offset = 0; uint32_t fourcc = 0; AVIOContext b; - char* key_id_base64 = NULL; + char* key_id = NULL; + int key_id_size = 0; int bit_depth = -1; /* Apply some sanity checks. */ @@ -2133,14 +2134,8 @@ static int matroska_parse_tracks(AVFormatContext *s) if (encodings[0].encryption.key_id.size > 0) { /* Save the encryption key id to be stored later as a metadata tag. */ - const int b64_size = AV_BASE64_SIZE(encodings[0].encryption.key_id.size); - key_id_base64 = av_malloc(b64_size); - if (key_id_base64 == NULL) - return AVERROR(ENOMEM); - - av_base64_encode(key_id_base64, b64_size, - encodings[0].encryption.key_id.data, - encodings[0].encryption.key_id.size); + key_id = encodings[0].encryption.key_id.data; + key_id_size = encodings[0].encryption.key_id.size; } else { encodings[0].scope = 0; av_log(matroska->ctx, AV_LOG_ERROR, @@ -2198,14 +2193,40 @@ static int matroska_parse_tracks(AVFormatContext *s) st = track->stream = avformat_new_stream(s, NULL); if (!st) { - av_free(key_id_base64); return AVERROR(ENOMEM); } - if (key_id_base64) { + if (key_id) { + AVEncryptionInitInfo *init_info; + uint8_t *side_data; + size_t side_data_size; + const int b64_size = AV_BASE64_SIZE(key_id_size); + char *key_id_base64 = av_malloc(b64_size); + if (!key_id_base64) + return AVERROR(ENOMEM); + av_base64_encode(key_id_base64, b64_size, key_id, key_id_size); + /* export encryption key id as base64 metadata tag */ av_dict_set(&st->metadata, "enc_key_id", key_id_base64, 0); av_freep(&key_id_base64); + + + /* Convert the key ID to a generic encryption init info */ + init_info = av_encryption_init_info_alloc(/* system_id_size */ 0, /* num_key_ids */ 1, + /* key_id_size */ key_id_size, /* data_size */ 0); + if (!init_info) + return AVERROR(ENOMEM); + memcpy(init_info->key_ids[0], key_id, key_id_size); + side_data = av_encryption_init_info_add_side_data(init_info, &side_data_size); + av_encryption_init_info_free(init_info); + if (!side_data) + return AVERROR(ENOMEM); + ret = av_stream_add_side_data(st, AV_PKT_DATA_ENCRYPTION_INIT_INFO, + side_data, side_data_size); + if (ret < 0) { + av_free(side_data); + return ret; + } } if (!strcmp(track->codec_id, "V_MS/VFW/FOURCC") && -- 2.18.0.203.gfac676dfb9-goog _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel