Shaka Packager SDK
chunk_info_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/chunk_info_iterator.h>
8 
9 #include <algorithm>
10 #include <limits>
11 
12 #include <absl/log/check.h>
13 #include <absl/log/log.h>
14 
15 namespace shaka {
16 namespace media {
17 namespace mp4 {
18 
20  : chunk_sample_index_(0),
21  current_chunk_(0),
22  chunk_info_table_(sample_to_chunk.chunk_info),
23  iterator_(chunk_info_table_.begin()) {
24  if (iterator_ != chunk_info_table_.end())
25  current_chunk_ = iterator_->first_chunk;
26 }
27 ChunkInfoIterator::~ChunkInfoIterator() {}
28 
30  ++current_chunk_;
31  if (iterator_ + 1 != chunk_info_table_.end()) {
32  if (current_chunk_ >= (iterator_ + 1)->first_chunk)
33  ++iterator_;
34  }
35  chunk_sample_index_ = 0;
36  return true;
37 }
38 
40  ++chunk_sample_index_;
41  if (chunk_sample_index_ >= iterator_->samples_per_chunk)
42  AdvanceChunk();
43  return true;
44 }
45 
47  return iterator_ != chunk_info_table_.end() &&
48  chunk_sample_index_ < iterator_->samples_per_chunk;
49 }
50 
51 uint32_t ChunkInfoIterator::NumSamples(uint32_t start_chunk,
52  uint32_t end_chunk) const {
53  DCHECK_LE(start_chunk, end_chunk);
54 
55  uint32_t last_chunk = 0;
56  uint32_t num_samples = 0;
57  for (std::vector<ChunkInfo>::const_iterator it = chunk_info_table_.begin();
58  it != chunk_info_table_.end();
59  ++it) {
60  last_chunk = (it + 1 == chunk_info_table_.end())
61  ? std::numeric_limits<uint32_t>::max()
62  : (it + 1)->first_chunk - 1;
63  if (last_chunk >= start_chunk) {
64  num_samples += (std::min(end_chunk, last_chunk) -
65  std::max(start_chunk, it->first_chunk) + 1) *
66  it->samples_per_chunk;
67  if (last_chunk >= end_chunk)
68  break;
69  }
70  }
71  return num_samples;
72 }
73 
74 } // namespace mp4
75 } // namespace media
76 } // namespace shaka
uint32_t NumSamples(uint32_t start_chunk, uint32_t end_chunk) const
ChunkInfoIterator(const SampleToChunk &sample_to_chunk)
Create ChunkInfoIterator from sample to chunk box.
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66