OMX_VideoDec_Utils.c revision 2acd4700b78e88cf0f8d52bb14fd9deb99d9f9bf
1 2/* 3 * Copyright (C) Texas Instruments - http://www.ti.com/ 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21/* ============================================================================= 22* Texas Instruments OMAP(TM) Platform Software 23* (c) Copyright Texas Instruments, Incorporated. All Rights Reserved. 24* 25* Use of this software is controlled by the terms and conditions found 26* in the license agreement under which this software has been supplied. 27* =========================================================================== */ 28/** 29* @file OMX_Video_Dec_Utils.c 30* 31* This file implements OMX Component for MPEG-4 decoder that 32* is fully compliant with the Khronos OMX specification 1.0. 33* 34* @path $(CSLPATH)\src 35* 36* @rev 0.1 37*/ 38/* -------------------------------------------------------------------------- */ 39/* ============================================================================= 40*! 41*! Revision History 42*! =================================== 43*! 44*! 02-Feb-2006 mf: Revisions appear in reverse chronological order; 45*! that is, newest first. The date format is dd-Mon-yyyy. 46* =========================================================================== */ 47 48/* ------compilation control switches ----------------------------------------*/ 49/******************************************************************************* 50* INCLUDE FILES 51*******************************************************************************/ 52/* ----- system and platform files -------------------------------------------*/ 53#include "OMX_VideoDecoder.h" 54#include "OMX_VideoDec_Utils.h" 55#include "OMX_VideoDec_DSP.h" 56#include "OMX_VideoDec_Thread.h" 57/*----------------------------------------------------------------------------*/ 58/** 59 * VIDDEC_GetRMFrecuency() Return the value for frecuecny to use RM. 60 **/ 61/*----------------------------------------------------------------------------*/ 62OMX_U32 VIDDEC_GetRMFrecuency(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 63{ 64 OMX_U32 nReturnValue = VIDDEC_MPU; 65 66 OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n"); 67#ifdef RESOURCE_MANAGER_ENABLED 68 /*resolution for greater than CIF*/ 69 if ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > VIDDEC_CIF_WIDTH) || 70 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > VIDDEC_CIF_HEIGHT)) { 71 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 72 nReturnValue = VIDDEC_RM_FREC_H264_VGA; 73 } 74 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 75 nReturnValue = VIDDEC_RM_FREC_WMV_VGA; 76 } 77 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) { 78 if ((OMX_U16)pComponentPrivate->pInPortDef->format.video.nFrameHeight > VIDDEC_D1MAX_HEIGHT || 79 (OMX_U16)pComponentPrivate->pInPortDef->format.video.nFrameWidth > VIDDEC_D1MAX_WIDTH) 80 { 81 nReturnValue = VIDDEC_RM_FREC_MPEG4_720P; 82 } 83 else 84 { 85 nReturnValue = VIDDEC_RM_FREC_MPEG4_VGA; 86 } 87 } 88 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 89 nReturnValue = VIDDEC_RM_FREC_MPEG2_VGA; 90 } 91 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 92 nReturnValue = VIDDEC_RM_FREC_H263_VGA; 93 } 94#ifdef VIDDEC_SPARK_CODE 95 else if (VIDDEC_SPARKCHECK) { 96 nReturnValue = VIDDEC_RM_FREC_SPARK_VGA; 97 } 98#endif 99 else { 100 nReturnValue = VIDDEC_MPU; 101 } 102 } 103 /*resolution from QCIF up to CIF*/ 104 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= VIDDEC_CIF_WIDTH) && 105 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > VIDDEC_QCIF_WIDTH)) || 106 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= VIDDEC_CIF_HEIGHT) && 107 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > VIDDEC_QCIF_HEIGHT))) { 108 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 109 nReturnValue = VIDDEC_RM_FREC_H264_CIF; 110 } 111 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 112 nReturnValue = VIDDEC_RM_FREC_WMV_CIF; 113 } 114 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) { 115 nReturnValue = VIDDEC_RM_FREC_MPEG4_CIF; 116 } 117 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 118 nReturnValue = VIDDEC_RM_FREC_MPEG2_CIF; 119 } 120 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 121 nReturnValue = VIDDEC_RM_FREC_H263_CIF; 122 } 123#ifdef VIDDEC_SPARK_CODE 124 else if (VIDDEC_SPARKCHECK) { 125 nReturnValue = VIDDEC_RM_FREC_SPARK_CIF; 126 } 127#endif 128 else { 129 nReturnValue = VIDDEC_MPU; 130 } 131 } 132 /*resolution up to QCIF*/ 133 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= VIDDEC_QCIF_WIDTH) && 134 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth >= VIDDEC_MIN_WIDTH)) || 135 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= VIDDEC_QCIF_HEIGHT) && 136 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight >= VIDDEC_MIN_HEIGHT))) { 137 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 138 nReturnValue = VIDDEC_RM_FREC_H264_QCIF; 139 } 140 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 141 nReturnValue = VIDDEC_RM_FREC_WMV_QCIF; 142 } 143 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) { 144 nReturnValue = VIDDEC_RM_FREC_MPEG4_QCIF; 145 } 146 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 147 nReturnValue = VIDDEC_RM_FREC_MPEG2_QCIF; 148 } 149 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 150 nReturnValue = VIDDEC_RM_FREC_H263_QCIF; 151 } 152#ifdef VIDDEC_SPARK_CODE 153 else if (VIDDEC_SPARKCHECK) { 154 nReturnValue = VIDDEC_RM_FREC_SPARK_QCIF; 155 } 156#endif 157 else { 158 nReturnValue = VIDDEC_MPU; 159 } 160 } 161 else { 162 nReturnValue = VIDDEC_MPU; 163 } 164 OMX_PRDSP2(pComponentPrivate->dbg, "Used RM Frec value = %d\n",(int)nReturnValue); 165#else 166 OMX_PRDSP2(pComponentPrivate->dbg, "Used RM Frec defaulted value = %d\n",(int)nReturnValue); 167#endif 168 OMX_PRINT1(pComponentPrivate->dbg, "---EXITING\n"); 169 return nReturnValue; 170 171} 172 173OMX_ERRORTYPE VIDDEC_Queue_Init(VIDDEC_QUEUE_TYPE *queue, VIDDEC_QUEUE_TYPES type) 174{ 175 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 176 OMX_U32 count; 177 178 queue->nHead = 0; 179 queue->nTail = 0; 180 queue->nElements = 0; 181 182 switch(type) 183 { 184 case VIDDEC_QUEUE_OMX_U32: 185 queue->Elements = (void*)malloc(VIDDEC_MAX_QUEUE_SIZE*sizeof(OMX_U32)); 186 /*OMX_MALLOC_STRUCT_SIZED(queue->Elements, void, VIDDEC_MAX_QUEUE_SIZE*sizeof(OMX_U32));*/ 187 break; 188 case VIDDEC_QUEUE_OMX_MARKTYPE: 189 queue->Elements = (void*)malloc(VIDDEC_MAX_QUEUE_SIZE*sizeof(OMX_MARKTYPE)); 190 /*OMX_MALLOC_STRUCT_SIZED(queue->Elements, void, VIDDEC_MAX_QUEUE_SIZE*sizeof(OMX_MARKTYPE));*/ 191 break; 192 } 193 194 pthread_mutex_init(&(queue->mMutex), NULL); 195 196 for(count=0; count < VIDDEC_MAX_QUEUE_SIZE; count++) 197 { 198 queue->CounterElements[count] = 0; 199 } 200 201 eError = OMX_ErrorNone; 202/*EXIT:*/ 203 return eError; 204} 205 206OMX_ERRORTYPE VIDDEC_Queue_Flush(VIDDEC_QUEUE_TYPE *queue) 207{ 208 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 209 OMX_U32 count; 210 211 if (pthread_mutex_lock (&(queue->mMutex)) != 0) { 212 eError = OMX_ErrorUndefined; 213 goto EXIT; 214 } 215 queue->nHead = 0; 216 queue->nTail = 0; 217 queue->nElements = 0; 218 219 for(count=0; count < VIDDEC_MAX_QUEUE_SIZE; count++) 220 { 221 queue->CounterElements[count] = 0; 222 } 223 eError = OMX_ErrorNone; 224 225 if (pthread_mutex_unlock (&(queue->mMutex)) != 0) { 226 eError = OMX_ErrorUndefined; 227 } 228 229EXIT: 230 return eError; 231} 232 233OMX_ERRORTYPE VIDDEC_Queue_Add(VIDDEC_QUEUE_TYPE *queue, OMX_PTR pElement, VIDDEC_QUEUE_TYPES type) 234{ 235 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 236 237 if (pthread_mutex_lock (&(queue->mMutex)) != 0) { 238 eError = OMX_ErrorUndefined; 239 goto EXIT; 240 } 241 if(queue->nElements == 0) 242 { 243 switch(type) 244 { 245 case VIDDEC_QUEUE_OMX_U32: 246 { 247 OMX_U32 *pLocal = (OMX_U32 *)queue->Elements; 248 pLocal[queue->nHead] = *(OMX_U32 *)pElement; 249 } 250 break; 251 case VIDDEC_QUEUE_OMX_MARKTYPE: 252 { 253 OMX_MARKTYPE *pLocal = (OMX_MARKTYPE *)queue->Elements; 254 pLocal[queue->nHead] = *(OMX_MARKTYPE *)pElement; 255 /*memcpy(&pLocal[queue->nHead], pElement, sizeof(OMX_MARKTYPE));*/ 256 } 257 break; 258 } 259 queue->CounterElements[queue->nHead] = 1; 260 queue->nElements++; 261 eError = OMX_ErrorNone; 262 } 263 else 264 { 265 switch(type) 266 { 267 case VIDDEC_QUEUE_OMX_U32: 268 { 269 OMX_U32 *pLocal = (OMX_U32 *)queue->Elements; 270 271 if(pLocal[queue->nHead] == *(OMX_U32 *)pElement) 272 { 273 queue->CounterElements[queue->nHead]++; 274 eError = OMX_ErrorNone; 275 } 276 else 277 { 278 if(queue->nElements >= VIDDEC_MAX_QUEUE_SIZE) 279 { 280 eError = OMX_ErrorInsufficientResources; 281 goto UNLOCK; 282 } 283 queue->nHead++; 284 if(queue->nHead >= VIDDEC_MAX_QUEUE_SIZE) 285 { 286 queue->nHead = 0; 287 } 288 pLocal[queue->nHead] = *(OMX_U32 *)pElement; 289 queue->CounterElements[queue->nHead] = 1; 290 queue->nElements++; 291 } 292 } 293 break; 294 case VIDDEC_QUEUE_OMX_MARKTYPE: 295 { 296 OMX_MARKTYPE *pLocal = (OMX_MARKTYPE *)queue->Elements; 297 298 if(pLocal[queue->nHead].hMarkTargetComponent == ((OMX_MARKTYPE *)pElement)->hMarkTargetComponent 299 && pLocal[queue->nHead].pMarkData == ((OMX_MARKTYPE *)pElement)->pMarkData) 300 { 301 queue->CounterElements[queue->nHead]++; 302 eError = OMX_ErrorNone; 303 } 304 else 305 { 306 if(queue->nElements >= VIDDEC_MAX_QUEUE_SIZE) 307 { 308 eError = OMX_ErrorInsufficientResources; 309 goto UNLOCK; 310 } 311 queue->nHead++; 312 if(queue->nHead >= VIDDEC_MAX_QUEUE_SIZE) 313 { 314 queue->nHead = 0; 315 } 316 pLocal[queue->nHead] = *(OMX_MARKTYPE *)pElement; 317 queue->CounterElements[queue->nHead] = 1; 318 queue->nElements++; 319 } 320 } 321 break; 322 } 323 324 eError = OMX_ErrorNone; 325 } 326UNLOCK: 327 if (pthread_mutex_unlock (&(queue->mMutex)) != 0) { 328 eError = OMX_ErrorUndefined; 329 } 330EXIT: 331 return eError; 332 333} 334 335OMX_ERRORTYPE VIDDEC_Queue_Remove(VIDDEC_QUEUE_TYPE *queue, OMX_PTR pElement, VIDDEC_QUEUE_TYPES type) 336{ 337 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 338 339 if (pthread_mutex_lock (&(queue->mMutex)) != 0) { 340 eError = OMX_ErrorUndefined; 341 goto EXIT; 342 } 343 344 if(queue->nElements > 0) 345 { 346 if(pElement) 347 { 348 switch(type) 349 { 350 case VIDDEC_QUEUE_OMX_U32: 351 { 352 OMX_U32 *pLocal = (OMX_U32 *)queue->Elements; 353 *(OMX_U32 *)pElement = pLocal[queue->nTail]; 354 break; 355 } 356 case VIDDEC_QUEUE_OMX_MARKTYPE: 357 { 358 OMX_MARKTYPE *pLocal = (OMX_MARKTYPE *)queue->Elements; 359 *(OMX_MARKTYPE *)pElement = pLocal[queue->nTail]; 360 break; 361 } 362 } 363 } 364 queue->CounterElements[queue->nTail]--; 365 if(queue->CounterElements[queue->nTail] == 0) 366 { 367 queue->nElements--; 368 if(queue->nElements > 0) 369 { 370 queue->nTail++; 371 if(queue->nTail == VIDDEC_MAX_QUEUE_SIZE) 372 { 373 queue->nTail = 0; 374 } 375 } 376 } 377 eError = OMX_ErrorNone; 378 } 379 380 if (pthread_mutex_unlock (&(queue->mMutex)) != 0) { 381 eError = OMX_ErrorUndefined; 382 } 383EXIT: 384 return eError; 385} 386 387OMX_ERRORTYPE VIDDEC_Queue_Get_Tail(VIDDEC_QUEUE_TYPE *queue, OMX_PTR pElement, VIDDEC_QUEUE_TYPES type) 388{ 389 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 390 391 if (pthread_mutex_lock (&(queue->mMutex)) != 0) { 392 eError = OMX_ErrorUndefined; 393 goto EXIT; 394 } 395 if(queue->nElements > 0) 396 { 397 switch(type) 398 { 399 case VIDDEC_QUEUE_OMX_U32: 400 { 401 OMX_U32 *pLocal = (OMX_U32 *)queue->Elements; 402 *(OMX_U32 *)pElement = pLocal[queue->nTail]; 403 break; 404 } 405 case VIDDEC_QUEUE_OMX_MARKTYPE: 406 { 407 OMX_MARKTYPE *pLocal = (OMX_MARKTYPE *)queue->Elements; 408 *(OMX_MARKTYPE *)pElement = pLocal[queue->nTail]; 409 break; 410 } 411 } 412 eError = OMX_ErrorNone; 413 } 414 if (pthread_mutex_unlock (&(queue->mMutex)) != 0) { 415 eError = OMX_ErrorUndefined; 416 } 417 418EXIT: 419 return eError; 420} 421 422OMX_ERRORTYPE VIDDEC_Queue_Replace_Tail(VIDDEC_QUEUE_TYPE *queue, OMX_PTR pElement, VIDDEC_QUEUE_TYPES type) 423{ 424 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 425 426 if (pthread_mutex_lock (&(queue->mMutex)) != 0) { 427 eError = OMX_ErrorUndefined; 428 goto EXIT; 429 } 430 if(queue->nElements > 0) 431 { 432 switch(type) 433 { 434 case VIDDEC_QUEUE_OMX_U32: 435 { 436 OMX_U32 *pLocal = (OMX_U32 *)queue->Elements; 437 if(*(OMX_U32 *)pElement != pLocal[queue->nTail]) 438 { 439 if(queue->CounterElements[queue->nTail] != 1) 440 { 441 if(queue->nElements >= VIDDEC_MAX_QUEUE_SIZE) 442 { 443 eError = OMX_ErrorInsufficientResources; 444 goto UNLOCK; 445 } 446 queue->CounterElements[queue->nTail]--; 447 queue->nTail--; 448 if( (queue->nTail >= VIDDEC_MAX_QUEUE_SIZE) || (queue->nTail < 0) ) 449 { 450 queue->nTail = VIDDEC_MAX_QUEUE_SIZE-1; 451 } 452 queue->CounterElements[queue->nTail] = 1; 453 queue->nElements++; 454 } 455 pLocal[queue->nTail] = *(OMX_U32 *)pElement; 456 eError = OMX_ErrorNone; 457 goto UNLOCK; 458 } 459 break; 460 } 461 case VIDDEC_QUEUE_OMX_MARKTYPE: 462 { 463 OMX_MARKTYPE *pLocal = (OMX_MARKTYPE *)queue->Elements; 464 if(pLocal[queue->nTail].hMarkTargetComponent != ((OMX_MARKTYPE *)pElement)->hMarkTargetComponent 465 || pLocal[queue->nTail].pMarkData != ((OMX_MARKTYPE *)pElement)->pMarkData) 466 { 467 if(queue->CounterElements[queue->nTail] != 1) 468 { 469 if(queue->nElements >= VIDDEC_MAX_QUEUE_SIZE) 470 { 471 eError = OMX_ErrorInsufficientResources; 472 goto UNLOCK; 473 } 474 queue->CounterElements[queue->nTail]--; 475 queue->nTail--; 476 if( (queue->nTail >= VIDDEC_MAX_QUEUE_SIZE) || (queue->nTail < 0) ) 477 { 478 queue->nTail = VIDDEC_MAX_QUEUE_SIZE-1; 479 } 480 queue->CounterElements[queue->nTail] = 1; 481 queue->nElements++; 482 } 483 pLocal[queue->nTail] = *(OMX_MARKTYPE *)pElement; 484 eError = OMX_ErrorNone; 485 goto UNLOCK; 486 } 487 break; 488 } 489 } 490 } 491UNLOCK: 492 if (pthread_mutex_unlock (&(queue->mMutex)) != 0) { 493 eError = OMX_ErrorUndefined; 494 } 495EXIT: 496 return eError; 497} 498 499OMX_ERRORTYPE VIDDEC_Queue_Free(VIDDEC_QUEUE_TYPE *queue) 500{ 501 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 502 503 queue->nHead = 0; 504 queue->nTail = 0; 505 queue->nElements = 0; 506 507 if(queue->Elements) 508 { 509 free(queue->Elements); 510 } 511 queue->Elements = NULL; 512 513 if (pthread_mutex_destroy (&(queue->mMutex)) != 0) { 514 eError = OMX_ErrorUndefined; 515 goto EXIT; 516 } 517 518 eError = OMX_ErrorNone; 519EXIT: 520 return eError; 521} 522 523/*----------------------------------------------------------------------------*/ 524/** 525 * VIDDEC_CircBuf_Init() 526 **/ 527/*----------------------------------------------------------------------------*/ 528OMX_ERRORTYPE VIDDEC_CircBuf_Init(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex) 529{ 530 OMX_ERRORTYPE eError = OMX_ErrorNone; 531 VIDDEC_CIRCULAR_BUFFER *pTempCBuffer = NULL; 532 OMX_U32 nCount = 0; 533 534 if(nTypeIndex == VIDDEC_CBUFFER_TIMESTAMP){ 535 pTempCBuffer = &pComponentPrivate->pCompPort[nPortIndex]->eTimeStamp; 536 } 537 else { 538 eError = OMX_ErrorBadParameter; 539 return eError; 540 } 541#ifdef VIDDEC_CBUFFER_LOCK 542 if(pTempCBuffer->m_lock != NULL) { 543 free(pTempCBuffer->m_lock); 544 pTempCBuffer->m_lock = NULL; 545 } 546 OMX_MALLOC_STRUCT(pTempCBuffer->m_lock, pthread_mutex_t,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel3]); 547 /*pTempCBuffer->m_lock = malloc(sizeof(pthread_mutex_t));*/ 548 pthread_mutex_init(pTempCBuffer->m_lock, NULL); 549#endif 550 for(nCount = 0; nCount >= CBUFFER_SIZE; nCount++) { 551 pTempCBuffer->pElement[nCount] = NULL; 552 } 553EXIT: 554 pTempCBuffer->nCount = 0; 555 pTempCBuffer->nHead = 0; 556 pTempCBuffer->nTail = 0; 557 558 return eError; 559} 560 561/*----------------------------------------------------------------------------*/ 562/** 563 * VIDDEC_CircBuf_Flush() 564 **/ 565/*----------------------------------------------------------------------------*/ 566OMX_ERRORTYPE VIDDEC_CircBuf_Flush(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex) 567{ 568 OMX_ERRORTYPE eError = OMX_ErrorNone; 569 VIDDEC_CIRCULAR_BUFFER *pTempCBuffer = NULL; 570 OMX_U32 nCount = 0; 571 572 if(nTypeIndex == VIDDEC_CBUFFER_TIMESTAMP){ 573 pTempCBuffer = &pComponentPrivate->pCompPort[nPortIndex]->eTimeStamp; 574 } 575 else { 576 eError = OMX_ErrorBadParameter; 577 return eError; 578 } 579#ifdef VIDDEC_CBUFFER_LOCK 580 if(pthread_mutex_lock(pTempCBuffer->m_lock) != 0) { 581 eError = OMX_ErrorHardware; 582 return eError; 583 } 584#endif 585 for (nCount = pTempCBuffer->nTail; nCount <= pTempCBuffer->nHead; nCount++){ 586 pTempCBuffer->pElement[nCount] = NULL; 587 } 588 pTempCBuffer->nCount = 0; 589 pTempCBuffer->nHead = 0; 590 pTempCBuffer->nTail = 0; 591 592#ifdef VIDDEC_CBUFFER_LOCK 593 if(pthread_mutex_unlock(pTempCBuffer->m_lock) != 0) { 594 eError = OMX_ErrorHardware; 595 return eError; 596 } 597#endif 598 return eError; 599} 600 601/*----------------------------------------------------------------------------*/ 602/** 603 * VIDDEC_CircBuf_DeInit() 604 **/ 605/*----------------------------------------------------------------------------*/ 606OMX_ERRORTYPE VIDDEC_CircBuf_DeInit(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex) 607{ 608 OMX_ERRORTYPE eError = OMX_ErrorNone; 609 VIDDEC_CIRCULAR_BUFFER *pTempCBuffer = NULL; 610 OMX_U32 nCount = 0; 611 612 if(nTypeIndex == VIDDEC_CBUFFER_TIMESTAMP){ 613 pTempCBuffer = &pComponentPrivate->pCompPort[nPortIndex]->eTimeStamp; 614 } 615 else { 616 eError = OMX_ErrorBadParameter; 617 return eError; 618 } 619#ifdef VIDDEC_CBUFFER_LOCK 620 if(pTempCBuffer->m_lock != NULL) { 621 free(pTempCBuffer->m_lock); 622 pTempCBuffer->m_lock = NULL; 623 } 624#endif 625 for(nCount = 0; nCount >= CBUFFER_SIZE; nCount++) { 626 pTempCBuffer->pElement[nCount] = NULL; 627 } 628 return eError; 629} 630 631/*----------------------------------------------------------------------------*/ 632/** 633 * VIDDEC_CircBuf_Add() set the last element in the Circular Buffer 634 * return the error number in case of exist an error. 635 **/ 636/*----------------------------------------------------------------------------*/ 637OMX_ERRORTYPE VIDDEC_CircBuf_Add(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex, OMX_PTR pElement) 638{ 639 OMX_ERRORTYPE eError = OMX_ErrorNone; 640 VIDDEC_CIRCULAR_BUFFER *pTempCBuffer = NULL; 641 642 if(nTypeIndex == VIDDEC_CBUFFER_TIMESTAMP){ 643 pTempCBuffer = &pComponentPrivate->pCompPort[nPortIndex]->eTimeStamp; 644 } 645 else { 646 eError = OMX_ErrorBadParameter; 647 return eError; 648 } 649#ifdef VIDDEC_CBUFFER_LOCK 650 if(pthread_mutex_lock(pTempCBuffer->m_lock) != 0) { 651 eError = OMX_ErrorHardware; 652 return eError; 653 } 654#endif 655 pTempCBuffer->pElement[pTempCBuffer->nHead++] = pElement; 656 pTempCBuffer->nCount++; 657 if(pTempCBuffer->nHead >= CBUFFER_SIZE){ 658 pTempCBuffer->nHead = 0; 659 } 660#ifdef VIDDEC_CBUFFER_LOCK 661 if(pthread_mutex_unlock(pTempCBuffer->m_lock) != 0) { 662 eError = OMX_ErrorHardware; 663 return eError; 664 } 665#endif 666 return eError; 667} 668 669/*----------------------------------------------------------------------------*/ 670/** 671 * VIDDEC_CircBuf_Remove() get the first element in the Circular Buffer 672 * return the error number in case of exist an error. 673 **/ 674/*----------------------------------------------------------------------------*/ 675OMX_ERRORTYPE VIDDEC_CircBuf_Remove(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex, OMX_PTR* pElement) 676{ 677 OMX_ERRORTYPE eError = OMX_ErrorNone; 678 VIDDEC_CIRCULAR_BUFFER *pTempCBuffer = NULL; 679 680 if(nTypeIndex == VIDDEC_CBUFFER_TIMESTAMP){ 681 pTempCBuffer = &pComponentPrivate->pCompPort[nPortIndex]->eTimeStamp; 682 } 683 else { 684 eError = OMX_ErrorBadParameter; 685 return eError; 686 } 687#ifdef VIDDEC_CBUFFER_LOCK 688 if(pthread_mutex_lock(pTempCBuffer->m_lock) != 0) { 689 eError = OMX_ErrorHardware; 690 return eError; 691 } 692#endif 693 if(pTempCBuffer->nCount) 694 { 695 *pElement = pTempCBuffer->pElement[pTempCBuffer->nTail]; 696 pTempCBuffer->pElement[pTempCBuffer->nTail++] = NULL; 697 pTempCBuffer->nCount--; 698 if(pTempCBuffer->nTail >= CBUFFER_SIZE){ 699 pTempCBuffer->nTail = 0; 700 } 701 } 702 else 703 { 704 *pElement = NULL; 705 } 706#ifdef VIDDEC_CBUFFER_LOCK 707 if(pthread_mutex_unlock(pTempCBuffer->m_lock) != 0) { 708 eError = OMX_ErrorHardware; 709 return eError; 710 } 711#endif 712 return eError; 713} 714 715/*----------------------------------------------------------------------------*/ 716/** 717 * VIDDEC_CircBuf_Count() get the number of elements in the Circular Buffer 718 * return the error number in case of exist an error. 719 **/ 720/*----------------------------------------------------------------------------*/ 721OMX_ERRORTYPE VIDDEC_CircBuf_Count(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex, OMX_U8* pCount) 722{ 723 OMX_ERRORTYPE eError = OMX_ErrorNone; 724 VIDDEC_CIRCULAR_BUFFER *pTempCBuffer = NULL; 725 726 if(nTypeIndex == VIDDEC_CBUFFER_TIMESTAMP){ 727 pTempCBuffer = &pComponentPrivate->pCompPort[nPortIndex]->eTimeStamp; 728 } 729 else { 730 eError = OMX_ErrorBadParameter; 731 pCount = 0; 732 return eError; 733 } 734#ifdef VIDDEC_CBUFFER_LOCK 735 if(pthread_mutex_lock(pTempCBuffer->m_lock) != 0) { 736 eError = OMX_ErrorHardware; 737 return eError; 738 } 739#endif 740 741 *pCount = pTempCBuffer->nCount; 742 743#ifdef VIDDEC_CBUFFER_LOCK 744 if(pthread_mutex_unlock(pTempCBuffer->m_lock) != 0) { 745 eError = OMX_ErrorHardware; 746 return eError; 747 } 748#endif 749 return eError; 750} 751 752/*----------------------------------------------------------------------------*/ 753/** 754 * VIDDEC_CircBuf_Head() get the number of elements in the Circular Buffer 755 * return the error number in case of exist an error. 756 **/ 757/*----------------------------------------------------------------------------*/ 758OMX_U8 VIDDEC_CircBuf_GetHead(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex) 759{ 760 /*OMX_ERRORTYPE eError = OMX_ErrorNone;*/ 761 VIDDEC_CIRCULAR_BUFFER *pTempCBuffer = NULL; 762 OMX_U8 ucHead = 0; 763 764 if(nTypeIndex == VIDDEC_CBUFFER_TIMESTAMP){ 765 pTempCBuffer = &pComponentPrivate->pCompPort[nPortIndex]->eTimeStamp; 766 } 767 else { 768 ucHead = 0; 769 return 0; 770 } 771#ifdef VIDDEC_CBUFFER_LOCK 772 if(pthread_mutex_lock(pTempCBuffer->m_lock) != 0) { 773 return 0; 774 } 775#endif 776 777 ucHead = pTempCBuffer->nHead; 778 779#ifdef VIDDEC_CBUFFER_LOCK 780 if(pthread_mutex_unlock(pTempCBuffer->m_lock) != 0) { 781 return 0; 782 } 783#endif 784 return ucHead; 785} 786 787/* ========================================================================== */ 788/** 789 * VIDDEC_Load_Defaults() function will be called by the component to 790 * 791 * load the default values 792 * 793 * @param pComponentPrivate Pointer to the pComponentPrivatePrivate 794 * 795 * @retval OMX_NoError Success, ready to roll 796 **/ 797/* ========================================================================== */ 798 799OMX_ERRORTYPE VIDDEC_Load_Defaults (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_S32 nPassing) 800{ 801 OMX_U32 iCount = 0; 802 OMX_ERRORTYPE eError = OMX_ErrorNone; 803 804 switch(nPassing){ 805 case VIDDEC_INIT_ALL: 806 case VIDDEC_INIT_STRUCTS: 807 pComponentPrivate->nInBufIndex = 0; 808 pComponentPrivate->nOutBufIndex = 0; 809 pComponentPrivate->nInMarkBufIndex = 0; 810 pComponentPrivate->nOutMarkBufIndex = 0; 811 pComponentPrivate->nInCmdMarkBufIndex = 0; 812 pComponentPrivate->nOutCmdMarkBufIndex = 0; 813 814 pComponentPrivate->pCompPort[0]->hTunnelComponent = NULL; 815 pComponentPrivate->pCompPort[1]->hTunnelComponent = NULL; 816 817 /* Set component version */ 818 pComponentPrivate->pComponentVersion.s.nVersionMajor = VERSION_MAJOR; 819 pComponentPrivate->pComponentVersion.s.nVersionMinor = VERSION_MINOR; 820 pComponentPrivate->pComponentVersion.s.nRevision = VERSION_REVISION; 821 pComponentPrivate->pComponentVersion.s.nStep = VERSION_STEP; 822 823 /* Set spec version */ 824 pComponentPrivate->pSpecVersion.s.nVersionMajor = VERSION_MAJOR; 825 pComponentPrivate->pSpecVersion.s.nVersionMinor = VERSION_MINOR; 826 pComponentPrivate->pSpecVersion.s.nRevision = VERSION_REVISION; 827 pComponentPrivate->pSpecVersion.s.nStep = VERSION_STEP; 828 829 pComponentPrivate->pHandle->pApplicationPrivate = NULL; 830 /* Set pPortParamType defaults */ 831 OMX_CONF_INIT_STRUCT(pComponentPrivate->pPortParamType, OMX_PORT_PARAM_TYPE, pComponentPrivate->dbg); 832 pComponentPrivate->pPortParamType->nPorts = NUM_OF_PORTS; 833 pComponentPrivate->pPortParamType->nStartPortNumber = VIDDEC_INPUT_PORT; 834#ifdef __STD_COMPONENT__ 835 OMX_CONF_INIT_STRUCT(pComponentPrivate->pPortParamTypeAudio, OMX_PORT_PARAM_TYPE, pComponentPrivate->dbg); 836 pComponentPrivate->pPortParamTypeAudio->nPorts = VIDDEC_ZERO; 837 pComponentPrivate->pPortParamTypeAudio->nStartPortNumber = VIDDEC_ZERO; 838 OMX_CONF_INIT_STRUCT(pComponentPrivate->pPortParamTypeImage, OMX_PORT_PARAM_TYPE, pComponentPrivate->dbg); 839 pComponentPrivate->pPortParamTypeImage->nPorts = VIDDEC_ZERO; 840 pComponentPrivate->pPortParamTypeImage->nStartPortNumber = VIDDEC_ZERO; 841 OMX_CONF_INIT_STRUCT(pComponentPrivate->pPortParamTypeOthers, OMX_PORT_PARAM_TYPE, pComponentPrivate->dbg); 842 pComponentPrivate->pPortParamTypeOthers->nPorts = VIDDEC_ZERO; 843 pComponentPrivate->pPortParamTypeOthers->nStartPortNumber = VIDDEC_ZERO; 844#endif 845 846 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->nBufferCnt = 0; 847 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->nBufferCnt = 0; 848 849 /* Set pInPortDef defaults */ 850 OMX_CONF_INIT_STRUCT(pComponentPrivate->pInPortDef, OMX_PARAM_PORTDEFINITIONTYPE, pComponentPrivate->dbg); 851 pComponentPrivate->pInPortDef->nPortIndex = VIDDEC_INPUT_PORT; 852 pComponentPrivate->pInPortDef->eDir = OMX_DirInput; 853 pComponentPrivate->pInPortDef->nBufferCountActual = MAX_PRIVATE_IN_BUFFERS; 854 pComponentPrivate->pInPortDef->nBufferCountMin = VIDDEC_BUFFERMINCOUNT; 855 pComponentPrivate->pInPortDef->nBufferSize = VIDDEC_DEFAULT_INPUT_BUFFER_SIZE; 856 pComponentPrivate->pInPortDef->bEnabled = VIDDEC_PORT_ENABLED; 857 pComponentPrivate->pInPortDef->bPopulated = VIDDEC_PORT_POPULATED; 858 pComponentPrivate->pInPortDef->eDomain = VIDDEC_PORT_DOMAIN; 859#ifdef KHRONOS_1_2 860 pComponentPrivate->pInPortDef->bBuffersContiguous = OMX_FALSE; 861 pComponentPrivate->pInPortDef->nBufferAlignment = OMX_FALSE; 862#endif 863 pComponentPrivate->pInPortDef->format.video.pNativeRender = VIDDEC_INPUT_PORT_NATIVERENDER; 864 pComponentPrivate->pInPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 865 pComponentPrivate->pInPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 866 pComponentPrivate->pInPortDef->format.video.nStride = VIDDEC_INPUT_PORT_STRIDE; 867 pComponentPrivate->pInPortDef->format.video.nSliceHeight = VIDDEC_INPUT_PORT_SLICEHEIGHT; 868 pComponentPrivate->pInPortDef->format.video.nBitrate = VIDDEC_INPUT_PORT_BITRATE; 869 pComponentPrivate->pInPortDef->format.video.xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 870 pComponentPrivate->pInPortDef->format.video.cMIMEType = VIDDEC_MIMETYPEMPEG4; 871 pComponentPrivate->pInPortDef->format.video.bFlagErrorConcealment = VIDDEC_INPUT_PORT_FLAGERRORCONCEALMENT; 872 pComponentPrivate->pInPortDef->format.video.eCompressionFormat = VIDDEC_INPUT_PORT_COMPRESSIONFORMAT; 873 pComponentPrivate->pInPortDef->format.video.eColorFormat = VIDDEC_COLORFORMATUNUSED; 874#ifdef KHRONOS_1_1 875 pComponentPrivate->pInPortDef->format.video.pNativeWindow = 0; 876#endif 877 878 /* Set pOutPortDef defaults */ 879 OMX_CONF_INIT_STRUCT(pComponentPrivate->pOutPortDef, OMX_PARAM_PORTDEFINITIONTYPE, pComponentPrivate->dbg); 880 pComponentPrivate->pOutPortDef->nPortIndex = VIDDEC_OUTPUT_PORT; 881 pComponentPrivate->pOutPortDef->eDir = OMX_DirOutput; 882 pComponentPrivate->pOutPortDef->nBufferCountActual = MAX_PRIVATE_OUT_BUFFERS; 883 pComponentPrivate->pOutPortDef->nBufferCountMin = VIDDEC_BUFFERMINCOUNT; 884 pComponentPrivate->pOutPortDef->nBufferSize = VIDDEC_DEFAULT_OUTPUT_BUFFER_SIZE; 885 pComponentPrivate->pOutPortDef->bEnabled = VIDDEC_PORT_ENABLED; 886 pComponentPrivate->pOutPortDef->bPopulated = VIDDEC_PORT_POPULATED; 887 pComponentPrivate->pOutPortDef->eDomain = VIDDEC_PORT_DOMAIN; 888#ifdef KHRONOS_1_2 889 pComponentPrivate->pInPortDef->bBuffersContiguous = OMX_FALSE; 890 pComponentPrivate->pInPortDef->nBufferAlignment = OMX_FALSE; 891#endif 892 pComponentPrivate->pOutPortDef->format.video.cMIMEType = VIDDEC_MIMETYPEYUV; 893 pComponentPrivate->pOutPortDef->format.video.pNativeRender = VIDDEC_OUTPUT_PORT_NATIVERENDER; 894 pComponentPrivate->pOutPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 895 pComponentPrivate->pOutPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 896 pComponentPrivate->pOutPortDef->format.video.nStride = VIDDEC_OUTPUT_PORT_STRIDE; 897 pComponentPrivate->pOutPortDef->format.video.nSliceHeight = VIDDEC_OUTPUT_PORT_SLICEHEIGHT; 898 pComponentPrivate->pOutPortDef->format.video.nBitrate = VIDDEC_OUTPUT_PORT_BITRATE; 899 pComponentPrivate->pOutPortDef->format.video.xFramerate = VIDDEC_OUTPUT_PORT_FRAMERATE; 900 pComponentPrivate->pOutPortDef->format.video.bFlagErrorConcealment = VIDDEC_OUTPUT_PORT_FLAGERRORCONCEALMENT; 901 pComponentPrivate->pOutPortDef->format.video.eCompressionFormat = VIDDEC_OUTPUT_PORT_COMPRESSIONFORMAT; 902 pComponentPrivate->pOutPortDef->format.video.eColorFormat = VIDDEC_COLORFORMAT420; 903#ifdef KHRONOS_1_1 904 pComponentPrivate->pOutPortDef->format.video.pNativeWindow = 0; 905#endif 906 for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) { 907 OMX_MALLOC_STRUCT(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount], VIDDEC_BUFFER_PRIVATE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]); 908 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr = NULL; 909 } 910 911 for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) { 912 OMX_MALLOC_STRUCT(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount], VIDDEC_BUFFER_PRIVATE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]); 913 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr = NULL; 914 } 915 916 /* Set pInPortFormat defaults */ 917 OMX_CONF_INIT_STRUCT(pComponentPrivate->pInPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE, pComponentPrivate->dbg); 918 pComponentPrivate->pInPortFormat->nPortIndex = VIDDEC_INPUT_PORT; 919 pComponentPrivate->pInPortFormat->nIndex = VIDDEC_DEFAULT_INPUT_INDEX_MPEG4; 920 pComponentPrivate->pInPortFormat->eCompressionFormat = VIDDEC_INPUT_PORT_COMPRESSIONFORMAT; 921 pComponentPrivate->pInPortFormat->eColorFormat = VIDDEC_COLORFORMATUNUSED; 922#ifdef KHRONOS_1_1 923 pComponentPrivate->pInPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 924#endif 925 926 /* Set pOutPortFormat defaults */ 927 OMX_CONF_INIT_STRUCT(pComponentPrivate->pOutPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE, pComponentPrivate->dbg); 928 pComponentPrivate->pOutPortFormat->nPortIndex = VIDDEC_OUTPUT_PORT; 929 pComponentPrivate->pOutPortFormat->nIndex = VIDDEC_DEFAULT_OUTPUT_INDEX_PLANAR420; 930 pComponentPrivate->pOutPortFormat->eCompressionFormat = VIDDEC_OUTPUT_PORT_COMPRESSIONFORMAT; 931 pComponentPrivate->pOutPortFormat->eColorFormat = VIDDEC_COLORFORMAT420; 932#ifdef KHRONOS_1_1 933 pComponentPrivate->pOutPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 934#endif 935 /* Set pPriorityMgmt defaults */ 936 OMX_CONF_INIT_STRUCT(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE, pComponentPrivate->dbg); 937 pComponentPrivate->pPriorityMgmt->nGroupPriority = -1; 938 pComponentPrivate->pPriorityMgmt->nGroupID = -1; 939 940 /* Buffer supplier setting */ 941 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->eSupplierSetting = OMX_BufferSupplyOutput; 942 943 /* Set pInBufSupplier defaults */ 944 OMX_CONF_INIT_STRUCT(pComponentPrivate->pInBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE , pComponentPrivate->dbg); 945 pComponentPrivate->pInBufSupplier->nPortIndex = VIDDEC_INPUT_PORT; 946 pComponentPrivate->pInBufSupplier->eBufferSupplier = VIDDEC_INPUT_PORT_BUFFERSUPPLIER; 947 948 /* Set pOutBufSupplier defaults */ 949 OMX_CONF_INIT_STRUCT(pComponentPrivate->pOutBufSupplier, OMX_PARAM_BUFFERSUPPLIERTYPE , pComponentPrivate->dbg); 950 pComponentPrivate->pOutBufSupplier->nPortIndex = VIDDEC_OUTPUT_PORT; 951 pComponentPrivate->pOutBufSupplier->eBufferSupplier = VIDDEC_OUTPUT_PORT_BUFFERSUPPLIER; 952 953#ifdef KHRONOS_1_1 954 /*MBError Reporting code */ 955 /* Set eMBErrorReport defaults */ 956 OMX_CONF_INIT_STRUCT(&pComponentPrivate->eMBErrorReport, OMX_CONFIG_MBERRORREPORTINGTYPE , pComponentPrivate->dbg); 957 pComponentPrivate->eMBErrorReport.nPortIndex = VIDDEC_OUTPUT_PORT; 958 pComponentPrivate->eMBErrorReport.bEnabled = OMX_FALSE; 959 /*MBError Reporting code */ 960 /* Set eMBErrorMapType defaults */ 961 for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) { 962 OMX_CONF_INIT_STRUCT(&pComponentPrivate->eMBErrorMapType[iCount], OMX_CONFIG_MACROBLOCKERRORMAPTYPE_TI , pComponentPrivate->dbg); 963 pComponentPrivate->eMBErrorMapType[iCount].nPortIndex = VIDDEC_OUTPUT_PORT; 964 pComponentPrivate->eMBErrorMapType[iCount].nErrMapSize = (VIDDEC_DEFAULT_WIDTH * VIDDEC_DEFAULT_HEIGHT) / 256; 965 } 966 pComponentPrivate->cMBErrorIndexIn = 0; 967 pComponentPrivate->cMBErrorIndexOut = 0; 968 969#endif 970 971 /* Set pMpeg4 defaults */ 972 OMX_CONF_INIT_STRUCT (pComponentPrivate->pMpeg4, OMX_VIDEO_PARAM_MPEG4TYPE, pComponentPrivate->dbg); 973 pComponentPrivate->pMpeg4->nPortIndex = VIDDEC_DEFAULT_MPEG4_PORTINDEX; 974 pComponentPrivate->pMpeg4->nSliceHeaderSpacing = VIDDEC_DEFAULT_MPEG4_SLICEHEADERSPACING; 975 pComponentPrivate->pMpeg4->bSVH = VIDDEC_DEFAULT_MPEG4_SVH; 976 pComponentPrivate->pMpeg4->bGov = VIDDEC_DEFAULT_MPEG4_GOV; 977 pComponentPrivate->pMpeg4->nPFrames = VIDDEC_DEFAULT_MPEG4_PFRAMES; 978 pComponentPrivate->pMpeg4->nBFrames = VIDDEC_DEFAULT_MPEG4_BFRAMES; 979 pComponentPrivate->pMpeg4->nIDCVLCThreshold = VIDDEC_DEFAULT_MPEG4_IDCVLCTHRESHOLD; 980 pComponentPrivate->pMpeg4->bACPred = VIDDEC_DEFAULT_MPEG4_ACPRED; 981 pComponentPrivate->pMpeg4->nMaxPacketSize = VIDDEC_DEFAULT_MPEG4_MAXPACKETSIZE; 982 pComponentPrivate->pMpeg4->nTimeIncRes = VIDDEC_DEFAULT_MPEG4_TIMEINCRES; 983 pComponentPrivate->pMpeg4->eProfile = VIDDEC_DEFAULT_MPEG4_PROFILE; 984 pComponentPrivate->pMpeg4->eLevel = VIDDEC_DEFAULT_MPEG4_LEVEL; 985 pComponentPrivate->pMpeg4->nAllowedPictureTypes = VIDDEC_DEFAULT_MPEG4_ALLOWEDPICTURETYPES; 986 pComponentPrivate->pMpeg4->nHeaderExtension = VIDDEC_DEFAULT_MPEG4_HEADEREXTENSION; 987 pComponentPrivate->pMpeg4->bReversibleVLC = VIDDEC_DEFAULT_MPEG4_REVERSIBLEVLC; 988 989 /* Set pMpeg2 defaults */ 990 OMX_CONF_INIT_STRUCT (pComponentPrivate->pMpeg2, OMX_VIDEO_PARAM_MPEG2TYPE, pComponentPrivate->dbg); 991 pComponentPrivate->pMpeg2->nPortIndex = VIDDEC_DEFAULT_MPEG2_PORTINDEX; 992 pComponentPrivate->pMpeg2->nPFrames = VIDDEC_DEFAULT_MPEG2_PFRAMES; 993 pComponentPrivate->pMpeg2->nBFrames = VIDDEC_DEFAULT_MPEG2_BFRAMES; 994 pComponentPrivate->pMpeg2->eProfile = VIDDEC_DEFAULT_MPEG2_PROFILE; 995 pComponentPrivate->pMpeg2->eLevel = VIDDEC_DEFAULT_MPEG2_LEVEL; 996 997 /* Set pH264 defaults */ 998 OMX_CONF_INIT_STRUCT(pComponentPrivate->pH264, OMX_VIDEO_PARAM_AVCTYPE, pComponentPrivate->dbg); 999 pComponentPrivate->pH264->nPortIndex = VIDDEC_DEFAULT_H264_PORTINDEX; 1000 pComponentPrivate->pH264->nSliceHeaderSpacing = VIDDEC_DEFAULT_H264_SLICEHEADERSPACING; 1001 pComponentPrivate->pH264->nPFrames = VIDDEC_DEFAULT_H264_PFRAMES; 1002 pComponentPrivate->pH264->nBFrames = VIDDEC_DEFAULT_H264_BFRAMES; 1003 pComponentPrivate->pH264->bUseHadamard = VIDDEC_DEFAULT_H264_USEHADAMARD; 1004 pComponentPrivate->pH264->nRefFrames = VIDDEC_DEFAULT_H264_REFFRAMES; 1005 pComponentPrivate->pH264->nRefIdx10ActiveMinus1 = VIDDEC_DEFAULT_H264_REFIDX10ACTIVEMINUS1; 1006 pComponentPrivate->pH264->nRefIdx11ActiveMinus1 = VIDDEC_DEFAULT_H264_REFIDX11ACTIVEMINUS1; 1007 pComponentPrivate->pH264->bEnableUEP = VIDDEC_DEFAULT_H264_ENABLEUEP; 1008 pComponentPrivate->pH264->bEnableFMO = VIDDEC_DEFAULT_H264_ENABLEFMO; 1009 pComponentPrivate->pH264->bEnableASO = VIDDEC_DEFAULT_H264_ENABLEASO; 1010 pComponentPrivate->pH264->bEnableRS = VIDDEC_DEFAULT_H264_ENABLERS; 1011 pComponentPrivate->pH264->eProfile = VIDDEC_DEFAULT_H264_PROFILE; 1012 pComponentPrivate->pH264->eLevel = VIDDEC_DEFAULT_H264_LEVEL; 1013 pComponentPrivate->pH264->nAllowedPictureTypes = VIDDEC_DEFAULT_H264_ALLOWEDPICTURETYPES; 1014 pComponentPrivate->pH264->bFrameMBsOnly = VIDDEC_DEFAULT_H264_FRAMEMBSONLY; 1015 pComponentPrivate->pH264->bMBAFF = VIDDEC_DEFAULT_H264_MBAFF; 1016 pComponentPrivate->pH264->bEntropyCodingCABAC = VIDDEC_DEFAULT_H264_ENTROPYCODINGCABAC; 1017 pComponentPrivate->pH264->bWeightedPPrediction = VIDDEC_DEFAULT_H264_WEIGHTEDPPREDICTION; 1018 pComponentPrivate->pH264->nWeightedBipredicitonMode = VIDDEC_DEFAULT_H264_WEIGHTEDBIPREDICITONMODE; 1019 pComponentPrivate->pH264->bconstIpred = VIDDEC_DEFAULT_H264_CONSTIPRED; 1020 pComponentPrivate->pH264->bDirect8x8Inference = VIDDEC_DEFAULT_H264_DIRECT8X8INFERENCE; 1021 pComponentPrivate->pH264->bDirectSpatialTemporal = VIDDEC_DEFAULT_H264_DIRECTSPATIALTEMPORAL; 1022 pComponentPrivate->pH264->nCabacInitIdc = VIDDEC_DEFAULT_H264_CABACINITIDC; 1023 pComponentPrivate->pH264->eLoopFilterMode = VIDDEC_DEFAULT_H264_LOOPFILTERMODE; 1024 pComponentPrivate->H264BitStreamFormat = VIDDEC_DEFAULT_H264BITSTRMFMT; 1025 1026 pComponentPrivate->pH263->nPortIndex = VIDDEC_DEFAULT_H263_PORTINDEX; 1027 pComponentPrivate->pH263->nPFrames = VIDDEC_DEFAULT_H263_PFRAMES; 1028 pComponentPrivate->pH263->nBFrames = VIDDEC_DEFAULT_H263_BFRAMES; 1029 pComponentPrivate->pH263->eProfile = VIDDEC_DEFAULT_H263_PROFILE; 1030 pComponentPrivate->pH263->eLevel = VIDDEC_DEFAULT_H263_LEVEL; 1031 pComponentPrivate->pH263->bPLUSPTYPEAllowed = VIDDEC_DEFAULT_H263_PLUSPTYPEALLOWED; 1032 pComponentPrivate->pH263->nAllowedPictureTypes = VIDDEC_DEFAULT_H263_ALLOWEDPICTURETYPES; 1033 pComponentPrivate->pH263->bForceRoundingTypeToZero = VIDDEC_DEFAULT_H263_FORCEROUNDINGTYPETOZERO; 1034 pComponentPrivate->pH263->nPictureHeaderRepetition = VIDDEC_DEFAULT_H263_PICTUREHEADERREPETITION; 1035 pComponentPrivate->pH263->nGOBHeaderInterval = VIDDEC_DEFAULT_H263_GOBHEADERINTERVAL; 1036 1037 OMX_CONF_INIT_STRUCT(pComponentPrivate->pWMV, OMX_VIDEO_PARAM_WMVTYPE, pComponentPrivate->dbg); 1038 pComponentPrivate->pWMV->nPortIndex = VIDDEC_DEFAULT_WMV_PORTINDEX; 1039 pComponentPrivate->pWMV->eFormat = VIDDEC_DEFAULT_WMV_FORMAT; 1040 pComponentPrivate->nWMVFileType = VIDDEC_WMV_RCVSTREAM; /* RCVSTREAM must be the default value*/ 1041 pComponentPrivate->wmvProfile = VIDDEC_WMV_PROFILEMAX; 1042#ifdef UNDER_CE 1043 pComponentPrivate->bIsNALBigEndian = OMX_TRUE; 1044#else 1045 pComponentPrivate->bIsNALBigEndian = OMX_FALSE; 1046#endif 1047 pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload; 1048 pComponentPrivate->bLCMLHalted = OMX_TRUE; 1049#ifndef UNDER_CE 1050 pComponentPrivate->bLCMLOut = OMX_FALSE; 1051#endif 1052 pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Unload; 1053 pComponentPrivate->ProcessMode = VIDDEC_DEFAULT_PROCESSMODE; 1054 pComponentPrivate->bParserEnabled = OMX_TRUE; 1055 1056 VIDDEC_CircBuf_Init(pComponentPrivate, VIDDEC_CBUFFER_TIMESTAMP, VIDDEC_INPUT_PORT); 1057#ifndef UNDER_CE 1058 VIDDEC_PTHREAD_MUTEX_INIT(pComponentPrivate->sMutex); 1059 VIDDEC_PTHREAD_SEMAPHORE_INIT(pComponentPrivate->sInSemaphore); 1060 VIDDEC_PTHREAD_SEMAPHORE_INIT(pComponentPrivate->sOutSemaphore); 1061#endif 1062 for (iCount = 0; iCount < CBUFFER_SIZE; iCount++) { 1063 pComponentPrivate->aBufferFlags[iCount].nTimeStamp = 0; 1064 pComponentPrivate->aBufferFlags[iCount].nFlags = 0; 1065 pComponentPrivate->aBufferFlags[iCount].pMarkData = NULL; 1066 pComponentPrivate->aBufferFlags[iCount].hMarkTargetComponent = NULL; 1067 } 1068 pComponentPrivate->pBufferRCV.sStructRCV.nNumFrames = 0xFFFFFF; /*Infinite frame number*/ 1069 pComponentPrivate->pBufferRCV.sStructRCV.nFrameType = 0x85; /*85*/ 1070 pComponentPrivate->pBufferRCV.sStructRCV.nID = 0x04; /*WMV3*/ 1071 pComponentPrivate->pBufferRCV.sStructRCV.nStructData = 0x018a3106; /*0x06318a01zero fill 0x018a3106*/ 1072 pComponentPrivate->pBufferRCV.sStructRCV.nVertSize = 352; /*720*/ 1073 pComponentPrivate->pBufferRCV.sStructRCV.nHorizSize = 288; /*576*/ 1074 OMX_CONF_INIT_STRUCT( &pComponentPrivate->pBufferTemp, OMX_BUFFERHEADERTYPE, pComponentPrivate->dbg); 1075 pComponentPrivate->pBufferTemp.nFilledLen = sizeof(VIDDEC_WMV_RCV_header); 1076 pComponentPrivate->pBufferTemp.nAllocLen = sizeof(VIDDEC_WMV_RCV_header); 1077 1078#ifdef ANDROID 1079 /*Set PV (opencore) capability flags*/ 1080 pComponentPrivate->pPVCapabilityFlags->iIsOMXComponentMultiThreaded = OMX_TRUE; 1081 pComponentPrivate->pPVCapabilityFlags->iOMXComponentSupportsExternalOutputBufferAlloc = OMX_TRUE; 1082 pComponentPrivate->pPVCapabilityFlags->iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE; 1083 pComponentPrivate->pPVCapabilityFlags->iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; 1084 pComponentPrivate->pPVCapabilityFlags->iOMXComponentSupportsPartialFrames = OMX_FALSE; 1085 pComponentPrivate->pPVCapabilityFlags->iOMXComponentCanHandleIncompleteFrames = OMX_FALSE; 1086 1087 1088 if (pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat == 0) { 1089 /* frame mode + bytestream */ 1090 pComponentPrivate->pPVCapabilityFlags->iOMXComponentUsesNALStartCodes = OMX_TRUE; 1091 } 1092 else if (pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat >= 1) { 1093 /* frame mode + NAL-bitstream */ 1094 pComponentPrivate->pPVCapabilityFlags->iOMXComponentUsesNALStartCodes = OMX_FALSE; 1095 } 1096 else if (pComponentPrivate->ProcessMode == 1 && pComponentPrivate->H264BitStreamFormat == 0) { 1097 /* stream mode + bytestream */ 1098 pComponentPrivate->pPVCapabilityFlags->iOMXComponentUsesNALStartCodes = OMX_TRUE; 1099 } 1100 else if (pComponentPrivate->ProcessMode == 1 && pComponentPrivate->H264BitStreamFormat >= 1) { 1101 /* stream mode + NAL-bitstream */ 1102 /* not supported */ 1103 } 1104 else { 1105 } 1106 1107 if (pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat == 0) { 1108 /* frame mode + bytestream */ 1109 pComponentPrivate->pPVCapabilityFlags->iOMXComponentUsesFullAVCFrames = OMX_TRUE; 1110 } 1111 else if (pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat >= 1) { 1112 /* frame mode + NAL-bitstream */ 1113 pComponentPrivate->pPVCapabilityFlags->iOMXComponentUsesFullAVCFrames = OMX_TRUE; 1114 } 1115 else if (pComponentPrivate->ProcessMode == 1 && pComponentPrivate->H264BitStreamFormat == 0) { 1116 /* stream mode + bytestream */ 1117 pComponentPrivate->pPVCapabilityFlags->iOMXComponentUsesFullAVCFrames = OMX_FALSE; 1118 } 1119 else if (pComponentPrivate->ProcessMode == 1 && pComponentPrivate->H264BitStreamFormat >= 1) { 1120 /* stream mode + NAL-bitstream */ 1121 /* not supported */ 1122 } 1123 else { 1124 } 1125#endif 1126 /* Set default deblocking value for default format MPEG4 */ 1127 OMX_CONF_INIT_STRUCT(pComponentPrivate->pDeblockingParamType, OMX_PARAM_DEBLOCKINGTYPE, pComponentPrivate->dbg); 1128 pComponentPrivate->pDeblockingParamType->nPortIndex = VIDDEC_OUTPUT_PORT; 1129 pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_FALSE; 1130 1131 1132 case VIDDEC_INIT_VARS: 1133 /* Set the process mode to zero, frame = 0, stream = 1 */ 1134 VIDDEC_CircBuf_Flush(pComponentPrivate, VIDDEC_CBUFFER_TIMESTAMP, VIDDEC_INPUT_PORT); 1135 pComponentPrivate->bIsPaused = 0; 1136 pComponentPrivate->bIsStopping = 0; 1137 pComponentPrivate->bFirstBuffer = 1; 1138 pComponentPrivate->eIdleToLoad = OMX_StateInvalid; 1139 pComponentPrivate->iEndofInputSent = 0; 1140 pComponentPrivate->nInputBCountDsp = 0; 1141 pComponentPrivate->nOutputBCountDsp = 0; 1142 pComponentPrivate->nInputBCountApp = 0; 1143 pComponentPrivate->nOutputBCountApp = 0; 1144 pComponentPrivate->frameCounter = 0; 1145 pComponentPrivate->bMult16Size = OMX_FALSE; 1146 pComponentPrivate->bFlushOut = OMX_FALSE; 1147 pComponentPrivate->nBytesConsumed = 0; 1148 pComponentPrivate->bBuffMarkTaked = OMX_FALSE; 1149 pComponentPrivate->bBuffalreadyMarked = OMX_FALSE; 1150 pComponentPrivate->bFirstHeader = OMX_FALSE; 1151 pComponentPrivate->nDisplayWidth = 0; 1152 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1] = 0; 1153 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel2] = 0; 1154 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel3] = 0; 1155 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4] = 0; 1156 pComponentPrivate->bVC1Fix = OMX_TRUE; 1157 pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL; 1158 pComponentPrivate->eFirstBuffer.bSaveFirstBuffer = OMX_FALSE; 1159 pComponentPrivate->eFirstBuffer.nFilledLen = 0; 1160 pComponentPrivate->bDynamicConfigurationInProgress = OMX_FALSE; 1161 pComponentPrivate->nInternalConfigBufferFilledAVC = 0; 1162 pComponentPrivate->eMBErrorReport.bEnabled = OMX_FALSE; 1163 break; 1164 1165case VIDDEC_INIT_IDLEEXECUTING: 1166 /* Set the process mode to zero, frame = 0, stream = 1 */ 1167 pComponentPrivate->bIsPaused = 0; 1168 pComponentPrivate->bIsStopping = 0; 1169 pComponentPrivate->bFirstBuffer = 1; 1170 pComponentPrivate->iEndofInputSent = 0; 1171 pComponentPrivate->nInputBCountDsp = 0; 1172 pComponentPrivate->nOutputBCountDsp = 0; 1173 pComponentPrivate->nInputBCountApp = 0; 1174 pComponentPrivate->nOutputBCountApp = 0; 1175 pComponentPrivate->frameCounter = 0; 1176 pComponentPrivate->bMult16Size = OMX_FALSE; 1177 pComponentPrivate->bFlushOut = OMX_FALSE; 1178 pComponentPrivate->bFirstHeader = OMX_FALSE; 1179 pComponentPrivate->nInBufIndex = 0; 1180 pComponentPrivate->nOutBufIndex = 0; 1181 pComponentPrivate->nInMarkBufIndex = 0; 1182 pComponentPrivate->nOutMarkBufIndex = 0; 1183 pComponentPrivate->nInCmdMarkBufIndex = 0; 1184 pComponentPrivate->nOutCmdMarkBufIndex = 0; 1185 break; 1186 1187 case VIDDEC_INIT_H263: 1188 pComponentPrivate->pH263->nPortIndex = VIDDEC_DEFAULT_H263_PORTINDEX; 1189 pComponentPrivate->pH263->nPFrames = VIDDEC_DEFAULT_H263_PFRAMES; 1190 pComponentPrivate->pH263->nBFrames = VIDDEC_DEFAULT_H263_BFRAMES; 1191 pComponentPrivate->pH263->eProfile = OMX_VIDEO_H263ProfileBaseline; 1192 pComponentPrivate->pH263->eLevel = OMX_VIDEO_H263Level10; 1193 pComponentPrivate->pH263->bPLUSPTYPEAllowed = VIDDEC_DEFAULT_H263_PLUSPTYPEALLOWED; 1194 pComponentPrivate->pH263->nAllowedPictureTypes = VIDDEC_DEFAULT_H263_ALLOWEDPICTURETYPES; 1195 pComponentPrivate->pH263->bForceRoundingTypeToZero = VIDDEC_DEFAULT_H263_FORCEROUNDINGTYPETOZERO; 1196 pComponentPrivate->pH263->nPictureHeaderRepetition = VIDDEC_DEFAULT_H263_PICTUREHEADERREPETITION; 1197 pComponentPrivate->pH263->nGOBHeaderInterval = VIDDEC_DEFAULT_H263_GOBHEADERINTERVAL; 1198 1199 pComponentPrivate->pInPortFormat->nPortIndex = VIDDEC_INPUT_PORT; 1200 pComponentPrivate->pInPortFormat->nIndex = VIDDEC_DEFAULT_INPUT_INDEX_H263; 1201 pComponentPrivate->pInPortFormat->eCompressionFormat = OMX_VIDEO_CodingH263; 1202 pComponentPrivate->pInPortFormat->eColorFormat = OMX_COLOR_FormatUnused; 1203#ifdef KHRONOS_1_1 1204 pComponentPrivate->pInPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1205#endif 1206 pComponentPrivate->pInPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 1207 pComponentPrivate->pInPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 1208 pComponentPrivate->pInPortDef->format.video.nBitrate = VIDDEC_INPUT_PORT_BITRATE; 1209 pComponentPrivate->pInPortDef->format.video.xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1210 pComponentPrivate->pInPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingH263; 1211 pComponentPrivate->pInPortDef->format.video.eColorFormat = OMX_COLOR_FormatUnused; 1212 pComponentPrivate->pInPortDef->nBufferSize = pComponentPrivate->pInPortDef->format.video.nFrameWidth * 1213 pComponentPrivate->pInPortDef->format.video.nFrameHeight * 1214 VIDDEC_FACTORFORMAT420; 1215 pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_FALSE; 1216 pComponentPrivate->bIsSparkInput = OMX_FALSE; 1217 break; 1218#ifdef VIDDEC_SPARK_CODE 1219 case VIDDEC_INIT_SPARK: 1220 pComponentPrivate->pInPortFormat->nPortIndex = VIDDEC_INPUT_PORT; 1221 pComponentPrivate->pInPortFormat->nIndex = VIDDEC_DEFAULT_INPUT_INDEX_H263; 1222 pComponentPrivate->pInPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; 1223 pComponentPrivate->pInPortFormat->eColorFormat = OMX_COLOR_FormatUnused; 1224#ifdef KHRONOS_1_1 1225 pComponentPrivate->pInPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1226#endif 1227 pComponentPrivate->pInPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 1228 pComponentPrivate->pInPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 1229 pComponentPrivate->pInPortDef->format.video.nBitrate = VIDDEC_INPUT_PORT_BITRATE; 1230 pComponentPrivate->pInPortDef->format.video.xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1231 pComponentPrivate->pInPortDef->format.video.eCompressionFormat = pComponentPrivate->pInPortFormat->eCompressionFormat; 1232 pComponentPrivate->pInPortDef->format.video.eColorFormat = pComponentPrivate->pInPortFormat->eColorFormat; 1233 pComponentPrivate->pInPortDef->nBufferSize = pComponentPrivate->pInPortDef->format.video.nFrameWidth * 1234 pComponentPrivate->pInPortDef->format.video.nFrameHeight * 1235 VIDDEC_FACTORFORMAT420; 1236 pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_FALSE; 1237 pComponentPrivate->bIsSparkInput = OMX_TRUE; 1238 break; 1239#endif 1240 1241 case VIDDEC_INIT_H264: 1242 pComponentPrivate->pH264->nPortIndex = VIDDEC_DEFAULT_H264_PORTINDEX; 1243 pComponentPrivate->pH264->nPFrames = VIDDEC_DEFAULT_H264_PFRAMES; 1244 pComponentPrivate->pH264->nBFrames = VIDDEC_DEFAULT_H264_BFRAMES; 1245 pComponentPrivate->pH264->eProfile = OMX_VIDEO_AVCProfileBaseline; 1246 pComponentPrivate->pH264->eLevel = OMX_VIDEO_AVCLevelMax; 1247 1248 pComponentPrivate->pInPortFormat->nPortIndex = VIDDEC_INPUT_PORT; 1249 pComponentPrivate->pInPortFormat->nIndex = VIDDEC_DEFAULT_INPUT_INDEX_H264; 1250 pComponentPrivate->pInPortFormat->eCompressionFormat = OMX_VIDEO_CodingAVC; 1251 pComponentPrivate->pInPortFormat->eColorFormat = OMX_COLOR_FormatUnused; 1252#ifdef KHRONOS_1_1 1253 pComponentPrivate->pInPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1254#endif 1255 pComponentPrivate->pInPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 1256 pComponentPrivate->pInPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 1257 pComponentPrivate->pInPortDef->format.video.nBitrate = VIDDEC_INPUT_PORT_BITRATE; 1258 pComponentPrivate->pInPortDef->format.video.xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1259 pComponentPrivate->pInPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; 1260 pComponentPrivate->pInPortDef->format.video.eColorFormat = OMX_COLOR_FormatUnused; 1261 pComponentPrivate->pInPortDef->nBufferSize = pComponentPrivate->pInPortDef->format.video.nFrameWidth * 1262 pComponentPrivate->pInPortDef->format.video.nFrameHeight * 1263 VIDDEC_FACTORFORMAT420; 1264 pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_TRUE; /* Always enable */ 1265 pComponentPrivate->bIsSparkInput = OMX_FALSE; 1266 break; 1267 1268 case VIDDEC_INIT_MPEG2: 1269 pComponentPrivate->pMpeg2->nPortIndex = VIDDEC_DEFAULT_MPEG2_PORTINDEX; 1270 pComponentPrivate->pMpeg2->nPFrames = VIDDEC_DEFAULT_MPEG2_PFRAMES; 1271 pComponentPrivate->pMpeg2->nBFrames = VIDDEC_DEFAULT_MPEG2_BFRAMES; 1272 pComponentPrivate->pMpeg2->eProfile = OMX_VIDEO_MPEG2ProfileSimple; 1273 pComponentPrivate->pMpeg2->eLevel = OMX_VIDEO_MPEG2LevelLL; 1274 1275 pComponentPrivate->pInPortFormat->nPortIndex = VIDDEC_INPUT_PORT; 1276 pComponentPrivate->pInPortFormat->nIndex = VIDDEC_DEFAULT_INPUT_INDEX_MPEG2; 1277 pComponentPrivate->pInPortFormat->eCompressionFormat = OMX_VIDEO_CodingMPEG2; 1278 pComponentPrivate->pInPortFormat->eColorFormat = OMX_COLOR_FormatUnused; 1279#ifdef KHRONOS_1_1 1280 pComponentPrivate->pInPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1281#endif 1282 pComponentPrivate->pInPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 1283 pComponentPrivate->pInPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 1284 pComponentPrivate->pInPortDef->format.video.nBitrate = VIDDEC_INPUT_PORT_BITRATE; 1285 pComponentPrivate->pInPortDef->format.video.xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1286 pComponentPrivate->pInPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG2; 1287 pComponentPrivate->pInPortDef->format.video.eColorFormat = OMX_COLOR_FormatUnused; 1288 pComponentPrivate->pInPortDef->nBufferSize = pComponentPrivate->pInPortDef->format.video.nFrameWidth * 1289 pComponentPrivate->pInPortDef->format.video.nFrameHeight * 1290 VIDDEC_FACTORFORMAT420; 1291 pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_FALSE; /*TODO: Verify with algo team*/ 1292 pComponentPrivate->bIsSparkInput = OMX_FALSE; 1293 break; 1294 1295 case VIDDEC_INIT_MPEG4: 1296 pComponentPrivate->pMpeg4->nPortIndex = VIDDEC_DEFAULT_MPEG4_PORTINDEX; 1297 pComponentPrivate->pMpeg4->nPFrames = VIDDEC_DEFAULT_MPEG4_PFRAMES; 1298 pComponentPrivate->pMpeg4->nBFrames = VIDDEC_DEFAULT_MPEG4_BFRAMES; 1299 pComponentPrivate->pMpeg4->eProfile = OMX_VIDEO_MPEG4ProfileSimple; 1300#ifdef KHRONOS_1_1 1301 pComponentPrivate->pMpeg4->eLevel = OMX_VIDEO_MPEG4Level1; 1302#else 1303 pComponentPrivate->pMpeg4->eLevel = OMX_VIDEO_MPEG4Levell; 1304#endif 1305 pComponentPrivate->pInPortFormat->nPortIndex = VIDDEC_INPUT_PORT; 1306 pComponentPrivate->pInPortFormat->nIndex = VIDDEC_DEFAULT_INPUT_INDEX_MPEG4; 1307 pComponentPrivate->pInPortFormat->eCompressionFormat = OMX_VIDEO_CodingMPEG4; 1308 pComponentPrivate->pInPortFormat->eColorFormat = OMX_COLOR_FormatUnused; 1309#ifdef KHRONOS_1_1 1310 pComponentPrivate->pInPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1311#endif 1312 pComponentPrivate->pInPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 1313 pComponentPrivate->pInPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 1314 pComponentPrivate->pInPortDef->format.video.nBitrate = VIDDEC_INPUT_PORT_BITRATE; 1315 pComponentPrivate->pInPortDef->format.video.xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1316 pComponentPrivate->pInPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4; 1317 pComponentPrivate->pInPortDef->format.video.eColorFormat = OMX_COLOR_FormatUnused; 1318 pComponentPrivate->pInPortDef->nBufferSize = pComponentPrivate->pInPortDef->format.video.nFrameWidth * 1319 pComponentPrivate->pInPortDef->format.video.nFrameHeight * 1320 VIDDEC_FACTORFORMAT420; 1321 pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_FALSE; 1322 pComponentPrivate->bIsSparkInput = OMX_FALSE; 1323 break; 1324 1325 case VIDDEC_INIT_WMV9: 1326 pComponentPrivate->pWMV->nPortIndex = VIDDEC_DEFAULT_WMV_PORTINDEX; 1327 pComponentPrivate->pWMV->eFormat = OMX_VIDEO_WMVFormat9; 1328 1329 pComponentPrivate->pInPortFormat->nPortIndex = VIDDEC_INPUT_PORT; 1330 pComponentPrivate->pInPortFormat->nIndex = VIDDEC_DEFAULT_INPUT_INDEX_WMV9; 1331 pComponentPrivate->pInPortFormat->eCompressionFormat = OMX_VIDEO_CodingWMV; 1332 pComponentPrivate->pInPortFormat->eColorFormat = OMX_COLOR_FormatUnused; 1333#ifdef KHRONOS_1_1 1334 pComponentPrivate->pInPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1335#endif 1336 pComponentPrivate->pInPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 1337 pComponentPrivate->pInPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 1338 pComponentPrivate->pInPortDef->format.video.nBitrate = VIDDEC_INPUT_PORT_BITRATE; 1339 pComponentPrivate->pInPortDef->format.video.xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1340 pComponentPrivate->pInPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingWMV; 1341 pComponentPrivate->pInPortDef->format.video.eColorFormat = OMX_COLOR_FormatUnused; 1342 pComponentPrivate->pInPortDef->nBufferSize = pComponentPrivate->pInPortDef->format.video.nFrameWidth * 1343 pComponentPrivate->pInPortDef->format.video.nFrameHeight * 1344 VIDDEC_FACTORFORMAT420; 1345 1346 pComponentPrivate->nWMVFileType = VIDDEC_WMV_RCVSTREAM; /* RCVSTREAM must be the default value*/ 1347 pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_TRUE; /* Always enable */ 1348 pComponentPrivate->bIsSparkInput = OMX_FALSE; 1349 break; 1350 1351 case VIDDEC_INIT_PLANAR420: 1352 1353 pComponentPrivate->pOutPortFormat->nPortIndex = VIDDEC_OUTPUT_PORT; 1354 pComponentPrivate->pOutPortFormat->nIndex = VIDDEC_DEFAULT_OUTPUT_INDEX_PLANAR420; 1355 pComponentPrivate->pOutPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; 1356 pComponentPrivate->pOutPortFormat->eColorFormat = VIDDEC_COLORFORMAT420; 1357#ifdef KHRONOS_1_1 1358 pComponentPrivate->pOutPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1359#endif 1360 pComponentPrivate->pOutPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 1361 pComponentPrivate->pOutPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 1362 pComponentPrivate->pOutPortDef->format.video.nBitrate = VIDDEC_OUTPUT_PORT_BITRATE; 1363 pComponentPrivate->pOutPortDef->format.video.xFramerate = VIDDEC_OUTPUT_PORT_FRAMERATE; 1364 pComponentPrivate->pOutPortDef->format.video.eCompressionFormat = VIDDEC_OUTPUT_PORT_COMPRESSIONFORMAT; 1365 pComponentPrivate->pOutPortDef->format.video.eColorFormat = VIDDEC_COLORFORMAT420; 1366 pComponentPrivate->pOutPortDef->nBufferSize = pComponentPrivate->pOutPortDef->format.video.nFrameWidth * 1367 pComponentPrivate->pOutPortDef->format.video.nFrameHeight * 1368 VIDDEC_FACTORFORMAT420; 1369 1370 break; 1371 1372 case VIDDEC_INIT_INTERLEAVED422: 1373 pComponentPrivate->pOutPortFormat->nPortIndex = VIDDEC_OUTPUT_PORT; 1374 pComponentPrivate->pOutPortFormat->nIndex = VIDDEC_DEFAULT_OUTPUT_INDEX_INTERLEAVED422; 1375 pComponentPrivate->pOutPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; 1376 pComponentPrivate->pOutPortFormat->eColorFormat = VIDDEC_COLORFORMAT422; 1377#ifdef KHRONOS_1_1 1378 pComponentPrivate->pOutPortFormat->xFramerate = VIDDEC_INPUT_PORT_FRAMERATE; 1379#endif 1380 pComponentPrivate->pOutPortDef->format.video.nFrameWidth = VIDDEC_DEFAULT_WIDTH; 1381 pComponentPrivate->pOutPortDef->format.video.nFrameHeight = VIDDEC_DEFAULT_HEIGHT; 1382 pComponentPrivate->pOutPortDef->format.video.nBitrate = VIDDEC_OUTPUT_PORT_BITRATE; 1383 pComponentPrivate->pOutPortDef->format.video.xFramerate = VIDDEC_OUTPUT_PORT_FRAMERATE; 1384 pComponentPrivate->pOutPortDef->format.video.eCompressionFormat = VIDDEC_OUTPUT_PORT_COMPRESSIONFORMAT; 1385 pComponentPrivate->pOutPortDef->format.video.eColorFormat = VIDDEC_COLORFORMAT422; 1386 pComponentPrivate->pOutPortDef->nBufferSize = pComponentPrivate->pOutPortDef->format.video.nFrameWidth * 1387 pComponentPrivate->pOutPortDef->format.video.nFrameHeight * 1388 VIDDEC_FACTORFORMAT422; 1389 1390 break; 1391 1392 } 1393 1394EXIT: 1395 return(eError); 1396} 1397 1398/*----------------------------------------------------------------------------*/ 1399/** 1400 * VIDDEC_Start_ComponentThread() starts the component thread and all the pipes 1401 * to achieve communication between dsp and application for commands and buffer 1402 * interchanging 1403 **/ 1404/*----------------------------------------------------------------------------*/ 1405OMX_ERRORTYPE VIDDEC_Start_ComponentThread(OMX_HANDLETYPE hComponent) 1406{ 1407 OMX_ERRORTYPE eError = OMX_ErrorNone; 1408 OMX_COMPONENTTYPE* pComp = (OMX_COMPONENTTYPE*)hComponent; 1409 VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pComp->pComponentPrivate; 1410 1411 pComponentPrivate->bIsStopping = 0; 1412 1413 OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n"); 1414 /* create the pipe used to maintain free input buffers*/ 1415 eError = pipe(pComponentPrivate->free_inpBuf_Q); 1416 if (eError) { 1417 eError = OMX_ErrorInsufficientResources; 1418 goto EXIT; 1419 } 1420 1421 /* create the pipe used to maintain free input buffers*/ 1422 eError = pipe(pComponentPrivate->free_outBuf_Q); 1423 if (eError) { 1424 eError = OMX_ErrorInsufficientResources; 1425 goto EXIT; 1426 } 1427 1428 /* create the pipe used to maintain input buffers*/ 1429 eError = pipe(pComponentPrivate->filled_inpBuf_Q); 1430 if (eError) { 1431 eError = OMX_ErrorInsufficientResources; 1432 goto EXIT; 1433 } 1434 1435 /* create the pipe used to maintain dsp output/encoded buffers*/ 1436 eError = pipe(pComponentPrivate->filled_outBuf_Q); 1437 if (eError) { 1438 eError = OMX_ErrorInsufficientResources; 1439 goto EXIT; 1440 } 1441 1442 /* create the pipe used to send commands to the thread */ 1443 eError = pipe(pComponentPrivate->cmdPipe); 1444 if (eError) { 1445 eError = OMX_ErrorInsufficientResources; 1446 goto EXIT; 1447 } 1448 1449 /* create the pipe used to send commands to the thread */ 1450 eError = pipe(pComponentPrivate->cmdDataPipe); 1451 if (eError) { 1452 eError = OMX_ErrorInsufficientResources; 1453 goto EXIT; 1454 } 1455 1456 /* Create the Component Thread */ 1457 eError = pthread_create(&(pComponentPrivate->ComponentThread), 1458 NULL, 1459 OMX_VidDec_Thread, 1460 pComponentPrivate); 1461 1462 OMX_TRACE2(pComponentPrivate->dbg, "pthread_create 0x%lx\n",(OMX_U32) pComponentPrivate->ComponentThread); 1463 if (eError || !pComponentPrivate->ComponentThread) { 1464 OMX_TRACE4(pComponentPrivate->dbg, "pthread_create 0x%x\n",eError); 1465 eError = OMX_ErrorInsufficientResources; 1466 goto EXIT; 1467 } 1468 1469#ifdef __PERF_INSTRUMENTATION__ 1470 PERF_ThreadCreated(pComponentPrivate->pPERF, 1471 pComponentPrivate->ComponentThread, 1472 PERF_FOURS("VD T")); 1473#endif 1474 1475EXIT: 1476 OMX_PRINT1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 1477 return eError; 1478} 1479 1480/* ========================================================================== */ 1481/** 1482* @Stop_ComponentThread() This function is called by the component during 1483* de-init to close component thread, Command pipe & data pipes. 1484* 1485* @param pComponent handle for this instance of the component 1486* 1487* @pre 1488* 1489* @post 1490* 1491* @return none 1492*/ 1493/* ========================================================================== */ 1494OMX_ERRORTYPE VIDDEC_Stop_ComponentThread(OMX_HANDLETYPE pComponent) 1495{ 1496 OMX_ERRORTYPE eError = OMX_ErrorNone; 1497 OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)pComponent; 1498 VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate; 1499 OMX_ERRORTYPE threadError = OMX_ErrorNone; 1500 OMX_ERRORTYPE err = OMX_ErrorNone; 1501 int pthreadError = 0; 1502 1503 /* Join the component thread */ 1504 OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n"); 1505 OMX_TRACE2(pComponentPrivate->dbg, "pthread_join 0x%lx\n",(OMX_U32) pComponentPrivate->ComponentThread); 1506 1507#ifdef UNDER_CE 1508 pthreadError = pthread_join(pComponentPrivate->ComponentThread, (void*)&threadError); 1509 if (0 != pthreadError) { 1510 eError = OMX_ErrorHardware; 1511 } 1512#else 1513 if(pComponentPrivate->bLCMLOut == OMX_TRUE) { 1514 /*pthreadError = pthread_cancel(pComponentPrivate->ComponentThread);*/ 1515 if (0 != pthreadError) { 1516 eError = OMX_ErrorHardware; 1517 } 1518 } 1519 else{ 1520 pthreadError = pthread_join(pComponentPrivate->ComponentThread, (void*)&threadError); 1521 if (0 != pthreadError) { 1522 eError = OMX_ErrorHardware; 1523 } 1524 } 1525#endif 1526 1527 /* Check for the errors */ 1528 if (OMX_ErrorNone != eError) { 1529 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1530 pComponentPrivate->pHandle->pApplicationPrivate, 1531 OMX_EventError, 1532 eError, 1533 OMX_TI_ErrorSevere, 1534 "Error while closing Component Thread\n"); 1535 } 1536 1537 /* close the data pipe handles */ 1538 err = close(pComponentPrivate->free_inpBuf_Q[VIDDEC_PIPE_READ]); 1539 if (0 != err) { 1540 eError = OMX_ErrorHardware; 1541 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1542 pComponentPrivate->pHandle->pApplicationPrivate, 1543 OMX_EventError, 1544 eError, 1545 OMX_TI_ErrorMajor, 1546 "Error while closing data pipe\n"); 1547 } 1548 1549 err = close(pComponentPrivate->free_outBuf_Q[VIDDEC_PIPE_READ]); 1550 if (0 != err) { 1551 eError = OMX_ErrorHardware; 1552 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1553 pComponentPrivate->pHandle->pApplicationPrivate, 1554 OMX_EventError, 1555 eError, 1556 OMX_TI_ErrorMajor, 1557 "Error while closing data pipe\n"); 1558 } 1559 1560 err = close(pComponentPrivate->filled_inpBuf_Q[VIDDEC_PIPE_READ]); 1561 if (0 != err) { 1562 eError = OMX_ErrorHardware; 1563 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1564 pComponentPrivate->pHandle->pApplicationPrivate, 1565 OMX_EventError, 1566 eError, 1567 OMX_TI_ErrorMajor, 1568 "Error while closing data pipe\n"); 1569 } 1570 1571 err = close(pComponentPrivate->filled_outBuf_Q[VIDDEC_PIPE_READ]); 1572 if (0 != err) { 1573 eError = OMX_ErrorHardware; 1574 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1575 pComponentPrivate->pHandle->pApplicationPrivate, 1576 OMX_EventError, 1577 eError, 1578 OMX_TI_ErrorMajor, 1579 "Error while closing data pipe\n"); 1580 } 1581 1582 err = close(pComponentPrivate->free_inpBuf_Q[VIDDEC_PIPE_WRITE]); 1583 if (0 != err) { 1584 eError = OMX_ErrorHardware; 1585 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1586 pComponentPrivate->pHandle->pApplicationPrivate, 1587 OMX_EventError, 1588 eError, 1589 OMX_TI_ErrorMajor, 1590 "Error while closing data pipe\n"); 1591 } 1592 1593 err = close(pComponentPrivate->free_outBuf_Q[VIDDEC_PIPE_WRITE]); 1594 if (0 != err) { 1595 eError = OMX_ErrorHardware; 1596 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1597 pComponentPrivate->pHandle->pApplicationPrivate, 1598 OMX_EventError, 1599 eError, 1600 OMX_TI_ErrorMajor, 1601 "Error while closing data pipe\n"); 1602 } 1603 1604 err = close(pComponentPrivate->filled_inpBuf_Q[VIDDEC_PIPE_WRITE]); 1605 if (0 != err) { 1606 eError = OMX_ErrorHardware; 1607 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1608 pComponentPrivate->pHandle->pApplicationPrivate, 1609 OMX_EventError, 1610 eError, 1611 OMX_TI_ErrorMajor, 1612 "Error while closing data pipe\n"); 1613 } 1614 1615 err = close(pComponentPrivate->filled_outBuf_Q[VIDDEC_PIPE_WRITE]); 1616 if (0 != err) { 1617 eError = OMX_ErrorHardware; 1618 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1619 pComponentPrivate->pHandle->pApplicationPrivate, 1620 OMX_EventError, 1621 eError, 1622 OMX_TI_ErrorMajor, 1623 "Error while closing data pipe\n"); 1624 } 1625 1626 /* Close the command pipe handles */ 1627 err = close(pComponentPrivate->cmdPipe[VIDDEC_PIPE_READ]); 1628 if (0 != err) { 1629 eError = OMX_ErrorHardware; 1630 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1631 pComponentPrivate->pHandle->pApplicationPrivate, 1632 OMX_EventError, 1633 eError, 1634 OMX_TI_ErrorMajor, 1635 "Error while closing cmd pipe\n"); 1636 } 1637 1638 err = close(pComponentPrivate->cmdPipe[VIDDEC_PIPE_WRITE]); 1639 if (0 != err) { 1640 eError = OMX_ErrorHardware; 1641 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1642 pComponentPrivate->pHandle->pApplicationPrivate, 1643 OMX_EventError, 1644 eError, 1645 OMX_TI_ErrorMajor, 1646 "Error while closing cmd pipe\n"); 1647 } 1648 1649 /* Close the command data pipe handles */ 1650 err = close (pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_READ]); 1651 if (0 != err) { 1652 eError = OMX_ErrorHardware; 1653 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1654 pComponentPrivate->pHandle->pApplicationPrivate, 1655 OMX_EventError, 1656 eError, 1657 OMX_TI_ErrorMajor, 1658 "Error while closing cmd pipe\n"); 1659 } 1660 1661 err = close (pComponentPrivate->cmdDataPipe[VIDDEC_PIPE_WRITE]); 1662 if (0 != err) { 1663 eError = OMX_ErrorHardware; 1664 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 1665 pComponentPrivate->pHandle->pApplicationPrivate, 1666 OMX_EventError, 1667 eError, 1668 OMX_TI_ErrorMajor, 1669 "Error while closing cmd pipe\n"); 1670 } 1671 OMX_PRINT1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 1672 return eError; 1673} 1674 1675/* ========================================================================== */ 1676/** 1677 * Disable Port() 1678 * 1679 * Called by component thread, handles commands sent by the app. 1680 * 1681 * @param 1682 * 1683 * @retval OMX_ErrorNone success, ready to roll 1684 * 1685 **/ 1686/* ========================================================================== */ 1687 1688OMX_ERRORTYPE VIDDEC_DisablePort (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1) 1689{ 1690 OMX_ERRORTYPE eError = OMX_ErrorNone; 1691 static OMX_BOOL bFirstTimeToUnLoadCodec = OMX_TRUE; /*Needed when port disable is been call for input & output ports*/ 1692 OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n"); 1693 OMX_PRINT1(pComponentPrivate->dbg, "pComponentPrivate 0x%p nParam1 0x%lx\n",pComponentPrivate, nParam1); 1694 1695 /* Protect VIDDEC_UnloadCodec() to be called twice while doing Dynamic port configuration*/ 1696 if(pComponentPrivate->bDynamicConfigurationInProgress && bFirstTimeToUnLoadCodec){ 1697 OMX_PRINT1(pComponentPrivate->dbg, "VIDDEC_UnloadCodec\n"); 1698 eError = VIDDEC_UnloadCodec(pComponentPrivate); 1699 if (eError != OMX_ErrorNone) { 1700 goto EXIT; 1701 } 1702 bFirstTimeToUnLoadCodec = OMX_FALSE; 1703 } 1704 1705 eError = VIDDEC_HandleCommandFlush(pComponentPrivate, -1, OMX_FALSE); 1706 1707 1708 1709#ifdef UNDER_CE 1710 while(1) { 1711 if (nParam1 == VIDDEC_INPUT_PORT && !pComponentPrivate->pInPortDef->bPopulated) { 1712 /* return cmdcomplete event if input unpopulated */ 1713 OMX_PRBUFFER2(pComponentPrivate->dbg, "Unpopulated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 1714 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1715 pComponentPrivate->pHandle->pApplicationPrivate, 1716 OMX_EventCmdComplete, 1717 OMX_CommandPortDisable, 1718 VIDDEC_INPUT_PORT, 1719 NULL); 1720 break; 1721 } 1722 else if (nParam1 == VIDDEC_OUTPUT_PORT && !pComponentPrivate->pOutPortDef->bPopulated) { 1723 /* return cmdcomplete event if output unpopulated */ 1724 OMX_PRBUFFER2(pComponentPrivate->dbg, "Unpopulated VIDDEC_OUTPUT_PORT OUT 0x%x\n",pComponentPrivate->pOutPortDef->bPopulated); 1725 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1726 pComponentPrivate->pHandle->pApplicationPrivate, 1727 OMX_EventCmdComplete, 1728 OMX_CommandPortDisable, 1729 VIDDEC_OUTPUT_PORT, 1730 NULL); 1731 break; 1732 } 1733 else if (nParam1 == VIDDEC_BOTH_PORT && !pComponentPrivate->pInPortDef->bPopulated && 1734 !pComponentPrivate->pOutPortDef->bPopulated) { 1735 /* return cmdcomplete event if inout & output unpopulated */ 1736 OMX_PRBUFFER2(pComponentPrivate->dbg, "Unpopulated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 1737 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1738 pComponentPrivate->pHandle->pApplicationPrivate, 1739 OMX_EventCmdComplete, 1740 OMX_CommandPortDisable, 1741 VIDDEC_INPUT_PORT, 1742 NULL); 1743 OMX_PRBUFFER2(pComponentPrivate->dbg, "Unpopulated VIDDEC_OUTPUT_PORT OUT 0x%x\n",pComponentPrivate->pOutPortDef->bPopulated); 1744 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1745 pComponentPrivate->pHandle->pApplicationPrivate, 1746 OMX_EventCmdComplete, 1747 OMX_CommandPortDisable, 1748 VIDDEC_OUTPUT_PORT, 1749 NULL); 1750 break; 1751 } 1752 else if (nParam1 == VIDDEC_BOTH_PORT && !pComponentPrivate->pInPortDef->bPopulated && 1753 (pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL)) { 1754 /* return cmdcomplete event if inout & output unpopulated */ 1755 OMX_PRBUFFER2(pComponentPrivate->dbg, "Unpopulated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 1756 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1757 pComponentPrivate->pHandle->pApplicationPrivate, 1758 OMX_EventCmdComplete, 1759 OMX_CommandPortDisable, 1760 VIDDEC_INPUT_PORT, 1761 NULL); 1762 break; 1763 } 1764 VIDDEC_WAIT_CODE(); 1765 } 1766#else 1767 if (nParam1 == VIDDEC_INPUT_PORT) { 1768 if((!(pComponentPrivate->eState == OMX_StateLoaded) && pComponentPrivate->pInPortDef->bPopulated) || 1769 pComponentPrivate->sInSemaphore.bSignaled) { 1770 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 1771 } 1772 OMX_PRBUFFER2(pComponentPrivate->dbg, "Unpopulated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 1773 pComponentPrivate->bInPortSettingsChanged = OMX_FALSE; 1774 OMX_PRBUFFER1(pComponentPrivate->dbg, "bInPortSettingsChanged = OMX_FALSE;\n"); 1775 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1776 pComponentPrivate->pHandle->pApplicationPrivate, 1777 OMX_EventCmdComplete, 1778 OMX_CommandPortDisable, 1779 VIDDEC_INPUT_PORT, 1780 NULL); 1781 } 1782 else if (nParam1 == VIDDEC_OUTPUT_PORT) { 1783 if((!(pComponentPrivate->eState == OMX_StateLoaded) && pComponentPrivate->pOutPortDef->bPopulated) || 1784 pComponentPrivate->sOutSemaphore.bSignaled) { 1785 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sOutSemaphore); 1786 } 1787 1788 OMX_PRBUFFER2(pComponentPrivate->dbg, "Unpopulated VIDDEC_OUTPUT_PORT OUT 0x%x\n",pComponentPrivate->pOutPortDef->bPopulated); 1789 OMX_PRBUFFER1(pComponentPrivate->dbg, "bOutPortSettingsChanged = OMX_FALSE;\n"); 1790 pComponentPrivate->bOutPortSettingsChanged = OMX_FALSE; 1791 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1792 pComponentPrivate->pHandle->pApplicationPrivate, 1793 OMX_EventCmdComplete, 1794 OMX_CommandPortDisable, 1795 VIDDEC_OUTPUT_PORT, 1796 NULL); 1797 } 1798 else if (nParam1 == OMX_ALL) { 1799 if(pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 1800 if((!(pComponentPrivate->eState == OMX_StateLoaded) && pComponentPrivate->pInPortDef->bPopulated) || 1801 pComponentPrivate->sInSemaphore.bSignaled) { 1802 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 1803 } 1804 OMX_PRBUFFER2(pComponentPrivate->dbg, "Unpopulated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 1805 pComponentPrivate->bInPortSettingsChanged = OMX_FALSE; 1806 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1807 pComponentPrivate->pHandle->pApplicationPrivate, 1808 OMX_EventCmdComplete, 1809 OMX_CommandPortDisable, 1810 VIDDEC_INPUT_PORT, 1811 NULL); 1812 } 1813 else { 1814 if((!(pComponentPrivate->eState == OMX_StateLoaded) && pComponentPrivate->pInPortDef->bPopulated) || 1815 pComponentPrivate->sInSemaphore.bSignaled) { 1816 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 1817 } 1818 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 1819 pComponentPrivate->bInPortSettingsChanged = OMX_FALSE; 1820 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1821 pComponentPrivate->pHandle->pApplicationPrivate, 1822 OMX_EventCmdComplete, 1823 OMX_CommandPortDisable, 1824 VIDDEC_INPUT_PORT, 1825 NULL); 1826 if((!(pComponentPrivate->eState == OMX_StateLoaded) && pComponentPrivate->pOutPortDef->bPopulated) || 1827 pComponentPrivate->sOutSemaphore.bSignaled) { 1828 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sOutSemaphore); 1829 } 1830 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_OUTPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 1831 pComponentPrivate->bOutPortSettingsChanged = OMX_FALSE; 1832 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1833 pComponentPrivate->pHandle->pApplicationPrivate, 1834 OMX_EventCmdComplete, 1835 OMX_CommandPortDisable, 1836 VIDDEC_OUTPUT_PORT, 1837 NULL); 1838 } 1839 } 1840#endif 1841 1842 /* Reset values to initial state*/ 1843 if(pComponentPrivate->bDynamicConfigurationInProgress){ 1844 if(pComponentPrivate->bOutPortSettingsChanged == OMX_FALSE && pComponentPrivate->bInPortSettingsChanged == OMX_FALSE){ 1845 pComponentPrivate->bDynamicConfigurationInProgress = OMX_FALSE; 1846 bFirstTimeToUnLoadCodec = OMX_TRUE; 1847 OMX_PRBUFFER1(pComponentPrivate->dbg, "bDynamicConfigurationInProgress = OMX_FALSE;\n"); 1848 } 1849 } 1850 1851EXIT: 1852 OMX_PRINT1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 1853 return eError; 1854} 1855 1856/* ========================================================================== */ 1857/** 1858 * Return Buffers() 1859 * 1860 * Called by Disable and Enable Buffers, return the buffers to their respective source. 1861 * 1862 * @param 1863 * 1864 * @retval OMX_ErrorNone success, ready to roll 1865 * 1866 **/ 1867/* ========================================================================== */ 1868OMX_ERRORTYPE VIDDEC_ReturnBuffers (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1, OMX_BOOL bRetDSP) 1869{ 1870 OMX_U8 i = 0; 1871 OMX_ERRORTYPE eError = OMX_ErrorNone; 1872 OMX_BUFFERHEADERTYPE *pBuffHead; 1873 1874 OMX_PRBUFFER1(pComponentPrivate->dbg, "+++ENTERING\n"); 1875 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate 0x%p nParam1 0x%lx bRetDSP 0x%x\n",pComponentPrivate,nParam1,bRetDSP); 1876 OMX_VidDec_Return(pComponentPrivate); 1877 OMX_VidDec_Return(pComponentPrivate); 1878 if (nParam1 == pComponentPrivate->pInPortFormat->nPortIndex || nParam1 == OMX_ALL) { 1879 for (i = 0; i < pComponentPrivate->pInPortDef->nBufferCountActual; i++) { 1880 if((pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->eBufferOwner == VIDDEC_BUFFER_WITH_DSP) && bRetDSP){ 1881 OMX_PRBUFFER1(pComponentPrivate->dbg, "inBuffer 0x%p eBufferOwner 0x%x\n",pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr, 1882 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->eBufferOwner); 1883 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 1884 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen = 0; 1885 1886#ifdef __PERF_INSTRUMENTATION__ 1887 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1888 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr->pBuffer, 1889 pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen, 1890 PERF_ModuleHLMM); 1891#endif 1892 1893 eError = pComponentPrivate->cbInfo.EmptyBufferDone((OMX_HANDLETYPE *)pComponentPrivate->pHandle, 1894 pComponentPrivate->pHandle->pApplicationPrivate, 1895 (OMX_BUFFERHEADERTYPE*)pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr); 1896 } 1897 } 1898 } 1899 if (nParam1 == pComponentPrivate->pOutPortFormat->nPortIndex || nParam1 == OMX_ALL) { 1900 if (pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->hTunnelComponent != NULL) { 1901 for (i = 0; i < pComponentPrivate->pOutPortDef->nBufferCountActual; i++) { 1902 OMX_PRBUFFER1(pComponentPrivate->dbg, "tunnelVideoDecBuffer[%x]=%x-%lx\n",i, 1903 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner,pComponentPrivate->pOutPortDef->nBufferCountActual); 1904 OMX_PRBUFFER1(pComponentPrivate->dbg, "enter return %lx\n",pComponentPrivate->pOutPortDef->nBufferCountActual); 1905 if((pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner == VIDDEC_BUFFER_WITH_DSP) && bRetDSP){ 1906 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner = VIDDEC_BUFFER_WITH_TUNNELEDCOMP; 1907 OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer 0x%x eBufferOwner 0x%x\n",(int)pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr 1908 ,pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner); 1909 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen = 0; 1910 1911#ifdef __PERF_INSTRUMENTATION__ 1912 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1913 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr->pBuffer, 1914 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen, 1915 PERF_ModuleLLMM); 1916#endif 1917 1918 OMX_PRBUFFER1(pComponentPrivate->dbg, "VideDec->PostProc EmptyThisBuffer\n"); 1919 OMX_PRBUFFER1(pComponentPrivate->dbg, "wait to return buffer\n"); 1920 pBuffHead = (OMX_BUFFERHEADERTYPE*)pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr; 1921 VIDDEC_Propagate_Mark(pComponentPrivate, pBuffHead); 1922 eError = OMX_EmptyThisBuffer(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->hTunnelComponent, pBuffHead); 1923 } 1924 } 1925 } 1926 else { 1927 OMX_PRINT1(pComponentPrivate->dbg, "non tunneling\n"); 1928 for (i = 0; i < pComponentPrivate->pOutPortDef->nBufferCountActual; i++) { 1929 if((pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner == VIDDEC_BUFFER_WITH_DSP) && bRetDSP){ 1930 OMX_PRBUFFER1(pComponentPrivate->dbg, "xBuffer 0x%p eBufferOwner 0x%x\n",pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr, 1931 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner); 1932 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 1933 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen = 0; 1934 1935#ifdef __PERF_INSTRUMENTATION__ 1936 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 1937 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr->pBuffer, 1938 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen, 1939 PERF_ModuleHLMM); 1940#endif 1941 1942 pBuffHead = (OMX_BUFFERHEADERTYPE*)pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr; 1943 VIDDEC_Propagate_Mark(pComponentPrivate, pBuffHead); 1944 eError = pComponentPrivate->cbInfo.FillBufferDone((OMX_HANDLETYPE *)pComponentPrivate->pHandle, 1945 pComponentPrivate->pHandle->pApplicationPrivate, 1946 (OMX_BUFFERHEADERTYPE*)pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr); 1947 } 1948 } 1949 } 1950 } 1951 OMX_PRBUFFER1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 1952 return eError; 1953} 1954 1955 1956/* ========================================================================== */ 1957/** 1958 * Enable Port() 1959 * 1960 * Called by component thread, handles commands sent by the app. 1961 * 1962 * @param 1963 * 1964 * @retval OMX_ErrorNone success, ready to roll 1965 * 1966 **/ 1967/* ========================================================================== */ 1968OMX_ERRORTYPE VIDDEC_EnablePort (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1) 1969{ 1970 OMX_ERRORTYPE eError = OMX_ErrorNone; 1971 OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n"); 1972 OMX_PRINT1(pComponentPrivate->dbg, "pComponentPrivate 0x%p nParam1 0x%lx\n",pComponentPrivate, nParam1); 1973 1974#ifdef UNDER_CE 1975 while(1) { 1976 if (nParam1 == VIDDEC_INPUT_PORT && (pComponentPrivate->eState == OMX_StateLoaded || pComponentPrivate->pInPortDef->bPopulated)) { 1977 /* return cmdcomplete event if input unpopulated */ 1978 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT 0x%x\n",pComponentPrivate->pInPortDef->bEnabled); 1979 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1980 pComponentPrivate->pHandle->pApplicationPrivate, 1981 OMX_EventCmdComplete, 1982 OMX_CommandPortEnable, 1983 VIDDEC_INPUT_PORT, 1984 NULL); 1985 break; 1986 } 1987 else if (nParam1 == VIDDEC_OUTPUT_PORT && (pComponentPrivate->eState == OMX_StateLoaded || 1988 pComponentPrivate->pOutPortDef->bPopulated)) { 1989 /* return cmdcomplete event if output unpopulated */ 1990 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_OUTPUT_PORT 0x%x\n",pComponentPrivate->pOutPortDef->bEnabled); 1991 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 1992 pComponentPrivate->pHandle->pApplicationPrivate, 1993 OMX_EventCmdComplete, 1994 OMX_CommandPortEnable, 1995 VIDDEC_OUTPUT_PORT, 1996 NULL); 1997 break; 1998 } 1999 else if (nParam1 == VIDDEC_BOTH_PORT && (pComponentPrivate->eState == OMX_StateLoaded || 2000 (pComponentPrivate->pInPortDef->bPopulated && 2001 pComponentPrivate->pOutPortDef->bPopulated))) { 2002 /* return cmdcomplete event if inout & output unpopulated */ 2003 OMX_PRBUFFER2(pComponentPrivate->dbg, "Enabling VIDDEC_OUTPUT_PORT 0x%x\n",pComponentPrivate->pOutPortDef->bEnabled); 2004 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT 0x%x\n",pComponentPrivate->pOutPortDef->bEnabled); 2005 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2006 pComponentPrivate->pHandle->pApplicationPrivate, 2007 OMX_EventCmdComplete, 2008 OMX_CommandPortEnable, 2009 VIDDEC_INPUT_PORT, 2010 NULL); 2011 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_OUTPUT_PORT 0x%x\n",pComponentPrivate->pOutPortDef->bEnabled); 2012 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2013 pComponentPrivate->pHandle->pApplicationPrivate, 2014 OMX_EventCmdComplete, 2015 OMX_CommandPortEnable, 2016 VIDDEC_OUTPUT_PORT, 2017 NULL); 2018 break; 2019 } 2020 else if (nParam1 == OMX_ALL && && (pComponentPrivate->eState == OMX_StateLoaded || 2021 pComponentPrivate->pInPortDef->bPopulated) && 2022 (pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL)) { 2023 /* return cmdcomplete event if inout & output unpopulated */ 2024 OMX_PRBUFFER2(pComponentPrivate->dbg, "Enabling VIDDEC_OUTPUT_PORT 0x%x\n",pComponentPrivate->pOutPortDef->bEnabled); 2025 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT 0x%x\n",pComponentPrivate->pOutPortDef->bEnabled); 2026 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2027 pComponentPrivate->pHandle->pApplicationPrivate, 2028 OMX_EventCmdComplete, 2029 OMX_CommandPortEnable, 2030 VIDDEC_INPUT_PORT, 2031 NULL); 2032 break; 2033 } 2034 VIDDEC_WAIT_CODE(); 2035 } 2036#else 2037 if (nParam1 == VIDDEC_INPUT_PORT) { 2038 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 2039 if((!(pComponentPrivate->eState == OMX_StateLoaded) && !pComponentPrivate->pInPortDef->bPopulated) || 2040 pComponentPrivate->sInSemaphore.bSignaled) { 2041 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 2042 } 2043 2044 2045 if(pComponentPrivate->eLCMLState == VidDec_LCML_State_Unload && 2046 pComponentPrivate->bDynamicConfigurationInProgress == OMX_FALSE && 2047 pComponentPrivate->pInPortDef->bEnabled == OMX_TRUE && 2048 pComponentPrivate->pOutPortDef->bEnabled == OMX_TRUE){ 2049 OMX_PRBUFFER1(pComponentPrivate->dbg, "BSC VIDDEC_INPUT_PORT\n"); 2050 eError = VIDDEC_LoadCodec(pComponentPrivate); 2051 if(eError != OMX_ErrorNone){ 2052 goto EXIT; 2053 } 2054 } 2055 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2056 pComponentPrivate->pHandle->pApplicationPrivate, 2057 OMX_EventCmdComplete, 2058 OMX_CommandPortEnable, 2059 VIDDEC_INPUT_PORT, 2060 NULL); 2061 } 2062 else if (nParam1 == VIDDEC_OUTPUT_PORT) { 2063 2064 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_OUTPUT_PORT OUT 0x%x\n",pComponentPrivate->pOutPortDef->bPopulated); 2065 if((!(pComponentPrivate->eState == OMX_StateLoaded) && !pComponentPrivate->pOutPortDef->bPopulated) || 2066 pComponentPrivate->sOutSemaphore.bSignaled) { 2067 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sOutSemaphore); 2068 } 2069 2070 if(pComponentPrivate->eLCMLState == VidDec_LCML_State_Unload && 2071 pComponentPrivate->bDynamicConfigurationInProgress == OMX_FALSE && 2072 pComponentPrivate->pInPortDef->bEnabled == OMX_TRUE && 2073 pComponentPrivate->pOutPortDef->bEnabled == OMX_TRUE){ 2074 OMX_PRBUFFER1(pComponentPrivate->dbg, "BSC VIDDEC_OUTPUT_PORT\n"); 2075 eError = VIDDEC_LoadCodec(pComponentPrivate); 2076 if(eError != OMX_ErrorNone){ 2077 goto EXIT; 2078 } 2079 } 2080 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2081 pComponentPrivate->pHandle->pApplicationPrivate, 2082 OMX_EventCmdComplete, 2083 OMX_CommandPortEnable, 2084 VIDDEC_OUTPUT_PORT, 2085 NULL); 2086 } 2087 else if (nParam1 == OMX_ALL) { 2088 if(pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 2089 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 2090 if((!(pComponentPrivate->eState == OMX_StateLoaded) && !pComponentPrivate->pInPortDef->bPopulated) || 2091 pComponentPrivate->sInSemaphore.bSignaled) { 2092 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 2093 } 2094 2095 if(pComponentPrivate->eLCMLState == VidDec_LCML_State_Unload){ 2096 eError = VIDDEC_LoadCodec(pComponentPrivate); 2097 if(eError != OMX_ErrorNone){ 2098 goto EXIT; 2099 } 2100 } 2101 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2102 pComponentPrivate->pHandle->pApplicationPrivate, 2103 OMX_EventCmdComplete, 2104 OMX_CommandPortEnable, 2105 VIDDEC_INPUT_PORT, 2106 NULL); 2107 } 2108 else { 2109 if((!(pComponentPrivate->eState == OMX_StateLoaded) && !pComponentPrivate->pInPortDef->bPopulated) || 2110 pComponentPrivate->sInSemaphore.bSignaled) { 2111 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 2112 } 2113 if(pComponentPrivate->eLCMLState == VidDec_LCML_State_Unload){ 2114 OMX_PRBUFFER1(pComponentPrivate->dbg, "BSC OMX_ALL\n"); 2115 eError = VIDDEC_LoadCodec(pComponentPrivate); 2116 if(eError != OMX_ErrorNone){ 2117 goto EXIT; 2118 } 2119 } 2120 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 2121 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2122 pComponentPrivate->pHandle->pApplicationPrivate, 2123 OMX_EventCmdComplete, 2124 OMX_CommandPortEnable, 2125 VIDDEC_INPUT_PORT, 2126 NULL); 2127 if((!(pComponentPrivate->eState == OMX_StateLoaded) && !pComponentPrivate->pOutPortDef->bPopulated) || 2128 pComponentPrivate->sOutSemaphore.bSignaled) { 2129 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sOutSemaphore); 2130 } 2131 OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated); 2132 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2133 pComponentPrivate->pHandle->pApplicationPrivate, 2134 OMX_EventCmdComplete, 2135 OMX_CommandPortEnable, 2136 VIDDEC_OUTPUT_PORT, 2137 NULL); 2138 } 2139 } 2140#endif 2141EXIT: 2142 OMX_PRINT1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 2143 return eError; 2144} 2145 2146/* ========================================================================== */ 2147/** 2148 * HandleCommandFlush() 2149 * 2150 * Called by component thread, handles the flush command from thread. 2151 * 2152 * @param 2153 * 2154 * @retval OMX_ErrorNone success, ready to roll 2155 * 2156 **/ 2157/* ========================================================================== */ 2158 2159OMX_ERRORTYPE VIDDEC_HandleCommandFlush(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1, OMX_BOOL bPass) 2160{ 2161 OMX_ERRORTYPE eError = OMX_ErrorNone; 2162 OMX_U32 aParam[4]; 2163 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 2164 2165 OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n"); 2166 OMX_PRINT1(pComponentPrivate->dbg, "pComponentPrivate 0x%p nParam1 0x%lx\n",pComponentPrivate, nParam1); 2167 2168 if ( nParam1 == VIDDEC_INPUT_PORT || nParam1 == OMX_ALL){ 2169 if(bPass) { 2170 OMX_VidDec_Return(pComponentPrivate); 2171 OMX_VidDec_Return(pComponentPrivate); 2172 OMX_VidDec_Return(pComponentPrivate); 2173 } 2174 2175 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2176 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2177 pComponentPrivate->pLCML != NULL && pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2178 aParam[0] = USN_STRMCMD_FLUSH; 2179 aParam[1] = VIDDEC_INPUT_PORT; 2180 aParam[2] = 0; 2181 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 2182 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 2183 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam); 2184 if (eError != OMX_ErrorNone) { 2185 eError = OMX_ErrorHardware; 2186 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2187 goto EXIT; 2188 } 2189 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 2190 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2191 2192 } 2193 VIDDEC_CircBuf_Flush(pComponentPrivate, VIDDEC_CBUFFER_TIMESTAMP, VIDDEC_INPUT_PORT); 2194 OMX_VidDec_Return(pComponentPrivate); 2195 OMX_VidDec_Return(pComponentPrivate); 2196 VIDDEC_ReturnBuffers(pComponentPrivate, VIDDEC_INPUT_PORT, OMX_TRUE); 2197 if(bPass) { 2198 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2199 pComponentPrivate->pHandle->pApplicationPrivate, 2200 OMX_EventCmdComplete, 2201 OMX_CommandFlush, 2202 VIDDEC_INPUT_PORT, 2203 NULL); 2204 } 2205 } 2206 2207 if ( nParam1 == VIDDEC_OUTPUT_PORT || nParam1 == OMX_ALL){ 2208 if(bPass){ 2209 OMX_VidDec_Return(pComponentPrivate); 2210 OMX_VidDec_Return(pComponentPrivate); 2211 OMX_VidDec_Return(pComponentPrivate); 2212 } 2213 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2214 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2215 pComponentPrivate->pLCML != NULL && pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2216 aParam[0] = USN_STRMCMD_FLUSH; 2217 aParam[1] = VIDDEC_OUTPUT_PORT; 2218 aParam[2] = 0; 2219 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 2220 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 2221 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam); 2222 if (eError != OMX_ErrorNone) { 2223 eError = OMX_ErrorHardware; 2224 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2225 goto EXIT; 2226 } 2227 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 2228 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2229 } 2230 OMX_VidDec_Return(pComponentPrivate); 2231 OMX_VidDec_Return(pComponentPrivate); 2232 VIDDEC_ReturnBuffers(pComponentPrivate, VIDDEC_OUTPUT_PORT, OMX_TRUE); 2233 if(bPass) { 2234 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2235 pComponentPrivate->pHandle->pApplicationPrivate, 2236 OMX_EventCmdComplete, 2237 OMX_CommandFlush, 2238 VIDDEC_OUTPUT_PORT, 2239 NULL); 2240 2241 } 2242 } 2243EXIT: 2244 OMX_PRINT1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 2245 return eError; 2246 2247} 2248 2249/* ========================================================================== */ 2250/** 2251 * HandleCommandMarkBuffer() 2252 * 2253 * Called by component thread, handles the Mark Buffer command from thread. 2254 * 2255 * @param 2256 * 2257 * @retval OMX_ErrorNone success, ready to roll 2258 * 2259 **/ 2260/* ========================================================================== */ 2261 2262OMX_ERRORTYPE VIDDEC_HandleCommandMarkBuffer(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1, OMX_PTR pCmdData) 2263{ 2264 OMX_ERRORTYPE eError = OMX_ErrorNone; 2265 OMX_PRBUFFER1(pComponentPrivate->dbg, "+++ENTERING\n"); 2266 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate 0x%p nParam1 0x%lx pCmdData 0x%p\n",pComponentPrivate, nParam1, pCmdData); 2267 OMX_PRBUFFER1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 2268 return eError; 2269 2270} 2271/* ========================================================================== */ 2272/** 2273 * OMX_HandleCommand() state machine in charge of interpretation of every 2274 * command received from application, depending on which state the component 2275 * is. 2276 **/ 2277/* ========================================================================== */ 2278 2279OMX_ERRORTYPE VIDDEC_HandleCommand (OMX_HANDLETYPE phandle, OMX_U32 nParam1) 2280{ 2281 OMX_U32 message[4]; 2282 OMX_U32 iCount = 0; 2283 VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)phandle; 2284 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 2285 OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = pComponentPrivate->pInPortDef; 2286 OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = pComponentPrivate->pOutPortDef; 2287 OMX_ERRORTYPE eError = OMX_ErrorNone; 2288 unsigned int cmd_rcv = 0; 2289 OMX_HANDLETYPE hLCML = NULL; 2290 void* p = NULL; 2291 2292#ifdef UNDER_CE 2293 typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE); 2294 HINSTANCE hDLL; 2295 LPFNDLLFUNC1 fpGetHandle1; 2296#else 2297 void* pMyLCML; 2298 VIDDEC_fpo fpGetHandle; 2299 char* error; 2300#endif 2301 2302 OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n"); 2303 OMX_PRINT1(pComponentPrivate->dbg, "pComponentPrivate 0x%p phandle 0x%lx\n",pComponentPrivate, nParam1); 2304 pComponentPrivate->frameCounter = 0; 2305 2306 message[0] = 0x400; 2307 message[1] = 100; 2308 message[2] = 0; 2309 p = (void*)&message; 2310 cmd_rcv = (unsigned int)nParam1; 2311 2312 switch (nParam1) { 2313 case OMX_StateIdle: 2314 OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning to OMX_StateIdle C 0x%x N 0x%lx\n",pComponentPrivate->eState, nParam1); 2315 if (pComponentPrivate->eState == OMX_StateIdle) { 2316 eError = OMX_ErrorSameState; 2317 OMX_PRSTATE4(pComponentPrivate->dbg, "Same State 0x%x\n", eError); 2318 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2319 pComponentPrivate->pHandle->pApplicationPrivate, 2320 OMX_EventError, 2321 OMX_ErrorSameState, 2322 OMX_TI_ErrorMinor, 2323 "Same state"); 2324 break; 2325 } 2326 else if (( pComponentPrivate->eState == OMX_StateLoaded) || pComponentPrivate->eState == OMX_StateWaitForResources ) { 2327#ifdef __PERF_INSTRUMENTATION__ 2328 PERF_Boundary(pComponentPrivate->pPERFcomp, 2329 PERF_BoundaryStart | PERF_BoundarySetup); 2330#endif 2331 2332 if ((pPortDefIn->bEnabled == OMX_TRUE && pPortDefOut->bEnabled == OMX_TRUE) || 2333 (pPortDefIn->bEnabled == OMX_TRUE && pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL)) { 2334 OMX_PRBUFFER1(pComponentPrivate->dbg, "Before pPortDefIn->bEnabled 0x%x pPortDefOut->bEnabled 0x%x\n",pPortDefIn->bEnabled, pPortDefOut->bEnabled); 2335#ifdef UNDER_CE 2336 while (1) { 2337 if (pPortDefIn->bPopulated && pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 2338 OMX_PRBUFFER1(pComponentPrivate->dbg, "tunneling pPortDefIn->bEnabled 0x%x pPortDefOut->bEnabled 0x%x\n", 2339 pPortDefIn->bEnabled, pPortDefOut->bEnabled); 2340 break; 2341 } 2342 if (pPortDefIn->bPopulated && pPortDefOut->bPopulated) { 2343 OMX_PRINT1(pComponentPrivate->dbg, "Standalone pPortDefIn->bEnabled 0x%x pPortDefOut->bEnabled 0x%x\n", 2344 pPortDefIn->bEnabled, pPortDefOut->bEnabled); 2345 break; 2346 } 2347 /* Sleep for a while, so the application thread can allocate buffers */ 2348 VIDDEC_WAIT_CODE(); 2349 } 2350#else 2351 if(pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 2352 if((!pComponentPrivate->pInPortDef->bPopulated) || pComponentPrivate->sInSemaphore.bSignaled) { 2353 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 2354 OMX_PRBUFFER1(pComponentPrivate->dbg, "tunneling pPortDefIn->bEnabled 0x%x pPortDefOut->bEnabled 0x%x\n", 2355 pPortDefIn->bEnabled, pPortDefOut->bEnabled); 2356 } 2357 } 2358 else { 2359 if((!pComponentPrivate->pOutPortDef->bPopulated) || pComponentPrivate->sOutSemaphore.bSignaled) { 2360 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 2361 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sOutSemaphore); 2362 OMX_PRBUFFER1(pComponentPrivate->dbg, "Standalone pPortDefIn->bEnabled 0x%x pPortDefOut->bEnabled 0x%x\n", 2363 pPortDefIn->bEnabled, pPortDefOut->bEnabled); 2364 } 2365 } 2366#endif 2367 OMX_PRBUFFER1(pComponentPrivate->dbg, "After pPortDefIn->bEnabled 0x%x pPortDefOut->bEnabled 0x%x\n",pPortDefIn->bEnabled, pPortDefOut->bEnabled); 2368 } 2369#ifndef UNDER_CE 2370 else { 2371 if(pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 2372 if(pComponentPrivate->sInSemaphore.bSignaled){ 2373 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 2374 } 2375 } 2376 else { 2377 if(pComponentPrivate->sInSemaphore.bSignaled){ 2378 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 2379 } 2380 if(pComponentPrivate->sOutSemaphore.bSignaled){ 2381 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sOutSemaphore); 2382 } 2383 } 2384 } 2385#endif 2386 2387#if 1 2388#ifndef UNDER_CE 2389 pMyLCML = dlopen("libLCML.so", RTLD_LAZY); 2390 if (!pMyLCML) { 2391 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 2392 fputs(dlerror(), stderr); 2393 eError = OMX_ErrorBadParameter; 2394 goto EXIT; 2395 } 2396 fpGetHandle = dlsym(pMyLCML, "GetHandle"); 2397 if ((error = dlerror()) != NULL) { 2398 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 2399 fputs(error, stderr); 2400 dlclose(pMyLCML); 2401 pMyLCML = NULL; 2402 eError = OMX_ErrorBadParameter; 2403 goto EXIT; 2404 } 2405 eError = (*fpGetHandle)(&hLCML); 2406 if (eError != OMX_ErrorNone) { 2407 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 2408 dlclose(pMyLCML); 2409 pMyLCML = NULL; 2410 eError = OMX_ErrorBadParameter; 2411 goto EXIT; 2412 } 2413 pComponentPrivate->pModLCML = pMyLCML; 2414#else 2415 hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL, 0); 2416 if (hDLL == NULL) { 2417 OMX_PRDSP4(pComponentPrivate->dbg, "BML Load Failed!!!\n"); 2418 eError = OMX_ErrorBadParameter; 2419 goto EXIT; 2420 } 2421 fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,TEXT("GetHandle")); 2422 if (!fpGetHandle1) { 2423 /* handle the error */ 2424 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 2425 FreeLibrary(hDLL); 2426 hDLL = NULL; 2427 eError = OMX_ErrorBadParameter; 2428 goto EXIT; 2429 } 2430 /* call the function */ 2431 eError = fpGetHandle1(&hLCML); 2432 if (eError != OMX_ErrorNone) { 2433 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 2434 FreeLibrary(hDLL); 2435 hDLL = NULL; 2436 eError = OMX_ErrorBadParameter; 2437 goto EXIT; 2438 } 2439 pComponentPrivate->pModLCML = hDLL; 2440#endif 2441 2442 pComponentPrivate->eLCMLState = VidDec_LCML_State_Load; 2443 OMX_PRDSP2(pComponentPrivate->dbg, "LCML Handler 0x%p\n",hLCML); 2444 /*(LCML_DSP_INTERFACE*)pComponentPrivate->pLCML = (LCML_DSP_INTERFACE*)hLCML;*/ 2445 pComponentPrivate->pLCML = (LCML_DSP_INTERFACE*)hLCML; 2446 pComponentPrivate->pLCML->pComponentPrivate = pComponentPrivate; 2447#endif 2448 2449#ifdef __PERF_INSTRUMENTATION__ 2450 pComponentPrivate->lcml_nCntOpReceived = 0; 2451#endif 2452 eError = OMX_ErrorNone; 2453#ifndef UNDER_CE 2454 pComponentPrivate->bLCMLOut = OMX_TRUE; 2455#endif 2456 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 2457 eError = VIDDEC_InitDSP_H264Dec(pComponentPrivate); 2458 } 2459 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 2460 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 2461 eError = VIDDEC_InitDSP_Mpeg4Dec(pComponentPrivate); 2462 } 2463 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 2464 eError = VIDDEC_InitDSP_Mpeg2Dec(pComponentPrivate); 2465 } 2466 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 2467 eError = VIDDEC_InitDSP_WMVDec(pComponentPrivate); 2468 } 2469#ifdef VIDDEC_SPARK_CODE 2470 else if (VIDDEC_SPARKCHECK) { 2471 eError = VIDDEC_InitDSP_SparkDec(pComponentPrivate); 2472 } 2473#endif 2474 else { 2475 OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedSetting\n"); 2476 eError = OMX_ErrorUnsupportedSetting; 2477 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2478 pComponentPrivate->pHandle->pApplicationPrivate, 2479 OMX_EventError, 2480 OMX_ErrorUnsupportedSetting, 2481 OMX_TI_ErrorMinor, 2482 "DSP Initialization"); 2483 goto EXIT; 2484 } 2485 /************************************************************************/ 2486 /************************************************************************/ 2487 /************************************************************************/ 2488 if(eError != OMX_ErrorNone){ 2489 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2490 pComponentPrivate->pModLCML != NULL){ 2491#ifndef UNDER_CE 2492 if(pComponentPrivate->pModLCML != NULL){ 2493 dlclose(pComponentPrivate->pModLCML); 2494 pComponentPrivate->pModLCML = NULL; 2495 pComponentPrivate->pLCML = NULL; 2496 pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload; 2497 } 2498#else 2499 if(pComponentPrivate->pModLCML != NULL){ 2500 FreeLibrary(pComponentPrivate->pModLCML); 2501 pComponentPrivate->pModLCML = NULL; 2502 pComponentPrivate->pLCML = NULL; 2503 pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload; 2504 } 2505#endif 2506 2507 pComponentPrivate->bLCMLHalted = OMX_TRUE; 2508 } 2509 OMX_PRDSP4(pComponentPrivate->dbg, "LCML Error %x\n", pComponentPrivate->eState); 2510 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2511 pComponentPrivate->pHandle->pApplicationPrivate, 2512 OMX_EventError, 2513 eError, 2514 OMX_TI_ErrorSevere, 2515 "DSP Initialization"); 2516 goto EXIT; 2517 } 2518 2519#ifndef UNDER_CE 2520 pComponentPrivate->bLCMLOut = OMX_FALSE; 2521#endif 2522 pComponentPrivate->bLCMLHalted = OMX_FALSE; 2523 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 2524 if (!pLcmlHandle) { 2525 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 2526 eError = OMX_ErrorHardware; 2527 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2528 pComponentPrivate->pHandle->pApplicationPrivate, 2529 OMX_EventError, 2530 OMX_ErrorHardware, 2531 OMX_TI_ErrorSevere, 2532 "Lcml Handle NULL"); 2533 goto EXIT; 2534 } 2535 pComponentPrivate->eLCMLState = VidDec_LCML_State_Init; 2536 OMX_PRINT1(pComponentPrivate->dbg, "OUTPUT width=%lu height=%lu\n", pComponentPrivate->pOutPortDef->format.video.nFrameWidth, pComponentPrivate->pOutPortDef->format.video.nFrameHeight); 2537 OMX_PRINT1(pComponentPrivate->dbg, "INPUT width=%lu height=%lu\n", pComponentPrivate->pInPortDef->format.video.nFrameWidth, pComponentPrivate->pInPortDef->format.video.nFrameHeight); 2538 2539 2540#if 1 2541#ifdef RESOURCE_MANAGER_ENABLED 2542 pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) VIDDEC_ResourceManagerCallback; 2543 if(pComponentPrivate->eRMProxyState != VidDec_RMPROXY_State_Unload){ 2544 OMX_PRMGR2(pComponentPrivate->dbg, "memory usage 1 %u : %u bytes\n",(unsigned int)pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0],(unsigned int)VIDDEC_MEMUSAGE); 2545 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 2546 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_RequestResource, OMX_H264_Decode_COMPONENT, VIDDEC_GetRMFrecuency(pComponentPrivate), VIDDEC_MEMUSAGE, &(pComponentPrivate->rmproxyCallback)); 2547 } 2548 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) { 2549 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_RequestResource, OMX_MPEG4_Decode_COMPONENT, VIDDEC_GetRMFrecuency(pComponentPrivate), VIDDEC_MEMUSAGE, &(pComponentPrivate->rmproxyCallback)); 2550 } 2551 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 2552 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_RequestResource, OMX_H263_Decode_COMPONENT, VIDDEC_GetRMFrecuency(pComponentPrivate), VIDDEC_MEMUSAGE, &(pComponentPrivate->rmproxyCallback)); 2553 } 2554 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 2555 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_RequestResource, OMX_MPEG2_Decode_COMPONENT, VIDDEC_GetRMFrecuency(pComponentPrivate), VIDDEC_MEMUSAGE, &(pComponentPrivate->rmproxyCallback)); 2556 } 2557 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 2558 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_RequestResource, OMX_WMV_Decode_COMPONENT, VIDDEC_GetRMFrecuency(pComponentPrivate), VIDDEC_MEMUSAGE, &(pComponentPrivate->rmproxyCallback)); 2559 } 2560#ifdef VIDDEC_SPARK_CODE 2561 else if (VIDDEC_SPARKCHECK) { 2562 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_RequestResource, OMX_MPEG4_Decode_COMPONENT, VIDDEC_GetRMFrecuency(pComponentPrivate), VIDDEC_MEMUSAGE, &(pComponentPrivate->rmproxyCallback)); 2563 } 2564#endif 2565 else { 2566 eError = OMX_ErrorUnsupportedSetting; 2567 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2568 pComponentPrivate->pHandle->pApplicationPrivate, 2569 OMX_EventError, 2570 OMX_ErrorUnsupportedSetting, 2571 OMX_TI_ErrorMajor, 2572 "RM SendCommand OMX_ErrorUnsupportedSetting Error"); 2573 OMX_PRMGR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedSetting 0x%x\n",eError); 2574 goto EXIT; 2575 } 2576 if (eError != OMX_ErrorNone) { 2577 pComponentPrivate->eState = OMX_StateLoaded; 2578 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2579 pComponentPrivate->pHandle->pApplicationPrivate, 2580 OMX_EventError, 2581 OMX_ErrorInsufficientResources, 2582 OMX_TI_ErrorMajor, 2583 "RM SendCommand Error"); 2584 OMX_PRMGR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedSetting 0x%x\n",eError); 2585 break; 2586 } 2587 pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Registered; 2588 } 2589#endif 2590#endif 2591 /* Send command to USN to do the propagation of the EOS flag */ 2592 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2593 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2594 pComponentPrivate->pLCML != NULL && 2595 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2596 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlUsnEos 0x%p\n",pLcmlHandle); 2597 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlUsnEos, NULL); 2598 if (eError != OMX_ErrorNone) { 2599 OMX_PRDSP4(pComponentPrivate->dbg, "error in EMMCodecControlUsnEos %x\n",eError); 2600 eError = OMX_ErrorHardware; 2601 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2602 pComponentPrivate->pHandle->pApplicationPrivate, 2603 OMX_EventError, 2604 OMX_ErrorHardware, 2605 OMX_TI_ErrorSevere, 2606 "LCML_ControlCodec EMMCodecControlUsnEos function"); 2607 OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorHardware 0x%x\n",eError); 2608 goto EXIT; 2609 } 2610 } 2611 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat != OMX_VIDEO_CodingWMV) { 2612 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2613 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2614 pComponentPrivate->pLCML != NULL && 2615 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2616 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 2617 message[1] = 4; 2618 } 2619 else { 2620 message[1] = 100; 2621 } 2622 message[0] = 0x400; 2623 message[2] = 0; 2624 p = (void*)&message; 2625 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 2626 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlSendDspMessage 0x%p\n",pLcmlHandle); 2627 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlSendDspMessage, (void *)p); 2628 if (eError != OMX_ErrorNone) { 2629 OMX_PRDSP4(pComponentPrivate->dbg, "error in EMMCodecControlSendDspMessage %x\n",eError); 2630 eError = OMX_ErrorHardware; 2631 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2632 pComponentPrivate->pHandle->pApplicationPrivate, 2633 OMX_EventError, 2634 OMX_ErrorHardware, 2635 OMX_TI_ErrorSevere, 2636 "LCML_ControlCodec function"); 2637 OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorHardware 0x%x\n",eError); 2638 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2639 goto EXIT; 2640 } 2641 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 2642 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2643 } 2644 } 2645 2646 pComponentPrivate->eState = OMX_StateIdle; 2647 pComponentPrivate->bIsPaused = 0; 2648 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2649 pComponentPrivate->pHandle->pApplicationPrivate, 2650 OMX_EventCmdComplete, 2651 OMX_CommandStateSet, 2652 pComponentPrivate->eState, 2653 NULL); 2654 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StateIdle\n"); 2655 break; 2656 } 2657 else if (pComponentPrivate->eState == OMX_StateExecuting || pComponentPrivate->eState == OMX_StatePause) { 2658 /*Set the bIsStopping bit*/ 2659 if (pComponentPrivate->bDynamicConfigurationInProgress == OMX_TRUE) { 2660 pComponentPrivate->bDynamicConfigurationInProgress = OMX_FALSE; 2661 OMX_PRSTATE1(pComponentPrivate->dbg, "We were doing DynamicConfiguration, canceling it. %d \n",pComponentPrivate->bDynamicConfigurationInProgress); 2662 } 2663 pComponentPrivate->bIsStopping = 1; 2664 OMX_PRSTATE1(pComponentPrivate->dbg, "bIsStopping 0x%lx\n",pComponentPrivate->bIsStopping); 2665 OMX_PRSTATE1(pComponentPrivate->dbg, "eExecuteToIdle 0x%x\n",pComponentPrivate->eExecuteToIdle); 2666 OMX_VidDec_Return(pComponentPrivate); 2667 OMX_VidDec_Return(pComponentPrivate); 2668 2669#ifdef __PERF_INSTRUMENTATION__ 2670 PERF_Boundary(pComponentPrivate->pPERFcomp, 2671 PERF_BoundaryComplete | PERF_BoundarySteadyState); 2672#endif 2673 pComponentPrivate->bIsPaused = 0; 2674 pComponentPrivate->iEndofInputSent = 0; 2675/********************************************************************************************************************/ 2676 if (pComponentPrivate->bIsStopping == OMX_TRUE) { 2677 pComponentPrivate->bIsPaused = OMX_FALSE; 2678 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2679 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2680 pComponentPrivate->pLCML != NULL && 2681 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2682 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 2683 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLCML; 2684 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, MMCodecControlStop, NULL); 2685 if (eError != OMX_ErrorNone) { 2686 eError = OMX_ErrorHardware; 2687 OMX_PRDSP4(pComponentPrivate->dbg, "Error Occurred in Codec Stop...\n"); 2688 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2689 break; 2690 } 2691 pComponentPrivate->eLCMLState = VidDec_LCML_State_Stop; 2692 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 2693 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2694 } 2695 VIDDEC_HandleCommandFlush(pComponentPrivate, -1, OMX_FALSE); 2696 2697#if 1 2698#ifdef RESOURCE_MANAGER_ENABLED 2699 if(pComponentPrivate->eRMProxyState != VidDec_RMPROXY_State_Unload){ 2700 OMX_PRMGR2(pComponentPrivate->dbg, "memory usage 2 %d : %d bytes\n",(unsigned int)pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0],(unsigned int)VIDDEC_MEMUSAGE); 2701 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 2702 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_H264_Decode_COMPONENT, OMX_StateIdle, VIDDEC_MEMUSAGE, NULL); 2703 } 2704 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) { 2705 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_MPEG4_Decode_COMPONENT, OMX_StateIdle, VIDDEC_MEMUSAGE, NULL); 2706 } 2707 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 2708 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_H263_Decode_COMPONENT, OMX_StateIdle, VIDDEC_MEMUSAGE, NULL); 2709 } 2710 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 2711 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_MPEG2_Decode_COMPONENT, OMX_StateIdle, VIDDEC_MEMUSAGE, NULL); 2712 } 2713 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 2714 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_WMV_Decode_COMPONENT, OMX_StateIdle, VIDDEC_MEMUSAGE, NULL); 2715 } 2716#ifdef VIDDEC_SPARK_CODE 2717 else if (VIDDEC_SPARKCHECK) { 2718 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_MPEG4_Decode_COMPONENT, OMX_StateIdle, VIDDEC_MEMUSAGE, NULL); 2719 } 2720#endif 2721 } 2722#endif 2723#endif 2724 if(pComponentPrivate->pUalgParams != NULL) { 2725 OMX_U8* pTemp = NULL; 2726 pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams); 2727 pTemp -= VIDDEC_PADDING_HALF; 2728 pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp; 2729 free(pComponentPrivate->pUalgParams); 2730 pComponentPrivate->pUalgParams = NULL; 2731 } 2732 2733 pComponentPrivate->bIsStopping = OMX_FALSE; 2734 pComponentPrivate->eState = OMX_StateIdle; 2735 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2736 pComponentPrivate->pHandle->pApplicationPrivate, 2737 OMX_EventCmdComplete, 2738 OMX_CommandStateSet, 2739 pComponentPrivate->eState, 2740 NULL); 2741 eError = OMX_ErrorNone; 2742 pComponentPrivate->bTransPause = 0; 2743 pComponentPrivate->bIsPaused = 0; 2744 pComponentPrivate->eExecuteToIdle = OMX_StateInvalid; 2745 } 2746/********************************************************************************************************************/ 2747 2748 } 2749 else { 2750 eError = OMX_ErrorIncorrectStateTransition; 2751 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2752 pComponentPrivate->pHandle->pApplicationPrivate, 2753 OMX_EventError, 2754 OMX_ErrorIncorrectStateTransition, 2755 OMX_TI_ErrorMinor, 2756 NULL); 2757 OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorHardware 0x%x\n",eError); 2758 } 2759 pComponentPrivate->eExecuteToIdle = OMX_StateInvalid; 2760 OMX_PRSTATE1(pComponentPrivate->dbg, "Passing bIsStopping 0x%lx\n",pComponentPrivate->bIsStopping); 2761 OMX_PRSTATE1(pComponentPrivate->dbg, "Passing eExecuteToIdle 0x%x\n",pComponentPrivate->eExecuteToIdle); 2762 break; 2763 2764 case OMX_StateExecuting: 2765#ifdef __PERF_INSTRUMENTATION__ 2766 pComponentPrivate->lcml_nCntOpReceived = 0; 2767#endif 2768 OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning to OMX_StateExecuting C 0x%x N 0x%lx\n",pComponentPrivate->eState, nParam1); 2769 if (pComponentPrivate->eState == OMX_StateExecuting) { 2770 eError = OMX_ErrorSameState; 2771 pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 2772 pComponentPrivate->pHandle->pApplicationPrivate, 2773 OMX_EventError, 2774 OMX_ErrorSameState, 2775 OMX_TI_ErrorMinor, 2776 "Invalid State"); 2777 OMX_PRSTATE4(pComponentPrivate->dbg, "OMX_ErrorSameState 0x%x\n",eError); 2778 } 2779 else if (pComponentPrivate->eState == OMX_StateIdle || pComponentPrivate->eState == OMX_StatePause) { 2780 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 2781 pComponentPrivate->bIsPaused = 0; 2782 pComponentPrivate->bFirstBuffer = 1; 2783 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2784 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2785 pComponentPrivate->pLCML != NULL && 2786 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2787 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlStart 0x%p\n",pLcmlHandle); 2788 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStart,NULL); 2789 if (eError != OMX_ErrorNone) { 2790 eError = OMX_ErrorHardware; 2791 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2792 pComponentPrivate->pHandle->pApplicationPrivate, 2793 OMX_EventError, 2794 OMX_ErrorHardware, 2795 OMX_TI_ErrorSevere, 2796 "LCML_ControlCodec Start"); 2797 break; 2798 OMX_PRDSP4(pComponentPrivate->dbg, "Occurred in Codec Start... 0x%x\n",eError); 2799 } 2800 } 2801 pComponentPrivate->eLCMLState = VidDec_LCML_State_Start; 2802 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC && 2803 pComponentPrivate->eState == OMX_StateIdle) { 2804 H264_Iualg_Cmd_SetStatus* pDynParams = NULL; 2805 char* pTmp = NULL; 2806 OMX_U32 cmdValues[3] = {0, 0, 0}; 2807 2808 VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_IDLEEXECUTING); 2809 OMX_PRDSP2(pComponentPrivate->dbg, "Initializing DSP for h264 eCompressionFormat 0x%x\n", 2810 pComponentPrivate->pInPortDef->format.video.eCompressionFormat); 2811 OMX_MALLOC_STRUCT_SIZED(pDynParams, H264_Iualg_Cmd_SetStatus, sizeof(H264_Iualg_Cmd_SetStatus) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 2812 if (pDynParams == NULL) { 2813 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n"); 2814 eError = OMX_ErrorInsufficientResources; 2815 goto EXIT; 2816 } 2817 memset(pDynParams, 0, sizeof(H264_Iualg_Cmd_SetStatus) + VIDDEC_PADDING_FULL); 2818 pTmp = (char*)pDynParams; 2819 pTmp += VIDDEC_PADDING_HALF; 2820 pDynParams = (H264_Iualg_Cmd_SetStatus*)pTmp; 2821#ifdef VIDDEC_SN_R8_14 2822 pDynParams->size = sizeof(H264_Iualg_Cmd_SetStatus); 2823#endif 2824 pDynParams->ulDecodeHeader = 1; 2825 pDynParams->ulDisplayWidth = 0; 2826 pDynParams->ulFrameSkipMode = 0; 2827 pDynParams->ulPPType = 0; 2828 2829 cmdValues[0] = IUALG_CMD_SETSTATUS; 2830 cmdValues[1] = (OMX_U32)(pDynParams); 2831 cmdValues[2] = sizeof(H264_Iualg_Cmd_SetStatus); 2832 2833 p = (void*)&cmdValues; 2834 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2835 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2836 pComponentPrivate->pLCML != NULL && 2837 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2838 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 2839 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 2840 EMMCodecControlAlgCtrl, 2841 (void*)p); 2842 if (eError != OMX_ErrorNone) { 2843 eError = OMX_ErrorHardware; 2844 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2845 break; 2846 } 2847 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 2848 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 2849 } 2850 pTmp = (char*)pDynParams; 2851 pTmp -= VIDDEC_PADDING_HALF; 2852 pDynParams = (H264_Iualg_Cmd_SetStatus*)pTmp; 2853 free(pDynParams); 2854 2855 if (eError != OMX_ErrorNone) { 2856 OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError); 2857 goto EXIT; 2858 } 2859 } 2860 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2 && 2861 pComponentPrivate->eState == OMX_StateIdle) { 2862 MP2VDEC_UALGDynamicParams* pDynParams = NULL; 2863 char* pTmp = NULL; 2864 OMX_U32 cmdValues[3] = {0, 0, 0}; 2865 2866 VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_IDLEEXECUTING); 2867 OMX_PRDSP2(pComponentPrivate->dbg, "Initializing DSP for wmv9 eCompressionFormat 0x%x\n", 2868 pComponentPrivate->pInPortDef->format.video.eCompressionFormat); 2869 OMX_MALLOC_STRUCT_SIZED(pDynParams, MP2VDEC_UALGDynamicParams, sizeof(MP2VDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 2870 memset(pDynParams, 0, sizeof(MP2VDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL); 2871 pTmp = (char*)pDynParams; 2872 pTmp += VIDDEC_PADDING_HALF; 2873 pDynParams = (MP2VDEC_UALGDynamicParams*)pTmp; 2874 2875#ifdef VIDDEC_SN_R8_14 2876 pDynParams->size = sizeof(MP2VDEC_UALGDynamicParams); 2877#endif 2878 if (pComponentPrivate->nDisplayWidth > 0) { 2879 if (pComponentPrivate->pInPortDef->format.video.nFrameWidth > pComponentPrivate->nDisplayWidth) { 2880 pComponentPrivate->nDisplayWidth = pComponentPrivate->pInPortDef->format.video.nFrameWidth; 2881 } 2882 pDynParams->ulDisplayWidth = (((pComponentPrivate->nDisplayWidth + 15) >> 4) << 4); 2883 if (pComponentPrivate->nDisplayWidth != pDynParams->ulDisplayWidth ) { 2884 pComponentPrivate->nDisplayWidth = pDynParams->ulDisplayWidth; 2885 OMX_PRINT2(pComponentPrivate->dbg, "warning Display Width adjusted to %lu\n",pDynParams->ulDisplayWidth); 2886 } 2887 } 2888 else if (pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL){ 2889 if (pComponentPrivate->pInPortDef->format.video.nFrameWidth > pComponentPrivate->nDisplayWidth) { 2890 pComponentPrivate->nDisplayWidth = pComponentPrivate->pInPortDef->format.video.nFrameWidth; 2891 } 2892 pDynParams->ulDisplayWidth = (((pComponentPrivate->nDisplayWidth + 15) >> 4) << 4); 2893 if (pComponentPrivate->nDisplayWidth != pDynParams->ulDisplayWidth ) { 2894 pComponentPrivate->nDisplayWidth = pDynParams->ulDisplayWidth; 2895 OMX_PRINT2(pComponentPrivate->dbg, "warning Display Width adjusted to %lu\n",pDynParams->ulDisplayWidth); 2896 } 2897 } 2898 else { 2899 pDynParams->ulDisplayWidth = 0; 2900 } 2901 pDynParams->ulDecodeHeader = 0; 2902 pDynParams->ulFrameSkipMode = 0; 2903 pDynParams->ulPPType = 0; 2904 pDynParams->ulPpNone = 0; 2905 if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT422) { 2906 pDynParams->ulDyna_chroma_format = MP2VIDDEC_YUVFORMAT_INTERLEAVED422; 2907 } 2908 else { 2909 pDynParams->ulDyna_chroma_format = MP2VIDDEC_YUVFORMAT_PLANAR420; 2910 } 2911 2912 cmdValues[0] = IUALG_CMD_SETSTATUS; 2913 cmdValues[1] = (OMX_U32)(pDynParams); 2914 cmdValues[2] = sizeof(MP2VDEC_UALGDynamicParams); 2915 2916 pComponentPrivate->bTransPause = 0; 2917 p = (void*)&cmdValues; 2918 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2919 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2920 pComponentPrivate->pLCML != NULL && 2921 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2922 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 2923 EMMCodecControlAlgCtrl, 2924 (void*)p); 2925 if(eError != OMX_ErrorNone){ 2926 eError = OMX_ErrorHardware; 2927 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 2928 pComponentPrivate->pHandle->pApplicationPrivate, 2929 OMX_EventError, 2930 eError, 2931 0x0, 2932 "LCML_ControlCodec function"); 2933 goto EXIT; 2934 } 2935 while(1) { 2936 if(pComponentPrivate->bTransPause != 0) { 2937 pComponentPrivate->bTransPause = 0; 2938 break; 2939 } 2940 VIDDEC_WAIT_CODE(); 2941 } 2942 } 2943 2944 pTmp = (char*)pDynParams; 2945 pTmp -= VIDDEC_PADDING_HALF; 2946 pDynParams = (MP2VDEC_UALGDynamicParams*)pTmp; 2947 free(pDynParams); 2948 2949 if (eError != OMX_ErrorNone) { 2950 OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError); 2951 goto EXIT; 2952 } 2953 } 2954#ifdef VIDDEC_SPARK_CODE 2955 else if (VIDDEC_SPARKCHECK) { 2956 if(pComponentPrivate->eState == OMX_StateIdle) { 2957 SPARKVDEC_UALGDynamicParams* pDynParams = NULL; 2958 char* pTmp = NULL; 2959 OMX_U32 cmdValues[3] = {0, 0, 0}; 2960 2961 VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_IDLEEXECUTING); 2962 OMX_PRDSP2(pComponentPrivate->dbg, "Initializing DSP for mpeg4 and h263 eCompressionFormat 0x%x\n", 2963 pComponentPrivate->pInPortDef->format.video.eCompressionFormat); 2964 OMX_MALLOC_STRUCT_SIZED(pDynParams, SPARKVDEC_UALGDynamicParams, sizeof(SPARKVDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 2965 if (pDynParams == NULL) { 2966 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n"); 2967 eError = OMX_ErrorInsufficientResources; 2968 goto EXIT; 2969 } 2970 memset(pDynParams, 0, sizeof(SPARKVDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL); 2971 pTmp = (char*)pDynParams; 2972 pTmp += VIDDEC_PADDING_HALF; 2973 pDynParams = (SPARKVDEC_UALGDynamicParams*)pTmp; 2974 #ifdef VIDDEC_SN_R8_14 2975 pDynParams->size = sizeof(SPARKVDEC_UALGDynamicParams); 2976 #endif 2977 pDynParams->ulDecodeHeader = 0; 2978 pDynParams->ulDisplayWidth = 0; 2979 pDynParams->ulFrameSkipMode = 0; 2980 pDynParams->ulPPType = 0; 2981 2982 cmdValues[0] = IUALG_CMD_SETSTATUS; 2983 cmdValues[1] = (OMX_U32)(pDynParams); 2984 cmdValues[2] = sizeof(SPARKVDEC_UALGDynamicParams); 2985 2986 /*pComponentPrivate->bTransPause = 0;*//*flag to wait for the generated event*/ 2987 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 2988 p = (void*)&cmdValues; 2989 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 2990 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 2991 pComponentPrivate->pLCML != NULL && 2992 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 2993 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 2994 EMMCodecControlAlgCtrl, 2995 (void*)p); 2996 if (eError != OMX_ErrorNone) { 2997 eError = OMX_ErrorHardware; 2998 goto EXIT; 2999 } 3000 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 3001 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 3002 } 3003 3004 pTmp = (char*)pDynParams; 3005 pTmp -= VIDDEC_PADDING_HALF; 3006 pDynParams = (SPARKVDEC_UALGDynamicParams*)pTmp; 3007 free(pDynParams); 3008 3009 if (eError != OMX_ErrorNone) { 3010 OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError); 3011 goto EXIT; 3012 } 3013 } 3014 } 3015#endif 3016 else { 3017 if(pComponentPrivate->eState == OMX_StateIdle) { 3018 eError = VIDDEC_Set_Debocking(pComponentPrivate); 3019 if (eError != OMX_ErrorNone){ 3020 goto EXIT; 3021 } 3022 } 3023 } 3024 3025 /* Start existing code */ 3026#if 1 3027#ifdef RESOURCE_MANAGER_ENABLED 3028 if(pComponentPrivate->eRMProxyState != VidDec_RMPROXY_State_Unload){ 3029 OMX_PRMGR2(pComponentPrivate->dbg, "memory usage 3 %d : %d bytes\n",(unsigned int)pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0],(unsigned int)VIDDEC_MEMUSAGE); 3030 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 3031 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_H264_Decode_COMPONENT, OMX_StateExecuting, VIDDEC_MEMUSAGE, NULL); 3032 } 3033 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) { 3034 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_MPEG4_Decode_COMPONENT, OMX_StateExecuting, VIDDEC_MEMUSAGE, NULL); 3035 } 3036 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 3037 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_H263_Decode_COMPONENT, OMX_StateExecuting, VIDDEC_MEMUSAGE, NULL); 3038 } 3039 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 3040 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_MPEG2_Decode_COMPONENT, OMX_StateExecuting, VIDDEC_MEMUSAGE, NULL); 3041 } 3042 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 3043 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_WMV_Decode_COMPONENT, OMX_StateExecuting, VIDDEC_MEMUSAGE, NULL); 3044 } 3045#ifdef VIDDEC_SPARK_CODE 3046 else if (VIDDEC_SPARKCHECK) { 3047 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_MPEG4_Decode_COMPONENT, OMX_StateExecuting, VIDDEC_MEMUSAGE, NULL); 3048 } 3049#endif 3050 else { 3051 eError = OMX_ErrorUnsupportedSetting; 3052 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3053 pComponentPrivate->pHandle->pApplicationPrivate, 3054 OMX_EventError, 3055 OMX_ErrorUnsupportedSetting, 3056 OMX_TI_ErrorMinor, 3057 "RM SendCommand OMX_ErrorUnsupportedSetting Error"); 3058 OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedSetting 0x%x\n",eError); 3059 goto EXIT; 3060 } 3061 if (eError != OMX_ErrorNone) { 3062 pComponentPrivate->eState = OMX_StateLoaded; 3063 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3064 pComponentPrivate->pHandle->pApplicationPrivate, 3065 OMX_EventError, 3066 OMX_ErrorInsufficientResources, 3067 OMX_TI_ErrorMajor, 3068 "RM SendCommand Error"); 3069 OMX_PRMGR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedSetting 0x%x\n",eError); 3070 break; 3071 } 3072 } 3073#endif 3074#endif 3075 3076 eError = OMX_ErrorNone; 3077 pComponentPrivate->bIsPaused = 0; 3078 pComponentPrivate->iEndofInputSent = 0; 3079 pComponentPrivate->eState = OMX_StateExecuting; 3080 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3081 pComponentPrivate->pHandle->pApplicationPrivate, 3082 OMX_EventCmdComplete, 3083 OMX_CommandStateSet, 3084 pComponentPrivate->eState, 3085 NULL); 3086 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StateExecuting\n"); 3087 } 3088 else { 3089 eError = OMX_ErrorIncorrectStateTransition; 3090 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3091 pComponentPrivate->pHandle->pApplicationPrivate, 3092 OMX_EventError, 3093 OMX_ErrorIncorrectStateTransition, 3094 OMX_TI_ErrorMinor, 3095 "Incorrect State Transition"); 3096 OMX_PRSTATE4(pComponentPrivate->dbg, "OMX_ErrorIncorrectStateTransition 0x%x\n",eError); 3097 } 3098 break; 3099 case OMX_StateLoaded: 3100 OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning to OMX_StateLoaded C 0x%x N 0x%lx\n",pComponentPrivate->eState, nParam1); 3101 if (pComponentPrivate->eState == OMX_StateLoaded) { 3102 eError = OMX_ErrorSameState; 3103 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3104 pComponentPrivate->pHandle->pApplicationPrivate, 3105 OMX_EventError, 3106 OMX_ErrorSameState, 3107 OMX_TI_ErrorMinor, 3108 "Same State"); 3109 OMX_PRSTATE4(pComponentPrivate->dbg, "OMX_ErrorSameState 0x%x\n",eError); 3110 } 3111 else if (pComponentPrivate->eState == OMX_StateIdle) { 3112#ifdef __PERF_INSTRUMENTATION__ 3113 PERF_Boundary(pComponentPrivate->pPERFcomp, 3114 PERF_BoundaryStart | PERF_BoundaryCleanup); 3115#endif 3116 OMX_VidDec_Return(pComponentPrivate); 3117 OMX_VidDec_Return(pComponentPrivate); 3118 pComponentPrivate->eIdleToLoad = OMX_StateLoaded; 3119 if(pComponentPrivate->eFirstBuffer.pFirstBufferSaved){ 3120 free(pComponentPrivate->eFirstBuffer.pFirstBufferSaved); 3121 pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL; 3122 pComponentPrivate->eFirstBuffer.bSaveFirstBuffer = OMX_FALSE; 3123 pComponentPrivate->eFirstBuffer.nFilledLen = 0; 3124 } 3125#ifdef RESOURCE_MANAGER_ENABLED 3126 if(pComponentPrivate->eRMProxyState == VidDec_RMPROXY_State_Registered){ 3127 OMX_PRMGR2(pComponentPrivate->dbg, "memory usage 4 %d : %d bytes\n",(unsigned int)pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0],(unsigned int)VIDDEC_MEMUSAGE); 3128 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 3129 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_H264_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3130 if (eError != OMX_ErrorNone) { 3131 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3132 } 3133 } 3134 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 3135 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_WMV_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3136 if (eError != OMX_ErrorNone) { 3137 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3138 } 3139 } 3140 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) { 3141 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG4_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3142 if (eError != OMX_ErrorNone) { 3143 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3144 } 3145 } 3146 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 3147 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_H263_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3148 if (eError != OMX_ErrorNone) { 3149 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3150 } 3151 } 3152 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 3153 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG2_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3154 if (eError != OMX_ErrorNone) { 3155 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3156 } 3157 } 3158#ifdef VIDDEC_SPARK_CODE 3159 else if (VIDDEC_SPARKCHECK) { 3160 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG4_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3161 if (eError != OMX_ErrorNone) { 3162 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3163 } 3164 } 3165#endif 3166 else { 3167 eError = OMX_ErrorUnsupportedSetting; 3168 goto EXIT; 3169 } 3170 pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Load; 3171 } 3172#endif 3173 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 3174 pComponentPrivate->pLCML != NULL){ 3175 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlDestroy 0x%p\n",pLcmlHandle); 3176 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 3177 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlDestroy, NULL); 3178 if (eError != OMX_ErrorNone) { 3179 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3180 pComponentPrivate->pHandle->pApplicationPrivate, 3181 OMX_EventError, 3182 OMX_ErrorHardware, 3183 OMX_TI_ErrorSevere, 3184 NULL); 3185 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorHardware 0x%x\n",eError); 3186 break; 3187 } 3188 pComponentPrivate->eLCMLState = VidDec_LCML_State_Destroy; 3189 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlDestroy 0x%p\n",pLcmlHandle); 3190 } 3191 3192 OMX_PRDSP2(pComponentPrivate->dbg, "Closing LCML lib 0x%p\n",pComponentPrivate->pModLCML); 3193 3194#ifndef UNDER_CE 3195 if(pComponentPrivate->pModLCML != NULL){ 3196 dlclose(pComponentPrivate->pModLCML); 3197 pComponentPrivate->pModLCML = NULL; 3198 pComponentPrivate->pLCML = NULL; 3199 } 3200#else 3201 if(pComponentPrivate->pModLCML != NULL){ 3202 FreeLibrary(pComponentPrivate->pModLCML); 3203 pComponentPrivate->pModLCML = NULL; 3204 pComponentPrivate->pLCML = NULL; 3205 } 3206#endif 3207 pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload; 3208 3209 OMX_PRDSP1(pComponentPrivate->dbg, "Closed LCML lib 0x%p\n",pComponentPrivate->pModLCML); 3210 OMX_PRBUFFER2(pComponentPrivate->dbg, "Waiting for unpopulate ports IN 0x%x OUT 0x%x\n",pPortDefIn->bEnabled,pPortDefOut->bEnabled); 3211 OMX_PRBUFFER1(pComponentPrivate->dbg, "Tunneling 0x%p\n",(pComponentPrivate->pCompPort[1]->hTunnelComponent)); 3212 if ((pPortDefIn->bEnabled == OMX_TRUE && pPortDefOut->bEnabled == OMX_TRUE) || 3213 (pPortDefIn->bEnabled == OMX_TRUE && pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL)) { 3214#ifdef UNDER_CE 3215 while(1) { 3216 if(!pPortDefIn->bPopulated && !pPortDefOut->bPopulated) { 3217 OMX_PRBUFFER2(pComponentPrivate->dbg, "Standalone unpopulated ports IN 0x%x OUT 0x%x\n",pPortDefIn->bEnabled,pPortDefOut->bEnabled); 3218 eError = OMX_ErrorNone; 3219 pComponentPrivate->bIsPaused = 0; 3220 pComponentPrivate->eState = OMX_StateLoaded; 3221 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3222 pComponentPrivate->pHandle->pApplicationPrivate, 3223 OMX_EventCmdComplete, 3224 OMX_CommandStateSet, 3225 pComponentPrivate->eState, 3226 NULL); 3227 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StateLoaded\n"); 3228 VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_VARS); 3229 pComponentPrivate->eIdleToLoad = OMX_StateInvalid; 3230 break; 3231 } 3232 else if(!pPortDefIn->bPopulated && (pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL)) { 3233 OMX_PRBUFFER2(pComponentPrivate->dbg, "Tunneling unpopulated ports IN 0x%x TUNNEL 0x%x\n", 3234 pPortDefIn->bEnabled,pComponentPrivate->pCompPort[1]->hTunnelComponent); 3235 eError = OMX_ErrorNone; 3236 pComponentPrivate->bIsPaused = 0; 3237 pComponentPrivate->eState = OMX_StateLoaded; 3238 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3239 pComponentPrivate->pHandle->pApplicationPrivate, 3240 OMX_EventCmdComplete, 3241 OMX_CommandStateSet, 3242 pComponentPrivate->eState, 3243 NULL); 3244 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StateLoaded\n"); 3245 VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_VARS); 3246 pComponentPrivate->eIdleToLoad = OMX_StateInvalid; 3247 break; 3248 } 3249 VIDDEC_WAIT_CODE(); 3250 } 3251#else 3252 if(pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 3253 if((!(pComponentPrivate->eState == OMX_StateLoaded) && pComponentPrivate->pInPortDef->bPopulated) || 3254 pComponentPrivate->sInSemaphore.bSignaled) { 3255 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 3256 } 3257 OMX_PRBUFFER2(pComponentPrivate->dbg, "Tunneling unpopulated ports IN 0x%x TUNNEL 0x%p\n", 3258 pPortDefIn->bEnabled,pComponentPrivate->pCompPort[1]->hTunnelComponent); 3259 eError = OMX_ErrorNone; 3260 pComponentPrivate->bIsPaused = 0; 3261 pComponentPrivate->eState = OMX_StateLoaded; 3262 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3263 pComponentPrivate->pHandle->pApplicationPrivate, 3264 OMX_EventCmdComplete, 3265 OMX_CommandStateSet, 3266 pComponentPrivate->eState, 3267 NULL); 3268 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StateLoaded\n"); 3269 VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_VARS); 3270 pComponentPrivate->eIdleToLoad = OMX_StateInvalid; 3271 } 3272 else { 3273 if((!(pComponentPrivate->eState == OMX_StateLoaded) && pComponentPrivate->pInPortDef->bPopulated) || 3274 pComponentPrivate->sInSemaphore.bSignaled) { 3275 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 3276 } 3277 if((!(pComponentPrivate->eState == OMX_StateLoaded) && pComponentPrivate->pOutPortDef->bPopulated) || 3278 pComponentPrivate->sOutSemaphore.bSignaled) { 3279 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sOutSemaphore); 3280 } 3281 OMX_PRBUFFER2(pComponentPrivate->dbg, "Standalone unpopulated ports IN 0x%x OUT 0x%x\n",pPortDefIn->bEnabled,pPortDefOut->bEnabled); 3282 eError = OMX_ErrorNone; 3283 pComponentPrivate->bIsPaused = 0; 3284 pComponentPrivate->eState = OMX_StateLoaded; 3285 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3286 pComponentPrivate->pHandle->pApplicationPrivate, 3287 OMX_EventCmdComplete, 3288 OMX_CommandStateSet, 3289 pComponentPrivate->eState, 3290 NULL); 3291 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StateLoaded\n"); 3292 VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_VARS); 3293 pComponentPrivate->eIdleToLoad = OMX_StateInvalid; 3294 3295 } 3296 3297 3298#endif 3299#ifdef __PERF_INSTRUMENTATION__ 3300 PERF_Boundary(pComponentPrivate->pPERFcomp, 3301 PERF_BoundaryComplete | PERF_BoundaryCleanup); 3302#endif 3303 3304 } 3305#ifndef UNDER_CE 3306 else { 3307 if(pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 3308 if(pComponentPrivate->sInSemaphore.bSignaled){ 3309 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 3310 } 3311 } 3312 else { 3313 if(pComponentPrivate->sInSemaphore.bSignaled){ 3314 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore); 3315 } 3316 if(pComponentPrivate->sOutSemaphore.bSignaled){ 3317 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sOutSemaphore); 3318 } 3319 } 3320 pComponentPrivate->eState = OMX_StateLoaded; 3321 pComponentPrivate->bIsPaused = 0; 3322 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3323 pComponentPrivate->pHandle->pApplicationPrivate, 3324 OMX_EventCmdComplete, 3325 OMX_CommandStateSet, 3326 pComponentPrivate->eState, 3327 NULL); 3328 pComponentPrivate->eIdleToLoad = OMX_StateInvalid; 3329 VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_VARS); 3330 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StateLoaded\n"); 3331 break; 3332 } 3333#endif 3334 } 3335 else if (pComponentPrivate->eState == OMX_StateWaitForResources) { 3336 pComponentPrivate->eState = OMX_StateLoaded; 3337 pComponentPrivate->bIsPaused = 0; 3338 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3339 pComponentPrivate->pHandle->pApplicationPrivate, 3340 OMX_EventCmdComplete, 3341 OMX_CommandStateSet, 3342 pComponentPrivate->eState, 3343 NULL); 3344 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StateLoaded\n"); 3345 break; 3346 } 3347 else { 3348 eError = OMX_ErrorIncorrectStateTransition; 3349 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3350 pComponentPrivate->pHandle->pApplicationPrivate, 3351 OMX_EventError, 3352 OMX_ErrorIncorrectStateTransition, 3353 OMX_TI_ErrorMinor, 3354 NULL); 3355 OMX_PRSTATE2(pComponentPrivate->dbg, "Incorrect State Transition 0x%x\n",eError); 3356 } 3357 break; 3358 case OMX_StatePause: 3359 OMX_VidDec_Return(pComponentPrivate); 3360 OMX_VidDec_Return(pComponentPrivate); 3361 3362 OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning to OMX_StatePause C 0x%x N 0x%lx\n",pComponentPrivate->eState, nParam1); 3363 if (pComponentPrivate->eState == OMX_StatePause) { 3364 eError = OMX_ErrorSameState; 3365 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3366 pComponentPrivate->pHandle->pApplicationPrivate, 3367 OMX_EventError, 3368 OMX_ErrorSameState, 3369 OMX_TI_ErrorMinor, 3370 NULL); 3371 OMX_PRSTATE4(pComponentPrivate->dbg, "Same State 0x%x\n",eError); 3372 break; 3373 } 3374 else if (pComponentPrivate->eState == OMX_StateExecuting) { 3375#ifdef __PERF_INSTRUMENTATION__ 3376 pComponentPrivate->lcml_nCntOpReceived = 0; 3377 PERF_Boundary(pComponentPrivate->pPERFcomp, 3378 PERF_BoundaryComplete | PERF_BoundarySteadyState); 3379#endif 3380 3381 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 3382 pComponentPrivate->bIsPaused = 1; 3383 OMX_VidDec_Return(pComponentPrivate); 3384 OMX_VidDec_Return(pComponentPrivate); 3385 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 3386 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 3387 pComponentPrivate->pLCML != NULL && 3388 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 3389 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 3390 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlPause 0x%p\n",pLcmlHandle); 3391 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlPause, NULL); 3392 if (eError != OMX_ErrorNone) { 3393 eError = OMX_ErrorHardware; 3394 OMX_PRDSP4(pComponentPrivate->dbg, "Error during EMMCodecControlPause...\n"); 3395 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3396 pComponentPrivate->pHandle->pApplicationPrivate, 3397 OMX_EventError, 3398 eError, 3399 OMX_TI_ErrorSevere, 3400 NULL); 3401 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 3402 break; 3403 } 3404 eError = OMX_ErrorNone; 3405 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 3406 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 3407 } 3408 pComponentPrivate->eLCMLState = VidDec_LCML_State_Pause; 3409 OMX_VidDec_Return(pComponentPrivate); 3410 OMX_VidDec_Return(pComponentPrivate); 3411 pComponentPrivate->eLCMLState = VidDec_LCML_State_Pause; 3412 eError = OMX_ErrorNone; 3413 pComponentPrivate->bIsPaused = 1; 3414 pComponentPrivate->eState = OMX_StatePause; 3415 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3416 pComponentPrivate->pHandle->pApplicationPrivate, 3417 OMX_EventCmdComplete, 3418 OMX_CommandStateSet, 3419 pComponentPrivate->eState, 3420 NULL); 3421 3422 break; 3423 } 3424 else if (pComponentPrivate->eState == OMX_StateIdle) { 3425 pComponentPrivate->bIsPaused = 1; 3426 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 3427 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 3428 pComponentPrivate->pLCML != NULL && 3429 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 3430 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 3431 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 3432 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlPause 0x%p\n",pLcmlHandle); 3433 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlPause, NULL); 3434 if (eError != OMX_ErrorNone) { 3435 OMX_PRDSP4(pComponentPrivate->dbg, "During EMMCodecControlPause...\n"); 3436 eError = OMX_ErrorHardware; 3437 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3438 pComponentPrivate->pHandle->pApplicationPrivate, 3439 OMX_EventError, 3440 eError, 3441 OMX_TI_ErrorSevere, 3442 NULL); 3443 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 3444 break; 3445 } 3446 eError = OMX_ErrorNone; 3447 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 3448 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 3449 } 3450 pComponentPrivate->eLCMLState = VidDec_LCML_State_Pause; 3451 eError = OMX_ErrorNone; 3452 pComponentPrivate->bIsPaused = 1; 3453 pComponentPrivate->eState = OMX_StatePause; 3454 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3455 pComponentPrivate->pHandle->pApplicationPrivate, 3456 OMX_EventCmdComplete, 3457 OMX_CommandStateSet, 3458 pComponentPrivate->eState, 3459 NULL); 3460 OMX_PRSTATE2(pComponentPrivate->dbg, "Transition to OMX_StatePause\n"); 3461 } 3462 else { 3463 eError = OMX_ErrorIncorrectStateTransition; 3464 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3465 pComponentPrivate->pHandle->pApplicationPrivate, 3466 OMX_EventError, 3467 OMX_ErrorIncorrectStateTransition, 3468 OMX_TI_ErrorMinor, 3469 "Incorrect State Transition"); 3470 OMX_PRSTATE4(pComponentPrivate->dbg, "Incorrect State Transition\n"); 3471 } 3472 break; 3473 case OMX_StateInvalid: 3474 OMX_PRINT1(pComponentPrivate->dbg, "Transitioning to OMX_StateInvalid C 0x%x N 0x%lx\n",pComponentPrivate->eState, nParam1); 3475 if (pComponentPrivate->eState == OMX_StateInvalid) { 3476 eError = OMX_ErrorSameState; 3477 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3478 pComponentPrivate->pHandle->pApplicationPrivate, 3479 OMX_EventError, 3480 OMX_ErrorSameState, 3481 OMX_TI_ErrorCritical, 3482 "Same State"); 3483 OMX_PRSTATE4(pComponentPrivate->dbg, "Same State...\n"); 3484 break; 3485 } 3486 else if (pComponentPrivate->eState == OMX_StateIdle || pComponentPrivate->eState == OMX_StateExecuting) { 3487 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 3488 if (pComponentPrivate->eState == OMX_StateExecuting) { 3489 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 3490 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 3491 pComponentPrivate->pLCML != NULL && 3492 pComponentPrivate->bLCMLHalted != OMX_TRUE) { 3493 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 3494 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called MMCodecControlStop 0x%x\n",eError); 3495 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, MMCodecControlStop, NULL); 3496 if (eError != OMX_ErrorNone) { 3497 OMX_PRDSP4(pComponentPrivate->dbg, "Occurred in Codec Stop...\n"); 3498 eError = OMX_ErrorHardware; 3499 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3500 pComponentPrivate->pHandle->pApplicationPrivate, 3501 OMX_EventError, 3502 eError, 3503 OMX_TI_ErrorCritical, 3504 NULL); 3505 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 3506 break; 3507 } 3508 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 3509 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 3510 } 3511 3512 pComponentPrivate->eLCMLState = VidDec_LCML_State_Stop; 3513 } 3514 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 3515 pComponentPrivate->pLCML != NULL){ 3516 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlDestroy, NULL); 3517 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlDestroy 0x%p\n",pLcmlHandle); 3518 if (eError != OMX_ErrorNone) { 3519 OMX_PRDSP4(pComponentPrivate->dbg, "Occurred in Codec Destroy...\n"); 3520 eError = OMX_ErrorHardware; 3521 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3522 pComponentPrivate->pHandle->pApplicationPrivate, 3523 OMX_EventError, 3524 eError, 3525 OMX_TI_ErrorCritical, 3526 NULL); 3527 OMX_PRSTATE4(pComponentPrivate->dbg, "Incorrect State Transition 0x%x\n", eError); 3528 break; 3529 } 3530 } 3531 3532 pComponentPrivate->eLCMLState = VidDec_LCML_State_Destroy; 3533 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload) { 3534#ifndef UNDER_CE 3535 if(pComponentPrivate->pModLCML != NULL){ 3536 dlclose(pComponentPrivate->pModLCML); 3537 pComponentPrivate->pModLCML = NULL; 3538 pComponentPrivate->pLCML = NULL; 3539 pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload; 3540 } 3541#else 3542 if(pComponentPrivate->pModLCML != NULL){ 3543 FreeLibrary(pComponentPrivate->pModLCML); 3544 pComponentPrivate->pModLCML = NULL; 3545 pComponentPrivate->pLCML = NULL; 3546 pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload; 3547 } 3548#endif 3549 } 3550 for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) { 3551 if(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->bAllocByComponent == OMX_TRUE){ 3552 if(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr != NULL) { 3553 OMX_BUFFERHEADERTYPE* pBuffHead = NULL; 3554 OMX_U8* pTemp = NULL; 3555 pBuffHead = pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr; 3556 if(pBuffHead->pBuffer != NULL){ 3557 pTemp = (OMX_U8*)(pBuffHead->pBuffer); 3558 pTemp -= VIDDEC_PADDING_HALF; 3559 pBuffHead->pBuffer = (OMX_U8*)pTemp; 3560 free(pBuffHead->pBuffer); 3561 pBuffHead->pBuffer = NULL; 3562 pTemp = NULL; 3563 } 3564 } 3565 } 3566 } 3567 3568 for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) { 3569 if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->bAllocByComponent == OMX_TRUE){ 3570 if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr != NULL) { 3571 OMX_BUFFERHEADERTYPE* pBuffHead = NULL; 3572 OMX_U8* pTemp = NULL; 3573 pBuffHead = pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr; 3574 if(pBuffHead->pBuffer != NULL){ 3575 pTemp = (OMX_U8*)(pBuffHead->pBuffer); 3576 pTemp -= VIDDEC_PADDING_HALF; 3577 pBuffHead->pBuffer = (OMX_U8*)pTemp; 3578 free(pBuffHead->pBuffer); 3579 pBuffHead->pBuffer = NULL; 3580 pTemp = NULL; 3581 } 3582 } 3583 } 3584 } 3585#ifdef RESOURCE_MANAGER_ENABLED 3586 if(pComponentPrivate->eRMProxyState == VidDec_RMPROXY_State_Registered){ 3587 OMX_PRMGR2(pComponentPrivate->dbg, "memory usage 4 %d : %d bytes\n",(unsigned int)pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0],(unsigned int)VIDDEC_MEMUSAGE); 3588 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 3589 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_H264_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3590 if (eError != OMX_ErrorNone) { 3591 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3592 } 3593 } 3594 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 3595 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_WMV_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3596 if (eError != OMX_ErrorNone) { 3597 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3598 } 3599 } 3600 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) { 3601 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG4_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3602 if (eError != OMX_ErrorNone) { 3603 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3604 } 3605 } 3606 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 3607 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_H263_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3608 if (eError != OMX_ErrorNone) { 3609 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3610 } 3611 } 3612 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 3613 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG2_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3614 if (eError != OMX_ErrorNone) { 3615 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3616 } 3617 } 3618#ifdef VIDDEC_SPARK_CODE 3619 else if (VIDDEC_SPARKCHECK) { 3620 eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_FreeResource, OMX_MPEG4_Decode_COMPONENT, 0, VIDDEC_MEMUSAGE, NULL); 3621 if (eError != OMX_ErrorNone) { 3622 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3623 } 3624 } 3625#endif 3626 else { 3627 eError = OMX_ErrorUnsupportedSetting; 3628 goto EXIT; 3629 } 3630 pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Load; 3631 } 3632 if(pComponentPrivate->eRMProxyState != VidDec_RMPROXY_State_Unload){ 3633 eError = RMProxy_DeinitalizeEx(OMX_COMPONENTTYPE_VIDEO); 3634 if (eError != OMX_ErrorNone) { 3635 OMX_PRMGR4(pComponentPrivate->dbg, "Error returned from destroy ResourceManagerProxy thread\n"); 3636 } 3637 pComponentPrivate->eRMProxyState = VidDec_RMPROXY_State_Unload; 3638 } 3639#endif 3640 eError = OMX_ErrorInvalidState; 3641 pComponentPrivate->eState = OMX_StateInvalid; 3642 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3643 pComponentPrivate->pHandle->pApplicationPrivate, 3644 OMX_EventError, 3645 OMX_ErrorInvalidState, 3646 OMX_TI_ErrorCritical, 3647 "Invalid State"); 3648 OMX_PRSTATE4(pComponentPrivate->dbg, "Incorrect State Transition 0x%x\n", eError); 3649 break; 3650 } 3651 else{ 3652 eError = OMX_ErrorIncorrectStateTransition; 3653 pComponentPrivate->eState = OMX_StateInvalid; 3654 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3655 pComponentPrivate->pHandle->pApplicationPrivate, 3656 OMX_EventError, 3657 OMX_ErrorInvalidState, 3658 OMX_TI_ErrorCritical, 3659 "Incorrect State Transition"); 3660 OMX_PRSTATE4(pComponentPrivate->dbg, "Incorrect State Transition 0x%x\n", eError); 3661 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3662 pComponentPrivate->pHandle->pApplicationPrivate, 3663 OMX_EventCmdComplete, 3664 OMX_CommandStateSet, 3665 pComponentPrivate->eState, 3666 NULL); 3667 3668 } 3669 break; 3670 case OMX_StateWaitForResources: 3671 OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning to OMX_StateWaitForResources C 0x%x N 0x%lx\n",pComponentPrivate->eState, nParam1); 3672 if (pComponentPrivate->eState == OMX_StateWaitForResources) { 3673 eError = OMX_ErrorSameState; 3674 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3675 pComponentPrivate->pHandle->pApplicationPrivate, 3676 OMX_EventError, 3677 OMX_ErrorSameState, 3678 OMX_TI_ErrorMinor, 3679 NULL); 3680 OMX_PRSTATE4(pComponentPrivate->dbg, "Same State 0x%x\n", eError); 3681 } 3682 else if (pComponentPrivate->eState == OMX_StateLoaded) { 3683 /*add code to wait for resources*/ 3684 eError = OMX_ErrorNone; 3685 pComponentPrivate->bIsPaused = 0; 3686 pComponentPrivate->eState = OMX_StateWaitForResources; 3687 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3688 pComponentPrivate->pHandle->pApplicationPrivate, 3689 OMX_EventCmdComplete, 3690 OMX_CommandStateSet, 3691 pComponentPrivate->eState, 3692 NULL); 3693 } 3694 else { 3695 eError = OMX_ErrorIncorrectStateTransition; 3696 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3697 pComponentPrivate->pHandle->pApplicationPrivate, 3698 OMX_EventError, 3699 OMX_ErrorIncorrectStateTransition, 3700 OMX_TI_ErrorMinor, 3701 NULL); 3702 OMX_PRSTATE4(pComponentPrivate->dbg, "Incorrect State Transition 0x%x\n", eError); 3703 } 3704 3705 break; 3706 3707 case OMX_StateMax: 3708 OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning to OMX_StateMax C 0x%x N 0x%lx\n",pComponentPrivate->eState, nParam1); 3709 eError = OMX_ErrorIncorrectStateTransition; 3710 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3711 pComponentPrivate->pHandle->pApplicationPrivate, 3712 OMX_EventError, 3713 OMX_ErrorIncorrectStateTransition, 3714 OMX_TI_ErrorMinor, 3715 NULL); 3716 OMX_PRSTATE4(pComponentPrivate->dbg, "Incorrect State Transition 0x%x\n", eError); 3717 break; 3718 default: 3719 OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning to default C 0x%x N 0x%lx\n",pComponentPrivate->eState, nParam1); 3720 eError = OMX_ErrorIncorrectStateTransition; 3721 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 3722 pComponentPrivate->pHandle->pApplicationPrivate, 3723 OMX_EventError, 3724 OMX_ErrorIncorrectStateTransition, 3725 OMX_TI_ErrorMinor, 3726 NULL); 3727 OMX_PRSTATE4(pComponentPrivate->dbg, "Incorrect State Transition 0x%x\n", eError); 3728 break; 3729 } /* End of Switch */ 3730 3731 3732 3733EXIT: 3734 OMX_PRINT1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 3735 return eError; 3736} 3737 3738/******************************************************************************/ 3739/** 3740 * Sets free output buffers 3741 **/ 3742/******************************************************************************/ 3743 3744OMX_ERRORTYPE VIDDEC_HandleFreeOutputBufferFromApp(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate) 3745{ 3746 OMX_ERRORTYPE eError = OMX_ErrorNone; 3747 OMX_BUFFERHEADERTYPE* pBuffHead; 3748 OMX_U32 size_out_buf; 3749 int ret; 3750 LCML_DSP_INTERFACE* pLcmlHandle; 3751 VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL; 3752 OMX_PRBUFFER1(pComponentPrivate->dbg, "+++ENTERING\n"); 3753 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate 0x%p\n", pComponentPrivate); 3754 size_out_buf = (OMX_U32)pComponentPrivate->pOutPortDef->nBufferSize; 3755 pLcmlHandle = (LCML_DSP_INTERFACE*)(pComponentPrivate->pLCML); 3756 ret = read(pComponentPrivate->free_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead)); 3757 3758 3759 if (ret == -1) { 3760 OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from the pipe\n"); 3761 eError = OMX_ErrorHardware; 3762 goto EXIT; 3763 } 3764 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead 0x%p eExecuteToIdle 0x%x\n", pBuffHead, pComponentPrivate->eExecuteToIdle); 3765 3766 if(pBuffHead->pOutputPortPrivate != NULL) { 3767 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate; 3768 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 3769 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 3770 pComponentPrivate->pLCML != NULL) { 3771#ifdef KHRONOS_1_1 3772 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 3773 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 3774 MP4VD_GPP_SN_UALGOutputParams* pUalgOutParams = NULL; 3775 pUalgOutParams = (MP4VD_GPP_SN_UALGOutputParams *)pBufferPrivate->pUalgParam; 3776 if (pComponentPrivate->eMBErrorReport.bEnabled) { 3777 pUalgOutParams->lMbErrorBufFlag = 1; 3778 } 3779 else { 3780 pUalgOutParams->lMbErrorBufFlag = 0; 3781 } 3782 } 3783 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 3784 H264VDEC_UALGOutputParam* pUalgOutParams = NULL; 3785 pUalgOutParams = (H264VDEC_UALGOutputParam *)pBufferPrivate->pUalgParam; 3786 if (pComponentPrivate->eMBErrorReport.bEnabled) { 3787 pUalgOutParams->lMBErrStatFlag = 1; 3788 } 3789 else { 3790 pUalgOutParams->lMBErrStatFlag = 0; 3791 } 3792 } 3793#endif 3794 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP; 3795 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 3796 3797#ifdef __PERF_INSTRUMENTATION__ 3798 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 3799 pBuffHead->pBuffer, 3800 pBuffHead->nFilledLen, 3801 PERF_ModuleCommonLayer); 3802#endif 3803 3804 OMX_PRDSP1(pComponentPrivate->dbg, "LCML_QueueBuffer(OUTPUT)\n"); 3805 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 3806 EMMCodecOuputBuffer, 3807 pBuffHead->pBuffer, 3808 pBuffHead->nAllocLen, 3809 pBuffHead->nFilledLen, 3810 (OMX_U8*)(pBufferPrivate->pUalgParam), 3811 (OMX_S32)pBufferPrivate->nUalgParamSize, 3812 (OMX_U8*)pBuffHead); 3813 if (eError != OMX_ErrorNone){ 3814 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer 0x%x\n", eError); 3815 eError = OMX_ErrorHardware; 3816 goto EXIT; 3817 } 3818 } 3819 else { 3820 eError = OMX_ErrorHardware; 3821 goto EXIT; 3822 } 3823 } 3824 else { 3825 OMX_PRBUFFER2(pComponentPrivate->dbg, "null element *************n\n"); 3826 } 3827 3828EXIT: 3829 OMX_PRBUFFER1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 3830 return eError; 3831} 3832 3833#ifdef VIDDEC_ACTIVATEPARSER 3834OMX_S32 GET_NUM_BIT_REQ(OMX_U32 num) 3835{ 3836 OMX_S32 i; 3837 for ( i = 31; i >= 0; i--) 3838 { 3839 if (num & (0x1 << i) ) break; 3840 } 3841 return (i+1); 3842} 3843#endif 3844 3845#ifdef VIDDEC_ACTIVATEPARSER 3846/* ==========================================================================*/ 3847/* func VIDDEC_ParseVideo_MPEG2 */ 3848/* */ 3849/* desc */ 3850/* ==========================================================================*/ 3851OMX_ERRORTYPE VIDDEC_ParseVideo_MPEG2( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead) 3852{ 3853 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 3854 OMX_U32 nTempValue = 0; 3855 /*OMX_U8* pTempValue = 0;*/ 3856 /*OMX_U8* pTempSize = 0;*/ 3857 /*OMX_U32 nProfile = 0;*/ 3858 /*OMX_U32 nLevel = 0;*/ 3859 OMX_U32 nBitPosition = 0; 3860 OMX_U8* pHeaderStream = (OMX_U8*)pBuffHead->pBuffer; 3861 OMX_BOOL nStartFlag = OMX_FALSE; 3862 OMX_U32 nInBytePosition = 0; 3863 OMX_U32 nTotalInBytes = 0; 3864 OMX_U32 nNalUnitType = 0; 3865 3866 nTotalInBytes = pBuffHead->nFilledLen; 3867 3868 do{ 3869 for (; (!nStartFlag) && (nInBytePosition < nTotalInBytes - 3); ) { 3870 if (VIDDEC_GetBits(&nBitPosition, 24, pHeaderStream, OMX_FALSE) != 0x000001) { 3871 nBitPosition += 8; 3872 nInBytePosition++; 3873 } 3874 else { 3875 nStartFlag = OMX_TRUE; 3876 nBitPosition += 24; 3877 nInBytePosition += 3; 3878 } 3879 } 3880 if (!nStartFlag) { 3881 eError = OMX_ErrorStreamCorrupt; 3882 goto EXIT; 3883 } 3884 nNalUnitType = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3885 nInBytePosition++; 3886 if (nNalUnitType != 0xB3) { 3887 nStartFlag = OMX_FALSE; 3888 } 3889 }while (nNalUnitType != 0xB3); 3890 3891 if (nNalUnitType == 0xB3) { 3892 nTempValue = VIDDEC_GetBits(&nBitPosition, 12, pHeaderStream, OMX_TRUE); 3893 (*nWidth) = (nTempValue); 3894 nTempValue = VIDDEC_GetBits(&nBitPosition, 12, pHeaderStream, OMX_TRUE); 3895 (*nHeight) = (nTempValue); 3896 eError = OMX_ErrorNone; 3897 } 3898 3899EXIT: 3900 return eError; 3901} 3902#endif 3903 3904#ifdef VIDDEC_ACTIVATEPARSER 3905/* ==========================================================================*/ 3906/* func VIDDEC_ParseVideo_WMV9_VC1 */ 3907/* */ 3908/* desc */ 3909/* ==========================================================================*/ 3910OMX_ERRORTYPE VIDDEC_ParseVideo_WMV9_VC1( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead) 3911{ 3912 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 3913 OMX_U32 nTempValue = 0; 3914 /*OMX_U8* pTempValue = 0;*/ 3915 /*OMX_U8* pTempSize = 0;*/ 3916 OMX_U32 nProfile = 0; 3917 OMX_U32 nLevel = 0; 3918 OMX_U32 nBitPosition = 0; 3919 OMX_U8* pHeaderStream = (OMX_U8*)pBuffHead->pBuffer; 3920 OMX_BOOL nStartFlag = OMX_FALSE; 3921 OMX_U32 nInBytePosition = 0; 3922 OMX_U32 nTotalInBytes = 0; 3923 OMX_U32 nNalUnitType = 0; 3924 3925 nTotalInBytes = pBuffHead->nFilledLen; 3926 3927 do{ 3928 for (; (!nStartFlag) && (nInBytePosition < nTotalInBytes - 3); ) { 3929 if (VIDDEC_GetBits(&nBitPosition, 24, pHeaderStream, OMX_FALSE) != 0x000001) { 3930 nBitPosition += 8; 3931 nInBytePosition++; 3932 } 3933 else { 3934 nStartFlag = OMX_TRUE; 3935 nBitPosition += 24; 3936 nInBytePosition += 3; 3937 } 3938 } 3939 if (!nStartFlag) { 3940 eError = OMX_ErrorStreamCorrupt; 3941 goto EXIT; 3942 } 3943 nNalUnitType = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3944 nInBytePosition++; 3945 if (nNalUnitType != 0x0f && nNalUnitType != 0x0e) { 3946 nStartFlag = OMX_FALSE; 3947 } 3948 }while (nNalUnitType != 0x0f && nNalUnitType != 0x0e); 3949 3950 if (nNalUnitType == 0x0f || nNalUnitType == 0x0e) { 3951 nProfile = VIDDEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); 3952 nLevel = VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); 3953 nTempValue = VIDDEC_GetBits(&nBitPosition, 11, pHeaderStream, OMX_TRUE); 3954 nTempValue = VIDDEC_GetBits(&nBitPosition, 12, pHeaderStream, OMX_TRUE); 3955 (*nWidth) = (nTempValue * 2) + 2; 3956 nTempValue = VIDDEC_GetBits(&nBitPosition, 12, pHeaderStream, OMX_TRUE); 3957 (*nHeight) = (nTempValue * 2) + 2; 3958 eError = OMX_ErrorNone; 3959 } 3960 3961EXIT: 3962 return eError; 3963} 3964#endif 3965 3966#ifdef VIDDEC_ACTIVATEPARSER 3967/* ==========================================================================*/ 3968/* func VIDDEC_ParseVideo_WMV9_RCV */ 3969/* */ 3970/* desc */ 3971/* ==========================================================================*/ 3972OMX_ERRORTYPE VIDDEC_ParseVideo_WMV9_RCV( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead) 3973{ 3974 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 3975 OMX_U32 nTempValue = 0; 3976 OMX_U8* pTempValue = 0; 3977 /*OMX_U8* pTempSize = 0;*/ 3978 OMX_U32 Profile = 0; 3979 /*OMX_U32 i = 0;*/ 3980 OMX_U32 nBitPosition = 0; 3981 OMX_U8* pHeaderStream = (OMX_U8*)pBuffHead->pBuffer; 3982 3983 if (pBuffHead->nFilledLen >= 20) { 3984 nTempValue = VIDDEC_GetBits(&nBitPosition, 32, pHeaderStream, OMX_TRUE); 3985 nTempValue = VIDDEC_GetBits(&nBitPosition, 32, pHeaderStream, OMX_TRUE); 3986 Profile = VIDDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE); 3987 nTempValue = VIDDEC_GetBits(&nBitPosition, 28, pHeaderStream, OMX_TRUE); 3988 3989 pTempValue = (OMX_U8*)&nTempValue; 3990 pTempValue[0] = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3991 pTempValue[1] = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3992 pTempValue[2] = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3993 pTempValue[3] = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3994 (*nHeight) = nTempValue; 3995 3996 pTempValue[0] = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3997 pTempValue[1] = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3998 pTempValue[2] = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 3999 pTempValue[3] = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); 4000 (*nWidth) = nTempValue; 4001 eError = OMX_ErrorNone; 4002 } 4003 else { 4004 (*nWidth) = 0; 4005 (*nHeight) = 0; 4006 eError = OMX_ErrorUndefined; 4007 } 4008 4009 return eError; 4010} 4011#endif 4012 4013#ifdef VIDDEC_ACTIVATEPARSER 4014/* ==========================================================================*/ 4015/* func VIDDEC_ParseVideo_MPEG4 */ 4016/* */ 4017/* desc */ 4018/* ==========================================================================*/ 4019OMX_ERRORTYPE VIDDEC_ParseVideo_MPEG4( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead) 4020{ 4021 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 4022 OMX_U32 nSartCode = 0; 4023 OMX_U32 nBitPosition = 0; 4024 OMX_BOOL bHeaderParseCompleted = OMX_FALSE; 4025 OMX_BOOL bFillHeaderInfo = OMX_FALSE; 4026 OMX_U8* pHeaderStream = (OMX_U8*)pBuffHead->pBuffer; 4027 4028 /*OMX_U32 nTotalInBytes = pBuffHead->nFilledLen;*/ 4029 VIDDEC_MPEG4_ParserParam MPEG4_Param; 4030 VIDDEC_MPEG4UncompressedVideoFormat iOutputFormat; 4031 VIDDEC_MPEG4_ParserParam* sMPEG4_Param = &MPEG4_Param; 4032 VIDDEC_VideoPictureHeader sPictHeaderDummy; 4033 VIDDEC_MPEG4VisualVOLHeader sVolHeaderDummy; 4034 VIDDEC_VideoPictureHeader* pPictHeaderPtr = &sPictHeaderDummy; 4035 VIDDEC_MPEG4VisualVOLHeader* sVolHeaderPtr = &sVolHeaderDummy; 4036 4037 pPictHeaderPtr->cnOptional = (OMX_U8*)malloc( sizeof(VIDDEC_MPEG4VisualVOLHeader)); 4038 while (!bHeaderParseCompleted) 4039 { 4040 nSartCode = VIDDEC_GetBits(&nBitPosition, 32, pHeaderStream, OMX_TRUE); 4041 if (nSartCode == 0x1B0) 4042 { 4043 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 4); 4044 pPictHeaderPtr->nProfile = VIDDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE); 4045 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 4); 4046 pPictHeaderPtr->nLevel = VIDDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE); 4047 } 4048 else if (nSartCode == 0x1B5) 4049 { 4050 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4051 sMPEG4_Param->nIsVisualObjectIdentifier = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4052 if (sMPEG4_Param->nIsVisualObjectIdentifier) 4053 { 4054 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 7); 4055 (void)VIDDEC_GetBits(&nBitPosition, 7, pHeaderStream, OMX_TRUE); /* DISCARD THIS INFO (7 bits)*/ 4056 } 4057 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 4); 4058 sMPEG4_Param->nVisualObjectType = VIDDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE); 4059 if (sMPEG4_Param->nVisualObjectType== 1|| sMPEG4_Param->nVisualObjectType== 2) 4060 { 4061 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4062 sMPEG4_Param->nVideoSignalType = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4063 if (sMPEG4_Param->nVideoSignalType) 4064 { 4065 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 3); 4066 sMPEG4_Param->nVideoFormat = VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); 4067 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4068 sMPEG4_Param->nVideoRange = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4069 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4070 sMPEG4_Param->nColorDescription = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4071 if (sMPEG4_Param->nColorDescription) 4072 { 4073 /*Discard this info*/ 4074 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 24); 4075 (void)VIDDEC_GetBits(&nBitPosition, 24, pHeaderStream, OMX_TRUE); 4076 } 4077 } 4078 } 4079 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4080 sMPEG4_Param->NBitZero = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4081 while ((nBitPosition%8)!= 0) { 4082 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4083 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE);/*discard align bits*/ 4084 } 4085 } 4086 else if ((nSartCode >= 0x100)&&(nSartCode <= 0x11F)) 4087 { 4088 /*Do nothing*/ 4089 /* OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 8); 4090 (void)VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE);*/ 4091 } 4092 else if (nSartCode == 0x1B3) /*GOV*/ 4093 { 4094 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 20); 4095 (void)VIDDEC_GetBits(&nBitPosition, 20, pHeaderStream, OMX_TRUE); 4096 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4097 sMPEG4_Param->NBitZero = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4098 while ((nBitPosition%8)!= 0){ 4099 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4100 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE);/*discard align bits*/ 4101 } 4102 } 4103 else if (nSartCode == 0x1B2) /*user data*/ 4104 { 4105 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 24); 4106 while (VIDDEC_GetBits(&nBitPosition, 24, pHeaderStream, OMX_TRUE)!= 0x1) 4107 nBitPosition-=16; /*discard only 8 bits and try againg until*/ 4108 /*the next start code is found*/ 4109 nBitPosition -=24; /* prepare to read the entire start code*/ 4110 /* OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4111 sMPEG4_Param->NBitZero = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4112 PRINT("sMPEG4_Param->NBitZero = %d", sMPEG4_Param->NBitZero); 4113 while ((nBitPosition%8)!= 0) { 4114 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4115 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE);*//*discard align bits*/ 4116 /*}*/ 4117 } 4118 else if ((nSartCode >= 0x120)&&(nSartCode <= 0x12F)) 4119 { 4120 sVolHeaderPtr->nVideoObjectLayerId = nSartCode&0x0000000f; 4121 sVolHeaderPtr->bShortVideoHeader = 0; 4122 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4123 pPictHeaderPtr->bIsRandomAccessible = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4124 sVolHeaderPtr->bRandomAccessibleVOL = pPictHeaderPtr->bIsRandomAccessible; 4125 if (pPictHeaderPtr->bIsRandomAccessible) 4126 { 4127 /* it seems this never happens*/ 4128 } 4129 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 8); 4130 sMPEG4_Param->nVideoObjectTypeIndication = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); /* 8 bits*/ 4131 sVolHeaderPtr->nVideoObjectTypeIndication = sMPEG4_Param->nVideoObjectTypeIndication; 4132 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4133 sMPEG4_Param->nIsVisualObjectLayerIdentifier = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE);/*1 bit*/ 4134 sVolHeaderPtr->nVideoObjectLayerId = sMPEG4_Param->nIsVisualObjectLayerIdentifier; 4135 sMPEG4_Param->nLayerVerId = 0; 4136 if (sMPEG4_Param->nIsVisualObjectLayerIdentifier) 4137 { 4138 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 4); 4139 sMPEG4_Param->nLayerVerId = VIDDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE); /*4 bits*/ 4140 sVolHeaderPtr->nVideoObjectLayerVerId = sMPEG4_Param->nLayerVerId; 4141 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 3); 4142 sMPEG4_Param->nLayerPriority = VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); /*3 bits*/ 4143 sVolHeaderPtr->nVideoObjectLayerPriority = sMPEG4_Param->nLayerPriority; 4144 } 4145 4146 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 4); 4147 sMPEG4_Param->nAspectRadio = VIDDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE); /*4 bits*/ 4148 if (sMPEG4_Param->nAspectRadio == 0xf) 4149 { 4150 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 8); 4151 sMPEG4_Param->nParWidth = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); /*8 bits*/ 4152 sVolHeaderPtr->nAspectRatioNum = sMPEG4_Param->nParWidth; 4153 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 8); 4154 sMPEG4_Param->nParHeight = VIDDEC_GetBits(&nBitPosition, 8, pHeaderStream, OMX_TRUE); /*8 bits*/ 4155 sVolHeaderPtr->nAspectRatioDenom = sMPEG4_Param->nParHeight; 4156 } 4157 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4158 sMPEG4_Param->nControlParameters = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4159 if ( sMPEG4_Param->nControlParameters ) 4160 { 4161 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 2); 4162 sMPEG4_Param->nChromaFormat = VIDDEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); /*2 bits*/ 4163 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4164 sMPEG4_Param->nLowDelay = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4165 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4166 sMPEG4_Param->nVbvParameters = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4167 if (sMPEG4_Param->nVbvParameters) 4168 { 4169 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 15); 4170 sMPEG4_Param->nBitRate = VIDDEC_GetBits(&nBitPosition, 15, pHeaderStream, OMX_TRUE)<<15; /*15 bit*/ 4171 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4172 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4173 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 15); 4174 sMPEG4_Param->nBitRate |= VIDDEC_GetBits(&nBitPosition, 15, pHeaderStream, OMX_TRUE); /*15 bit*/ 4175 sVolHeaderPtr->sVbvParams.nBitRate = sMPEG4_Param->nBitRate; 4176 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4177 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4178 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 15); 4179 sMPEG4_Param->nFirstHalfVbvBufferSize = VIDDEC_GetBits(&nBitPosition, 15, pHeaderStream, OMX_TRUE); 4180 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4181 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4182 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 3); 4183 sMPEG4_Param->nLatterHalfVbvBufferSize = VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); 4184 sVolHeaderPtr->sVbvParams.nVbvBufferSize = 4185 (((sMPEG4_Param->nFirstHalfVbvBufferSize) << 3) + sMPEG4_Param->nLatterHalfVbvBufferSize) * 2048; 4186 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 11); 4187 sMPEG4_Param->nFirstHalfVbvOccupancy = VIDDEC_GetBits(&nBitPosition, 11, pHeaderStream, OMX_TRUE); 4188 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4189 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4190 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 15); 4191 sMPEG4_Param->nLatterHalfVbvOccupancy = VIDDEC_GetBits(&nBitPosition, 15, pHeaderStream, OMX_TRUE); 4192 sVolHeaderPtr->sVbvParams.nVbvOccupancy = 4193 (((sMPEG4_Param->nFirstHalfVbvOccupancy) << 15) + sMPEG4_Param->nLatterHalfVbvOccupancy) * 2048; 4194 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4195 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4196 4197 /*OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 48); 4198 (void)VIDDEC_GetBits(&nBitPosition, 48, pHeaderStream, OMX_TRUE);*/ 4199 } 4200 else 4201 { 4202 sMPEG4_Param->nBitRate = 0; 4203 } 4204 } 4205 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 2); 4206 sMPEG4_Param->nLayerShape = VIDDEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); /*2 bits*/ 4207 /*skip one marker_bit*/ 4208 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4209 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4210 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 16); 4211 sMPEG4_Param->nTimeIncrementResolution = VIDDEC_GetBits(&nBitPosition, 16, pHeaderStream, OMX_TRUE); /*16 bits*/ 4212 sVolHeaderPtr->nVOPTimeIncrementResolution = sMPEG4_Param->nTimeIncrementResolution; 4213 /*skip one market bit*/ 4214 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4215 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4216 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4217 sMPEG4_Param->nFnXedVopRate = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4218 sVolHeaderPtr->bnFnXedVopRate = sMPEG4_Param->nFnXedVopRate; 4219 if (sMPEG4_Param->nFnXedVopRate) 4220 { 4221 sMPEG4_Param->nNum_bits = GET_NUM_BIT_REQ (sMPEG4_Param->nTimeIncrementResolution); 4222 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, sMPEG4_Param->nNum_bits); 4223 sVolHeaderPtr->nFnXedVOPTimeIncrement = VIDDEC_GetBits (&nBitPosition, sMPEG4_Param->nNum_bits, pHeaderStream, OMX_TRUE); 4224 } 4225 /*skip one market bit*/ 4226 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4227 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4228 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 13); 4229 (*nWidth) = VIDDEC_GetBits(&nBitPosition, 13, pHeaderStream, OMX_TRUE); /*13 bits*/ 4230 /*skip one market bit*/ 4231 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4232 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4233 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 13); 4234 (*nHeight) = VIDDEC_GetBits(&nBitPosition, 13, pHeaderStream, OMX_TRUE); /*13 bits*/ 4235 4236 /*skip one market bit*/ 4237 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4238 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4239 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4240 sMPEG4_Param->nInterlaced = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4241 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4242 sMPEG4_Param->nObmc = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4243 if (sMPEG4_Param->nLayerVerId) 4244 { 4245 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4246 sMPEG4_Param->NSpriteNotSupported = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4247 if (sMPEG4_Param->NSpriteNotSupported) 4248 { 4249 } 4250 } 4251 else 4252 { 4253 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 2); 4254 sMPEG4_Param->NSpriteNotSupported = VIDDEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); /*2 bits*/ 4255 if (sMPEG4_Param->NSpriteNotSupported) 4256 { 4257 } 4258 } 4259 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4260 sMPEG4_Param->nNot8Bit = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bits*/ 4261 sMPEG4_Param->nQuantPrecision = 5; 4262 sMPEG4_Param->nBitsPerPnXel = 8; 4263 if (sMPEG4_Param->nNot8Bit) 4264 { 4265 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 4); 4266 sMPEG4_Param->nQuantPrecision = VIDDEC_GetBits(&nBitPosition,4, pHeaderStream, OMX_TRUE); /* 4 bits*/ 4267 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 4); 4268 sMPEG4_Param->nBitsPerPnXel = VIDDEC_GetBits(&nBitPosition,4, pHeaderStream, OMX_TRUE); /* 4 bits*/ 4269 } 4270 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4271 sMPEG4_Param->nIsInverseQuantMethodFirst = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bits*/ 4272 if (sMPEG4_Param->nLayerVerId !=1) 4273 { 4274 /*does not support quater sample*/ 4275 /*kip one market bit*/ 4276 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4277 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4278 } 4279 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4280 sMPEG4_Param->nComplexityEstimationDisable = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4281 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4282 sMPEG4_Param->nIsResyncMarkerDisabled = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4283 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4284 sMPEG4_Param->nIsDataPartitioned = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4285 sVolHeaderPtr->bDataPartitioning = sMPEG4_Param->nIsDataPartitioned; 4286 if (sMPEG4_Param->nIsDataPartitioned) 4287 { 4288 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4289 sMPEG4_Param->nRvlc = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4290 sVolHeaderPtr->bReversibleVLC = sMPEG4_Param->nRvlc; 4291 if (sMPEG4_Param->nRvlc) 4292 { 4293 } 4294 } 4295 if (sMPEG4_Param->nLayerVerId !=1) 4296 { 4297 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 2); 4298 (void)VIDDEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); /*2 bit*/ 4299 } 4300 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 1); 4301 sMPEG4_Param->nScalability = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); /*1 bit*/ 4302 /*pPictHeaderPtr->sSizeInMemory.nWidth = (*nWidth); 4303 pPictHeaderPtr->sSizeInMemory.nHeight = (*nHeight); 4304 pPictHeaderPtr->sDisplayedRect = TRect(TSize((*nWidth),(*nHeight)));*/ 4305 if (iOutputFormat.iYuvFormat.iPattern == 0x00000001) 4306 pPictHeaderPtr->nPostDecoderBufferSize = (*nHeight) * (*nWidth) * 3 / 2; /*YUV 420 Planar*/ 4307 else if (iOutputFormat.iYuvFormat.iPattern == 0x00000008) 4308 pPictHeaderPtr->nPostDecoderBufferSize = (*nHeight) * (*nWidth) * 2; /*YUV 422 Interleaved*/ 4309 pPictHeaderPtr->nOptions |= 0x00000008; 4310 if(bFillHeaderInfo) 4311 { 4312 ; 4313 } 4314 bHeaderParseCompleted = OMX_TRUE; 4315 eError = OMX_ErrorNone; 4316 } 4317 else if ( (nSartCode&0xfffffc00) == 0x00008000 ) 4318 { 4319 sVolHeaderPtr->bShortVideoHeader = 1; 4320 /* discard 3 bits for split_screen_indicator, document_camera_indicator*/ 4321 /* and full_picture_freeze_release*/ 4322 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 3); 4323 (void)VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); 4324 OMX_PARSER_CHECKLIMIT(nTotalInBytes, nBitPosition, 3); 4325 sMPEG4_Param->nSourceFormat = VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); 4326 if (sMPEG4_Param->nSourceFormat == 0x1) 4327 { 4328 (*nWidth) = 128; 4329 (*nHeight) = 96; 4330 } 4331 else if (sMPEG4_Param->nSourceFormat == 0x2) 4332 { 4333 (*nWidth) = 176; 4334 (*nHeight) = 144; 4335 } 4336 else if (sMPEG4_Param->nSourceFormat == 0x3) 4337 { 4338 (*nWidth) = 352; 4339 (*nHeight) = 288; 4340 } 4341 else if (sMPEG4_Param->nSourceFormat == 0x4) 4342 { 4343 (*nWidth) = 704; 4344 (*nHeight) = 576; 4345 } 4346 else if (sMPEG4_Param->nSourceFormat == 0x5) 4347 { 4348 (*nWidth) = 1408; 4349 (*nHeight) = 1152; 4350 } 4351 else if (sMPEG4_Param->nSourceFormat == 0x7) 4352 { 4353 sMPEG4_Param->nUFEP = VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); 4354 if(sMPEG4_Param->nUFEP == 1) { 4355 sMPEG4_Param->nSourceFormat = VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); 4356 if (sMPEG4_Param->nSourceFormat == 0x1) 4357 { 4358 (*nWidth) = 128; 4359 (*nHeight) = 96; 4360 } 4361 else if (sMPEG4_Param->nSourceFormat == 0x2) 4362 { 4363 (*nWidth) = 176; 4364 (*nHeight) = 144; 4365 } 4366 else if (sMPEG4_Param->nSourceFormat == 0x3) 4367 { 4368 (*nWidth) = 352; 4369 (*nHeight) = 288; 4370 } 4371 else if (sMPEG4_Param->nSourceFormat == 0x4) 4372 { 4373 4374 (*nWidth) = 704; 4375 (*nHeight) = 576; 4376 } 4377 else if (sMPEG4_Param->nSourceFormat == 0x5) 4378 { 4379 (*nWidth) = 1408; 4380 (*nHeight) = 1152; 4381 } 4382 else if (sMPEG4_Param->nSourceFormat == 0x6) 4383 { 4384 (void)VIDDEC_GetBits(&nBitPosition, 24, pHeaderStream, OMX_TRUE); 4385 sMPEG4_Param->nCPM = VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4386 if(sMPEG4_Param->nCPM) 4387 (void)VIDDEC_GetBits(&nBitPosition, 2, pHeaderStream, OMX_TRUE); 4388 4389 (void)VIDDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE); 4390 4391 sMPEG4_Param->nPWI = VIDDEC_GetBits(&nBitPosition, 9, pHeaderStream, OMX_TRUE); 4392 (*nWidth) = (sMPEG4_Param->nPWI + 1)*4; 4393 4394 (void)VIDDEC_GetBits(&nBitPosition, 1, pHeaderStream, OMX_TRUE); 4395 4396 sMPEG4_Param->nPHI = VIDDEC_GetBits(&nBitPosition, 9, pHeaderStream, OMX_TRUE); 4397 (*nHeight) = sMPEG4_Param->nPHI*4; 4398 4399 } 4400 else if (sMPEG4_Param->nSourceFormat == 0x7) 4401 { 4402 sMPEG4_Param->nSourceFormat = VIDDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE); 4403 (*nWidth) = 1408; 4404 (*nHeight) = 1152; 4405 } 4406 else 4407 { 4408 eError = OMX_ErrorUnsupportedSetting; 4409 goto EXIT; 4410 } 4411 } 4412 } 4413 else 4414 { 4415 eError = OMX_ErrorUnsupportedSetting; 4416 goto EXIT; 4417 } 4418 bHeaderParseCompleted = OMX_TRUE; 4419 eError = OMX_ErrorNone; 4420 } 4421 else 4422 { 4423 eError = OMX_ErrorUnsupportedSetting; 4424 goto EXIT; 4425 } 4426 } 4427EXIT: 4428 if(pPictHeaderPtr->cnOptional != NULL) 4429 { 4430 free( pPictHeaderPtr->cnOptional); 4431 pPictHeaderPtr->cnOptional = NULL; 4432 } 4433 return eError; 4434} 4435#endif 4436 4437#ifdef VIDDEC_ACTIVATEPARSER 4438/* ==========================================================================*/ 4439/* func VIDDEC_ScanConfigBufferAVC */ 4440/* */ 4441/* desc Use to scan buffer for certain patter. Used to know if ConfigBuffers are together */ 4442/* ==========================================================================*/ 4443static OMX_U32 VIDDEC_ScanConfigBufferAVC(OMX_BUFFERHEADERTYPE* pBuffHead, OMX_U32 pattern){ 4444 OMX_U32 nBitPosition = 0; 4445 OMX_U32 nInBytePosition = 0; 4446 OMX_U32 nPatternCounter = 0; 4447 OMX_U32 nTotalInBytes = pBuffHead->nFilledLen; 4448 OMX_U8* nBitStream = (OMX_U8*)pBuffHead->pBuffer; 4449 4450 while (nInBytePosition < nTotalInBytes - 3){ 4451 if (VIDDEC_GetBits(&nBitPosition, 24, nBitStream, OMX_FALSE) != pattern) { 4452 nBitPosition += 8; 4453 nInBytePosition++; 4454 } 4455 else { 4456 /*Pattern found; add count*/ 4457 nPatternCounter++; 4458 nBitPosition += 24; 4459 nInBytePosition += 3; 4460 } 4461 } 4462 return nPatternCounter; 4463} 4464 4465/* ==========================================================================*/ 4466/* func VIDDEC_ParseVideo_H264 */ 4467/* */ 4468/* desc */ 4469/* ==========================================================================*/ 4470OMX_ERRORTYPE VIDDEC_ParseVideo_H264(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, 4471 OMX_BUFFERHEADERTYPE* pBuffHead,OMX_S32* nWidth, 4472 OMX_S32* nHeight, OMX_S32* nCropWidth, 4473 OMX_S32* nCropHeight, OMX_U32 nType) 4474{ 4475 OMX_ERRORTYPE eError = OMX_ErrorBadParameter; 4476 OMX_S32 i = 0; 4477 VIDDEC_AVC_ParserParam* sParserParam; 4478 /*OMX_S32 nRetVal = 0;*/ 4479 OMX_BOOL nStartFlag = OMX_FALSE; 4480 OMX_U32 nBitPosition = 0; 4481 OMX_U32 nRbspPosition = 0; 4482 OMX_U32 nTotalInBytes = 0; 4483 OMX_U32 nInBytePosition = 0; 4484 OMX_U32 nInPositionTemp = 0; 4485 OMX_U32 nNumOfBytesInRbsp = 0; 4486 OMX_S32 nNumBytesInNALunit = 0; 4487 OMX_U8* nBitStream = 0; 4488 OMX_U32 nNalUnitType = 0; 4489 OMX_U8* nRbspByte = NULL; 4490 4491 OMX_U8 *pDataBuf; 4492 4493 /* counter used for fragmentation of Config Buffer Code */ 4494 static OMX_U32 nConfigBufferCounter; 4495 4496 nTotalInBytes = pBuffHead->nFilledLen; 4497 nBitStream = (OMX_U8*)pBuffHead->pBuffer;/* + (OMX_U8*)pBuffHead->nOffset;*/ 4498 nRbspByte = (OMX_U8*)malloc(nTotalInBytes); 4499 memset(nRbspByte, 0x0, nTotalInBytes); 4500 sParserParam = (VIDDEC_AVC_ParserParam *)malloc(sizeof(VIDDEC_AVC_ParserParam)); 4501 4502 if (nType == 0) { 4503 /* Start of Handle fragmentation of Config Buffer Code*/ 4504 /*Scan for 2 "0x000001", requiered on buffer to parser properly*/ 4505 nConfigBufferCounter += VIDDEC_ScanConfigBufferAVC(pBuffHead, 0x000001); 4506 if(nConfigBufferCounter < 2){ /*If less of 2 we need to store the data internally to later assembly the complete ConfigBuffer*/ 4507 /*Set flag to False, the Config Buffer is not complete */ 4508 OMX_PRINT2(pComponentPrivate->dbg, "Setting bConfigBufferCompleteAVC = OMX_FALSE"); 4509 pComponentPrivate->bConfigBufferCompleteAVC = OMX_FALSE; 4510 /* Malloc Buffer if is not created yet, use Port buffer size*/ 4511 if(pComponentPrivate->pInternalConfigBufferAVC == NULL){ 4512 pComponentPrivate->pInternalConfigBufferAVC = malloc(pComponentPrivate->pInPortDef->nBufferSize); 4513 if(pComponentPrivate->pInternalConfigBufferAVC == NULL){ 4514 eError = OMX_ErrorInsufficientResources; 4515 goto EXIT; 4516 } 4517 } 4518 /* Check if memcpy is safe*/ 4519 if(pComponentPrivate->pInPortDef->nBufferSize >= pComponentPrivate->nInternalConfigBufferFilledAVC + pBuffHead->nFilledLen){ 4520 /*Append current buffer data to Internal Config Buffer */ 4521 if(memcpy((OMX_U8*)(pComponentPrivate->pInternalConfigBufferAVC + pComponentPrivate->nInternalConfigBufferFilledAVC), 4522 pBuffHead->pBuffer, 4523 pBuffHead->nFilledLen) == NULL) { 4524 eError = OMX_ErrorInsufficientResources; 4525 goto EXIT; 4526 } 4527 } 4528 else{ 4529 eError =OMX_ErrorInsufficientResources; 4530 goto EXIT; 4531 } 4532 /*Update Filled length of Internal Buffer*/ 4533 pComponentPrivate->nInternalConfigBufferFilledAVC += pBuffHead->nFilledLen; 4534 /* Exit with out error*/ 4535 eError = OMX_ErrorNone; 4536 goto EXIT; 4537 } 4538 else{ /* We have all the requiered data*/ 4539 OMX_PRINT2(pComponentPrivate->dbg, "Setting bConfigBufferCompleteAVC = OMX_TRUE"); 4540 pComponentPrivate->bConfigBufferCompleteAVC = OMX_TRUE; 4541 /* If we have already Config data of previous buffer, we assembly the final ConfigBuffer*/ 4542 if(pComponentPrivate->pInternalConfigBufferAVC != NULL){ 4543 /*Check if memcpy is safe*/ 4544 if(pComponentPrivate->pInPortDef->nBufferSize >= 4545 pComponentPrivate->nInternalConfigBufferFilledAVC + pBuffHead->nFilledLen){ 4546 /*The current data of the Buffer has to be placed at the end of buffer*/ 4547 if(memcpy((OMX_U8*)(pBuffHead->pBuffer + pComponentPrivate->nInternalConfigBufferFilledAVC), 4548 pBuffHead->pBuffer, 4549 pBuffHead->nFilledLen) == NULL){ 4550 eError = OMX_ErrorInsufficientResources; 4551 goto EXIT; 4552 } 4553 /*The data internally stored has to be put at the begining of the buffer*/ 4554 if(memcpy(pBuffHead->pBuffer, 4555 pComponentPrivate->pInternalConfigBufferAVC, 4556 pComponentPrivate->nInternalConfigBufferFilledAVC) == NULL){ 4557 eError = OMX_ErrorInsufficientResources; 4558 goto EXIT; 4559 } 4560 } 4561 else{ 4562 eError = OMX_ErrorInsufficientResources; 4563 goto EXIT; 4564 } 4565 4566 /*Update filled length of current buffer */ 4567 pBuffHead->nFilledLen = pComponentPrivate->nInternalConfigBufferFilledAVC + pBuffHead->nFilledLen; 4568 /*Free Internal Buffer used to temporarly hold the data*/ 4569 free(pComponentPrivate->pInternalConfigBufferAVC); 4570 /* Reset Internal Variables*/ 4571 pComponentPrivate->pInternalConfigBufferAVC = NULL; 4572 pComponentPrivate->nInternalConfigBufferFilledAVC = 0; 4573 nConfigBufferCounter = 0; 4574 /* Update Buffer Variables before parsing */ 4575 nTotalInBytes = pBuffHead->nFilledLen; 4576 free(nRbspByte); 4577 nRbspByte = (OMX_U8*)malloc(nTotalInBytes); 4578 if(nRbspByte == NULL){ 4579 eError = OMX_ErrorInsufficientResources; 4580 goto EXIT; 4581 } 4582 memset(nRbspByte, 0x0, nTotalInBytes); 4583 /*Buffer ready to be parse =) */ 4584 } 4585 } 4586 /* End of Handle fragmentation Config Buffer Code*/ 4587 4588 do{ 4589 for (; (!nStartFlag) && (nInBytePosition < nTotalInBytes - 3); ) 4590 { 4591 if (VIDDEC_GetBits(&nBitPosition, 24, nBitStream, OMX_FALSE) != 0x000001) 4592 { 4593 nBitPosition += 8; 4594 nInBytePosition++; 4595 } 4596 else 4597 { 4598 /*Start Code found*/ 4599 nStartFlag = OMX_TRUE; 4600 nBitPosition += 24; 4601 nInBytePosition += 3; 4602 } 4603 } 4604 nStartFlag = OMX_FALSE; 4605 /* offset to NumBytesInNALunit*/ 4606 nNumBytesInNALunit = nInBytePosition; 4607 sParserParam->nBitPosTemp = nBitPosition; 4608 for (;(!nStartFlag)&&(nNumBytesInNALunit < nTotalInBytes-3); ) 4609 { 4610 if (VIDDEC_GetBits(&sParserParam->nBitPosTemp, 24, nBitStream, OMX_FALSE) != 0x000001) 4611 /*find start code*/ 4612 { 4613 sParserParam->nBitPosTemp += 8; 4614 nNumBytesInNALunit++; 4615 } 4616 else 4617 { 4618 /*Start Code found*/ 4619 nStartFlag = OMX_TRUE; 4620 sParserParam->nBitPosTemp += 24; 4621 nNumBytesInNALunit += 3; 4622 } 4623 } 4624 4625 if (!nStartFlag) 4626 { 4627 eError = OMX_ErrorStreamCorrupt; 4628 goto EXIT; 4629 } 4630 /* forbidden_zero_bit */ 4631 sParserParam->nForbiddenZeroBit = VIDDEC_GetBits(&nBitPosition, 1, nBitStream, OMX_TRUE); 4632 /* nal_ref_idc */ 4633 sParserParam->nNalRefIdc = VIDDEC_GetBits(&nBitPosition, 2, nBitStream, OMX_TRUE); 4634 /* nal_unit_type */ 4635 nNalUnitType = VIDDEC_GetBits(&nBitPosition, 5, nBitStream, OMX_TRUE); 4636 nInBytePosition++; 4637 4638 /* This code is to ensure we will get parameter info */ 4639 if (nNalUnitType != 7) 4640 { 4641 OMX_PRINT2(pComponentPrivate->dbg, "nal_unit_type does not specify parameter information need to look for next startcode\n"); 4642 nStartFlag = OMX_FALSE; 4643 } 4644 }while (nNalUnitType != 7); 4645 } 4646 else { 4647 pDataBuf = (OMX_U8*)nBitStream; 4648 do { 4649 /* iOMXComponentUsesNALStartCodes is set to OMX_FALSE on opencore */ 4650#ifndef ANDROID 4651 if (pComponentPrivate->H264BitStreamFormat == 1) { 4652 if (pComponentPrivate->bIsNALBigEndian) { 4653 nNumBytesInNALunit = (OMX_U32)pDataBuf[nInBytePosition]; 4654 } 4655 else { 4656 nNumBytesInNALunit = (OMX_U32)pDataBuf[nInBytePosition]; 4657 } 4658 } 4659 else if (pComponentPrivate->H264BitStreamFormat == 2) { 4660 if (pComponentPrivate>bIsNALBigEndian) { 4661 nNumBytesInNALunit = (OMX_U32)pDataBuf[nInBytePosition] << 8 | pDataBuf[nInBytePosition+1]; 4662 } 4663 else { 4664 nNumBytesInNALunit = (OMX_U32)pDataBuf[nInBytePosition] << 0 | pDataBuf[nInBytePosition+1] << 8 ; 4665 } 4666 } 4667 else if (pComponentPrivate->H264BitStreamFormat == 4){ 4668 if (pComponentPrivate->bIsNALBigEndian) { 4669 nNumBytesInNALunit = (OMX_U32)pDataBuf[nInBytePosition]<<24 | pDataBuf[nInBytePosition+1] << 16 | pDataBuf[nInBytePosition+2] << 8 | pDataBuf[nInBytePosition+3]; 4670 } 4671 else { 4672 nNumBytesInNALunit = (OMX_U32)pDataBuf[nInBytePosition]<<0 | pDataBuf[nInBytePosition+1] << 8 | pDataBuf[nInBytePosition+2] << 16 | pDataBuf[nInBytePosition+3]<<24; 4673 } 4674 } 4675 else { 4676 eError = OMX_ErrorBadParameter; 4677 goto EXIT; 4678 } 4679#endif 4680 nBitPosition = (nInPositionTemp + nType) * 8; 4681 nInBytePosition = nInPositionTemp + nType; 4682 nInPositionTemp += nNumBytesInNALunit + nType; 4683 if (nInBytePosition > nTotalInBytes) { 4684 eError = OMX_ErrorBadParameter; 4685 goto EXIT; 4686 } 4687 /* forbidden_zero_bit */ 4688 sParserParam->nForbiddenZeroBit = VIDDEC_GetBits(&nBitPosition, 1, nBitStream, OMX_TRUE); 4689 /* nal_ref_idc */ 4690 sParserParam->nNalRefIdc = VIDDEC_GetBits(&nBitPosition, 2, nBitStream, OMX_TRUE); 4691 /* nal_unit_type */ 4692 nNalUnitType = VIDDEC_GetBits(&nBitPosition, 5, nBitStream, OMX_TRUE); 4693 nInBytePosition++; 4694 /* This code is to ensure we will get parameter info */ 4695 if (nNalUnitType != 7) { 4696 /*nBitPosition += (nNumBytesInNALunit - 1) * 8; 4697 nInBytePosition += (nNumBytesInNALunit - 1);*/ 4698 nBitPosition = (nInPositionTemp) * 8; 4699 nInBytePosition = (nInPositionTemp); 4700 4701 } 4702 } while (nNalUnitType != 7); 4703 nNumBytesInNALunit += 8 + nInBytePosition;/*sum to keep the code flow*/ 4704 /*the buffer must had enough space to enter this number*/ 4705 } 4706 for (i=0; nInBytePosition < nNumBytesInNALunit - 3; ) 4707 { 4708 4709 if (((nInBytePosition + 2) < nNumBytesInNALunit - 3)&& 4710 (VIDDEC_GetBits(&nBitPosition, 24, nBitStream, OMX_FALSE) == 0x000003)) 4711 { 4712 OMX_PRINT2(pComponentPrivate->dbg, "discard emulation prev byte\n"); 4713 nRbspByte[i++] = nBitStream[nInBytePosition++]; 4714 nRbspByte[i++] = nBitStream[nInBytePosition++]; 4715 nNumOfBytesInRbsp += 2; 4716 /* discard emulation prev byte */ 4717 nInBytePosition++; 4718 nBitPosition += 24; 4719 } 4720 else 4721 { 4722 nRbspByte[i++] = nBitStream[nInBytePosition++]; 4723 nNumOfBytesInRbsp++; 4724 nBitPosition += 8; 4725 } 4726 } 4727 4728 4729 /*Parse RBSP sequence*/ 4730 /*///////////////////*/ 4731 /* profile_idc u(8) */ 4732 sParserParam->nProfileIdc = VIDDEC_GetBits(&nRbspPosition, 8, nRbspByte, OMX_TRUE); 4733 /* constraint_set0_flag u(1)*/ 4734 sParserParam->nConstraintSet0Flag = VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4735 /* constraint_set1_flag u(1)*/ 4736 sParserParam->nConstraintSet1Flag = VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4737 /* constraint_set2_flag u(1)*/ 4738 sParserParam->nConstraintSet2Flag = VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4739 /* reserved_zero_5bits u(5)*/ 4740 sParserParam->nReservedZero5bits = VIDDEC_GetBits(&nRbspPosition, 5, nRbspByte, OMX_TRUE); 4741 /* level_idc*/ 4742 sParserParam->nLevelIdc = VIDDEC_GetBits(&nRbspPosition, 8, nRbspByte, OMX_TRUE); 4743 sParserParam->nSeqParameterSetId = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4744 sParserParam->nLog2MaxFrameNumMinus4 = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4745 sParserParam->nPicOrderCntType = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4746 4747 if ( sParserParam->nPicOrderCntType == 0 ) 4748 { 4749 sParserParam->nLog2MaxPicOrderCntLsbMinus4 = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4750 } 4751 else if( sParserParam->nPicOrderCntType == 1 ) 4752 { 4753 /* delta_pic_order_always_zero_flag*/ 4754 VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4755 sParserParam->nOffsetForNonRefPic = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4756 if (sParserParam->nOffsetForNonRefPic > 1) 4757 sParserParam->nOffsetForNonRefPic = sParserParam->nOffsetForNonRefPic & 0x1 ? 4758 sParserParam->nOffsetForNonRefPic >> 1 : 4759 -(sParserParam->nOffsetForNonRefPic >> 1); 4760 sParserParam->nOffsetForTopToBottomField = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4761 sParserParam->nNumRefFramesInPicOrderCntCycle = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4762 for(i = 0; i < sParserParam->nNumRefFramesInPicOrderCntCycle; i++ ) 4763 VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); /*offset_for_ref_frame[i]*/ 4764 } 4765 4766 sParserParam->nNumRefFrames = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4767 sParserParam->nGapsInFrameNumValueAllowedFlag = VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4768 sParserParam->nPicWidthInMbsMinus1 = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4769 (*nWidth) = (sParserParam->nPicWidthInMbsMinus1 + 1) * 16; 4770 sParserParam->nPicHeightInMapUnitsMinus1 = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4771 (*nHeight) = (sParserParam->nPicHeightInMapUnitsMinus1 + 1) * 16; 4772 /* Checking for cropping in picture saze */ 4773 /* getting frame_mbs_only_flag */ 4774 sParserParam->nFrameMbsOnlyFlag = VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4775 if (!sParserParam->nFrameMbsOnlyFlag) 4776 { 4777 sParserParam->nMBAdaptiveFrameFieldFlag = VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4778 } 4779 /*getting direct_8x8_inference_flag and frame_cropping_flag*/ 4780 sParserParam->nDirect8x8InferenceFlag = VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4781 sParserParam->nFrameCroppingFlag = VIDDEC_GetBits(&nRbspPosition, 1, nRbspByte, OMX_TRUE); 4782 /*getting the crop values if exist*/ 4783 if (sParserParam->nFrameCroppingFlag) 4784 { 4785 sParserParam->nFrameCropLeftOffset = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4786 sParserParam->nFrameCropRightOffset = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4787 sParserParam->nFrameCropTopOffset = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4788 sParserParam->nFrameCropBottomOffset = VIDDEC_UVLC_dec(&nRbspPosition, nRbspByte); 4789 /* Update framesize taking into account the cropping values */ 4790 (*nCropWidth) = (2 * sParserParam->nFrameCropLeftOffset + 2 * sParserParam->nFrameCropRightOffset); 4791 (*nCropHeight) = (2 * sParserParam->nFrameCropTopOffset + 2 * sParserParam->nFrameCropBottomOffset); 4792 } 4793 eError = OMX_ErrorNone; 4794 4795EXIT: 4796 free( nRbspByte); 4797 free( sParserParam); 4798 return eError; 4799} 4800#endif 4801 4802#ifdef VIDDEC_ACTIVATEPARSER 4803/* =========================================================================*/ 4804/* func GetBits */ 4805/* */ 4806/* desc Gets aBits number of bits from position aPosition of one buffer */ 4807/* and returns the value in a TUint value. */ 4808/* =========================================================================*/ 4809OMX_U32 VIDDEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition) 4810{ 4811 OMX_U32 nOutput; 4812 OMX_U32 nNumBitsRead = 0; 4813 OMX_U32 nBytePosition = 0; 4814 OMX_U8 nBitPosition = 0; 4815 nBytePosition = *nPosition / 8; 4816 nBitPosition = *nPosition % 8; 4817 4818 if (bIcreasePosition) 4819 *nPosition += nBits; 4820 nOutput = ((OMX_U32)pBuffer[nBytePosition] << (24+nBitPosition) ); 4821 nNumBitsRead = nNumBitsRead + (8 - nBitPosition); 4822 if (nNumBitsRead < nBits) 4823 { 4824 nOutput = nOutput | ( pBuffer[nBytePosition + 1] << (16+nBitPosition)); 4825 nNumBitsRead = nNumBitsRead + 8; 4826 } 4827 if (nNumBitsRead < nBits) 4828 { 4829 nOutput = nOutput | ( pBuffer[nBytePosition + 2] << (8+nBitPosition)); 4830 nNumBitsRead = nNumBitsRead + 8; 4831 } 4832 if (nNumBitsRead < nBits) 4833 { 4834 nOutput = nOutput | ( pBuffer[nBytePosition + 3] << (nBitPosition)); 4835 nNumBitsRead = nNumBitsRead + 8; 4836 } 4837 nOutput = nOutput >> (32 - nBits) ; 4838 return nOutput; 4839} 4840 4841 4842OMX_S32 VIDDEC_UVLC_dec(OMX_U32 *nPosition, OMX_U8* pBuffer) 4843{ 4844 4845 OMX_U32 nBytePosition = (*nPosition) / 8; 4846 OMX_U8 cBitPosition = (*nPosition) % 8; 4847 OMX_U32 nLen = 1; 4848 OMX_U32 nCtrBit = 0; 4849 OMX_U32 nVal = 1; 4850 OMX_S32 nInfoBit=0; 4851 4852 nCtrBit = pBuffer[nBytePosition] & (0x1 << (7-cBitPosition)); 4853 while (nCtrBit==0) 4854 { 4855 nLen++; 4856 cBitPosition++; 4857 (*nPosition)++; 4858 if (!(cBitPosition%8)) 4859 { 4860 cBitPosition=0; 4861 nBytePosition++; 4862 } 4863 nCtrBit = pBuffer[nBytePosition] & (0x1<<(7-cBitPosition)); 4864 } 4865 for(nInfoBit=0; (nInfoBit<(nLen-1)); nInfoBit++) 4866 { 4867 cBitPosition++; 4868 (*nPosition)++; 4869 4870 if (!(cBitPosition%8)) 4871 { 4872 cBitPosition=0; 4873 nBytePosition++; 4874 } 4875 nVal=(nVal << 1); 4876 if(pBuffer[nBytePosition] & (0x01 << (7 - cBitPosition))) 4877 nVal |= 1; 4878 } 4879 (*nPosition)++; 4880 nVal -= 1; 4881 return nVal; 4882} 4883#endif 4884 4885#ifdef VIDDEC_ACTIVATEPARSER 4886/* ========================================================================== */ 4887/** 4888 * Parse the input buffer to get the correct width and height 4889 **/ 4890/* ========================================================================== */ 4891OMX_ERRORTYPE VIDDEC_ParseHeader(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE *pBuffHead) 4892{ 4893 OMX_ERRORTYPE eError = OMX_ErrorNone; 4894 OMX_S32 nWidth = 0; 4895 OMX_S32 nHeight = 0; 4896 OMX_S32 nPadWidth = 0; 4897 OMX_S32 nPadHeight = 0; 4898 OMX_S32 nCropWidth = 0; 4899 OMX_S32 nCropHeight = 0; 4900 OMX_S32 nCroppedWidth = 0; 4901 OMX_S32 nCroppedHeight = 0; 4902 4903 OMX_U32 nOutMinBufferSize = 0; 4904 OMX_BOOL bInPortSettingsChanged = OMX_FALSE; 4905 OMX_BOOL bOutPortSettingsChanged = OMX_FALSE; 4906 OMX_U32 nOutPortActualAllocLen = 0; 4907 4908 OMX_PRINT1(pComponentPrivate->dbg, "IN\n"); 4909 if(!pComponentPrivate) { 4910 goto EXIT; 4911 } 4912 4913 bInPortSettingsChanged = pComponentPrivate->bInPortSettingsChanged; 4914 bOutPortSettingsChanged = pComponentPrivate->bOutPortSettingsChanged; 4915 /*Get output port allocated buffer size*/ 4916 nOutPortActualAllocLen = pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[0]->pBufferHdr->nAllocLen; 4917 4918 OMX_PRINT1(pComponentPrivate->dbg, "pBuffHead %x, Original resolution IN %dx%d : OUT %dx%d\n", 4919 (unsigned int)pBuffHead, 4920 (unsigned int)pComponentPrivate->pInPortDef->format.video.nFrameWidth, 4921 (unsigned int)pComponentPrivate->pInPortDef->format.video.nFrameHeight, 4922 (unsigned int)pComponentPrivate->pOutPortDef->format.video.nFrameWidth, 4923 (unsigned int)pComponentPrivate->pOutPortDef->format.video.nFrameHeight); 4924 4925 4926 if( pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 4927 eError = VIDDEC_ParseVideo_H264( pComponentPrivate, pBuffHead, &nWidth, &nHeight, 4928 &nCropWidth, &nCropHeight, pComponentPrivate->H264BitStreamFormat); 4929 4930 /* Start Code to handle fragmentation of ConfigBuffer for AVC*/ 4931 if(pComponentPrivate->bConfigBufferCompleteAVC == OMX_FALSE && 4932 pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat == 0){ 4933 /* We have received some part of the config Buffer. 4934 * Send EmptyThisBuffer of the buffer we have just received to Client 4935 */ 4936 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 4937 pComponentPrivate->pHandle->pApplicationPrivate, 4938 pBuffHead); 4939 /* Exit with out error to avoid sending again EmptyBufferDone in upper function*/ 4940 eError = OMX_ErrorNone; 4941 goto EXIT; 4942 } 4943 /*End Code to handle fragmentation of ConfigBuffer for AVC*/ 4944 } 4945 else if( pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 4946 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 4947 VIDDEC_ParseVideo_MPEG4( &nWidth, &nHeight, pBuffHead); 4948 } 4949 else if( pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 4950 VIDDEC_ParseVideo_MPEG2( &nWidth, &nHeight, pBuffHead); 4951 } 4952 else if( pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 4953 if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM) { 4954 eError = VIDDEC_ParseVideo_WMV9_VC1( &nWidth, &nHeight, pBuffHead); 4955 } 4956 else { 4957 eError = VIDDEC_ParseVideo_WMV9_RCV( &nWidth, &nHeight, pBuffHead); 4958 } 4959 } 4960 4961 nPadWidth = nWidth; 4962 nPadHeight = nHeight; 4963 if((nPadWidth%16) != 0){ 4964 nPadWidth += 16-(nPadWidth%16); 4965 } 4966 if((nPadHeight%16) != 0){ 4967 nPadHeight += 16-(nPadHeight%16); 4968 } 4969 4970 /*TODO: Test Croped MPEG4*/ 4971 4972 if(pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 4973 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263){ 4974 if(nPadWidth == 864){ 4975 nPadWidth = 854; 4976 } 4977 if(nPadHeight == 864){ 4978 nPadHeight = 864; 4979 } 4980 } 4981 4982 /*TODO: Get minimum INPUT buffer size & verify if the actual size is enough*/ 4983 /*Verify correct values in the initial setup*/ 4984 4985 /*Verify if actual width & height parameters are correct*/ 4986 if (pComponentPrivate->pInPortDef->format.video.nFrameWidth != nWidth || 4987 pComponentPrivate->pInPortDef->format.video.nFrameHeight != nHeight) { 4988 if((nWidth >= 1500) || (nHeight >= 1500)){ 4989 pComponentPrivate->pInPortDef->format.video.nFrameHeight = 576; 4990 pComponentPrivate->pInPortDef->format.video.nFrameWidth = 720; 4991 eError = OMX_ErrorBadParameter; 4992 goto EXIT; 4993 } 4994 else if(((nWidth < 16) || (nHeight < 16))){ 4995 pComponentPrivate->pInPortDef->format.video.nFrameHeight = 576; 4996 pComponentPrivate->pInPortDef->format.video.nFrameWidth = 720; 4997 eError = OMX_ErrorBadParameter; 4998 goto EXIT; 4999 } 5000 pComponentPrivate->pInPortDef->format.video.nFrameWidth = nPadWidth; 5001 pComponentPrivate->pInPortDef->format.video.nFrameHeight = nPadHeight; 5002#ifdef ANDROID 5003 /*Force reload the component to configure create face args (SN)*/ 5004 bOutPortSettingsChanged = OMX_TRUE; 5005 OMX_PRINT1(pComponentPrivate->dbg, "Input port setting change, Force reload component !!!!!!\n"); 5006#else 5007 /*OpenCORE doesn't support dynamic input port configuration*/ 5008 bInPortSettingsChanged = OMX_TRUE; 5009#endif 5010 } 5011 5012 if(pComponentPrivate->pInPortDef->format.video.eCompressionFormat != OMX_VIDEO_CodingAVC && 5013 pComponentPrivate->pInPortDef->format.video.eCompressionFormat != OMX_VIDEO_CodingMPEG4 && 5014 pComponentPrivate->pInPortDef->format.video.eCompressionFormat != OMX_VIDEO_CodingH263){ 5015 if(pComponentPrivate->pOutPortDef->format.video.nFrameWidth != nWidth || 5016 pComponentPrivate->pOutPortDef->format.video.nFrameHeight != nHeight) { 5017 5018 pComponentPrivate->pOutPortDef->format.video.nFrameWidth = nPadWidth; 5019 pComponentPrivate->pOutPortDef->format.video.nFrameHeight = nPadHeight; 5020 bOutPortSettingsChanged = OMX_TRUE; 5021 OMX_PRINT1(pComponentPrivate->dbg, "Resolution: default new: %dx%d\n", nPadWidth, nPadHeight); 5022 } 5023 } 5024 else if(pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 5025 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263){ 5026 if(pComponentPrivate->pOutPortDef->format.video.nFrameWidth != nWidth || 5027 pComponentPrivate->pOutPortDef->format.video.nFrameHeight != nHeight) { 5028 5029 pComponentPrivate->pOutPortDef->format.video.nFrameWidth = nWidth; 5030 pComponentPrivate->pOutPortDef->format.video.nFrameHeight = nHeight; 5031 bOutPortSettingsChanged = OMX_TRUE; 5032 OMX_PRINT1(pComponentPrivate->dbg, "Resolution: new MPEG4: %dx%d\n", nWidth, nHeight); 5033 } 5034 } 5035 else{ /*OMX_VIDEO_CodingAVC*/ 5036 /* nCroppedWidth & nCroppedHeight indicate the resultant o/p resolution */ 5037 if((nWidth%16) != 0){ 5038 nWidth += 16-(nWidth%16); 5039 } 5040 if((nHeight%16) != 0){ 5041 nHeight += 16-(nHeight%16); 5042 } 5043 nCroppedWidth = nWidth - nCropWidth; 5044 nCroppedHeight = nHeight - nCropHeight; 5045 if(pComponentPrivate->pOutPortDef->format.video.nFrameWidth != nCroppedWidth || 5046 pComponentPrivate->pOutPortDef->format.video.nFrameHeight != nCroppedHeight) { 5047 5048 pComponentPrivate->pOutPortDef->format.video.nFrameWidth = nCroppedWidth; 5049 pComponentPrivate->pOutPortDef->format.video.nFrameHeight = nCroppedHeight; 5050 bOutPortSettingsChanged = OMX_TRUE; 5051 OMX_PRINT1(pComponentPrivate->dbg, "Resolution: AVC new: %dx%d \n", nCroppedWidth, nCroppedHeight); 5052 } 5053 } 5054 5055 /*Get minimum OUTPUT buffer size & verify if the actual allocated size is enough*/ 5056 nOutMinBufferSize = pComponentPrivate->pOutPortDef->format.video.nFrameWidth * 5057 pComponentPrivate->pOutPortDef->format.video.nFrameHeight * 5058 ((pComponentPrivate->pOutPortFormat->eColorFormat == VIDDEC_COLORFORMAT420) ? VIDDEC_FACTORFORMAT420 : VIDDEC_FACTORFORMAT422); 5059 5060 if(nOutPortActualAllocLen != nOutMinBufferSize){ 5061 pComponentPrivate->pOutPortDef->nBufferSize = nOutMinBufferSize; 5062 bOutPortSettingsChanged = OMX_TRUE; 5063 OMX_PRINT1(pComponentPrivate->dbg, "NEW output BUFFSIZE:0x%x \n", nOutMinBufferSize); 5064 } 5065 5066 5067 OMX_PRINT1(pComponentPrivate->dbg, "pBuffHead %x, Resolution after parser: IN %dx%d : OUT %dx%d\n", 5068 (unsigned int)pBuffHead, 5069 (unsigned int)pComponentPrivate->pInPortDef->format.video.nFrameWidth, 5070 (unsigned int)pComponentPrivate->pInPortDef->format.video.nFrameHeight, 5071 (unsigned int)pComponentPrivate->pOutPortDef->format.video.nFrameWidth, 5072 (unsigned int)pComponentPrivate->pOutPortDef->format.video.nFrameHeight); 5073 5074 pComponentPrivate->bInPortSettingsChanged |= bInPortSettingsChanged; 5075 pComponentPrivate->bOutPortSettingsChanged |= bOutPortSettingsChanged; 5076 5077 if(bOutPortSettingsChanged || bInPortSettingsChanged){ 5078 OMX_PRINT1(pComponentPrivate->dbg, "bDynamicConfigurationInProgress = OMX_TRUE\n"); 5079 pComponentPrivate->bDynamicConfigurationInProgress = OMX_TRUE; 5080 5081 if(bOutPortSettingsChanged && bInPortSettingsChanged){ 5082 OMX_PRBUFFER2(pComponentPrivate->dbg, "sending OMX_EventPortSettingsChanged to both ports\n"); 5083 5084 5085#ifdef ANDROID 5086 /*We must send first INPUT port callback*/ 5087 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sDynConfigMutex); 5088#endif 5089 5090 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 5091 pComponentPrivate->pHandle->pApplicationPrivate, 5092 OMX_EventPortSettingsChanged, 5093 VIDDEC_INPUT_PORT, 5094 0, 5095 NULL); 5096 VIDDEC_WAIT_CODE(); 5097 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 5098 pComponentPrivate->pHandle->pApplicationPrivate, 5099 OMX_EventPortSettingsChanged, 5100 VIDDEC_OUTPUT_PORT, 5101 0, 5102 NULL); 5103 5104#ifdef ANDROID 5105 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sDynConfigMutex); 5106#endif 5107 eError = OMX_ErrorBadParameter; 5108 goto EXIT; 5109 } 5110 else { 5111 OMX_PRBUFFER2(pComponentPrivate->dbg, "sending OMX_EventPortSettingsChanged SINGLE port\n"); 5112 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 5113 pComponentPrivate->pHandle->pApplicationPrivate, 5114 OMX_EventPortSettingsChanged, 5115 bOutPortSettingsChanged ? VIDDEC_OUTPUT_PORT : VIDDEC_INPUT_PORT, 5116 0, 5117 NULL); 5118 eError = OMX_ErrorBadParameter; 5119 goto EXIT; 5120 } 5121 } 5122 else { 5123 eError = OMX_ErrorNone; 5124 } 5125EXIT: 5126 OMX_PRINT1(pComponentPrivate->dbg, "OUT\n"); 5127 return eError; 5128} 5129#endif 5130 5131/* ========================================================================== */ 5132/** 5133 * Handle Data Buff function from application 5134 **/ 5135/* ========================================================================== */ 5136 5137OMX_ERRORTYPE VIDDEC_HandleDataBuf_FromApp(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate) 5138{ 5139 OMX_ERRORTYPE eError = OMX_ErrorNone; 5140 OMX_BUFFERHEADERTYPE* pBuffHead = NULL; 5141 VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL; 5142 OMX_U32 inpBufSize; 5143 int ret = 0; 5144 OMX_U32 size_dsp; 5145 OMX_U8* pCSD = NULL; 5146 OMX_U8* pData = NULL; 5147 OMX_U32 nValue = 0; 5148 OMX_U32 nWidth = 0; 5149 OMX_U32 nHeight = 0; 5150 OMX_U32 nActualCompression = 0; 5151 OMX_U32 nSize_CSD = 0; 5152 5153 void* pUalgInpParams = NULL; 5154 LCML_DSP_INTERFACE* pLcmlHandle; 5155 OMX_PRBUFFER1(pComponentPrivate->dbg, "+++ENTERING\n"); 5156 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate 0x%p iEndofInputSent 0x%x\n", pComponentPrivate, pComponentPrivate->iEndofInputSent); 5157 inpBufSize = pComponentPrivate->pInPortDef->nBufferSize; 5158 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 5159 ret = read(pComponentPrivate->filled_inpBuf_Q[0], &(pBuffHead), sizeof(pBuffHead)); 5160 if (ret == -1) { 5161 OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from the pipe\n"); 5162 eError = OMX_ErrorHardware; 5163 goto EXIT; 5164 } 5165 5166 if( pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV && 5167 pComponentPrivate->ProcessMode == 0 && 5168 pBuffHead->nFilledLen != 0) { 5169 5170 if (pComponentPrivate->bFirstHeader == OMX_FALSE) { 5171 if (pBuffHead->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { 5172#ifdef VIDDEC_HANDLE_FULL_STRM_PROP_OBJ 5173 pData = pBuffHead->pBuffer + 15; /*Position to Width & Height*/ 5174 5175 VIDDEC_LoadDWORD(nValue, pData); 5176 nWidth = nValue; 5177 VIDDEC_LoadDWORD(nValue, pData); 5178 nHeight = nValue; 5179 5180 if((nWidth != (OMX_U32)pComponentPrivate->pOutPortDef->format.video.nFrameWidth) || 5181 (nHeight != (OMX_U32)pComponentPrivate->pOutPortDef->format.video.nFrameHeight)){ 5182 pComponentPrivate->pOutPortDef->format.video.nFrameWidth = nWidth; 5183 pComponentPrivate->pOutPortDef->format.video.nFrameHeight = nHeight; 5184 pComponentPrivate->bOutPortSettingsChanged = OMX_TRUE; 5185 } 5186 5187 pData += 4; /*Position to compression type*/ 5188 VIDDEC_LoadDWORD(nValue, pData); 5189 nActualCompression = nValue; 5190 5191 /*If incorrect re-load SN with the proper nWMVFileType*/ 5192 OMX_PRINT2(pComponentPrivate->dbg, "Compressions: WMV1=%lu, WMV2=%lu, WMV3=%lu, WVC1=%lu. Actual=%lu\n", 5193 FOURCC_WMV1, FOURCC_WMV2, FOURCC_WMV3, FOURCC_WVC1, nActualCompression); 5194 if(pComponentPrivate->nWMVFileType == VIDDEC_WMV_RCVSTREAM && nActualCompression == FOURCC_WVC1){ 5195 pComponentPrivate->nWMVFileType = VIDDEC_WMV_ELEMSTREAM; 5196 } 5197 5198 eError = VIDDEC_Set_SN_StreamType(pComponentPrivate); 5199 if(eError != OMX_ErrorNone){ 5200 goto EXIT; 5201 } 5202 5203 /*Seting pCSD to proper position*/ 5204 pCSD = pBuffHead->pBuffer; 5205 pCSD += CSD_POSITION; 5206 nSize_CSD = pBuffHead->nFilledLen - CSD_POSITION; 5207#else 5208 pCSD = pBuffHead->pBuffer; 5209 nSize_CSD = pBuffHead->nFilledLen; 5210#endif 5211 } 5212 if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_RCVSTREAM) { 5213 if(pComponentPrivate->pUalgParams == NULL) { 5214 OMX_U8* pTemp = NULL; 5215 OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams, WMV9DEC_UALGInputParam, 5216 sizeof(WMV9DEC_UALGInputParam) + VIDDEC_PADDING_FULL, 5217 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]); 5218 pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams); 5219 pTemp += VIDDEC_PADDING_HALF; 5220 pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp; 5221 } 5222 pBuffHead->nFlags &= ~(OMX_BUFFERFLAG_CODECCONFIG); 5223 if (pComponentPrivate->bIsNALBigEndian) { 5224 pComponentPrivate->pBufferRCV.sStructRCV.nStructData = (OMX_U32)pCSD[0] << 24 | 5225 pCSD[1] << 16 | 5226 pCSD[2] << 8 | 5227 pCSD[3]; 5228 } 5229 else { 5230 pComponentPrivate->pBufferRCV.sStructRCV.nStructData = (OMX_U32)pCSD[0] << 0 | 5231 pCSD[1] << 8 | 5232 pCSD[2] << 16 | 5233 pCSD[3] << 24; 5234 } 5235 size_dsp = sizeof(WMV9DEC_UALGInputParam); 5236 ((WMV9DEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = ++pComponentPrivate->frameCounter; 5237 pUalgInpParams = pComponentPrivate->pUalgParams; 5238 /* Only WMV need to send EMMCodecInputBufferMapBufLen buffers */ 5239 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*) 5240 pLcmlHandle)->pCodecinterfacehandle, 5241 EMMCodecInputBufferMapBufLen, 5242 (OMX_U8*)&pComponentPrivate->pBufferRCV.pBuffer, 5243 sizeof(VIDDEC_WMV_RCV_struct), 5244 sizeof(VIDDEC_WMV_RCV_struct), 5245 (OMX_U8 *)pUalgInpParams, 5246 size_dsp, 5247 (OMX_U8*)&pComponentPrivate->pBufferTemp); 5248 OMX_PRBUFFER1(pComponentPrivate->dbg, "Returning First Input Buffer to test application\n"); 5249 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 5250 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 5251 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5252 #ifdef __PERF_INSTRUMENTATION__ 5253 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5254 pBuffHead->pBuffer, 5255 pBuffHead->nFilledLen, 5256 PERF_ModuleHLMM); 5257 #endif 5258 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 5259 pComponentPrivate->pHandle->pApplicationPrivate, 5260 pBuffHead); 5261 pComponentPrivate->bFirstHeader = OMX_TRUE; 5262 goto EXIT; 5263 } 5264 else { /* VC1 Advance profile */ 5265#ifdef VIDDEC_WMVPOINTERFIXED 5266 if (pComponentPrivate->pCodecData == NULL || 5267 !(pBuffHead->pBuffer[0] == 0 && 5268 pBuffHead->pBuffer[1] == 0 && 5269 pBuffHead->pBuffer[2] == 1)) { 5270#else 5271 if (pBuffHead->nOffset != 0) { 5272#endif 5273 if (pBuffHead->nFlags & OMX_BUFFERFLAG_CODECCONFIG) { 5274 pBuffHead->nFlags &= ~(OMX_BUFFERFLAG_CODECCONFIG); 5275 if (pComponentPrivate->pCodecData != NULL) { 5276 free(pComponentPrivate->pCodecData); 5277 pComponentPrivate->pCodecData = NULL; 5278 } 5279 /* Save Codec Specific Data */ 5280 pComponentPrivate->pCodecData = malloc (pBuffHead->nFilledLen); 5281#ifdef VIDDEC_WMVPOINTERFIXED 5282 memcpy (pComponentPrivate->pCodecData, pBuffHead->pBuffer, pBuffHead->nFilledLen); 5283#else 5284 memcpy (pComponentPrivate->pCodecData, pBuffHead->pBuffer + pBuffHead->nOffset, pBuffHead->nFilledLen); 5285#endif 5286 pComponentPrivate->nCodecDataSize = pBuffHead->nFilledLen; 5287#ifdef VIDDEC_ACTIVATEPARSER 5288 eError = VIDDEC_ParseHeader( pComponentPrivate, pBuffHead); 5289#endif 5290 OMX_PRBUFFER1(pComponentPrivate->dbg, "Returning First Input Buffer to test application %x\n",eError); 5291 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 5292 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 5293 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5294 #ifdef __PERF_INSTRUMENTATION__ 5295 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5296 pBuffHead->pBuffer, 5297 pBuffHead->nFilledLen, 5298 PERF_ModuleHLMM); 5299 #endif 5300#ifdef VIDDEC_WMVPOINTERFIXED 5301 OMX_PRBUFFER1(pComponentPrivate->dbg, "restoring buffer pointer 0x%p >> pBuffer 0x%p\n", 5302 pBufferPrivate->pTempBuffer, pBuffHead->pBuffer); 5303 pBuffHead->pBuffer = pBufferPrivate->pTempBuffer; 5304#else 5305 pBuffHead->nOffset = VIDDEC_WMV_BUFFER_OFFSET; 5306#endif 5307 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle, 5308 pComponentPrivate->pHandle->pApplicationPrivate, 5309 pBuffHead); 5310 return OMX_ErrorNone; 5311 } 5312 else { 5313 OMX_S32 nDifference = 0; 5314 OMX_U8* pTempBuffer = NULL; 5315 pComponentPrivate->bFirstHeader = OMX_TRUE; 5316#ifdef VIDDEC_WMVPOINTERFIXED 5317 pTempBuffer = pBuffHead->pBuffer; 5318#else 5319 pTempBuffer = pBuffHead->pBuffer + pBuffHead->nOffset; 5320#endif 5321 (*(--pTempBuffer)) = 0x0d; 5322 (*(--pTempBuffer)) = 0x01; 5323 (*(--pTempBuffer)) = 0x00; 5324 (*(--pTempBuffer)) = 0x00; 5325 pTempBuffer -= pComponentPrivate->nCodecDataSize; 5326#ifdef VIDDEC_WMVPOINTERFIXED 5327 nDifference = pBuffHead->pBuffer - pTempBuffer; 5328#else 5329 nDifference = pTempBuffer - pBuffHead->pBuffer; 5330#endif 5331 if (nDifference < 0) { 5332 OMX_ERROR4(pComponentPrivate->dbg, "Insufficient space in buffer pbuffer %p - nOffset %p\n", 5333 (void *)pBuffHead->pBuffer,(void *)pBuffHead->nOffset); 5334 eError = OMX_ErrorStreamCorrupt; 5335 goto EXIT; 5336 } 5337 memcpy (pTempBuffer, pComponentPrivate->pCodecData, pComponentPrivate->nCodecDataSize); 5338 pBuffHead->nFilledLen += pComponentPrivate->nCodecDataSize + 4; 5339#ifdef VIDDEC_WMVPOINTERFIXED 5340 pBuffHead->pBuffer = pTempBuffer; 5341 pBuffHead->nOffset = 0; 5342#else 5343 pBuffHead->nOffset = pTempBuffer - pBuffHead->pBuffer; 5344#endif 5345 OMX_PRBUFFER1(pComponentPrivate->dbg, "pTempBuffer %p - pBuffHead->pBuffer %p - pBuffHead->nOffset %lx\n", 5346 pTempBuffer,pBuffHead->pBuffer,pBuffHead->nOffset); 5347 eError = OMX_ErrorNone; 5348 } 5349 } 5350 else { 5351 /*if no config flag is set just parse buffer and set flag first buffer*/ 5352 /*this is ejecuted by the first buffer regular buffer*/ 5353 if (pComponentPrivate->bFirstHeader == OMX_FALSE) { 5354 pComponentPrivate->bFirstHeader = OMX_TRUE; 5355 eError = VIDDEC_ParseHeader(pComponentPrivate, pBuffHead); 5356 if(eError != OMX_ErrorNone) { 5357 OMX_PRBUFFER1(pComponentPrivate->dbg, "Returning First Input Buffer to test application\n"); 5358 pComponentPrivate->bFirstHeader = OMX_TRUE; 5359 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 5360 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 5361 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5362 #ifdef __PERF_INSTRUMENTATION__ 5363 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5364 pBuffHead->pBuffer, 5365 pBuffHead->nFilledLen, 5366 PERF_ModuleHLMM); 5367 #endif 5368#ifdef VIDDEC_WMVPOINTERFIXED 5369 OMX_PRBUFFER1(pComponentPrivate->dbg, "restoring buffer pointer 0x%p >> pBuffer 0x%p\n", 5370 pBufferPrivate->pTempBuffer, pBuffHead->pBuffer); 5371 pBuffHead->pBuffer = pBufferPrivate->pTempBuffer; 5372#else 5373 pBuffHead->nOffset = VIDDEC_WMV_BUFFER_OFFSET; 5374#endif 5375 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 5376 pComponentPrivate->pHandle->pApplicationPrivate, 5377 pBuffHead); 5378 eError = OMX_ErrorNone; 5379 goto EXIT; 5380 } 5381 else { 5382 eError = OMX_ErrorNone; 5383 } 5384 } 5385 } 5386 } 5387 }/*codec data is stored one time and repeated for each Config buffer*/ 5388 else if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM) { 5389#ifdef VIDDEC_WMVPOINTERFIXED 5390 if (!(pBuffHead->pBuffer[0] == 0 && 5391 pBuffHead->pBuffer[1] == 0 && 5392 pBuffHead->pBuffer[2] == 1)) { 5393#else 5394 if (pBuffHead->nOffset != 0) { 5395#endif 5396 OMX_S32 nDifference = 0; 5397 OMX_U8* pTempBuffer = NULL; 5398#ifdef VIDDEC_WMVPOINTERFIXED 5399 pTempBuffer = pBuffHead->pBuffer; 5400#else 5401 pTempBuffer = pBuffHead->pBuffer + pBuffHead->nOffset; 5402#endif 5403#ifdef VIDDEC_WMVPOINTERFIXED 5404 nDifference = pBuffHead->pBuffer - pTempBuffer; 5405#else 5406 nDifference = pTempBuffer - pBuffHead->pBuffer; 5407#endif 5408 if (nDifference < 0) { 5409 OMX_ERROR4(pComponentPrivate->dbg, "Insufficient space in buffer pbuffer %p - nOffset %lx\n", 5410 pBuffHead->pBuffer, pBuffHead->nOffset); 5411 eError = OMX_ErrorStreamCorrupt; 5412 goto EXIT; 5413 } 5414 (*(--pTempBuffer)) = 0x0d; 5415 (*(--pTempBuffer)) = 0x01; 5416 (*(--pTempBuffer)) = 0x00; 5417 (*(--pTempBuffer)) = 0x00; 5418 pBuffHead->nFilledLen += 4; 5419#ifdef VIDDEC_WMVPOINTERFIXED 5420 pBuffHead->pBuffer = pTempBuffer; 5421 pBuffHead->nOffset = 0; 5422#else 5423 pBuffHead->nOffset = pTempBuffer - pBuffHead->pBuffer; 5424#endif 5425 OMX_PRBUFFER1(pComponentPrivate->dbg, "pTempBuffer %p - pBuffHead->pBuffer %p - pBuffHead->nOffset %lx\n", 5426 pTempBuffer,pBuffHead->pBuffer,pBuffHead->nOffset); 5427 eError = OMX_ErrorNone; 5428 } 5429 else { 5430 OMX_PRBUFFER1(pComponentPrivate->dbg, "incorrect path %lu\n",pBuffHead->nOffset); 5431 /*if no config flag is set just parse buffer and set flag first buffer*/ 5432 /*this is ejecuted by the first buffer regular buffer*/ 5433 if (pComponentPrivate->bFirstHeader == OMX_FALSE) { 5434 pComponentPrivate->bFirstHeader = OMX_TRUE; 5435 eError = VIDDEC_ParseHeader(pComponentPrivate, pBuffHead); 5436 if(eError != OMX_ErrorNone) { 5437 OMX_PRBUFFER1(pComponentPrivate->dbg, "Returning First Input Buffer to test application\n"); 5438 pComponentPrivate->bFirstHeader = OMX_TRUE; 5439 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 5440 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 5441 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5442 #ifdef __PERF_INSTRUMENTATION__ 5443 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5444 pBuffHead->pBuffer, 5445 pBuffHead->nFilledLen, 5446 PERF_ModuleHLMM); 5447 #endif 5448#ifdef VIDDEC_WMVPOINTERFIXED 5449 OMX_PRBUFFER1(pComponentPrivate->dbg, "restoring buffer pointer 0x%p >> pBuffer 0x%p\n", 5450 pBufferPrivate->pTempBuffer, pBuffHead->pBuffer); 5451 pBuffHead->pBuffer = pBufferPrivate->pTempBuffer; 5452#else 5453 pBuffHead->nOffset = VIDDEC_WMV_BUFFER_OFFSET; 5454#endif 5455 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 5456 pComponentPrivate->pHandle->pApplicationPrivate, 5457 pBuffHead); 5458 eError = OMX_ErrorNone; 5459 goto EXIT; 5460 } 5461 else { 5462 eError = OMX_ErrorNone; 5463 } 5464 } 5465 } 5466 } 5467 } 5468#ifdef VIDDEC_ACTIVATEPARSER 5469 if((((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) || 5470 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 5471 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2 || 5472 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) || 5473 (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV && 5474 pComponentPrivate->ProcessMode == 1)) && 5475 pComponentPrivate->bParserEnabled && 5476 pComponentPrivate->bFirstHeader == OMX_FALSE) { 5477 pComponentPrivate->bFirstHeader = OMX_TRUE; 5478 /* If VIDDEC_ParseHeader() does not return OMX_ErrorNone, then 5479 * reconfiguration is required. 5480 * eError is set to OMX_ErrorNone after saving the buffer, which will 5481 * be used later by the reconfiguration logic. 5482 */ 5483 eError = VIDDEC_ParseHeader( pComponentPrivate, pBuffHead); 5484 5485 /* The MPEG4 & H.263 algorithm expects both the configuration buffer 5486 * and the first data buffer to be in the same frame - this logic only 5487 * applies when in frame mode and when the framework sends the config data 5488 * separately. The same situation is handled elsewhere for H.264 & WMV 5489 * decoding. 5490 */ 5491 if(eError != OMX_ErrorNone || 5492 ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 5493 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) && 5494 pComponentPrivate->ProcessMode == 0)) { 5495 if (pBuffHead != NULL) { 5496 5497#ifdef ANDROID 5498 OMX_PRINT1(pComponentPrivate->dbg,"save 1st ccd buffer - pBuffhead->nFilledLen = %d\n", pBuffHead->nFilledLen); 5499 eError = VIDDEC_SaveBuffer(pComponentPrivate, pBuffHead); 5500 if(eError != OMX_ErrorNone){ 5501 goto EXIT; 5502 } 5503 /* only if NAL-bitstream format in frame mode */ 5504 if (pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat > 0) { 5505 pComponentPrivate->aCCDsize[pComponentPrivate->nCCDcnt++] = pBuffHead->nFilledLen; 5506 } 5507#endif 5508 5509 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 5510 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 5511 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5512 #ifdef __PERF_INSTRUMENTATION__ 5513 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5514 pBuffHead->pBuffer, 5515 pBuffHead->nFilledLen, 5516 PERF_ModuleHLMM); 5517 #endif 5518 5519 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 5520 pComponentPrivate->pHandle->pApplicationPrivate, 5521 pBuffHead); 5522 } 5523 eError = OMX_ErrorNone; 5524 goto EXIT; 5525 } 5526 else { 5527 /* We have received only one part of the Config Buffer, we need to wait for more buffers. ONLY FOR AVC*/ 5528 if(pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC && 5529 pComponentPrivate->bConfigBufferCompleteAVC == FALSE){ 5530 /* Set bFirstHeader flag to false so next buffer enters to ParseHeade again*/ 5531 pComponentPrivate->bFirstHeader = OMX_FALSE; 5532 OMX_PRINT1(pComponentPrivate->dbg, "AVC: bConfigBufferCompleateAVC == FALSE!"); 5533 goto EXIT; 5534 } 5535 eError = OMX_ErrorNone; 5536 } 5537 } 5538#endif 5539 5540 5541 if (pComponentPrivate->nInCmdMarkBufIndex != pComponentPrivate->nOutCmdMarkBufIndex) { 5542 pComponentPrivate->arrMarkBufIndex[pComponentPrivate->nInMarkBufIndex].hMarkTargetComponent = pComponentPrivate->arrCmdMarkBufIndex[pComponentPrivate->nOutCmdMarkBufIndex].hMarkTargetComponent; 5543 pComponentPrivate->arrMarkBufIndex[pComponentPrivate->nInMarkBufIndex].pMarkData = pComponentPrivate->arrCmdMarkBufIndex[pComponentPrivate->nOutCmdMarkBufIndex].pMarkData; 5544 pComponentPrivate->nOutCmdMarkBufIndex++; 5545 pComponentPrivate->nOutCmdMarkBufIndex %= VIDDEC_MAX_QUEUE_SIZE; 5546 pComponentPrivate->nInMarkBufIndex++; 5547 pComponentPrivate->nInMarkBufIndex %= VIDDEC_MAX_QUEUE_SIZE; 5548 } 5549 else { 5550 pComponentPrivate->arrMarkBufIndex[pComponentPrivate->nInMarkBufIndex].hMarkTargetComponent = pBuffHead->hMarkTargetComponent; 5551 pComponentPrivate->arrMarkBufIndex[pComponentPrivate->nInMarkBufIndex].pMarkData = pBuffHead->pMarkData; 5552 pComponentPrivate->nInMarkBufIndex++; 5553 pComponentPrivate->nInMarkBufIndex %= VIDDEC_MAX_QUEUE_SIZE; 5554 } 5555 5556 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead 0x%p eExecuteToIdle 0x%x\n", pBuffHead,pComponentPrivate->eExecuteToIdle); 5557 OMX_PRBUFFER1(pComponentPrivate->dbg, "nFilledLen 0x%lx nFlags 0x%lx\n", pBuffHead->nFilledLen,pBuffHead->nFlags); 5558 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 5559 5560 if(pBuffHead->nFlags & OMX_BUFFERFLAG_EOS){ 5561 OMX_PRBUFFER2(pComponentPrivate->dbg, "End of Input EOS, nFlags=0x%x nFilledLen 0x%lx\n", pBuffHead->nFlags, pBuffHead->nFilledLen); 5562 if(pBuffHead->nFilledLen != 0) { /*TODO: Validate this lagic*/ 5563 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 5564 pUalgInpParams = (OMX_PTR)pBufferPrivate->pUalgParam; 5565 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 5566 ((H264VDEC_UALGInputParam *)pUalgInpParams)->lBuffCount = ++pComponentPrivate->frameCounter; 5567 5568 /* prepare buffer and input parameter if H264BitStreamFormat = 1 */ 5569 /* the orignial buffer is: NAL1_Len NAL1 NAL2_Len NAL2...*/ 5570 /* we need to pack the data buffer as: NAL1 NAL2 NAL3..*/ 5571 /* and put the length info to the parameter array*/ 5572 if (pComponentPrivate->H264BitStreamFormat) { 5573 OMX_U32 nal_len, i; 5574 OMX_U8 *pDataBuf; 5575 OMX_U32 length_pos = 0; 5576 OMX_U32 data_pos = 0; 5577 OMX_U32 buf_len; 5578 H264VDEC_UALGInputParam *pParam; 5579 5580 buf_len = pBuffHead->nFilledLen; 5581 pDataBuf = pBuffHead->pBuffer; 5582 pParam = (H264VDEC_UALGInputParam *)pUalgInpParams; 5583 pParam->ulNumOfNALU = 0; 5584 while (pBuffHead->nFilledLen > length_pos+pComponentPrivate->H264BitStreamFormat) { 5585 if (pComponentPrivate->H264BitStreamFormat == 1) 5586 if (pComponentPrivate->bIsNALBigEndian) { 5587 nal_len = (OMX_U32)pDataBuf[length_pos]; 5588 } 5589 else { 5590 nal_len = (OMX_U32)pDataBuf[length_pos]; 5591 } 5592 else if (pComponentPrivate->H264BitStreamFormat == 2) 5593 if (pComponentPrivate->bIsNALBigEndian) { 5594 nal_len = (OMX_U32)pDataBuf[length_pos] << 8 | pDataBuf[length_pos+1]; 5595 } 5596 else { 5597 nal_len = (OMX_U32)pDataBuf[length_pos] << 0 | pDataBuf[length_pos+1] << 8 ; 5598 } 5599 else if (pComponentPrivate->H264BitStreamFormat == 4){ 5600 if (pComponentPrivate->bIsNALBigEndian) { 5601 nal_len = (OMX_U32)pDataBuf[length_pos]<<24 | pDataBuf[length_pos+1] << 16 | pDataBuf[length_pos+2] << 8 | pDataBuf[length_pos+3]; 5602 } 5603 else { 5604 nal_len = (OMX_U32)pDataBuf[length_pos]<<0 | pDataBuf[length_pos+1] << 8 | pDataBuf[length_pos+2] << 16 | pDataBuf[length_pos+3]<<24; 5605 } 5606 } 5607 else { 5608 eError = OMX_ErrorBadParameter; 5609 goto EXIT; 5610 } 5611 length_pos += pComponentPrivate->H264BitStreamFormat; 5612 if (nal_len > buf_len - length_pos) { 5613 eError = OMX_ErrorBadParameter; 5614 goto EXIT; 5615 } 5616 /* move the memory*/ 5617 for (i=0; i<nal_len; i++) 5618 pDataBuf[data_pos+i] = pDataBuf[length_pos+i]; 5619 data_pos += nal_len; 5620 length_pos += nal_len; 5621 /* save the size*/ 5622 pParam->pNALUSizeArray[pParam->ulNumOfNALU++] = nal_len; 5623 } 5624 /* update with the new data size*/ 5625 pBuffHead->nFilledLen = data_pos; 5626 } 5627 } 5628 size_dsp = sizeof(H264VDEC_UALGInputParam); 5629 } 5630 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 5631 pUalgInpParams = (OMX_PTR)pBufferPrivate->pUalgParam; 5632 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 5633 ((WMV9DEC_UALGInputParam*)pUalgInpParams)->lBuffCount = ++pComponentPrivate->frameCounter; 5634 } 5635 size_dsp = sizeof(WMV9DEC_UALGInputParam); 5636 } 5637 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 5638 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 5639 pUalgInpParams = (OMX_PTR)pBufferPrivate->pUalgParam; 5640 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 5641 ((MP4VD_GPP_SN_UALGInputParams*)pUalgInpParams)->nBuffCount = ++pComponentPrivate->frameCounter; 5642 } 5643 size_dsp = sizeof(MP4VD_GPP_SN_UALGInputParams); 5644 } 5645 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 5646 pUalgInpParams = (OMX_PTR)pBufferPrivate->pUalgParam; 5647 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 5648 ((MP2VDEC_UALGInputParam*)pUalgInpParams)->lBuffCount = ++pComponentPrivate->frameCounter; 5649 } 5650 size_dsp = sizeof(MP2VDEC_UALGInputParam); 5651 } 5652#ifdef VIDDEC_SPARK_CODE 5653 else if (VIDDEC_SPARKCHECK) { 5654 pUalgInpParams = (OMX_PTR)pBufferPrivate->pUalgParam; 5655 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 5656 ((SPARKVD_GPP_SN_UALGInputParams*)pUalgInpParams)->lBuffCount = ++pComponentPrivate->frameCounter; 5657 } 5658 ((SPARKVD_GPP_SN_UALGInputParams*)pUalgInpParams)->nIsSparkInput = 1; 5659 size_dsp = sizeof(SPARKVD_GPP_SN_UALGInputParams); 5660 } 5661#endif 5662 else { 5663 eError = OMX_ErrorUnsupportedSetting; 5664 OMX_PRBUFFER4(pComponentPrivate->dbg, "VIDDEC_HandleDataBuf_FromApp 0x%x\n", eError); 5665 goto EXIT; 5666 } 5667 5668 if (pComponentPrivate->ProcessMode == 0) { 5669 OMX_U8 ucIndex = 0; 5670 OMX_PTR pBufferFlags = NULL; 5671 ucIndex = VIDDEC_CircBuf_GetHead(pComponentPrivate, 5672 VIDDEC_CBUFFER_TIMESTAMP, 5673 VIDDEC_INPUT_PORT); 5674 pComponentPrivate->aBufferFlags[ucIndex].nTimeStamp = pBuffHead->nTimeStamp; 5675 pComponentPrivate->aBufferFlags[ucIndex].nTickCount = pBuffHead->nTickCount; 5676 pBuffHead->nFlags &= ~OMX_BUFFERFLAG_EOS; 5677 pComponentPrivate->aBufferFlags[ucIndex].nFlags = pBuffHead->nFlags; 5678 pBufferFlags = &pComponentPrivate->aBufferFlags[ucIndex]; 5679 VIDDEC_CircBuf_Add(pComponentPrivate, 5680 VIDDEC_CBUFFER_TIMESTAMP, 5681 VIDDEC_INPUT_PORT, 5682 pBufferFlags); 5683 } 5684 else { 5685 pComponentPrivate->arrBufIndex[pComponentPrivate->nInBufIndex] = pBuffHead->nTimeStamp; 5686 pComponentPrivate->nInBufIndex++; 5687 pComponentPrivate->nInBufIndex %= VIDDEC_MAX_QUEUE_SIZE; 5688 } 5689 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nTimeStamp %lld\n", pBuffHead->nTimeStamp); 5690 5691#ifdef __PERF_INSTRUMENTATION__ 5692 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5693 pBuffHead->pBuffer, 5694 pBuffHead->nFilledLen, 5695 PERF_ModuleCommonLayer); 5696#endif 5697 5698 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 5699 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 5700 pComponentPrivate->pLCML != NULL){ 5701 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP; 5702 pBuffHead->nFlags = 0; 5703 5704#ifdef __PERF_INSTRUMENTATION__ 5705 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5706 pBuffHead->pBuffer, 5707 pBuffHead->nFilledLen, 5708 PERF_ModuleHLMM); 5709#endif 5710 5711 if(pComponentPrivate->bDynamicConfigurationInProgress){ 5712 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 5713 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 5714 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5715 5716 OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending buffer back to client pBuffer=%p\n", pBuffHead->pBuffer); 5717 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 5718 pComponentPrivate->pHandle->pApplicationPrivate, 5719 pBuffHead); 5720 goto EXIT; 5721 } 5722 5723 OMX_PRDSP1(pComponentPrivate->dbg, "Sending EOS Filled eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5724 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_QueueBuffer(INPUT)\n"); 5725 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*) 5726 pLcmlHandle)->pCodecinterfacehandle, 5727 ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) ? EMMCodecInputBufferMapBufLen : EMMCodecInputBuffer), 5728 &pBuffHead->pBuffer[pBuffHead->nOffset],/*WMV_VC1_CHANGES*/ 5729 pBuffHead->nAllocLen, 5730 pBuffHead->nFilledLen, 5731 (OMX_U8 *)pUalgInpParams, 5732 size_dsp, 5733 (OMX_U8 *)pBuffHead); 5734 if (eError != OMX_ErrorNone){ 5735 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer(INPUT):OMX_BUFFERFLAG_EOS, Error 0x%x\n", eError); 5736 eError = OMX_ErrorHardware; 5737 goto EXIT; 5738 } 5739 } 5740 else { 5741 eError = OMX_ErrorHardware; 5742 goto EXIT; 5743 } 5744 } 5745 else { 5746 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT; 5747 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5748 pComponentPrivate->nInputBCountDsp++; 5749 ret = write(pComponentPrivate->free_inpBuf_Q[1], &pBuffHead, sizeof(pBuffHead)); 5750 if(ret == -1){ 5751 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%d)\n", OMX_ErrorInsufficientResources,ret); 5752 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 5753 pComponentPrivate->pHandle->pApplicationPrivate, 5754 OMX_EventError, 5755 OMX_ErrorInsufficientResources, 5756 OMX_TI_ErrorSevere, 5757 "Error writing to the output pipe"); 5758 } 5759 } 5760 5761 if(pComponentPrivate->iEndofInputSent == 0){ 5762 pComponentPrivate->iEndofInputSent = 1; 5763 OMX_PRBUFFER1(pComponentPrivate->dbg, "Sending EOS Empty eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5764 if(pComponentPrivate->eFirstBuffer.bSaveFirstBuffer == OMX_FALSE){ 5765 if(pComponentPrivate->pUalgParams != NULL){ 5766 OMX_U8* pTemp = NULL; 5767 pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams); 5768 pTemp -= VIDDEC_PADDING_HALF; 5769 pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp; 5770 free(pComponentPrivate->pUalgParams); 5771 pComponentPrivate->pUalgParams = NULL; 5772 } 5773 } 5774 5775 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 5776 if(pComponentPrivate->pUalgParams == NULL){ 5777 OMX_U8* pTemp = NULL; 5778 OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams, 5779 H264VDEC_UALGInputParam, 5780 sizeof(H264VDEC_UALGInputParam) + VIDDEC_PADDING_FULL, 5781 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]); 5782 pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams); 5783 pTemp += VIDDEC_PADDING_HALF; 5784 pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp; 5785 } 5786 size_dsp = sizeof(H264VDEC_UALGInputParam); 5787 ((H264VDEC_UALGInputParam *)pComponentPrivate->pUalgParams)->lBuffCount = -1; 5788 OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n", 5789 ((H264VDEC_UALGInputParam *)pComponentPrivate->pUalgParams)->lBuffCount); 5790 } 5791 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 5792 if(pComponentPrivate->pUalgParams == NULL){ 5793 OMX_U8* pTemp = NULL; 5794 OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams, 5795 WMV9DEC_UALGInputParam, 5796 sizeof(WMV9DEC_UALGInputParam) + VIDDEC_PADDING_FULL, 5797 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]); 5798 pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams); 5799 pTemp += VIDDEC_PADDING_HALF; 5800 pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp; 5801 } 5802 size_dsp = sizeof(WMV9DEC_UALGInputParam); 5803 ((WMV9DEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = -1; 5804 OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n", 5805 ((WMV9DEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount); 5806 } 5807 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 5808 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 5809 if(pComponentPrivate->pUalgParams == NULL){ 5810 OMX_U8* pTemp = NULL; 5811 OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams, 5812 MP4VD_GPP_SN_UALGInputParams, 5813 sizeof(MP4VD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL, 5814 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]); 5815 pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams); 5816 pTemp += VIDDEC_PADDING_HALF; 5817 pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp; 5818 } 5819 size_dsp = sizeof(MP4VD_GPP_SN_UALGInputParams); 5820 ((MP4VD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nBuffCount = -1; 5821 OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n", 5822 ((MP4VD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nBuffCount); 5823 } 5824 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 5825 if(pComponentPrivate->pUalgParams == NULL){ 5826 OMX_U8* pTemp = NULL; 5827 OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams, 5828 MP2VDEC_UALGInputParam, 5829 sizeof(MP2VDEC_UALGInputParam) + VIDDEC_PADDING_FULL, 5830 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]); 5831 pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams); 5832 pTemp += VIDDEC_PADDING_HALF; 5833 pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp; 5834 } 5835 size_dsp = sizeof(MP2VDEC_UALGInputParam); 5836 ((MP2VDEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = -1; 5837 OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n", 5838 ((MP2VDEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount); 5839 } 5840#ifdef VIDDEC_SPARK_CODE 5841 else if (VIDDEC_SPARKCHECK) { 5842 if(pComponentPrivate->pUalgParams == NULL){ 5843 OMX_U8* pTemp = NULL; 5844 OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams, 5845 SPARKVD_GPP_SN_UALGInputParams, 5846 sizeof(SPARKVD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL, 5847 pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]); 5848 pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams); 5849 pTemp += VIDDEC_PADDING_HALF; 5850 pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp; 5851 } 5852 size_dsp = sizeof(SPARKVD_GPP_SN_UALGInputParams); 5853 ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->lBuffCount = -1; 5854 ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nIsSparkInput = 1; 5855 OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n", 5856 ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->lBuffCount); 5857 } 5858#endif 5859 else { 5860 eError = OMX_ErrorUnsupportedSetting; 5861 goto EXIT; 5862 } 5863 5864#ifdef __PERF_INSTRUMENTATION__ 5865 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5866 NULL, 0, 5867 PERF_ModuleCommonLayer); 5868#endif 5869 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 5870 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 5871 pComponentPrivate->pLCML != NULL){ 5872 pComponentPrivate->pTempBuffHead.nFlags = 0; 5873 pComponentPrivate->pTempBuffHead.nFlags |= OMX_BUFFERFLAG_EOS; 5874 pComponentPrivate->pTempBuffHead.nFilledLen = 0; 5875 pComponentPrivate->pTempBuffHead.pBuffer = NULL; 5876 5877#ifdef __PERF_INSTRUMENTATION__ 5878 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 5879 pBuffHead->pBuffer, 5880 pBuffHead->nFilledLen, 5881 PERF_ModuleHLMM); 5882#endif 5883 5884 if(pComponentPrivate->bDynamicConfigurationInProgress){ 5885 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 5886 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 5887 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 5888 OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending buffer back to client pBuffer=%p\n", pBuffHead->pBuffer); 5889 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 5890 pComponentPrivate->pHandle->pApplicationPrivate, 5891 pBuffHead); 5892 goto EXIT; 5893 } 5894 5895 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_QueueBuffer(INPUT)\n"); 5896 5897 /* Verify if first buffer as been stored. 5898 * Handle case were only one frame is decoded */ 5899 if(pComponentPrivate->eFirstBuffer.bSaveFirstBuffer){ 5900 eError = VIDDEC_CopyBuffer(pComponentPrivate, pBuffHead); 5901 if (eError != OMX_ErrorNone) { 5902 OMX_PRDSP4(pComponentPrivate->dbg, "VIDDEC_HandleDataBuf_FromApp: VIDDEC_CopyBuffer()= 0x%x\n", eError); 5903 if (eError == OMX_ErrorInsufficientResources) { 5904 goto EXIT; 5905 } 5906 } 5907 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP; 5908 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*) 5909 pLcmlHandle)->pCodecinterfacehandle, 5910 ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) ? EMMCodecInputBufferMapBufLen : EMMCodecInputBuffer), 5911 &pBuffHead->pBuffer[pBuffHead->nOffset],/*WMV_VC1_CHANGES*/ 5912 pBuffHead->nAllocLen, 5913 pBuffHead->nFilledLen, 5914 (OMX_U8 *)pComponentPrivate->pUalgParams, 5915 size_dsp, 5916 (OMX_U8 *)pBuffHead); 5917 if (eError != OMX_ErrorNone){ 5918 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer EOS (0x%x)\n",eError); 5919 eError = OMX_ErrorHardware; 5920 goto EXIT; 5921 } 5922 } 5923 else{ 5924 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle, 5925 ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) ? EMMCodecInputBufferMapBufLen : EMMCodecInputBuffer), 5926 NULL, 5927 0, 5928 0, 5929 (OMX_U8 *)pComponentPrivate->pUalgParams, 5930 size_dsp, 5931 (OMX_PTR)&pComponentPrivate->pTempBuffHead); 5932 } 5933 if (eError != OMX_ErrorNone){ 5934 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer 1 (0x%x)\n",eError); 5935 eError = OMX_ErrorHardware; 5936 goto EXIT; 5937 } 5938 } 5939 else { 5940 eError = OMX_ErrorHardware; 5941 goto EXIT; 5942 } 5943 } 5944 } 5945 else { 5946 pComponentPrivate->iEndofInputSent = 0; 5947 if(pBuffHead->nFilledLen != 0) { 5948 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 5949 pUalgInpParams = pBufferPrivate->pUalgParam; 5950 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 5951 ((H264VDEC_UALGInputParam *)pUalgInpParams)->lBuffCount = ++pComponentPrivate->frameCounter; 5952 if (pComponentPrivate->H264BitStreamFormat) { 5953 H264VDEC_UALGInputParam *pParam; 5954#ifndef ANDROID 5955 OMX_U32 nal_len, i; 5956 OMX_U8 *pDataBuf; 5957 OMX_U32 length_pos = 0; 5958 OMX_U32 data_pos = 0; 5959 OMX_U32 buf_len; 5960 5961 buf_len = pBuffHead->nFilledLen; 5962 pDataBuf = pBuffHead->pBuffer; 5963 pParam = (H264VDEC_UALGInputParam *)pUalgInpParams; 5964 pParam->ulNumOfNALU = 0; 5965 while (pBuffHead->nFilledLen > length_pos+pComponentPrivate->H264BitStreamFormat) { 5966 if (pComponentPrivate->H264BitStreamFormat == 1) 5967 if (pComponentPrivate->bIsNALBigEndian) { 5968 nal_len = (OMX_U32)pDataBuf[length_pos]; 5969 } 5970 else { 5971 nal_len = (OMX_U32)pDataBuf[length_pos]; 5972 } 5973 else if (pComponentPrivate->H264BitStreamFormat == 2) 5974 if (pComponentPrivate->bIsNALBigEndian) { 5975 nal_len = (OMX_U32)pDataBuf[length_pos] << 8 | pDataBuf[length_pos+1]; 5976 } 5977 else { 5978 nal_len = (OMX_U32)pDataBuf[length_pos] << 0 | pDataBuf[length_pos+1] << 8 ; 5979 } 5980 else if (pComponentPrivate->H264BitStreamFormat == 4){ 5981 if (pComponentPrivate->bIsNALBigEndian) { 5982 nal_len = (OMX_U32)pDataBuf[length_pos]<<24 | pDataBuf[length_pos+1] << 16 | pDataBuf[length_pos+2] << 8 | pDataBuf[length_pos+3]; 5983 } 5984 else { 5985 nal_len = (OMX_U32)pDataBuf[length_pos]<<0 | pDataBuf[length_pos+1] << 8 | pDataBuf[length_pos+2] << 16 | pDataBuf[length_pos+3]<<24; 5986 } 5987 } 5988 else { 5989 eError = OMX_ErrorBadParameter; 5990 goto EXIT; 5991 } 5992 length_pos += pComponentPrivate->H264BitStreamFormat; 5993 if (nal_len > buf_len - length_pos) { 5994 eError = OMX_ErrorBadParameter; 5995 goto EXIT; 5996 } 5997 /* move the memory*/ 5998 for (i=0; i<nal_len; i++) 5999 pDataBuf[data_pos+i] = pDataBuf[length_pos+i]; 6000 data_pos += nal_len; 6001 length_pos += nal_len; 6002 /* save the size*/ 6003 pParam->pNALUSizeArray[pParam->ulNumOfNALU++] = nal_len; 6004 } 6005 /* update with the new data size*/ 6006 pBuffHead->nFilledLen = data_pos; 6007#else 6008 pParam = (H264VDEC_UALGInputParam *)pUalgInpParams; 6009 pParam->ulNumOfNALU = 0; 6010 6011 if (pBuffHead->nFlags >= OMX_BUFFERFLAG_CODECCONFIG) { 6012 OMX_PRINT1(pComponentPrivate->dbg,"nFlags = %x\n", pBuffHead->nFlags); 6013 OMX_PRINT1(pComponentPrivate->dbg,"copy previous codec config data to current ccd buffer\n"); 6014 eError = VIDDEC_CopyBuffer(pComponentPrivate, pBuffHead); 6015 6016 OMX_PRINT1(pComponentPrivate->dbg,"save current ccd buff - nFilledLen = %d\n", pBuffHead->nFilledLen); 6017 eError = VIDDEC_SaveBuffer(pComponentPrivate, pBuffHead); 6018 pComponentPrivate->aCCDsize[pComponentPrivate->nCCDcnt++] = pBuffHead->nFilledLen; 6019 6020 OMX_PRINT1(pComponentPrivate->dbg,"send ccd buffer back to client\n"); 6021 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 6022 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 6023 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 6024 pComponentPrivate->pHandle->pApplicationPrivate, 6025 pBuffHead); 6026 goto EXIT; 6027 } 6028 else { 6029 H264VDEC_UALGInputParam *pParam; 6030 OMX_U32 len = 0; /* offset+filledlen+padding */ 6031 OMX_U32 off = 0; /* offset */ 6032 OMX_U32 fl = 0; /* filledlen */ 6033 OMX_U32 rem = 0; /* modulus */ 6034 OMX_U32 pad = 0; /* padding */ 6035 OMX_U32 numnalu = 0; /* number of nal units */ 6036 OMX_U32 sp = 0; /* starting position of 4 byte nDataSize */ 6037 OMX_U32 nalusize[256] = {0}; /* array to store nal sizes */ 6038 OMX_U32 i = 0; 6039 OMX_U32 j = 0; 6040 OMX_U32 t1 = 0; 6041 OMX_U32 t2 = 0; 6042 6043 /* This is how pBuffer is arranged when 6044 * iOMXComponentUsesFullAVCFrames is set 6045 * to true 6046 */ 6047 6048 /* offset, 6049 * NALU1, NALU2, ... 6050 * padding, 6051 * nSize, 6052 * nVersion, 6053 * nPortIndex, 6054 * eType, 6055 * nDataSize, 6056 * NAL1Len, NAL2Len, ... 6057 */ 6058 6059 pParam = (H264VDEC_UALGInputParam *)pUalgInpParams; 6060 pParam->ulNumOfNALU = 0; 6061 off = pBuffHead->nOffset; 6062 fl = pBuffHead->nFilledLen; 6063 rem = (off + fl) % 4; 6064 if (rem > 0) { 6065 pad = 4 - rem; 6066 } 6067 6068 len = off + fl + pad; 6069 OMX_PRINT1(pComponentPrivate->dbg,"nFlags = %x\n", pBuffHead->nFlags); 6070 OMX_PRINT1(pComponentPrivate->dbg,"off=%d,fl=%d,rem=%d,pad=%d,len=%d\n", off, fl, rem, pad, len); 6071 6072 /* print the OMX_ExtraDataNALSizeArry marker */ 6073 OMX_PRINT1(pComponentPrivate->dbg,"extradata marker -> 0x %x %x %x %x\n", 6074 pBuffHead->pBuffer[len+15], 6075 pBuffHead->pBuffer[len+14], 6076 pBuffHead->pBuffer[len+13], 6077 pBuffHead->pBuffer[len+12]); 6078 6079 /* store number of numnalu */ 6080 ((OMX_U8*)(&numnalu))[3] = pBuffHead->pBuffer[len+19]; 6081 ((OMX_U8*)(&numnalu))[2] = pBuffHead->pBuffer[len+18]; 6082 ((OMX_U8*)(&numnalu))[1] = pBuffHead->pBuffer[len+17]; 6083 ((OMX_U8*)(&numnalu))[0] = pBuffHead->pBuffer[len+16]; 6084 numnalu /= 4; 6085 6086 /* print the numnalu */ 6087 OMX_PRINT1(pComponentPrivate->dbg,"numnalu -> 0x %x %x %x %x\n", ((OMX_U8*)(&numnalu))[3] 6088 , ((OMX_U8*)(&numnalu))[2] 6089 , ((OMX_U8*)(&numnalu))[1] 6090 , ((OMX_U8*)(&numnalu))[0]); 6091 6092 /* print the nDataSize */ 6093 OMX_PRINT1(pComponentPrivate->dbg,"nDataSize -> 0x %x %x %x %x\n", pBuffHead->pBuffer[len+19] 6094 , pBuffHead->pBuffer[len+18] 6095 , pBuffHead->pBuffer[len+17] 6096 , pBuffHead->pBuffer[len+16]); 6097 /* print the first NALU len */ 6098 OMX_PRINT1(pComponentPrivate->dbg,"first NALU len -> 0x %x %x %x %x\n", pBuffHead->pBuffer[len+23] 6099 , pBuffHead->pBuffer[len+22] 6100 , pBuffHead->pBuffer[len+21] 6101 , pBuffHead->pBuffer[len+20]); 6102 pParam->ulNumOfNALU = 0; 6103 6104 /* starting position of nalu sizes */ 6105 sp = t1 = len+20; 6106 t2 = i; 6107 6108 OMX_PRINT1(pComponentPrivate->dbg,"numnalu = %d", numnalu); 6109 6110 while (i<(t2+numnalu)) { 6111 j=0; 6112 while (sp<(t1+4)) { 6113 ((OMX_U8*)(&nalusize[i]))[j] = pBuffHead->pBuffer[sp]; 6114 sp++; 6115 j++; 6116 } 6117 t1 = sp; 6118 i++; 6119 } 6120 OMX_PRINT1(pComponentPrivate->dbg,"confirm ulNumOfNALU = %d\n", i); 6121 6122 if (pComponentPrivate->bCopiedCCDBuffer == OMX_FALSE){ 6123 pComponentPrivate->bCopiedCCDBuffer = OMX_TRUE; 6124 OMX_PRINT1(pComponentPrivate->dbg,"copy saved ccd buffer to data buffer\n"); 6125 eError = VIDDEC_CopyBuffer(pComponentPrivate, pBuffHead); 6126 6127 i=0; 6128 /* tally number of ccd nalus and add sizes to nalu array */ 6129 while (i < pComponentPrivate->nCCDcnt) { 6130 if (i == 0) { 6131 pParam->pNALUSizeArray[i] = pComponentPrivate->aCCDsize[i]; 6132 } 6133 else { 6134 pParam->pNALUSizeArray[i] = pComponentPrivate->aCCDsize[i] - 6135 pComponentPrivate->aCCDsize[i-1]; 6136 } 6137 pParam->ulNumOfNALU++; 6138 OMX_PRINT1(pComponentPrivate->dbg,"aCCDsize[%d] = %d\n", i, pParam->pNALUSizeArray[i]); 6139 i++; 6140 } 6141 6142 /* adjust the filled length to account for the ccd nalus */ 6143 pBuffHead->nFilledLen = fl + pComponentPrivate->aCCDsize[i-1]; 6144 6145 OMX_PRINT1(pComponentPrivate->dbg,"new nFilledLen=%d; old fl=%d + aCCDsize=%d\n", pBuffHead->nFilledLen 6146 , fl 6147 , pComponentPrivate->aCCDsize[i-1]); 6148 t1 = i; 6149 j=0; 6150 6151 /* now, add the data nalu sizes to the array, 6152 * which already contain the ccd nalu sizes */ 6153 for(;i<t1+numnalu;i++) { 6154 pParam->pNALUSizeArray[i] = nalusize[j]; 6155 j++; 6156 } 6157 pParam->ulNumOfNALU = i+numnalu; 6158 6159 for(j=0;j<i;j++) { 6160 OMX_PRINT1(pComponentPrivate->dbg,"pParm->pNALUSizeArray[%d] = %d\n",j,pParam->pNALUSizeArray[j]); 6161 } 6162 } 6163 else { 6164 /* add the data nalu sizes to the array. 6165 * we should not have any ccd sizes in here */ 6166 for(j=0;j<i;j++) { 6167 pParam->pNALUSizeArray[j] = nalusize[j]; 6168 OMX_PRINT1(pComponentPrivate->dbg,"pParm->pNALUSizeArray[%d] = %d\n",j,pParam->pNALUSizeArray[j]); 6169 } 6170 pParam->ulNumOfNALU = i; 6171 } 6172 }/* end else */ 6173#endif 6174 }/* end bitstrm fmt */ 6175 }/* end nFlags & EOS */ 6176 size_dsp = sizeof(H264VDEC_UALGInputParam); 6177 }/* end if AVC */ 6178 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 6179 pUalgInpParams = pBufferPrivate->pUalgParam; 6180 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 6181 ((WMV9DEC_UALGInputParam*)pUalgInpParams)->lBuffCount = ++pComponentPrivate->frameCounter; 6182 } 6183 size_dsp = sizeof(WMV9DEC_UALGInputParam); 6184 } 6185 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 6186 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 6187 pUalgInpParams = pBufferPrivate->pUalgParam; 6188 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 6189 ((MP4VD_GPP_SN_UALGInputParams*)pUalgInpParams)->nBuffCount = ++pComponentPrivate->frameCounter; 6190 } 6191 size_dsp = sizeof(MP4VD_GPP_SN_UALGInputParams); 6192 } 6193 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 6194 pUalgInpParams = pBufferPrivate->pUalgParam; 6195 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 6196 ((MP2VDEC_UALGInputParam*)pUalgInpParams)->lBuffCount = ++pComponentPrivate->frameCounter; 6197 } 6198 size_dsp = sizeof(MP2VDEC_UALGInputParam); 6199 } 6200#ifdef VIDDEC_SPARK_CODE 6201 else if (VIDDEC_SPARKCHECK) { 6202 pUalgInpParams = pBufferPrivate->pUalgParam; 6203 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) { 6204 ((SPARKVD_GPP_SN_UALGInputParams*)pUalgInpParams)->lBuffCount = ++pComponentPrivate->frameCounter; 6205 } 6206 ((SPARKVD_GPP_SN_UALGInputParams*)pUalgInpParams)->nIsSparkInput = 1; 6207 size_dsp = sizeof(SPARKVD_GPP_SN_UALGInputParams); 6208 } 6209#endif 6210 else { 6211 eError = OMX_ErrorUnsupportedSetting; 6212 OMX_PRBUFFER4(pComponentPrivate->dbg, "VIDDEC_HandleDataBuf_FromApp 0x%x\n", eError); 6213 goto EXIT; 6214 } 6215 /* Store time stamp information */ 6216 if (pComponentPrivate->ProcessMode == 0) { 6217 OMX_U8 ucIndex = 0; 6218 OMX_PTR pBufferFlags = NULL; 6219 ucIndex = VIDDEC_CircBuf_GetHead(pComponentPrivate, 6220 VIDDEC_CBUFFER_TIMESTAMP, 6221 VIDDEC_INPUT_PORT); 6222 pComponentPrivate->aBufferFlags[ucIndex].nTimeStamp = pBuffHead->nTimeStamp; 6223 pBuffHead->nFlags &= ~OMX_BUFFERFLAG_EOS; 6224 pComponentPrivate->aBufferFlags[ucIndex].nFlags = pBuffHead->nFlags; 6225 pComponentPrivate->aBufferFlags[ucIndex].nTickCount = pBuffHead->nTickCount; 6226 pBufferFlags = &pComponentPrivate->aBufferFlags[ucIndex]; 6227 VIDDEC_CircBuf_Add(pComponentPrivate, 6228 VIDDEC_CBUFFER_TIMESTAMP, 6229 VIDDEC_INPUT_PORT, 6230 pBufferFlags); 6231 } 6232 else { 6233 pComponentPrivate->arrBufIndex[pComponentPrivate->nInBufIndex] = pBuffHead->nTimeStamp; 6234 pComponentPrivate->nInBufIndex++; 6235 pComponentPrivate->nInBufIndex %= VIDDEC_MAX_QUEUE_SIZE; 6236 } 6237 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nTimeStamp %lld\n", pBuffHead->nTimeStamp); 6238 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nOffset %lu\n", pBuffHead->nOffset); 6239 #ifdef __PERF_INSTRUMENTATION__ 6240 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 6241 pBuffHead->pBuffer, 6242 pBuffHead->nFilledLen, 6243 PERF_ModuleCommonLayer); 6244 #endif 6245 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 6246 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 6247 pComponentPrivate->pLCML != NULL){ 6248 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP; 6249 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFilledLen %lu\n", pBuffHead->nFilledLen); 6250 OMX_PRBUFFER1(pComponentPrivate->dbg, "Sending Filled eBufferOwner 0x%x f%x\n", pBufferPrivate->eBufferOwner, pComponentPrivate->frameCounter); 6251 6252 6253#ifdef __PERF_INSTRUMENTATION__ 6254 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 6255 pBuffHead->pBuffer, 6256 pBuffHead->nFilledLen, 6257 PERF_ModuleHLMM); 6258#endif 6259 6260 if(pComponentPrivate->bDynamicConfigurationInProgress){ 6261 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 6262 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 6263 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 6264 6265 OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending buffer back to client pBuffer=%p\n", pBuffHead->pBuffer); 6266 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 6267 pComponentPrivate->pHandle->pApplicationPrivate, 6268 pBuffHead); 6269 goto EXIT; 6270 } 6271#ifdef ANDROID 6272 6273 if(pComponentPrivate->eFirstBuffer.bSaveFirstBuffer == OMX_TRUE){ 6274 if(pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV && 6275 pComponentPrivate->nWMVFileType == VIDDEC_WMV_RCVSTREAM){ 6276 ((WMV9DEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = ++pComponentPrivate->frameCounter; 6277 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*) 6278 pLcmlHandle)->pCodecinterfacehandle, 6279 EMMCodecInputBufferMapBufLen, 6280 (OMX_U8*)&pComponentPrivate->pBufferRCV.pBuffer, 6281 sizeof(VIDDEC_WMV_RCV_struct), 6282 sizeof(VIDDEC_WMV_RCV_struct), 6283 (OMX_U8 *)pUalgInpParams, 6284 sizeof(WMV9DEC_UALGInputParam), 6285 (OMX_U8*)&pComponentPrivate->pBufferTemp); 6286 } 6287 else { 6288 eError = VIDDEC_CopyBuffer(pComponentPrivate, pBuffHead); 6289 if (eError != OMX_ErrorNone) { 6290 OMX_PRDSP4(pComponentPrivate->dbg, "VIDDEC_HandleDataBuf_FromApp: VIDDEC_CopyBuffer()= 0x%x\n", eError); 6291 if (eError == OMX_ErrorInsufficientResources) { 6292 goto EXIT; 6293 } 6294 } 6295 } 6296 } 6297#endif 6298 6299 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_QueueBuffer(INPUT), nFilledLen=0x%x nFlags=0x%x", pBuffHead->nFilledLen, pBuffHead->nFlags); 6300 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP; 6301 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*) 6302 pLcmlHandle)->pCodecinterfacehandle, 6303 ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) ? EMMCodecInputBufferMapBufLen : EMMCodecInputBuffer), /*Only WMV need to send map buffers */ 6304 &pBuffHead->pBuffer[pBuffHead->nOffset],/*WMV_VC1_CHANGES*/ 6305 pBuffHead->nAllocLen, 6306 pBuffHead->nFilledLen, 6307 (OMX_U8 *)pUalgInpParams, 6308 size_dsp, 6309 (OMX_U8 *)pBuffHead); 6310 if (eError != OMX_ErrorNone){ 6311 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer 2 (0x%x)\n",eError); 6312 eError = OMX_ErrorHardware; 6313 goto EXIT; 6314 } 6315 } 6316 else { 6317 eError = OMX_ErrorHardware; 6318 goto EXIT; 6319 } 6320 } 6321 else { 6322 pBuffHead->nFilledLen = 0; 6323 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT; 6324 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 6325 pComponentPrivate->nInputBCountDsp++; 6326 ret = write(pComponentPrivate->free_inpBuf_Q[1], &pBuffHead, sizeof(pBuffHead)); 6327 if(ret == -1){ 6328 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%d)\n", OMX_ErrorInsufficientResources,ret); 6329 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 6330 pComponentPrivate->pHandle->pApplicationPrivate, 6331 OMX_EventError, 6332 OMX_ErrorInsufficientResources, 6333 OMX_TI_ErrorSevere, 6334 "Error writing to the output pipe"); 6335 } 6336 } 6337 } 6338EXIT: 6339 OMX_PRBUFFER1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 6340 return eError; 6341} 6342 6343/* ========================================================================== */ 6344/** 6345 * Handle Data Buff function from DSP 6346 **/ 6347/* ========================================================================== */ 6348 6349OMX_ERRORTYPE VIDDEC_HandleDataBuf_FromDsp(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate) 6350{ 6351 OMX_ERRORTYPE eError = OMX_ErrorNone; 6352 OMX_ERRORTYPE eExtendedError = OMX_ErrorNone; 6353 OMX_BUFFERHEADERTYPE* pBuffHead; 6354 VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL; 6355 int ret; 6356 6357 OMX_PRBUFFER1(pComponentPrivate->dbg, "+++ENTERING\n"); 6358 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate 0x%p\n", (int*)pComponentPrivate); 6359 ret = read(pComponentPrivate->filled_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead)); 6360 if (ret == -1) { 6361 OMX_PRDSP4(pComponentPrivate->dbg, "Error while reading from dsp out pipe\n"); 6362 eError = OMX_ErrorHardware; 6363 goto EXIT; 6364 } 6365 if (pComponentPrivate->eState == OMX_StateLoaded || pComponentPrivate->eState == OMX_StateIdle) { 6366 eError = OMX_ErrorNone; 6367 goto EXIT; 6368 } 6369 OMX_PRBUFFER1(pComponentPrivate->dbg, "BufferSize fromDSP %lu \n",pBuffHead->nAllocLen); 6370 OMX_PRBUFFER1(pComponentPrivate->dbg, "AllocLen: 0x%x, FilledLen: 0x%x\n", pBuffHead->nAllocLen, pBuffHead->nFilledLen); 6371 OMX_PRSTATE1(pComponentPrivate->dbg, "pBuffHead 0x%p eExecuteToIdle 0x%x\n", pBuffHead,pComponentPrivate->eExecuteToIdle); 6372 if(pBuffHead != NULL) { 6373 OMX_S32 nErrorCode = 0; 6374 OMX_S32 nInternalErrorCode = 0; 6375 OMX_U32 ulDisplayID = 0; 6376 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate; 6377 pBuffHead->nFlags &= ~(OMX_BUFFERFLAG_SYNCFRAME); 6378 pBuffHead->nFlags &= ~(VIDDEC_BUFFERFLAG_FRAMETYPE_MASK); 6379 pBuffHead->nFlags &= ~(VIDDEC_BUFFERFLAG_EXTENDERROR_MASK); 6380 6381 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 6382 H264VDEC_UALGOutputParam* pUalgOutParams = NULL; 6383 pUalgOutParams = (H264VDEC_UALGOutputParam *)pBufferPrivate->pUalgParam; 6384 nErrorCode = (pUalgOutParams->iErrorCode); 6385 ulDisplayID = pUalgOutParams->ulDisplayID; 6386 if(pUalgOutParams->ulDecodedFrameType == VIDDEC_I_FRAME) { 6387 pBuffHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 6388 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_I_FRAME; 6389 } 6390 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_P_FRAME){ 6391 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_P_FRAME; 6392 } 6393 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_B_FRAME){ 6394 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_B_FRAME; 6395 } 6396 else { 6397 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_IDR_FRAME; 6398 } 6399 /*VIDDEC_ISFLAGSET*/ 6400 } 6401 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 6402 WMV9DEC_UALGOutputParam* pUalgOutParams = NULL; 6403 pUalgOutParams = (WMV9DEC_UALGOutputParam *)pBufferPrivate->pUalgParam; 6404 nErrorCode = (pUalgOutParams->iErrorCode); 6405 ulDisplayID = pUalgOutParams->ulDisplayID; 6406 if(pUalgOutParams->ulDecodedFrameType == VIDDEC_I_FRAME) { 6407 pBuffHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 6408 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_I_FRAME; 6409 } 6410 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_P_FRAME){ 6411 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_P_FRAME; 6412 } 6413 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_B_FRAME){ 6414 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_B_FRAME; 6415 } 6416 else { 6417 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_IDR_FRAME; 6418 } 6419 } 6420 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 6421 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 6422 MP4VD_GPP_SN_UALGOutputParams* pUalgOutParams = NULL; 6423 pUalgOutParams = (MP4VD_GPP_SN_UALGOutputParams *)pBufferPrivate->pUalgParam; 6424 nErrorCode = (pUalgOutParams->iErrorCode); 6425 ulDisplayID = pUalgOutParams->ulDisplayID; 6426 if(pUalgOutParams->ulDecodedFrameType == VIDDEC_I_FRAME) { 6427 pBuffHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 6428 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_I_FRAME; 6429 } 6430 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_P_FRAME){ 6431 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_P_FRAME; 6432 } 6433 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_B_FRAME){ 6434 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_B_FRAME; 6435 } 6436 else { 6437 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_IDR_FRAME; 6438 } 6439 } 6440 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 6441 MP2VDEC_UALGOutputParam* pUalgOutParams = NULL; 6442 pUalgOutParams = (MP2VDEC_UALGOutputParam *)pBufferPrivate->pUalgParam; 6443 nErrorCode = (pUalgOutParams->lErrorCode); 6444 ulDisplayID = pUalgOutParams->ulDisplayID; 6445 if(pUalgOutParams->ulDecodedFrameType == VIDDEC_I_FRAME) { 6446 pBuffHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 6447 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_I_FRAME; 6448 } 6449 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_P_FRAME){ 6450 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_P_FRAME; 6451 } 6452 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_B_FRAME){ 6453 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_B_FRAME; 6454 } 6455 else { 6456 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_IDR_FRAME; 6457 } 6458 } 6459#ifdef VIDDEC_SPARK_CODE 6460 else if (VIDDEC_SPARKCHECK) { 6461 SPARKVD_GPP_SN_UALGOutputParams* pUalgOutParams = NULL; 6462 pUalgOutParams = (SPARKVD_GPP_SN_UALGOutputParams *)pBufferPrivate->pUalgParam; 6463 nErrorCode = (pUalgOutParams->iErrorCode); 6464 ulDisplayID = pUalgOutParams->ulDisplayID; 6465 if(pUalgOutParams->ulDecodedFrameType == VIDDEC_I_FRAME) { 6466 pBuffHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 6467 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_I_FRAME; 6468 } 6469 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_P_FRAME){ 6470 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_P_FRAME; 6471 } 6472 else if(pUalgOutParams->ulDecodedFrameType == VIDDEC_B_FRAME){ 6473 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_B_FRAME; 6474 } 6475 else { 6476 pBuffHead->nFlags |= VIDDEC_BUFFERFLAG_FRAMETYPE_IDR_FRAME; 6477 } 6478 } 6479#endif 6480 else { 6481 eError = OMX_ErrorUnsupportedSetting; 6482 goto EXIT; 6483 } 6484 pBuffHead->nFlags |= (nErrorCode<<12); 6485 /*OMX_ERROR4(pComponentPrivate->dbg, "nErrorCode %x nFlags %x\n", (int *)nErrorCode, (int *)pBuffHead->nFlags);*/ 6486 if((nErrorCode & 0xff) != 0){/*OMX_BUFFERFLAG_DATACORRUPT*/ 6487 nInternalErrorCode = ((nErrorCode & VIDDEC_BUFFERFLAG_EXTENDERROR_DIRTY)>>12); 6488 if(VIDDEC_ISFLAGSET(nErrorCode,VIDDEC_XDM_FATALERROR)){ 6489 eExtendedError = OMX_ErrorStreamCorrupt; 6490 pBuffHead->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; 6491 pBuffHead->nFilledLen = 0; 6492 OMX_PRDSP4(pComponentPrivate->dbg, "Not Recoverable Error Detected in Buffer in buffer %p %lu(int# %lx/%lu) OMX_ErrorStreamCorrupt\n", 6493 pBuffHead, ulDisplayID, (nErrorCode & VIDDEC_BUFFERFLAG_EXTENDERROR_DIRTY), pBuffHead->nFilledLen); 6494 } 6495 if(VIDDEC_ISFLAGSET(nErrorCode,VIDDEC_XDM_APPLIEDCONCEALMENT)){ 6496 pBuffHead->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; 6497 OMX_PRDSP4(pComponentPrivate->dbg, "Applied Concealment in buffer %p %lu(int# %lx/%lu)\n", 6498 pBuffHead, ulDisplayID, nInternalErrorCode, pBuffHead->nFilledLen); 6499 } 6500 if(VIDDEC_ISFLAGSET(nErrorCode,VIDDEC_XDM_INSUFFICIENTDATA)){ 6501 pBuffHead->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; 6502 pBuffHead->nFilledLen = 0; 6503 OMX_PRDSP4(pComponentPrivate->dbg, "Insufficient Data in buffer %p %lu(int# %lx/%lu)\n", 6504 pBuffHead, ulDisplayID, nInternalErrorCode, pBuffHead->nFilledLen); 6505 } 6506 if(VIDDEC_ISFLAGSET(nErrorCode,VIDDEC_XDM_CORRUPTEDDATA)){ 6507 pBuffHead->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; 6508 pBuffHead->nFilledLen = 0; 6509 OMX_PRDSP4(pComponentPrivate->dbg, "Corrupted Data in buffer %p %lu(int# %lx/%lu)\n", 6510 pBuffHead, ulDisplayID, nInternalErrorCode, pBuffHead->nFilledLen); 6511 } 6512 if(VIDDEC_ISFLAGSET(nErrorCode,VIDDEC_XDM_CORRUPTEDHEADER)){ 6513 pBuffHead->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; 6514 pBuffHead->nFilledLen = 0; 6515 OMX_PRDSP4(pComponentPrivate->dbg, "Corrupted Header in buffer %p %lu(int# %lx/%lu)\n", 6516 pBuffHead, ulDisplayID, nInternalErrorCode, pBuffHead->nFilledLen); 6517 } 6518 if(VIDDEC_ISFLAGSET(nErrorCode,VIDDEC_XDM_UNSUPPORTEDINPUT)){ 6519 pBuffHead->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; 6520 pBuffHead->nFilledLen = 0; 6521 OMX_PRDSP4(pComponentPrivate->dbg, "Unsupported Input in buffer %p %lu(int# %lx/%lu)\n", 6522 pBuffHead, ulDisplayID, nInternalErrorCode, pBuffHead->nFilledLen); 6523 } 6524 if(VIDDEC_ISFLAGSET(nErrorCode,VIDDEC_XDM_UNSUPPORTEDPARAM)){ 6525 pBuffHead->nFlags |= OMX_BUFFERFLAG_DATACORRUPT; 6526 pBuffHead->nFilledLen = 0; 6527 OMX_PRDSP4(pComponentPrivate->dbg, "Unsupported Parameter in buffer %p %lu(int# %lx/%lu)\n", 6528 pBuffHead, ulDisplayID, nInternalErrorCode, pBuffHead->nFilledLen); 6529 } 6530 } 6531#ifdef KHRONOS_1_1 6532 if (pComponentPrivate->eMBErrorReport.bEnabled) {/* && pBuffHead->nFilledLen != 0*/ 6533 OMX_U8* ErrMapFrom = NULL; 6534 OMX_U8* ErrMapTo = NULL; 6535 /*OMX_U32 nlooping = 0;*/ 6536 OMX_U32 nErrMapSize = 0; 6537 if (pComponentPrivate->MPEG4Codec_IsTI && 6538 (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 6539 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)) { 6540 MP4VD_GPP_SN_UALGOutputParams* pUalgOutParams = NULL; 6541 pUalgOutParams = (MP4VD_GPP_SN_UALGOutputParams *)pBufferPrivate->pUalgParam; 6542 ErrMapFrom = pUalgOutParams->usMbErrorBuf; 6543 /*todo add code to use ualg_array*/ 6544 nErrMapSize = pComponentPrivate->pOutPortDef->format.video.nFrameWidth * 6545 pComponentPrivate->pOutPortDef->format.video.nFrameHeight / 256; 6546 ErrMapTo = pComponentPrivate->eMBErrorMapType[pComponentPrivate->cMBErrorIndexIn].ErrMap; 6547 pComponentPrivate->eMBErrorMapType[pComponentPrivate->cMBErrorIndexIn].nErrMapSize = nErrMapSize; 6548 memcpy(ErrMapTo, ErrMapFrom, nErrMapSize); 6549 pComponentPrivate->cMBErrorIndexIn++; 6550 pComponentPrivate->cMBErrorIndexIn %= pComponentPrivate->pOutPortDef->nBufferCountActual; 6551 } 6552 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 6553 H264VDEC_UALGOutputParam* pUalgOutParams = NULL; 6554 pUalgOutParams = (H264VDEC_UALGOutputParam *)pBufferPrivate->pUalgParam; 6555 ErrMapFrom = pUalgOutParams->pMBErrStatOutBuf; 6556 /*todo add code to use ualg_array*/ 6557 nErrMapSize = pComponentPrivate->pOutPortDef->format.video.nFrameWidth * 6558 pComponentPrivate->pOutPortDef->format.video.nFrameHeight / 256; 6559 ErrMapTo = pComponentPrivate->eMBErrorMapType[pComponentPrivate->cMBErrorIndexIn].ErrMap; 6560 pComponentPrivate->eMBErrorMapType[pComponentPrivate->cMBErrorIndexIn].nErrMapSize = nErrMapSize; 6561 memcpy(ErrMapTo, ErrMapFrom, nErrMapSize); 6562 pComponentPrivate->cMBErrorIndexIn++; 6563 pComponentPrivate->cMBErrorIndexIn %= pComponentPrivate->pOutPortDef->nBufferCountActual; 6564 } 6565 } 6566#endif 6567 if (pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 6568 if(pComponentPrivate->bFirstBuffer) { 6569 OMX_PRBUFFER2(pComponentPrivate->dbg, "**** Setting OMX_BUFFERFLAG_STARTTIME\n"); 6570 pBuffHead->nFlags |= OMX_BUFFERFLAG_STARTTIME; 6571 pComponentPrivate->bFirstBuffer = 0; 6572 } 6573 else { 6574 pBuffHead->nFlags &= ~(OMX_BUFFERFLAG_STARTTIME); 6575 } 6576 if(pBuffHead != NULL){ 6577 if((pBuffHead->nFlags & OMX_BUFFERFLAG_DECODEONLY) == 0) { 6578 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_TUNNELEDCOMP; 6579 OMX_PRBUFFER1(pComponentPrivate->dbg, "tunnel eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 6580 #ifdef __PERF_INSTRUMENTATION__ 6581 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 6582 pBuffHead->pBuffer, 6583 pBuffHead->nFilledLen, 6584 PERF_ModuleLLMM); 6585 #endif 6586 OMX_PRDSP2(pComponentPrivate->dbg, "VIDDEC_HandleDataBuf_FromDsp %x %x\n",(int)pBuffHead->nFlags,(int)pBuffHead->nFilledLen); 6587 VIDDEC_Propagate_Mark(pComponentPrivate, pBuffHead); 6588 eError = OMX_EmptyThisBuffer(pComponentPrivate->pCompPort[1]->hTunnelComponent, pBuffHead); 6589 } 6590 else { 6591 write(pComponentPrivate->free_outBuf_Q[1],&pBuffHead,sizeof(pBuffHead)); 6592 } 6593 } 6594 } 6595 else { 6596 if(pBuffHead != NULL) { 6597 #ifdef __PERF_INSTRUMENTATION__ 6598 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 6599 pBuffHead->pBuffer, 6600 pBuffHead->nFilledLen, 6601 PERF_ModuleHLMM); 6602 #endif 6603 6604 VIDDEC_Propagate_Mark(pComponentPrivate, pBuffHead); 6605 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 6606 OMX_PRBUFFER1(pComponentPrivate->dbg, "standalone buffer eBufferOwner 0x%x -- %lx\n", pBufferPrivate->eBufferOwner,pBuffHead->nFlags); 6607 if((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS)){ 6608 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 6609 pComponentPrivate->pHandle->pApplicationPrivate, 6610 OMX_EventBufferFlag, 6611 VIDDEC_OUTPUT_PORT, 6612 OMX_BUFFERFLAG_EOS, 6613 NULL); 6614 } 6615 pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle, 6616 pComponentPrivate->pHandle->pApplicationPrivate, 6617 pBuffHead); 6618 } 6619 } 6620 } 6621 6622EXIT: 6623 if(eExtendedError != OMX_ErrorNone) { 6624 eError = eExtendedError; 6625 } 6626 OMX_PRBUFFER1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 6627 return eError; 6628} 6629 6630/* ========================================================================== */ 6631/** 6632 * Handle Free Data Buff 6633 **/ 6634/* ========================================================================== */ 6635 6636OMX_ERRORTYPE VIDDEC_HandleFreeDataBuf( VIDDEC_COMPONENT_PRIVATE *pComponentPrivate ) 6637{ 6638 OMX_ERRORTYPE eError = OMX_ErrorNone; 6639 OMX_BUFFERHEADERTYPE* pBuffHead; 6640 VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL; 6641 int ret; 6642 int inputbufsize = (int)pComponentPrivate->pInPortDef->nBufferSize; 6643 6644 OMX_PRBUFFER1(pComponentPrivate->dbg, "+++ENTERING\n"); 6645 OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate 0x%p\n", (int*)pComponentPrivate); 6646 ret = read(pComponentPrivate->free_inpBuf_Q[0], &pBuffHead, sizeof(pBuffHead)); 6647 if (ret == -1) { 6648 OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from the free Q\n"); 6649 eError = OMX_ErrorHardware; 6650 goto EXIT; 6651 } 6652 if (pComponentPrivate->eState == OMX_StateLoaded || pComponentPrivate->eState == OMX_StateIdle) { 6653 eError = OMX_ErrorNone; 6654 goto EXIT; 6655 } 6656 OMX_PRSTATE1(pComponentPrivate->dbg, "pBuffHead 0x%p eExecuteToIdle 0x%x\n", pBuffHead,pComponentPrivate->eExecuteToIdle); 6657 if (pBuffHead != NULL) { 6658 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 6659 pBuffHead->nAllocLen = inputbufsize; 6660 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT; 6661 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 6662#ifdef __PERF_INSTRUMENTATION__ 6663 PERF_SendingFrame(pComponentPrivate->pPERFcomp, 6664 pBuffHead->pBuffer, 6665 pBuffHead->nFilledLen, 6666 PERF_ModuleHLMM); 6667#endif 6668 6669 pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle, 6670 pComponentPrivate->pHandle->pApplicationPrivate, 6671 pBuffHead); 6672 } 6673 OMX_PRBUFFER1(pComponentPrivate->dbg, "---EXITING(0x%x) \n",eError); 6674EXIT: 6675 return eError; 6676} 6677 6678/*-------------------------------------------------------------------*/ 6679/** 6680 * Function to fill DSP structures via LCML 6681 * 6682 * 6683 * 6684 * @retval OMX_NoError Success, ready to roll 6685 * 6686 **/ 6687/*-------------------------------------------------------------------*/ 6688OMX_ERRORTYPE VIDDEC_InitDSP_WMVDec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 6689{ 6690 OMX_ERRORTYPE eError = OMX_ErrorNone; 6691 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 6692 LCML_DSP *lcml_dsp = NULL; 6693 OMX_U32 nInpBuff = MAX_PRIVATE_IN_BUFFERS; 6694 OMX_U32 nInpBuffSize = 0; 6695 OMX_U32 nOutBuff = MAX_PRIVATE_OUT_BUFFERS; 6696 OMX_U32 nOutBuffSize = 0; 6697 WMV9DEC_SNCreatePhArg* pCreatePhaseArgs = NULL; 6698 LCML_CALLBACKTYPE cb; 6699 6700 OMX_PRDSP1(pComponentPrivate->dbg, "+++ENTERING\n"); 6701 nInpBuff = pComponentPrivate->pInPortDef->nBufferCountActual; 6702 nOutBuff = pComponentPrivate->pOutPortDef->nBufferCountActual; 6703 6704 /* Back it up for further use in this function */ 6705 nInpBuffSize = pComponentPrivate->pInPortDef->nBufferSize; 6706 nOutBuffSize = pComponentPrivate->pOutPortDef->nBufferSize; 6707 6708 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLCML; 6709 lcml_dsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec); 6710 6711 lcml_dsp->DeviceInfo.TypeofDevice = 0; 6712 lcml_dsp->DeviceInfo.DspStream = NULL; 6713 6714 lcml_dsp->In_BufInfo.nBuffers = nInpBuff; 6715 lcml_dsp->In_BufInfo.nSize = nInpBuffSize; 6716 lcml_dsp->In_BufInfo.DataTrMethod = DMM_METHOD; 6717 6718 lcml_dsp->Out_BufInfo.nBuffers = nOutBuff; 6719 lcml_dsp->Out_BufInfo.nSize = nOutBuffSize; 6720 lcml_dsp->Out_BufInfo.DataTrMethod = DMM_METHOD; 6721 6722 lcml_dsp->NodeInfo.nNumOfDLLs = OMX_WMVDEC_NUM_DLLS; 6723 lcml_dsp->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID *)&WMVDSOCKET_TI_UUID; 6724 strcpy ((char*)(lcml_dsp->NodeInfo.AllUUIDs[0].DllName),(char*)WMV_DEC_NODE_DLL); 6725 lcml_dsp->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 6726 6727 lcml_dsp->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID *)&WMVDSOCKET_TI_UUID; 6728 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[1].DllName,(char*)WMV_DEC_NODE_DLL); 6729 lcml_dsp->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 6730 6731 lcml_dsp->NodeInfo.AllUUIDs[2].uuid = (struct DSP_UUID *)&USN_UUID; 6732 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[2].DllName,(char*)USN_DLL); 6733 lcml_dsp->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT; 6734 6735 lcml_dsp->NodeInfo.AllUUIDs[3].uuid = (struct DSP_UUID *)&RINGIO_TI_UUID; 6736 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)RINGIO_NODE_DLL); 6737 lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT; 6738 6739 lcml_dsp->SegID = 0; 6740 lcml_dsp->Timeout = -1; 6741 lcml_dsp->Alignment = 0; 6742 lcml_dsp->Priority = 5; 6743 6744 if(pComponentPrivate->ProcessMode == 0){ 6745 if(pComponentPrivate->wmvProfile == VIDDEC_WMV_PROFILEMAX) 6746 { 6747 if ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 640) || 6748 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 480)) { 6749 lcml_dsp->ProfileID = 4; 6750 } 6751 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 640) && 6752 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 352)) || 6753 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 480) && 6754 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 288))) { 6755 lcml_dsp->ProfileID = 2; 6756 } 6757 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 352) && 6758 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 176)) || 6759 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 288) && 6760 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 144))) { 6761 lcml_dsp->ProfileID = 1; 6762 } 6763 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 176) && 6764 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth >= 16)) || 6765 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 144) && 6766 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight >= 16))) { 6767 lcml_dsp->ProfileID = 0; 6768 } 6769 else { 6770 eError = OMX_ErrorUnsupportedSetting; 6771 goto EXIT; 6772 } 6773 } 6774 else 6775 { 6776 switch(pComponentPrivate->wmvProfile) 6777 { 6778 case VIDDEC_WMV_PROFILE0: 6779 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID0; 6780 break; 6781 case VIDDEC_WMV_PROFILE1: 6782 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID1; 6783 break; 6784 case VIDDEC_WMV_PROFILE2: 6785 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID2; 6786 break; 6787 default: 6788 { 6789 eError = OMX_ErrorBadParameter; 6790 goto EXIT; 6791 } 6792 } 6793 } 6794 } else if(pComponentPrivate->ProcessMode == 1) 6795 { 6796 switch(pComponentPrivate->wmvProfile) 6797 { 6798 case VIDDEC_WMV_PROFILE3: 6799 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID3; 6800 break; 6801 case VIDDEC_WMV_PROFILE4: 6802 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID4; 6803 break; 6804 case VIDDEC_WMV_PROFILE5: 6805 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID5; 6806 break; 6807 case VIDDEC_WMV_PROFILE6: 6808 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID6; 6809 break; 6810 case VIDDEC_WMV_PROFILE7: 6811 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID7; 6812 break; 6813 case VIDDEC_WMV_PROFILE8: 6814 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID8; 6815 break; 6816 case VIDDEC_WMV_PROFILEMAX: 6817 lcml_dsp->ProfileID = VIDDEC_WMV_PROFILE_ID8; 6818 break; 6819 default: 6820 eError = OMX_ErrorBadParameter; 6821 goto EXIT; 6822 } 6823 } 6824 else 6825 { 6826 eError = OMX_ErrorUnsupportedSetting; 6827 goto EXIT; 6828 } 6829 6830 OMX_MALLOC_STRUCT(pCreatePhaseArgs, WMV9DEC_SNCreatePhArg,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 6831 if (pCreatePhaseArgs == NULL) { 6832 eError = OMX_ErrorInsufficientResources; 6833 goto EXIT; 6834 } 6835 pCreatePhaseArgs->unNumOfStreams = 2; 6836 pCreatePhaseArgs->unInputStreamID = 0; 6837 pCreatePhaseArgs->unInputBufferType = 0; 6838 pCreatePhaseArgs->unInputNumBufsPerStream = (OMX_U16)nInpBuff; 6839 pCreatePhaseArgs->unOutputStreamID = 1; 6840 pCreatePhaseArgs->unOutputBufferType = 0; 6841 pCreatePhaseArgs->unOutputNumBufsPerStream = (OMX_U16)nOutBuff; 6842 pCreatePhaseArgs->ulMaxWidth = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth); 6843 pCreatePhaseArgs->ulMaxHeight = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight); 6844 6845 if (pComponentPrivate->nWMVFileType != VIDDEC_WMV_ELEMSTREAM) { 6846 pComponentPrivate->pBufferRCV.sStructRCV.nVertSize = (OMX_U32)(pComponentPrivate->pInPortDef->format.video.nFrameHeight); 6847 pComponentPrivate->pBufferRCV.sStructRCV.nHorizSize = (OMX_U32)(pComponentPrivate->pInPortDef->format.video.nFrameWidth); 6848 } 6849 6850 if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT422) { 6851 pCreatePhaseArgs->ulYUVFormat = WMV9VIDDEC_YUVFORMAT_INTERLEAVED422; 6852 } 6853 else if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT420) { 6854 pCreatePhaseArgs->ulYUVFormat = WMV9VIDDEC_YUVFORMAT_PLANAR420; 6855 } 6856 else 6857 { 6858 OMX_PRDSP4(pComponentPrivate->dbg, "Incorrect Color format %x\n",pComponentPrivate->pOutPortDef->format.video.eColorFormat); 6859 eError = OMX_ErrorUnsupportedSetting; 6860 goto EXIT; 6861 } 6862 6863 pCreatePhaseArgs->ulMaxFrameRate = 0; 6864 pCreatePhaseArgs->ulMaxBitRate = 0; 6865 pCreatePhaseArgs->ulDataEndianness = 1; 6866 pCreatePhaseArgs->ulProfile = -1; 6867 pCreatePhaseArgs->ulMaxLevel = -1; 6868 pCreatePhaseArgs->ulProcessMode = pComponentPrivate->ProcessMode; 6869 pCreatePhaseArgs->lPreRollBufConfig = 0; 6870 6871 if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM) { 6872 pCreatePhaseArgs->usIsElementaryStream = VIDDEC_SN_WMV_ELEMSTREAM; 6873 } 6874 else { 6875 pCreatePhaseArgs->usIsElementaryStream = VIDDEC_SN_WMV_RCVSTREAM; 6876 } 6877 6878 pCreatePhaseArgs->endArgs = END_OF_CR_PHASE_ARGS; 6879 6880 lcml_dsp->pCrPhArgs = (OMX_U16 *) pCreatePhaseArgs; 6881 cb.LCML_Callback = (void *) VIDDEC_LCML_Callback; 6882 6883 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 6884 pComponentPrivate->pLCML != NULL){ 6885 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb); 6886 if (eError != OMX_ErrorNone) { 6887 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError); 6888 eError = OMX_ErrorHardware; 6889 goto EXIT; 6890 } 6891 } 6892 else { 6893 eError = OMX_ErrorHardware; 6894 goto EXIT; 6895 } 6896EXIT: 6897 free(pCreatePhaseArgs); 6898 pCreatePhaseArgs = NULL; 6899 6900 OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 6901 return eError; 6902} 6903 6904 6905 6906/*-------------------------------------------------------------------*/ 6907/** 6908 * Function to fill DSP structures via LCML 6909 * 6910 * 6911 * 6912 * @retval OMX_NoError Success, ready to roll 6913 * 6914 **/ 6915/*-------------------------------------------------------------------*/ 6916 6917OMX_ERRORTYPE VIDDEC_InitDSP_H264Dec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 6918{ 6919 OMX_ERRORTYPE eError = OMX_ErrorNone; 6920 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 6921 LCML_DSP *lcml_dsp = NULL; 6922 OMX_U32 nInpBuff = MAX_PRIVATE_IN_BUFFERS; 6923 OMX_U32 nInpBuffSize = 0; 6924 OMX_U32 nOutBuff = MAX_PRIVATE_OUT_BUFFERS; 6925 OMX_U32 nOutBuffSize = 0; 6926 H264VDEC_SNCreatePhArg* pCreatePhaseArgs = NULL; 6927 LCML_CALLBACKTYPE cb; 6928 6929 OMX_PRDSP1(pComponentPrivate->dbg, "+++ENTERING\n"); 6930 6931 /* Get number of input and output buffers */ 6932 nInpBuff = pComponentPrivate->pInPortDef->nBufferCountActual; 6933 nOutBuff = pComponentPrivate->pOutPortDef->nBufferCountActual; 6934 6935 /* Back it up for further use in this function */ 6936 nInpBuffSize = pComponentPrivate->pInPortDef->nBufferSize; 6937 nOutBuffSize = pComponentPrivate->pOutPortDef->nBufferSize; 6938 6939 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLCML; 6940 lcml_dsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec); 6941 6942 lcml_dsp->DeviceInfo.TypeofDevice = 0; 6943 lcml_dsp->DeviceInfo.DspStream = NULL; 6944 6945 lcml_dsp->In_BufInfo.nBuffers = nInpBuff; 6946 lcml_dsp->In_BufInfo.nSize = nInpBuffSize; 6947 lcml_dsp->In_BufInfo.DataTrMethod = DMM_METHOD; 6948 6949 lcml_dsp->Out_BufInfo.nBuffers = nOutBuff; 6950 lcml_dsp->Out_BufInfo.nSize = nOutBuffSize; 6951 lcml_dsp->Out_BufInfo.DataTrMethod = DMM_METHOD; 6952 6953 lcml_dsp->NodeInfo.nNumOfDLLs = OMX_H264DEC_NUM_DLLS; 6954 lcml_dsp->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID *)&H264VDSOCKET_TI_UUID; 6955 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[0].DllName,(char*)H264_DEC_NODE_DLL); 6956 lcml_dsp->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 6957 6958 lcml_dsp->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID *)&H264VDSOCKET_TI_UUID; 6959 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[1].DllName,(char*)H264_DEC_NODE_DLL); 6960 lcml_dsp->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 6961 6962 lcml_dsp->NodeInfo.AllUUIDs[2].uuid = (struct DSP_UUID *)&USN_UUID; 6963 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[2].DllName,(char*)USN_DLL); 6964 lcml_dsp->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT; 6965 6966 lcml_dsp->NodeInfo.AllUUIDs[3].uuid = (struct DSP_UUID *)&RINGIO_TI_UUID; 6967 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)RINGIO_NODE_DLL); 6968 lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT; 6969 6970 lcml_dsp->SegID = 0; 6971 lcml_dsp->Timeout = -1; 6972 lcml_dsp->Alignment = 0; 6973 lcml_dsp->Priority = 5; 6974 6975 if(pComponentPrivate->ProcessMode == 0){ 6976 if ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 352) || 6977 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 288)) { 6978 lcml_dsp->ProfileID = 3; 6979 } 6980 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 352) && 6981 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 176)) || 6982 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 288) && 6983 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 144))) { 6984 lcml_dsp->ProfileID = 2; 6985 } 6986 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 176) && 6987 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth >= 16)) || 6988 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 144) && 6989 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight >= 16))) { 6990 lcml_dsp->ProfileID = 1; 6991 } 6992 else { 6993 eError = OMX_ErrorUnsupportedSetting; 6994 goto EXIT; 6995 } 6996 } 6997 else if(pComponentPrivate->ProcessMode == 1) { 6998 /*OMX_VIDEO_AVCLevelMax*/ 6999 switch(pComponentPrivate->pH264->eLevel) { 7000 case OMX_VIDEO_AVCLevel1: 7001 lcml_dsp->ProfileID = 8; 7002 break; 7003 case OMX_VIDEO_AVCLevel1b: 7004 lcml_dsp->ProfileID = 9; 7005 break; 7006 case OMX_VIDEO_AVCLevel11: 7007 lcml_dsp->ProfileID = 10; 7008 break; 7009 case OMX_VIDEO_AVCLevel12: 7010 lcml_dsp->ProfileID = 11; 7011 break; 7012 case OMX_VIDEO_AVCLevel13: 7013 case OMX_VIDEO_AVCLevel2: 7014 lcml_dsp->ProfileID = 12; 7015 break; 7016 case OMX_VIDEO_AVCLevel21: 7017 case OMX_VIDEO_AVCLevel22: 7018 lcml_dsp->ProfileID = 13; 7019 break; 7020 default: 7021 lcml_dsp->ProfileID = 14; 7022 break; 7023 } 7024 } 7025 /*add code to error*/ 7026 OMX_PRDSP1(pComponentPrivate->dbg, "lcml_dsp->ProfileID = %lu\n", lcml_dsp->ProfileID); 7027 OMX_MALLOC_STRUCT(pCreatePhaseArgs, H264VDEC_SNCreatePhArg,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 7028 if (pCreatePhaseArgs == NULL) { 7029 eError = OMX_ErrorInsufficientResources; 7030 goto EXIT; 7031 } 7032 pCreatePhaseArgs->unNumOfStreams = 2; 7033 pCreatePhaseArgs->unInputStreamID = 0; 7034 pCreatePhaseArgs->unInputBufferType = 0; 7035 pCreatePhaseArgs->unInputNumBufsPerStream = (OMX_U16)nInpBuff; 7036 pCreatePhaseArgs->unOutputStreamID = 1; 7037 pCreatePhaseArgs->unOutputBufferType = 0; 7038 pCreatePhaseArgs->unOutputNumBufsPerStream = (OMX_U16)nOutBuff; 7039 pCreatePhaseArgs->ulMaxWidth = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth); 7040 pCreatePhaseArgs->ulMaxHeight = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight); 7041 7042 if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT422) { 7043 pCreatePhaseArgs->ulYUVFormat = H264VIDDEC_YUVFORMAT_INTERLEAVED422; 7044 } 7045 else if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT420) { 7046 pCreatePhaseArgs->ulYUVFormat = H264VIDDEC_YUVFORMAT_PLANAR420; 7047 } 7048 else 7049 { 7050 OMX_PRDSP4(pComponentPrivate->dbg, "Incorrect Color format %x\n",pComponentPrivate->pOutPortDef->format.video.eColorFormat); 7051 eError = OMX_ErrorUnsupportedSetting; 7052 goto EXIT; 7053 } 7054 7055 pCreatePhaseArgs->ulMaxFrameRate = 0; 7056 pCreatePhaseArgs->ulMaxBitRate = 0; 7057 pCreatePhaseArgs->ulDataEndianness = 1; 7058 pCreatePhaseArgs->ulProfile = 0; 7059 pCreatePhaseArgs->ulMaxLevel = -1; 7060 pCreatePhaseArgs->ulProcessMode = pComponentPrivate->ProcessMode; 7061 pCreatePhaseArgs->lPreRollBufConfig = 0; 7062 pCreatePhaseArgs->ulBitStreamFormat = (pComponentPrivate->H264BitStreamFormat>0?1:0); 7063 7064 pCreatePhaseArgs->ulDisplayWidth = 0; 7065 pCreatePhaseArgs->endArgs = END_OF_CR_PHASE_ARGS; 7066 7067 memcpy (pComponentPrivate->arr, pCreatePhaseArgs, sizeof(H264VDEC_SNCreatePhArg)); 7068 lcml_dsp->pCrPhArgs = pComponentPrivate->arr; 7069 cb.LCML_Callback = (void *) VIDDEC_LCML_Callback; 7070 free(pCreatePhaseArgs); 7071 pCreatePhaseArgs = NULL; 7072 7073 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 7074 pComponentPrivate->pLCML != NULL){ 7075 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb); 7076 if (eError != OMX_ErrorNone) { 7077 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError); 7078 eError = OMX_ErrorHardware; 7079 goto EXIT; 7080 } 7081 } 7082 else { 7083 eError = OMX_ErrorHardware; 7084 goto EXIT; 7085 } 7086EXIT: 7087 OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 7088 return eError; 7089} 7090 7091/*-------------------------------------------------------------------*/ 7092/** 7093 * Function to fill DSP structures via LCML 7094 * 7095 * 7096 * 7097 * @retval OMX_NoError Success, ready to roll 7098 * 7099 **/ 7100/*-------------------------------------------------------------------*/ 7101 7102OMX_ERRORTYPE VIDDEC_InitDSP_Mpeg4Dec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 7103{ 7104 OMX_ERRORTYPE eError = OMX_ErrorNone; 7105 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 7106 LCML_DSP *lcml_dsp = NULL; 7107 OMX_U32 nInpBuff = MAX_PRIVATE_IN_BUFFERS; 7108 OMX_U32 nInpBuffSize = 0; 7109 OMX_U32 nOutBuff = MAX_PRIVATE_OUT_BUFFERS; 7110 OMX_U32 nOutBuffSize = 0; 7111 MP4VD_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs = NULL; 7112 LCML_CALLBACKTYPE cb; 7113 7114 OMX_PRDSP1(pComponentPrivate->dbg, "+++ENTERING\n"); 7115 /* Get number of input and output buffers */ 7116 nInpBuff = pComponentPrivate->pInPortDef->nBufferCountActual; 7117 nOutBuff = pComponentPrivate->pOutPortDef->nBufferCountActual; 7118 7119 /* Back it up for further use in this function */ 7120 nInpBuffSize = pComponentPrivate->pInPortDef->nBufferSize; 7121 nOutBuffSize = pComponentPrivate->pOutPortDef->nBufferSize; 7122 7123 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 7124 lcml_dsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec); 7125 7126 lcml_dsp->DeviceInfo.TypeofDevice = 0; 7127 lcml_dsp->DeviceInfo.DspStream = NULL; 7128 7129 lcml_dsp->In_BufInfo.nBuffers = nInpBuff; 7130 lcml_dsp->In_BufInfo.nSize = nInpBuffSize; 7131 lcml_dsp->In_BufInfo.DataTrMethod = DMM_METHOD; 7132 7133 lcml_dsp->Out_BufInfo.nBuffers = nOutBuff; 7134 lcml_dsp->Out_BufInfo.nSize = nOutBuffSize; 7135 lcml_dsp->Out_BufInfo.DataTrMethod = DMM_METHOD; 7136 7137 lcml_dsp->NodeInfo.nNumOfDLLs = OMX_MP4DEC_NUM_DLLS; 7138 OMX_U32 nFrameWidth = pComponentPrivate->pOutPortDef->format.video.nFrameWidth; 7139 OMX_U32 nFrameHeight = pComponentPrivate->pOutPortDef->format.video.nFrameHeight; 7140 7141 /* nFrameWidth and nFrameHeight needs to be multiples of 16. */ 7142 nFrameWidth = (nFrameWidth + 0x0f) & ~0x0f; 7143 nFrameHeight = (nFrameHeight + 0x0f) & ~0x0f; 7144 7145 if (nFrameWidth * nFrameHeight > 880 * 720) 7146 { 7147 lcml_dsp->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID *)&MP4D720PSOCKET_TI_UUID; 7148 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[0].DllName,(char*)MP4720P_DEC_NODE_DLL); 7149 lcml_dsp->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 7150 7151 lcml_dsp->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID *)&MP4D720PSOCKET_TI_UUID; 7152 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[1].DllName,(char*)MP4720P_DEC_NODE_DLL); 7153 lcml_dsp->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 7154 7155 pComponentPrivate->eMBErrorReport.bEnabled = FALSE; 7156 pComponentPrivate->MPEG4Codec_IsTI = FALSE; 7157 } 7158 else 7159 { 7160 lcml_dsp->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID *)&MP4DSOCKET_TI_UUID; 7161 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[0].DllName,(char*)MP4_DEC_NODE_DLL); 7162 lcml_dsp->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 7163 7164 lcml_dsp->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID *)&MP4DSOCKET_TI_UUID; 7165 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[1].DllName,(char*)MP4_DEC_NODE_DLL); 7166 lcml_dsp->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 7167 pComponentPrivate->MPEG4Codec_IsTI = TRUE; 7168 } 7169 7170 lcml_dsp->NodeInfo.AllUUIDs[2].uuid = (struct DSP_UUID *)&RINGIO_TI_UUID; 7171 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[2].DllName,(char*)RINGIO_NODE_DLL); 7172 lcml_dsp->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT; 7173 7174 lcml_dsp->NodeInfo.AllUUIDs[3].uuid = (struct DSP_UUID *)&USN_UUID; 7175 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)USN_DLL); 7176 lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT; 7177 7178 lcml_dsp->SegID = 0; 7179 lcml_dsp->Timeout = -1; 7180 lcml_dsp->Alignment = 0; 7181 lcml_dsp->Priority = 5; 7182 7183 if (nFrameWidth * nFrameHeight > 640 * 480) { 7184 lcml_dsp->ProfileID = 4; 7185 } 7186 else if (nFrameWidth * nFrameHeight > 352 * 288) { 7187 lcml_dsp->ProfileID = 3; 7188 } 7189 else if (nFrameWidth * nFrameHeight > 176 * 144) { 7190 lcml_dsp->ProfileID = 2; 7191 } 7192 else if (nFrameWidth * nFrameHeight >= 16 * 16) { 7193 lcml_dsp->ProfileID = 1; 7194 } 7195 else { 7196 eError = OMX_ErrorUnsupportedSetting; 7197 goto EXIT; 7198 } 7199 7200 OMX_MALLOC_STRUCT(pCreatePhaseArgs, MP4VD_GPP_SN_Obj_CreatePhase,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 7201 if (pCreatePhaseArgs == NULL) { 7202 eError = OMX_ErrorInsufficientResources; 7203 goto EXIT; 7204 } 7205 pCreatePhaseArgs->unNumOfStreams = 2; 7206 pCreatePhaseArgs->unInputStreamID = 0; 7207 pCreatePhaseArgs->unInputBufferType = 0; 7208 pCreatePhaseArgs->unlInputNumBufsPerStream = (OMX_U16)(pComponentPrivate->pInPortDef->nBufferCountActual); 7209 pCreatePhaseArgs->unOutputStreamID = 1; 7210 pCreatePhaseArgs->unOutputBufferType = 0; 7211 pCreatePhaseArgs->unOutputNumBufsPerStream = (OMX_U16)(pComponentPrivate->pOutPortDef->nBufferCountActual); 7212 pCreatePhaseArgs->ulMaxWidth = (OMX_U16)(nFrameWidth); 7213 pCreatePhaseArgs->ulMaxHeight = (OMX_U16)(nFrameHeight); 7214 7215 if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT422) { 7216 pCreatePhaseArgs->ulYUVFormat = MP4VIDDEC_YUVFORMAT_INTERLEAVED422; 7217 } 7218 else if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT420) { 7219 pCreatePhaseArgs->ulYUVFormat = MP4VIDDEC_YUVFORMAT_PLANAR420; 7220 } 7221 else 7222 { 7223 OMX_PRDSP4(pComponentPrivate->dbg, "Incorrect Color format %x\n",pComponentPrivate->pOutPortDef->format.video.eColorFormat); 7224 OMX_PRDSP1(pComponentPrivate->dbg, "lcml_dsp->ProfileID = %lu\n", lcml_dsp->ProfileID); 7225 eError = OMX_ErrorUnsupportedSetting; 7226 goto EXIT; 7227 } 7228 7229 OMX_PRBUFFER1(pComponentPrivate->dbg, "pCreatePhaseArgs->ulMaxWidth %lu pCreatePhaseArgs->ulMaxHeight %lu\n", 7230 pCreatePhaseArgs->ulMaxWidth,pCreatePhaseArgs->ulMaxHeight); 7231 pCreatePhaseArgs->ulMaxFrameRate = 0; 7232 pCreatePhaseArgs->ulMaxBitRate = -1; 7233 pCreatePhaseArgs->ulDataEndianness = 1; 7234 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4){ 7235 pCreatePhaseArgs->ulProfile = 0; 7236 } 7237 else { 7238 pCreatePhaseArgs->ulProfile = 8; 7239 } 7240 pCreatePhaseArgs->ulMaxLevel = -1; 7241 pCreatePhaseArgs->ulProcessMode = pComponentPrivate->ProcessMode; 7242 pCreatePhaseArgs->ulPreRollBufConfig = 0; 7243 pCreatePhaseArgs->ulDisplayWidth = 0; 7244 pCreatePhaseArgs->endArgs = END_OF_CR_PHASE_ARGS; 7245 7246 memcpy(pComponentPrivate->arr, pCreatePhaseArgs, sizeof(MP4VD_GPP_SN_Obj_CreatePhase)); 7247 lcml_dsp->pCrPhArgs = pComponentPrivate->arr; 7248 cb.LCML_Callback = (void*) VIDDEC_LCML_Callback; 7249 free(pCreatePhaseArgs); 7250 pCreatePhaseArgs = NULL; 7251 7252 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 7253 pComponentPrivate->pLCML != NULL){ 7254 pComponentPrivate->eLCMLState = VidDec_LCML_State_Init; 7255 7256 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb); 7257 if (eError != OMX_ErrorNone) { 7258 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError); 7259 eError = OMX_ErrorHardware; 7260 goto EXIT; 7261 } 7262 } 7263 else { 7264 eError = OMX_ErrorHardware; 7265 goto EXIT; 7266 } 7267EXIT: 7268 OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 7269 return eError; 7270} 7271 7272 7273/*-------------------------------------------------------------------*/ 7274/** 7275 * Function to fill DSP structures via LCML 7276 * 7277 * 7278 * 7279 * @retval OMX_NoError Success, ready to roll 7280 * 7281 **/ 7282/*-------------------------------------------------------------------*/ 7283 7284OMX_ERRORTYPE VIDDEC_InitDSP_Mpeg2Dec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 7285{ 7286 OMX_ERRORTYPE eError = OMX_ErrorNone; 7287 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 7288 LCML_DSP *lcml_dsp = NULL; 7289 OMX_U32 nInpBuff = MAX_PRIVATE_IN_BUFFERS; 7290 OMX_U32 nInpBuffSize = 0; 7291 OMX_U32 nOutBuff = MAX_PRIVATE_OUT_BUFFERS; 7292 OMX_U32 nOutBuffSize = 0; 7293 MP2VDEC_SNCreatePhArg* pCreatePhaseArgs = NULL; 7294 LCML_CALLBACKTYPE cb; 7295 7296 OMX_PRDSP1(pComponentPrivate->dbg, "+++ENTERING\n"); 7297 /* Get number of input and output buffers */ 7298 nInpBuff = pComponentPrivate->pInPortDef->nBufferCountActual; 7299 nOutBuff = pComponentPrivate->pOutPortDef->nBufferCountActual; 7300 7301 /* Back it up for further use in this function */ 7302 nInpBuffSize = pComponentPrivate->pInPortDef->nBufferSize; 7303 nOutBuffSize = pComponentPrivate->pOutPortDef->nBufferSize; 7304 7305 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 7306 lcml_dsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec); 7307 7308 lcml_dsp->DeviceInfo.TypeofDevice = 0; 7309 lcml_dsp->DeviceInfo.DspStream = NULL; 7310 7311 lcml_dsp->In_BufInfo.nBuffers = nInpBuff; 7312 lcml_dsp->In_BufInfo.nSize = nInpBuffSize; 7313 lcml_dsp->In_BufInfo.DataTrMethod = DMM_METHOD; 7314 7315 lcml_dsp->Out_BufInfo.nBuffers = nOutBuff; 7316 lcml_dsp->Out_BufInfo.nSize = nOutBuffSize; 7317 lcml_dsp->Out_BufInfo.DataTrMethod = DMM_METHOD; 7318 7319 lcml_dsp->NodeInfo.nNumOfDLLs = OMX_MP2DEC_NUM_DLLS; 7320 lcml_dsp->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID *)&MP2DSOCKET_TI_UUID; 7321 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[0].DllName,(char*)MP2_DEC_NODE_DLL); 7322 lcml_dsp->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 7323 7324 lcml_dsp->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID *)&MP2DSOCKET_TI_UUID; 7325 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[1].DllName,(char*)MP2_DEC_NODE_DLL); 7326 lcml_dsp->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 7327 7328 lcml_dsp->NodeInfo.AllUUIDs[2].uuid = (struct DSP_UUID *)&RINGIO_TI_UUID; 7329 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[2].DllName,(char*)RINGIO_NODE_DLL); 7330 lcml_dsp->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT; 7331 7332 lcml_dsp->NodeInfo.AllUUIDs[3].uuid = (struct DSP_UUID *)&USN_UUID; 7333 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)USN_DLL); 7334 lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT; 7335 7336 lcml_dsp->SegID = 0; 7337 lcml_dsp->Timeout = -1; 7338 lcml_dsp->Alignment = 0; 7339 lcml_dsp->Priority = 5; 7340 7341 if(pComponentPrivate->ProcessMode == 0){ 7342 if ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 352) || 7343 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 288)) { 7344 lcml_dsp->ProfileID = 3; 7345 } 7346 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 352) && 7347 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 176)) || 7348 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 288) && 7349 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 144))) { 7350 lcml_dsp->ProfileID = 2; 7351 } 7352 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 176) && 7353 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth >= 16)) || 7354 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 144) && 7355 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight >= 16))) { 7356 lcml_dsp->ProfileID = 1; 7357 } 7358 else { 7359 eError = OMX_ErrorUnsupportedSetting; 7360 goto EXIT; 7361 } 7362 } 7363 else if(pComponentPrivate->ProcessMode == 1) { 7364 if ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 352) || 7365 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 288)) { 7366 lcml_dsp->ProfileID = 3; 7367 } 7368 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 352) && 7369 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 176)) || 7370 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 288) && 7371 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 144))) { 7372 lcml_dsp->ProfileID = 2; 7373 } 7374 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 176) && 7375 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth >= 16)) || 7376 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 144) && 7377 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight >= 16))) { 7378 lcml_dsp->ProfileID = 1; 7379 } 7380 else { 7381 eError = OMX_ErrorUnsupportedSetting; 7382 goto EXIT; 7383 } 7384 } 7385 7386 OMX_MALLOC_STRUCT(pCreatePhaseArgs, MP2VDEC_SNCreatePhArg,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 7387 if (pCreatePhaseArgs == NULL) { 7388 eError = OMX_ErrorInsufficientResources; 7389 goto EXIT; 7390 } 7391 pCreatePhaseArgs->unNumOfStreams = 2; 7392 pCreatePhaseArgs->unInputStreamID = 0; 7393 pCreatePhaseArgs->unInputBufferType = 0; 7394 pCreatePhaseArgs->unInputNumBufsPerStream = (OMX_U16)(pComponentPrivate->pInPortDef->nBufferCountActual); 7395 pCreatePhaseArgs->unOutputStreamID = 1; 7396 pCreatePhaseArgs->unOutputBufferType = 0; 7397 pCreatePhaseArgs->unOutputNumBufsPerStream = (OMX_U16)(pComponentPrivate->pOutPortDef->nBufferCountActual); 7398 pCreatePhaseArgs->ulMaxWidth = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth); 7399 pCreatePhaseArgs->ulMaxHeight = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight); 7400 7401 if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT422) { 7402 pCreatePhaseArgs->ulYUVFormat = MP2VIDDEC_YUVFORMAT_INTERLEAVED422; 7403 } 7404 else if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT420) { 7405 pCreatePhaseArgs->ulYUVFormat = MP2VIDDEC_YUVFORMAT_PLANAR420; 7406 } 7407 else 7408 { 7409 OMX_PRDSP4(pComponentPrivate->dbg, "Incorrect Color format %x\n",pComponentPrivate->pOutPortDef->format.video.eColorFormat); 7410 eError = OMX_ErrorUnsupportedSetting; 7411 goto EXIT; 7412 } 7413 7414 pCreatePhaseArgs->ulMaxFrameRate = 0; 7415 pCreatePhaseArgs->ulMaxBitRate = -1; 7416 pCreatePhaseArgs->ulDataEndianness = 1; 7417 pCreatePhaseArgs->ulProfile = 0; 7418 pCreatePhaseArgs->lMaxLevel = -1; 7419 pCreatePhaseArgs->ulProcessMode = pComponentPrivate->ProcessMode; 7420 pCreatePhaseArgs->lPreRollBufConfig = 0; 7421 pCreatePhaseArgs->ulDisplayWidth = 0; 7422 pCreatePhaseArgs->endArgs = END_OF_CR_PHASE_ARGS; 7423 7424 7425 memcpy(pComponentPrivate->arr, pCreatePhaseArgs, sizeof(MP2VDEC_SNCreatePhArg)); 7426 lcml_dsp->pCrPhArgs = pComponentPrivate->arr; 7427 cb.LCML_Callback = (void*) VIDDEC_LCML_Callback; 7428 free(pCreatePhaseArgs); 7429 pCreatePhaseArgs = NULL; 7430 7431 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 7432 pComponentPrivate->pLCML != NULL){ 7433 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb); 7434 if (eError != OMX_ErrorNone) { 7435 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError); 7436 eError = OMX_ErrorHardware; 7437 goto EXIT; 7438 } 7439 } 7440 else { 7441 eError = OMX_ErrorHardware; 7442 goto EXIT; 7443 } 7444EXIT: 7445 OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 7446 return eError; 7447} 7448 7449/*-------------------------------------------------------------------*/ 7450/** 7451 * Function to fill DSP structures via LCML 7452 * 7453 * 7454 * 7455 * @retval OMX_NoError Success, ready to roll 7456 * 7457 **/ 7458/*-------------------------------------------------------------------*/ 7459 7460OMX_ERRORTYPE VIDDEC_InitDSP_SparkDec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 7461{ 7462 OMX_ERRORTYPE eError = OMX_ErrorNone; 7463 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 7464 LCML_DSP *lcml_dsp = NULL; 7465 OMX_U32 nInpBuff = MAX_PRIVATE_IN_BUFFERS; 7466 OMX_U32 nInpBuffSize = 0; 7467 OMX_U32 nOutBuff = MAX_PRIVATE_OUT_BUFFERS; 7468 OMX_U32 nOutBuffSize = 0; 7469 SPARKVD_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs = NULL; 7470 LCML_CALLBACKTYPE cb; 7471 7472 OMX_PRDSP1(pComponentPrivate->dbg, "+++ENTERING\n"); 7473 /* Get number of input and output buffers */ 7474 nInpBuff = pComponentPrivate->pInPortDef->nBufferCountActual; 7475 nOutBuff = pComponentPrivate->pOutPortDef->nBufferCountActual; 7476 7477 /* Back it up for further use in this function */ 7478 nInpBuffSize = pComponentPrivate->pInPortDef->nBufferSize; 7479 nOutBuffSize = pComponentPrivate->pOutPortDef->nBufferSize; 7480 7481 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 7482 lcml_dsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec); 7483 7484 lcml_dsp->DeviceInfo.TypeofDevice = 0; 7485 lcml_dsp->DeviceInfo.DspStream = NULL; 7486 7487 lcml_dsp->In_BufInfo.nBuffers = nInpBuff; 7488 lcml_dsp->In_BufInfo.nSize = nInpBuffSize; 7489 lcml_dsp->In_BufInfo.DataTrMethod = DMM_METHOD; 7490 7491 lcml_dsp->Out_BufInfo.nBuffers = nOutBuff; 7492 lcml_dsp->Out_BufInfo.nSize = nOutBuffSize; 7493 lcml_dsp->Out_BufInfo.DataTrMethod = DMM_METHOD; 7494 7495 lcml_dsp->NodeInfo.nNumOfDLLs = OMX_SPARKDEC_NUM_DLLS; 7496 lcml_dsp->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID *)&SPARKDSOCKET_TI_UUID; 7497 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[0].DllName,(char*)SPARK_DEC_NODE_DLL); 7498 lcml_dsp->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT; 7499 7500 lcml_dsp->NodeInfo.AllUUIDs[1].uuid = (struct DSP_UUID *)&SPARKDSOCKET_TI_UUID; 7501 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[1].DllName,(char*)SPARK_DEC_NODE_DLL); 7502 lcml_dsp->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT; 7503 7504 lcml_dsp->NodeInfo.AllUUIDs[2].uuid = (struct DSP_UUID *)&RINGIO_TI_UUID; 7505 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[2].DllName,(char*)RINGIO_NODE_DLL); 7506 lcml_dsp->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT; 7507 7508 lcml_dsp->NodeInfo.AllUUIDs[3].uuid = (struct DSP_UUID *)&USN_UUID; 7509 strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)USN_DLL); 7510 lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT; 7511 7512 lcml_dsp->SegID = 0; 7513 lcml_dsp->Timeout = -1; 7514 lcml_dsp->Alignment = 0; 7515 lcml_dsp->Priority = 5; 7516 7517 7518 if(pComponentPrivate->ProcessMode == 0){ 7519 if ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 640) || 7520 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 480)) { 7521 lcml_dsp->ProfileID = 4; 7522 } 7523 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 640) && 7524 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 352)) || 7525 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 480) && 7526 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 288))) { 7527 lcml_dsp->ProfileID = 3; 7528 } 7529 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 352) && 7530 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 176)) || 7531 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 288) && 7532 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 144))) { 7533 lcml_dsp->ProfileID = 2; 7534 } 7535 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 176) && 7536 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth >= 16)) || 7537 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 144) && 7538 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight >= 16))) { 7539 lcml_dsp->ProfileID = 1; 7540 } 7541 else { 7542 eError = OMX_ErrorUnsupportedSetting; 7543 goto EXIT; 7544 } 7545 } 7546 else if(pComponentPrivate->ProcessMode == 1) { 7547 if ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 640) || 7548 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 480)) { 7549 lcml_dsp->ProfileID = 4; 7550 } 7551 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 640) && 7552 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 352)) || 7553 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 480) && 7554 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 288))) { 7555 lcml_dsp->ProfileID = 3; 7556 } 7557 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 352) && 7558 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth > 176)) || 7559 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 288) && 7560 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight > 144))) { 7561 lcml_dsp->ProfileID = 2; 7562 } 7563 else if (((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth <= 176) && 7564 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth >= 16)) || 7565 ((OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight <= 144) && 7566 (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight >= 16))) { 7567 lcml_dsp->ProfileID = 1; 7568 } 7569 else { 7570 eError = OMX_ErrorUnsupportedSetting; 7571 goto EXIT; 7572 } 7573 } 7574 7575 OMX_MALLOC_STRUCT(pCreatePhaseArgs, SPARKVD_GPP_SN_Obj_CreatePhase,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 7576 if (pCreatePhaseArgs == NULL) { 7577 eError = OMX_ErrorInsufficientResources; 7578 goto EXIT; 7579 } 7580 pCreatePhaseArgs->unNumOfStreams = 2; 7581 pCreatePhaseArgs->unInputStreamID = 0; 7582 pCreatePhaseArgs->unInputBufferType = 0; 7583 pCreatePhaseArgs->unlInputNumBufsPerStream = (OMX_U16)(pComponentPrivate->pInPortDef->nBufferCountActual); 7584 pCreatePhaseArgs->unOutputStreamID = 1; 7585 pCreatePhaseArgs->unOutputBufferType = 0; 7586 pCreatePhaseArgs->unOutputNumBufsPerStream = (OMX_U16)(pComponentPrivate->pOutPortDef->nBufferCountActual); 7587 pCreatePhaseArgs->ulMaxWidth = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth); 7588 pCreatePhaseArgs->ulMaxHeight = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight); 7589 7590 if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT422) { 7591 pCreatePhaseArgs->ulYUVFormat = SPARKVIDDEC_YUVFORMAT_INTERLEAVED422; 7592 } 7593 else if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT420) { 7594 pCreatePhaseArgs->ulYUVFormat = SPARKVIDDEC_YUVFORMAT_PLANAR420; 7595 } 7596 else 7597 { 7598 OMX_PRDSP4(pComponentPrivate->dbg, "Incorrect Color format %x\n",pComponentPrivate->pOutPortDef->format.video.eColorFormat); 7599 eError = OMX_ErrorUnsupportedSetting; 7600 goto EXIT; 7601 } 7602 7603 pCreatePhaseArgs->ulMaxFrameRate = 0; 7604 pCreatePhaseArgs->ulMaxBitRate = -1; 7605 pCreatePhaseArgs->ulDataEndianness = 1; 7606 pCreatePhaseArgs->ulProfile = 0; 7607 pCreatePhaseArgs->ulMaxLevel = -1; 7608 pCreatePhaseArgs->ulProcessMode = pComponentPrivate->ProcessMode; 7609 pCreatePhaseArgs->ulPreRollBufConfig = 0; 7610 pCreatePhaseArgs->endArgs = END_OF_CR_PHASE_ARGS; 7611 7612 memcpy(pComponentPrivate->arr, pCreatePhaseArgs, sizeof(SPARKVD_GPP_SN_Obj_CreatePhase)); 7613 lcml_dsp->pCrPhArgs = pComponentPrivate->arr; 7614 cb.LCML_Callback = (void*) VIDDEC_LCML_Callback; 7615 free(pCreatePhaseArgs); 7616 pCreatePhaseArgs = NULL; 7617 7618 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 7619 pComponentPrivate->pLCML != NULL){ 7620 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb); 7621 if (eError != OMX_ErrorNone) { 7622 OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError); 7623 eError = OMX_ErrorHardware; 7624 goto EXIT; 7625 } 7626 } 7627 else { 7628 eError = OMX_ErrorHardware; 7629 goto EXIT; 7630 } 7631EXIT: 7632 OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 7633 return eError; 7634} 7635 7636/* ========================================================================== */ 7637/** 7638 * VIDDEC_Handle_InvalidState() Function called for a non recoverable error 7639 * 7640 * @param pComponentPrivate This is the pointer to the private structure 7641 * 7642 * @retval OMX_NoError Success, ready to roll 7643 * OMX_ErrorHardware If OMX_StateInvalid is the actual state 7644 **/ 7645/* ========================================================================== */ 7646OMX_ERRORTYPE VIDDEC_Handle_InvalidState (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 7647{ 7648 OMX_ERRORTYPE eError = OMX_ErrorNone; 7649 7650 OMX_PRSTATE1(pComponentPrivate->dbg, "+++ENTERING\n"); 7651 OMX_PRSTATE2(pComponentPrivate->dbg, "pComponentPrivate 0x%p\n", (int*)pComponentPrivate); 7652 7653 if(pComponentPrivate->eState != OMX_StateInvalid) { 7654 pComponentPrivate->eState = OMX_StateInvalid; 7655 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 7656 pComponentPrivate->pHandle->pApplicationPrivate, 7657 OMX_EventError, 7658 OMX_ErrorInvalidState, 7659 OMX_TI_ErrorCritical, 7660 "Transitioning to Invalid State"); 7661 eError = OMX_ErrorNone; 7662 } 7663 else { 7664 eError = OMX_ErrorHardware; 7665 } 7666 OMX_PRSTATE1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 7667 return eError; 7668} 7669 7670 7671/* ========================================================================== */ 7672/** 7673 * VIDDEC_PROPAGATE_MARK() Function called for propagate mark from input buffers to output buffers 7674 * 7675 * @param pComponentPrivate This is the pointer to the private structure 7676 * @param pBuffHead This is the pointer to the output buffer 7677 * 7678 * @retval OMX_NoError Success 7679 * OMX_ErrorUnsupportedSetting If CompressionFormat has not a valid value 7680 **/ 7681/* ========================================================================== */ 7682OMX_ERRORTYPE VIDDEC_Propagate_Mark(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE *pBuffHead) 7683{ 7684 OMX_ERRORTYPE eError = OMX_ErrorNone; 7685 7686 if (pBuffHead->nFilledLen != 0) { 7687 pBuffHead->hMarkTargetComponent = pComponentPrivate->arrMarkBufIndex[pComponentPrivate->nInMarkBufIndex].hMarkTargetComponent; 7688 pBuffHead->pMarkData = pComponentPrivate->arrMarkBufIndex[pComponentPrivate->nInMarkBufIndex].pMarkData; 7689 pComponentPrivate->nOutMarkBufIndex++; 7690 pComponentPrivate->nOutMarkBufIndex %= VIDDEC_MAX_QUEUE_SIZE; 7691 eError = OMX_ErrorNone; 7692 } 7693 if(pBuffHead->hMarkTargetComponent == pComponentPrivate->pHandle) 7694 { 7695 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 7696 pComponentPrivate->pHandle->pApplicationPrivate, 7697 OMX_EventMark, 7698 0, 7699 0, 7700 pBuffHead->pMarkData); 7701 } 7702 7703 return eError; 7704} 7705 7706 7707 7708/* ========================================================================== */ 7709/** 7710 * Callback() function will be called LCML component to write the msg 7711 * 7712 * @param msgBuffer This buffer will be returned by the LCML 7713 * 7714 * @retval OMX_NoError Success, ready to roll 7715 * OMX_Error_BadParameter The input parameter pointer is null 7716 **/ 7717/* ========================================================================== */ 7718 7719OMX_ERRORTYPE VIDDEC_LCML_Callback (TUsnCodecEvent event,void * argsCb [10]) 7720{ 7721 VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL; 7722 OMX_ERRORTYPE eError = OMX_ErrorNone; 7723 VIDDEC_BUFFER_PRIVATE* pBufferPrivate = NULL; 7724 OMX_S32 nRetVal = 0; 7725 7726 pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)argsCb[6])->pComponentPrivate; 7727 7728#if 0 7729 switch(event) { 7730 case EMMCodecDspError: 7731 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecDspError (int)argsCb [0] %x (int)argsCb [4] %x (int)argsCb [5] %x\n",(int)argsCb [0],(int)argsCb [4],(int)argsCb [5]); 7732 break; 7733 7734 case EMMCodecInternalError: 7735 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecInternalError\n"); 7736 break; 7737 7738 case EMMCodecInitError: 7739 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecInitError\n"); 7740 break; 7741 7742 case EMMCodecDspMessageRecieved: 7743 OMX_PRDSP1(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecDspMessageRecieved\n"); 7744 break; 7745 case EMMCodecBufferProcessed: 7746 OMX_PRDSP0(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecBufferProcessed %x\n",(int)argsCb [0]); 7747 break; 7748 case EMMCodecProcessingStarted: 7749 OMX_PRDSP1(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingStarted\n"); 7750 break; 7751 7752 case EMMCodecProcessingPaused: 7753 OMX_PRDSP1(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingPaused\n"); 7754 break; 7755 7756 case EMMCodecProcessingStoped: 7757 OMX_PRDSP1(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingStoped\n"); 7758 break; 7759 7760 case EMMCodecProcessingEof: 7761 OMX_PRDSP1(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecProcessingEof\n"); 7762 break; 7763 case EMMCodecBufferNotProcessed: 7764 OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecBufferNotProcessed %x\n",(int)argsCb [0]); 7765 break; 7766 case EMMCodecAlgCtrlAck: 7767 OMX_PRDSP1(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecAlgCtrlAck\n"); 7768 break; 7769 7770 case EMMCodecStrmCtrlAck: 7771 OMX_PRDSP1(pComponentPrivate->dbg, "[LCML CALLBACK EVENT] EMMCodecStrmCtrlAck\n"); 7772 break; 7773 } 7774#endif 7775 7776 OMX_PRDSP0(pComponentPrivate->dbg, "+++ENTERING\n"); 7777 OMX_PRDSP0(pComponentPrivate->dbg, "pComponentPrivate 0x%p 0x%x\n", (int*)pComponentPrivate,event); 7778 7779 if(pComponentPrivate->pCompPort[0] == NULL){ 7780 OMX_PRDSP4(pComponentPrivate->dbg, "*****************************error in lcmlcalback******************************\n"); 7781 goto EXIT; 7782 } 7783 if (event == EMMCodecProcessingPaused) { 7784 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 7785 VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex); 7786 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 7787 pComponentPrivate->bTransPause = 1; 7788 } 7789 if (event == EMMCodecAlgCtrlAck) { 7790 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 7791 VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex); 7792 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 7793 pComponentPrivate->bTransPause = 1; 7794 } 7795 if (event == EMMCodecProcessingStoped) { 7796 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 7797 VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex); 7798 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 7799 pComponentPrivate->bTransPause = 1; 7800 pComponentPrivate->bIsPaused = 0; 7801 } 7802 if (event == EMMCodecProcessingStarted) { 7803 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 7804 VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex); 7805 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 7806 pComponentPrivate->bTransPause = 1; 7807 pComponentPrivate->bIsPaused = 0; 7808 } 7809 if (event == EMMCodecBufferProcessed) { 7810 OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecBufferProcessed 0x%lx\n", (OMX_U32)argsCb [0]); 7811 if ((OMX_U32)argsCb [0] == EMMCodecOuputBuffer) { 7812 OMX_PRBUFFER1(pComponentPrivate->dbg, "EMMCodecOuputBuffer\n"); 7813 OMX_BUFFERHEADERTYPE* pBuffHead = NULL; 7814 VIDDEC_BUFFER_PRIVATE* pBuffPriv = NULL; 7815 OMX_U8* pBuffer; 7816 7817 if (pComponentPrivate->eState != OMX_StateLoaded && pComponentPrivate->eState != OMX_StateIdle) { 7818 pBuffHead = (OMX_BUFFERHEADERTYPE*)argsCb[7]; 7819 if(pBuffHead != NULL) 7820 { 7821 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead Output 0x%p pBuffer 0x%p\n", pBuffHead, argsCb[1]); 7822 pBuffPriv = (VIDDEC_BUFFER_PRIVATE*)pBuffHead->pOutputPortPrivate; 7823 if (pBuffPriv != NULL) { 7824 if(pBuffPriv->eBufferOwner != VIDDEC_BUFFER_WITH_CLIENT) 7825 { 7826#ifdef __PERF_INSTRUMENTATION__ 7827 pComponentPrivate->lcml_nCntOpReceived++; 7828 if (pComponentPrivate->lcml_nCntOpReceived == 4) { 7829 PERF_Boundary(pComponentPrivate->pPERFcomp, 7830 PERF_BoundaryStart | PERF_BoundarySteadyState); 7831 } 7832#endif 7833 pBuffer = (OMX_U8*)argsCb[1]; 7834 /* Retrieve time stamp information */ 7835 if (pComponentPrivate->ProcessMode == 0) { 7836 OMX_PTR pBufferFlags; 7837 VIDDEC_CircBuf_Remove(pComponentPrivate, 7838 VIDDEC_CBUFFER_TIMESTAMP, 7839 VIDDEC_INPUT_PORT, 7840 &pBufferFlags); 7841 if(pBufferFlags != NULL){ 7842 pBuffHead->nTimeStamp = (OMX_TICKS)((VIDDEC_CBUFFER_BUFFERFLAGS*)pBufferFlags)->nTimeStamp; 7843 /*pBuffHead->nFlags = 0; 7844 pBuffHead->nFlags = (OMX_U32)((VIDDEC_CBUFFER_BUFFERFLAGS*)pBufferFlags)->nFlags;*/ 7845 pBuffHead->nFlags |= (((OMX_U32)((VIDDEC_CBUFFER_BUFFERFLAGS*)pBufferFlags)->nFlags) & OMX_BUFFERFLAG_DECODEONLY); 7846 pBuffHead->nTickCount = (OMX_U32)((VIDDEC_CBUFFER_BUFFERFLAGS*)pBufferFlags)->nTickCount; 7847 } 7848 else { 7849 pBuffHead->nTimeStamp = 0; 7850 pBuffHead->nTickCount = 0; 7851 } 7852 } 7853 else { 7854 if (pBuffHead->nFilledLen != 0){ 7855 pBuffHead->nTimeStamp = (OMX_TICKS)pComponentPrivate->arrBufIndex[pComponentPrivate->nOutBufIndex]; 7856 pComponentPrivate->nOutBufIndex++; 7857 pComponentPrivate->nOutBufIndex %= VIDDEC_MAX_QUEUE_SIZE; 7858 } 7859 } 7860 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nTimeStamp %lld\n", pBuffHead->nTimeStamp); 7861 if(pBuffHead != NULL){ 7862 /*if (pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 7863 pBuffHead->nFilledLen = (OMX_S32)argsCb[2]; 7864 } 7865 else {*/ 7866 pBuffHead->nFilledLen = (OMX_S32)argsCb[8]; 7867 /*}*/ 7868 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFilledLen %lu\n", pBuffHead->nFilledLen); 7869 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate; 7870 pComponentPrivate->nOutputBCountDsp++; 7871 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT; 7872 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 7873#ifdef __PERF_INSTRUMENTATION__ 7874 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp, 7875 pBuffHead->pBuffer, 7876 pBuffHead->nFilledLen, 7877 PERF_ModuleCommonLayer); 7878#endif 7879 7880 nRetVal = write(pComponentPrivate->filled_outBuf_Q[1],&pBuffHead,sizeof(pBuffHead)); 7881 if(nRetVal == -1){ 7882 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%ld)\n", OMX_ErrorInsufficientResources,nRetVal); 7883 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 7884 pComponentPrivate->pHandle->pApplicationPrivate, 7885 OMX_EventError, 7886 OMX_ErrorInsufficientResources, 7887 OMX_TI_ErrorSevere, 7888 "Error writing to the output pipe"); 7889 } 7890 } 7891 } 7892 else { 7893 OMX_PRDSP1(pComponentPrivate->dbg, "buffer dropped lcml out process pBuffHead %p owner %d\n",pBuffHead,pBuffPriv->eBufferOwner); 7894 } 7895 } 7896 } 7897 } 7898 } 7899 if ((OMX_U32)argsCb [0] == EMMCodecInputBuffer || 7900 ((OMX_U32)argsCb [0] == EMMCodecInputBufferMapBufLen)) { 7901 OMX_PRBUFFER1(pComponentPrivate->dbg, "EMMCodecInputBuffer\n"); 7902 OMX_BUFFERHEADERTYPE* pBuffHead = NULL; 7903 VIDDEC_BUFFER_PRIVATE* pBuffPriv = NULL; 7904 OMX_U8* pBuffer; 7905 if (pComponentPrivate->eState != OMX_StateLoaded && pComponentPrivate->eState != OMX_StateIdle) { 7906 pBuffHead = (OMX_BUFFERHEADERTYPE*)argsCb[7]; 7907 if(pBuffHead != NULL) 7908 { 7909 pBuffPriv = (VIDDEC_BUFFER_PRIVATE*)pBuffHead->pInputPortPrivate; 7910 if (pBuffPriv == NULL ) { 7911 goto EXIT; 7912 } 7913 else { 7914 if(pBuffPriv->eBufferOwner != VIDDEC_BUFFER_WITH_CLIENT) 7915 { 7916 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead Input 0x%p pBuffer 0x%p\n", pBuffHead, argsCb[1]); 7917 pBuffer = (OMX_U8*)argsCb[1]; 7918 if(pBuffer != NULL){ 7919 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 7920 pComponentPrivate->nInputBCountDsp++; 7921 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT; 7922 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 7923 #ifdef __PERF_INSTRUMENTATION__ 7924 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp, 7925 PREF(pBuffHead,pBuffer), 7926 PREF(pBuffHead,nFilledLen), 7927 PERF_ModuleCommonLayer); 7928 #endif 7929 pBuffHead->nFilledLen = 0; 7930 if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM && 7931 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV && 7932 pComponentPrivate->ProcessMode == 0) { 7933 /* vc-1 fix */ 7934#ifdef VIDDEC_WMVPOINTERFIXED 7935 OMX_PRBUFFER1(pComponentPrivate->dbg, "restoring buffer pointer 0x%p >> pBuffer 0x%p\n", 7936 pBufferPrivate->pTempBuffer, pBuffHead->pBuffer); 7937 pBuffHead->pBuffer = pBufferPrivate->pTempBuffer; 7938#else 7939 pBuffHead->nOffset = VIDDEC_WMV_BUFFER_OFFSET; 7940#endif 7941 } 7942 nRetVal = write(pComponentPrivate->free_inpBuf_Q[1], &pBuffHead, sizeof(pBuffHead)); 7943 if(nRetVal == -1){ 7944 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%lu)\n", OMX_ErrorInsufficientResources,nRetVal); 7945 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 7946 pComponentPrivate->pHandle->pApplicationPrivate, 7947 OMX_EventError, 7948 OMX_ErrorInsufficientResources, 7949 OMX_TI_ErrorSevere, 7950 "Error writing to the output pipe"); 7951 } 7952 } 7953 } 7954 else { 7955 OMX_PRDSP1(pComponentPrivate->dbg, "buffer dropped lcml in notprocess pBuffHead %p owner %d\n",pBuffHead,pBuffPriv->eBufferOwner); 7956 } 7957 } 7958 } 7959 } 7960 } 7961 } 7962 /************************************************************************************************/ 7963 if (event == EMMCodecBufferNotProcessed) { 7964 OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecBufferNotProcessed\n"); 7965 if ((OMX_U32)argsCb [0] == EMMCodecOuputBuffer) { 7966 OMX_BUFFERHEADERTYPE* pBuffHead = NULL; 7967 VIDDEC_BUFFER_PRIVATE* pBuffPriv = NULL; 7968 OMX_U8* pBuffer; 7969 7970 if (pComponentPrivate->eState != OMX_StateLoaded && pComponentPrivate->eState != OMX_StateIdle) { 7971 pBuffHead = (OMX_BUFFERHEADERTYPE*)argsCb[7]; 7972 if(pBuffHead != NULL) 7973 { 7974 pBuffPriv = (VIDDEC_BUFFER_PRIVATE*)pBuffHead->pOutputPortPrivate; 7975 if (pBuffPriv != NULL) { 7976 if(pBuffPriv->eBufferOwner != VIDDEC_BUFFER_WITH_CLIENT) 7977 { 7978#ifdef __PERF_INSTRUMENTATION__ 7979 pComponentPrivate->lcml_nCntOpReceived++; 7980 if (pComponentPrivate->lcml_nCntOpReceived == 4) { 7981 PERF_Boundary(pComponentPrivate->pPERFcomp, 7982 PERF_BoundaryStart | PERF_BoundarySteadyState); 7983 } 7984#endif 7985 pBuffer = (OMX_U8*)argsCb[1]; 7986 /* Retrieve time stamp information */ 7987 if (pComponentPrivate->ProcessMode == 0) { 7988 OMX_PTR pBufferFlags; 7989 VIDDEC_CircBuf_Remove(pComponentPrivate, 7990 VIDDEC_CBUFFER_TIMESTAMP, 7991 VIDDEC_INPUT_PORT, 7992 &pBufferFlags); 7993 if(pBufferFlags != NULL){ 7994 pBuffHead->nTimeStamp = (OMX_TICKS)((VIDDEC_CBUFFER_BUFFERFLAGS*)pBufferFlags)->nTimeStamp; 7995 /*pBuffHead->nFlags = 0; 7996 pBuffHead->nFlags = (OMX_U32)((VIDDEC_CBUFFER_BUFFERFLAGS*)pBufferFlags)->nFlags;*/ 7997 pBuffHead->nFlags |= (((OMX_U32)((VIDDEC_CBUFFER_BUFFERFLAGS*)pBufferFlags)->nFlags) & OMX_BUFFERFLAG_DECODEONLY); 7998 pBuffHead->nTickCount = (OMX_U32)((VIDDEC_CBUFFER_BUFFERFLAGS*)pBufferFlags)->nTickCount; 7999 } 8000 else { 8001 pBuffHead->nTimeStamp = 0; 8002 pBuffHead->nTickCount = 0; 8003 } 8004 } 8005 else { 8006 if (pBuffHead->nFilledLen != 0){ 8007 pBuffHead->nTimeStamp = (OMX_TICKS)pComponentPrivate->arrBufIndex[pComponentPrivate->nOutBufIndex]; 8008 pComponentPrivate->nOutBufIndex++; 8009 pComponentPrivate->nOutBufIndex %= VIDDEC_MAX_QUEUE_SIZE; 8010 } 8011 } 8012 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nTimeStamp %lld\n", pBuffHead->nTimeStamp); 8013 if(pBuffHead != NULL){ 8014 /*if (pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL) { 8015 pBuffHead->nFilledLen = (OMX_S32)argsCb[2]; 8016 } 8017 else {*/ 8018 pBuffHead->nFilledLen = (OMX_S32)argsCb[8]; 8019 /*}*/ 8020 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFilledLen %lu\n", pBuffHead->nFilledLen); 8021 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate; 8022 pComponentPrivate->nOutputBCountDsp++; 8023 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT; 8024 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 8025#ifdef __PERF_INSTRUMENTATION__ 8026 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp, 8027 pBuffHead->pBuffer, 8028 pBuffHead->nFilledLen, 8029 PERF_ModuleCommonLayer); 8030#endif 8031 8032 nRetVal = write(pComponentPrivate->filled_outBuf_Q[1],&pBuffHead,sizeof(pBuffHead)); 8033 if(nRetVal == -1){ 8034 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%lu)\n", OMX_ErrorInsufficientResources,nRetVal); 8035 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8036 pComponentPrivate->pHandle->pApplicationPrivate, 8037 OMX_EventError, 8038 OMX_ErrorInsufficientResources, 8039 OMX_TI_ErrorSevere, 8040 "Error writing to the output pipe"); 8041 } 8042 } 8043 } 8044 else { 8045 OMX_PRDSP1(pComponentPrivate->dbg, "buffer dropped lcml out process pBuffHead %p owner %d\n",pBuffHead,pBuffPriv->eBufferOwner); 8046 } 8047 } 8048 } 8049 } 8050 } 8051 if ((OMX_U32)argsCb [0] == EMMCodecInputBuffer || 8052 ((OMX_U32)argsCb [0] == EMMCodecInputBufferMapBufLen)) { 8053 OMX_BUFFERHEADERTYPE* pBuffHead = NULL; 8054 VIDDEC_BUFFER_PRIVATE* pBuffPriv = NULL; 8055 OMX_U8* pBuffer; 8056 if (pComponentPrivate->eState != OMX_StateLoaded && pComponentPrivate->eState != OMX_StateIdle) { 8057 pBuffHead = (OMX_BUFFERHEADERTYPE*)argsCb[7]; 8058 if(pBuffHead != NULL) 8059 { 8060 pBuffPriv = (VIDDEC_BUFFER_PRIVATE*)pBuffHead->pInputPortPrivate; 8061 if (pBuffPriv == NULL ) { 8062 goto EXIT; 8063 } 8064 else { 8065 if(pBuffPriv->eBufferOwner != VIDDEC_BUFFER_WITH_CLIENT) 8066 { 8067 OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead Input 0x%p pBuffer 0x%p\n", pBuffHead, argsCb[1]); 8068 pBuffer = (OMX_U8*)argsCb[1]; 8069 if(pBuffer != NULL){ 8070 pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate; 8071 pComponentPrivate->nInputBCountDsp++; 8072 pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT; 8073 OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner); 8074 #ifdef __PERF_INSTRUMENTATION__ 8075 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp, 8076 PREF(pBuffHead,pBuffer), 8077 PREF(pBuffHead,nFilledLen), 8078 PERF_ModuleCommonLayer); 8079 #endif 8080 pBuffHead->nFilledLen = 0; 8081 if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM && 8082 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV && 8083 pComponentPrivate->ProcessMode == 0) { 8084 /* vc-1 fix */ 8085#ifdef VIDDEC_WMVPOINTERFIXED 8086 OMX_PRBUFFER1(pComponentPrivate->dbg, "restoring buffer pointer 0x%p >> pBuffer 0x%p\n", 8087 pBufferPrivate->pTempBuffer, pBuffHead->pBuffer); 8088 pBuffHead->pBuffer = pBufferPrivate->pTempBuffer; 8089#else 8090 pBuffHead->nOffset = VIDDEC_WMV_BUFFER_OFFSET; 8091#endif 8092 } 8093 nRetVal = write(pComponentPrivate->free_inpBuf_Q[1], &pBuffHead, sizeof(pBuffHead)); 8094 if(nRetVal == -1){ 8095 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%lu)\n", OMX_ErrorInsufficientResources,nRetVal); 8096 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8097 pComponentPrivate->pHandle->pApplicationPrivate, 8098 OMX_EventError, 8099 OMX_ErrorInsufficientResources, 8100 OMX_TI_ErrorSevere, 8101 "Error writing to the output pipe"); 8102 } 8103 } 8104 } 8105 else { 8106 OMX_PRDSP1(pComponentPrivate->dbg, "buffer dropped lcml in notprocess pBuffHead %p owner %d\n",pBuffHead,pBuffPriv->eBufferOwner); 8107 } 8108 } 8109 } 8110 } 8111 } 8112 } 8113 /************************************************************************************************/ 8114 if (event == EMMCodecDspError) { 8115 OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecDspError\n"); 8116 if((argsCb[4] == (void *)NULL) && (argsCb[5] == (void*)NULL)) { 8117 OMX_PRDSP4(pComponentPrivate->dbg, "DSP MMU_Fault\n"); 8118 pComponentPrivate->bLCMLHalted = OMX_TRUE; 8119 pComponentPrivate->pHandle->SendCommand( pComponentPrivate->pHandle, OMX_CommandStateSet, -2, 0); 8120 } 8121 if((int)argsCb[5] == IUALG_ERR_NOT_SUPPORTED) 8122 { 8123 OMX_PRDSP4(pComponentPrivate->dbg, "Algorithm error. Parameter not supported\n"); 8124 OMX_PRDSP2(pComponentPrivate->dbg, "argsCb5 = %p\n",argsCb[5]); 8125 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_Callback: IUALG_ERR_NOT_SUPPORTED\n"); 8126 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8127 pComponentPrivate->pHandle->pApplicationPrivate, 8128 OMX_EventError, 8129 OMX_ErrorInsufficientResources, 8130 OMX_TI_ErrorCritical, 8131 "Error from the DSP"); 8132 goto EXIT; 8133 } 8134 if ((int)argsCb [0] == USN_DSPMSG_EVENT) { 8135 if ((int)argsCb [4] == USN_ERR_WARNING) { 8136 if ((int)argsCb [5] == IUALG_WARN_PLAYCOMPLETED) { 8137 OMX_PRDSP2(pComponentPrivate->dbg, "Received PLAYCOMPLETED\n"); 8138 } 8139 else { 8140 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8141 pComponentPrivate->pHandle->pApplicationPrivate, 8142 OMX_EventError, 8143 OMX_ErrorHardware, 8144 OMX_TI_ErrorCritical, 8145 "Error from the DSP"); 8146 } 8147 } 8148 else { 8149 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8150 pComponentPrivate->pHandle->pApplicationPrivate, 8151 OMX_EventError, 8152 OMX_ErrorHardware, 8153 OMX_TI_ErrorCritical, 8154 "Error from the DSP"); 8155 goto EXIT; 8156 } 8157 } 8158 else { 8159 pComponentPrivate->bLCMLHalted = OMX_TRUE; 8160 pComponentPrivate->pHandle->SendCommand( pComponentPrivate->pHandle, OMX_CommandStateSet, -2, 0); 8161 8162 } 8163 } 8164 if (event == EMMCodecInternalError || event == EMMCodecInitError) { 8165 OMX_PRDSP4(pComponentPrivate->dbg, "EMMCodecInternalError || EMMCodecInitError\n"); 8166 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8167 pComponentPrivate->pHandle->pApplicationPrivate, 8168 OMX_EventError, 8169 OMX_ErrorHardware, 8170 OMX_TI_ErrorCritical, 8171 "Error from the DSP"); 8172 } 8173 if (event == EMMCodecStrmCtrlAck) { 8174 if ((int)argsCb [0] == USN_ERR_NONE) { 8175 OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecStrmCtrlAck\n"); 8176 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 8177 VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex); 8178 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8179 } 8180 } 8181 8182EXIT: 8183 OMX_PRDSP0(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError); 8184 return eError; 8185} 8186 8187#ifdef RESOURCE_MANAGER_ENABLED 8188void VIDDEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData) 8189{ 8190 8191 /*OMX_COMMANDTYPE Cmd = OMX_CommandStateSet; 8192 OMX_U32 state ; 8193 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;*/ 8194 VIDDEC_COMPONENT_PRIVATE *pCompPrivate = NULL; 8195 pCompPrivate = NULL; 8196} 8197#endif 8198 8199#ifdef ANDROID 8200/* ========================================================================== */ 8201/** 8202 * VIDDEC_SaveBuffer() function will be use to copy a buffer at private space, to be used later by VIDDEC_CopyBuffer() 8203 * 8204 * @param 8205 * pComponentPrivate Component private structure 8206 * pBuffHead Header of the buffer to be store 8207 * 8208 * @retval OMX_ErrorNone Success, ready to roll 8209 * OMX_ErrorInsufficientResources Not enough memory to save first buffer 8210 **/ 8211/* ========================================================================== */ 8212 8213OMX_ERRORTYPE VIDDEC_SaveBuffer(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, 8214 OMX_BUFFERHEADERTYPE* pBuffHead) 8215{ 8216 OMX_ERRORTYPE eError = OMX_ErrorNone; 8217 OMX_PRINT1(pComponentPrivate->dbg, "IN\n"); 8218 pComponentPrivate->eFirstBuffer.bSaveFirstBuffer = OMX_TRUE; 8219 8220 OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->eFirstBuffer.pFirstBufferSaved, OMX_U8, pBuffHead->nFilledLen, NULL); 8221 memcpy(pComponentPrivate->eFirstBuffer.pFirstBufferSaved, pBuffHead->pBuffer, pBuffHead->nFilledLen); 8222 8223 pComponentPrivate->eFirstBuffer.nFilledLen = pBuffHead->nFilledLen; 8224 8225EXIT: 8226 OMX_PRINT1(pComponentPrivate->dbg, "OUT\n"); 8227 return eError; 8228} 8229 8230 8231 8232/* ========================================================================== */ 8233/** 8234 * VIDDEC_CopyBuffer() function will insert an the begining of pBuffer the buffer stored using VIDDEC_SaveBuffer() 8235 * and update nFilledLen of the buffer header 8236 * 8237 * @param 8238 * pComponentPrivate Component private structure 8239 * pBuffHead Header of the buffer to be store 8240 * 8241 * @retval OMX_ErrorNone Success, ready to roll 8242 * OMX_ErrorUndefined No buffer to be copy. 8243 * OMX_ErrorInsufficientResources Not enough memory to save buffer 8244 **/ 8245/* ========================================================================== */ 8246 8247OMX_ERRORTYPE VIDDEC_CopyBuffer(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, 8248 OMX_BUFFERHEADERTYPE* pBuffHead) 8249{ 8250 OMX_PRINT1(pComponentPrivate->dbg, "IN\n"); 8251 OMX_ERRORTYPE eError = OMX_ErrorNone; 8252 if (pComponentPrivate->eFirstBuffer.bSaveFirstBuffer == OMX_FALSE) { 8253 eError = OMX_ErrorUndefined; 8254 goto EXIT; 8255 } 8256 OMX_PRINT1(pComponentPrivate->dbg, "pBuffer=%p\n", pBuffHead->pBuffer); 8257 OMX_PTR pTemp = NULL; 8258 pComponentPrivate->eFirstBuffer.bSaveFirstBuffer = OMX_FALSE; 8259 8260 /* only if NAL-bitstream format in frame mode */ 8261 if (pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat > 0) { 8262 OMX_MALLOC_STRUCT_SIZED(pTemp, OMX_U8, pBuffHead->nFilledLen, NULL); 8263 memcpy(pTemp, pBuffHead->pBuffer, pBuffHead->nFilledLen); /*copy somewere actual buffer*/ 8264 memcpy(pBuffHead->pBuffer, pComponentPrivate->eFirstBuffer.pFirstBufferSaved, pComponentPrivate->eFirstBuffer.nFilledLen); /*copy first buffer to the beganing of pBuffer.*/ 8265 memcpy(pBuffHead->pBuffer+((OMX_U8)pComponentPrivate->eFirstBuffer.nFilledLen), (OMX_U8 *)pTemp, pBuffHead->nFilledLen); /* copy back actual buffer after first buffer*/ 8266 pBuffHead->nFilledLen += (OMX_U8)pComponentPrivate->eFirstBuffer.nFilledLen; /*Add first buffer size*/ 8267 8268 free(pTemp); 8269 free(pComponentPrivate->eFirstBuffer.pFirstBufferSaved); 8270 pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL; 8271 } 8272 else { 8273 if (pBuffHead->nFilledLen > pComponentPrivate->eFirstBuffer.nFilledLen) { 8274 OMX_MALLOC_STRUCT_SIZED(pTemp, OMX_U8, pBuffHead->nFilledLen, NULL); 8275 memcpy(pTemp, pBuffHead->pBuffer, pBuffHead->nFilledLen); /*copy somewere actual buffer*/ 8276 memcpy(pBuffHead->pBuffer, pComponentPrivate->eFirstBuffer.pFirstBufferSaved, pComponentPrivate->eFirstBuffer.nFilledLen); /*copy first buffer to the beganing of pBuffer.*/ 8277 memcpy(pBuffHead->pBuffer+((OMX_U8)pComponentPrivate->eFirstBuffer.nFilledLen), (OMX_U8 *)pTemp, pBuffHead->nFilledLen); /* copy back actual buffer after first buffer*/ 8278 pBuffHead->nFilledLen += (OMX_U8)pComponentPrivate->eFirstBuffer.nFilledLen; /*Add first buffer size*/ 8279 8280 free(pTemp); 8281 free(pComponentPrivate->eFirstBuffer.pFirstBufferSaved); 8282 pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL; 8283 } 8284 /*The first buffer has more information than the second, so the first buffer will be send to codec*/ 8285 /*We are loosing the second fame. TODO: Fix this*/ 8286 else { 8287 /*copy first buffer data to the actual buffer*/ 8288 memcpy(pBuffHead->pBuffer, pComponentPrivate->eFirstBuffer.pFirstBufferSaved, pComponentPrivate->eFirstBuffer.nFilledLen); /*copy first buffer*/ 8289 pBuffHead->nFilledLen = pComponentPrivate->eFirstBuffer.nFilledLen; /*Update buffer size*/ 8290 free(pComponentPrivate->eFirstBuffer.pFirstBufferSaved); 8291 pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL; 8292 } 8293 } 8294 8295EXIT: 8296 OMX_PRINT1(pComponentPrivate->dbg, "OUT\n"); 8297 return eError; 8298} 8299#endif 8300 8301 8302/* ========================================================================== */ 8303/** 8304 * VIDDEC_LoadCodec() function will get LCML resource and start the codec. 8305 * 8306 * @param 8307 * pComponentPrivate Component private structure 8308 * 8309 * @retval OMX_ErrorNone Success, ready to roll 8310 * OMX_ErrorUndefined 8311 * OMX_ErrorInsufficientResources Not enough memory 8312 **/ 8313/* ========================================================================== */ 8314 8315OMX_ERRORTYPE VIDDEC_LoadCodec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 8316{ 8317 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 8318 OMX_U32 message[4]; 8319 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 8320 OMX_HANDLETYPE hLCML = NULL; 8321 void* p = NULL; 8322#ifdef UNDER_CE 8323 typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE); 8324 HINSTANCE hDLL; 8325 LPFNDLLFUNC1 fpGetHandle1; 8326#else 8327 VIDDEC_fpo fpGetHandle; 8328 char* error; 8329#endif 8330 8331#ifndef UNDER_CE 8332 pComponentPrivate->pModLCML = dlopen("libLCML.so", RTLD_LAZY); 8333 if (!pComponentPrivate->pModLCML) { 8334 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 8335 fputs(dlerror(), stderr); 8336 eError = OMX_ErrorBadParameter; 8337 goto EXIT; 8338 } 8339 fpGetHandle = dlsym(pComponentPrivate->pModLCML, "GetHandle"); 8340 if ((error = dlerror()) != NULL) { 8341 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 8342 fputs(error, stderr); 8343 dlclose(pComponentPrivate->pModLCML); 8344 pComponentPrivate->pModLCML = NULL; 8345 eError = OMX_ErrorBadParameter; 8346 goto EXIT; 8347 } 8348 eError = (*fpGetHandle)(&hLCML); 8349 if (eError != OMX_ErrorNone) { 8350 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n"); 8351 dlclose(pComponentPrivate->pModLCML); 8352 pComponentPrivate->pModLCML = NULL; 8353 eError = OMX_ErrorBadParameter; 8354 goto EXIT; 8355 } 8356 8357#endif 8358 8359 pComponentPrivate->eLCMLState = VidDec_LCML_State_Load; 8360 OMX_PRDSP2(pComponentPrivate->dbg, "LCML Handler 0x%p\n",hLCML); 8361 /*(LCML_DSP_INTERFACE*)pComponentPrivate->pLCML = (LCML_DSP_INTERFACE*)hLCML;*/ 8362 pComponentPrivate->pLCML = (LCML_DSP_INTERFACE*)hLCML; 8363 pComponentPrivate->pLCML->pComponentPrivate = pComponentPrivate; 8364 8365 8366#ifdef __PERF_INSTRUMENTATION__ 8367 pComponentPrivate->lcml_nCntOpReceived = 0; 8368#endif 8369 eError = OMX_ErrorNone; 8370#ifndef UNDER_CE 8371 pComponentPrivate->bLCMLOut = OMX_TRUE; 8372#endif 8373 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 8374 eError = VIDDEC_InitDSP_H264Dec(pComponentPrivate); 8375 } 8376 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 8377 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) { 8378 eError = VIDDEC_InitDSP_Mpeg4Dec(pComponentPrivate); 8379 } 8380 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) { 8381 eError = VIDDEC_InitDSP_Mpeg2Dec(pComponentPrivate); 8382 } 8383 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) { 8384 eError = VIDDEC_InitDSP_WMVDec(pComponentPrivate); 8385 } 8386#ifdef VIDDEC_SPARK_CODE 8387 else if (VIDDEC_SPARKCHECK) { 8388 eError = VIDDEC_InitDSP_SparkDec(pComponentPrivate); 8389 } 8390#endif 8391 else { 8392 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedSetting\n"); 8393 eError = OMX_ErrorUnsupportedSetting; 8394 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8395 pComponentPrivate->pHandle->pApplicationPrivate, 8396 OMX_EventError, 8397 OMX_ErrorUnsupportedSetting, 8398 OMX_TI_ErrorMinor, 8399 "DSP Initialization"); 8400 goto EXIT; 8401 } 8402 #ifndef UNDER_CE 8403 pComponentPrivate->bLCMLOut = OMX_FALSE; 8404#endif 8405 pComponentPrivate->bLCMLHalted = OMX_FALSE; 8406 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 8407 pComponentPrivate->eLCMLState = VidDec_LCML_State_Init; 8408 8409 OMX_PRDSP2(pComponentPrivate->dbg, "OUTPUT width=%lu height=%lu\n", pComponentPrivate->pOutPortDef->format.video.nFrameWidth, pComponentPrivate->pOutPortDef->format.video.nFrameHeight); 8410 OMX_PRDSP2(pComponentPrivate->dbg, "INPUT width=%lu height=%lu\n", pComponentPrivate->pInPortDef->format.video.nFrameWidth, pComponentPrivate->pInPortDef->format.video.nFrameHeight); 8411 8412 /*Enable EOS propagation at USN*/ 8413 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 8414 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 8415 pComponentPrivate->pLCML != NULL && 8416 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 8417 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlUsnEos 0x%p\n",pLcmlHandle); 8418 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlUsnEos, NULL); 8419 if (eError != OMX_ErrorNone) { 8420 OMX_PRDSP4(pComponentPrivate->dbg, "error in EMMCodecControlUsnEos %x\n",eError); 8421 eError = OMX_ErrorHardware; 8422 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8423 pComponentPrivate->pHandle->pApplicationPrivate, 8424 OMX_EventError, 8425 OMX_ErrorHardware, 8426 OMX_TI_ErrorSevere, 8427 "LCML_ControlCodec EMMCodecControlUsnEos function"); 8428 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorHardware 0x%x\n",eError); 8429 goto EXIT; 8430 } 8431 } 8432 8433 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat != OMX_VIDEO_CodingWMV) { 8434 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) { 8435 message[1] = 4; 8436 } 8437 else { 8438 message[1] = 100; 8439 } 8440 message[0] = 0x400; 8441 message[2] = 0; 8442 p = (void*)&message; 8443 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 8444 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlSendDspMessage 0x%p\n",pLcmlHandle); 8445 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlSendDspMessage, (void *)p); 8446 if (eError != OMX_ErrorNone) { 8447 OMX_PRDSP4(pComponentPrivate->dbg, "error in EMMCodecControlSendDspMessage %x\n",eError); 8448 eError = OMX_ErrorHardware; 8449 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8450 pComponentPrivate->pHandle->pApplicationPrivate, 8451 OMX_EventError, 8452 OMX_ErrorHardware, 8453 OMX_TI_ErrorSevere, 8454 "LCML_ControlCodec function"); 8455 OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorHardware 0x%x\n",eError); 8456 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8457 goto EXIT; 8458 } 8459 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 8460 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8461 } 8462 8463 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 8464 pComponentPrivate->bIsPaused = 0; 8465 pComponentPrivate->bFirstBuffer = 1; 8466 8467 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlStart 0x%p\n",pLcmlHandle); 8468 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStart,NULL); 8469 if (eError != OMX_ErrorNone) { 8470 eError = OMX_ErrorHardware; 8471 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8472 pComponentPrivate->pHandle->pApplicationPrivate, 8473 OMX_EventError, 8474 OMX_ErrorHardware, 8475 OMX_TI_ErrorSevere, 8476 "LCML_ControlCodec Start"); 8477 goto EXIT; 8478 OMX_PRDSP4(pComponentPrivate->dbg, "Occurred in Codec Start... 0x%x\n",eError); 8479 } 8480 pComponentPrivate->eLCMLState = VidDec_LCML_State_Start; 8481 8482 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC && 8483 pComponentPrivate->eState == OMX_StateIdle) { 8484 H264_Iualg_Cmd_SetStatus* pDynParams = NULL; 8485 char* pTmp = NULL; 8486 OMX_U32 cmdValues[3] = {0, 0, 0}; 8487 8488 OMX_PRDSP2(pComponentPrivate->dbg, "Initializing DSP for h264 eCompressionFormat 0x%x\n", 8489 pComponentPrivate->pInPortDef->format.video.eCompressionFormat); 8490 OMX_MALLOC_STRUCT_SIZED(pDynParams, H264_Iualg_Cmd_SetStatus, sizeof(H264_Iualg_Cmd_SetStatus) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 8491 if (pDynParams == NULL) { 8492 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n"); 8493 eError = OMX_ErrorInsufficientResources; 8494 goto EXIT; 8495 } 8496 memset(pDynParams, 0, sizeof(H264_Iualg_Cmd_SetStatus) + VIDDEC_PADDING_FULL); 8497 pTmp = (char*)pDynParams; 8498 pTmp += VIDDEC_PADDING_HALF; 8499 pDynParams = (H264_Iualg_Cmd_SetStatus*)pTmp; 8500#ifdef VIDDEC_SN_R8_14 8501 pDynParams->size = sizeof(H264_Iualg_Cmd_SetStatus); 8502#endif 8503 pDynParams->ulDecodeHeader = 1; 8504 pDynParams->ulDisplayWidth = 0; 8505 pDynParams->ulFrameSkipMode = 0; 8506 pDynParams->ulPPType = 0; 8507 8508 cmdValues[0] = IUALG_CMD_SETSTATUS; 8509 cmdValues[1] = (OMX_U32)(pDynParams); 8510 cmdValues[2] = sizeof(H264_Iualg_Cmd_SetStatus); 8511 8512 p = (void*)&cmdValues; 8513 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 8514 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 8515 pComponentPrivate->pLCML != NULL && 8516 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 8517 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 8518 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 8519 EMMCodecControlAlgCtrl, 8520 (void*)p); 8521 if (eError != OMX_ErrorNone) { 8522 eError = OMX_ErrorHardware; 8523 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8524 goto EXIT; 8525 } 8526 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 8527 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8528 } 8529 pTmp = (char*)pDynParams; 8530 pTmp -= VIDDEC_PADDING_HALF; 8531 pDynParams = (H264_Iualg_Cmd_SetStatus*)pTmp; 8532 free(pDynParams); 8533 8534 if (eError != OMX_ErrorNone) { 8535 OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError); 8536 goto EXIT; 8537 } 8538 } 8539 else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2 && 8540 pComponentPrivate->eState == OMX_StateIdle) { 8541 MP2VDEC_UALGDynamicParams* pDynParams = NULL; 8542 char* pTmp = NULL; 8543 OMX_U32 cmdValues[3] = {0, 0, 0}; 8544 8545 OMX_PRDSP2(pComponentPrivate->dbg, "Initializing DSP for wmv9 eCompressionFormat 0x%x\n", 8546 pComponentPrivate->pInPortDef->format.video.eCompressionFormat); 8547 OMX_MALLOC_STRUCT_SIZED(pDynParams, MP2VDEC_UALGDynamicParams, sizeof(MP2VDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 8548 memset(pDynParams, 0, sizeof(MP2VDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL); 8549 pTmp = (char*)pDynParams; 8550 pTmp += VIDDEC_PADDING_HALF; 8551 pDynParams = (MP2VDEC_UALGDynamicParams*)pTmp; 8552 8553#ifdef VIDDEC_SN_R8_14 8554 pDynParams->size = sizeof(MP2VDEC_UALGDynamicParams); 8555#endif 8556 if (pComponentPrivate->nDisplayWidth > 0) { 8557 if (pComponentPrivate->pInPortDef->format.video.nFrameWidth > pComponentPrivate->nDisplayWidth) { 8558 pComponentPrivate->nDisplayWidth = pComponentPrivate->pInPortDef->format.video.nFrameWidth; 8559 } 8560 pDynParams->ulDisplayWidth = (((pComponentPrivate->nDisplayWidth + 15) >> 4) << 4); 8561 if (pComponentPrivate->nDisplayWidth != pDynParams->ulDisplayWidth ) { 8562 pComponentPrivate->nDisplayWidth = pDynParams->ulDisplayWidth; 8563 OMX_PRDSP2(pComponentPrivate->dbg, "warning Display Width adjusted to %lu\n",pDynParams->ulDisplayWidth); 8564 } 8565 } 8566 else if (pComponentPrivate->pCompPort[1]->hTunnelComponent != NULL){ 8567 if (pComponentPrivate->pInPortDef->format.video.nFrameWidth > pComponentPrivate->nDisplayWidth) { 8568 pComponentPrivate->nDisplayWidth = pComponentPrivate->pInPortDef->format.video.nFrameWidth; 8569 } 8570 pDynParams->ulDisplayWidth = (((pComponentPrivate->nDisplayWidth + 15) >> 4) << 4); 8571 if (pComponentPrivate->nDisplayWidth != pDynParams->ulDisplayWidth ) { 8572 pComponentPrivate->nDisplayWidth = pDynParams->ulDisplayWidth; 8573 OMX_PRDSP2(pComponentPrivate->dbg, "warning Display Width adjusted to %lu\n",pDynParams->ulDisplayWidth); 8574 } 8575 } 8576 else { 8577 pDynParams->ulDisplayWidth = 0; 8578 } 8579 pDynParams->ulDecodeHeader = 0; 8580 pDynParams->ulFrameSkipMode = 0; 8581 pDynParams->ulPPType = 0; 8582 pDynParams->ulPpNone = 0; 8583 if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT422) { 8584 pDynParams->ulDyna_chroma_format = MP2VIDDEC_YUVFORMAT_INTERLEAVED422; 8585 } 8586 else { 8587 pDynParams->ulDyna_chroma_format = MP2VIDDEC_YUVFORMAT_PLANAR420; 8588 } 8589 8590 cmdValues[0] = IUALG_CMD_SETSTATUS; 8591 cmdValues[1] = (OMX_U32)(pDynParams); 8592 cmdValues[2] = sizeof(MP2VDEC_UALGDynamicParams); 8593 8594 pComponentPrivate->bTransPause = 0; 8595 p = (void*)&cmdValues; 8596 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 8597 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 8598 pComponentPrivate->pLCML != NULL && 8599 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 8600 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 8601 EMMCodecControlAlgCtrl, 8602 (void*)p); 8603 if(eError != OMX_ErrorNone){ 8604 eError = OMX_ErrorHardware; 8605 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8606 pComponentPrivate->pHandle->pApplicationPrivate, 8607 OMX_EventError, 8608 eError, 8609 0x0, 8610 "LCML_ControlCodec function"); 8611 goto EXIT; 8612 } 8613 while(1) { 8614 if(pComponentPrivate->bTransPause != 0) { 8615 pComponentPrivate->bTransPause = 0; 8616 break; 8617 } 8618 VIDDEC_WAIT_CODE(); 8619 } 8620 } 8621 8622 pTmp = (char*)pDynParams; 8623 pTmp -= VIDDEC_PADDING_HALF; 8624 pDynParams = (MP2VDEC_UALGDynamicParams*)pTmp; 8625 free(pDynParams); 8626 8627 if (eError != OMX_ErrorNone) { 8628 OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError); 8629 goto EXIT; 8630 } 8631 } 8632#ifdef VIDDEC_SPARK_CODE 8633 else if (VIDDEC_SPARKCHECK) { 8634 if(pComponentPrivate->eState == OMX_StateIdle) { 8635 SPARKVDEC_UALGDynamicParams* pDynParams = NULL; 8636 char* pTmp = NULL; 8637 OMX_U32 cmdValues[3] = {0, 0, 0}; 8638 8639 OMX_PRDSP2(pComponentPrivate->dbg, "Initializing DSP for mpeg4 and h263 eCompressionFormat 0x%x\n", 8640 pComponentPrivate->pInPortDef->format.video.eCompressionFormat); 8641 OMX_MALLOC_STRUCT_SIZED(pDynParams, SPARKVDEC_UALGDynamicParams, sizeof(SPARKVDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 8642 if (pDynParams == NULL) { 8643 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n"); 8644 eError = OMX_ErrorInsufficientResources; 8645 goto EXIT; 8646 } 8647 memset(pDynParams, 0, sizeof(SPARKVDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL); 8648 pTmp = (char*)pDynParams; 8649 pTmp += VIDDEC_PADDING_HALF; 8650 pDynParams = (SPARKVDEC_UALGDynamicParams*)pTmp; 8651#ifdef VIDDEC_SN_R8_14 8652 pDynParams->size = sizeof(SPARKVDEC_UALGDynamicParams); 8653#endif 8654 pDynParams->ulDecodeHeader = 0; 8655 pDynParams->ulDisplayWidth = 0; 8656 pDynParams->ulFrameSkipMode = 0; 8657 pDynParams->ulPPType = 0; 8658 8659 cmdValues[0] = IUALG_CMD_SETSTATUS; 8660 cmdValues[1] = (OMX_U32)(pDynParams); 8661 cmdValues[2] = sizeof(SPARKVDEC_UALGDynamicParams); 8662 8663 /*pComponentPrivate->bTransPause = 0;*//*flag to wait for the generated event*/ 8664 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 8665 p = (void*)&cmdValues; 8666 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 8667 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 8668 pComponentPrivate->pLCML != NULL && 8669 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 8670 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 8671 EMMCodecControlAlgCtrl, 8672 (void*)p); 8673 if (eError != OMX_ErrorNone) { 8674 eError = OMX_ErrorHardware; 8675 goto EXIT; 8676 } 8677 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 8678 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8679 } 8680 8681 pTmp = (char*)pDynParams; 8682 pTmp -= VIDDEC_PADDING_HALF; 8683 pDynParams = (SPARKVDEC_UALGDynamicParams*)pTmp; 8684 free(pDynParams); 8685 8686 if (eError != OMX_ErrorNone) { 8687 OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError); 8688 goto EXIT; 8689 } 8690 } 8691 } 8692#endif 8693 else { 8694 if(pComponentPrivate->eState == OMX_StateIdle) { 8695 eError = VIDDEC_Set_Debocking(pComponentPrivate); 8696 if (eError != OMX_ErrorNone){ 8697 goto EXIT; 8698 } 8699 } 8700 } 8701 8702 eError = OMX_ErrorNone; 8703 8704EXIT: 8705 return eError; 8706} 8707 8708 8709 8710/* ========================================================================== */ 8711/** 8712 * VIDDEC_UnloadCodec() function will stop & destroy the codec. LCML resource is also been freed. 8713 * 8714 * @param 8715 * pComponentPrivate Component private structure 8716 * 8717 * @retval OMX_NoError Success, ready to roll 8718 * OMX_ErrorUndefined 8719 * OMX_ErrorInsufficientResources Not enough memory 8720 **/ 8721/* ========================================================================== */ 8722 8723OMX_ERRORTYPE VIDDEC_UnloadCodec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 8724{ 8725 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 8726 LCML_DSP_INTERFACE *pLcmlHandle = NULL; 8727 OMX_PRDSP1(pComponentPrivate->dbg, "+++ENTERING\n"); 8728 if (!(pComponentPrivate->eState == OMX_StateLoaded) && 8729 !(pComponentPrivate->eState == OMX_StateWaitForResources)) { 8730 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 8731 if (pComponentPrivate->eState == OMX_StateExecuting) { 8732 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 8733 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 8734 pComponentPrivate->pLCML != NULL && 8735 pComponentPrivate->bLCMLHalted != OMX_TRUE) { 8736 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 8737 OMX_PRDSP1(pComponentPrivate->dbg, "LCML_ControlCodec called MMCodecControlStop 0x%x\n",eError); 8738 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, MMCodecControlStop, NULL); 8739 if (eError != OMX_ErrorNone) { 8740 OMX_PRDSP4(pComponentPrivate->dbg, "Occurred in Codec Stop...\n"); 8741 eError = OMX_ErrorHardware; 8742 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8743 pComponentPrivate->pHandle->pApplicationPrivate, 8744 OMX_EventError, 8745 eError, 8746 OMX_TI_ErrorCritical, 8747 NULL); 8748 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8749 goto EXIT; 8750 } 8751 8752 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 8753 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8754 } 8755 pComponentPrivate->eLCMLState = VidDec_LCML_State_Stop; 8756 } 8757 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 8758 pComponentPrivate->pLCML != NULL){ 8759 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlDestroy, NULL); 8760 8761 OMX_PRDSP2(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlDestroy 0x%p\n",pLcmlHandle); 8762 if (eError != OMX_ErrorNone) { 8763 OMX_PRDSP4(pComponentPrivate->dbg, "Occurred in Codec Destroy...\n"); 8764 eError = OMX_ErrorHardware; 8765 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8766 pComponentPrivate->pHandle->pApplicationPrivate, 8767 OMX_EventError, 8768 eError, 8769 OMX_TI_ErrorCritical, 8770 NULL); 8771 OMX_ERROR4(pComponentPrivate->dbg, "Incorrect State Transition 0x%x\n", eError); 8772 goto EXIT; 8773 } 8774 } 8775 pComponentPrivate->eLCMLState = VidDec_LCML_State_Destroy; 8776 OMX_PRDSP1(pComponentPrivate->dbg, "LCML_ControlCodec called EMMCodecControlDestroy 0x%p\n",pLcmlHandle); 8777 8778#ifndef UNDER_CE 8779 if(pComponentPrivate->pModLCML != NULL){ 8780 dlclose(pComponentPrivate->pModLCML); 8781 pComponentPrivate->pModLCML = NULL; 8782 pComponentPrivate->pLCML = NULL; 8783 pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload; 8784 } 8785#else 8786 if(pComponentPrivate->pModLCML != NULL){ 8787 FreeLibrary(pComponentPrivate->pModLCML); 8788 pComponentPrivate->pModLCML = NULL; 8789 pComponentPrivate->pLCML = NULL; 8790 pComponentPrivate->eLCMLState = VidDec_LCML_State_Unload; 8791 } 8792#endif 8793 8794 pComponentPrivate->bLCMLHalted = OMX_TRUE; 8795 } 8796 eError = OMX_ErrorNone; 8797EXIT: 8798 return eError; 8799} 8800 8801 8802 8803/* ========================================================================== */ 8804/** 8805 * VIDDEC_Set_SN_StreamType() Set stream type using dynamic parameters at the SN. 8806 * 8807 * @param 8808 * pComponentPrivate Component private structure 8809 * 8810 * @retval OMX_NoError Success, ready to roll 8811 * OMX_ErrorUndefined 8812 * OMX_ErrorInsufficientResources Not enough memory 8813 **/ 8814/* ========================================================================== */ 8815 8816OMX_ERRORTYPE VIDDEC_Set_SN_StreamType(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 8817{ 8818 8819 WMV9DEC_UALGDynamicParams* pDynParams = NULL; 8820 LCML_DSP_INTERFACE* pLcmlHandle; 8821 char* pTmp = NULL; 8822 OMX_U32 cmdValues[3] = {0, 0, 0}; 8823 void* p = NULL; 8824 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 8825 8826 OMX_PRDSP1(pComponentPrivate->dbg, "Initializing DSP for wmv9 eCompressionFormat 0x%x\n", 8827 pComponentPrivate->pInPortDef->format.video.eCompressionFormat); 8828 8829 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 8830 OMX_MALLOC_STRUCT_SIZED(pDynParams, WMV9DEC_UALGDynamicParams, sizeof(WMV9DEC_UALGDynamicParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 8831 if (pDynParams == NULL) { 8832 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n"); 8833 eError = OMX_ErrorInsufficientResources; 8834 goto EXIT; 8835 } 8836 memset(pDynParams, 0, sizeof(WMV9DEC_UALGDynamicParams) + VIDDEC_PADDING_FULL); 8837 pTmp = (char*)pDynParams; 8838 pTmp += VIDDEC_PADDING_HALF; 8839 pDynParams = (WMV9DEC_UALGDynamicParams*)pTmp; 8840 8841 pDynParams->size = sizeof(WMV9DEC_UALGDynamicParams); 8842 pDynParams->ulDecodeHeader = 0; 8843 pDynParams->ulDisplayWidth = 0; 8844 pDynParams->ulFrameSkipMode = 0; 8845 pDynParams->ulPPType = 0; 8846 8847 if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM) { 8848 pDynParams->usIsElementaryStream = VIDDEC_SN_WMV_ELEMSTREAM; 8849 } 8850 else { 8851 pDynParams->usIsElementaryStream = VIDDEC_SN_WMV_RCVSTREAM; 8852 } 8853 8854 cmdValues[0] = IUALG_CMD_SETSTATUS; /* add #define IUALG_CMD_SETSTATUS 3 */ 8855 cmdValues[1] = (OMX_U32)(pDynParams); 8856 cmdValues[2] = sizeof(WMV9DEC_UALGDynamicParams); 8857 8858 p = (void*)&cmdValues; 8859 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 8860 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 8861 pComponentPrivate->pLCML != NULL && 8862 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 8863 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 8864 OMX_PRDSP1(pComponentPrivate->dbg, "Sending Control coded command EMMCodecControlAlgCtrl\n"); 8865 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 8866 EMMCodecControlAlgCtrl, 8867 (void*)p); 8868 if(eError != OMX_ErrorNone){ 8869 eError = OMX_ErrorHardware; 8870 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 8871 pComponentPrivate->pHandle->pApplicationPrivate, 8872 OMX_EventError, 8873 eError, 8874 OMX_TI_ErrorSevere, 8875 "LCML_ControlCodec function"); 8876 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8877 goto EXIT; 8878 } 8879 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 8880 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8881 /*This flag is set to TRUE in the LCML callback from EMMCodecControlAlgCtrl 8882 * this is not the case were we need it*/ 8883 pComponentPrivate->bTransPause = OMX_FALSE; 8884 } 8885 8886 pTmp = (char*)pDynParams; 8887 pTmp -= VIDDEC_PADDING_HALF; 8888 pDynParams = (WMV9DEC_UALGDynamicParams*)pTmp; 8889 free(pDynParams); 8890 8891 if (eError != OMX_ErrorNone) { 8892 OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError); 8893 } 8894 8895EXIT: 8896 return eError; 8897} 8898 8899 8900 8901/* ========================================================================== */ 8902/** 8903 * VIDDEC_Set_Debocking() Enable Deblocking filter 8904 * 8905 * @param 8906 * pComponentPrivate Component private structure 8907 * 8908 * @retval OMX_NoError Success, ready to roll 8909 * OMX_ErrorUndefined 8910 * OMX_ErrorInsufficientResources Not enough memory 8911 **/ 8912/* ========================================================================== */ 8913 8914OMX_ERRORTYPE VIDDEC_Set_Debocking(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) 8915{ 8916 MP4VDEC_UALGDynamicParams* pDynParams = NULL; 8917 LCML_DSP_INTERFACE* pLcmlHandle = NULL; 8918 char* pTmp = NULL; 8919 OMX_U32 cmdValues[3] = {0, 0, 0}; 8920 void* p = NULL; 8921 char value[PROPERTY_VALUE_MAX]; 8922 static int mDisableDeblockingIfD1 = 0; 8923 OMX_BOOL bDisDeblocking = OMX_FALSE; 8924 OMX_ERRORTYPE eError = OMX_ErrorUndefined; 8925 8926 property_get("deblocking.video.disableIfD1", value, "0"); 8927 mDisableDeblockingIfD1 = atoi(value); 8928 LOGD_IF(mDisableDeblockingIfD1, "Disabling deblocking if D1 resolution"); 8929 8930 OMX_PRDSP2(pComponentPrivate->dbg,"Initializing DSP for mpeg4 and h263 eCompressionFormat 0x%x\n", 8931 pComponentPrivate->pInPortDef->format.video.eCompressionFormat); 8932 pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 8933 OMX_MALLOC_STRUCT_SIZED(pDynParams, MP4VDEC_UALGDynamicParams, sizeof(MP4VDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]); 8934 if (pDynParams == NULL) { 8935 OMX_TRACE4(pComponentPrivate->dbg, "Error: Malloc failed\n"); 8936 eError = OMX_ErrorInsufficientResources; 8937 goto EXIT; 8938 } 8939 memset(pDynParams, 0, sizeof(MP4VDEC_UALGDynamicParams) + VIDDEC_PADDING_FULL); 8940 pTmp = (char*)pDynParams; 8941 pTmp += VIDDEC_PADDING_HALF; 8942 pDynParams = (MP4VDEC_UALGDynamicParams*)pTmp; 8943#ifdef VIDDEC_SN_R8_14 8944 pDynParams->size = sizeof(MP4VDEC_UALGDynamicParams); 8945#endif 8946 pDynParams->ulDecodeHeader = 0; 8947 pDynParams->ulDisplayWidth = 0; 8948 pDynParams->ulFrameSkipMode = 0; 8949 8950 8951 if(mDisableDeblockingIfD1){ 8952 /* Disable if resolution higher than D1 NTSC (720x480) */ 8953 if(pComponentPrivate->pOutPortDef->format.video.nFrameWidth > 480 || 8954 pComponentPrivate->pOutPortDef->format.video.nFrameHeight > 480){ 8955 bDisDeblocking = OMX_TRUE; 8956 LOGD("D1 or higher resolution: Disable Deblocking!!"); 8957 } 8958 } 8959 8960 if(pComponentPrivate->pDeblockingParamType->bDeblocking && bDisDeblocking == OMX_FALSE){ 8961 pDynParams->ulPPType = 1; /* Enable deblocking filter*/ 8962 } 8963 else{ 8964 pDynParams->ulPPType = 0; /* Disable */ 8965 } 8966 8967 cmdValues[0] = IUALG_CMD_SETSTATUS; 8968 cmdValues[1] = (OMX_U32)(pDynParams); 8969 cmdValues[2] = sizeof(MP4VDEC_UALGDynamicParams); 8970 8971 p = (void*)&cmdValues; 8972 if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload && 8973 pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy && 8974 pComponentPrivate->pLCML != NULL && 8975 pComponentPrivate->bLCMLHalted != OMX_TRUE){ 8976 8977 VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex); 8978 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 8979 EMMCodecControlAlgCtrl, 8980 (void*)p); 8981 if (eError != OMX_ErrorNone) { 8982 eError = OMX_ErrorHardware; 8983 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8984 goto EXIT; 8985 } 8986 VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex); 8987 VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex); 8988 /*This flag is set to TRUE in the LCML callback from EMMCodecControlAlgCtrl 8989 * this is not the case were we need it*/ 8990 pComponentPrivate->bTransPause = OMX_FALSE; 8991 } 8992 8993 pTmp = (char*)pDynParams; 8994 pTmp -= VIDDEC_PADDING_HALF; 8995 pDynParams = (MP4VDEC_UALGDynamicParams*)pTmp; 8996 free(pDynParams); 8997 8998 if (eError != OMX_ErrorNone) { 8999 OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError); 9000 goto EXIT; 9001 } 9002 9003EXIT: 9004 return eError; 9005} 9006 9007