• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "media/formats/mp4/sample_to_group_iterator.h"
6 
7 #include "base/logging.h"
8 
9 namespace media {
10 namespace mp4 {
11 
SampleToGroupIterator(const SampleToGroup & sample_to_group)12 SampleToGroupIterator::SampleToGroupIterator(
13     const SampleToGroup& sample_to_group)
14     : remaining_samples_(0),
15       sample_to_group_table_(sample_to_group.entries),
16       iterator_(sample_to_group_table_.begin()) {
17   // Handle the case that the table contains an entry with sample count 0.
18   while (iterator_ != sample_to_group_table_.end()) {
19     remaining_samples_ = iterator_->sample_count;
20     if (remaining_samples_ > 0)
21       break;
22     ++iterator_;
23   }
24 }
25 
~SampleToGroupIterator()26 SampleToGroupIterator::~SampleToGroupIterator() {}
27 
Advance()28 bool SampleToGroupIterator::Advance() {
29   DCHECK(IsValid());
30 
31   --remaining_samples_;
32   // Handle the case that the table contains an entry with sample count 0.
33   while (remaining_samples_ == 0) {
34     ++iterator_;
35     if (iterator_ == sample_to_group_table_.end())
36       return false;
37     remaining_samples_ = iterator_->sample_count;
38   }
39   return true;
40 }
41 
IsValid() const42 bool SampleToGroupIterator::IsValid() const {
43   return remaining_samples_ > 0;
44 }
45 
46 }  // namespace mp4
47 }  // namespace media
48