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_CodingVPX;
    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_CodingVPX) {
    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_CodingVPX) {
    311         m_sOutPortDef.format.video.eCompressionFormat =  OMX_VIDEO_CodingVPX;
    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_CodingVPX) {
    342         m_sOutPortFormat.eCompressionFormat =  OMX_VIDEO_CodingVPX;
    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_input_msg_id = OMX_COMPONENT_GENERATE_ETB;
    651                         mUseProxyColorFormat = false;
    652                     }
    653                     m_sInPortFormat.xFramerate = portFmt->xFramerate;
    654                 }
    655                 //TODO if no use case for O/P port,delet m_sOutPortFormat
    656             }
    657             break;
    658         case OMX_IndexParamVideoInit:
    659             { //TODO, do we need this index set param
    660                 OMX_PORT_PARAM_TYPE* pParam = (OMX_PORT_PARAM_TYPE*)(paramData);
    661                 DEBUG_PRINT_LOW("Set OMX_IndexParamVideoInit called");
    662                 break;
    663             }
    664 
    665         case OMX_IndexParamVideoBitrate:
    666             {
    667                 OMX_VIDEO_PARAM_BITRATETYPE* pParam = (OMX_VIDEO_PARAM_BITRATETYPE*)paramData;
    668                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoBitrate");
    669                 if (handle->venc_set_param(paramData,OMX_IndexParamVideoBitrate) != true) {
    670                     return OMX_ErrorUnsupportedSetting;
    671                 }
    672                 m_sParamBitrate.nTargetBitrate = pParam->nTargetBitrate;
    673                 m_sParamBitrate.eControlRate = pParam->eControlRate;
    674                 update_profile_level(); //bitrate
    675                 m_sConfigBitrate.nEncodeBitrate = pParam->nTargetBitrate;
    676                 m_sInPortDef.format.video.nBitrate = pParam->nTargetBitrate;
    677                 m_sOutPortDef.format.video.nBitrate = pParam->nTargetBitrate;
    678                 DEBUG_PRINT_LOW("bitrate = %u", (unsigned int)m_sOutPortDef.format.video.nBitrate);
    679                 break;
    680             }
    681         case OMX_IndexParamVideoMpeg4:
    682             {
    683                 OMX_VIDEO_PARAM_MPEG4TYPE* pParam = (OMX_VIDEO_PARAM_MPEG4TYPE*)paramData;
    684                 OMX_VIDEO_PARAM_MPEG4TYPE mp4_param;
    685                 memcpy(&mp4_param, pParam, sizeof(struct OMX_VIDEO_PARAM_MPEG4TYPE));
    686                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4");
    687                 if (pParam->eProfile == OMX_VIDEO_MPEG4ProfileAdvancedSimple) {
    688 #ifdef MAX_RES_1080P
    689                     if (pParam->nBFrames) {
    690                         DEBUG_PRINT_HIGH("INFO: Only 1 Bframe is supported");
    691                         mp4_param.nBFrames = 1;
    692                     }
    693 #else
    694                     if (pParam->nBFrames) {
    695                         DEBUG_PRINT_ERROR("Warning: B frames not supported");
    696                         mp4_param.nBFrames = 0;
    697                     }
    698 #endif
    699 #ifdef _MSM8974_
    700                     if (pParam->nBFrames || bframes)
    701                         mp4_param.nBFrames = (pParam->nBFrames > (unsigned int) bframes)? pParam->nBFrames : bframes;
    702                     if (mp4_param.nBFrames > 3)
    703                         mp4_param.nBFrames = 3;
    704                     DEBUG_PRINT_HIGH("MPEG4: %u BFrames are being set", (unsigned int)mp4_param.nBFrames);
    705 #endif
    706 
    707                 } else {
    708                     if (pParam->nBFrames) {
    709                         DEBUG_PRINT_ERROR("Warning: B frames not supported");
    710                         mp4_param.nBFrames = 0;
    711                     }
    712                 }
    713                 if (handle->venc_set_param(&mp4_param,OMX_IndexParamVideoMpeg4) != true) {
    714                     return OMX_ErrorUnsupportedSetting;
    715                 }
    716                 memcpy(&m_sParamMPEG4,pParam, sizeof(struct OMX_VIDEO_PARAM_MPEG4TYPE));
    717                 m_sIntraperiod.nPFrames = m_sParamMPEG4.nPFrames;
    718                 if (pParam->nBFrames || bframes)
    719                     m_sIntraperiod.nBFrames = m_sParamMPEG4.nBFrames = mp4_param.nBFrames;
    720                 else
    721                 m_sIntraperiod.nBFrames = m_sParamMPEG4.nBFrames;
    722                 break;
    723             }
    724         case OMX_IndexParamVideoH263:
    725             {
    726                 OMX_VIDEO_PARAM_H263TYPE* pParam = (OMX_VIDEO_PARAM_H263TYPE*)paramData;
    727                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263");
    728                 if (handle->venc_set_param(paramData,OMX_IndexParamVideoH263) != true) {
    729                     return OMX_ErrorUnsupportedSetting;
    730                 }
    731                 memcpy(&m_sParamH263,pParam, sizeof(struct OMX_VIDEO_PARAM_H263TYPE));
    732                 m_sIntraperiod.nPFrames = m_sParamH263.nPFrames;
    733                 m_sIntraperiod.nBFrames = m_sParamH263.nBFrames;
    734                 break;
    735             }
    736         case OMX_IndexParamVideoAvc:
    737             {
    738                 OMX_VIDEO_PARAM_AVCTYPE* pParam = (OMX_VIDEO_PARAM_AVCTYPE*)paramData;
    739                 OMX_VIDEO_PARAM_AVCTYPE avc_param;
    740                 memcpy(&avc_param, pParam, sizeof( struct OMX_VIDEO_PARAM_AVCTYPE));
    741                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc");
    742 
    743                 if ((pParam->eProfile == OMX_VIDEO_AVCProfileHigh)||
    744                         (pParam->eProfile == OMX_VIDEO_AVCProfileMain)) {
    745 #ifdef MAX_RES_1080P
    746                     if (pParam->nBFrames) {
    747                         DEBUG_PRINT_HIGH("INFO: Only 1 Bframe is supported");
    748                         avc_param.nBFrames = 1;
    749                     }
    750                     if (pParam->nRefFrames != 2) {
    751                         DEBUG_PRINT_ERROR("Warning: 2 RefFrames are needed, changing RefFrames from %u to 2", (unsigned int)pParam->nRefFrames);
    752                         avc_param.nRefFrames = 2;
    753                     }
    754 #else
    755                     if (pParam->nBFrames) {
    756                         DEBUG_PRINT_ERROR("Warning: B frames not supported");
    757                         avc_param.nBFrames = 0;
    758                     }
    759                     if (pParam->nRefFrames != 1) {
    760                         DEBUG_PRINT_ERROR("Warning: Only 1 RefFrame is supported, changing RefFrame from %lu to 1)", pParam->nRefFrames);
    761                         avc_param.nRefFrames = 1;
    762                     }
    763 #endif
    764 #ifdef _MSM8974_
    765                     if (pParam->nBFrames || bframes) {
    766                         avc_param.nBFrames = (pParam->nBFrames > (unsigned int) bframes)? pParam->nBFrames : bframes;
    767                         avc_param.nRefFrames = avc_param.nBFrames + 1;
    768                     }
    769                     if (avc_param.nBFrames > 3) {
    770                         avc_param.nBFrames = 3;
    771                         avc_param.nRefFrames = avc_param.nBFrames + 1;
    772                     }
    773                     DEBUG_PRINT_HIGH("AVC: RefFrames: %u, BFrames: %u", (unsigned int)avc_param.nRefFrames, (unsigned int)avc_param.nBFrames);
    774 
    775                     avc_param.bEntropyCodingCABAC = (OMX_BOOL)(avc_param.bEntropyCodingCABAC && entropy);
    776                     avc_param.nCabacInitIdc = entropy ? avc_param.nCabacInitIdc : 0;
    777 #endif
    778                 } else {
    779                     if (pParam->nRefFrames != 1) {
    780                         DEBUG_PRINT_ERROR("Warning: Only 1 RefFrame is supported, changing RefFrame from %u to 1)", (unsigned int)pParam->nRefFrames);
    781                         avc_param.nRefFrames = 1;
    782                     }
    783                     if (pParam->nBFrames) {
    784                         DEBUG_PRINT_ERROR("Warning: B frames not supported");
    785                         avc_param.nBFrames = 0;
    786                     }
    787                 }
    788                 if (handle->venc_set_param(&avc_param,OMX_IndexParamVideoAvc) != true) {
    789                     return OMX_ErrorUnsupportedSetting;
    790                 }
    791                 memcpy(&m_sParamAVC,pParam, sizeof(struct OMX_VIDEO_PARAM_AVCTYPE));
    792                 m_sIntraperiod.nPFrames = m_sParamAVC.nPFrames;
    793                 if (pParam->nBFrames || bframes)
    794                     m_sIntraperiod.nBFrames = m_sParamAVC.nBFrames = avc_param.nBFrames;
    795                 else
    796                 m_sIntraperiod.nBFrames = m_sParamAVC.nBFrames;
    797                 break;
    798             }
    799         case (OMX_INDEXTYPE)OMX_IndexParamVideoVp8:
    800             {
    801                 OMX_VIDEO_PARAM_VP8TYPE* pParam = (OMX_VIDEO_PARAM_VP8TYPE*)paramData;
    802                 OMX_VIDEO_PARAM_VP8TYPE vp8_param;
    803                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoVp8");
    804                 if (pParam->nDCTPartitions != m_sParamVP8.nDCTPartitions ||
    805                     pParam->bErrorResilientMode != m_sParamVP8.bErrorResilientMode) {
    806                     DEBUG_PRINT_ERROR("VP8 doesn't support nDCTPartitions or bErrorResilientMode");
    807                 }
    808                 memcpy(&vp8_param, pParam, sizeof( struct OMX_VIDEO_PARAM_VP8TYPE));
    809                 if (handle->venc_set_param(&vp8_param, (OMX_INDEXTYPE)OMX_IndexParamVideoVp8) != true) {
    810                     return OMX_ErrorUnsupportedSetting;
    811                 }
    812                 memcpy(&m_sParamVP8,pParam, sizeof(struct OMX_VIDEO_PARAM_VP8TYPE));
    813                 break;
    814             }
    815         case OMX_IndexParamVideoProfileLevelCurrent:
    816             {
    817                 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData;
    818                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoProfileLevelCurrent");
    819                 if (handle->venc_set_param(pParam,OMX_IndexParamVideoProfileLevelCurrent) != true) {
    820                     DEBUG_PRINT_ERROR("set_parameter: OMX_IndexParamVideoProfileLevelCurrent failed for Profile: %u "
    821                             "Level :%u", (unsigned int)pParam->eProfile, (unsigned int)pParam->eLevel);
    822                     return OMX_ErrorUnsupportedSetting;
    823                 }
    824                 m_sParamProfileLevel.eProfile = pParam->eProfile;
    825                 m_sParamProfileLevel.eLevel = pParam->eLevel;
    826 
    827                 if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.mpeg4",\
    828                             OMX_MAX_STRINGNAME_SIZE)) {
    829                     m_sParamMPEG4.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)m_sParamProfileLevel.eProfile;
    830                     m_sParamMPEG4.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)m_sParamProfileLevel.eLevel;
    831                     DEBUG_PRINT_LOW("MPEG4 profile = %d, level = %d", m_sParamMPEG4.eProfile,
    832                             m_sParamMPEG4.eLevel);
    833                 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\
    834                             OMX_MAX_STRINGNAME_SIZE)) {
    835                     m_sParamH263.eProfile = (OMX_VIDEO_H263PROFILETYPE)m_sParamProfileLevel.eProfile;
    836                     m_sParamH263.eLevel = (OMX_VIDEO_H263LEVELTYPE)m_sParamProfileLevel.eLevel;
    837                     DEBUG_PRINT_LOW("H263 profile = %d, level = %d", m_sParamH263.eProfile,
    838                             m_sParamH263.eLevel);
    839                 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
    840                             OMX_MAX_STRINGNAME_SIZE)) {
    841                     m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)m_sParamProfileLevel.eProfile;
    842                     m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel;
    843                     DEBUG_PRINT_LOW("AVC profile = %d, level = %d", m_sParamAVC.eProfile,
    844                             m_sParamAVC.eLevel);
    845                 } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
    846                             OMX_MAX_STRINGNAME_SIZE)) {
    847                     m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)m_sParamProfileLevel.eProfile;
    848                     m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel;
    849                     DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
    850                             m_sParamAVC.eLevel);
    851                 }
    852                 else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.vp8",\
    853                             OMX_MAX_STRINGNAME_SIZE)) {
    854                     m_sParamVP8.eProfile = (OMX_VIDEO_VP8PROFILETYPE)m_sParamProfileLevel.eProfile;
    855                     m_sParamVP8.eLevel = (OMX_VIDEO_VP8LEVELTYPE)m_sParamProfileLevel.eLevel;
    856                     DEBUG_PRINT_LOW("VP8 profile = %d, level = %d", m_sParamVP8.eProfile,
    857                             m_sParamVP8.eLevel);
    858                 }
    859                 break;
    860             }
    861         case OMX_IndexParamStandardComponentRole:
    862             {
    863                 OMX_PARAM_COMPONENTROLETYPE *comp_role;
    864                 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData;
    865                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s",
    866                         comp_role->cRole);
    867 
    868                 if ((m_state == OMX_StateLoaded)&&
    869                         !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) {
    870                     DEBUG_PRINT_LOW("Set Parameter called in valid state");
    871                 } else {
    872                     DEBUG_PRINT_ERROR("Set Parameter called in Invalid State");
    873                     return OMX_ErrorIncorrectStateOperation;
    874                 }
    875 
    876                 if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
    877                     if (!strncmp((char*)comp_role->cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
    878                         strlcpy((char*)m_cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
    879                     } else {
    880                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
    881                         eRet =OMX_ErrorUnsupportedSetting;
    882                     }
    883                 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc.secure",OMX_MAX_STRINGNAME_SIZE)) {
    884                     if (!strncmp((char*)comp_role->cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE)) {
    885                         strlcpy((char*)m_cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE);
    886                     } else {
    887                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole);
    888                         eRet =OMX_ErrorUnsupportedSetting;
    889                     }
    890                 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
    891                     if (!strncmp((const char*)comp_role->cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) {
    892                         strlcpy((char*)m_cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE);
    893                     } else {
    894                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
    895                         eRet = OMX_ErrorUnsupportedSetting;
    896                     }
    897                 } else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
    898                     if (!strncmp((const char*)comp_role->cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE)) {
    899                         strlcpy((char*)m_cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE);
    900                     } else {
    901                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
    902                         eRet =OMX_ErrorUnsupportedSetting;
    903                     }
    904                 }
    905 #ifdef _MSM8974_
    906                 else if (!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
    907                     if (!strncmp((const char*)comp_role->cRole,"video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE)) {
    908                         strlcpy((char*)m_cRole,"video_encoder.vp8",OMX_MAX_STRINGNAME_SIZE);
    909                     } else {
    910                         DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole);
    911                         eRet =OMX_ErrorUnsupportedSetting;
    912                     }
    913                 }
    914 #endif
    915                 else {
    916                     DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %s", m_nkind);
    917                     eRet = OMX_ErrorInvalidComponentName;
    918                 }
    919                 break;
    920             }
    921 
    922         case OMX_IndexParamPriorityMgmt:
    923             {
    924                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt");
    925                 if (m_state != OMX_StateLoaded) {
    926                     DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State");
    927                     return OMX_ErrorIncorrectStateOperation;
    928                 }
    929                 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData;
    930                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %u",
    931                         (unsigned int)priorityMgmtype->nGroupID);
    932 
    933                 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %u",
    934                         (unsigned int)priorityMgmtype->nGroupPriority);
    935 
    936                 m_sPriorityMgmt.nGroupID = priorityMgmtype->nGroupID;
    937                 m_sPriorityMgmt.nGroupPriority = priorityMgmtype->nGroupPriority;
    938 
    939                 break;
    940             }
    941 
    942         case OMX_IndexParamCompBufferSupplier:
    943             {
    944                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier");
    945                 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData;
    946                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d",
    947                         bufferSupplierType->eBufferSupplier);
    948                 if (bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1)
    949                     m_sInBufSupplier.eBufferSupplier = bufferSupplierType->eBufferSupplier;
    950 
    951                 else
    952 
    953                     eRet = OMX_ErrorBadPortIndex;
    954 
    955                 break;
    956 
    957             }
    958         case OMX_IndexParamVideoQuantization:
    959             {
    960                 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoQuantization");
    961                 OMX_VIDEO_PARAM_QUANTIZATIONTYPE *session_qp = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) paramData;
    962                 if (session_qp->nPortIndex == PORT_INDEX_OUT) {
    963                     if (handle->venc_set_param(paramData, OMX_IndexParamVideoQuantization) != true) {
    964                         return OMX_ErrorUnsupportedSetting;
    965                     }
    966                     m_sSessionQuantization.nQpI = session_qp->nQpI;
    967                     m_sSessionQuantization.nQpP = session_qp->nQpP;
    968                     m_sSessionQuantization.nQpB = session_qp->nQpB;
    969                 } else {
    970                     DEBUG_PRINT_ERROR("ERROR: Unsupported port Index for Session QP setting");
    971                     eRet = OMX_ErrorBadPortIndex;
    972                 }
    973                 break;
    974             }
    975 
    976         case OMX_QcomIndexParamVideoQPRange:
    977             {
    978                 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoQPRange");
    979                 OMX_QCOM_VIDEO_PARAM_QPRANGETYPE *qp_range = (OMX_QCOM_VIDEO_PARAM_QPRANGETYPE*) paramData;
    980                 if (qp_range->nPortIndex == PORT_INDEX_OUT) {
    981                     if (handle->venc_set_param(paramData,
    982                                 (OMX_INDEXTYPE)OMX_QcomIndexParamVideoQPRange) != true) {
    983                         return OMX_ErrorUnsupportedSetting;
    984                     }
    985                     m_sSessionQPRange.minQP= qp_range->minQP;
    986                     m_sSessionQPRange.maxQP= qp_range->maxQP;
    987                 } else {
    988                     DEBUG_PRINT_ERROR("ERROR: Unsupported port Index for QP range setting");
    989                     eRet = OMX_ErrorBadPortIndex;
    990                 }
    991                 break;
    992             }
    993 
    994         case OMX_QcomIndexPortDefn:
    995             {
    996                 OMX_QCOM_PARAM_PORTDEFINITIONTYPE* pParam =
    997                     (OMX_QCOM_PARAM_PORTDEFINITIONTYPE*)paramData;
    998                 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexPortDefn");
    999                 if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_IN) {
   1000                     if (pParam->nMemRegion > OMX_QCOM_MemRegionInvalid &&
   1001                             pParam->nMemRegion < OMX_QCOM_MemRegionMax) {
   1002                         m_use_input_pmem = OMX_TRUE;
   1003                     } else {
   1004                         m_use_input_pmem = OMX_FALSE;
   1005                     }
   1006                 } else if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_OUT) {
   1007                     if (pParam->nMemRegion > OMX_QCOM_MemRegionInvalid &&
   1008                             pParam->nMemRegion < OMX_QCOM_MemRegionMax) {
   1009                         m_use_output_pmem = OMX_TRUE;
   1010                     } else {
   1011                         m_use_output_pmem = OMX_FALSE;
   1012                     }
   1013                 } else {
   1014                     DEBUG_PRINT_ERROR("ERROR: SetParameter called on unsupported Port Index for QcomPortDefn");
   1015                     return OMX_ErrorBadPortIndex;
   1016                 }
   1017                 break;
   1018             }
   1019 
   1020         case OMX_IndexParamVideoErrorCorrection:
   1021             {
   1022                 DEBUG_PRINT_LOW("OMX_IndexParamVideoErrorCorrection");
   1023                 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pParam =
   1024                     (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)paramData;
   1025                 if (!handle->venc_set_param(paramData, OMX_IndexParamVideoErrorCorrection)) {
   1026                     DEBUG_PRINT_ERROR("ERROR: Request for setting Error Resilience failed");
   1027                     return OMX_ErrorUnsupportedSetting;
   1028                 }
   1029                 memcpy(&m_sErrorCorrection,pParam, sizeof(m_sErrorCorrection));
   1030                 break;
   1031             }
   1032         case OMX_IndexParamVideoIntraRefresh:
   1033             {
   1034                 DEBUG_PRINT_LOW("set_param:OMX_IndexParamVideoIntraRefresh");
   1035                 OMX_VIDEO_PARAM_INTRAREFRESHTYPE* pParam =
   1036                     (OMX_VIDEO_PARAM_INTRAREFRESHTYPE*)paramData;
   1037                 if (!handle->venc_set_param(paramData,OMX_IndexParamVideoIntraRefresh)) {
   1038                     DEBUG_PRINT_ERROR("ERROR: Request for setting intra refresh failed");
   1039                     return OMX_ErrorUnsupportedSetting;
   1040                 }
   1041                 memcpy(&m_sIntraRefresh, pParam, sizeof(m_sIntraRefresh));
   1042                 break;
   1043             }
   1044 #ifdef _ANDROID_ICS_
   1045         case OMX_QcomIndexParamVideoMetaBufferMode:
   1046             {
   1047                 StoreMetaDataInBuffersParams *pParam =
   1048                     (StoreMetaDataInBuffersParams*)paramData;
   1049                 DEBUG_PRINT_HIGH("set_parameter:OMX_QcomIndexParamVideoMetaBufferMode: "
   1050                         "port_index = %u, meta_mode = %d", (unsigned int)pParam->nPortIndex, pParam->bStoreMetaData);
   1051                 if (pParam->nPortIndex == PORT_INDEX_IN) {
   1052                     if (pParam->bStoreMetaData != meta_mode_enable) {
   1053                         if (!handle->venc_set_meta_mode(pParam->bStoreMetaData)) {
   1054                             DEBUG_PRINT_ERROR("ERROR: set Metabuffer mode %d fail",
   1055                                     pParam->bStoreMetaData);
   1056                             return OMX_ErrorUnsupportedSetting;
   1057                         }
   1058                         meta_mode_enable = pParam->bStoreMetaData;
   1059                         if (meta_mode_enable) {
   1060                             m_sInPortDef.nBufferCountActual = m_sInPortDef.nBufferCountMin;
   1061                             if (handle->venc_set_param(&m_sInPortDef,OMX_IndexParamPortDefinition) != true) {
   1062                                 DEBUG_PRINT_ERROR("ERROR: venc_set_param input failed");
   1063                                 return OMX_ErrorUnsupportedSetting;
   1064                             }
   1065                         } else {
   1066                             /*TODO: reset encoder driver Meta mode*/
   1067                             dev_get_buf_req   (&m_sOutPortDef.nBufferCountMin,
   1068                                     &m_sOutPortDef.nBufferCountActual,
   1069                                     &m_sOutPortDef.nBufferSize,
   1070                                     m_sOutPortDef.nPortIndex);
   1071                         }
   1072                     }
   1073                 } else if (pParam->nPortIndex == PORT_INDEX_OUT && secure_session) {
   1074                     if (pParam->bStoreMetaData != meta_mode_enable) {
   1075                         if (!handle->venc_set_meta_mode(pParam->bStoreMetaData)) {
   1076                             DEBUG_PRINT_ERROR("\nERROR: set Metabuffer mode %d fail",
   1077                                     pParam->bStoreMetaData);
   1078                             return OMX_ErrorUnsupportedSetting;
   1079                         }
   1080                         meta_mode_enable = pParam->bStoreMetaData;
   1081                     }
   1082                 } else {
   1083                     DEBUG_PRINT_ERROR("set_parameter: metamode is "
   1084                             "valid for input port only");
   1085                     eRet = OMX_ErrorUnsupportedIndex;
   1086                 }
   1087             }
   1088             break;
   1089 #endif
   1090 #if !defined(MAX_RES_720P) || defined(_MSM8974_)
   1091         case OMX_QcomIndexParamIndexExtraDataType:
   1092             {
   1093                 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType");
   1094                 QOMX_INDEXEXTRADATATYPE *pParam = (QOMX_INDEXEXTRADATATYPE *)paramData;
   1095                 bool enable = false;
   1096                 OMX_U32 mask = 0;
   1097 
   1098                 if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderSliceInfo) {
   1099                     if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1100                         mask = VEN_EXTRADATA_SLICEINFO;
   1101 
   1102                         DEBUG_PRINT_HIGH("SliceInfo extradata %s",
   1103                                 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
   1104                         } else {
   1105                         DEBUG_PRINT_ERROR("set_parameter: Slice information is "
   1106                                 "valid for output port only");
   1107                         eRet = OMX_ErrorUnsupportedIndex;
   1108                         break;
   1109                         }
   1110                 } else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderMBInfo) {
   1111                     if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1112                         mask = VEN_EXTRADATA_MBINFO;
   1113 
   1114                         DEBUG_PRINT_HIGH("MBInfo extradata %s",
   1115                                 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
   1116                     } else {
   1117                         DEBUG_PRINT_ERROR("set_parameter: MB information is "
   1118                                 "valid for output port only");
   1119                         eRet = OMX_ErrorUnsupportedIndex;
   1120                         break;
   1121                     }
   1122                 }
   1123 #ifndef _MSM8974_
   1124                 else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoLTRInfo) {
   1125                     if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1126                         if (pParam->bEnabled == OMX_TRUE)
   1127                             mask = VEN_EXTRADATA_LTRINFO;
   1128 
   1129                         DEBUG_PRINT_HIGH("LTRInfo extradata %s",
   1130                                 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled"));
   1131                     } else {
   1132                         DEBUG_PRINT_ERROR("set_parameter: LTR information is "
   1133                                 "valid for output port only");
   1134                         eRet = OMX_ErrorUnsupportedIndex;
   1135                         break;
   1136                     }
   1137                 }
   1138 #endif
   1139                 else {
   1140                     DEBUG_PRINT_ERROR("set_parameter: unsupported extrdata index (%x)",
   1141                             pParam->nIndex);
   1142                     eRet = OMX_ErrorUnsupportedIndex;
   1143                     break;
   1144                 }
   1145 
   1146 
   1147                 if (pParam->bEnabled == OMX_TRUE)
   1148                     m_sExtraData |= mask;
   1149                 else
   1150                     m_sExtraData &= ~mask;
   1151 
   1152                 enable = !!(m_sExtraData & mask);
   1153                 if (handle->venc_set_param(&enable,
   1154                             (OMX_INDEXTYPE)pParam->nIndex) != true) {
   1155                     DEBUG_PRINT_ERROR("ERROR: Setting Extradata (%x) failed", pParam->nIndex);
   1156                     return OMX_ErrorUnsupportedSetting;
   1157                 } else {
   1158                     m_sOutPortDef.nPortIndex = PORT_INDEX_OUT;
   1159                     dev_get_buf_req(&m_sOutPortDef.nBufferCountMin,
   1160                             &m_sOutPortDef.nBufferCountActual,
   1161                             &m_sOutPortDef.nBufferSize,
   1162                             m_sOutPortDef.nPortIndex);
   1163                     DEBUG_PRINT_HIGH("updated out_buf_req: buffer cnt=%u, "
   1164                             "count min=%u, buffer size=%u",
   1165                             (unsigned int)m_sOutPortDef.nBufferCountActual,
   1166                             (unsigned int)m_sOutPortDef.nBufferCountMin,
   1167                             (unsigned int)m_sOutPortDef.nBufferSize);
   1168                 }
   1169                 break;
   1170             }
   1171         case QOMX_IndexParamVideoLTRMode:
   1172             {
   1173                 QOMX_VIDEO_PARAM_LTRMODE_TYPE* pParam =
   1174                     (QOMX_VIDEO_PARAM_LTRMODE_TYPE*)paramData;
   1175                 if (!handle->venc_set_param(paramData, (OMX_INDEXTYPE)QOMX_IndexParamVideoLTRMode)) {
   1176                     DEBUG_PRINT_ERROR("ERROR: Setting LTR mode failed");
   1177                     return OMX_ErrorUnsupportedSetting;
   1178                 }
   1179                 memcpy(&m_sParamLTRMode, pParam, sizeof(m_sParamLTRMode));
   1180                 break;
   1181             }
   1182         case QOMX_IndexParamVideoLTRCount:
   1183             {
   1184                 QOMX_VIDEO_PARAM_LTRCOUNT_TYPE* pParam =
   1185                     (QOMX_VIDEO_PARAM_LTRCOUNT_TYPE*)paramData;
   1186                 if (!handle->venc_set_param(paramData, (OMX_INDEXTYPE)QOMX_IndexParamVideoLTRCount)) {
   1187                     DEBUG_PRINT_ERROR("ERROR: Setting LTR count failed");
   1188                     return OMX_ErrorUnsupportedSetting;
   1189                 }
   1190                 memcpy(&m_sParamLTRCount, pParam, sizeof(m_sParamLTRCount));
   1191                 break;
   1192             }
   1193 #endif
   1194         case OMX_QcomIndexParamVideoMaxAllowedBitrateCheck:
   1195             {
   1196                 QOMX_EXTNINDEX_PARAMTYPE* pParam =
   1197                     (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
   1198                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1199                     handle->m_max_allowed_bitrate_check =
   1200                         ((pParam->bEnable == OMX_TRUE) ? true : false);
   1201                     DEBUG_PRINT_HIGH("set_parameter: max allowed bitrate check %s",
   1202                             ((pParam->bEnable == OMX_TRUE) ? "enabled" : "disabled"));
   1203                 } else {
   1204                     DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexParamVideoMaxAllowedBitrateCheck "
   1205                             " called on wrong port(%u)", (unsigned int)pParam->nPortIndex);
   1206                     return OMX_ErrorBadPortIndex;
   1207                 }
   1208                 break;
   1209             }
   1210 #ifdef MAX_RES_1080P
   1211         case OMX_QcomIndexEnableSliceDeliveryMode:
   1212             {
   1213                 QOMX_EXTNINDEX_PARAMTYPE* pParam =
   1214                     (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
   1215                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1216                     if (!handle->venc_set_param(paramData,
   1217                                 (OMX_INDEXTYPE)OMX_QcomIndexEnableSliceDeliveryMode)) {
   1218                         DEBUG_PRINT_ERROR("ERROR: Request for setting slice delivery mode failed");
   1219                         return OMX_ErrorUnsupportedSetting;
   1220                     }
   1221                 } else {
   1222                     DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexEnableSliceDeliveryMode "
   1223                             "called on wrong port(%u)", (unsigned int)pParam->nPortIndex);
   1224                     return OMX_ErrorBadPortIndex;
   1225                 }
   1226                 break;
   1227             }
   1228 #endif
   1229         case OMX_QcomIndexEnableH263PlusPType:
   1230             {
   1231                 QOMX_EXTNINDEX_PARAMTYPE* pParam =
   1232                     (QOMX_EXTNINDEX_PARAMTYPE*)paramData;
   1233                 DEBUG_PRINT_LOW("OMX_QcomIndexEnableH263PlusPType");
   1234                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1235                     if (!handle->venc_set_param(paramData,
   1236                                 (OMX_INDEXTYPE)OMX_QcomIndexEnableH263PlusPType)) {
   1237                         DEBUG_PRINT_ERROR("ERROR: Request for setting PlusPType failed");
   1238                         return OMX_ErrorUnsupportedSetting;
   1239                     }
   1240                 } else {
   1241                     DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexEnableH263PlusPType "
   1242                             "called on wrong port(%u)", (unsigned int)pParam->nPortIndex);
   1243                     return OMX_ErrorBadPortIndex;
   1244                 }
   1245                 break;
   1246             }
   1247         case OMX_QcomIndexParamSequenceHeaderWithIDR:
   1248             {
   1249                 if(!handle->venc_set_param(paramData,
   1250                             (OMX_INDEXTYPE)OMX_QcomIndexParamSequenceHeaderWithIDR)) {
   1251                     DEBUG_PRINT_ERROR("%s: %s",
   1252                             "OMX_QComIndexParamSequenceHeaderWithIDR:",
   1253                             "request for inband sps/pps failed.");
   1254                     return OMX_ErrorUnsupportedSetting;
   1255                 }
   1256                 break;
   1257             }
   1258         case OMX_QcomIndexParamH264AUDelimiter:
   1259             {
   1260                 if(!handle->venc_set_param(paramData,
   1261                             (OMX_INDEXTYPE)OMX_QcomIndexParamH264AUDelimiter)) {
   1262                     DEBUG_PRINT_ERROR("%s: %s",
   1263                             "OMX_QComIndexParamh264AUDelimiter:",
   1264                             "request for AU Delimiters failed.");
   1265                     return OMX_ErrorUnsupportedSetting;
   1266                 }
   1267                 break;
   1268             }
   1269        case OMX_QcomIndexHierarchicalStructure:
   1270            {
   1271                 QOMX_VIDEO_HIERARCHICALLAYERS* pParam =
   1272                     (QOMX_VIDEO_HIERARCHICALLAYERS*)paramData;
   1273                 DEBUG_PRINT_LOW("OMX_QcomIndexHierarchicalStructure");
   1274                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1275                     if (!handle->venc_set_param(paramData,
   1276                                 (OMX_INDEXTYPE)OMX_QcomIndexHierarchicalStructure)) {
   1277                         DEBUG_PRINT_ERROR("ERROR: Request for setting PlusPType failed");
   1278                         return OMX_ErrorUnsupportedSetting;
   1279                     }
   1280                     m_sHierLayers.nNumLayers = pParam->nNumLayers;
   1281                     m_sHierLayers.eHierarchicalCodingType = pParam->eHierarchicalCodingType;
   1282                 } else {
   1283                     DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexHierarchicalStructure called on wrong port(%u)",
   1284                           (unsigned int)pParam->nPortIndex);
   1285                     return OMX_ErrorBadPortIndex;
   1286                 }
   1287                 break;
   1288 
   1289            }
   1290         case OMX_QcomIndexParamPerfLevel:
   1291             {
   1292                 if (!handle->venc_set_param(paramData,
   1293                             (OMX_INDEXTYPE) OMX_QcomIndexParamPerfLevel)) {
   1294                     DEBUG_PRINT_ERROR("ERROR: Setting performance level");
   1295                     return OMX_ErrorUnsupportedSetting;
   1296                 }
   1297                 break;
   1298             }
   1299         case OMX_QcomIndexParamH264VUITimingInfo:
   1300             {
   1301                 if (!handle->venc_set_param(paramData,
   1302                             (OMX_INDEXTYPE) OMX_QcomIndexParamH264VUITimingInfo)) {
   1303                     DEBUG_PRINT_ERROR("ERROR: Setting VUI timing info");
   1304                     return OMX_ErrorUnsupportedSetting;
   1305                 }
   1306                 break;
   1307             }
   1308         case OMX_QcomIndexParamPeakBitrate:
   1309             {
   1310                 if (!handle->venc_set_param(paramData,
   1311                             (OMX_INDEXTYPE) OMX_QcomIndexParamPeakBitrate)) {
   1312                     DEBUG_PRINT_ERROR("ERROR: Setting peak bitrate");
   1313                     return OMX_ErrorUnsupportedSetting;
   1314                 }
   1315                 break;
   1316              }
   1317        case QOMX_IndexParamVideoInitialQp:
   1318             {
   1319                 if(!handle->venc_set_param(paramData,
   1320                             (OMX_INDEXTYPE)QOMX_IndexParamVideoInitialQp)) {
   1321                     DEBUG_PRINT_ERROR("Request to Enable initial QP failed");
   1322                     return OMX_ErrorUnsupportedSetting;
   1323                 }
   1324                 memcpy(&m_sParamInitqp, paramData, sizeof(m_sParamInitqp));
   1325                 break;
   1326             }
   1327         case OMX_QcomIndexParamSetMVSearchrange:
   1328             {
   1329                 if (!handle->venc_set_param(paramData,
   1330                             (OMX_INDEXTYPE) OMX_QcomIndexParamSetMVSearchrange)) {
   1331                     DEBUG_PRINT_ERROR("ERROR: Setting Searchrange");
   1332                     return OMX_ErrorUnsupportedSetting;
   1333                 }
   1334                 break;
   1335             }
   1336         case OMX_IndexParamVideoSliceFMO:
   1337         default:
   1338             {
   1339                 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %d", paramIndex);
   1340                 eRet = OMX_ErrorUnsupportedIndex;
   1341                 break;
   1342             }
   1343     }
   1344     return eRet;
   1345 }
   1346 
   1347 bool omx_venc::update_profile_level()
   1348 {
   1349     OMX_U32 eProfile, eLevel;
   1350 
   1351     if (!handle->venc_get_profile_level(&eProfile,&eLevel)) {
   1352         DEBUG_PRINT_ERROR("Failed to update the profile_level");
   1353         return false;
   1354     }
   1355 
   1356     m_sParamProfileLevel.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)eProfile;
   1357     m_sParamProfileLevel.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)eLevel;
   1358 
   1359     if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.mpeg4",\
   1360                 OMX_MAX_STRINGNAME_SIZE)) {
   1361         m_sParamMPEG4.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)eProfile;
   1362         m_sParamMPEG4.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)eLevel;
   1363         DEBUG_PRINT_LOW("MPEG4 profile = %d, level = %d", m_sParamMPEG4.eProfile,
   1364                 m_sParamMPEG4.eLevel);
   1365     } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\
   1366                 OMX_MAX_STRINGNAME_SIZE)) {
   1367         m_sParamH263.eProfile = (OMX_VIDEO_H263PROFILETYPE)eProfile;
   1368         m_sParamH263.eLevel = (OMX_VIDEO_H263LEVELTYPE)eLevel;
   1369         DEBUG_PRINT_LOW("H263 profile = %d, level = %d", m_sParamH263.eProfile,
   1370                 m_sParamH263.eLevel);
   1371     } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\
   1372                 OMX_MAX_STRINGNAME_SIZE)) {
   1373         m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)eProfile;
   1374         m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
   1375         DEBUG_PRINT_LOW("AVC profile = %d, level = %d", m_sParamAVC.eProfile,
   1376                 m_sParamAVC.eLevel);
   1377     } else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc.secure",\
   1378                 OMX_MAX_STRINGNAME_SIZE)) {
   1379         m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)eProfile;
   1380         m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)eLevel;
   1381         DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile,
   1382                 m_sParamAVC.eLevel);
   1383     }
   1384     else if (!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.vp8",\
   1385                 OMX_MAX_STRINGNAME_SIZE)) {
   1386         m_sParamVP8.eProfile = (OMX_VIDEO_VP8PROFILETYPE)eProfile;
   1387         m_sParamVP8.eLevel = (OMX_VIDEO_VP8LEVELTYPE)eLevel;
   1388         DEBUG_PRINT_LOW("VP8 profile = %d, level = %d", m_sParamVP8.eProfile,
   1389                 m_sParamVP8.eLevel);
   1390     }
   1391     return true;
   1392 }
   1393 /* ======================================================================
   1394    FUNCTION
   1395    omx_video::SetConfig
   1396 
   1397    DESCRIPTION
   1398    OMX Set Config method implementation
   1399 
   1400    PARAMETERS
   1401    <TBD>.
   1402 
   1403    RETURN VALUE
   1404    OMX Error None if successful.
   1405    ========================================================================== */
   1406 OMX_ERRORTYPE  omx_venc::set_config(OMX_IN OMX_HANDLETYPE      hComp,
   1407         OMX_IN OMX_INDEXTYPE configIndex,
   1408         OMX_IN OMX_PTR        configData)
   1409 {
   1410     (void)hComp;
   1411     if (configData == NULL) {
   1412         DEBUG_PRINT_ERROR("ERROR: param is null");
   1413         return OMX_ErrorBadParameter;
   1414     }
   1415 
   1416     if (m_state == OMX_StateInvalid) {
   1417         DEBUG_PRINT_ERROR("ERROR: config called in Invalid state");
   1418         return OMX_ErrorIncorrectStateOperation;
   1419     }
   1420 
   1421     // params will be validated prior to venc_init
   1422     switch ((int)configIndex) {
   1423         case OMX_IndexConfigVideoBitrate:
   1424             {
   1425                 OMX_VIDEO_CONFIG_BITRATETYPE* pParam =
   1426                     reinterpret_cast<OMX_VIDEO_CONFIG_BITRATETYPE*>(configData);
   1427                 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoBitrate (%u)", (unsigned int)pParam->nEncodeBitrate);
   1428 
   1429                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1430                     if (handle->venc_set_config(configData, OMX_IndexConfigVideoBitrate) != true) {
   1431                         DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoBitrate failed");
   1432                         return OMX_ErrorUnsupportedSetting;
   1433                     }
   1434 
   1435                     m_sConfigBitrate.nEncodeBitrate = pParam->nEncodeBitrate;
   1436                     m_sParamBitrate.nTargetBitrate = pParam->nEncodeBitrate;
   1437                     m_sOutPortDef.format.video.nBitrate = pParam->nEncodeBitrate;
   1438                 } else {
   1439                     DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
   1440                     return OMX_ErrorBadPortIndex;
   1441                 }
   1442                 break;
   1443             }
   1444         case OMX_IndexConfigVideoFramerate:
   1445             {
   1446                 OMX_CONFIG_FRAMERATETYPE* pParam =
   1447                     reinterpret_cast<OMX_CONFIG_FRAMERATETYPE*>(configData);
   1448                 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoFramerate (0x%x)", (unsigned int)pParam->xEncodeFramerate);
   1449 
   1450                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1451                     if (handle->venc_set_config(configData, OMX_IndexConfigVideoFramerate) != true) {
   1452                         DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoFramerate failed");
   1453                         return OMX_ErrorUnsupportedSetting;
   1454                     }
   1455 
   1456                     m_sConfigFramerate.xEncodeFramerate = pParam->xEncodeFramerate;
   1457                     m_sOutPortDef.format.video.xFramerate = pParam->xEncodeFramerate;
   1458                     m_sOutPortFormat.xFramerate = pParam->xEncodeFramerate;
   1459                 } else {
   1460                     DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
   1461                     return OMX_ErrorBadPortIndex;
   1462                 }
   1463 
   1464                 break;
   1465             }
   1466         case QOMX_IndexConfigVideoIntraperiod:
   1467             {
   1468                 QOMX_VIDEO_INTRAPERIODTYPE* pParam =
   1469                     reinterpret_cast<QOMX_VIDEO_INTRAPERIODTYPE*>(configData);
   1470 
   1471                 DEBUG_PRINT_HIGH("set_config(): QOMX_IndexConfigVideoIntraperiod");
   1472                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1473 #ifdef MAX_RES_720P
   1474                     if (pParam->nBFrames > 0) {
   1475                         DEBUG_PRINT_ERROR("B frames not supported");
   1476                         return OMX_ErrorUnsupportedSetting;
   1477                     }
   1478 #endif
   1479                     DEBUG_PRINT_HIGH("Old: P/B frames = %u/%u, New: P/B frames = %u/%u",
   1480                             (unsigned int)m_sIntraperiod.nPFrames, (unsigned int)m_sIntraperiod.nBFrames,
   1481                             (unsigned int)pParam->nPFrames, (unsigned int)pParam->nBFrames);
   1482                     if (m_sIntraperiod.nBFrames != pParam->nBFrames) {
   1483                         DEBUG_PRINT_HIGH("Dynamically changing B-frames not supported");
   1484                         return OMX_ErrorUnsupportedSetting;
   1485                     }
   1486                     if (handle->venc_set_config(configData, (OMX_INDEXTYPE) QOMX_IndexConfigVideoIntraperiod) != true) {
   1487                         DEBUG_PRINT_ERROR("ERROR: Setting QOMX_IndexConfigVideoIntraperiod failed");
   1488                         return OMX_ErrorUnsupportedSetting;
   1489                     }
   1490                     m_sIntraperiod.nPFrames = pParam->nPFrames;
   1491                     m_sIntraperiod.nBFrames = pParam->nBFrames;
   1492                     m_sIntraperiod.nIDRPeriod = pParam->nIDRPeriod;
   1493 
   1494                     if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
   1495                         m_sParamMPEG4.nPFrames = pParam->nPFrames;
   1496                         if (m_sParamMPEG4.eProfile != OMX_VIDEO_MPEG4ProfileSimple)
   1497                             m_sParamMPEG4.nBFrames = pParam->nBFrames;
   1498                         else
   1499                             m_sParamMPEG4.nBFrames = 0;
   1500                     } else if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingH263) {
   1501                         m_sParamH263.nPFrames = pParam->nPFrames;
   1502                     } else {
   1503                         m_sParamAVC.nPFrames = pParam->nPFrames;
   1504                         if ((m_sParamAVC.eProfile != OMX_VIDEO_AVCProfileBaseline) &&
   1505                             (m_sParamAVC.eProfile != (OMX_VIDEO_AVCPROFILETYPE) QOMX_VIDEO_AVCProfileConstrainedBaseline))
   1506                             m_sParamAVC.nBFrames = pParam->nBFrames;
   1507                         else
   1508                             m_sParamAVC.nBFrames = 0;
   1509                     }
   1510                 } else {
   1511                     DEBUG_PRINT_ERROR("ERROR: (QOMX_IndexConfigVideoIntraperiod) Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
   1512                     return OMX_ErrorBadPortIndex;
   1513                 }
   1514 
   1515                 break;
   1516             }
   1517 
   1518         case OMX_IndexConfigVideoIntraVOPRefresh:
   1519             {
   1520                 OMX_CONFIG_INTRAREFRESHVOPTYPE* pParam =
   1521                     reinterpret_cast<OMX_CONFIG_INTRAREFRESHVOPTYPE*>(configData);
   1522 
   1523                 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoIntraVOPRefresh");
   1524                 if (pParam->nPortIndex == PORT_INDEX_OUT) {
   1525                     if (handle->venc_set_config(configData,
   1526                                 OMX_IndexConfigVideoIntraVOPRefresh) != true) {
   1527                         DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoIntraVOPRefresh failed");
   1528                         return OMX_ErrorUnsupportedSetting;
   1529                     }
   1530 
   1531                     m_sConfigIntraRefreshVOP.IntraRefreshVOP = pParam->IntraRefreshVOP;
   1532                 } else {
   1533                     DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
   1534                     return OMX_ErrorBadPortIndex;
   1535                 }
   1536 
   1537                 break;
   1538             }
   1539         case OMX_IndexConfigCommonRotate:
   1540             {
   1541                 OMX_CONFIG_ROTATIONTYPE *pParam =
   1542                     reinterpret_cast<OMX_CONFIG_ROTATIONTYPE*>(configData);
   1543                 OMX_S32 nRotation;
   1544 
   1545                 if (pParam->nPortIndex != PORT_INDEX_IN) {
   1546                     DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", (unsigned int)pParam->nPortIndex);
   1547                     return OMX_ErrorBadPortIndex;
   1548                 }
   1549                 if ( pParam->nRotation == 0   ||
   1550                         pParam->nRotation == 90  ||
   1551                         pParam->nRotation == 180 ||
   1552                         pParam->nRotation == 270 ) {
   1553                     DEBUG_PRINT_HIGH("set_config: Rotation Angle %u", (unsigned int)pParam->nRotation);
   1554                 } else {
   1555                     DEBUG_PRINT_ERROR("ERROR: un supported Rotation %u", (unsigned int)pParam->nRotation);
   1556                     return OMX_ErrorUnsupportedSetting;
   1557                 }
   1558                 nRotation = pParam->nRotation - m_sConfigFrameRotation.nRotation;
   1559                 if (nRotation < 0)
   1560                     nRotation = -nRotation;
   1561                 if (nRotation == 90 || nRotation == 270) {
   1562                     DEBUG_PRINT_HIGH("set_config: updating device Dims");
   1563                     if (handle->venc_set_config(configData,
   1564                                 OMX_IndexConfigCommonRotate) != true) {
   1565                         DEBUG_PRINT_ERROR("ERROR: Set OMX_IndexConfigCommonRotate failed");
   1566                         return OMX_ErrorUnsupportedSetting;
   1567                     } else {
   1568                         OMX_U32 nFrameWidth;
   1569 
   1570                         DEBUG_PRINT_HIGH("set_config: updating port Dims");
   1571 
   1572                         nFrameWidth = m_sInPortDef.format.video.nFrameWidth;
   1573                         m_sInPortDef.format.video.nFrameWidth =
   1574                             m_sInPortDef.format.video.nFrameHeight;
   1575                         m_sInPortDef.format.video.nFrameHeight = nFrameWidth;
   1576 
   1577                         m_sOutPortDef.format.video.nFrameWidth  =
   1578                             m_sInPortDef.format.video.nFrameWidth;
   1579                         m_sOutPortDef.format.video.nFrameHeight =
   1580                             m_sInPortDef.format.video.nFrameHeight;
   1581                         m_sConfigFrameRotation.nRotation = pParam->nRotation;
   1582                     }
   1583                 } else {
   1584                     m_sConfigFrameRotation.nRotation = pParam->nRotation;
   1585                 }
   1586                 break;
   1587             }
   1588         case OMX_QcomIndexConfigVideoFramePackingArrangement:
   1589             {
   1590                 DEBUG_PRINT_HIGH("set_config(): OMX_QcomIndexConfigVideoFramePackingArrangement");
   1591                 if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingAVC) {
   1592                     OMX_QCOM_FRAME_PACK_ARRANGEMENT *configFmt =
   1593                         (OMX_QCOM_FRAME_PACK_ARRANGEMENT *) configData;
   1594                     extra_data_handle.set_frame_pack_data(configFmt);
   1595                 } else {
   1596                     DEBUG_PRINT_ERROR("ERROR: FramePackingData not supported for non AVC compression");
   1597                 }
   1598                 break;
   1599             }
   1600         case QOMX_IndexConfigVideoLTRPeriod:
   1601             {
   1602                 QOMX_VIDEO_CONFIG_LTRPERIOD_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRPERIOD_TYPE*)configData;
   1603                 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRPeriod)) {
   1604                     DEBUG_PRINT_ERROR("ERROR: Setting LTR period failed");
   1605                     return OMX_ErrorUnsupportedSetting;
   1606                 }
   1607                 memcpy(&m_sConfigLTRPeriod, pParam, sizeof(m_sConfigLTRPeriod));
   1608                 break;
   1609             }
   1610 
   1611        case OMX_IndexConfigVideoVp8ReferenceFrame:
   1612            {
   1613                OMX_VIDEO_VP8REFERENCEFRAMETYPE* pParam = (OMX_VIDEO_VP8REFERENCEFRAMETYPE*) configData;
   1614                if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE) OMX_IndexConfigVideoVp8ReferenceFrame)) {
   1615                    DEBUG_PRINT_ERROR("ERROR: Setting VP8 reference frame");
   1616                    return OMX_ErrorUnsupportedSetting;
   1617                }
   1618                memcpy(&m_sConfigVp8ReferenceFrame, pParam, sizeof(m_sConfigVp8ReferenceFrame));
   1619                break;
   1620            }
   1621 
   1622         case QOMX_IndexConfigVideoLTRUse:
   1623             {
   1624                 QOMX_VIDEO_CONFIG_LTRUSE_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRUSE_TYPE*)configData;
   1625                 if (!handle->venc_set_config(configData, (OMX_INDEXTYPE)QOMX_IndexConfigVideoLTRUse)) {
   1626                     DEBUG_PRINT_ERROR("ERROR: Setting LTR use failed");
   1627                     return OMX_ErrorUnsupportedSetting;
   1628                 }
   1629                 memcpy(&m_sConfigLTRUse, pParam, sizeof(m_sConfigLTRUse));
   1630                 break;
   1631             }
   1632         case QOMX_IndexConfigVideoLTRMark:
   1633             {
   1634                 QOMX_VIDEO_CONFIG_LTRMARK_TYPE* pParam = (QOMX_VIDEO_CONFIG_LTRMARK_TYPE*)configData;
   1635                 DEBUG_PRINT_ERROR("Setting ltr mark is not supported");
   1636                 return OMX_ErrorUnsupportedSetting;
   1637                 break;
   1638             }
   1639         case OMX_IndexConfigVideoAVCIntraPeriod:
   1640             {
   1641                 OMX_VIDEO_CONFIG_AVCINTRAPERIOD *pParam = (OMX_VIDEO_CONFIG_AVCINTRAPERIOD*) configData;
   1642                 DEBUG_PRINT_LOW("set_config: OMX_IndexConfigVideoAVCIntraPeriod");
   1643                 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_IndexConfigVideoAVCIntraPeriod)) {
   1644                     DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoAVCIntraPeriod failed");
   1645                     return OMX_ErrorUnsupportedSetting;
   1646                 }
   1647                 memcpy(&m_sConfigAVCIDRPeriod, pParam, sizeof(m_sConfigAVCIDRPeriod));
   1648                 break;
   1649             }
   1650         case OMX_IndexConfigCommonDeinterlace:
   1651             {
   1652                 OMX_VIDEO_CONFIG_DEINTERLACE *pParam = (OMX_VIDEO_CONFIG_DEINTERLACE*) configData;
   1653                 DEBUG_PRINT_LOW("set_config: OMX_IndexConfigCommonDeinterlace");
   1654                 if (!handle->venc_set_config(pParam, (OMX_INDEXTYPE)OMX_IndexConfigCommonDeinterlace)) {
   1655                     DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigCommonDeinterlace failed");
   1656                     return OMX_ErrorUnsupportedSetting;
   1657                 }
   1658                 memcpy(&m_sConfigDeinterlace, pParam, sizeof(m_sConfigDeinterlace));
   1659                 break;
   1660             }
   1661         default:
   1662             DEBUG_PRINT_ERROR("ERROR: unsupported index %d", (int) configIndex);
   1663             break;
   1664     }
   1665 
   1666     return OMX_ErrorNone;
   1667 }
   1668 
   1669 /* ======================================================================
   1670    FUNCTION
   1671    omx_venc::ComponentDeInit
   1672 
   1673    DESCRIPTION
   1674    Destroys the component and release memory allocated to the heap.
   1675 
   1676    PARAMETERS
   1677    <TBD>.
   1678 
   1679    RETURN VALUE
   1680    OMX Error None if everything successful.
   1681 
   1682    ========================================================================== */
   1683 OMX_ERRORTYPE  omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp)
   1684 {
   1685     (void) hComp;
   1686     OMX_U32 i = 0;
   1687     DEBUG_PRINT_HIGH("omx_venc(): Inside component_deinit()");
   1688     if (OMX_StateLoaded != m_state) {
   1689         DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d",\
   1690                 m_state);
   1691     }
   1692     if (m_out_mem_ptr) {
   1693         DEBUG_PRINT_LOW("Freeing the Output Memory");
   1694         for (i=0; i< m_sOutPortDef.nBufferCountActual; i++ ) {
   1695             free_output_buffer (&m_out_mem_ptr[i]);
   1696         }
   1697         free(m_out_mem_ptr);
   1698         m_out_mem_ptr = NULL;
   1699     }
   1700 
   1701     /*Check if the input buffers have to be cleaned up*/
   1702     if (m_inp_mem_ptr
   1703 #ifdef _ANDROID_ICS_
   1704             && !meta_mode_enable
   1705 #endif
   1706        ) {
   1707         DEBUG_PRINT_LOW("Freeing the Input Memory");
   1708         for (i=0; i<m_sInPortDef.nBufferCountActual; i++ ) {
   1709             free_input_buffer (&m_inp_mem_ptr[i]);
   1710         }
   1711 
   1712 
   1713         free(m_inp_mem_ptr);
   1714         m_inp_mem_ptr = NULL;
   1715     }
   1716 
   1717     // Reset counters in mesg queues
   1718     m_ftb_q.m_size=0;
   1719     m_cmd_q.m_size=0;
   1720     m_etb_q.m_size=0;
   1721     m_ftb_q.m_read = m_ftb_q.m_write =0;
   1722     m_cmd_q.m_read = m_cmd_q.m_write =0;
   1723     m_etb_q.m_read = m_etb_q.m_write =0;
   1724 
   1725 #ifdef _ANDROID_
   1726     // Clear the strong reference
   1727     DEBUG_PRINT_HIGH("Calling m_heap_ptr.clear()");
   1728     m_heap_ptr.clear();
   1729 #endif // _ANDROID_
   1730     DEBUG_PRINT_HIGH("Calling venc_close()");
   1731     handle->venc_close();
   1732     DEBUG_PRINT_HIGH("Deleting HANDLE[%p]", handle);
   1733     delete (handle);
   1734     DEBUG_PRINT_INFO("Component Deinit");
   1735     return OMX_ErrorNone;
   1736 }
   1737 
   1738 
   1739 OMX_U32 omx_venc::dev_stop( void)
   1740 {
   1741     return handle->venc_stop();
   1742 }
   1743 
   1744 
   1745 OMX_U32 omx_venc::dev_pause(void)
   1746 {
   1747     return handle->venc_pause();
   1748 }
   1749 
   1750 OMX_U32 omx_venc::dev_start(void)
   1751 {
   1752     return handle->venc_start();
   1753 }
   1754 
   1755 OMX_U32 omx_venc::dev_flush(unsigned port)
   1756 {
   1757     return handle->venc_flush(port);
   1758 }
   1759 OMX_U32 omx_venc::dev_resume(void)
   1760 {
   1761     return handle->venc_resume();
   1762 }
   1763 
   1764 OMX_U32 omx_venc::dev_start_done(void)
   1765 {
   1766     return handle->venc_start_done();
   1767 }
   1768 
   1769 OMX_U32 omx_venc::dev_set_message_thread_id(pthread_t tid)
   1770 {
   1771     return handle->venc_set_message_thread_id(tid);
   1772 }
   1773 
   1774 bool omx_venc::dev_use_buf(void *buf_addr,unsigned port,unsigned index)
   1775 {
   1776     return handle->venc_use_buf(buf_addr,port,index);
   1777 }
   1778 
   1779 bool omx_venc::dev_free_buf(void *buf_addr,unsigned port)
   1780 {
   1781     return handle->venc_free_buf(buf_addr,port);
   1782 }
   1783 
   1784 bool omx_venc::dev_empty_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
   1785 {
   1786     return  handle->venc_empty_buf(buffer, pmem_data_buf,index,fd);
   1787 }
   1788 
   1789 bool omx_venc::dev_fill_buf(void *buffer, void *pmem_data_buf,unsigned index,unsigned fd)
   1790 {
   1791     return handle->venc_fill_buf(buffer, pmem_data_buf,index,fd);
   1792 }
   1793 
   1794 bool omx_venc::dev_get_seq_hdr(void *buffer, unsigned size, OMX_U32 *hdrlen)
   1795 {
   1796     return handle->venc_get_seq_hdr(buffer, size, hdrlen);
   1797 }
   1798 
   1799 bool omx_venc::dev_get_capability_ltrcount(OMX_U32 *min, OMX_U32 *max, OMX_U32 *step_size)
   1800 {
   1801 #ifdef _MSM8974_
   1802     (void) min;
   1803     (void) max;
   1804     (void) step_size;
   1805     DEBUG_PRINT_ERROR("Get Capability LTR Count is not supported");
   1806     return false;
   1807 #else
   1808     return handle->venc_get_capability_ltrcount(min, max, step_size);
   1809 #endif
   1810 }
   1811 
   1812 bool omx_venc::dev_get_performance_level(OMX_U32 *perflevel)
   1813 {
   1814 #ifdef _MSM8974_
   1815     return handle->venc_get_performance_level(perflevel);
   1816 #else
   1817     DEBUG_PRINT_ERROR("Get performance level is not supported");
   1818     return false;
   1819 #endif
   1820 }
   1821 
   1822 bool omx_venc::dev_get_vui_timing_info(OMX_U32 *enabled)
   1823 {
   1824 #ifdef _MSM8974_
   1825     return handle->venc_get_vui_timing_info(enabled);
   1826 #else
   1827     DEBUG_PRINT_ERROR("Get vui timing information is not supported");
   1828     return false;
   1829 #endif
   1830 }
   1831 
   1832 bool omx_venc::dev_get_peak_bitrate(OMX_U32 *peakbitrate)
   1833 {
   1834 #ifdef _MSM8974_
   1835     return handle->venc_get_peak_bitrate(peakbitrate);
   1836 #else
   1837     DEBUG_PRINT_ERROR("Get peak bitrate is not supported");
   1838     return false;
   1839 #endif
   1840 }
   1841 
   1842 bool omx_venc::dev_loaded_start()
   1843 {
   1844     return handle->venc_loaded_start();
   1845 }
   1846 
   1847 bool omx_venc::dev_loaded_stop()
   1848 {
   1849     return handle->venc_loaded_stop();
   1850 }
   1851 
   1852 bool omx_venc::dev_loaded_start_done()
   1853 {
   1854     return handle->venc_loaded_start_done();
   1855 }
   1856 
   1857 bool omx_venc::dev_loaded_stop_done()
   1858 {
   1859     return handle->venc_loaded_stop_done();
   1860 }
   1861 
   1862 bool omx_venc::dev_get_buf_req(OMX_U32 *min_buff_count,
   1863         OMX_U32 *actual_buff_count,
   1864         OMX_U32 *buff_size,
   1865         OMX_U32 port)
   1866 {
   1867     return handle->venc_get_buf_req(min_buff_count,
   1868             actual_buff_count,
   1869             buff_size,
   1870             port);
   1871 
   1872 }
   1873 
   1874 bool omx_venc::dev_set_buf_req(OMX_U32 *min_buff_count,
   1875         OMX_U32 *actual_buff_count,
   1876         OMX_U32 *buff_size,
   1877         OMX_U32 port)
   1878 {
   1879     return handle->venc_set_buf_req(min_buff_count,
   1880             actual_buff_count,
   1881             buff_size,
   1882             port);
   1883 
   1884 }
   1885 
   1886 bool omx_venc::dev_is_video_session_supported(OMX_U32 width, OMX_U32 height)
   1887 {
   1888 #ifdef _MSM8974_
   1889     return handle->venc_is_video_session_supported(width,height);
   1890 #else
   1891     DEBUG_PRINT_LOW("Check against video capability not supported");
   1892     return true;
   1893 #endif
   1894 }
   1895 
   1896 #ifdef _MSM8974_
   1897 int omx_venc::dev_handle_extradata(void *buffer, int index)
   1898 {
   1899     return handle->handle_extradata(buffer, index);
   1900 }
   1901 
   1902 int omx_venc::dev_set_format(int color)
   1903 {
   1904     return handle->venc_set_format(color);
   1905 }
   1906 #endif
   1907 
   1908 int omx_venc::async_message_process (void *context, void* message)
   1909 {
   1910     omx_video* omx = NULL;
   1911     struct venc_msg *m_sVenc_msg = NULL;
   1912     OMX_BUFFERHEADERTYPE* omxhdr = NULL;
   1913     struct venc_buffer *temp_buff = NULL;
   1914 
   1915     if (context == NULL || message == NULL) {
   1916         DEBUG_PRINT_ERROR("ERROR: omx_venc::async_message_process invalid i/p params");
   1917         return -1;
   1918     }
   1919     m_sVenc_msg = (struct venc_msg *)message;
   1920 
   1921     omx = reinterpret_cast<omx_video*>(context);
   1922 
   1923     if (m_sVenc_msg->statuscode != VEN_S_SUCCESS) {
   1924         DEBUG_PRINT_ERROR("ERROR: async_msg_process() - Error statuscode = %lu",
   1925                 m_sVenc_msg->statuscode);
   1926         omx->omx_report_error();
   1927     }
   1928 
   1929     DEBUG_PRINT_LOW("omx_venc::async_message_process- msgcode = %lu",
   1930             m_sVenc_msg->msgcode);
   1931     switch (m_sVenc_msg->msgcode) {
   1932         case VEN_MSG_START:
   1933             omx->post_event (0,m_sVenc_msg->statuscode,\
   1934                     OMX_COMPONENT_GENERATE_START_DONE);
   1935             break;
   1936         case VEN_MSG_STOP:
   1937             omx->post_event (0,m_sVenc_msg->statuscode,\
   1938                     OMX_COMPONENT_GENERATE_STOP_DONE);
   1939             break;
   1940         case VEN_MSG_RESUME:
   1941             omx->post_event (0,m_sVenc_msg->statuscode,\
   1942                     OMX_COMPONENT_GENERATE_RESUME_DONE);
   1943             break;
   1944         case VEN_MSG_PAUSE:
   1945             omx->post_event (0,m_sVenc_msg->statuscode,\
   1946                     OMX_COMPONENT_GENERATE_PAUSE_DONE);
   1947             break;
   1948         case VEN_MSG_FLUSH_INPUT_DONE:
   1949 
   1950             omx->post_event (0,m_sVenc_msg->statuscode,\
   1951                     OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH);
   1952             break;
   1953         case VEN_MSG_FLUSH_OUPUT_DONE:
   1954             omx->post_event (0,m_sVenc_msg->statuscode,\
   1955                     OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH);
   1956             break;
   1957         case VEN_MSG_INPUT_BUFFER_DONE:
   1958             omxhdr = (OMX_BUFFERHEADERTYPE* )\
   1959                      m_sVenc_msg->buf.clientdata;
   1960 
   1961             if (omxhdr == NULL ||
   1962                     (((OMX_U32)(omxhdr - omx->m_inp_mem_ptr) > omx->m_sInPortDef.nBufferCountActual) &&
   1963                      ((OMX_U32)(omxhdr - omx->meta_buffer_hdr) > omx->m_sInPortDef.nBufferCountActual))) {
   1964                 omxhdr = NULL;
   1965                 m_sVenc_msg->statuscode = VEN_S_EFAIL;
   1966             }
   1967 
   1968 #ifdef _ANDROID_ICS_
   1969             omx->omx_release_meta_buffer(omxhdr);
   1970 #endif
   1971             omx->post_event ((unsigned long)omxhdr,m_sVenc_msg->statuscode,
   1972                     OMX_COMPONENT_GENERATE_EBD);
   1973             break;
   1974         case VEN_MSG_OUTPUT_BUFFER_DONE:
   1975             omxhdr = (OMX_BUFFERHEADERTYPE*)m_sVenc_msg->buf.clientdata;
   1976 
   1977             if ( (omxhdr != NULL) &&
   1978                     ((OMX_U32)(omxhdr - omx->m_out_mem_ptr)  < omx->m_sOutPortDef.nBufferCountActual)) {
   1979                 if (m_sVenc_msg->buf.len <=  omxhdr->nAllocLen) {
   1980                     omxhdr->nFilledLen = m_sVenc_msg->buf.len;
   1981                     omxhdr->nOffset = m_sVenc_msg->buf.offset;
   1982                     omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp;
   1983                     DEBUG_PRINT_LOW("o/p TS = %u", (unsigned int)m_sVenc_msg->buf.timestamp);
   1984                     omxhdr->nFlags = m_sVenc_msg->buf.flags;
   1985 
   1986                     /*Use buffer case*/
   1987                     if (omx->output_use_buffer && !omx->m_use_output_pmem) {
   1988                         DEBUG_PRINT_LOW("memcpy() for o/p Heap UseBuffer");
   1989                         memcpy(omxhdr->pBuffer,
   1990                                 (m_sVenc_msg->buf.ptrbuffer),
   1991                                 m_sVenc_msg->buf.len);
   1992                     }
   1993                 } else {
   1994                     omxhdr->nFilledLen = 0;
   1995                 }
   1996 
   1997             } else {
   1998                 omxhdr = NULL;
   1999                 m_sVenc_msg->statuscode = VEN_S_EFAIL;
   2000             }
   2001             omx->post_event ((unsigned long)omxhdr,m_sVenc_msg->statuscode,
   2002                     OMX_COMPONENT_GENERATE_FBD);
   2003             break;
   2004         case VEN_MSG_NEED_OUTPUT_BUFFER:
   2005             //TBD what action needs to be done here??
   2006             break;
   2007 #ifndef _MSM8974_
   2008         case VEN_MSG_LTRUSE_FAILED:
   2009             DEBUG_PRINT_ERROR("LTRUSE Failed!");
   2010             omx->post_event (NULL,m_sVenc_msg->statuscode,
   2011                     OMX_COMPONENT_GENERATE_LTRUSE_FAILED);
   2012             break;
   2013 #endif
   2014         default:
   2015             DEBUG_PRINT_HIGH("Unknown msg received : %lu", m_sVenc_msg->msgcode);
   2016             break;
   2017     }
   2018     return 0;
   2019 }
   2020 
   2021 bool omx_venc::dev_color_align(OMX_BUFFERHEADERTYPE *buffer,
   2022                 OMX_U32 width, OMX_U32 height)
   2023 {
   2024     if(secure_session) {
   2025         DEBUG_PRINT_ERROR("Cannot align colors in secure session.");
   2026         return OMX_FALSE;
   2027     }
   2028     return handle->venc_color_align(buffer, width,height);
   2029 }
   2030 
   2031 bool omx_venc::is_secure_session()
   2032 {
   2033     return secure_session;
   2034 }
   2035 
   2036 bool omx_venc::dev_get_output_log_flag()
   2037 {
   2038     return handle->venc_get_output_log_flag();
   2039 }
   2040 
   2041 int omx_venc::dev_output_log_buffers(const char *buffer, int bufferlen)
   2042 {
   2043     return handle->venc_output_log_buffers(buffer, bufferlen);
   2044 }
   2045 
   2046 int omx_venc::dev_extradata_log_buffers(char *buffer)
   2047 {
   2048     return handle->venc_extradata_log_buffers(buffer);
   2049 }
   2050