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
|
|
|
|
|
|
|
#ifndef MEDIA_MP4_CHUNK_INFO_ITERATOR_H_
|
|
|
|
#define MEDIA_MP4_CHUNK_INFO_ITERATOR_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "media/mp4/box_definitions.h"
|
|
|
|
|
|
|
|
namespace media {
|
|
|
|
namespace mp4 {
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Sample to chunk box (STSC) iterator used to iterate through the compressed
|
|
|
|
/// table by sample/chunk. This class also provides a convenient function to
|
|
|
|
/// query total number of samples from start_chunk to end_chunk.
|
2013-10-08 17:37:58 +00:00
|
|
|
class ChunkInfoIterator {
|
|
|
|
public:
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Create ChunkInfoIterator from sample to chunk box.
|
2013-10-08 17:37:58 +00:00
|
|
|
explicit ChunkInfoIterator(const SampleToChunk& sample_to_chunk);
|
2014-02-26 23:55:01 +00:00
|
|
|
~ChunkInfoIterator();
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Advance to the next chunk.
|
|
|
|
/// @return true if not past the last chunk, false otherwise.
|
2013-10-08 17:37:58 +00:00
|
|
|
bool AdvanceChunk();
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// Advance to the next sample.
|
|
|
|
/// @return true if not past the last sample, false otherwise.
|
2013-10-08 17:37:58 +00:00
|
|
|
bool AdvanceSample();
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return true if not past the last chunk/sample, false otherwise.
|
2014-02-21 02:09:35 +00:00
|
|
|
bool IsValid() const;
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return Current chunk.
|
2014-02-21 02:09:35 +00:00
|
|
|
uint32 current_chunk() const { return current_chunk_; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return Samples per chunk for current chunk.
|
2014-02-21 02:09:35 +00:00
|
|
|
uint32 samples_per_chunk() const { return iterator_->samples_per_chunk; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return Sample description index for current chunk.
|
2014-02-21 02:09:35 +00:00
|
|
|
uint32 sample_description_index() const {
|
2013-10-08 17:37:58 +00:00
|
|
|
return iterator_->sample_description_index;
|
|
|
|
}
|
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return Number of samples from start_chunk to end_chunk, both 1-based,
|
|
|
|
/// inclusive.
|
2014-02-21 02:09:35 +00:00
|
|
|
uint32 NumSamples(uint32 start_chunk, uint32 end_chunk) const;
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2014-01-23 22:34:39 +00:00
|
|
|
/// @return The last first_chunk in chunk_info_table.
|
2014-02-21 02:09:35 +00:00
|
|
|
uint32 LastFirstChunk() const {
|
|
|
|
return chunk_info_table_.empty() ? 0
|
|
|
|
: chunk_info_table_.back().first_chunk;
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint32 chunk_sample_index_;
|
|
|
|
uint32 current_chunk_;
|
|
|
|
const std::vector<ChunkInfo>& chunk_info_table_;
|
|
|
|
std::vector<ChunkInfo>::const_iterator iterator_;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ChunkInfoIterator);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
|
|
|
|
|
|
|
#endif // MEDIA_MP4_CHUNK_INFO_ITERATOR_H_
|