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_AmrDec_Utils.c
30 *
31 * This file implements OMX Component for PCM decoder that
32 * is fully compliant with the OMX Audio specification.
33 *
34 * @path $(CSLPATH)\
35 *
36 * @rev 0.1
37 */
38 /* ----------------------------------------------------------------------------*/
39
40 /* ------compilation control switches -------------------------*/
41 /****************************************************************
42 * INCLUDE FILES
43 ****************************************************************/
44 /* ----- system and platform files ----------------------------*/
45 #ifdef UNDER_CE
46 #include <windows.h>
47 #include <oaf_osal.h>
48 #include <omx_core.h>
49 #include <stdlib.h>
50 #else
51 #include <wchar.h>
52 #include <unistd.h>
53 #include <sys/types.h>
54 #include <sys/wait.h>
55 #include <sys/types.h>
56 #include <sys/stat.h>
57 #include <dlfcn.h>
58 #include <malloc.h>
59 #include <memory.h>
60 #include <fcntl.h>
61 #include <errno.h>
62 #include <dlfcn.h>
63 #endif
64 #include <dbapi.h>
65 #include <string.h>
66 #include <stdio.h>
67 #include "OMX_AmrDecoder.h"
68 #include "OMX_AmrDec_Utils.h"
69 #include "amrdecsocket_ti.h"
70 #include <decode_common_ti.h>
71 #include "OMX_AmrDec_ComponentThread.h"
72 #include "usn.h"
73 #include "LCML_DspCodec.h"
74
75 #ifdef RESOURCE_MANAGER_ENABLED
76 #include <ResourceManagerProxyAPI.h>
77 #endif
78
79 /* Log for Android system*/
80 #include <utils/Log.h>
81
82 /* ======================================================================= */
83 /**
84 * @def DASF Defines the value for identify DASF ON
85 */
86 /* ======================================================================= */
87 #define DASF 1
88
89 #ifdef UNDER_CE
sleep(DWORD Duration)90 void sleep(DWORD Duration)
91 {
92 Sleep(Duration);
93
94 }
95 #endif
96
97 /* ========================================================================== */
98 /**
99 * @NBAMRDECFill_LCMLInitParams () This function is used by the component thread to
100 * fill the all of its initialization parameters, buffer deatils etc
101 * to LCML structure,
102 *
103 * @param pComponent handle for this instance of the component
104 * @param plcml_Init pointer to LCML structure to be filled
105 *
106 * @pre
107 *
108 * @post
109 *
110 * @return none
111 */
112 /* ========================================================================== */
NBAMRDECFill_LCMLInitParams(OMX_HANDLETYPE pComponent,LCML_DSP * plcml_Init,OMX_U16 arr[])113 OMX_ERRORTYPE NBAMRDECFill_LCMLInitParams(OMX_HANDLETYPE pComponent,
114 LCML_DSP *plcml_Init, OMX_U16 arr[])
115 {
116
117 OMX_ERRORTYPE eError = OMX_ErrorNone;
118 OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
119 OMX_U16 i;
120 OMX_BUFFERHEADERTYPE *pTemp;
121 OMX_U32 size_lcml;
122 LCML_STRMATTR *strmAttr = NULL;
123 LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
124 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
125 LCML_NBAMRDEC_BUFHEADERTYPE *pTemp_lcml;
126 char *ptr;
127
128 pComponentPrivate = pHandle->pComponentPrivate;
129 OMX_PRINT1 (pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECFill_LCMLInitParams\n ",__LINE__);
130
131 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
132 pComponentPrivate->nRuntimeInputBuffers = nIpBuf;
133
134 if(pComponentPrivate->mimemode == 1)
135 {
136 nIpBufSize = INPUT_NBAMRDEC_BUFFER_SIZE_MIME;
137 }
138 else if (pComponentPrivate->mimemode == 2)
139 {
140 nIpBufSize = INPUT_NBAMRDEC_BUFFER_SIZE_IF2;
141 }
142 else
143 {
144 if (OMX_AUDIO_AMRDTXasEFR == pComponentPrivate->iAmrMode)
145 {
146 nIpBufSize = INPUT_BUFF_SIZE_EFR;
147 }
148 else{
149 nIpBufSize = STD_NBAMRDEC_BUF_SIZE;
150 }
151 }
152
153 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
154 pComponentPrivate->nRuntimeOutputBuffers = nOpBuf;
155
156 nOpBufSize = OUTPUT_NBAMRDEC_BUFFER_SIZE;
157
158
159 /* Fill Input Buffers Info for LCML */
160 plcml_Init->In_BufInfo.nBuffers = nIpBuf;
161 plcml_Init->In_BufInfo.nSize = nIpBufSize;
162 plcml_Init->In_BufInfo.DataTrMethod = DMM_METHOD;
163
164
165 /* Fill Output Buffers Info for LCML */
166 plcml_Init->Out_BufInfo.nBuffers = nOpBuf;
167 plcml_Init->Out_BufInfo.nSize = nOpBufSize;
168 plcml_Init->Out_BufInfo.DataTrMethod = DMM_METHOD;
169
170 /*Copy the node information */
171 plcml_Init->NodeInfo.nNumOfDLLs = 3;
172
173 plcml_Init->NodeInfo.AllUUIDs[0].uuid = &AMRDECSOCKET_TI_UUID;
174
175 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName,NBAMRDEC_DLL_NAME);
176
177 plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
178
179 plcml_Init->NodeInfo.AllUUIDs[1].uuid = &AMRDECSOCKET_TI_UUID;
180 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName,NBAMRDEC_DLL_NAME);
181 plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
182
183 plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID;
184 strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[2].DllName,NBAMRDEC_USN_DLL_NAME);
185 plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
186
187
188 if(pComponentPrivate->dasfmode == 1) {
189 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pComponentPrivate->dasfmode = %d\n",__LINE__,pComponentPrivate->dasfmode);
190 OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
191
192 pComponentPrivate->strmAttr = strmAttr;
193 strmAttr->uSegid = 0;
194 strmAttr->uAlignment = 0;
195 strmAttr->uTimeout = NBAMRD_TIMEOUT;
196 strmAttr->uBufsize = OUTPUT_NBAMRDEC_BUFFER_SIZE;
197 strmAttr->uNumBufs = 2;
198 strmAttr->lMode = STRMMODE_PROCCOPY;
199 plcml_Init->DeviceInfo.TypeofDevice =1;
200 plcml_Init->DeviceInfo.TypeofRender =0;
201 if(pComponentPrivate->acdnmode == 1)
202 {
203 /* ACDN mode */
204 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &ACDN_TI_UUID;
205 }
206 else
207 {
208 /* DASF/TeeDN mode */
209 plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &MMMDN_TI_UUID;
210 }
211 plcml_Init->DeviceInfo.DspStream = strmAttr;
212 }
213 else {
214 pComponentPrivate->strmAttr = NULL;
215 }
216
217
218 /*copy the other information */
219 plcml_Init->SegID = OMX_AMRDEC_DEFAULT_SEGMENT;
220 plcml_Init->Timeout = OMX_AMRDEC_SN_TIMEOUT;
221 plcml_Init->Alignment = 0;
222 plcml_Init->Priority = OMX_AMRDEC_SN_PRIORITY;
223 plcml_Init->ProfileID = -1;
224
225 /* TODO: Set this using SetParameter() */
226 pComponentPrivate->iAmrSamplingFrequeny = NBAMRDEC_SAMPLING_FREQUENCY;
227
228 pComponentPrivate->iAmrChannels = pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT]->nChannels;
229
230 pComponentPrivate->iAmrMode =
231 pComponentPrivate->amrParams[NBAMRDEC_INPUT_PORT]->eAMRDTXMode;
232
233 /*if(pComponentPrivate->mimemode == 1)
234 {
235 pComponentPrivate->iAmrMimeFlag = MODE_MIME;
236 } else {
237 pComponentPrivate->iAmrMimeFlag = MODE_NONMIME;
238 }*/
239
240 arr[0] = STREAM_COUNT;
241 arr[1] = NBAMRDEC_INPUT_PORT;
242 arr[2] = NBAMRDEC_DMM;
243 OMX_PRINT2(pComponentPrivate->dbg, "%s: IN %d", __FUNCTION__, pComponentPrivate->pOutputBufferList->numBuffers);
244 if (pComponentPrivate->pInputBufferList->numBuffers) {
245 arr[3] = pComponentPrivate->pInputBufferList->numBuffers;
246 }
247 else {
248 arr[3] = 1;
249 }
250
251 arr[4] = NBAMRDEC_OUTPUT_PORT;
252
253 if(pComponentPrivate->dasfmode == 1) {
254 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Setting up create phase params for DASF mode\n",__LINE__);
255 arr[5] = NBAMRDEC_OUTSTRM;
256 arr[6] = NUM_NBAMRDEC_OUTPUT_BUFFERS_DASF;
257 }
258 else {
259 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Setting up create phase params for FILE mode\n",__LINE__);
260 arr[5] = NBAMRDEC_DMM;
261 OMX_PRINT2(pComponentPrivate->dbg, "%s: OUT : %d", __FUNCTION__, pComponentPrivate->pOutputBufferList->numBuffers);
262
263 if (pComponentPrivate->pOutputBufferList->numBuffers) {
264 arr[6] = pComponentPrivate->pOutputBufferList->numBuffers;
265 }
266 else {
267 arr[6] = 2;
268 }
269
270 }
271
272 if(pComponentPrivate->iAmrMode == OMX_AUDIO_AMRDTXasEFR) {
273 arr[7] = NBAMRDEC_EFR;
274 }
275 else {
276 arr[7] = NBAMR;
277 }
278
279 /*if(1 == pComponentPrivate->mimemode) {
280 arr[8] = NBAMRDEC_MIMEMODE;
281 }
282 else {
283 arr[8] = NBAMRDEC_NONMIMEMODE;
284 }
285 */
286 arr[8] = pComponentPrivate->mimemode; /*MIME, IF2 or FORMATCONFORMANCE*/
287 arr[9] = END_OF_CR_PHASE_ARGS;
288
289 plcml_Init->pCrPhArgs = arr;
290
291 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
292 size_lcml = nIpBuf * sizeof(LCML_NBAMRDEC_BUFHEADERTYPE);
293 OMX_MALLOC_SIZE(ptr, size_lcml,char);
294 pTemp_lcml = (LCML_NBAMRDEC_BUFHEADERTYPE *)ptr;
295 pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT] = pTemp_lcml;
296
297 for (i=0; i<nIpBuf; i++) {
298 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
299 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
300 /* pTemp->nAllocLen = nIpBufSize;*/
301 pTemp->nFilledLen = nIpBufSize;
302 pTemp->nVersion.s.nVersionMajor = AMRDEC_MAJOR_VER;
303 pTemp->nVersion.s.nVersionMinor = AMRDEC_MINOR_VER;
304 pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
305 pTemp->nTickCount = NOT_USED;
306 pTemp_lcml->buffer = pTemp;
307 pTemp_lcml->eDir = OMX_DirInput;
308
309 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
310 sizeof(NBAMRDEC_ParamStruct),
311 NBAMRDEC_ParamStruct);
312
313 pTemp_lcml->pBufferParam->usNbFrames =0;
314 pTemp_lcml->pBufferParam->pParamElem = NULL;
315 pTemp_lcml->pFrameParam = NULL;
316 OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
317
318 /* This means, it is not a last buffer. This flag is to be modified by
319 * the application to indicate the last buffer */
320 pTemp->nFlags = NORMAL_BUFFER;
321
322 pTemp_lcml++;
323 }
324
325 /* Allocate memory for all output buffer headers..
326 * This memory pointer will be sent to LCML */
327 size_lcml = nOpBuf * sizeof(LCML_NBAMRDEC_BUFHEADERTYPE);
328 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,LCML_NBAMRDEC_BUFHEADERTYPE);
329 pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT] = pTemp_lcml;
330
331 for (i=0; i<nOpBuf; i++) {
332 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
333 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
334 /* pTemp->nAllocLen = nOpBufSize;*/
335 pTemp->nFilledLen = nOpBufSize;
336 pTemp->nVersion.s.nVersionMajor = AMRDEC_MAJOR_VER;
337 pTemp->nVersion.s.nVersionMinor = AMRDEC_MINOR_VER;
338 pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
339 pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
340 pTemp->nTickCount = NOT_USED;
341 /* This means, it is not a last buffer. This flag is to be modified by
342 * the application to indicate the last buffer */
343
344 pTemp_lcml->buffer = pTemp;
345 pTemp_lcml->eDir = OMX_DirOutput;
346 pTemp_lcml->pFrameParam = NULL;
347
348 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
349 sizeof(NBAMRDEC_ParamStruct),
350 NBAMRDEC_ParamStruct);
351
352 pTemp_lcml->pBufferParam->usNbFrames =0;
353 pTemp_lcml->pBufferParam->pParamElem = NULL;
354 OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
355
356 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::pTemp_lcml = %p\n",__LINE__,pTemp_lcml);
357 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::pTemp_lcml->buffer = %p\n",__LINE__,pTemp_lcml->buffer);
358
359 pTemp->nFlags = NORMAL_BUFFER;
360
361 pTemp++;
362 pTemp_lcml++;
363 }
364 pComponentPrivate->bPortDefsAllocated = 1;
365 #ifdef __PERF_INSTRUMENTATION__
366 pComponentPrivate->nLcml_nCntIp = 0;
367 pComponentPrivate->nLcml_nCntOpReceived = 0;
368 #endif
369
370 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Exiting NBAMRDECFill_LCMLInitParams\n",__LINE__);
371
372 pComponentPrivate->bInitParamsInitialized = 1;
373 EXIT:
374
375 return eError;
376 }
377
378
379 /* ========================================================================== */
380 /**
381 * @NBAMRDEC_StartComponentThread() This function is called by the component to create
382 * the component thread, command pipe, data pipe and LCML Pipe.
383 *
384 * @param pComponent handle for this instance of the component
385 *
386 * @pre
387 *
388 * @post
389 *
390 * @return none
391 */
392 /* ========================================================================== */
NBAMRDEC_StartComponentThread(OMX_HANDLETYPE pComponent)393 OMX_ERRORTYPE NBAMRDEC_StartComponentThread(OMX_HANDLETYPE pComponent)
394 {
395 OMX_ERRORTYPE eError = OMX_ErrorNone;
396 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
397 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate =
398 (AMRDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
399 #ifdef UNDER_CE
400 pthread_attr_t attr;
401 memset(&attr, 0, sizeof(attr));
402 attr.__inheritsched = PTHREAD_EXPLICIT_SCHED;
403 attr.__schedparam.__sched_priority = OMX_AUDIO_DECODER_THREAD_PRIORITY;
404 #endif
405
406 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDEC_StartComponentThread\n", __LINE__);
407
408 /* Initialize all the variables*/
409 pComponentPrivate->bIsStopping = 0;
410 pComponentPrivate->lcml_nOpBuf = 0;
411 pComponentPrivate->lcml_nIpBuf = 0;
412 pComponentPrivate->app_nBuf = 0;
413 pComponentPrivate->num_Reclaimed_Op_Buff = 0;
414 pComponentPrivate->first_output_buf_rcv = 0;
415
416 /* create the pipe used to send buffers to the thread */
417 eError = pipe (pComponentPrivate->cmdDataPipe);
418 if (eError) {
419 eError = OMX_ErrorInsufficientResources;
420 goto EXIT;
421 }
422
423 /* create the pipe used to send buffers to the thread */
424 eError = pipe (pComponentPrivate->dataPipe);
425 if (eError) {
426 eError = OMX_ErrorInsufficientResources;
427 goto EXIT;
428 }
429
430 /* create the pipe used to send commands to the thread */
431 eError = pipe (pComponentPrivate->cmdPipe);
432 if (eError) {
433 eError = OMX_ErrorInsufficientResources;
434 goto EXIT;
435 }
436
437 /* create the pipe used to send commands to the thread */
438 /* eError = pipe (pComponentPrivate->lcml_Pipe);
439 if (eError) {
440 eError = OMX_ErrorInsufficientResources;
441 goto EXIT;
442 }
443 */
444 /* Create the Component Thread */
445 #ifdef UNDER_CE
446 eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr, NBAMRDEC_ComponentThread, pComponentPrivate);
447 #else
448 eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL, NBAMRDEC_ComponentThread, pComponentPrivate);
449 #endif
450 if (eError || !pComponentPrivate->ComponentThread) {
451 eError = OMX_ErrorInsufficientResources;
452 goto EXIT;
453 }
454 pComponentPrivate->bCompThreadStarted = 1;
455 EXIT:
456 return eError;
457 }
458
459 /* ========================================================================== */
460 /**
461 * @Mp3Dec_FreeCompResources() This function is called by the component during
462 * de-init to close component thread, Command pipe, data pipe & LCML pipe.
463 *
464 * @param pComponent handle for this instance of the component
465 *
466 * @pre
467 *
468 * @post
469 *
470 * @return none
471 */
472 /* ========================================================================== */
473
NBAMRDEC_FreeCompResources(OMX_HANDLETYPE pComponent)474 OMX_ERRORTYPE NBAMRDEC_FreeCompResources(OMX_HANDLETYPE pComponent)
475 {
476 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
477 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)
478 pHandle->pComponentPrivate;
479
480 OMX_ERRORTYPE eError = OMX_ErrorNone;
481 OMX_ERRORTYPE err = OMX_ErrorNone;
482 OMX_U32 nIpBuf = 0;
483 OMX_U32 nOpBuf = 0;
484
485 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDEC_FreeCompResources\n", __LINE__);
486
487 if (pComponentPrivate->bPortDefsAllocated) {
488 nIpBuf = pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->nBufferCountActual;
489 nOpBuf = pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->nBufferCountActual;
490 }
491
492 if (pComponentPrivate->bCompThreadStarted) {
493 err = close (pComponentPrivate->dataPipe[0]);
494
495 if (0 != err && OMX_ErrorNone == eError) {
496 eError = OMX_ErrorHardware;
497 }
498
499 err = close (pComponentPrivate->dataPipe[1]);
500 if (0 != err && OMX_ErrorNone == eError) {
501 eError = OMX_ErrorHardware;
502 }
503
504 err = close (pComponentPrivate->cmdPipe[0]);
505 if (0 != err && OMX_ErrorNone == eError) {
506 eError = OMX_ErrorHardware;
507 }
508
509 err = close (pComponentPrivate->cmdPipe[1]);
510 if (0 != err && OMX_ErrorNone == eError) {
511 eError = OMX_ErrorHardware;
512 }
513
514 err = close (pComponentPrivate->cmdDataPipe[0]);
515 if (0 != err && OMX_ErrorNone == eError) {
516 eError = OMX_ErrorHardware;
517 }
518
519 err = close (pComponentPrivate->cmdDataPipe[1]);
520 if (0 != err && OMX_ErrorNone == eError) {
521 eError = OMX_ErrorHardware;
522 }
523
524 /* err = close (pComponentPrivate->lcml_Pipe[0]);
525 if (0 != err && OMX_ErrorNone == eError) {
526 eError = OMX_ErrorHardware;
527 }
528
529 err = close (pComponentPrivate->lcml_Pipe[1]);
530 if (0 != err && OMX_ErrorNone == eError) {
531 eError = OMX_ErrorHardware;
532 } */
533
534 }
535 OMX_MEMFREE_STRUCT(pComponentPrivate->pPriorityMgmt);
536 OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
537 OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]);
538 OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]);
539 OMX_MEMFREE_STRUCT(pComponentPrivate->amrParams[NBAMRDEC_INPUT_PORT]);
540 OMX_MEMFREE_STRUCT(pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT]);
541
542 pComponentPrivate->bPortDefsAllocated = 0;
543 /* Removing sleep() calls. */
544 #ifndef UNDER_CE
545 OMX_PRDSP2(pComponentPrivate->dbg, "\n\n FreeCompResources: Destroying mutexes.\n\n");
546 pthread_mutex_destroy(&pComponentPrivate->InLoaded_mutex);
547 pthread_cond_destroy(&pComponentPrivate->InLoaded_threshold);
548
549 pthread_mutex_destroy(&pComponentPrivate->InIdle_mutex);
550 pthread_cond_destroy(&pComponentPrivate->InIdle_threshold);
551
552 pthread_mutex_destroy(&pComponentPrivate->AlloBuf_mutex);
553 pthread_cond_destroy(&pComponentPrivate->AlloBuf_threshold);
554 #else
555 pComponentPrivate->bPortDefsAllocated = 0;
556 OMX_DestroyEvent(&(pComponentPrivate->InLoaded_event));
557 OMX_DestroyEvent(&(pComponentPrivate->InIdle_event));
558 OMX_DestroyEvent(&(pComponentPrivate->AlloBuf_event));
559 #endif
560 /* Removing sleep() calls. */
561 return eError;
562 }
563
564
565
NBAMRDEC_CleanupInitParams(OMX_HANDLETYPE pComponent)566 OMX_ERRORTYPE NBAMRDEC_CleanupInitParams(OMX_HANDLETYPE pComponent)
567 {
568 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
569 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)
570 pHandle->pComponentPrivate;
571
572 LCML_NBAMRDEC_BUFHEADERTYPE *pTemp_lcml;
573
574 OMX_ERRORTYPE eError = OMX_ErrorNone;
575 OMX_U32 nIpBuf = 0;
576 OMX_U16 i=0;
577 LCML_DSP_INTERFACE *pLcmlHandle;
578 LCML_DSP_INTERFACE *pLcmlHandleAux;
579
580 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDEC_CleanupInitParams()\n", __LINE__);
581
582 OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
583
584 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams,AMRDEC_AudioCodecParams);
585
586 nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
587 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT];
588 for(i=0; i<nIpBuf; i++) {
589 if(pTemp_lcml->pFrameParam!=NULL){
590 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, NBAMRDEC_FrameStruct);
591 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
592 pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
593 OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc,
594 (void*)pTemp_lcml->pBufferParam->pParamElem,
595 pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
596 }
597 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, NBAMRDEC_ParamStruct);
598 OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
599 pTemp_lcml++;
600 }
601
602 pTemp_lcml = pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT];
603 for(i=0; i<pComponentPrivate->nRuntimeOutputBuffers; i++){
604 if(pTemp_lcml->pFrameParam!=NULL){
605 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, NBAMRDEC_FrameStruct);
606 pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
607 pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
608 OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc,
609 (void*)pTemp_lcml->pBufferParam->pParamElem,
610 pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
611 }
612 OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, NBAMRDEC_ParamStruct);
613 OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
614 pTemp_lcml++;
615 }
616 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT]);
617 OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT]);
618 return eError;
619 }
620
621 /* ========================================================================== */
622 /**
623 * @NBAMRDEC_StopComponentThread() This function is called by the component during
624 * de-init to close component thread, Command pipe, data pipe & LCML pipe.
625 *
626 * @param pComponent handle for this instance of the component
627 *
628 * @pre
629 *
630 * @post
631 *
632 * @return none
633 */
634 /* ========================================================================== */
635
NBAMRDEC_StopComponentThread(OMX_HANDLETYPE pComponent)636 OMX_ERRORTYPE NBAMRDEC_StopComponentThread(OMX_HANDLETYPE pComponent)
637 {
638 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
639 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)
640 pHandle->pComponentPrivate;
641
642 OMX_ERRORTYPE eError = OMX_ErrorNone;
643 OMX_ERRORTYPE threadError = OMX_ErrorNone;
644 OMX_S16 pthreadError = 0;
645
646 /*Join the component thread */
647 pComponentPrivate->bIsStopping = 1;
648 write (pComponentPrivate->cmdPipe[1], &pComponentPrivate->bIsStopping, sizeof(OMX_U16));
649 pthreadError = pthread_join (pComponentPrivate->ComponentThread,
650 (void*)&threadError);
651 if (0 != pthreadError) {
652 eError = OMX_ErrorHardware;
653 }
654
655 /*Check for the errors */
656 if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError) {
657 eError = OMX_ErrorInsufficientResources;
658 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error while closing Component Thread\n",__LINE__);
659 }
660 return eError;
661 }
662
663
664 /* ========================================================================== */
665 /**
666 * @NBAMRDECHandleCommand() This function is called by the component when ever it
667 * receives the command from the application
668 *
669 * @param pComponentPrivate Component private data
670 *
671 * @pre
672 *
673 * @post
674 *
675 * @return none
676 */
677 /* ========================================================================== */
678
NBAMRDECHandleCommand(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate)679 OMX_U32 NBAMRDECHandleCommand (AMRDEC_COMPONENT_PRIVATE *pComponentPrivate)
680 {
681
682 OMX_COMPONENTTYPE *pHandle;
683 OMX_COMMANDTYPE command;
684 OMX_STATETYPE commandedState;
685 OMX_U32 commandData;
686 OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
687
688 OMX_U16 i;
689 OMX_ERRORTYPE eError = OMX_ErrorNone;
690
691 OMX_U32 nBuf;
692 OMX_U16 arr[100];
693 OMX_STRING p = "hello";
694 LCML_CALLBACKTYPE cb;
695 LCML_DSP *pLcmlDsp;
696 AMRDEC_AudioCodecParams *pParams;
697 ssize_t ret;
698 LCML_NBAMRDEC_BUFHEADERTYPE *pLcmlHdr = NULL;
699 int inputPortFlag=0,outputPortFlag=0;
700 #ifdef RESOURCE_MANAGER_ENABLED
701 OMX_ERRORTYPE rm_error;
702 #endif
703
704 pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
705
706 ret = read (pComponentPrivate->cmdPipe[0], &command, sizeof (command));
707 if (ret == -1) {
708 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error While reading from the Pipe\n",__LINE__);
709 eError = OMX_ErrorHardware;
710 goto EXIT;
711 }
712
713 ret = read (pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData));
714 if (ret == -1) {
715 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error While reading from the Pipe\n",__LINE__);
716 eError = OMX_ErrorHardware;
717 goto EXIT;
718 }
719
720 #ifdef __PERF_INSTRUMENTATION__
721 PERF_ReceivedCommand(pComponentPrivate->pPERFcomp,
722 command,
723 commandData,
724 PERF_ModuleLLMM);
725 #endif
726
727 if (command == OMX_CommandStateSet) {
728 commandedState = (OMX_STATETYPE)commandData;
729 switch(commandedState) {
730 case OMX_StateIdle:
731 if (pComponentPrivate->curState == commandedState){
732 pComponentPrivate->cbInfo.EventHandler (pHandle,
733 pHandle->pApplicationPrivate,
734 OMX_EventError,
735 OMX_ErrorSameState,
736 OMX_TI_ErrorMinor,
737 NULL);
738 }
739 else if (pComponentPrivate->curState == OMX_StateLoaded || pComponentPrivate->curState == OMX_StateWaitForResources) {
740 while (1) {
741 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: In while loop OMX_StateLoaded [NBAMRDEC_INPUT_PORT]->bPopulated %d \n",__LINE__,pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bPopulated);
742 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: In while loop OMX_StateLoaded [NBAMRDEC_INPUT_PORT]->bEnabled %d \n",__LINE__,pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled);
743 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: In while loop OMX_StateLoaded [NBAMRDEC_OUTPUT_PORT]->bPopulated %d \n",__LINE__,pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bPopulated);
744 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: In while loop OMX_StateLoaded [NBAMRDEC_OUTPUT_PORT]->bEnabled %d \n",__LINE__,pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled);
745 #ifdef __PERF_INSTRUMENTATION__
746 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySetup);
747 #endif
748
749 if (pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bPopulated && pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled) {
750 inputPortFlag = 1;
751 }
752
753 if (!pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bPopulated && !pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled) {
754 inputPortFlag = 1;
755 }
756
757 if (pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bPopulated && pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled) {
758 outputPortFlag = 1;
759 }
760
761 if (!pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bPopulated && !pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled) {
762 outputPortFlag = 1;
763 }
764
765 if (inputPortFlag && outputPortFlag) {
766 break;
767 }
768 pComponentPrivate->InLoaded_readytoidle = 1;
769 #ifndef UNDER_CE
770 pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
771 pthread_cond_wait(&pComponentPrivate->InLoaded_threshold, &pComponentPrivate->InLoaded_mutex);
772 pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
773 break;
774 #else
775 OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
776 #endif
777 break;
778 }
779
780 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECHandleCommand\n",__LINE__);
781 cb.LCML_Callback = (void *) NBAMRDECLCML_Callback;
782 pLcmlHandle = (OMX_HANDLETYPE) NBAMRDECGetLCMLHandle(pComponentPrivate);
783 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECHandleCommand\n",__LINE__);
784
785 if (pLcmlHandle == NULL) {
786 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: LCML Handle is NULL........exiting..\n",__LINE__);
787 pComponentPrivate->curState = OMX_StateInvalid;
788 eError = OMX_ErrorHardware;
789 pComponentPrivate->cbInfo.EventHandler(pHandle,
790 pHandle->pApplicationPrivate,
791 OMX_EventError,
792 OMX_ErrorHardware,
793 OMX_TI_ErrorSevere,
794 "Lcml Handle NULL");
795 goto EXIT;
796 }
797 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand\n",__LINE__);
798 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pLcmlHandle = %p\n",__LINE__,pLcmlHandle);
799
800 /* Got handle of dsp via phandle filling information about DSP
801 specific things */
802 pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
803 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pLcmlDsp = %p\n",__LINE__,pLcmlDsp);
804
805 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand\n",__LINE__);
806 eError = NBAMRDECFill_LCMLInitParams(pHandle, pLcmlDsp, arr);
807 if(eError != OMX_ErrorNone) {
808 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error returned from\
809 NBAMRDECFill_LCMLInitParams()\n",__LINE__);
810 pComponentPrivate->curState = OMX_StateInvalid;
811 pComponentPrivate->cbInfo.EventHandler(pHandle,
812 pHandle->pApplicationPrivate,
813 OMX_EventError,
814 eError,
815 OMX_TI_ErrorSevere,
816 NULL);
817 goto EXIT;
818 }
819 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
820 pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
821 /*filling create phase params */
822 cb.LCML_Callback = (void *) NBAMRDECLCML_Callback;
823 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Calling LCML_InitMMCodec...\n",__LINE__);
824
825 #ifndef UNDER_CE
826 /* TeeDN will be default for decoder component */
827 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMR decoder support TeeDN\n",__LINE__);
828
829 eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
830 p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString);
831 #else
832
833 eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
834 p,&pLcmlHandle,(void *)p,&cb);
835
836 #endif
837
838 if(eError != OMX_ErrorNone) {
839 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error returned from\
840 LCML_Init()\n",__LINE__);
841 /* send an event to client */
842 /* client should unload the component if the codec is not able to load */
843 pComponentPrivate->cbInfo.EventHandler (pHandle,
844 pHandle->pApplicationPrivate,
845 OMX_EventError,
846 eError,
847 OMX_TI_ErrorSevere,
848 NULL);
849 goto EXIT;
850 }
851
852 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Setting to OMX_StateIdle\n",__LINE__);
853
854
855 #ifdef RESOURCE_MANAGER_ENABLED
856 /* need check the resource with RM */
857 pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) NBAMR_ResourceManagerCallback;
858 if (pComponentPrivate->curState != OMX_StateWaitForResources) {
859 rm_error = RMProxy_NewSendCommand(pHandle,
860 RMProxy_RequestResource,
861 OMX_NBAMR_Decoder_COMPONENT,
862 NBAMRDEC_CPU_LOAD,
863 3456,
864 &(pComponentPrivate->rmproxyCallback));
865 if(rm_error == OMX_ErrorNone) {
866 /* resource is available */
867 pComponentPrivate->curState = OMX_StateIdle;
868 pComponentPrivate->cbInfo.EventHandler(pHandle,
869 pHandle->pApplicationPrivate,
870 OMX_EventCmdComplete,
871 OMX_CommandStateSet,
872 pComponentPrivate->curState,
873 NULL);
874 rm_error = RMProxy_NewSendCommand(pHandle,
875 RMProxy_StateSet,
876 OMX_NBAMR_Decoder_COMPONENT,
877 OMX_StateIdle,
878 3456,
879 NULL);
880
881 }
882 else if(rm_error == OMX_ErrorInsufficientResources) {
883 /* resource is not available, need set state to OMX_StateWaitForResources */
884 pComponentPrivate->curState = OMX_StateWaitForResources;
885 pComponentPrivate->cbInfo.EventHandler(pHandle,
886 pHandle->pApplicationPrivate,
887 OMX_EventCmdComplete,
888 OMX_CommandStateSet,
889 pComponentPrivate->curState,
890 NULL);
891 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: AMRDEC: Error - insufficient resources\n", __LINE__);
892 }
893 }
894 else {
895 pComponentPrivate->curState = OMX_StateIdle;
896 pComponentPrivate->cbInfo.EventHandler(pHandle,
897 pHandle->pApplicationPrivate,
898 OMX_EventCmdComplete,
899 OMX_CommandStateSet,
900 pComponentPrivate->curState,
901 NULL);
902 rm_error = RMProxy_NewSendCommand(pHandle,
903 RMProxy_StateSet,
904 OMX_NBAMR_Decoder_COMPONENT,
905 OMX_StateIdle,
906 3456,
907 NULL);
908 }
909 #else
910 pComponentPrivate->curState = OMX_StateIdle;
911 pComponentPrivate->cbInfo.EventHandler(pHandle,
912 pHandle->pApplicationPrivate,
913 OMX_EventCmdComplete,
914 OMX_CommandStateSet,
915 pComponentPrivate->curState,
916 NULL);
917 #endif
918 #ifdef __PERF_INSTRUMENTATION__
919 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySetup);
920 #endif
921 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: AMRDEC: State has been Set to Idle\n",
922 __LINE__);
923 if(pComponentPrivate->dasfmode == 1) {
924 OMX_U32 pValues[4];
925 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ---- Comp: DASF Functionality is ON ---\n",__LINE__);
926
927 if(pComponentPrivate->streamID == 0)
928 {
929 OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n");
930 OMX_ERROR4(pComponentPrivate->dbg, ":: Error = OMX_ErrorInsufficientResources\n");
931 OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n");
932 eError = OMX_ErrorInsufficientResources;
933 pComponentPrivate->curState = OMX_StateInvalid;
934 pComponentPrivate->cbInfo.EventHandler( pHandle,
935 pHandle->pApplicationPrivate,
936 OMX_EventError,
937 OMX_ErrorInvalidState,
938 OMX_TI_ErrorMajor,
939 "AM: No Stream ID Available");
940 goto EXIT;
941 }
942
943 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams, sizeof(AMRDEC_AudioCodecParams), AMRDEC_AudioCodecParams);
944
945 pParams = pComponentPrivate->pParams;
946 pParams->iAudioFormat = 1;
947 pParams->iSamplingRate = 8000;
948 pParams->iStrmId = pComponentPrivate->streamID;
949
950 pValues[0] = USN_STRMCMD_SETCODECPARAMS;
951 pValues[1] = (OMX_U32)pParams;
952 pValues[2] = sizeof(AMRDEC_AudioCodecParams);
953 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
954 EMMCodecControlStrmCtrl,(void *)pValues);
955
956 if(eError != OMX_ErrorNone) {
957 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error Occurred in Codec StreamControl..\n",__LINE__);
958 pComponentPrivate->curState = OMX_StateInvalid;
959 pComponentPrivate->cbInfo.EventHandler(pHandle,
960 pHandle->pApplicationPrivate,
961 OMX_EventError,
962 eError,
963 OMX_TI_ErrorSevere,
964 NULL);
965 goto EXIT;
966 }
967 }
968 }
969 else if (pComponentPrivate->curState == OMX_StateExecuting)
970 {
971 OMX_U8 *pArgs = (void*)"damedesuStr";
972 #ifdef __PERF_INSTRUMENTATION__
973 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
974 #endif
975 /*Set the bIsStopping bit */
976 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: AMRDEC: About to set bIsStopping bit\n", __LINE__);
977
978 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: About to call LCML_ControlCodec(STOP)\n",__LINE__);
979 if (pComponentPrivate->codecStop_waitingsignal == 0){
980 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
981 }
982 eError = LCML_ControlCodec(
983 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
984 MMCodecControlStop,(void *)pArgs);
985 if (pComponentPrivate->codecStop_waitingsignal == 0){
986 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
987 pComponentPrivate->codecStop_waitingsignal = 0;
988 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
989 }
990 pComponentPrivate->bStopSent=1;
991 if (pComponentPrivate->pHoldBuffer) {
992 OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
993 }
994 pComponentPrivate->nHoldLength = 0;
995
996 if(eError != OMX_ErrorNone) {
997 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error Occurred in Codec Stop..\n",
998 __LINE__);
999 pComponentPrivate->curState = OMX_StateInvalid;
1000 pComponentPrivate->cbInfo.EventHandler(pHandle,
1001 pHandle->pApplicationPrivate,
1002 OMX_EventError,
1003 eError,
1004 OMX_TI_ErrorSevere,
1005 NULL);
1006 goto EXIT;
1007 }
1008 /* pComponentPrivate->bStopSent=1;
1009 OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
1010 pComponentPrivate->nHoldLength = 0;*/
1011 }
1012 else if(pComponentPrivate->curState == OMX_StatePause) {
1013 OMX_U8 *pArgs = (void*)"damedesuStr";
1014 if (pComponentPrivate->codecStop_waitingsignal == 0){
1015 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
1016 }
1017 eError = LCML_ControlCodec(
1018 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1019 MMCodecControlStop,(void *)pArgs);
1020 if (pComponentPrivate->codecStop_waitingsignal == 0){
1021 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
1022 pComponentPrivate->codecStop_waitingsignal = 0;
1023 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
1024 }
1025
1026 #ifdef __PERF_INSTRUMENTATION__
1027 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
1028 #endif
1029 pComponentPrivate->curState = OMX_StateIdle;
1030 #ifdef RESOURCE_MANAGER_ENABLED
1031 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL);
1032 #endif
1033
1034 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: The component is stopped\n",__LINE__);
1035 pComponentPrivate->cbInfo.EventHandler (
1036 pHandle,pHandle->pApplicationPrivate,
1037 OMX_EventCmdComplete,OMX_CommandStateSet,pComponentPrivate->curState,
1038 NULL);
1039 }
1040 else {
1041 /* This means, it is invalid state from application */
1042 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1043 pComponentPrivate->cbInfo.EventHandler(
1044 pHandle,
1045 pHandle->pApplicationPrivate,
1046 OMX_EventError,
1047 OMX_ErrorIncorrectStateTransition,
1048 OMX_TI_ErrorMinor,
1049 "Invalid State");
1050 }
1051 break;
1052
1053 case OMX_StateExecuting:
1054 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand: Cmd Executing \n",__LINE__);
1055 if (pComponentPrivate->curState == commandedState){
1056 pComponentPrivate->cbInfo.EventHandler (pHandle,
1057 pHandle->pApplicationPrivate,
1058 OMX_EventError,
1059 OMX_ErrorSameState,
1060 OMX_TI_ErrorMinor,
1061 "Invalid State");
1062 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Same State Given by \
1063 Application\n",__LINE__);
1064 goto EXIT;
1065 }
1066 else if (pComponentPrivate->curState == OMX_StateIdle) {
1067 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1068 /* Sending commands to DSP via LCML_ControlCodec third argument
1069 is not used for time being */
1070 pComponentPrivate->nFillBufferDoneCount = 0;
1071 pComponentPrivate->bStopSent=0;
1072
1073 pComponentPrivate->nEmptyBufferDoneCount = 0;
1074 pComponentPrivate->nEmptyThisBufferCount = 0;
1075 pComponentPrivate->nFillBufferDoneCount =0;
1076
1077 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1078 EMMCodecControlStart, (void *)p);
1079
1080 if(eError != OMX_ErrorNone) {
1081 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error Occurred in Codec Start..\n",__LINE__);
1082 pComponentPrivate->curState = OMX_StateInvalid;
1083 pComponentPrivate->cbInfo.EventHandler(pHandle,
1084 pHandle->pApplicationPrivate,
1085 OMX_EventError,
1086 eError,
1087 OMX_TI_ErrorSevere,
1088 NULL);
1089 goto EXIT;
1090 }
1091 /* Send input buffers to application */
1092 nBuf = pComponentPrivate->pInputBufferList->numBuffers;
1093
1094
1095 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: nBuf = %ld\n",__LINE__,nBuf);
1096 /* Send output buffers to codec */
1097 }
1098 else if (pComponentPrivate->curState == OMX_StatePause) {
1099 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1100 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1101 EMMCodecControlStart, (void *)p);
1102 if (eError != OMX_ErrorNone) {
1103 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error While Resuming the codec\n",__LINE__);
1104 pComponentPrivate->curState = OMX_StateInvalid;
1105 pComponentPrivate->cbInfo.EventHandler(pHandle,
1106 pHandle->pApplicationPrivate,
1107 OMX_EventError,
1108 eError,
1109 OMX_TI_ErrorSevere,
1110 NULL);
1111 goto EXIT;
1112 }
1113 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) {
1114 if (pComponentPrivate->pInputBufHdrPending[i]) {
1115 NBAMRDECGetCorresponding_LCMLHeader(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr);
1116 NBAMRDEC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput);
1117
1118 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1119 EMMCodecInputBuffer,
1120 pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
1121 pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
1122 pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
1123 (OMX_U8 *) pLcmlHdr->pBufferParam,
1124 sizeof(NBAMRDEC_ParamStruct),
1125 NULL);
1126 }
1127 }
1128 pComponentPrivate->nNumInputBufPending = 0;
1129
1130 /* if (pComponentPrivate->nNumOutputBufPending < pComponentPrivate->pOutputBufferList->numBuffers) {
1131 pComponentPrivate->nNumOutputBufPending = pComponentPrivate->pOutputBufferList->numBuffers;
1132 }
1133 */
1134 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
1135 if (pComponentPrivate->pOutputBufHdrPending[i]) {
1136 NBAMRDECGetCorresponding_LCMLHeader(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, OMX_DirOutput, &pLcmlHdr);
1137 NBAMRDEC_SetPending(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i],OMX_DirOutput);
1138
1139 eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1140 EMMCodecOuputBuffer,
1141 pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
1142 pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
1143 pComponentPrivate->pOutputBufHdrPending[i]->nFilledLen,
1144 (OMX_U8 *) pLcmlHdr->pBufferParam,
1145 sizeof(NBAMRDEC_ParamStruct),
1146 NULL);
1147 }
1148
1149 }
1150 pComponentPrivate->nNumOutputBufPending = 0;
1151 }
1152 else {
1153 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1154 pComponentPrivate->cbInfo.EventHandler (pHandle,
1155 pHandle->pApplicationPrivate,
1156 OMX_EventError,
1157 OMX_ErrorIncorrectStateTransition,
1158 OMX_TI_ErrorMinor,
1159 "Incorrect State Transition");
1160 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Invalid State Given by \
1161 Application\n",__LINE__);
1162 goto EXIT;
1163
1164 }
1165 #ifdef RESOURCE_MANAGER_ENABLED
1166 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Decoder_COMPONENT, OMX_StateExecuting, 3456,NULL);
1167 #endif
1168 pComponentPrivate->curState = OMX_StateExecuting;
1169 #ifdef __PERF_INSTRUMENTATION__
1170 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySteadyState);
1171 #endif
1172 /*Send state change notificaiton to Application */
1173 pComponentPrivate->cbInfo.EventHandler(pHandle,
1174 pHandle->pApplicationPrivate,
1175 OMX_EventCmdComplete,
1176 OMX_CommandStateSet,
1177 pComponentPrivate->curState,
1178 NULL);
1179 break;
1180
1181 case OMX_StateLoaded:
1182 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand: Cmd Loaded - curState = %d\n",__LINE__,pComponentPrivate->curState);
1183 if (pComponentPrivate->curState == commandedState){
1184 pComponentPrivate->cbInfo.EventHandler (pHandle,
1185 pHandle->pApplicationPrivate,
1186 OMX_EventError,
1187 OMX_ErrorSameState,
1188 OMX_TI_ErrorMinor,
1189 "Same State");
1190 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Same State Given by \
1191 Application\n",__LINE__);
1192 break;
1193 }
1194 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pComponentPrivate->pInputBufferList->numBuffers = %d\n",__LINE__,pComponentPrivate->pInputBufferList->numBuffers);
1195 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pComponentPrivate->pOutputBufferList->numBuffers = %d\n",__LINE__,pComponentPrivate->pOutputBufferList->numBuffers);
1196
1197 if (pComponentPrivate->curState == OMX_StateWaitForResources){
1198 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand: Cmd Loaded\n",__LINE__);
1199 #ifdef __PERF_INSTRUMENTATION__
1200 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
1201 #endif
1202 pComponentPrivate->curState = OMX_StateLoaded;
1203 #ifdef __PERF_INSTRUMENTATION__
1204 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup);
1205 #endif
1206 pComponentPrivate->cbInfo.EventHandler (
1207 pHandle, pHandle->pApplicationPrivate,
1208 OMX_EventCmdComplete, OMX_CommandStateSet,pComponentPrivate->curState,
1209 NULL);
1210 break;
1211
1212 }
1213 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: In side OMX_StateLoaded State: \n",__LINE__);
1214 if (pComponentPrivate->curState != OMX_StateIdle &&
1215 pComponentPrivate->curState != OMX_StateWaitForResources) {
1216 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1217 pComponentPrivate->cbInfo.EventHandler (pHandle,
1218 pHandle->pApplicationPrivate,
1219 OMX_EventError,
1220 OMX_ErrorIncorrectStateTransition,
1221 OMX_TI_ErrorMinor,
1222 "Incorrect State Transition");
1223 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Invalid State Given by \
1224 Application\n",__LINE__);
1225 goto EXIT;
1226 }
1227 #ifdef __PERF_INSTRUMENTATION__
1228 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
1229 #endif
1230 while (1) {
1231
1232
1233 if (!pComponentPrivate->pInputBufferList->numBuffers &&
1234 !pComponentPrivate->pOutputBufferList->numBuffers) {
1235
1236 break;
1237 }
1238 pComponentPrivate->InIdle_goingtoloaded = 1;
1239 #ifndef UNDER_CE
1240 pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
1241 pthread_cond_wait(&pComponentPrivate->InIdle_threshold, &pComponentPrivate->InIdle_mutex);
1242 pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
1243 #else
1244 OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
1245 #endif
1246 break;
1247 }
1248
1249 /* Now Deinitialize the component No error should be returned from
1250 * this function. It should clean the system as much as possible */
1251 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: In side OMX_StateLoaded State: \n",__LINE__);
1252 NBAMRDEC_CleanupInitParams(pComponentPrivate->pHandle);
1253
1254 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1255 EMMCodecControlDestroy, (void *)p);
1256
1257 /*Closing LCML Lib*/
1258 if (pComponentPrivate->ptrLibLCML != NULL)
1259 {
1260 OMX_PRDSP1(pComponentPrivate->dbg, "%d OMX_AmrDecoder.c Closing LCML library\n",__LINE__);
1261 dlclose( pComponentPrivate->ptrLibLCML );
1262 pComponentPrivate->ptrLibLCML = NULL;
1263 }
1264
1265 #ifdef __PERF_INSTRUMENTATION__
1266 PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, PERF_ModuleComponent);
1267 #endif
1268 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: In side OMX_StateLoaded State: \n",__LINE__);
1269 if (eError != OMX_ErrorNone) {
1270 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: in Destroying the codec: no. %x\n",__LINE__, eError);
1271 goto EXIT;
1272 }
1273 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand: Cmd Loaded\n",__LINE__);
1274 eError = EXIT_COMPONENT_THRD;
1275 pComponentPrivate->bInitParamsInitialized = 0;
1276 pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
1277 /* Send StateChangeNotification to application */
1278 break;
1279
1280 case OMX_StatePause:
1281 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand: Cmd Pause\n",__LINE__);
1282 if (pComponentPrivate->curState == commandedState){
1283 pComponentPrivate->cbInfo.EventHandler (pHandle,
1284 pHandle->pApplicationPrivate,
1285 OMX_EventError,
1286 OMX_ErrorSameState,
1287 OMX_TI_ErrorMinor,
1288 "Same State");
1289 break;
1290 }
1291 if (pComponentPrivate->curState != OMX_StateExecuting &&
1292 pComponentPrivate->curState != OMX_StateIdle) {
1293 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1294 pComponentPrivate->cbInfo.EventHandler (pHandle,
1295 pHandle->pApplicationPrivate,
1296 OMX_EventError,
1297 OMX_ErrorIncorrectStateTransition,
1298 OMX_TI_ErrorMinor,
1299 "Incorrect State Transition");
1300 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Invalid State Given by \
1301 Application\n",__LINE__);
1302 goto EXIT;
1303 }
1304 #ifdef __PERF_INSTRUMENTATION__
1305 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
1306 #endif
1307 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1308 EMMCodecControlPause, (void *)p);
1309
1310 if (eError != OMX_ErrorNone) {
1311 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: in Pausing the codec\n",__LINE__);
1312 pComponentPrivate->curState = OMX_StateInvalid;
1313 pComponentPrivate->cbInfo.EventHandler(pHandle,
1314 pHandle->pApplicationPrivate,
1315 OMX_EventError,
1316 eError,
1317 OMX_TI_ErrorSevere,
1318 NULL);
1319 goto EXIT;
1320 }
1321 #ifdef RESOURCE_MANAGER_ENABLED
1322 /* notify RM of pause so resources can be redistributed if needed */
1323 rm_error = RMProxy_NewSendCommand(pHandle,
1324 RMProxy_StateSet,
1325 OMX_NBAMR_Decoder_COMPONENT,
1326 OMX_StatePause,
1327 3456,
1328 NULL);
1329 #endif
1330 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1331 break;
1332
1333 case OMX_StateWaitForResources:
1334
1335 if (pComponentPrivate->curState == commandedState){
1336 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1337 pComponentPrivate->cbInfo.EventHandler (pHandle,
1338 pHandle->pApplicationPrivate,
1339 OMX_EventError,
1340 OMX_ErrorSameState,
1341 OMX_TI_ErrorMinor,
1342 "Same State");
1343 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Same State Given by \
1344 Application\n",__LINE__);
1345 }
1346 else if (pComponentPrivate->curState == OMX_StateLoaded) {
1347 #ifdef RESOURCE_MANAGER_ENABLED
1348 rm_error = RMProxy_NewSendCommand(pHandle,
1349 RMProxy_StateSet,
1350 OMX_NBAMR_Decoder_COMPONENT,
1351 OMX_StateWaitForResources,
1352 3456,
1353 NULL);
1354 #endif
1355 pComponentPrivate->curState = OMX_StateWaitForResources;
1356 pComponentPrivate->cbInfo.EventHandler(
1357 pHandle, pHandle->pApplicationPrivate,
1358 OMX_EventCmdComplete, OMX_CommandStateSet,pComponentPrivate->curState,NULL);
1359 }
1360 else{
1361 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1362 pComponentPrivate->cbInfo.EventHandler(pHandle,
1363 pHandle->pApplicationPrivate,
1364 OMX_EventError,
1365 OMX_ErrorIncorrectStateTransition,
1366 OMX_TI_ErrorMinor,
1367 "Incorrect State Transition");
1368 }
1369 break;
1370
1371
1372 case OMX_StateInvalid:
1373 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand: Cmd OMX_StateInvalid:\n",__LINE__);
1374 if (pComponentPrivate->curState == commandedState){
1375 pComponentPrivate->cbInfo.EventHandler (pHandle,
1376 pHandle->pApplicationPrivate,
1377 OMX_EventError,
1378 OMX_ErrorSameState,
1379 OMX_TI_ErrorSevere,
1380 "Same State");
1381 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Same State Given by \
1382 Application\n",__LINE__);
1383 }
1384 else{
1385 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
1386 if (pComponentPrivate->curState != OMX_StateWaitForResources &&
1387 pComponentPrivate->curState != OMX_StateLoaded) {
1388
1389 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1390 EMMCodecControlDestroy, (void *)p);
1391
1392 NBAMRDEC_CleanupInitParams(pHandle);
1393 }
1394 pComponentPrivate->curState = OMX_StateInvalid;
1395
1396 pComponentPrivate->cbInfo.EventHandler(pHandle,
1397 pHandle->pApplicationPrivate,
1398 OMX_EventError,
1399 OMX_ErrorInvalidState,
1400 OMX_TI_ErrorSevere,
1401 "Incorrect State Transition");
1402 }
1403
1404 break;
1405
1406 case OMX_StateMax:
1407 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleCommand: Cmd OMX_StateMax::\n",__LINE__);
1408 break;
1409 default:
1410 break;
1411 } /* End of Switch */
1412 }
1413 else if (command == OMX_CommandMarkBuffer) {
1414 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: command OMX_CommandMarkBuffer received\n",__LINE__);
1415 if(!pComponentPrivate->pMarkBuf){
1416 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: command OMX_CommandMarkBuffer received\n",__LINE__);
1417 /* TODO Need to handle multiple marks */
1418 pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData);
1419 }
1420 }
1421 else if (command == OMX_CommandPortDisable) {
1422 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
1423
1424 if (!pComponentPrivate->bDisableCommandPending) {
1425 if(commandData == 0x0 || commandData == -1){ /*Input*/
1426 /* disable port */
1427 pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled = OMX_FALSE;
1428 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
1429 if (NBAMRDEC_IsPending(pComponentPrivate,pComponentPrivate->pInputBufferList->pBufHdr[i],OMX_DirInput)) {
1430 /* Real solution is flush buffers from DSP. Until we have the ability to do that
1431 we just call EmptyBufferDone() on any pending buffers */
1432 #ifdef __PERF_INSTRUMENTATION__
1433 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1434 PREF(pComponentPrivate->pInputBufferList->pBufHdr[i], pBuffer),
1435 0,
1436 PERF_ModuleHLMM);
1437 #endif
1438 NBAMRDEC_ClearPending(pComponentPrivate,pComponentPrivate->pInputBufferList->pBufHdr[i],OMX_DirInput);
1439 pComponentPrivate->nEmptyBufferDoneCount++;
1440 pComponentPrivate->cbInfo.EmptyBufferDone (
1441 pComponentPrivate->pHandle,
1442 pComponentPrivate->pHandle->pApplicationPrivate,
1443 pComponentPrivate->pInputBufferList->pBufHdr[i]
1444 );
1445 SignalIfAllBuffersAreReturned(pComponentPrivate);
1446 }
1447 }
1448 }
1449 if(commandData == 0x1 || commandData == -1){ /*Output*/
1450 char *pArgs = "damedesuStr";
1451 pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled = OMX_FALSE;
1452 if (pComponentPrivate->curState == OMX_StateExecuting) {
1453 pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
1454 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Calling LCML_ControlCodec()\n",__LINE__);
1455 if (pComponentPrivate->codecStop_waitingsignal == 0){
1456 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
1457 }
1458 eError = LCML_ControlCodec(
1459 ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1460 MMCodecControlStop,(void *)pArgs);
1461 if (pComponentPrivate->codecStop_waitingsignal == 0){
1462 pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
1463 pComponentPrivate->codecStop_waitingsignal = 0;
1464 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
1465 }
1466
1467 }
1468 }
1469 }
1470
1471 if(commandData == 0x0) {
1472 if(!pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bPopulated){
1473 /* return cmdcomplete event if input unpopulated */
1474 pComponentPrivate->cbInfo.EventHandler(
1475 pHandle, pHandle->pApplicationPrivate,
1476 OMX_EventCmdComplete, OMX_CommandPortDisable,NBAMRDEC_INPUT_PORT, NULL);
1477 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Clearing bDisableCommandPending\n",__LINE__);
1478 pComponentPrivate->bDisableCommandPending = 0;
1479 }
1480 else{
1481 pComponentPrivate->bDisableCommandPending = 1;
1482 pComponentPrivate->bDisableCommandParam = commandData;
1483 }
1484 }
1485
1486 if(commandData == 0x1) {
1487 if (!pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bPopulated){
1488 /* return cmdcomplete event if output unpopulated */
1489 pComponentPrivate->cbInfo.EventHandler(
1490 pHandle, pHandle->pApplicationPrivate,
1491 OMX_EventCmdComplete, OMX_CommandPortDisable,NBAMRDEC_OUTPUT_PORT, NULL);
1492 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Clearing bDisableCommandPending\n",__LINE__);
1493 pComponentPrivate->bDisableCommandPending = 0;
1494 }
1495 else {
1496 pComponentPrivate->bDisableCommandPending = 1;
1497 pComponentPrivate->bDisableCommandParam = commandData;
1498 }
1499 }
1500
1501 if(commandData == -1) {
1502 if (!pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bPopulated &&
1503 !pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bPopulated){
1504
1505 /* return cmdcomplete event if inout & output unpopulated */
1506 pComponentPrivate->cbInfo.EventHandler(
1507 pHandle, pHandle->pApplicationPrivate,
1508 OMX_EventCmdComplete, OMX_CommandPortDisable,NBAMRDEC_INPUT_PORT, NULL);
1509
1510 pComponentPrivate->cbInfo.EventHandler(
1511 pHandle, pHandle->pApplicationPrivate,
1512 OMX_EventCmdComplete, OMX_CommandPortDisable,NBAMRDEC_OUTPUT_PORT, NULL);
1513 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Clearing bDisableCommandPending\n",__LINE__);
1514 pComponentPrivate->bDisableCommandPending = 0;
1515 }
1516 else {
1517 pComponentPrivate->bDisableCommandPending = 1;
1518 pComponentPrivate->bDisableCommandParam = commandData;
1519 }
1520 }
1521 }
1522 else if (command == OMX_CommandPortEnable) {
1523 if(!pComponentPrivate->bEnableCommandPending) {
1524 if(commandData == 0x0 || commandData == -1){
1525 /* enable in port */
1526 OMX_PRCOMM1(pComponentPrivate->dbg, "setting input port to enabled\n");
1527 pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled = OMX_TRUE;
1528 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled = %d\n",
1529 pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled);
1530
1531 if(pComponentPrivate->AlloBuf_waitingsignal){
1532 pComponentPrivate->AlloBuf_waitingsignal = 0;
1533 }
1534 }
1535 if(commandData == 0x1 || commandData == -1){
1536 char *pArgs = "damedesuStr";
1537 /* enable out port */
1538 if(pComponentPrivate->AlloBuf_waitingsignal){
1539 pComponentPrivate->AlloBuf_waitingsignal = 0;
1540 #ifndef UNDER_CE
1541 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1542 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
1543 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1544 #else
1545 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
1546 #endif
1547 }
1548 if(pComponentPrivate->curState == OMX_StateExecuting) {
1549 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1550 EMMCodecControlStart,(void *)pArgs);
1551 }
1552 OMX_PRCOMM1(pComponentPrivate->dbg, "setting output port to enabled\n");
1553 pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled = OMX_TRUE;
1554 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled = %d\n",
1555 pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bEnabled);
1556 }
1557 }
1558
1559 if(commandData == 0x0){
1560 if (pComponentPrivate->curState == OMX_StateLoaded ||
1561 pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bPopulated) {
1562 pComponentPrivate->cbInfo.EventHandler(pHandle,
1563 pHandle->pApplicationPrivate,
1564 OMX_EventCmdComplete,
1565 OMX_CommandPortEnable,
1566 NBAMRDEC_INPUT_PORT,
1567 NULL);
1568 pComponentPrivate->bEnableCommandPending = 0;
1569 }
1570 else {
1571 pComponentPrivate->bEnableCommandPending = 1;
1572 pComponentPrivate->bEnableCommandParam = commandData;
1573 }
1574 }
1575 else if(commandData == 0x1) {
1576 if (pComponentPrivate->curState == OMX_StateLoaded ||
1577 pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bPopulated){
1578 pComponentPrivate->cbInfo.EventHandler( pHandle,
1579 pHandle->pApplicationPrivate,
1580 OMX_EventCmdComplete,
1581 OMX_CommandPortEnable,
1582 NBAMRDEC_OUTPUT_PORT,
1583 NULL);
1584 pComponentPrivate->bEnableCommandPending = 0;
1585 }
1586 else {
1587 pComponentPrivate->bEnableCommandPending = 1;
1588 pComponentPrivate->bEnableCommandParam = commandData;
1589 }
1590 }
1591 else if(commandData == -1) {
1592 if (pComponentPrivate->curState == OMX_StateLoaded ||
1593 (pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bPopulated
1594 && pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]->bPopulated)){
1595 pComponentPrivate->cbInfo.EventHandler(pHandle,
1596 pHandle->pApplicationPrivate,
1597 OMX_EventCmdComplete,
1598 OMX_CommandPortEnable,
1599 NBAMRDEC_INPUT_PORT,
1600 NULL);
1601 pComponentPrivate->cbInfo.EventHandler(pHandle,
1602 pHandle->pApplicationPrivate,
1603 OMX_EventCmdComplete,
1604 OMX_CommandPortEnable,
1605 NBAMRDEC_OUTPUT_PORT,
1606 NULL);
1607 pComponentPrivate->bEnableCommandPending = 0;
1608 NBAMRDECFill_LCMLInitParamsEx(pComponentPrivate->pHandle);
1609 }
1610 else {
1611 pComponentPrivate->bEnableCommandPending = 1;
1612 pComponentPrivate->bEnableCommandParam = commandData;
1613 }
1614 }
1615 #ifndef UNDER_CE
1616 pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
1617 pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
1618 pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
1619 #else
1620 OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
1621 #endif
1622
1623
1624 }
1625 else if (command == OMX_CommandFlush) {
1626 OMX_U32 aParam[3] = {0};
1627 OMX_PRCOMM1(pComponentPrivate->dbg, "Flushing input port %d\n",pComponentPrivate->nUnhandledEmptyThisBuffers);
1628 if(commandData == 0x0 || commandData == -1) {
1629 if(pComponentPrivate->nUnhandledEmptyThisBuffers == 0) {
1630 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
1631 pComponentPrivate->first_buff = 0;
1632
1633 aParam[0] = USN_STRMCMD_FLUSH;
1634 aParam[1] = 0x0;
1635 aParam[2] = 0x0;
1636
1637 OMX_PRCOMM2(pComponentPrivate->dbg, "Sending USN_STRMCMD_FLUSH Command for IN port\n");
1638 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1639 EMMCodecControlStrmCtrl,
1640 (void*)aParam);
1641 if (eError != OMX_ErrorNone) {
1642 goto EXIT;
1643 }
1644 } else{
1645 pComponentPrivate->bFlushInputPortCommandPending = OMX_TRUE;
1646 }
1647 }
1648 if(commandData == 0x1 || commandData == -1){
1649 OMX_PRCOMM1(pComponentPrivate->dbg, "Flushing out port %d\n",pComponentPrivate->nUnhandledFillThisBuffers);
1650 if (pComponentPrivate->nUnhandledFillThisBuffers == 0) {
1651 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
1652 if (pComponentPrivate->first_output_buf_rcv != 0) {
1653 pComponentPrivate->first_buff = 0;
1654 pComponentPrivate->first_output_buf_rcv = 0;
1655 }
1656
1657 aParam[0] = USN_STRMCMD_FLUSH;
1658 aParam[1] = 0x1;
1659 aParam[2] = 0x0;
1660
1661 OMX_PRCOMM1(pComponentPrivate->dbg, "Sending USN_STRMCMD_FLUSH Command for OUT port\n");
1662 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
1663 EMMCodecControlStrmCtrl,
1664 (void*)aParam);
1665 if (eError != OMX_ErrorNone) {
1666 goto EXIT;
1667 }
1668 }else{
1669 pComponentPrivate->bFlushOutputPortCommandPending = OMX_TRUE;
1670 }
1671 }
1672 }
1673 EXIT:
1674 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Exiting NBAMRDECHandleCommand Function\n",__LINE__);
1675 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Returning %d\n",__LINE__,eError);
1676 if (eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD) {
1677 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
1678 pComponentPrivate->pHandle->pApplicationPrivate,
1679 OMX_EventError,
1680 eError,
1681 OMX_TI_ErrorSevere,
1682 NULL);
1683 }
1684 return eError;
1685 }
1686
1687
1688 /* ========================================================================== */
1689 /**
1690 * @NBAMRDECHandleDataBuf_FromApp() This function is called by the component when ever it
1691 * receives the buffer from the application
1692 *
1693 * @param pComponentPrivate Component private data
1694 * @param pBufHeader Buffer from the application
1695 *
1696 * @pre
1697 *
1698 * @post
1699 *
1700 * @return none
1701 */
1702 /* ========================================================================== */
NBAMRDECHandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE * pBufHeader,AMRDEC_COMPONENT_PRIVATE * pComponentPrivate)1703 OMX_ERRORTYPE NBAMRDECHandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE* pBufHeader,
1704 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate)
1705 {
1706 OMX_ERRORTYPE eError = OMX_ErrorNone;
1707 OMX_DIRTYPE eDir;
1708 LCML_NBAMRDEC_BUFHEADERTYPE *pLcmlHdr;
1709 LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)
1710 pComponentPrivate->pLcmlHandle;
1711 OMX_U32 index;
1712 OMX_U32 frameType;
1713 OMX_U32 frameLength;
1714 OMX_U8* pExtraData;
1715 OMX_U16 i;
1716 OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
1717
1718 OMX_U32 holdBufferSize;
1719 OMX_U8 nFrames =0;
1720 LCML_DSP_INTERFACE * phandle;
1721 OMX_U8 bufSize=0;
1722 AMRDEC_AudioCodecParams *pParams;
1723 OMX_STRING p = "";
1724
1725 OMX_U32 nFilledLenLocal;
1726 OMX_U8 TOCentry, hh=0, *TOCframetype=0;
1727 OMX_U16 offset = 0;
1728
1729 DSP_STATUS status;
1730 OMX_BOOL isFrameParamChanged=OMX_FALSE;
1731
1732 if (OMX_AUDIO_AMRDTXasEFR == pComponentPrivate->iAmrMode){
1733 bufSize = INPUT_BUFF_SIZE_EFR;
1734 }
1735 else{
1736 bufSize = STD_NBAMRDEC_BUF_SIZE;
1737 }
1738
1739 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Entering NBAMRDECHandleDataBuf_FromApp Function\n",__LINE__);
1740
1741 holdBufferSize = bufSize * (pComponentPrivate->pInputBufferList->numBuffers + 1);
1742 /*Find the direction of the received buffer from buffer list */
1743 eError = NBAMRDECGetBufferDirection(pBufHeader, &eDir);
1744 if (eError != OMX_ErrorNone) {
1745 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: The PBufHeader is not found in the list\n",
1746 __LINE__);
1747 goto EXIT;
1748 }
1749 if (pBufHeader->pBuffer == NULL) {
1750 eError = OMX_ErrorBadParameter;
1751 goto EXIT;
1752 }
1753
1754 if (eDir == OMX_DirInput) {
1755 pComponentPrivate->nUnhandledEmptyThisBuffers--;
1756 if (pComponentPrivate->curState == OMX_StateIdle){
1757 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
1758 pComponentPrivate->pHandle->pApplicationPrivate,
1759 pBufHeader);
1760 pComponentPrivate->nEmptyBufferDoneCount++;
1761 SignalIfAllBuffersAreReturned(pComponentPrivate);
1762 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return input buffers\n", __LINE__, __FUNCTION__);
1763 goto EXIT;
1764 }
1765 pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
1766 if ( pBufHeader->nFilledLen > 0) {
1767 pComponentPrivate->bBypassDSP = 0;
1768 if ( pComponentPrivate->nHoldLength == 0 )
1769 {
1770 if (pComponentPrivate->mimemode == NBAMRDEC_MIMEMODE)
1771 {
1772 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleDa\
1773 taBuf_FromApp - reading NBAMRDEC_MIMEMODE\n",__LINE__);
1774 frameLength=INPUT_NBAMRDEC_BUFFER_SIZE_MIME;
1775 if(pComponentPrivate->using_rtsp==1){ /* formating data */
1776 nFilledLenLocal=pBufHeader->nFilledLen;
1777 while(TRUE)
1778 {
1779 TOCframetype = (OMX_U8*)realloc(TOCframetype, ((hh + 1) * sizeof(OMX_U8)));
1780 if (TOCframetype == NULL)
1781 {
1782 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Couldn't realloc memory!",__LINE__);
1783 goto EXIT;
1784 }
1785 TOCentry = pBufHeader->pBuffer[0];
1786 TOCframetype[hh]= TOCentry & 0x7C;
1787 hh++;
1788 if (!(TOCentry & 0x80))
1789 break;
1790 memmove(pBufHeader->pBuffer,
1791 pBufHeader->pBuffer + 1,
1792 nFilledLenLocal);
1793 }
1794 while(nFilledLenLocal> 0 ){
1795 index = (TOCframetype[nFrames] >> 3) & 0x0F;
1796 /* adding TOC to each frame */
1797 if (offset > pBufHeader->nAllocLen){
1798 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
1799 goto EXIT;
1800 }
1801 else
1802 memcpy(pBufHeader->pBuffer + offset,
1803 &TOCframetype[nFrames],
1804 sizeof(OMX_U8));
1805 offset+=pComponentPrivate->amrMimeBytes[index];
1806 if ( offset + 1 + nFilledLenLocal > pBufHeader->nAllocLen){
1807 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
1808 goto EXIT;
1809 }
1810 else
1811 memmove(pBufHeader->pBuffer + offset + 1,
1812 pBufHeader->pBuffer + offset,
1813 nFilledLenLocal);
1814 if (pComponentPrivate->amrMimeBytes[index] > nFilledLenLocal){
1815 nFilledLenLocal = 0;
1816 }else{
1817 nFilledLenLocal -= pComponentPrivate->amrMimeBytes[index];
1818 }
1819 nFrames++;
1820 }
1821 free(TOCframetype);
1822 TOCframetype = NULL;
1823 }
1824 frameType = 0;
1825 nFrames = 0;
1826 i=0;
1827 while(pBufHeader->nFilledLen > 0 )
1828 { /*Reorder the Mime buffer in case that has*/
1829 frameType = pBufHeader->pBuffer[i]; /*more than 1 frame */
1830 index = (frameType >> 3) & 0x0F;
1831 if(nFrames)
1832 {
1833 if (((nFrames*INPUT_NBAMRDEC_BUFFER_SIZE_MIME) + pBufHeader->nFilledLen)
1834 > pBufHeader->nAllocLen) {
1835 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
1836 goto EXIT;
1837 }
1838 memmove(pBufHeader->pBuffer + (nFrames*INPUT_NBAMRDEC_BUFFER_SIZE_MIME),
1839 pBufHeader->pBuffer + i,
1840 pBufHeader->nFilledLen);
1841 }
1842 if ((index >= NUM_MIME_BYTES_ARRAY) ||
1843 ((index < NUM_MIME_BYTES_ARRAY) &&
1844 (pComponentPrivate->amrMimeBytes[index] == 0))) {
1845 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: no more frames index=%d", __LINE__, (int)index);
1846 if (index < NUM_MIME_BYTES_ARRAY)
1847 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: no more frames mimebytes=%d", __LINE__, (int)pComponentPrivate->amrMimeBytes[index]);
1848 break;
1849 }
1850 if (pComponentPrivate->amrMimeBytes[index] > pBufHeader->nFilledLen){
1851 pBufHeader->nFilledLen = 0;
1852 }else{
1853 pBufHeader->nFilledLen -= pComponentPrivate->amrMimeBytes[index];
1854 }
1855 i = (nFrames*INPUT_NBAMRDEC_BUFFER_SIZE_MIME) + (OMX_U16)pComponentPrivate->amrMimeBytes[index];
1856 nFrames++;
1857 }
1858 pBufHeader->nFilledLen=nFrames*INPUT_NBAMRDEC_BUFFER_SIZE_MIME;
1859 }
1860 else if (pComponentPrivate->mimemode == NBAMRDEC_PADMIMEMODE)
1861 {
1862 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleDa\
1863 taBuf_FromApp - reading NBAMRDEC_PADMIMEMODE\
1864 nFilledLen %ld nAllocLen %ld\n",__LINE__, pBufHeader->nFilledLen, pBufHeader->nAllocLen);
1865 frameLength=INPUT_NBAMRDEC_BUFFER_SIZE_MIME;
1866 nFrames=pBufHeader->nAllocLen / frameLength; /*to get the corresponding header in the LCML */
1867 }
1868 else if (pComponentPrivate->mimemode == NBAMRDEC_IF2)
1869 {
1870 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleDataBuf_FromApp - reading NBAMRDEC_IF2MODE\n", __LINE__);
1871 frameLength=INPUT_NBAMRDEC_BUFFER_SIZE_IF2;
1872 nFrames = 0;
1873 i = 0;
1874 while (pBufHeader->nFilledLen > 0)
1875 {
1876 /*Reorder the IF2 buffer in case that has more than 1 frame */
1877 frameType = pBufHeader->pBuffer[i];
1878 index = frameType&0x0F;
1879 if (nFrames)
1880 {
1881 if (((nFrames*INPUT_NBAMRDEC_BUFFER_SIZE_IF2) + pBufHeader->nFilledLen)
1882 > pBufHeader->nAllocLen) {
1883 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
1884 goto EXIT;
1885 }
1886 memmove(pBufHeader->pBuffer + (nFrames *INPUT_NBAMRDEC_BUFFER_SIZE_IF2),
1887 pBufHeader->pBuffer + i,
1888 pBufHeader->nFilledLen);
1889 }
1890 if ((index >= NUM_IF2_BYTES_ARRAY) ||
1891 ((index < NUM_IF2_BYTES_ARRAY) &&
1892 (pComponentPrivate->amrIF2Bytes[index] == 0))) {
1893 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: no more frames index=%d", __LINE__, (int)index);
1894 if (index < NUM_IF2_BYTES_ARRAY)
1895 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: no more frames mimebytes=%d", __LINE__, (int)pComponentPrivate->amrIF2Bytes[index]);
1896 break;
1897 }
1898 if(pComponentPrivate->amrIF2Bytes[index] > pBufHeader->nFilledLen){
1899 pBufHeader->nFilledLen=0;
1900 }else{
1901 pBufHeader->nFilledLen -= pComponentPrivate->amrIF2Bytes[index];
1902 }
1903 i = (nFrames *INPUT_NBAMRDEC_BUFFER_SIZE_IF2) + (OMX_U16)pComponentPrivate->amrIF2Bytes[index];
1904 nFrames++;
1905 }
1906 pBufHeader->nFilledLen = nFrames * INPUT_NBAMRDEC_BUFFER_SIZE_IF2;
1907 }
1908
1909 else
1910 {
1911 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleDataBuf_FromApp - reading NBAMRDEC_NONMIMEMODE\n",__LINE__);
1912 frameLength = STD_NBAMRDEC_BUF_SIZE; /*/ non Mime mode*/
1913 nFrames = (OMX_U8)(pBufHeader->nFilledLen / frameLength);
1914 }
1915
1916 if (nFrames >= 1 && (NBAMRDEC_FORMATCONFORMANCE == pComponentPrivate->mimemode))
1917 {
1918 /* At least there is 1 frame in the buffer */
1919 pComponentPrivate->nHoldLength = pBufHeader->nFilledLen - frameLength*nFrames;
1920 if ( pComponentPrivate->nHoldLength > 0 ) {/* something need to be hold in iHoldBuffer */
1921 if (pComponentPrivate->pHoldBuffer == NULL) {
1922 OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer, (bufSize * (pComponentPrivate->pInputBufferList->numBuffers + 3)),void);
1923 }
1924 /* Copy the extra data into pHoldBuffer. Size will be nHoldLength. */
1925 pExtraData = pBufHeader->pBuffer + bufSize*nFrames;
1926 if (pComponentPrivate->nHoldLength >
1927 (bufSize * (pComponentPrivate->pInputBufferList->numBuffers + 3)))
1928 {
1929 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
1930 goto EXIT;
1931 }
1932 memcpy (pComponentPrivate->pHoldBuffer, pExtraData, pComponentPrivate->nHoldLength);
1933 }
1934 }
1935 else {
1936 if (pComponentPrivate->mimemode == NBAMRDEC_FORMATCONFORMANCE)
1937 {
1938 /* received buffer with less than 1 AMR frame. Save the data in iHoldBuffer.*/
1939 pComponentPrivate->nHoldLength = pBufHeader->nFilledLen;
1940 /* save the data into iHoldBuffer.*/
1941 if (pComponentPrivate->pHoldBuffer == NULL) {
1942 OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer, (bufSize * (pComponentPrivate->pInputBufferList->numBuffers + 3)),void);
1943 }
1944 /* Not enough data to be sent. Copy all received data into iHoldBuffer.*/
1945 /* Size to be copied will be iHoldLen == mmData->BufferSize() */
1946 memset (pComponentPrivate->pHoldBuffer,0,bufSize * (pComponentPrivate->pInputBufferList->numBuffers + 1));
1947 memcpy (pComponentPrivate->pHoldBuffer, pBufHeader->pBuffer, pComponentPrivate->nHoldLength);
1948
1949 /* since not enough data, we shouldn't send anything to SN, but instead request to EmptyBufferDone again.*/
1950 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Calling EmptyBufferDone\n",__LINE__);
1951 if (pComponentPrivate->curState != OMX_StatePause) {
1952 pComponentPrivate->nEmptyBufferDoneCount++;
1953 #ifdef __PERF_INSTRUMENTATION__
1954 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
1955 PREF(pBufHeader,pBuffer),
1956 0,
1957 PERF_ModuleHLMM);
1958 #endif
1959 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
1960 pComponentPrivate->pHandle->pApplicationPrivate,
1961 pBufHeader);
1962 SignalIfAllBuffersAreReturned(pComponentPrivate);
1963 }
1964 else {
1965 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
1966 }
1967 goto EXIT;
1968 }
1969 }
1970 }
1971 else {
1972 /* iHoldBuffer has data. There is no possibility that data in iHoldBuffer is less for 1 frame without*/
1973 /* lastBufferFlag being set. Unless it's a corrupt file.*/
1974 /* Copy the data in dataPtr to iHoldBuffer. Update the iHoldBuffer size (iHoldLen).*/
1975
1976 pExtraData = pComponentPrivate->pHoldBuffer + pComponentPrivate->nHoldLength;
1977 memcpy(pExtraData,pBufHeader->pBuffer,pBufHeader->nFilledLen);
1978
1979 pComponentPrivate->nHoldLength += pBufHeader->nFilledLen;
1980
1981 /* Check if it is mime mode or non-mime mode to decide the frame length to be sent down*/
1982 /* to DSP/ALG.*/
1983 if ( pComponentPrivate->mimemode == NBAMRDEC_MIMEMODE)
1984 {
1985 frameType = pComponentPrivate->pHoldBuffer[0];
1986 index = ( frameType >> 3 ) & 0x0F;
1987 frameLength = pComponentPrivate->amrMimeBytes[index];
1988 }
1989 else if(pComponentPrivate->mimemode == NBAMRDEC_IF2)
1990 {
1991 frameType = pComponentPrivate->pHoldBuffer[0];
1992 index = frameType&0x0F;
1993 frameLength = pComponentPrivate->amrIF2Bytes[index];
1994 }
1995 else
1996 {
1997 frameLength = STD_NBAMRDEC_BUF_SIZE;
1998 }
1999
2000 nFrames = (OMX_U8)(pComponentPrivate->nHoldLength / frameLength);
2001 if ( nFrames >= 1 ) {
2002 /* Copy the data from pComponentPrivate->pHoldBuffer to pBufHeader->pBuffer*/
2003 /* check the pBufHeader boundery before copying */
2004 if ((nFrames*frameLength) > pBufHeader->nAllocLen)
2005 {
2006 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
2007 goto EXIT;
2008 }
2009 memcpy(pBufHeader->pBuffer,pComponentPrivate->pHoldBuffer,nFrames*frameLength);
2010 pBufHeader->nFilledLen = nFrames*frameLength;
2011
2012 /* Now the pHoldBuffer has pBufHeader->nFilledLen fewer bytes, update nHoldLength*/
2013 pComponentPrivate->nHoldLength = pComponentPrivate->nHoldLength - pBufHeader->nFilledLen;
2014
2015 /* Shift the remaining bytes to the beginning of the pHoldBuffer */
2016 pExtraData = pComponentPrivate->pHoldBuffer + pBufHeader->nFilledLen;
2017
2018 memcpy(pComponentPrivate->pHoldBuffer,pExtraData,pComponentPrivate->nHoldLength);
2019
2020 /* Clear the rest of the data from the pHoldBuffer */
2021 /*pExtraData = pComponentPrivate->pHoldBuffer + pComponentPrivate->nHoldLength;*/
2022 /*memset(pExtraData,0,holdBufferSize - pComponentPrivate->nHoldLength);*/
2023 }
2024 else {
2025 if (pComponentPrivate->curState != OMX_StatePause) {
2026 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Calling EmptyBufferDone\n",__LINE__);
2027 pComponentPrivate->nEmptyBufferDoneCount++;
2028 #ifdef __PERF_INSTRUMENTATION__
2029 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2030 PREF(pBufHeader,pBuffer),
2031 0,
2032 PERF_ModuleHLMM);
2033 #endif
2034 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
2035 pComponentPrivate->pHandle->pApplicationPrivate,
2036 pBufHeader);
2037 SignalIfAllBuffersAreReturned(pComponentPrivate);
2038 goto EXIT;
2039 }
2040 else {
2041 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
2042 }
2043 }
2044 }
2045 }else{
2046 if((((pBufHeader->nFlags)&(OMX_BUFFERFLAG_EOS)) != OMX_BUFFERFLAG_EOS) && !pBufHeader->pMarkData){
2047 pComponentPrivate->nEmptyBufferDoneCount++;
2048 #ifdef __PERF_INSTRUMENTATION__
2049 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2050 pComponentPrivate->pInputBufferList->pBufHdr[0]->pBuffer,0,PERF_ModuleHLMM);
2051 #endif
2052 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
2053 pComponentPrivate->pHandle->pApplicationPrivate,
2054 pComponentPrivate->pInputBufferList->pBufHdr[0]);
2055 SignalIfAllBuffersAreReturned(pComponentPrivate);
2056 goto EXIT;
2057 }
2058 else{
2059 nFrames=1;
2060 }
2061 }
2062
2063 if(nFrames >= 1){
2064 eError = NBAMRDECGetCorresponding_LCMLHeader(pComponentPrivate,pBufHeader->pBuffer, OMX_DirInput, &pLcmlHdr);
2065 if (eError != OMX_ErrorNone) {
2066 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Invalid Buffer Came ...\n",__LINE__);
2067 goto EXIT;
2068 }
2069
2070 #ifdef __PERF_INSTRUMENTATION__
2071 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2072 PREF(pBufHeader,pBuffer),
2073 pPortDefIn->nBufferSize,
2074 PERF_ModuleCommonLayer);
2075 #endif
2076 /*---------------------------------------------------------------*/
2077
2078 phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
2079
2080 if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){
2081
2082 OMX_DmmUnMap(phandle->dspCodec->hProc, /*Unmap DSP memory used*/
2083 (void*)pLcmlHdr->pBufferParam->pParamElem,
2084 pLcmlHdr->pDmmBuf->pReserved, pComponentPrivate->dbg);
2085 pLcmlHdr->pBufferParam->pParamElem = NULL;
2086
2087 OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam,NBAMRDEC_FrameStruct);
2088 }
2089
2090 if(pLcmlHdr->pFrameParam==NULL ){
2091 OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam,(sizeof(NBAMRDEC_FrameStruct)*nFrames),NBAMRDEC_FrameStruct);
2092
2093 eError = OMX_DmmMap(phandle->dspCodec->hProc,
2094 nFrames*sizeof(NBAMRDEC_FrameStruct),
2095 (void*)pLcmlHdr->pFrameParam,
2096 (pLcmlHdr->pDmmBuf), pComponentPrivate->dbg);
2097
2098 if (eError != OMX_ErrorNone)
2099 {
2100 OMX_ERROR4(pComponentPrivate->dbg, "OMX_DmmMap ERRROR!!!!\n\n");
2101 goto EXIT;
2102 }
2103 pLcmlHdr->pBufferParam->pParamElem = (NBAMRDEC_FrameStruct *)pLcmlHdr->pDmmBuf->pMapped; /*DSP Address*/
2104 }
2105
2106 for(i=0;i<nFrames;i++){
2107 (pLcmlHdr->pFrameParam+i)->usLastFrame = 0;
2108 (pLcmlHdr->pFrameParam+i)->usFrameLost = 0;
2109 }
2110
2111 /* We only support frame lost error concealment if there is one frame per buffer */
2112 if (nFrames == 1)
2113 {
2114 /* if the bFrameLost flag is set it means that the client has
2115 indicated that the next frame is corrupt so set the frame
2116 lost frame parameter */
2117 if (pComponentPrivate->bFrameLost == 1)
2118 {
2119 pLcmlHdr->pFrameParam->usFrameLost = 1;
2120 /* clear the internal frame lost flag */
2121 pComponentPrivate->bFrameLost = OMX_FALSE;
2122 }
2123 }
2124 isFrameParamChanged = OMX_TRUE;
2125 /** ring tone**/
2126 if(pComponentPrivate->SendAfterEOS == 1){
2127 OMX_PRINT2(pComponentPrivate->dbg, "%d :: reconfiguring SN\n",__LINE__);
2128 if(pComponentPrivate->dasfmode == 1) {
2129 OMX_U32 pValues[4];
2130 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ---- Comp: DASF Functionality is ON ---\n",__LINE__);
2131
2132 if(pComponentPrivate->streamID == 0)
2133 {
2134 OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n");
2135 OMX_ERROR4(pComponentPrivate->dbg, ":: Error = OMX_ErrorInsufficientResources\n");
2136 OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n");
2137 eError = OMX_ErrorInsufficientResources;
2138 pComponentPrivate->curState = OMX_StateInvalid;
2139 pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
2140 pComponentPrivate->pHandle->pApplicationPrivate,
2141 OMX_EventError,
2142 OMX_ErrorInvalidState,
2143 OMX_TI_ErrorMajor,
2144 "AM: No Stream ID Available");
2145 goto EXIT;
2146 }
2147
2148 OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,sizeof(AMRDEC_AudioCodecParams),AMRDEC_AudioCodecParams);
2149 pParams = pComponentPrivate->pParams;
2150 pParams->iAudioFormat = 1;
2151 pParams->iSamplingRate = 8000;
2152 pParams->iStrmId = pComponentPrivate->streamID;
2153
2154 pValues[0] = USN_STRMCMD_SETCODECPARAMS;
2155 pValues[1] = (OMX_U32)pParams;
2156 pValues[2] = sizeof(AMRDEC_AudioCodecParams);
2157 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
2158 EMMCodecControlStrmCtrl,(void *)pValues);
2159
2160 if(eError != OMX_ErrorNone) {
2161 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error Occurred in Codec StreamControl..\n",__LINE__);
2162 pComponentPrivate->curState = OMX_StateInvalid;
2163 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2164 pComponentPrivate->pHandle->pApplicationPrivate,
2165 OMX_EventError,
2166 eError,
2167 OMX_TI_ErrorSevere,
2168 NULL);
2169 goto EXIT;
2170 }
2171 }
2172
2173 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
2174 EMMCodecControlStart, (void *)p);
2175 if(eError != OMX_ErrorNone) {
2176 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error Occurred in Codec Start..\n",__LINE__);
2177 pComponentPrivate->curState = OMX_StateInvalid;
2178 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2179 pComponentPrivate->pHandle->pApplicationPrivate,
2180 OMX_EventError,
2181 eError,
2182 OMX_TI_ErrorSevere,
2183 NULL);
2184 goto EXIT;
2185 }
2186 pComponentPrivate->SendAfterEOS = 0;
2187 }
2188 /** **/
2189
2190
2191
2192 if(pBufHeader->nFlags & OMX_BUFFERFLAG_EOS)
2193 {
2194 (pLcmlHdr->pFrameParam+(nFrames-1))->usLastFrame = OMX_BUFFERFLAG_EOS;
2195 isFrameParamChanged = OMX_TRUE;
2196 pBufHeader->nFlags = 0;
2197 if(!pComponentPrivate->dasfmode)
2198 {
2199 if(!pBufHeader->nFilledLen)
2200 {
2201 pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags |= OMX_BUFFERFLAG_EOS;
2202 }
2203 pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
2204 pComponentPrivate->pHandle->pApplicationPrivate,
2205 OMX_EventBufferFlag,
2206 pComponentPrivate->pOutputBufferList->pBufHdr[0]->nOutputPortIndex,
2207 pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags, NULL);
2208 }
2209
2210 pComponentPrivate->SendAfterEOS = 1;
2211 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c : pComponentPrivate->SendAfterEOS %d\n",__LINE__,pComponentPrivate->SendAfterEOS);
2212 }
2213 if (isFrameParamChanged == OMX_TRUE) {
2214 isFrameParamChanged = OMX_FALSE;
2215 //Issue an initial memory flush to ensure cache coherency */
2216 OMX_PRINT1(pComponentPrivate->dbg, "OMX_AmrDec_Utils.c : flushing pFrameParam\n");
2217 status = DSPProcessor_FlushMemory(phandle->dspCodec->hProc, pLcmlHdr->pFrameParam, nFrames*sizeof(NBAMRDEC_FrameStruct), 0);
2218 if(DSP_FAILED(status))
2219 {
2220 OMXDBG_PRINT(stderr, ERROR, 4, 0, "Unable to flush mapped buffer: error 0x%x",(int)status);
2221 goto EXIT;
2222 }
2223 }
2224 pLcmlHdr->pBufferParam->usNbFrames = nFrames;
2225 /*---------------------------------------------------------------*/
2226
2227 /* Store time stamp information */
2228 pComponentPrivate->arrBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;
2229 /* Store nTickCount information */
2230 pComponentPrivate->arrTickCount[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount;
2231 pComponentPrivate->IpBufindex++;
2232 pComponentPrivate->IpBufindex %= pPortDefIn->nBufferCountActual;
2233
2234 if(pComponentPrivate->first_buff == 0){
2235 pComponentPrivate->first_TS = pBufHeader->nTimeStamp;
2236 OMX_PRBUFFER2(pComponentPrivate->dbg, "in ts-%ld\n",pBufHeader->nTimeStamp);
2237 pComponentPrivate->first_buff = 1;
2238 }
2239
2240 for (i=0; i < INPUT_NBAMRDEC_BUFFER_SIZE_MIME; i++) {
2241 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Queueing pBufHeader->pBuffer[%d] = %x\n",__LINE__,i,pBufHeader->pBuffer[i]);
2242 }
2243
2244 if (pComponentPrivate->curState == OMX_StateExecuting)
2245 {
2246 if (!NBAMRDEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput))
2247 {
2248 NBAMRDEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput);
2249 if (pComponentPrivate->mimemode == NBAMRDEC_MIMEMODE)
2250 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
2251 EMMCodecInputBuffer,
2252 (OMX_U8*)pBufHeader->pBuffer,
2253 pBufHeader->nAllocLen,
2254 pBufHeader->nFilledLen,
2255 (OMX_U8*)pLcmlHdr->pBufferParam,
2256 sizeof(NBAMRDEC_ParamStruct),
2257 NULL);
2258 else if (pComponentPrivate->mimemode == NBAMRDEC_IF2)
2259 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
2260 EMMCodecInputBuffer,
2261 (OMX_U8*)pBufHeader->pBuffer,
2262 INPUT_NBAMRDEC_BUFFER_SIZE_IF2*nFrames,
2263 INPUT_NBAMRDEC_BUFFER_SIZE_IF2*nFrames,
2264 (OMX_U8*)pLcmlHdr->pBufferParam,
2265 sizeof(NBAMRDEC_ParamStruct),
2266 NULL);
2267 else /*Frame Conformace, 120 for EFR, 118 for Standart*/
2268 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
2269 EMMCodecInputBuffer,
2270 (OMX_U8*)pBufHeader->pBuffer,
2271 bufSize*nFrames,
2272 bufSize*nFrames,
2273 (OMX_U8*)pLcmlHdr->pBufferParam,
2274 sizeof(NBAMRDEC_ParamStruct),
2275 NULL);
2276 if (eError != OMX_ErrorNone) {
2277 eError = OMX_ErrorHardware;
2278 goto EXIT;
2279 }
2280 pComponentPrivate->lcml_nCntIp++;
2281 pComponentPrivate->lcml_nIpBuf++;
2282 }
2283 }else if(pComponentPrivate->curState == OMX_StatePause){
2284 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
2285 }
2286
2287 if(pBufHeader->pMarkData)
2288 {
2289 /* copy mark to output buffer header */
2290 if(pComponentPrivate->pOutputBufferList->pBufHdr[0]!=NULL){
2291 pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData;
2292 pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent;
2293 }
2294
2295 /* trigger event handler if we are supposed to */
2296 if(pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle && pBufHeader->pMarkData){
2297 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2298 pComponentPrivate->pHandle->pApplicationPrivate,
2299 OMX_EventMark,
2300 0,
2301 0,
2302 pBufHeader->pMarkData);
2303 }
2304 if (pComponentPrivate->curState != OMX_StatePause ) {
2305 OMX_PRBUFFER2(pComponentPrivate->dbg, "line %d:: Calling EmptyBufferDone\n",__LINE__);
2306 pComponentPrivate->nEmptyBufferDoneCount++;
2307 #ifdef __PERF_INSTRUMENTATION__
2308 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2309 pBufHeader->pBuffer,
2310 0,
2311 PERF_ModuleHLMM);
2312 #endif
2313 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
2314 pComponentPrivate->pHandle->pApplicationPrivate,
2315 pBufHeader);
2316 SignalIfAllBuffersAreReturned(pComponentPrivate);
2317 }
2318 }
2319 }
2320 else
2321 {
2322 OMX_PRBUFFER2(pComponentPrivate->dbg, "line %d:: No Frames in Buffer, calling EmptyBufferDone\n",__LINE__);
2323 pComponentPrivate->nEmptyBufferDoneCount++;
2324 #ifdef __PERF_INSTRUMENTATION__
2325 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2326 pBufHeader->pBuffer,
2327 0,
2328 PERF_ModuleHLMM);
2329 #endif
2330 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
2331 pComponentPrivate->pHandle->pApplicationPrivate,
2332 pBufHeader);
2333 SignalIfAllBuffersAreReturned(pComponentPrivate);
2334 }
2335 if (pComponentPrivate->bFlushInputPortCommandPending) {
2336 OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL);
2337 }
2338 }
2339 else if (eDir == OMX_DirOutput) {
2340 /* Make sure that output buffer is issued to output stream only when
2341 * there is an outstanding input buffer already issued on input stream
2342 */
2343 pComponentPrivate->nUnhandledFillThisBuffers--;
2344 if (pComponentPrivate->curState == OMX_StateIdle){
2345 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
2346 pComponentPrivate->pHandle->pApplicationPrivate,
2347 pBufHeader);
2348 pComponentPrivate->nFillBufferDoneCount++;
2349 SignalIfAllBuffersAreReturned(pComponentPrivate);
2350 OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return output buffers\n", __LINE__, __FUNCTION__);
2351 goto EXIT;
2352 }
2353 eError = NBAMRDECGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);
2354 phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
2355
2356 #ifdef __PERF_INSTRUMENTATION__
2357 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2358 PREF(pBufHeader,pBuffer),
2359 0,
2360 PERF_ModuleCommonLayer);
2361 #endif
2362
2363 nFrames = (OMX_U8)(pBufHeader->nAllocLen/OUTPUT_NBAMRDEC_BUFFER_SIZE);
2364
2365 if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){
2366
2367 OMX_DmmUnMap(phandle->dspCodec->hProc, /*Unmap DSP memory used*/
2368 (void*)pLcmlHdr->pBufferParam->pParamElem,
2369 pLcmlHdr->pDmmBuf->pReserved, pComponentPrivate->dbg);
2370 pLcmlHdr->pBufferParam->pParamElem = NULL;
2371
2372 OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam,NBAMRDEC_FrameStruct);
2373 }
2374
2375 if(pLcmlHdr->pFrameParam==NULL ){
2376 OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam,(sizeof(NBAMRDEC_FrameStruct)*nFrames),NBAMRDEC_FrameStruct);
2377
2378 eError = OMX_DmmMap(phandle->dspCodec->hProc,
2379 nFrames*sizeof(NBAMRDEC_FrameStruct),
2380 (void*)pLcmlHdr->pFrameParam,
2381 (pLcmlHdr->pDmmBuf), pComponentPrivate->dbg);
2382
2383 if (eError != OMX_ErrorNone)
2384 {
2385 OMX_ERROR4(pComponentPrivate->dbg, "OMX_DmmMap ERRROR!!!!\n");
2386 goto EXIT;
2387 }
2388
2389 pLcmlHdr->pBufferParam->pParamElem = (NBAMRDEC_FrameStruct *)pLcmlHdr->pDmmBuf->pMapped;/*DSP Address*/
2390 }
2391
2392 pLcmlHdr->pBufferParam->usNbFrames = nFrames;
2393
2394 for(i=0;i<pLcmlHdr->pBufferParam->usNbFrames;i++){
2395 (pLcmlHdr->pFrameParam+i)->usLastFrame = 0;
2396 (pLcmlHdr->pFrameParam+i)->usFrameLost = 0;
2397 }
2398
2399 //Issue an initial memory flush to ensure cache coherency */
2400 OMX_PRINT1(pComponentPrivate->dbg, "OMX_AmrDec_Utils.c : flushing pFrameParam\n");
2401 status = DSPProcessor_FlushMemory(phandle->dspCodec->hProc, pLcmlHdr->pFrameParam, nFrames*sizeof(NBAMRDEC_FrameStruct), 0);
2402 if(DSP_FAILED(status))
2403 {
2404 OMXDBG_PRINT(stderr, ERROR, 4, 0, "Unable to flush mapped buffer: error 0x%x",(int)status);
2405 goto EXIT;
2406 }
2407
2408 if (pComponentPrivate->curState == OMX_StateExecuting) {
2409 if (!NBAMRDEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput)) {
2410 NBAMRDEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput);
2411 eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
2412 EMMCodecOuputBuffer,
2413 (OMX_U8 *)pBufHeader->pBuffer,
2414 OUTPUT_NBAMRDEC_BUFFER_SIZE*nFrames,
2415 OUTPUT_NBAMRDEC_BUFFER_SIZE*nFrames,
2416 (OMX_U8 *) pLcmlHdr->pBufferParam,
2417 sizeof(NBAMRDEC_ParamStruct),
2418 NULL);
2419 if (eError != OMX_ErrorNone ) {
2420 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: IssuingDSP OP: Error Occurred\n",__LINE__);
2421 eError = OMX_ErrorHardware;
2422 goto EXIT;
2423 }
2424 pComponentPrivate->lcml_nOpBuf++;
2425 }
2426 }
2427 else if (pComponentPrivate->curState == OMX_StatePause){
2428 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
2429 }
2430
2431 if (pComponentPrivate->bFlushOutputPortCommandPending) {
2432 OMX_SendCommand(pComponentPrivate->pHandle,
2433 OMX_CommandFlush,
2434 1,
2435 NULL);
2436 }
2437 }
2438 else {
2439 eError = OMX_ErrorBadParameter;
2440 }
2441
2442 EXIT:
2443 if (TOCframetype != NULL) {
2444 free(TOCframetype);
2445 }
2446 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Exiting from NBAMRDECHandleDataBuf_FromApp \n",__LINE__);
2447 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Returning error %d\n",__LINE__,eError);
2448 if (eError != OMX_ErrorNone ) {
2449 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2450 pComponentPrivate->pHandle->pApplicationPrivate,
2451 OMX_EventError,
2452 eError,
2453 OMX_TI_ErrorSevere,
2454 NULL);
2455 }
2456 return eError;
2457 }
2458
2459 /*-------------------------------------------------------------------*/
2460 /**
2461 * NBAMRDECGetBufferDirection () This function is used by the component thread to
2462 * request a buffer from the application. Since it was called from 2 places,
2463 * it made sense to turn this into a small function.
2464 *
2465 * @param pData pointer to AMR Decoder Context Structure
2466 * @param pCur pointer to the buffer to be requested to be filled
2467 *
2468 * @retval none
2469 **/
2470 /*-------------------------------------------------------------------*/
2471
NBAMRDECGetBufferDirection(OMX_BUFFERHEADERTYPE * pBufHeader,OMX_DIRTYPE * eDir)2472 OMX_ERRORTYPE NBAMRDECGetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader,
2473 OMX_DIRTYPE *eDir)
2474 {
2475 OMX_ERRORTYPE eError = OMX_ErrorNone;
2476 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate;
2477 OMX_U32 nBuf;
2478 OMX_BUFFERHEADERTYPE *pBuf = NULL;
2479 OMX_U16 flag = 1,i;
2480
2481 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Entering NBAMRDECGetBufferDirection Function\n",__LINE__);
2482
2483 /*Search this buffer in input buffers list */
2484 nBuf = pComponentPrivate->pInputBufferList->numBuffers;
2485 for(i=0; i<nBuf; i++) {
2486 pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i];
2487 if(pBufHeader == pBuf) {
2488 *eDir = OMX_DirInput;
2489 OMX_ERROR2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Buffer %p is INPUT BUFFER\n",__LINE__, pBufHeader);
2490 flag = 0;
2491 goto EXIT;
2492 }
2493 }
2494
2495 /*Search this buffer in input buffers list */
2496 nBuf = pComponentPrivate->pOutputBufferList->numBuffers;
2497
2498 for(i=0; i<nBuf; i++) {
2499 pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i];
2500 if(pBufHeader == pBuf) {
2501 *eDir = OMX_DirOutput;
2502 OMX_ERROR2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Buffer %p is OUTPUT BUFFER\n",__LINE__, pBufHeader);
2503 flag = 0;
2504 goto EXIT;
2505 }
2506 }
2507
2508 if (flag == 1) {
2509 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Buffer %p is Not Found in the List\n",__LINE__,pBufHeader);
2510 eError = OMX_ErrorUndefined;
2511 goto EXIT;
2512 }
2513 EXIT:
2514 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Exiting NBAMRDECGetBufferDirection Function\n",__LINE__);
2515 return eError;
2516 }
2517 /* -------------------------------------------------------------------*/
2518 /**
2519 * Callback() function will be called LCML component to write the msg
2520 *
2521 * @param msgBuffer This buffer will be returned by the LCML
2522 *
2523 * @retval OMX_NoError Success, ready to roll
2524 * OMX_Error_BadParameter The input parameter pointer is null
2525 **/
2526 /*-------------------------------------------------------------------*/
NBAMRDECLCML_Callback(TUsnCodecEvent event,void * args[10])2527 OMX_ERRORTYPE NBAMRDECLCML_Callback (TUsnCodecEvent event,void * args [10])
2528 {
2529 OMX_ERRORTYPE eError = OMX_ErrorNone;
2530 OMX_U8 *pBuffer = args[1];
2531 LCML_NBAMRDEC_BUFHEADERTYPE *pLcmlHdr;
2532 #ifdef RESOURCE_MANAGER_ENABLED
2533 OMX_ERRORTYPE rm_error = OMX_ErrorNone;
2534 #endif
2535 /* ssize_t ret; */
2536 OMX_COMPONENTTYPE *pHandle = NULL;
2537 LCML_DSP_INTERFACE *pLcmlHandle;
2538 OMX_U8 i;
2539 NBAMRDEC_BUFDATA *OutputFrames;
2540 DSP_STATUS status;
2541 LCML_DSP_INTERFACE *dspphandle = (LCML_DSP_INTERFACE *)args[6];
2542
2543 AMRDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
2544 pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)args[6])->pComponentPrivate;
2545 static double time_stmp = 0;
2546 pHandle = pComponentPrivate->pHandle;
2547
2548 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Entering the NBAMRDECLCML_Callback Function\n",__LINE__);
2549 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: args = %p\n",__LINE__,args[0]);
2550 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: event = %d\n",__LINE__,event);
2551
2552 switch(event) {
2553
2554 case EMMCodecDspError:
2555 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecDspError\n",__LINE__);
2556 break;
2557
2558 case EMMCodecInternalError:
2559 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecInternalError\n",__LINE__);
2560 break;
2561
2562 case EMMCodecInitError:
2563 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecInitError\n",__LINE__);
2564 break;
2565
2566 case EMMCodecDspMessageRecieved:
2567 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecDspMessageRecieved\n",__LINE__);
2568 break;
2569
2570 case EMMCodecBufferProcessed:
2571 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecBufferProcessed\n",__LINE__);
2572 break;
2573
2574 case EMMCodecProcessingStarted:
2575 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecProcessingStarted\n",__LINE__);
2576 break;
2577
2578 case EMMCodecProcessingPaused:
2579 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecProcessingPaused\n",__LINE__);
2580 break;
2581
2582 case EMMCodecProcessingStoped:
2583 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecProcessingStoped\n",__LINE__);
2584 break;
2585
2586 case EMMCodecProcessingEof:
2587 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecProcessingEof\n",__LINE__);
2588 break;
2589
2590 case EMMCodecBufferNotProcessed:
2591 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecBufferNotProcessed\n",__LINE__);
2592 break;
2593
2594 case EMMCodecAlgCtrlAck:
2595 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecAlgCtrlAck\n",__LINE__);
2596 break;
2597
2598 case EMMCodecStrmCtrlAck:
2599 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: [LCML CALLBACK EVENT] EMMCodecStrmCtrlAck\n",__LINE__);
2600 break;
2601 }
2602
2603
2604
2605 if(event == EMMCodecBufferProcessed)
2606 {
2607 if( (OMX_U32)args [0] == EMMCodecInputBuffer) {
2608 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Input: pBufferr = %p\n",__LINE__, pBuffer);
2609 if( pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]->bEnabled != OMX_FALSE){
2610 eError = NBAMRDECGetCorresponding_LCMLHeader(pComponentPrivate, pBuffer, OMX_DirInput, &pLcmlHdr);
2611 #ifdef __PERF_INSTRUMENTATION__
2612 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
2613 PREF(pLcmlHdr->buffer,pBuffer),
2614 0,
2615 PERF_ModuleCommonLayer);
2616 #endif
2617 if (eError != OMX_ErrorNone) {
2618 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Invalid Buffer Came ...\n",__LINE__);
2619 goto EXIT;
2620 }
2621 NBAMRDEC_ClearPending(pComponentPrivate,pLcmlHdr->buffer,OMX_DirInput);
2622 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Calling EmptyBufferDone\n",__LINE__);
2623 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pComponentPrivate->n\
2624 HoldLength = %ld\n",__LINE__,pComponentPrivate->nHoldLength);
2625 pComponentPrivate->nEmptyBufferDoneCount++;
2626
2627 #ifdef __PERF_INSTRUMENTATION__
2628 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
2629 PREF(pLcmlHdr->buffer,pBuffer),
2630 0,
2631 PERF_ModuleHLMM);
2632 #endif
2633 pComponentPrivate->cbInfo.EmptyBufferDone (pHandle,
2634 pHandle->pApplicationPrivate,
2635 pLcmlHdr->buffer);
2636 SignalIfAllBuffersAreReturned(pComponentPrivate);
2637 pComponentPrivate->lcml_nIpBuf--;
2638 pComponentPrivate->app_nBuf++;
2639 }
2640 } else if ((OMX_U32)args [0] == EMMCodecOuputBuffer) {
2641 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Output: pBufferr = %p\n",__LINE__, pBuffer);
2642
2643 eError = NBAMRDECGetCorresponding_LCMLHeader(pComponentPrivate, pBuffer, OMX_DirOutput, &pLcmlHdr);
2644 if (eError != OMX_ErrorNone) {
2645 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error: Invalid Buffer Came ...\n",__LINE__);
2646 goto EXIT;
2647 }
2648
2649 if (!pComponentPrivate->bStopSent){
2650 pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8];
2651 }
2652 else
2653 pLcmlHdr->buffer->nFilledLen = 0;
2654
2655 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECLCML_Callback:::\
2656 pLcmlHdr->buffer->nFilledLen = %ld\n",__LINE__,pLcmlHdr->buffer->nFilledLen);
2657
2658 OutputFrames = (pLcmlHdr->buffer)->pOutputPortPrivate;
2659 OutputFrames->nFrames = (OMX_U8) ((OMX_U32)args[8] / OUTPUT_NBAMRDEC_BUFFER_SIZE);
2660
2661 #ifdef __PERF_INSTRUMENTATION__
2662 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
2663 PREF(pLcmlHdr->buffer,pBuffer),
2664 PREF(pLcmlHdr->buffer,nFilledLen),
2665 PERF_ModuleCommonLayer);
2666 pComponentPrivate->nLcml_nCntOpReceived++;
2667 if ((pComponentPrivate->nLcml_nCntIp >= 1) &&
2668 (pComponentPrivate->nLcml_nCntOpReceived == 1)) {
2669 PERF_Boundary(pComponentPrivate->pPERFcomp,
2670 PERF_BoundaryStart | PERF_BoundarySteadyState);
2671 }
2672 #endif
2673
2674 NBAMRDEC_ClearPending(pComponentPrivate,pLcmlHdr->buffer,OMX_DirOutput);
2675 pComponentPrivate->nOutStandingFillDones++;
2676 pComponentPrivate->first_output_buf_rcv = 1;
2677
2678 for(i=0;i<pLcmlHdr->pBufferParam->usNbFrames;i++){
2679 if ( (pLcmlHdr->pFrameParam+i)->usLastFrame & OMX_BUFFERFLAG_EOS){
2680 (pLcmlHdr->pFrameParam+i)->usLastFrame = 0;
2681 (pLcmlHdr->pFrameParam+i)->usLastFrame = 0;
2682 pLcmlHdr->buffer->nFlags |= OMX_BUFFERFLAG_EOS;
2683 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: On Component receiving OMX_BUFFERFLAG_EOS on output\n", __LINE__);
2684 OMX_PRINT1(pComponentPrivate->dbg, "OMX_AmrDec_Utils.c : flushing pFrameParam2\n");
2685 status = DSPProcessor_FlushMemory(dspphandle->dspCodec->hProc, pLcmlHdr->pFrameParam, pLcmlHdr->pBufferParam->usNbFrames*sizeof(NBAMRDEC_FrameStruct), 0);
2686 if(DSP_FAILED(status))
2687 {
2688 OMXDBG_PRINT(stderr, ERROR, 4, 0, "Unable to flush mapped buffer: error 0x%x",(int)status);
2689 goto EXIT;
2690 }
2691 break;
2692 }
2693 }
2694 /* Copying time stamp information to output buffer */
2695 if(pComponentPrivate->first_buff == 1){
2696 pComponentPrivate->first_buff = 2;
2697 pLcmlHdr->buffer->nTimeStamp = pComponentPrivate->first_TS;
2698 pComponentPrivate->temp_TS = pLcmlHdr->buffer->nTimeStamp;
2699 }else{
2700 time_stmp = pLcmlHdr->buffer->nFilledLen / (1 * (((OMX_AUDIO_PARAM_PCMMODETYPE*)pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT])->nBitPerSample / 8));
2701 time_stmp = (time_stmp / ((OMX_AUDIO_PARAM_PCMMODETYPE*)pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT])->nSamplingRate) * 1000;
2702 pComponentPrivate->temp_TS += (OMX_U32)(time_stmp*1000);
2703 pLcmlHdr->buffer->nTimeStamp = pComponentPrivate->temp_TS;
2704 }
2705 /* Copying nTickCount information to output buffer */
2706 pLcmlHdr->buffer->nTickCount = pComponentPrivate->arrTickCount[pComponentPrivate->OpBufindex];
2707 pComponentPrivate->OpBufindex++;
2708 pComponentPrivate->OpBufindex %= pComponentPrivate->pPortDef[OMX_DirInput]->nBufferCountActual;
2709
2710 pComponentPrivate->LastOutbuf = pLcmlHdr->buffer;
2711 pComponentPrivate->num_Reclaimed_Op_Buff++;
2712
2713 OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Calling FillBufferDone\n",__LINE__);
2714
2715 pComponentPrivate->nFillBufferDoneCount++;
2716 #ifdef __PERF_INSTRUMENTATION__
2717 PERF_SendingBuffer(pComponentPrivate->pPERFcomp,
2718 PREF(pLcmlHdr->buffer,pBuffer),
2719 PREF(pLcmlHdr->buffer,nFilledLen),
2720 PERF_ModuleHLMM);
2721 #endif
2722 pComponentPrivate->cbInfo.FillBufferDone (pHandle,
2723 pHandle->pApplicationPrivate,
2724 pLcmlHdr->buffer);
2725 SignalIfAllBuffersAreReturned(pComponentPrivate);
2726 pComponentPrivate->lcml_nOpBuf--;
2727 pComponentPrivate->app_nBuf++;
2728 pComponentPrivate->nOutStandingFillDones--;
2729
2730 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Incrementing app_nBuf = %ld\n",__LINE__,pComponentPrivate->app_nBuf);
2731 }
2732 } else if (event == EMMCodecStrmCtrlAck) {
2733 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__);
2734 if (args[1] == (void *)USN_STRMCMD_FLUSH) {
2735 pHandle = pComponentPrivate->pHandle;
2736 if ( args[2] == (void *)EMMCodecInputBuffer) {
2737 if (args[0] == (void *)USN_ERR_NONE ) {
2738 OMX_PRCOMM1(pComponentPrivate->dbg, "Flushing input port %d\n",__LINE__);
2739 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) {
2740 pComponentPrivate->cbInfo.EmptyBufferDone (pHandle,
2741 pHandle->pApplicationPrivate,
2742 pComponentPrivate->pInputBufHdrPending[i]);
2743 pComponentPrivate->nEmptyBufferDoneCount++;
2744 SignalIfAllBuffersAreReturned(pComponentPrivate);
2745 pComponentPrivate->pInputBufHdrPending[i] = NULL;
2746 }
2747 pComponentPrivate->nNumInputBufPending=0;
2748 pComponentPrivate->cbInfo.EventHandler(pHandle,
2749 pHandle->pApplicationPrivate,
2750 OMX_EventCmdComplete,
2751 OMX_CommandFlush,
2752 NBAMRDEC_INPUT_PORT,
2753 NULL);
2754 } else {
2755 OMX_ERROR4(pComponentPrivate->dbg, "LCML reported error while flushing input port\n");
2756 goto EXIT;
2757 }
2758 }
2759 else if ( args[2] == (void *)EMMCodecOuputBuffer) {
2760 if (args[0] == (void *)USN_ERR_NONE ) {
2761 OMX_PRCOMM1(pComponentPrivate->dbg, "Flushing output port %d\n",__LINE__);
2762 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
2763 pComponentPrivate->cbInfo.FillBufferDone (pHandle,
2764 pHandle->pApplicationPrivate,
2765 pComponentPrivate->pOutputBufHdrPending[i]);
2766 pComponentPrivate->nFillBufferDoneCount++;
2767 SignalIfAllBuffersAreReturned(pComponentPrivate);
2768 pComponentPrivate->pOutputBufHdrPending[i] = NULL;
2769 }
2770 pComponentPrivate->nNumOutputBufPending=0;
2771 pComponentPrivate->cbInfo.EventHandler(pHandle,
2772 pHandle->pApplicationPrivate,
2773 OMX_EventCmdComplete,
2774 OMX_CommandFlush,
2775 NBAMRDEC_OUTPUT_PORT,
2776 NULL);
2777 } else {
2778 OMX_ERROR4(pComponentPrivate->dbg, "LCML reported error while flushing output port\n");
2779 goto EXIT;
2780 }
2781 }
2782 }
2783 }
2784 else if(event == EMMCodecProcessingStoped) {
2785 for (i = 0; i < pComponentPrivate->nNumInputBufPending; i++) {
2786 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
2787 pComponentPrivate->pHandle->pApplicationPrivate,
2788 pComponentPrivate->pInputBufHdrPending[i]);
2789 pComponentPrivate->nEmptyBufferDoneCount++;
2790 pComponentPrivate->pInputBufHdrPending[i] = NULL;
2791 SignalIfAllBuffersAreReturned(pComponentPrivate);
2792 }
2793 pComponentPrivate->nNumInputBufPending = 0;
2794 for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
2795 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
2796 pComponentPrivate->pHandle->pApplicationPrivate,
2797 pComponentPrivate->pOutputBufHdrPending[i]);
2798 pComponentPrivate->nFillBufferDoneCount++;
2799 SignalIfAllBuffersAreReturned(pComponentPrivate);
2800 pComponentPrivate->nOutStandingFillDones--;
2801 pComponentPrivate->pOutputBufHdrPending[i] = NULL;
2802 }
2803 pComponentPrivate->nNumOutputBufPending=0;
2804 pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
2805 if(pComponentPrivate->codecStop_waitingsignal == 0){
2806 pComponentPrivate->codecStop_waitingsignal = 1;
2807 pthread_cond_signal(&pComponentPrivate->codecStop_threshold);
2808 OMX_ERROR2(pComponentPrivate->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
2809 }
2810 pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
2811
2812 if (!pComponentPrivate->bNoIdleOnStop) {
2813 pComponentPrivate->nNumOutputBufPending=0;
2814
2815 /* pComponentPrivate->ProcessingInputBuf=0;
2816 pComponentPrivate->ProcessingOutputBuf=0;
2817 */
2818 pComponentPrivate->nHoldLength = 0;
2819 /* pComponentPrivate->InBuf_Eos_alreadysent =0; */
2820
2821 /* OMX_NBMEMFREE_STRUCT(pComponentPrivate->pHoldBuffer); */
2822 /* OMX_NBMEMFREE_STRUCT(pComponentPrivate->iMMFDataLastBuffer); */
2823
2824 pComponentPrivate->curState = OMX_StateIdle;
2825 #ifdef RESOURCE_MANAGER_ENABLED
2826 eError = RMProxy_NewSendCommand(pHandle,
2827 RMProxy_StateSet,
2828 OMX_NBAMR_Decoder_COMPONENT,
2829 OMX_StateIdle,
2830 3456,
2831 NULL);
2832 #endif
2833 /*
2834 if((pComponentPrivate->nEmptyThisBufferCount != pComponentPrivate->nEmptyBufferDoneCount) || (pComponentPrivate->nFillThisBufferCount != pComponentPrivate->nFillBufferDoneCount)) {
2835 if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
2836 {
2837 OMXDBG_PRINT(stderr, PRINT, 1, 0, "bufferReturned_mutex mutex lock error");
2838 }
2839 OMXDBG_PRINT(stderr, PRINT, 1, 0, "pthread_cond_waiting for OMX to return all input and outbut buffers");
2840 pthread_cond_wait(&bufferReturned_condition, &bufferReturned_mutex);
2841 OMXDBG_PRINT(stderr, PRINT, 1, 0, "OMX has returned all input and output buffers");
2842 if(pthread_mutex_unlock(&bufferReturned_mutex) != 0)
2843 {
2844 OMXDBG_PRINT(stderr, PRINT, 1, 0, "bufferReturned_mutex mutex unlock error");
2845 }
2846 }
2847 else
2848 {
2849 OMXDBG_PRINT(stderr, PRINT, 1, 0, "OMX has returned all input and output buffers");
2850 }
2851 */
2852 if(pComponentPrivate->bPreempted == 0){
2853 pComponentPrivate->cbInfo.EventHandler(pHandle,
2854 pHandle->pApplicationPrivate,
2855 OMX_EventCmdComplete,
2856 OMX_CommandStateSet,
2857 pComponentPrivate->curState,
2858 NULL);
2859 }else{
2860 pComponentPrivate->cbInfo.EventHandler(pHandle,
2861 pHandle->pApplicationPrivate,
2862 OMX_EventError,
2863 OMX_ErrorResourcesPreempted,
2864 OMX_TI_ErrorSevere,
2865 0);
2866 }
2867 }else{
2868 pComponentPrivate->bNoIdleOnStop = OMX_FALSE;
2869 }
2870 }
2871 else if (event == EMMCodecProcessingPaused) {
2872 pComponentPrivate->curState = OMX_StatePause;
2873 /* Send StateChangeNotification to application */
2874 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
2875 pComponentPrivate->pHandle->pApplicationPrivate,
2876 OMX_EventCmdComplete,
2877 OMX_CommandStateSet,
2878 pComponentPrivate->curState,
2879 NULL);
2880
2881 }
2882 else if (event == EMMCodecDspError) {
2883 switch ( (OMX_U32) args [4])
2884 {
2885 /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
2886 * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
2887 * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
2888 * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
2889 * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
2890 * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
2891 * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
2892 * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
2893
2894 #ifdef _ERROR_PROPAGATION__
2895 case USN_ERR_PAUSE:
2896 case USN_ERR_STOP:
2897 case USN_ERR_ALGCTRL:
2898 case USN_ERR_STRMCTRL:
2899 case USN_ERR_UNKNOWN_MSG:
2900
2901 {
2902 pComponentPrivate->bIsInvalidState=OMX_TRUE;
2903 pComponentPrivate->curState = OMX_StateInvalid;
2904 pHandle = pComponentPrivate->pHandle;
2905 pComponentPrivate->cbInfo.EventHandler(pHandle,
2906 pHandle->pApplicationPrivate,
2907 OMX_EventError,
2908 OMX_ErrorInvalidState,
2909 OMX_TI_ErrorSevere,
2910 NULL);
2911 }
2912 break;
2913 #endif
2914
2915 case USN_ERR_WARNING:
2916 case USN_ERR_PROCESS:
2917 NBAMRDEC_HandleUSNError (pComponentPrivate, (OMX_U32)args[5]);
2918 break;
2919 default:
2920 break;
2921 }
2922 }
2923
2924 if(event == EMMCodecDspMessageRecieved) {
2925 OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: commandedState = %p\n",__LINE__,args[0]);
2926 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: arg1 = %p\n",__LINE__,args[1]);
2927 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: arg2 = %p\n",__LINE__,args[2]);
2928 }
2929
2930 #ifdef _ERROR_PROPAGATION__
2931
2932 else if (event ==EMMCodecInitError){
2933 /* Cheking for MMU_fault */
2934 if(((int) args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*) NULL)) {
2935 pComponentPrivate->bIsInvalidState=OMX_TRUE;
2936 pComponentPrivate->curState = OMX_StateInvalid;
2937 pHandle = pComponentPrivate->pHandle;
2938 pComponentPrivate->cbInfo.EventHandler(pHandle,
2939 pHandle->pApplicationPrivate,
2940 OMX_EventError,
2941 OMX_ErrorInvalidState,
2942 OMX_TI_ErrorSevere,
2943 NULL);
2944 }
2945 }
2946 else if (event ==EMMCodecInternalError){
2947 /* Cheking for MMU_fault */
2948 if(((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*) NULL)) {
2949 pComponentPrivate->bIsInvalidState=OMX_TRUE;
2950 pComponentPrivate->curState = OMX_StateInvalid;
2951 pHandle = pComponentPrivate->pHandle;
2952 pComponentPrivate->cbInfo.EventHandler(pHandle,
2953 pHandle->pApplicationPrivate,
2954 OMX_EventError,
2955 OMX_ErrorInvalidState,
2956 OMX_TI_ErrorSevere,
2957 NULL);
2958 }
2959
2960 }
2961 #endif
2962 EXIT:
2963 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Exiting the NBAMRDECLCML_Callback Function\n",__LINE__);
2964 return eError;
2965 }
2966
2967
NBAMRDECGetCorresponding_LCMLHeader(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate,OMX_U8 * pBuffer,OMX_DIRTYPE eDir,LCML_NBAMRDEC_BUFHEADERTYPE ** ppLcmlHdr)2968 OMX_ERRORTYPE NBAMRDECGetCorresponding_LCMLHeader(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate,
2969 OMX_U8 *pBuffer,
2970 OMX_DIRTYPE eDir,
2971 LCML_NBAMRDEC_BUFHEADERTYPE **ppLcmlHdr)
2972 {
2973 OMX_ERRORTYPE eError = OMX_ErrorNone;
2974 LCML_NBAMRDEC_BUFHEADERTYPE *pLcmlBufHeader;
2975
2976 OMX_S16 nIpBuf;
2977 OMX_S16 nOpBuf;
2978 OMX_S16 i;
2979
2980 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
2981 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
2982
2983 while (!pComponentPrivate->bInitParamsInitialized)
2984 {
2985 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Waiting for init to complete\n",__LINE__);
2986 #ifndef UNDER_CE
2987 sched_yield();
2988 #else
2989 Sleep(0);
2990 #endif
2991 }
2992 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECGetCorresponding_LCMLHeader..\n",__LINE__);
2993 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pComponentPrivate = %p\n",__LINE__,pComponentPrivate);
2994
2995 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: eDir = %d\n",__LINE__,eDir);
2996 if(eDir == OMX_DirInput) {
2997 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
2998 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECGetCorresponding_LCMLHeader..\n",__LINE__);
2999 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pComponentPrivate = %p\n",__LINE__,pComponentPrivate);
3000 pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT];
3001 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECGetCorresponding_LCMLHeader..\n",__LINE__);
3002 for(i=0; i<nIpBuf; i++) {
3003 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECGetCorresponding_LCMLHeader..\n",__LINE__);
3004 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pBuffer = %p\n",__LINE__,pBuffer);
3005 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECGetCorresponding_LCMLHeader..\n",__LINE__);
3006 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pLcmlBufHeader->buffer->pBuffer = %p\n",__LINE__,pLcmlBufHeader->buffer->pBuffer);
3007 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECGetCorresponding_LCMLHeader..\n",__LINE__);
3008 if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
3009 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECGetCorresponding_LCMLHeader..\n",__LINE__);
3010 *ppLcmlHdr = pLcmlBufHeader;
3011 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Corresponding LCML Header Found\n",__LINE__);
3012 goto EXIT;
3013 }
3014 pLcmlBufHeader++;
3015 }
3016 } else if (eDir == OMX_DirOutput) {
3017 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
3018 pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT];
3019 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
3020
3021 for(i=0; i<nOpBuf; i++) {
3022 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
3023
3024 if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
3025
3026 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pBuffer = %p\n",__LINE__,pBuffer);
3027 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pLcmlBufHeader->buffer->pBuffer = %p\n",__LINE__,pLcmlBufHeader->buffer->pBuffer);
3028
3029 *ppLcmlHdr = pLcmlBufHeader;
3030 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
3031
3032 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Corresponding LCML Header Found\n",__LINE__);
3033 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
3034
3035 goto EXIT;
3036 }
3037 pLcmlBufHeader++;
3038 }
3039 } else {
3040 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
3041 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Invalid Buffer Type :: exiting...\n",__LINE__);
3042 }
3043 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::\n",__LINE__);
3044
3045 EXIT:
3046 return eError;
3047 }
3048
3049
3050 #ifndef UNDER_CE
3051
NBAMRDECGetLCMLHandle(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate)3052 OMX_HANDLETYPE NBAMRDECGetLCMLHandle(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate)
3053 {
3054 void *handle;
3055 OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
3056 OMX_HANDLETYPE pHandle = NULL;
3057 OMX_S8 *error;
3058 OMX_ERRORTYPE eError;
3059
3060 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECGetLCMLHandle\n",__LINE__);
3061 handle = dlopen("libLCML.so", RTLD_LAZY);
3062 if (!handle) {
3063 fputs(dlerror(), stderr);
3064 goto EXIT;
3065 }
3066
3067 fpGetHandle = dlsym (handle, "GetHandle");
3068 if ((error = (void*)dlerror()) != NULL)
3069 {
3070 fputs((void*)error, stderr);
3071 dlclose(handle);
3072 goto EXIT;
3073 }
3074 eError = (*fpGetHandle)(&pHandle);
3075 if(eError != OMX_ErrorNone) {
3076 eError = OMX_ErrorUndefined;
3077 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: eError != OMX_ErrorNone...\n",__LINE__);
3078 pHandle = NULL;
3079 dlclose(handle);
3080 goto EXIT;
3081 }
3082 pComponentPrivate->bLcmlHandleOpened = 1;
3083
3084 ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
3085
3086 pComponentPrivate->ptrLibLCML=handle; /* saving LCML lib pointer */
3087
3088 EXIT:
3089 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECGetLCMLHandle returning %p\n",__LINE__,pHandle);
3090
3091 return pHandle;
3092 }
3093
3094
3095 #else
3096 //WINDOWS Explicit dll load procedure
NBAMRDECGetLCMLHandle(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate)3097 OMX_HANDLETYPE NBAMRDECGetLCMLHandle(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate)
3098 {
3099 typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
3100 OMX_HANDLETYPE pHandle = NULL;
3101 OMX_ERRORTYPE eError;
3102 HINSTANCE hDLL; // Handle to DLL
3103 LPFNDLLFUNC1 fpGetHandle1;
3104
3105 hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL,0);
3106 if (hDLL == NULL)
3107 {
3108 //fputs(dlerror(), stderr);
3109 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: BML Load Failed!!!\n",__LINE__);
3110 return pHandle;
3111 }
3112
3113 fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,TEXT("GetHandle"));
3114 if (!fpGetHandle1)
3115 {
3116 // handle the error
3117 FreeLibrary(hDLL);
3118
3119 return pHandle;
3120 }
3121
3122 // call the function
3123 eError = fpGetHandle1(&pHandle);
3124 if(eError != OMX_ErrorNone) {
3125 eError = OMX_ErrorUndefined;
3126 OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: eError != OMX_ErrorNone...\n",__LINE__);
3127
3128 pHandle = NULL;
3129 return pHandle;
3130 }
3131
3132 ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
3133 return pHandle;
3134 }
3135 #endif
3136
3137
3138 #ifndef UNDER_CE
3139
NBAMRDECFreeLCMLHandle(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate)3140 OMX_ERRORTYPE NBAMRDECFreeLCMLHandle(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate)
3141 {
3142 OMX_S16 retValue;
3143 OMX_ERRORTYPE eError = OMX_ErrorNone;
3144
3145 if (pComponentPrivate->bLcmlHandleOpened) {
3146 retValue = dlclose(pComponentPrivate->pLcmlHandle);
3147
3148 if (retValue != 0) {
3149 eError = OMX_ErrorUndefined;
3150 }
3151 pComponentPrivate->bLcmlHandleOpened = 0;
3152 }
3153
3154 return eError;
3155 }
3156 #else
3157
3158
NBAMRDECFreeLCMLHandle(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate)3159 OMX_ERRORTYPE NBAMRDECFreeLCMLHandle(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate)
3160 {
3161
3162 OMX_S16 retValue;
3163 OMX_ERRORTYPE eError = OMX_ErrorNone;
3164
3165 if (pComponentPrivate->bLcmlHandleOpened) {
3166
3167 retValue = FreeLibrary(pComponentPrivate->pLcmlHandle);
3168 if (retValue == 0) { /* Zero Indicates failure */
3169 eError = OMX_ErrorUndefined;
3170 }
3171 pComponentPrivate->bLcmlHandleOpened = 0;
3172 }
3173
3174 return eError;
3175 }
3176
3177
3178
3179 #endif
NBAMRDEC_SetPending(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate,OMX_BUFFERHEADERTYPE * pBufHdr,OMX_DIRTYPE eDir)3180 void NBAMRDEC_SetPending(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir)
3181 {
3182 OMX_S16 i;
3183
3184 if (eDir == OMX_DirInput) {
3185 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
3186 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
3187 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1;
3188 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: *****INPUT BUFFER %d IS PENDING****\n",__LINE__,i);
3189 }
3190 }
3191 }
3192 else {
3193 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
3194 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
3195 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1;
3196 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: *****OUTPUT BUFFER %d IS PENDING****\n",__LINE__,i);
3197 }
3198 }
3199 }
3200 }
3201
NBAMRDEC_ClearPending(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate,OMX_BUFFERHEADERTYPE * pBufHdr,OMX_DIRTYPE eDir)3202 void NBAMRDEC_ClearPending(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir)
3203 {
3204 OMX_S16 i;
3205
3206 if (eDir == OMX_DirInput) {
3207 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
3208 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
3209 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0;
3210 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ****INPUT BUFFER %d IS RECLAIMED****\n",__LINE__,i);
3211 }
3212 }
3213 }
3214 else {
3215 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
3216 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
3217 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0;
3218 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ****OUTPUT BUFFER %d IS RECLAIMED****\n",__LINE__,i);
3219 }
3220 }
3221 }
3222 }
3223
NBAMRDEC_IsPending(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate,OMX_BUFFERHEADERTYPE * pBufHdr,OMX_DIRTYPE eDir)3224 OMX_U32 NBAMRDEC_IsPending(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir)
3225 {
3226 OMX_S16 i;
3227
3228 if (eDir == OMX_DirInput) {
3229 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
3230 if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
3231 return pComponentPrivate->pInputBufferList->bBufferPending[i];
3232 }
3233 }
3234 }
3235 else {
3236 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
3237 if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
3238 return pComponentPrivate->pOutputBufferList->bBufferPending[i];
3239 }
3240 }
3241 }
3242 return -1;
3243 }
3244
3245
NBAMRDEC_IsValid(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate,OMX_U8 * pBuffer,OMX_DIRTYPE eDir)3246 OMX_U32 NBAMRDEC_IsValid(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir)
3247 {
3248 OMX_S16 i;
3249 OMX_S16 found=0;
3250
3251 if (eDir == OMX_DirInput) {
3252 for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
3253 if (pBuffer == pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer) {
3254 found = 1;
3255 }
3256 }
3257 }
3258 else {
3259 for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
3260 if (pBuffer == pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer) {
3261 found = 1;
3262 }
3263 }
3264 }
3265 return found;
3266 }
3267
3268
NBAMRDECFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent)3269 OMX_ERRORTYPE NBAMRDECFill_LCMLInitParamsEx (OMX_HANDLETYPE pComponent )
3270 {
3271 OMX_ERRORTYPE eError = OMX_ErrorNone;
3272 OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
3273 OMX_U16 i;
3274 OMX_BUFFERHEADERTYPE *pTemp;
3275 OMX_S16 size_lcml;
3276 char *ptr;
3277
3278 LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
3279 AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
3280 LCML_NBAMRDEC_BUFHEADERTYPE *pTemp_lcml;
3281
3282 OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECFill_LCMLInitParams\n ",__LINE__);
3283 OMXDBG_PRINT(stderr, PRINT, 2, 0, "%d :: OMX_AmrDec_Utils.c :: pHandle = %p\n",__LINE__,pHandle);
3284 OMXDBG_PRINT(stderr, PRINT, 2, 0, "%d :: OMX_AmrDec_Utils.c :: pHandle->pComponentPrivate = %p\n",__LINE__,pHandle->pComponentPrivate);
3285 pComponentPrivate = pHandle->pComponentPrivate;
3286
3287 nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
3288
3289 if(pComponentPrivate->mimemode == 1) {
3290 nIpBufSize = INPUT_NBAMRDEC_BUFFER_SIZE_MIME;
3291 }
3292 else {
3293 if (OMX_AUDIO_AMRDTXasEFR == pComponentPrivate->iAmrMode){
3294 nIpBufSize = INPUT_BUFF_SIZE_EFR;
3295 }
3296 else{
3297 nIpBufSize = STD_NBAMRDEC_BUF_SIZE;
3298 }
3299 }
3300
3301 nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
3302 nOpBufSize = OUTPUT_NBAMRDEC_BUFFER_SIZE;
3303
3304
3305 size_lcml = (OMX_S16)nIpBuf * sizeof(LCML_NBAMRDEC_BUFHEADERTYPE);
3306 OMX_MALLOC_SIZE(ptr, size_lcml,char);
3307 pTemp_lcml = (LCML_NBAMRDEC_BUFHEADERTYPE *)ptr;
3308
3309 pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT] = pTemp_lcml;
3310
3311 for (i=0; i<nIpBuf; i++) {
3312 pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
3313 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
3314 /* pTemp->nAllocLen = nIpBufSize;*/
3315 pTemp->nFilledLen = nIpBufSize;
3316 pTemp->nVersion.s.nVersionMajor = AMRDEC_MAJOR_VER;
3317 pTemp->nVersion.s.nVersionMinor = AMRDEC_MINOR_VER;
3318 pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
3319 pTemp->nTickCount = NOT_USED;
3320 pTemp_lcml->buffer = pTemp;
3321 pTemp_lcml->eDir = OMX_DirInput;
3322
3323 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
3324 sizeof(NBAMRDEC_ParamStruct),
3325 NBAMRDEC_ParamStruct);
3326
3327
3328 OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
3329 pTemp_lcml->pFrameParam = NULL;
3330 pTemp_lcml->pBufferParam->usNbFrames =0;
3331 pTemp_lcml->pBufferParam->pParamElem = NULL;
3332
3333 /* This means, it is not a last buffer. This flag is to be modified by
3334 * the application to indicate the last buffer */
3335 pTemp->nFlags = NORMAL_BUFFER;
3336
3337 pTemp_lcml++;
3338 }
3339
3340 /* Allocate memory for all output buffer headers..
3341 * This memory pointer will be sent to LCML */
3342 size_lcml = (OMX_S16)nOpBuf * sizeof(LCML_NBAMRDEC_BUFHEADERTYPE);
3343
3344 OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,LCML_NBAMRDEC_BUFHEADERTYPE);
3345
3346 pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT] = pTemp_lcml;
3347
3348 for (i=0; i<nOpBuf; i++) {
3349 pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
3350 pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
3351 /* pTemp->nAllocLen = nOpBufSize;*/
3352 pTemp->nFilledLen = nOpBufSize;
3353 pTemp->nVersion.s.nVersionMajor = AMRDEC_MAJOR_VER;
3354 pTemp->nVersion.s.nVersionMinor = AMRDEC_MINOR_VER;
3355 pComponentPrivate->nVersion = pTemp->nVersion.nVersion;
3356 pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
3357 pTemp->nTickCount = NOT_USED;
3358 pTemp_lcml->pFrameParam = NULL;
3359
3360 OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
3361 sizeof(NBAMRDEC_ParamStruct),
3362 NBAMRDEC_ParamStruct);
3363
3364 pTemp_lcml->pBufferParam->usNbFrames =0;
3365 pTemp_lcml->pBufferParam->pParamElem = NULL;
3366 OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
3367
3368 pTemp_lcml->buffer = pTemp;
3369 pTemp_lcml->eDir = OMX_DirOutput;
3370 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pTemp_lcml = %p\n",__LINE__,pTemp_lcml);
3371 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: pTemp_lcml->buffer = %p\n",__LINE__,pTemp_lcml->buffer);
3372
3373 pTemp->nFlags = NORMAL_BUFFER;
3374
3375 pTemp++;
3376 pTemp_lcml++;
3377 }
3378 pComponentPrivate->bPortDefsAllocated = 1;
3379
3380 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Exiting NBAMRDECFill_LCMLInitParams",__LINE__);
3381
3382 pComponentPrivate->bInitParamsInitialized = 1;
3383 EXIT:
3384 return eError;
3385 }
3386 /** ========================================================================
3387 * OMX_DmmMap () method is used to allocate the memory using DMM.
3388 *
3389 * @param ProcHandle - Component identification number
3390 * @param size - Buffer header address, that needs to be sent to codec
3391 * @param pArmPtr - Message used to send the buffer to codec
3392 * @param pDmmBuf - buffer id
3393 *
3394 * @retval OMX_ErrorNone - Success
3395 * OMX_ErrorHardware - Hardware Error
3396 ** ==========================================================================*/
OMX_DmmMap(DSP_HPROCESSOR ProcHandle,int size,void * pArmPtr,DMM_BUFFER_OBJ * pDmmBuf,struct OMX_TI_Debug dbg)3397 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle,
3398 int size,
3399 void* pArmPtr,
3400 DMM_BUFFER_OBJ* pDmmBuf, struct OMX_TI_Debug dbg)
3401 {
3402 OMX_ERRORTYPE eError = OMX_ErrorUndefined;
3403 DSP_STATUS status;
3404 int nSizeReserved = 0;
3405
3406 if(pDmmBuf == NULL)
3407 {
3408 OMX_ERROR4 (dbg, "pBuf is NULL\n");
3409 eError = OMX_ErrorBadParameter;
3410 goto EXIT;
3411 }
3412
3413 if(pArmPtr == NULL)
3414 {
3415 OMX_ERROR4 (dbg, "pBuf is NULL\n");
3416 eError = OMX_ErrorBadParameter;
3417 goto EXIT;
3418 }
3419
3420 /* Allocate */
3421 pDmmBuf->pAllocated = pArmPtr;
3422
3423 /* Reserve */
3424 nSizeReserved = ROUND_TO_PAGESIZE(size) + 2*DMM_PAGE_SIZE ;
3425 status = DSPProcessor_ReserveMemory(ProcHandle, nSizeReserved, &(pDmmBuf->pReserved));
3426 OMX_PRDSP2 (dbg, "\nOMX Reserve DSP: %p\n",pDmmBuf->pReserved);
3427
3428 if(DSP_FAILED(status))
3429 {
3430 OMX_ERROR4 (dbg, "DSPProcessor_ReserveMemory() failed - error 0x%x", (int)status);
3431 eError = OMX_ErrorHardware;
3432 goto EXIT;
3433 }
3434 pDmmBuf->nSize = size;
3435 OMX_PRBUFFER2 (dbg, " DMM MAP Reserved: %p, size 0x%x (%d)\n", pDmmBuf->pReserved,nSizeReserved,nSizeReserved);
3436
3437 /* Map */
3438 status = DSPProcessor_Map(ProcHandle,
3439 pDmmBuf->pAllocated,/* Arm addres of data to Map on DSP*/
3440 size , /* size to Map on DSP*/
3441 pDmmBuf->pReserved, /* reserved space */
3442 &(pDmmBuf->pMapped), /* returned map pointer */
3443 0); /* final param is reserved. set to zero. */
3444 if(DSP_FAILED(status))
3445 {
3446 OMX_ERROR4 (dbg, "DSPProcessor_Map() failed - error 0x%x", (int)status);
3447 eError = OMX_ErrorHardware;
3448 goto EXIT;
3449 }
3450 OMX_PRBUFFER2 (dbg, "DMM Mapped: %p, size 0x%x (%d)\n",pDmmBuf->pMapped, size,size);
3451
3452 /* Issue an initial memory flush to ensure cache coherency */
3453 status = DSPProcessor_FlushMemory(ProcHandle, pDmmBuf->pAllocated, size, 0);
3454 if(DSP_FAILED(status))
3455 {
3456 OMX_ERROR4 (dbg, "Unable to flush mapped buffer: error 0x%x",(int)status);
3457 goto EXIT;
3458 }
3459 eError = OMX_ErrorNone;
3460
3461 EXIT:
3462 return eError;
3463 }
3464
3465 /** ========================================================================
3466 * OMX_DmmUnMap () method is used to de-allocate the memory using DMM.
3467 *
3468 * @param ProcHandle - Component identification number
3469 * @param pMapPtr - Map address
3470 * @param pResPtr - reserve adress
3471 *
3472 * @retval OMX_ErrorNone - Success
3473 * OMX_ErrorHardware - Hardware Error
3474 ** ==========================================================================*/
OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle,void * pMapPtr,void * pResPtr,struct OMX_TI_Debug dbg)3475 OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg)
3476 {
3477 DSP_STATUS status = DSP_SOK;
3478 OMX_ERRORTYPE eError = OMX_ErrorNone;
3479 OMX_PRDSP2 (dbg, "\nOMX UnReserve DSP: %p\n",pResPtr);
3480
3481 if(pMapPtr == NULL)
3482 {
3483 OMX_ERROR4 (dbg, "pMapPtr is NULL\n");
3484 eError = OMX_ErrorBadParameter;
3485 goto EXIT;
3486 }
3487 if(pResPtr == NULL)
3488 {
3489 OMX_ERROR4 (dbg, "pResPtr is NULL\n");
3490 eError = OMX_ErrorBadParameter;
3491 goto EXIT;
3492 }
3493 status = DSPProcessor_UnMap(ProcHandle,pMapPtr);
3494 if(DSP_FAILED(status))
3495 {
3496 OMX_ERROR4 (dbg, "DSPProcessor_UnMap() failed - error 0x%x",(int)status);
3497 }
3498
3499 OMX_PRINT2 (dbg, "unreserving structure =0x%p\n",pResPtr);
3500 status = DSPProcessor_UnReserveMemory(ProcHandle,pResPtr);
3501 if(DSP_FAILED(status))
3502 {
3503 OMX_ERROR4 (dbg, "DSPProcessor_UnReserveMemory() failed - error 0x%x", (int)status);
3504 }
3505
3506 EXIT:
3507 return eError;
3508 }
3509
3510 #ifdef UNDER_CE
3511 /* ================================================================================= */
3512 /**
3513 * @fns Sleep replace for WIN CE
3514 */
3515 /* ================================================================================ */
OMX_CreateEvent(OMX_Event * event)3516 int OMX_CreateEvent(OMX_Event *event){
3517 int ret = OMX_ErrorNone;
3518 HANDLE createdEvent = NULL;
3519 if(event == NULL){
3520 ret = OMX_ErrorBadParameter;
3521 goto EXIT;
3522 }
3523 event->event = CreateEvent(NULL, TRUE, FALSE, NULL);
3524 if(event->event == NULL)
3525 ret = (int)GetLastError();
3526 EXIT:
3527 return ret;
3528 }
3529
OMX_SignalEvent(OMX_Event * event)3530 int OMX_SignalEvent(OMX_Event *event){
3531 int ret = OMX_ErrorNone;
3532 if(event == NULL){
3533 ret = OMX_ErrorBadParameter;
3534 goto EXIT;
3535 }
3536 SetEvent(event->event);
3537 ret = (int)GetLastError();
3538 EXIT:
3539 return ret;
3540 }
3541
OMX_WaitForEvent(OMX_Event * event)3542 int OMX_WaitForEvent(OMX_Event *event) {
3543 int ret = OMX_ErrorNone;
3544 if(event == NULL){
3545 ret = OMX_ErrorBadParameter;
3546 goto EXIT;
3547 }
3548 WaitForSingleObject(event->event, INFINITE);
3549 ret = (int)GetLastError();
3550 EXIT:
3551 return ret;
3552 }
3553
OMX_DestroyEvent(OMX_Event * event)3554 int OMX_DestroyEvent(OMX_Event *event) {
3555 int ret = OMX_ErrorNone;
3556 if(event == NULL){
3557 ret = OMX_ErrorBadParameter;
3558 goto EXIT;
3559 }
3560 CloseHandle(event->event);
3561 EXIT:
3562 return ret;
3563 }
3564 #endif
3565
SignalIfAllBuffersAreReturned(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate)3566 void SignalIfAllBuffersAreReturned(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate)
3567 {
3568 if((pComponentPrivate->nEmptyThisBufferCount == pComponentPrivate->nEmptyBufferDoneCount) && (pComponentPrivate->nFillThisBufferCount == pComponentPrivate->nFillBufferDoneCount))
3569 {
3570 if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
3571 {
3572 OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex lock error\n",__LINE__);
3573 }
3574 pthread_cond_broadcast(&bufferReturned_condition);
3575 OMX_PRINT2(pComponentPrivate->dbg, ":: Sending pthread signal that OMX has returned all buffers to app\n");
3576 if(pthread_mutex_unlock(&bufferReturned_mutex) != 0)
3577 {
3578 OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex unlock error\n",__LINE__);
3579 }
3580 return;
3581 }
3582 }
3583 #ifdef RESOURCE_MANAGER_ENABLED
NBAMR_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)3584 void NBAMR_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
3585 {
3586 OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
3587 OMX_STATETYPE state = OMX_StateIdle;
3588 OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
3589 AMRDEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
3590
3591 pCompPrivate = (AMRDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
3592
3593 if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) {
3594 if (pCompPrivate->curState == OMX_StateExecuting ||
3595 pCompPrivate->curState == OMX_StatePause) {
3596 write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
3597 write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
3598
3599 pCompPrivate->bPreempted = 1;
3600 }
3601 }
3602 else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
3603 pCompPrivate->cbInfo.EventHandler (
3604 pHandle, pHandle->pApplicationPrivate,
3605 OMX_EventResourcesAcquired, 0,0,
3606 NULL);
3607 }
3608 }
3609 #endif
3610
NBAMRDEC_HandleUSNError(AMRDEC_COMPONENT_PRIVATE * pComponentPrivate,OMX_U32 arg)3611 void NBAMRDEC_HandleUSNError (AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
3612 {
3613 OMX_COMPONENTTYPE *pHandle = NULL;
3614 OMX_U8 pending_buffers = OMX_FALSE;
3615 OMX_U32 i;
3616 switch (arg)
3617 {
3618 case IUALG_WARN_CONCEALED:
3619 case IUALG_WARN_UNDERFLOW:
3620 case IUALG_WARN_OVERFLOW:
3621 case IUALG_WARN_ENDOFDATA:
3622 /* all of these are informative messages, Algo can recover, no need to notify the
3623 * IL Client at this stage of the implementation */
3624 break;
3625
3626 case IUALG_WARN_PLAYCOMPLETED:
3627 {
3628 pHandle = pComponentPrivate->pHandle;
3629 OMX_PRDSP1(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__);
3630 if(pComponentPrivate->LastOutbuf!=NULL && !pComponentPrivate->dasfmode){
3631 pComponentPrivate->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS;
3632 }
3633
3634 /* add callback to application to indicate SN/USN has completed playing of current set of date */
3635 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
3636 pComponentPrivate->pHandle->pApplicationPrivate,
3637 OMX_EventBufferFlag,
3638 (OMX_U32)NULL,
3639 OMX_BUFFERFLAG_EOS,
3640 NULL);
3641 }
3642 break;
3643
3644 #ifdef _ERROR_PROPAGATION__
3645 case IUALG_ERR_BAD_HANDLE:
3646 case IUALG_ERR_DATA_CORRUPT:
3647 case IUALG_ERR_NOT_SUPPORTED:
3648 case IUALG_ERR_ARGUMENT:
3649 case IUALG_ERR_NOT_READY:
3650 case IUALG_ERR_GENERAL:
3651 {
3652 /* all of these are fatal messages, Algo can not recover
3653 * hence return an error */
3654 pComponentPrivate->bIsInvalidState=OMX_TRUE;
3655 pComponentPrivate->curState = OMX_StateInvalid;
3656 pHandle = pComponentPrivate->pHandle;
3657 pComponentPrivate->cbInfo.EventHandler(pHandle,
3658 pHandle->pApplicationPrivate,
3659 OMX_EventError,
3660 OMX_ErrorInvalidState,
3661 OMX_TI_ErrorSevere,
3662 NULL);
3663 }
3664 break;
3665 #endif
3666 default:
3667 break;
3668 }
3669 }
3670