diff mbox

[FFmpeg-devel,3/3] avformat/mov: Expose encryption info to the app.

Message ID 20180105194928.104085-3-modmaker@google.com
State Superseded
Headers show

Commit Message

Jacob Trimble Jan. 5, 2018, 7:49 p.m. UTC
This exposes encryption info from the container to the app.  This
includes key ID, IV, and subsample byte ranges.  The info is passed
using the new side-data AV_PKT_DATA_ENCRYPTION_INIT_DATA.

Signed-off-by: Jacob Trimble <modmaker@google.com>
---
 libavformat/mov.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Carl Eugen Hoyos Jan. 5, 2018, 8:43 p.m. UTC | #1
2018-01-05 20:49 GMT+01:00 Jacob Trimble <modmaker-at-google.com@ffmpeg.org>:

> +    AV_WB32(side_data, size);
> +    AV_WL32(side_data + 4, MKTAG('p','s','s','h'));

I didn't check:
Is this what applications on both big- and little-endian expect?

Carl Eugen
Jacob Trimble Jan. 5, 2018, 8:55 p.m. UTC | #2
On Fri, Jan 5, 2018 at 12:43 PM, Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
> 2018-01-05 20:49 GMT+01:00 Jacob Trimble <modmaker-at-google.com@ffmpeg.org>:
>
>> +    AV_WB32(side_data, size);
>> +    AV_WL32(side_data + 4, MKTAG('p','s','s','h'));
>
> I didn't check:
> Is this what applications on both big- and little-endian expect?

Yes.  This should match the MP4 atom, so the size and 'pssh' string
should be big-endian.

>
> Carl Eugen
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

diff --git a/libavformat/mov.c b/libavformat/mov.c
index 554b2be8bd..abd59d8c7b 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5994,6 +5994,32 @@  static int mov_read_saio(MOVContext *c, AVIOContext *pb, MOVAtom atom)
     return 0;
 }
 
+static int mov_read_pssh(MOVContext *c, AVIOContext *pb, MOVAtom atom)
+{
+    AVStream *st;
+    uint8_t* side_data;
+    size_t size;
+
+    if (c->fc->nb_streams < 1)
+        return 0;
+    st = c->fc->streams[c->fc->nb_streams-1];
+
+    size = atom.size + 8;
+    side_data = av_stream_new_side_data(st, AV_PKT_DATA_ENCRYPTION_INIT_DATA, size);
+    if (!side_data) {
+        return AVERROR(ENOMEM);
+    }
+
+    AV_WB32(side_data, size);
+    AV_WL32(side_data + 4, MKTAG('p','s','s','h'));
+    if (avio_read(pb, side_data + 8, atom.size) != atom.size) {
+        av_log(c->fc, AV_LOG_ERROR, "failed to read the pssh atom\n");
+        return AVERROR_INVALIDDATA;
+    }
+
+    return 0;
+}
+
 static int mov_read_schm(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     AVStream *st;
@@ -6233,6 +6259,8 @@  static int cenc_filter(MOVContext *mov, MOVStreamContext *sc, AVPacket *pkt, int
 
         if (mov->decryption_key) {
             return cenc_decrypt(mov, sc, encrypted_sample, pkt->data, pkt->size);
+        } else {
+            return av_encryption_info_add_side_data(pkt, encrypted_sample);
         }
     }
 
@@ -6366,6 +6394,7 @@  static const MOVParseTableEntry mov_default_parse_table[] = {
 { MKTAG('s','e','n','c'), mov_read_senc },
 { MKTAG('s','a','i','z'), mov_read_saiz },
 { MKTAG('s','a','i','o'), mov_read_saio },
+{ MKTAG('p','s','s','h'), mov_read_pssh },
 { MKTAG('s','c','h','m'), mov_read_schm },
 { MKTAG('s','c','h','i'), mov_read_default },
 { MKTAG('t','e','n','c'), mov_read_tenc },