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 "SimpleSoftOMXComponent.h" 23 #include "mp4enc_api.h" 24 25 26 namespace android { 27 28 struct MediaBuffer; 29 30 struct SoftMPEG4Encoder : public SimpleSoftOMXComponent { 31 SoftMPEG4Encoder( 32 const char *name, 33 const OMX_CALLBACKTYPE *callbacks, 34 OMX_PTR appData, 35 OMX_COMPONENTTYPE **component); 36 37 // Override SimpleSoftOMXComponent methods 38 virtual OMX_ERRORTYPE internalGetParameter( 39 OMX_INDEXTYPE index, OMX_PTR params); 40 41 virtual OMX_ERRORTYPE internalSetParameter( 42 OMX_INDEXTYPE index, const OMX_PTR params); 43 44 virtual void onQueueFilled(OMX_U32 portIndex); 45 46 protected: 47 virtual ~SoftMPEG4Encoder(); 48 49 private: 50 enum { 51 kNumBuffers = 2, 52 }; 53 54 // OMX input buffer's timestamp and flags 55 typedef struct { 56 int64_t mTimeUs; 57 int32_t mFlags; 58 } InputBufferInfo; 59 60 MP4EncodingMode mEncodeMode; 61 int32_t mVideoWidth; 62 int32_t mVideoHeight; 63 int32_t mVideoFrameRate; 64 int32_t mVideoBitRate; 65 int32_t mVideoColorFormat; 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 void initPorts(); 79 OMX_ERRORTYPE initEncParams(); 80 OMX_ERRORTYPE initEncoder(); 81 OMX_ERRORTYPE releaseEncoder(); 82 83 DISALLOW_EVIL_CONSTRUCTORS(SoftMPEG4Encoder); 84 }; 85 86 } // namespace android 87 88 #endif // SOFT_MPEG4_ENCODER_H_ 89