1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SAMPLE_ITERATOR_H_
18 
19 #define SAMPLE_ITERATOR_H_
20 
21 #include <utils/Vector.h>
22 
23 namespace android {
24 
25 class SampleTable;
26 
27 struct SampleIterator {
28     SampleIterator(SampleTable *table);
29 
30     status_t seekTo(uint32_t sampleIndex);
31 
getChunkIndexSampleIterator32     uint32_t getChunkIndex() const { return mCurrentChunkIndex; }
getDescIndexSampleIterator33     uint32_t getDescIndex() const { return mChunkDesc; }
getSampleOffsetSampleIterator34     off64_t getSampleOffset() const { return mCurrentSampleOffset; }
getSampleSizeSampleIterator35     size_t getSampleSize() const { return mCurrentSampleSize; }
getSampleTimeSampleIterator36     uint32_t getSampleTime() const { return mCurrentSampleTime; }
getSampleDurationSampleIterator37     uint32_t getSampleDuration() const { return mCurrentSampleDuration; }
38 
39     status_t getSampleSizeDirect(
40             uint32_t sampleIndex, size_t *size);
41 
42 private:
43     SampleTable *mTable;
44 
45     bool mInitialized;
46 
47     uint32_t mSampleToChunkIndex;
48     uint32_t mFirstChunk;
49     uint32_t mFirstChunkSampleIndex;
50     uint32_t mStopChunk;
51     uint32_t mStopChunkSampleIndex;
52     uint32_t mSamplesPerChunk;
53     uint32_t mChunkDesc;
54 
55     uint32_t mCurrentChunkIndex;
56     off64_t mCurrentChunkOffset;
57     Vector<size_t> mCurrentChunkSampleSizes;
58 
59     uint32_t mTimeToSampleIndex;
60     uint32_t mTTSSampleIndex;
61     uint32_t mTTSSampleTime;
62     uint32_t mTTSCount;
63     uint32_t mTTSDuration;
64 
65     uint32_t mCurrentSampleIndex;
66     off64_t mCurrentSampleOffset;
67     size_t mCurrentSampleSize;
68     uint32_t mCurrentSampleTime;
69     uint32_t mCurrentSampleDuration;
70 
71     void reset();
72     status_t findChunkRange(uint32_t sampleIndex);
73     status_t getChunkOffset(uint32_t chunk, off64_t *offset);
74     status_t findSampleTimeAndDuration(uint32_t sampleIndex, uint32_t *time, uint32_t *duration);
75 
76     SampleIterator(const SampleIterator &);
77     SampleIterator &operator=(const SampleIterator &);
78 };
79 
80 }  // namespace android
81 
82 #endif  // SAMPLE_ITERATOR_H_
83