1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2010, Code Aurora Forum. 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 33 /*---------------------------------------------------------------------------- 34 * Preprocessor Definitions and Constants 35 * -------------------------------------------------------------------------*/ 36 37 #define OMX_SPEC_VERSION 0x00000101 38 #define OMX_INIT_STRUCT(_s_, _name_) \ 39 memset((_s_), 0x0, sizeof(_name_)); \ 40 (_s_)->nSize = sizeof(_name_); \ 41 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION 42 43 extern int m_pipe; 44 45 // factory function executed by the core to create instances 46 void *get_omx_component_factory_fn(void) 47 { 48 return(new omx_venc); 49 } 50 51 //constructor 52 53 omx_venc::omx_venc() 54 { 55 //nothing to do 56 } 57 58 omx_venc::~omx_venc() 59 { 60 //nothing to do 61 } 62 63 /* ====================================================================== 64 FUNCTION 65 omx_venc::ComponentInit 66 67 DESCRIPTION 68 Initialize the component. 69 70 PARAMETERS 71 ctxt -- Context information related to the self. 72 id -- Event identifier. This could be any of the following: 73 1. Command completion event 74 2. Buffer done callback event 75 3. Frame done callback event 76 77 RETURN VALUE 78 None. 79 80 ========================================================================== */ 81 OMX_ERRORTYPE omx_venc::component_init(OMX_STRING role) 82 { 83 84 OMX_ERRORTYPE eRet = OMX_ErrorNone; 85 86 int fds[2]; 87 int r; 88 89 OMX_VIDEO_CODINGTYPE codec_type; 90 91 DEBUG_PRINT_HIGH("\n omx_venc(): Inside component_init()"); 92 // Copy the role information which provides the decoder m_nkind 93 strncpy((char *)m_nkind,role,OMX_MAX_STRINGNAME_SIZE); 94 95 if(!strncmp((char *)m_nkind,"OMX.qcom.video.encoder.mpeg4",\ 96 OMX_MAX_STRINGNAME_SIZE)) 97 { 98 strncpy((char *)m_cRole, "video_encoder.mpeg4",\ 99 OMX_MAX_STRINGNAME_SIZE); 100 codec_type = OMX_VIDEO_CodingMPEG4; 101 } 102 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\ 103 OMX_MAX_STRINGNAME_SIZE)) 104 { 105 strncpy((char *)m_cRole, "video_encoder.h263",OMX_MAX_STRINGNAME_SIZE); 106 codec_type = OMX_VIDEO_CodingH263; 107 } 108 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\ 109 OMX_MAX_STRINGNAME_SIZE)) 110 { 111 strncpy((char *)m_cRole, "video_encoder.avc",OMX_MAX_STRINGNAME_SIZE); 112 codec_type = OMX_VIDEO_CodingAVC; 113 } 114 else 115 { 116 DEBUG_PRINT_ERROR("\nERROR: Unknown Component\n"); 117 eRet = OMX_ErrorInvalidComponentName; 118 } 119 120 121 if(eRet != OMX_ErrorNone) 122 { 123 return eRet; 124 } 125 126 handle = new venc_dev(); 127 128 if(handle == NULL) 129 { 130 DEBUG_PRINT_ERROR("\nERROR: handle is NULL"); 131 return OMX_ErrorInsufficientResources; 132 } 133 134 if(handle->venc_open(codec_type) != true) 135 { 136 DEBUG_PRINT_ERROR("\nERROR: venc_open failed"); 137 return OMX_ErrorInsufficientResources; 138 } 139 140 //Intialise the OMX layer variables 141 memset(&m_pCallbacks,0,sizeof(OMX_CALLBACKTYPE)); 142 143 OMX_INIT_STRUCT(&m_sPortParam, OMX_PORT_PARAM_TYPE); 144 m_sPortParam.nPorts = 0x2; 145 m_sPortParam.nStartPortNumber = (OMX_U32) PORT_INDEX_IN; 146 147 OMX_INIT_STRUCT(&m_sPortParam_audio, OMX_PORT_PARAM_TYPE); 148 m_sPortParam_audio.nPorts = 0; 149 m_sPortParam_audio.nStartPortNumber = 0; 150 151 OMX_INIT_STRUCT(&m_sPortParam_img, OMX_PORT_PARAM_TYPE); 152 m_sPortParam_img.nPorts = 0; 153 m_sPortParam_img.nStartPortNumber = 0; 154 155 OMX_INIT_STRUCT(&m_sParamBitrate, OMX_VIDEO_PARAM_BITRATETYPE); 156 m_sParamBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 157 m_sParamBitrate.eControlRate = OMX_Video_ControlRateVariableSkipFrames; 158 m_sParamBitrate.nTargetBitrate = 64000; 159 160 OMX_INIT_STRUCT(&m_sConfigBitrate, OMX_VIDEO_CONFIG_BITRATETYPE); 161 m_sConfigBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 162 m_sConfigBitrate.nEncodeBitrate = 64000; 163 164 OMX_INIT_STRUCT(&m_sConfigFramerate, OMX_CONFIG_FRAMERATETYPE); 165 m_sConfigFramerate.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 166 m_sConfigFramerate.xEncodeFramerate = 30 << 16; 167 168 OMX_INIT_STRUCT(&m_sConfigIntraRefreshVOP, OMX_CONFIG_INTRAREFRESHVOPTYPE); 169 m_sConfigIntraRefreshVOP.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 170 m_sConfigIntraRefreshVOP.IntraRefreshVOP = OMX_FALSE; 171 172 OMX_INIT_STRUCT(&m_sConfigFrameRotation, OMX_CONFIG_ROTATIONTYPE); 173 m_sConfigFrameRotation.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 174 m_sConfigFrameRotation.nRotation = 0; 175 176 OMX_INIT_STRUCT(&m_sSessionQuantization, OMX_VIDEO_PARAM_QUANTIZATIONTYPE); 177 m_sSessionQuantization.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 178 m_sSessionQuantization.nQpI = 9; 179 m_sSessionQuantization.nQpP = 6; 180 m_sSessionQuantization.nQpB = 2; 181 182 OMX_INIT_STRUCT(&m_sAVCSliceFMO, OMX_VIDEO_PARAM_AVCSLICEFMO); 183 m_sAVCSliceFMO.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 184 m_sAVCSliceFMO.eSliceMode = OMX_VIDEO_SLICEMODE_AVCDefault; 185 m_sAVCSliceFMO.nNumSliceGroups = 0; 186 m_sAVCSliceFMO.nSliceGroupMapType = 0; 187 OMX_INIT_STRUCT(&m_sParamProfileLevel, OMX_VIDEO_PARAM_PROFILELEVELTYPE); 188 m_sParamProfileLevel.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 189 190 if(codec_type == OMX_VIDEO_CodingMPEG4) 191 { 192 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_MPEG4ProfileSimple; 193 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_MPEG4Level0; 194 } 195 else if(codec_type == OMX_VIDEO_CodingH263) 196 { 197 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_H263ProfileBaseline; 198 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_H263Level10; 199 } 200 else if(codec_type == OMX_VIDEO_CodingAVC) 201 { 202 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_AVCProfileBaseline; 203 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_AVCLevel1; 204 } 205 206 // Initialize the video parameters for input port 207 OMX_INIT_STRUCT(&m_sInPortDef, OMX_PARAM_PORTDEFINITIONTYPE); 208 m_sInPortDef.nPortIndex= (OMX_U32) PORT_INDEX_IN; 209 m_sInPortDef.bEnabled = OMX_TRUE; 210 m_sInPortDef.bPopulated = OMX_FALSE; 211 m_sInPortDef.eDomain = OMX_PortDomainVideo; 212 m_sInPortDef.eDir = OMX_DirInput; 213 m_sInPortDef.format.video.cMIMEType = "YUV420"; 214 m_sInPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH; 215 m_sInPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT; 216 m_sInPortDef.format.video.nBitrate = 64000; 217 m_sInPortDef.format.video.xFramerate = 15 << 16; 218 m_sInPortDef.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; 219 m_sInPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; 220 221 if(dev_get_buf_req(&m_sInPortDef.nBufferCountMin, 222 &m_sInPortDef.nBufferCountActual, 223 &m_sInPortDef.nBufferSize, 224 m_sInPortDef.nPortIndex) != true) 225 { 226 eRet = OMX_ErrorUndefined; 227 228 } 229 230 // Initialize the video parameters for output port 231 OMX_INIT_STRUCT(&m_sOutPortDef, OMX_PARAM_PORTDEFINITIONTYPE); 232 m_sOutPortDef.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 233 m_sOutPortDef.bEnabled = OMX_TRUE; 234 m_sOutPortDef.bPopulated = OMX_FALSE; 235 m_sOutPortDef.eDomain = OMX_PortDomainVideo; 236 m_sOutPortDef.eDir = OMX_DirOutput; 237 m_sOutPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH; 238 m_sOutPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT; 239 m_sOutPortDef.format.video.nBitrate = 64000; 240 m_sOutPortDef.format.video.xFramerate = 15 << 16; 241 m_sOutPortDef.format.video.eColorFormat = OMX_COLOR_FormatUnused; 242 if(codec_type == OMX_VIDEO_CodingMPEG4) 243 { 244 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 245 } 246 else if(codec_type == OMX_VIDEO_CodingH263) 247 { 248 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 249 } 250 else 251 { 252 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; 253 } 254 if(dev_get_buf_req(&m_sOutPortDef.nBufferCountMin, 255 &m_sOutPortDef.nBufferCountActual, 256 &m_sOutPortDef.nBufferSize, 257 m_sOutPortDef.nPortIndex) != true) 258 { 259 eRet = OMX_ErrorUndefined; 260 } 261 262 // Initialize the video color format for input port 263 OMX_INIT_STRUCT(&m_sInPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE); 264 m_sInPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_IN; 265 m_sInPortFormat.nIndex = 0; 266 m_sInPortFormat.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; 267 m_sInPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused; 268 269 270 // Initialize the compression format for output port 271 OMX_INIT_STRUCT(&m_sOutPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE); 272 m_sOutPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 273 m_sOutPortFormat.nIndex = 0; 274 m_sOutPortFormat.eColorFormat = OMX_COLOR_FormatUnused; 275 if(codec_type == OMX_VIDEO_CodingMPEG4) 276 { 277 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 278 } 279 else if(codec_type == OMX_VIDEO_CodingH263) 280 { 281 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingH263; 282 } 283 else 284 { 285 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingAVC; 286 } 287 288 // mandatory Indices for kronos test suite 289 OMX_INIT_STRUCT(&m_sPriorityMgmt, OMX_PRIORITYMGMTTYPE); 290 291 OMX_INIT_STRUCT(&m_sInBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE); 292 m_sInBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_IN; 293 294 OMX_INIT_STRUCT(&m_sOutBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE); 295 m_sOutBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 296 297 298 // mp4 specific init 299 OMX_INIT_STRUCT(&m_sParamMPEG4, OMX_VIDEO_PARAM_MPEG4TYPE); 300 m_sParamMPEG4.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 301 m_sParamMPEG4.eProfile = OMX_VIDEO_MPEG4ProfileSimple; 302 m_sParamMPEG4.eLevel = OMX_VIDEO_MPEG4Level0; 303 m_sParamMPEG4.nSliceHeaderSpacing = 0; 304 m_sParamMPEG4.bSVH = OMX_FALSE; 305 m_sParamMPEG4.bGov = OMX_FALSE; 306 m_sParamMPEG4.nPFrames = 29; // 2 second intra period for default 15 fps 307 m_sParamMPEG4.bACPred = OMX_TRUE; 308 m_sParamMPEG4.nTimeIncRes = 30; // delta = 2 @ 15 fps 309 m_sParamMPEG4.nAllowedPictureTypes = 2; // pframe and iframe 310 m_sParamMPEG4.nHeaderExtension = 1; // number of video packet headers per vop 311 m_sParamMPEG4.bReversibleVLC = OMX_FALSE; 312 313 // h263 specific init 314 OMX_INIT_STRUCT(&m_sParamH263, OMX_VIDEO_PARAM_H263TYPE); 315 m_sParamH263.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 316 m_sParamH263.nPFrames = 29; 317 m_sParamH263.nBFrames = 0; 318 m_sParamH263.eProfile = OMX_VIDEO_H263ProfileBaseline; 319 m_sParamH263.eLevel = OMX_VIDEO_H263Level10; 320 m_sParamH263.bPLUSPTYPEAllowed = OMX_FALSE; 321 m_sParamH263.nAllowedPictureTypes = 2; 322 m_sParamH263.bForceRoundingTypeToZero = OMX_TRUE; ///@todo determine what this should be 323 m_sParamH263.nPictureHeaderRepetition = 0; ///@todo determine what this should be 324 m_sParamH263.nGOBHeaderInterval = 0; ///@todo determine what this should be 325 326 // h264 specific init 327 OMX_INIT_STRUCT(&m_sParamH263, OMX_VIDEO_PARAM_AVCTYPE); 328 m_sParamAVC.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 329 m_sParamAVC.nSliceHeaderSpacing = 330 m_sParamAVC.nPFrames = 29; 331 m_sParamAVC.nBFrames = 0; 332 m_sParamAVC.bUseHadamard = OMX_FALSE;//todo: to decide the value 333 m_sParamAVC.nRefFrames = 0; //todo: to decide the value 334 m_sParamAVC.nRefIdx10ActiveMinus1 = 0; //todo: to decide the value 335 m_sParamAVC.nRefIdx11ActiveMinus1 = 0; //todo: to decide the value 336 m_sParamAVC.bEnableUEP = OMX_FALSE; //todo: to decide the value 337 m_sParamAVC.bEnableFMO = OMX_FALSE;//todo: to decide the value 338 m_sParamAVC.bEnableASO = OMX_FALSE; //todo: to decide the value 339 m_sParamAVC.bEnableRS = OMX_FALSE;//todo: to decide the value 340 m_sParamAVC.eProfile = OMX_VIDEO_AVCProfileBaseline; 341 m_sParamAVC.eLevel = OMX_VIDEO_AVCLevel1; 342 m_sParamAVC.nAllowedPictureTypes = 2; 343 m_sParamAVC.bFrameMBsOnly = OMX_FALSE; //todo: to decide the value 344 m_sParamAVC.bMBAFF = OMX_FALSE; //todo: to decide the value 345 m_sParamAVC.bEntropyCodingCABAC = OMX_FALSE; //todo: to decide the value 346 m_sParamAVC.bWeightedPPrediction = OMX_FALSE; //todo: to decide the value 347 m_sParamAVC.nWeightedBipredicitonMode = 0;//todo: to decide the value 348 m_sParamAVC.bconstIpred = OMX_FALSE;//todo: to decide the value 349 m_sParamAVC.bDirect8x8Inference = OMX_FALSE; //todo: to decide the value 350 m_sParamAVC.bDirectSpatialTemporal = OMX_FALSE; //todo: to decide the value 351 m_sParamAVC.nCabacInitIdc = 0; //todo: to decide the value 352 //m_sParamAVC.eLoopFilterMode = 0; //todo: to decide the value 353 354 m_state = OMX_StateLoaded; 355 356 if(eRet == OMX_ErrorNone) 357 { 358 if(pipe(fds)) 359 { 360 DEBUG_PRINT_ERROR("ERROR: pipe creation failed\n"); 361 eRet = OMX_ErrorInsufficientResources; 362 } 363 else 364 { 365 if(fds[0] == 0 || fds[1] == 0) 366 { 367 if(pipe(fds)) 368 { 369 DEBUG_PRINT_ERROR("ERROR: pipe creation failed\n"); 370 eRet = OMX_ErrorInsufficientResources; 371 } 372 } 373 if(eRet == OMX_ErrorNone) 374 { 375 m_pipe_in = fds[0]; 376 m_pipe_out = fds[1]; 377 } 378 } 379 r = pthread_create(&msg_thread_id,0,message_thread,this); 380 381 if(r < 0) 382 { 383 eRet = OMX_ErrorInsufficientResources; 384 } 385 else 386 { 387 r = pthread_create(&async_thread_id,0,async_venc_message_thread,this); 388 if(r < 0) 389 { 390 eRet = OMX_ErrorInsufficientResources; 391 } 392 } 393 } 394 395 DEBUG_PRINT_HIGH("\n Component_init return value = 0x%x", eRet); 396 return eRet; 397 } 398 399 400 /* ====================================================================== 401 FUNCTION 402 omx_venc::Setparameter 403 404 DESCRIPTION 405 OMX Set Parameter method implementation. 406 407 PARAMETERS 408 <TBD>. 409 410 RETURN VALUE 411 OMX Error None if successful. 412 413 ========================================================================== */ 414 OMX_ERRORTYPE omx_venc::set_parameter(OMX_IN OMX_HANDLETYPE hComp, 415 OMX_IN OMX_INDEXTYPE paramIndex, 416 OMX_IN OMX_PTR paramData) 417 { 418 OMX_ERRORTYPE eRet = OMX_ErrorNone; 419 420 421 if(m_state == OMX_StateInvalid) 422 { 423 DEBUG_PRINT_ERROR("ERROR: Set Param in Invalid State\n"); 424 return OMX_ErrorInvalidState; 425 } 426 if(paramData == NULL) 427 { 428 DEBUG_PRINT_ERROR("ERROR: Get Param in Invalid paramData \n"); 429 return OMX_ErrorBadParameter; 430 } 431 432 /*set_parameter can be called in loaded state 433 or disabled port */ 434 if(m_state == OMX_StateLoaded 435 || m_sInPortDef.bEnabled == OMX_FALSE 436 || m_sOutPortDef.bEnabled == OMX_FALSE) 437 { 438 DEBUG_PRINT_LOW("Set Parameter called in valid state"); 439 } 440 else 441 { 442 DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State\n"); 443 return OMX_ErrorIncorrectStateOperation; 444 } 445 446 switch(paramIndex) 447 { 448 case OMX_IndexParamPortDefinition: 449 { 450 OMX_PARAM_PORTDEFINITIONTYPE *portDefn; 451 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; 452 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d\n", 453 (int)portDefn->format.video.nFrameHeight, 454 (int)portDefn->format.video.nFrameWidth); 455 456 if(PORT_INDEX_IN == portDefn->nPortIndex) 457 { 458 DEBUG_PRINT_LOW("\n i/p actual cnt requested = %d\n", portDefn->nBufferCountActual); 459 DEBUG_PRINT_LOW("\n i/p min cnt requested = %d\n", portDefn->nBufferCountMin); 460 DEBUG_PRINT_LOW("\n i/p buffersize requested = %d\n", portDefn->nBufferSize); 461 if(handle->venc_set_param(paramData,OMX_IndexParamPortDefinition) != true) 462 { 463 DEBUG_PRINT_ERROR("\nERROR: venc_set_param input failed"); 464 return OMX_ErrorUnsupportedSetting; 465 } 466 467 DEBUG_PRINT_LOW("\n i/p previous actual cnt = %d\n", m_sInPortDef.nBufferCountActual); 468 DEBUG_PRINT_LOW("\n i/p previous min cnt = %d\n", m_sInPortDef.nBufferCountMin); 469 m_sInPortDef.format.video.nFrameWidth = portDefn->format.video.nFrameWidth; 470 m_sInPortDef.format.video.nFrameHeight = portDefn->format.video.nFrameHeight; 471 m_sInPortDef.format.video.xFramerate = portDefn->format.video.xFramerate; 472 m_sInPortDef.format.video.nBitrate = portDefn->format.video.nBitrate; 473 m_sInPortDef.format.video.eColorFormat = portDefn->format.video.eColorFormat; 474 475 476 /*Query Input Buffer Requirements*/ 477 dev_get_buf_req (&m_sInPortDef.nBufferCountMin, 478 &m_sInPortDef.nBufferCountActual, 479 &m_sInPortDef.nBufferSize, 480 m_sInPortDef.nPortIndex); 481 482 /*Query ouput Buffer Requirements*/ 483 dev_get_buf_req (&m_sOutPortDef.nBufferCountMin, 484 &m_sOutPortDef.nBufferCountActual, 485 &m_sOutPortDef.nBufferSize, 486 m_sOutPortDef.nPortIndex); 487 m_sInPortDef.nBufferCountActual = portDefn->nBufferCountActual; 488 } 489 else if(PORT_INDEX_OUT == portDefn->nPortIndex) 490 { 491 DEBUG_PRINT_LOW("\n o/p actual cnt requested = %d\n", portDefn->nBufferCountActual); 492 DEBUG_PRINT_LOW("\n o/p min cnt requested = %d\n", portDefn->nBufferCountMin); 493 DEBUG_PRINT_LOW("\n o/p buffersize requested = %d\n", portDefn->nBufferSize); 494 if(handle->venc_set_param(paramData,OMX_IndexParamPortDefinition) != true) 495 { 496 DEBUG_PRINT_ERROR("\nERROR: venc_set_param output failed"); 497 return OMX_ErrorUnsupportedSetting; 498 } 499 500 DEBUG_PRINT_LOW("\n o/p previous actual cnt = %d\n", m_sOutPortDef.nBufferCountActual); 501 DEBUG_PRINT_LOW("\n o/p previous min cnt = %d\n", m_sOutPortDef.nBufferCountMin); 502 m_sOutPortDef.nBufferCountActual = portDefn->nBufferCountActual; 503 } 504 else 505 { 506 DEBUG_PRINT_ERROR("ERROR: Set_parameter: Bad Port idx %d", 507 (int)portDefn->nPortIndex); 508 eRet = OMX_ErrorBadPortIndex; 509 } 510 m_sConfigFramerate.xEncodeFramerate = portDefn->format.video.xFramerate; 511 m_sConfigBitrate.nEncodeBitrate = portDefn->format.video.nBitrate; 512 m_sParamBitrate.nTargetBitrate = portDefn->format.video.nBitrate; 513 } 514 break; 515 516 case OMX_IndexParamVideoPortFormat: 517 { 518 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = 519 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; 520 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d\n", 521 portFmt->eColorFormat); 522 //set the driver with the corresponding values 523 if(PORT_INDEX_IN == portFmt->nPortIndex) 524 { 525 if(handle->venc_set_param(paramData,OMX_IndexParamVideoPortFormat) != true) 526 { 527 return OMX_ErrorUnsupportedSetting; 528 } 529 530 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d\n", 531 portFmt->eColorFormat); 532 533 m_sInPortFormat.eColorFormat = portFmt->eColorFormat; 534 m_sInPortFormat.xFramerate = portFmt->xFramerate; 535 } 536 //TODO if no use case for O/P port,delet m_sOutPortFormat 537 } 538 break; 539 case OMX_IndexParamVideoInit: 540 { //TODO, do we need this index set param 541 OMX_PORT_PARAM_TYPE* pParam = (OMX_PORT_PARAM_TYPE*)(paramData); 542 DEBUG_PRINT_LOW("\n Set OMX_IndexParamVideoInit called"); 543 break; 544 } 545 546 case OMX_IndexParamVideoBitrate: 547 { 548 OMX_VIDEO_PARAM_BITRATETYPE* pParam = (OMX_VIDEO_PARAM_BITRATETYPE*)paramData; 549 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoBitrate"); 550 if(handle->venc_set_param(paramData,OMX_IndexParamVideoBitrate) != true) 551 { 552 return OMX_ErrorUnsupportedSetting; 553 } 554 m_sParamBitrate.nTargetBitrate = pParam->nTargetBitrate; 555 m_sParamBitrate.eControlRate = pParam->eControlRate; 556 557 m_sConfigBitrate.nEncodeBitrate = pParam->nTargetBitrate; 558 m_sInPortDef.format.video.nBitrate = pParam->nTargetBitrate; 559 m_sOutPortDef.format.video.nBitrate = pParam->nTargetBitrate; 560 DEBUG_PRINT_LOW("\nbitrate = %u", m_sOutPortDef.format.video.nBitrate); 561 break; 562 } 563 case OMX_IndexParamVideoMpeg4: 564 { 565 OMX_VIDEO_PARAM_MPEG4TYPE* pParam = (OMX_VIDEO_PARAM_MPEG4TYPE*)paramData; 566 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4"); 567 if(handle->venc_set_param(paramData,OMX_IndexParamVideoMpeg4) != true) 568 { 569 return OMX_ErrorUnsupportedSetting; 570 } 571 //.. more than one variable storing the npframes,profile,level details 572 m_sParamMPEG4.nPFrames = pParam->nPFrames; 573 m_sParamMPEG4.eProfile = pParam->eProfile; 574 m_sParamMPEG4.eLevel = pParam->eLevel; 575 m_sParamMPEG4.bACPred = pParam->bACPred; 576 m_sParamMPEG4.nTimeIncRes = pParam->nTimeIncRes; 577 m_sParamMPEG4.bReversibleVLC = pParam->bReversibleVLC; 578 579 m_sParamProfileLevel.eProfile = pParam->eProfile; 580 m_sParamProfileLevel.eLevel = pParam->eLevel; 581 break; 582 } 583 case OMX_IndexParamVideoH263: 584 { 585 OMX_VIDEO_PARAM_H263TYPE* pParam = (OMX_VIDEO_PARAM_H263TYPE*)paramData; 586 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263"); 587 if(handle->venc_set_param(paramData,OMX_IndexParamVideoH263) != true) 588 { 589 return OMX_ErrorUnsupportedSetting; 590 } 591 //.. more than one variable storing the npframes,profile,level details 592 m_sParamH263.nPFrames = pParam->nPFrames; 593 m_sParamH263.eProfile = pParam->eProfile; 594 m_sParamH263.eLevel = pParam->eLevel; 595 596 m_sParamProfileLevel.eProfile = pParam->eProfile; 597 m_sParamProfileLevel.eLevel = pParam->eLevel; 598 break; 599 } 600 case OMX_IndexParamVideoAvc: 601 { 602 OMX_VIDEO_PARAM_AVCTYPE* pParam = (OMX_VIDEO_PARAM_AVCTYPE*)paramData; 603 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoAvc"); 604 if(handle->venc_set_param(paramData,OMX_IndexParamVideoAvc) != true) 605 { 606 return OMX_ErrorUnsupportedSetting; 607 } 608 //.. more than one variable storing the npframes,profile,level details 609 m_sParamAVC.nPFrames = pParam->nPFrames; 610 m_sParamAVC.eProfile = pParam->eProfile; 611 m_sParamAVC.eLevel = pParam->eLevel; 612 613 m_sParamProfileLevel.eProfile = pParam->eProfile; 614 m_sParamProfileLevel.eLevel = pParam->eLevel; 615 break; 616 } 617 case OMX_IndexParamVideoProfileLevelCurrent: 618 { 619 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData; 620 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoProfileLevelCurrent"); 621 if(handle->venc_set_param(paramData,OMX_IndexParamVideoProfileLevelCurrent) != true) 622 { 623 return OMX_ErrorUnsupportedSetting; 624 } 625 m_sParamProfileLevel.eProfile = pParam->eProfile; 626 m_sParamProfileLevel.eLevel = pParam->eLevel; 627 628 if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.mpeg4",\ 629 OMX_MAX_STRINGNAME_SIZE)) 630 { 631 m_sParamMPEG4.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)m_sParamProfileLevel.eProfile; 632 m_sParamMPEG4.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)m_sParamProfileLevel.eLevel; 633 DEBUG_PRINT_LOW("\n MPEG4 profile = %d, level = %d", m_sParamMPEG4.eProfile, 634 m_sParamMPEG4.eLevel); 635 } 636 else if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.h263",\ 637 OMX_MAX_STRINGNAME_SIZE)) 638 { 639 m_sParamH263.eProfile = (OMX_VIDEO_H263PROFILETYPE)m_sParamProfileLevel.eProfile; 640 m_sParamH263.eLevel = (OMX_VIDEO_H263LEVELTYPE)m_sParamProfileLevel.eLevel; 641 DEBUG_PRINT_LOW("\n H263 profile = %d, level = %d", m_sParamH263.eProfile, 642 m_sParamH263.eLevel); 643 } 644 else 645 { 646 m_sParamAVC.eProfile = (OMX_VIDEO_AVCPROFILETYPE)m_sParamProfileLevel.eProfile; 647 m_sParamAVC.eLevel = (OMX_VIDEO_AVCLEVELTYPE)m_sParamProfileLevel.eLevel; 648 DEBUG_PRINT_LOW("\n AVC profile = %d, level = %d", m_sParamAVC.eProfile, 649 m_sParamAVC.eLevel); 650 } 651 break; 652 } 653 case OMX_IndexParamStandardComponentRole: 654 { 655 OMX_PARAM_COMPONENTROLETYPE *comp_role; 656 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; 657 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s\n", 658 comp_role->cRole); 659 660 if((m_state == OMX_StateLoaded)&& 661 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) 662 { 663 DEBUG_PRINT_LOW("Set Parameter called in valid state"); 664 } 665 else 666 { 667 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State\n"); 668 return OMX_ErrorIncorrectStateOperation; 669 } 670 671 if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.avc",OMX_MAX_STRINGNAME_SIZE)) 672 { 673 if(!strncmp((char*)comp_role->cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE)) 674 { 675 strncpy((char*)m_cRole,"video_encoder.avc",OMX_MAX_STRINGNAME_SIZE); 676 } 677 else 678 { 679 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole); 680 eRet =OMX_ErrorUnsupportedSetting; 681 } 682 } 683 else if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) 684 { 685 if(!strncmp((const char*)comp_role->cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) 686 { 687 strncpy((char*)m_cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); 688 } 689 else 690 { 691 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole); 692 eRet = OMX_ErrorUnsupportedSetting; 693 } 694 } 695 else if(!strncmp((char*)m_nkind, "OMX.qcom.video.encoder.h263",OMX_MAX_STRINGNAME_SIZE)) 696 { 697 if(!strncmp((const char*)comp_role->cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE)) 698 { 699 strncpy((char*)m_cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE); 700 } 701 else 702 { 703 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s\n", comp_role->cRole); 704 eRet =OMX_ErrorUnsupportedSetting; 705 } 706 } 707 else 708 { 709 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %s\n", m_nkind); 710 eRet = OMX_ErrorInvalidComponentName; 711 } 712 break; 713 } 714 715 case OMX_IndexParamPriorityMgmt: 716 { 717 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt"); 718 if(m_state != OMX_StateLoaded) 719 { 720 DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State\n"); 721 return OMX_ErrorIncorrectStateOperation; 722 } 723 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData; 724 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %d\n", 725 priorityMgmtype->nGroupID); 726 727 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %d\n", 728 priorityMgmtype->nGroupPriority); 729 730 m_sPriorityMgmt.nGroupID = priorityMgmtype->nGroupID; 731 m_sPriorityMgmt.nGroupPriority = priorityMgmtype->nGroupPriority; 732 733 break; 734 } 735 736 case OMX_IndexParamCompBufferSupplier: 737 { 738 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier"); 739 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; 740 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d\n", 741 bufferSupplierType->eBufferSupplier); 742 if(bufferSupplierType->nPortIndex == 0 || bufferSupplierType->nPortIndex ==1) 743 m_sInBufSupplier.eBufferSupplier = bufferSupplierType->eBufferSupplier; 744 745 else 746 747 eRet = OMX_ErrorBadPortIndex; 748 749 break; 750 751 } 752 case OMX_IndexParamVideoQuantization: 753 { 754 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoQuantization\n"); 755 OMX_VIDEO_PARAM_QUANTIZATIONTYPE *session_qp = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) paramData; 756 if(session_qp->nPortIndex == PORT_INDEX_OUT) 757 { 758 if(handle->venc_set_param(paramData, OMX_IndexParamVideoQuantization) != true) 759 { 760 return OMX_ErrorUnsupportedSetting; 761 } 762 m_sSessionQuantization.nQpI = session_qp->nQpI; 763 m_sSessionQuantization.nQpP = session_qp->nQpP; 764 } 765 else 766 { 767 DEBUG_PRINT_ERROR("\nERROR: Unsupported port Index for Session QP setting\n"); 768 eRet = OMX_ErrorBadPortIndex; 769 } 770 break; 771 } 772 773 case OMX_QcomIndexPortDefn: 774 { 775 OMX_QCOM_PARAM_PORTDEFINITIONTYPE* pParam = 776 (OMX_QCOM_PARAM_PORTDEFINITIONTYPE*)paramData; 777 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexPortDefn"); 778 if(pParam->nPortIndex == (OMX_U32)PORT_INDEX_IN) 779 { 780 if(pParam->nMemRegion > OMX_QCOM_MemRegionInvalid && 781 pParam->nMemRegion < OMX_QCOM_MemRegionMax) 782 { 783 m_use_input_pmem = OMX_TRUE; 784 } 785 else 786 { 787 m_use_input_pmem = OMX_FALSE; 788 } 789 } 790 else if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_OUT) 791 { 792 if(pParam->nMemRegion > OMX_QCOM_MemRegionInvalid && 793 pParam->nMemRegion < OMX_QCOM_MemRegionMax) 794 { 795 m_use_output_pmem = OMX_TRUE; 796 } 797 else 798 { 799 m_use_output_pmem = OMX_FALSE; 800 } 801 } 802 else 803 { 804 DEBUG_PRINT_ERROR("ERROR: SetParameter called on unsupported Port Index for QcomPortDefn"); 805 return OMX_ErrorBadPortIndex; 806 } 807 break; 808 } 809 //#endif //# QCOM_EXT 810 case OMX_IndexParamVideoSliceFMO: 811 { 812 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoSliceFMO\n"); 813 OMX_VIDEO_PARAM_AVCSLICEFMO *avc_slice_fmo = (OMX_VIDEO_PARAM_AVCSLICEFMO*)paramData; 814 if(!strncmp((char *)m_nkind, "OMX.qcom.video.encoder.avc",\ 815 OMX_MAX_STRINGNAME_SIZE) && avc_slice_fmo->nPortIndex == PORT_INDEX_OUT) 816 { 817 if(handle->venc_set_param(paramData, OMX_IndexParamVideoSliceFMO) != true) 818 { 819 return OMX_ErrorUnsupportedSetting; 820 } 821 m_sAVCSliceFMO.eSliceMode = avc_slice_fmo->eSliceMode; 822 } 823 else 824 { 825 DEBUG_PRINT_ERROR("\nERROR: Unsupported codec type/port Index for AVCSliceFMO setting\n"); 826 eRet = OMX_ErrorBadPortIndex; 827 } 828 break; 829 } 830 case OMX_IndexParamVideoErrorCorrection: 831 { 832 DEBUG_PRINT_ERROR("ERROR: OMX_IndexParamVideoErrorCorrection unsupported\n"); 833 eRet = OMX_ErrorUnsupportedIndex; 834 break; 835 } 836 case OMX_IndexParamVideoIntraRefresh: 837 { 838 DEBUG_PRINT_ERROR("ERROR: OMX_IndexParamVideoIntraRefresh unsupported\n"); 839 eRet = OMX_ErrorUnsupportedIndex; 840 break; 841 } 842 default: 843 { 844 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %d\n", paramIndex); 845 eRet = OMX_ErrorUnsupportedIndex; 846 break; 847 } 848 } 849 return eRet; 850 } 851 852 /* ====================================================================== 853 FUNCTION 854 omx_video::SetConfig 855 856 DESCRIPTION 857 OMX Set Config method implementation 858 859 PARAMETERS 860 <TBD>. 861 862 RETURN VALUE 863 OMX Error None if successful. 864 ========================================================================== */ 865 OMX_ERRORTYPE omx_venc::set_config(OMX_IN OMX_HANDLETYPE hComp, 866 OMX_IN OMX_INDEXTYPE configIndex, 867 OMX_IN OMX_PTR configData) 868 { 869 if(configData == NULL) 870 { 871 DEBUG_PRINT_ERROR("ERROR: param is null"); 872 return OMX_ErrorBadParameter; 873 } 874 875 if(m_state == OMX_StateInvalid) 876 { 877 DEBUG_PRINT_ERROR("ERROR: config called in Invalid state"); 878 return OMX_ErrorIncorrectStateOperation; 879 } 880 881 // params will be validated prior to venc_init 882 switch(configIndex) 883 { 884 case OMX_IndexConfigVideoBitrate: 885 { 886 OMX_VIDEO_CONFIG_BITRATETYPE* pParam = 887 reinterpret_cast<OMX_VIDEO_CONFIG_BITRATETYPE*>(configData); 888 DEBUG_PRINT_LOW("\n omx_venc:: set_config(): OMX_IndexConfigVideoBitrate"); 889 890 if(pParam->nPortIndex == PORT_INDEX_OUT) 891 { 892 if(handle->venc_set_config(configData, OMX_IndexConfigVideoBitrate) != true) 893 { 894 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoBitrate failed"); 895 return OMX_ErrorUnsupportedSetting; 896 } 897 898 m_sConfigBitrate.nEncodeBitrate = pParam->nEncodeBitrate; 899 m_sParamBitrate.nTargetBitrate = pParam->nEncodeBitrate; 900 m_sOutPortDef.format.video.nBitrate = pParam->nEncodeBitrate; 901 } 902 else 903 { 904 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex); 905 return OMX_ErrorBadPortIndex; 906 } 907 break; 908 } 909 case OMX_IndexConfigVideoFramerate: 910 { 911 OMX_CONFIG_FRAMERATETYPE* pParam = 912 reinterpret_cast<OMX_CONFIG_FRAMERATETYPE*>(configData); 913 DEBUG_PRINT_LOW("\n omx_venc:: set_config(): OMX_IndexConfigVideoFramerate"); 914 915 if(pParam->nPortIndex == PORT_INDEX_OUT) 916 { 917 if(handle->venc_set_config(configData, OMX_IndexConfigVideoFramerate) != true) 918 { 919 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoFramerate failed"); 920 return OMX_ErrorUnsupportedSetting; 921 } 922 923 m_sConfigFramerate.xEncodeFramerate = pParam->xEncodeFramerate; 924 m_sOutPortDef.format.video.xFramerate = pParam->xEncodeFramerate; 925 m_sOutPortFormat.xFramerate = pParam->xEncodeFramerate; 926 } 927 else 928 { 929 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex); 930 return OMX_ErrorBadPortIndex; 931 } 932 933 break; 934 } 935 case OMX_IndexConfigVideoIntraVOPRefresh: 936 { 937 OMX_CONFIG_INTRAREFRESHVOPTYPE* pParam = 938 reinterpret_cast<OMX_CONFIG_INTRAREFRESHVOPTYPE*>(configData); 939 940 if(pParam->nPortIndex == PORT_INDEX_OUT) 941 { 942 if(handle->venc_set_config(configData, 943 OMX_IndexConfigVideoIntraVOPRefresh) != true) 944 { 945 DEBUG_PRINT_ERROR("ERROR: Setting OMX_IndexConfigVideoIntraVOPRefresh failed"); 946 return OMX_ErrorUnsupportedSetting; 947 } 948 949 m_sConfigIntraRefreshVOP.IntraRefreshVOP = pParam->IntraRefreshVOP; 950 } 951 else 952 { 953 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex); 954 return OMX_ErrorBadPortIndex; 955 } 956 957 break; 958 } 959 case OMX_IndexConfigCommonRotate: 960 { 961 DEBUG_PRINT_ERROR("ERROR: OMX_IndexConfigCommonRotate is currently unsupported"); 962 break; 963 } 964 default: 965 DEBUG_PRINT_ERROR("ERROR: unsupported index %d", (int) configIndex); 966 break; 967 } 968 969 return OMX_ErrorNone; 970 } 971 972 /* ====================================================================== 973 FUNCTION 974 omx_venc::ComponentDeInit 975 976 DESCRIPTION 977 Destroys the component and release memory allocated to the heap. 978 979 PARAMETERS 980 <TBD>. 981 982 RETURN VALUE 983 OMX Error None if everything successful. 984 985 ========================================================================== */ 986 OMX_ERRORTYPE omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp) 987 { 988 OMX_U32 i = 0; 989 DEBUG_PRINT_HIGH("\n omx_venc(): Inside component_deinit()"); 990 if(OMX_StateLoaded != m_state) 991 { 992 DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d\n",\ 993 m_state); 994 } 995 if(m_out_mem_ptr) 996 { 997 DEBUG_PRINT_LOW("Freeing the Output Memory\n"); 998 for(i=0; i< m_sOutPortDef.nBufferCountActual; i++ ) 999 { 1000 free_output_buffer (&m_out_mem_ptr[i]); 1001 } 1002 free(m_out_mem_ptr); 1003 m_out_mem_ptr = NULL; 1004 } 1005 1006 /*Check if the input buffers have to be cleaned up*/ 1007 if(m_inp_mem_ptr) 1008 { 1009 DEBUG_PRINT_LOW("Freeing the Input Memory\n"); 1010 for(i=0; i<m_sInPortDef.nBufferCountActual; i++ ) 1011 { 1012 free_input_buffer (&m_inp_mem_ptr[i]); 1013 } 1014 1015 1016 free(m_inp_mem_ptr); 1017 m_inp_mem_ptr = NULL; 1018 } 1019 1020 // Reset counters in mesg queues 1021 m_ftb_q.m_size=0; 1022 m_cmd_q.m_size=0; 1023 m_etb_q.m_size=0; 1024 m_ftb_q.m_read = m_ftb_q.m_write =0; 1025 m_cmd_q.m_read = m_cmd_q.m_write =0; 1026 m_etb_q.m_read = m_etb_q.m_write =0; 1027 1028 #ifdef _ANDROID_ 1029 // Clear the strong reference 1030 DEBUG_PRINT_HIGH("Calling m_heap_ptr.clear()\n"); 1031 m_heap_ptr.clear(); 1032 #endif // _ANDROID_ 1033 DEBUG_PRINT_HIGH("Calling venc_close()\n"); 1034 handle->venc_close(); 1035 DEBUG_PRINT_HIGH("Deleting HANDLE[%p]\n", handle); 1036 delete (handle); 1037 DEBUG_PRINT_HIGH("OMX_Venc:Component Deinit\n"); 1038 return OMX_ErrorNone; 1039 } 1040 1041 1042 OMX_U32 omx_venc::dev_stop( void) 1043 { 1044 return handle->venc_stop(); 1045 } 1046 1047 1048 OMX_U32 omx_venc::dev_pause(void) 1049 { 1050 return handle->venc_pause(); 1051 } 1052 1053 OMX_U32 omx_venc::dev_start(void) 1054 { 1055 return handle->venc_start(); 1056 } 1057 1058 OMX_U32 omx_venc::dev_flush(unsigned port) 1059 { 1060 return handle->venc_flush(port); 1061 } 1062 OMX_U32 omx_venc::dev_resume(void) 1063 { 1064 return handle->venc_resume(); 1065 } 1066 1067 bool omx_venc::dev_use_buf(void *buf_addr,unsigned port) 1068 { 1069 return handle->venc_use_buf(buf_addr,port); 1070 } 1071 1072 bool omx_venc::dev_free_buf(void *buf_addr,unsigned port) 1073 { 1074 return handle->venc_free_buf(buf_addr,port); 1075 } 1076 1077 bool omx_venc::dev_empty_buf(void *buffer, void *pmem_data_buf) 1078 { 1079 return handle->venc_empty_buf(buffer, pmem_data_buf); 1080 } 1081 1082 bool omx_venc::dev_fill_buf(void *buffer, void *pmem_data_buf) 1083 { 1084 return handle->venc_fill_buf(buffer, pmem_data_buf); 1085 } 1086 1087 1088 bool omx_venc::dev_get_buf_req(OMX_U32 *min_buff_count, 1089 OMX_U32 *actual_buff_count, 1090 OMX_U32 *buff_size, 1091 OMX_U32 port) 1092 { 1093 return handle->venc_get_buf_req(min_buff_count, 1094 actual_buff_count, 1095 buff_size, 1096 port); 1097 1098 } 1099 1100 bool omx_venc::dev_set_buf_req(OMX_U32 *min_buff_count, 1101 OMX_U32 *actual_buff_count, 1102 OMX_U32 *buff_size, 1103 OMX_U32 port) 1104 { 1105 return handle->venc_set_buf_req(min_buff_count, 1106 actual_buff_count, 1107 buff_size, 1108 port); 1109 1110 } 1111 1112 int omx_venc::async_message_process (void *context, void* message) 1113 { 1114 omx_video* omx = NULL; 1115 struct venc_msg *m_sVenc_msg = NULL; 1116 OMX_BUFFERHEADERTYPE* omxhdr = NULL; 1117 struct venc_buffer *temp_buff = NULL; 1118 1119 if(context == NULL || message == NULL) 1120 { 1121 DEBUG_PRINT_ERROR("\nERROR: omx_venc::async_message_process invalid i/p params"); 1122 return -1; 1123 } 1124 m_sVenc_msg = (struct venc_msg *)message; 1125 1126 omx = reinterpret_cast<omx_video*>(context); 1127 1128 if(m_sVenc_msg->statuscode != VEN_S_SUCCESS) 1129 { 1130 DEBUG_PRINT_ERROR("\nERROR: async_msg_process() - Error statuscode = %d\n", 1131 m_sVenc_msg->statuscode); 1132 omx->omx_report_error(); 1133 } 1134 1135 DEBUG_PRINT_LOW("\n omx_venc::async_message_process- msgcode = %d\n", 1136 m_sVenc_msg->msgcode); 1137 switch(m_sVenc_msg->msgcode) 1138 { 1139 1140 case VEN_MSG_START: 1141 omx->post_event (NULL,m_sVenc_msg->statuscode,\ 1142 OMX_COMPONENT_GENERATE_START_DONE); 1143 break; 1144 1145 case VEN_MSG_STOP: 1146 omx->post_event (NULL,m_sVenc_msg->statuscode,\ 1147 OMX_COMPONENT_GENERATE_STOP_DONE); 1148 break; 1149 1150 case VEN_MSG_RESUME: 1151 omx->post_event (NULL,m_sVenc_msg->statuscode,\ 1152 OMX_COMPONENT_GENERATE_RESUME_DONE); 1153 break; 1154 1155 case VEN_MSG_PAUSE: 1156 omx->post_event (NULL,m_sVenc_msg->statuscode,\ 1157 OMX_COMPONENT_GENERATE_PAUSE_DONE); 1158 1159 break; 1160 1161 case VEN_MSG_FLUSH_INPUT_DONE: 1162 1163 omx->post_event (NULL,m_sVenc_msg->statuscode,\ 1164 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH); 1165 break; 1166 case VEN_MSG_FLUSH_OUPUT_DONE: 1167 omx->post_event (NULL,m_sVenc_msg->statuscode,\ 1168 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH); 1169 break; 1170 case VEN_MSG_INPUT_BUFFER_DONE: 1171 omxhdr = (OMX_BUFFERHEADERTYPE* )\ 1172 m_sVenc_msg->buf.clientdata; 1173 1174 if(omxhdr == NULL || 1175 ((OMX_U32)(omxhdr - omx->m_inp_mem_ptr) > omx->m_sInPortDef.nBufferCountActual) ) 1176 { 1177 omxhdr = NULL; 1178 m_sVenc_msg->statuscode = VEN_S_EFAIL; 1179 } 1180 1181 omx->post_event ((unsigned int)omxhdr,m_sVenc_msg->statuscode, 1182 OMX_COMPONENT_GENERATE_EBD); 1183 break; 1184 case VEN_MSG_OUTPUT_BUFFER_DONE: 1185 1186 omxhdr = (OMX_BUFFERHEADERTYPE*)m_sVenc_msg->buf.clientdata; 1187 1188 if( (omxhdr != NULL) && 1189 ((OMX_U32)(omxhdr - omx->m_out_mem_ptr) < omx->m_sOutPortDef.nBufferCountActual)) 1190 { 1191 if(m_sVenc_msg->buf.len <= omxhdr->nAllocLen) 1192 { 1193 omxhdr->nFilledLen = m_sVenc_msg->buf.len; 1194 omxhdr->nOffset = m_sVenc_msg->buf.offset; 1195 omxhdr->nTimeStamp = m_sVenc_msg->buf.timestamp; 1196 DEBUG_PRINT_LOW("\n o/p TS = %u", (OMX_U32)m_sVenc_msg->buf.timestamp); 1197 omxhdr->nFlags = m_sVenc_msg->buf.flags; 1198 1199 /*Use buffer case*/ 1200 if(omx->output_use_buffer && !omx->m_use_output_pmem) 1201 { 1202 DEBUG_PRINT_LOW("\n memcpy() for o/p Heap UseBuffer"); 1203 memcpy(omxhdr->pBuffer, 1204 (m_sVenc_msg->buf.ptrbuffer), 1205 m_sVenc_msg->buf.len); 1206 } 1207 } 1208 else 1209 { 1210 omxhdr->nFilledLen = 0; 1211 } 1212 1213 } 1214 else 1215 { 1216 omxhdr = NULL; 1217 m_sVenc_msg->statuscode = VEN_S_EFAIL; 1218 } 1219 1220 omx->post_event ((unsigned int)omxhdr,m_sVenc_msg->statuscode, 1221 OMX_COMPONENT_GENERATE_FBD); 1222 break; 1223 case VEN_MSG_NEED_OUTPUT_BUFFER: 1224 //TBD what action needs to be done here?? 1225 break; 1226 default: 1227 break; 1228 } 1229 return 0; 1230 } 1231