diff --git a/packager/media/formats/mp4/encrypting_fragmenter.cc b/packager/media/formats/mp4/encrypting_fragmenter.cc index b878ca4023..b8dc27763b 100644 --- a/packager/media/formats/mp4/encrypting_fragmenter.cc +++ b/packager/media/formats/mp4/encrypting_fragmenter.cc @@ -241,6 +241,16 @@ Status EncryptingFragmenter::EncryptSample(scoped_refptr sample) { EncryptBytes(data + subsample.clear_bytes, subsample.cipher_bytes); data += frame.frame_size; } + // Add subsample for the superframe index if exists. + if (is_superframe) { + size_t index_size = sample->data() + sample->data_size() - data; + DCHECK_LE(index_size, 2 + vpx_frames.size() * 4); + DCHECK_GE(index_size, 2 + vpx_frames.size() * 1); + SubsampleEntry subsample; + subsample.clear_bytes = index_size; + subsample.cipher_bytes = 0; + sample_encryption_entry.subsamples.push_back(subsample); + } } else { const NaluReader::NaluType nalu_type = (video_codec_ == kCodecHVC1 || video_codec_ == kCodecHEV1) @@ -295,6 +305,8 @@ Status EncryptingFragmenter::EncryptSample(scoped_refptr sample) { AddSubsamples(accumulated_clear_bytes, 0, &sample_encryption_entry.subsamples); } + DCHECK_EQ(sample_encryption_entry.GetTotalSizeOfSubsamples(), + sample->data_size()); // The length of per-sample auxiliary datum, defined in CENC ch. 7. traf()->auxiliary_size.sample_info_sizes.push_back(