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_Mpeg4dec.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 #include <stdio.h> 28 #include <stdlib.h> 29 #include <string.h> 30 31 #include "SEC_OMX_Macros.h" 32 #include "SEC_OMX_Basecomponent.h" 33 #include "SEC_OMX_Baseport.h" 34 #include "SEC_OMX_Vdec.h" 35 #include "library_register.h" 36 #include "SEC_OMX_Mpeg4dec.h" 37 #include "SsbSipMfcApi.h" 38 39 #undef SEC_LOG_TAG 40 #define SEC_LOG_TAG "SEC_MPEG4_DEC" 41 #define SEC_LOG_OFF 42 #include "SEC_OSAL_Log.h" 43 44 //#define FULL_FRAME_SEARCH 45 46 /* MPEG4 Decoder 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 Decoder Supported Levels & profiles */ 66 SEC_OMX_VIDEO_PROFILELEVEL supportedH263ProfileLevels[] = { 67 /* Baseline (Profile 0) */ 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 /* Profile 1 */ 77 {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level10}, 78 {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level20}, 79 {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level30}, 80 {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level40}, 81 {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level45}, 82 {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level50}, 83 {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level60}, 84 {OMX_VIDEO_H263ProfileH320Coding, OMX_VIDEO_H263Level70}, 85 /* Profile 2 */ 86 {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level10}, 87 {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level20}, 88 {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level30}, 89 {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level40}, 90 {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level45}, 91 {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level50}, 92 {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level60}, 93 {OMX_VIDEO_H263ProfileBackwardCompatible, OMX_VIDEO_H263Level70}, 94 /* Profile 3, restricted up to SD resolution */ 95 {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level10}, 96 {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level20}, 97 {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level30}, 98 {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level40}, 99 {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level45}, 100 {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level50}, 101 {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level60}, 102 {OMX_VIDEO_H263ProfileISWV2, OMX_VIDEO_H263Level70}}; 103 104 static OMX_HANDLETYPE ghMFCHandle = NULL; 105 static OMX_BOOL gbFIMV1 = OMX_FALSE; 106 107 static int Check_Mpeg4_Frame(OMX_U8 *pInputStream, OMX_U32 buffSize, OMX_U32 flag, OMX_BOOL bPreviousFrameEOF, OMX_BOOL *pbEndOfFrame) 108 { 109 int len, readStream; 110 unsigned startCode; 111 OMX_BOOL bFrameStart; 112 113 len = 0; 114 bFrameStart = OMX_FALSE; 115 116 if (flag & OMX_BUFFERFLAG_CODECCONFIG) { 117 if (*pInputStream == 0x03) { /* FIMV1 */ 118 if (ghMFCHandle != NULL) { 119 BitmapInfoHhr *pInfoHeader; 120 SSBSIP_MFC_IMG_RESOLUTION imgResolution; 121 122 pInfoHeader = (BitmapInfoHhr *)(pInputStream + 1); 123 imgResolution.width = pInfoHeader->BiWidth; 124 imgResolution.height = pInfoHeader->BiHeight; 125 SsbSipMfcDecSetConfig(ghMFCHandle, MFC_DEC_SETCONF_FIMV1_WIDTH_HEIGHT, &imgResolution); 126 127 SEC_OSAL_Log(SEC_LOG_TRACE, "width(%d), height(%d)", imgResolution.width, imgResolution.height); 128 gbFIMV1 = OMX_TRUE; 129 *pbEndOfFrame = OMX_TRUE; 130 return buffSize; 131 } 132 } 133 } 134 135 if (gbFIMV1) { 136 *pbEndOfFrame = OMX_TRUE; 137 return buffSize; 138 } 139 140 if (bPreviousFrameEOF == OMX_FALSE) 141 bFrameStart = OMX_TRUE; 142 143 startCode = 0xFFFFFFFF; 144 if (bFrameStart == OMX_FALSE) { 145 /* find VOP start code */ 146 while(startCode != 0x1B6) { 147 readStream = *(pInputStream + len); 148 startCode = (startCode << 8) | readStream; 149 len++; 150 if (len > buffSize) 151 goto EXIT; 152 } 153 } 154 155 /* find next VOP start code */ 156 startCode = 0xFFFFFFFF; 157 while ((startCode != 0x1B6)) { 158 readStream = *(pInputStream + len); 159 startCode = (startCode << 8) | readStream; 160 len++; 161 if (len > buffSize) 162 goto EXIT; 163 } 164 165 *pbEndOfFrame = OMX_TRUE; 166 167 SEC_OSAL_Log(SEC_LOG_TRACE, "1. Check_Mpeg4_Frame returned EOF = %d, len = %d, buffSize = %d", *pbEndOfFrame, len - 4, buffSize); 168 169 return len - 4; 170 171 EXIT : 172 *pbEndOfFrame = OMX_FALSE; 173 174 SEC_OSAL_Log(SEC_LOG_TRACE, "2. Check_Mpeg4_Frame returned EOF = %d, len = %d, buffSize = %d", *pbEndOfFrame, len - 1, buffSize); 175 176 return --len; 177 } 178 179 static int Check_H263_Frame(OMX_U8 *pInputStream, OMX_U32 buffSize, OMX_U32 flag, OMX_BOOL bPreviousFrameEOF, OMX_BOOL *pbEndOfFrame) 180 { 181 int len, readStream; 182 unsigned startCode; 183 OMX_BOOL bFrameStart = 0; 184 185 len = 0; 186 bFrameStart = OMX_FALSE; 187 188 if (bPreviousFrameEOF == OMX_FALSE) 189 bFrameStart = OMX_TRUE; 190 191 startCode = 0xFFFFFFFF; 192 if (bFrameStart == OMX_FALSE) { 193 /* find PSC(Picture Start Code) : 0000 0000 0000 0000 1000 00 */ 194 while (((startCode << 8 >> 10) != 0x20)) { 195 readStream = *(pInputStream + len); 196 startCode = (startCode << 8) | readStream; 197 len++; 198 if (len > buffSize) 199 goto EXIT; 200 } 201 } 202 203 /* find next PSC */ 204 startCode = 0xFFFFFFFF; 205 while (((startCode << 8 >> 10) != 0x20)) { 206 readStream = *(pInputStream + len); 207 startCode = (startCode << 8) | readStream; 208 len++; 209 if (len > buffSize) 210 goto EXIT; 211 } 212 213 *pbEndOfFrame = OMX_TRUE; 214 215 SEC_OSAL_Log(SEC_LOG_TRACE, "1. Check_H263_Frame returned EOF = %d, len = %d, iBuffSize = %d", *pbEndOfFrame, len - 3, buffSize); 216 217 return len - 3; 218 219 EXIT : 220 221 *pbEndOfFrame = OMX_FALSE; 222 223 SEC_OSAL_Log(SEC_LOG_TRACE, "2. Check_H263_Frame returned EOF = %d, len = %d, iBuffSize = %d", *pbEndOfFrame, len - 1, buffSize); 224 225 return --len; 226 } 227 228 OMX_BOOL Check_Stream_PrefixCode(OMX_U8 *pInputStream, OMX_U32 streamSize, CODEC_TYPE codecType) 229 { 230 switch (codecType) { 231 case CODEC_TYPE_MPEG4: 232 if (gbFIMV1) { 233 return OMX_TRUE; 234 } else { 235 if (streamSize < 3) { 236 return OMX_FALSE; 237 } else if ((pInputStream[0] == 0x00) && 238 (pInputStream[1] == 0x00) && 239 (pInputStream[2] == 0x01)) { 240 return OMX_TRUE; 241 } else { 242 return OMX_FALSE; 243 } 244 } 245 break; 246 case CODEC_TYPE_H263: 247 if (streamSize > 0) 248 return OMX_TRUE; 249 else 250 return OMX_FALSE; 251 default: 252 SEC_OSAL_Log(SEC_LOG_WARNING, "%s: undefined codec type (%d)", __FUNCTION__, codecType); 253 return OMX_FALSE; 254 } 255 } 256 257 OMX_ERRORTYPE SEC_MFC_Mpeg4Dec_GetParameter( 258 OMX_IN OMX_HANDLETYPE hComponent, 259 OMX_IN OMX_INDEXTYPE nParamIndex, 260 OMX_INOUT OMX_PTR pComponentParameterStructure) 261 { 262 OMX_ERRORTYPE ret = OMX_ErrorNone; 263 OMX_COMPONENTTYPE *pOMXComponent = NULL; 264 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 265 266 FunctionIn(); 267 268 if (hComponent == NULL || pComponentParameterStructure == NULL) { 269 ret = OMX_ErrorBadParameter; 270 goto EXIT; 271 } 272 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 273 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 274 if (ret != OMX_ErrorNone) { 275 goto EXIT; 276 } 277 if (pOMXComponent->pComponentPrivate == NULL) { 278 ret = OMX_ErrorBadParameter; 279 goto EXIT; 280 } 281 282 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 283 if (pSECComponent->currentState == OMX_StateInvalid ) { 284 ret = OMX_StateInvalid; 285 goto EXIT; 286 } 287 288 switch (nParamIndex) { 289 case OMX_IndexParamVideoMpeg4: 290 { 291 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pComponentParameterStructure; 292 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = NULL; 293 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 294 ret = SEC_OMX_Check_SizeVersion(pDstMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 295 if (ret != OMX_ErrorNone) { 296 goto EXIT; 297 } 298 299 if (pDstMpeg4Param->nPortIndex >= ALL_PORT_NUM) { 300 ret = OMX_ErrorBadPortIndex; 301 goto EXIT; 302 } 303 304 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 305 pSrcMpeg4Param = &pMpeg4Dec->mpeg4Component[pDstMpeg4Param->nPortIndex]; 306 307 SEC_OSAL_Memcpy(pDstMpeg4Param, pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 308 } 309 break; 310 case OMX_IndexParamVideoH263: 311 { 312 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = (OMX_VIDEO_PARAM_H263TYPE *)pComponentParameterStructure; 313 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = NULL; 314 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 315 ret = SEC_OMX_Check_SizeVersion(pDstH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 316 if (ret != OMX_ErrorNone) { 317 goto EXIT; 318 } 319 320 if (pDstH263Param->nPortIndex >= ALL_PORT_NUM) { 321 ret = OMX_ErrorBadPortIndex; 322 goto EXIT; 323 } 324 325 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 326 pSrcH263Param = &pMpeg4Dec->h263Component[pDstH263Param->nPortIndex]; 327 328 SEC_OSAL_Memcpy(pDstH263Param, pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 329 } 330 break; 331 case OMX_IndexParamStandardComponentRole: 332 { 333 OMX_S32 codecType; 334 OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE *)pComponentParameterStructure; 335 336 ret = SEC_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 337 if (ret != OMX_ErrorNone) { 338 goto EXIT; 339 } 340 341 codecType = ((SEC_MPEG4_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 342 if (codecType == CODEC_TYPE_MPEG4) 343 SEC_OSAL_Strcpy((char *)pComponentRole->cRole, SEC_OMX_COMPOMENT_MPEG4_DEC_ROLE); 344 else 345 SEC_OSAL_Strcpy((char *)pComponentRole->cRole, SEC_OMX_COMPOMENT_H263_DEC_ROLE); 346 } 347 break; 348 case OMX_IndexParamVideoProfileLevelQuerySupported: 349 { 350 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 351 SEC_OMX_VIDEO_PROFILELEVEL *pProfileLevel = NULL; 352 OMX_U32 maxProfileLevelNum = 0; 353 OMX_S32 codecType; 354 355 ret = SEC_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 356 if (ret != OMX_ErrorNone) { 357 goto EXIT; 358 } 359 360 if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { 361 ret = OMX_ErrorBadPortIndex; 362 goto EXIT; 363 } 364 365 codecType = ((SEC_MPEG4_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 366 if (codecType == CODEC_TYPE_MPEG4) { 367 pProfileLevel = supportedMPEG4ProfileLevels; 368 maxProfileLevelNum = sizeof(supportedMPEG4ProfileLevels) / sizeof(SEC_OMX_VIDEO_PROFILELEVEL); 369 } else { 370 pProfileLevel = supportedH263ProfileLevels; 371 maxProfileLevelNum = sizeof(supportedH263ProfileLevels) / sizeof(SEC_OMX_VIDEO_PROFILELEVEL); 372 } 373 374 if (pDstProfileLevel->nProfileIndex >= maxProfileLevelNum) { 375 ret = OMX_ErrorNoMore; 376 goto EXIT; 377 } 378 379 pProfileLevel += pDstProfileLevel->nProfileIndex; 380 pDstProfileLevel->eProfile = pProfileLevel->profile; 381 pDstProfileLevel->eLevel = pProfileLevel->level; 382 } 383 break; 384 case OMX_IndexParamVideoProfileLevelCurrent: 385 { 386 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pDstProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 387 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = NULL; 388 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = NULL; 389 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 390 OMX_S32 codecType; 391 392 ret = SEC_OMX_Check_SizeVersion(pDstProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 393 if (ret != OMX_ErrorNone) { 394 goto EXIT; 395 } 396 397 if (pDstProfileLevel->nPortIndex >= ALL_PORT_NUM) { 398 ret = OMX_ErrorBadPortIndex; 399 goto EXIT; 400 } 401 402 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 403 codecType = pMpeg4Dec->hMFCMpeg4Handle.codecType; 404 if (codecType == CODEC_TYPE_MPEG4) { 405 pSrcMpeg4Param = &pMpeg4Dec->mpeg4Component[pDstProfileLevel->nPortIndex]; 406 pDstProfileLevel->eProfile = pSrcMpeg4Param->eProfile; 407 pDstProfileLevel->eLevel = pSrcMpeg4Param->eLevel; 408 } else { 409 pSrcH263Param = &pMpeg4Dec->h263Component[pDstProfileLevel->nPortIndex]; 410 pDstProfileLevel->eProfile = pSrcH263Param->eProfile; 411 pDstProfileLevel->eLevel = pSrcH263Param->eLevel; 412 } 413 } 414 break; 415 case OMX_IndexParamVideoErrorCorrection: 416 { 417 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; 418 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = NULL; 419 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 420 421 ret = SEC_OMX_Check_SizeVersion(pDstErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); 422 if (ret != OMX_ErrorNone) { 423 goto EXIT; 424 } 425 426 if (pDstErrorCorrectionType->nPortIndex != INPUT_PORT_INDEX) { 427 ret = OMX_ErrorBadPortIndex; 428 goto EXIT; 429 } 430 431 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 432 pSrcErrorCorrectionType = &pMpeg4Dec->errorCorrectionType[INPUT_PORT_INDEX]; 433 434 pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; 435 pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; 436 pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; 437 pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; 438 pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; 439 } 440 break; 441 default: 442 ret = SEC_OMX_VideoDecodeGetParameter(hComponent, nParamIndex, pComponentParameterStructure); 443 break; 444 } 445 EXIT: 446 FunctionOut(); 447 448 return ret; 449 } 450 451 OMX_ERRORTYPE SEC_MFC_Mpeg4Dec_SetParameter( 452 OMX_IN OMX_HANDLETYPE hComponent, 453 OMX_IN OMX_INDEXTYPE nIndex, 454 OMX_IN OMX_PTR pComponentParameterStructure) 455 { 456 OMX_ERRORTYPE ret = OMX_ErrorNone; 457 OMX_COMPONENTTYPE *pOMXComponent = NULL; 458 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 459 460 FunctionIn(); 461 462 if (hComponent == NULL || pComponentParameterStructure == NULL) { 463 ret = OMX_ErrorBadParameter; 464 goto EXIT; 465 } 466 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 467 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 468 if (ret != OMX_ErrorNone) { 469 goto EXIT; 470 } 471 if (pOMXComponent->pComponentPrivate == NULL) { 472 ret = OMX_ErrorBadParameter; 473 goto EXIT; 474 } 475 476 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 477 if (pSECComponent->currentState == OMX_StateInvalid ) { 478 ret = OMX_StateInvalid; 479 goto EXIT; 480 } 481 482 switch (nIndex) { 483 case OMX_IndexParamVideoMpeg4: 484 { 485 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = NULL; 486 OMX_VIDEO_PARAM_MPEG4TYPE *pSrcMpeg4Param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pComponentParameterStructure; 487 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 488 489 ret = SEC_OMX_Check_SizeVersion(pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 490 if (ret != OMX_ErrorNone) { 491 goto EXIT; 492 } 493 494 if (pSrcMpeg4Param->nPortIndex >= ALL_PORT_NUM) { 495 ret = OMX_ErrorBadPortIndex; 496 goto EXIT; 497 } 498 499 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 500 pDstMpeg4Param = &pMpeg4Dec->mpeg4Component[pSrcMpeg4Param->nPortIndex]; 501 502 SEC_OSAL_Memcpy(pDstMpeg4Param, pSrcMpeg4Param, sizeof(OMX_VIDEO_PARAM_MPEG4TYPE)); 503 } 504 break; 505 case OMX_IndexParamVideoH263: 506 { 507 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = NULL; 508 OMX_VIDEO_PARAM_H263TYPE *pSrcH263Param = (OMX_VIDEO_PARAM_H263TYPE *)pComponentParameterStructure; 509 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 510 511 ret = SEC_OMX_Check_SizeVersion(pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 512 if (ret != OMX_ErrorNone) { 513 goto EXIT; 514 } 515 516 if (pSrcH263Param->nPortIndex >= ALL_PORT_NUM) { 517 ret = OMX_ErrorBadPortIndex; 518 goto EXIT; 519 } 520 521 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 522 pDstH263Param = &pMpeg4Dec->h263Component[pSrcH263Param->nPortIndex]; 523 524 SEC_OSAL_Memcpy(pDstH263Param, pSrcH263Param, sizeof(OMX_VIDEO_PARAM_H263TYPE)); 525 } 526 break; 527 case OMX_IndexParamStandardComponentRole: 528 { 529 OMX_PARAM_COMPONENTROLETYPE *pComponentRole = (OMX_PARAM_COMPONENTROLETYPE*)pComponentParameterStructure; 530 531 ret = SEC_OMX_Check_SizeVersion(pComponentRole, sizeof(OMX_PARAM_COMPONENTROLETYPE)); 532 if (ret != OMX_ErrorNone) { 533 goto EXIT; 534 } 535 536 if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) { 537 ret = OMX_ErrorIncorrectStateOperation; 538 goto EXIT; 539 } 540 541 if (!SEC_OSAL_Strcmp((char*)pComponentRole->cRole, SEC_OMX_COMPOMENT_MPEG4_DEC_ROLE)) { 542 pSECComponent->pSECPort[INPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 543 //((SEC_MPEG4_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType = CODEC_TYPE_MPEG4; 544 } else if (!SEC_OSAL_Strcmp((char*)pComponentRole->cRole, SEC_OMX_COMPOMENT_H263_DEC_ROLE)) { 545 pSECComponent->pSECPort[INPUT_PORT_INDEX].portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 546 //((SEC_MPEG4_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType = CODEC_TYPE_H263; 547 } else { 548 ret = OMX_ErrorBadParameter; 549 goto EXIT; 550 } 551 } 552 break; 553 case OMX_IndexParamPortDefinition: 554 { 555 OMX_PARAM_PORTDEFINITIONTYPE *pPortDefinition = (OMX_PARAM_PORTDEFINITIONTYPE *)pComponentParameterStructure; 556 OMX_U32 portIndex = pPortDefinition->nPortIndex; 557 SEC_OMX_BASEPORT *pSECPort; 558 OMX_U32 width, height, size; 559 560 if (portIndex >= pSECComponent->portParam.nPorts) { 561 ret = OMX_ErrorBadPortIndex; 562 goto EXIT; 563 } 564 ret = SEC_OMX_Check_SizeVersion(pPortDefinition, sizeof(OMX_PARAM_PORTDEFINITIONTYPE)); 565 if (ret != OMX_ErrorNone) { 566 goto EXIT; 567 } 568 569 pSECPort = &pSECComponent->pSECPort[portIndex]; 570 571 if ((pSECComponent->currentState != OMX_StateLoaded) && (pSECComponent->currentState != OMX_StateWaitForResources)) { 572 if (pSECPort->portDefinition.bEnabled == OMX_TRUE) { 573 ret = OMX_ErrorIncorrectStateOperation; 574 goto EXIT; 575 } 576 } 577 if (pPortDefinition->nBufferCountActual < pSECPort->portDefinition.nBufferCountMin) { 578 ret = OMX_ErrorBadParameter; 579 goto EXIT; 580 } 581 582 SEC_OSAL_Memcpy(&pSECPort->portDefinition, pPortDefinition, pPortDefinition->nSize); 583 584 width = ((pSECPort->portDefinition.format.video.nFrameWidth + 15) & (~15)); 585 height = ((pSECPort->portDefinition.format.video.nFrameHeight + 15) & (~15)); 586 size = (width * height * 3) / 2; 587 pSECPort->portDefinition.format.video.nStride = width; 588 pSECPort->portDefinition.format.video.nSliceHeight = height; 589 pSECPort->portDefinition.nBufferSize = (size > pSECPort->portDefinition.nBufferSize) ? size : pSECPort->portDefinition.nBufferSize; 590 591 if (portIndex == INPUT_PORT_INDEX) { 592 SEC_OMX_BASEPORT *pSECOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 593 pSECOutputPort->portDefinition.format.video.nFrameWidth = pSECPort->portDefinition.format.video.nFrameWidth; 594 pSECOutputPort->portDefinition.format.video.nFrameHeight = pSECPort->portDefinition.format.video.nFrameHeight; 595 pSECOutputPort->portDefinition.format.video.nStride = width; 596 pSECOutputPort->portDefinition.format.video.nSliceHeight = height; 597 if (pSECOutputPort->portDefinition.format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) { 598 pSECOutputPort->portDefinition.nBufferSize = (width * height * 3) / 2; 599 } else if (pSECOutputPort->portDefinition.format.video.eColorFormat == OMX_COLOR_FormatYUV422Planar) { 600 pSECOutputPort->portDefinition.nBufferSize = width * height * 2; 601 } 602 } 603 } 604 break; 605 case OMX_IndexParamVideoProfileLevelCurrent: 606 { 607 OMX_VIDEO_PARAM_PROFILELEVELTYPE *pSrcProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pComponentParameterStructure; 608 OMX_VIDEO_PARAM_MPEG4TYPE *pDstMpeg4Param = NULL; 609 OMX_VIDEO_PARAM_H263TYPE *pDstH263Param = NULL; 610 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 611 OMX_S32 codecType; 612 613 ret = SEC_OMX_Check_SizeVersion(pSrcProfileLevel, sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE)); 614 if (ret != OMX_ErrorNone) { 615 goto EXIT; 616 } 617 618 if (pSrcProfileLevel->nPortIndex >= ALL_PORT_NUM) { 619 ret = OMX_ErrorBadPortIndex; 620 goto EXIT; 621 } 622 623 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 624 codecType = pMpeg4Dec->hMFCMpeg4Handle.codecType; 625 if (codecType == CODEC_TYPE_MPEG4) { 626 /* 627 * To do: Check validity of profile & level parameters 628 */ 629 630 pDstMpeg4Param = &pMpeg4Dec->mpeg4Component[pSrcProfileLevel->nPortIndex]; 631 pDstMpeg4Param->eProfile = pSrcProfileLevel->eProfile; 632 pDstMpeg4Param->eLevel = pSrcProfileLevel->eLevel; 633 } else { 634 /* 635 * To do: Check validity of profile & level parameters 636 */ 637 638 pDstH263Param = &pMpeg4Dec->h263Component[pSrcProfileLevel->nPortIndex]; 639 pDstH263Param->eProfile = pSrcProfileLevel->eProfile; 640 pDstH263Param->eLevel = pSrcProfileLevel->eLevel; 641 } 642 } 643 break; 644 case OMX_IndexParamVideoErrorCorrection: 645 { 646 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pSrcErrorCorrectionType = (OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *)pComponentParameterStructure; 647 OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE *pDstErrorCorrectionType = NULL; 648 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 649 650 ret = SEC_OMX_Check_SizeVersion(pSrcErrorCorrectionType, sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE)); 651 if (ret != OMX_ErrorNone) { 652 goto EXIT; 653 } 654 655 if (pSrcErrorCorrectionType->nPortIndex != INPUT_PORT_INDEX) { 656 ret = OMX_ErrorBadPortIndex; 657 goto EXIT; 658 } 659 660 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 661 pDstErrorCorrectionType = &pMpeg4Dec->errorCorrectionType[INPUT_PORT_INDEX]; 662 663 pDstErrorCorrectionType->bEnableHEC = pSrcErrorCorrectionType->bEnableHEC; 664 pDstErrorCorrectionType->bEnableResync = pSrcErrorCorrectionType->bEnableResync; 665 pDstErrorCorrectionType->nResynchMarkerSpacing = pSrcErrorCorrectionType->nResynchMarkerSpacing; 666 pDstErrorCorrectionType->bEnableDataPartitioning = pSrcErrorCorrectionType->bEnableDataPartitioning; 667 pDstErrorCorrectionType->bEnableRVLC = pSrcErrorCorrectionType->bEnableRVLC; 668 } 669 break; 670 default: 671 ret = SEC_OMX_VideoDecodeSetParameter(hComponent, nIndex, pComponentParameterStructure); 672 break; 673 } 674 EXIT: 675 FunctionOut(); 676 677 return ret; 678 } 679 680 OMX_ERRORTYPE SEC_MFC_Mpeg4Dec_SetConfig( 681 OMX_IN OMX_HANDLETYPE hComponent, 682 OMX_IN OMX_INDEXTYPE nIndex, 683 OMX_IN OMX_PTR pComponentConfigStructure) 684 { 685 OMX_ERRORTYPE ret = OMX_ErrorNone; 686 OMX_COMPONENTTYPE *pOMXComponent = NULL; 687 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 688 689 FunctionIn(); 690 691 if (hComponent == NULL || pComponentConfigStructure == NULL) { 692 ret = OMX_ErrorBadParameter; 693 goto EXIT; 694 } 695 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 696 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 697 if (ret != OMX_ErrorNone) { 698 goto EXIT; 699 } 700 if (pOMXComponent->pComponentPrivate == NULL) { 701 ret = OMX_ErrorBadParameter; 702 goto EXIT; 703 } 704 705 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 706 if (pSECComponent->currentState == OMX_StateInvalid) { 707 ret = OMX_ErrorInvalidState; 708 goto EXIT; 709 } 710 711 switch (nIndex) { 712 case OMX_IndexVendorThumbnailMode: 713 { 714 SEC_MPEG4_HANDLE *pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 715 716 pMpeg4Dec->hMFCMpeg4Handle.bThumbnailMode = *((OMX_BOOL *)pComponentConfigStructure); 717 } 718 break; 719 default: 720 ret = SEC_OMX_SetConfig(hComponent, nIndex, pComponentConfigStructure); 721 break; 722 } 723 724 EXIT: 725 FunctionOut(); 726 727 return ret; 728 } 729 730 OMX_ERRORTYPE SEC_MFC_Mpeg4Dec_GetExtensionIndex( 731 OMX_IN OMX_HANDLETYPE hComponent, 732 OMX_IN OMX_STRING cParameterName, 733 OMX_OUT OMX_INDEXTYPE *pIndexType) 734 { 735 OMX_ERRORTYPE ret = OMX_ErrorNone; 736 OMX_COMPONENTTYPE *pOMXComponent = NULL; 737 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 738 739 FunctionIn(); 740 741 if (hComponent == NULL) { 742 ret = OMX_ErrorBadParameter; 743 goto EXIT; 744 } 745 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 746 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 747 if (ret != OMX_ErrorNone) { 748 goto EXIT; 749 } 750 751 if (pOMXComponent->pComponentPrivate == NULL) { 752 ret = OMX_ErrorBadParameter; 753 goto EXIT; 754 } 755 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 756 757 if ((cParameterName == NULL) || (pIndexType == NULL)) { 758 ret = OMX_ErrorBadParameter; 759 goto EXIT; 760 } 761 if (pSECComponent->currentState == OMX_StateInvalid) { 762 ret = OMX_ErrorInvalidState; 763 goto EXIT; 764 } 765 766 if (SEC_OSAL_Strcmp(cParameterName, "OMX.SEC.index.ThumbnailMode") == 0) { 767 SEC_MPEG4_HANDLE *pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 768 769 *pIndexType = OMX_IndexVendorThumbnailMode; 770 771 ret = OMX_ErrorNone; 772 } else { 773 ret = SEC_OMX_GetExtensionIndex(hComponent, cParameterName, pIndexType); 774 } 775 776 EXIT: 777 FunctionOut(); 778 779 return ret; 780 } 781 782 OMX_ERRORTYPE SEC_MFC_Mpeg4Dec_ComponentRoleEnum( 783 OMX_IN OMX_HANDLETYPE hComponent, 784 OMX_OUT OMX_U8 *cRole, 785 OMX_IN OMX_U32 nIndex) 786 { 787 OMX_ERRORTYPE ret = OMX_ErrorNone; 788 OMX_COMPONENTTYPE *pOMXComponent = NULL; 789 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 790 OMX_S32 codecType; 791 792 FunctionIn(); 793 794 if ((hComponent == NULL) || (cRole == NULL)) { 795 ret = OMX_ErrorBadParameter; 796 goto EXIT; 797 } 798 if (nIndex != (MAX_COMPONENT_ROLE_NUM - 1)) { 799 ret = OMX_ErrorNoMore; 800 goto EXIT; 801 } 802 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 803 ret = SEC_OMX_Check_SizeVersion(pOMXComponent, sizeof(OMX_COMPONENTTYPE)); 804 if (ret != OMX_ErrorNone) { 805 goto EXIT; 806 } 807 if (pOMXComponent->pComponentPrivate == NULL) { 808 ret = OMX_ErrorBadParameter; 809 goto EXIT; 810 } 811 812 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 813 if (pSECComponent->currentState == OMX_StateInvalid ) { 814 ret = OMX_StateInvalid; 815 goto EXIT; 816 } 817 818 codecType = ((SEC_MPEG4_HANDLE *)(pSECComponent->hCodecHandle))->hMFCMpeg4Handle.codecType; 819 if (codecType == CODEC_TYPE_MPEG4) 820 SEC_OSAL_Strcpy((char *)cRole, SEC_OMX_COMPOMENT_MPEG4_DEC_ROLE); 821 else 822 SEC_OSAL_Strcpy((char *)cRole, SEC_OMX_COMPOMENT_H263_DEC_ROLE); 823 824 EXIT: 825 FunctionOut(); 826 827 return ret; 828 } 829 830 /* MFC Init */ 831 OMX_ERRORTYPE SEC_MFC_Mpeg4Dec_Init(OMX_COMPONENTTYPE *pOMXComponent) 832 { 833 OMX_ERRORTYPE ret = OMX_ErrorNone; 834 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 835 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 836 OMX_HANDLETYPE hMFCHandle = NULL; 837 OMX_PTR pStreamBuffer = NULL; 838 OMX_PTR pStreamPhyBuffer = NULL; 839 840 FunctionIn(); 841 842 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 843 pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFC = OMX_FALSE; 844 pSECComponent->bUseFlagEOF = OMX_FALSE; 845 pSECComponent->bSaveFlagEOS = OMX_FALSE; 846 847 /* MFC(Multi Format Codec) decoder and CMM(Codec Memory Management) driver open */ 848 hMFCHandle = SsbSipMfcDecOpen(); 849 if (hMFCHandle == NULL) { 850 ret = OMX_ErrorInsufficientResources; 851 goto EXIT; 852 } 853 ghMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle = hMFCHandle; 854 855 /* Allocate decoder's input buffer */ 856 pStreamBuffer = SsbSipMfcDecGetInBuf(hMFCHandle, &pStreamPhyBuffer, DEFAULT_MFC_INPUT_BUFFER_SIZE); 857 if (pStreamBuffer == NULL) { 858 ret = OMX_ErrorInsufficientResources; 859 goto EXIT; 860 } 861 pMpeg4Dec->hMFCMpeg4Handle.pMFCStreamBuffer = pStreamBuffer; 862 pMpeg4Dec->hMFCMpeg4Handle.pMFCStreamPhyBuffer = pStreamPhyBuffer; 863 pSECComponent->processData[INPUT_PORT_INDEX].dataBuffer = pStreamBuffer; 864 pSECComponent->processData[INPUT_PORT_INDEX].allocSize = DEFAULT_MFC_INPUT_BUFFER_SIZE; 865 866 SEC_OSAL_Memset(pSECComponent->timeStamp, -19771003, sizeof(OMX_TICKS) * MAX_TIMESTAMP); 867 SEC_OSAL_Memset(pSECComponent->nFlags, 0, sizeof(OMX_U32) * MAX_FLAGS); 868 pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp = 0; 869 pSECComponent->getAllDelayBuffer = OMX_FALSE; 870 871 EXIT: 872 FunctionOut(); 873 874 return ret; 875 } 876 877 /* MFC Terminate */ 878 OMX_ERRORTYPE SEC_MFC_Mpeg4Dec_Terminate(OMX_COMPONENTTYPE *pOMXComponent) 879 { 880 OMX_ERRORTYPE ret = OMX_ErrorNone; 881 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 882 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 883 OMX_HANDLETYPE hMFCHandle = NULL; 884 885 FunctionIn(); 886 887 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 888 hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle; 889 890 pMpeg4Dec->hMFCMpeg4Handle.pMFCStreamBuffer = NULL; 891 pMpeg4Dec->hMFCMpeg4Handle.pMFCStreamPhyBuffer = NULL; 892 pSECComponent->processData[INPUT_PORT_INDEX].dataBuffer = NULL; 893 pSECComponent->processData[INPUT_PORT_INDEX].allocSize = 0; 894 895 if (hMFCHandle != NULL) { 896 SsbSipMfcDecClose(hMFCHandle); 897 pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle = NULL; 898 } 899 900 EXIT: 901 FunctionOut(); 902 903 return ret; 904 } 905 906 OMX_ERRORTYPE SEC_MFC_Mpeg4_Decode(OMX_COMPONENTTYPE *pOMXComponent, SEC_OMX_DATA *pInputData, SEC_OMX_DATA *pOutputData) 907 { 908 OMX_ERRORTYPE ret = OMX_ErrorNone; 909 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 910 SEC_MPEG4_HANDLE *pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 911 OMX_HANDLETYPE hMFCHandle = pMpeg4Dec->hMFCMpeg4Handle.hMFCHandle; 912 OMX_U32 oneFrameSize = pInputData->dataLen; 913 SSBSIP_MFC_DEC_OUTPUT_INFO outputInfo; 914 OMX_S32 configValue; 915 OMX_S32 returnCodec; 916 int bufWidth; 917 int bufHeight; 918 919 FunctionIn(); 920 921 if (pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFC == OMX_FALSE) { 922 SSBSIP_MFC_CODEC_TYPE MFCCodecType; 923 if (pMpeg4Dec->hMFCMpeg4Handle.codecType == CODEC_TYPE_MPEG4) { 924 if (gbFIMV1) 925 MFCCodecType = FIMV1_DEC; 926 else 927 MFCCodecType = MPEG4_DEC; 928 } else { 929 MFCCodecType = H263_DEC; 930 } 931 932 if ((oneFrameSize <= 0) && (pInputData->nFlags & OMX_BUFFERFLAG_EOS)) { 933 pOutputData->timeStamp = pInputData->timeStamp; 934 pOutputData->nFlags = pInputData->nFlags; 935 ret = OMX_ErrorNone; 936 goto EXIT; 937 } 938 939 /* Set the number of extra buffer to prevent tearing */ 940 configValue = 5; 941 SsbSipMfcDecSetConfig(hMFCHandle, MFC_DEC_SETCONF_EXTRA_BUFFER_NUM, &configValue); 942 943 /* Set mpeg4 deblocking filter enable */ 944 configValue = 1; 945 SsbSipMfcDecSetConfig(hMFCHandle, MFC_DEC_SETCONF_POST_ENABLE, &configValue); 946 947 if (pMpeg4Dec->hMFCMpeg4Handle.bThumbnailMode == OMX_TRUE) { 948 configValue = 0; // the number that you want to delay 949 SsbSipMfcDecSetConfig(hMFCHandle, MFC_DEC_SETCONF_DISPLAY_DELAY, &configValue); 950 } 951 952 returnCodec = SsbSipMfcDecInit(hMFCHandle, MFCCodecType, oneFrameSize); 953 if (returnCodec == MFC_RET_OK) { 954 SSBSIP_MFC_IMG_RESOLUTION imgResol; 955 SEC_OMX_BASEPORT *pInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 956 957 if (SsbSipMfcDecGetConfig(hMFCHandle, MFC_DEC_GETCONF_BUF_WIDTH_HEIGHT, &imgResol) != MFC_RET_OK) { 958 ret = OMX_ErrorMFCInit; 959 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcDecGetConfig failed", __FUNCTION__); 960 goto EXIT; 961 } 962 963 /** Update Frame Size **/ 964 if ((pInputPort->portDefinition.format.video.nFrameWidth != imgResol.width) || 965 (pInputPort->portDefinition.format.video.nFrameHeight != imgResol.height)) { 966 /* change width and height information */ 967 pInputPort->portDefinition.format.video.nFrameWidth = imgResol.width; 968 pInputPort->portDefinition.format.video.nFrameHeight = imgResol.height; 969 pInputPort->portDefinition.format.video.nStride = ((imgResol.width + 15) & (~15)); 970 pInputPort->portDefinition.format.video.nSliceHeight = ((imgResol.height + 15) & (~15)); 971 972 SEC_UpdateFrameSize(pOMXComponent); 973 974 /* Send Port Settings changed call back */ 975 (*(pSECComponent->pCallbacks->EventHandler)) 976 (pOMXComponent, 977 pSECComponent->callbackData, 978 OMX_EventPortSettingsChanged, // The command was completed 979 OMX_DirOutput, // This is the port index 980 0, 981 NULL); 982 } 983 984 SEC_OSAL_Log(SEC_LOG_TRACE, "nFrameWidth(%d) nFrameHeight(%d), nStride(%d), nSliceHeight(%d)", 985 pInputPort->portDefinition.format.video.nFrameWidth, pInputPort->portDefinition.format.video.nFrameHeight, 986 pInputPort->portDefinition.format.video.nStride, pInputPort->portDefinition.format.video.nSliceHeight); 987 988 pMpeg4Dec->hMFCMpeg4Handle.bConfiguredMFC = OMX_TRUE; 989 if (pMpeg4Dec->hMFCMpeg4Handle.codecType == CODEC_TYPE_MPEG4) { 990 pOutputData->timeStamp = pInputData->timeStamp; 991 pOutputData->nFlags = pInputData->nFlags; 992 ret = OMX_ErrorNone; 993 } else { 994 pOutputData->dataLen = 0; 995 ret = OMX_ErrorInputDataDecodeYet; 996 } 997 goto EXIT; 998 } else { 999 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SsbSipMfcDecInit failed", __FUNCTION__); 1000 ret = OMX_ErrorMFCInit; /* OMX_ErrorUndefined */ 1001 goto EXIT; 1002 } 1003 } 1004 1005 #ifndef FULL_FRAME_SEARCH 1006 if ((pInputData->nFlags & OMX_BUFFERFLAG_ENDOFFRAME) && 1007 (pSECComponent->bUseFlagEOF == OMX_FALSE)) { 1008 pSECComponent->bUseFlagEOF = OMX_TRUE; 1009 } 1010 #endif 1011 1012 pSECComponent->timeStamp[pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp] = pInputData->timeStamp; 1013 pSECComponent->nFlags[pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp] = pInputData->nFlags; 1014 SsbSipMfcDecSetConfig(hMFCHandle, MFC_DEC_SETCONF_FRAME_TAG, &(pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp)); 1015 pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp++; 1016 if (pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp >= MAX_TIMESTAMP) 1017 pMpeg4Dec->hMFCMpeg4Handle.indexTimestamp = 0; 1018 1019 if (Check_Stream_PrefixCode(pInputData->dataBuffer, pInputData->dataLen, pMpeg4Dec->hMFCMpeg4Handle.codecType) == OMX_TRUE) { 1020 returnCodec = SsbSipMfcDecExe(hMFCHandle, oneFrameSize); 1021 } else { 1022 pOutputData->timeStamp = pInputData->timeStamp; 1023 pOutputData->nFlags = pInputData->nFlags; 1024 returnCodec = MFC_RET_OK; 1025 goto EXIT; 1026 } 1027 1028 if (returnCodec == MFC_RET_OK) { 1029 SSBSIP_MFC_DEC_OUTBUF_STATUS status; 1030 OMX_S32 indexTimestamp = 0; 1031 1032 status = SsbSipMfcDecGetOutBuf(hMFCHandle, &outputInfo); 1033 bufWidth = (outputInfo.img_width + 15) & (~15); 1034 bufHeight = (outputInfo.img_height + 15) & (~15); 1035 1036 if ((SsbSipMfcDecGetConfig(hMFCHandle, MFC_DEC_GETCONF_FRAME_TAG, &indexTimestamp) != MFC_RET_OK) || 1037 (((indexTimestamp < 0) || (indexTimestamp > MAX_TIMESTAMP)))) { 1038 pOutputData->timeStamp = pInputData->timeStamp; 1039 pOutputData->nFlags = pInputData->nFlags; 1040 } else { 1041 pOutputData->timeStamp = pSECComponent->timeStamp[indexTimestamp]; 1042 pOutputData->nFlags = pSECComponent->nFlags[indexTimestamp]; 1043 } 1044 1045 if ((status == MFC_GETOUTBUF_DISPLAY_DECODING) || 1046 (status == MFC_GETOUTBUF_DISPLAY_ONLY)) { 1047 switch(pSECComponent->pSECPort[OUTPUT_PORT_INDEX].portDefinition.format.video.eColorFormat) { 1048 case OMX_COLOR_FormatYUV420Planar: 1049 case OMX_COLOR_FormatYUV420SemiPlanar: 1050 pOutputData->dataLen = (bufWidth * bufHeight * 3) /2; 1051 break; 1052 default: 1053 pOutputData->dataLen = bufWidth * bufHeight * 2; 1054 break; 1055 } 1056 } 1057 if (pOutputData->nFlags & OMX_BUFFERFLAG_EOS) 1058 pOutputData->dataLen = 0; 1059 1060 if ((status == MFC_GETOUTBUF_DISPLAY_ONLY) || 1061 (pSECComponent->getAllDelayBuffer == OMX_TRUE)) { 1062 ret = OMX_ErrorInputDataDecodeYet; 1063 } 1064 1065 if (status == MFC_GETOUTBUF_DECODING_ONLY) { 1066 /* ret = OMX_ErrorInputDataDecodeYet; */ 1067 ret = OMX_ErrorNone; 1068 goto EXIT; 1069 } 1070 1071 #ifdef FULL_FRAME_SEARCH 1072 if (((pInputData->nFlags & OMX_BUFFERFLAG_EOS) != OMX_BUFFERFLAG_EOS) && 1073 (pSECComponent->bSaveFlagEOS == OMX_TRUE)) { 1074 pInputData->nFlags |= OMX_BUFFERFLAG_EOS; 1075 pSECComponent->getAllDelayBuffer = OMX_TRUE; 1076 ret = OMX_ErrorInputDataDecodeYet; 1077 } else 1078 #endif 1079 1080 if ((pInputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { 1081 pInputData->nFlags = (pOutputData->nFlags & (~OMX_BUFFERFLAG_EOS)); 1082 pSECComponent->getAllDelayBuffer = OMX_TRUE; 1083 ret = OMX_ErrorInputDataDecodeYet; 1084 } else if ((pOutputData->nFlags & OMX_BUFFERFLAG_EOS) == OMX_BUFFERFLAG_EOS) { 1085 pSECComponent->getAllDelayBuffer = OMX_FALSE; 1086 ret = OMX_ErrorNone; 1087 } 1088 } else { 1089 pOutputData->timeStamp = pInputData->timeStamp; 1090 pOutputData->nFlags = pInputData->nFlags; 1091 switch(pSECComponent->pSECPort[OUTPUT_PORT_INDEX].portDefinition.format.video.eColorFormat) { 1092 case OMX_COLOR_FormatYUV420Planar: 1093 case OMX_COLOR_FormatYUV420SemiPlanar: 1094 pOutputData->dataLen = (bufWidth * bufHeight * 3) / 2; 1095 break; 1096 default: 1097 pOutputData->dataLen = bufWidth * bufHeight * 2; 1098 break; 1099 } 1100 1101 if ((pSECComponent->bSaveFlagEOS == OMX_TRUE) || 1102 (pSECComponent->getAllDelayBuffer == OMX_TRUE) || 1103 (pInputData->nFlags & OMX_BUFFERFLAG_EOS)) { 1104 pOutputData->nFlags |= OMX_BUFFERFLAG_EOS; 1105 pSECComponent->getAllDelayBuffer = OMX_FALSE; 1106 pOutputData->dataLen = 0; 1107 } 1108 1109 /* ret = OMX_ErrorUndefined; */ /* ????? */ 1110 ret = OMX_ErrorNone; 1111 goto EXIT; 1112 } 1113 1114 /** Fill Output Buffer **/ 1115 if (pOutputData->dataLen > 0) 1116 { 1117 int frameSize = bufWidth * bufHeight; 1118 void *pOutputBuf = (void *)pOutputData->dataBuffer; 1119 1120 #ifdef USE_SAMSUNG_COLORFORMAT 1121 SEC_OMX_BASEPORT *pSECOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1122 1123 if ((pMpeg4Dec->hMFCMpeg4Handle.bThumbnailMode == OMX_FALSE) && 1124 (pSECOutputPort->portDefinition.format.video.eColorFormat == SEC_OMX_COLOR_FormatNV12PhysicalAddress)) 1125 1126 #else 1127 if (pMpeg4Dec->hMFCMpeg4Handle.bThumbnailMode == OMX_FALSE) 1128 #endif 1129 { 1130 /* if use Post copy address structure */ 1131 SEC_OSAL_Memcpy(pOutputBuf, &frameSize, sizeof(frameSize)); 1132 SEC_OSAL_Memcpy(pOutputBuf + sizeof(frameSize), &(outputInfo.YPhyAddr), sizeof(outputInfo.YPhyAddr)); 1133 SEC_OSAL_Memcpy(pOutputBuf + sizeof(frameSize) + (sizeof(void *) * 1), &(outputInfo.CPhyAddr), sizeof(outputInfo.CPhyAddr)); 1134 SEC_OSAL_Memcpy(pOutputBuf + sizeof(frameSize) + (sizeof(void *) * 2), &(outputInfo.YVirAddr), sizeof(outputInfo.YVirAddr)); 1135 SEC_OSAL_Memcpy(pOutputBuf + sizeof(frameSize) + (sizeof(void *) * 3), &(outputInfo.CVirAddr), sizeof(outputInfo.CVirAddr)); 1136 } else { 1137 SEC_OSAL_Log(SEC_LOG_TRACE, "YUV420 out for ThumbnailMode"); 1138 Y_tile_to_linear_4x2( 1139 (unsigned char *)pOutputBuf, 1140 (unsigned char *)outputInfo.YVirAddr, 1141 bufWidth, bufHeight); 1142 CbCr_tile_to_linear_4x2( 1143 ((unsigned char *)pOutputBuf) + frameSize, 1144 (unsigned char *)outputInfo.CVirAddr, 1145 bufWidth, bufHeight); 1146 } 1147 } 1148 1149 EXIT: 1150 FunctionOut(); 1151 1152 return ret; 1153 } 1154 1155 /* MFC Decode */ 1156 OMX_ERRORTYPE SEC_MFC_Mpeg4Dec_bufferProcess(OMX_COMPONENTTYPE *pOMXComponent, SEC_OMX_DATA *pInputData, SEC_OMX_DATA *pOutputData) 1157 { 1158 OMX_ERRORTYPE ret = OMX_ErrorNone; 1159 SEC_OMX_BASECOMPONENT *pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1160 SEC_MPEG4_HANDLE *pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 1161 SEC_OMX_BASEPORT *pInputPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1162 SEC_OMX_BASEPORT *pOutputPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1163 OMX_BOOL bCheckPrefix = OMX_FALSE; 1164 1165 FunctionIn(); 1166 1167 if ((!CHECK_PORT_ENABLED(pInputPort)) || (!CHECK_PORT_ENABLED(pOutputPort)) || 1168 (!CHECK_PORT_POPULATED(pInputPort)) || (!CHECK_PORT_POPULATED(pOutputPort))) { 1169 ret = OMX_ErrorNone; 1170 goto EXIT; 1171 } 1172 if (OMX_FALSE == SEC_Check_BufferProcess_State(pSECComponent)) { 1173 ret = OMX_ErrorNone; 1174 goto EXIT; 1175 } 1176 1177 ret = SEC_MFC_Mpeg4_Decode(pOMXComponent, pInputData, pOutputData); 1178 if (ret != OMX_ErrorNone) { 1179 if (ret == OMX_ErrorInputDataDecodeYet) { 1180 pOutputData->usedDataLen = 0; 1181 pOutputData->remainDataLen = pOutputData->dataLen; 1182 } else { 1183 pSECComponent->pCallbacks->EventHandler((OMX_HANDLETYPE)pOMXComponent, 1184 pSECComponent->callbackData, 1185 OMX_EventError, ret, 0, NULL); 1186 } 1187 } else { 1188 pInputData->previousDataLen = pInputData->dataLen; 1189 pInputData->usedDataLen += pInputData->dataLen; 1190 pInputData->remainDataLen = pInputData->dataLen - pInputData->usedDataLen; 1191 pInputData->dataLen -= pInputData->usedDataLen; 1192 pInputData->usedDataLen = 0; 1193 1194 pOutputData->usedDataLen = 0; 1195 pOutputData->remainDataLen = pOutputData->dataLen; 1196 } 1197 1198 EXIT: 1199 FunctionOut(); 1200 1201 return ret; 1202 } 1203 1204 OSCL_EXPORT_REF OMX_ERRORTYPE SEC_OMX_ComponentInit(OMX_HANDLETYPE hComponent, OMX_STRING componentName) 1205 { 1206 OMX_ERRORTYPE ret = OMX_ErrorNone; 1207 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1208 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1209 SEC_OMX_BASEPORT *pSECPort = NULL; 1210 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 1211 OMX_S32 codecType = -1; 1212 int i = 0; 1213 1214 FunctionIn(); 1215 1216 if ((hComponent == NULL) || (componentName == NULL)) { 1217 ret = OMX_ErrorBadParameter; 1218 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: parameters are null, ret: %X", __FUNCTION__, ret); 1219 goto EXIT; 1220 } 1221 if (SEC_OSAL_Strcmp(SEC_OMX_COMPOMENT_MPEG4_DEC, componentName) == 0) { 1222 codecType = CODEC_TYPE_MPEG4; 1223 } else if (SEC_OSAL_Strcmp(SEC_OMX_COMPOMENT_H263_DEC, componentName) == 0) { 1224 codecType = CODEC_TYPE_H263; 1225 } else { 1226 ret = OMX_ErrorBadParameter; 1227 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: componentName(%s) error, ret: %X", __FUNCTION__, ret); 1228 goto EXIT; 1229 } 1230 1231 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1232 ret = SEC_OMX_VideoDecodeComponentInit(pOMXComponent); 1233 if (ret != OMX_ErrorNone) { 1234 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SEC_OMX_VideoDecodeComponentInit error, ret: %X", __FUNCTION__, ret); 1235 goto EXIT; 1236 } 1237 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1238 pSECComponent->codecType = HW_VIDEO_CODEC; 1239 1240 pSECComponent->componentName = (OMX_STRING)SEC_OSAL_Malloc(MAX_OMX_COMPONENT_NAME_SIZE); 1241 if (pSECComponent->componentName == NULL) { 1242 SEC_OMX_VideoDecodeComponentDeinit(pOMXComponent); 1243 ret = OMX_ErrorInsufficientResources; 1244 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: componentName alloc error, ret: %X", __FUNCTION__, ret); 1245 goto EXIT; 1246 } 1247 SEC_OSAL_Memset(pSECComponent->componentName, 0, MAX_OMX_COMPONENT_NAME_SIZE); 1248 1249 pMpeg4Dec = SEC_OSAL_Malloc(sizeof(SEC_MPEG4_HANDLE)); 1250 if (pMpeg4Dec == NULL) { 1251 SEC_OMX_VideoDecodeComponentDeinit(pOMXComponent); 1252 ret = OMX_ErrorInsufficientResources; 1253 SEC_OSAL_Log(SEC_LOG_ERROR, "%s: SEC_MPEG4_HANDLE alloc error, ret: %X", __FUNCTION__, ret); 1254 goto EXIT; 1255 } 1256 SEC_OSAL_Memset(pMpeg4Dec, 0, sizeof(SEC_MPEG4_HANDLE)); 1257 pSECComponent->hCodecHandle = (OMX_HANDLETYPE)pMpeg4Dec; 1258 pMpeg4Dec->hMFCMpeg4Handle.codecType = codecType; 1259 1260 if (codecType == CODEC_TYPE_MPEG4) 1261 SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPOMENT_MPEG4_DEC); 1262 else 1263 SEC_OSAL_Strcpy(pSECComponent->componentName, SEC_OMX_COMPOMENT_H263_DEC); 1264 1265 /* Set componentVersion */ 1266 pSECComponent->componentVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; 1267 pSECComponent->componentVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; 1268 pSECComponent->componentVersion.s.nRevision = REVISION_NUMBER; 1269 pSECComponent->componentVersion.s.nStep = STEP_NUMBER; 1270 /* Set specVersion */ 1271 pSECComponent->specVersion.s.nVersionMajor = VERSIONMAJOR_NUMBER; 1272 pSECComponent->specVersion.s.nVersionMinor = VERSIONMINOR_NUMBER; 1273 pSECComponent->specVersion.s.nRevision = REVISION_NUMBER; 1274 pSECComponent->specVersion.s.nStep = STEP_NUMBER; 1275 1276 /* Android CapabilityFlags */ 1277 pSECComponent->capabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; 1278 pSECComponent->capabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_TRUE; 1279 pSECComponent->capabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_TRUE; 1280 pSECComponent->capabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; 1281 pSECComponent->capabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE; 1282 pSECComponent->capabilityFlags.iOMXComponentUsesNALStartCodes = OMX_TRUE; 1283 pSECComponent->capabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE; 1284 pSECComponent->capabilityFlags.iOMXComponentUsesFullAVCFrames = OMX_TRUE; 1285 1286 /* Input port */ 1287 pSECPort = &pSECComponent->pSECPort[INPUT_PORT_INDEX]; 1288 pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; 1289 pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; 1290 pSECPort->portDefinition.format.video.nStride = 0; 1291 pSECPort->portDefinition.format.video.nSliceHeight = 0; 1292 pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_INPUT_BUFFER_SIZE; 1293 if (codecType == CODEC_TYPE_MPEG4) { 1294 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 1295 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1296 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/mpeg4"); 1297 } else { 1298 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 1299 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1300 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "video/h263"); 1301 } 1302 pSECPort->portDefinition.format.video.pNativeRender = 0; 1303 pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; 1304 pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatUnused; 1305 pSECPort->portDefinition.bEnabled = OMX_TRUE; 1306 1307 /* Output port */ 1308 pSECPort = &pSECComponent->pSECPort[OUTPUT_PORT_INDEX]; 1309 pSECPort->portDefinition.format.video.nFrameWidth = DEFAULT_FRAME_WIDTH; 1310 pSECPort->portDefinition.format.video.nFrameHeight= DEFAULT_FRAME_HEIGHT; 1311 pSECPort->portDefinition.format.video.nStride = 0; 1312 pSECPort->portDefinition.format.video.nSliceHeight = 0; 1313 pSECPort->portDefinition.nBufferSize = DEFAULT_VIDEO_OUTPUT_BUFFER_SIZE; 1314 pSECPort->portDefinition.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; 1315 SEC_OSAL_Memset(pSECPort->portDefinition.format.video.cMIMEType, 0, MAX_OMX_MIMETYPE_SIZE); 1316 SEC_OSAL_Strcpy(pSECPort->portDefinition.format.video.cMIMEType, "raw/video"); 1317 pSECPort->portDefinition.format.video.pNativeRender = 0; 1318 pSECPort->portDefinition.format.video.bFlagErrorConcealment = OMX_FALSE; 1319 pSECPort->portDefinition.format.video.eColorFormat = OMX_COLOR_FormatYUV420Planar; 1320 pSECPort->portDefinition.bEnabled = OMX_TRUE; 1321 1322 if (codecType == CODEC_TYPE_MPEG4) { 1323 for(i = 0; i < ALL_PORT_NUM; i++) { 1324 INIT_SET_SIZE_VERSION(&pMpeg4Dec->mpeg4Component[i], OMX_VIDEO_PARAM_MPEG4TYPE); 1325 pMpeg4Dec->mpeg4Component[i].nPortIndex = i; 1326 pMpeg4Dec->mpeg4Component[i].eProfile = OMX_VIDEO_MPEG4ProfileSimple; 1327 pMpeg4Dec->mpeg4Component[i].eLevel = OMX_VIDEO_MPEG4Level3; 1328 } 1329 } else { 1330 for(i = 0; i < ALL_PORT_NUM; i++) { 1331 INIT_SET_SIZE_VERSION(&pMpeg4Dec->h263Component[i], OMX_VIDEO_PARAM_H263TYPE); 1332 pMpeg4Dec->h263Component[i].nPortIndex = i; 1333 pMpeg4Dec->h263Component[i].eProfile = OMX_VIDEO_H263ProfileBaseline | OMX_VIDEO_H263ProfileISWV2; 1334 pMpeg4Dec->h263Component[i].eLevel = OMX_VIDEO_H263Level45; 1335 } 1336 } 1337 1338 pOMXComponent->GetParameter = &SEC_MFC_Mpeg4Dec_GetParameter; 1339 pOMXComponent->SetParameter = &SEC_MFC_Mpeg4Dec_SetParameter; 1340 pOMXComponent->SetConfig = &SEC_MFC_Mpeg4Dec_SetConfig; 1341 pOMXComponent->GetExtensionIndex = &SEC_MFC_Mpeg4Dec_GetExtensionIndex; 1342 pOMXComponent->ComponentRoleEnum = &SEC_MFC_Mpeg4Dec_ComponentRoleEnum; 1343 pOMXComponent->ComponentDeInit = &SEC_OMX_ComponentDeinit; 1344 1345 pSECComponent->sec_mfc_componentInit = &SEC_MFC_Mpeg4Dec_Init; 1346 pSECComponent->sec_mfc_componentTerminate = &SEC_MFC_Mpeg4Dec_Terminate; 1347 pSECComponent->sec_mfc_bufferProcess = &SEC_MFC_Mpeg4Dec_bufferProcess; 1348 if (codecType == CODEC_TYPE_MPEG4) 1349 pSECComponent->sec_checkInputFrame = &Check_Mpeg4_Frame; 1350 else 1351 pSECComponent->sec_checkInputFrame = &Check_H263_Frame; 1352 1353 pSECComponent->currentState = OMX_StateLoaded; 1354 1355 ret = OMX_ErrorNone; 1356 1357 EXIT: 1358 FunctionOut(); 1359 1360 return ret; 1361 } 1362 1363 OMX_ERRORTYPE SEC_OMX_ComponentDeinit(OMX_HANDLETYPE hComponent) 1364 { 1365 OMX_ERRORTYPE ret = OMX_ErrorNone; 1366 OMX_COMPONENTTYPE *pOMXComponent = NULL; 1367 SEC_OMX_BASECOMPONENT *pSECComponent = NULL; 1368 SEC_MPEG4_HANDLE *pMpeg4Dec = NULL; 1369 1370 FunctionIn(); 1371 1372 if (hComponent == NULL) { 1373 ret = OMX_ErrorBadParameter; 1374 goto EXIT; 1375 } 1376 pOMXComponent = (OMX_COMPONENTTYPE *)hComponent; 1377 pSECComponent = (SEC_OMX_BASECOMPONENT *)pOMXComponent->pComponentPrivate; 1378 1379 SEC_OSAL_Free(pSECComponent->componentName); 1380 pSECComponent->componentName = NULL; 1381 1382 pMpeg4Dec = (SEC_MPEG4_HANDLE *)pSECComponent->hCodecHandle; 1383 if (pMpeg4Dec != NULL) { 1384 SEC_OSAL_Free(pMpeg4Dec); 1385 pSECComponent->hCodecHandle = NULL; 1386 } 1387 1388 ret = SEC_OMX_VideoDecodeComponentDeinit(pOMXComponent); 1389 if (ret != OMX_ErrorNone) { 1390 goto EXIT; 1391 } 1392 1393 ret = OMX_ErrorNone; 1394 1395 EXIT: 1396 FunctionOut(); 1397 1398 return ret; 1399 } 1400