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) {