Shaka Packager SDK
composition_offset_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/composition_offset_iterator.h>
8 
9 #include <absl/log/check.h>
10 #include <absl/log/log.h>
11 
12 namespace shaka {
13 namespace media {
14 namespace mp4 {
15 
17  const CompositionTimeToSample& composition_time_to_sample)
18  : sample_index_(0),
19  composition_offset_table_(composition_time_to_sample.composition_offset),
20  iterator_(composition_offset_table_.begin()) {}
21 CompositionOffsetIterator::~CompositionOffsetIterator() {}
22 
24  ++sample_index_;
25  if (sample_index_ >= iterator_->sample_count) {
26  ++iterator_;
27  if (iterator_ == composition_offset_table_.end())
28  return false;
29  sample_index_ = 0;
30  }
31  return true;
32 }
33 
35  return iterator_ != composition_offset_table_.end() &&
36  sample_index_ < iterator_->sample_count;
37 }
38 
39 int64_t CompositionOffsetIterator::SampleOffset(uint32_t sample) const {
40  uint32_t current_sample = 0;
41  std::vector<CompositionOffset>::const_iterator it =
42  composition_offset_table_.begin();
43  for (; it != composition_offset_table_.end(); ++it) {
44  current_sample += it->sample_count;
45  if (current_sample >= sample)
46  return it->sample_offset;
47  }
48  DCHECK_LE(sample, current_sample) << " Sample is invalid";
49  return 0;
50 }
51 
53  uint32_t num_samples = 0;
54  std::vector<CompositionOffset>::const_iterator it =
55  composition_offset_table_.begin();
56  for (; it != composition_offset_table_.end(); ++it) {
57  num_samples += it->sample_count;
58  }
59  return num_samples;
60 }
61 
62 } // namespace mp4
63 } // namespace media
64 } // namespace shaka
CompositionOffsetIterator(const CompositionTimeToSample &composition_time_to_sample)
Create CompositionOffsetIterator from composition time to sample box.
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66