[FFmpeg-devel] [PATCH] avformat/matroskadec: Parse encryption init info from streams.

Jacob Trimble modmaker at google.com
Tue Aug 28 22:56:21 EEST 2018


On Mon, Aug 20, 2018 at 11:39 AM Jacob Trimble <modmaker at google.com> wrote:
>
> On Thu, Aug 9, 2018 at 9:14 AM Jacob Trimble <modmaker at google.com> wrote:
> >
> > On Wed, Aug 1, 2018 at 1:46 PM Jacob Trimble <modmaker at google.com> wrote:
> > >
> > > On Mon, Jul 23, 2018 at 2:01 PM Jacob Trimble <modmaker at google.com> wrote:
> > > >
> > > > On Thu, Jul 12, 2018 at 5:05 PM Jacob Trimble <modmaker at google.com> wrote:
> > > > >
> > > > > Signed-off-by: Jacob Trimble <modmaker at 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
> > > > >
> > > >
> > > > Ping.
> > >
> > > Ping.
> >
> > Ping (only 43 lines changed, in "review" for 28 days...)
>
> Ping.

Ping.  (initially sent 47 days ago, attached again for your convenience)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-avformat-matroskadec-Parse-encryption-init-info-from.patch
Type: text/x-patch
Size: 3771 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20180828/2db375c7/attachment.bin>


More information about the ffmpeg-devel mailing list