Shaka Packager SDK
sync_sample_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/sync_sample_iterator.h>
8 
9 #include <algorithm>
10 
11 namespace shaka {
12 namespace media {
13 namespace mp4 {
14 
16  : sample_number_(1),
17  sync_sample_vector_(sync_sample.sample_number),
18  iterator_(sync_sample_vector_.begin()),
19  is_empty_(iterator_ == sync_sample_vector_.end()) {}
20 SyncSampleIterator::~SyncSampleIterator() {}
21 
23  if (iterator_ != sync_sample_vector_.end() && sample_number_ == *iterator_)
24  ++iterator_;
25  ++sample_number_;
26  return true;
27 }
28 
30  // If the sync sample box is not present, every sample is a sync sample.
31  if (is_empty_)
32  return true;
33  return iterator_ != sync_sample_vector_.end() && sample_number_ == *iterator_;
34 }
35 
36 bool SyncSampleIterator::IsSyncSample(uint32_t sample) const {
37  // If the sync sample box is not present, every sample is a sync sample.
38  if (is_empty_)
39  return true;
40  return std::binary_search(
41  sync_sample_vector_.begin(), sync_sample_vector_.end(), sample);
42 }
43 
44 } // namespace mp4
45 } // namespace media
46 } // namespace shaka
SyncSampleIterator(const SyncSample &sync_sample)
Create a new SyncSampleIterator from sync sample box.
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66