Index: media/mp4/track_run_iterator.cc |
diff --git a/media/mp4/track_run_iterator.cc b/media/mp4/track_run_iterator.cc |
index 73bb435f68bef89a734fbfa83ee97c2f42f3305f..5cbb3ccaf4108359ccd0b30b2512bffee0627584 100644 |
--- a/media/mp4/track_run_iterator.cc |
+++ b/media/mp4/track_run_iterator.cc |
@@ -24,10 +24,10 @@ static const uint32 kSampleIsDifferenceSampleFlagMask = 0x10000; |
TrackRunInfo::TrackRunInfo() |
: track_id(0), |
sample_start_offset(-1), |
- is_encrypted(false), |
- cenc_start_offset(-1), |
- cenc_total_size(-1), |
- default_cenc_size(0) {} |
+ aux_info_start_offset(-1), |
+ aux_info_default_size(-1), |
+ aux_info_total_size(-1) { |
+} |
TrackRunInfo::~TrackRunInfo() {} |
@@ -81,11 +81,11 @@ class CompareOffset { |
public: |
bool operator()(const TrackRunInfo& a, const TrackRunInfo& b) { |
int64 a_min = a.sample_start_offset; |
- if (a.is_encrypted && a.cenc_start_offset < a_min) |
- a_min = a.cenc_start_offset; |
+ if (a.aux_info_total_size > 0 && a.aux_info_start_offset < a_min) |
ddorwin
2012/06/26 06:09:19
The .h comment seems to say is_encrypted and aux i
strobe_
2012/06/27 02:01:21
Hopefully addressed by renames.
|
+ a_min = a.aux_info_start_offset; |
int64 b_min = b.sample_start_offset; |
- if (b.is_encrypted && b.cenc_start_offset < b_min) |
- b_min = b.cenc_start_offset; |
+ if (b.aux_info_total_size > 0 && b.aux_info_start_offset < b_min) |
+ b_min = b.aux_info_start_offset; |
return a_min < b_min; |
} |
}; |
@@ -121,12 +121,6 @@ bool TrackRunIterator::Init(const Movie& moov, const MovieFragment& moof) { |
continue; |
} |
- if (sinf->info.track_encryption.is_encrypted) { |
- // TODO(strobe): CENC recovery and testing (http://crbug.com/132351) |
- DVLOG(1) << "Encrypted tracks not handled"; |
- continue; |
- } |
- |
for (size_t j = 0; j < traf.runs.size(); j++) { |
const TrackFragmentRun& trun = traf.runs[j]; |
TrackRunInfo tri; |
@@ -135,13 +129,28 @@ bool TrackRunIterator::Init(const Movie& moov, const MovieFragment& moof) { |
trak->media.header.timescale); |
tri.sample_start_offset = trun.data_offset; |
- tri.is_encrypted = false; |
- tri.cenc_start_offset = 0; |
- tri.cenc_total_size = 0; |
- tri.default_cenc_size = 0; |
+ if (traf.auxiliary_offset.offsets.size() > j) { |
ddorwin
2012/06/26 06:09:19
What? How is an iterator related to some other col
strobe_
2012/06/27 02:01:21
Done.
|
+ RCHECK(traf.auxiliary_size.sample_count == trun.sample_count); |
ddorwin
2012/06/26 06:09:19
I have no idea what the rest of this code is doing
strobe_
2012/06/27 02:01:21
Done.
|
+ tri.aux_info_start_offset = traf.auxiliary_offset.offsets[j]; |
+ tri.aux_info_default_size = |
+ traf.auxiliary_size.default_sample_info_size; |
+ tri.aux_info_sizes = traf.auxiliary_size.sample_info_sizes; |
+ if (tri.aux_info_default_size) { |
+ tri.aux_info_total_size = |
+ tri.aux_info_default_size * trun.sample_count; |
+ } else { |
+ tri.aux_info_total_size = 0; |
+ for (size_t k = 0; k < trun.sample_count; k++) { |
+ tri.aux_info_total_size += tri.aux_info_sizes[k]; |
+ } |
+ } |
+ } else { |
+ tri.aux_info_start_offset = 0; |
+ tri.aux_info_total_size = 0; |
+ } |
+ tri.track_encryption = sinf->info.track_encryption; |
tri.samples.resize(trun.sample_count); |
- |
for (size_t k = 0; k < trun.sample_count; k++) { |
PopulateSampleInfo(*trak, *trex, traf.header, trun, k, &tri.samples[k]); |
} |
@@ -168,6 +177,7 @@ void TrackRunIterator::ResetRun() { |
sample_dts_ = run_itr_->start_dts; |
sample_offset_ = run_itr_->sample_start_offset; |
sample_itr_ = run_itr_->samples.begin(); |
+ cenc_info_.clear(); |
} |
void TrackRunIterator::AdvanceSample() { |
@@ -177,14 +187,30 @@ void TrackRunIterator::AdvanceSample() { |
++sample_itr_; |
} |
-bool TrackRunIterator::NeedsCENC() { |
- CHECK(!is_encrypted()) << "TODO(strobe): Implement CENC."; |
- return is_encrypted(); |
+bool TrackRunIterator::AuxInfoRequired() { |
ddorwin
2012/06/26 06:09:19
What does this function really mean? "Need to read
strobe_
2012/06/27 02:01:21
Hopefully addressed by rename.
|
+ DCHECK(RunValid()); |
+ // The only kind of aux info that we handle is CENC info, so we only cache it |
ddorwin
2012/06/26 06:09:19
Seems like a function-level comment.
strobe_
2012/06/27 02:01:21
Done.
|
+ // if encryption is active |
+ return is_encrypted() && aux_info_size() > 0 && cenc_info_.size() == 0; |
} |
-bool TrackRunIterator::CacheCENC(const uint8* buf, int size) { |
- LOG(FATAL) << "Not implemented"; |
- return false; |
+bool TrackRunIterator::CacheAuxInfo(const uint8* buf, int size) { |
ddorwin
2012/06/26 06:09:19
buf_size would make this easier to read.
ddorwin
2012/06/26 06:09:19
Add a function-level comment that this only caches
strobe_
2012/06/27 02:01:21
Done.
strobe_
2012/06/27 02:01:21
Done.
|
+ RCHECK(AuxInfoRequired() && size >= aux_info_size()); |
ddorwin
2012/06/26 06:09:19
Nothing in the loop below verifies that we don't g
strobe_
2012/06/27 02:01:21
As noted below, the RCHECK() does this.
|
+ |
+ cenc_info_.resize(run_itr_->samples.size()); |
+ int64 pos = 0; |
+ for (size_t i = 0; i < run_itr_->samples.size(); i++) { |
+ int info_size = run_itr_->aux_info_default_size; |
+ if (!info_size) |
+ info_size = run_itr_->aux_info_sizes[i]; |
+ |
+ BufferReader reader(buf + pos, info_size); |
+ RCHECK(cenc_info_[i].Parse(run_itr_->track_encryption.default_iv_size, |
ddorwin
2012/06/26 06:09:19
does something verify we don't exceed info_size (p
strobe_
2012/06/27 02:01:21
Yes, if a request would read past the given size,
ddorwin
2012/07/03 21:03:46
We should have tests for this.
|
+ &reader)); |
+ pos += info_size; |
+ } |
+ |
+ return true; |
} |
bool TrackRunIterator::RunValid() const { |
@@ -200,8 +226,8 @@ int64 TrackRunIterator::GetMaxClearOffset() { |
if (SampleValid()) { |
offset = std::min(offset, sample_offset_); |
- if (NeedsCENC()) { |
- offset = std::min(offset, cenc_offset()); |
+ if (AuxInfoRequired()) { |
+ offset = std::min(offset, aux_info_offset()); |
} |
} |
if (min_clear_offset_itr_ != min_clear_offsets_.end()) { |
@@ -227,17 +253,15 @@ uint32 TrackRunIterator::track_id() const { |
bool TrackRunIterator::is_encrypted() const { |
DCHECK(RunValid()); |
- return run_itr_->is_encrypted; |
+ return run_itr_->track_encryption.is_encrypted; |
} |
-int64 TrackRunIterator::cenc_offset() const { |
- DCHECK(is_encrypted()); |
- return run_itr_->cenc_start_offset; |
+int64 TrackRunIterator::aux_info_offset() const { |
+ return run_itr_->aux_info_start_offset; |
} |
-int TrackRunIterator::cenc_size() const { |
- DCHECK(is_encrypted()); |
- return run_itr_->cenc_total_size; |
+int TrackRunIterator::aux_info_size() const { |
+ return run_itr_->aux_info_total_size; |
} |
int64 TrackRunIterator::offset() const { |
@@ -270,9 +294,22 @@ bool TrackRunIterator::is_keyframe() const { |
return sample_itr_->is_keyframe; |
} |
-const FrameCENCInfo& TrackRunIterator::frame_cenc_info() { |
- DCHECK(is_encrypted()); |
- return frame_cenc_info_; |
+scoped_ptr<DecryptConfig> TrackRunIterator::GetDecryptConfig() { |
ddorwin
2012/06/26 06:09:19
What tests do we have for this? :)
strobe_
2012/06/27 02:01:21
Yeah, this whole class needs a big ol' test. On sk
|
+ const FrameCENCInfo& cenc_info = |
+ cenc_info_[sample_itr_ - run_itr_->samples.begin()]; |
ddorwin
2012/06/26 06:09:19
What is this math doing?
strobe_
2012/06/27 02:01:21
Retrieves the index of the sample to which sample_
ddorwin
2012/07/03 21:03:46
Since it's already two lines, an index temp variab
strobe_
2012/07/13 00:47:07
Done.
|
+ DCHECK(is_encrypted() && !AuxInfoRequired()); |
+ |
+ if (!cenc_info.subsamples.empty() && |
+ (cenc_info.GetTotalSize() != static_cast<size_t>(size()))) { |
ddorwin
2012/06/26 06:09:19
It's unclear how these are related.
strobe_
2012/06/27 02:01:21
Hopefully renames make this clearer.
|
+ DVLOG(1) << "Incorrect CENC subsample size."; |
+ return scoped_ptr<DecryptConfig>(); |
+ } |
+ |
+ return scoped_ptr<DecryptConfig>(new DecryptConfig( |
+ &run_itr_->track_encryption.default_kid[0], |
ddorwin
2012/06/26 06:09:19
Does this code not support sample groups?
strobe_
2012/06/27 02:01:21
Correct, it does not. The restricted BMFF format u
ddorwin
2012/07/03 21:03:46
We should document this somewhere.
strobe_
2012/07/13 00:47:07
Expanded comment in mp4/box_definitions.h.
|
+ run_itr_->track_encryption.default_kid.size(), |
+ cenc_info.iv, sizeof(cenc_info.iv), |
ddorwin
2012/06/26 06:09:19
iv is a fixed size now, so you'l always send 16 bu
strobe_
2012/06/27 02:01:21
According to the CENC spec, an 8-byte IV shall be
|
+ &cenc_info.subsamples[0], cenc_info.subsamples.size())); |
} |
} // namespace mp4 |