SampleTable.h revision 89e69da4d86348409994c9dafbbb2634ccd7c196
1/*
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>
25#include <utils/RefBase.h>
26#include <utils/threads.h>
27
28namespace android {
29
30class DataSource;
31
32class SampleTable : public RefBase {
33public:
34    SampleTable(const sp<DataSource> &source);
35
36    // type can be 'stco' or 'co64'.
37    status_t setChunkOffsetParams(
38            uint32_t type, off_t data_offset, size_t data_size);
39
40    status_t setSampleToChunkParams(off_t data_offset, size_t data_size);
41
42    // type can be 'stsz' or 'stz2'.
43    status_t setSampleSizeParams(
44            uint32_t type, off_t data_offset, size_t data_size);
45
46    status_t setTimeToSampleParams(off_t data_offset, size_t data_size);
47
48    status_t setSyncSampleParams(off_t data_offset, size_t data_size);
49
50    ////////////////////////////////////////////////////////////////////////////
51
52    uint32_t countChunkOffsets() const;
53    status_t getChunkOffset(uint32_t chunk_index, off_t *offset);
54
55    status_t getChunkForSample(
56            uint32_t sample_index, uint32_t *chunk_index,
57            uint32_t *chunk_relative_sample_index, uint32_t *desc_index);
58
59    uint32_t countSamples() const;
60    status_t getSampleSize(uint32_t sample_index, size_t *sample_size);
61
62    status_t getSampleOffsetAndSize(
63            uint32_t sample_index, off_t *offset, size_t *size);
64
65    status_t getMaxSampleSize(size_t *size);
66
67    status_t getDecodingTime(uint32_t sample_index, uint32_t *time);
68
69    enum {
70        kSyncSample_Flag = 1
71    };
72    status_t findClosestSample(
73            uint32_t req_time, uint32_t *sample_index, uint32_t flags);
74
75    status_t findClosestSyncSample(
76            uint32_t start_sample_index, uint32_t *sample_index);
77
78protected:
79    ~SampleTable();
80
81private:
82    sp<DataSource> mDataSource;
83    Mutex mLock;
84
85    off_t mChunkOffsetOffset;
86    uint32_t mChunkOffsetType;
87    uint32_t mNumChunkOffsets;
88
89    off_t mSampleToChunkOffset;
90    uint32_t mNumSampleToChunkOffsets;
91
92    off_t mSampleSizeOffset;
93    uint32_t mSampleSizeFieldSize;
94    uint32_t mDefaultSampleSize;
95    uint32_t mNumSampleSizes;
96
97    uint32_t mTimeToSampleCount;
98    uint32_t *mTimeToSample;
99
100    off_t mSyncSampleOffset;
101    uint32_t mNumSyncSamples;
102
103    SampleTable(const SampleTable &);
104    SampleTable &operator=(const SampleTable &);
105};
106
107}  // namespace android
108
109#endif  // SAMPLE_TABLE_H_
110