From 458d3763432c922f0794aa20216f1199a157b7bc Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Mon, 4 Jan 2016 16:18:34 -0800 Subject: [PATCH] Block align frames in superframe for vp9 cenc Change-Id: I065151c05d55c993ffbd0c30f2aa521e8476833c --- .../media/formats/mp4/encrypting_fragmenter.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packager/media/formats/mp4/encrypting_fragmenter.cc b/packager/media/formats/mp4/encrypting_fragmenter.cc index cf40c5fb76..065b264a84 100644 --- a/packager/media/formats/mp4/encrypting_fragmenter.cc +++ b/packager/media/formats/mp4/encrypting_fragmenter.cc @@ -17,6 +17,7 @@ namespace { // Generate 64bit IV by default. const size_t kDefaultIvSize = 8u; +const size_t kCencBlockSize = 16u; } // namespace namespace edash_packager { @@ -156,11 +157,24 @@ Status EncryptingFragmenter::EncryptSample(scoped_refptr sample) { &vpx_frames)) { return Status(error::MUXER_FAILURE, "Failed to parse vpx frame."); } + + const bool is_superframe = vpx_frames.size() > 1; for (const VPxFrameInfo& frame : vpx_frames) { SubsampleEntry subsample; subsample.clear_bytes = frame.uncompressed_header_size; subsample.cipher_bytes = frame.frame_size - frame.uncompressed_header_size; + + // "VP Codec ISO Media File Format Binding" document requires that the + // encrypted bytes of each frame within the superframe must be block + // aligned so that the counter state can be computed for each frame + // within the superframe. + if (is_superframe) { + uint16_t misalign_bytes = subsample.cipher_bytes % kCencBlockSize; + subsample.clear_bytes += misalign_bytes; + subsample.cipher_bytes -= misalign_bytes; + } + sample_encryption_entry.subsamples.push_back(subsample); if (subsample.cipher_bytes > 0) EncryptBytes(data + subsample.clear_bytes, subsample.cipher_bytes);