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 40 #undef SEC_LOG_TAG 41 #define SEC_LOG_TAG "SEC_MPEG4_ENC" 42 #define SEC_LOG_OFF 43 #include "SEC_OSAL_Log.h" 44 45 46 /* MPEG4 Encoder Supported Levels & profiles */ 47 SEC_OMX_VIDEO_PROFILELEVEL supportedMPEG4ProfileLevels[] ={ 48 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0}, 49 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level0b}, 50 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level1}, 51 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level2}, 52 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level3}, 53 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level4}, 54 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level4a}, 55 {OMX_VIDEO_MPEG4ProfileSimple, OMX_VIDEO_MPEG4Level5}, 56 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level0}, 57 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level0b}, 58 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level1}, 59 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level2}, 60 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level3}, 61 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level4}, 62 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level4a}, 63 {OMX_VIDEO_MPEG4ProfileAdvancedSimple, OMX_VIDEO_MPEG4Level5}}; 64 65 /* H.263 Encoder Supported Levels & profiles */ 66 SEC_OMX_VIDEO_PROFILELEVEL supportedH263ProfileLevels[] = { 67 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10}, 68 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level20}, 69 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level30}, 70 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level40}, 71 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level45}, 72 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level50}, 73 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level60}, 74 {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level70}}; 75 76 OMX_U32 OMXMpeg4ProfileToMFCProfile(OMX_VIDEO_MPEG4PROFILETYPE profile) 77 { 78 OMX_U32 ret; 79 80 switch (profile) { 81 case OMX_VIDEO_MPEG4ProfileSimple: 82 ret = 0; 83 break; 84 case OMX_VIDEO_MPEG4ProfileAdvancedSimple: 85 ret = 1; 86 break; 87 default: 88 ret = 0; 89 }; 90 91 return ret; 92 } 93 OMX_U32 OMXMpeg4LevelToMFCLevel(OMX_VIDEO_MPEG4LEVELTYPE level) 94 { 95 OMX_U32 ret; 96 97 switch (level) { 98 case OMX_VIDEO_MPEG4Level0: 99 ret = 0; 100 break; 101 case OMX_VIDEO_MPEG4Level0b: 102 ret = 9; 103 break; 104 case OMX_VIDEO_MPEG4Level1: 105 ret = 1; 106 break; 107 case OMX_VIDEO_MPEG4Level2: 108 ret = 2; 109 break; 110 case OMX_VIDEO_MPEG4Level3: 111 ret = 3; 112 break; 113 case OMX_VIDEO_MPEG4Level4: 114 case OMX_VIDEO_MPEG4Level4a: 115 ret = 4; 116 break; 117 case OMX_VIDEO_MPEG4Level5: 118 ret = 5; 119 break; 120 default: 121 ret = 0; 122 }; 123 124 return ret; 125 } 126 127 void Mpeg4PrintParams(SSBSIP_MFC_ENC_MPEG4_PARAM mpeg4Param) 128 { 129 SEC_OSAL_Log(SEC_LOG_TRACE, "SourceWidth : %d\n", mpeg4Param.SourceWidth); 130 SEC_OSAL_Log(SEC_LOG_TRACE, "SourceHeight : %d\n", mpeg4Param.SourceHeight); 131 SEC_OSAL_Log(SEC_LOG_TRACE, "IDRPeriod : %d\n", mpeg4Param.IDRPeriod); 132 SEC_OSAL_Log(SEC_LOG_TRACE, "SliceMode : %d\n", mpeg4Param.SliceMode); 133 SEC_OSAL_Log(SEC_LOG_TRACE, "RandomIntraMBRefresh : %d\n", mpeg4Param.RandomIntraMBRefresh); 134 SEC_OSAL_Log(SEC_LOG_TRACE, "EnableFRMRateControl : %d\n", mpeg4Param.EnableFRMRateControl); 135 SEC_OSAL_Log(SEC_LOG_TRACE, "Bitrate : %d\n", mpeg4Param.Bitrate); 136 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp : %d\n", mpeg4Param.FrameQp); 137 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp_P : %d\n", mpeg4Param.FrameQp_P); 138 SEC_OSAL_Log(SEC_LOG_TRACE, "QSCodeMax : %d\n", mpeg4Param.QSCodeMax); 139 SEC_OSAL_Log(SEC_LOG_TRACE, "QSCodeMin : %d\n", mpeg4Param.QSCodeMin); 140 SEC_OSAL_Log(SEC_LOG_TRACE, "CBRPeriodRf : %d\n", mpeg4Param.CBRPeriodRf); 141 SEC_OSAL_Log(SEC_LOG_TRACE, "PadControlOn : %d\n", mpeg4Param.PadControlOn); 142 SEC_OSAL_Log(SEC_LOG_TRACE, "LumaPadVal : %d\n", mpeg4Param.LumaPadVal); 143 SEC_OSAL_Log(SEC_LOG_TRACE, "CbPadVal : %d\n", mpeg4Param.CbPadVal); 144 SEC_OSAL_Log(SEC_LOG_TRACE, "CrPadVal : %d\n", mpeg4Param.CrPadVal); 145 146 /* MPEG4 specific parameters */ 147 SEC_OSAL_Log(SEC_LOG_TRACE, "ProfileIDC : %d\n", mpeg4Param.ProfileIDC); 148 SEC_OSAL_Log(SEC_LOG_TRACE, "LevelIDC : %d\n", mpeg4Param.LevelIDC); 149 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp_B : %d\n", mpeg4Param.FrameQp_B); 150 SEC_OSAL_Log(SEC_LOG_TRACE, "TimeIncreamentRes : %d\n", mpeg4Param.TimeIncreamentRes); 151 SEC_OSAL_Log(SEC_LOG_TRACE, "VopTimeIncreament : %d\n", mpeg4Param.VopTimeIncreament); 152 SEC_OSAL_Log(SEC_LOG_TRACE, "SliceArgument : %d\n", mpeg4Param.SliceArgument); 153 SEC_OSAL_Log(SEC_LOG_TRACE, "NumberBFrames : %d\n", mpeg4Param.NumberBFrames); 154 SEC_OSAL_Log(SEC_LOG_TRACE, "DisableQpelME : %d\n", mpeg4Param.DisableQpelME); 155 } 156 157 void H263PrintParams(SSBSIP_MFC_ENC_H263_PARAM h263Param) 158 { 159 SEC_OSAL_Log(SEC_LOG_TRACE, "SourceWidth : %d\n", h263Param.SourceWidth); 160 SEC_OSAL_Log(SEC_LOG_TRACE, "SourceHeight : %d\n", h263Param.SourceHeight); 161 SEC_OSAL_Log(SEC_LOG_TRACE, "IDRPeriod : %d\n", h263Param.IDRPeriod); 162 SEC_OSAL_Log(SEC_LOG_TRACE, "SliceMode : %d\n", h263Param.SliceMode); 163 SEC_OSAL_Log(SEC_LOG_TRACE, "RandomIntraMBRefresh : %d\n", h263Param.RandomIntraMBRefresh); 164 SEC_OSAL_Log(SEC_LOG_TRACE, "EnableFRMRateControl : %d\n", h263Param.EnableFRMRateControl); 165 SEC_OSAL_Log(SEC_LOG_TRACE, "Bitrate : %d\n", h263Param.Bitrate); 166 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp : %d\n", h263Param.FrameQp); 167 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameQp_P : %d\n", h263Param.FrameQp_P); 168 SEC_OSAL_Log(SEC_LOG_TRACE, "QSCodeMax : %d\n", h263Param.QSCodeMax); 169 SEC_OSAL_Log(SEC_LOG_TRACE, "QSCodeMin : %d\n", h263Param.QSCodeMin); 170 SEC_OSAL_Log(SEC_LOG_TRACE, "CBRPeriodRf : %d\n", h263Param.CBRPeriodRf); 171 SEC_OSAL_Log(SEC_LOG_TRACE, "PadControlOn : %d\n", h263Param.PadControlOn); 172 SEC_OSAL_Log(SEC_LOG_TRACE, "LumaPadVal : %d\n", h263Param.LumaPadVal); 173 SEC_OSAL_Log(SEC_LOG_TRACE, "CbPadVal : %d\n", h263Param.CbPadVal); 174 SEC_OSAL_Log(SEC_LOG_TRACE, "CrPadVal : %d\n", h263Param.CrPadVal); 175 176 /* H.263 specific parameters */ 177 SEC_OSAL_Log(SEC_LOG_TRACE, "FrameRate : %d\n", h263Param.FrameRate); 178 } 179 180 void Set_Mpeg4Enc_Param(SSBSIP_MFC_ENC_MPEG4_PARAM *pMpeg4Param, SEC_OMX_BASECOMPONENT *pSECComponent) 181 { 182 SEC_OMX_BASEPORT *pSECInputPort = NULL; 183 SEC_OMX_BASEPORT *pSECOutputPort = NULL; 184 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 185 186 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 187 pSECInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 188 pSECOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 189 190 pMpeg4Param->codecType = MPEG4_ENC; 191 pMpeg4Param->SourceWidth = pSECOutputPort->portDefinition.format.video.nFrameWidth; 192 pMpeg4Param->SourceHeight = pSECOutputPort->portDefinition.format.video.nFrameHeight; 193 pMpeg4Param->IDRPeriod = pMpeg4Enc->mpeg4Component[OUTPUT_PORT_INDEX].nPFrames + 1; 194 pMpeg4Param->SliceMode = 0; 195 pMpeg4Param->RandomIntraMBRefresh = 0; 196 pMpeg4Param->EnableFRMRateControl = 1; /* 0: disable, 1: enable */ 197 pMpeg4Param->Bitrate = pSECOutputPort->portDefinition.format.video.nBitrate; 198 pMpeg4Param->FrameQp = 20; 199 pMpeg4Param->FrameQp_P = 20; 200 pMpeg4Param->QSCodeMax = 30; 201 pMpeg4Param->QSCodeMin = 10; 202 pMpeg4Param->CBRPeriodRf = 10; 203 pMpeg4Param->PadControlOn = 0; /* 0: Use boundary pixel, 1: Use the below setting value */ 204 pMpeg4Param->LumaPadVal = 0; 205 pMpeg4Param->CbPadVal = 0; 206 pMpeg4Param->CrPadVal = 0; 207 208 pMpeg4Param->ProfileIDC = OMXMpeg4ProfileToMFCProfile(pMpeg4Enc->mpeg4Component[OUTPUT_PORT_INDEX].eProfile); 209 pMpeg4Param->LevelIDC = OMXMpeg4LevelToMFCLevel(pMpeg4Enc->mpeg4Component[OUTPUT_PORT_INDEX].eLevel); 210 pMpeg4Param->FrameQp_B = 20; 211 pMpeg4Param->TimeIncreamentRes = (pSECInputPort->portDefinition.format.video.xFramerate) >> 16; 212 pMpeg4Param->VopTimeIncreament = 1; 213 pMpeg4Param->SliceArgument = 0; /* MB number or byte number */ 214 pMpeg4Param->NumberBFrames = 0; /* 0(not used) ~ 2 */ 215 pMpeg4Param->DisableQpelME = 1; 216 217 SEC_OSAL_Log(SEC_LOG_TRACE, "pSECPort->eControlRate: 0x%x", pSECOutputPort->eControlRate); 218 switch (pSECOutputPort->eControlRate) { 219 case OMX_Video_ControlRateDisable: 220 /* TBD */ 221 break; 222 case OMX_Video_ControlRateVariable: 223 /* TBD */ 224 break; 225 default: 226 break; 227 } 228 229 Mpeg4PrintParams(*pMpeg4Param); 230 } 231 232 void Set_H263Enc_Param(SSBSIP_MFC_ENC_H263_PARAM *pH263Param, SEC_OMX_BASECOMPONENT *pSECComponent) 233 { 234 SEC_OMX_BASEPORT *pSECInputPort = NULL; 235 SEC_OMX_BASEPORT *pSECOutputPort = NULL; 236 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 237 238 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 239 pSECInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 240 pSECOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 241 242 pH263Param->codecType = H263_ENC; 243 pH263Param->SourceWidth = pSECOutputPort->portDefinition.format.video.nFrameWidth; 244 pH263Param->SourceHeight = pSECOutputPort->portDefinition.format.video.nFrameHeight; 245 pH263Param->IDRPeriod = pMpeg4Enc->h263Component[OUTPUT_PORT_INDEX].nPFrames + 1; 246 pH263Param->SliceMode = 0; 247 pH263Param->RandomIntraMBRefresh = 0; 248 pH263Param->EnableFRMRateControl = 1; /* 0: disable, 1: enable */ 249 pH263Param->Bitrate = pSECOutputPort->portDefinition.format.video.nBitrate; 250 pH263Param->FrameQp = 20; 251 pH263Param->FrameQp_P = 20; 252 pH263Param->QSCodeMax = 30; 253 pH263Param->QSCodeMin = 10; 254 pH263Param->CBRPeriodRf = 10; 255 pH263Param->PadControlOn = 0; /* 0: Use boundary pixel, 1: Use the below setting value */ 256 pH263Param->LumaPadVal = 0; 257 pH263Param->CbPadVal = 0; 258 pH263Param->CrPadVal = 0; 259 260 pH263Param->FrameRate = (pSECInputPort->portDefinition.format.video.xFramerate) >> 16; 261 262 SEC_OSAL_Log(SEC_LOG_TRACE, "pSECPort->eControlRate: 0x%x", pSECOutputPort->eControlRate); 263 switch (pSECOutputPort->eControlRate) { 264 case OMX_Video_ControlRateDisable: 265 /* TBD */ 266 break; 267 case OMX_Video_ControlRateVariable: 268 /* TBD */ 269 break; 270 default: 271 break; 272 } 273 274 H263PrintParams(*pH263Param); 275 } 276 277 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_GetParameter( 278 OMX_IN OMX_HANDLETYPE hComponent, 279 OMX_IN OMX_INDEXTYPE nParamIndex, 280 OMX_INOUT OMX_PTR pComponentParameterStructure) 281 { 282 OMX_ERRORTYPE ret = OMX_ErrorNone; 283 OMX_COMPONENTTYPE *pOMXComponent = NULL; 284 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 285 286 FunctionIn(); 287 288 if (hComponent == NULL || pComponentParameterStructure == NULL) { 289 ret = OMX_ErrorBadParameter; 290 goto EXIT; 291 } 292 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 293 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 294 if (ret != OMX_ErrorNone) { 295 goto EXIT; 296 } 297 if (pOMXComponent->pComponentPrivate == NULL) { 298 ret = OMX_ErrorBadParameter; 299 goto EXIT; 300 } 301 302 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 303 if (pSECComponent->currentState == OMX_StateInvalid ) { 304 ret = OMX_StateInvalid; 305 goto EXIT; 306 } 307 308 switch (nParamIndex) { 309 case OMX_IndexParamVideoMpeg4: 310 { 311 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pComponentParameterStructure; 312 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = NULL; 313 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 314 315 ret = SEC_OMX_Check_SizeVersion(pDstMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 316 if (ret != OMX_ErrorNone) { 317 goto EXIT; 318 } 319 320 if (pDstMpeg4Param->nPortIndex >= ALL_PORT_NUM) { 321 ret = OMX_ErrorBadPortIndex; 322 goto EXIT; 323 } 324 325 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 326 pSrcMpeg4Param = &pMpeg4Enc->mpeg4Component[pDstMpeg4Param->nPortIndex]; 327 328 SEC_OSAL_Memcpy(pDstMpeg4Param, pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 329 } 330 break; 331 case OMX_IndexParamVideoH263: 332 { 333 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = (OMX_VIDEO_PARAM_H263TYPE *)pComponentParameterStructure; 334 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = NULL; 335 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 336 337 ret = SEC_OMX_Check_SizeVersion(pDstH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 338 if (ret != OMX_ErrorNone) { 339 goto EXIT; 340 } 341 342 if (pDstH263Param->nPortIndex >= ALL_PORT_NUM) { 343 ret = OMX_ErrorBadPortIndex; 344 goto EXIT; 345 } 346 347 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 348 pSrcH263Param = &pMpeg4Enc->h263Component[pDstH263Param->nPortIndex]; 349 350 SEC_OSAL_Memcpy(pDstH263Param, pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 351 } 352 break; 353 case OMX_IndexParamStandardComponentRole: 354 { 355 OMX_S32 codecType; 356 OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)pComponentParameterStructure; 357 358 ret = SEC_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 359 if (ret != OMX_ErrorNone) { 360 goto EXIT; 361 } 362 363 codecType = ((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 364 if (codecType == CODEC_TYPE_MPEG4) 365 SEC_OSAL_Strcpy((char *)pComponentRole->cRole, SEC_OMX_COMPOMENT_MPEG4_ENC_ROLE); 366 else 367 SEC_OSAL_Strcpy((char *)pComponentRole->cRole, SEC_OMX_COMPOMENT_H263_ENC_ROLE); 368 } 369 break; 370 case OMX_IndexParamVideoProfileLevelQuerySupported: 371 { 372 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 373 SEC_OMX_VIDEO_PROFILELEVEL *pProfileLevel = NULL; 374 OMX_U32 maxProfileLevelNum = 0; 375 OMX_S32 codecType; 376 377 ret = SEC_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 378 if (ret != OMX_ErrorNone) { 379 goto EXIT; 380 } 381 382 if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { 383 ret = OMX_ErrorBadPortIndex; 384 goto EXIT; 385 } 386 387 codecType = ((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 388 if (codecType == CODEC_TYPE_MPEG4) { 389 pProfileLevel = supportedMPEG4ProfileLevels; 390 maxProfileLevelNum = sizeof(supportedMPEG4ProfileLevels) / sizeof(SEC_OMX_VIDEO_PROFILELEVEL); 391 } else { 392 pProfileLevel = supportedH263ProfileLevels; 393 maxProfileLevelNum = sizeof(supportedH263ProfileLevels) / sizeof(SEC_OMX_VIDEO_PROFILELEVEL); 394 } 395 396 if (pDstProfileLevel->nProfileIndex >= maxProfileLevelNum) { 397 ret = OMX_ErrorNoMore; 398 goto EXIT; 399 } 400 401 pProfileLevel += pDstProfileLevel->nProfileIndex; 402 pDstProfileLevel->eProfile = pProfileLevel->profile; 403 pDstProfileLevel->eLevel = pProfileLevel->level; 404 } 405 break; 406 case OMX_IndexParamVideoProfileLevelCurrent: 407 { 408 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 409 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = NULL; 410 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = NULL; 411 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 412 OMX_S32 codecType; 413 414 ret = SEC_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 415 if (ret != OMX_ErrorNone) { 416 goto EXIT; 417 } 418 419 if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { 420 ret = OMX_ErrorBadPortIndex; 421 goto EXIT; 422 } 423 424 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 425 codecType = pMpeg4Enc->hMFCMpeg4Handle.codecType; 426 if (codecType == CODEC_TYPE_MPEG4) { 427 pSrcMpeg4Param = &pMpeg4Enc->mpeg4Component[pDstProfileLevel->nPortIndex]; 428 pDstProfileLevel->eProfile = pSrcMpeg4Param->eProfile; 429 pDstProfileLevel->eLevel = pSrcMpeg4Param->eLevel; 430 } else { 431 pSrcH263Param = &pMpeg4Enc->h263Component[pDstProfileLevel->nPortIndex]; 432 pDstProfileLevel->eProfile = pSrcH263Param->eProfile; 433 pDstProfileLevel->eLevel = pSrcH263Param->eLevel; 434 } 435 } 436 break; 437 case OMX_IndexParamVideoErrorCorrection: 438 { 439 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; 440 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = NULL; 441 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 442 443 ret = SEC_OMX_Check_SizeVersion(pDstErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); 444 if (ret != OMX_ErrorNone) { 445 goto EXIT; 446 } 447 448 if (pDstErrorCorrectionType->nPortIndex != OUTPUT_PORT_INDEX) { 449 ret = OMX_ErrorBadPortIndex; 450 goto EXIT; 451 } 452 453 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 454 pSrcErrorCorrectionType = &pMpeg4Enc->errorCorrectionType[OUTPUT_PORT_INDEX]; 455 456 pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; 457 pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; 458 pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; 459 pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; 460 pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; 461 } 462 break; 463 default: 464 ret = SEC_OMX_VideoEncodeGetParameter(hComponent, nParamIndex, pComponentParameterStructure); 465 break; 466 } 467 EXIT: 468 FunctionOut(); 469 470 return ret; 471 } 472 473 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_SetParameter( 474 OMX_IN OMX_HANDLETYPE hComponent, 475 OMX_IN OMX_INDEXTYPE nIndex, 476 OMX_IN OMX_PTR pComponentParameterStructure) 477 { 478 OMX_ERRORTYPE ret = OMX_ErrorNone; 479 OMX_COMPONENTTYPE *pOMXComponent = NULL; 480 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 481 482 FunctionIn(); 483 484 if (hComponent == NULL || pComponentParameterStructure == NULL) { 485 ret = OMX_ErrorBadParameter; 486 goto EXIT; 487 } 488 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 489 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 490 if (ret != OMX_ErrorNone) { 491 goto EXIT; 492 } 493 if (pOMXComponent->pComponentPrivate == NULL) { 494 ret = OMX_ErrorBadParameter; 495 goto EXIT; 496 } 497 498 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 499 if (pSECComponent->currentState == OMX_StateInvalid ) { 500 ret = OMX_StateInvalid; 501 goto EXIT; 502 } 503 504 switch (nIndex) { 505 case OMX_IndexParamVideoMpeg4: 506 { 507 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = NULL; 508 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pComponentParameterStructure; 509 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 510 511 ret = SEC_OMX_Check_SizeVersion(pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 512 if (ret != OMX_ErrorNone) { 513 goto EXIT; 514 } 515 516 if (pSrcMpeg4Param->nPortIndex >= ALL_PORT_NUM) { 517 ret = OMX_ErrorBadPortIndex; 518 goto EXIT; 519 } 520 521 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 522 pDstMpeg4Param = &pMpeg4Enc->mpeg4Component[pSrcMpeg4Param->nPortIndex]; 523 524 SEC_OSAL_Memcpy(pDstMpeg4Param, pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 525 } 526 break; 527 case OMX_IndexParamVideoH263: 528 { 529 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = NULL; 530 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = (OMX_VIDEO_PARAM_H263TYPE *)pComponentParameterStructure; 531 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 532 533 ret = SEC_OMX_Check_SizeVersion(pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 534 if (ret != OMX_ErrorNone) { 535 goto EXIT; 536 } 537 538 if (pSrcH263Param->nPortIndex >= ALL_PORT_NUM) { 539 ret = OMX_ErrorBadPortIndex; 540 goto EXIT; 541 } 542 543 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 544 pDstH263Param = &pMpeg4Enc->h263Component[pSrcH263Param->nPortIndex]; 545 546 SEC_OSAL_Memcpy(pDstH263Param, pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 547 } 548 break; 549 case OMX_IndexParamStandardComponentRole: 550 { 551 OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)pComponentParameterStructure; 552 553 ret = SEC_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 554 if (ret != OMX_ErrorNone) { 555 goto EXIT; 556 } 557 558 if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) { 559 ret = OMX_ErrorIncorrectStateOperation; 560 goto EXIT; 561 } 562 563 if (!SEC_OSAL_Strcmp((char*)pComponentRole->cRole, SEC_OMX_COMPOMENT_MPEG4_ENC_ROLE)) { 564 pSECComponent->pSECPort[OUTPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 565 //((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType = CODEC_TYPE_MPEG4; 566 } else if (!SEC_OSAL_Strcmp((char*)pComponentRole->cRole, SEC_OMX_COMPOMENT_H263_ENC_ROLE)) { 567 pSECComponent->pSECPort[OUTPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 568 //((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType = CODEC_TYPE_H263; 569 } else { 570 ret = OMX_ErrorBadParameter; 571 goto EXIT; 572 } 573 } 574 break; 575 case OMX_IndexParamVideoProfileLevelCurrent: 576 { 577 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 578 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = NULL; 579 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = NULL; 580 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 581 OMX_S32 codecType; 582 583 ret = SEC_OMX_Check_SizeVersion(pSrcProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 584 if (ret != OMX_ErrorNone) { 585 goto EXIT; 586 } 587 588 if (pSrcProfileLevel->nPortIndex >= ALL_PORT_NUM) { 589 ret = OMX_ErrorBadPortIndex; 590 goto EXIT; 591 } 592 593 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 594 codecType = pMpeg4Enc->hMFCMpeg4Handle.codecType; 595 if (codecType == CODEC_TYPE_MPEG4) { 596 /* 597 * To do: Check validity of profile & level parameters 598 */ 599 600 pDstMpeg4Param = &pMpeg4Enc->mpeg4Component[pSrcProfileLevel->nPortIndex]; 601 pDstMpeg4Param->eProfile = pSrcProfileLevel->eProfile; 602 pDstMpeg4Param->eLevel = pSrcProfileLevel->eLevel; 603 } else { 604 /* 605 * To do: Check validity of profile & level parameters 606 */ 607 608 pDstH263Param = &pMpeg4Enc->h263Component[pSrcProfileLevel->nPortIndex]; 609 pDstH263Param->eProfile = pSrcProfileLevel->eProfile; 610 pDstH263Param->eLevel = pSrcProfileLevel->eLevel; 611 } 612 } 613 break; 614 case OMX_IndexParamVideoErrorCorrection: 615 { 616 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; 617 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = NULL; 618 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 619 620 ret = SEC_OMX_Check_SizeVersion(pSrcErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); 621 if (ret != OMX_ErrorNone) { 622 goto EXIT; 623 } 624 625 if (pSrcErrorCorrectionType->nPortIndex != OUTPUT_PORT_INDEX) { 626 ret = OMX_ErrorBadPortIndex; 627 goto EXIT; 628 } 629 630 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 631 pDstErrorCorrectionType = &pMpeg4Enc->errorCorrectionType[OUTPUT_PORT_INDEX]; 632 633 pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; 634 pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; 635 pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; 636 pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; 637 pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; 638 } 639 break; 640 default: 641 ret = SEC_OMX_VideoEncodeSetParameter(hComponent, nIndex, pComponentParameterStructure); 642 break; 643 } 644 EXIT: 645 FunctionOut(); 646 647 return ret; 648 } 649 650 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_SetConfig( 651 OMX_IN OMX_HANDLETYPE hComponent, 652 OMX_IN OMX_INDEXTYPE nIndex, 653 OMX_IN OMX_PTR pComponentConfigStructure) 654 { 655 OMX_ERRORTYPE ret = OMX_ErrorNone; 656 OMX_COMPONENTTYPE *pOMXComponent = NULL; 657 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 658 659 FunctionIn(); 660 661 if (hComponent == NULL || pComponentConfigStructure == NULL) { 662 ret = OMX_ErrorBadParameter; 663 goto EXIT; 664 } 665 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 666 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 667 if (ret != OMX_ErrorNone) { 668 goto EXIT; 669 } 670 if (pOMXComponent->pComponentPrivate == NULL) { 671 ret = OMX_ErrorBadParameter; 672 goto EXIT; 673 } 674 675 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 676 if (pSECComponent->currentState == OMX_StateInvalid) { 677 ret = OMX_ErrorInvalidState; 678 goto EXIT; 679 } 680 681 switch (nIndex) { 682 default: 683 ret = SEC_OMX_SetConfig(hComponent, nIndex, pComponentConfigStructure); 684 break; 685 } 686 687 EXIT: 688 FunctionOut(); 689 690 return ret; 691 } 692 693 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_ComponentRoleEnum( 694 OMX_IN OMX_HANDLETYPE hComponent, 695 OMX_OUT OMX_U8 *cRole, 696 OMX_IN OMX_U32 nIndex) 697 { 698 OMX_ERRORTYPE ret = OMX_ErrorNone; 699 OMX_COMPONENTTYPE *pOMXComponent = NULL; 700 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 701 OMX_S32 codecType; 702 703 FunctionIn(); 704 705 if ((hComponent == NULL) || (cRole == NULL)) { 706 ret = OMX_ErrorBadParameter; 707 goto EXIT; 708 } 709 if (nIndex != (MAX_COMPONENT_ROLE_NUM - 1)) { 710 ret = OMX_ErrorNoMore; 711 goto EXIT; 712 } 713 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 714 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 715 if (ret != OMX_ErrorNone) { 716 goto EXIT; 717 } 718 if (pOMXComponent->pComponentPrivate == NULL) { 719 ret = OMX_ErrorBadParameter; 720 goto EXIT; 721 } 722 723 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 724 if (pSECComponent->currentState == OMX_StateInvalid ) { 725 ret = OMX_StateInvalid; 726 goto EXIT; 727 } 728 729 codecType = ((SEC_MPEG4ENC_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 730 if (codecType == CODEC_TYPE_MPEG4) 731 SEC_OSAL_Strcpy((char *)cRole, SEC_OMX_COMPOMENT_MPEG4_ENC_ROLE); 732 else 733 SEC_OSAL_Strcpy((char *)cRole, SEC_OMX_COMPOMENT_H263_ENC_ROLE); 734 735 EXIT: 736 FunctionOut(); 737 738 return ret; 739 } 740 741 /* MFC Init */ 742 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_Init(OMX_COMPONENTTYPE *pOMXComponent) 743 { 744 OMX_ERRORTYPE ret = OMX_ErrorNone; 745 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 746 SEC_OMX_BASEPORT *pSECPort = NULL; 747 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 748 OMX_HANDLETYPE hMFCHandle = NULL; 749 OMX_S32 returnCodec = 0; 750 751 FunctionIn(); 752 753 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 754 pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC = OMX_FALSE; 755 pSECComponent->bUseFlagEOF = OMX_FALSE; 756 pSECComponent->bSaveFlagEOS = OMX_FALSE; 757 758 /* MFC(Multi Format Codec) encoder and CMM(Codec Memory Management) driver open */ 759 hMFCHandle = SsbSipMfcEncOpen(); 760 if (hMFCHandle == NULL) { 761 ret = OMX_ErrorInsufficientResources; 762 goto EXIT; 763 } 764 pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle = hMFCHandle; 765 766 /* set MFC ENC VIDEO PARAM and initialize MFC encoder instance */ 767 if (pMpeg4Enc->hMFCMpeg4Handle.codecType == CODEC_TYPE_MPEG4) { 768 Set_Mpeg4Enc_Param(&(pMpeg4Enc->hMFCMpeg4Handle.mpeg4MFCParam), pSECComponent); 769 returnCodec = SsbSipMfcEncInit(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.mpeg4MFCParam)); 770 } else { 771 Set_H263Enc_Param(&(pMpeg4Enc->hMFCMpeg4Handle.h263MFCParam), pSECComponent); 772 returnCodec = SsbSipMfcEncInit(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.h263MFCParam)); 773 } 774 if (returnCodec != MFC_RET_OK) { 775 ret = OMX_ErrorInsufficientResources; 776 goto EXIT; 777 } 778 779 /* allocate encoder's input buffer */ 780 returnCodec = SsbSipMfcEncGetInBuf(hMFCHandle, &(pMpeg4Enc->hMFCMpeg4Handle.inputInfo)); 781 if (returnCodec != MFC_RET_OK) { 782 ret = OMX_ErrorInsufficientResources; 783 goto EXIT; 784 } 785 786 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YPhyAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YPhyAddr; 787 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CPhyAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CPhyAddr; 788 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YVirAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YVirAddr; 789 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CVirAddr = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CVirAddr; 790 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.YSize = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.YSize; 791 pSECComponent->processData[INPUT_PORT_INDEX].specificBufferHeader.CSize = pMpeg4Enc->hMFCMpeg4Handle.inputInfo.CSize; 792 793 SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); 794 SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); 795 pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp = 0; 796 797 EXIT: 798 FunctionOut(); 799 800 return ret; 801 } 802 803 /* MFC Terminate */ 804 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_Terminate(OMX_COMPONENTTYPE *pOMXComponent) 805 { 806 OMX_ERRORTYPE ret = OMX_ErrorNone; 807 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 808 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 809 OMX_HANDLETYPE hMFCHandle = NULL; 810 811 FunctionIn(); 812 813 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 814 hMFCHandle = pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle; 815 816 if (hMFCHandle != NULL) { 817 SsbSipMfcEncClose(hMFCHandle); 818 pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle = NULL; 819 } 820 821 EXIT: 822 FunctionOut(); 823 824 return ret; 825 } 826 827 OMX_ERRORTYPE SEC_MFC_Mpeg4_Encode(OMX_COMPONENTTYPE *pOMXComponent, SEC_OMX_DATA *pInputData, SEC_OMX_DATA *pOutputData) 828 { 829 OMX_ERRORTYPE ret = OMX_ErrorNone; 830 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 831 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 832 OMX_HANDLETYPE hMFCHandle = pMpeg4Enc->hMFCMpeg4Handle.hMFCHandle; 833 SSBSIP_MFC_ENC_INPUT_INFO *pInputInfo = &(pMpeg4Enc->hMFCMpeg4Handle.inputInfo); 834 SSBSIP_MFC_ENC_OUTPUT_INFO outputInfo; 835 SEC_OMX_BASEPORT *pSECPort = NULL; 836 MFC_ENC_ADDR_INFO addrInfo; 837 OMX_U32 oneFrameSize = pInputData->dataLen; 838 OMX_S32 returnCodec = 0; 839 840 FunctionIn(); 841 842 if (pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC == OMX_FALSE) { 843 returnCodec = SsbSipMfcEncGetOutBuf(hMFCHandle, &outputInfo); 844 if (returnCodec != MFC_RET_OK) 845 { 846 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncGetOutBuf failed, ret:%d", __FUNCTION__, returnCodec); 847 ret = OMX_ErrorUndefined; 848 goto EXIT; 849 } 850 851 pOutputData->dataBuffer = outputInfo.StrmVirAddr; 852 pOutputData->allocSize = outputInfo.headerSize; 853 pOutputData->dataLen = outputInfo.headerSize; 854 pOutputData->timeStamp = pInputData->timeStamp; 855 pOutputData->nFlags |= OMX_BUFFERFLAG_CODECCONFIG; 856 pOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; 857 858 pMpeg4Enc->hMFCMpeg4Handle.bConfiguredMFC = OMX_TRUE; 859 860 if (pOutputData->dataLen > 0) { 861 ret = OMX_ErrorNone; 862 goto EXIT; 863 } else { 864 ret = OMX_ErrorInputDataEncodeYet; 865 goto EXIT; 866 } 867 } 868 869 if ((pInputData->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) && 870 (pSECComponent->bUseFlagEOF == OMX_FALSE)) { 871 pSECComponent->bUseFlagEOF = OMX_TRUE; 872 } 873 874 pSECComponent->timeStamp[pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp] = pInputData->timeStamp; 875 pSECComponent->nFlags[pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp] = pInputData->nFlags; 876 SsbSipMfcEncSetConfig(hMFCHandle, MFC_ENC_SETCONF_FRAME_TAG, &(pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp)); 877 pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp++; 878 if (pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp >= MAX_TIMESTAMP) 879 pMpeg4Enc->hMFCMpeg4Handle.indexTimestamp = 0; 880 881 if (oneFrameSize <= 0) { 882 pOutputData->timeStamp = pInputData->timeStamp; 883 pOutputData->nFlags = pInputData->nFlags; 884 885 ret = OMX_ErrorNone; 886 goto EXIT; 887 } 888 889 pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 890 if (pSECPort->portDefinition.format.video.eColorFormat == SEC_OMX_COLOR_FormatNV12PhysicalAddress) { 891 /* input data from Real camera */ 892 #define USE_FIMC_FRAME_BUFFER 893 #ifdef USE_FIMC_FRAME_BUFFER 894 SEC_OSAL_Memcpy(&addrInfo.pAddrY, pInputData->dataBuffer, sizeof(addrInfo.pAddrY)); 895 SEC_OSAL_Memcpy(&addrInfo.pAddrC, pInputData->dataBuffer + sizeof(addrInfo.pAddrY), sizeof(addrInfo.pAddrC)); 896 pInputInfo->YPhyAddr = addrInfo.pAddrY; 897 pInputInfo->CPhyAddr = addrInfo.pAddrC; 898 returnCodec = SsbSipMfcEncSetInBuf(hMFCHandle, pInputInfo); 899 if (returnCodec != MFC_RET_OK) { 900 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncSetInBuf failed, ret:%d", __FUNCTION__, returnCodec); 901 ret = OMX_ErrorUndefined; 902 goto EXIT; 903 } 904 #else 905 OMX_U32 width, height; 906 907 width = pSECPort->portDefinition.format.video.nFrameWidth; 908 height = pSECPort->portDefinition.format.video.nFrameHeight; 909 910 SEC_OSAL_Memcpy(pInputInfo->YVirAddr, pInputData->dataBuffer, ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height))); 911 SEC_OSAL_Memcpy(pInputInfo->CVirAddr, pInputData->dataBuffer + ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height)), ALIGN_TO_8KB(ALIGN_TO_128B(width) * ALIGN_TO_32B(height / 2))); 912 #endif 913 } 914 915 returnCodec = SsbSipMfcEncExe(hMFCHandle); 916 if (returnCodec == MFC_RET_OK) { 917 OMX_S32 indexTimestamp = 0; 918 919 returnCodec = SsbSipMfcEncGetOutBuf(hMFCHandle, &outputInfo); 920 921 if ((SsbSipMfcEncGetConfig(hMFCHandle, MFC_ENC_GETCONF_FRAME_TAG, &indexTimestamp) != MFC_RET_OK) || 922 (((indexTimestamp < 0) || (indexTimestamp > MAX_TIMESTAMP)))) { 923 pOutputData->timeStamp = pInputData->timeStamp; 924 pOutputData->nFlags = pInputData->nFlags; 925 } else { 926 pOutputData->timeStamp = pSECComponent->timeStamp[indexTimestamp]; 927 pOutputData->nFlags = pSECComponent->nFlags[indexTimestamp]; 928 } 929 930 if (returnCodec == MFC_RET_OK) { 931 /** Fill Output Buffer **/ 932 pOutputData->dataBuffer = outputInfo.StrmVirAddr; 933 pOutputData->allocSize = outputInfo.dataSize; 934 pOutputData->dataLen = outputInfo.dataSize; 935 pOutputData->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME; 936 if (outputInfo.frameType == MFC_FRAME_TYPE_I_FRAME) 937 pOutputData->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 938 939 ret = OMX_ErrorNone; 940 } else { 941 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncGetOutBuf failed, ret:%d", __FUNCTION__, returnCodec); 942 ret = OMX_ErrorUndefined; 943 } 944 } else { 945 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcEncExe failed, ret:%d", __FUNCTION__, returnCodec); 946 ret = OMX_ErrorUndefined; 947 } 948 949 EXIT: 950 FunctionOut(); 951 952 return ret; 953 } 954 955 /* MFC Encode */ 956 OMX_ERRORTYPE SEC_MFC_Mpeg4Enc_bufferProcess(OMX_COMPONENTTYPE *pOMXComponent, SEC_OMX_DATA *pInputData, SEC_OMX_DATA *pOutputData) 957 { 958 OMX_ERRORTYPE ret = OMX_ErrorNone; 959 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 960 SEC_OMX_BASEPORT *pInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 961 SEC_OMX_BASEPORT *pOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 962 963 FunctionIn(); 964 965 if ((!CHECK_PORT_ENABLED(pInputPort)) || (!CHECK_PORT_ENABLED(pOutputPort)) || 966 (!CHECK_PORT_POPULATED(pInputPort)) || (!CHECK_PORT_POPULATED(pOutputPort))) { 967 goto EXIT; 968 } 969 if (OMX_FALSE == SEC_Check_BufferProcess_State(pSECComponent)) { 970 goto EXIT; 971 } 972 973 ret = SEC_MFC_Mpeg4_Encode(pOMXComponent, pInputData, pOutputData); 974 if (ret != OMX_ErrorNone) { 975 if (ret == OMX_ErrorInputDataEncodeYet) { 976 pOutputData->usedDataLen = 0; 977 pOutputData->remainDataLen = pOutputData->dataLen; 978 } else { 979 pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, 980 pSECComponent->callbackData, 981 OMX_EventError, ret, 0, NULL); 982 } 983 } else { 984 pInputData->usedDataLen += pInputData->dataLen; 985 pInputData->remainDataLen = pInputData->dataLen - pInputData->usedDataLen; 986 pInputData->dataLen -= pInputData->usedDataLen; 987 pInputData->usedDataLen = 0; 988 989 pOutputData->usedDataLen = 0; 990 pOutputData->remainDataLen = pOutputData->dataLen; 991 } 992 993 EXIT: 994 FunctionOut(); 995 996 return ret; 997 } 998 999 OSCL_EXPORT_REF OMX_ERRORTYPE SEC_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName) 1000 { 1001 OMX_ERRORTYPE ret = OMX_ErrorNone; 1002 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1003 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1004 SEC_OMX_BASEPORT *pSECPort = NULL; 1005 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 1006 OMX_S32 codecType = -1; 1007 int i = 0; 1008 1009 FunctionIn(); 1010 1011 if ((hComponent == NULL) || (componentName == NULL)) { 1012 ret = OMX_ErrorBadParameter; 1013 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: parameters are null, ret: %X", __FUNCTION__, ret); 1014 goto EXIT; 1015 } 1016 if (SEC_OSAL_Strcmp(SEC_OMX_COMPOMENT_MPEG4_ENC, componentName) == 0) { 1017 codecType = CODEC_TYPE_MPEG4; 1018 } else if (SEC_OSAL_Strcmp(SEC_OMX_COMPOMENT_H263_ENC, componentName) == 0) { 1019 codecType = CODEC_TYPE_H263; 1020 } else { 1021 ret = OMX_ErrorBadParameter; 1022 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: componentName(%s) error, ret: %X", __FUNCTION__, componentName, ret); 1023 goto EXIT; 1024 } 1025 1026 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1027 ret = SEC_OMX_VideoEncodeComponentInit(pOMXComponent); 1028 if (ret != OMX_ErrorNone) { 1029 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SEC_OMX_VideoDecodeComponentInit error, ret: %X", __FUNCTION__, ret); 1030 goto EXIT; 1031 } 1032 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1033 pSECComponent->codecType = HW_VIDEO_CODEC; 1034 1035 pSECComponent->componentName = (OMX_STRING)SEC_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE); 1036 if (pSECComponent->componentName == NULL) { 1037 SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); 1038 ret = OMX_ErrorInsufficientResources; 1039 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: componentName alloc error, ret: %X", __FUNCTION__, ret); 1040 goto EXIT; 1041 } 1042 SEC_OSAL_Memset(pSECComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE); 1043 1044 pMpeg4Enc = SEC_OSAL_Malloc(sizeof(SEC_MPEG4ENC_HANDLE)); 1045 if (pMpeg4Enc == NULL) { 1046 SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); 1047 ret = OMX_ErrorInsufficientResources; 1048 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SEC_MPEG4ENC_HANDLE alloc error, ret: %X", __FUNCTION__, ret); 1049 goto EXIT; 1050 } 1051 SEC_OSAL_Memset(pMpeg4Enc, 0, sizeof(SEC_MPEG4ENC_HANDLE)); 1052 pSECComponent->hCodecHandle = (OMX_HANDLETYPE)pMpeg4Enc; 1053 pMpeg4Enc->hMFCMpeg4Handle.codecType = codecType; 1054 1055 if (codecType == CODEC_TYPE_MPEG4) 1056 SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPOMENT_MPEG4_ENC); 1057 else 1058 SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPOMENT_H263_ENC); 1059 1060 /* Set componentVersion */ 1061 pSECComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; 1062 pSECComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; 1063 pSECComponent->componentVersion.s.nRevision = REVISION_NUMBER; 1064 pSECComponent->componentVersion.s.nStep = STEP_NUMBER; 1065 /* Set specVersion */ 1066 pSECComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; 1067 pSECComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; 1068 pSECComponent->specVersion.s.nRevision = REVISION_NUMBER; 1069 pSECComponent->specVersion.s.nStep = STEP_NUMBER; 1070 1071 /* Android CapabilityFlags */ 1072 pSECComponent->capabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; 1073 pSECComponent->capabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_TRUE; 1074 pSECComponent->capabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_TRUE; 1075 pSECComponent->capabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; 1076 pSECComponent->capabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE; 1077 pSECComponent->capabilityFlags.iOMXComponentUsesNALStartCodes = OMX_TRUE; 1078 pSECComponent->capabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE; 1079 pSECComponent->capabilityFlags.iOMXComponentUsesFullAVCFrames = OMX_TRUE; 1080 1081 /* Input port */ 1082 pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1083 pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; 1084 pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; 1085 pSECPort->portDefinition.format.video.nBitrate = 64000; 1086 pSECPort->portDefinition.format.video.xFramerate= (15 << 16); 1087 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; 1088 pSECPort->portDefinition.format.video.pNativeRender = 0; 1089 pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; 1090 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1091 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video"); 1092 pSECPort->portDefinition.format.video.eColorFormat = SEC_OMX_COLOR_FormatNV12PhysicalAddress;//OMX_COLOR_FormatYUV420SemiPlanar; 1093 pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE; 1094 pSECPort->portDefinition.bEnabled = OMX_TRUE; 1095 1096 /* Output port */ 1097 pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1098 pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; 1099 pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; 1100 pSECPort->portDefinition.format.video.nBitrate = 64000; 1101 pSECPort->portDefinition.format.video.xFramerate= (15 << 16); 1102 if (codecType == CODEC_TYPE_MPEG4) { 1103 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 1104 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1105 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/mpeg4"); 1106 } else { 1107 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 1108 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1109 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/h263"); 1110 } 1111 pSECPort->portDefinition.format.video.pNativeRender = 0; 1112 pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; 1113 pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; 1114 pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE; 1115 pSECPort->portDefinition.bEnabled = OMX_TRUE; 1116 1117 if (codecType == CODEC_TYPE_MPEG4) { 1118 for(i = 0; i < ALL_PORT_NUM; i++) { 1119 INIT_SET_SIZE_VERSION(&pMpeg4Enc->mpeg4Component[i], OMX_VIDEO_PARAM_MPEG4TYPE); 1120 pMpeg4Enc->mpeg4Component[i].nPortIndex = i; 1121 pMpeg4Enc->mpeg4Component[i].eProfile = OMX_VIDEO_MPEG4ProfileSimple; 1122 pMpeg4Enc->mpeg4Component[i].eLevel = OMX_VIDEO_MPEG4Level4; 1123 1124 pMpeg4Enc->mpeg4Component[i].nPFrames = 10; 1125 pMpeg4Enc->mpeg4Component[i].nBFrames = 0; /* No support for B frames */ 1126 pMpeg4Enc->mpeg4Component[i].nMaxPacketSize = 256; /* Default value */ 1127 pMpeg4Enc->mpeg4Component[i].nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP; 1128 pMpeg4Enc->mpeg4Component[i].bGov = OMX_FALSE; 1129 1130 } 1131 } else { 1132 for(i = 0; i < ALL_PORT_NUM; i++) { 1133 INIT_SET_SIZE_VERSION(&pMpeg4Enc->h263Component[i], OMX_VIDEO_PARAM_H263TYPE); 1134 pMpeg4Enc->h263Component[i].nPortIndex = i; 1135 pMpeg4Enc->h263Component[i].eProfile = OMX_VIDEO_H263ProfileBaseline; 1136 pMpeg4Enc->h263Component[i].eLevel = OMX_VIDEO_H263Level45; 1137 1138 pMpeg4Enc->h263Component[i].nPFrames = 20; 1139 pMpeg4Enc->h263Component[i].nBFrames = 0; /* No support for B frames */ 1140 pMpeg4Enc->h263Component[i].bPLUSPTYPEAllowed = OMX_FALSE; 1141 pMpeg4Enc->h263Component[i].nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP; 1142 pMpeg4Enc->h263Component[i].bForceRoundingTypeToZero = OMX_TRUE; 1143 pMpeg4Enc->h263Component[i].nPictureHeaderRepetition = 0; 1144 pMpeg4Enc->h263Component[i].nGOBHeaderInterval = 0; 1145 } 1146 } 1147 1148 pOMXComponent->GetParameter = &SEC_MFC_Mpeg4Enc_GetParameter; 1149 pOMXComponent->SetParameter = &SEC_MFC_Mpeg4Enc_SetParameter; 1150 pOMXComponent->SetConfig = &SEC_MFC_Mpeg4Enc_SetConfig; 1151 pOMXComponent->ComponentRoleEnum = &SEC_MFC_Mpeg4Enc_ComponentRoleEnum; 1152 pOMXComponent->ComponentDeInit = &SEC_OMX_ComponentDeinit; 1153 1154 pSECComponent->sec_mfc_componentInit = &SEC_MFC_Mpeg4Enc_Init; 1155 pSECComponent->sec_mfc_componentTerminate = &SEC_MFC_Mpeg4Enc_Terminate; 1156 pSECComponent->sec_mfc_bufferProcess = &SEC_MFC_Mpeg4Enc_bufferProcess; 1157 pSECComponent->sec_checkInputFrame = NULL; 1158 1159 pSECComponent->currentState = OMX_StateLoaded; 1160 1161 ret = OMX_ErrorNone; 1162 1163 EXIT: 1164 FunctionOut(); 1165 1166 return ret; 1167 } 1168 1169 OMX_ERRORTYPE SEC_OMX_ComponentDeinit(OMX_HANDLETYPE hComponent) 1170 { 1171 OMX_ERRORTYPE ret = OMX_ErrorNone; 1172 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1173 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1174 SEC_MPEG4ENC_HANDLE *pMpeg4Enc = NULL; 1175 1176 FunctionIn(); 1177 1178 if (hComponent == NULL) { 1179 ret = OMX_ErrorBadParameter; 1180 goto EXIT; 1181 } 1182 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1183 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1184 1185 SEC_OSAL_Free(pSECComponent->componentName); 1186 pSECComponent->componentName = NULL; 1187 1188 pMpeg4Enc = (SEC_MPEG4ENC_HANDLE *)pSECComponent->hCodecHandle; 1189 if (pMpeg4Enc != NULL) { 1190 SEC_OSAL_Free(pMpeg4Enc); 1191 pMpeg4Enc = pSECComponent->hCodecHandle = NULL; 1192 } 1193 1194 ret = SEC_OMX_VideoEncodeComponentDeinit(pOMXComponent); 1195 if (ret != OMX_ErrorNone) { 1196 goto EXIT; 1197 } 1198 1199 ret = OMX_ErrorNone; 1200 1201 EXIT: 1202 FunctionOut(); 1203 1204 return ret; 1205 } 1206