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 #ifndef MEDIA_FORMATS_MP4_SAMPLE_TO_GROUP_ITERATOR_H_ 6 #define MEDIA_FORMATS_MP4_SAMPLE_TO_GROUP_ITERATOR_H_ 7 8 #include <vector> 9 10 #include "media/formats/mp4/box_definitions.h" 11 12 namespace media { 13 namespace mp4 { 14 15 // Sample To Group Box ('sbgp') can be used to find the group that a sample 16 // belongs to and the associated description of that sample group. It is 17 // compactly coded though. This class implements the iterator to iterate 18 // through the compressed table to get the associated sample group description 19 // index. 20 class MEDIA_EXPORT SampleToGroupIterator { 21 public: 22 explicit SampleToGroupIterator(const SampleToGroup& sample_to_group); 23 ~SampleToGroupIterator(); 24 25 // Advances the iterator to refer to the next sample. Return status 26 // indicating whether the sample is still valid. 27 bool Advance(); 28 29 // Returns whether the current sample is valid. 30 bool IsValid() const; 31 32 // Returns group description index for current sample. 33 uint32 group_description_index() const { 34 return iterator_->group_description_index; 35 } 36 37 private: 38 // Track how many samples remaining for current table entry. 39 uint32 remaining_samples_; 40 const std::vector<SampleToGroupEntry>& sample_to_group_table_; 41 std::vector<SampleToGroupEntry>::const_iterator iterator_; 42 43 DISALLOW_COPY_AND_ASSIGN(SampleToGroupIterator); 44 }; 45 46 } // namespace mp4 47 } // namespace media 48 49 #endif // MEDIA_FORMATS_MP4_SAMPLE_TO_GROUP_ITERATOR_H_ 50