summaryrefslogtreecommitdiffstats
path: root/media/formats/mp4/sample_to_group_iterator.h
blob: c2ea60f827e6b508ea3153571ae3915b57acb9b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_FORMATS_MP4_SAMPLE_TO_GROUP_ITERATOR_H_
#define MEDIA_FORMATS_MP4_SAMPLE_TO_GROUP_ITERATOR_H_

#include <vector>

#include "media/formats/mp4/box_definitions.h"

namespace media {
namespace mp4 {

// Sample To Group Box ('sbgp') can be used to find the group that a sample
// belongs to and the associated description of that sample group. It is
// compactly coded though. This class implements the iterator to iterate
// through the compressed table to get the associated sample group description
// index.
class MEDIA_EXPORT SampleToGroupIterator {
 public:
  explicit SampleToGroupIterator(const SampleToGroup& sample_to_group);
  ~SampleToGroupIterator();

  // Advances the iterator to refer to the next sample. Return status
  // indicating whether the sample is still valid.
  bool Advance();

  // Returns whether the current sample is valid.
  bool IsValid() const;

  // Returns group description index for current sample.
  uint32 group_description_index() const {
    return iterator_->group_description_index;
  }

 private:
  // Track how many samples remaining for current table entry.
  uint32 remaining_samples_;
  const std::vector<SampleToGroupEntry>& sample_to_group_table_;
  std::vector<SampleToGroupEntry>::const_iterator iterator_;

  DISALLOW_COPY_AND_ASSIGN(SampleToGroupIterator);
};

}  // namespace mp4
}  // namespace media

#endif  // MEDIA_FORMATS_MP4_SAMPLE_TO_GROUP_ITERATOR_H_