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