blob: 2f95de9ce5eda0d3edbb08587293f997555c0cb9 [file] [log] [blame]
Andreas Hubere46b7be2009-07-14 16:56:47 -07001/*
2 * Copyright (C) 2009 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_TABLE_H_
18
19#define SAMPLE_TABLE_H_
20
21#include <sys/types.h>
22#include <stdint.h>
23
24#include <media/stagefright/MediaErrors.h>
Andreas Huberbe06d262009-08-14 14:37:10 -070025#include <utils/RefBase.h>
Andreas Hubere46b7be2009-07-14 16:56:47 -070026#include <utils/threads.h>
27
28namespace android {
29
30class DataSource;
Andreas Huber1faa92a2010-01-19 10:39:21 -080031struct SampleIterator;
Andreas Hubere46b7be2009-07-14 16:56:47 -070032
Andreas Huberbe06d262009-08-14 14:37:10 -070033class SampleTable : public RefBase {
Andreas Hubere46b7be2009-07-14 16:56:47 -070034public:
Andreas Huberbe06d262009-08-14 14:37:10 -070035 SampleTable(const sp<DataSource> &source);
Andreas Hubere46b7be2009-07-14 16:56:47 -070036
37 // type can be 'stco' or 'co64'.
38 status_t setChunkOffsetParams(
James Dongb1262a82010-11-16 14:04:54 -080039 uint32_t type, off64_t data_offset, size_t data_size);
Andreas Hubere46b7be2009-07-14 16:56:47 -070040
James Dongb1262a82010-11-16 14:04:54 -080041 status_t setSampleToChunkParams(off64_t data_offset, size_t data_size);
Andreas Hubere46b7be2009-07-14 16:56:47 -070042
43 // type can be 'stsz' or 'stz2'.
44 status_t setSampleSizeParams(
James Dongb1262a82010-11-16 14:04:54 -080045 uint32_t type, off64_t data_offset, size_t data_size);
Andreas Hubere46b7be2009-07-14 16:56:47 -070046
James Dongb1262a82010-11-16 14:04:54 -080047 status_t setTimeToSampleParams(off64_t data_offset, size_t data_size);
Andreas Hubere46b7be2009-07-14 16:56:47 -070048
Andreas Huberbd352c32011-02-03 13:18:16 -080049 status_t setCompositionTimeToSampleParams(
50 off64_t data_offset, size_t data_size);
51
James Dongb1262a82010-11-16 14:04:54 -080052 status_t setSyncSampleParams(off64_t data_offset, size_t data_size);
Andreas Hubere46b7be2009-07-14 16:56:47 -070053
54 ////////////////////////////////////////////////////////////////////////////
55
56 uint32_t countChunkOffsets() const;
Andreas Hubere46b7be2009-07-14 16:56:47 -070057
58 uint32_t countSamples() const;
Andreas Hubere46b7be2009-07-14 16:56:47 -070059
60 status_t getMaxSampleSize(size_t *size);
61
Andreas Huber1faa92a2010-01-19 10:39:21 -080062 status_t getMetaDataForSample(
63 uint32_t sampleIndex,
James Dongb1262a82010-11-16 14:04:54 -080064 off64_t *offset,
Andreas Huber1faa92a2010-01-19 10:39:21 -080065 size_t *size,
Andreas Huberad98d382010-08-06 14:13:10 -070066 uint32_t *decodingTime,
67 bool *isSyncSample = NULL);
Andreas Hubere46b7be2009-07-14 16:56:47 -070068
69 enum {
Andreas Huber6624c9f2010-07-20 15:04:28 -070070 kFlagBefore,
71 kFlagAfter,
72 kFlagClosest
Andreas Hubere46b7be2009-07-14 16:56:47 -070073 };
Andreas Huber6624c9f2010-07-20 15:04:28 -070074 status_t findSampleAtTime(
Andreas Hubere46b7be2009-07-14 16:56:47 -070075 uint32_t req_time, uint32_t *sample_index, uint32_t flags);
76
Andreas Huber6624c9f2010-07-20 15:04:28 -070077 status_t findSyncSampleNear(
78 uint32_t start_sample_index, uint32_t *sample_index,
79 uint32_t flags);
80
Andreas Hubere981c332009-10-22 13:49:30 -070081 status_t findThumbnailSample(uint32_t *sample_index);
82
Andreas Huberbe06d262009-08-14 14:37:10 -070083protected:
84 ~SampleTable();
85
Andreas Hubere46b7be2009-07-14 16:56:47 -070086private:
Andreas Huber1faa92a2010-01-19 10:39:21 -080087 static const uint32_t kChunkOffsetType32;
88 static const uint32_t kChunkOffsetType64;
89 static const uint32_t kSampleSizeType32;
90 static const uint32_t kSampleSizeTypeCompact;
91
Andreas Huberbe06d262009-08-14 14:37:10 -070092 sp<DataSource> mDataSource;
Andreas Hubere46b7be2009-07-14 16:56:47 -070093 Mutex mLock;
94
James Dongb1262a82010-11-16 14:04:54 -080095 off64_t mChunkOffsetOffset;
Andreas Hubere46b7be2009-07-14 16:56:47 -070096 uint32_t mChunkOffsetType;
97 uint32_t mNumChunkOffsets;
98
James Dongb1262a82010-11-16 14:04:54 -080099 off64_t mSampleToChunkOffset;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700100 uint32_t mNumSampleToChunkOffsets;
101
James Dongb1262a82010-11-16 14:04:54 -0800102 off64_t mSampleSizeOffset;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700103 uint32_t mSampleSizeFieldSize;
104 uint32_t mDefaultSampleSize;
105 uint32_t mNumSampleSizes;
106
107 uint32_t mTimeToSampleCount;
108 uint32_t *mTimeToSample;
109
Andreas Huberbd352c32011-02-03 13:18:16 -0800110 uint32_t *mCompositionTimeDeltaEntries;
111 size_t mNumCompositionTimeDeltaEntries;
112
James Dongb1262a82010-11-16 14:04:54 -0800113 off64_t mSyncSampleOffset;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700114 uint32_t mNumSyncSamples;
Andreas Huberad98d382010-08-06 14:13:10 -0700115 uint32_t *mSyncSamples;
116 size_t mLastSyncSampleIndex;
Andreas Hubere46b7be2009-07-14 16:56:47 -0700117
Andreas Huber1faa92a2010-01-19 10:39:21 -0800118 SampleIterator *mSampleIterator;
119
120 struct SampleToChunkEntry {
121 uint32_t startChunk;
122 uint32_t samplesPerChunk;
123 uint32_t chunkDesc;
124 };
125 SampleToChunkEntry *mSampleToChunkEntries;
126
127 friend struct SampleIterator;
128
Andreas Huber1faa92a2010-01-19 10:39:21 -0800129 status_t getSampleSize_l(uint32_t sample_index, size_t *sample_size);
130
Andreas Huberbd352c32011-02-03 13:18:16 -0800131 uint32_t getCompositionTimeOffset(uint32_t sampleIndex) const;
132
Andreas Hubere46b7be2009-07-14 16:56:47 -0700133 SampleTable(const SampleTable &);
134 SampleTable &operator=(const SampleTable &);
135};
136
137} // namespace android
138
139#endif // SAMPLE_TABLE_H_