Home | History | Annotate | Download | only in enc
      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 
     27 namespace android {
     28 
     29 struct 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 
     55 protected:
     56     virtual ~SoftAVCEncoder();
     57 
     58 private:
     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  mIDRFrameRefreshIntervalInSec;
     70     AVCProfile mAVCEncProfile;
     71     AVCLevel   mAVCEncLevel;
     72 
     73     int64_t  mNumInputFrames;
     74     int64_t  mPrevTimestampUs;
     75     bool     mStarted;
     76     bool     mSpsPpsHeaderReceived;
     77     bool     mReadyForNextFrame;
     78     bool     mSawInputEOS;
     79     bool     mSignalledError;
     80     bool     mIsIDRFrame;
     81 
     82     tagAVCHandle          *mHandle;
     83     tagAVCEncParam        *mEncParams;
     84     uint8_t               *mInputFrameData;
     85     uint32_t              *mSliceGroup;
     86     Vector<MediaBuffer *> mOutputBuffers;
     87     Vector<InputBufferInfo> mInputBufferInfoVec;
     88 
     89     OMX_ERRORTYPE initEncParams();
     90     OMX_ERRORTYPE initEncoder();
     91     OMX_ERRORTYPE releaseEncoder();
     92     void releaseOutputBuffers();
     93 
     94     DISALLOW_EVIL_CONSTRUCTORS(SoftAVCEncoder);
     95 };
     96 
     97 }  // namespace android
     98 
     99 #endif  // SOFT_AVC_ENCODER_H_
    100