1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2014-2015, The Linux Foundation. All rights reserved. 3 4 Redistribution and use in source and binary forms, with or without 5 modification, are permitted provided that the following conditions are met: 6 * Redistributions of source code must retain the above copyright 7 notice, this list of conditions and the following disclaimer. 8 * Redistributions in binary form must reproduce the above copyright 9 notice, this list of conditions and the following disclaimer in the 10 documentation and/or other materials provided with the distribution. 11 * Neither the name of The Linux Foundation nor 12 the names of its contributors may be used to endorse or promote 13 products derived from this software without specific prior written 14 permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 --------------------------------------------------------------------------*/ 28 #include "omx_swvenc_mpeg4.h" 29 30 /* def: StoreMetaDataInBuffersParams */ 31 #include <media/hardware/HardwareAPI.h> 32 33 /* def: VENUS_BUFFER_SIZE, VENUS_Y_STRIDE etc */ 34 #include <media/msm_media_info.h> 35 36 /* def: private_handle_t*/ 37 #include <gralloc_priv.h> 38 39 40 /*---------------------------------------------------------------------------- 41 * Preprocessor Definitions and Constants 42 * -------------------------------------------------------------------------*/ 43 #define OMX_SPEC_VERSION 0x00000101 44 #define OMX_INIT_STRUCT(_s_, _name_) \ 45 memset((_s_), 0x0, sizeof(_name_)); \ 46 (_s_)->nSize = sizeof(_name_); \ 47 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION 48 49 #define ENTER_FUNC() DEBUG_PRINT_HIGH("ENTERING: %s",__FUNCTION__) 50 #define EXIT_FUNC() DEBUG_PRINT_HIGH("EXITING: %s",__FUNCTION__) 51 #define RETURN(x) EXIT_FUNC(); return x; 52 #define ALIGN(value,alignment) (((value) + (alignment-1)) & (~(alignment-1))) 53 54 #define BUFFER_LOG_LOC "/data/misc/media" 55 56 /* factory function executed by the core to create instances */ 57 void *get_omx_component_factory_fn(void) 58 { 59 RETURN((new omx_venc)); 60 } 61 62 omx_venc::omx_venc() 63 { 64 ENTER_FUNC(); 65 66 char property_value[PROPERTY_VALUE_MAX] = {0}; 67 68 memset(&m_debug,0,sizeof(m_debug)); 69 70 property_value[0] = '\0'; 71 property_get("vidc.debug.level", property_value, "1"); 72 debug_level = atoi(property_value); 73 74 property_value[0] = '\0'; 75 property_get("vidc.enc.log.in", property_value, "0"); 76 m_debug.in_buffer_log = atoi(property_value); 77 78 property_value[0] = '\0'; 79 property_get("vidc.enc.log.out", property_value, "0"); 80 m_debug.out_buffer_log = atoi(property_value); 81 82 snprintf(m_debug.log_loc, PROPERTY_VALUE_MAX, "%s", BUFFER_LOG_LOC); 83 property_value[0] = '\0'; 84 property_get("vidc.log.loc", property_value, ""); 85 if (*property_value) 86 { 87 strlcpy(m_debug.log_loc, property_value, PROPERTY_VALUE_MAX); 88 } 89 90 memset(meta_buffer_hdr,0,sizeof(meta_buffer_hdr)); 91 meta_mode_enable = false; 92 memset(meta_buffer_hdr,0,sizeof(meta_buffer_hdr)); 93 memset(meta_buffers,0,sizeof(meta_buffers)); 94 memset(opaque_buffer_hdr,0,sizeof(opaque_buffer_hdr)); 95 mUseProxyColorFormat = false; 96 get_syntaxhdr_enable = false; 97 m_bSeqHdrRequested = false; 98 format_set = false; 99 100 EXIT_FUNC(); 101 } 102 103 omx_venc::~omx_venc() 104 { 105 ENTER_FUNC(); 106 get_syntaxhdr_enable = false; 107 EXIT_FUNC(); 108 } 109 110 OMX_ERRORTYPE omx_venc::component_init(OMX_STRING role) 111 { 112 ENTER_FUNC(); 113 114 OMX_ERRORTYPE eRet = OMX_ErrorNone; 115 SWVENC_STATUS Ret = SWVENC_S_SUCCESS; 116 SWVENC_CALLBACK callBackInfo; 117 OMX_VIDEO_CODINGTYPE codec_type; 118 SWVENC_PROPERTY Prop; 119 int fds[2]; 120 121 strlcpy((char *)m_nkind,role,OMX_MAX_STRINGNAME_SIZE); 122 secure_session = false; 123 124 if (!strncmp( (char *)m_nkind,"OMX.qcom.video.encoder.mpeg4sw", 125 OMX_MAX_STRINGNAME_SIZE)) 126 { 127 strlcpy((char *)m_cRole, "video_encoder.mpeg4",\ 128 OMX_MAX_STRINGNAME_SIZE); 129 codec_type = OMX_VIDEO_CodingMPEG4; 130 m_codec = SWVENC_CODEC_MPEG4; 131 } 132 else if (!strncmp( (char *)m_nkind,"OMX.qcom.video.encoder.h263sw", 133 OMX_MAX_STRINGNAME_SIZE)) 134 { 135 strlcpy((char *)m_cRole, "video_encoder.h263",\ 136 OMX_MAX_STRINGNAME_SIZE); 137 codec_type = OMX_VIDEO_CodingH263; 138 m_codec = SWVENC_CODEC_H263; 139 } 140 else 141 { 142 DEBUG_PRINT_ERROR("ERROR: Unknown Component"); 143 eRet = OMX_ErrorInvalidComponentName; 144 RETURN(eRet); 145 } 146 147 #ifdef ENABLE_GET_SYNTAX_HDR 148 get_syntaxhdr_enable = true; 149 DEBUG_PRINT_HIGH("Get syntax header enabled"); 150 #endif 151 152 callBackInfo.pfn_empty_buffer_done = swvenc_empty_buffer_done_cb; 153 callBackInfo.pfn_fill_buffer_done = swvenc_fill_buffer_done_cb; 154 callBackInfo.pfn_event_notification = swvenc_handle_event_cb; 155 callBackInfo.p_client = (void*)this; 156 157 SWVENC_STATUS sRet = swvenc_init(&m_hSwVenc, m_codec, &callBackInfo); 158 if (sRet != SWVENC_S_SUCCESS) 159 { 160 DEBUG_PRINT_ERROR("swvenc_init returned %d, ret insufficient resources", 161 sRet); 162 RETURN(OMX_ErrorInsufficientResources); 163 } 164 165 m_stopped = true; 166 167 //Intialise the OMX layer variables 168 memset(&m_pCallbacks,0,sizeof(OMX_CALLBACKTYPE)); 169 170 OMX_INIT_STRUCT(&m_sPortParam, OMX_PORT_PARAM_TYPE); 171 m_sPortParam.nPorts = 0x2; 172 m_sPortParam.nStartPortNumber = (OMX_U32) PORT_INDEX_IN; 173 174 OMX_INIT_STRUCT(&m_sPortParam_audio, OMX_PORT_PARAM_TYPE); 175 m_sPortParam_audio.nPorts = 0; 176 m_sPortParam_audio.nStartPortNumber = 0; 177 178 OMX_INIT_STRUCT(&m_sPortParam_img, OMX_PORT_PARAM_TYPE); 179 m_sPortParam_img.nPorts = 0; 180 m_sPortParam_img.nStartPortNumber = 0; 181 182 OMX_INIT_STRUCT(&m_sParamBitrate, OMX_VIDEO_PARAM_BITRATETYPE); 183 m_sParamBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 184 m_sParamBitrate.eControlRate = OMX_Video_ControlRateVariableSkipFrames; 185 m_sParamBitrate.nTargetBitrate = 64000; 186 187 OMX_INIT_STRUCT(&m_sConfigBitrate, OMX_VIDEO_CONFIG_BITRATETYPE); 188 m_sConfigBitrate.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 189 m_sConfigBitrate.nEncodeBitrate = 64000; 190 191 OMX_INIT_STRUCT(&m_sConfigFramerate, OMX_CONFIG_FRAMERATETYPE); 192 m_sConfigFramerate.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 193 m_sConfigFramerate.xEncodeFramerate = 30 << 16; 194 195 OMX_INIT_STRUCT(&m_sConfigIntraRefreshVOP, OMX_CONFIG_INTRAREFRESHVOPTYPE); 196 m_sConfigIntraRefreshVOP.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 197 m_sConfigIntraRefreshVOP.IntraRefreshVOP = OMX_FALSE; 198 199 OMX_INIT_STRUCT(&m_sConfigFrameRotation, OMX_CONFIG_ROTATIONTYPE); 200 m_sConfigFrameRotation.nPortIndex = (OMX_U32) PORT_INDEX_IN; 201 m_sConfigFrameRotation.nRotation = 0; 202 203 OMX_INIT_STRUCT(&m_sSessionQuantization, OMX_VIDEO_PARAM_QUANTIZATIONTYPE); 204 m_sSessionQuantization.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 205 m_sSessionQuantization.nQpI = 9; 206 m_sSessionQuantization.nQpP = 6; 207 m_sSessionQuantization.nQpB = 2; 208 209 OMX_INIT_STRUCT(&m_sSessionQPRange, OMX_QCOM_VIDEO_PARAM_QPRANGETYPE); 210 m_sSessionQPRange.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 211 m_sSessionQPRange.minQP = 2; 212 213 OMX_INIT_STRUCT(&m_sParamProfileLevel, OMX_VIDEO_PARAM_PROFILELEVELTYPE); 214 m_sParamProfileLevel.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 215 216 OMX_INIT_STRUCT(&m_sIntraperiod, QOMX_VIDEO_INTRAPERIODTYPE); 217 m_sIntraperiod.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 218 m_sIntraperiod.nPFrames = (m_sConfigFramerate.xEncodeFramerate * 2) - 1; 219 220 OMX_INIT_STRUCT(&m_sErrorCorrection, OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE); 221 m_sErrorCorrection.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 222 m_sErrorCorrection.bEnableDataPartitioning = OMX_FALSE; 223 m_sErrorCorrection.bEnableHEC = OMX_FALSE; 224 m_sErrorCorrection.bEnableResync = OMX_FALSE; 225 m_sErrorCorrection.bEnableRVLC = OMX_FALSE; 226 m_sErrorCorrection.nResynchMarkerSpacing = 0; 227 228 OMX_INIT_STRUCT(&m_sIntraRefresh, OMX_VIDEO_PARAM_INTRAREFRESHTYPE); 229 m_sIntraRefresh.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 230 m_sIntraRefresh.eRefreshMode = OMX_VIDEO_IntraRefreshMax; 231 232 if (codec_type == OMX_VIDEO_CodingMPEG4) 233 { 234 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_MPEG4ProfileSimple; 235 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_MPEG4Level0; 236 } else if (codec_type == OMX_VIDEO_CodingH263) 237 { 238 m_sParamProfileLevel.eProfile = (OMX_U32) OMX_VIDEO_H263ProfileBaseline; 239 m_sParamProfileLevel.eLevel = (OMX_U32) OMX_VIDEO_H263Level10; 240 } 241 242 /* set the profile and level */ 243 Ret = swvenc_set_profile_level(m_sParamProfileLevel.eProfile, 244 m_sParamProfileLevel.eLevel); 245 if (Ret != SWVENC_S_SUCCESS) 246 { 247 DEBUG_PRINT_ERROR("%s, swvenc_set_rc_mode failed (%d)", 248 __FUNCTION__, Ret); 249 RETURN(OMX_ErrorUndefined); 250 } 251 252 // Initialize the video parameters for input port 253 OMX_INIT_STRUCT(&m_sInPortDef, OMX_PARAM_PORTDEFINITIONTYPE); 254 m_sInPortDef.nPortIndex= (OMX_U32) PORT_INDEX_IN; 255 m_sInPortDef.bEnabled = OMX_TRUE; 256 m_sInPortDef.bPopulated = OMX_FALSE; 257 m_sInPortDef.eDomain = OMX_PortDomainVideo; 258 m_sInPortDef.eDir = OMX_DirInput; 259 m_sInPortDef.format.video.cMIMEType = (char *)"YUV420"; 260 m_sInPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH; 261 m_sInPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT; 262 m_sInPortDef.format.video.nStride = OMX_CORE_QCIF_WIDTH; 263 m_sInPortDef.format.video.nSliceHeight = OMX_CORE_QCIF_HEIGHT; 264 m_sInPortDef.format.video.nBitrate = 64000; 265 m_sInPortDef.format.video.xFramerate = 15 << 16; 266 m_sInPortDef.format.video.eColorFormat = (OMX_COLOR_FORMATTYPE) 267 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; 268 m_sInPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; 269 270 /* set the frame size */ 271 Prop.id = SWVENC_PROPERTY_ID_FRAME_SIZE; 272 Prop.info.frame_size.height = m_sInPortDef.format.video.nFrameHeight; 273 Prop.info.frame_size.width = m_sInPortDef.format.video.nFrameWidth; 274 275 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 276 if (Ret != SWVENC_S_SUCCESS) 277 { 278 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 279 __FUNCTION__, Ret); 280 RETURN(OMX_ErrorUnsupportedSetting); 281 } 282 283 /* set the frame attributes */ 284 Prop.id = SWVENC_PROPERTY_ID_FRAME_ATTRIBUTES; 285 Prop.info.frame_attributes.stride_luma = m_sInPortDef.format.video.nStride; 286 Prop.info.frame_attributes.stride_chroma = m_sInPortDef.format.video.nStride; 287 Prop.info.frame_attributes.offset_luma = 0; 288 Prop.info.frame_attributes.offset_chroma = 289 (m_sInPortDef.format.video.nSliceHeight * m_sInPortDef.format.video.nStride); 290 Prop.info.frame_attributes.size = (Prop.info.frame_attributes.offset_chroma * 3) >> 1; 291 292 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 293 if (Ret != SWVENC_S_SUCCESS) 294 { 295 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 296 __FUNCTION__, Ret); 297 RETURN(OMX_ErrorUndefined); 298 } 299 300 Ret = swvenc_get_buffer_req(&m_sInPortDef.nBufferCountMin, 301 &m_sInPortDef.nBufferCountActual, 302 &m_sInPortDef.nBufferSize, 303 &m_sInPortDef.nBufferAlignment, 304 PORT_INDEX_IN); 305 if (Ret != SWVENC_S_SUCCESS) 306 { 307 DEBUG_PRINT_ERROR("ERROR: %s, swvenc_get_buffer_req failed (%d)", __FUNCTION__, 308 Ret); 309 RETURN(OMX_ErrorUndefined); 310 } 311 312 // Initialize the video parameters for output port 313 OMX_INIT_STRUCT(&m_sOutPortDef, OMX_PARAM_PORTDEFINITIONTYPE); 314 m_sOutPortDef.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 315 m_sOutPortDef.bEnabled = OMX_TRUE; 316 m_sOutPortDef.bPopulated = OMX_FALSE; 317 m_sOutPortDef.eDomain = OMX_PortDomainVideo; 318 m_sOutPortDef.eDir = OMX_DirOutput; 319 m_sOutPortDef.format.video.nFrameWidth = OMX_CORE_QCIF_WIDTH; 320 m_sOutPortDef.format.video.nFrameHeight = OMX_CORE_QCIF_HEIGHT; 321 m_sOutPortDef.format.video.nBitrate = 64000; 322 m_sOutPortDef.format.video.xFramerate = 15 << 16; 323 m_sOutPortDef.format.video.eColorFormat = OMX_COLOR_FormatUnused; 324 if (codec_type == OMX_VIDEO_CodingMPEG4) 325 { 326 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 327 } 328 else if (codec_type == OMX_VIDEO_CodingH263) 329 { 330 m_sOutPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 331 } 332 333 Ret = swvenc_get_buffer_req(&m_sOutPortDef.nBufferCountMin, 334 &m_sOutPortDef.nBufferCountActual, 335 &m_sOutPortDef.nBufferSize, 336 &m_sOutPortDef.nBufferAlignment, 337 PORT_INDEX_OUT); 338 if (Ret != SWVENC_S_SUCCESS) 339 { 340 DEBUG_PRINT_ERROR("ERROR: %s, swvenc_get_buffer_req failed (%d)", __FUNCTION__, 341 Ret); 342 RETURN(OMX_ErrorUndefined); 343 } 344 345 // Initialize the video color format for input port 346 OMX_INIT_STRUCT(&m_sInPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE); 347 m_sInPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_IN; 348 m_sInPortFormat.nIndex = 0; 349 m_sInPortFormat.eColorFormat = (OMX_COLOR_FORMATTYPE) 350 QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m; 351 m_sInPortFormat.eCompressionFormat = OMX_VIDEO_CodingUnused; 352 353 // Initialize the compression format for output port 354 OMX_INIT_STRUCT(&m_sOutPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE); 355 m_sOutPortFormat.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 356 m_sOutPortFormat.nIndex = 0; 357 m_sOutPortFormat.eColorFormat = OMX_COLOR_FormatUnused; 358 if (codec_type == OMX_VIDEO_CodingMPEG4) 359 { 360 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 361 } else if (codec_type == OMX_VIDEO_CodingH263) 362 { 363 m_sOutPortFormat.eCompressionFormat = OMX_VIDEO_CodingH263; 364 } 365 366 // mandatory Indices for kronos test suite 367 OMX_INIT_STRUCT(&m_sPriorityMgmt, OMX_PRIORITYMGMTTYPE); 368 369 OMX_INIT_STRUCT(&m_sInBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE); 370 m_sInBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_IN; 371 372 OMX_INIT_STRUCT(&m_sOutBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE); 373 m_sOutBufSupplier.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 374 375 OMX_INIT_STRUCT(&m_sParamInitqp, QOMX_EXTNINDEX_VIDEO_INITIALQP); 376 m_sParamInitqp.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 377 378 // mp4 specific init 379 OMX_INIT_STRUCT(&m_sParamMPEG4, OMX_VIDEO_PARAM_MPEG4TYPE); 380 m_sParamMPEG4.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 381 m_sParamMPEG4.eProfile = OMX_VIDEO_MPEG4ProfileSimple; 382 m_sParamMPEG4.eLevel = OMX_VIDEO_MPEG4Level0; 383 m_sParamMPEG4.nSliceHeaderSpacing = 0; 384 m_sParamMPEG4.bSVH = OMX_FALSE; 385 m_sParamMPEG4.bGov = OMX_FALSE; 386 // 2 second intra period for default outport fps 387 m_sParamMPEG4.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1); 388 m_sParamMPEG4.bACPred = OMX_TRUE; 389 // delta = 2 @ 15 fps 390 m_sParamMPEG4.nTimeIncRes = 30; 391 // pframe and iframe 392 m_sParamMPEG4.nAllowedPictureTypes = 2; 393 // number of video packet headers per vop 394 m_sParamMPEG4.nHeaderExtension = 1; 395 m_sParamMPEG4.bReversibleVLC = OMX_FALSE; 396 397 // h263 specific init 398 OMX_INIT_STRUCT(&m_sParamH263, OMX_VIDEO_PARAM_H263TYPE); 399 m_sParamH263.nPortIndex = (OMX_U32) PORT_INDEX_OUT; 400 // 2 second intra period for default outport fps 401 m_sParamH263.nPFrames = (m_sOutPortFormat.xFramerate * 2 - 1); 402 m_sParamH263.nBFrames = 0; 403 m_sParamH263.eProfile = OMX_VIDEO_H263ProfileBaseline; 404 m_sParamH263.eLevel = OMX_VIDEO_H263Level10; 405 m_sParamH263.bPLUSPTYPEAllowed = OMX_FALSE; 406 m_sParamH263.nAllowedPictureTypes = 2; 407 m_sParamH263.bForceRoundingTypeToZero = OMX_TRUE; 408 m_sParamH263.nPictureHeaderRepetition = 0; 409 m_sParamH263.nGOBHeaderInterval = 1; 410 411 m_state = OMX_StateLoaded; 412 m_sExtraData = 0; 413 414 m_capability.max_height = OMX_CORE_WVGA_HEIGHT; 415 m_capability.max_width = OMX_CORE_WVGA_WIDTH; 416 m_capability.min_height = 32; 417 m_capability.min_width = 32; 418 419 if (eRet == OMX_ErrorNone) 420 { 421 if (pipe(fds)) 422 { 423 DEBUG_PRINT_ERROR("ERROR: pipe creation failed"); 424 eRet = OMX_ErrorInsufficientResources; 425 } 426 else 427 { 428 if ((fds[0] == 0) || (fds[1] == 0)) 429 { 430 if (pipe(fds)) 431 { 432 DEBUG_PRINT_ERROR("ERROR: pipe creation failed"); 433 eRet = OMX_ErrorInsufficientResources; 434 } 435 } 436 if (eRet == OMX_ErrorNone) 437 { 438 m_pipe_in = fds[0]; 439 m_pipe_out = fds[1]; 440 } 441 } 442 443 if (pthread_create(&msg_thread_id,0, message_thread, this) < 0) 444 { 445 eRet = OMX_ErrorInsufficientResources; 446 msg_thread_created = false; 447 } 448 else 449 { 450 msg_thread_created = true; 451 } 452 } 453 454 DEBUG_PRINT_HIGH("Component_init return value = 0x%x", eRet); 455 456 EXIT_FUNC(); 457 458 RETURN(eRet); 459 } 460 461 OMX_ERRORTYPE omx_venc::set_parameter 462 ( 463 OMX_IN OMX_HANDLETYPE hComp, 464 OMX_IN OMX_INDEXTYPE paramIndex, 465 OMX_IN OMX_PTR paramData 466 ) 467 { 468 ENTER_FUNC(); 469 470 OMX_ERRORTYPE eRet = OMX_ErrorNone; 471 SWVENC_STATUS Ret = SWVENC_S_SUCCESS; 472 SWVENC_PROPERTY Prop; 473 bool bResult; 474 unsigned int stride, scanlines; 475 476 (void)hComp; 477 478 if (m_state == OMX_StateInvalid) 479 { 480 DEBUG_PRINT_ERROR("ERROR: Set Param in Invalid State"); 481 RETURN(OMX_ErrorInvalidState); 482 } 483 if (paramData == NULL) 484 { 485 DEBUG_PRINT_ERROR("ERROR: Get Param in Invalid paramData"); 486 RETURN(OMX_ErrorBadParameter); 487 } 488 489 /* set_parameter can be called in loaded state or disabled port */ 490 if ( (m_state == OMX_StateLoaded) || 491 (m_sInPortDef.bEnabled == OMX_FALSE) || 492 (m_sOutPortDef.bEnabled == OMX_FALSE) 493 ) 494 { 495 DEBUG_PRINT_LOW("Set Parameter called in valid state"); 496 } 497 else 498 { 499 DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State"); 500 RETURN(OMX_ErrorIncorrectStateOperation); 501 } 502 503 switch ((int)paramIndex) 504 { 505 case OMX_IndexParamPortDefinition: 506 { 507 OMX_PARAM_PORTDEFINITIONTYPE *portDefn; 508 portDefn = (OMX_PARAM_PORTDEFINITIONTYPE *) paramData; 509 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPortDefinition H= %d, W = %d", 510 (int)portDefn->format.video.nFrameHeight, 511 (int)portDefn->format.video.nFrameWidth); 512 513 if (PORT_INDEX_IN == portDefn->nPortIndex) 514 { 515 if (!dev_is_video_session_supported(portDefn->format.video.nFrameWidth, 516 portDefn->format.video.nFrameHeight)) 517 { 518 DEBUG_PRINT_ERROR("video session not supported"); 519 omx_report_unsupported_setting(); 520 RETURN(OMX_ErrorUnsupportedSetting); 521 } 522 DEBUG_PRINT_LOW("i/p actual cnt requested = %u", portDefn->nBufferCountActual); 523 DEBUG_PRINT_LOW("i/p min cnt requested = %u", portDefn->nBufferCountMin); 524 DEBUG_PRINT_LOW("i/p buffersize requested = %u", portDefn->nBufferSize); 525 if (portDefn->nBufferCountMin > portDefn->nBufferCountActual) 526 { 527 DEBUG_PRINT_ERROR("ERROR: (In_PORT) Min buffers (%u) > actual count (%u)", 528 portDefn->nBufferCountMin, portDefn->nBufferCountActual); 529 RETURN(OMX_ErrorUnsupportedSetting); 530 } 531 532 /* set the frame size */ 533 Prop.id = SWVENC_PROPERTY_ID_FRAME_SIZE; 534 Prop.info.frame_size.height = portDefn->format.video.nFrameHeight; 535 Prop.info.frame_size.width = portDefn->format.video.nFrameWidth; 536 537 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 538 if (Ret != SWVENC_S_SUCCESS) 539 { 540 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 541 __FUNCTION__, Ret); 542 RETURN(OMX_ErrorUnsupportedSetting); 543 } 544 545 /* set the input frame-rate */ 546 if (portDefn->format.video.xFramerate != 0) 547 { 548 Ret = swvenc_set_frame_rate(portDefn->format.video.xFramerate >> 16); 549 if (Ret != SWVENC_S_SUCCESS) 550 { 551 DEBUG_PRINT_ERROR("%s, swvenc_set_frame_rate failed (%d)", 552 __FUNCTION__, Ret); 553 RETURN(OMX_ErrorUnsupportedSetting); 554 } 555 } 556 557 /* set the frame attributes */ 558 stride = VENUS_Y_STRIDE(COLOR_FMT_NV12, portDefn->format.video.nFrameWidth); 559 scanlines = VENUS_Y_SCANLINES(COLOR_FMT_NV12, portDefn->format.video.nSliceHeight); 560 Prop.id = SWVENC_PROPERTY_ID_FRAME_ATTRIBUTES; 561 Prop.info.frame_attributes.stride_luma = stride; 562 Prop.info.frame_attributes.stride_chroma = stride; 563 Prop.info.frame_attributes.offset_luma = 0; 564 Prop.info.frame_attributes.offset_chroma = scanlines * stride; 565 Prop.info.frame_attributes.size = 566 VENUS_BUFFER_SIZE(COLOR_FMT_NV12, 567 portDefn->format.video.nFrameWidth, 568 portDefn->format.video.nFrameHeight); 569 570 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 571 if (Ret != SWVENC_S_SUCCESS) 572 { 573 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 574 __FUNCTION__, Ret); 575 RETURN(OMX_ErrorUnsupportedSetting); 576 } 577 578 DEBUG_PRINT_LOW("i/p previous actual cnt = %u", m_sInPortDef.nBufferCountActual); 579 DEBUG_PRINT_LOW("i/p previous min cnt = %u", m_sInPortDef.nBufferCountMin); 580 DEBUG_PRINT_LOW("i/p previous buffersize = %u", m_sInPortDef.nBufferSize); 581 582 memcpy(&m_sInPortDef, portDefn,sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 583 584 /* update the input buffer requirement */ 585 Ret = swvenc_get_buffer_req(&m_sInPortDef.nBufferCountMin, 586 &m_sInPortDef.nBufferCountActual, 587 &m_sInPortDef.nBufferSize, 588 &m_sInPortDef.nBufferAlignment, 589 portDefn->nPortIndex); 590 if (Ret != SWVENC_S_SUCCESS) 591 { 592 DEBUG_PRINT_ERROR("ERROR: %s, swvenc_get_buffer_req failed (%d)", __FUNCTION__, 593 Ret); 594 RETURN(OMX_ErrorUndefined); 595 } 596 597 if (portDefn->nBufferCountActual > m_sInPortDef.nBufferCountActual) 598 { 599 m_sInPortDef.nBufferCountActual = portDefn->nBufferCountActual; 600 } 601 if (portDefn->nBufferSize > m_sInPortDef.nBufferSize) 602 { 603 m_sInPortDef.nBufferSize = portDefn->nBufferSize; 604 } 605 606 DEBUG_PRINT_LOW("i/p new actual cnt = %u", m_sInPortDef.nBufferCountActual); 607 DEBUG_PRINT_LOW("i/p new min cnt = %u", m_sInPortDef.nBufferCountMin); 608 DEBUG_PRINT_LOW("i/p new buffersize = %u", m_sInPortDef.nBufferSize); 609 } 610 else if (PORT_INDEX_OUT == portDefn->nPortIndex) 611 { 612 DEBUG_PRINT_LOW("o/p actual cnt requested = %u", portDefn->nBufferCountActual); 613 DEBUG_PRINT_LOW("o/p min cnt requested = %u", portDefn->nBufferCountMin); 614 DEBUG_PRINT_LOW("o/p buffersize requested = %u", portDefn->nBufferSize); 615 if (portDefn->nBufferCountMin > portDefn->nBufferCountActual) 616 { 617 DEBUG_PRINT_ERROR("ERROR: (Out_PORT) Min buffers (%u) > actual count (%u)", 618 portDefn->nBufferCountMin, portDefn->nBufferCountActual); 619 RETURN(OMX_ErrorUnsupportedSetting); 620 } 621 622 /* set the output bit-rate */ 623 Ret = swvenc_set_bit_rate(portDefn->format.video.nBitrate); 624 if (Ret != SWVENC_S_SUCCESS) 625 { 626 DEBUG_PRINT_ERROR("%s, swvenc_set_bit_rate failed (%d)", 627 __FUNCTION__, Ret); 628 RETURN(OMX_ErrorUnsupportedSetting); 629 } 630 631 DEBUG_PRINT_LOW("o/p previous actual cnt = %u", m_sOutPortDef.nBufferCountActual); 632 DEBUG_PRINT_LOW("o/p previous min cnt = %u", m_sOutPortDef.nBufferCountMin); 633 DEBUG_PRINT_LOW("o/p previous buffersize = %u", m_sOutPortDef.nBufferSize); 634 635 /* set the buffer requirement */ 636 bResult = dev_set_buf_req(&portDefn->nBufferCountMin, 637 &portDefn->nBufferCountActual, 638 &portDefn->nBufferSize, 639 portDefn->nPortIndex); 640 if (bResult != true) 641 { 642 DEBUG_PRINT_ERROR("%s, dev_set_buf_req failed", 643 __FUNCTION__); 644 RETURN(OMX_ErrorUnsupportedSetting); 645 } 646 memcpy(&m_sOutPortDef, portDefn,sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 647 648 /* update the output buffer requirement */ 649 Ret = swvenc_get_buffer_req(&m_sOutPortDef.nBufferCountMin, 650 &m_sOutPortDef.nBufferCountActual, 651 &m_sOutPortDef.nBufferSize, 652 &m_sOutPortDef.nBufferAlignment, 653 portDefn->nPortIndex); 654 if (Ret != SWVENC_S_SUCCESS) 655 { 656 DEBUG_PRINT_ERROR("ERROR: %s, swvenc_get_buffer_req failed (%d)", __FUNCTION__, 657 Ret); 658 RETURN(OMX_ErrorUndefined); 659 } 660 661 if (portDefn->nBufferCountActual > m_sOutPortDef.nBufferCountActual) 662 { 663 m_sOutPortDef.nBufferCountActual = portDefn->nBufferCountActual; 664 } 665 if (portDefn->nBufferSize > m_sOutPortDef.nBufferSize) 666 { 667 m_sOutPortDef.nBufferSize = portDefn->nBufferSize; 668 } 669 670 DEBUG_PRINT_LOW("o/p new actual cnt = %u", m_sOutPortDef.nBufferCountActual); 671 DEBUG_PRINT_LOW("o/p new min cnt = %u", m_sOutPortDef.nBufferCountMin); 672 DEBUG_PRINT_LOW("o/p new buffersize = %u", m_sOutPortDef.nBufferSize); 673 } 674 else 675 { 676 DEBUG_PRINT_ERROR("ERROR: Set_parameter: Bad Port idx %d", 677 (int)portDefn->nPortIndex); 678 eRet = OMX_ErrorBadPortIndex; 679 } 680 m_sConfigFramerate.xEncodeFramerate = portDefn->format.video.xFramerate; 681 m_sConfigBitrate.nEncodeBitrate = portDefn->format.video.nBitrate; 682 m_sParamBitrate.nTargetBitrate = portDefn->format.video.nBitrate; 683 break; 684 } 685 686 case OMX_IndexParamVideoPortFormat: 687 { 688 OMX_VIDEO_PARAM_PORTFORMATTYPE *portFmt = 689 (OMX_VIDEO_PARAM_PORTFORMATTYPE *)paramData; 690 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d", 691 portFmt->eColorFormat); 692 SWVENC_COLOR_FORMAT color_format; 693 694 /* set the driver with the corresponding values */ 695 if (PORT_INDEX_IN == portFmt->nPortIndex) 696 { 697 if (portFmt->eColorFormat == 698 ((OMX_COLOR_FORMATTYPE) QOMX_COLOR_FormatAndroidOpaque)) 699 { 700 /* meta_mode = 2 (kMetadataBufferTypeGrallocSource) */ 701 m_sInPortFormat.eColorFormat = 702 (OMX_COLOR_FORMATTYPE) QOMX_COLOR_FormatYVU420SemiPlanar; 703 color_format = SWVENC_COLOR_FORMAT_NV21; 704 if (!mUseProxyColorFormat) 705 { 706 if (!c2d_conv.init()) 707 { 708 DEBUG_PRINT_ERROR("C2D init failed"); 709 return OMX_ErrorUnsupportedSetting; 710 } 711 DEBUG_PRINT_ERROR("C2D init is successful"); 712 } 713 mUseProxyColorFormat = true; 714 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB_OPQ; 715 } 716 else 717 { 718 m_sInPortFormat.eColorFormat = portFmt->eColorFormat; 719 if ((portFmt->eColorFormat == OMX_COLOR_FormatYUV420SemiPlanar) || 720 (portFmt->eColorFormat == 721 ((OMX_COLOR_FORMATTYPE) QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m))) 722 { 723 color_format = SWVENC_COLOR_FORMAT_NV12; 724 } 725 else if (portFmt->eColorFormat == 726 ((OMX_COLOR_FORMATTYPE) QOMX_COLOR_FormatYVU420SemiPlanar)) 727 { 728 color_format = SWVENC_COLOR_FORMAT_NV21; 729 } 730 else 731 { 732 DEBUG_PRINT_ERROR("%s: OMX_IndexParamVideoPortFormat %d invalid", 733 __FUNCTION__, 734 portFmt->eColorFormat); 735 RETURN(OMX_ErrorBadParameter); 736 } 737 m_input_msg_id = OMX_COMPONENT_GENERATE_ETB; 738 mUseProxyColorFormat = false; 739 } 740 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoPortFormat %d", 741 portFmt->eColorFormat); 742 743 /* set the input color format */ 744 Prop.id = SWVENC_PROPERTY_ID_COLOR_FORMAT; 745 Prop.info.color_format = color_format; 746 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 747 if (Ret != SWVENC_S_SUCCESS) 748 { 749 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 750 __FUNCTION__, Ret); 751 RETURN(OMX_ErrorUnsupportedSetting); 752 } 753 754 /* set the input frame-rate */ 755 if (portFmt->xFramerate != 0) 756 { 757 Ret = swvenc_set_frame_rate(portFmt->xFramerate >> 16); 758 if (Ret != SWVENC_S_SUCCESS) 759 { 760 DEBUG_PRINT_ERROR("%s, swvenc_set_frame_rate failed (%d)", 761 __FUNCTION__, Ret); 762 //RETURN(OMX_ErrorUnsupportedSetting); 763 } 764 m_sInPortFormat.xFramerate = portFmt->xFramerate; 765 } 766 } 767 break; 768 } 769 770 case OMX_IndexParamVideoInit: 771 { 772 OMX_PORT_PARAM_TYPE* pParam = (OMX_PORT_PARAM_TYPE*)(paramData); 773 DEBUG_PRINT_LOW("Set OMX_IndexParamVideoInit called"); 774 break; 775 } 776 777 case OMX_IndexParamVideoBitrate: 778 { 779 OMX_VIDEO_PARAM_BITRATETYPE* pParam = (OMX_VIDEO_PARAM_BITRATETYPE*)paramData; 780 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoBitrate"); 781 782 if (m_max_allowed_bitrate_check) 783 { 784 //TBD: to add bitrate check 785 } 786 787 /* set the output bit-rate */ 788 Ret = swvenc_set_bit_rate(pParam->nTargetBitrate); 789 if (Ret != SWVENC_S_SUCCESS) 790 { 791 DEBUG_PRINT_ERROR("%s, swvenc_set_bit_rate failed (%d)", 792 __FUNCTION__, Ret); 793 RETURN(OMX_ErrorUnsupportedSetting); 794 } 795 796 /* set the RC-mode */ 797 Ret = swvenc_set_rc_mode(pParam->eControlRate); 798 if (Ret != SWVENC_S_SUCCESS) 799 { 800 DEBUG_PRINT_ERROR("%s, swvenc_set_rc_mode failed (%d)", 801 __FUNCTION__, Ret); 802 RETURN(OMX_ErrorUnsupportedSetting); 803 } 804 805 m_sParamBitrate.nTargetBitrate = pParam->nTargetBitrate; 806 m_sParamBitrate.eControlRate = pParam->eControlRate; 807 m_sConfigBitrate.nEncodeBitrate = pParam->nTargetBitrate; 808 m_sInPortDef.format.video.nBitrate = pParam->nTargetBitrate; 809 m_sOutPortDef.format.video.nBitrate = pParam->nTargetBitrate; 810 DEBUG_PRINT_LOW("bitrate = %u", m_sOutPortDef.format.video.nBitrate); 811 break; 812 } 813 814 case OMX_IndexParamVideoMpeg4: 815 { 816 OMX_VIDEO_PARAM_MPEG4TYPE* pParam = (OMX_VIDEO_PARAM_MPEG4TYPE*)paramData; 817 818 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoMpeg4"); 819 820 if (pParam->nBFrames) 821 { 822 DEBUG_PRINT_ERROR("Warning: B frames not supported"); 823 } 824 825 /* set the intra period */ 826 Ret = swvenc_set_intra_period(pParam->nPFrames,pParam->nBFrames); 827 if (Ret != SWVENC_S_SUCCESS) 828 { 829 DEBUG_PRINT_ERROR("%s, swvenc_set_intra_period failed (%d)", 830 __FUNCTION__, Ret); 831 RETURN(OMX_ErrorUnsupportedSetting); 832 } 833 834 memcpy(&m_sParamMPEG4,pParam, sizeof(struct OMX_VIDEO_PARAM_MPEG4TYPE)); 835 m_sIntraperiod.nPFrames = m_sParamMPEG4.nPFrames; 836 m_sIntraperiod.nBFrames = m_sParamMPEG4.nBFrames; 837 break; 838 } 839 840 case OMX_IndexParamVideoH263: 841 { 842 OMX_VIDEO_PARAM_H263TYPE* pParam = (OMX_VIDEO_PARAM_H263TYPE*)paramData; 843 844 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoH263"); 845 846 /* set the intra period */ 847 Ret = swvenc_set_intra_period(pParam->nPFrames,pParam->nBFrames); 848 if (Ret != SWVENC_S_SUCCESS) 849 { 850 DEBUG_PRINT_ERROR("%s, swvenc_set_intra_period failed (%d)", 851 __FUNCTION__, Ret); 852 RETURN(OMX_ErrorUnsupportedSetting); 853 } 854 855 memcpy(&m_sParamH263,pParam, sizeof(struct OMX_VIDEO_PARAM_H263TYPE)); 856 m_sIntraperiod.nPFrames = m_sParamH263.nPFrames; 857 m_sIntraperiod.nBFrames = m_sParamH263.nBFrames; 858 break; 859 } 860 861 case OMX_IndexParamVideoProfileLevelCurrent: 862 { 863 OMX_VIDEO_PARAM_PROFILELEVELTYPE* pParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE*)paramData; 864 865 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoProfileLevelCurrent"); 866 867 /* set the profile and level */ 868 Ret = swvenc_set_profile_level(pParam->eProfile,pParam->eLevel); 869 if (Ret != SWVENC_S_SUCCESS) 870 { 871 DEBUG_PRINT_ERROR("%s, swvenc_set_rc_mode failed (%d)", 872 __FUNCTION__, Ret); 873 RETURN(OMX_ErrorUnsupportedSetting); 874 } 875 876 877 m_sParamProfileLevel.eProfile = pParam->eProfile; 878 m_sParamProfileLevel.eLevel = pParam->eLevel; 879 880 if (SWVENC_CODEC_MPEG4 == m_codec) 881 { 882 m_sParamMPEG4.eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)m_sParamProfileLevel.eProfile; 883 m_sParamMPEG4.eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)m_sParamProfileLevel.eLevel; 884 DEBUG_PRINT_LOW("MPEG4 profile = %d, level = %d", m_sParamMPEG4.eProfile, 885 m_sParamMPEG4.eLevel); 886 } 887 else if (SWVENC_CODEC_H263 == m_codec) 888 { 889 m_sParamH263.eProfile = (OMX_VIDEO_H263PROFILETYPE)m_sParamProfileLevel.eProfile; 890 m_sParamH263.eLevel = (OMX_VIDEO_H263LEVELTYPE)m_sParamProfileLevel.eLevel; 891 DEBUG_PRINT_LOW("H263 profile = %d, level = %d", m_sParamH263.eProfile, 892 m_sParamH263.eLevel); 893 } 894 break; 895 } 896 897 case OMX_IndexParamStandardComponentRole: 898 { 899 OMX_PARAM_COMPONENTROLETYPE *comp_role; 900 comp_role = (OMX_PARAM_COMPONENTROLETYPE *) paramData; 901 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamStandardComponentRole %s", 902 comp_role->cRole); 903 904 if ((m_state == OMX_StateLoaded)&& 905 !BITMASK_PRESENT(&m_flags,OMX_COMPONENT_IDLE_PENDING)) 906 { 907 DEBUG_PRINT_LOW("Set Parameter called in valid state"); 908 } 909 else 910 { 911 DEBUG_PRINT_ERROR("Set Parameter called in Invalid State"); 912 RETURN(OMX_ErrorIncorrectStateOperation); 913 } 914 915 if (SWVENC_CODEC_MPEG4 == m_codec) 916 { 917 if (!strncmp((const char*)comp_role->cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE)) 918 { 919 strlcpy((char*)m_cRole,"video_encoder.mpeg4",OMX_MAX_STRINGNAME_SIZE); 920 } 921 else 922 { 923 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole); 924 eRet = OMX_ErrorUnsupportedSetting; 925 } 926 } 927 else if (SWVENC_CODEC_H263 == m_codec) 928 { 929 if (!strncmp((const char*)comp_role->cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE)) 930 { 931 strlcpy((char*)m_cRole,"video_encoder.h263",OMX_MAX_STRINGNAME_SIZE); 932 } 933 else 934 { 935 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown Index %s", comp_role->cRole); 936 eRet =OMX_ErrorUnsupportedSetting; 937 } 938 } 939 else 940 { 941 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %s", m_nkind); 942 eRet = OMX_ErrorInvalidComponentName; 943 } 944 break; 945 } 946 947 case OMX_IndexParamPriorityMgmt: 948 { 949 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt"); 950 if (m_state != OMX_StateLoaded) { 951 DEBUG_PRINT_ERROR("ERROR: Set Parameter called in Invalid State"); 952 RETURN(OMX_ErrorIncorrectStateOperation); 953 } 954 OMX_PRIORITYMGMTTYPE *priorityMgmtype = (OMX_PRIORITYMGMTTYPE*) paramData; 955 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamPriorityMgmt %u", 956 priorityMgmtype->nGroupID); 957 958 DEBUG_PRINT_LOW("set_parameter: priorityMgmtype %u", 959 priorityMgmtype->nGroupPriority); 960 961 m_sPriorityMgmt.nGroupID = priorityMgmtype->nGroupID; 962 m_sPriorityMgmt.nGroupPriority = priorityMgmtype->nGroupPriority; 963 964 break; 965 } 966 967 case OMX_IndexParamCompBufferSupplier: 968 { 969 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier"); 970 OMX_PARAM_BUFFERSUPPLIERTYPE *bufferSupplierType = (OMX_PARAM_BUFFERSUPPLIERTYPE*) paramData; 971 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamCompBufferSupplier %d", 972 bufferSupplierType->eBufferSupplier); 973 if ( (bufferSupplierType->nPortIndex == 0) || 974 (bufferSupplierType->nPortIndex ==1) 975 ) 976 { 977 m_sInBufSupplier.eBufferSupplier = bufferSupplierType->eBufferSupplier; 978 } 979 else 980 { 981 eRet = OMX_ErrorBadPortIndex; 982 } 983 984 break; 985 986 } 987 988 case OMX_IndexParamVideoQuantization: 989 { 990 // this is applicable only for RC-off case 991 DEBUG_PRINT_LOW("set_parameter: OMX_IndexParamVideoQuantization"); 992 OMX_VIDEO_PARAM_QUANTIZATIONTYPE *session_qp = (OMX_VIDEO_PARAM_QUANTIZATIONTYPE*) paramData; 993 if (session_qp->nPortIndex == PORT_INDEX_OUT) 994 { 995 Prop.id = SWVENC_PROPERTY_ID_QP; 996 Prop.info.qp.qp_i = session_qp->nQpI; 997 Prop.info.qp.qp_p = session_qp->nQpP; 998 Prop.info.qp.qp_b = session_qp->nQpB; 999 1000 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 1001 if (Ret != SWVENC_S_SUCCESS) 1002 { 1003 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 1004 __FUNCTION__, Ret); 1005 RETURN(OMX_ErrorUnsupportedSetting); 1006 } 1007 1008 m_sSessionQuantization.nQpI = session_qp->nQpI; 1009 m_sSessionQuantization.nQpP = session_qp->nQpP; 1010 m_sSessionQuantization.nQpB = session_qp->nQpB; 1011 } 1012 else 1013 { 1014 DEBUG_PRINT_ERROR("ERROR: Unsupported port Index for Session QP setting"); 1015 eRet = OMX_ErrorBadPortIndex; 1016 } 1017 break; 1018 } 1019 1020 case OMX_QcomIndexParamVideoQPRange: 1021 { 1022 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexParamVideoQPRange"); 1023 OMX_QCOM_VIDEO_PARAM_QPRANGETYPE *qp_range = (OMX_QCOM_VIDEO_PARAM_QPRANGETYPE*) paramData; 1024 if (qp_range->nPortIndex == PORT_INDEX_OUT) 1025 { 1026 if ( (qp_range->minQP > 255) || 1027 (qp_range->maxQP > 255) 1028 ) 1029 { 1030 DEBUG_PRINT_ERROR("ERROR: Out of range QP"); 1031 eRet = OMX_ErrorBadParameter; 1032 } 1033 1034 Prop.id = SWVENC_PROPERTY_ID_QP_RANGE; 1035 Prop.info.qp_range.min_qp_packed = 1036 (qp_range->minQP << 16) | (qp_range->minQP) | (qp_range->minQP << 8); 1037 Prop.info.qp_range.max_qp_packed = 1038 (qp_range->maxQP << 16) | (qp_range->maxQP) | (qp_range->maxQP << 8); 1039 1040 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 1041 if (Ret != SWVENC_S_SUCCESS) 1042 { 1043 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 1044 __FUNCTION__, Ret); 1045 RETURN(OMX_ErrorUnsupportedSetting); 1046 } 1047 1048 m_sSessionQPRange.minQP= qp_range->minQP; 1049 m_sSessionQPRange.maxQP= qp_range->maxQP; 1050 } 1051 else 1052 { 1053 DEBUG_PRINT_ERROR("ERROR: Unsupported port Index for QP range setting"); 1054 eRet = OMX_ErrorBadPortIndex; 1055 } 1056 break; 1057 } 1058 1059 case OMX_QcomIndexPortDefn: 1060 { 1061 OMX_QCOM_PARAM_PORTDEFINITIONTYPE* pParam = 1062 (OMX_QCOM_PARAM_PORTDEFINITIONTYPE*)paramData; 1063 DEBUG_PRINT_LOW("set_parameter: OMX_QcomIndexPortDefn"); 1064 if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_IN) 1065 { 1066 if (pParam->nMemRegion > OMX_QCOM_MemRegionInvalid && 1067 pParam->nMemRegion < OMX_QCOM_MemRegionMax) 1068 { 1069 m_use_input_pmem = OMX_TRUE; 1070 } 1071 else 1072 { 1073 m_use_input_pmem = OMX_FALSE; 1074 } 1075 } 1076 else if (pParam->nPortIndex == (OMX_U32)PORT_INDEX_OUT) 1077 { 1078 if (pParam->nMemRegion > OMX_QCOM_MemRegionInvalid && 1079 pParam->nMemRegion < OMX_QCOM_MemRegionMax) 1080 { 1081 m_use_output_pmem = OMX_TRUE; 1082 } 1083 else 1084 { 1085 m_use_output_pmem = OMX_FALSE; 1086 } 1087 } 1088 else 1089 { 1090 DEBUG_PRINT_ERROR("ERROR: SetParameter called on unsupported Port Index for QcomPortDefn"); 1091 RETURN(OMX_ErrorBadPortIndex); 1092 } 1093 break; 1094 } 1095 1096 case OMX_IndexParamVideoErrorCorrection: 1097 { 1098 DEBUG_PRINT_LOW("OMX_IndexParamVideoErrorCorrection"); 1099 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pParam = 1100 (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)paramData; 1101 1102 /* HEC */ 1103 if (m_codec == SWVENC_CODEC_MPEG4) 1104 { 1105 Prop.id = SWVENC_PROPERTY_ID_MPEG4_HEC; 1106 Prop.info.mpeg4_hec = pParam->bEnableHEC; 1107 1108 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 1109 if (Ret != SWVENC_S_SUCCESS) 1110 { 1111 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 1112 __FUNCTION__, Ret); 1113 RETURN(OMX_ErrorUndefined); 1114 } 1115 1116 /* Data partitioning */ 1117 Prop.id = SWVENC_PROPERTY_ID_MPEG4_DP; 1118 Prop.info.mpeg4_dp = pParam->bEnableDataPartitioning; 1119 1120 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 1121 if (Ret != SWVENC_S_SUCCESS) 1122 { 1123 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 1124 __FUNCTION__, Ret); 1125 RETURN(OMX_ErrorUndefined); 1126 } 1127 } 1128 1129 /* RVLC */ 1130 if (pParam->bEnableRVLC) 1131 { 1132 DEBUG_PRINT_ERROR("%s, RVLC not support", __FUNCTION__); 1133 } 1134 1135 /* Re-sync Marker */ 1136 Prop.id = SWVENC_PROPERTY_ID_SLICE_CONFIG; 1137 if ( (m_codec != SWVENC_CODEC_H263) && (pParam->bEnableDataPartitioning) ) 1138 { 1139 DEBUG_PRINT_ERROR("DataPartioning are not Supported for this codec"); 1140 break; 1141 } 1142 if ( (m_codec != SWVENC_CODEC_H263) && (pParam->nResynchMarkerSpacing) ) 1143 { 1144 Prop.info.slice_config.mode = SWVENC_SLICE_MODE_BYTE; 1145 Prop.info.slice_config.size = pParam->nResynchMarkerSpacing; 1146 } 1147 else if ( (SWVENC_CODEC_H263 == m_codec) && (pParam->bEnableResync) ) 1148 { 1149 Prop.info.slice_config.mode = SWVENC_SLICE_MODE_GOB; 1150 Prop.info.slice_config.size = 0; 1151 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 1152 if (Ret != SWVENC_S_SUCCESS) 1153 { 1154 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 1155 __FUNCTION__, Ret); 1156 RETURN(OMX_ErrorUndefined); 1157 } 1158 } 1159 else 1160 { 1161 Prop.info.slice_config.mode = SWVENC_SLICE_MODE_OFF; 1162 Prop.info.slice_config.size = 0; 1163 } 1164 1165 memcpy(&m_sErrorCorrection,pParam, sizeof(m_sErrorCorrection)); 1166 break; 1167 } 1168 1169 case OMX_IndexParamVideoIntraRefresh: 1170 { 1171 DEBUG_PRINT_LOW("set_param:OMX_IndexParamVideoIntraRefresh"); 1172 OMX_VIDEO_PARAM_INTRAREFRESHTYPE* pParam = 1173 (OMX_VIDEO_PARAM_INTRAREFRESHTYPE*)paramData; 1174 1175 Ret = swvenc_set_intra_refresh(pParam); 1176 if (Ret != SWVENC_S_SUCCESS) 1177 { 1178 DEBUG_PRINT_ERROR("%s, swvenc_set_intra_refresh failed (%d)", 1179 __FUNCTION__, Ret); 1180 RETURN(OMX_ErrorUnsupportedSetting); 1181 } 1182 1183 memcpy(&m_sIntraRefresh, pParam, sizeof(m_sIntraRefresh)); 1184 break; 1185 } 1186 1187 case OMX_QcomIndexParamVideoMetaBufferMode: 1188 { 1189 StoreMetaDataInBuffersParams *pParam = 1190 (StoreMetaDataInBuffersParams*)paramData; 1191 DEBUG_PRINT_HIGH("set_parameter:OMX_QcomIndexParamVideoMetaBufferMode: " 1192 "port_index = %u, meta_mode = %d", pParam->nPortIndex, pParam->bStoreMetaData); 1193 1194 if (pParam->nPortIndex == PORT_INDEX_IN) 1195 { 1196 if (pParam->bStoreMetaData != meta_mode_enable) 1197 { 1198 meta_mode_enable = pParam->bStoreMetaData; 1199 if (!meta_mode_enable) 1200 { 1201 Ret = swvenc_get_buffer_req(&m_sOutPortDef.nBufferCountMin, 1202 &m_sOutPortDef.nBufferCountActual, 1203 &m_sOutPortDef.nBufferSize, 1204 &m_sOutPortDef.nBufferAlignment, 1205 m_sOutPortDef.nPortIndex); 1206 if (Ret != SWVENC_S_SUCCESS) 1207 { 1208 DEBUG_PRINT_ERROR("ERROR: %s, swvenc_get_buffer_req failed (%d)", __FUNCTION__, 1209 Ret); 1210 eRet = OMX_ErrorUndefined; 1211 break; 1212 } 1213 } 1214 } 1215 } 1216 else if (pParam->nPortIndex == PORT_INDEX_OUT && secure_session) 1217 { 1218 if (pParam->bStoreMetaData != meta_mode_enable) 1219 { 1220 meta_mode_enable = pParam->bStoreMetaData; 1221 } 1222 } 1223 else 1224 { 1225 if (pParam->bStoreMetaData) 1226 { 1227 DEBUG_PRINT_ERROR("set_parameter: metamode is " 1228 "valid for input port only"); 1229 eRet = OMX_ErrorUnsupportedIndex; 1230 } 1231 } 1232 } 1233 break; 1234 1235 case OMX_QcomIndexParamIndexExtraDataType: 1236 { 1237 DEBUG_PRINT_HIGH("set_parameter: OMX_QcomIndexParamIndexExtraDataType"); 1238 QOMX_INDEXEXTRADATATYPE *pParam = (QOMX_INDEXEXTRADATATYPE *)paramData; 1239 OMX_U32 mask = 0; 1240 1241 if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderSliceInfo) 1242 { 1243 if (pParam->nPortIndex == PORT_INDEX_OUT) 1244 { 1245 mask = VEN_EXTRADATA_SLICEINFO; 1246 1247 DEBUG_PRINT_HIGH("SliceInfo extradata %s", 1248 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled")); 1249 } 1250 else 1251 { 1252 DEBUG_PRINT_ERROR("set_parameter: Slice information is " 1253 "valid for output port only"); 1254 eRet = OMX_ErrorUnsupportedIndex; 1255 break; 1256 } 1257 } 1258 else if (pParam->nIndex == (OMX_INDEXTYPE)OMX_ExtraDataVideoEncoderMBInfo) 1259 { 1260 if (pParam->nPortIndex == PORT_INDEX_OUT) 1261 { 1262 mask = VEN_EXTRADATA_MBINFO; 1263 1264 DEBUG_PRINT_HIGH("MBInfo extradata %s", 1265 ((pParam->bEnabled == OMX_TRUE) ? "enabled" : "disabled")); 1266 } 1267 else 1268 { 1269 DEBUG_PRINT_ERROR("set_parameter: MB information is " 1270 "valid for output port only"); 1271 eRet = OMX_ErrorUnsupportedIndex; 1272 break; 1273 } 1274 } 1275 else 1276 { 1277 DEBUG_PRINT_ERROR("set_parameter: unsupported extrdata index (%x)", 1278 pParam->nIndex); 1279 eRet = OMX_ErrorUnsupportedIndex; 1280 break; 1281 } 1282 1283 1284 if (pParam->bEnabled == OMX_TRUE) 1285 { 1286 m_sExtraData |= mask; 1287 } 1288 else 1289 { 1290 m_sExtraData &= ~mask; 1291 } 1292 1293 #if 0 1294 // TBD: add setprop to swvenc once the support is added 1295 if (handle->venc_set_param((OMX_PTR)!!(m_sExtraData & mask), 1296 (OMX_INDEXTYPE)pParam->nIndex) != true) 1297 { 1298 DEBUG_PRINT_ERROR("ERROR: Setting Extradata (%x) failed", pParam->nIndex); 1299 RETURN(OMX_ErrorUnsupportedSetting); 1300 } 1301 else 1302 #endif 1303 { 1304 m_sOutPortDef.nPortIndex = PORT_INDEX_OUT; 1305 bResult = dev_get_buf_req(&m_sOutPortDef.nBufferCountMin, 1306 &m_sOutPortDef.nBufferCountActual, 1307 &m_sOutPortDef.nBufferSize, 1308 m_sOutPortDef.nPortIndex); 1309 if (false == bResult) 1310 { 1311 DEBUG_PRINT_ERROR("dev_get_buf_req failed"); 1312 eRet = OMX_ErrorUndefined; 1313 break; 1314 } 1315 1316 DEBUG_PRINT_HIGH("updated out_buf_req: buffer cnt=%u, " 1317 "count min=%u, buffer size=%u", 1318 m_sOutPortDef.nBufferCountActual, 1319 m_sOutPortDef.nBufferCountMin, 1320 m_sOutPortDef.nBufferSize); 1321 } 1322 break; 1323 } 1324 1325 case OMX_QcomIndexParamVideoMaxAllowedBitrateCheck: 1326 { 1327 QOMX_EXTNINDEX_PARAMTYPE* pParam = 1328 (QOMX_EXTNINDEX_PARAMTYPE*)paramData; 1329 if (pParam->nPortIndex == PORT_INDEX_OUT) 1330 { 1331 m_max_allowed_bitrate_check = 1332 ((pParam->bEnable == OMX_TRUE) ? true : false); 1333 DEBUG_PRINT_HIGH("set_parameter: max allowed bitrate check %s", 1334 ((pParam->bEnable == OMX_TRUE) ? "enabled" : "disabled")); 1335 } 1336 else 1337 { 1338 DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexParamVideoMaxAllowedBitrateCheck " 1339 " called on wrong port(%u)", pParam->nPortIndex); 1340 RETURN(OMX_ErrorBadPortIndex); 1341 } 1342 break; 1343 } 1344 1345 case OMX_QcomIndexEnableSliceDeliveryMode: 1346 { 1347 QOMX_EXTNINDEX_PARAMTYPE* pParam = 1348 (QOMX_EXTNINDEX_PARAMTYPE*)paramData; 1349 if (pParam->nPortIndex == PORT_INDEX_OUT) 1350 { 1351 //TBD: add setprop to swvenc once the support is added 1352 #if 0 1353 if (!handle->venc_set_param(paramData, 1354 (OMX_INDEXTYPE)OMX_QcomIndexEnableSliceDeliveryMode)) { 1355 DEBUG_PRINT_ERROR("ERROR: Request for setting slice delivery mode failed"); 1356 RETURN( OMX_ErrorUnsupportedSetting; 1357 } 1358 #endif 1359 { 1360 DEBUG_PRINT_ERROR("ERROR: Request for setting slice delivery mode failed"); 1361 RETURN(OMX_ErrorUnsupportedSetting); 1362 } 1363 } 1364 else 1365 { 1366 DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexEnableSliceDeliveryMode " 1367 "called on wrong port(%u)", pParam->nPortIndex); 1368 RETURN(OMX_ErrorBadPortIndex); 1369 } 1370 break; 1371 } 1372 1373 case OMX_QcomIndexEnableH263PlusPType: 1374 { 1375 QOMX_EXTNINDEX_PARAMTYPE* pParam = 1376 (QOMX_EXTNINDEX_PARAMTYPE*)paramData; 1377 DEBUG_PRINT_LOW("OMX_QcomIndexEnableH263PlusPType"); 1378 if (pParam->nPortIndex == PORT_INDEX_OUT) 1379 { 1380 DEBUG_PRINT_ERROR("ERROR: Request for setting PlusPType failed"); 1381 RETURN(OMX_ErrorUnsupportedSetting); 1382 } 1383 else 1384 { 1385 DEBUG_PRINT_ERROR("ERROR: OMX_QcomIndexEnableH263PlusPType " 1386 "called on wrong port(%u)", pParam->nPortIndex); 1387 RETURN(OMX_ErrorBadPortIndex); 1388 } 1389 break; 1390 } 1391 1392 case OMX_QcomIndexParamPeakBitrate: 1393 { 1394 DEBUG_PRINT_ERROR("ERROR: Setting peak bitrate"); 1395 RETURN(OMX_ErrorUnsupportedSetting); 1396 break; 1397 } 1398 1399 case QOMX_IndexParamVideoInitialQp: 1400 { 1401 // TBD: applicable to RC-on case only 1402 DEBUG_PRINT_ERROR("ERROR: Setting Initial QP for RC-on case"); 1403 RETURN(OMX_ErrorNone); 1404 break; 1405 } 1406 1407 1408 case OMX_QcomIndexParamSetMVSearchrange: 1409 { 1410 DEBUG_PRINT_ERROR("ERROR: Setting Searchrange"); 1411 RETURN(OMX_ErrorUnsupportedSetting); 1412 break; 1413 } 1414 1415 default: 1416 { 1417 DEBUG_PRINT_ERROR("ERROR: Setparameter: unknown param %d", paramIndex); 1418 eRet = OMX_ErrorUnsupportedIndex; 1419 break; 1420 } 1421 } 1422 1423 RETURN(eRet); 1424 } 1425 1426 OMX_ERRORTYPE omx_venc::set_config 1427 ( 1428 OMX_IN OMX_HANDLETYPE hComp, 1429 OMX_IN OMX_INDEXTYPE configIndex, 1430 OMX_IN OMX_PTR configData 1431 ) 1432 { 1433 ENTER_FUNC(); 1434 1435 SWVENC_STATUS SwStatus; 1436 1437 (void)hComp; 1438 1439 if (configData == NULL) 1440 { 1441 DEBUG_PRINT_ERROR("ERROR: param is null"); 1442 RETURN(OMX_ErrorBadParameter); 1443 } 1444 1445 if (m_state == OMX_StateInvalid) 1446 { 1447 DEBUG_PRINT_ERROR("ERROR: config called in Invalid state"); 1448 RETURN(OMX_ErrorIncorrectStateOperation); 1449 } 1450 1451 switch ((int)configIndex) 1452 { 1453 case OMX_IndexConfigVideoBitrate: 1454 { 1455 OMX_VIDEO_CONFIG_BITRATETYPE* pParam = 1456 reinterpret_cast<OMX_VIDEO_CONFIG_BITRATETYPE*>(configData); 1457 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoBitrate (%u)", pParam->nEncodeBitrate); 1458 1459 if (pParam->nPortIndex == PORT_INDEX_OUT) 1460 { 1461 SwStatus = swvenc_set_bit_rate(pParam->nEncodeBitrate); 1462 if (SwStatus != SWVENC_S_SUCCESS) 1463 { 1464 DEBUG_PRINT_ERROR("%s, swvenc_set_bit_rate failed (%d)", 1465 __FUNCTION__, SwStatus); 1466 RETURN(OMX_ErrorUnsupportedSetting); 1467 } 1468 1469 m_sConfigBitrate.nEncodeBitrate = pParam->nEncodeBitrate; 1470 m_sParamBitrate.nTargetBitrate = pParam->nEncodeBitrate; 1471 m_sOutPortDef.format.video.nBitrate = pParam->nEncodeBitrate; 1472 } 1473 else 1474 { 1475 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex); 1476 RETURN(OMX_ErrorBadPortIndex); 1477 } 1478 break; 1479 } 1480 case OMX_IndexConfigVideoFramerate: 1481 { 1482 OMX_CONFIG_FRAMERATETYPE* pParam = 1483 reinterpret_cast<OMX_CONFIG_FRAMERATETYPE*>(configData); 1484 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoFramerate (0x%x)", pParam->xEncodeFramerate); 1485 1486 if (pParam->nPortIndex == PORT_INDEX_OUT) 1487 { 1488 SwStatus = swvenc_set_frame_rate(pParam->xEncodeFramerate >> 16); 1489 if (SwStatus != SWVENC_S_SUCCESS) 1490 { 1491 DEBUG_PRINT_ERROR("%s, swvenc_set_frame_rate failed (%d)", 1492 __FUNCTION__, SwStatus); 1493 RETURN(OMX_ErrorUnsupportedSetting); 1494 } 1495 1496 m_sConfigFramerate.xEncodeFramerate = pParam->xEncodeFramerate; 1497 m_sOutPortDef.format.video.xFramerate = pParam->xEncodeFramerate; 1498 m_sOutPortFormat.xFramerate = pParam->xEncodeFramerate; 1499 } 1500 else 1501 { 1502 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex); 1503 RETURN(OMX_ErrorBadPortIndex); 1504 } 1505 break; 1506 } 1507 case QOMX_IndexConfigVideoIntraperiod: 1508 { 1509 QOMX_VIDEO_INTRAPERIODTYPE* pParam = 1510 reinterpret_cast<QOMX_VIDEO_INTRAPERIODTYPE*>(configData); 1511 DEBUG_PRINT_HIGH("set_config(): QOMX_IndexConfigVideoIntraperiod"); 1512 1513 if (pParam->nPortIndex == PORT_INDEX_OUT) 1514 { 1515 if (pParam->nBFrames > 0) 1516 { 1517 DEBUG_PRINT_ERROR("B frames not supported"); 1518 RETURN(OMX_ErrorUnsupportedSetting); 1519 } 1520 1521 DEBUG_PRINT_HIGH("Old: P/B frames = %u/%u, New: P/B frames = %u/%u", 1522 m_sIntraperiod.nPFrames, m_sIntraperiod.nBFrames, 1523 pParam->nPFrames, pParam->nBFrames); 1524 if (m_sIntraperiod.nBFrames != pParam->nBFrames) 1525 { 1526 DEBUG_PRINT_HIGH("Dynamically changing B-frames not supported"); 1527 RETURN(OMX_ErrorUnsupportedSetting); 1528 } 1529 1530 /* set the intra period */ 1531 SwStatus = swvenc_set_intra_period(pParam->nPFrames,pParam->nBFrames); 1532 if (SwStatus != SWVENC_S_SUCCESS) 1533 { 1534 DEBUG_PRINT_ERROR("%s, swvenc_set_intra_period failed (%d)", 1535 __FUNCTION__, SwStatus); 1536 RETURN(OMX_ErrorUnsupportedSetting); 1537 } 1538 1539 m_sIntraperiod.nPFrames = pParam->nPFrames; 1540 m_sIntraperiod.nBFrames = pParam->nBFrames; 1541 m_sIntraperiod.nIDRPeriod = pParam->nIDRPeriod; 1542 1543 if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingMPEG4) 1544 { 1545 m_sParamMPEG4.nPFrames = pParam->nPFrames; 1546 if (m_sParamMPEG4.eProfile != OMX_VIDEO_MPEG4ProfileSimple) 1547 { 1548 m_sParamMPEG4.nBFrames = pParam->nBFrames; 1549 } 1550 else 1551 { 1552 m_sParamMPEG4.nBFrames = 0; 1553 } 1554 } 1555 else if (m_sOutPortFormat.eCompressionFormat == OMX_VIDEO_CodingH263) 1556 { 1557 m_sParamH263.nPFrames = pParam->nPFrames; 1558 } 1559 } 1560 else 1561 { 1562 DEBUG_PRINT_ERROR("ERROR: (QOMX_IndexConfigVideoIntraperiod) Unsupported port index: %u", pParam->nPortIndex); 1563 RETURN(OMX_ErrorBadPortIndex); 1564 } 1565 1566 break; 1567 } 1568 case OMX_IndexConfigVideoIntraVOPRefresh: 1569 { 1570 OMX_CONFIG_INTRAREFRESHVOPTYPE* pParam = 1571 reinterpret_cast<OMX_CONFIG_INTRAREFRESHVOPTYPE*>(configData); 1572 DEBUG_PRINT_HIGH("set_config(): OMX_IndexConfigVideoIntraVOPRefresh"); 1573 1574 if (pParam->nPortIndex == PORT_INDEX_OUT) 1575 { 1576 1577 SWVENC_PROPERTY Prop; 1578 1579 Prop.id = SWVENC_PROPERTY_ID_IFRAME_REQUEST; 1580 1581 SwStatus = swvenc_setproperty(m_hSwVenc, &Prop); 1582 if (SwStatus != SWVENC_S_SUCCESS) 1583 { 1584 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 1585 __FUNCTION__, SwStatus); 1586 RETURN(OMX_ErrorUnsupportedSetting); 1587 } 1588 1589 m_sConfigIntraRefreshVOP.IntraRefreshVOP = pParam->IntraRefreshVOP; 1590 } 1591 else 1592 { 1593 DEBUG_PRINT_ERROR("ERROR: Unsupported port index: %u", pParam->nPortIndex); 1594 RETURN(OMX_ErrorBadPortIndex); 1595 } 1596 break; 1597 } 1598 case OMX_IndexConfigCommonRotate: 1599 { 1600 DEBUG_PRINT_ERROR("ERROR: OMX_IndexConfigCommonRotate not supported"); 1601 RETURN(OMX_ErrorUnsupportedSetting); 1602 break; 1603 } 1604 default: 1605 DEBUG_PRINT_ERROR("ERROR: unsupported index %d", (int) configIndex); 1606 break; 1607 } 1608 1609 EXIT_FUNC(); 1610 1611 RETURN(OMX_ErrorNone); 1612 } 1613 1614 OMX_ERRORTYPE omx_venc::component_deinit(OMX_IN OMX_HANDLETYPE hComp) 1615 { 1616 ENTER_FUNC(); 1617 1618 OMX_U32 i = 0; 1619 DEBUG_PRINT_HIGH("omx_venc(): Inside component_deinit()"); 1620 1621 (void)hComp; 1622 1623 if (OMX_StateLoaded != m_state) 1624 { 1625 DEBUG_PRINT_ERROR("WARNING:Rxd DeInit,OMX not in LOADED state %d", 1626 m_state); 1627 } 1628 if (m_out_mem_ptr) 1629 { 1630 DEBUG_PRINT_LOW("Freeing the Output Memory"); 1631 for (i=0; i< m_sOutPortDef.nBufferCountActual; i++ ) 1632 { 1633 free_output_buffer (&m_out_mem_ptr[i]); 1634 } 1635 free(m_out_mem_ptr); 1636 m_out_mem_ptr = NULL; 1637 } 1638 1639 /* Check if the input buffers have to be cleaned up */ 1640 if ( m_inp_mem_ptr && !meta_mode_enable ) 1641 { 1642 DEBUG_PRINT_LOW("Freeing the Input Memory"); 1643 for (i=0; i<m_sInPortDef.nBufferCountActual; i++) 1644 { 1645 free_input_buffer (&m_inp_mem_ptr[i]); 1646 } 1647 1648 free(m_inp_mem_ptr); 1649 m_inp_mem_ptr = NULL; 1650 } 1651 1652 /* Reset counters in msg queues */ 1653 m_ftb_q.m_size=0; 1654 m_cmd_q.m_size=0; 1655 m_etb_q.m_size=0; 1656 m_ftb_q.m_read = m_ftb_q.m_write =0; 1657 m_cmd_q.m_read = m_cmd_q.m_write =0; 1658 m_etb_q.m_read = m_etb_q.m_write =0; 1659 1660 /* Clear the strong reference */ 1661 DEBUG_PRINT_HIGH("Calling m_heap_ptr.clear()"); 1662 m_heap_ptr.clear(); 1663 1664 DEBUG_PRINT_HIGH("Calling swvenc_deinit()"); 1665 swvenc_deinit(m_hSwVenc); 1666 1667 DEBUG_PRINT_HIGH("OMX_Venc:Component Deinit"); 1668 1669 RETURN(OMX_ErrorNone); 1670 } 1671 1672 OMX_U32 omx_venc::dev_stop(void) 1673 { 1674 ENTER_FUNC(); 1675 1676 SWVENC_STATUS Ret; 1677 1678 if (false == m_stopped) 1679 { 1680 Ret = swvenc_stop(m_hSwVenc); 1681 if (Ret != SWVENC_S_SUCCESS) 1682 { 1683 DEBUG_PRINT_ERROR("%s, swvenc_stop failed (%d)", 1684 __FUNCTION__, Ret); 1685 RETURN(-1); 1686 } 1687 format_set = false; 1688 m_stopped = true; 1689 1690 /* post STOP_DONE event as start is synchronus */ 1691 post_event (0, OMX_ErrorNone, OMX_COMPONENT_GENERATE_STOP_DONE); 1692 } 1693 1694 RETURN(0); 1695 } 1696 1697 OMX_U32 omx_venc::dev_pause(void) 1698 { 1699 ENTER_FUNC(); 1700 // nothing to be done for sw encoder 1701 1702 RETURN(true); 1703 } 1704 1705 OMX_U32 omx_venc::dev_resume(void) 1706 { 1707 ENTER_FUNC(); 1708 // nothing to be done for sw encoder 1709 1710 RETURN(true); 1711 } 1712 1713 OMX_U32 omx_venc::dev_start(void) 1714 { 1715 ENTER_FUNC(); 1716 SWVENC_STATUS Ret; 1717 Ret = swvenc_start(m_hSwVenc); 1718 if (Ret != SWVENC_S_SUCCESS) 1719 { 1720 DEBUG_PRINT_ERROR("%s, swvenc_start failed (%d)", 1721 __FUNCTION__, Ret); 1722 RETURN(-1); 1723 } 1724 1725 m_stopped = false; 1726 1727 RETURN(0); 1728 } 1729 1730 OMX_U32 omx_venc::dev_flush(unsigned port) 1731 { 1732 ENTER_FUNC(); 1733 SWVENC_STATUS Ret; 1734 1735 (void)port; 1736 Ret = swvenc_flush(m_hSwVenc); 1737 if (Ret != SWVENC_S_SUCCESS) 1738 { 1739 DEBUG_PRINT_ERROR("%s, swvenc_flush failed (%d)", 1740 __FUNCTION__, Ret); 1741 RETURN(-1); 1742 } 1743 1744 RETURN(0); 1745 } 1746 1747 OMX_U32 omx_venc::dev_start_done(void) 1748 { 1749 ENTER_FUNC(); 1750 1751 /* post START_DONE event as start is synchronus */ 1752 post_event (0, OMX_ErrorNone, OMX_COMPONENT_GENERATE_START_DONE); 1753 1754 RETURN(0); 1755 } 1756 1757 OMX_U32 omx_venc::dev_set_message_thread_id(pthread_t tid) 1758 { 1759 ENTER_FUNC(); 1760 1761 // nothing to be done for sw encoder 1762 (void)tid; 1763 1764 RETURN(true); 1765 } 1766 1767 bool omx_venc::dev_use_buf(void *buf_addr,unsigned port,unsigned index) 1768 { 1769 ENTER_FUNC(); 1770 1771 (void)buf_addr; 1772 (void)port; 1773 (void)index; 1774 1775 RETURN(true); 1776 } 1777 1778 bool omx_venc::dev_free_buf(void *buf_addr,unsigned port) 1779 { 1780 ENTER_FUNC(); 1781 1782 (void)buf_addr; 1783 (void)port; 1784 1785 RETURN(true); 1786 } 1787 1788 bool omx_venc::dev_empty_buf 1789 ( 1790 void *buffer, 1791 void *pmem_data_buf, 1792 unsigned index, 1793 unsigned fd 1794 ) 1795 { 1796 ENTER_FUNC(); 1797 1798 SWVENC_STATUS Ret; 1799 SWVENC_IPBUFFER ipbuffer; 1800 OMX_BUFFERHEADERTYPE *bufhdr = (OMX_BUFFERHEADERTYPE *)buffer; 1801 unsigned int size = 0, filled_length, offset = 0; 1802 1803 (void)pmem_data_buf; 1804 (void)index; 1805 1806 if (meta_mode_enable) 1807 { 1808 encoder_media_buffer_type *meta_buf = NULL; 1809 meta_buf = (encoder_media_buffer_type *)bufhdr->pBuffer; 1810 if (meta_buf) 1811 { 1812 if (meta_buf->buffer_type == kMetadataBufferTypeCameraSource) 1813 { 1814 offset = meta_buf->meta_handle->data[1]; 1815 size = meta_buf->meta_handle->data[2]; 1816 if (!format_set && 1817 (meta_buf->meta_handle->numFds + meta_buf->meta_handle->numInts > 5)) 1818 { 1819 format_set = true; 1820 if (((OMX_COLOR_FORMATTYPE) meta_buf->meta_handle->data[5]) != 1821 m_sInPortFormat.eColorFormat) 1822 { 1823 return false; 1824 } 1825 } 1826 } 1827 else if (meta_buf->buffer_type == kMetadataBufferTypeGrallocSource) 1828 { 1829 private_handle_t *handle = (private_handle_t *)meta_buf->meta_handle; 1830 size = handle->size; 1831 } 1832 } 1833 ipbuffer.p_buffer = (unsigned char *)mmap(NULL, size, PROT_READ|PROT_WRITE,MAP_SHARED, fd, offset); 1834 ipbuffer.size = size; 1835 ipbuffer.filled_length = size; 1836 } 1837 else 1838 { 1839 ipbuffer.p_buffer = bufhdr->pBuffer; 1840 ipbuffer.size = bufhdr->nAllocLen; 1841 ipbuffer.filled_length = bufhdr->nFilledLen; 1842 } 1843 ipbuffer.flags = 0; 1844 if (bufhdr->nFlags & OMX_BUFFERFLAG_EOS) 1845 { 1846 ipbuffer.flags |= SWVENC_FLAG_EOS; 1847 } 1848 ipbuffer.timestamp = bufhdr->nTimeStamp; 1849 ipbuffer.p_client_data = (unsigned char *)bufhdr; 1850 1851 DEBUG_PRINT_LOW("ETB: p_buffer (%p) size (%d) filled_len (%d) flags (0x%X) timestamp (%lld) clientData (%p)", 1852 ipbuffer.p_buffer, 1853 ipbuffer.size, 1854 ipbuffer.filled_length, 1855 (unsigned int)ipbuffer.flags, 1856 ipbuffer.timestamp, 1857 ipbuffer.p_client_data); 1858 1859 Ret = swvenc_emptythisbuffer(m_hSwVenc, &ipbuffer); 1860 if (Ret != SWVENC_S_SUCCESS) 1861 { 1862 DEBUG_PRINT_ERROR("%s, swvenc_emptythisbuffer failed (%d)", 1863 __FUNCTION__, Ret); 1864 RETURN(false); 1865 } 1866 1867 if (m_debug.in_buffer_log) 1868 { 1869 swvenc_input_log_buffers((const char*)ipbuffer.p_buffer, ipbuffer.filled_length); 1870 } 1871 1872 RETURN(true); 1873 } 1874 1875 bool omx_venc::dev_fill_buf 1876 ( 1877 void *buffer, 1878 void *pmem_data_buf, 1879 unsigned index, 1880 unsigned fd 1881 ) 1882 { 1883 ENTER_FUNC(); 1884 1885 SWVENC_STATUS Ret; 1886 1887 SWVENC_OPBUFFER opbuffer; 1888 OMX_BUFFERHEADERTYPE *bufhdr = (OMX_BUFFERHEADERTYPE *)buffer; 1889 1890 (void)pmem_data_buf; 1891 (void)index; 1892 (void)fd; 1893 1894 opbuffer.p_buffer = bufhdr->pBuffer; 1895 opbuffer.size = bufhdr->nAllocLen; 1896 opbuffer.filled_length = bufhdr->nFilledLen; 1897 opbuffer.flags = bufhdr->nFlags; 1898 opbuffer.extradata_type = SWVENC_EXTRADATA_TYPE_NONE; 1899 opbuffer.p_extradata = NULL; 1900 opbuffer.p_client_data = (unsigned char *)bufhdr; 1901 1902 DEBUG_PRINT_LOW("FTB: p_buffer (%p) size (%d) filled_len (%d) flags (0x%X) timestamp (%lld) clientData (%p)", 1903 opbuffer.p_buffer, 1904 opbuffer.size, 1905 opbuffer.filled_length, 1906 opbuffer.flags, 1907 opbuffer.timestamp, 1908 opbuffer.p_client_data); 1909 DEBUG_PRINT_LOW("FTB: extradata_type (%d) p_extradata (%p)", 1910 opbuffer.extradata_type, 1911 opbuffer.p_extradata); 1912 1913 if ( false == m_bSeqHdrRequested) 1914 { 1915 if (dev_get_seq_hdr(opbuffer.p_buffer, opbuffer.size, &opbuffer.filled_length) == 0) 1916 { 1917 bufhdr->nFilledLen = opbuffer.filled_length; 1918 bufhdr->nOffset = 0; 1919 bufhdr->nTimeStamp = 0; 1920 bufhdr->nFlags = OMX_BUFFERFLAG_CODECCONFIG; 1921 1922 DEBUG_PRINT_LOW("sending FBD with codec config"); 1923 m_bSeqHdrRequested = true; 1924 post_event ((unsigned long)bufhdr,0,OMX_COMPONENT_GENERATE_FBD); 1925 } 1926 else 1927 { 1928 DEBUG_PRINT_ERROR("ERROR: couldn't get sequence header"); 1929 post_event(OMX_EventError,OMX_ErrorUndefined,OMX_COMPONENT_GENERATE_EVENT); 1930 } 1931 } 1932 else 1933 { 1934 Ret = swvenc_fillthisbuffer(m_hSwVenc, &opbuffer); 1935 if (Ret != SWVENC_S_SUCCESS) 1936 { 1937 DEBUG_PRINT_ERROR("%s, swvenc_fillthisbuffer failed (%d)", 1938 __FUNCTION__, Ret); 1939 RETURN(false); 1940 } 1941 } 1942 1943 RETURN(true); 1944 } 1945 1946 bool omx_venc::dev_get_seq_hdr 1947 ( 1948 void *buffer, 1949 unsigned size, 1950 unsigned *hdrlen 1951 ) 1952 { 1953 ENTER_FUNC(); 1954 1955 SWVENC_STATUS Ret; 1956 SWVENC_OPBUFFER Buffer; 1957 1958 Buffer.p_buffer = (unsigned char*) buffer; 1959 Buffer.size = size; 1960 1961 Ret = swvenc_getsequenceheader(m_hSwVenc, &Buffer); 1962 if (Ret != SWVENC_S_SUCCESS) 1963 { 1964 DEBUG_PRINT_ERROR("%s, swvenc_flush failed (%d)", 1965 __FUNCTION__, Ret); 1966 RETURN(-1); 1967 } 1968 1969 *hdrlen = Buffer.filled_length; 1970 1971 RETURN(0); 1972 } 1973 1974 bool omx_venc::dev_get_capability_ltrcount 1975 ( 1976 OMX_U32 *min, 1977 OMX_U32 *max, 1978 OMX_U32 *step_size 1979 ) 1980 { 1981 ENTER_FUNC(); 1982 1983 (void)min; 1984 (void)max; 1985 (void)step_size; 1986 1987 DEBUG_PRINT_ERROR("Get Capability LTR Count is not supported"); 1988 1989 RETURN(false); 1990 } 1991 1992 bool omx_venc::dev_get_performance_level(OMX_U32 *perflevel) 1993 { 1994 ENTER_FUNC(); 1995 1996 (void)perflevel; 1997 DEBUG_PRINT_ERROR("Get performance level is not supported"); 1998 1999 RETURN(false); 2000 } 2001 2002 bool omx_venc::dev_get_vui_timing_info(OMX_U32 *enabled) 2003 { 2004 ENTER_FUNC(); 2005 2006 (void)enabled; 2007 DEBUG_PRINT_ERROR("Get vui timing information is not supported"); 2008 2009 RETURN(false); 2010 } 2011 2012 bool omx_venc::dev_get_vqzip_sei_info(OMX_U32 *enabled) 2013 { 2014 ENTER_FUNC(); 2015 2016 (void)enabled; 2017 DEBUG_PRINT_ERROR("Get vqzip sei info is not supported"); 2018 2019 RETURN(false); 2020 } 2021 2022 bool omx_venc::dev_get_peak_bitrate(OMX_U32 *peakbitrate) 2023 { 2024 //TBD: store the peak bitrate in class and return here; 2025 ENTER_FUNC(); 2026 2027 (void)peakbitrate; 2028 DEBUG_PRINT_ERROR("Get peak bitrate is not supported"); 2029 2030 RETURN(false); 2031 } 2032 2033 bool omx_venc::dev_get_batch_size(OMX_U32 *size) 2034 { 2035 ENTER_FUNC(); 2036 2037 (void)size; 2038 2039 DEBUG_PRINT_ERROR("Get batch size is not supported"); 2040 2041 RETURN(false); 2042 } 2043 2044 bool omx_venc::dev_loaded_start() 2045 { 2046 ENTER_FUNC(); 2047 RETURN(true); 2048 } 2049 2050 bool omx_venc::dev_loaded_stop() 2051 { 2052 ENTER_FUNC(); 2053 RETURN(true); 2054 } 2055 2056 bool omx_venc::dev_loaded_start_done() 2057 { 2058 ENTER_FUNC(); 2059 RETURN(true); 2060 } 2061 2062 bool omx_venc::dev_loaded_stop_done() 2063 { 2064 ENTER_FUNC(); 2065 RETURN(true); 2066 } 2067 2068 bool omx_venc::dev_get_buf_req(OMX_U32 *min_buff_count, 2069 OMX_U32 *actual_buff_count, 2070 OMX_U32 *buff_size, 2071 OMX_U32 port) 2072 { 2073 ENTER_FUNC(); 2074 2075 bool bRet = true; 2076 OMX_PARAM_PORTDEFINITIONTYPE *PortDef; 2077 2078 if (PORT_INDEX_IN == port) 2079 { 2080 PortDef = &m_sInPortDef; 2081 } 2082 else if (PORT_INDEX_OUT == port) 2083 { 2084 PortDef = &m_sOutPortDef; 2085 } 2086 else 2087 { 2088 DEBUG_PRINT_ERROR("ERROR: %s, Unsupported parameter", __FUNCTION__); 2089 bRet = false; 2090 } 2091 2092 if (true == bRet) 2093 { 2094 *min_buff_count = PortDef->nBufferCountMin; 2095 *actual_buff_count = PortDef->nBufferCountActual; 2096 *buff_size = PortDef->nBufferSize; 2097 } 2098 2099 RETURN(true); 2100 } 2101 2102 bool omx_venc::dev_set_buf_req 2103 ( 2104 OMX_U32 const *min_buff_count, 2105 OMX_U32 const *actual_buff_count, 2106 OMX_U32 const *buff_size, 2107 OMX_U32 port 2108 ) 2109 { 2110 ENTER_FUNC(); 2111 2112 SWVENC_STATUS Ret; 2113 OMX_PARAM_PORTDEFINITIONTYPE *PortDef; 2114 2115 (void)min_buff_count; 2116 if (PORT_INDEX_IN == port) 2117 { 2118 PortDef = &m_sInPortDef; 2119 } 2120 else if (PORT_INDEX_OUT == port) 2121 { 2122 PortDef = &m_sOutPortDef; 2123 } 2124 else 2125 { 2126 DEBUG_PRINT_ERROR("ERROR: %s, Unsupported parameter", __FUNCTION__); 2127 RETURN(false); 2128 } 2129 2130 if (*actual_buff_count < PortDef->nBufferCountMin) 2131 { 2132 DEBUG_PRINT_ERROR("ERROR: %s, (actual,min) buffer count (%d, %d)", 2133 __FUNCTION__, *actual_buff_count, PortDef->nBufferCountMin); 2134 RETURN(false); 2135 } 2136 if (false == meta_mode_enable) 2137 { 2138 if (*buff_size < PortDef->nBufferSize) 2139 { 2140 DEBUG_PRINT_ERROR("ERROR: %s, (new,old) buffer count (%d, %d)", 2141 __FUNCTION__, *actual_buff_count, PortDef->nBufferCountMin); 2142 RETURN(false); 2143 } 2144 } 2145 2146 RETURN(true); 2147 } 2148 2149 bool omx_venc::dev_is_video_session_supported(OMX_U32 width, OMX_U32 height) 2150 { 2151 ENTER_FUNC(); 2152 2153 if ( (width * height < m_capability.min_width * m_capability.min_height) || 2154 (width * height > m_capability.max_width * m_capability.max_height) 2155 ) 2156 { 2157 DEBUG_PRINT_ERROR( 2158 "Unsupported Resolution WxH = (%u)x(%u) Supported Range = min (%d)x(%d) - max (%d)x(%d)", 2159 width, height, 2160 m_capability.min_width, m_capability.min_height, 2161 m_capability.max_width, m_capability.max_height); 2162 RETURN(false); 2163 } 2164 2165 RETURN(true); 2166 } 2167 2168 int omx_venc::dev_handle_output_extradata(void *buffer, int index) 2169 { 2170 ENTER_FUNC(); 2171 2172 (void)buffer; 2173 (void)index; 2174 2175 RETURN(true); 2176 } 2177 2178 int omx_venc::dev_handle_input_extradata(void *buffer, int index, int fd) 2179 { 2180 ENTER_FUNC(); 2181 2182 (void)buffer; 2183 (void)index; 2184 (void)fd; 2185 2186 RETURN(true); 2187 } 2188 2189 int omx_venc::dev_set_format(int color) 2190 { 2191 ENTER_FUNC(); 2192 2193 (void)color; 2194 2195 RETURN(true); 2196 //return handle->venc_set_format(color); 2197 } 2198 2199 bool omx_venc::dev_color_align(OMX_BUFFERHEADERTYPE *buffer, 2200 OMX_U32 width, OMX_U32 height) 2201 { 2202 ENTER_FUNC(); 2203 2204 (void)buffer; 2205 (void)width; 2206 (void)height; 2207 if(secure_session) { 2208 DEBUG_PRINT_ERROR("Cannot align colors in secure session."); 2209 RETURN(OMX_FALSE); 2210 } 2211 2212 RETURN(true); 2213 //return handle->venc_color_align(buffer, width,height); 2214 } 2215 2216 bool omx_venc::is_secure_session() 2217 { 2218 ENTER_FUNC(); 2219 2220 RETURN(secure_session); 2221 } 2222 2223 bool omx_venc::dev_get_output_log_flag() 2224 { 2225 ENTER_FUNC(); 2226 2227 RETURN(m_debug.out_buffer_log == 1); 2228 } 2229 2230 int omx_venc::dev_output_log_buffers(const char *buffer, int bufferlen) 2231 { 2232 ENTER_FUNC(); 2233 2234 if (m_debug.out_buffer_log && !m_debug.outfile) 2235 { 2236 int size = 0; 2237 int width = m_sInPortDef.format.video.nFrameWidth; 2238 int height = m_sInPortDef.format.video.nFrameHeight; 2239 if(SWVENC_CODEC_MPEG4 == m_codec) 2240 { 2241 size = snprintf(m_debug.outfile_name, PROPERTY_VALUE_MAX, 2242 "%s/output_enc_%d_%d_%p.m4v", 2243 m_debug.log_loc, width, height, this); 2244 } 2245 else if(SWVENC_CODEC_H263 == m_codec) 2246 { 2247 size = snprintf(m_debug.outfile_name, PROPERTY_VALUE_MAX, 2248 "%s/output_enc_%d_%d_%p.263", 2249 m_debug.log_loc, width, height, this); 2250 } 2251 if ((size > PROPERTY_VALUE_MAX) || (size < 0)) 2252 { 2253 DEBUG_PRINT_ERROR("Failed to open output file: %s for logging as size:%d", 2254 m_debug.outfile_name, size); 2255 RETURN(-1); 2256 } 2257 DEBUG_PRINT_LOW("output filename = %s", m_debug.outfile_name); 2258 m_debug.outfile = fopen(m_debug.outfile_name, "ab"); 2259 if (!m_debug.outfile) 2260 { 2261 DEBUG_PRINT_ERROR("Failed to open output file: %s for logging errno:%d", 2262 m_debug.outfile_name, errno); 2263 m_debug.outfile_name[0] = '\0'; 2264 RETURN(-1); 2265 } 2266 } 2267 if (m_debug.outfile && buffer && bufferlen) 2268 { 2269 DEBUG_PRINT_LOW("%s buffer length: %d", __func__, bufferlen); 2270 fwrite(buffer, bufferlen, 1, m_debug.outfile); 2271 } 2272 2273 RETURN(0); 2274 } 2275 2276 int omx_venc::swvenc_input_log_buffers(const char *buffer, int bufferlen) 2277 { 2278 int width = m_sInPortDef.format.video.nFrameWidth; 2279 int height = m_sInPortDef.format.video.nFrameHeight; 2280 int stride = VENUS_Y_STRIDE(COLOR_FMT_NV12, width); 2281 int scanlines = VENUS_Y_SCANLINES(COLOR_FMT_NV12, height); 2282 char *temp = (char*)buffer; 2283 2284 if (!m_debug.infile) 2285 { 2286 int size = snprintf(m_debug.infile_name, PROPERTY_VALUE_MAX, 2287 "%s/input_enc_%d_%d_%p.yuv", 2288 m_debug.log_loc, width, height, this); 2289 if ((size > PROPERTY_VALUE_MAX) || (size < 0)) 2290 { 2291 DEBUG_PRINT_ERROR("Failed to open input file: %s for logging size:%d", 2292 m_debug.infile_name, size); 2293 RETURN(-1); 2294 } 2295 DEBUG_PRINT_LOW("input filename = %s", m_debug.infile_name); 2296 m_debug.infile = fopen (m_debug.infile_name, "ab"); 2297 if (!m_debug.infile) 2298 { 2299 DEBUG_PRINT_HIGH("Failed to open input file: %s for logging", 2300 m_debug.infile_name); 2301 m_debug.infile_name[0] = '\0'; 2302 RETURN(-1); 2303 } 2304 } 2305 if (m_debug.infile && buffer && bufferlen) 2306 { 2307 DEBUG_PRINT_LOW("%s buffer length: %d", __func__, bufferlen); 2308 for (int i = 0; i < height; i++) 2309 { 2310 fwrite(temp, width, 1, m_debug.infile); 2311 temp += stride; 2312 } 2313 for(int i = 0; i < height/2; i++) 2314 { 2315 fwrite(temp, width, 1, m_debug.infile); 2316 temp += stride; 2317 } 2318 } 2319 2320 RETURN(0); 2321 } 2322 2323 int omx_venc::dev_extradata_log_buffers(char *buffer) 2324 { 2325 ENTER_FUNC(); 2326 2327 (void)buffer; 2328 2329 RETURN(true); 2330 //return handle->venc_extradata_log_buffers(buffer); 2331 } 2332 2333 SWVENC_STATUS omx_venc::swvenc_get_buffer_req 2334 ( 2335 OMX_U32 *min_buff_count, 2336 OMX_U32 *actual_buff_count, 2337 OMX_U32 *buff_size, 2338 OMX_U32 *buff_alignment, 2339 OMX_U32 port 2340 ) 2341 { 2342 ENTER_FUNC(); 2343 2344 SWVENC_PROPERTY Prop; 2345 SWVENC_STATUS Ret; 2346 OMX_PARAM_PORTDEFINITIONTYPE *PortDef; 2347 2348 Prop.id = SWVENC_PROPERTY_ID_BUFFER_REQ; 2349 if (PORT_INDEX_IN == port) 2350 { 2351 Prop.info.buffer_req.type = SWVENC_BUFFER_INPUT; 2352 } 2353 else if (PORT_INDEX_OUT == port) 2354 { 2355 Prop.info.buffer_req.type = SWVENC_BUFFER_OUTPUT; 2356 } 2357 else 2358 { 2359 DEBUG_PRINT_ERROR("ERROR: %s, Unsupported parameter", __FUNCTION__); 2360 RETURN(SWVENC_S_INVALID_PARAMETERS); 2361 } 2362 2363 Ret = swvenc_getproperty(m_hSwVenc, &Prop); 2364 if (Ret != SWVENC_S_SUCCESS) 2365 { 2366 DEBUG_PRINT_ERROR("ERROR: %s, swvenc_setproperty failed (%d)", __FUNCTION__, 2367 Ret); 2368 RETURN(SWVENC_S_INVALID_PARAMETERS); 2369 } 2370 2371 *buff_size = Prop.info.buffer_req.size; 2372 *min_buff_count = Prop.info.buffer_req.mincount; 2373 *actual_buff_count = Prop.info.buffer_req.mincount; 2374 *buff_alignment = Prop.info.buffer_req.alignment; 2375 2376 RETURN(Ret); 2377 } 2378 2379 SWVENC_STATUS omx_venc::swvenc_empty_buffer_done_cb 2380 ( 2381 SWVENC_HANDLE swvenc, 2382 SWVENC_IPBUFFER *p_ipbuffer, 2383 void *p_client 2384 ) 2385 { 2386 ENTER_FUNC(); 2387 2388 (void)swvenc; 2389 SWVENC_STATUS eRet = SWVENC_S_SUCCESS; 2390 omx_venc *omx = reinterpret_cast<omx_venc*>(p_client); 2391 2392 if (p_ipbuffer == NULL) 2393 { 2394 eRet = SWVENC_S_FAILURE; 2395 } 2396 else 2397 { 2398 omx->swvenc_empty_buffer_done(p_ipbuffer); 2399 } 2400 return eRet; 2401 } 2402 2403 SWVENC_STATUS omx_venc::swvenc_empty_buffer_done 2404 ( 2405 SWVENC_IPBUFFER *p_ipbuffer 2406 ) 2407 { 2408 SWVENC_STATUS eRet = SWVENC_S_SUCCESS; 2409 OMX_ERRORTYPE error = OMX_ErrorNone; 2410 OMX_BUFFERHEADERTYPE* omxhdr = NULL; 2411 2412 //omx_video *omx = reinterpret_cast<omx_video*>(p_client); 2413 omxhdr = (OMX_BUFFERHEADERTYPE*)p_ipbuffer->p_client_data; 2414 2415 DEBUG_PRINT_LOW("EBD: clientData (%p)", p_ipbuffer->p_client_data); 2416 2417 if ( (omxhdr == NULL) || 2418 ( ((OMX_U32)(omxhdr - m_inp_mem_ptr) >m_sInPortDef.nBufferCountActual) && 2419 ((OMX_U32)(omxhdr - meta_buffer_hdr) >m_sInPortDef.nBufferCountActual) 2420 ) 2421 ) 2422 { 2423 omxhdr = NULL; 2424 error = OMX_ErrorUndefined; 2425 } 2426 2427 if (omxhdr != NULL) 2428 { 2429 // unmap the input buffer->pBuffer 2430 omx_release_meta_buffer(omxhdr); 2431 #ifdef _ANDROID_ICS_ 2432 if (meta_mode_enable) 2433 { 2434 encoder_media_buffer_type *meta_buf = NULL; 2435 unsigned int size = 0; 2436 meta_buf = (encoder_media_buffer_type *)omxhdr->pBuffer; 2437 if (meta_buf) 2438 { 2439 if (meta_buf->buffer_type == kMetadataBufferTypeCameraSource) 2440 { 2441 size = meta_buf->meta_handle->data[2]; 2442 } 2443 else if (meta_buf->buffer_type == kMetadataBufferTypeGrallocSource) 2444 { 2445 private_handle_t *handle = (private_handle_t *)meta_buf->meta_handle; 2446 size = handle->size; 2447 } 2448 } 2449 int status = munmap(p_ipbuffer->p_buffer, size); 2450 DEBUG_PRINT_HIGH("Unmapped pBuffer <%p> size <%d> status <%d>", p_ipbuffer->p_buffer, size, status); 2451 } 2452 #endif 2453 post_event ((unsigned long)omxhdr,error,OMX_COMPONENT_GENERATE_EBD); 2454 } 2455 2456 RETURN(eRet); 2457 } 2458 2459 SWVENC_STATUS omx_venc::swvenc_fill_buffer_done_cb 2460 ( 2461 SWVENC_HANDLE swvenc, 2462 SWVENC_OPBUFFER *p_opbuffer, 2463 void *p_client 2464 ) 2465 { 2466 ENTER_FUNC(); 2467 2468 SWVENC_STATUS eRet = SWVENC_S_SUCCESS; 2469 OMX_ERRORTYPE error = OMX_ErrorNone; 2470 OMX_BUFFERHEADERTYPE* omxhdr = NULL; 2471 omx_video *omx = reinterpret_cast<omx_video*>(p_client); 2472 2473 (void)swvenc; 2474 2475 if (p_opbuffer != NULL) 2476 { 2477 omxhdr = (OMX_BUFFERHEADERTYPE*)p_opbuffer->p_client_data; 2478 } 2479 2480 if ( (p_opbuffer != NULL) && 2481 ((OMX_U32)(omxhdr - omx->m_out_mem_ptr) < omx->m_sOutPortDef.nBufferCountActual) 2482 ) 2483 { 2484 DEBUG_PRINT_LOW("FBD: clientData (%p) buffer (%p) filled_lengh (%d) flags (0x%x) ts (%lld)", 2485 p_opbuffer->p_client_data, 2486 p_opbuffer->p_buffer, 2487 p_opbuffer->filled_length, 2488 p_opbuffer->flags, 2489 p_opbuffer->timestamp); 2490 2491 if (p_opbuffer->filled_length <= omxhdr->nAllocLen) 2492 { 2493 omxhdr->pBuffer = p_opbuffer->p_buffer; 2494 omxhdr->nFilledLen = p_opbuffer->filled_length; 2495 omxhdr->nOffset = 0; 2496 omxhdr->nTimeStamp = p_opbuffer->timestamp; 2497 omxhdr->nFlags = 0; 2498 if (SWVENC_FRAME_TYPE_I == p_opbuffer->frame_type) 2499 { 2500 omxhdr->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 2501 } 2502 if (SWVENC_FLAG_EOS & p_opbuffer->flags) 2503 { 2504 omxhdr->nFlags |= OMX_BUFFERFLAG_EOS; 2505 } 2506 if(omxhdr->nFilledLen) 2507 { 2508 omxhdr->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; 2509 } 2510 DEBUG_PRINT_LOW("o/p flag = 0x%x", omxhdr->nFlags); 2511 2512 /* Use buffer case */ 2513 if (omx->output_use_buffer && !omx->m_use_output_pmem) 2514 { 2515 DEBUG_PRINT_LOW("memcpy() for o/p Heap UseBuffer"); 2516 memcpy( omxhdr->pBuffer, 2517 (p_opbuffer->p_buffer), 2518 p_opbuffer->filled_length ); 2519 } 2520 } 2521 else 2522 { 2523 omxhdr->nFilledLen = 0; 2524 } 2525 2526 } 2527 else 2528 { 2529 omxhdr = NULL; 2530 error = OMX_ErrorUndefined; 2531 } 2532 2533 omx->post_event ((unsigned long)omxhdr,error,OMX_COMPONENT_GENERATE_FBD); 2534 2535 RETURN(eRet); 2536 } 2537 2538 SWVENC_STATUS omx_venc::swvenc_handle_event_cb 2539 ( 2540 SWVENC_HANDLE swvenc, 2541 SWVENC_EVENT event, 2542 void *p_client 2543 ) 2544 { 2545 ENTER_FUNC(); 2546 2547 SWVENC_STATUS eRet = SWVENC_S_SUCCESS; 2548 omx_video *omx = reinterpret_cast<omx_video*>(p_client); 2549 2550 OMX_BUFFERHEADERTYPE* omxhdr = NULL; 2551 2552 (void)swvenc; 2553 2554 if (omx == NULL || p_client == NULL) 2555 { 2556 DEBUG_PRINT_ERROR("ERROR: %s invalid i/p params", __FUNCTION__); 2557 RETURN(SWVENC_S_NULL_POINTER); 2558 } 2559 2560 DEBUG_PRINT_LOW("swvenc_handle_event_cb - event = %d", event); 2561 2562 switch (event) 2563 { 2564 case SWVENC_EVENT_FLUSH_DONE: 2565 { 2566 DEBUG_PRINT_ERROR("SWVENC_EVENT_FLUSH_DONE input_flush_progress %d output_flush_progress %d", 2567 omx->input_flush_progress, omx->output_flush_progress); 2568 if (omx->input_flush_progress) 2569 { 2570 omx->post_event ((unsigned)NULL, SWVENC_S_SUCCESS, 2571 OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH); 2572 } 2573 if (omx->output_flush_progress) 2574 { 2575 omx->post_event ((unsigned)NULL, SWVENC_S_SUCCESS, 2576 OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH); 2577 } 2578 break; 2579 } 2580 2581 case SWVENC_EVENT_FATAL_ERROR: 2582 { 2583 DEBUG_PRINT_ERROR("ERROR: SWVENC_EVENT_FATAL_ERROR"); 2584 omx->omx_report_error(); 2585 break; 2586 } 2587 2588 default: 2589 DEBUG_PRINT_HIGH("Unknown event received : %d", event); 2590 break; 2591 } 2592 2593 RETURN(eRet); 2594 } 2595 2596 SWVENC_STATUS omx_venc::swvenc_set_rc_mode 2597 ( 2598 OMX_VIDEO_CONTROLRATETYPE eControlRate 2599 ) 2600 { 2601 ENTER_FUNC(); 2602 2603 SWVENC_STATUS Ret = SWVENC_S_SUCCESS; 2604 SWVENC_RC_MODE rc_mode; 2605 SWVENC_PROPERTY Prop; 2606 2607 switch (eControlRate) 2608 { 2609 case OMX_Video_ControlRateDisable: 2610 rc_mode = SWVENC_RC_MODE_NONE; 2611 break; 2612 case OMX_Video_ControlRateVariableSkipFrames: 2613 rc_mode = SWVENC_RC_MODE_VBR_VFR; 2614 break; 2615 case OMX_Video_ControlRateVariable: 2616 rc_mode = SWVENC_RC_MODE_VBR_CFR; 2617 break; 2618 case OMX_Video_ControlRateConstantSkipFrames: 2619 rc_mode = SWVENC_RC_MODE_CBR_VFR; 2620 break; 2621 case OMX_Video_ControlRateConstant: 2622 rc_mode = SWVENC_RC_MODE_CBR_CFR; 2623 break; 2624 default: 2625 DEBUG_PRINT_ERROR("ERROR: UNKNOWN RC MODE"); 2626 Ret = SWVENC_S_FAILURE; 2627 break; 2628 } 2629 2630 if (SWVENC_S_SUCCESS == Ret) 2631 { 2632 Prop.id = SWVENC_PROPERTY_ID_RC_MODE; 2633 Prop.info.rc_mode = rc_mode; 2634 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 2635 if (Ret != SWVENC_S_SUCCESS) 2636 { 2637 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 2638 __FUNCTION__, Ret); 2639 RETURN(SWVENC_S_FAILURE); 2640 } 2641 } 2642 2643 RETURN(Ret); 2644 } 2645 2646 SWVENC_STATUS omx_venc::swvenc_set_profile_level 2647 ( 2648 OMX_U32 eProfile, 2649 OMX_U32 eLevel 2650 ) 2651 { 2652 ENTER_FUNC(); 2653 2654 SWVENC_STATUS Ret = SWVENC_S_SUCCESS; 2655 SWVENC_PROPERTY Prop; 2656 SWVENC_PROFILE Profile; 2657 SWVENC_LEVEL Level; 2658 2659 /* set the profile */ 2660 if (SWVENC_CODEC_MPEG4 == m_codec) 2661 { 2662 switch (eProfile) 2663 { 2664 case OMX_VIDEO_MPEG4ProfileSimple: 2665 Profile.mpeg4 = SWVENC_PROFILE_MPEG4_SIMPLE; 2666 break; 2667 case OMX_VIDEO_MPEG4ProfileAdvancedSimple: 2668 Profile.mpeg4 = SWVENC_PROFILE_MPEG4_ADVANCED_SIMPLE; 2669 break; 2670 default: 2671 DEBUG_PRINT_ERROR("ERROR: UNKNOWN PROFILE"); 2672 Ret = SWVENC_S_FAILURE; 2673 break; 2674 } 2675 switch (eLevel) 2676 { 2677 case OMX_VIDEO_MPEG4Level0: 2678 Level.mpeg4 = SWVENC_LEVEL_MPEG4_0; 2679 break; 2680 case OMX_VIDEO_MPEG4Level0b: 2681 Level.mpeg4 = SWVENC_LEVEL_MPEG4_0B; 2682 break; 2683 case OMX_VIDEO_MPEG4Level1: 2684 Level.mpeg4 = SWVENC_LEVEL_MPEG4_1; 2685 break; 2686 case OMX_VIDEO_MPEG4Level2: 2687 Level.mpeg4 = SWVENC_LEVEL_MPEG4_2; 2688 break; 2689 case OMX_VIDEO_MPEG4Level3: 2690 Level.mpeg4 = SWVENC_LEVEL_MPEG4_3; 2691 break; 2692 case OMX_VIDEO_MPEG4Level4: 2693 Level.mpeg4 = SWVENC_LEVEL_MPEG4_4; 2694 break; 2695 case OMX_VIDEO_MPEG4Level4a: 2696 Level.mpeg4 = SWVENC_LEVEL_MPEG4_4A; 2697 break; 2698 case OMX_VIDEO_MPEG4Level5: 2699 Level.mpeg4 = SWVENC_LEVEL_MPEG4_5; 2700 break; 2701 default: 2702 DEBUG_PRINT_ERROR("ERROR: UNKNOWN LEVEL"); 2703 Ret = SWVENC_S_FAILURE; 2704 break; 2705 } 2706 } 2707 else if (SWVENC_CODEC_H263 == m_codec) 2708 { 2709 switch (eProfile) 2710 { 2711 case OMX_VIDEO_H263ProfileBaseline: 2712 Profile.h263 = SWVENC_PROFILE_H263_BASELINE; 2713 break; 2714 default: 2715 DEBUG_PRINT_ERROR("ERROR: UNKNOWN PROFILE"); 2716 Ret = SWVENC_S_FAILURE; 2717 break; 2718 } 2719 switch (eLevel) 2720 { 2721 case OMX_VIDEO_H263Level10: 2722 Level.h263 = SWVENC_LEVEL_H263_10; 2723 break; 2724 case OMX_VIDEO_H263Level20: 2725 Level.h263 = SWVENC_LEVEL_H263_20; 2726 break; 2727 case OMX_VIDEO_H263Level30: 2728 Level.h263 = SWVENC_LEVEL_H263_30; 2729 break; 2730 case OMX_VIDEO_H263Level40: 2731 Level.h263 = SWVENC_LEVEL_H263_40; 2732 break; 2733 case OMX_VIDEO_H263Level50: 2734 Level.h263 = SWVENC_LEVEL_H263_50; 2735 break; 2736 case OMX_VIDEO_H263Level60: 2737 Level.h263 = SWVENC_LEVEL_H263_60; 2738 break; 2739 case OMX_VIDEO_H263Level70: 2740 Level.h263 = SWVENC_LEVEL_H263_70; 2741 break; 2742 default: 2743 DEBUG_PRINT_ERROR("ERROR: UNKNOWN LEVEL"); 2744 Ret = SWVENC_S_FAILURE; 2745 break; 2746 } 2747 } 2748 else 2749 { 2750 DEBUG_PRINT_ERROR("ERROR: UNSUPPORTED CODEC"); 2751 Ret = SWVENC_S_FAILURE; 2752 } 2753 2754 if (SWVENC_S_SUCCESS == Ret) 2755 { 2756 Prop.id = SWVENC_PROPERTY_ID_PROFILE; 2757 Prop.info.profile = Profile; 2758 2759 /* set the profile */ 2760 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 2761 if (Ret != SWVENC_S_SUCCESS) 2762 { 2763 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 2764 __FUNCTION__, Ret); 2765 RETURN(SWVENC_S_FAILURE); 2766 } 2767 2768 /* set the level */ 2769 Prop.id = SWVENC_PROPERTY_ID_LEVEL; 2770 Prop.info.level = Level; 2771 2772 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 2773 if (Ret != SWVENC_S_SUCCESS) 2774 { 2775 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 2776 __FUNCTION__, Ret); 2777 RETURN(SWVENC_S_FAILURE); 2778 } 2779 } 2780 2781 RETURN(Ret); 2782 } 2783 2784 SWVENC_STATUS omx_venc::swvenc_set_intra_refresh 2785 ( 2786 OMX_VIDEO_PARAM_INTRAREFRESHTYPE *IntraRefresh 2787 ) 2788 { 2789 ENTER_FUNC(); 2790 2791 SWVENC_STATUS Ret = SWVENC_S_SUCCESS; 2792 SWVENC_IR_CONFIG ir_config; 2793 SWVENC_PROPERTY Prop; 2794 2795 switch (IntraRefresh->eRefreshMode) 2796 { 2797 case OMX_VIDEO_IntraRefreshCyclic: 2798 Prop.info.ir_config.mode = SWVENC_IR_MODE_CYCLIC; 2799 break; 2800 case OMX_VIDEO_IntraRefreshAdaptive: 2801 Prop.info.ir_config.mode = SWVENC_IR_MODE_ADAPTIVE; 2802 break; 2803 case OMX_VIDEO_IntraRefreshBoth: 2804 Prop.info.ir_config.mode = SWVENC_IR_MODE_CYCLIC_ADAPTIVE; 2805 break; 2806 case OMX_VIDEO_IntraRefreshRandom: 2807 Prop.info.ir_config.mode = SWVENC_IR_MODE_RANDOM; 2808 break; 2809 default: 2810 DEBUG_PRINT_ERROR("ERROR: UNKNOWN INTRA REFRESH MODE"); 2811 Ret = SWVENC_S_FAILURE; 2812 break; 2813 } 2814 2815 if (SWVENC_S_SUCCESS == Ret) 2816 { 2817 Prop.id = SWVENC_PROPERTY_ID_IR_CONFIG; 2818 Prop.info.ir_config.cir_mbs = IntraRefresh->nCirMBs; 2819 2820 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 2821 if (Ret != SWVENC_S_SUCCESS) 2822 { 2823 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 2824 __FUNCTION__, Ret); 2825 Ret = SWVENC_S_FAILURE; 2826 } 2827 } 2828 2829 RETURN(Ret); 2830 } 2831 2832 SWVENC_STATUS omx_venc::swvenc_set_frame_rate 2833 ( 2834 OMX_U32 nFrameRate 2835 ) 2836 { 2837 ENTER_FUNC(); 2838 2839 SWVENC_STATUS Ret = SWVENC_S_SUCCESS; 2840 SWVENC_PROPERTY Prop; 2841 2842 Prop.id = SWVENC_PROPERTY_ID_FRAME_RATE; 2843 Prop.info.frame_rate = nFrameRate; 2844 2845 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 2846 if (Ret != SWVENC_S_SUCCESS) 2847 { 2848 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 2849 __FUNCTION__, Ret); 2850 Ret = SWVENC_S_FAILURE; 2851 } 2852 2853 RETURN(Ret); 2854 } 2855 2856 SWVENC_STATUS omx_venc::swvenc_set_bit_rate 2857 ( 2858 OMX_U32 nTargetBitrate 2859 ) 2860 { 2861 ENTER_FUNC(); 2862 2863 SWVENC_STATUS Ret = SWVENC_S_SUCCESS; 2864 SWVENC_PROPERTY Prop; 2865 2866 Prop.id = SWVENC_PROPERTY_ID_TARGET_BITRATE; 2867 Prop.info.target_bitrate = nTargetBitrate; 2868 2869 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 2870 if (Ret != SWVENC_S_SUCCESS) 2871 { 2872 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 2873 __FUNCTION__, Ret); 2874 Ret = SWVENC_S_FAILURE; 2875 } 2876 2877 RETURN(Ret); 2878 } 2879 2880 SWVENC_STATUS omx_venc::swvenc_set_intra_period 2881 ( 2882 OMX_U32 nPFrame, 2883 OMX_U32 nBFrame 2884 ) 2885 { 2886 ENTER_FUNC(); 2887 2888 SWVENC_STATUS Ret = SWVENC_S_SUCCESS; 2889 SWVENC_PROPERTY Prop; 2890 2891 Prop.id = SWVENC_PROPERTY_ID_INTRA_PERIOD; 2892 Prop.info.intra_period.pframes = nPFrame; 2893 Prop.info.intra_period.bframes = nBFrame; 2894 2895 Ret = swvenc_setproperty(m_hSwVenc, &Prop); 2896 if (Ret != SWVENC_S_SUCCESS) 2897 { 2898 DEBUG_PRINT_ERROR("%s, swvenc_setproperty failed (%d)", 2899 __FUNCTION__, Ret); 2900 Ret = SWVENC_S_FAILURE; 2901 } 2902 2903 RETURN(Ret); 2904 } 2905