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