SoftAVCEncoder.h revision 031be0f358b07732092a4d1bf02fc99f109a63c4
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_AVC_ENCODER_H_ 18#define SOFT_AVC_ENCODER_H_ 19 20#include <media/stagefright/MediaBuffer.h> 21#include <media/stagefright/foundation/ABase.h> 22#include <utils/Vector.h> 23 24#include "avcenc_api.h" 25#include "SimpleSoftOMXComponent.h" 26 27namespace android { 28 29struct MediaBuffer; 30 31struct SoftAVCEncoder : public MediaBufferObserver, 32 public SimpleSoftOMXComponent { 33 SoftAVCEncoder( 34 const char *name, 35 const OMX_CALLBACKTYPE *callbacks, 36 OMX_PTR appData, 37 OMX_COMPONENTTYPE **component); 38 39 // Override SimpleSoftOMXComponent methods 40 virtual OMX_ERRORTYPE internalGetParameter( 41 OMX_INDEXTYPE index, OMX_PTR params); 42 43 virtual OMX_ERRORTYPE internalSetParameter( 44 OMX_INDEXTYPE index, const OMX_PTR params); 45 46 virtual void onQueueFilled(OMX_U32 portIndex); 47 48 // Override SoftOMXComponent methods 49 50 virtual OMX_ERRORTYPE getExtensionIndex( 51 const char *name, OMX_INDEXTYPE *index); 52 53 // Implement MediaBufferObserver 54 virtual void signalBufferReturned(MediaBuffer *buffer); 55 56 57 // Callbacks required by PV's encoder 58 int32_t allocOutputBuffers(unsigned int sizeInMbs, unsigned int numBuffers); 59 void unbindOutputBuffer(int32_t index); 60 int32_t bindOutputBuffer(int32_t index, uint8_t **yuv); 61 62protected: 63 virtual ~SoftAVCEncoder(); 64 65private: 66 enum { 67 kNumBuffers = 2, 68 }; 69 70 // OMX input buffer's timestamp and flags 71 typedef struct { 72 int64_t mTimeUs; 73 int32_t mFlags; 74 } InputBufferInfo; 75 76 int32_t mVideoWidth; 77 int32_t mVideoHeight; 78 int32_t mVideoFrameRate; 79 int32_t mVideoBitRate; 80 int32_t mVideoColorFormat; 81 bool mStoreMetaDataInBuffers; 82 int32_t mIDRFrameRefreshIntervalInSec; 83 AVCProfile mAVCEncProfile; 84 AVCLevel mAVCEncLevel; 85 86 int64_t mNumInputFrames; 87 int64_t mPrevTimestampUs; 88 bool mStarted; 89 bool mSpsPpsHeaderReceived; 90 bool mReadyForNextFrame; 91 bool mSawInputEOS; 92 bool mSignalledError; 93 bool mIsIDRFrame; 94 95 tagAVCHandle *mHandle; 96 tagAVCEncParam *mEncParams; 97 uint8_t *mInputFrameData; 98 uint32_t *mSliceGroup; 99 Vector<MediaBuffer *> mOutputBuffers; 100 Vector<InputBufferInfo> mInputBufferInfoVec; 101 102 void initPorts(); 103 OMX_ERRORTYPE initEncParams(); 104 OMX_ERRORTYPE initEncoder(); 105 OMX_ERRORTYPE releaseEncoder(); 106 void releaseOutputBuffers(); 107 108 uint8_t* extractGrallocData(void *data, buffer_handle_t *buffer); 109 void releaseGrallocData(buffer_handle_t buffer); 110 111 DISALLOW_EVIL_CONSTRUCTORS(SoftAVCEncoder); 112}; 113 114} // namespace android 115 116#endif // SOFT_AVC_ENCODER_H_ 117