Andreas Huber | cabb7da | 2011-03-24 14:18:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 AVI_EXTRACTOR_H_ |
| 18 | |
| 19 | #define AVI_EXTRACTOR_H_ |
| 20 | |
| 21 | #include <media/stagefright/foundation/ABase.h> |
| 22 | #include <media/stagefright/MediaExtractor.h> |
| 23 | #include <media/stagefright/MediaSource.h> |
| 24 | #include <utils/Vector.h> |
| 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | struct AVIExtractor : public MediaExtractor { |
| 29 | AVIExtractor(const sp<DataSource> &dataSource); |
| 30 | |
| 31 | virtual size_t countTracks(); |
| 32 | |
| 33 | virtual sp<MediaSource> getTrack(size_t index); |
| 34 | |
| 35 | virtual sp<MetaData> getTrackMetaData( |
| 36 | size_t index, uint32_t flags); |
| 37 | |
| 38 | virtual sp<MetaData> getMetaData(); |
| 39 | |
| 40 | protected: |
| 41 | virtual ~AVIExtractor(); |
| 42 | |
| 43 | private: |
| 44 | struct AVISource; |
| 45 | |
| 46 | struct SampleInfo { |
| 47 | uint32_t mOffset; |
| 48 | bool mIsKey; |
| 49 | }; |
| 50 | |
| 51 | struct Track { |
| 52 | sp<MetaData> mMeta; |
| 53 | Vector<SampleInfo> mSamples; |
| 54 | uint32_t mRate; |
| 55 | uint32_t mScale; |
| 56 | |
| 57 | enum Kind { |
| 58 | AUDIO, |
| 59 | VIDEO, |
| 60 | OTHER |
| 61 | |
| 62 | } mKind; |
| 63 | |
| 64 | size_t mNumSyncSamples; |
| 65 | size_t mThumbnailSampleSize; |
| 66 | ssize_t mThumbnailSampleIndex; |
| 67 | size_t mMaxSampleSize; |
| 68 | }; |
| 69 | |
| 70 | sp<DataSource> mDataSource; |
| 71 | status_t mInitCheck; |
| 72 | Vector<Track> mTracks; |
| 73 | |
| 74 | off64_t mMovieOffset; |
| 75 | bool mFoundIndex; |
| 76 | bool mOffsetsAreAbsolute; |
| 77 | |
| 78 | ssize_t parseChunk(off64_t offset, off64_t size, int depth = 0); |
| 79 | status_t parseStreamHeader(off64_t offset, size_t size); |
| 80 | status_t parseStreamFormat(off64_t offset, size_t size); |
| 81 | status_t parseIndex(off64_t offset, size_t size); |
| 82 | |
| 83 | status_t parseHeaders(); |
| 84 | |
| 85 | status_t getSampleInfo( |
| 86 | size_t trackIndex, size_t sampleIndex, |
| 87 | off64_t *offset, size_t *size, bool *isKey); |
| 88 | |
| 89 | status_t getSampleIndexAtTime( |
| 90 | size_t trackIndex, |
| 91 | int64_t timeUs, MediaSource::ReadOptions::SeekMode mode, |
| 92 | size_t *sampleIndex) const; |
| 93 | |
| 94 | status_t addMPEG4CodecSpecificData(size_t trackIndex); |
| 95 | |
| 96 | static bool IsCorrectChunkType( |
| 97 | ssize_t trackIndex, Track::Kind kind, uint32_t chunkType); |
| 98 | |
| 99 | DISALLOW_EVIL_CONSTRUCTORS(AVIExtractor); |
| 100 | }; |
| 101 | |
| 102 | class String8; |
| 103 | struct AMessage; |
| 104 | |
| 105 | bool SniffAVI( |
| 106 | const sp<DataSource> &source, String8 *mimeType, float *confidence, |
| 107 | sp<AMessage> *); |
| 108 | |
| 109 | } // namespace android |
| 110 | |
| 111 | #endif // AVI_EXTRACTOR_H_ |