2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2014-04-10 21:42:38 +00:00
|
|
|
#include "media/formats/mp4/chunk_info_iterator.h"
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <limits>
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
ChunkInfoIterator::ChunkInfoIterator(const SampleToChunk& sample_to_chunk)
|
|
|
|
: chunk_sample_index_(0),
|
|
|
|
current_chunk_(0),
|
|
|
|
chunk_info_table_(sample_to_chunk.chunk_info),
|
|
|
|
iterator_(chunk_info_table_.begin()) {
|
|
|
|
if (iterator_ != chunk_info_table_.end())
|
|
|
|
current_chunk_ = iterator_->first_chunk;
|
|
|
|
}
|
2014-02-26 23:55:01 +00:00
|
|
|
ChunkInfoIterator::~ChunkInfoIterator() {}
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
bool ChunkInfoIterator::AdvanceChunk() {
|
|
|
|
++current_chunk_;
|
|
|
|
if (iterator_ + 1 != chunk_info_table_.end()) {
|
|
|
|
if (current_chunk_ >= (iterator_ + 1)->first_chunk)
|
|
|
|
++iterator_;
|
|
|
|
}
|
|
|
|
chunk_sample_index_ = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ChunkInfoIterator::AdvanceSample() {
|
|
|
|
++chunk_sample_index_;
|
|
|
|
if (chunk_sample_index_ >= iterator_->samples_per_chunk)
|
|
|
|
AdvanceChunk();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-21 02:09:35 +00:00
|
|
|
bool ChunkInfoIterator::IsValid() const {
|
|
|
|
return iterator_ != chunk_info_table_.end() &&
|
|
|
|
chunk_sample_index_ < iterator_->samples_per_chunk;
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 02:09:35 +00:00
|
|
|
uint32 ChunkInfoIterator::NumSamples(uint32 start_chunk,
|
|
|
|
uint32 end_chunk) const {
|
|
|
|
DCHECK_LE(start_chunk, end_chunk);
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
uint32 last_chunk = 0;
|
|
|
|
uint32 num_samples = 0;
|
|
|
|
for (std::vector<ChunkInfo>::const_iterator it = chunk_info_table_.begin();
|
2014-02-21 02:09:35 +00:00
|
|
|
it != chunk_info_table_.end();
|
|
|
|
++it) {
|
|
|
|
last_chunk = (it + 1 == chunk_info_table_.end())
|
|
|
|
? std::numeric_limits<uint32>::max()
|
|
|
|
: (it + 1)->first_chunk - 1;
|
2013-10-08 17:37:58 +00:00
|
|
|
if (last_chunk >= start_chunk) {
|
2014-02-21 02:09:35 +00:00
|
|
|
num_samples += (std::min(end_chunk, last_chunk) -
|
|
|
|
std::max(start_chunk, it->first_chunk) + 1) *
|
|
|
|
it->samples_per_chunk;
|
2013-10-08 17:37:58 +00:00
|
|
|
if (last_chunk >= end_chunk)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return num_samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|