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