2 * Copyright 2012 Michael Chen <omxcodec@gmail.com>
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef SUPER_EXTRACTOR_H_
19 #define SUPER_EXTRACTOR_H_
21 #include <media/MediaExtractor.h>
22 #include <media/MediaSource.h>
23 #include <media/stagefright/foundation/ABase.h>
24 #include <utils/threads.h>
25 #include <utils/KeyedVector.h>
27 #include "utils/ffmpeg_utils.h"
36 struct FFmpegExtractor : public MediaExtractor {
37 FFmpegExtractor(DataSourceBase *source, const sp<AMessage> &meta);
39 virtual size_t countTracks();
40 virtual MediaTrack* getTrack(size_t index);
41 virtual status_t getTrackMetaData(MetaDataBase &meta, size_t index, uint32_t flags);
43 virtual status_t getMetaData(MetaDataBase &meta);
45 virtual uint32_t flags() const;
48 virtual ~FFmpegExtractor();
51 friend struct FFmpegSource;
54 int mIndex; //stream index
60 Vector<TrackInfo> mTracks;
63 mutable Mutex mExtractorMutex;
66 DataSourceBase *mDataSource;
70 char mFilename[PATH_MAX];
87 MediaSource::ReadOptions::SeekMode mSeekMode;
95 bool mVideoEOSReceived;
96 bool mAudioEOSReceived;
98 AVFormatContext *mFormatCtx;
101 AVStream *mVideoStream;
102 AVStream *mAudioStream;
103 bool mDefersToCreateVideoTrack;
104 bool mDefersToCreateAudioTrack;
105 AVBitStreamFilterContext *mVideoBsfc;
106 AVBitStreamFilterContext *mAudioBsfc;
108 static int decode_interrupt_cb(void *ctx);
110 void deInitStreams();
111 void fetchStuffsFromSniffedMeta(const sp<AMessage> &meta);
112 void setFFmpegDefaultOpts();
113 void printTime(int64_t time);
114 bool is_codec_supported(enum AVCodecID codec_id);
115 status_t setVideoFormat(AVStream *stream, MetaDataBase &meta);
116 status_t setAudioFormat(AVStream *stream, MetaDataBase &meta);
117 void setDurationMetaData(AVStream *stream, MetaDataBase &meta);
118 int stream_component_open(int stream_index);
119 void stream_component_close(int stream_index);
120 void reachedEOS(enum AVMediaType media_type);
121 int stream_seek(int64_t pos, enum AVMediaType media_type,
122 MediaSource::ReadOptions::SeekMode mode);
123 int check_extradata(AVCodecContext *avctx);
125 bool mReaderThreadStarted;
126 pthread_t mReaderThread;
127 status_t startReaderThread();
128 void stopReaderThread();
129 static void *ReaderWrapper(void *me);
132 bool mParsedMetadata;
134 DISALLOW_EVIL_CONSTRUCTORS(FFmpegExtractor);
140 static const char *findMatchingContainer(const char *name);
143 const sp<DataSource> &source, String8 *mimeType, float *confidence,
146 MediaExtractor* CreateFFMPEGExtractor(const sp<DataSource> &source,
147 const char *mime, const sp<AMessage> &meta);
152 } // namespace android
154 #endif // SUPER_EXTRACTOR_H_