Home | History | Annotate | Download | only in videocodec
      1 /*
      2 * Copyright (c) 2009-2011 Intel Corporation.  All rights reserved.
      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 
     18 #ifndef OMX_VIDEO_ENCODER_AVC_H_
     19 #define OMX_VIDEO_ENCODER_AVC_H_
     20 
     21 
     22 #include "OMXVideoEncoderBase.h"
     23 #include <utils/List.h>
     24 #include <IntelMetadataBuffer.h>
     25 #include <OMX_VideoExt.h>
     26 enum {
     27     F_UNKNOWN = 0x00,    // Unknown
     28     F_I       = 0x01,    // General I-frame type
     29     F_P       = 0x02,    // General P-frame type
     30     F_B       = 0x03,    // General B-frame type
     31     F_SI      = 0x04,    // H.263 SI-frame type
     32     F_SP      = 0x05,    // H.263 SP-frame type
     33     F_EI      = 0x06,    // H.264 EI-frame type
     34     F_EP      = 0x07,    // H.264 EP-frame type
     35     F_S       = 0x08,    // MPEG-4 S-frame type
     36     F_IDR     = 0x09,    // IDR-frame type
     37 };
     38 
     39 enum {
     40     CACHE_NONE    = 0x00,    //nothing to be done
     41     CACHE_PUSH    = 0x01,    //push this frame into cache
     42     CACHE_POP     = 0x02,    //pop all from cache into queue head by STACK rule
     43     CACHE_RESET   = 0x03,    //reset cache, clear all cached frames
     44 };
     45 
     46 #define ENC_NSTOP    0x02000000
     47 
     48 #define GET_FT(x)  ( (x & 0xF0000000 ) >> 28 )       //get frame type
     49 #define GET_CO(x)  ( (x & 0x0C000000 ) >> 26 )       //get cache operation
     50 #define GET_FC(x)  ( (x & 0x01FFFFFF ) )             //get frame count
     51 
     52 #define SET_FT(x, y)  { x = ((x & ~0xF0000000) | (y << 28)); }
     53 #define SET_CO(x, y)  { x = ((x & ~0x0C000000) | (y << 26 )); }
     54 #define SET_FC(x, y)  { x = ((x & ~0x01FFFFFF) | (y & 0x01FFFFFF )); }
     55 
     56 const char* FrameTypeStr[10] = {"UNKNOWN", "I", "P", "B", "SI", "SP", "EI", "EP", "S", "IDR"};
     57 const char* CacheOperationStr[4]= {"NONE", "PUSH", "POP", "RESET"};
     58 
     59 typedef struct {
     60     uint32_t FrameType;
     61     uint32_t CacheOperation;
     62     bool NotStopFrame;
     63     uint32_t FrameCount;
     64 }Encode_Info;
     65 
     66 #define MAX_H264_PROFILE 3
     67 
     68 class OMXVideoEncoderAVC : public OMXVideoEncoderBase {
     69 public:
     70     OMXVideoEncoderAVC();
     71     virtual ~OMXVideoEncoderAVC();
     72 
     73 protected:
     74     virtual OMX_ERRORTYPE InitOutputPortFormatSpecific(OMX_PARAM_PORTDEFINITIONTYPE *paramPortDefinitionOutput);
     75     virtual OMX_ERRORTYPE ProcessorInit(void);
     76     virtual OMX_ERRORTYPE ProcessorDeinit(void);
     77     virtual OMX_ERRORTYPE ProcessorStop(void);
     78     virtual OMX_ERRORTYPE ProcessorProcess(
     79             OMX_BUFFERHEADERTYPE **buffers,
     80             buffer_retain_t *retains,
     81             OMX_U32 numberBuffers);
     82     virtual OMX_ERRORTYPE ProcessorPreEmptyBuffer(OMX_BUFFERHEADERTYPE* buffer);
     83 
     84     virtual OMX_ERRORTYPE BuildHandlerList(void);
     85     virtual OMX_ERRORTYPE SetVideoEncoderParam();
     86     DECLARE_HANDLER(OMXVideoEncoderAVC, ParamVideoAvc);
     87     DECLARE_HANDLER(OMXVideoEncoderAVC, ParamNalStreamFormat);
     88     DECLARE_HANDLER(OMXVideoEncoderAVC, ParamNalStreamFormatSupported);
     89     DECLARE_HANDLER(OMXVideoEncoderAVC, ParamNalStreamFormatSelect);
     90     DECLARE_HANDLER(OMXVideoEncoderAVC, ConfigVideoAVCIntraPeriod);
     91     DECLARE_HANDLER(OMXVideoEncoderAVC, ConfigVideoNalSize);
     92     DECLARE_HANDLER(OMXVideoEncoderAVC, ParamIntelAVCVUI);
     93     DECLARE_HANDLER(OMXVideoEncoderAVC, ParamVideoBytestream);
     94     DECLARE_HANDLER(OMXVideoEncoderAVC, ConfigIntelSliceNumbers);
     95     DECLARE_HANDLER(OMXVideoEncoderAVC, ParamVideoProfileLevelQuerySupported);
     96 
     97 
     98 private:
     99     enum {
    100         // OMX_PARAM_PORTDEFINITIONTYPE
    101         OUTPORT_MIN_BUFFER_COUNT = 1,
    102         OUTPORT_ACTUAL_BUFFER_COUNT = 6,
    103         OUTPORT_BUFFER_SIZE = 1382400,
    104         NUM_REFERENCE_FRAME = 4,
    105     };
    106 
    107     OMX_VIDEO_PARAM_AVCTYPE mParamAvc;
    108     OMX_NALSTREAMFORMATTYPE mNalStreamFormat;
    109     OMX_VIDEO_CONFIG_AVCINTRAPERIOD mConfigAvcIntraPeriod;
    110     OMX_VIDEO_CONFIG_NALSIZE mConfigNalSize;
    111     OMX_VIDEO_PARAM_INTEL_AVCVUI mParamIntelAvcVui;
    112     OMX_VIDEO_CONFIG_INTEL_SLICE_NUMBERS mConfigIntelSliceNumbers;
    113     VideoParamsAVC *mAVCParams;
    114 
    115     OMX_U32 mInputPictureCount;
    116     OMX_U32 mFrameEncodedCount;
    117 
    118     List<OMX_BUFFERHEADERTYPE*> mBFrameList;
    119 
    120     OMX_BOOL ProcessCacheOperation(OMX_BUFFERHEADERTYPE **buffers);
    121     OMX_ERRORTYPE ProcessDataRetrieve(
    122             OMX_BUFFERHEADERTYPE **buffers,
    123             OMX_BOOL *outBufReturned);
    124 
    125     struct ProfileLevelTable {
    126         OMX_U32 profile;
    127         OMX_U32 level;
    128     };
    129 
    130     ProfileLevelTable mPLTable[MAX_H264_PROFILE];
    131     OMX_U32 mPLTableCount;
    132 
    133     OMX_BOOL mEmptyEOSBuf;
    134     OMX_BOOL mCSDOutputted;
    135 };
    136 
    137 #endif /* OMX_VIDEO_ENCODER_AVC_H_ */
    138