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/decoding_time_iterator.h"
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-10-08 17:37:58 +00:00
|
|
|
namespace media {
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
DecodingTimeIterator::DecodingTimeIterator(
|
|
|
|
const DecodingTimeToSample& decoding_time_to_sample)
|
|
|
|
: sample_index_(0),
|
|
|
|
decoding_time_table_(decoding_time_to_sample.decoding_time),
|
2014-02-21 02:09:35 +00:00
|
|
|
iterator_(decoding_time_table_.begin()) {}
|
2014-02-26 23:55:01 +00:00
|
|
|
DecodingTimeIterator::~DecodingTimeIterator() {}
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
bool DecodingTimeIterator::AdvanceSample() {
|
|
|
|
++sample_index_;
|
|
|
|
if (sample_index_ >= iterator_->sample_count) {
|
|
|
|
++iterator_;
|
|
|
|
if (iterator_ == decoding_time_table_.end())
|
|
|
|
return false;
|
|
|
|
sample_index_ = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-21 02:09:35 +00:00
|
|
|
bool DecodingTimeIterator::IsValid() const {
|
|
|
|
return iterator_ != decoding_time_table_.end() &&
|
|
|
|
sample_index_ < iterator_->sample_count;
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint64_t DecodingTimeIterator::Duration(uint32_t start_sample,
|
|
|
|
uint32_t end_sample) const {
|
2014-02-21 02:09:35 +00:00
|
|
|
DCHECK_LE(start_sample, end_sample);
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t current_sample = 0;
|
|
|
|
uint32_t prev_sample = 0;
|
|
|
|
uint64_t duration = 0;
|
2013-10-08 17:37:58 +00:00
|
|
|
std::vector<DecodingTime>::const_iterator it = decoding_time_table_.begin();
|
|
|
|
for (; it != decoding_time_table_.end(); ++it) {
|
|
|
|
current_sample += it->sample_count;
|
|
|
|
if (current_sample >= start_sample) {
|
2014-02-21 02:09:35 +00:00
|
|
|
duration += (std::min(end_sample, current_sample) -
|
|
|
|
std::max(start_sample, prev_sample + 1) + 1) *
|
|
|
|
it->sample_delta;
|
2013-10-08 17:37:58 +00:00
|
|
|
if (current_sample >= end_sample)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prev_sample = current_sample;
|
|
|
|
}
|
|
|
|
return duration;
|
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t DecodingTimeIterator::NumSamples() const {
|
|
|
|
uint32_t num_samples = 0;
|
2013-10-08 17:37:58 +00:00
|
|
|
std::vector<DecodingTime>::const_iterator it = decoding_time_table_.begin();
|
|
|
|
for (; it != decoding_time_table_.end(); ++it) {
|
|
|
|
num_samples += it->sample_count;
|
|
|
|
}
|
|
|
|
return num_samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|