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/MediaExtractorPluginApi.h>
22 #include <media/MediaExtractorPluginHelper.h>
23 #include <media/NdkMediaFormat.h>
24 #include <media/stagefright/foundation/ABase.h>
25 #include <utils/threads.h>
26 #include <utils/KeyedVector.h>
28 #include "utils/ffmpeg_utils.h"
37 struct FFmpegExtractor : public MediaExtractorPluginHelper {
38 FFmpegExtractor(DataSourceHelper *source, const sp<AMessage> &meta);
40 virtual size_t countTracks();
41 virtual MediaTrackHelper* getTrack(size_t index);
42 virtual media_status_t getTrackMetaData(AMediaFormat *meta, size_t index, uint32_t flags);
44 virtual media_status_t getMetaData(AMediaFormat *meta);
46 virtual uint32_t flags() const;
47 virtual const char* name() { return "FFmpegExtractor"; }
50 virtual ~FFmpegExtractor();
53 friend struct FFmpegSource;
56 int mIndex; //stream index
62 Vector<TrackInfo> mTracks;
65 mutable Mutex mExtractorMutex;
68 DataSourceHelper *mDataSource;
72 char mFilename[PATH_MAX];
89 MediaTrackHelper::ReadOptions::SeekMode mSeekMode;
97 bool mVideoEOSReceived;
98 bool mAudioEOSReceived;
100 AVFormatContext *mFormatCtx;
103 AVStream *mVideoStream;
104 AVStream *mAudioStream;
105 bool mDefersToCreateVideoTrack;
106 bool mDefersToCreateAudioTrack;
107 AVBitStreamFilterContext *mVideoBsfc;
108 AVBitStreamFilterContext *mAudioBsfc;
110 static int decode_interrupt_cb(void *ctx);
112 void deInitStreams();
113 void fetchStuffsFromSniffedMeta(const sp<AMessage> &meta);
114 void setFFmpegDefaultOpts();
115 void printTime(int64_t time);
116 bool is_codec_supported(enum AVCodecID codec_id);
117 media_status_t setVideoFormat(AVStream *stream, AMediaFormat *meta);
118 media_status_t setAudioFormat(AVStream *stream, AMediaFormat *meta);
119 void setDurationMetaData(AVStream *stream, AMediaFormat *meta);
120 int stream_component_open(int stream_index);
121 void stream_component_close(int stream_index);
122 void reachedEOS(enum AVMediaType media_type);
123 int stream_seek(int64_t pos, enum AVMediaType media_type,
124 MediaTrackHelper::ReadOptions::SeekMode mode);
125 int check_extradata(AVCodecContext *avctx);
127 bool mReaderThreadStarted;
128 pthread_t mReaderThread;
129 status_t startReaderThread();
130 void stopReaderThread();
131 static void *ReaderWrapper(void *me);
134 bool mParsedMetadata;
136 DISALLOW_EVIL_CONSTRUCTORS(FFmpegExtractor);
139 } // namespace android
141 #endif // SUPER_EXTRACTOR_H_