diff mbox

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

Message ID 20180713000503.210700-1-modmaker@google.com
State Superseded
Headers show

Commit Message

Jacob Trimble July 13, 2018, 12:05 a.m. UTC
Signed-off-by: Jacob Trimble <modmaker@google.com>
---
 libavformat/matroskadec.c | 43 +++++++++++++++++++++++++++++----------
 1 file changed, 32 insertions(+), 11 deletions(-)

Comments

Jacob Trimble July 23, 2018, 9:01 p.m. UTC | #1
On Thu, Jul 12, 2018 at 5:05 PM Jacob Trimble <modmaker@google.com> wrote:
>
> Signed-off-by: Jacob Trimble <modmaker@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.
Jacob Trimble Aug. 1, 2018, 8:46 p.m. UTC | #2
On Mon, Jul 23, 2018 at 2:01 PM Jacob Trimble <modmaker@google.com> wrote:
>
> On Thu, Jul 12, 2018 at 5:05 PM Jacob Trimble <modmaker@google.com> wrote:
> >
> > Signed-off-by: Jacob Trimble <modmaker@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.
Jacob Trimble Aug. 9, 2018, 4:14 p.m. UTC | #3
On Wed, Aug 1, 2018 at 1:46 PM Jacob Trimble <modmaker@google.com> wrote:
>
> On Mon, Jul 23, 2018 at 2:01 PM Jacob Trimble <modmaker@google.com> wrote:
> >
> > On Thu, Jul 12, 2018 at 5:05 PM Jacob Trimble <modmaker@google.com> wrote:
> > >
> > > Signed-off-by: Jacob Trimble <modmaker@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...)
Jacob Trimble Aug. 20, 2018, 6:39 p.m. UTC | #4
On Thu, Aug 9, 2018 at 9:14 AM Jacob Trimble <modmaker@google.com> wrote:
>
> On Wed, Aug 1, 2018 at 1:46 PM Jacob Trimble <modmaker@google.com> wrote:
> >
> > On Mon, Jul 23, 2018 at 2:01 PM Jacob Trimble <modmaker@google.com> wrote:
> > >
> > > On Thu, Jul 12, 2018 at 5:05 PM Jacob Trimble <modmaker@google.com> wrote:
> > > >
> > > > Signed-off-by: Jacob Trimble <modmaker@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.
diff mbox

Patch

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") &&