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/stagefright/foundation/ABase.h>
22 #include <media/stagefright/MediaExtractor.h>
23 #include <utils/threads.h>
24 #include <utils/KeyedVector.h>
25 #include <media/stagefright/MediaSource.h>
27 #include "utils/ffmpeg_utils.h"
36 struct FFmpegExtractor : public MediaExtractor {
37 FFmpegExtractor(const sp<DataSource> &source, const sp<AMessage> &meta);
39 virtual size_t countTracks();
40 virtual sp<MediaSource> getTrack(size_t index);
41 virtual sp<MetaData> getTrackMetaData(size_t index, uint32_t flags);
43 virtual sp<MetaData> getMetaData();
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 sp<DataSource> mDataSource;
70 char mFilename[PATH_MAX];
87 MediaSource::ReadOptions::SeekMode mSeekMode;
95 bool mVideoEOSReceived;
96 bool mAudioEOSReceived;
99 AVFormatContext *mFormatCtx;
102 AVStream *mVideoStream;
103 AVStream *mAudioStream;
104 bool mDefersToCreateVideoTrack;
105 bool mDefersToCreateAudioTrack;
106 AVBitStreamFilterContext *mVideoBsfc;
107 AVBitStreamFilterContext *mAudioBsfc;
109 static int decode_interrupt_cb(void *ctx);
111 void deInitStreams();
112 void fetchStuffsFromSniffedMeta(const sp<AMessage> &meta);
113 void setFFmpegDefaultOpts();
114 void printTime(int64_t time);
115 bool is_codec_supported(enum AVCodecID codec_id);
116 sp<MetaData> setVideoFormat(AVStream *stream);
117 sp<MetaData> setAudioFormat(AVStream *stream);
118 void setDurationMetaData(AVStream *stream, sp<MetaData> &meta);
119 int stream_component_open(int stream_index);
120 void stream_component_close(int stream_index);
121 void reachedEOS(enum AVMediaType media_type);
122 int stream_seek(int64_t pos, enum AVMediaType media_type,
123 MediaSource::ReadOptions::SeekMode mode);
124 int check_extradata(AVCodecContext *avctx);
126 bool mReaderThreadStarted;
127 pthread_t mReaderThread;
128 status_t startReaderThread();
129 void stopReaderThread();
130 static void *ReaderWrapper(void *me);
133 DISALLOW_EVIL_CONSTRUCTORS(FFmpegExtractor);
137 const sp<DataSource> &source, String8 *mimeType, float *confidence,
140 } // namespace android
142 #endif // SUPER_EXTRACTOR_H_