Chromium Code Reviews| 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..26900e2ffeab01cbf6ab93fdf12603dab0ac4767 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) |
| + 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,37 @@ 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; |
| + // Collect information from the auxiliary_offset entry with the same index |
| + // in the 'saiz' container as the current run's index in the 'trun' |
| + // container, if it is present |
|
xhwang
2012/06/27 19:37:43
Add period "." at the end.
strobe_
2012/07/13 00:47:07
Done.
|
| + if (traf.auxiliary_offset.offsets.size() > j) { |
| + // There should be an auxiliary info entry corresponding to each sample |
| + // in the auxiliary offset entry's corresponding track run |
| + RCHECK(traf.auxiliary_size.sample_count == trun.sample_count); |
| + 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 the default info size is positive, find the total size of the aux |
| + // info block from it, otherwise sum over the individual sizes of each |
| + // aux info entry in the aux_offset entry |
| + 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 +186,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 +196,31 @@ void TrackRunIterator::AdvanceSample() { |
| ++sample_itr_; |
| } |
| -bool TrackRunIterator::NeedsCENC() { |
| - CHECK(!is_encrypted()) << "TODO(strobe): Implement CENC."; |
| - return is_encrypted(); |
| +// This implementation only indicates a need for caching if CENC-style auxiliary |
| +// info is available in the stream. |
| +bool TrackRunIterator::AuxInfoNeedsToBeCached() { |
| + DCHECK(RunValid()); |
| + 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; |
| +// This implementation currently only caches CENC auxiliary info. |
|
ddorwin
2012/07/03 21:03:47
"CENC-style" to be consistent with 199?
strobe_
2012/07/13 00:47:07
Done.
|
| +bool TrackRunIterator::CacheAuxInfo(const uint8* buf, int buf_size) { |
| + RCHECK(AuxInfoNeedsToBeCached() && buf_size >= aux_info_size()); |
| + |
| + 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, |
| + &reader)); |
| + pos += info_size; |
| + } |
| + |
| + return true; |
| } |
| bool TrackRunIterator::RunValid() const { |
| @@ -200,8 +236,8 @@ int64 TrackRunIterator::GetMaxClearOffset() { |
| if (SampleValid()) { |
| offset = std::min(offset, sample_offset_); |
| - if (NeedsCENC()) { |
| - offset = std::min(offset, cenc_offset()); |
| + if (AuxInfoNeedsToBeCached()) { |
| + offset = std::min(offset, aux_info_offset()); |
| } |
| } |
| if (min_clear_offset_itr_ != min_clear_offsets_.end()) { |
| @@ -227,25 +263,23 @@ 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 { |
| +int64 TrackRunIterator::sample_offset() const { |
| DCHECK(SampleValid()); |
| return sample_offset_; |
| } |
| -int TrackRunIterator::size() const { |
| +int TrackRunIterator::sample_size() const { |
| DCHECK(SampleValid()); |
| return sample_itr_->size; |
| } |
| @@ -270,9 +304,23 @@ 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() { |
| + const FrameCENCInfo& cenc_info = |
| + cenc_info_[sample_itr_ - run_itr_->samples.begin()]; |
| + DCHECK(is_encrypted() && !AuxInfoNeedsToBeCached()); |
| + |
| + if (!cenc_info.subsamples.empty() && |
| + (cenc_info.GetTotalSizeOfSubsamples() != |
| + static_cast<size_t>(sample_size()))) { |
| + DVLOG(1) << "Incorrect CENC subsample size."; |
| + return scoped_ptr<DecryptConfig>(); |
| + } |
| + |
| + return scoped_ptr<DecryptConfig>(new DecryptConfig( |
| + &run_itr_->track_encryption.default_kid[0], |
| + run_itr_->track_encryption.default_kid.size(), |
| + cenc_info.iv, sizeof(cenc_info.iv), |
| + &cenc_info.subsamples[0], cenc_info.subsamples.size())); |
| } |
| } // namespace mp4 |