Shaka Packager SDK
decoding_time_iterator.cc
1 // Copyright 2014 Google LLC. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 
7 #include <packager/media/formats/mp4/decoding_time_iterator.h>
8 
9 #include <algorithm>
10 
11 #include <absl/log/check.h>
12 #include <absl/log/log.h>
13 
14 namespace shaka {
15 namespace media {
16 namespace mp4 {
17 
19  const DecodingTimeToSample& decoding_time_to_sample)
20  : sample_index_(0),
21  decoding_time_table_(decoding_time_to_sample.decoding_time),
22  iterator_(decoding_time_table_.begin()) {}
23 DecodingTimeIterator::~DecodingTimeIterator() {}
24 
26  ++sample_index_;
27  if (sample_index_ >= iterator_->sample_count) {
28  ++iterator_;
29  if (iterator_ == decoding_time_table_.end())
30  return false;
31  sample_index_ = 0;
32  }
33  return true;
34 }
35 
37  return iterator_ != decoding_time_table_.end() &&
38  sample_index_ < iterator_->sample_count;
39 }
40 
41 int64_t DecodingTimeIterator::Duration(uint32_t start_sample,
42  uint32_t end_sample) const {
43  DCHECK_LE(start_sample, end_sample);
44  uint32_t current_sample = 0;
45  uint32_t prev_sample = 0;
46  int64_t duration = 0;
47  std::vector<DecodingTime>::const_iterator it = decoding_time_table_.begin();
48  for (; it != decoding_time_table_.end(); ++it) {
49  current_sample += it->sample_count;
50  if (current_sample >= start_sample) {
51  duration += (std::min(end_sample, current_sample) -
52  std::max(start_sample, prev_sample + 1) + 1) *
53  it->sample_delta;
54  if (current_sample >= end_sample)
55  break;
56  }
57  prev_sample = current_sample;
58  }
59  return duration;
60 }
61 
63  uint32_t num_samples = 0;
64  std::vector<DecodingTime>::const_iterator it = decoding_time_table_.begin();
65  for (; it != decoding_time_table_.end(); ++it) {
66  num_samples += it->sample_count;
67  }
68  return num_samples;
69 }
70 
71 } // namespace mp4
72 } // namespace media
73 } // namespace shaka
DecodingTimeIterator(const DecodingTimeToSample &decoding_time_to_sample)
Create DecodingTimeIterator from decoding time to sample box.
int64_t Duration(uint32_t start_sample, uint32_t end_sample) const
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66