SampleTable.h revision abd1f4f870925d6776dbe4b930b759a1ab6595ca
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; 31struct SampleIterator; 32 33class SampleTable : public RefBase { 34public: 35 SampleTable(const sp<DataSource> &source); 36 37 // type can be 'stco' or 'co64'. 38 status_t setChunkOffsetParams( 39 uint32_t type, off_t data_offset, size_t data_size); 40 41 status_t setSampleToChunkParams(off_t data_offset, size_t data_size); 42 43 // type can be 'stsz' or 'stz2'. 44 status_t setSampleSizeParams( 45 uint32_t type, off_t data_offset, size_t data_size); 46 47 status_t setTimeToSampleParams(off_t data_offset, size_t data_size); 48 49 status_t setSyncSampleParams(off_t data_offset, size_t data_size); 50 51 //////////////////////////////////////////////////////////////////////////// 52 53 uint32_t countChunkOffsets() const; 54 55 uint32_t countSamples() const; 56 57 status_t getMaxSampleSize(size_t *size); 58 59 status_t getMetaDataForSample( 60 uint32_t sampleIndex, 61 off_t *offset, 62 size_t *size, 63 uint32_t *decodingTime); 64 65 enum { 66 kFlagBefore, 67 kFlagAfter, 68 kFlagClosest 69 }; 70 status_t findSampleAtTime( 71 uint32_t req_time, uint32_t *sample_index, uint32_t flags); 72 73 status_t findSyncSampleNear( 74 uint32_t start_sample_index, uint32_t *sample_index, 75 uint32_t flags); 76 77 status_t findThumbnailSample(uint32_t *sample_index); 78 79protected: 80 ~SampleTable(); 81 82private: 83 static const uint32_t kChunkOffsetType32; 84 static const uint32_t kChunkOffsetType64; 85 static const uint32_t kSampleSizeType32; 86 static const uint32_t kSampleSizeTypeCompact; 87 88 sp<DataSource> mDataSource; 89 Mutex mLock; 90 91 off_t mChunkOffsetOffset; 92 uint32_t mChunkOffsetType; 93 uint32_t mNumChunkOffsets; 94 95 off_t mSampleToChunkOffset; 96 uint32_t mNumSampleToChunkOffsets; 97 98 off_t mSampleSizeOffset; 99 uint32_t mSampleSizeFieldSize; 100 uint32_t mDefaultSampleSize; 101 uint32_t mNumSampleSizes; 102 103 uint32_t mTimeToSampleCount; 104 uint32_t *mTimeToSample; 105 106 off_t mSyncSampleOffset; 107 uint32_t mNumSyncSamples; 108 109 SampleIterator *mSampleIterator; 110 111 struct SampleToChunkEntry { 112 uint32_t startChunk; 113 uint32_t samplesPerChunk; 114 uint32_t chunkDesc; 115 }; 116 SampleToChunkEntry *mSampleToChunkEntries; 117 118 friend struct SampleIterator; 119 120 status_t getSampleSize_l(uint32_t sample_index, size_t *sample_size); 121 122 SampleTable(const SampleTable &); 123 SampleTable &operator=(const SampleTable &); 124}; 125 126} // namespace android 127 128#endif // SAMPLE_TABLE_H_ 129