SoftAVCEncoder.h revision 2edda09a2ad1d112c52acd37d323f63f0a492d67
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 "SoftVideoEncoderOMXComponent.h" 26 27namespace android { 28 29struct MediaBuffer; 30 31struct SoftAVCEncoder : public MediaBufferObserver, 32 public SoftVideoEncoderOMXComponent { 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 // Implement MediaBufferObserver 49 virtual void signalBufferReturned(MediaBuffer *buffer); 50 51 52 // Callbacks required by PV's encoder 53 int32_t allocOutputBuffers(unsigned int sizeInMbs, unsigned int numBuffers); 54 void unbindOutputBuffer(int32_t index); 55 int32_t bindOutputBuffer(int32_t index, uint8_t **yuv); 56 57protected: 58 virtual ~SoftAVCEncoder(); 59 60private: 61 enum { 62 kNumBuffers = 2, 63 }; 64 65 // OMX input buffer's timestamp and flags 66 typedef struct { 67 int64_t mTimeUs; 68 int32_t mFlags; 69 } InputBufferInfo; 70 71 int32_t mVideoWidth; 72 int32_t mVideoHeight; 73 int32_t mVideoFrameRate; 74 int32_t mVideoBitRate; 75 int32_t mVideoColorFormat; 76 bool mStoreMetaDataInBuffers; 77 int32_t mIDRFrameRefreshIntervalInSec; 78 AVCProfile mAVCEncProfile; 79 AVCLevel mAVCEncLevel; 80 81 int64_t mNumInputFrames; 82 int64_t mPrevTimestampUs; 83 bool mStarted; 84 bool mSpsPpsHeaderReceived; 85 bool mReadyForNextFrame; 86 bool mSawInputEOS; 87 bool mSignalledError; 88 bool mIsIDRFrame; 89 90 tagAVCHandle *mHandle; 91 tagAVCEncParam *mEncParams; 92 uint8_t *mInputFrameData; 93 uint32_t *mSliceGroup; 94 Vector<MediaBuffer *> mOutputBuffers; 95 Vector<InputBufferInfo> mInputBufferInfoVec; 96 97 void initPorts(); 98 OMX_ERRORTYPE initEncParams(); 99 OMX_ERRORTYPE initEncoder(); 100 OMX_ERRORTYPE releaseEncoder(); 101 void releaseOutputBuffers(); 102 103 DISALLOW_EVIL_CONSTRUCTORS(SoftAVCEncoder); 104}; 105 106} // namespace android 107 108#endif // SOFT_AVC_ENCODER_H_ 109