From patchwork Tue Aug 28 19:56:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Trimble X-Patchwork-Id: 10164 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp8033046jap; Tue, 28 Aug 2018 13:02:09 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZyuAZJMnTOK+4C4Ig3/GLttbzNcF3HiVbUmpDy1alIBO4KcIUG3loydJCHLIc6lJyp9JRO X-Received: by 2002:adf:ed88:: with SMTP id c8-v6mr2130925wro.264.1535486529320; Tue, 28 Aug 2018 13:02:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535486529; cv=none; d=google.com; s=arc-20160816; b=FFsvDtIAnZuwyNugX1seZwj5zM1Z5jJKdHDLpDA7XyzRdaaqwGsrTWWdVEjTT0yPlR +9K0rmfJfEYc4OMO3VCMy2CUHMQUvNP2A23mosQeWHMPbZ0J3rWkFda0bRlNZsHNxXhF q9ltKzwBzJjWlpC080s1fiAvNtr0DwiHRsScdor/4DMnYerI6792wIWYBLZOGtetE/zG pnLa/WwkRo3inD5agwg3Uo/2oKC/aOrIqdLUHUBB3htZyL8fRRAPsUe354CGW30Qnn0d aWAf372kIMeoS0fPqZHeWcisQDZ9cwb6UmqUZEJHjNJ4VOKbjOI5Mh8kVWigfjZD8GJl eUrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:subject:to :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=XJIMlt8X9RHUHHcWiDGWpeuxpmx07T879TgIZbg2R2E=; b=efjkmzTQrpeFRIQOm/TyQ5LuQK6bd5ynPUFiAt3OJpAvMjV5bi4e65bOja7isgCVcg vzajZhVsz2dAVVylZhmn47K+u36Uqp8r+PX8YpNvK7+cgkfqh75NRnXsfgQ70ICMIhV7 YjSNSPcZC9ZFJfg6n3U9hTnJ3n4kiB5l3xmxYcIAGO/cUyTb2DSqSXbVTG5ZkP7Dv/qM iSptRz6xd60U9bnUZcbRQEpIyQPuIkny6D/4RGDKNpUSlKGVi8/QQhb2X54esjslE/cs nEPWeE+XSsC4M7k+crv7NAvGYYO6BvKl38yopzRJOPKeBd+OCTlmtPPDHmBOmblZV6SA vlGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=W7JPrxTW; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m11-v6si1552569wri.185.2018.08.28.13.02.08; Tue, 28 Aug 2018 13:02:09 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=W7JPrxTW; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A793F689D0F; Tue, 28 Aug 2018 23:02:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 62ED168832E for ; Tue, 28 Aug 2018 23:01:56 +0300 (EEST) Received: by mail-lj1-f196.google.com with SMTP id p6-v6so2469966ljc.5 for ; Tue, 28 Aug 2018 13:02:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=o/LBzp9q0gQI1ML/X6tELWOcoNBWfzGFfh51Rf2n4co=; b=W7JPrxTWDaryjnQnIlo+wiTHA9h3H6fN7oywVNZmF+EPebhfnU9vXPU8uMsLNcHgU6 xqfHs4Feqd0AqGBz7FlhbsFkdSuuFmw/k3n/sAKST0f4N7OADh+ei3GWh/2LQ3j7F0rX DlWYOc+ez+LEQGWUuREcA+eRf20f8Y0epV6haK1BHOypQ1cw2XBTvEsb7Y4jEmqPOwQb bMzWiL1uMclNwshgpD3SwKjEiXZN9iRmeP8JWnj4zDFre1fJoWXZWQvDKYf9z99sMmNk 4iNm66Uhy9V5ZascbH9jApGXqU42mlDv0VpIXjVa0/d1CdSj7aHPeQiAK+5P2KuqiHg/ 5IYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=o/LBzp9q0gQI1ML/X6tELWOcoNBWfzGFfh51Rf2n4co=; b=gltHNVqhLR/7dNJ4n6aGpg4qzwqOigMDrTiIEwFTF+vVe1IcXTivwsuu8AOzuhdLbA 12qbiVk+rIhUbqFn1HckXNaH7LOU3Uezicci/mX6GFqMyZzehwuirFafc8E8mDF5a0yp U43Rx3G8JzpxtcxWp4/wP4RZ/Mw2uLREXqdaxlW9PmHazZnMBrWZPxCA005Uls9FDg/P 8vy9y0Ybu38yG1975u4rzkgSA9l8ZahqPNC/8zvwXCp/zP92E3s0RY0s4QGSoolapS71 /k6eTuyTxd3yCYv834u0CcxssPrib9SVvWUqd2rGm8pfol3dXMRgOp1NcChBmq59qvWO LKxA== X-Gm-Message-State: APzg51A5o55j3dA9hWyLiX74Bxx5bZBSLRNBzdalon9rXIWynpMt/1Rb 7c3g40mtUDnPvEq2KfhLFXUx4ihaVQlzrccwsdwDRAJf X-Received: by 2002:a2e:2e02:: with SMTP id u2-v6mr2282783lju.77.1535486193337; Tue, 28 Aug 2018 12:56:33 -0700 (PDT) MIME-Version: 1.0 References: <20180713000503.210700-1-modmaker@google.com> In-Reply-To: From: Jacob Trimble Date: Tue, 28 Aug 2018 12:56:21 -0700 Message-ID: To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH] avformat/matroskadec: Parse encryption init info from streams. 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" On Mon, Aug 20, 2018 at 11:39 AM Jacob Trimble wrote: > > On Thu, Aug 9, 2018 at 9:14 AM Jacob Trimble wrote: > > > > On Wed, Aug 1, 2018 at 1:46 PM Jacob Trimble wrote: > > > > > > On Mon, Jul 23, 2018 at 2:01 PM Jacob Trimble wrote: > > > > > > > > On Thu, Jul 12, 2018 at 5:05 PM Jacob Trimble wrote: > > > > > > > > > > Signed-off-by: Jacob Trimble > > > > > --- > > > > > 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 > > > > > > > > > > > > > Ping. > > > > > > Ping. > > > > Ping (only 43 lines changed, in "review" for 28 days...) > > Ping. Ping. (initially sent 47 days ago, attached again for your convenience) From 7cd8db21516adf56b97610d9fdac660bc4a6baa4 Mon Sep 17 00:00:00 2001 From: Jacob Trimble Date: Tue, 10 Jul 2018 16:39:43 -0700 Subject: [PATCH] avformat/matroskadec: Parse encryption init info from streams. Signed-off-by: Jacob Trimble --- libavformat/matroskadec.c | 43 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index e6793988e1..6f79b5e400 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.19.0.rc0.228.g281dcd1b4d0-goog