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
This commit is contained in:
KongQun Yang 2020-02-10 22:09:45 -08:00
parent 624b2ca725
commit ce932f68a2
2 changed files with 24 additions and 13 deletions

View File

@ -35,11 +35,6 @@ bool ShouldAlignProtectedData(Codec codec,
FourCC protection_scheme, FourCC protection_scheme,
bool vp9_subsample_encryption) { bool vp9_subsample_encryption) {
switch (codec) { 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: case kCodecVP9:
// "VP Codec ISO Media File Format Binding" document requires that the // "VP Codec ISO Media File Format Binding" document requires that the
// encrypted bytes of each frame within the superframe must be block // 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 // CMAF requires 'cenc' scheme BytesOfProtectedData SHALL be a multiple of
// 16 bytes; while 'cbcs' scheme BytesOfProtectedData SHALL start on the // 16 bytes; while 'cbcs' scheme BytesOfProtectedData SHALL start on the
// first byte of video data following the slice header. // 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 || return protection_scheme == FOURCC_cbc1 ||
protection_scheme == FOURCC_cens || protection_scheme == FOURCC_cens ||
protection_scheme == FOURCC_cenc; protection_scheme == FOURCC_cenc;

View File

@ -389,20 +389,31 @@ TEST_P(SubsampleGeneratorTest, AV1SubsampleEncryption) {
ASSERT_OK( ASSERT_OK(
generator.Initialize(protection_scheme_, GetVideoStreamInfo(kCodecAV1))); generator.Initialize(protection_scheme_, GetVideoStreamInfo(kCodecAV1)));
constexpr size_t kFrameSize = 50; constexpr size_t kFrameSize = 70;
constexpr uint8_t kFrame[kFrameSize] = {}; constexpr uint8_t kFrame[kFrameSize] = {};
constexpr size_t kTileOffsets[] = {4, 11}; constexpr size_t kTileOffsets[] = {4, 11, 44};
constexpr size_t kTileSizes[] = {6, 33}; constexpr size_t kTileSizes[] = {6, 33, 20};
constexpr int kNumTiles = 3;
// AV1 block align protected data for all protection schemes. // AV1 block align protected data for all protection schemes.
const SubsampleEntry kExpectedSubsamples[] = { const SubsampleEntry kExpectedSubsamplesCbcs[] = {
// {4,6},{11-4-6,33},{50-11-33,0} block aligned => {10,0},{2,32},{6,0}. // {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. // Then merge consecutive clear-only subsamples.
{12, 32}, {12, 32},
{4, 16},
{6, 0}, {6, 0},
}; };
std::vector<AV1Parser::Tile> tiles(2); std::vector<AV1Parser::Tile> tiles(kNumTiles);
for (int i = 0; i < 2; i++) { for (int i = 0; i < kNumTiles; i++) {
tiles[i].start_offset_in_bytes = kTileOffsets[i]; tiles[i].start_offset_in_bytes = kTileOffsets[i];
tiles[i].size_in_bytes = kTileSizes[i]; tiles[i].size_in_bytes = kTileSizes[i];
} }
@ -415,7 +426,10 @@ TEST_P(SubsampleGeneratorTest, AV1SubsampleEncryption) {
std::vector<SubsampleEntry> subsamples; std::vector<SubsampleEntry> subsamples;
ASSERT_OK(generator.GenerateSubsamples(kFrame, kFrameSize, &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) { TEST_P(SubsampleGeneratorTest, AACIsFullSampleEncrypted) {