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     explicit 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     uint64_t getSampleTime() const { return mCurrentSampleTime; }
getSampleDurationSampleIterator37     uint64_t getSampleDuration() const { return mCurrentSampleDuration; }
38 
getLastSampleIndexInChunkSampleIterator39     uint32_t getLastSampleIndexInChunk() const {
40         return mCurrentSampleIndex + mSamplesPerChunk -
41                 ((mCurrentSampleIndex - mFirstChunkSampleIndex) % mSamplesPerChunk) - 1;
42     }
43 
44     status_t getSampleSizeDirect(
45             uint32_t sampleIndex, size_t *size);
46 
47 private:
48     SampleTable *mTable;
49 
50     bool mInitialized;
51 
52     uint32_t mSampleToChunkIndex;
53     uint32_t mFirstChunk;
54     uint32_t mFirstChunkSampleIndex;
55     uint32_t mStopChunk;
56     uint32_t mStopChunkSampleIndex;
57     uint32_t mSamplesPerChunk;
58     uint32_t mChunkDesc;
59 
60     uint32_t mCurrentChunkIndex;
61     off64_t mCurrentChunkOffset;
62     Vector<size_t> mCurrentChunkSampleSizes;
63 
64     uint32_t mTimeToSampleIndex;
65     uint32_t mTTSSampleIndex;
66     uint64_t mTTSSampleTime;
67     uint32_t mTTSCount;
68     uint64_t mTTSDuration;
69 
70     uint32_t mCurrentSampleIndex;
71     off64_t mCurrentSampleOffset;
72     size_t mCurrentSampleSize;
73     uint64_t mCurrentSampleTime;
74     uint64_t mCurrentSampleDuration;
75 
76     void reset();
77     status_t findChunkRange(uint32_t sampleIndex);
78     status_t getChunkOffset(uint32_t chunk, off64_t *offset);
79     status_t findSampleTimeAndDuration(uint32_t sampleIndex, uint64_t *time, uint64_t *duration);
80 
81     SampleIterator(const SampleIterator &);
82     SampleIterator &operator=(const SampleIterator &);
83 };
84 
85 }  // namespace android
86 
87 #endif  // SAMPLE_ITERATOR_H_
88