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_G726Decoder.c
30 *
31 * This file implements OpenMAX (TM) 1.0 Specific APIs and its functionality
32 * that is fully compliant with the Khronos OpenMAX (TM) 1.0 Specification
33 *
34 * @path  $(CSLPATH)\OMAPSW_MPU\linux\audio\src\openmax_il\g726_dec\src
35 *
36 * @rev  1.0
37 */
38/* ----------------------------------------------------------------------------
39 *!
40 *! Revision History
41 *! ===================================
42 *! This is newest file
43 * =========================================================================== */
44/* ------compilation control switches -------------------------*/
45/****************************************************************
46 *  INCLUDE FILES
47 ****************************************************************/
48/* ----- system and platform files ----------------------------*/
49
50#ifdef UNDER_CE
51#include <windows.h>
52#include <oaf_osal.h>
53#include <omx_core.h>
54
55#else
56
57#include <unistd.h>
58#include <sys/time.h>
59#include <sys/types.h>
60#include <sys/ioctl.h>
61#include <sys/select.h>
62#include <errno.h>
63#endif
64
65#include <pthread.h>
66#include <string.h>
67#include <fcntl.h>
68#include <stdlib.h>
69#include <stdio.h>
70#include <dbapi.h>
71
72/*------- Program Header Files -----------------------------------------------*/
73
74#include "LCML_DspCodec.h"
75#include "OMX_G726Dec_Utils.h"
76#include <TIDspOmx.h>
77
78#ifdef DSP_RENDERING_ON
79#include <AudioManagerAPI.h>
80#endif
81
82#ifdef RESOURCE_MANAGER_ENABLED
83#include <ResourceManagerProxyAPI.h>
84#endif
85
86#ifdef DSP_RENDERING_ON
87
88#define FIFO1 "/dev/fifo.1"
89#define FIFO2 "/dev/fifo.2"
90#define PERMS 0666
91
92AM_COMMANDDATATYPE cmd_data;
93int G726d_fdwrite = 0, G726d_fdread = 0;
94int errno;
95#endif
96
97/****************************************************************
98 *  EXTERNAL REFERENCES NOTE : only use if not found in header file
99 ****************************************************************/
100/*--------data declarations -----------------------------------*/
101
102/*--------function prototypes ---------------------------------*/
103
104/****************************************************************
105 *  PUBLIC DECLARATIONS Defined here, used elsewhere
106 ****************************************************************/
107/*--------data declarations -----------------------------------*/
108
109/*--------function prototypes ---------------------------------*/
110
111/****************************************************************
112 *  PRIVATE DECLARATIONS Defined here, used only here
113 ****************************************************************/
114/*--------data declarations -----------------------------------*/
115
116/*--------function prototypes ---------------------------------*/
117
118static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp,
119                                   OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData);
120static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
121                                          OMX_STRING pComponentName,
122                                          OMX_VERSIONTYPE* pComponentVersion,
123                                          OMX_VERSIONTYPE* pSpecVersion,
124                                          OMX_UUIDTYPE* pComponentUUID);
125
126static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand,
127                                  OMX_U32 nParam, OMX_PTR pCmdData);
128
129static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex,
130                                  OMX_PTR ComponentParamStruct);
131static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
132                                   OMX_INDEXTYPE nParamIndex,
133                                   OMX_PTR ComponentParamStruct);
134static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
135                                OMX_INDEXTYPE nConfigIndex,
136                                OMX_PTR pComponentConfigStructure);
137static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
138                                OMX_INDEXTYPE nConfigIndex,
139                                OMX_PTR pComponentConfigStructure);
140
141static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
142
143static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
144static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
145static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
146                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
147                                             OMX_U32 nTunneledPort,
148                                             OMX_TUNNELSETUPTYPE* pTunnelSetup);
149
150static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle);
151
152static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
153                                     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
154                                     OMX_IN OMX_U32 nPortIndex,
155                                     OMX_IN OMX_PTR pAppPrivate,
156                                     OMX_IN OMX_U32 nSizeBytes);
157
158static OMX_ERRORTYPE FreeBuffer(
159                                OMX_IN  OMX_HANDLETYPE hComponent,
160                                OMX_IN  OMX_U32 nPortIndex,
161                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer);
162
163static OMX_ERRORTYPE UseBuffer (
164                                OMX_IN OMX_HANDLETYPE hComponent,
165                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
166                                OMX_IN OMX_U32 nPortIndex,
167                                OMX_IN OMX_PTR pAppPrivate,
168                                OMX_IN OMX_U32 nSizeBytes,
169                                OMX_IN OMX_U8* pBuffer);
170
171static OMX_ERRORTYPE GetExtensionIndex(
172                                       OMX_IN  OMX_HANDLETYPE hComponent,
173                                       OMX_IN  OMX_STRING cParameterName,
174                                       OMX_OUT OMX_INDEXTYPE* pIndexType);
175
176static OMX_ERRORTYPE ComponentRoleEnum(
177                                       OMX_IN OMX_HANDLETYPE hComponent,
178                                       OMX_OUT OMX_U8 *cRole,
179                                       OMX_IN OMX_U32 nIndex);
180
181/* ================================================================================= * */
182/**
183 * @fn OMX_ComponentInit() function is called by OMX Core to initialize the component
184 * with default values of the component. Before calling this function OMX_Init
185 * must have been called.
186 *
187 * @param *hComp This is component handle allocated by the OMX core.
188 *
189 * @pre          OMX_Init should be called by application.
190 *
191 * @post         Component has initialzed with default values.
192 *
193 *  @return      OMX_ErrorNone = Successful Inirialization of the component\n
194 *               OMX_ErrorInsufficientResources = Not enough memory
195 *
196 *  @see          G726Dec_StartCompThread()
197 */
198/* ================================================================================ * */
199OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
200{
201
202    OMX_ERRORTYPE eError = OMX_ErrorNone;
203    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
204    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL, *pPortDef_op = NULL;
205    OMX_AUDIO_PARAM_PORTFORMATTYPE *pPortFormat = NULL;
206    OMX_AUDIO_PARAM_PCMMODETYPE  *G726_op = NULL;
207    OMX_AUDIO_PARAM_G726TYPE *G726_ip = NULL;
208    G726DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
209    G726D_AUDIODEC_PORT_TYPE *pCompPort = NULL;
210    G726D_BUFFERLIST *pTemp = NULL;
211    int i=0;
212
213    G726DEC_DPRINT ("Entering OMX_ComponentInit\n");
214
215    G726D_OMX_CONF_CHECK_CMD(pHandle,1,1)
216
217        pHandle->SetCallbacks = SetCallbacks;
218    pHandle->GetComponentVersion = GetComponentVersion;
219    pHandle->SendCommand = SendCommand;
220    pHandle->GetParameter = GetParameter;
221    pHandle->SetParameter = SetParameter;
222    pHandle->GetConfig = GetConfig;
223    pHandle->SetConfig = SetConfig;
224    pHandle->GetState = GetState;
225    pHandle->EmptyThisBuffer = EmptyThisBuffer;
226    pHandle->FillThisBuffer = FillThisBuffer;
227    pHandle->ComponentTunnelRequest = ComponentTunnelRequest;
228    pHandle->ComponentDeInit = ComponentDeInit;
229    pHandle->AllocateBuffer =  AllocateBuffer;
230    pHandle->FreeBuffer = FreeBuffer;
231    pHandle->UseBuffer = UseBuffer;
232    pHandle->GetExtensionIndex = GetExtensionIndex;
233    pHandle->ComponentRoleEnum = ComponentRoleEnum;
234
235    G726D_OMX_MALLOC(pHandle->pComponentPrivate,G726DEC_COMPONENT_PRIVATE);
236
237    pComponentPrivate = pHandle->pComponentPrivate;
238    pComponentPrivate->pHandle = pHandle;
239
240    G726D_OMX_MALLOC(pCompPort, G726D_AUDIODEC_PORT_TYPE);
241    pComponentPrivate->pCompPort[G726D_INPUT_PORT] =  pCompPort;
242
243    G726D_OMX_MALLOC(pCompPort, G726D_AUDIODEC_PORT_TYPE);
244    pComponentPrivate->pCompPort[G726D_OUTPUT_PORT] = pCompPort;
245    G726D_OMX_MALLOC(pTemp, G726D_BUFFERLIST);
246    pComponentPrivate->pInputBufferList = pTemp;
247
248    G726D_OMX_MALLOC(pTemp, G726D_BUFFERLIST);
249    pComponentPrivate->pOutputBufferList = pTemp;
250
251    pComponentPrivate->pInputBufferList->numBuffers = 0;
252    pComponentPrivate->pOutputBufferList->numBuffers = 0;
253
254    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
255        pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL;
256        pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL;
257        pComponentPrivate->arrTickCount[i] = 0;
258        pComponentPrivate->arrTimestamp[i] = 0;
259    }
260
261    pComponentPrivate->bufAlloced = 0;
262
263    G726D_OMX_MALLOC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
264    OMX_CONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
265    G726D_OMX_MALLOC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
266    OMX_CONF_INIT_STRUCT(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
267    pComponentPrivate->sPortParam->nPorts = 0x2;
268    pComponentPrivate->sPortParam->nStartPortNumber = 0x0;
269    pComponentPrivate->G726Params = NULL;
270    pComponentPrivate->PcmParams = NULL;
271
272    G726D_OMX_MALLOC(G726_ip, OMX_AUDIO_PARAM_G726TYPE);
273    G726D_OMX_MALLOC(G726_op, OMX_AUDIO_PARAM_PCMMODETYPE);
274
275    pComponentPrivate->G726Params = G726_ip;
276    pComponentPrivate->PcmParams = G726_op;
277    pComponentPrivate->bIsEOFSent = 0;
278    pComponentPrivate->dasfmode = 0;
279    pComponentPrivate->packingType = 0;
280    pComponentPrivate->bCompThreadStarted = 0;
281    pComponentPrivate->bExitCompThrd = 0;
282
283    pComponentPrivate->bInitParamsInitialized = 0;
284    pComponentPrivate->pMarkBuf = NULL;
285    pComponentPrivate->pMarkData = NULL;
286    pComponentPrivate->nEmptyBufferDoneCount = 0;
287    pComponentPrivate->nEmptyThisBufferCount = 0;
288    pComponentPrivate->nFillBufferDoneCount = 0;
289    pComponentPrivate->nFillThisBufferCount = 0;
290    pComponentPrivate->strmAttr = NULL;
291    pComponentPrivate->bDisableCommandParam = 0;
292    pComponentPrivate->IpBufindex = 0;
293    pComponentPrivate->OpBufindex = 0;
294    pComponentPrivate->nUnhandledFillThisBuffers=0;
295    pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
296    pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
297    pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
298    pComponentPrivate->bPreempted = OMX_FALSE;
299
300    /* Initialize device string to the default value */
301    G726D_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString,(100*sizeof(OMX_STRING)),OMX_STRING);
302    strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
303
304
305#ifndef UNDER_CE
306    pthread_mutex_init(&pComponentPrivate->AlloBuf_mutex, NULL);
307    pthread_cond_init (&pComponentPrivate->AlloBuf_threshold, NULL);
308    pComponentPrivate->AlloBuf_waitingsignal = 0;
309
310    pthread_mutex_init(&pComponentPrivate->InLoaded_mutex, NULL);
311    pthread_cond_init (&pComponentPrivate->InLoaded_threshold, NULL);
312    pComponentPrivate->InLoaded_readytoidle = 0;
313
314    pthread_mutex_init(&pComponentPrivate->InIdle_mutex, NULL);
315    pthread_cond_init (&pComponentPrivate->InIdle_threshold, NULL);
316    pComponentPrivate->InIdle_goingtoloaded = 0;
317#else
318    OMX_CreateEvent(&(pComponentPrivate->AlloBuf_event));
319    pComponentPrivate->AlloBuf_waitingsignal = 0;
320
321    OMX_CreateEvent(&(pComponentPrivate->InLoaded_event));
322    pComponentPrivate->InLoaded_readytoidle = 0;
323
324    OMX_CreateEvent(&(pComponentPrivate->InIdle_event));
325    pComponentPrivate->InIdle_goingtoloaded = 0;
326#endif
327
328    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
329        pComponentPrivate->pInputBufHdrPending[i] = NULL;
330        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
331    }
332
333    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
334        pComponentPrivate->pOutBufHdrWhilePaused[i] = NULL;
335    }
336    pComponentPrivate->nPendingOutPausedBufs = 0;
337
338    pComponentPrivate->nInvalidFrameCount = 0;
339    pComponentPrivate->bDisableCommandPending = 0;
340
341    pComponentPrivate->numPendingBuffers = 0;
342    pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
343    pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
344    pComponentPrivate->bIdleCommandPending = OMX_FALSE;
345    pComponentPrivate->nOutStandingFillDones = 0;
346    G726D_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
347    G726D_OMX_MALLOC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
348
349    pComponentPrivate->pPortDef[G726D_INPUT_PORT] = pPortDef_ip;
350    pComponentPrivate->pPortDef[G726D_OUTPUT_PORT] = pPortDef_op;
351
352    /* Set input port defaults */
353    pPortDef_ip->nSize                                  = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
354    pPortDef_ip->nPortIndex                         = G726D_INPUT_PORT;
355    pPortDef_ip->eDir                               = OMX_DirInput;
356    pPortDef_ip->nBufferCountActual                 = G726D_NUM_INPUT_BUFFERS;
357    pPortDef_ip->nBufferCountMin                    = G726D_NUM_INPUT_BUFFERS;
358    pPortDef_ip->nBufferSize                        = G726D_INPUT_BUFFER_SIZE;
359    pPortDef_ip->bEnabled                           = OMX_TRUE;
360    pPortDef_ip->bPopulated                         = OMX_FALSE;
361    pPortDef_ip->eDomain                            = OMX_PortDomainAudio;
362    pPortDef_ip->format.audio.eEncoding             = OMX_AUDIO_CodingG726;
363    pPortDef_ip->format.audio.cMIMEType             = NULL;
364    pPortDef_ip->format.audio.pNativeRender         = NULL;
365    pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE;
366
367    /* Set input port defaults */
368    pPortDef_op->nSize                                  = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
369    pPortDef_op->nPortIndex                         = G726D_OUTPUT_PORT;
370    pPortDef_op->eDir                               = OMX_DirOutput;
371    pPortDef_op->nBufferCountMin                    = G726D_NUM_OUTPUT_BUFFERS;
372    pPortDef_op->nBufferCountActual                 = G726D_NUM_OUTPUT_BUFFERS;
373    pPortDef_op->nBufferSize                        = G726D_OUTPUT_BUFFER_SIZE;
374    pPortDef_op->bEnabled                           = OMX_TRUE;
375    pPortDef_op->bPopulated                         = OMX_FALSE;
376    pPortDef_op->eDomain                            = OMX_PortDomainAudio;
377    pPortDef_op->format.audio.eEncoding             = OMX_AUDIO_CodingPCM;
378    pPortDef_op->format.audio.cMIMEType             = NULL;
379    pPortDef_op->format.audio.pNativeRender         = NULL;
380    pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
381
382    G726D_OMX_MALLOC(pComponentPrivate->pCompPort[G726D_INPUT_PORT]->pPortFormat,
383                     OMX_AUDIO_PARAM_PORTFORMATTYPE);
384    G726D_OMX_MALLOC(pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]->pPortFormat,
385                     OMX_AUDIO_PARAM_PORTFORMATTYPE);
386    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[G726D_INPUT_PORT]->pPortFormat,
387                         OMX_AUDIO_PARAM_PORTFORMATTYPE);
388    OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]->pPortFormat,
389                         OMX_AUDIO_PARAM_PORTFORMATTYPE);
390
391
392    /* Set input port format defaults */
393    pPortFormat = pComponentPrivate->pCompPort[G726D_INPUT_PORT]->pPortFormat;
394    OMX_CONF_INIT_STRUCT(pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
395    pPortFormat->nPortIndex         = G726D_INPUT_PORT;
396    pPortFormat->nIndex             = OMX_IndexParamAudioPcm;
397    pPortFormat->eEncoding          = OMX_AUDIO_CodingPCM;
398
399    /* Set output port format defaults */
400    pPortFormat = pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]->pPortFormat;
401    OMX_CONF_INIT_STRUCT(pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
402    pPortFormat->nPortIndex         = G726D_OUTPUT_PORT;
403    pPortFormat->nIndex             = OMX_IndexParamAudioPcm;
404    pPortFormat->eEncoding          = OMX_AUDIO_CodingPCM;
405
406    /* Set input port parameters */
407    OMX_CONF_INIT_STRUCT(G726_ip, OMX_AUDIO_PARAM_G726TYPE);
408    G726_ip->nPortIndex               = G726D_INPUT_PORT;
409    G726_ip->nSize                    = sizeof(OMX_AUDIO_PARAM_G726TYPE);
410    G726_ip->nVersion.s.nVersionMajor = G726DEC_MAJOR_VER;
411    G726_ip->nVersion.s.nVersionMinor = G726DEC_MINOR_VER;
412    G726_ip->nChannels                = 1; /* mono */
413    G726_ip->eG726Mode            = OMX_AUDIO_G726Mode32;   /*most common used for default */
414
415    /* Set output port parameters */
416    OMX_CONF_INIT_STRUCT(G726_op, OMX_AUDIO_PARAM_PCMMODETYPE);
417    G726_op->nPortIndex               = G726D_OUTPUT_PORT;
418    G726_op->nSamplingRate            = 16000;
419    G726_op->nChannels                = OMX_AUDIO_ChannelModeMono;
420    G726_op->nSize                    = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE);
421    G726_op->nVersion.s.nVersionMajor = 0x1;
422    G726_op->nVersion.s.nVersionMinor = 0x1;
423    G726_op->nBitPerSample            = 16;
424    G726_op->eNumData                 = OMX_NumericalDataUnsigned;
425    G726_op->eEndian                  = OMX_EndianLittle;
426    G726_op->bInterleaved             = OMX_FALSE;
427    G726_op->ePCMMode                 = OMX_AUDIO_PCMModeLinear;
428
429    pComponentPrivate->bBufferIsAllocated = 1;
430    pComponentPrivate->bPortDefsAllocated = 1;
431
432#ifdef DSP_RENDERING_ON
433    if((G726d_fdwrite=open(FIFO1,O_WRONLY))<0) {
434        G726DEC_EPRINT("[G726 Component] - failure to open WRITE pipe\n");
435        eError = OMX_ErrorHardware;
436    }
437    if((G726d_fdread=open(FIFO2,O_RDONLY))<0) {
438        G726DEC_EPRINT("[G726 Component] - failure to open READ pipe\n");
439        eError = OMX_ErrorHardware;
440    }
441#endif
442
443#ifdef RESOURCE_MANAGER_ENABLED
444    eError = RMProxy_NewInitalize();
445    if (eError != OMX_ErrorNone) {
446        G726DEC_DPRINT ("Error returned from loading ResourceManagerProxy thread\n");
447        goto EXIT;
448    }
449#endif
450
451    eError = G726Dec_StartCompThread(pHandle);
452    if (eError != OMX_ErrorNone) {
453        G726DEC_EPRINT ("Error returned from the Component\n");
454        goto EXIT;
455    }
456
457 EXIT:
458    if(OMX_ErrorNone != eError) {
459        G726DEC_EPRINT(":: ************* ERROR: Freeing Other Malloced Resources\n");
460        G726D_OMX_FREE(pPortDef_ip);
461        G726D_OMX_FREE(pPortDef_op);
462        G726D_OMX_FREE(G726_ip);
463        G726D_OMX_FREE(G726_op);
464        G726D_OMX_FREE(pTemp);
465    }
466    G726DEC_DPRINT ("Exiting OMX_ComponentInit\n");
467    return eError;
468}
469
470
471/* ================================================================================= * */
472/**
473 * @fn SendCommand() function receives all the commands from the application.
474 *
475 * @param phandle This is component handle.
476 *
477 * @param Cmd    This is commnad set that came from application.
478 *
479 * @param nParam This is commnad of the commands set that came from application.
480 *
481 * @param G726dData This is command data that came with command.
482 *
483 * @pre          OMX_Init should be called by application.
484 *
485 * @post         None
486 *
487 * @return      OMX_ErrorNone = Successful Inirialization of the component\n
488 *              OMX_ErrorBadPortIndex = Bad port index specified by application.
489 */
490/* ================================================================================ * */
491static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle,
492                                  OMX_COMMANDTYPE Cmd,
493                                  OMX_U32 nParam,OMX_PTR pCmdData)
494{
495    OMX_ERRORTYPE eError = OMX_ErrorNone;
496    int nRet = 0;
497    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
498    G726DEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
499
500    G726D_OMX_CONF_CHECK_CMD(pHandle,1,1);
501    pCompPrivate = (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
502
503    G726DEC_DPRINT("G726DEC: Entered SendCommand\n");
504    if(pCompPrivate->curState == OMX_StateInvalid){
505        G726DEC_DPRINT("G726DEC: Error Notofication Sent to App\n");
506#if 0
507        pCompPrivate->cbInfo.EventHandler (pHandle,
508                                           pHandle->pApplicationPrivate,
509                                           OMX_EventError,
510                                           OMX_ErrorInvalidState,0,
511                                           "Invalid State");
512#endif
513        G726D_OMX_ERROR_EXIT(eError, OMX_ErrorInvalidState,"OMX_ErrorInvalidState");
514    }
515
516    switch(Cmd) {
517    case OMX_CommandStateSet:
518        G726DEC_DPRINT("G726DEC: Entered switch - Command State Set\n");
519        if (nParam == OMX_StateLoaded) {
520            pCompPrivate->bLoadedCommandPending = OMX_TRUE;
521        }
522        if(pCompPrivate->curState == OMX_StateLoaded) {
523            G726DEC_DPRINT("G726DEC: Entered switch - curState == OMX_StateLoaded\n");
524            if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) {
525                G726DEC_DPRINT("G726DEC: Entered switch - nParam == StatExecuting \
526|| OMX_StatePause\n");
527                pCompPrivate->cbInfo.EventHandler (pHandle,
528                                                   pHandle->pApplicationPrivate,
529                                                   OMX_EventError,
530                                                   OMX_ErrorIncorrectStateTransition,
531                                                   0,
532                                                   NULL);
533                G726DEC_DPRINT("Incorrect St Tr fm Loaded to Executing By App\n");
534                goto EXIT;
535            }
536            if(nParam == OMX_StateInvalid) {
537                pCompPrivate->curState = OMX_StateInvalid;
538                pCompPrivate->cbInfo.EventHandler (pHandle,
539                                                   pHandle->pApplicationPrivate,
540                                                   OMX_EventError,
541                                                   OMX_ErrorInvalidState,
542                                                   0,
543                                                   NULL);
544                G726DEC_DPRINT("Incorrect State Tr from Loaded to Invalid by Application\n");
545                goto EXIT;
546            }
547        }
548        break;
549    case OMX_CommandFlush:
550        G726DEC_DPRINT("G726DEC: Entered switch - Command Flush\n");
551        if(nParam > 1 && nParam != -1) {
552            G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
553        }
554        break;
555    case OMX_CommandPortDisable:
556        break;
557    case OMX_CommandPortEnable:
558        G726DEC_DPRINT("G726DEC: Entered switch - Command Port Enable/Disbale\n");
559        break;
560    case OMX_CommandMarkBuffer:
561        G726DEC_DPRINT("G726DEC: Entered switch - Command Mark Buffer\n");
562
563        if(nParam > 0) {
564            G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
565        }
566        break;
567    default:
568        G726DEC_DPRINT("G726DEC: Command Received Default error\n");
569        pCompPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
570                                          OMX_EventError,
571                                          OMX_ErrorUndefined,0,
572                                          "Invalid Command");
573        break;
574    }
575
576
577    nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
578    if (nRet == -1) {
579        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
580    }
581
582    if (Cmd == OMX_CommandMarkBuffer) {
583        nRet = write (pCompPrivate->cmdDataPipe[1], &pCmdData,
584                      sizeof(OMX_PTR));
585        if (nRet == -1) {
586            G726D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
587        }
588    }
589    else {
590        nRet = write (pCompPrivate->cmdDataPipe[1], &nParam,
591                      sizeof(OMX_U32));
592        if (nRet == -1) {
593            G726D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
594        }
595    }
596
597
598#ifdef DSP_RENDERING_ON
599    if(Cmd == OMX_CommandStateSet && nParam == OMX_StateExecuting){
600        if(pCompPrivate->acdnmode == 1) {
601            /* enable COMP for ACDN1 */
602            cmd_data.hComponent = pHandle;
603            cmd_data.AM_Cmd = AM_CommandACDN1CompressorMode;
604            cmd_data.param1 = ECOMPRESSORENABLE;  /* mode  */
605            cmd_data.param2 = 0;
606            cmd_data.streamID = 0;
607
608            if((write(G726d_fdwrite, &cmd_data, sizeof(cmd_data)))<0)
609                G726DEC_DPRINT("[G726 decoder] - fail to send command to audio manager\n");
610
611            /* enable DL EQ for ACDN0 */
612            cmd_data.hComponent = pHandle;
613            cmd_data.AM_Cmd = AM_CommandACDN0EQDLLMode;
614            cmd_data.param1 = EEQ_DLENABLE;  /* mode  */
615            cmd_data.param2 = 0;
616            cmd_data.streamID = 0;
617
618            if((write(G726d_fdwrite, &cmd_data, sizeof(cmd_data)))<0)
619                G726DEC_DPRINT("[G726 decoder] - fail to send command to audio manager\n");
620        }else {
621            /* enable Tee device command*/
622            cmd_data.hComponent = pHandle;
623            cmd_data.AM_Cmd = AM_CommandTDNDownlinkMode;
624            cmd_data.param1 = 0;
625            cmd_data.param2 = 0;
626            cmd_data.streamID = 0;
627
628            if((write(G726d_fdwrite, &cmd_data, sizeof(cmd_data)))<0) {
629                eError = OMX_ErrorHardware;
630                goto EXIT;
631            }
632        }
633    }
634#endif
635
636 EXIT:
637    return eError;
638}
639
640
641
642/* ================================================================================= * */
643/**
644 * @fn GetParameter() function gets the various parameter values of the
645 * component.
646 *
647 * @param hComp         This is component handle.
648 *
649 * @param nParamIndex   This is enumerate values which specifies what kind of
650 *                      information is to be retreived form the component.
651 *
652 * @param ComponentParameterStructure      This is output argument which is
653 *                                         filled by the component component
654 *
655 * @pre          The component should be in loaded state.
656 *
657 * @post         None
658 *
659 * @return      OMX_ErrorNone = Successful Inirialization of the component\n
660 *              OMX_ErrorBadPortIndex = Bad port index specified by application.
661 */
662/* ================================================================================ * */
663static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp,
664                                   OMX_INDEXTYPE nParamIndex,
665                                   OMX_PTR ComponentParameterStructure)
666{
667    OMX_ERRORTYPE eError = OMX_ErrorNone;
668    G726DEC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
669    OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure = NULL;
670
671
672    G726DEC_DPRINT("Inside the GetParameter:: %x\n",nParamIndex);
673
674    G726D_OMX_CONF_CHECK_CMD(hComp,1,1);
675    pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
676
677    G726D_OMX_CONF_CHECK_CMD(pComponentPrivate, ComponentParameterStructure, 1);
678    pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure;
679
680    G726DEC_DPRINT(":: Entering the GetParameter\n");
681
682    if(pComponentPrivate->curState == OMX_StateInvalid) {
683#if 0
684        pComponentPrivate->cbInfo.EventHandler(hComp,
685                                               ((OMX_COMPONENTTYPE *)hComp)->pApplicationPrivate,
686                                               OMX_EventError,
687                                               OMX_ErrorIncorrectStateOperation,
688                                               0,
689                                               NULL);
690#endif
691        eError = OMX_ErrorIncorrectStateOperation;
692        goto EXIT;
693    }
694
695    switch(nParamIndex){
696    case OMX_IndexParamAudioInit:
697        G726DEC_DPRINT(":: GetParameter OMX_IndexParamAudioInit\n");
698        G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
699        memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
700        break;
701
702    case OMX_IndexParamPortDefinition:
703        G726DEC_DPRINT(": GetParameter OMX_IndexParamPortDefinition \n");
704        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
705           pComponentPrivate->pPortDef[G726D_INPUT_PORT]->nPortIndex) {
706            memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[G726D_INPUT_PORT],
707                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
708        } else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
709                  pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nPortIndex) {
710            memcpy(ComponentParameterStructure, pComponentPrivate->pPortDef[G726D_OUTPUT_PORT],
711                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
712        } else {
713            G726DEC_DPRINT(":: OMX_ErrorBadPortIndex from GetParameter \n");
714            eError = OMX_ErrorBadPortIndex;
715        }
716        break;
717
718    case OMX_IndexParamAudioPortFormat:
719        G726DEC_DPRINT(":: GetParameter OMX_IndexParamAudioPortFormat \n");
720        if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
721           pComponentPrivate->pPortDef[G726D_INPUT_PORT]->nPortIndex) {
722            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
723               pComponentPrivate->pCompPort[G726D_INPUT_PORT]->pPortFormat->nPortIndex) {
724                eError = OMX_ErrorNoMore;
725            }
726            else {
727                memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[G726D_INPUT_PORT]->pPortFormat,
728                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
729            }
730        }
731        else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
732                pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nPortIndex){
733            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
734               pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]->pPortFormat->nPortIndex) {
735                eError = OMX_ErrorNoMore;
736            }
737            else {
738                memcpy(ComponentParameterStructure, pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]->pPortFormat,
739                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
740            }
741        }
742        else {
743            G726DEC_DPRINT(":: OMX_ErrorBadPortIndex from GetParameter \n");
744            eError = OMX_ErrorBadPortIndex;
745        }
746        break;
747
748    case OMX_IndexParamAudioPcm:
749        G726DEC_DPRINT(" :: GetParameter OMX_IndexParamAudioPcm \n");
750        if(((OMX_AUDIO_PARAM_G726TYPE *)(ComponentParameterStructure))->nPortIndex ==
751           pComponentPrivate->G726Params->nPortIndex) {
752            memcpy(ComponentParameterStructure, pComponentPrivate->G726Params,
753                   sizeof(OMX_AUDIO_PARAM_G726TYPE));
754        } else if(((OMX_AUDIO_PARAM_PCMMODETYPE *)(ComponentParameterStructure))->nPortIndex ==
755                  pComponentPrivate->PcmParams->nPortIndex) {
756            memcpy(ComponentParameterStructure, pComponentPrivate->PcmParams,
757                   sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
758        } else {
759            G726DEC_DPRINT(" :: OMX_ErrorBadPortIndex from GetParameter \n");
760            eError = OMX_ErrorBadPortIndex;
761        }
762        break;
763
764    case OMX_IndexParamPriorityMgmt:
765        G726DEC_DPRINT(" :: GetParameter OMX_IndexParamPriorityMgmt \n");
766        G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
767        memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
768        break;
769
770    default:
771        G726DEC_DPRINT(" :: OMX_ErrorUnsupportedIndex GetParameter \n");
772        eError = OMX_ErrorUnsupportedIndex;
773        break;
774    }
775 EXIT:
776    G726DEC_DPRINT(" :: Exiting GetParameter\n");
777    G726DEC_DPRINT(" :: Returning = 0x%x\n",eError);
778    return eError;
779}
780
781
782/* ================================================================================= * */
783/**
784 * @fn SetParameter() function sets the various parameter values of the
785 * component.
786 *
787 * @param hComp         This is component handle.
788 *
789 * @param nParamIndex   This is enumerate values which specifies what kind of
790 *                      information is to be set for the component.
791 *
792 * @param ComponentParameterStructure      This is input argument which contains
793 *                                         the values to be set for the component.
794 *
795 * @pre          The component should be in loaded state.
796 *
797 * @post         None
798 *
799 * @return      OMX_ErrorNone = Successful Inirialization of the component\n
800 *              OMX_ErrorBadPortIndex = Bad port index specified by application.
801 */
802/* ================================================================================ * */
803static OMX_ERRORTYPE SetParameter (
804                                   OMX_IN  OMX_HANDLETYPE hComponent,
805                                   OMX_IN  OMX_INDEXTYPE nIndex,
806                                   OMX_IN  OMX_PTR pCompParam)
807{
808    OMX_ERRORTYPE eError = OMX_ErrorNone;
809    OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComponent;
810    G726DEC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
811    OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL;
812    OMX_PARAM_PORTDEFINITIONTYPE *pComponentParamPort = NULL;
813    OMX_AUDIO_PARAM_PCMMODETYPE *pCompPcmParam = NULL;
814    OMX_AUDIO_PARAM_G726TYPE *pCompG726Param = NULL;
815    OMX_PARAM_COMPONENTROLETYPE  *pRole = NULL;
816    OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
817
818    G726D_OMX_CONF_CHECK_CMD(hComponent,1,1)
819
820        pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
821    G726D_OMX_CONF_CHECK_CMD(pComponentPrivate, pCompParam, 1);
822
823
824    G726DEC_DPRINT(" :: Entering the SetParameter\n");
825    if (pComponentPrivate->curState != OMX_StateLoaded) {
826        eError = OMX_ErrorIncorrectStateOperation;
827        G726DEC_DPRINT(" :: OMX_ErrorIncorrectStateOperation from SetParameter");
828        goto EXIT;
829    }
830
831    switch(nIndex) {
832    case OMX_IndexParamAudioPortFormat:
833        G726DEC_DPRINT(":: SetParameter OMX_IndexParamAudioPortFormat \n");
834        pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
835        if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G726D_INPUT_PORT]->pPortFormat->nPortIndex ) {
836            memcpy(pComponentPrivate->pCompPort[G726D_INPUT_PORT]->pPortFormat,
837                   pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
838        } else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]->pPortFormat->nPortIndex ) {
839            memcpy(pComponentPrivate->pCompPort[G726D_OUTPUT_PORT]->pPortFormat,
840                   pComponentParam, sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
841        } else {
842            G726DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
843            eError = OMX_ErrorBadPortIndex;
844        }
845        break;
846
847    case OMX_IndexParamAudioPcm:
848        G726DEC_DPRINT(" :: SetParameter OMX_IndexParamAudioPcm \n");
849        pCompPcmParam = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
850
851        /* This if condition is not yet well defined because khronos
852         * test suite does not set the sampling frequency. For component
853         * test application, it is meant to test that component returns
854         * the error on invalid frequecy */
855
856        if (pCompPcmParam->nPortIndex == G726D_OUTPUT_PORT) { /* means Output port */
857            G726D_OMX_CONF_CHECK_CMD(((G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->PcmParams, 1, 1);
858            memcpy(((G726DEC_COMPONENT_PRIVATE *)
859                    pHandle->pComponentPrivate)->PcmParams, pCompPcmParam,
860                   sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
861        }
862        else {
863            G726DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
864            eError = OMX_ErrorBadPortIndex;
865        }
866        break;
867
868        /********/
869    case OMX_IndexParamAudioG726:
870        G726DEC_DPRINT(" :: SetParameter OMX_IndexParamAudioPcm \n");
871        pCompG726Param = (OMX_AUDIO_PARAM_G726TYPE *)pCompParam;
872
873        if(pCompG726Param->nPortIndex == G726D_INPUT_PORT) { /* means Input port */
874            G726D_OMX_CONF_CHECK_CMD(((G726DEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->G726Params, 1, 1);
875            memcpy(((G726DEC_COMPONENT_PRIVATE*)
876                    pHandle->pComponentPrivate)->G726Params, pCompG726Param,
877                   sizeof(OMX_AUDIO_PARAM_G726TYPE));
878        }
879        else {
880            G726DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
881            eError = OMX_ErrorBadPortIndex;
882        }
883        break;
884        /********/
885
886    case OMX_IndexParamPortDefinition:
887        pComponentParamPort = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
888        if (pComponentParamPort->nPortIndex == 0) {
889            if (pComponentParamPort->eDir != OMX_DirInput) {
890                G726DEC_DPRINT(":: Invalid input buffer Direction\n");
891                eError = OMX_ErrorBadParameter;
892                goto EXIT;
893            }
894            if (pComponentParamPort->format.audio.eEncoding != OMX_AUDIO_CodingG726) {
895                G726DEC_DPRINT(":: Invalid format Parameter\n");
896                eError = OMX_ErrorBadParameter;
897                goto EXIT;
898            }
899        } else if (pComponentParamPort->nPortIndex == 1) {
900            if (pComponentParamPort->eDir != OMX_DirOutput) {
901                G726DEC_DPRINT(" :: Invalid Output buffer Direction\n");
902                eError = OMX_ErrorBadParameter;
903                goto EXIT;
904            }
905            if (pComponentParamPort->format.audio.eEncoding != OMX_AUDIO_CodingPCM) {
906                G726DEC_DPRINT(":: Invalid format Parameter\n");
907                eError = OMX_ErrorBadParameter;
908                goto EXIT;
909            }
910        } else {
911            G726DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
912            eError = OMX_ErrorBadPortIndex;
913        }
914        G726DEC_DPRINT(":: SetParameter OMX_IndexParamPortDefinition \n");
915        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
916           pComponentPrivate->pPortDef[G726D_INPUT_PORT]->nPortIndex) {
917            G726DEC_DPRINT(":: SetParameter OMX_IndexParamPortDefinition input \n");
918            memcpy(pComponentPrivate->pPortDef[G726D_INPUT_PORT], pCompParam,
919                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
920        }
921        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
922                pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nPortIndex) {
923            G726DEC_DPRINT(":: SetParameter OMX_IndexParamPortDefinition output\n");
924            memcpy(pComponentPrivate->pPortDef[G726D_OUTPUT_PORT], pCompParam,
925                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
926        }
927        else {
928            G726DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
929            eError = OMX_ErrorBadPortIndex;
930        }
931        break;
932
933    case OMX_IndexParamPriorityMgmt:
934        G726DEC_DPRINT(":: SetParameter OMX_IndexParamPriorityMgmt \n");
935        G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
936        memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam,
937               sizeof(OMX_PRIORITYMGMTTYPE));
938        break;
939
940    case OMX_IndexParamAudioInit:
941        G726DEC_DPRINT(":: SetParameter OMX_IndexParamAudioInit \n");
942        G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
943        memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam,
944               sizeof(OMX_PORT_PARAM_TYPE));
945        break;
946
947    case OMX_IndexParamStandardComponentRole:
948        if (pCompParam) {
949            pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
950            G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->componentRole, 1, 1);
951            memcpy(pComponentPrivate->componentRole, (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
952        } else {
953            eError = OMX_ErrorBadParameter;
954        }
955        break;
956
957    case OMX_IndexParamCompBufferSupplier:
958        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
959           pComponentPrivate->pPortDef[G726D_INPUT_PORT]->nPortIndex) {
960            G726DEC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n");
961            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput;
962            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
963
964        }
965        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
966                pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nPortIndex) {
967            G726DEC_DPRINT(":: SetParameter OMX_IndexParamCompBufferSupplier \n");
968            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput;
969            memcpy(&sBufferSupplier, pCompParam, sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
970        }
971        else {
972            G726DEC_DPRINT(":: OMX_ErrorBadPortIndex from SetParameter");
973            eError = OMX_ErrorBadPortIndex;
974        }
975        break;
976
977    default:
978        G726DEC_DPRINT(":: SetParameter OMX_ErrorUnsupportedIndex \n");
979        eError = OMX_ErrorUnsupportedIndex;
980        break;
981    }
982
983 EXIT:
984    G726DEC_DPRINT(":: Exiting SetParameter\n");
985    G726DEC_DPRINT(":: Returning = 0x%x\n",eError);
986    return eError;
987
988}
989
990
991/* ================================================================================= * */
992/**
993 * @fn SetCallbacks() Sets application callbacks to the component
994 *
995 * @param pComponent  This is component handle.
996 *
997 * @param pCallBacks  Application callbacks
998 *
999 * @param pAppData    Application specified private data.
1000 *
1001 * @pre          None
1002 *
1003 * @post         None
1004 *
1005 * @return      OMX_ErrorNone = Successful Inirialization of the component
1006 *              OMX_ErrorBadParameter = If callback argument is NULL.
1007 */
1008/* ================================================================================ * */
1009
1010static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent,
1011                                   OMX_CALLBACKTYPE* pCallBacks,
1012                                   OMX_PTR pAppData)
1013{
1014    OMX_ERRORTYPE eError = OMX_ErrorNone;
1015    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
1016    G726DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1017
1018
1019    G726D_OMX_CONF_CHECK_CMD(pHandle,1,1)
1020
1021        pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1022    G726D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1)
1023
1024        G726DEC_DPRINT ("Entering SetCallbacks\n");
1025
1026    G726D_OMX_CONF_CHECK_CMD(pCallBacks, pCallBacks->EventHandler, pCallBacks->EmptyBufferDone)
1027        G726D_OMX_CONF_CHECK_CMD(pCallBacks->FillBufferDone, 1, 1)
1028
1029        memcpy (&(pComponentPrivate->cbInfo), pCallBacks, sizeof(OMX_CALLBACKTYPE));
1030    pHandle->pApplicationPrivate = pAppData;
1031    G726DEC_STATEPRINT("****************** Component State Set to Loaded\n\n");
1032    pComponentPrivate->curState = OMX_StateLoaded;
1033
1034 EXIT:
1035    G726DEC_DPRINT ("Exiting SetCallbacks\n");
1036    return eError;
1037}
1038
1039
1040/* ================================================================================= * */
1041/**
1042 * @fn GetComponentVersion() Sets application callbacks to the component. Currently this
1043 * function is not implemented.
1044 *
1045 * @param hComp  This is component handle.
1046 *
1047 * @param pComponentName  This is component name.
1048 *
1049 * @param pComponentVersion  This output argument will contain the component
1050 *                           version when this function exits successfully.
1051 *
1052 * @param pSpecVersion    This is specification version.
1053 *
1054 * @param pComponentUUID  This specifies the UUID of the component.
1055 *
1056 * @pre          None
1057 *
1058 * @post         None
1059 *
1060 * @return      OMX_ErrorNone = Successful Inirialization of the component
1061 */
1062/* ================================================================================ * */
1063static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
1064                                          OMX_STRING pComponentName,
1065                                          OMX_VERSIONTYPE* pComponentVersion,
1066                                          OMX_VERSIONTYPE* pSpecVersion,
1067                                          OMX_UUIDTYPE* pComponentUUID)
1068{
1069    OMX_ERRORTYPE eError = OMX_ErrorNone;
1070    eError = OMX_ErrorNotImplemented;
1071    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
1072    G726DEC_COMPONENT_PRIVATE *pComponentPrivate =
1073        (G726DEC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate;
1074
1075    /* Copy component version structure */
1076    if(pComponentVersion != NULL && pComponentName != NULL) {
1077        strcpy(pComponentName, pComponentPrivate->cComponentName);
1078        memcpy(pComponentVersion, &(pComponentPrivate->ComponentVersion.s),
1079               sizeof(pComponentPrivate->ComponentVersion.s));
1080    }
1081    else {
1082        G726DEC_DPRINT("%d :: OMX_ErrorBadParameter from GetComponentVersion",__LINE__);
1083        eError = OMX_ErrorBadParameter;
1084    }
1085
1086    return eError;
1087}
1088
1089
1090
1091/* ================================================================================= * */
1092/**
1093 * @fn GetConfig() gets the configuration of the component depending on the value
1094 * of nConfigINdex. This function is currently not implemented.
1095 *
1096 * @param hComp  This is component handle.
1097 *
1098 * @param nConfigIndex  This is config index to get the configuration of
1099 *                      component.
1100 *
1101 * @param ComponentConfigStructure This is configuration structure that is filled
1102 * by the component depending on the value of nConfigIndex.
1103 *
1104 * @pre          None
1105 *
1106 * @post         None
1107 *
1108 * @return      OMX_ErrorNone = Successful Inirialization of the component
1109 */
1110/* ================================================================================ * */
1111static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
1112                                OMX_INDEXTYPE nConfigIndex,
1113                                OMX_PTR ComponentConfigStructure)
1114{
1115    OMX_ERRORTYPE eError = OMX_ErrorNone;
1116    G726DEC_DPRINT ("Entering GetConfig\n");
1117    G726DEC_DPRINT ("Inside   GetConfig\n");
1118    G726DEC_DPRINT ("Exiting  GetConfig\n");
1119    return eError;
1120}
1121
1122/* ================================================================================= * */
1123/**
1124 * @fn SetConfig() Sets the configuration of the component depending on the value
1125 * of nConfigINdex.
1126 *
1127 * @param hComp  This is component handle.
1128 *
1129 * @param nConfigIndex  This is config index to get the configuration of
1130 *                      component.
1131 *
1132 * @param ComponentConfigStructure This is configuration structure that contains
1133 *                                 the information which the component has to
1134 *                                 configured with.
1135 *
1136 * @pre          None
1137 *
1138 * @post         None
1139 *
1140 * @return      OMX_ErrorNone = Successful Inirialization of the component
1141 */
1142/* ================================================================================ * */
1143static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
1144                                OMX_INDEXTYPE nConfigIndex,
1145                                OMX_PTR ComponentConfigStructure)
1146{
1147    OMX_ERRORTYPE eError = OMX_ErrorNone;
1148    G726DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1149    OMX_AUDIO_CONFIG_MUTETYPE *pMuteStructure = NULL;
1150    OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL;
1151    TI_OMX_DSP_DEFINITION* pDspDefinition = NULL;
1152    OMX_S16* deviceString = NULL;
1153    TI_OMX_DATAPATH dataPath;
1154
1155    G726DEC_DPRINT ("Entering SetConfig\n");
1156
1157    G726D_OMX_CONF_CHECK_CMD(hComp,ComponentConfigStructure,1)
1158
1159        pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)
1160        (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
1161
1162    G726D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1)
1163
1164        switch (nConfigIndex){
1165        case OMX_IndexCustomG726DecHeaderInfoConfig:
1166            pDspDefinition = (TI_OMX_DSP_DEFINITION *)ComponentConfigStructure;
1167            pComponentPrivate->dasfmode = pDspDefinition->dasfMode;
1168            pComponentPrivate->streamID = pDspDefinition->streamId;
1169            pComponentPrivate->packingType = pDspDefinition->packingType;
1170            break;
1171
1172            /* set mute/unmute for playback stream */
1173        case OMX_IndexConfigAudioMute:
1174#ifdef DSP_RENDERING_ON
1175            pMuteStructure = (OMX_AUDIO_CONFIG_MUTETYPE *)ComponentConfigStructure;
1176            G726DEC_DPRINT("Set Mute/Unmute for playback stream\n");
1177            cmd_data.hComponent = hComp;
1178            if(pMuteStructure->bMute == OMX_TRUE){
1179                G726DEC_DPRINT("Mute the playback stream\n");
1180                cmd_data.AM_Cmd = AM_CommandStreamMute;
1181            }
1182            else{
1183                G726DEC_DPRINT("unMute the playback stream\n");
1184                cmd_data.AM_Cmd = AM_CommandStreamUnMute;
1185            }
1186            cmd_data.param1 = 0;
1187            cmd_data.param2 = 0;
1188            cmd_data.streamID = pComponentPrivate->streamID;
1189
1190            if((write(G726d_fdwrite, &cmd_data, sizeof(cmd_data)))<0){
1191                G726DEC_DPRINT("[G726 decoder] - fail to send command to audio manager\n");
1192            }
1193#endif
1194            break;
1195
1196            /* set volume for playback stream */
1197        case OMX_IndexConfigAudioVolume:
1198#ifdef DSP_RENDERING_ON
1199            pVolumeStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure;
1200            G726DEC_DPRINT("Set volume for playback stream\n");
1201            cmd_data.hComponent = hComp;
1202            cmd_data.AM_Cmd = AM_CommandSWGain;
1203            cmd_data.param1 = pVolumeStructure->sVolume.nValue;
1204            cmd_data.param2 = 0;
1205            cmd_data.streamID = pComponentPrivate->streamID;
1206
1207            if((write(G726d_fdwrite, &cmd_data, sizeof(cmd_data)))<0){
1208                G726DEC_DPRINT("[G726 decoder] - fail to send command to audio manager\n");
1209            }
1210#endif
1211            break;
1212
1213        case  OMX_IndexCustomG726DecDataPath:
1214            deviceString = (OMX_S16*)ComponentConfigStructure;
1215            if (deviceString == NULL) {
1216                eError = OMX_ErrorBadParameter;
1217                goto EXIT;
1218            }
1219
1220            dataPath = (TI_OMX_DATAPATH)*deviceString;
1221
1222            switch(dataPath) {
1223            case DATAPATH_APPLICATION:
1224                /*strcpy((char*)pComponentPrivate->sDeviceString,(char*)ETEEDN_STRING);*/
1225                OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString, RENDERTYPE_DECODER,
1226                                     pComponentPrivate->streamID);
1227                break;
1228
1229            case DATAPATH_APPLICATION_RTMIXER:
1230                strcpy((char*)pComponentPrivate->sDeviceString,(char*)RTM_STRING);
1231                break;
1232
1233            case DATAPATH_ACDN:
1234                strcpy((char*)pComponentPrivate->sDeviceString,(char*)ACDN_STRING);
1235                break;
1236
1237            default:
1238                break;
1239            }
1240            break;
1241
1242        default:
1243            eError = OMX_ErrorUnsupportedIndex;
1244            break;
1245        }
1246
1247    G726DEC_DPRINT ("Exiting  SetConfig\n");
1248 EXIT:
1249
1250    return eError;
1251}
1252
1253/* ================================================================================= * */
1254/**
1255 * @fn GetState() Gets the current state of the component.
1256 *
1257 * @param pComponent  This is component handle.
1258 *
1259 * @param pState      This is the output argument that contains the state of the
1260 *                    component.
1261 *
1262 * @pre          None
1263 *
1264 * @post         None
1265 *
1266 * @return      OMX_ErrorNone = Successful Inirialization of the component
1267 *              OMX_ErrorBadParameter = if output argument is NULL.
1268 */
1269/* ================================================================================ * */
1270static OMX_ERRORTYPE GetState (OMX_HANDLETYPE pComponent, OMX_STATETYPE* pState)
1271{
1272    OMX_ERRORTYPE eError = OMX_ErrorUndefined;
1273    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1274
1275    if (!pState) {
1276        G726DEC_DPRINT (":: About to exit with bad parameter\n");
1277        eError = OMX_ErrorBadParameter;
1278        goto EXIT;
1279    }
1280
1281    G726D_OMX_CONF_CHECK_CMD(pHandle,1,1)
1282        if (pHandle && pHandle->pComponentPrivate) {
1283            *pState =  ((G726DEC_COMPONENT_PRIVATE*)
1284                        pHandle->pComponentPrivate)->curState;
1285        } else {
1286            G726DEC_STATEPRINT("Component State Set to Loaded\n\n");
1287            *pState = OMX_StateLoaded;
1288        }
1289
1290    eError = OMX_ErrorNone;
1291
1292 EXIT:
1293    return eError;
1294}
1295
1296/* ================================================================================= * */
1297/**
1298 * @fn EmptyThisBuffer() This function is used by application to sent the filled
1299 * input buffers to the component.
1300 *
1301 * @param pComponent  This is component handle.
1302 *
1303 * @param pBuffer     This is poiter to the buffer header that come from the
1304 *                    application.
1305 *
1306 * @pre          None
1307 *
1308 * @post         None
1309 *
1310 * @return      OMX_ErrorNone = Successful exit of the function
1311 *              OMX_ErrorBadParameter =  Bad input argument
1312 *              OMX_ErrorBadPortIndex = Bad port index supplied by the
1313 *              application
1314 */
1315/* ================================================================================ * */
1316static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
1317                                      OMX_BUFFERHEADERTYPE* pBuffer)
1318{
1319    OMX_ERRORTYPE eError = OMX_ErrorNone;
1320    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1321    G726DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1322    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1323    int ret=0;
1324
1325    G726D_OMX_CONF_CHECK_CMD(pHandle,1,1)
1326
1327        pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1328
1329    G726D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1)
1330
1331        pPortDef = ((G726DEC_COMPONENT_PRIVATE*)
1332                    pComponentPrivate)->pPortDef[G726D_INPUT_PORT];
1333
1334
1335    if(!pPortDef->bEnabled) {
1336        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation,
1337                             "OMX_ErrorIncorrectStateOperation");
1338    }
1339
1340    if (pBuffer == NULL) {
1341        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"OMX_ErrorBadParameter");
1342    }
1343
1344    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1345        G726DEC_EPRINT(":: Error: Bad Size = %ld, Add: %p\n",
1346                       pBuffer->nSize,pBuffer);
1347        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"Bad Size");
1348    }
1349
1350    if (pBuffer->nInputPortIndex != G726D_INPUT_PORT) {
1351        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
1352    }
1353
1354
1355    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1356        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorVersionMismatch,"OMX_ErrorVersionMismatch");
1357    }
1358
1359
1360    if(pComponentPrivate->curState != OMX_StateExecuting &&
1361       pComponentPrivate->curState != OMX_StatePause &&
1362       pComponentPrivate->curState != OMX_StateIdle) {
1363        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation,
1364                             "OMX_ErrorIncorrectStateOperation");
1365    }
1366
1367
1368    G726DEC_DPRINT("\n------------------------------------------\n\n");
1369    G726DEC_DPRINT (":: Component Sending Filled ip buff %p \
1370                             to Component Thread\n",pBuffer);
1371    G726DEC_DPRINT("\n------------------------------------------\n\n");
1372
1373    if (pComponentPrivate->bBypassDSP == 0) {
1374        pComponentPrivate->app_nBuf--;
1375    }
1376
1377    pComponentPrivate->pMarkData = pBuffer->pMarkData;
1378    pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
1379    pComponentPrivate->nUnhandledEmptyThisBuffers++;
1380    ret = write (pComponentPrivate->dataPipe[1], &pBuffer,
1381                 sizeof(OMX_BUFFERHEADERTYPE*));
1382    if (ret == -1) {
1383        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
1384    }
1385
1386    pComponentPrivate->nEmptyThisBufferCount++;
1387
1388 EXIT:
1389    G726DEC_DPRINT (":: Exiting EmptyThisBuffer, eError = %d\n",eError);
1390    return eError;
1391}
1392
1393/* ================================================================================= * */
1394/**
1395 * @fn FillThisBuffer() This function is used by application to sent the empty
1396 * output buffers to the component.
1397 *
1398 * @param pComponent  This is component handle.
1399 *
1400 * @param pBuffer     This is poiter to the output buffer header that come from the
1401 *                    application.
1402 *
1403 * @pre          None
1404 *
1405 * @post         None
1406 *
1407 * @return      OMX_ErrorNone = Successful exit of the function
1408 *              OMX_ErrorBadParameter =  Bad input argument
1409 *              OMX_ErrorBadPortIndex = Bad port index supplied by the
1410 *              application
1411 */
1412/* ================================================================================ * */
1413static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
1414                                     OMX_BUFFERHEADERTYPE* pBuffer)
1415{
1416    OMX_ERRORTYPE eError = OMX_ErrorNone;
1417    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
1418    G726DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1419    int nRet=0;
1420    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1421
1422    G726DEC_DPRINT("\n------------------------------------------\n\n");
1423    G726DEC_DPRINT (" :: Component Sending Emptied op buff %p \
1424                             to Component Thread\n",pBuffer);
1425    G726DEC_DPRINT("\n------------------------------------------\n\n");
1426
1427
1428    G726D_OMX_CONF_CHECK_CMD(pHandle,1,1)
1429
1430        pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
1431
1432    G726D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1)
1433
1434
1435        pPortDef = ((G726DEC_COMPONENT_PRIVATE*)
1436                    pComponentPrivate)->pPortDef[G726D_OUTPUT_PORT];
1437
1438    if(!pPortDef->bEnabled) {
1439        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation,
1440                             "OMX_ErrorIncorrectStateOperation");
1441    }
1442
1443    if (pBuffer == NULL) {
1444        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"OMX_ErrorBadParameter");
1445    }
1446
1447    if (pBuffer->nSize != sizeof(OMX_BUFFERHEADERTYPE)) {
1448        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,"OMX_ErrorBadParameter");
1449    }
1450
1451    if (pBuffer->nOutputPortIndex != G726D_OUTPUT_PORT) {
1452        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
1453    }
1454
1455    G726DEC_DPRINT("::pBuffer->nVersion.nVersion:%ld\n",pBuffer->nVersion.nVersion);
1456    G726DEC_DPRINT("::pComponentPrivate->nVersion:%ld\n",pComponentPrivate->nVersion);
1457    if (pBuffer->nVersion.nVersion != pComponentPrivate->nVersion) {
1458        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorVersionMismatch,"OMX_ErrorVersionMismatch");
1459    }
1460
1461    if(pComponentPrivate->curState != OMX_StateExecuting &&
1462       pComponentPrivate->curState != OMX_StatePause &&
1463       pComponentPrivate->curState != OMX_StateIdle) {
1464        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation,
1465                             "OMX_ErrorIncorrectStateOperation");
1466    }
1467
1468
1469    pBuffer->nFilledLen = 0;
1470
1471    if (pComponentPrivate->bBypassDSP == 0) {
1472        pComponentPrivate->app_nBuf--;
1473    }
1474
1475    if(pComponentPrivate->pMarkBuf){
1476        G726DEC_DPRINT("FillThisBuffer Line\n");
1477        pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
1478        pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
1479        pComponentPrivate->pMarkBuf = NULL;
1480    }
1481
1482    if (pComponentPrivate->pMarkData) {
1483        G726DEC_DPRINT("FillThisBuffer Line\n");
1484        pBuffer->hMarkTargetComponent = pComponentPrivate->hMarkTargetComponent;
1485        pBuffer->pMarkData = pComponentPrivate->pMarkData;
1486        pComponentPrivate->pMarkData = NULL;
1487    }
1488    pComponentPrivate->nUnhandledFillThisBuffers++;
1489    nRet = write (pComponentPrivate->dataPipe[1], &pBuffer,
1490                  sizeof (OMX_BUFFERHEADERTYPE*));
1491    if (nRet == -1) {
1492        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
1493    }
1494
1495    pComponentPrivate->nFillThisBufferCount++;
1496
1497 EXIT:
1498    G726DEC_DPRINT (":: Exiting FillThisBuffer\n");
1499    return eError;
1500}
1501
1502/* ================================================================================= * */
1503/**
1504 * @fn ComponentDeInit() This function deinitializes the component. It is called
1505 * from OMX Core, not by application. Albeit, Application does call
1506 * OMX_FreeHandle of OMX Core and which in turn calls this function.
1507 *
1508 * @param pHandle  This is component handle.
1509 *
1510 * @pre          None
1511 *
1512 * @post        This function should clean or free as much resources as
1513 *              possible.
1514 *
1515 * @return      OMX_ErrorNone = On Success
1516 *              Appropriate error number in case any error happens.
1517 */
1518/* ================================================================================ * */
1519static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
1520{
1521    OMX_ERRORTYPE eError = OMX_ErrorNone;
1522    OMX_ERRORTYPE eError1 = OMX_ErrorNone;
1523    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
1524    G726DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1525    OMX_ERRORTYPE threadError = OMX_ErrorNone;
1526    int pthreadError = 0;
1527
1528    G726DEC_DPRINT("ComponentDeInit\n");
1529    G726D_OMX_CONF_CHECK_CMD(pComponent,1,1)
1530        pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
1531    G726D_OMX_CONF_CHECK_CMD(pComponentPrivate,1,1)
1532
1533#ifdef DSP_RENDERING_ON
1534        close(G726d_fdwrite);
1535    close(G726d_fdread);
1536#endif
1537
1538#ifdef RESOURCE_MANAGER_ENABLED
1539    /*  eError = RMProxy_SendCommand(pHandle, RMProxy_FreeResource,
1540        OMX_PCM_Decoder_COMPONENT, 0, NULL); */
1541    eError = RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_PCM_Decoder_COMPONENT, 0, 3456,NULL);
1542    if (eError != OMX_ErrorNone) {
1543        G726DEC_EPRINT ("%d ::Error returned from destroy ResourceManagerProxy thread\n",
1544                        __LINE__);
1545    }
1546
1547    eError1 = RMProxy_Deinitalize();
1548    if (eError1 != OMX_ErrorNone) {
1549        G726DEC_EPRINT(":: First Error in ComponentDeinit: From RMProxy_Deinitalize\n");
1550        eError = eError1;
1551    }
1552
1553    /*eError = RMProxy_SendCommand(pHandle, RMProxy_FreeResource,
1554      OMX_G726_Decoder_COMPONENT, 0, NULL);
1555      if (eError != OMX_ErrorNone) {
1556      G726DEC_EPRINT ("%d ::Error returned from destroy ResourceManagerProxy thread\n",
1557      __LINE__);
1558      }
1559
1560      eError1 = RMProxy_Deinitalize();
1561      if (eError1 != OMX_ErrorNone) {
1562      G726DEC_EPRINT(":: First Error in ComponentDeinit: From RMProxy_Deinitalize\n");
1563      eError = eError1;
1564      }*/
1565#endif
1566
1567    pComponentPrivate->bExitCompThrd = 1;
1568
1569    pthreadError = pthread_join(pComponentPrivate->ComponentThread, (void*)&threadError);
1570    if(0 != pthreadError) {
1571        G726DEC_EPRINT(":: First Error in ComponentDeinit: From pthread_join\n");
1572        eError = OMX_ErrorHardware;
1573        goto EXIT;
1574    }
1575
1576    if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError) {
1577        eError = OMX_ErrorInsufficientResources;
1578        G726DEC_EPRINT("%d :: Error while closing Component Thread\n",__LINE__);
1579        goto EXIT;
1580    }
1581
1582    eError1 = G726DEC_FreeCompResources(pHandle);
1583    if (OMX_ErrorNone != eError1) {
1584        if (OMX_ErrorNone == eError) {
1585            G726DEC_EPRINT(":: First Error in ComponentDeinit: From FreeCompResources\n");
1586            eError = eError1;
1587        }
1588    }
1589
1590    if (pComponentPrivate->sDeviceString != NULL) {
1591        G726D_OMX_FREE(pComponentPrivate->sDeviceString);
1592    }
1593
1594    G726DEC_MEMPRINT(":: Freeing: pComponentPrivate = %p\n", pComponentPrivate);
1595    G726D_OMX_FREE(pComponentPrivate);
1596    G726DEC_DPRINT("::*********** ComponentDeinit is Done************** \n");
1597
1598 EXIT:
1599    return eError;
1600}
1601
1602
1603/* ================================================================================= * */
1604/**
1605 * @fn ComponentTunnelRequest() This function estabilishes the tunnel between two
1606 * components. This is not implemented currently.
1607 *
1608 * @param hComp  Handle of this component.
1609 *
1610 * @param nPort Port of this component on which tunneling has to be done.
1611 *
1612 * @param hTunneledComp Handle of the component with which tunnel has to be
1613 *                      established.
1614 *
1615 * @param nTunneledPort Port of the tunneling component.
1616 *
1617 * @param pTunnelSetup Tunnel Setuup parameters.
1618 *
1619 * @pre          None
1620 *
1621 * @post        None
1622 *
1623 * @return      OMX_ErrorNone = On Success
1624 *              Appropriate error number in case any error happens.
1625 */
1626/* ================================================================================ * */
1627static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
1628                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
1629                                             OMX_U32 nTunneledPort,
1630                                             OMX_TUNNELSETUPTYPE* pTunnelSetup)
1631{
1632    OMX_ERRORTYPE eError = OMX_ErrorNone;
1633    G726DEC_DPRINT (":: Entering ComponentTunnelRequest\n");
1634    G726DEC_DPRINT (":: Inside   ComponentTunnelRequest\n");
1635    eError = OMX_ErrorNotImplemented;
1636    G726DEC_DPRINT (":: Exiting ComponentTunnelRequest\n");
1637    return eError;
1638}
1639
1640
1641
1642/* ================================================================================= * */
1643/**
1644 * @fn AllocateBuffer() This function allocated the memory for the buffer onm
1645 * request from application.
1646 *
1647 * @param hComponent  Handle of this component.
1648 *
1649 * @param pBuffer  Pointer to the buffer header.
1650 *
1651 * @param nPortIndex  Input port or Output port
1652 *
1653 * @param pAppPrivate Application private data.
1654 *
1655 * @param nSizeBytes Size of the buffer that is to be allocated.
1656 *
1657 * @pre          None
1658 *
1659 * @post        Requested buffer should get the memory allocated.
1660 *
1661 * @return      OMX_ErrorNone = On Success
1662 *              OMX_ErrorBadPortIndex = Bad port index from app
1663 */
1664/* ================================================================================ * */
1665static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
1666                                     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
1667                                     OMX_IN OMX_U32 nPortIndex,
1668                                     OMX_IN OMX_PTR pAppPrivate,
1669                                     OMX_IN OMX_U32 nSizeBytes)
1670{
1671    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
1672    G726DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
1673    OMX_ERRORTYPE eError = OMX_ErrorNone;
1674    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
1675
1676
1677    G726DEC_DPRINT (":: Entering AllocateBuffer\n");
1678    G726D_OMX_CONF_CHECK_CMD(hComponent,1,1)
1679        pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)
1680        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1681
1682    G726D_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1)
1683
1684        pPortDef = ((G726DEC_COMPONENT_PRIVATE*)
1685                    pComponentPrivate)->pPortDef[nPortIndex];
1686
1687    G726D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1)
1688
1689        if (!pPortDef->bEnabled) {
1690            pComponentPrivate->AlloBuf_waitingsignal = 1;
1691#ifndef UNDER_CE
1692            pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1693            pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold,
1694                              &pComponentPrivate->AlloBuf_mutex);
1695            pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1696#else
1697            OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
1698#endif
1699        }
1700
1701    G726D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
1702
1703    /* Needed for cache synchronization between ARM and DSP */
1704    G726D_OMX_MALLOC_SIZE(pBufferHeader->pBuffer,(nSizeBytes + 256),OMX_U8);
1705    pBufferHeader->pBuffer += 128;
1706    pBufferHeader->nVersion.nVersion = G726DEC_BUFHEADER_VERSION;
1707
1708
1709    G726DEC_DPRINT("********************************************\n");
1710    G726DEC_DPRINT(":: Allocated BufHeader %p Buffer = %p, on port %ld\n",
1711                   pBufferHeader,
1712                   pBufferHeader->pBuffer, nPortIndex);
1713
1714    G726DEC_DPRINT(":: Ip Num = %ld\n",pComponentPrivate->pInputBufferList->numBuffers);
1715    G726DEC_DPRINT(":: Op Num = %ld\n",pComponentPrivate->pOutputBufferList->numBuffers);
1716    G726DEC_DPRINT("********************************************\n");
1717
1718
1719    pBufferHeader->pAppPrivate = pAppPrivate;
1720    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1721    pBufferHeader->nAllocLen = nSizeBytes;
1722
1723    if (nPortIndex == G726D_INPUT_PORT) {
1724        pBufferHeader->nInputPortIndex = nPortIndex;
1725        pBufferHeader->nOutputPortIndex = -1;
1726        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
1727        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
1728
1729        G726DEC_DPRINT("pComponentPrivate->pInputBufferList->pBufHdr[%ld] = %p\n",
1730                       pComponentPrivate->pInputBufferList->numBuffers,
1731                       pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]);
1732
1733        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
1734
1735        G726DEC_DPRINT("pComponentPrivate->pInputBufferList->numBuffers = %ld\n",
1736                       pComponentPrivate->pInputBufferList->numBuffers);
1737
1738        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1739            pPortDef->bPopulated = 1;
1740        }
1741    } else if (nPortIndex == G726D_OUTPUT_PORT) {
1742        pBufferHeader->nInputPortIndex = -1;
1743        pBufferHeader->nOutputPortIndex = nPortIndex;
1744        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
1745        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
1746
1747        G726DEC_DPRINT("pComponentPrivate->pOutputBufferList->pBufHdr[%ld] = %p\n",
1748                       pComponentPrivate->pOutputBufferList->numBuffers,
1749                       pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]);
1750
1751        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
1752
1753        G726DEC_DPRINT("pComponentPrivate->pOutputBufferList->numBuffers = %ld\n",
1754                       pComponentPrivate->pOutputBufferList->numBuffers);
1755
1756        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
1757            pPortDef->bPopulated = 1;
1758        }
1759    } else {
1760        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadPortIndex,"OMX_ErrorBadPortIndex");
1761    }
1762
1763    if((pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated ==
1764        pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled)&&
1765       (pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated ==
1766        pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled) &&
1767       (pComponentPrivate->InLoaded_readytoidle)) {
1768        pComponentPrivate->InLoaded_readytoidle = 0;
1769#ifndef UNDER_CE
1770
1771        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
1772        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
1773        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
1774#else
1775        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
1776#endif
1777    }
1778
1779    pBufferHeader->pAppPrivate = pAppPrivate;
1780    pBufferHeader->pPlatformPrivate = pComponentPrivate;
1781    pBufferHeader->nAllocLen = nSizeBytes;
1782
1783    pBufferHeader->nVersion.s.nVersionMajor = G726DEC_MAJOR_VER;
1784    pBufferHeader->nVersion.s.nVersionMinor = G726DEC_MINOR_VER;
1785    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
1786    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
1787
1788    *pBuffer = pBufferHeader;
1789    pComponentPrivate->bufAlloced = 1;
1790    G726DEC_DPRINT(":: A Buffer has been alloced\n");
1791
1792 EXIT:
1793    if(OMX_ErrorNone != eError) {
1794        G726DEC_DPRINT("%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__);
1795	 if (pBufferHeader != NULL) {
1796	     G726D_OMX_FREE(pBufferHeader->pBuffer);
1797	     G726D_OMX_FREE(pBufferHeader);
1798	 }
1799    }
1800
1801    return eError;
1802}
1803
1804/* ================================================================================= * */
1805/**
1806 * @fn FreeBuffer() This function frees the meomory of the buffer specified.
1807 *
1808 * @param hComponent  Handle of this component.
1809 *
1810 * @param nPortIndex  Input port or Output port
1811 *
1812 * @param pBuffer  Pointer to the buffer header.
1813 *
1814 * @pre          None
1815 *
1816 * @post        Requested buffer should get the memory allocated.
1817 *
1818 * @return      OMX_ErrorNone = On Success
1819 *              OMX_ErrorBadPortIndex = Bad port index from app
1820 */
1821/* ================================================================================ * */
1822static OMX_ERRORTYPE FreeBuffer(
1823                                OMX_IN  OMX_HANDLETYPE hComponent,
1824                                OMX_IN  OMX_U32 nPortIndex,
1825                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
1826{
1827    OMX_ERRORTYPE eError = OMX_ErrorNone;
1828    G726DEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
1829    OMX_U8* buff = NULL;
1830    int i = 0;
1831    int inputIndex = -1;
1832    int outputIndex = -1;
1833    OMX_COMPONENTTYPE *pHandle = 0;
1834
1835    G726DEC_DPRINT ("Entering FreeBuffer\n");
1836
1837    pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)
1838        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
1839
1840    pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
1841    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
1842        buff = (OMX_U8 *)pComponentPrivate->pInputBufferList->pBufHdr[i];
1843        if (buff == (OMX_U8 *)pBuffer) {
1844            G726DEC_DPRINT("Found matching input buffer\n");
1845            G726DEC_DPRINT("buff = %p\n",buff);
1846            G726DEC_DPRINT("pBuffer = %p\n",pBuffer);
1847            inputIndex = i;
1848            break;
1849        }else{
1850            G726DEC_DPRINT("%d:: No matching found for pBuffer %p\n",__LINE__,pBuffer);
1851        }
1852    }
1853
1854    for (i=0; i < MAX_NUM_OF_BUFS; i++) {
1855        buff = (OMX_U8 *)pComponentPrivate->pOutputBufferList->pBufHdr[i];
1856        if (buff == (OMX_U8 *)pBuffer) {
1857            G726DEC_DPRINT("Found matching output buffer\n");
1858            G726DEC_DPRINT("buff = %p\n",buff);
1859            G726DEC_DPRINT("pBuffer = %p\n",pBuffer);
1860            outputIndex = i;
1861            break;
1862        }else{
1863            G726DEC_DPRINT("%d:: No matching found for pBuffer %p\n",__LINE__,pBuffer);
1864        }
1865    }
1866
1867
1868    if (inputIndex != -1) {
1869        if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
1870            buff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
1871            if(buff != 0){
1872                buff -= 128;
1873            }
1874            G726DEC_MEMPRINT("\n: Freeing:  %p IP Buffer\n",buff);
1875            G726D_OMX_FREE(buff);
1876        }
1877
1878        G726DEC_MEMPRINT("Freeing: %p IP Buf Header\n\n",
1879                         pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
1880
1881        G726D_OMX_FREE(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
1882        pComponentPrivate->pInputBufferList->numBuffers--;
1883
1884        if (pComponentPrivate->pInputBufferList->numBuffers <
1885            pComponentPrivate->pPortDef[G726D_INPUT_PORT]->nBufferCountMin) {
1886            pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated = OMX_FALSE;
1887        }
1888        if(pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled &&
1889           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1890           (pComponentPrivate->curState == OMX_StateIdle ||
1891            pComponentPrivate->curState == OMX_StateExecuting ||
1892            pComponentPrivate->curState == OMX_StatePause)) {
1893
1894            pComponentPrivate->cbInfo.EventHandler(
1895                                                   pHandle, pHandle->pApplicationPrivate,
1896                                                   OMX_EventError, OMX_ErrorPortUnpopulated,nPortIndex, NULL);
1897        }
1898    } else if (outputIndex != -1) {
1899        if (pComponentPrivate->pOutputBufferList->bBufferPending[outputIndex]) {
1900            pComponentPrivate->numPendingBuffers++;
1901        }
1902        if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
1903            buff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
1904            if(buff != 0){
1905                buff -= 128;
1906            }
1907            G726DEC_MEMPRINT("Freeing: %p OP Buffer\n",buff);
1908            G726D_OMX_FREE(buff);
1909        }
1910
1911        G726DEC_MEMPRINT("Freeing: %p OP Buf Header\n\n",
1912                         pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
1913
1914        G726D_OMX_FREE(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
1915        pComponentPrivate->pOutputBufferList->numBuffers--;
1916
1917        G726DEC_DPRINT("pComponentPrivate->pOutputBufferList->numBuffers = %ld\n",
1918                       pComponentPrivate->pOutputBufferList->numBuffers);
1919        G726DEC_DPRINT("pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nBufferCountMin = %ld\n",
1920                       pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nBufferCountMin);
1921
1922        if (pComponentPrivate->pOutputBufferList->numBuffers <
1923            pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->nBufferCountMin) {
1924            pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated = OMX_FALSE;
1925        }
1926
1927        if(pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled &&
1928           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
1929           (pComponentPrivate->curState == OMX_StateIdle ||
1930            pComponentPrivate->curState == OMX_StateExecuting ||
1931            pComponentPrivate->curState == OMX_StatePause)) {
1932            pComponentPrivate->cbInfo.EventHandler(
1933                                                   pHandle, pHandle->pApplicationPrivate,
1934                                                   OMX_EventError, OMX_ErrorPortUnpopulated,nPortIndex, NULL);
1935        }
1936    } else {
1937        G726DEC_DPRINT("Returning OMX_ErrorBadParameter\n");
1938        eError = OMX_ErrorBadParameter;
1939    }
1940
1941    if ((!pComponentPrivate->pInputBufferList->numBuffers &&
1942         !pComponentPrivate->pOutputBufferList->numBuffers) &&
1943        pComponentPrivate->InIdle_goingtoloaded){
1944        pComponentPrivate->InIdle_goingtoloaded = 0;
1945#ifndef UNDER_CE
1946        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
1947        pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
1948        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
1949#else
1950        OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
1951#endif
1952    }
1953
1954    pComponentPrivate->bufAlloced = 0;
1955    if (pComponentPrivate->bDisableCommandPending && (pComponentPrivate->pInputBufferList->numBuffers +
1956                                                      pComponentPrivate->pOutputBufferList->numBuffers == 0)) {
1957        SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,
1958                     pComponentPrivate->bDisableCommandParam,NULL);
1959    }
1960
1961    G726DEC_DPRINT ("Exiting FreeBuffer\n");
1962    return eError;
1963}
1964
1965
1966/* ================================================================================= * */
1967/**
1968 * @fn UseBuffer() This function is called by application when app allocated the
1969 * memory for the buffer and sends it to application for use of component.
1970 *
1971 * @param hComponent  Handle of this component.
1972 *
1973 * @param ppBufferHdr  Double pointer to the buffer header.
1974 *
1975 * @param nPortIndex  Input port or Output port
1976 *
1977 * @param pAppPrivate Application private data.
1978 *
1979 * @param nSizeBytes Size of the buffer that is to be allocated.
1980 *
1981 * @param pBuffer    Pointer to data buffer which was allocated by the
1982 * application.
1983 *
1984 * @pre          None
1985 *
1986 * @post        None
1987 *
1988 * @return      OMX_ErrorNone = On Success
1989 *              OMX_ErrorBadPortIndex = Bad port index from app
1990 */
1991/* ================================================================================ * */
1992static OMX_ERRORTYPE UseBuffer (
1993                                OMX_IN OMX_HANDLETYPE hComponent,
1994                                OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
1995                                OMX_IN OMX_U32 nPortIndex,
1996                                OMX_IN OMX_PTR pAppPrivate,
1997                                OMX_IN OMX_U32 nSizeBytes,
1998                                OMX_IN OMX_U8* pBuffer)
1999{
2000    OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
2001    G726DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
2002    OMX_ERRORTYPE eError = OMX_ErrorNone;
2003    OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
2004
2005    G726DEC_DPRINT ("Entering UseBuffer\n");
2006    G726DEC_DPRINT ("pBuffer = %p\n",pBuffer);
2007
2008    pComponentPrivate = (G726DEC_COMPONENT_PRIVATE *)
2009        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
2010
2011    pPortDef = ((G726DEC_COMPONENT_PRIVATE*)
2012                pComponentPrivate)->pPortDef[nPortIndex];
2013    G726DEC_DPRINT ("pPortDef = %p\n", pPortDef);
2014    G726DEC_DPRINT ("pPortDef->bEnabled = %d\n",pPortDef->bEnabled);
2015
2016    if(!pPortDef->bEnabled) {
2017        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorIncorrectStateOperation,
2018                             "Port is Disabled: OMX_ErrorIncorrectStateOperation");
2019    }
2020#if 1
2021    if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) {
2022        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,
2023                             "Bad Size or Port Disabled : OMX_ErrorBadParameter");
2024    }
2025#endif
2026
2027#if 0
2028    if(pPortDef->bPopulated) {
2029        G726D_OMX_ERROR_EXIT(eError,OMX_ErrorBadParameter,
2030                             "Bad Size or Port Disabled : OMX_ErrorBadParameter");
2031    }
2032#endif
2033
2034    G726D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
2035
2036    if (nPortIndex == G726D_OUTPUT_PORT) {
2037        pBufferHeader->nInputPortIndex = -1;
2038        pBufferHeader->nOutputPortIndex = nPortIndex;
2039
2040        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
2041        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
2042        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
2043        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
2044            pPortDef->bPopulated = OMX_TRUE;
2045        }
2046    }
2047    else {
2048        pBufferHeader->nInputPortIndex = nPortIndex;
2049        pBufferHeader->nOutputPortIndex = -1;
2050
2051        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
2052        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
2053        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0;
2054        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
2055            pPortDef->bPopulated = OMX_TRUE;
2056        }
2057    }
2058
2059    if((pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bPopulated ==
2060        pComponentPrivate->pPortDef[G726D_OUTPUT_PORT]->bEnabled)&&
2061       (pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bPopulated ==
2062        pComponentPrivate->pPortDef[G726D_INPUT_PORT]->bEnabled) &&
2063       (pComponentPrivate->InLoaded_readytoidle)) {
2064        pComponentPrivate->InLoaded_readytoidle = 0;
2065#ifndef UNDER_CE
2066
2067        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
2068        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
2069        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
2070#else
2071        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
2072#endif
2073    }
2074
2075    pBufferHeader->pAppPrivate = pAppPrivate;
2076    pBufferHeader->pPlatformPrivate = pComponentPrivate;
2077    pBufferHeader->nAllocLen = nSizeBytes;
2078
2079    pBufferHeader->nVersion.s.nVersionMajor = G726DEC_MAJOR_VER;
2080    pBufferHeader->nVersion.s.nVersionMinor = G726DEC_MINOR_VER;
2081    pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
2082
2083    pBufferHeader->pBuffer = pBuffer;
2084    pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
2085    *ppBufferHdr = pBufferHeader;
2086    pComponentPrivate->bufAlloced = 1;
2087
2088 EXIT:
2089    return eError;
2090}
2091
2092/* ================================================================================= */
2093/**
2094 * @fn GetExtensionIndex() description for GetExtensionIndex
2095 GetExtensionIndex().
2096 Returns index for vendor specific settings.
2097 *
2098 *  @see         OMX_Core.h
2099 */
2100/* ================================================================================ */
2101static OMX_ERRORTYPE GetExtensionIndex(
2102                                       OMX_IN  OMX_HANDLETYPE hComponent,
2103                                       OMX_IN  OMX_STRING cParameterName,
2104                                       OMX_OUT OMX_INDEXTYPE* pIndexType)
2105{
2106    OMX_ERRORTYPE eError = OMX_ErrorNone;
2107
2108    G726DEC_DPRINT("GetExtensionIndex\n");
2109    if (!(strcmp(cParameterName,"OMX.TI.index.config.g726headerinfo"))) {
2110        *pIndexType = OMX_IndexCustomG726DecHeaderInfoConfig;
2111        G726DEC_DPRINT("OMX_IndexCustomG726DecHeaderInfoConfig\n");
2112    }
2113    else if(!(strcmp(cParameterName,"OMX.TI.index.config.g726decstreamIDinfo"))){
2114        *pIndexType = OMX_IndexCustomG726DecStreamIDConfig;
2115        G726DEC_DPRINT("OMX_IndexCustomG726DecStreamIDConfig\n");
2116    }
2117    else if(!(strcmp(cParameterName,"OMX.TI.index.config.g726dec.datapath"))) {
2118        *pIndexType = OMX_IndexCustomG726DecDataPath;
2119        G726DEC_DPRINT("OMX_IndexCustomG726DecDataPath\n");
2120    }
2121    else {
2122        eError = OMX_ErrorBadParameter;
2123    }
2124
2125    G726DEC_DPRINT("Exiting GetExtensionIndex\n");
2126    return eError;
2127}
2128
2129/* ================================================================================= */
2130/**
2131 * @fn ComponentRoleEnum() description for ComponentRoleEnum()
2132
2133 Returns the role at the given index
2134 *
2135 *  @see         OMX_Core.h
2136 */
2137/* ================================================================================ */
2138static OMX_ERRORTYPE ComponentRoleEnum(
2139                                       OMX_IN OMX_HANDLETYPE hComponent,
2140                                       OMX_OUT OMX_U8 *cRole,
2141                                       OMX_IN OMX_U32 nIndex)
2142{
2143    OMX_ERRORTYPE eError = OMX_ErrorNotImplemented;
2144
2145    return eError;
2146}
2147#ifdef UNDER_CE
2148/* ================================================================================= */
2149/**
2150 * @fns Sleep replace for WIN CE
2151 */
2152/* ================================================================================ */
2153int OMX_CreateEvent(OMX_Event *event){
2154    int ret = OMX_ErrorNone;
2155    HANDLE createdEvent = NULL;
2156    if(event == NULL){
2157        ret = OMX_ErrorBadParameter;
2158        MP3DEC_EPRINT("OMX_CreateEvent: OMX_ErrorBadParameter\n");
2159        goto EXIT;
2160    }
2161    event->event  = CreateEvent(NULL, TRUE, FALSE, NULL);
2162    if(event->event == NULL)
2163        ret = (int)GetLastError();
2164 EXIT:
2165    return ret;
2166}
2167
2168int OMX_SignalEvent(OMX_Event *event){
2169    int ret = OMX_ErrorNone;
2170    if(event == NULL){
2171        ret = OMX_ErrorBadParameter;
2172        MP3DEC_EPRINT("OMX_CreateEvent: OMX_ErrorBadParameter\n");
2173        goto EXIT;
2174    }
2175    SetEvent(event->event);
2176    ret = (int)GetLastError();
2177 EXIT:
2178    return ret;
2179}
2180
2181int OMX_WaitForEvent(OMX_Event *event) {
2182    int ret = OMX_ErrorNone;
2183    if(event == NULL){
2184        ret = OMX_ErrorBadParameter;
2185        MP3DEC_EPRINT("OMX_CreateEvent: OMX_ErrorBadParameter\n");
2186        goto EXIT;
2187    }
2188    WaitForSingleObject(event->event, INFINITE);
2189    ret = (int)GetLastError();
2190 EXIT:
2191    return ret;
2192}
2193
2194int OMX_DestroyEvent(OMX_Event *event) {
2195    int ret = OMX_ErrorNone;
2196    if(event == NULL){
2197        ret = OMX_ErrorBadParameter;
2198        MP3DEC_EPRINT("OMX_CreateEvent: OMX_ErrorBadParameter\n");
2199        goto EXIT;
2200    }
2201    CloseHandle(event->event);
2202 EXIT:
2203    return ret;
2204}
2205#endif
2206