SoftAVCEncoder.h revision 5c61b361d1c55a93a215cfb2c325b4987f57f1c5
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 49 // Implement MediaBufferObserver 50 virtual void signalBufferReturned(MediaBuffer *buffer); 51 52 53 // Callbacks required by PV's encoder 54 int32_t allocOutputBuffers(unsigned int sizeInMbs, unsigned int numBuffers); 55 void unbindOutputBuffer(int32_t index); 56 int32_t bindOutputBuffer(int32_t index, uint8_t **yuv); 57 58protected: 59 virtual ~SoftAVCEncoder(); 60 61private: 62 enum { 63 kNumBuffers = 2, 64 }; 65 66 // OMX input buffer's timestamp and flags 67 typedef struct { 68 int64_t mTimeUs; 69 int32_t mFlags; 70 } InputBufferInfo; 71 72 int32_t mVideoWidth; 73 int32_t mVideoHeight; 74 int32_t mVideoFrameRate; 75 int32_t mVideoBitRate; 76 int32_t mVideoColorFormat; 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