1 /* 2 * 3 * Copyright 2010 Samsung Electronics S.LSI Co. LTD 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /* 19 * @file SEC_OMX_Mpeg4enc.c 20 * @brief 21 * @author Yunji Kim (yunji.kim (at) samsung.com) 22 * @version 1.0 23 * @history 24 * 2010.7.15 : Create 25 */ 26 27 28 #include <stdio.h> 29 #include <stdlib.h> 30 #include <string.h> 31 32 #include "SEC_OMX_Macros.h" 33 #include "SEC_OMX_Basecomponent.h" 34 #include "SEC_OMX_Baseport.h" 35 #include "SEC_OMX_Venc.h" 36 #include "library_register.h" 37 #include "SEC_OMX_Mpeg4enc.h" 38 #include "SsbSipMfcApi.h" 39 #include "color_space_convertor.h" 40 41 #undef SEC_LOG_TAG 42 #define SEC_LOG_TAG "SEC_MPEG4_ENC" 43 #define SEC_LOG_OFF 44 #include "SEC_OSAL_Log.h" 45 46 47 /* MPEG4 Encoder Supported Levels & profiles */ 48 SEC_OMX_VIDEO_PROFILELEVEL supportedMPEG4ProfileLevels[] ={ 49 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0}, 50 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0b}, 51 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level1}, 52 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level2}, 53 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level3}, 54 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level4}, 55 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level4a}, 56 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level5}, 57 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level0}, 58 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level0b}, 59 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level1}, 60 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level2}, 61 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level3}, 62 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level4}, 63 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level4a}, 64 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level5}}; 65 66 /* H.263 Encoder Supported Levels & profiles */ 67 SEC_OMX_VIDEO_PROFILELEVEL supportedH263ProfileLevels[] = { 68 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10}, 69 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level20}, 70 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level30}, 71 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level40}, 72 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level45}, 73 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level50}, 74 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level60}, 75 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level70}}; 76 77 OMX_U32 OMXMpeg4ProfileToMFCProfile(OMX_VIDEO_MPEG4PROFILETYPE profile) 78 { 79 OMX_U32 ret; 80 81 switch (profile) { 82 case OMX_VIDEO_MPEG4ProfileSimple: 83 ret = 0; 84 break; 85 case OMX_VIDEO_MPEG4ProfileAdvancedSimple: 86 ret = 1; 87 break; 88 default: 89 ret = 0; 90 }; 91 92 return ret; 93 } 94 OMX_U32 OMXMpeg4LevelToMFCLevel(OMX_VIDEO_MPEG4LEVELTYPE level) 95 { 96 OMX_U32 ret; 97 98 switch (level) { 99 case OMX_VIDEO_MPEG4Level0: 100 ret = 0; 101 break; 102 case OMX_VIDEO_MPEG4Level0b: 103 ret = 9; 104 break; 105 case OMX_VIDEO_MPEG4Level1: 106 ret = 1; 107 break; 108 case OMX_VIDEO_MPEG4Level2: 109 ret = 2; 110 break; 111 case OMX_VIDEO_MPEG4Level3: 112 ret = 3; 113 break; 114 case OMX_VIDEO_MPEG4Level4: 115 case OMX_VIDEO_MPEG4Level4a: 116 ret = 4; 117 break; 118 case OMX_VIDEO_MPEG4Level5: 119 ret = 5; 120 break; 121 default: 122 ret = 0; 123 }; 124 125 return ret; 126 } 127 128 void Mpeg4PrintParams(SSBSIP_MFC_ENC_MPEG4_PARAM mpeg4Param) 129 { 130 SEC_OSAL_Log(SEC_LOG_TRACE, "SourceWidth : %d\n", mpeg4Param.SourceWidth); 131 SEC_OSAL_Log(SEC_LOG_TRACE, "SourceHeight : %d\n", mpeg4Param.SourceHeight); 132 SEC_OSAL_Log(SEC_LOG_TRACE, "IDRPeriod : %d\n", mpeg4Param.IDRPeriod); 133 SEC_OSAL_Log(SEC_LOG_TRACE, "SliceMode : %d\n", mpeg4Param.SliceMode); 134 SEC_OSAL_Log(SEC_LOG_TRACE, "RandomIntraMBRefresh : %d\n", mpeg4Param.RandomIntraMBRefresh); 135 SEC_OSAL_Log(SEC_LOG_TRACE, "EnableFRMRateControl : %d\n", mpeg4Param.EnableFRMRateControl); 136 SEC_OSAL_Log(SEC_LOG_TRACE, "Bitrate : %d\n", mpeg4Param.Bitrate); 137 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp : %d\n", mpeg4Param.FrameQp); 138 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp_P : %d\n", mpeg4Param.FrameQp_P); 139 SEC_OSAL_Log(SEC_LOG_TRACE, "QSCodeMax : %d\n", mpeg4Param.QSCodeMax); 140 SEC_OSAL_Log(SEC_LOG_TRACE, "QSCodeMin : %d\n", mpeg4Param.QSCodeMin); 141 SEC_OSAL_Log(SEC_LOG_TRACE, "CBRPeriodRf : %d\n", mpeg4Param.CBRPeriodRf); 142 SEC_OSAL_Log(SEC_LOG_TRACE, "PadControlOn : %d\n", mpeg4Param.PadControlOn); 143 SEC_OSAL_Log(SEC_LOG_TRACE, "LumaPadVal : %d\n", mpeg4Param.LumaPadVal); 144 SEC_OSAL_Log(SEC_LOG_TRACE, "CbPadVal : %d\n", mpeg4Param.CbPadVal); 145 SEC_OSAL_Log(SEC_LOG_TRACE, "CrPadVal : %d\n", mpeg4Param.CrPadVal); 146 147 /* MPEG4 specific parameters */ 148 SEC_OSAL_Log(SEC_LOG_TRACE, "ProfileIDC : %d\n", mpeg4Param.ProfileIDC); 149 SEC_OSAL_Log(SEC_LOG_TRACE, "LevelIDC : %d\n", mpeg4Param.LevelIDC); 150 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp_B : %d\n", mpeg4Param.FrameQp_B); 151 SEC_OSAL_Log(SEC_LOG_TRACE, "TimeIncreamentRes : %d\n", mpeg4Param.TimeIncreamentRes); 152 SEC_OSAL_Log(SEC_LOG_TRACE, "VopTimeIncreament : %d\n", mpeg4Param.VopTimeIncreament); 153 SEC_OSAL_Log(SEC_LOG_TRACE, "SliceArgument : %d\n", mpeg4Param.SliceArgument); 154 SEC_OSAL_Log(SEC_LOG_TRACE, "NumberBFrames : %d\n", mpeg4Param.NumberBFrames); 155 SEC_OSAL_Log(SEC_LOG_TRACE, "DisableQpelME : %d\n", mpeg4Param.DisableQpelME); 156 } 157 158 void H263PrintParams(SSBSIP_MFC_ENC_H263_PARAM h263Param) 159 { 160 SEC_OSAL_Log(SEC_LOG_TRACE, "SourceWidth : %d\n", h263Param.SourceWidth); 161 SEC_OSAL_Log(SEC_LOG_TRACE, "SourceHeight : %d\n", h263Param.SourceHeight); 162 SEC_OSAL_Log(SEC_LOG_TRACE, "IDRPeriod : %d\n", h263Param.IDRPeriod); 163 SEC_OSAL_Log(SEC_LOG_TRACE, "SliceMode : %d\n", h263Param.SliceMode); 164 SEC_OSAL_Log(SEC_LOG_TRACE, "RandomIntraMBRefresh : %d\n", h263Param.RandomIntraMBRefresh); 165 SEC_OSAL_Log(SEC_LOG_TRACE, "EnableFRMRateControl : %d\n", h263Param.EnableFRMRateControl); 166 SEC_OSAL_Log(SEC_LOG_TRACE, "Bitrate : %d\n", h263Param.Bitrate); 167 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp : %d\n", h263Param.FrameQp); 168 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp_P : %d\n", h263Param.FrameQp_P); 169 SEC_OSAL_Log(SEC_LOG_TRACE, "QSCodeMax : %d\n", h263Param.QSCodeMax); 170 SEC_OSAL_Log(SEC_LOG_TRACE, "QSCodeMin : %d\n", h263Param.QSCodeMin); 171 SEC_OSAL_Log(SEC_LOG_TRACE, "CBRPeriodRf : %d\n", h263Param.CBRPeriodRf); 172 SEC_OSAL_Log(SEC_LOG_TRACE, "PadControlOn : %d\n", h263Param.PadControlOn); 173 SEC_OSAL_Log(SEC_LOG_TRACE, "LumaPadVal : %d\n", h263Param.LumaPadVal); 174 SEC_OSAL_Log(SEC_LOG_TRACE, "CbPadVal : %d\n", h263Param.CbPadVal); 175 SEC_OSAL_Log(SEC_LOG_TRACE, "CrPadVal : %d\n", h263Param.CrPadVal); 176 177 /* H.263 specific parameters */ 178 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameRate : %d\n", h263Param.FrameRate); 179 } 180 181 void Set_Mpeg4Enc_Param(SSBSIP_MFC_ENC_MPEG4_PARAM *pMpeg4Param, SEC_OMX_BASECOMPONENT *pSECComponent) 182 { 183 SEC_OMX_BASEPORT *pSECInputPort = NULL; 184 SEC_OMX_BASEPORT *pSECOutputPort = NULL; 185 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 186 187 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 188 pSECInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 189 pSECOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 190 191 pMpeg4Param->codecType = MPEG4_ENC; 192 pMpeg4Param->SourceWidth = pSECOutputPort->portDefinition.format.video.nFrameWidth; 193 pMpeg4Param->SourceHeight = pSECOutputPort->portDefinition.format.video.nFrameHeight; 194 pMpeg4Param->IDRPeriod = pMpeg4Enc->mpeg4Component[OUTPUT_PORT_INDEX].nPFrames + 1; 195 pMpeg4Param->SliceMode = 0; 196 pMpeg4Param->RandomIntraMBRefresh = 0; 197 pMpeg4Param->EnableFRMRateControl = 1; /* 0: disable, 1: enable */ 198 pMpeg4Param->Bitrate = pSECOutputPort->portDefinition.format.video.nBitrate; 199 pMpeg4Param->FrameQp = 20; 200 pMpeg4Param->FrameQp_P = 20; 201 pMpeg4Param->QSCodeMax = 30; 202 pMpeg4Param->QSCodeMin = 10; 203 pMpeg4Param->CBRPeriodRf = 10; 204 pMpeg4Param->PadControlOn = 0; /* 0: Use boundary pixel, 1: Use the below setting value */ 205 pMpeg4Param->LumaPadVal = 0; 206 pMpeg4Param->CbPadVal = 0; 207 pMpeg4Param->CrPadVal = 0; 208 209 pMpeg4Param->ProfileIDC = OMXMpeg4ProfileToMFCProfile(pMpeg4Enc->mpeg4Component[OUTPUT_PORT_INDEX].eProfile); 210 pMpeg4Param->LevelIDC = OMXMpeg4LevelToMFCLevel(pMpeg4Enc->mpeg4Component[OUTPUT_PORT_INDEX].eLevel); 211 pMpeg4Param->FrameQp_B = 20; 212 pMpeg4Param->TimeIncreamentRes = (pSECInputPort->portDefinition.format.video.xFramerate) >> 16; 213 pMpeg4Param->VopTimeIncreament = 1; 214 pMpeg4Param->SliceArgument = 0; /* MB number or byte number */ 215 pMpeg4Param->NumberBFrames = 0; /* 0(not used) ~ 2 */ 216 pMpeg4Param->DisableQpelME = 1; 217 218 switch ((SEC_OMX_COLOR_FORMATTYPE)pSECInputPort->portDefinition.format.video.eColorFormat) { 219 case OMX_COLOR_FormatYUV420SemiPlanar: 220 pMpeg4Param->FrameMap = NV12_LINEAR; 221 break; 222 case OMX_SEC_COLOR_FormatNV12TPhysicalAddress: 223 default: 224 pMpeg4Param->FrameMap = NV12_TILE; 225 break; 226 } 227 228 #ifdef USE_ANDROID_EXTENSION 229 if (pSECInputPort->bStoreMetaDataInBuffer != OMX_FALSE) { 230 SEC_OMX_DATA *pInputData = &pSECComponent->processData[INPUT_PORT_INDEX]; 231 if(isMetadataBufferTypeGrallocSource(pInputData->dataBuffer) == OMX_TRUE) 232 pMpeg4Param->FrameMap = NV12_LINEAR; 233 else 234 pMpeg4Param->FrameMap = NV12_TILE; 235 } 236 #endif 237 238 /* 239 SEC_OSAL_Log(SEC_LOG_TRACE, "pSECPort->eControlRate: 0x%x", pSECOutputPort->eControlRate); 240 switch (pSECOutputPort->eControlRate) { 241 case OMX_Video_ControlRateVariable: 242 SEC_OSAL_Log(SEC_LOG_TRACE, "Video Encode VBR"); 243 pH264Arg->EnableFRMRateControl = 0; // 0: Disable, 1: Frame level RC 244 pH264Arg->EnableMBRateControl = 0; // 0: Disable, 1:MB level RC 245 pH264Arg->CBRPeriodRf = 100; 246 break; 247 case OMX_Video_ControlRateConstant: 248 SEC_OSAL_Log(SEC_LOG_TRACE, "Video Encode CBR"); 249 pH264Arg->EnableFRMRateControl = 1; // 0: Disable, 1: Frame level RC 250 pH264Arg->EnableMBRateControl = 1; // 0: Disable, 1:MB level RC 251 pH264Arg->CBRPeriodRf = 10; 252 break; 253 case OMX_Video_ControlRateDisable: 254 default: //Android default 255 SEC_OSAL_Log(SEC_LOG_TRACE, "Video Encode VBR"); 256 pH264Arg->EnableFRMRateControl = 0; 257 pH264Arg->EnableMBRateControl = 0; 258 pH264Arg->CBRPeriodRf = 100; 259 break; 260 } 261 */ 262 Mpeg4PrintParams(*pMpeg4Param); 263 } 264 265 void Set_H263Enc_Param(SSBSIP_MFC_ENC_H263_PARAM *pH263Param, SEC_OMX_BASECOMPONENT *pSECComponent) 266 { 267 SEC_OMX_BASEPORT *pSECInputPort = NULL; 268 SEC_OMX_BASEPORT *pSECOutputPort = NULL; 269 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 270 271 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 272 pSECInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 273 pSECOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 274 275 pH263Param->codecType = H263_ENC; 276 pH263Param->SourceWidth = pSECOutputPort->portDefinition.format.video.nFrameWidth; 277 pH263Param->SourceHeight = pSECOutputPort->portDefinition.format.video.nFrameHeight; 278 pH263Param->IDRPeriod = pMpeg4Enc->h263Component[OUTPUT_PORT_INDEX].nPFrames + 1; 279 pH263Param->SliceMode = 0; 280 pH263Param->RandomIntraMBRefresh = 0; 281 pH263Param->EnableFRMRateControl = 1; /* 0: disable, 1: enable */ 282 pH263Param->Bitrate = pSECOutputPort->portDefinition.format.video.nBitrate; 283 pH263Param->FrameQp = 20; 284 pH263Param->FrameQp_P = 20; 285 pH263Param->QSCodeMax = 30; 286 pH263Param->QSCodeMin = 10; 287 pH263Param->CBRPeriodRf = 10; 288 pH263Param->PadControlOn = 0; /* 0: Use boundary pixel, 1: Use the below setting value */ 289 pH263Param->LumaPadVal = 0; 290 pH263Param->CbPadVal = 0; 291 pH263Param->CrPadVal = 0; 292 293 pH263Param->FrameRate = (pSECInputPort->portDefinition.format.video.xFramerate) >> 16; 294 295 switch ((SEC_OMX_COLOR_FORMATTYPE)pSECInputPort->portDefinition.format.video.eColorFormat) { 296 case OMX_COLOR_FormatYUV420SemiPlanar: 297 pH263Param->FrameMap = NV12_LINEAR; 298 break; 299 case OMX_SEC_COLOR_FormatNV12TPhysicalAddress: 300 default: 301 pH263Param->FrameMap = NV12_TILE; 302 break; 303 } 304 305 #ifdef USE_ANDROID_EXTENSION 306 if (pSECInputPort->bStoreMetaDataInBuffer != OMX_FALSE) { 307 SEC_OMX_DATA *pInputData = &pSECComponent->processData[INPUT_PORT_INDEX]; 308 if(isMetadataBufferTypeGrallocSource(pInputData->dataBuffer) == OMX_TRUE) 309 pH263Param->FrameMap = NV12_LINEAR; 310 else 311 pH263Param->FrameMap = NV12_TILE; 312 } 313 #endif 314 315 /* 316 SEC_OSAL_Log(SEC_LOG_TRACE, "pSECPort->eControlRate: 0x%x", pSECOutputPort->eControlRate); 317 switch (pSECOutputPort->eControlRate) { 318 case OMX_Video_ControlRateVariable: 319 SEC_OSAL_Log(SEC_LOG_TRACE, "Video Encode VBR"); 320 pH264Arg->EnableFRMRateControl = 0; // 0: Disable, 1: Frame level RC 321 pH264Arg->EnableMBRateControl = 0; // 0: Disable, 1:MB level RC 322 pH264Arg->CBRPeriodRf = 100; 323 break; 324 case OMX_Video_ControlRateConstant: 325 SEC_OSAL_Log(SEC_LOG_TRACE, "Video Encode CBR"); 326 pH264Arg->EnableFRMRateControl = 1; // 0: Disable, 1: Frame level RC 327 pH264Arg->EnableMBRateControl = 1; // 0: Disable, 1:MB level RC 328 pH264Arg->CBRPeriodRf = 10; 329 break; 330 case OMX_Video_ControlRateDisable: 331 default: //Android default 332 SEC_OSAL_Log(SEC_LOG_TRACE, "Video Encode VBR"); 333 pH264Arg->EnableFRMRateControl = 0; 334 pH264Arg->EnableMBRateControl = 0; 335 pH264Arg->CBRPeriodRf = 100; 336 break; 337 } 338 */ 339 H263PrintParams(*pH263Param); 340 } 341 342 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_GetParameter( 343 OMX_IN OMX_HANDLETYPE hComponent, 344 OMX_IN OMX_INDEXTYPE nParamIndex, 345 OMX_INOUT OMX_PTR pComponentParameterStructure) 346 { 347 OMX_ERRORTYPE ret = OMX_ErrorNone; 348 OMX_COMPONENTTYPE *pOMXComponent = NULL; 349 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 350 351 FunctionIn(); 352 353 if (hComponent == NULL || pComponentParameterStructure == NULL) { 354 ret = OMX_ErrorBadParameter; 355 goto EXIT; 356 } 357 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 358 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 359 if (ret != OMX_ErrorNone) { 360 goto EXIT; 361 } 362 if (pOMXComponent->pComponentPrivate == NULL) { 363 ret = OMX_ErrorBadParameter; 364 goto EXIT; 365 } 366 367 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 368 if (pSECComponent->currentState == OMX_StateInvalid ) { 369 ret = OMX_StateInvalid; 370 goto EXIT; 371 } 372 373 switch (nParamIndex) { 374 case OMX_IndexParamVideoMpeg4: 375 { 376 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pComponentParameterStructure; 377 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = NULL; 378 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 379 380 ret = SEC_OMX_Check_SizeVersion(pDstMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 381 if (ret != OMX_ErrorNone) { 382 goto EXIT; 383 } 384 385 if (pDstMpeg4Param->nPortIndex >= ALL_PORT_NUM) { 386 ret = OMX_ErrorBadPortIndex; 387 goto EXIT; 388 } 389 390 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 391 pSrcMpeg4Param = &pMpeg4Enc->mpeg4Component[pDstMpeg4Param->nPortIndex]; 392 393 SEC_OSAL_Memcpy(pDstMpeg4Param, pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 394 } 395 break; 396 case OMX_IndexParamVideoH263: 397 { 398 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = (OMX_VIDEO_PARAM_H263TYPE *)pComponentParameterStructure; 399 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = NULL; 400 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 401 402 ret = SEC_OMX_Check_SizeVersion(pDstH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 403 if (ret != OMX_ErrorNone) { 404 goto EXIT; 405 } 406 407 if (pDstH263Param->nPortIndex >= ALL_PORT_NUM) { 408 ret = OMX_ErrorBadPortIndex; 409 goto EXIT; 410 } 411 412 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 413 pSrcH263Param = &pMpeg4Enc->h263Component[pDstH263Param->nPortIndex]; 414 415 SEC_OSAL_Memcpy(pDstH263Param, pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 416 } 417 break; 418 case OMX_IndexParamStandardComponentRole: 419 { 420 OMX_S32 codecType; 421 OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)pComponentParameterStructure; 422 423 ret = SEC_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 424 if (ret != OMX_ErrorNone) { 425 goto EXIT; 426 } 427 428 codecType = ((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 429 if (codecType == CODEC_TYPE_MPEG4) 430 SEC_OSAL_Strcpy((char *)pComponentRole->cRole, SEC_OMX_COMPONENT_MPEG4_ENC_ROLE); 431 else 432 SEC_OSAL_Strcpy((char *)pComponentRole->cRole, SEC_OMX_COMPONENT_H263_ENC_ROLE); 433 } 434 break; 435 case OMX_IndexParamVideoProfileLevelQuerySupported: 436 { 437 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 438 SEC_OMX_VIDEO_PROFILELEVEL *pProfileLevel = NULL; 439 OMX_U32 maxProfileLevelNum = 0; 440 OMX_S32 codecType; 441 442 ret = SEC_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 443 if (ret != OMX_ErrorNone) { 444 goto EXIT; 445 } 446 447 if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { 448 ret = OMX_ErrorBadPortIndex; 449 goto EXIT; 450 } 451 452 codecType = ((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 453 if (codecType == CODEC_TYPE_MPEG4) { 454 pProfileLevel = supportedMPEG4ProfileLevels; 455 maxProfileLevelNum = sizeof(supportedMPEG4ProfileLevels) / sizeof(SEC_OMX_VIDEO_PROFILELEVEL); 456 } else { 457 pProfileLevel = supportedH263ProfileLevels; 458 maxProfileLevelNum = sizeof(supportedH263ProfileLevels) / sizeof(SEC_OMX_VIDEO_PROFILELEVEL); 459 } 460 461 if (pDstProfileLevel->nProfileIndex >= maxProfileLevelNum) { 462 ret = OMX_ErrorNoMore; 463 goto EXIT; 464 } 465 466 pProfileLevel += pDstProfileLevel->nProfileIndex; 467 pDstProfileLevel->eProfile = pProfileLevel->profile; 468 pDstProfileLevel->eLevel = pProfileLevel->level; 469 } 470 break; 471 case OMX_IndexParamVideoProfileLevelCurrent: 472 { 473 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 474 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = NULL; 475 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = NULL; 476 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 477 OMX_S32 codecType; 478 479 ret = SEC_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 480 if (ret != OMX_ErrorNone) { 481 goto EXIT; 482 } 483 484 if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { 485 ret = OMX_ErrorBadPortIndex; 486 goto EXIT; 487 } 488 489 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 490 codecType = pMpeg4Enc->hMFCMpeg4Handle.codecType; 491 if (codecType == CODEC_TYPE_MPEG4) { 492 pSrcMpeg4Param = &pMpeg4Enc->mpeg4Component[pDstProfileLevel->nPortIndex]; 493 pDstProfileLevel->eProfile = pSrcMpeg4Param->eProfile; 494 pDstProfileLevel->eLevel = pSrcMpeg4Param->eLevel; 495 } else { 496 pSrcH263Param = &pMpeg4Enc->h263Component[pDstProfileLevel->nPortIndex]; 497 pDstProfileLevel->eProfile = pSrcH263Param->eProfile; 498 pDstProfileLevel->eLevel = pSrcH263Param->eLevel; 499 } 500 } 501 break; 502 case OMX_IndexParamVideoErrorCorrection: 503 { 504 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; 505 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = NULL; 506 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 507 508 ret = SEC_OMX_Check_SizeVersion(pDstErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); 509 if (ret != OMX_ErrorNone) { 510 goto EXIT; 511 } 512 513 if (pDstErrorCorrectionType->nPortIndex != OUTPUT_PORT_INDEX) { 514 ret = OMX_ErrorBadPortIndex; 515 goto EXIT; 516 } 517 518 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 519 pSrcErrorCorrectionType = &pMpeg4Enc->errorCorrectionType[OUTPUT_PORT_INDEX]; 520 521 pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; 522 pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; 523 pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; 524 pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; 525 pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; 526 } 527 break; 528 default: 529 ret = SEC_OMX_VideoEncodeGetParameter(hComponent, nParamIndex, pComponentParameterStructure); 530 break; 531 } 532 EXIT: 533 FunctionOut(); 534 535 return ret; 536 } 537 538 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_SetParameter( 539 OMX_IN OMX_HANDLETYPE hComponent, 540 OMX_IN OMX_INDEXTYPE nIndex, 541 OMX_IN OMX_PTR pComponentParameterStructure) 542 { 543 OMX_ERRORTYPE ret = OMX_ErrorNone; 544 OMX_COMPONENTTYPE *pOMXComponent = NULL; 545 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 546 547 FunctionIn(); 548 549 if (hComponent == NULL || pComponentParameterStructure == NULL) { 550 ret = OMX_ErrorBadParameter; 551 goto EXIT; 552 } 553 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 554 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 555 if (ret != OMX_ErrorNone) { 556 goto EXIT; 557 } 558 if (pOMXComponent->pComponentPrivate == NULL) { 559 ret = OMX_ErrorBadParameter; 560 goto EXIT; 561 } 562 563 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 564 if (pSECComponent->currentState == OMX_StateInvalid ) { 565 ret = OMX_StateInvalid; 566 goto EXIT; 567 } 568 569 switch (nIndex) { 570 case OMX_IndexParamVideoMpeg4: 571 { 572 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = NULL; 573 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pComponentParameterStructure; 574 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 575 576 ret = SEC_OMX_Check_SizeVersion(pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 577 if (ret != OMX_ErrorNone) { 578 goto EXIT; 579 } 580 581 if (pSrcMpeg4Param->nPortIndex >= ALL_PORT_NUM) { 582 ret = OMX_ErrorBadPortIndex; 583 goto EXIT; 584 } 585 586 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 587 pDstMpeg4Param = &pMpeg4Enc->mpeg4Component[pSrcMpeg4Param->nPortIndex]; 588 589 SEC_OSAL_Memcpy(pDstMpeg4Param, pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 590 } 591 break; 592 case OMX_IndexParamVideoH263: 593 { 594 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = NULL; 595 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = (OMX_VIDEO_PARAM_H263TYPE *)pComponentParameterStructure; 596 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 597 598 ret = SEC_OMX_Check_SizeVersion(pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 599 if (ret != OMX_ErrorNone) { 600 goto EXIT; 601 } 602 603 if (pSrcH263Param->nPortIndex >= ALL_PORT_NUM) { 604 ret = OMX_ErrorBadPortIndex; 605 goto EXIT; 606 } 607 608 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 609 pDstH263Param = &pMpeg4Enc->h263Component[pSrcH263Param->nPortIndex]; 610 611 SEC_OSAL_Memcpy(pDstH263Param, pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 612 } 613 break; 614 case OMX_IndexParamStandardComponentRole: 615 { 616 OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)pComponentParameterStructure; 617 618 ret = SEC_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 619 if (ret != OMX_ErrorNone) { 620 goto EXIT; 621 } 622 623 if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) { 624 ret = OMX_ErrorIncorrectStateOperation; 625 goto EXIT; 626 } 627 628 if (!SEC_OSAL_Strcmp((char*)pComponentRole->cRole, SEC_OMX_COMPONENT_MPEG4_ENC_ROLE)) { 629 pSECComponent->pSECPort[OUTPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 630 //((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType = CODEC_TYPE_MPEG4; 631 } else if (!SEC_OSAL_Strcmp((char*)pComponentRole->cRole, SEC_OMX_COMPONENT_H263_ENC_ROLE)) { 632 pSECComponent->pSECPort[OUTPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 633 //((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType = CODEC_TYPE_H263; 634 } else { 635 ret = OMX_ErrorBadParameter; 636 goto EXIT; 637 } 638 } 639 break; 640 case OMX_IndexParamVideoProfileLevelCurrent: 641 { 642 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 643 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = NULL; 644 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = NULL; 645 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 646 OMX_S32 codecType; 647 648 ret = SEC_OMX_Check_SizeVersion(pSrcProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 649 if (ret != OMX_ErrorNone) { 650 goto EXIT; 651 } 652 653 if (pSrcProfileLevel->nPortIndex >= ALL_PORT_NUM) { 654 ret = OMX_ErrorBadPortIndex; 655 goto EXIT; 656 } 657 658 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 659 codecType = pMpeg4Enc->hMFCMpeg4Handle.codecType; 660 if (codecType == CODEC_TYPE_MPEG4) { 661 /* 662 * To do: Check validity of profile & level parameters 663 */ 664 665 pDstMpeg4Param = &pMpeg4Enc->mpeg4Component[pSrcProfileLevel->nPortIndex]; 666 pDstMpeg4Param->eProfile = pSrcProfileLevel->eProfile; 667 pDstMpeg4Param->eLevel = pSrcProfileLevel->eLevel; 668 } else { 669 /* 670 * To do: Check validity of profile & level parameters 671 */ 672 673 pDstH263Param = &pMpeg4Enc->h263Component[pSrcProfileLevel->nPortIndex]; 674 pDstH263Param->eProfile = pSrcProfileLevel->eProfile; 675 pDstH263Param->eLevel = pSrcProfileLevel->eLevel; 676 } 677 } 678 break; 679 case OMX_IndexParamVideoErrorCorrection: 680 { 681 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; 682 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = NULL; 683 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 684 685 ret = SEC_OMX_Check_SizeVersion(pSrcErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); 686 if (ret != OMX_ErrorNone) { 687 goto EXIT; 688 } 689 690 if (pSrcErrorCorrectionType->nPortIndex != OUTPUT_PORT_INDEX) { 691 ret = OMX_ErrorBadPortIndex; 692 goto EXIT; 693 } 694 695 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 696 pDstErrorCorrectionType = &pMpeg4Enc->errorCorrectionType[OUTPUT_PORT_INDEX]; 697 698 pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; 699 pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; 700 pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; 701 pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; 702 pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; 703 } 704 break; 705 default: 706 ret = SEC_OMX_VideoEncodeSetParameter(hComponent, nIndex, pComponentParameterStructure); 707 break; 708 } 709 EXIT: 710 FunctionOut(); 711 712 return ret; 713 } 714 715 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_GetConfig( 716 OMX_HANDLETYPE hComponent, 717 OMX_INDEXTYPE nIndex, 718 OMX_PTR pComponentConfigStructure) 719 { 720 OMX_ERRORTYPE ret = OMX_ErrorNone; 721 OMX_COMPONENTTYPE *pOMXComponent = NULL; 722 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 723 724 FunctionIn(); 725 726 if (hComponent == NULL) { 727 ret = OMX_ErrorBadParameter; 728 goto EXIT; 729 } 730 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 731 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 732 if (ret != OMX_ErrorNone) { 733 goto EXIT; 734 } 735 736 if (pOMXComponent->pComponentPrivate == NULL) { 737 ret = OMX_ErrorBadParameter; 738 goto EXIT; 739 } 740 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 741 742 if (pComponentConfigStructure == NULL) { 743 ret = OMX_ErrorBadParameter; 744 goto EXIT; 745 } 746 if (pSECComponent->currentState == OMX_StateInvalid) { 747 ret = OMX_ErrorInvalidState; 748 goto EXIT; 749 } 750 751 switch (nIndex) { 752 default: 753 ret = SEC_OMX_GetConfig(hComponent, nIndex, pComponentConfigStructure); 754 break; 755 } 756 757 EXIT: 758 FunctionOut(); 759 760 return ret; 761 } 762 763 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_SetConfig( 764 OMX_IN OMX_HANDLETYPE hComponent, 765 OMX_IN OMX_INDEXTYPE nIndex, 766 OMX_IN OMX_PTR pComponentConfigStructure) 767 { 768 OMX_ERRORTYPE ret = OMX_ErrorNone; 769 OMX_COMPONENTTYPE *pOMXComponent = NULL; 770 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 771 772 FunctionIn(); 773 774 if (hComponent == NULL || pComponentConfigStructure == NULL) { 775 ret = OMX_ErrorBadParameter; 776 goto EXIT; 777 } 778 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 779 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 780 if (ret != OMX_ErrorNone) { 781 goto EXIT; 782 } 783 if (pOMXComponent->pComponentPrivate == NULL) { 784 ret = OMX_ErrorBadParameter; 785 goto EXIT; 786 } 787 788 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 789 if (pSECComponent->currentState == OMX_StateInvalid) { 790 ret = OMX_ErrorInvalidState; 791 goto EXIT; 792 } 793 794 switch (nIndex) { 795 default: 796 ret = SEC_OMX_SetConfig(hComponent, nIndex, pComponentConfigStructure); 797 break; 798 } 799 800 EXIT: 801 FunctionOut(); 802 803 return ret; 804 } 805 806 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_GetExtensionIndex( 807 OMX_IN OMX_HANDLETYPE hComponent, 808 OMX_IN OMX_STRING cParameterName, 809 OMX_OUT OMX_INDEXTYPE *pIndexType) 810 { 811 OMX_ERRORTYPE ret = OMX_ErrorNone; 812 OMX_COMPONENTTYPE *pOMXComponent = NULL; 813 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 814 815 FunctionIn(); 816 817 if (hComponent == NULL) { 818 ret = OMX_ErrorBadParameter; 819 goto EXIT; 820 } 821 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 822 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 823 if (ret != OMX_ErrorNone) { 824 goto EXIT; 825 } 826 827 if (pOMXComponent->pComponentPrivate == NULL) { 828 ret = OMX_ErrorBadParameter; 829 goto EXIT; 830 } 831 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 832 833 if ((cParameterName == NULL) || (pIndexType == NULL)) { 834 ret = OMX_ErrorBadParameter; 835 goto EXIT; 836 } 837 if (pSECComponent->currentState == OMX_StateInvalid) { 838 ret = OMX_ErrorInvalidState; 839 goto EXIT; 840 } 841 842 #ifdef USE_ANDROID_EXTENSION 843 if (SEC_OSAL_Strcmp(cParameterName, SEC_INDEX_PARAM_STORE_METADATA_BUFFER) == 0) { 844 *pIndexType = OMX_IndexParamStoreMetaDataBuffer; 845 ret = OMX_ErrorNone; 846 } else { 847 ret = SEC_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType); 848 } 849 #else 850 ret = SEC_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType); 851 #endif 852 853 EXIT: 854 FunctionOut(); 855 856 return ret; 857 } 858 859 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_ComponentRoleEnum( 860 OMX_IN OMX_HANDLETYPE hComponent, 861 OMX_OUT OMX_U8 *cRole, 862 OMX_IN OMX_U32 nIndex) 863 { 864 OMX_ERRORTYPE ret = OMX_ErrorNone; 865 OMX_COMPONENTTYPE *pOMXComponent = NULL; 866 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 867 OMX_S32 codecType; 868 869 FunctionIn(); 870 871 if ((hComponent == NULL) || (cRole == NULL)) { 872 ret = OMX_ErrorBadParameter; 873 goto EXIT; 874 } 875 if (nIndex != (MAX_COMPONENT_ROLE_NUM - 1)) { 876 ret = OMX_ErrorNoMore; 877 goto EXIT; 878 } 879 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 880 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 881 if (ret != OMX_ErrorNone) { 882 goto EXIT; 883 } 884 if (pOMXComponent->pComponentPrivate == NULL) { 885 ret = OMX_ErrorBadParameter; 886 goto EXIT; 887 } 888 889 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 890 if (pSECComponent->currentState == OMX_StateInvalid ) { 891 ret = OMX_StateInvalid; 892 goto EXIT; 893 } 894 895 codecType = ((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 896 if (codecType == CODEC_TYPE_MPEG4) 897 SEC_OSAL_Strcpy((char *)cRole, SEC_OMX_COMPONENT_MPEG4_ENC_ROLE); 898 else 899 SEC_OSAL_Strcpy((char *)cRole, SEC_OMX_COMPONENT_H263_ENC_ROLE); 900 901 EXIT: 902 FunctionOut(); 903 904 return ret; 905 } 906 907 OMX_ERRORTYPE SEC_MFC_EncodeThread(OMX_HANDLETYPE hComponent) 908 { 909 OMX_ERRORTYPE ret = OMX_ErrorNone; 910 OMX_COMPONENTTYPE *pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 911 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 912 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 913 914 FunctionIn(); 915 916 if (hComponent == NULL) { 917 ret = OMX_ErrorBadParameter; 918 goto EXIT; 919 } 920 921 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 922 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 923 924 while (pMpeg4Enc->NBEncThread.bExitEncodeThread == OMX_FALSE) { 925 SEC_OSAL_SemaphoreWait(pMpeg4Enc->NBEncThread.hEncFrameStart); 926 927 if (pMpeg4Enc->NBEncThread.bExitEncodeThread == OMX_FALSE) { 928 pMpeg4Enc->hMFCMpeg4Handle.returnCodec = SsbSipMfcEncExe(pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle); 929 SEC_OSAL_SemaphorePost(pMpeg4Enc->NBEncThread.hEncFrameEnd); 930 } 931 } 932 933 EXIT: 934 FunctionOut(); 935 SEC_OSAL_ThreadExit(NULL); 936 937 return ret; 938 } 939 940 /* MFC Init */ 941 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) 942 { 943 OMX_ERRORTYPE ret = OMX_ErrorNone; 944 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 945 SEC_OMX_BASEPORT *pSECInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 946 SEC_OMX_BASEPORT *pSECOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 947 SEC_OMX_BASEPORT *pSECPort = NULL; 948 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 949 OMX_HANDLETYPE hMFCHandle = NULL; 950 OMX_S32 returnCodec = 0; 951 952 FunctionIn(); 953 954 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 955 pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC = OMX_FALSE; 956 pSECComponent->bUseFlagEOF = OMX_FALSE; 957 pSECComponent->bSaveFlagEOS = OMX_FALSE; 958 959 /* MFC(Multi Format Codec) encoder and CMM(Codec Memory Management) driver open */ 960 SSBIP_MFC_BUFFER_TYPE buf_type = CACHE; 961 hMFCHandle = (OMX_PTR)SsbSipMfcEncOpen(&buf_type); 962 if (hMFCHandle == NULL) { 963 ret = OMX_ErrorInsufficientResources; 964 goto EXIT; 965 } 966 pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle = hMFCHandle; 967 968 /* set MFC ENC VIDEO PARAM and initialize MFC encoder instance */ 969 if (pMpeg4Enc->hMFCMpeg4Handle.codecType == CODEC_TYPE_MPEG4) { 970 SsbSipMfcEncSetSize(hMFCHandle, MPEG4_ENC, 971 pSECOutputPort->portDefinition.format.video.nFrameWidth, 972 pSECOutputPort->portDefinition.format.video.nFrameHeight); 973 } else { 974 SsbSipMfcEncSetSize(hMFCHandle, H263_ENC, 975 pSECOutputPort->portDefinition.format.video.nFrameWidth, 976 pSECOutputPort->portDefinition.format.video.nFrameHeight); 977 } 978 979 /* allocate encoder's input buffer */ 980 returnCodec = SsbSipMfcEncGetInBuf(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.inputInfo)); 981 if (returnCodec != MFC_RET_OK) { 982 ret = OMX_ErrorInsufficientResources; 983 goto EXIT; 984 } 985 pMpeg4Enc->MFCEncInputBuffer[0].YPhyAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YPhyAddr; 986 pMpeg4Enc->MFCEncInputBuffer[0].CPhyAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CPhyAddr; 987 pMpeg4Enc->MFCEncInputBuffer[0].YVirAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YVirAddr; 988 pMpeg4Enc->MFCEncInputBuffer[0].CVirAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CVirAddr; 989 pMpeg4Enc->MFCEncInputBuffer[0].YBufferSize = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YSize; 990 pMpeg4Enc->MFCEncInputBuffer[0].CBufferSize = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CSize; 991 pMpeg4Enc->MFCEncInputBuffer[0].YDataSize = 0; 992 pMpeg4Enc->MFCEncInputBuffer[0].CDataSize = 0; 993 SEC_OSAL_Log(SEC_LOG_TRACE, "pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YVirAddr : 0x%x", pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YVirAddr); 994 SEC_OSAL_Log(SEC_LOG_TRACE, "pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CVirAddr : 0x%x", pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CVirAddr); 995 996 /* allocate encoder's input buffer */ 997 returnCodec = SsbSipMfcEncGetInBuf(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.inputInfo)); 998 if (returnCodec != MFC_RET_OK) { 999 ret = OMX_ErrorInsufficientResources; 1000 goto EXIT; 1001 } 1002 pMpeg4Enc->MFCEncInputBuffer[1].YPhyAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YPhyAddr; 1003 pMpeg4Enc->MFCEncInputBuffer[1].CPhyAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CPhyAddr; 1004 pMpeg4Enc->MFCEncInputBuffer[1].YVirAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YVirAddr; 1005 pMpeg4Enc->MFCEncInputBuffer[1].CVirAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CVirAddr; 1006 pMpeg4Enc->MFCEncInputBuffer[1].YBufferSize = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YSize; 1007 pMpeg4Enc->MFCEncInputBuffer[1].CBufferSize = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CSize; 1008 pMpeg4Enc->MFCEncInputBuffer[1].YDataSize = 0; 1009 pMpeg4Enc->MFCEncInputBuffer[1].CDataSize = 0; 1010 SEC_OSAL_Log(SEC_LOG_TRACE, "pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YVirAddr : 0x%x", pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YVirAddr); 1011 SEC_OSAL_Log(SEC_LOG_TRACE, "pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CVirAddr : 0x%x", pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CVirAddr); 1012 1013 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YPhyAddr = pMpeg4Enc->MFCEncInputBuffer[0].YPhyAddr; 1014 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CPhyAddr = pMpeg4Enc->MFCEncInputBuffer[0].CPhyAddr; 1015 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YVirAddr = pMpeg4Enc->MFCEncInputBuffer[0].YVirAddr; 1016 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CVirAddr = pMpeg4Enc->MFCEncInputBuffer[0].CVirAddr; 1017 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YSize = pMpeg4Enc->MFCEncInputBuffer[0].YBufferSize; 1018 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CSize = pMpeg4Enc->MFCEncInputBuffer[0].CBufferSize; 1019 1020 pMpeg4Enc->indexInputBuffer = 0; 1021 pMpeg4Enc->bFirstFrame = OMX_TRUE; 1022 1023 pMpeg4Enc->NBEncThread.bExitEncodeThread = OMX_FALSE; 1024 pMpeg4Enc->NBEncThread.bEncoderRun = OMX_FALSE; 1025 SEC_OSAL_SemaphoreCreate(&(pMpeg4Enc->NBEncThread.hEncFrameStart)); 1026 SEC_OSAL_SemaphoreCreate(&(pMpeg4Enc->NBEncThread.hEncFrameEnd)); 1027 if (OMX_ErrorNone == SEC_OSAL_ThreadCreate(&pMpeg4Enc->NBEncThread.hNBEncodeThread, 1028 SEC_MFC_EncodeThread, 1029 pOMXComponent)) { 1030 pMpeg4Enc->hMFCMpeg4Handle.returnCodec = MFC_RET_OK; 1031 } 1032 1033 SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); 1034 SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); 1035 pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp = 0; 1036 1037 EXIT: 1038 FunctionOut(); 1039 1040 return ret; 1041 } 1042 1043 /* MFC Terminate */ 1044 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) 1045 { 1046 OMX_ERRORTYPE ret = OMX_ErrorNone; 1047 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1048 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 1049 OMX_HANDLETYPE hMFCHandle = NULL; 1050 1051 FunctionIn(); 1052 1053 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 1054 1055 if (pMpeg4Enc->NBEncThread.hNBEncodeThread != NULL) { 1056 pMpeg4Enc->NBEncThread.bExitEncodeThread = OMX_TRUE; 1057 SEC_OSAL_SemaphorePost(pMpeg4Enc->NBEncThread.hEncFrameStart); 1058 SEC_OSAL_ThreadTerminate(pMpeg4Enc->NBEncThread.hNBEncodeThread); 1059 pMpeg4Enc->NBEncThread.hNBEncodeThread = NULL; 1060 } 1061 1062 if(pMpeg4Enc->NBEncThread.hEncFrameEnd != NULL) { 1063 SEC_OSAL_SemaphoreTerminate(pMpeg4Enc->NBEncThread.hEncFrameEnd); 1064 pMpeg4Enc->NBEncThread.hEncFrameEnd = NULL; 1065 } 1066 1067 if(pMpeg4Enc->NBEncThread.hEncFrameStart != NULL) { 1068 SEC_OSAL_SemaphoreTerminate(pMpeg4Enc->NBEncThread.hEncFrameStart); 1069 pMpeg4Enc->NBEncThread.hEncFrameStart = NULL; 1070 } 1071 1072 hMFCHandle = pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle; 1073 if (hMFCHandle != NULL) { 1074 SsbSipMfcEncClose(hMFCHandle); 1075 pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle = NULL; 1076 } 1077 1078 EXIT: 1079 FunctionOut(); 1080 1081 return ret; 1082 } 1083 1084 OMX_ERRORTYPE SEC_MFC_Mpeg4_Encode(OMX_COMPONENTTYPE *pOMXComponent, SEC_OMX_DATA *pInputData, SEC_OMX_DATA *pOutputData) 1085 { 1086 OMX_ERRORTYPE ret = OMX_ErrorNone; 1087 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1088 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 1089 OMX_HANDLETYPE hMFCHandle = pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle; 1090 SSBSIP_MFC_ENC_INPUT_INFO *pInputInfo = &(pMpeg4Enc->hMFCMpeg4Handle.inputInfo); 1091 SSBSIP_MFC_ENC_OUTPUT_INFO outputInfo; 1092 SEC_OMX_BASEPORT *pSECPort = NULL; 1093 MFC_ENC_ADDR_INFO addrInfo; 1094 OMX_U32 oneFrameSize = pInputData->dataLen; 1095 1096 FunctionIn(); 1097 1098 if (pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC == OMX_FALSE) { 1099 /* set MFC ENC VIDEO PARAM and initialize MFC encoder instance */ 1100 if (pMpeg4Enc->hMFCMpeg4Handle.codecType == CODEC_TYPE_MPEG4) { 1101 Set_Mpeg4Enc_Param(&(pMpeg4Enc->hMFCMpeg4Handle.mpeg4MFCParam), pSECComponent); 1102 pMpeg4Enc->hMFCMpeg4Handle.returnCodec = SsbSipMfcEncInit(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.mpeg4MFCParam)); 1103 } else { 1104 Set_H263Enc_Param(&(pMpeg4Enc->hMFCMpeg4Handle.h263MFCParam), pSECComponent); 1105 pMpeg4Enc->hMFCMpeg4Handle.returnCodec = SsbSipMfcEncInit(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.h263MFCParam)); 1106 } 1107 if (pMpeg4Enc->hMFCMpeg4Handle.returnCodec != MFC_RET_OK) { 1108 ret = OMX_ErrorInsufficientResources; 1109 goto EXIT; 1110 } 1111 1112 pMpeg4Enc->hMFCMpeg4Handle.returnCodec = SsbSipMfcEncGetOutBuf(hMFCHandle, &outputInfo); 1113 if (pMpeg4Enc->hMFCMpeg4Handle.returnCodec != MFC_RET_OK) 1114 { 1115 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncGetOutBuf failed, ret:%d", __FUNCTION__, pMpeg4Enc->hMFCMpeg4Handle.returnCodec); 1116 ret = OMX_ErrorUndefined; 1117 goto EXIT; 1118 } 1119 1120 pOutputData->dataBuffer = outputInfo.StrmVirAddr; 1121 pOutputData->allocSize = outputInfo.headerSize; 1122 pOutputData->dataLen = outputInfo.headerSize; 1123 pOutputData->timeStamp = 0; 1124 pOutputData->nFlags |= OMX_BUFFERFLAG_CODECCONFIG; 1125 pOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; 1126 1127 pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC = OMX_TRUE; 1128 1129 ret = OMX_ErrorInputDataEncodeYet; 1130 goto EXIT; 1131 } 1132 1133 if ((pInputData->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) && 1134 (pSECComponent->bUseFlagEOF == OMX_FALSE)) { 1135 pSECComponent->bUseFlagEOF = OMX_TRUE; 1136 } 1137 1138 if (oneFrameSize <= 0) { 1139 pOutputData->timeStamp = pInputData->timeStamp; 1140 pOutputData->nFlags = pInputData->nFlags; 1141 1142 ret = OMX_ErrorNone; 1143 goto EXIT; 1144 } 1145 1146 pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1147 if (((pInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) || 1148 (pSECComponent->getAllDelayBuffer == OMX_TRUE)){ 1149 /* Dummy input data for get out encoded last frame */ 1150 pInputInfo->YPhyAddr = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].YPhyAddr; 1151 pInputInfo->CPhyAddr = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].CPhyAddr; 1152 pInputInfo->YVirAddr = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].YVirAddr; 1153 pInputInfo->CVirAddr = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].CVirAddr; 1154 } else if (pSECPort->portDefinition.format.video.eColorFormat == OMX_SEC_COLOR_FormatNV12TPhysicalAddress) { 1155 SEC_OSAL_Memcpy(&addrInfo.pAddrY, pInputData->dataBuffer, sizeof(addrInfo.pAddrY)); 1156 SEC_OSAL_Memcpy(&addrInfo.pAddrC, pInputData->dataBuffer + sizeof(addrInfo.pAddrY), sizeof(addrInfo.pAddrC)); 1157 pInputInfo->YPhyAddr = addrInfo.pAddrY; 1158 pInputInfo->CPhyAddr = addrInfo.pAddrC; 1159 #ifdef USE_ANDROID_EXTENSION 1160 } else if (pSECPort->bStoreMetaDataInBuffer != OMX_FALSE) { 1161 ret = preprocessMetaDataInBuffers(pOMXComponent, pInputData->dataBuffer, pInputInfo); 1162 if (ret != OMX_ErrorNone) 1163 goto EXIT; 1164 #endif 1165 } else { 1166 /* Real input data */ 1167 pInputInfo->YPhyAddr = pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YPhyAddr; 1168 pInputInfo->CPhyAddr = pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CPhyAddr; 1169 } 1170 1171 pSECComponent->timeStamp[pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp] = pInputData->timeStamp; 1172 pSECComponent->nFlags[pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp] = pInputData->nFlags; 1173 1174 if ((pMpeg4Enc->hMFCMpeg4Handle.returnCodec == MFC_RET_OK) && 1175 (pMpeg4Enc->bFirstFrame == OMX_FALSE)) { 1176 OMX_S32 indexTimestamp = 0; 1177 1178 /* wait for mfc encode done */ 1179 if (pMpeg4Enc->NBEncThread.bEncoderRun != OMX_FALSE) { 1180 SEC_OSAL_SemaphoreWait(pMpeg4Enc->NBEncThread.hEncFrameEnd); 1181 pMpeg4Enc->NBEncThread.bEncoderRun = OMX_FALSE; 1182 } 1183 1184 pMpeg4Enc->hMFCMpeg4Handle.returnCodec = SsbSipMfcEncGetOutBuf(hMFCHandle, &outputInfo); 1185 if ((SsbSipMfcEncGetConfig(hMFCHandle, MFC_ENC_GETCONF_FRAME_TAG, &indexTimestamp) != MFC_RET_OK) || 1186 (((indexTimestamp < 0) || (indexTimestamp >= MAX_TIMESTAMP)))) { 1187 pOutputData->timeStamp = pInputData->timeStamp; 1188 pOutputData->nFlags = pInputData->nFlags; 1189 } else { 1190 pOutputData->timeStamp = pSECComponent->timeStamp[indexTimestamp]; 1191 pOutputData->nFlags = pSECComponent->nFlags[indexTimestamp]; 1192 } 1193 1194 if (pMpeg4Enc->hMFCMpeg4Handle.returnCodec == MFC_RET_OK) { 1195 /** Fill Output Buffer **/ 1196 pOutputData->dataBuffer = outputInfo.StrmVirAddr; 1197 pOutputData->allocSize = outputInfo.dataSize; 1198 pOutputData->dataLen = outputInfo.dataSize; 1199 pOutputData->usedDataLen = 0; 1200 1201 pOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; 1202 if (outputInfo.frameType == MFC_FRAME_TYPE_I_FRAME) 1203 pOutputData->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 1204 1205 ret = OMX_ErrorNone; 1206 } else { 1207 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncGetOutBuf failed, ret:%d", __FUNCTION__, pMpeg4Enc->hMFCMpeg4Handle.returnCodec); 1208 ret = OMX_ErrorUndefined; 1209 goto EXIT; 1210 } 1211 1212 if (pSECComponent->getAllDelayBuffer == OMX_TRUE) { 1213 ret = OMX_ErrorInputDataEncodeYet; 1214 } 1215 if ((pInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { 1216 pInputData->nFlags = (pOutputData->nFlags & (~OMX_BUFFERFLAG_EOS)); 1217 pSECComponent->getAllDelayBuffer = OMX_TRUE; 1218 ret = OMX_ErrorInputDataEncodeYet; 1219 } 1220 if ((pOutputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { 1221 pSECComponent->getAllDelayBuffer = OMX_FALSE; 1222 pOutputData->dataLen = 0; 1223 pOutputData->usedDataLen = 0; 1224 SEC_OSAL_Log(SEC_LOG_TRACE, "OMX_BUFFERFLAG_EOS!!!"); 1225 ret = OMX_ErrorNone; 1226 } 1227 } 1228 if (pMpeg4Enc->hMFCMpeg4Handle.returnCodec != MFC_RET_OK) { 1229 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncExe failed, ret:%d", __FUNCTION__, pMpeg4Enc->hMFCMpeg4Handle.returnCodec); 1230 ret = OMX_ErrorUndefined; 1231 } 1232 1233 pMpeg4Enc->hMFCMpeg4Handle.returnCodec = SsbSipMfcEncSetInBuf(hMFCHandle, pInputInfo); 1234 if (pMpeg4Enc->hMFCMpeg4Handle.returnCodec != MFC_RET_OK) { 1235 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncSetInBuf failed, ret:%d", __FUNCTION__, pMpeg4Enc->hMFCMpeg4Handle.returnCodec); 1236 ret = OMX_ErrorUndefined; 1237 goto EXIT; 1238 } else { 1239 pMpeg4Enc->indexInputBuffer++; 1240 pMpeg4Enc->indexInputBuffer %= MFC_INPUT_BUFFER_NUM_MAX; 1241 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YPhyAddr = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].YPhyAddr; 1242 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CPhyAddr = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].CPhyAddr; 1243 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YVirAddr = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].YVirAddr; 1244 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CVirAddr = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].CVirAddr; 1245 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YSize = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].YBufferSize; 1246 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CSize = pMpeg4Enc->MFCEncInputBuffer[pMpeg4Enc->indexInputBuffer].CBufferSize; 1247 } 1248 1249 SsbSipMfcEncSetConfig(hMFCHandle, MFC_ENC_SETCONF_FRAME_TAG, &(pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp)); 1250 1251 /* mfc encode start */ 1252 SEC_OSAL_SemaphorePost(pMpeg4Enc->NBEncThread.hEncFrameStart); 1253 pMpeg4Enc->NBEncThread.bEncoderRun = OMX_TRUE; 1254 pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp++; 1255 pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp %= MAX_TIMESTAMP; 1256 pMpeg4Enc->bFirstFrame = OMX_FALSE; 1257 1258 EXIT: 1259 FunctionOut(); 1260 1261 return ret; 1262 } 1263 1264 /* MFC Encode */ 1265 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_bufferProcess(OMX_COMPONENTTYPE *pOMXComponent, SEC_OMX_DATA *pInputData, SEC_OMX_DATA *pOutputData) 1266 { 1267 OMX_ERRORTYPE ret = OMX_ErrorNone; 1268 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1269 SEC_OMX_BASEPORT *pInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1270 SEC_OMX_BASEPORT *pOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1271 1272 FunctionIn(); 1273 1274 if ((!CHECK_PORT_ENABLED(pInputPort)) || (!CHECK_PORT_ENABLED(pOutputPort)) || 1275 (!CHECK_PORT_POPULATED(pInputPort)) || (!CHECK_PORT_POPULATED(pOutputPort))) { 1276 goto EXIT; 1277 } 1278 if (OMX_FALSE == SEC_Check_BufferProcess_State(pSECComponent)) { 1279 goto EXIT; 1280 } 1281 1282 ret = SEC_MFC_Mpeg4_Encode(pOMXComponent, pInputData, pOutputData); 1283 if (ret != OMX_ErrorNone) { 1284 if (ret == OMX_ErrorInputDataEncodeYet) { 1285 pOutputData->usedDataLen = 0; 1286 pOutputData->remainDataLen = pOutputData->dataLen; 1287 } else { 1288 pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, 1289 pSECComponent->callbackData, 1290 OMX_EventError, ret, 0, NULL); 1291 } 1292 } else { 1293 pInputData->usedDataLen += pInputData->dataLen; 1294 pInputData->remainDataLen = pInputData->dataLen - pInputData->usedDataLen; 1295 pInputData->dataLen -= pInputData->usedDataLen; 1296 pInputData->usedDataLen = 0; 1297 1298 pOutputData->usedDataLen = 0; 1299 pOutputData->remainDataLen = pOutputData->dataLen; 1300 } 1301 1302 EXIT: 1303 FunctionOut(); 1304 1305 return ret; 1306 } 1307 1308 OSCL_EXPORT_REF OMX_ERRORTYPE SEC_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName) 1309 { 1310 OMX_ERRORTYPE ret = OMX_ErrorNone; 1311 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1312 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1313 SEC_OMX_BASEPORT *pSECPort = NULL; 1314 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 1315 OMX_S32 codecType = -1; 1316 int i = 0; 1317 1318 FunctionIn(); 1319 1320 if ((hComponent == NULL) || (componentName == NULL)) { 1321 ret = OMX_ErrorBadParameter; 1322 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: parameters are null, ret: %X", __FUNCTION__, ret); 1323 goto EXIT; 1324 } 1325 if (SEC_OSAL_Strcmp(SEC_OMX_COMPONENT_MPEG4_ENC, componentName) == 0) { 1326 codecType = CODEC_TYPE_MPEG4; 1327 } else if (SEC_OSAL_Strcmp(SEC_OMX_COMPONENT_H263_ENC, componentName) == 0) { 1328 codecType = CODEC_TYPE_H263; 1329 } else { 1330 ret = OMX_ErrorBadParameter; 1331 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: componentName(%s) error, ret: %X", __FUNCTION__, componentName, ret); 1332 goto EXIT; 1333 } 1334 1335 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1336 ret = SEC_OMX_VideoEncodeComponentInit(pOMXComponent); 1337 if (ret != OMX_ErrorNone) { 1338 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SEC_OMX_VideoDecodeComponentInit error, ret: %X", __FUNCTION__, ret); 1339 goto EXIT; 1340 } 1341 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1342 pSECComponent->codecType = HW_VIDEO_CODEC; 1343 1344 pSECComponent->componentName = (OMX_STRING)SEC_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE); 1345 if (pSECComponent->componentName == NULL) { 1346 SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); 1347 ret = OMX_ErrorInsufficientResources; 1348 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: componentName alloc error, ret: %X", __FUNCTION__, ret); 1349 goto EXIT; 1350 } 1351 SEC_OSAL_Memset(pSECComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE); 1352 1353 pMpeg4Enc = SEC_OSAL_Malloc(sizeof(SEC_MPEG4ENC_HANDLE)); 1354 if (pMpeg4Enc == NULL) { 1355 SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); 1356 ret = OMX_ErrorInsufficientResources; 1357 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SEC_MPEG4ENC_HANDLE alloc error, ret: %X", __FUNCTION__, ret); 1358 goto EXIT; 1359 } 1360 SEC_OSAL_Memset(pMpeg4Enc, 0, sizeof(SEC_MPEG4ENC_HANDLE)); 1361 pSECComponent->hCodecHandle = (OMX_HANDLETYPE)pMpeg4Enc; 1362 pMpeg4Enc->hMFCMpeg4Handle.codecType = codecType; 1363 1364 if (codecType == CODEC_TYPE_MPEG4) 1365 SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPONENT_MPEG4_ENC); 1366 else 1367 SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPONENT_H263_ENC); 1368 1369 /* Set componentVersion */ 1370 pSECComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; 1371 pSECComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; 1372 pSECComponent->componentVersion.s.nRevision = REVISION_NUMBER; 1373 pSECComponent->componentVersion.s.nStep = STEP_NUMBER; 1374 /* Set specVersion */ 1375 pSECComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; 1376 pSECComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; 1377 pSECComponent->specVersion.s.nRevision = REVISION_NUMBER; 1378 pSECComponent->specVersion.s.nStep = STEP_NUMBER; 1379 1380 /* Android CapabilityFlags */ 1381 pSECComponent->capabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; 1382 pSECComponent->capabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_TRUE; 1383 pSECComponent->capabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_TRUE; 1384 pSECComponent->capabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; 1385 pSECComponent->capabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE; 1386 pSECComponent->capabilityFlags.iOMXComponentUsesNALStartCodes = OMX_TRUE; 1387 pSECComponent->capabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE; 1388 pSECComponent->capabilityFlags.iOMXComponentUsesFullAVCFrames = OMX_TRUE; 1389 1390 /* Input port */ 1391 pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1392 pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; 1393 pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; 1394 pSECPort->portDefinition.format.video.nBitrate = 64000; 1395 pSECPort->portDefinition.format.video.xFramerate= (15 << 16); 1396 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; 1397 pSECPort->portDefinition.format.video.pNativeRender = 0; 1398 pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; 1399 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1400 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video"); 1401 pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420SemiPlanar; 1402 pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE; 1403 pSECPort->portDefinition.bEnabled = OMX_TRUE; 1404 1405 /* Output port */ 1406 pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1407 pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; 1408 pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; 1409 pSECPort->portDefinition.format.video.nBitrate = 64000; 1410 pSECPort->portDefinition.format.video.xFramerate= (15 << 16); 1411 if (codecType == CODEC_TYPE_MPEG4) { 1412 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 1413 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1414 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/mpeg4"); 1415 } else { 1416 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 1417 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1418 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/h263"); 1419 } 1420 pSECPort->portDefinition.format.video.pNativeRender = 0; 1421 pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; 1422 pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; 1423 pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE; 1424 pSECPort->portDefinition.bEnabled = OMX_TRUE; 1425 1426 if (codecType == CODEC_TYPE_MPEG4) { 1427 for(i = 0; i < ALL_PORT_NUM; i++) { 1428 INIT_SET_SIZE_VERSION(&pMpeg4Enc->mpeg4Component[i], OMX_VIDEO_PARAM_MPEG4TYPE); 1429 pMpeg4Enc->mpeg4Component[i].nPortIndex = i; 1430 pMpeg4Enc->mpeg4Component[i].eProfile = OMX_VIDEO_MPEG4ProfileSimple; 1431 pMpeg4Enc->mpeg4Component[i].eLevel = OMX_VIDEO_MPEG4Level4; 1432 1433 pMpeg4Enc->mpeg4Component[i].nPFrames = 10; 1434 pMpeg4Enc->mpeg4Component[i].nBFrames = 0; /* No support for B frames */ 1435 pMpeg4Enc->mpeg4Component[i].nMaxPacketSize = 256; /* Default value */ 1436 pMpeg4Enc->mpeg4Component[i].nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP; 1437 pMpeg4Enc->mpeg4Component[i].bGov = OMX_FALSE; 1438 1439 } 1440 } else { 1441 for(i = 0; i < ALL_PORT_NUM; i++) { 1442 INIT_SET_SIZE_VERSION(&pMpeg4Enc->h263Component[i], OMX_VIDEO_PARAM_H263TYPE); 1443 pMpeg4Enc->h263Component[i].nPortIndex = i; 1444 pMpeg4Enc->h263Component[i].eProfile = OMX_VIDEO_H263ProfileBaseline; 1445 pMpeg4Enc->h263Component[i].eLevel = OMX_VIDEO_H263Level45; 1446 1447 pMpeg4Enc->h263Component[i].nPFrames = 20; 1448 pMpeg4Enc->h263Component[i].nBFrames = 0; /* No support for B frames */ 1449 pMpeg4Enc->h263Component[i].bPLUSPTYPEAllowed = OMX_FALSE; 1450 pMpeg4Enc->h263Component[i].nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP; 1451 pMpeg4Enc->h263Component[i].bForceRoundingTypeToZero = OMX_TRUE; 1452 pMpeg4Enc->h263Component[i].nPictureHeaderRepetition = 0; 1453 pMpeg4Enc->h263Component[i].nGOBHeaderInterval = 0; 1454 } 1455 } 1456 1457 pOMXComponent->GetParameter = &SEC_MFC_Mpeg4Enc_GetParameter; 1458 pOMXComponent->SetParameter = &SEC_MFC_Mpeg4Enc_SetParameter; 1459 pOMXComponent->GetConfig = &SEC_MFC_Mpeg4Enc_GetConfig; 1460 pOMXComponent->SetConfig = &SEC_MFC_Mpeg4Enc_SetConfig; 1461 pOMXComponent->GetExtensionIndex = &SEC_MFC_Mpeg4Enc_GetExtensionIndex; 1462 pOMXComponent->ComponentRoleEnum = &SEC_MFC_Mpeg4Enc_ComponentRoleEnum; 1463 pOMXComponent->ComponentDeInit = &SEC_OMX_ComponentDeinit; 1464 1465 pSECComponent->sec_mfc_componentInit = &SEC_MFC_Mpeg4Enc_Init; 1466 pSECComponent->sec_mfc_componentTerminate = &SEC_MFC_Mpeg4Enc_Terminate; 1467 pSECComponent->sec_mfc_bufferProcess = &SEC_MFC_Mpeg4Enc_bufferProcess; 1468 pSECComponent->sec_checkInputFrame = NULL; 1469 1470 pSECComponent->currentState = OMX_StateLoaded; 1471 1472 ret = OMX_ErrorNone; 1473 1474 EXIT: 1475 FunctionOut(); 1476 1477 return ret; 1478 } 1479 1480 OMX_ERRORTYPE SEC_OMX_ComponentDeinit(OMX_HANDLETYPE hComponent) 1481 { 1482 OMX_ERRORTYPE ret = OMX_ErrorNone; 1483 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1484 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1485 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 1486 1487 FunctionIn(); 1488 1489 if (hComponent == NULL) { 1490 ret = OMX_ErrorBadParameter; 1491 goto EXIT; 1492 } 1493 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1494 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1495 1496 SEC_OSAL_Free(pSECComponent->componentName); 1497 pSECComponent->componentName = NULL; 1498 1499 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 1500 if (pMpeg4Enc != NULL) { 1501 SEC_OSAL_Free(pMpeg4Enc); 1502 pMpeg4Enc = pSECComponent->hCodecHandle = NULL; 1503 } 1504 1505 ret = SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); 1506 if (ret != OMX_ErrorNone) { 1507 goto EXIT; 1508 } 1509 1510 ret = OMX_ErrorNone; 1511 1512 EXIT: 1513 FunctionOut(); 1514 1515 return ret; 1516 } 1517