2014-02-14 23:21:05 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2014-04-10 21:42:38 +00:00
|
|
|
#include "media/formats/mp4/sync_sample_iterator.h"
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2014-09-19 20:41:13 +00:00
|
|
|
namespace edash_packager {
|
2013-10-08 17:37:58 +00:00
|
|
|
namespace media {
|
|
|
|
namespace mp4 {
|
|
|
|
|
|
|
|
SyncSampleIterator::SyncSampleIterator(const SyncSample& sync_sample)
|
|
|
|
: sample_number_(1),
|
|
|
|
sync_sample_vector_(sync_sample.sample_number),
|
|
|
|
iterator_(sync_sample_vector_.begin()),
|
2014-02-21 02:09:35 +00:00
|
|
|
is_empty_(iterator_ == sync_sample_vector_.end()) {}
|
2014-02-26 23:55:01 +00:00
|
|
|
SyncSampleIterator::~SyncSampleIterator() {}
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
bool SyncSampleIterator::AdvanceSample() {
|
|
|
|
if (iterator_ != sync_sample_vector_.end() && sample_number_ == *iterator_)
|
|
|
|
++iterator_;
|
|
|
|
++sample_number_;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-02-21 02:09:35 +00:00
|
|
|
bool SyncSampleIterator::IsSyncSample() const {
|
2013-10-08 17:37:58 +00:00
|
|
|
// If the sync sample box is not present, every sample is a sync sample.
|
|
|
|
if (is_empty_)
|
|
|
|
return true;
|
|
|
|
return iterator_ != sync_sample_vector_.end() && sample_number_ == *iterator_;
|
|
|
|
}
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
bool SyncSampleIterator::IsSyncSample(uint32_t sample) const {
|
2013-10-08 17:37:58 +00:00
|
|
|
// If the sync sample box is not present, every sample is a sync sample.
|
|
|
|
if (is_empty_)
|
|
|
|
return true;
|
2014-02-21 02:09:35 +00:00
|
|
|
return std::binary_search(
|
|
|
|
sync_sample_vector_.begin(), sync_sample_vector_.end(), sample);
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
2014-09-19 20:41:13 +00:00
|
|
|
} // namespace edash_packager
|