1 /* 2 * Copyright (C) 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 SOFT_MPEG4_ENCODER_H_ 18 #define SOFT_MPEG4_ENCODER_H_ 19 20 #include <media/stagefright/MediaBuffer.h> 21 #include <media/stagefright/foundation/ABase.h> 22 #include "SoftVideoEncoderOMXComponent.h" 23 #include "mp4enc_api.h" 24 25 26 namespace android { 27 28 struct CodecProfileLevel; 29 30 struct SoftMPEG4Encoder : public SoftVideoEncoderOMXComponent { 31 SoftMPEG4Encoder( 32 const char *name, 33 const char *componentRole, 34 OMX_VIDEO_CODINGTYPE codingType, 35 const char *mime, 36 const CodecProfileLevel *profileLevels, 37 size_t numProfileLevels, 38 const OMX_CALLBACKTYPE *callbacks, 39 OMX_PTR appData, 40 OMX_COMPONENTTYPE **component); 41 42 // Override SimpleSoftOMXComponent methods 43 virtual OMX_ERRORTYPE internalGetParameter( 44 OMX_INDEXTYPE index, OMX_PTR params); 45 46 virtual OMX_ERRORTYPE internalSetParameter( 47 OMX_INDEXTYPE index, const OMX_PTR params); 48 49 virtual void onQueueFilled(OMX_U32 portIndex); 50 51 protected: 52 virtual ~SoftMPEG4Encoder(); 53 54 private: 55 enum { 56 kNumBuffers = 2, 57 }; 58 59 // OMX input buffer's timestamp and flags 60 typedef struct { 61 int64_t mTimeUs; 62 int32_t mFlags; 63 } InputBufferInfo; 64 65 MP4EncodingMode mEncodeMode; 66 int32_t mIDRFrameRefreshIntervalInSec; 67 68 int64_t mNumInputFrames; 69 bool mStarted; 70 bool mSawInputEOS; 71 bool mSignalledError; 72 73 tagvideoEncControls *mHandle; 74 tagvideoEncOptions *mEncParams; 75 uint8_t *mInputFrameData; 76 Vector<InputBufferInfo> mInputBufferInfoVec; 77 78 OMX_ERRORTYPE initEncParams(); 79 OMX_ERRORTYPE initEncoder(); 80 OMX_ERRORTYPE releaseEncoder(); 81 82 DISALLOW_EVIL_CONSTRUCTORS(SoftMPEG4Encoder); 83 }; 84 85 } // namespace android 86 87 #endif // SOFT_MPEG4_ENCODER_H_ 88