From ce932f68a2e45e9a85a8e9c3d6f50675682c6fdf Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Mon, 10 Feb 2020 22:09:45 -0800 Subject: [PATCH] Change AV1 cbcs to protect all bytes of decode_tile structure AV1-ISOBMFF spec is updated recently to use start alignment instead of end alignment for cbcs: for the protected scheme cbcs: - BytesOfProtectedData SHALL start on the first byte and end on the last byte of the decode_tile structure (including any trailing bits). - A subsample SHALL be created for each tile, even if its size is less than 16 bytes. - ... cenc protection scheme is not affected. Closes #698. Change-Id: Ic83a478fb2602d830c30daf3206a1c2d2c238a08 --- packager/media/crypto/subsample_generator.cc | 7 ++--- .../crypto/subsample_generator_unittest.cc | 30 ++++++++++++++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/packager/media/crypto/subsample_generator.cc b/packager/media/crypto/subsample_generator.cc index d2d3c70d27..74bd1b02b0 100644 --- a/packager/media/crypto/subsample_generator.cc +++ b/packager/media/crypto/subsample_generator.cc @@ -35,11 +35,6 @@ bool ShouldAlignProtectedData(Codec codec, FourCC protection_scheme, bool vp9_subsample_encryption) { switch (codec) { - case kCodecAV1: - // Per AV1 in ISO-BMFF spec [1], BytesOfProtectedData SHALL be a multiple - // of 16 bytes. - // [1] https://aomediacodec.github.io/av1-isobmff/#subsample-encryption - return true; case kCodecVP9: // "VP Codec ISO Media File Format Binding" document requires that the // encrypted bytes of each frame within the superframe must be block @@ -58,6 +53,8 @@ bool ShouldAlignProtectedData(Codec codec, // CMAF requires 'cenc' scheme BytesOfProtectedData SHALL be a multiple of // 16 bytes; while 'cbcs' scheme BytesOfProtectedData SHALL start on the // first byte of video data following the slice header. + // https://aomediacodec.github.io/av1-isobmff/#subsample-encryption AV1 + // has a similar clause. return protection_scheme == FOURCC_cbc1 || protection_scheme == FOURCC_cens || protection_scheme == FOURCC_cenc; diff --git a/packager/media/crypto/subsample_generator_unittest.cc b/packager/media/crypto/subsample_generator_unittest.cc index ea94edd92c..51ffd98908 100644 --- a/packager/media/crypto/subsample_generator_unittest.cc +++ b/packager/media/crypto/subsample_generator_unittest.cc @@ -389,20 +389,31 @@ TEST_P(SubsampleGeneratorTest, AV1SubsampleEncryption) { ASSERT_OK( generator.Initialize(protection_scheme_, GetVideoStreamInfo(kCodecAV1))); - constexpr size_t kFrameSize = 50; + constexpr size_t kFrameSize = 70; constexpr uint8_t kFrame[kFrameSize] = {}; - constexpr size_t kTileOffsets[] = {4, 11}; - constexpr size_t kTileSizes[] = {6, 33}; + constexpr size_t kTileOffsets[] = {4, 11, 44}; + constexpr size_t kTileSizes[] = {6, 33, 20}; + constexpr int kNumTiles = 3; // AV1 block align protected data for all protection schemes. - const SubsampleEntry kExpectedSubsamples[] = { - // {4,6},{11-4-6,33},{50-11-33,0} block aligned => {10,0},{2,32},{6,0}. + const SubsampleEntry kExpectedSubsamplesCbcs[] = { + // {4,6},{11-4-6,33},{44-11-33,20},{70-44-20,0} + // Always starts on the first byte and ends on the last byte of the tiles. + {4, 6}, + {1, 33}, + {0, 20}, + {6, 0}, + }; + const SubsampleEntry kExpectedSubsamplesNonCbcs[] = { + // {4,6},{11-4-6,33},{44-11-33,20},{70-44-20,0} block aligned => + // {10,0},{2,32},{4,16},{6,0}. // Then merge consecutive clear-only subsamples. {12, 32}, + {4, 16}, {6, 0}, }; - std::vector tiles(2); - for (int i = 0; i < 2; i++) { + std::vector tiles(kNumTiles); + for (int i = 0; i < kNumTiles; i++) { tiles[i].start_offset_in_bytes = kTileOffsets[i]; tiles[i].size_in_bytes = kTileSizes[i]; } @@ -415,7 +426,10 @@ TEST_P(SubsampleGeneratorTest, AV1SubsampleEncryption) { std::vector subsamples; ASSERT_OK(generator.GenerateSubsamples(kFrame, kFrameSize, &subsamples)); - EXPECT_THAT(subsamples, ElementsAreArray(kExpectedSubsamples)); + if (protection_scheme_ == FOURCC_cbcs) + EXPECT_THAT(subsamples, ElementsAreArray(kExpectedSubsamplesCbcs)); + else + EXPECT_THAT(subsamples, ElementsAreArray(kExpectedSubsamplesNonCbcs)); } TEST_P(SubsampleGeneratorTest, AACIsFullSampleEncrypted) {