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