sample_to_group_iterator.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include "media/formats/mp4/sample_to_group_iterator.h"
  5. #include "base/check.h"
  6. namespace media {
  7. namespace mp4 {
  8. SampleToGroupIterator::SampleToGroupIterator(
  9. const SampleToGroup& sample_to_group)
  10. : remaining_samples_(0),
  11. sample_to_group_table_(sample_to_group.entries),
  12. iterator_(sample_to_group_table_.begin()) {
  13. // Handle the case that the table contains an entry with sample count 0.
  14. while (iterator_ != sample_to_group_table_.end()) {
  15. remaining_samples_ = iterator_->sample_count;
  16. if (remaining_samples_ > 0)
  17. break;
  18. ++iterator_;
  19. }
  20. }
  21. SampleToGroupIterator::~SampleToGroupIterator() = default;
  22. bool SampleToGroupIterator::Advance() {
  23. DCHECK(IsValid());
  24. --remaining_samples_;
  25. // Handle the case that the table contains an entry with sample count 0.
  26. while (remaining_samples_ == 0) {
  27. ++iterator_;
  28. if (iterator_ == sample_to_group_table_.end())
  29. return false;
  30. remaining_samples_ = iterator_->sample_count;
  31. }
  32. return true;
  33. }
  34. bool SampleToGroupIterator::IsValid() const {
  35. return remaining_samples_ > 0;
  36. }
  37. } // namespace mp4
  38. } // namespace media