Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(885)

Unified Diff: media/formats/mp4/track_run_iterator.cc

Issue 1998333002: MP4 support for Common Encryption 'cbcs' scheme. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: accommodate comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/formats/mp4/track_run_iterator.cc
diff --git a/media/formats/mp4/track_run_iterator.cc b/media/formats/mp4/track_run_iterator.cc
index 7193b3d26dd9d5eb03b47ef298bc8d4d99ec11c6..98fcab3ac99f9dd977892be67b1236bc230b814a 100644
--- a/media/formats/mp4/track_run_iterator.cc
+++ b/media/formats/mp4/track_run_iterator.cc
@@ -12,6 +12,7 @@
#include "base/macros.h"
#include "media/formats/mp4/rcheck.h"
#include "media/formats/mp4/sample_to_group_iterator.h"
+#include "media/media_features.h"
namespace media {
namespace mp4 {
@@ -282,11 +283,11 @@ bool TrackRunIterator::Init(const MovieFragment& moof) {
const std::vector<uint8_t>& sample_encryption_data =
traf.sample_encryption.sample_encryption_data;
std::unique_ptr<BufferReader> sample_encryption_reader;
- uint32_t sample_encrytion_entries_count = 0;
+ uint32_t sample_encryption_entries_count = 0;
if (!sample_encryption_data.empty()) {
sample_encryption_reader.reset(new BufferReader(
sample_encryption_data.data(), sample_encryption_data.size()));
- RCHECK(sample_encryption_reader->Read4(&sample_encrytion_entries_count));
+ RCHECK(sample_encryption_reader->Read4(&sample_encryption_entries_count));
}
// Process edit list to remove CTS offset introduced in the presence of
@@ -323,26 +324,23 @@ bool TrackRunIterator::Init(const MovieFragment& moof) {
tri.fragment_sample_encryption_info =
traf.sample_group_description.entries;
- uint8_t default_iv_size = 0;
+ const TrackEncryption* track_encryption;
tri.is_audio = (stsd.type == kAudio);
if (tri.is_audio) {
RCHECK(!stsd.audio_entries.empty());
if (desc_idx > stsd.audio_entries.size())
desc_idx = 0;
tri.audio_description = &stsd.audio_entries[desc_idx];
- default_iv_size =
- tri.audio_description->sinf.info.track_encryption.default_iv_size;
+ track_encryption = &tri.audio_description->sinf.info.track_encryption;
} else {
RCHECK(!stsd.video_entries.empty());
if (desc_idx > stsd.video_entries.size())
desc_idx = 0;
tri.video_description = &stsd.video_entries[desc_idx];
- default_iv_size =
- tri.video_description->sinf.info.track_encryption.default_iv_size;
+ track_encryption = &tri.video_description->sinf.info.track_encryption;
}
-
// Initialize aux_info variables only if no sample encryption entries.
- if (sample_encrytion_entries_count == 0 &&
+ if (sample_encryption_entries_count == 0 &&
traf.auxiliary_offset.offsets.size() > j) {
// Collect information from the auxiliary_offset entry with the same
// index in the 'saiz' container as the current run's index in the
@@ -402,18 +400,42 @@ bool TrackRunIterator::Init(const MovieFragment& moof) {
RCHECK(GetSampleEncryptionInfoEntry(tri, index));
is_sample_to_group_valid = sample_to_group_itr.Advance();
}
- if (sample_encrytion_entries_count > 0) {
- RCHECK(sample_encrytion_entries_count >=
+ if (sample_encryption_entries_count > 0) {
+ RCHECK(sample_encryption_entries_count >=
sample_count_sum + trun.sample_count);
tri.sample_encryption_entries.resize(trun.sample_count);
for (size_t k = 0; k < trun.sample_count; k++) {
uint32_t index = tri.samples[k].cenc_group_description_index;
- const uint8_t iv_size =
- index == 0 ? default_iv_size
- : GetSampleEncryptionInfoEntry(tri, index)->iv_size;
- RCHECK(tri.sample_encryption_entries[k].Parse(
- sample_encryption_reader.get(), iv_size,
- traf.sample_encryption.use_subsample_encryption));
+ const CencSampleEncryptionInfoEntry* info_entry =
+ index == 0 ? nullptr : GetSampleEncryptionInfoEntry(tri, index);
+ const uint8_t iv_size = index == 0 ? track_encryption->default_iv_size
+ : info_entry->iv_size;
+ SampleEncryptionEntry& entry = tri.sample_encryption_entries[k];
+ RCHECK(entry.Parse(sample_encryption_reader.get(), iv_size,
+ traf.sample_encryption.use_subsample_encryption));
+#if BUILDFLAG(ENABLE_CBCS_ENCRYPTION_SCHEME)
+ // if we don't have a per-sample IV, get the constant IV.
+ if (!iv_size) {
+ const uint8_t constant_iv_size =
+ index == 0 ? track_encryption->default_constant_iv_size
+ : info_entry->constant_iv_size;
+ RCHECK(constant_iv_size != 0);
+ const uint8_t* constant_iv =
+ index == 0 ? track_encryption->default_constant_iv
+ : info_entry->constant_iv;
+ memcpy(entry.initialization_vector, constant_iv, constant_iv_size);
+ }
+ // We only support setting the pattern values in the 'tenc' box for
+ // the track (not varying on per sample group basis).
+ // Thus we need to verify that the settings in the sample group match
+ // those in the 'tenc'.
+ if (index != 0) {
+ RCHECK(info_entry->crypt_byte_block ==
+ track_encryption->default_crypt_byte_block);
+ RCHECK(info_entry->skip_byte_block ==
+ track_encryption->default_skip_byte_block);
+ }
+#endif
kqyang 2016/05/26 17:34:50 Consider add a new unittest in track_run_iterator_
dougsteed 2016/06/09 22:38:27 Done.
}
}
kqyang 2016/05/27 17:45:58 The implementation here only supports the case whe
dougsteed 2016/06/09 22:38:27 Done. I added code to cover the other cases.
runs_.push_back(tri);

Powered by Google App Engine
This is Rietveld 408576698