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