Shaka Packager SDK
Loading...
Searching...
No Matches
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#include <cstdint>
11
12#include <packager/media/formats/mp4/box_definitions.h>
13
14namespace shaka {
15namespace media {
16namespace mp4 {
17
19 : sample_number_(1),
20 sync_sample_vector_(sync_sample.sample_number),
21 iterator_(sync_sample_vector_.begin()),
22 is_empty_(iterator_ == sync_sample_vector_.end()) {}
23SyncSampleIterator::~SyncSampleIterator() {}
24
26 if (iterator_ != sync_sample_vector_.end() && sample_number_ == *iterator_)
27 ++iterator_;
28 ++sample_number_;
29 return true;
30}
31
33 // If the sync sample box is not present, every sample is a sync sample.
34 if (is_empty_)
35 return true;
36 return iterator_ != sync_sample_vector_.end() && sample_number_ == *iterator_;
37}
38
39bool SyncSampleIterator::IsSyncSample(uint32_t sample) const {
40 // If the sync sample box is not present, every sample is a sync sample.
41 if (is_empty_)
42 return true;
43 return std::binary_search(sync_sample_vector_.begin(),
44 sync_sample_vector_.end(), sample);
45}
46
47} // namespace mp4
48} // namespace media
49} // 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.