Converter.h revision 7f06639d375c44f260e00aa5e18cd883624b38bf
1/* 2 * Copyright 2012, 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 CONVERTER_H_ 18 19#define CONVERTER_H_ 20 21#include <media/stagefright/foundation/AHandler.h> 22 23namespace android { 24 25struct ABuffer; 26struct MediaCodec; 27 28// Utility class that receives media access units and converts them into 29// media access unit of a different format. 30// Right now this'll convert raw video into H.264 and raw audio into AAC. 31struct Converter : public AHandler { 32 Converter( 33 const sp<AMessage> ¬ify, 34 const sp<ALooper> &codecLooper, 35 const sp<AMessage> &format); 36 37 status_t initCheck() const; 38 39 size_t getInputBufferCount() const; 40 41 sp<AMessage> getOutputFormat() const; 42 43 void feedAccessUnit(const sp<ABuffer> &accessUnit); 44 void signalEOS(); 45 46 enum { 47 kWhatAccessUnit, 48 kWhatEOS, 49 kWhatError, 50 }; 51 52protected: 53 virtual ~Converter(); 54 virtual void onMessageReceived(const sp<AMessage> &msg); 55 56private: 57 enum { 58 kWhatFeedAccessUnit, 59 kWhatInputEOS, 60 kWhatDoMoreWork 61 }; 62 63 status_t mInitCheck; 64 sp<AMessage> mNotify; 65 sp<ALooper> mCodecLooper; 66 sp<AMessage> mInputFormat; 67 sp<AMessage> mOutputFormat; 68 69 sp<MediaCodec> mEncoder; 70 71 Vector<sp<ABuffer> > mEncoderInputBuffers; 72 Vector<sp<ABuffer> > mEncoderOutputBuffers; 73 74 List<size_t> mAvailEncoderInputIndices; 75 76 List<sp<ABuffer> > mInputBufferQueue; 77 78 bool mDoMoreWorkPending; 79 80 status_t initEncoder(); 81 82 status_t feedEncoderInputBuffers(); 83 84 void scheduleDoMoreWork(); 85 status_t doMoreWork(); 86 87 void notifyError(status_t err); 88 89 DISALLOW_EVIL_CONSTRUCTORS(Converter); 90}; 91 92} // namespace android 93 94#endif // CONVERTER_H_ 95 96