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