Home | History | Annotate | Download | only in src
      1 /*--------------------------------------------------------------------------
      2 Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
      3 
      4 Redistribution and use in source and binary forms, with or without
      5 modification, are permitted provided that the following conditions are met:
      6     * Redistributions of source code must retain the above copyright
      7       notice, this list of conditions and the following disclaimer.
      8     * Redistributions in binary form must reproduce the above copyright
      9       notice, this list of conditions and the following disclaimer in the
     10       documentation and/or other materials provided with the distribution.
     11     * Neither the name of The Linux Foundation nor
     12       the names of its contributors may be used to endorse or promote
     13       products derived from this software without specific prior written
     14       permission.
     15 
     16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19 NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 --------------------------------------------------------------------------*/
     28 #include "omx_video_encoder.h"
     29 #include <string.h>
     30 #include "video_encoder_device.h"
     31 #include <stdio.h>
     32 #ifdef _ANDROID_ICS_
     33 #include <media/hardware/HardwareAPI.h>
     34 #endif
     35 #ifdef _ANDROID_
     36 #include <cutils/properties.h>
     37 #endif
     38 #ifndef _ANDROID_
     39 #include <glib.h>
     40 #define strlcpy g_strlcpy
     41 #endif
     42 /*----------------------------------------------------------------------------
     43  * Preprocessor Definitions and Constants
     44  * -------------------------------------------------------------------------*/
     45 
     46 #define OMX_SPEC_VERSION 0x00000101
     47 #define OMX_INIT_STRUCT(_s_, _name_)            \
     48     memset((_s_), 0x0, sizeof(_name_));          \
     49 (_s_)->nSize = sizeof(_name_);               \
     50 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION
     51 
     52 extern int m_pipe;
     53 
     54 // factory function executed by the core to create instances
     55 void *get_omx_component_factory_fn(void)
     56 {
     57     return(new omx_venc);
     58 }
     59 
     60 //constructor
     61 
     62 omx_venc::omx_venc()
     63 {
     64 #ifdef _ANDROID_ICS_
     65     meta_mode_enable = false;
     66     memset(meta_buffer_hdr,0,sizeof(meta_buffer_hdr));
     67     memset(meta_buffers,0,sizeof(meta_buffers));
     68     memset(opaque_buffer_hdr,0,sizeof(opaque_buffer_hdr));
     69     mUseProxyColorFormat = false;
     70     get_syntaxhdr_enable = false;
     71 #endif
     72 }
     73 
     74 omx_venc::~omx_venc()
     75 {
     76     get_syntaxhdr_enable = false;
     77     //nothing to do
     78 }
     79 
     80 /* ======================================================================
     81    FUNCTION
     82    omx_venc::ComponentInit
     83 
     84    DESCRIPTION
     85    Initialize the component.
     86 
     87    PARAMETERS
     88    ctxt -- Context information related to the self.
     89    id   -- Event identifier. This could be any of the following:
     90    1. Command completion event
     91    2. Buffer done callback event
     92    3. Frame done callback event
     93 
     94    RETURN VALUE
     95    None.
     96 
     97    ========================================================================== */
     98 OMX_ERRORTYPE omx_venc::component_init(OMX_STRING role)
     99 {
    100 
    101     OMX_ERRORTYPE eRet = OMX_ErrorNone;
    102 
    103     int fds[2];
    104     int r;
    105 
    106     OMX_VIDEO_CODINGTYPE codec_type;
    107 
    108     DEBUG_PRINT_HIGH("\n omx_venc(): Inside component_init()");
    109     // Copy the role information which provides the decoder m_nkind
    110     strlcpy((char *)m_nkind,role,OMX_MAX_STRINGNAME_SIZE);
    111 
    112     if (!strncmp((char *)m_nkind,"OMX.qcom.video.encoder.mpeg4",\
    113                 OMX_MAX_STRINGNAME_SIZE)) {
    114         strlcpy((char *)m_cRole, "video_encoder.mpeg4",\
    115                 OMX_MAX_STRINGNAME_SIZE);
    116         codec_type = OMX_VIDEO_CodingMPEG4;
    117     } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\
    118                 OMX_MAX_STRINGNAME_SIZE)) {
    119         strlcpy((char *)m_cRole, "video_encoder.h263",OMX_MAX_STRINGNAME_SIZE);
    120         codec_type = OMX_VIDEO_CodingH263;
    121     } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
    122                 OMX_MAX_STRINGNAME_SIZE)) {
    123         strlcpy((char *)m_cRole, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
    124         codec_type = OMX_VIDEO_CodingAVC;
    125     }
    126 #ifdef _MSM8974_
    127     else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.vp8",    \
    128                 OMX_MAX_STRINGNAME_SIZE)) {
    129         strlcpy((char *)m_cRole, "video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE);
    130         codec_type = OMX_VIDEO_CodingVPX;
    131     }
    132 #endif
    133     else {
    134         DEBUG_PRINT_ERROR("\nERROR: Unknown Component\n");
    135         eRet = OMX_ErrorInvalidComponentName;
    136     }
    137 
    138 
    139     if (eRet != OMX_ErrorNone) {
    140         return eRet;
    141     }
    142 #ifdef ENABLE_GET_SYNTAX_HDR
    143     get_syntaxhdr_enable = true;
    144     DEBUG_PRINT_HIGH("Get syntax header enabled");
    145 #endif
    146 
    147     handle = new venc_dev(this);
    148 
    149     if (handle == NULL) {
    150         DEBUG_PRINT_ERROR("\nERROR: handle is NULL");
    151         return OMX_ErrorInsufficientResources;
    152     }
    153 
    154     if (handle->venc_open(codec_type) != true) {
    155         DEBUG_PRINT_ERROR("\nERROR: venc_open failed");
    156         return OMX_ErrorInsufficientResources;
    157     }
    158 
    159     //Intialise the OMX layer variables
    160     memset(&m_pCallbacks,0,sizeof(OMX_CALLBACKTYPE));
    161 
    162     OMX_INIT_STRUCT(&m_sPortParam, OMX_PORT_PARAM_TYPE);
    163     m_sPortParam.nPorts = 0x2;
    164     m_sPortParam.nStartPortNumber = (OMX_U32) PORT_INDEX_IN;
    165 
    166     OMX_INIT_STRUCT(&m_sPortParam_audio, OMX_PORT_PARAM_TYPE);
    167     m_sPortParam_audio.nPorts = 0;
    168     m_sPortParam_audio.nStartPortNumber = 0;
    169 
    170     OMX_INIT_STRUCT(&m_sPortParam_img, OMX_PORT_PARAM_TYPE);
    171     m_sPortParam_img.nPorts = 0;
    172     m_sPortParam_img.nStartPortNumber = 0;
    173 
    174     OMX_INIT_STRUCT(&m_sParamBitrate, OMX_VIDEO_PARAM_BITRATETYPE);
    175     m_sParamBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    176     m_sParamBitrate.eControlRate = OMX_Video_ControlRateVariableSkipFrames;
    177     m_sParamBitrate.nTargetBitrate = 64000;
    178 
    179     OMX_INIT_STRUCT(&m_sConfigBitrate, OMX_VIDEO_CONFIG_BITRATETYPE);
    180     m_sConfigBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    181     m_sConfigBitrate.nEncodeBitrate = 64000;
    182 
    183     OMX_INIT_STRUCT(&m_sConfigFramerate, OMX_CONFIG_FRAMERATETYPE);
    184     m_sConfigFramerate.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    185     m_sConfigFramerate.xEncodeFramerate = 30 << 16;
    186 
    187     OMX_INIT_STRUCT(&m_sConfigIntraRefreshVOP, OMX_CONFIG_INTRAREFRESHVOPTYPE);
    188     m_sConfigIntraRefreshVOP.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    189     m_sConfigIntraRefreshVOP.IntraRefreshVOP = OMX_FALSE;
    190 
    191     OMX_INIT_STRUCT(&m_sConfigFrameRotation, OMX_CONFIG_ROTATIONTYPE);
    192     m_sConfigFrameRotation.nPortIndex = (OMX_U32) PORT_INDEX_IN;
    193     m_sConfigFrameRotation.nRotation = 0;
    194 
    195     OMX_INIT_STRUCT(&m_sSessionQuantization, OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
    196     m_sSessionQuantization.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    197     m_sSessionQuantization.nQpI = 9;
    198     m_sSessionQuantization.nQpP = 6;
    199     m_sSessionQuantization.nQpB = 2;
    200 
    201     OMX_INIT_STRUCT(&m_sSessionQPRange, OMX_QCOM_VIDEO_PARAM_QPRANGETYPE);
    202     m_sSessionQPRange.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    203     m_sSessionQPRange.minQP = 2;
    204     if (codec_type == OMX_VIDEO_CodingAVC)
    205         m_sSessionQPRange.maxQP = 51;
    206     else
    207         m_sSessionQPRange.maxQP = 31;
    208 
    209     OMX_INIT_STRUCT(&m_sAVCSliceFMO, OMX_VIDEO_PARAM_AVCSLICEFMO);
    210     m_sAVCSliceFMO.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    211     m_sAVCSliceFMO.eSliceMode = OMX_VIDEO_SLICEMODE_AVCDefault;
    212     m_sAVCSliceFMO.nNumSliceGroups = 0;
    213     m_sAVCSliceFMO.nSliceGroupMapType = 0;
    214     OMX_INIT_STRUCT(&m_sParamProfileLevel, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
    215     m_sParamProfileLevel.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    216 
    217     OMX_INIT_STRUCT(&m_sIntraperiod, QOMX_VIDEO_INTRAPERIODTYPE);
    218     m_sIntraperiod.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    219     m_sIntraperiod.nPFrames = (m_sConfigFramerate.xEncodeFramerate * 2) - 1;
    220 
    221     OMX_INIT_STRUCT(&m_sErrorCorrection, OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE);
    222     m_sErrorCorrection.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    223     m_sErrorCorrection.bEnableDataPartitioning = OMX_FALSE;
    224     m_sErrorCorrection.bEnableHEC = OMX_FALSE;
    225     m_sErrorCorrection.bEnableResync = OMX_FALSE;
    226     m_sErrorCorrection.bEnableRVLC = OMX_FALSE;
    227     m_sErrorCorrection.nResynchMarkerSpacing = 0;
    228 
    229     OMX_INIT_STRUCT(&m_sIntraRefresh, OMX_VIDEO_PARAM_INTRAREFRESHTYPE);
    230     m_sIntraRefresh.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    231     m_sIntraRefresh.eRefreshMode = OMX_VIDEO_IntraRefreshMax;
    232 
    233     if (codec_type == OMX_VIDEO_CodingMPEG4) {
    234         m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_MPEG4ProfileSimple;
    235         m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_MPEG4Level0;
    236     } else if (codec_type == OMX_VIDEO_CodingH263) {
    237         m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_H263ProfileBaseline;
    238         m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_H263Level10;
    239     } else if (codec_type == OMX_VIDEO_CodingAVC) {
    240         m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_AVCProfileBaseline;
    241         m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_AVCLevel1;
    242     } else if (codec_type == OMX_VIDEO_CodingVPX) {
    243         m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_VP8ProfileMain;
    244         m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_VP8Level_Version0;
    245     }
    246 
    247     // Initialize the video parameters for input port
    248     OMX_INIT_STRUCT(&m_sInPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
    249     m_sInPortDef.nPortIndex= (OMX_U32) PORT_INDEX_IN;
    250     m_sInPortDef.bEnabled = OMX_TRUE;
    251     m_sInPortDef.bPopulated = OMX_FALSE;
    252     m_sInPortDef.eDomain = OMX_PortDomainVideo;
    253     m_sInPortDef.eDir = OMX_DirInput;
    254     m_sInPortDef.format.video.cMIMEType = "YUV420";
    255     m_sInPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH;
    256     m_sInPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT;
    257     m_sInPortDef.format.video.nStride = OMX_CORE_QCIF_WIDTH;
    258     m_sInPortDef.format.video.nSliceHeight = OMX_CORE_QCIF_HEIGHT;
    259     m_sInPortDef.format.video.nBitrate = 64000;
    260     m_sInPortDef.format.video.xFramerate = 15 << 16;
    261     m_sInPortDef.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)
    262         QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
    263     m_sInPortDef.format.video.eCompressionFormat =  OMX_VIDEO_CodingUnused;
    264 
    265     if (dev_get_buf_req(&m_sInPortDef.nBufferCountMin,
    266                 &m_sInPortDef.nBufferCountActual,
    267                 &m_sInPortDef.nBufferSize,
    268                 m_sInPortDef.nPortIndex) != true) {
    269         eRet = OMX_ErrorUndefined;
    270 
    271     }
    272 
    273     // Initialize the video parameters for output port
    274     OMX_INIT_STRUCT(&m_sOutPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
    275     m_sOutPortDef.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    276     m_sOutPortDef.bEnabled = OMX_TRUE;
    277     m_sOutPortDef.bPopulated = OMX_FALSE;
    278     m_sOutPortDef.eDomain = OMX_PortDomainVideo;
    279     m_sOutPortDef.eDir = OMX_DirOutput;
    280     m_sOutPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH;
    281     m_sOutPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT;
    282     m_sOutPortDef.format.video.nBitrate = 64000;
    283     m_sOutPortDef.format.video.xFramerate = 15 << 16;
    284     m_sOutPortDef.format.video.eColorFormat =  OMX_COLOR_FormatUnused;
    285     if (codec_type == OMX_VIDEO_CodingMPEG4) {
    286         m_sOutPortDef.format.video.eCompressionFormat =  OMX_VIDEO_CodingMPEG4;
    287     } else if (codec_type == OMX_VIDEO_CodingH263) {
    288         m_sOutPortDef.format.video.eCompressionFormat =  OMX_VIDEO_CodingH263;
    289     } else if (codec_type == OMX_VIDEO_CodingAVC) {
    290         m_sOutPortDef.format.video.eCompressionFormat =  OMX_VIDEO_CodingAVC;
    291     } else if (codec_type == OMX_VIDEO_CodingVPX) {
    292         m_sOutPortDef.format.video.eCompressionFormat =  OMX_VIDEO_CodingVPX;
    293     }
    294 
    295     if (dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
    296                 &m_sOutPortDef.nBufferCountActual,
    297                 &m_sOutPortDef.nBufferSize,
    298                 m_sOutPortDef.nPortIndex) != true) {
    299         eRet = OMX_ErrorUndefined;
    300     }
    301 
    302     // Initialize the video color format for input port
    303     OMX_INIT_STRUCT(&m_sInPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);
    304     m_sInPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_IN;
    305     m_sInPortFormat.nIndex = 0;
    306     m_sInPortFormat.eColorFormat = (OMX_COLOR_FORMATTYPE)
    307         QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
    308     m_sInPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused;
    309 
    310 
    311     // Initialize the compression format for output port
    312     OMX_INIT_STRUCT(&m_sOutPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);
    313     m_sOutPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    314     m_sOutPortFormat.nIndex = 0;
    315     m_sOutPortFormat.eColorFormat = OMX_COLOR_FormatUnused;
    316     if (codec_type == OMX_VIDEO_CodingMPEG4) {
    317         m_sOutPortFormat.eCompressionFormat =  OMX_VIDEO_CodingMPEG4;
    318     } else if (codec_type == OMX_VIDEO_CodingH263) {
    319         m_sOutPortFormat.eCompressionFormat =  OMX_VIDEO_CodingH263;
    320     } else if (codec_type == OMX_VIDEO_CodingAVC) {
    321         m_sOutPortFormat.eCompressionFormat =  OMX_VIDEO_CodingAVC;
    322     } else if (codec_type == OMX_VIDEO_CodingVPX) {
    323         m_sOutPortFormat.eCompressionFormat =  OMX_VIDEO_CodingVPX;
    324     }
    325 
    326 
    327     // mandatory Indices for kronos test suite
    328     OMX_INIT_STRUCT(&m_sPriorityMgmt, OMX_PRIORITYMGMTTYPE);
    329 
    330     OMX_INIT_STRUCT(&m_sInBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE);
    331     m_sInBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_IN;
    332 
    333     OMX_INIT_STRUCT(&m_sOutBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE);
    334     m_sOutBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    335 
    336 
    337     // mp4 specific init
    338     OMX_INIT_STRUCT(&m_sParamMPEG4, OMX_VIDEO_PARAM_MPEG4TYPE);
    339     m_sParamMPEG4.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    340     m_sParamMPEG4.eProfile = OMX_VIDEO_MPEG4ProfileSimple;
    341     m_sParamMPEG4.eLevel = OMX_VIDEO_MPEG4Level0;
    342     m_sParamMPEG4.nSliceHeaderSpacing = 0;
    343     m_sParamMPEG4.bSVH = OMX_FALSE;
    344     m_sParamMPEG4.bGov = OMX_FALSE;
    345     m_sParamMPEG4.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1);  // 2 second intra period for default outport fps
    346     m_sParamMPEG4.bACPred = OMX_TRUE;
    347     m_sParamMPEG4.nTimeIncRes = 30; // delta = 2 @ 15 fps
    348     m_sParamMPEG4.nAllowedPictureTypes = 2; // pframe and iframe
    349     m_sParamMPEG4.nHeaderExtension = 1; // number of video packet headers per vop
    350     m_sParamMPEG4.bReversibleVLC = OMX_FALSE;
    351 
    352     // h263 specific init
    353     OMX_INIT_STRUCT(&m_sParamH263, OMX_VIDEO_PARAM_H263TYPE);
    354     m_sParamH263.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    355     m_sParamH263.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1); // 2 second intra period for default outport fps
    356     m_sParamH263.nBFrames = 0;
    357     m_sParamH263.eProfile = OMX_VIDEO_H263ProfileBaseline;
    358     m_sParamH263.eLevel = OMX_VIDEO_H263Level10;
    359     m_sParamH263.bPLUSPTYPEAllowed = OMX_FALSE;
    360     m_sParamH263.nAllowedPictureTypes = 2;
    361     m_sParamH263.bForceRoundingTypeToZero = OMX_TRUE;
    362     m_sParamH263.nPictureHeaderRepetition = 0;
    363     m_sParamH263.nGOBHeaderInterval = 1;
    364 
    365     // h264 specific init
    366     OMX_INIT_STRUCT(&m_sParamAVC, OMX_VIDEO_PARAM_AVCTYPE);
    367     m_sParamAVC.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    368     m_sParamAVC.nSliceHeaderSpacing = 0;
    369     m_sParamAVC.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1); // 2 second intra period for default outport fps
    370     m_sParamAVC.nBFrames = 0;
    371     m_sParamAVC.bUseHadamard = OMX_FALSE;
    372     m_sParamAVC.nRefFrames = 1;
    373     m_sParamAVC.nRefIdx10ActiveMinus1 = 1;
    374     m_sParamAVC.nRefIdx11ActiveMinus1 = 0;
    375     m_sParamAVC.bEnableUEP = OMX_FALSE;
    376     m_sParamAVC.bEnableFMO = OMX_FALSE;
    377     m_sParamAVC.bEnableASO = OMX_FALSE;
    378     m_sParamAVC.bEnableRS = OMX_FALSE;
    379     m_sParamAVC.eProfile = OMX_VIDEO_AVCProfileBaseline;
    380     m_sParamAVC.eLevel = OMX_VIDEO_AVCLevel1;
    381     m_sParamAVC.nAllowedPictureTypes = 2;
    382     m_sParamAVC.bFrameMBsOnly = OMX_FALSE;
    383     m_sParamAVC.bMBAFF = OMX_FALSE;
    384     m_sParamAVC.bEntropyCodingCABAC = OMX_FALSE;
    385     m_sParamAVC.bWeightedPPrediction = OMX_FALSE;
    386     m_sParamAVC.nWeightedBipredicitonMode = 0;
    387     m_sParamAVC.bconstIpred = OMX_FALSE;
    388     m_sParamAVC.bDirect8x8Inference = OMX_FALSE;
    389     m_sParamAVC.bDirectSpatialTemporal = OMX_FALSE;
    390     m_sParamAVC.nCabacInitIdc = 0;
    391     m_sParamAVC.eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable;
    392 
    393     // VP8 specific init
    394     OMX_INIT_STRUCT(&m_sParamVP8, OMX_VIDEO_PARAM_VP8TYPE);
    395     m_sParamVP8.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    396     m_sParamVP8.eProfile = OMX_VIDEO_VP8ProfileMain;
    397     m_sParamVP8.eLevel = OMX_VIDEO_VP8Level_Version0;
    398     m_sParamVP8.nDCTPartitions = 0;
    399     m_sParamVP8.bErrorResilientMode = OMX_FALSE;
    400 
    401     OMX_INIT_STRUCT(&m_sParamLTRMode, QOMX_VIDEO_PARAM_LTRMODE_TYPE);
    402     m_sParamLTRMode.nPortIndex = (OMX_U32) PORT_INDEX_OUT;
    403     m_sParamLTRMode.eLTRMode = QOMX_VIDEO_LTRMode_Disable;
    404 
    405     m_state                   = OMX_StateLoaded;
    406     m_sExtraData = 0;
    407 
    408     if (eRet == OMX_ErrorNone) {
    409         if (pipe(fds)) {
    410             DEBUG_PRINT_ERROR("ERROR: pipe creation failed\n");
    411             eRet = OMX_ErrorInsufficientResources;
    412         } else {
    413             if (fds[0] == 0 || fds[1] == 0) {
    414                 if (pipe(fds)) {
    415                     DEBUG_PRINT_ERROR("ERROR: pipe creation failed\n");
    416                     eRet = OMX_ErrorInsufficientResources;
    417                 }
    418             }
    419             if (eRet == OMX_ErrorNone) {
    420                 m_pipe_in = fds[0];
    421                 m_pipe_out = fds[1];
    422             }
    423         }
    424         msg_thread_created = true;
    425         r = pthread_create(&msg_thread_id,0, message_thread, this);
    426         if (r < 0) {
    427             eRet = OMX_ErrorInsufficientResources;
    428             msg_thread_created = false;
    429         } else {
    430             async_thread_created = true;
    431             r = pthread_create(&async_thread_id,0, venc_dev::async_venc_message_thread, this);
    432             if (r < 0) {
    433                 eRet = OMX_ErrorInsufficientResources;
    434                 async_thread_created = false;
    435             } else
    436                 dev_set_message_thread_id(async_thread_id);
    437         }
    438     }
    439 
    440     DEBUG_PRINT_HIGH("\n Component_init return value = 0x%x", eRet);
    441     return eRet;
    442 }
    443 
    444 
    445 /* ======================================================================
    446    FUNCTION
    447    omx_venc::Setparameter
    448 
    449    DESCRIPTION
    450    OMX Set Parameter method implementation.
    451 
    452    PARAMETERS
    453    <TBD>.
    454 
    455    RETURN VALUE
    456    OMX Error None if successful.
    457 
    458    ========================================================================== */
    459 OMX_ERRORTYPE  omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE     hComp,
    460         OMX_IN OMX_INDEXTYPE paramIndex,
    461         OMX_IN OMX_PTR        paramData)
    462 {
    463     OMX_ERRORTYPE eRet = OMX_ErrorNone;
    464 
    465 
    466     if (m_state == OMX_StateInvalid) {
    467         DEBUG_PRINT_ERROR("ERROR: Set Param in Invalid State\n");
    468         return OMX_ErrorInvalidState;
    469     }
    470     if (paramData == NULL) {
    471         DEBUG_PRINT_ERROR("ERROR: Get Param in Invalid paramData \n");
    472         return OMX_ErrorBadParameter;
    473     }
    474 
    475     /*set_parameter can be called in loaded state
    476       or disabled port */
    477     if (m_state == OMX_StateLoaded
    478             || m_sInPortDef.bEnabled == OMX_FALSE
    479             || m_sOutPortDef.bEnabled == OMX_FALSE) {
    480         DEBUG_PRINT_LOW("Set Parameter called in valid state");
    481     } else {
    482         DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State\n");
    483         return OMX_ErrorIncorrectStateOperation;
    484     }
    485 
    486     switch (paramIndex) {
    487         case OMX_IndexParamPortDefinition:
    488             {
    489                 OMX_PARAM_PORTDEFINITIONTYPE *portDefn;
    490                 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData;
    491                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d\n",
    492                         (int)portDefn->format.video.nFrameHeight,
    493                         (int)portDefn->format.video.nFrameWidth);
    494 
    495                 if (PORT_INDEX_IN == portDefn->nPortIndex) {
    496                     if (!dev_is_video_session_supported(portDefn->format.video.nFrameWidth,
    497                                 portDefn->format.video.nFrameHeight)) {
    498                         DEBUG_PRINT_ERROR("video session not supported\n");
    499                         omx_report_unsupported_setting();
    500                         return OMX_ErrorUnsupportedSetting;
    501                     }
    502                     DEBUG_PRINT_LOW("\n i/p actual cnt requested = %d\n", portDefn->nBufferCountActual);
    503                     DEBUG_PRINT_LOW("\n i/p min cnt requested = %d\n", portDefn->nBufferCountMin);
    504                     DEBUG_PRINT_LOW("\n i/p buffersize requested = %d\n", portDefn->nBufferSize);
    505                     if (portDefn->nBufferCountMin > portDefn->nBufferCountActual) {
    506                         DEBUG_PRINT_ERROR("\nERROR: (In_PORT) Min buffers (%d) > actual count (%d)\n",
    507                                 portDefn->nBufferCountMin, portDefn->nBufferCountActual);
    508                         return OMX_ErrorUnsupportedSetting;
    509                     }
    510                     if (handle->venc_set_param(paramData,OMX_IndexParamPortDefinition) != true) {
    511                         DEBUG_PRINT_ERROR("\nERROR: venc_set_param input failed");
    512                         return OMX_ErrorUnsupportedSetting;
    513                     }
    514 
    515                     DEBUG_PRINT_LOW("\n i/p previous actual cnt = %d\n", m_sInPortDef.nBufferCountActual);
    516                     DEBUG_PRINT_LOW("\n i/p previous min cnt = %d\n", m_sInPortDef.nBufferCountMin);
    517                     memcpy(&m_sInPortDef, portDefn,sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
    518 
    519 #ifdef _ANDROID_ICS_
    520                     if (portDefn->format.video.eColorFormat ==
    521                             (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FormatAndroidOpaque) {
    522                         m_sInPortDef.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE)
    523                             QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
    524                         if (!mUseProxyColorFormat) {
    525                             if (!c2d_conv.init()) {
    526                                 DEBUG_PRINT_ERROR("\n C2D init failed");
    527                                 return OMX_ErrorUnsupportedSetting;
    528                             }
    529                             DEBUG_PRINT_ERROR("\nC2D init is successful");
    530                         }
    531                         mUseProxyColorFormat = true;
    532                         m_input_msg_id = OMX_COMPONENT_GENERATE_ETB_OPQ;
    533                     } else
    534                         mUseProxyColorFormat = false;
    535 #endif
    536                     /*Query Input Buffer Requirements*/
    537                     dev_get_buf_req   (&m_sInPortDef.nBufferCountMin,
    538                             &m_sInPortDef.nBufferCountActual,
    539                             &m_sInPortDef.nBufferSize,
    540                             m_sInPortDef.nPortIndex);
    541 
    542                     /*Query ouput Buffer Requirements*/
    543                     dev_get_buf_req   (&m_sOutPortDef.nBufferCountMin,
    544                             &m_sOutPortDef.nBufferCountActual,
    545                             &m_sOutPortDef.nBufferSize,
    546                             m_sOutPortDef.nPortIndex);
    547                     m_sInPortDef.nBufferCountActual = portDefn->nBufferCountActual;
    548                 } else if (PORT_INDEX_OUT == portDefn->nPortIndex) {
    549                     DEBUG_PRINT_LOW("\n o/p actual cnt requested = %d\n", portDefn->nBufferCountActual);
    550                     DEBUG_PRINT_LOW("\n o/p min cnt requested = %d\n", portDefn->nBufferCountMin);
    551                     DEBUG_PRINT_LOW("\n o/p buffersize requested = %d\n", portDefn->nBufferSize);
    552                     if (portDefn->nBufferCountMin > portDefn->nBufferCountActual) {
    553                         DEBUG_PRINT_ERROR("\nERROR: (Out_PORT) Min buffers (%d) > actual count (%d)\n",
    554                                 portDefn->nBufferCountMin, portDefn->nBufferCountActual);
    555                         return OMX_ErrorUnsupportedSetting;
    556                     }
    557                     if (handle->venc_set_param(paramData,OMX_IndexParamPortDefinition) != true) {
    558                         DEBUG_PRINT_ERROR("\nERROR: venc_set_param output failed");
    559                         return OMX_ErrorUnsupportedSetting;
    560                     }
    561 #ifdef _MSM8974_
    562                     /*Query ouput Buffer Requirements*/
    563                     dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
    564                             &m_sOutPortDef.nBufferCountActual,
    565                             &m_sOutPortDef.nBufferSize,
    566                             m_sOutPortDef.nPortIndex);
    567 #endif
    568                     memcpy(&m_sOutPortDef,portDefn,sizeof(struct OMX_PARAM_PORTDEFINITIONTYPE));
    569                     update_profile_level(); //framerate , bitrate
    570 
    571                     DEBUG_PRINT_LOW("\n o/p previous actual cnt = %d\n", m_sOutPortDef.nBufferCountActual);
    572                     DEBUG_PRINT_LOW("\n o/p previous min cnt = %d\n", m_sOutPortDef.nBufferCountMin);
    573                     m_sOutPortDef.nBufferCountActual = portDefn->nBufferCountActual;
    574                 } else {
    575                     DEBUG_PRINT_ERROR("ERROR: Set_parameter: Bad Port idx %d",
    576                             (int)portDefn->nPortIndex);
    577                     eRet = OMX_ErrorBadPortIndex;
    578                 }
    579                 m_sConfigFramerate.xEncodeFramerate = portDefn->format.video.xFramerate;
    580                 m_sConfigBitrate.nEncodeBitrate = portDefn->format.video.nBitrate;
    581                 m_sParamBitrate.nTargetBitrate = portDefn->format.video.nBitrate;
    582             }
    583             break;
    584 
    585         case OMX_IndexParamVideoPortFormat:
    586             {
    587                 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt =
    588                     (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData;
    589                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d\n",
    590                         portFmt->eColorFormat);
    591                 //set the driver with the corresponding values
    592                 if (PORT_INDEX_IN == portFmt->nPortIndex) {
    593                     if (handle->venc_set_param(paramData,OMX_IndexParamVideoPortFormat) != true) {
    594                         return OMX_ErrorUnsupportedSetting;
    595                     }
    596 
    597                     DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d\n",
    598                             portFmt->eColorFormat);
    599                     update_profile_level(); //framerate
    600 
    601 #ifdef _ANDROID_ICS_
    602                     if (portFmt->eColorFormat ==
    603                             (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FormatAndroidOpaque) {
    604                         m_sInPortFormat.eColorFormat = (OMX_COLOR_FORMATTYPE)
    605                             QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
    606                         if (!mUseProxyColorFormat) {
    607                             if (!c2d_conv.init()) {
    608                                 DEBUG_PRINT_ERROR("\n C2D init failed");
    609                                 return OMX_ErrorUnsupportedSetting;
    610                             }
    611                             DEBUG_PRINT_ERROR("\nC2D init is successful");
    612                         }
    613                         mUseProxyColorFormat = true;
    614                         m_input_msg_id = OMX_COMPONENT_GENERATE_ETB_OPQ;
    615                     } else
    616 #endif
    617                     {
    618                         m_sInPortFormat.eColorFormat = portFmt->eColorFormat;
    619                         m_input_msg_id = OMX_COMPONENT_GENERATE_ETB;
    620                         mUseProxyColorFormat = false;
    621                     }
    622                     m_sInPortFormat.xFramerate = portFmt->xFramerate;
    623                 }
    624                 //TODO if no use case for O/P port,delet m_sOutPortFormat
    625             }
    626             break;
    627         case OMX_IndexParamVideoInit:
    628             { //TODO, do we need this index set param
    629                 OMX_PORT_PARAM_TYPE* pParam = (OMX_PORT_PARAM_TYPE*)(paramData);
    630                 DEBUG_PRINT_LOW("\n Set OMX_IndexParamVideoInit called");
    631                 break;
    632             }
    633 
    634         case OMX_IndexParamVideoBitrate:
    635             {
    636                 OMX_VIDEO_PARAM_BITRATETYPE* pParam = (OMX_VIDEO_PARAM_BITRATETYPE*)paramData;
    637                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoBitrate");
    638                 if (handle->venc_set_param(paramData,OMX_IndexParamVideoBitrate) != true) {
    639                     return OMX_ErrorUnsupportedSetting;
    640                 }
    641                 m_sParamBitrate.nTargetBitrate = pParam->nTargetBitrate;
    642                 m_sParamBitrate.eControlRate = pParam->eControlRate;
    643                 update_profile_level(); //bitrate
    644                 m_sConfigBitrate.nEncodeBitrate = pParam->nTargetBitrate;
    645                 m_sInPortDef.format.video.nBitrate = pParam->nTargetBitrate;
    646                 m_sOutPortDef.format.video.nBitrate = pParam->nTargetBitrate;
    647                 DEBUG_PRINT_LOW("\nbitrate = %u", m_sOutPortDef.format.video.nBitrate);
    648                 break;
    649             }
    650         case OMX_IndexParamVideoMpeg4:
    651             {
    652                 OMX_VIDEO_PARAM_MPEG4TYPE* pParam = (OMX_VIDEO_PARAM_MPEG4TYPE*)paramData;
    653                 OMX_VIDEO_PARAM_MPEG4TYPE mp4_param;
    654                 memcpy(&mp4_param, pParam, sizeof(struct OMX_VIDEO_PARAM_MPEG4TYPE));
    655                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4");
    656                 if (pParam->eProfile == OMX_VIDEO_MPEG4ProfileAdvancedSimple) {
    657 #ifdef MAX_RES_1080P
    658                     if (pParam->nBFrames) {
    659                         DEBUG_PRINT_HIGH("INFO: Only 1 Bframe is supported");
    660                         mp4_param.nBFrames = 1;
    661                     }
    662 #else
    663                     if (pParam->nBFrames) {
    664                         DEBUG_PRINT_ERROR("Warning: B frames not supported\n");
    665                         mp4_param.nBFrames = 0;
    666                     }
    667 #endif
    668                 } else {
    669                     if (pParam->nBFrames) {
    670                         DEBUG_PRINT_ERROR("Warning: B frames not supported\n");
    671                         mp4_param.nBFrames = 0;
    672                     }
    673                 }
    674                 if (handle->venc_set_param(&mp4_param,OMX_IndexParamVideoMpeg4) != true) {
    675                     return OMX_ErrorUnsupportedSetting;
    676                 }
    677                 memcpy(&m_sParamMPEG4,pParam, sizeof(struct OMX_VIDEO_PARAM_MPEG4TYPE));
    678                 m_sIntraperiod.nPFrames = m_sParamMPEG4.nPFrames;
    679                 m_sIntraperiod.nBFrames = m_sParamMPEG4.nBFrames;
    680                 break;
    681             }
    682         case OMX_IndexParamVideoH263:
    683             {
    684                 OMX_VIDEO_PARAM_H263TYPE* pParam = (OMX_VIDEO_PARAM_H263TYPE*)paramData;
    685                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263");
    686                 if (handle->venc_set_param(paramData,OMX_IndexParamVideoH263) != true) {
    687                     return OMX_ErrorUnsupportedSetting;
    688                 }
    689                 memcpy(&m_sParamH263,pParam, sizeof(struct OMX_VIDEO_PARAM_H263TYPE));
    690                 m_sIntraperiod.nPFrames = m_sParamH263.nPFrames;
    691                 m_sIntraperiod.nBFrames = m_sParamH263.nBFrames;
    692                 break;
    693             }
    694         case OMX_IndexParamVideoAvc:
    695             {
    696                 OMX_VIDEO_PARAM_AVCTYPE* pParam = (OMX_VIDEO_PARAM_AVCTYPE*)paramData;
    697                 OMX_VIDEO_PARAM_AVCTYPE avc_param;
    698                 memcpy(&avc_param, pParam, sizeof( struct OMX_VIDEO_PARAM_AVCTYPE));
    699                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc");
    700 
    701                 if ((pParam->eProfile == OMX_VIDEO_AVCProfileHigh)||
    702                         (pParam->eProfile == OMX_VIDEO_AVCProfileMain)) {
    703 #ifdef MAX_RES_1080P
    704                     if (pParam->nBFrames) {
    705                         DEBUG_PRINT_HIGH("INFO: Only 1 Bframe is supported");
    706                         avc_param.nBFrames = 1;
    707                     }
    708                     if (pParam->nRefFrames != 2) {
    709                         DEBUG_PRINT_ERROR("Warning: 2 RefFrames are needed, changing RefFrames from %lu to 2", pParam->nRefFrames);
    710                         avc_param.nRefFrames = 2;
    711                     }
    712 #else
    713                     if (pParam->nBFrames) {
    714                         DEBUG_PRINT_ERROR("Warning: B frames not supported\n");
    715                         avc_param.nBFrames = 0;
    716                     }
    717                     if (pParam->nRefFrames != 1) {
    718                         DEBUG_PRINT_ERROR("Warning: Only 1 RefFrame is supported, changing RefFrame from %lu to 1)", pParam->nRefFrames);
    719                         avc_param.nRefFrames = 1;
    720                     }
    721 #endif
    722                 } else {
    723                     if (pParam->nRefFrames != 1) {
    724                         DEBUG_PRINT_ERROR("Warning: Only 1 RefFrame is supported, changing RefFrame from %lu to 1)", pParam->nRefFrames);
    725                         avc_param.nRefFrames = 1;
    726                     }
    727                     if (pParam->nBFrames) {
    728                         DEBUG_PRINT_ERROR("Warning: B frames not supported\n");
    729                         avc_param.nBFrames = 0;
    730                     }
    731                 }
    732                 if (handle->venc_set_param(&avc_param,OMX_IndexParamVideoAvc) != true) {
    733                     return OMX_ErrorUnsupportedSetting;
    734                 }
    735                 memcpy(&m_sParamAVC,pParam, sizeof(struct OMX_VIDEO_PARAM_AVCTYPE));
    736                 m_sIntraperiod.nPFrames = m_sParamAVC.nPFrames;
    737                 m_sIntraperiod.nBFrames = m_sParamAVC.nBFrames;
    738                 break;
    739             }
    740         case (OMX_INDEXTYPE)OMX_IndexParamVideoVp8:
    741             {
    742                 OMX_VIDEO_PARAM_VP8TYPE* pParam = (OMX_VIDEO_PARAM_VP8TYPE*)paramData;
    743                 OMX_VIDEO_PARAM_VP8TYPE vp8_param;
    744                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoVp8");
    745                 if (pParam->nDCTPartitions != m_sParamVP8.nDCTPartitions ||
    746                     pParam->bErrorResilientMode != m_sParamVP8.bErrorResilientMode) {
    747                     DEBUG_PRINT_ERROR("VP8 doesn't support nDCTPartitions or bErrorResilientMode");
    748                 }
    749                 memcpy(&vp8_param, pParam, sizeof( struct OMX_VIDEO_PARAM_VP8TYPE));
    750                 if (handle->venc_set_param(&vp8_param, (OMX_INDEXTYPE)OMX_IndexParamVideoVp8) != true) {
    751                     return OMX_ErrorUnsupportedSetting;
    752                 }
    753                 memcpy(&m_sParamVP8,pParam, sizeof(struct OMX_VIDEO_PARAM_VP8TYPE));
    754                 break;
    755             }
    756         case OMX_IndexParamVideoProfileLevelCurrent:
    757             {
    758                 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
    759                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoProfileLevelCurrent");
    760                 if (handle->venc_set_param(pParam,OMX_IndexParamVideoProfileLevelCurrent) != true) {
    761                     DEBUG_PRINT_ERROR("set_parameter: OMX_IndexParamVideoProfileLevelCurrent failed for Profile: %lu "
    762                             "Level :%lu", pParam->eProfile, pParam->eLevel);
    763                     return OMX_ErrorUnsupportedSetting;
    764                 }
    765                 m_sParamProfileLevel.eProfile = pParam->eProfile;
    766                 m_sParamProfileLevel.eLevel = pParam->eLevel;
    767 
    768                 if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.mpeg4",\
    769                             OMX_MAX_STRINGNAME_SIZE)) {
    770                     m_sParamMPEG4.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)m_sParamProfileLevel.eProfile;
    771                     m_sParamMPEG4.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)m_sParamProfileLevel.eLevel;
    772                     DEBUG_PRINT_LOW("\n MPEG4 profile = %d, level = %d", m_sParamMPEG4.eProfile,
    773                             m_sParamMPEG4.eLevel);
    774                 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\
    775                             OMX_MAX_STRINGNAME_SIZE)) {
    776                     m_sParamH263.eProfile = (OMX_VIDEO_H263PROFILETYPE)m_sParamProfileLevel.eProfile;
    777                     m_sParamH263.eLevel = (OMX_VIDEO_H263LEVELTYPE)m_sParamProfileLevel.eLevel;
    778                     DEBUG_PRINT_LOW("\n H263 profile = %d, level = %d", m_sParamH263.eProfile,
    779                             m_sParamH263.eLevel);
    780                 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
    781                             OMX_MAX_STRINGNAME_SIZE)) {
    782                     m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)m_sParamProfileLevel.eProfile;
    783                     m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel;
    784                     DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
    785                             m_sParamAVC.eLevel);
    786                 }
    787                 else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.vp8",\
    788                             OMX_MAX_STRINGNAME_SIZE)) {
    789                     m_sParamVP8.eProfile = (OMX_VIDEO_VP8PROFILETYPE)m_sParamProfileLevel.eProfile;
    790                     m_sParamVP8.eLevel = (OMX_VIDEO_VP8LEVELTYPE)m_sParamProfileLevel.eLevel;
    791                     DEBUG_PRINT_LOW("\n VP8 profile = %d, level = %d", m_sParamVP8.eProfile,
    792                             m_sParamVP8.eLevel);
    793                 }
    794                 break;
    795             }
    796         case OMX_IndexParamStandardComponentRole:
    797             {
    798                 OMX_PARAM_COMPONENTROLETYPE *comp_role;
    799                 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
    800                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s\n",
    801                         comp_role->cRole);
    802 
    803                 if ((m_state == OMX_StateLoaded)&&
    804                         !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
    805                     DEBUG_PRINT_LOW("Set Parameter called in valid state");
    806                 } else {
    807                     DEBUG_PRINT_ERROR("Set Parameter called in Invalid State\n");
    808                     return OMX_ErrorIncorrectStateOperation;
    809                 }
    810 
    811                 if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
    812                     if (!strncmp((char*)comp_role->cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
    813                         strlcpy((char*)m_cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
    814                     } else {
    815                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
    816                         eRet =OMX_ErrorUnsupportedSetting;
    817                     }
    818                 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
    819                     if (!strncmp((const char*)comp_role->cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
    820                         strlcpy((char*)m_cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
    821                     } else {
    822                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
    823                         eRet = OMX_ErrorUnsupportedSetting;
    824                     }
    825                 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
    826                     if (!strncmp((const char*)comp_role->cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
    827                         strlcpy((char*)m_cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE);
    828                     } else {
    829                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
    830                         eRet =OMX_ErrorUnsupportedSetting;
    831                     }
    832                 }
    833 #ifdef _MSM8974_
    834                 else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
    835                     if (!strncmp((const char*)comp_role->cRole,"video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
    836                         strlcpy((char*)m_cRole,"video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE);
    837                     } else {
    838                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
    839                         eRet =OMX_ErrorUnsupportedSetting;
    840                     }
    841                 }
    842 #endif
    843                 else {
    844                     DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %s\n", m_nkind);
    845                     eRet = OMX_ErrorInvalidComponentName;
    846                 }
    847                 break;
    848             }
    849 
    850         case OMX_IndexParamPriorityMgmt:
    851             {
    852                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt");
    853                 if (m_state != OMX_StateLoaded) {
    854                     DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State\n");
    855                     return OMX_ErrorIncorrectStateOperation;
    856                 }
    857                 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData;
    858                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %d\n",
    859                         priorityMgmtype->nGroupID);
    860 
    861                 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %d\n",
    862                         priorityMgmtype->nGroupPriority);
    863 
    864                 m_sPriorityMgmt.nGroupID = priorityMgmtype->nGroupID;
    865                 m_sPriorityMgmt.nGroupPriority = priorityMgmtype->nGroupPriority;
    866 
    867                 break;
    868             }
    869 
    870         case OMX_IndexParamCompBufferSupplier:
    871             {
    872                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier");
    873                 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
    874                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d\n",
    875                         bufferSupplierType->eBufferSupplier);
    876                 if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1)
    877                     m_sInBufSupplier.eBufferSupplier = bufferSupplierType->eBufferSupplier;
    878 
    879                 else
    880 
    881                     eRet = OMX_ErrorBadPortIndex;
    882 
    883                 break;
    884 
    885             }
    886         case OMX_IndexParamVideoQuantization:
    887             {
    888                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoQuantization\n");
    889                 OMX_VIDEO_PARAM_QUANTIZATIONTYPE *session_qp = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) paramData;
    890                 if (session_qp->nPortIndex == PORT_INDEX_OUT) {
    891                     if (handle->venc_set_param(paramData, OMX_IndexParamVideoQuantization) != true) {
    892                         return OMX_ErrorUnsupportedSetting;
    893                     }
    894                     m_sSessionQuantization.nQpI = session_qp->nQpI;
    895                     m_sSessionQuantization.nQpP = session_qp->nQpP;
    896                 } else {
    897                     DEBUG_PRINT_ERROR("\nERROR: Unsupported port Index for Session QP setting\n");
    898                     eRet = OMX_ErrorBadPortIndex;
    899                 }
    900                 break;
    901             }
    902 
    903         case OMX_QcomIndexParamVideoQPRange:
    904             {
    905                 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoQPRange\n");
    906                 OMX_QCOM_VIDEO_PARAM_QPRANGETYPE *qp_range = (OMX_QCOM_VIDEO_PARAM_QPRANGETYPE*) paramData;
    907                 if (qp_range->nPortIndex == PORT_INDEX_OUT) {
    908                     if (handle->venc_set_param(paramData,
    909                                 (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPRange) != true) {
    910                         return OMX_ErrorUnsupportedSetting;
    911                     }
    912                     m_sSessionQPRange.minQP= qp_range->minQP;
    913                     m_sSessionQPRange.maxQP= qp_range->maxQP;
    914                 } else {
    915                     DEBUG_PRINT_ERROR("\nERROR: Unsupported port Index for QP range setting\n");
    916                     eRet = OMX_ErrorBadPortIndex;
    917                 }
    918                 break;
    919             }
    920 
    921         case OMX_QcomIndexPortDefn:
    922             {
    923                 OMX_QCOM_PARAM_PORTDEFINITIONTYPE* pParam =
    924                     (OMX_QCOM_PARAM_PORTDEFINITIONTYPE*)paramData;
    925                 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexPortDefn");
    926                 if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_IN) {
    927                     if (pParam->nMemRegion > OMX_QCOM_MemRegionInvalid &&
    928                             pParam->nMemRegion < OMX_QCOM_MemRegionMax) {
    929                         m_use_input_pmem = OMX_TRUE;
    930                     } else {
    931                         m_use_input_pmem = OMX_FALSE;
    932                     }
    933                 } else if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_OUT) {
    934                     if (pParam->nMemRegion > OMX_QCOM_MemRegionInvalid &&
    935                             pParam->nMemRegion < OMX_QCOM_MemRegionMax) {
    936                         m_use_output_pmem = OMX_TRUE;
    937                     } else {
    938                         m_use_output_pmem = OMX_FALSE;
    939                     }
    940                 } else {
    941                     DEBUG_PRINT_ERROR("ERROR: SetParameter called on unsupported Port Index for QcomPortDefn");
    942                     return OMX_ErrorBadPortIndex;
    943                 }
    944                 break;
    945             }
    946 
    947         case OMX_IndexParamVideoErrorCorrection:
    948             {
    949                 DEBUG_PRINT_LOW("OMX_IndexParamVideoErrorCorrection\n");
    950                 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pParam =
    951                     (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)paramData;
    952                 if (!handle->venc_set_param(paramData, OMX_IndexParamVideoErrorCorrection)) {
    953                     DEBUG_PRINT_ERROR("\nERROR: Request for setting Error Resilience failed");
    954                     return OMX_ErrorUnsupportedSetting;
    955                 }
    956                 memcpy(&m_sErrorCorrection,pParam, sizeof(m_sErrorCorrection));
    957                 break;
    958             }
    959         case OMX_IndexParamVideoIntraRefresh:
    960             {
    961                 DEBUG_PRINT_LOW("set_param:OMX_IndexParamVideoIntraRefresh\n");
    962                 OMX_VIDEO_PARAM_INTRAREFRESHTYPE* pParam =
    963                     (OMX_VIDEO_PARAM_INTRAREFRESHTYPE*)paramData;
    964                 if (!handle->venc_set_param(paramData,OMX_IndexParamVideoIntraRefresh)) {
    965                     DEBUG_PRINT_ERROR("\nERROR: Request for setting intra refresh failed");
    966                     return OMX_ErrorUnsupportedSetting;
    967                 }
    968                 memcpy(&m_sIntraRefresh, pParam, sizeof(m_sIntraRefresh));
    969                 break;
    970             }
    971 #ifdef _ANDROID_ICS_
    972         case OMX_QcomIndexParamVideoMetaBufferMode:
    973             {
    974                 StoreMetaDataInBuffersParams *pParam =
    975                     (StoreMetaDataInBuffersParams*)paramData;
    976                 DEBUG_PRINT_HIGH("set_parameter:OMX_QcomIndexParamVideoMetaBufferMode: "
    977                         "port_index = %lu, meta_mode = %d", pParam->nPortIndex, pParam->bStoreMetaData);
    978                 if (pParam->nPortIndex == PORT_INDEX_IN) {
    979                     if (pParam->bStoreMetaData != meta_mode_enable) {
    980                         if (!handle->venc_set_meta_mode(pParam->bStoreMetaData)) {
    981                             DEBUG_PRINT_ERROR("\nERROR: set Metabuffer mode %d fail",
    982                                     pParam->bStoreMetaData);
    983                             return OMX_ErrorUnsupportedSetting;
    984                         }
    985                         meta_mode_enable = pParam->bStoreMetaData;
    986                         if (meta_mode_enable) {
    987                             m_sInPortDef.nBufferCountActual = m_sInPortDef.nBufferCountMin;
    988                             if (handle->venc_set_param(&m_sInPortDef,OMX_IndexParamPortDefinition) != true) {
    989                                 DEBUG_PRINT_ERROR("\nERROR: venc_set_param input failed");
    990                                 return OMX_ErrorUnsupportedSetting;
    991                             }
    992                         } else {
    993                             /*TODO: reset encoder driver Meta mode*/
    994                             dev_get_buf_req   (&m_sOutPortDef.nBufferCountMin,
    995                                     &m_sOutPortDef.nBufferCountActual,
    996                                     &m_sOutPortDef.nBufferSize,
    997                                     m_sOutPortDef.nPortIndex);
    998                         }
    999                     }
   1000                 } else {
   1001                     DEBUG_PRINT_ERROR("set_parameter: metamode is "
   1002                             "valid for input port only");
   1003                     eRet = OMX_ErrorUnsupportedIndex;
   1004                 }
   1005             }
   1006             break;
   1007 #endif
   1008 #if !defined(MAX_RES_720P) || defined(_MSM8974_)
   1009         case OMX_QcomIndexParamIndexExtraDataType:
   1010             {
   1011                 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType");
   1012                 QOMX_INDEXEXTRADATATYPE *pParam = (QOMX_INDEXEXTRADATATYPE *)paramData;
   1013                 if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderSliceInfo) {
   1014                     if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1015                         if (pParam->bEnabled == OMX_TRUE)
   1016                             m_sExtraData |= VEN_EXTRADATA_SLICEINFO;
   1017                         else
   1018                             m_sExtraData &= ~VEN_EXTRADATA_SLICEINFO;
   1019                         DEBUG_PRINT_HIGH("SliceInfo extradata %s",
   1020                                 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
   1021                         if (handle->venc_set_param(&m_sExtraData,
   1022                                     (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderSliceInfo) != true) {
   1023                             DEBUG_PRINT_ERROR("ERROR: Setting "
   1024                                     "OMX_ExtraDataVideoEncoderSliceInfo failed");
   1025                             return OMX_ErrorUnsupportedSetting;
   1026                         } else {
   1027                             m_sOutPortDef.nPortIndex = PORT_INDEX_OUT;
   1028                             dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
   1029                                     &m_sOutPortDef.nBufferCountActual,
   1030                                     &m_sOutPortDef.nBufferSize,
   1031                                     m_sOutPortDef.nPortIndex);
   1032                             DEBUG_PRINT_HIGH("updated out_buf_req: buffer cnt=%lu, "
   1033                                     "count min=%lu, buffer size=%lu",
   1034                                     m_sOutPortDef.nBufferCountActual,
   1035                                     m_sOutPortDef.nBufferCountMin,
   1036                                     m_sOutPortDef.nBufferSize);
   1037                         }
   1038                     }
   1039                 }
   1040 #ifndef _MSM8974_
   1041                 else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoLTRInfo) {
   1042                     if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1043                         if (pParam->bEnabled == OMX_TRUE)
   1044                             m_sExtraData |= VEN_EXTRADATA_LTRINFO;
   1045                         else
   1046                             m_sExtraData &= ~VEN_EXTRADATA_LTRINFO;
   1047                         DEBUG_PRINT_HIGH("LTRInfo extradata %s",
   1048                                 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
   1049                         if (handle->venc_set_param(&m_sExtraData,
   1050                                     (OMX_INDEXTYPE)OMX_ExtraDataVideoLTRInfo) != true) {
   1051                             DEBUG_PRINT_ERROR("ERROR: Setting "
   1052                                     "OMX_ExtraDataVideoLTRInfo failed");
   1053                             return OMX_ErrorUnsupportedSetting;
   1054                         } else {
   1055                             m_sOutPortDef.nPortIndex = PORT_INDEX_OUT;
   1056                             dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
   1057                                     &m_sOutPortDef.nBufferCountActual,
   1058                                     &m_sOutPortDef.nBufferSize,
   1059                                     m_sOutPortDef.nPortIndex);
   1060                             DEBUG_PRINT_HIGH("updated out_buf_req: buffer cnt=%d, "
   1061                                     "count min=%d, buffer size=%d",
   1062                                     m_sOutPortDef.nBufferCountActual,
   1063                                     m_sOutPortDef.nBufferCountMin,
   1064                                     m_sOutPortDef.nBufferSize);
   1065                         }
   1066                     } else {
   1067                         DEBUG_PRINT_ERROR("set_parameter: LTR information is "
   1068                                 "valid for output port only");
   1069                         eRet = OMX_ErrorUnsupportedIndex;
   1070                     }
   1071                 }
   1072 #endif
   1073                 else {
   1074                     DEBUG_PRINT_ERROR("set_parameter: unsupported extrdata index (%x)",
   1075                             pParam->nIndex);
   1076                     eRet = OMX_ErrorUnsupportedIndex;
   1077                 }
   1078                 break;
   1079             }
   1080         case QOMX_IndexParamVideoLTRMode:
   1081             {
   1082                 QOMX_VIDEO_PARAM_LTRMODE_TYPE* pParam =
   1083                     (QOMX_VIDEO_PARAM_LTRMODE_TYPE*)paramData;
   1084                 if (!handle->venc_set_param(paramData, (OMX_INDEXTYPE)QOMX_IndexParamVideoLTRMode)) {
   1085                     DEBUG_PRINT_ERROR("\nERROR: Setting LTR mode failed");
   1086                     return OMX_ErrorUnsupportedSetting;
   1087                 }
   1088                 memcpy(&m_sParamLTRMode, pParam, sizeof(m_sParamLTRMode));
   1089                 break;
   1090             }
   1091         case QOMX_IndexParamVideoLTRCount:
   1092             {
   1093                 QOMX_VIDEO_PARAM_LTRCOUNT_TYPE* pParam =
   1094                     (QOMX_VIDEO_PARAM_LTRCOUNT_TYPE*)paramData;
   1095                 if (!handle->venc_set_param(paramData, (OMX_INDEXTYPE)QOMX_IndexParamVideoLTRCount)) {
   1096                     DEBUG_PRINT_ERROR("\nERROR: Setting LTR count failed");
   1097                     return OMX_ErrorUnsupportedSetting;
   1098                 }
   1099                 memcpy(&m_sParamLTRCount, pParam, sizeof(m_sParamLTRCount));
   1100                 break;
   1101             }
   1102 #endif
   1103         case OMX_QcomIndexParamVideoMaxAllowedBitrateCheck:
   1104             {
   1105                 QOMX_EXTNINDEX_PARAMTYPE* pParam =
   1106                     (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
   1107                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1108                     handle->m_max_allowed_bitrate_check =
   1109                         ((pParam->bEnable == OMX_TRUE) ? true : false);
   1110                     DEBUG_PRINT_HIGH("set_parameter: max allowed bitrate check %s",
   1111                             ((pParam->bEnable == OMX_TRUE) ? "enabled" : "disabled"));
   1112                 } else {
   1113                     DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexParamVideoMaxAllowedBitrateCheck "
   1114                             " called on wrong port(%lu)", pParam->nPortIndex);
   1115                     return OMX_ErrorBadPortIndex;
   1116                 }
   1117                 break;
   1118             }
   1119 #ifdef MAX_RES_1080P
   1120         case OMX_QcomIndexEnableSliceDeliveryMode:
   1121             {
   1122                 QOMX_EXTNINDEX_PARAMTYPE* pParam =
   1123                     (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
   1124                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1125                     if (!handle->venc_set_param(paramData,
   1126                                 (OMX_INDEXTYPE)OMX_QcomIndexEnableSliceDeliveryMode)) {
   1127                         DEBUG_PRINT_ERROR("ERROR: Request for setting slice delivery mode failed");
   1128                         return OMX_ErrorUnsupportedSetting;
   1129                     }
   1130                 } else {
   1131                     DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexEnableSliceDeliveryMode "
   1132                             "called on wrong port(%lu)", pParam->nPortIndex);
   1133                     return OMX_ErrorBadPortIndex;
   1134                 }
   1135                 break;
   1136             }
   1137 #endif
   1138         case OMX_QcomIndexEnableH263PlusPType:
   1139             {
   1140                 QOMX_EXTNINDEX_PARAMTYPE* pParam =
   1141                     (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
   1142                 DEBUG_PRINT_LOW("OMX_QcomIndexEnableH263PlusPType");
   1143                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1144                     if (!handle->venc_set_param(paramData,
   1145                                 (OMX_INDEXTYPE)OMX_QcomIndexEnableH263PlusPType)) {
   1146                         DEBUG_PRINT_ERROR("ERROR: Request for setting PlusPType failed");
   1147                         return OMX_ErrorUnsupportedSetting;
   1148                     }
   1149                 } else {
   1150                     DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexEnableH263PlusPType "
   1151                             "called on wrong port(%lu)", pParam->nPortIndex);
   1152                     return OMX_ErrorBadPortIndex;
   1153                 }
   1154                 break;
   1155             }
   1156         case OMX_IndexParamVideoSliceFMO:
   1157         default:
   1158             {
   1159                 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %d\n", paramIndex);
   1160                 eRet = OMX_ErrorUnsupportedIndex;
   1161                 break;
   1162             }
   1163     }
   1164     return eRet;
   1165 }
   1166 
   1167 bool omx_venc::update_profile_level()
   1168 {
   1169     OMX_U32 eProfile, eLevel;
   1170 
   1171     if (!handle->venc_get_profile_level(&eProfile,&eLevel)) {
   1172         DEBUG_PRINT_ERROR("\nFailed to update the profile_level\n");
   1173         return false;
   1174     }
   1175 
   1176     m_sParamProfileLevel.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)eProfile;
   1177     m_sParamProfileLevel.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)eLevel;
   1178 
   1179     if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.mpeg4",\
   1180                 OMX_MAX_STRINGNAME_SIZE)) {
   1181         m_sParamMPEG4.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)eProfile;
   1182         m_sParamMPEG4.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)eLevel;
   1183         DEBUG_PRINT_LOW("\n MPEG4 profile = %d, level = %d", m_sParamMPEG4.eProfile,
   1184                 m_sParamMPEG4.eLevel);
   1185     } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\
   1186                 OMX_MAX_STRINGNAME_SIZE)) {
   1187         m_sParamH263.eProfile = (OMX_VIDEO_H263PROFILETYPE)eProfile;
   1188         m_sParamH263.eLevel = (OMX_VIDEO_H263LEVELTYPE)eLevel;
   1189         DEBUG_PRINT_LOW("\n H263 profile = %d, level = %d", m_sParamH263.eProfile,
   1190                 m_sParamH263.eLevel);
   1191     } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
   1192                 OMX_MAX_STRINGNAME_SIZE)) {
   1193         m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)eProfile;
   1194         m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
   1195         DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
   1196                 m_sParamAVC.eLevel);
   1197     }
   1198     else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.vp8",\
   1199                 OMX_MAX_STRINGNAME_SIZE)) {
   1200         m_sParamVP8.eProfile = (OMX_VIDEO_VP8PROFILETYPE)eProfile;
   1201         m_sParamVP8.eLevel = (OMX_VIDEO_VP8LEVELTYPE)eLevel;
   1202         DEBUG_PRINT_LOW("\n VP8 profile = %d, level = %d", m_sParamVP8.eProfile,
   1203                 m_sParamVP8.eLevel);
   1204     }
   1205     return true;
   1206 }
   1207 /* ======================================================================
   1208    FUNCTION
   1209    omx_video::SetConfig
   1210 
   1211    DESCRIPTION
   1212    OMX Set Config method implementation
   1213 
   1214    PARAMETERS
   1215    <TBD>.
   1216 
   1217    RETURN VALUE
   1218    OMX Error None if successful.
   1219    ========================================================================== */
   1220 OMX_ERRORTYPE  omx_venc::set_config(OMX_IN OMX_HANDLETYPE      hComp,
   1221         OMX_IN OMX_INDEXTYPE configIndex,
   1222         OMX_IN OMX_PTR        configData)
   1223 {
   1224     if (configData == NULL) {
   1225         DEBUG_PRINT_ERROR("ERROR: param is null");
   1226         return OMX_ErrorBadParameter;
   1227     }
   1228 
   1229     if (m_state == OMX_StateInvalid) {
   1230         DEBUG_PRINT_ERROR("ERROR: config called in Invalid state");
   1231         return OMX_ErrorIncorrectStateOperation;
   1232     }
   1233 
   1234     // params will be validated prior to venc_init
   1235     switch (configIndex) {
   1236         case OMX_IndexConfigVideoBitrate:
   1237             {
   1238                 OMX_VIDEO_CONFIG_BITRATETYPE* pParam =
   1239                     reinterpret_cast<OMX_VIDEO_CONFIG_BITRATETYPE*>(configData);
   1240                 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoBitrate (%lu)", pParam->nEncodeBitrate);
   1241 
   1242                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1243                     if (handle->venc_set_config(configData, OMX_IndexConfigVideoBitrate) != true) {
   1244                         DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoBitrate failed");
   1245                         return OMX_ErrorUnsupportedSetting;
   1246                     }
   1247 
   1248                     m_sConfigBitrate.nEncodeBitrate = pParam->nEncodeBitrate;
   1249                     m_sParamBitrate.nTargetBitrate = pParam->nEncodeBitrate;
   1250                     m_sOutPortDef.format.video.nBitrate = pParam->nEncodeBitrate;
   1251                 } else {
   1252                     DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %lu", pParam->nPortIndex);
   1253                     return OMX_ErrorBadPortIndex;
   1254                 }
   1255                 break;
   1256             }
   1257         case OMX_IndexConfigVideoFramerate:
   1258             {
   1259                 OMX_CONFIG_FRAMERATETYPE* pParam =
   1260                     reinterpret_cast<OMX_CONFIG_FRAMERATETYPE*>(configData);
   1261                 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoFramerate (0x%lx)", pParam->xEncodeFramerate);
   1262 
   1263                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1264                     if (handle->venc_set_config(configData, OMX_IndexConfigVideoFramerate) != true) {
   1265                         DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoFramerate failed");
   1266                         return OMX_ErrorUnsupportedSetting;
   1267                     }
   1268 
   1269                     m_sConfigFramerate.xEncodeFramerate = pParam->xEncodeFramerate;
   1270                     m_sOutPortDef.format.video.xFramerate = pParam->xEncodeFramerate;
   1271                     m_sOutPortFormat.xFramerate = pParam->xEncodeFramerate;
   1272                 } else {
   1273                     DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %lu", pParam->nPortIndex);
   1274                     return OMX_ErrorBadPortIndex;
   1275                 }
   1276 
   1277                 break;
   1278             }
   1279         case QOMX_IndexConfigVideoIntraperiod:
   1280             {
   1281                 QOMX_VIDEO_INTRAPERIODTYPE* pParam =
   1282                     reinterpret_cast<QOMX_VIDEO_INTRAPERIODTYPE*>(configData);
   1283 
   1284                 DEBUG_PRINT_HIGH("set_config(): QOMX_IndexConfigVideoIntraperiod");
   1285                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1286 #ifdef MAX_RES_720P
   1287                     if (pParam->nBFrames > 0) {
   1288                         DEBUG_PRINT_ERROR("B frames not supported\n");
   1289                         return OMX_ErrorUnsupportedSetting;
   1290                     }
   1291 #endif
   1292                     DEBUG_PRINT_HIGH("Old: P/B frames = %lu/%lu, New: P/B frames = %lu/%lu",
   1293                             m_sIntraperiod.nPFrames, m_sIntraperiod.nBFrames,
   1294                             pParam->nPFrames, pParam->nBFrames);
   1295                     if (m_sIntraperiod.nBFrames != pParam->nBFrames) {
   1296                         DEBUG_PRINT_HIGH("Dynamically changing B-frames not supported");
   1297                         return OMX_ErrorUnsupportedSetting;
   1298                     }
   1299                     if (handle->venc_set_config(configData, (OMX_INDEXTYPE) QOMX_IndexConfigVideoIntraperiod) != true) {
   1300                         DEBUG_PRINT_ERROR("ERROR: Setting QOMX_IndexConfigVideoIntraperiod failed");
   1301                         return OMX_ErrorUnsupportedSetting;
   1302                     }
   1303                     m_sIntraperiod.nPFrames = pParam->nPFrames;
   1304                     m_sIntraperiod.nBFrames = pParam->nBFrames;
   1305                     m_sIntraperiod.nIDRPeriod = pParam->nIDRPeriod;
   1306 
   1307                     if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
   1308                         m_sParamMPEG4.nPFrames = pParam->nPFrames;
   1309                         if (m_sParamMPEG4.eProfile != OMX_VIDEO_MPEG4ProfileSimple)
   1310                             m_sParamMPEG4.nBFrames = pParam->nBFrames;
   1311                         else
   1312                             m_sParamMPEG4.nBFrames = 0;
   1313                     } else if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingH263) {
   1314                         m_sParamH263.nPFrames = pParam->nPFrames;
   1315                     } else {
   1316                         m_sParamAVC.nPFrames = pParam->nPFrames;
   1317                         if (m_sParamAVC.eProfile != OMX_VIDEO_AVCProfileBaseline)
   1318                             m_sParamAVC.nBFrames = pParam->nBFrames;
   1319                         else
   1320                             m_sParamAVC.nBFrames = 0;
   1321                     }
   1322                 } else {
   1323                     DEBUG_PRINT_ERROR("ERROR: (QOMX_IndexConfigVideoIntraperiod) Unsupported port index: %lu", pParam->nPortIndex);
   1324                     return OMX_ErrorBadPortIndex;
   1325                 }
   1326 
   1327                 break;
   1328             }
   1329 
   1330         case OMX_IndexConfigVideoIntraVOPRefresh:
   1331             {
   1332                 OMX_CONFIG_INTRAREFRESHVOPTYPE* pParam =
   1333                     reinterpret_cast<OMX_CONFIG_INTRAREFRESHVOPTYPE*>(configData);
   1334 
   1335                 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoIntraVOPRefresh");
   1336                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1337                     if (handle->venc_set_config(configData,
   1338                                 OMX_IndexConfigVideoIntraVOPRefresh) != true) {
   1339                         DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoIntraVOPRefresh failed");
   1340                         return OMX_ErrorUnsupportedSetting;
   1341                     }
   1342 
   1343                     m_sConfigIntraRefreshVOP.IntraRefreshVOP = pParam->IntraRefreshVOP;
   1344                 } else {
   1345                     DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %lu", pParam->nPortIndex);
   1346                     return OMX_ErrorBadPortIndex;
   1347                 }
   1348 
   1349                 break;
   1350             }
   1351         case OMX_IndexConfigCommonRotate:
   1352             {
   1353                 OMX_CONFIG_ROTATIONTYPE *pParam =
   1354                     reinterpret_cast<OMX_CONFIG_ROTATIONTYPE*>(configData);
   1355                 OMX_S32 nRotation;
   1356 
   1357                 if (pParam->nPortIndex != PORT_INDEX_IN) {
   1358                     DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %lu", pParam->nPortIndex);
   1359                     return OMX_ErrorBadPortIndex;
   1360                 }
   1361                 if ( pParam->nRotation == 0   ||
   1362                         pParam->nRotation == 90  ||
   1363                         pParam->nRotation == 180 ||
   1364                         pParam->nRotation == 270 ) {
   1365                     DEBUG_PRINT_HIGH("\nset_config: Rotation Angle %lu", pParam->nRotation);
   1366                 } else {
   1367                     DEBUG_PRINT_ERROR("ERROR: un supported Rotation %lu", pParam->nRotation);
   1368                     return OMX_ErrorUnsupportedSetting;
   1369                 }
   1370                 nRotation = pParam->nRotation - m_sConfigFrameRotation.nRotation;
   1371                 if (nRotation < 0)
   1372                     nRotation = -nRotation;
   1373                 if (nRotation == 90 || nRotation == 270) {
   1374                     DEBUG_PRINT_HIGH("\nset_config: updating device Dims");
   1375                     if (handle->venc_set_config(configData,
   1376                                 OMX_IndexConfigCommonRotate) != true) {
   1377                         DEBUG_PRINT_ERROR("ERROR: Set OMX_IndexConfigCommonRotate failed");
   1378                         return OMX_ErrorUnsupportedSetting;
   1379                     } else {
   1380                         OMX_U32 nFrameWidth;
   1381 
   1382                         DEBUG_PRINT_HIGH("\nset_config: updating port Dims");
   1383 
   1384                         nFrameWidth = m_sInPortDef.format.video.nFrameWidth;
   1385                         m_sInPortDef.format.video.nFrameWidth =
   1386                             m_sInPortDef.format.video.nFrameHeight;
   1387                         m_sInPortDef.format.video.nFrameHeight = nFrameWidth;
   1388 
   1389                         m_sOutPortDef.format.video.nFrameWidth  =
   1390                             m_sInPortDef.format.video.nFrameWidth;
   1391                         m_sOutPortDef.format.video.nFrameHeight =
   1392                             m_sInPortDef.format.video.nFrameHeight;
   1393                         m_sConfigFrameRotation.nRotation = pParam->nRotation;
   1394                     }
   1395                 } else {
   1396                     m_sConfigFrameRotation.nRotation = pParam->nRotation;
   1397                 }
   1398                 break;
   1399             }
   1400         case OMX_QcomIndexConfigVideoFramePackingArrangement:
   1401             {
   1402                 DEBUG_PRINT_HIGH("set_config(): OMX_QcomIndexConfigVideoFramePackingArrangement");
   1403                 if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   1404                     OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
   1405                         (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
   1406                     extra_data_handle.set_frame_pack_data(configFmt);
   1407                 } else {
   1408                     DEBUG_PRINT_ERROR("ERROR: FramePackingData not supported for non AVC compression");
   1409                 }
   1410                 break;
   1411             }
   1412         case QOMX_IndexConfigVideoLTRPeriod:
   1413             {
   1414                 QOMX_VIDEO_CONFIG_LTRPERIOD_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRPERIOD_TYPE*)configData;
   1415                 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRPeriod)) {
   1416                     DEBUG_PRINT_ERROR("\nERROR: Setting LTR period failed");
   1417                     return OMX_ErrorUnsupportedSetting;
   1418                 }
   1419                 memcpy(&m_sConfigLTRPeriod, pParam, sizeof(m_sConfigLTRPeriod));
   1420                 break;
   1421             }
   1422         case QOMX_IndexConfigVideoLTRUse:
   1423             {
   1424                 QOMX_VIDEO_CONFIG_LTRUSE_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRUSE_TYPE*)configData;
   1425                 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRUse)) {
   1426                     DEBUG_PRINT_ERROR("\nERROR: Setting LTR use failed");
   1427                     return OMX_ErrorUnsupportedSetting;
   1428                 }
   1429                 memcpy(&m_sConfigLTRUse, pParam, sizeof(m_sConfigLTRUse));
   1430                 break;
   1431             }
   1432         case QOMX_IndexConfigVideoLTRMark:
   1433             {
   1434                 QOMX_VIDEO_CONFIG_LTRMARK_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRMARK_TYPE*)configData;
   1435                 DEBUG_PRINT_ERROR("Setting ltr mark is not supported");
   1436                 return OMX_ErrorUnsupportedSetting;
   1437                 break;
   1438             }
   1439         case OMX_IndexConfigVideoAVCIntraPeriod:
   1440             {
   1441                 OMX_VIDEO_CONFIG_AVCINTRAPERIOD *pParam = (OMX_VIDEO_CONFIG_AVCINTRAPERIOD*) configData;
   1442                 DEBUG_PRINT_LOW("set_config: OMX_IndexConfigVideoAVCIntraPeriod");
   1443                 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_IndexConfigVideoAVCIntraPeriod)) {
   1444                     DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoAVCIntraPeriod failed");
   1445                     return OMX_ErrorUnsupportedSetting;
   1446                 }
   1447                 memcpy(&m_sConfigAVCIDRPeriod, pParam, sizeof(m_sConfigAVCIDRPeriod));
   1448                 break;
   1449             }
   1450         default:
   1451             DEBUG_PRINT_ERROR("ERROR: unsupported index %d", (int) configIndex);
   1452             break;
   1453     }
   1454 
   1455     return OMX_ErrorNone;
   1456 }
   1457 
   1458 /* ======================================================================
   1459    FUNCTION
   1460    omx_venc::ComponentDeInit
   1461 
   1462    DESCRIPTION
   1463    Destroys the component and release memory allocated to the heap.
   1464 
   1465    PARAMETERS
   1466    <TBD>.
   1467 
   1468    RETURN VALUE
   1469    OMX Error None if everything successful.
   1470 
   1471    ========================================================================== */
   1472 OMX_ERRORTYPE  omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
   1473 {
   1474     OMX_U32 i = 0;
   1475     DEBUG_PRINT_HIGH("\n omx_venc(): Inside component_deinit()");
   1476     if (OMX_StateLoaded != m_state) {
   1477         DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d\n",\
   1478                 m_state);
   1479     }
   1480     if (m_out_mem_ptr) {
   1481         DEBUG_PRINT_LOW("Freeing the Output Memory\n");
   1482         for (i=0; i< m_sOutPortDef.nBufferCountActual; i++ ) {
   1483             free_output_buffer (&m_out_mem_ptr[i]);
   1484         }
   1485         free(m_out_mem_ptr);
   1486         m_out_mem_ptr = NULL;
   1487     }
   1488 
   1489     /*Check if the input buffers have to be cleaned up*/
   1490     if (m_inp_mem_ptr
   1491 #ifdef _ANDROID_ICS_
   1492             && !meta_mode_enable
   1493 #endif
   1494        ) {
   1495         DEBUG_PRINT_LOW("Freeing the Input Memory\n");
   1496         for (i=0; i<m_sInPortDef.nBufferCountActual; i++ ) {
   1497             free_input_buffer (&m_inp_mem_ptr[i]);
   1498         }
   1499 
   1500 
   1501         free(m_inp_mem_ptr);
   1502         m_inp_mem_ptr = NULL;
   1503     }
   1504 
   1505     // Reset counters in mesg queues
   1506     m_ftb_q.m_size=0;
   1507     m_cmd_q.m_size=0;
   1508     m_etb_q.m_size=0;
   1509     m_ftb_q.m_read = m_ftb_q.m_write =0;
   1510     m_cmd_q.m_read = m_cmd_q.m_write =0;
   1511     m_etb_q.m_read = m_etb_q.m_write =0;
   1512 
   1513 #ifdef _ANDROID_
   1514     // Clear the strong reference
   1515     DEBUG_PRINT_HIGH("Calling m_heap_ptr.clear()\n");
   1516     m_heap_ptr.clear();
   1517 #endif // _ANDROID_
   1518     DEBUG_PRINT_HIGH("Calling venc_close()\n");
   1519     handle->venc_close();
   1520     DEBUG_PRINT_HIGH("Deleting HANDLE[%p]\n", handle);
   1521     delete (handle);
   1522     DEBUG_PRINT_HIGH("OMX_Venc:Component Deinit\n");
   1523     return OMX_ErrorNone;
   1524 }
   1525 
   1526 
   1527 OMX_U32 omx_venc::dev_stop( void)
   1528 {
   1529     return handle->venc_stop();
   1530 }
   1531 
   1532 
   1533 OMX_U32 omx_venc::dev_pause(void)
   1534 {
   1535     return handle->venc_pause();
   1536 }
   1537 
   1538 OMX_U32 omx_venc::dev_start(void)
   1539 {
   1540     return handle->venc_start();
   1541 }
   1542 
   1543 OMX_U32 omx_venc::dev_flush(unsigned port)
   1544 {
   1545     return handle->venc_flush(port);
   1546 }
   1547 OMX_U32 omx_venc::dev_resume(void)
   1548 {
   1549     return handle->venc_resume();
   1550 }
   1551 
   1552 OMX_U32 omx_venc::dev_start_done(void)
   1553 {
   1554     return handle->venc_start_done();
   1555 }
   1556 
   1557 OMX_U32 omx_venc::dev_set_message_thread_id(pthread_t tid)
   1558 {
   1559     return handle->venc_set_message_thread_id(tid);
   1560 }
   1561 
   1562 bool omx_venc::dev_use_buf(void *buf_addr,unsigned port,unsigned index)
   1563 {
   1564     return handle->venc_use_buf(buf_addr,port,index);
   1565 }
   1566 
   1567 bool omx_venc::dev_free_buf(void *buf_addr,unsigned port)
   1568 {
   1569     return handle->venc_free_buf(buf_addr,port);
   1570 }
   1571 
   1572 bool omx_venc::dev_empty_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
   1573 {
   1574     return  handle->venc_empty_buf(buffer, pmem_data_buf,index,fd);
   1575 }
   1576 
   1577 bool omx_venc::dev_fill_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
   1578 {
   1579     return handle->venc_fill_buf(buffer, pmem_data_buf,index,fd);
   1580 }
   1581 
   1582 bool omx_venc::dev_get_seq_hdr(void *buffer, unsigned size, unsigned *hdrlen)
   1583 {
   1584     return handle->venc_get_seq_hdr(buffer, size, hdrlen);
   1585 }
   1586 
   1587 bool omx_venc::dev_get_capability_ltrcount(OMX_U32 *min, OMX_U32 *max, OMX_U32 *step_size)
   1588 {
   1589 #ifdef _MSM8974_
   1590     DEBUG_PRINT_ERROR("Get Capability LTR Count is not supported");
   1591     return false;
   1592 #else
   1593     return handle->venc_get_capability_ltrcount(min, max, step_size);
   1594 #endif
   1595 }
   1596 
   1597 bool omx_venc::dev_loaded_start()
   1598 {
   1599     return handle->venc_loaded_start();
   1600 }
   1601 
   1602 bool omx_venc::dev_loaded_stop()
   1603 {
   1604     return handle->venc_loaded_stop();
   1605 }
   1606 
   1607 bool omx_venc::dev_loaded_start_done()
   1608 {
   1609     return handle->venc_loaded_start_done();
   1610 }
   1611 
   1612 bool omx_venc::dev_loaded_stop_done()
   1613 {
   1614     return handle->venc_loaded_stop_done();
   1615 }
   1616 
   1617 bool omx_venc::dev_get_buf_req(OMX_U32 *min_buff_count,
   1618         OMX_U32 *actual_buff_count,
   1619         OMX_U32 *buff_size,
   1620         OMX_U32 port)
   1621 {
   1622     return handle->venc_get_buf_req(min_buff_count,
   1623             actual_buff_count,
   1624             buff_size,
   1625             port);
   1626 
   1627 }
   1628 
   1629 bool omx_venc::dev_set_buf_req(OMX_U32 *min_buff_count,
   1630         OMX_U32 *actual_buff_count,
   1631         OMX_U32 *buff_size,
   1632         OMX_U32 port)
   1633 {
   1634     return handle->venc_set_buf_req(min_buff_count,
   1635             actual_buff_count,
   1636             buff_size,
   1637             port);
   1638 
   1639 }
   1640 
   1641 bool omx_venc::dev_is_video_session_supported(OMX_U32 width, OMX_U32 height)
   1642 {
   1643 #ifdef _MSM8974_
   1644     return handle->venc_is_video_session_supported(width,height);
   1645 #else
   1646     DEBUG_PRINT_LOW("Check against video capability not supported");
   1647     return true;
   1648 #endif
   1649 }
   1650 
   1651 #ifdef _MSM8974_
   1652 int omx_venc::dev_handle_extradata(void *buffer, int index)
   1653 {
   1654     return handle->handle_extradata(buffer, index);
   1655 }
   1656 
   1657 int omx_venc::dev_set_format(int color)
   1658 {
   1659     return handle->venc_set_format(color);
   1660 }
   1661 #endif
   1662 
   1663 int omx_venc::async_message_process (void *context, void* message)
   1664 {
   1665     omx_video* omx = NULL;
   1666     struct venc_msg *m_sVenc_msg = NULL;
   1667     OMX_BUFFERHEADERTYPE* omxhdr = NULL;
   1668     struct venc_buffer *temp_buff = NULL;
   1669 
   1670     if (context == NULL || message == NULL) {
   1671         DEBUG_PRINT_ERROR("\nERROR: omx_venc::async_message_process invalid i/p params");
   1672         return -1;
   1673     }
   1674     m_sVenc_msg = (struct venc_msg *)message;
   1675 
   1676     omx = reinterpret_cast<omx_video*>(context);
   1677 
   1678     if (m_sVenc_msg->statuscode != VEN_S_SUCCESS) {
   1679         DEBUG_PRINT_ERROR("\nERROR: async_msg_process() - Error statuscode = %lu\n",
   1680                 m_sVenc_msg->statuscode);
   1681         omx->omx_report_error();
   1682     }
   1683 
   1684     DEBUG_PRINT_LOW("\n omx_venc::async_message_process- msgcode = %d\n",
   1685             m_sVenc_msg->msgcode);
   1686     switch (m_sVenc_msg->msgcode) {
   1687         case VEN_MSG_START:
   1688             omx->post_event (NULL,m_sVenc_msg->statuscode,\
   1689                     OMX_COMPONENT_GENERATE_START_DONE);
   1690             break;
   1691         case VEN_MSG_STOP:
   1692             omx->post_event (NULL,m_sVenc_msg->statuscode,\
   1693                     OMX_COMPONENT_GENERATE_STOP_DONE);
   1694             break;
   1695         case VEN_MSG_RESUME:
   1696             omx->post_event (NULL,m_sVenc_msg->statuscode,\
   1697                     OMX_COMPONENT_GENERATE_RESUME_DONE);
   1698             break;
   1699         case VEN_MSG_PAUSE:
   1700             omx->post_event (NULL,m_sVenc_msg->statuscode,\
   1701                     OMX_COMPONENT_GENERATE_PAUSE_DONE);
   1702             break;
   1703         case VEN_MSG_FLUSH_INPUT_DONE:
   1704 
   1705             omx->post_event (NULL,m_sVenc_msg->statuscode,\
   1706                     OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
   1707             break;
   1708         case VEN_MSG_FLUSH_OUPUT_DONE:
   1709             omx->post_event (NULL,m_sVenc_msg->statuscode,\
   1710                     OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
   1711             break;
   1712         case VEN_MSG_INPUT_BUFFER_DONE:
   1713             omxhdr = (OMX_BUFFERHEADERTYPE* )\
   1714                      m_sVenc_msg->buf.clientdata;
   1715 
   1716             if (omxhdr == NULL ||
   1717                     (((OMX_U32)(omxhdr - omx->m_inp_mem_ptr) > omx->m_sInPortDef.nBufferCountActual) &&
   1718                      ((OMX_U32)(omxhdr - omx->meta_buffer_hdr) > omx->m_sInPortDef.nBufferCountActual))) {
   1719                 omxhdr = NULL;
   1720                 m_sVenc_msg->statuscode = VEN_S_EFAIL;
   1721             }
   1722 
   1723 #ifdef _ANDROID_ICS_
   1724             omx->omx_release_meta_buffer(omxhdr);
   1725 #endif
   1726             omx->post_event ((unsigned int)omxhdr,m_sVenc_msg->statuscode,
   1727                     OMX_COMPONENT_GENERATE_EBD);
   1728             break;
   1729         case VEN_MSG_OUTPUT_BUFFER_DONE:
   1730             omxhdr = (OMX_BUFFERHEADERTYPE*)m_sVenc_msg->buf.clientdata;
   1731 
   1732             if ( (omxhdr != NULL) &&
   1733                     ((OMX_U32)(omxhdr - omx->m_out_mem_ptr)  < omx->m_sOutPortDef.nBufferCountActual)) {
   1734                 if (m_sVenc_msg->buf.len <=  omxhdr->nAllocLen) {
   1735                     omxhdr->nFilledLen = m_sVenc_msg->buf.len;
   1736                     omxhdr->nOffset = m_sVenc_msg->buf.offset;
   1737                     omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
   1738                     DEBUG_PRINT_LOW("\n o/p TS = %u", (OMX_U32)m_sVenc_msg->buf.timestamp);
   1739                     omxhdr->nFlags = m_sVenc_msg->buf.flags;
   1740 
   1741                     /*Use buffer case*/
   1742                     if (omx->output_use_buffer && !omx->m_use_output_pmem) {
   1743                         DEBUG_PRINT_LOW("\n memcpy() for o/p Heap UseBuffer");
   1744                         memcpy(omxhdr->pBuffer,
   1745                                 (m_sVenc_msg->buf.ptrbuffer),
   1746                                 m_sVenc_msg->buf.len);
   1747                     }
   1748                 } else {
   1749                     omxhdr->nFilledLen = 0;
   1750                 }
   1751 
   1752             } else {
   1753                 omxhdr = NULL;
   1754                 m_sVenc_msg->statuscode = VEN_S_EFAIL;
   1755             }
   1756             omx->post_event ((unsigned int)omxhdr,m_sVenc_msg->statuscode,
   1757                     OMX_COMPONENT_GENERATE_FBD);
   1758             break;
   1759         case VEN_MSG_NEED_OUTPUT_BUFFER:
   1760             //TBD what action needs to be done here??
   1761             break;
   1762 #ifndef _MSM8974_
   1763         case VEN_MSG_LTRUSE_FAILED:
   1764             DEBUG_PRINT_ERROR("LTRUSE Failed!");
   1765             omx->post_event (NULL,m_sVenc_msg->statuscode,
   1766                     OMX_COMPONENT_GENERATE_LTRUSE_FAILED);
   1767             break;
   1768 #endif
   1769         default:
   1770             break;
   1771     }
   1772     return 0;
   1773 }
   1774 
   1775 bool omx_venc::dev_color_align(OMX_BUFFERHEADERTYPE *buffer,
   1776                 OMX_U32 width, OMX_U32 height)
   1777 {
   1778     return handle->venc_color_align(buffer, width,height);
   1779 }
   1780