• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 LCML_DspCodec.c
30 *
31 * This file implements LCML for Linux 8.x
32 *
33 * @path  $(CSLPATH)\
34 *
35 * @rev  1.0
36 */
37 /* ----------------------------------------------------------------------------
38 *!
39 *! Revision History
40 *! ===================================
41 *!
42 *!
43 * ============================================================================= */
44 
45 #ifdef UNDER_CE
46     #include <windows.h>
47 #else
48     #include <errno.h>
49 #endif
50 
51 #ifdef ANDROID
52 #include <linux/prctl.h>
53 #endif
54 
55 #include <pthread.h>
56 
57 /* Common WinCE and Linux Headers */
58 #include "LCML_DspCodec.h"
59 #include <stdlib.h>
60 #include <stdio.h>
61 #include <string.h>
62 #include "usn.h"
63 #include <sys/time.h>
64 
65 #define CEXEC_DONE 1
66 /*DSP_HNODE hDasfNode;*/
67 #define ABS_DLL_NAME_LENGTH 128
68 #undef LOG_TAG
69 #define LOG_TAG "TI_LCML"
70 
71 #define LCML_MALLOC(p,s,t) \
72     p = (t*)malloc(s);                  \
73     if (NULL == p){             \
74         OMXDBG_PRINT(stderr, ERROR, 4, OMX_DBG_BASEMASK, "LCML:::::::: ERROR(#%d F:%s)!!! Ran out of memory while trying to allocate %d bytes!!!\n",__LINE__,__FUNCTION__,s);    \
75     }else { \
76         OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "LCML:::::::: (#%d F:%s)Success to allocate %d bytes ... pointer %p\n",__LINE__,__FUNCTION__,s,p); \
77     }
78 
79 #define LCML_FREE(p)    \
80         OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "LCML:::::::: (#%d F:%s)Freeing pointer %p done",__LINE__,__FUNCTION__,p); \
81         free(p);
82 
83 /*Prototyping*/
84 static OMX_ERRORTYPE InitMMCodec(OMX_HANDLETYPE hInt,
85                                  OMX_STRING  codecName,
86                                  void *toCodecInitParams,
87                                  void *fromCodecInfoStruct,
88                                  LCML_CALLBACKTYPE *pCallbacks);
89 static OMX_ERRORTYPE InitMMCodecEx(OMX_HANDLETYPE hInt,
90                                    OMX_STRING  codecName,
91                                    void *toCodecInitParams,
92                                    void *fromCodecInfoStruct,
93                                    LCML_CALLBACKTYPE *pCallbacks,
94                                    OMX_STRING  Args);
95 static OMX_ERRORTYPE WaitForEvent(OMX_HANDLETYPE hComponent,
96                                   TUsnCodecEvent event,
97                                   void *args[10]);
98 static OMX_ERRORTYPE QueueBuffer(OMX_HANDLETYPE hComponent,
99                                  TMMCodecBufferType bufType,
100                                  OMX_U8 *buffer,
101                                  OMX_S32 bufferLen,
102                                  OMX_S32 bufferSizeUsed ,
103                                  OMX_U8 *auxInfo,
104                                  OMX_S32 auxInfoLen,
105                                  OMX_U8 *usrArg);
106 static OMX_ERRORTYPE ControlCodec(OMX_HANDLETYPE hComponent,
107                                   TControlCmd iCodecCmd,
108                                   void *args[10]);
109 static OMX_ERRORTYPE DmmMap(DSP_HPROCESSOR ProcHandle,
110                      OMX_U32 size,
111                      void* pArmPtr,
112                      DMM_BUFFER_OBJ* pDmmBuf,
113                      struct OMX_TI_Debug dbg);
114 
115 static OMX_ERRORTYPE DmmUnMap(DSP_HPROCESSOR ProcHandle,
116                               void *pMapPtr,
117                               void *pResPtr,
118                               struct OMX_TI_Debug dbg);
119 static OMX_ERRORTYPE DeleteDspResource(LCML_DSP_INTERFACE *hInterface);
120 static OMX_ERRORTYPE FreeResources(LCML_DSP_INTERFACE *hInterface);
121 
122 void* MessagingThread(void *arg);
123 
124 static int append_dsp_path(char * dll64p_name, char *absDLLname);
125 
126 
127 /** ========================================================================
128 *  GetHandle function is called by OMX component to get LCML handle
129 *  @param hInterface - Handle of the component to be accessed
130 *  @return OMX_ERRORTYPE
131 *      If the command successfully executes, the return code will be
132 *      OMX_NoError.  Otherwise the appropriate OMX error will be returned.
133 ** =========================================================================*/
GetHandle(OMX_HANDLETYPE * hInterface)134 OMX_ERRORTYPE GetHandle(OMX_HANDLETYPE *hInterface )
135 {
136     OMX_ERRORTYPE err = 0 ;
137     LCML_DSP_INTERFACE* pHandle;
138     struct LCML_CODEC_INTERFACE *dspcodecinterface ;
139 
140     OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "%d :: GetHandle application\n",__LINE__);
141     LCML_MALLOC(*hInterface,sizeof(LCML_DSP_INTERFACE),LCML_DSP_INTERFACE);
142 
143     if (hInterface == NULL)
144     {
145         err = OMX_ErrorInsufficientResources;
146         goto EXIT;
147     }
148     memset(*hInterface, 0, sizeof(LCML_DSP_INTERFACE));
149 
150     pHandle = (LCML_DSP_INTERFACE*)*hInterface;
151 
152     LCML_MALLOC(dspcodecinterface,sizeof(LCML_CODEC_INTERFACE),LCML_CODEC_INTERFACE);
153     if (dspcodecinterface == NULL)
154     {
155         err = OMX_ErrorInsufficientResources;
156         goto EXIT;
157     }
158     memset(dspcodecinterface, 0, sizeof(LCML_CODEC_INTERFACE));
159     OMX_DBG_INIT (dspcodecinterface->dbg, "TI_LCML");
160 
161     pHandle->pCodecinterfacehandle = dspcodecinterface;
162     dspcodecinterface->InitMMCodec = InitMMCodec;
163     dspcodecinterface->InitMMCodecEx = InitMMCodecEx;
164     dspcodecinterface->WaitForEvent = WaitForEvent;
165     dspcodecinterface->QueueBuffer = QueueBuffer;
166     dspcodecinterface->ControlCodec = ControlCodec;
167 
168     LCML_MALLOC(pHandle->dspCodec,sizeof(LCML_DSP),LCML_DSP);
169     if(pHandle->dspCodec == NULL)
170     {
171         err = OMX_ErrorInsufficientResources;
172         goto EXIT;
173     }
174     memset(pHandle->dspCodec, 0, sizeof(LCML_DSP));
175 
176     pthread_mutex_init (&pHandle->mutex, NULL);
177     dspcodecinterface->pCodec = *hInterface;
178     OMX_PRINT2 (dspcodecinterface->dbg, "GetHandle application handle %p dspCodec %p",pHandle, pHandle->dspCodec);
179 
180 EXIT:
181     return (err);
182 }
183 
184 
185 
186 /** ========================================================================
187 *  InitMMCodecEx initialise the OMX Component specific handle to LCML.
188 *  The memory is allocated and the dsp node is created. Add notification object
189 *  to listener thread.
190 *
191 *  @param  hInterface - Handle to LCML which is allocated and filled
192 *  @param  codecName - not used
193 *  @param  toCodecInitParams - not used yet
194 *  @param  fromCodecInfoStruct - not used yet
195 *  @param  pCallbacks - List of callback that uses to call OMX
196 *  @param  Args - additional arguments
197 *  @return OMX_ERRORTYPE
198 *      If the command successfully executes, the return code will be
199 *      OMX_NoError.  Otherwise the appropriate OMX error will be returned.
200 * ==========================================================================*/
InitMMCodecEx(OMX_HANDLETYPE hInt,OMX_STRING codecName,void * toCodecInitParams,void * fromCodecInfoStruct,LCML_CALLBACKTYPE * pCallbacks,OMX_STRING Args)201 static OMX_ERRORTYPE InitMMCodecEx(OMX_HANDLETYPE hInt,
202                                    OMX_STRING codecName,
203                                    void * toCodecInitParams,
204                                    void * fromCodecInfoStruct,
205                                    LCML_CALLBACKTYPE *pCallbacks,
206                                    OMX_STRING Args)
207 
208 {
209 
210     OMX_ERRORTYPE eError = OMX_ErrorNone;
211     OMX_U32 dllinfo;
212 
213     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: InitMMCodecEx application\n", __LINE__);
214 
215     if (hInt == NULL )
216     {
217         eError = OMX_ErrorInsufficientResources;
218         goto ERROR;
219     }
220     if(Args ==NULL)
221     {
222         InitMMCodec(hInt, codecName, toCodecInitParams, fromCodecInfoStruct, pCallbacks);
223     }
224     else
225     {
226         LCML_DSP_INTERFACE * phandle;
227         LCML_CREATEPHASEARGS crData;
228         DSP_STATUS status;
229         int i = 0, k = 0;
230         struct DSP_NODEATTRIN NodeAttrIn;
231         struct DSP_CBDATA     *pArgs;
232         BYTE  argsBuf[32 + sizeof(ULONG)];
233         char abs_dsp_path[ABS_DLL_NAME_LENGTH];
234 #ifndef CEXEC_DONE
235         UINT argc = 1;
236         char argv[ABS_DLL_NAME_LENGTH];
237         k = append_dsp_path(DSP_DOF_IMAGE, argv);
238         if (k < 0)
239         {
240             OMX_PRDSP4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
241             eError = OMX_ErrorBadParameter;
242             goto ERROR;
243         }
244 #endif
245         int tmperr;
246 
247         phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)hInt)->pCodec);
248 
249 #ifdef __PERF_INSTRUMENTATION__
250         phandle->pPERF = PERF_Create(PERF_FOURCC('C','M','L',' '),
251                                  PERF_ModuleAudioDecode | PERF_ModuleAudioEncode |
252                                  PERF_ModuleVideoDecode | PERF_ModuleVideoEncode |
253                                  PERF_ModuleImageDecode | PERF_ModuleImageEncode |
254                                  PERF_ModuleCommonLayer);
255         PERF_Boundary(phandle->pPERF,
256                       PERF_BoundaryStart | PERF_BoundarySetup);
257 #endif
258         /* 720p implementation */
259         {
260             pthread_mutex_init(&phandle->m_isStopped_mutex, NULL);
261             phandle->mapped_buffer_count = 0;
262         }
263         /* INIT DSP RESOURCE */
264         if(pCallbacks)
265             phandle->dspCodec->Callbacks.LCML_Callback = pCallbacks->LCML_Callback;
266         else
267         {
268             eError = OMX_ErrorBadParameter;
269             goto ERROR;
270         }
271 
272         /* INITIALIZATION OF DSP */
273         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Entering Init_DSPSubSystem\n", __LINE__);
274         status = DspManager_Open(0, NULL);
275         DSP_ERROR_EXIT(status, "DSP Manager Open", ERROR);
276         OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DspManager_Open Successful\n");
277 
278         /* Attach and get handle to processor */
279         status = DSPProcessor_Attach(TI_PROCESSOR_DSP, NULL, &(phandle->dspCodec->hProc));
280         DSP_ERROR_EXIT(status, "Attach processor", ERROR);
281         OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DSPProcessor_Attach Successful\n");
282         OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Base Image is Already Loaded\n");
283 
284         for (dllinfo=0; dllinfo < phandle->dspCodec->NodeInfo.nNumOfDLLs; dllinfo++)
285         {
286             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Register Component Node\n",phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
287 
288             k = append_dsp_path((char*)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].DllName, abs_dsp_path);
289             if (k < 0)
290             {
291                 OMX_PRDSP4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
292                 eError = OMX_ErrorBadParameter;
293                 goto ERROR;
294             }
295 
296             status = DSPManager_RegisterObject((struct DSP_UUID *)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].uuid,
297                                                 phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType, abs_dsp_path);
298 
299             DSP_ERROR_EXIT (status, "Register Component Library", ERROR);
300         }
301 
302         /* NODE specific data */
303         NodeAttrIn.cbStruct = sizeof(struct DSP_NODEATTRIN);
304         NodeAttrIn.iPriority = phandle->dspCodec->Priority;
305         NodeAttrIn.uTimeout = phandle->dspCodec->Timeout;
306         NodeAttrIn.uTimeout = 1000; /* WORKAROUND */
307         NodeAttrIn.uProfileID= phandle->dspCodec->ProfileID;
308         /* Prepare Create Phase Argument */
309         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Prepare Create Phase Argument \n", __LINE__);
310         /* TO DO check is application setting it properly */
311         i = 0;
312         if(phandle->dspCodec->pCrPhArgs !=NULL)
313         {
314             while((phandle->dspCodec->pCrPhArgs[i] != END_OF_CR_PHASE_ARGS) && (i < LCML_DATA_SIZE))
315             {
316                 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: copying Create Phase Argument \n", i);
317                 crData.cData[i] = phandle->dspCodec->pCrPhArgs[i];
318                 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: CR PH arg[%d] = %d \n",__LINE__, i, crData.cData[i]);
319                 i++;
320             }
321         }
322         else
323         {
324             OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL CREATEPHASE SET IT ..\n", __LINE__);
325             eError = OMX_ErrorBadParameter;
326             goto ERROR;
327         }
328 
329         if (i >= LCML_DATA_SIZE)
330         {
331             OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg,
332                     "%d :: Reached end of Create Phase Args Array. Did not find END_OF_CR_PHASE_ARGS marker. \n", __LINE__);
333             eError = OMX_ErrorBadParameter;
334             goto ERROR;
335         }
336 
337         /* LCML_DPRINT("Create Phase args  strlen = %d\n",strlen(crData.cData)); */
338         /* crData.cbData = sizeof (ULONG) + strlen(crData.cData); */
339         crData.cbData = i*2;
340         OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Create Phase args  strlen = %ld\n", crData.cbData);
341 
342         status = DSPNode_Allocate(phandle->dspCodec->hProc,
343                                   (struct DSP_UUID *)phandle->dspCodec->NodeInfo.AllUUIDs[0].uuid,
344                                   (struct DSP_CBDATA*)&crData,
345                                   &NodeAttrIn,&(phandle->dspCodec->hNode));
346         DSP_ERROR_EXIT(status, "Allocate Component", ERROR);
347         OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Allocate Successfully\n", __LINE__);
348 
349         pArgs = (struct DSP_CBDATA *)argsBuf;
350         strcpy((char*)pArgs->cData, Args);
351         pArgs->cbData = (ULONG)strlen ((char *)pArgs->cData);
352 
353         /* For debugging on connect DSP nodes */
354         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "[LCML] - struct DSP_CBDATA.cbData (length): %d %s\n", (int)pArgs->cbData, (char *)pArgs->cData);
355 
356         if (phandle->dspCodec->DeviceInfo.TypeofDevice == 1)
357         {
358             OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Audio Device Selected\n", __LINE__);
359             status = DSPNode_Allocate(phandle->dspCodec->hProc,
360                                       (struct DSP_UUID *)phandle->dspCodec->DeviceInfo.AllUUIDs[0].uuid,
361                                       NULL,
362                                       NULL,
363                                       &(phandle->dspCodec->hDasfNode));
364             DSP_ERROR_EXIT(status, "DASF Allocate Component", ERROR);
365 
366 
367             OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
368             if(phandle->dspCodec->DeviceInfo.DspStream != NULL)
369             {
370                 if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
371                 {
372                     /* render for playback */
373                     OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for playback\n", __LINE__);
374                     status = DSPNode_ConnectEx(phandle->dspCodec->hNode,
375                                                0,
376                                                (phandle->dspCodec->hDasfNode),
377                                                0,
378                                                (struct DSP_STRMATTR *)phandle->dspCodec->DeviceInfo.DspStream,
379                                                pArgs);
380                     DSP_ERROR_EXIT(status, "Node Connect", ERROR);
381                 }
382                 else if(phandle->dspCodec->DeviceInfo.TypeofRender == 1)
383                 {
384                     /* render for record */
385                     OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for record\n", __LINE__);
386                     status = DSPNode_ConnectEx(phandle->dspCodec->hDasfNode,
387                                                0,
388                                                phandle->dspCodec->hNode,
389                                                0,
390                                                (struct DSP_STRMATTR *)phandle->dspCodec->DeviceInfo.DspStream,
391                                                pArgs);
392                     DSP_ERROR_EXIT(status, "Node Connect", ERROR);
393                 }
394             }
395             else
396             {
397                 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL STREAM PARAMETER SET IT ..\n",__LINE__);
398                 eError = OMX_ErrorBadParameter;
399                 goto ERROR;
400             }
401         }
402 
403         status = DSPNode_Create(phandle->dspCodec->hNode);
404         DSP_ERROR_EXIT(status, "Create the Node", ERROR);
405         OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: After DSPNode_Create !!! \n", __LINE__);
406 
407         status = DSPNode_Run(phandle->dspCodec->hNode);
408         DSP_ERROR_EXIT (status, "Goto RUN mode", ERROR);
409         OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Run Successfully\n", __LINE__);
410 
411         if ((phandle->dspCodec->In_BufInfo.DataTrMethod == DMM_METHOD) || (phandle->dspCodec->Out_BufInfo.DataTrMethod == DMM_METHOD))
412         {
413             struct DSP_NOTIFICATION* notification;
414             OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
415 
416 	        LCML_MALLOC(notification,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION)
417             if(notification == NULL)
418             {
419                 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
420                 goto ERROR;
421             }
422             memset(notification, 0, sizeof(struct DSP_NOTIFICATION));
423 
424             status = DSPNode_RegisterNotify(phandle->dspCodec->hNode, DSP_NODEMESSAGEREADY, DSP_SIGNALEVENT, notification);
425             DSP_ERROR_EXIT(status, "DSP node register notify", ERROR);
426             phandle->g_aNotificationObjects[0] = notification;
427 #ifdef __ERROR_PROPAGATION__
428             struct DSP_NOTIFICATION* notification_mmufault;
429 
430             OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
431 
432             LCML_MALLOC(notification_mmufault,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
433             if(notification_mmufault == NULL)
434             {
435                 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
436                 goto ERROR;
437             }
438             memset(notification_mmufault,0,sizeof(struct DSP_NOTIFICATION));
439 
440             status = DSPProcessor_RegisterNotify(phandle->dspCodec->hProc, DSP_MMUFAULT, DSP_SIGNALEVENT, notification_mmufault);
441             DSP_ERROR_EXIT(status, "DSP node register notify DSP_MMUFAULT", ERROR);
442             phandle->g_aNotificationObjects[1] =  notification_mmufault;
443 
444             struct DSP_NOTIFICATION* notification_syserror ;
445 
446             OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
447 
448             LCML_MALLOC(notification_syserror,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
449             if(notification_syserror == NULL)
450             {
451                 OMX_ERROR4  (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
452                 goto ERROR;
453             }
454             memset(notification_syserror,0,sizeof(struct DSP_NOTIFICATION));
455 
456             status = DSPProcessor_RegisterNotify(phandle->dspCodec->hProc, DSP_SYSERROR, DSP_SIGNALEVENT, notification_syserror);
457             DSP_ERROR_EXIT(status, "DSP node register notify DSP_SYSERROR", ERROR);
458             phandle->g_aNotificationObjects[2] =  notification_syserror;
459 #endif
460         }
461 
462         /* Listener thread */
463         phandle->pshutdownFlag = 0;
464         phandle->g_tidMessageThread = 0;
465         phandle->bUsnEos = OMX_FALSE;
466         tmperr = pthread_create(&phandle->g_tidMessageThread,
467                                 NULL,
468                                 MessagingThread,
469                                 (void*)phandle);
470 
471         if (tmperr || !phandle->g_tidMessageThread)
472         {
473             OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Thread creation failed: 0x%x",tmperr);
474             eError = OMX_ErrorInsufficientResources;
475             goto ERROR;
476         }
477 
478 #ifdef __PERF_INSTRUMENTATION__
479         PERF_ThreadCreated(phandle->pPERF,
480                            phandle->g_tidMessageThread,
481                            PERF_FOURCC('C','M','L','T'));
482 #endif
483         /* init buffers buffer counter */
484         phandle->iBufinputcount = 0;
485         phandle->iBufoutputcount = 0;
486 
487         for (i = 0; i < QUEUE_SIZE; i++)
488         {
489             phandle->Arminputstorage[i] = NULL;
490             phandle->Armoutputstorage[i] = NULL;
491             phandle->pAlgcntlDmmBuf[i] = NULL;
492             phandle->pStrmcntlDmmBuf[i] = NULL;
493             phandle->algcntlmapped[i] = 0;
494             phandle->strmcntlmapped[i] = 0;
495         }
496 #ifdef __PERF_INSTRUMENTATION__
497         PERF_Boundary(phandle->pPERF,
498                       PERF_BoundaryComplete | PERF_BoundarySetup);
499 #endif
500     }
501 
502 ERROR:
503 #ifndef CEXEC_DONE
504     LCML_FREE(argv);
505 #endif
506     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Exiting Init_DSPSubSystem\n error = %x\n", __LINE__, eError);
507     return eError;
508 }
509 
510 /** ========================================================================
511 *  InitMMCodec initialise the OMX Component specific handle to LCML.
512 *  The memory is allocated and the dsp node is created. Add notification object
513 *  to listener thread.
514 *
515 *  @param  hInterface - Handle to LCML which is allocated and filled
516 *  @param  codecName - not used
517 *  @param  toCodecInitParams - not used yet
518 *  @param  fromCodecInfoStruct - not used yet
519 *  @param  pCallbacks - List of callback that uses to call OMX
520 *  @return OMX_ERRORTYPE
521 *      If the command successfully executes, the return code will be
522 *      OMX_NoError.  Otherwise the appropriate OMX error will be returned.
523 * ==========================================================================*/
InitMMCodec(OMX_HANDLETYPE hInt,OMX_STRING codecName,void * toCodecInitParams,void * fromCodecInfoStruct,LCML_CALLBACKTYPE * pCallbacks)524 static OMX_ERRORTYPE InitMMCodec(OMX_HANDLETYPE hInt,
525                                  OMX_STRING  codecName,
526                                  void * toCodecInitParams,
527                                  void * fromCodecInfoStruct,
528                                  LCML_CALLBACKTYPE *pCallbacks)
529 {
530     OMX_ERRORTYPE eError = OMX_ErrorNone;
531     OMX_U32 dllinfo;
532     LCML_DSP_INTERFACE * phandle;
533 #ifndef CEXEC_DONE
534     UINT argc = 1;
535     char argv[ABS_DLL_NAME_LENGTH];
536     k = append_dsp_path(DSP_DOF_IMAGE, argv);
537     if (k < 0)
538     {
539         OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
540         eError = OMX_ErrorBadParameter;
541         goto ERROR;
542     }
543 #endif
544     LCML_CREATEPHASEARGS crData;
545     DSP_STATUS status;
546     int i = 0, k =0;
547     struct DSP_NODEATTRIN NodeAttrIn;
548     int tmperr;
549     char abs_dsp_path[ABS_DLL_NAME_LENGTH];
550 
551     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: InitMMCodec application\n",__LINE__);
552 
553     if (hInt == NULL )
554     {
555         eError = OMX_ErrorInsufficientResources;
556         goto ERROR;
557     }
558 
559     phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)hInt)->pCodec);
560 #ifdef __PERF_INSTRUMENTATION__
561     phandle->pPERF = PERF_Create(PERF_FOURCC('C','M','L',' '),
562                              PERF_ModuleAudioDecode | PERF_ModuleAudioEncode |
563                              PERF_ModuleVideoDecode | PERF_ModuleVideoEncode |
564                              PERF_ModuleImageDecode | PERF_ModuleImageEncode |
565                              PERF_ModuleCommonLayer);
566     PERF_Boundary(phandle->pPERF,
567                   PERF_BoundaryStart | PERF_BoundarySetup);
568 #endif
569 
570     /* 720p implementation */
571     {
572         pthread_mutex_init(&phandle->m_isStopped_mutex, NULL);
573         phandle->mapped_buffer_count = 0;
574     }
575 
576     /* INIT DSP RESOURCE */
577     if(pCallbacks)
578     {
579         phandle->dspCodec->Callbacks.LCML_Callback =  pCallbacks->LCML_Callback;
580     }
581     else
582     {
583         eError = OMX_ErrorBadParameter;
584         goto ERROR;
585     }
586 
587     /* INITIALIZATION OF DSP */
588     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Entering Init_DSPSubSystem\n", __LINE__);
589     status = DspManager_Open(0, NULL);
590     DSP_ERROR_EXIT(status, "DSP Manager Open", ERROR);
591     OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DspManager_Open Successful\n");
592 
593     /* Attach and get handle to processor */
594     status = DSPProcessor_Attach(TI_PROCESSOR_DSP, NULL, &(phandle->dspCodec->hProc));
595     DSP_ERROR_EXIT(status, "Attach processor", ERROR);
596     OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DSPProcessor_Attach Successful\n");
597     OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Base Image is Already Loaded\n");
598 
599     for(dllinfo=0; dllinfo < phandle->dspCodec->NodeInfo.nNumOfDLLs; dllinfo++)
600     {
601         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Register Component Node\n",phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
602 
603         k = append_dsp_path((char*)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].DllName, abs_dsp_path);
604         if (k < 0)
605         {
606             OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
607             eError = OMX_ErrorBadParameter;
608             goto ERROR;
609         }
610 
611         status = DSPManager_RegisterObject((struct DSP_UUID *)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].uuid,
612                                                phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType,
613                                                abs_dsp_path);
614 
615         DSP_ERROR_EXIT (status, "Register Component Library", ERROR)
616     }
617 
618     /* NODE specific data */
619 
620     NodeAttrIn.cbStruct = sizeof(struct DSP_NODEATTRIN);
621     NodeAttrIn.iPriority = phandle->dspCodec->Priority;
622     NodeAttrIn.uTimeout = phandle->dspCodec->Timeout;
623     NodeAttrIn.uTimeout  = 1000; /* WORKAROUND */
624     NodeAttrIn.uProfileID= phandle->dspCodec->ProfileID;
625     /* Prepare Create Phase Argument */
626 
627     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Prepare Create Phase Argument \n",__LINE__);
628     /* TO DO check is application setting it properly */
629     if(phandle->dspCodec->pCrPhArgs !=NULL)
630     {
631         while((phandle->dspCodec->pCrPhArgs[i] != END_OF_CR_PHASE_ARGS) && (i < LCML_DATA_SIZE))
632         {
633             OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: copying Create Phase Argument \n",i);
634             crData.cData[i] =phandle->dspCodec->pCrPhArgs[i];
635             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: CR PH arg[%d] = %d \n",__LINE__,i,crData.cData[i]);
636             i++;
637         }
638     }
639     else
640     {
641         OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL CREATEPHASE SET IT ..\n",__LINE__);
642         eError = OMX_ErrorBadParameter;
643         goto ERROR;
644     }
645 
646     if (i >= LCML_DATA_SIZE)
647     {
648         OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg,
649                 "%d :: Reached end of Create Phase Args Array. Did not find END_OF_CR_PHASE_ARGS marker. \n", __LINE__);
650        eError = OMX_ErrorBadParameter;
651        goto ERROR;
652     }
653 
654 
655     /* LCML_DPRINT ("Create Phase args  strlen = %d\n",strlen(crData.cData)); */
656     /* crData.cbData = sizeof (ULONG) + strlen(crData.cData); */
657     crData.cbData = i * 2;
658     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Create Phase args  strlen = %ld\n", crData.cbData);
659 
660     status = DSPNode_Allocate(phandle->dspCodec->hProc,
661                              (struct DSP_UUID *)phandle->dspCodec->NodeInfo.AllUUIDs[0].uuid,
662                              (struct DSP_CBDATA*)&crData, &NodeAttrIn,
663                              &(phandle->dspCodec->hNode));
664     DSP_ERROR_EXIT(status, "Allocate Component", ERROR);
665     OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Allocate Successfully\n", __LINE__);
666 
667     if(phandle->dspCodec->DeviceInfo.TypeofDevice == 1)
668     {
669         OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Audio Device Selected\n", __LINE__);
670         status = DSPNode_Allocate(phandle->dspCodec->hProc,
671                                  (struct DSP_UUID *)phandle->dspCodec->DeviceInfo.AllUUIDs[0].uuid,
672                                  NULL,
673                                  NULL,
674                                  &(phandle->dspCodec->hDasfNode));
675         DSP_ERROR_EXIT(status, "DASF Allocate Component", ERROR);
676 
677         OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
678         if(phandle->dspCodec->DeviceInfo.DspStream !=NULL)
679         {
680             if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
681             {
682                 /* render for playback */
683                 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for playback\n", __LINE__);
684                 status = DSPNode_Connect(phandle->dspCodec->hNode,
685                                          0,
686                                          phandle->dspCodec->hDasfNode,
687                                          0,
688                                          (struct DSP_STRMATTR *)phandle->dspCodec->DeviceInfo.DspStream);
689                 DSP_ERROR_EXIT(status, "Node Connect", ERROR);
690             }
691             else if(phandle->dspCodec->DeviceInfo.TypeofRender == 1)
692             {
693                 /* render for record */
694                 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for record\n", __LINE__);
695                 status = DSPNode_Connect(phandle->dspCodec->hDasfNode,
696                                          0,
697                                          phandle->dspCodec->hNode,
698                                          0,
699                                          (struct DSP_STRMATTR *)phandle->dspCodec->DeviceInfo.DspStream);
700                 DSP_ERROR_EXIT(status, "Node Connect", ERROR);
701             }
702         }
703         else
704         {
705             OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL STREAM PARAMETER SET IT ..\n",__LINE__);
706             eError = OMX_ErrorBadParameter;
707             goto ERROR;
708         }
709     }
710 
711     status = DSPNode_Create(phandle->dspCodec->hNode);
712     DSP_ERROR_EXIT(status, "Create the Node", ERROR);
713     OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: After DSPNode_Create !!! \n", __LINE__);
714 
715     status = DSPNode_Run (phandle->dspCodec->hNode);
716     DSP_ERROR_EXIT (status, "Goto RUN mode", ERROR);
717     OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Run Successfully\n", __LINE__);
718 
719     if ((phandle->dspCodec->In_BufInfo.DataTrMethod == DMM_METHOD) ||
720         (phandle->dspCodec->Out_BufInfo.DataTrMethod == DMM_METHOD))
721     {
722         struct DSP_NOTIFICATION* notification;
723         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
724 
725         LCML_MALLOC(notification,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
726         if(notification == NULL)
727         {
728             OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
729             goto ERROR;
730         }
731         memset(notification,0,sizeof(struct DSP_NOTIFICATION));
732 
733         status = DSPNode_RegisterNotify(phandle->dspCodec->hNode, DSP_NODEMESSAGEREADY, DSP_SIGNALEVENT, notification);
734         DSP_ERROR_EXIT(status, "DSP node register notify", ERROR);
735         phandle->g_aNotificationObjects[0] =  notification;
736 #ifdef __ERROR_PROPAGATION__
737         struct DSP_NOTIFICATION* notification_mmufault;
738 
739         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
740 
741         LCML_MALLOC(notification_mmufault,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
742         if(notification_mmufault == NULL)
743         {
744             OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
745             goto ERROR;
746         }
747         memset(notification_mmufault,0,sizeof(struct DSP_NOTIFICATION));
748 
749         status = DSPProcessor_RegisterNotify(phandle->dspCodec->hProc, DSP_MMUFAULT, DSP_SIGNALEVENT, notification_mmufault);
750         DSP_ERROR_EXIT(status, "DSP node register notify DSP_MMUFAULT", ERROR);
751         phandle->g_aNotificationObjects[1] =  notification_mmufault;
752 
753         struct DSP_NOTIFICATION* notification_syserror ;
754 
755         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
756 
757         LCML_MALLOC(notification_syserror,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
758         if(notification_syserror == NULL)
759         {
760             OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
761             goto ERROR;
762         }
763         memset(notification_syserror,0,sizeof(struct DSP_NOTIFICATION));
764 
765         status = DSPProcessor_RegisterNotify(phandle->dspCodec->hProc, DSP_SYSERROR, DSP_SIGNALEVENT, notification_syserror);
766         DSP_ERROR_EXIT(status, "DSP node register notify DSP_SYSERROR", ERROR);
767         phandle->g_aNotificationObjects[2] =  notification_syserror;
768 #endif
769     }
770 
771     /* Listener thread */
772     phandle->pshutdownFlag = 0;
773     phandle->g_tidMessageThread = 0;
774 
775     tmperr = pthread_create(&phandle->g_tidMessageThread,
776                             NULL,
777                             MessagingThread,
778                             (void*)phandle);
779 
780     if(tmperr || !phandle->g_tidMessageThread)
781     {
782         OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Thread creation failed: 0x%x",tmperr);
783         eError = OMX_ErrorInsufficientResources;
784         goto ERROR;
785     }
786 
787 #ifdef __PERF_INSTRUMENTATION__
788     PERF_ThreadCreated(phandle->pPERF,
789                        phandle->g_tidMessageThread,
790                        PERF_FOURCC('C','M','L','T'));
791 #endif
792     /* init buffers buffer counter */
793     phandle->iBufinputcount =0;
794     phandle->iBufoutputcount =0;
795 
796     for (i = 0; i < QUEUE_SIZE; i++)
797     {
798         phandle->Arminputstorage[i] = NULL;
799         phandle->Armoutputstorage[i] = NULL;
800         phandle->pAlgcntlDmmBuf[i] = NULL;
801         phandle->pStrmcntlDmmBuf[i] = NULL;
802         phandle->algcntlmapped[i] = 0;
803         phandle->strmcntlmapped[i] = 0;
804     }
805 
806 #ifdef __PERF_INSTRUMENTATION__
807     PERF_Boundary(phandle->pPERF,
808                   PERF_BoundaryComplete | PERF_BoundarySetup);
809 #endif
810 
811 ERROR:
812 #ifndef CEXEC_DONE
813     LCML_FREE(argv);
814 #endif
815     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Exiting Init_DSPSubSystem\n", __LINE__);
816     return eError;
817 }
818 
819 
820 
821 /** ========================================================================
822 *  The LCML_WaitForEvent Wait for a event sychronously
823 *  @param  hInterface -  Handle of the component to be accessed.  This is the
824 *      component handle returned by the call to the GetHandle function.
825 *  @param  event - Event occured
826 *  @param  args - Array of "void *" that contains the associated arguments for
827 *             occured event
828 *
829 *  @return OMX_ERRORTYPE
830 *      If the command successfully executes, the return code will be
831 *      OMX_NoError.  Otherwise the appropriate OMX error will be returned.
832 ** ==========================================================================*/
WaitForEvent(OMX_HANDLETYPE hComponent,TUsnCodecEvent event,void * args[10])833 static OMX_ERRORTYPE WaitForEvent(OMX_HANDLETYPE hComponent,
834                                   TUsnCodecEvent event,
835                                   void * args[10] )
836 {
837     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
838     return eError;
839 }
840 
841 
842 /** ========================================================================
843 *  The LCML_QueueBuffer send data to DSP convert it into USN format and send
844 *  it to DSP via setbuff
845 *  @param [in] hInterface -  Handle of the component to be accessed.  This is
846 *      the component handle returned by the call to the GetHandle function.
847 *  @param  bufType - type of buffer
848 *  @param  buffer - pointer to buffer
849 *  @param  bufferLen - length of  buffer
850 *  @param  bufferSizeUsed - length of used buffer
851 *  @param  auxInfo - pointer to parameter
852 *  @param  auxInfoLen - length of  parameter
853 *  @param  usrArg - not used
854 *  @return OMX_ERRORTYPE
855 *      If the command successfully executes, the return code will be
856 *      OMX_NoError.  Otherwise the appropriate OMX error will be returned.
857 * ==========================================================================*/
QueueBuffer(OMX_HANDLETYPE hComponent,TMMCodecBufferType bufType,OMX_U8 * buffer,OMX_S32 bufferLen,OMX_S32 bufferSizeUsed,OMX_U8 * auxInfo,OMX_S32 auxInfoLen,OMX_U8 * usrArg)858 static OMX_ERRORTYPE QueueBuffer (OMX_HANDLETYPE hComponent,
859                                   TMMCodecBufferType bufType,
860                                   OMX_U8 * buffer, OMX_S32 bufferLen,
861                                   OMX_S32 bufferSizeUsed ,OMX_U8 * auxInfo,
862                                   OMX_S32 auxInfoLen ,OMX_U8 * usrArg )
863 {
864     LCML_DSP_INTERFACE * phandle;
865     OMX_U32 streamId = 0;
866     DSP_STATUS status;
867     OMX_ERRORTYPE eError = OMX_ErrorNone;
868     char * tmp2=NULL;
869     DMM_BUFFER_OBJ* pDmmBuf=NULL;
870     int commandId;
871     struct DSP_MSG msg;
872     OMX_U32 MapBufLen=0;
873     OMX_BOOL mappedBufferFound = false;
874 
875     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: QueueBuffer application\n",__LINE__);
876 
877     if (hComponent == NULL )
878     {
879         eError = OMX_ErrorInsufficientResources;
880         goto EXIT;
881     }
882 
883     phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)hComponent)->pCodec);
884 
885     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "LCML QueueBuffer: phandle->iBufinputcount is %lu (%p) \n", phandle->iBufinputcount, phandle);
886 
887 #ifdef __PERF_INSTRUMENTATION__
888     PERF_XferingBuffer(phandle->pPERF,
889                        buffer,
890                        bufferSizeUsed,
891                        PERF_ModuleComponent,
892                        PERF_ModuleSocketNode);
893 #endif
894     pthread_mutex_lock(&phandle->mutex);
895     LCML_MALLOC(tmp2,sizeof(TArmDspCommunicationStruct) + 256,char);
896     if (tmp2 == NULL)
897     {
898             eError = OMX_ErrorInsufficientResources;
899             goto MUTEX_UNLOCK;
900     }
901     memset(tmp2,0,sizeof(TArmDspCommunicationStruct)+256);
902     phandle->commStruct = (TArmDspCommunicationStruct *)(tmp2 + 128);
903     phandle->commStruct->iBufferPtr = (OMX_U32) buffer;
904     phandle->commStruct->iBufferSize = bufferLen;
905     phandle->commStruct->iParamPtr = (OMX_U32) auxInfo;
906     phandle->commStruct->iParamSize = auxInfoLen;
907     /*USN updation */
908     phandle->commStruct->iBufSizeUsed =  bufferSizeUsed ;
909     phandle->commStruct->iArmArg = (OMX_U32) buffer;
910     phandle->commStruct->iArmParamArg = (OMX_U32) auxInfo;
911 
912     /* if the bUsnEos flag is set interpret the usrArg as a buffer header */
913     if (phandle->bUsnEos == OMX_TRUE) {
914         phandle->commStruct->iEOSFlag = (((OMX_BUFFERHEADERTYPE*)usrArg)->nFlags & 0x00000001);
915     }
916     else {
917         phandle->commStruct->iEOSFlag = 0;
918     }
919     phandle->commStruct->iUsrArg = (OMX_U32) usrArg;
920     phandle->iBufoutputcount = phandle->iBufoutputcount % QUEUE_SIZE;
921     phandle->iBufinputcount = phandle->iBufinputcount % QUEUE_SIZE;
922     phandle->commStruct->Bufoutindex = phandle->iBufoutputcount;
923     phandle->commStruct->BufInindex = phandle->iBufinputcount;
924     switch (bufType)
925     {
926         case EMMCodecInputBufferMapBufLen:
927             bufType = EMMCodecInputBuffer;
928             MapBufLen = 1;
929             break;
930         case EMMCodecOutputBufferMapBufLen:
931             bufType = EMMCodecOuputBuffer;
932             MapBufLen = 1;
933             break;
934         case EMMCodecInputBufferMapReuse:
935             bufType = EMMCodecInputBuffer;
936             phandle->ReUseMap = 1;
937             break;
938         case EMMCodecOutputBufferMapReuse:
939             bufType = EMMCodecOuputBuffer;
940             phandle->ReUseMap = 1;
941             break;
942         default:
943             break;
944     }
945 
946     if ((bufType >= EMMCodecStream0) && (bufType <= (EMMCodecStream0 + 20)))
947     {
948         streamId = bufType - EMMCodecStream0;
949     }
950 
951 	phandle->commStruct->iStreamID = streamId;
952 
953     if (bufType == EMMCodecInputBuffer || !(streamId % 2))
954     {
955         phandle->Arminputstorage[phandle->iBufinputcount] = phandle->commStruct;
956         pDmmBuf = phandle->dspCodec->InDmmBuffer;
957         pDmmBuf = pDmmBuf + phandle->iBufinputcount;
958         phandle->iBufinputcount++;
959         phandle->iBufinputcount = phandle->iBufinputcount % QUEUE_SIZE;
960         OMX_PRBUFFER1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "VPP port %lu use InDmmBuffer (%lu) %p\n", streamId, phandle->iBufinputcount, pDmmBuf);
961 
962     }
963     else if (bufType == EMMCodecOuputBuffer || streamId % 2)
964     {
965         phandle->Armoutputstorage[phandle->iBufoutputcount] = phandle->commStruct;
966         pDmmBuf = phandle->dspCodec->OutDmmBuffer;
967         pDmmBuf = pDmmBuf + phandle->iBufoutputcount;
968         phandle->iBufoutputcount++;
969         phandle->iBufoutputcount = phandle->iBufoutputcount % QUEUE_SIZE;
970     }
971     else
972     {
973         OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Unrecognized buffer type..");
974         eError = OMX_ErrorBadParameter;
975         if(tmp2)
976         {
977             free(tmp2);
978             phandle->commStruct = NULL;
979         }
980         goto MUTEX_UNLOCK;
981     }
982     commandId = USN_GPPMSG_SET_BUFF|streamId;
983     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending command ID 0x%x",commandId);
984     if( pDmmBuf == NULL)
985     {
986         eError = OMX_ErrorInsufficientResources;
987         goto MUTEX_UNLOCK;
988     }
989     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "buffer = 0x%p bufferlen = %ld auxInfo = 0x%p auxInfoLen %ld\n",
990         buffer, bufferLen, auxInfo, auxInfoLen );
991 
992     phandle->commStruct->iArmbufferArg = (OMX_U32)buffer;
993     if ((buffer != NULL) && (bufferLen != 0))
994     {
995         OMX_U32 i;
996         DSP_STATUS status;
997 
998         if (phandle->ReUseMap)
999         {
1000             mappedBufferFound = false;
1001             for(i = 0; i <= phandle->mapped_buffer_count; i++)
1002             {
1003                 if(phandle->mapped_dmm_buffers[i].pAllocated == buffer)
1004                 {
1005                     mappedBufferFound = true;
1006                     *pDmmBuf = phandle->mapped_dmm_buffers[i];
1007                      OMX_PRBUFFER1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Re-using pDmmBuf %p mapped %p\n", pDmmBuf, pDmmBuf->pMapped);
1008 
1009                     if(bufType == EMMCodecInputBuffer)
1010                     {
1011                         /* Issue a memory flush for input buffer to ensure cache coherency */
1012                         status = DSPProcessor_FlushMemory(phandle->dspCodec->hProc, pDmmBuf->pAllocated, bufferSizeUsed, (bufferSizeUsed > 512*1024) ? 3: 0);
1013                         if(DSP_FAILED(status))
1014                         {
1015                             goto MUTEX_UNLOCK;
1016                         }
1017                     }
1018 
1019                     else if(bufType == EMMCodecOuputBuffer)
1020                     {
1021                         /* Issue an memory invalidate for output buffer */
1022                         if (bufferLen > 512*1024)
1023                         {
1024                             status = DSPProcessor_FlushMemory(phandle->dspCodec->hProc, pDmmBuf->pAllocated, bufferLen, 3);
1025                             if(DSP_FAILED(status))
1026                             {
1027                                 goto MUTEX_UNLOCK;
1028                             }
1029                         }
1030                         else
1031                         {
1032                             status = DSPProcessor_InvalidateMemory(phandle->dspCodec->hProc, pDmmBuf->pAllocated, bufferLen);
1033                             if(DSP_FAILED(status))
1034                             {
1035                                 goto MUTEX_UNLOCK;
1036                             }
1037                         }
1038                     }
1039 
1040                     break;
1041                 }
1042             }
1043 
1044             if(false == mappedBufferFound)
1045             {
1046                 if (bufType == EMMCodecInputBuffer || !(streamId % 2))
1047                 {
1048                         phandle->commStruct->iBufferSize = bufferSizeUsed ? bufferSizeUsed : bufferLen;
1049                         eError = DmmMap(phandle->dspCodec->hProc, bufferLen,buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1050                 }
1051                 else if (bufType == EMMCodecOuputBuffer || streamId % 2) {
1052                     eError = DmmMap(phandle->dspCodec->hProc, bufferLen, buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1053                 }
1054                 if (eError != OMX_ErrorNone)
1055                 {
1056                     goto MUTEX_UNLOCK;
1057                 }
1058 
1059                 /*720p implementation */
1060                 phandle->commStruct->iBufferPtr = (OMX_U32) pDmmBuf->pMapped;
1061                 /* storing reserve address for buffer */
1062                 pDmmBuf->bufReserved = pDmmBuf->pReserved;
1063                 if(phandle->mapped_buffer_count <= MAX_DMM_BUFFERS)
1064                 {
1065                     phandle->mapped_dmm_buffers[phandle->mapped_buffer_count++] = *pDmmBuf;
1066                 }
1067             }
1068         phandle->commStruct->iBufferPtr = (OMX_U32) pDmmBuf->pMapped;
1069         }
1070         else
1071         {
1072 
1073             OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Mapping buffer continously\n");
1074             if (bufType == EMMCodecInputBuffer || !(streamId % 2))
1075             {
1076                 if (MapBufLen)
1077                 {
1078                     /*using this option only when not mapping the entire memory region
1079                      * can cause a DSP MMU FAULT or DSP SYS ERROR */
1080                     eError = DmmMap(phandle->dspCodec->hProc, bufferLen, buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1081                 }
1082                 else
1083                 {
1084                     phandle->commStruct->iBufferSize = bufferSizeUsed ? bufferSizeUsed : bufferLen;
1085                     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Mapping Size %ld out of %ld", bufferSizeUsed, bufferLen);
1086                     eError = DmmMap(phandle->dspCodec->hProc, bufferSizeUsed ? bufferSizeUsed : bufferLen,buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1087                 }
1088             }
1089             else if (bufType == EMMCodecOuputBuffer || streamId % 2) {
1090                 eError = DmmMap(phandle->dspCodec->hProc, bufferLen, buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1091             }
1092             if (eError != OMX_ErrorNone)
1093             {
1094                 goto MUTEX_UNLOCK;
1095             }
1096             phandle->commStruct->iBufferPtr = (OMX_U32) pDmmBuf->pMapped;
1097             pDmmBuf->bufReserved = pDmmBuf->pReserved;
1098         }
1099 
1100     }
1101 
1102     if (auxInfoLen != 0 && auxInfo != NULL )
1103     {
1104         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "mapping parameter \n");
1105         eError = DmmMap(phandle->dspCodec->hProc, phandle->commStruct->iParamSize, (void*)phandle->commStruct->iParamPtr, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1106         if (eError != OMX_ErrorNone)
1107         {
1108             goto MUTEX_UNLOCK;
1109         }
1110 
1111         phandle->commStruct->iParamPtr = (OMX_U32 )pDmmBuf->pMapped ;
1112         /* storing reserve address for param */
1113         pDmmBuf->paramReserved = pDmmBuf->pReserved;
1114     }
1115 
1116     eError = DmmMap(phandle->dspCodec->hProc, sizeof(TArmDspCommunicationStruct),(void *)phandle->commStruct, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1117     if (eError != OMX_ErrorNone)
1118     {
1119         goto MUTEX_UNLOCK;
1120     }
1121 
1122     /* storing mapped address of struct */
1123     phandle->commStruct->iArmArg = (OMX_U32)pDmmBuf->pMapped;
1124 
1125     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "sending SETBUFF \n");
1126     msg.dwCmd = commandId;
1127     msg.dwArg1 = (int)pDmmBuf->pMapped;
1128     msg.dwArg2 = 0;
1129 
1130     status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
1131     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "after SETBUFF \n");
1132     DSP_ERROR_EXIT (status, "Send message to node", MUTEX_UNLOCK);
1133 MUTEX_UNLOCK:
1134     pthread_mutex_unlock(&phandle->mutex);
1135 EXIT:
1136     return eError;
1137 }
1138 
1139 
1140 /** ========================================================================
1141 *  The LCML_ControlCodec send command to DSP convert it into USN format and
1142 *  send it to DSP
1143 *  @param  hInterface -  Handle of the component to be accessed.  This is the
1144 *      component handle returned by the call to the GetHandle function.
1145 *  @param  bufType - type of buffer
1146 *  @param  iCodecCmd -  command refer TControlCmd
1147 *  @param  args - pointer to send some specific command to DSP
1148 *
1149 *  @return OMX_ERRORTYPE
1150 *      If the command successfully executes, the return code will be
1151 *      OMX_NoError.  Otherwise the appropriate OMX error will be returned.
1152 ** ==========================================================================*/
ControlCodec(OMX_HANDLETYPE hComponent,TControlCmd iCodecCmd,void * args[10])1153 static OMX_ERRORTYPE ControlCodec(OMX_HANDLETYPE hComponent,
1154                                   TControlCmd iCodecCmd,
1155                                   void * args[10])
1156 {
1157     LCML_DSP_INTERFACE * phandle;
1158     DSP_STATUS status;
1159     OMX_ERRORTYPE eError = OMX_ErrorNone;
1160 
1161     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: ControlCodec application\n",__LINE__);
1162     if (hComponent == NULL )
1163     {
1164         eError= OMX_ErrorInsufficientResources;
1165         goto EXIT;
1166     }
1167     phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)hComponent)->pCodec);
1168 
1169 #ifdef __PERF_INSTRUMENTATION__
1170     PERF_ReceivedCommand(phandle->pPERF,
1171                          (OMX_U32) iCodecCmd,
1172                          (OMX_U32) args,
1173                          PERF_ModuleLLMM);
1174 #endif
1175     switch (iCodecCmd)
1176     {
1177         case EMMCodecControlPause:
1178         {
1179             struct DSP_MSG msg = {USN_GPPMSG_PAUSE, 0, 0};
1180             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending PAUSE command");
1181 #ifdef __PERF_INSTRUMENTATION__
1182             PERF_SendingCommand(phandle->pPERF,
1183                                 msg.dwCmd,
1184                                 msg.dwArg1,
1185                                 PERF_ModuleSocketNode);
1186 #endif
1187             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
1188             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
1189             break;
1190         }
1191         case EMMCodecControlStart:
1192         {
1193             struct DSP_MSG msg = {USN_GPPMSG_PLAY, 0, 0};
1194             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending PLAY --1 command");
1195 #ifdef __PERF_INSTRUMENTATION__
1196             PERF_SendingCommand(phandle->pPERF,
1197                                 msg.dwCmd,
1198                                 msg.dwArg1,
1199                                 PERF_ModuleSocketNode);
1200 #endif
1201             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
1202             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
1203             break;
1204         }
1205         case MMCodecControlStop:
1206         {
1207             struct DSP_MSG msg = {USN_GPPMSG_STOP, 0, 0};
1208             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending STOP command\n");
1209 #ifdef __PERF_INSTRUMENTATION__
1210             PERF_SendingCommand(phandle->pPERF,
1211                                 msg.dwCmd,
1212                                 msg.dwArg1,
1213                                 PERF_ModuleSocketNode);
1214 #endif
1215             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
1216             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
1217             break;
1218         }
1219         case EMMCodecControlDestroy:
1220         {
1221             int pthreadError = 0;
1222             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Destroy the codec");
1223 #ifdef __PERF_INSTRUMENTATION__
1224             PERF_Boundary(phandle->pPERF,
1225                           PERF_BoundaryStart | PERF_BoundaryCleanup);
1226             PERF_SendingCommand(phandle->pPERF,
1227                                 -1, 0, PERF_ModuleComponent);
1228 #endif
1229             phandle->pshutdownFlag = 1;
1230             pthreadError = pthread_join(phandle->g_tidMessageThread, NULL);
1231             if (0 != pthreadError)
1232             {
1233                 eError = OMX_ErrorHardware;
1234                 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: Error while closing Component Thread\n", pthreadError);
1235             }
1236             OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Destroy the codec %d",eError);
1237             /* 720p implementation */
1238             /*DeleteDspResource (phandle);*/
1239             if (phandle->ReUseMap)
1240             {
1241                 pthread_mutex_lock(&phandle->m_isStopped_mutex);
1242                 /*If you are able to obtain the lock then the Messaging thread has exited*/
1243                 pthread_mutex_unlock(&phandle->m_isStopped_mutex);
1244             }
1245 
1246             if (phandle->ReUseMap)
1247             {
1248                 OMX_U32 i;
1249 
1250                 /* Unmap buffers */
1251                 for(i=0; i< phandle->mapped_buffer_count; i++)
1252                 {
1253                     DmmUnMap(phandle->dspCodec->hProc,(void*)phandle->mapped_dmm_buffers[i].pMapped,
1254                             phandle->mapped_dmm_buffers[i].bufReserved, ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1255                 }
1256 
1257                 for(i = 0; i <= phandle->mapped_buffer_count; i++)
1258                 {
1259                     phandle->mapped_dmm_buffers[i].pAllocated = 0;
1260                     phandle->mapped_dmm_buffers[i].pReserved = 0;
1261                     phandle->mapped_dmm_buffers[i].pMapped = 0;
1262                     phandle->mapped_dmm_buffers[i].bufReserved = 0;
1263                     phandle->mapped_dmm_buffers[i].paramReserved = 0;
1264                     phandle->mapped_dmm_buffers[i].nSize = 0;
1265                 }
1266 
1267                 phandle->mapped_buffer_count = 0;
1268             }
1269 
1270             DeleteDspResource (phandle);
1271 
1272 #ifdef __PERF_INSTRUMENTATION__
1273             PERF_OBJHANDLE pPERF = phandle->pPERF;
1274 #endif
1275 
1276             FreeResources(phandle);
1277 
1278 #ifdef __PERF_INSTRUMENTATION__
1279             PERF_Boundary(pPERF, PERF_BoundaryComplete | PERF_BoundaryCleanup);
1280             PERF_Done(pPERF);
1281 #endif
1282 
1283             break;
1284         }
1285 
1286         /* this case is for sending extra custom commands to DSP socket node */
1287         case EMMCodecControlSendDspMessage:
1288         {
1289             /* todo: Check to see if the arguments are valid */
1290             struct DSP_MSG msg = {(int)args[0], (int)args[1], (int)args[2]};
1291             OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "message to codec");
1292 #ifdef __PERF_INSTRUMENTATION__
1293             PERF_SendingCommand(phandle->pPERF,
1294                                 msg.dwCmd,
1295                                 msg.dwArg1,
1296                                 PERF_ModuleSocketNode);
1297 #endif
1298             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
1299             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
1300             break;
1301         }
1302         case EMMCodecControlAlgCtrl:
1303         {
1304             struct DSP_MSG msg;
1305             int i;
1306             pthread_mutex_lock(&phandle->mutex);
1307             for (i = 0; i < QUEUE_SIZE; i++)
1308             {
1309                 /* searching for empty slot */
1310                 if (phandle->pAlgcntlDmmBuf[i] == NULL)
1311                     break;
1312             }
1313                     if(i >= QUEUE_SIZE)
1314                     {
1315                         pthread_mutex_unlock(&phandle->mutex);
1316                         eError = OMX_ErrorUndefined;
1317                         goto EXIT;
1318                     }
1319 
1320                     LCML_MALLOC(phandle->pAlgcntlDmmBuf[i],sizeof(DMM_BUFFER_OBJ),DMM_BUFFER_OBJ);
1321                     if(phandle->pAlgcntlDmmBuf[i] == NULL)
1322                     {
1323                         eError = OMX_ErrorInsufficientResources;
1324                         pthread_mutex_unlock(&phandle->mutex);
1325                         goto EXIT;
1326                     }
1327 
1328                     memset(phandle->pAlgcntlDmmBuf[i],0,sizeof(DMM_BUFFER_OBJ));
1329 
1330                     eError = DmmMap(phandle->dspCodec->hProc,(int)args[2], args[1],(phandle->pAlgcntlDmmBuf[i]), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1331                     if (eError != OMX_ErrorNone)
1332                     {
1333                         pthread_mutex_unlock(&phandle->mutex);
1334                         goto EXIT;
1335                     }
1336                     phandle->algcntlmapped[i] = 1;
1337                     msg.dwCmd = USN_GPPMSG_ALGCTRL;
1338                     msg.dwArg1 = (int)args[0];
1339                     msg.dwArg2 = (int)phandle->pAlgcntlDmmBuf[i]->pMapped;
1340 #ifdef __PERF_INSTRUMENTATION__
1341                     PERF_SendingCommand(phandle->pPERF,
1342                                         msg.dwCmd,
1343                                         msg.dwArg1,
1344                                         PERF_ModuleSocketNode);
1345 #endif
1346                     status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
1347                     pthread_mutex_unlock(&phandle->mutex);
1348                     DSP_ERROR_EXIT (status, "Send message to node", EXIT);
1349                     break;
1350                 }
1351         case EMMCodecControlStrmCtrl:
1352         {
1353             struct DSP_MSG msg;
1354 
1355             pthread_mutex_lock(&phandle->mutex);
1356             if ((int)args[0] == USN_STRMCMD_FLUSH) {
1357                 msg.dwCmd = USN_GPPMSG_STRMCTRL | (int)args[1];
1358                 msg.dwArg1  = USN_STRMCMD_FLUSH;
1359                 msg.dwArg2  = 0;
1360                 phandle->flush_pending[(int)args[1]]= 1;
1361 #ifdef __PERF_INSTRUMENTATION__
1362                 PERF_SendingCommand(phandle->pPERF,
1363                                  msg.dwCmd,
1364                                  msg.dwArg1,
1365                                  PERF_ModuleSocketNode);
1366 #endif
1367             }
1368             else
1369             {
1370                 int i;
1371                 for (i = 0; i < QUEUE_SIZE; i++)
1372                 {
1373                     /* searching for empty slot */
1374                     if (phandle->pStrmcntlDmmBuf[i] == NULL)
1375                         break;
1376                 }
1377                         if(i >= QUEUE_SIZE)
1378                         {
1379                             eError=OMX_ErrorUndefined;
1380                             pthread_mutex_unlock(&phandle->mutex);
1381                             goto EXIT;
1382                         }
1383 
1384                         LCML_MALLOC(phandle->pStrmcntlDmmBuf[i],sizeof(DMM_BUFFER_OBJ),DMM_BUFFER_OBJ);
1385                         if(phandle->pStrmcntlDmmBuf[i] == NULL)
1386                         {
1387                             eError = OMX_ErrorInsufficientResources;
1388                             pthread_mutex_unlock(&phandle->mutex);
1389                             goto EXIT;
1390                         }
1391 
1392                         memset(phandle->pStrmcntlDmmBuf[i],0,sizeof(DMM_BUFFER_OBJ)); //ATC
1393 
1394                         eError = DmmMap(phandle->dspCodec->hProc, (int)args[2], args[1],(phandle->pStrmcntlDmmBuf[i]), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
1395                         if (eError != OMX_ErrorNone)
1396                         {
1397                             pthread_mutex_unlock(&phandle->mutex);
1398                             goto EXIT;
1399                         }
1400                         phandle->strmcntlmapped[i] = 1;
1401                         if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
1402                         {
1403                             /* playback mode */
1404                             msg.dwCmd = USN_GPPMSG_STRMCTRL | 0x01;
1405                             msg.dwArg1 = (int)args[0];
1406                             msg.dwArg2 = (int)phandle->pStrmcntlDmmBuf[i]->pMapped;
1407                         }
1408                         else if(phandle->dspCodec->DeviceInfo.TypeofRender == 1)
1409                         {
1410                             /* record mode */
1411                             msg.dwCmd = USN_GPPMSG_STRMCTRL;
1412                             msg.dwArg1 = (int)args[0];
1413                             msg.dwArg2 = (int)phandle->pStrmcntlDmmBuf[i]->pMapped;
1414                         }
1415             }
1416 #ifdef __PERF_INSTRUMENTATION__
1417                         PERF_SendingCommand(phandle->pPERF,
1418                                             msg.dwCmd,
1419                                             msg.dwArg1,
1420                                             PERF_ModuleSocketNode);
1421 #endif
1422             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
1423             pthread_mutex_unlock(&phandle->mutex);
1424             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
1425 
1426             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "STRMControl: arg[0]: message = %x\n",(int)args[0]);
1427             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "STRMControl: arg[1]: address = %p\n",args[1]);
1428             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "STRMControl: arg[2]: size = %d\n",(int)args[2]);
1429             break;
1430         }
1431         case EMMCodecControlUsnEos:
1432         {
1433             phandle->bUsnEos = OMX_TRUE;
1434             break;
1435         }
1436 
1437     }
1438 
1439 EXIT:
1440     return eError;
1441 }
1442 
1443 
1444 /** ========================================================================
1445 *  DmmMap () method is used to allocate the memory using DMM.
1446 *
1447 *  @param ProcHandle -  Component identification number
1448 *  @param size  - Buffer header address, that needs to be sent to codec
1449 *  @param pArmPtr - Message used to send the buffer to codec
1450 *  @param pDmmBuf - buffer id
1451 *
1452 *  @retval OMX_ErrorNone  - Success
1453 *          OMX_ErrorHardware  -  Hardware Error
1454 ** ==========================================================================*/
DmmMap(DSP_HPROCESSOR ProcHandle,OMX_U32 size,void * pArmPtr,DMM_BUFFER_OBJ * pDmmBuf,struct OMX_TI_Debug dbg)1455 OMX_ERRORTYPE DmmMap(DSP_HPROCESSOR ProcHandle,
1456                      OMX_U32 size,
1457                      void* pArmPtr,
1458                      DMM_BUFFER_OBJ* pDmmBuf,
1459                      struct OMX_TI_Debug dbg)
1460 {
1461     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
1462     DSP_STATUS status;
1463     int nSizeReserved = 0;
1464 
1465     if(pDmmBuf == NULL)
1466     {
1467         OMX_ERROR4 (dbg, "pBuf is NULL\n");
1468         eError = OMX_ErrorBadParameter;
1469         goto EXIT;
1470     }
1471 
1472     if(pArmPtr == NULL)
1473     {
1474         OMX_ERROR4 (dbg, "pBuf is NULL\n");
1475         eError = OMX_ErrorBadParameter;
1476         goto EXIT;
1477     }
1478 
1479     /* Allocate */
1480     pDmmBuf->pAllocated = pArmPtr;
1481 
1482     /* Reserve */
1483     nSizeReserved = ROUND_TO_PAGESIZE(size) + 2*DMM_PAGE_SIZE ;
1484     status = DSPProcessor_ReserveMemory(ProcHandle, nSizeReserved, &(pDmmBuf->pReserved));
1485     if(DSP_FAILED(status))
1486     {
1487         OMX_ERROR4 (dbg, "DSPProcessor_ReserveMemory() failed - error 0x%x", (int)status);
1488         eError = OMX_ErrorInsufficientResources;
1489         goto EXIT;
1490     }
1491     pDmmBuf->nSize = size;
1492 
1493 
1494     OMX_PRBUFFER2 (dbg, " DMM MAP Reserved: %p (for buf %p), size 0x%x (%d)", pDmmBuf->pReserved, pArmPtr, nSizeReserved,nSizeReserved);
1495 
1496     /* Map */
1497     status = DSPProcessor_Map(ProcHandle,
1498                               pDmmBuf->pAllocated,/* malloc'd data here*/
1499                               size , /* size */
1500                               pDmmBuf->pReserved, /* reserved space */
1501                               &(pDmmBuf->pMapped), /* returned map pointer */
1502                               0); /* final param is reserved.  set to zero. */
1503     if(DSP_FAILED(status))
1504     {
1505         OMX_ERROR4 (dbg, "DSPProcessor_Map() failed - error 0x%x", (int)status);
1506         eError = OMX_ErrorInsufficientResources;
1507         goto EXIT;
1508     }
1509     OMX_PRBUFFER1 (dbg, "DMM Mapped: %p, size 0x%lx (%ld)",pDmmBuf->pMapped, size,size);
1510 
1511     /* Previously we used to Flush or Invalidate the mapped buffer.  This was
1512      * removed due to bridge is now handling the flush/invalidate operation */
1513     eError = OMX_ErrorNone;
1514 
1515 EXIT:
1516    return eError;
1517 }
1518 
1519 
1520 /** ========================================================================
1521 *  DmmUnMap () method is used to de-allocate the memory using DMM.
1522 *
1523 *  @param ProcHandle -  Component identification number
1524 *  @param pMapPtr  - Map address
1525 *  @param pResPtr - reserve adress
1526 *
1527 *  @retval OMX_ErrorNone  - Success
1528 *          OMX_ErrorHardware  -  Hardware Error
1529 ** ==========================================================================*/
DmmUnMap(DSP_HPROCESSOR ProcHandle,void * pMapPtr,void * pResPtr,struct OMX_TI_Debug dbg)1530 OMX_ERRORTYPE DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg )
1531 {
1532     DSP_STATUS status = DSP_SOK;
1533     OMX_ERRORTYPE eError = OMX_ErrorNone;
1534 
1535     if(pMapPtr == NULL)
1536     {
1537         OMX_ERROR4 (dbg, "pMapPtr is NULL\n");
1538         eError = OMX_ErrorBadParameter;
1539         goto EXIT;
1540     }
1541     if(pResPtr == NULL)
1542     {
1543         OMX_ERROR4 (dbg, "pResPtr is NULL\n");
1544         eError = OMX_ErrorBadParameter;
1545         goto EXIT;
1546     }
1547     status = DSPProcessor_UnMap(ProcHandle,pMapPtr);
1548     if(DSP_FAILED(status))
1549     {
1550         OMX_PRDSP4 (dbg, "DSPProcessor_UnMap() failed - error 0x%x",(int)status);
1551    }
1552 
1553     OMX_PRINT2 (dbg, "unreserving  structure =0x%p\n",pResPtr );
1554     status = DSPProcessor_UnReserveMemory(ProcHandle,pResPtr);
1555     if(DSP_FAILED(status))
1556     {
1557         OMX_PRDSP4 (dbg, "DSPProcessor_UnReserveMemory() failed - error 0x%x", (int)status);
1558     }
1559 
1560 EXIT:
1561     return eError;
1562 }
1563 
1564 /** ========================================================================
1565 * FreeResources () method is used to allocate the memory using DMM.
1566 *
1567 * @param hInterface  - Component identification number
1568 *
1569 * @retval OMX_ErrorNone           Success
1570 *         OMX_ErrorHardware       Hardware Error
1571 ** ==========================================================================*/
FreeResources(LCML_DSP_INTERFACE * hInterface)1572 OMX_ERRORTYPE FreeResources (LCML_DSP_INTERFACE *hInterface)
1573 {
1574     OMX_ERRORTYPE eError = OMX_ErrorNone;
1575     LCML_DSP_INTERFACE *codec;
1576 
1577     OMX_PRINT1 ((struct OMX_TI_Debug)(((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg), "%d :: LCML:: FreeResources\n",__LINE__);
1578     if(hInterface->dspCodec != NULL)
1579     {
1580         LCML_FREE(hInterface->dspCodec);
1581         hInterface->dspCodec = NULL;
1582     }
1583     codec = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle)->pCodec);
1584     if(codec != NULL)
1585     {
1586         pthread_mutex_destroy(&codec->m_isStopped_mutex);
1587         pthread_mutex_lock(&codec->mutex);
1588 
1589         OMX_PRINT1 ((struct OMX_TI_Debug)(((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg), "%d :: LCML:: FreeResources\n",__LINE__);
1590         if(codec->g_aNotificationObjects[0]!= NULL)
1591         {
1592             LCML_FREE(codec->g_aNotificationObjects[0]);
1593             codec->g_aNotificationObjects[0] = NULL;
1594 #ifdef __ERROR_PROPAGATION__
1595             if(codec->g_aNotificationObjects[1]!= NULL)
1596             {
1597                 LCML_FREE(codec->g_aNotificationObjects[1]);
1598                 codec->g_aNotificationObjects[1] = NULL;
1599             }
1600             if(codec->g_aNotificationObjects[2]!= NULL)
1601             {
1602                 LCML_FREE(codec->g_aNotificationObjects[2]);
1603                 codec->g_aNotificationObjects[2] = NULL;
1604             }
1605  #endif
1606             OMX_DBG_CLOSE((struct OMX_TI_Debug )(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle)->dbg));
1607             LCML_FREE(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle));
1608             hInterface->pCodecinterfacehandle = NULL;
1609         }
1610         pthread_mutex_unlock(&codec->mutex);
1611         pthread_mutex_destroy (&codec->mutex);
1612         LCML_FREE(codec);
1613         codec = NULL;
1614     }
1615     return eError;
1616 }
1617 
1618 /** ========================================================================
1619 * DeleteDspResource () method is used to allocate the memory using DMM.
1620 *
1621 * @param hInterface                   Component identification number
1622 *
1623 * @retval OMX_ErrorNone           Success
1624 *         OMX_ErrorHardware       Hardware Error
1625 ** ==========================================================================*/
DeleteDspResource(LCML_DSP_INTERFACE * hInterface)1626 OMX_ERRORTYPE DeleteDspResource(LCML_DSP_INTERFACE *hInterface)
1627 {
1628     OMX_ERRORTYPE eError = OMX_ErrorNone;
1629     DSP_STATUS status;
1630     DSP_STATUS nExit;
1631     struct DSP_NODEATTR nodeAttr;
1632     OMX_U32 dllinfo;
1633     LCML_DSP_INTERFACE *codec;
1634 
1635     /* Get current state of node, if it is running, then only terminate it */
1636 
1637     status = DSPNode_GetAttr(hInterface->dspCodec->hNode, &nodeAttr, sizeof(nodeAttr));
1638     DSP_ERROR_EXIT (status, "DeInit: Error in Node GetAtt ", EXIT);
1639         status = DSPNode_Terminate(hInterface->dspCodec->hNode, &nExit);
1640     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: LCML:: Node Has Been Terminated --1\n",__LINE__);
1641     codec = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle)->pCodec);
1642     if(codec->g_aNotificationObjects[0]!= NULL)
1643     {
1644     }
1645 #ifdef __ERROR_PROPAGATION__
1646     if(codec->g_aNotificationObjects[1]!= NULL)
1647     {
1648        /* status = DSPNode_RegisterNotify(hInterface->dspCodec->hProc, 0, DSP_SIGNALEVENT, codec->g_aNotificationObjects[1]);
1649         DSP_ERROR_EXIT(status, "DSP node de-register notify", EXIT);*/
1650     }
1651 #endif
1652     if (hInterface->dspCodec->DeviceInfo.TypeofDevice == 1) {
1653         /* delete DASF node */
1654         status = DSPNode_Delete(hInterface->dspCodec->hDasfNode);
1655         DSP_ERROR_EXIT (status, "DeInit: DASF Node Delete ", EXIT);
1656         OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Deleted the DASF node Successfully\n",__LINE__);
1657     }
1658 	/* delete SN */
1659     status = DSPNode_Delete(hInterface->dspCodec->hNode);
1660     DSP_ERROR_EXIT (status, "DeInit: Codec Node Delete ", EXIT);
1661     OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Deleted the node Successfully\n",__LINE__);
1662 
1663     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Entering UnLoadDLLs \n", __LINE__);
1664     for(dllinfo=0;dllinfo < hInterface->dspCodec->NodeInfo.nNumOfDLLs ;dllinfo++)
1665     {
1666         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Register Component Node\n",hInterface->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
1667         status = DSPManager_UnregisterObject ((struct DSP_UUID *) hInterface->dspCodec->NodeInfo.AllUUIDs[dllinfo].uuid,
1668                                                                                         hInterface->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
1669         /*DSP_ERROR_EXIT (status, "Unregister DSP Object, Socket UUID ", EXIT);*/
1670     }
1671 
1672     /* detach processor from gpp */
1673     status = DSPProcessor_Detach(hInterface->dspCodec->hProc);
1674     DSP_ERROR_EXIT (status, "DeInit: DSP Processor Detach ", EXIT);
1675 
1676     status = DspManager_Close(0, NULL);
1677     DSP_ERROR_EXIT (status, "DeInit: DSPManager Close ", EXIT);
1678 
1679 EXIT:
1680     return eError;
1681 
1682 }
1683 
1684 
1685 /** ========================================================================
1686 * This is the function run in the message thread.  It waits for an event
1687 * signal from Bridge and then reads all available messages.
1688 *
1689 * @param[in] arg  Unused - Required by pthreads API
1690 *
1691 * @retval  OMX_ErrorNone Success, ready to roll
1692 ** ==========================================================================*/
MessagingThread(void * arg)1693 void* MessagingThread(void* arg)
1694 {
1695     /* OMX_ERRORTYPE eError = OMX_ErrorUndefined; */
1696     DSP_STATUS status = DSP_SOK;
1697     struct DSP_MSG msg = {0,0,0};
1698     unsigned int index=0;
1699     LCML_MESSAGINGTHREAD_STATE threadState = EMessagingThreadCodecStopped;
1700     int waitForEventsTimeout = 1000;
1701 
1702     // There is no need to set a timeout value for message retrieval.
1703     // Just in case that we need to change it to a different value
1704     // such as 10 ms?
1705     const int getMessageTimeout = 0;
1706 
1707 #ifdef ANDROID
1708     prctl(PR_SET_NAME, (unsigned long)"Messaging", 0, 0, 0);
1709 #endif
1710 
1711     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Inside the Messaging thread\n");
1712 #ifdef __PERF_INSTRUMENTATION__
1713     ((LCML_DSP_INTERFACE *)arg)->pPERFcomp =
1714         PERF_Create(PERF_FOURCC('C','M','L','T'),
1715                     PERF_ModuleAudioDecode | PERF_ModuleAudioEncode |
1716                     PERF_ModuleVideoDecode | PERF_ModuleVideoEncode |
1717                     PERF_ModuleImageDecode | PERF_ModuleImageEncode |
1718                     PERF_ModuleCommonLayer);
1719 #endif
1720     if (((LCML_DSP_INTERFACE *)arg)->ReUseMap)
1721     {
1722         pthread_mutex_lock(&((LCML_DSP_INTERFACE *)arg)->m_isStopped_mutex);
1723     }
1724 
1725     /* get message from DSP */
1726     while (1)
1727     {
1728         if (((LCML_DSP_INTERFACE *)arg)->pshutdownFlag == 1)
1729         {
1730             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Breaking out of loop inmessaging thread \n");
1731             break;
1732         }
1733 
1734         if (threadState == EMessagingThreadCodecRunning) {
1735             waitForEventsTimeout = 10000;
1736         }
1737         /* set the timeouts lower when the codec is stopped so that thread deletion response will be faster */
1738         else if (threadState == EMessagingThreadCodecStopped) {
1739             waitForEventsTimeout = 10;
1740         }
1741 
1742 #ifdef __ERROR_PROPAGATION__
1743         status = DSPManager_WaitForEvents(((LCML_DSP_INTERFACE *)arg)->g_aNotificationObjects, 3, &index, waitForEventsTimeout);
1744 #else
1745         status = DSPManager_WaitForEvents(((LCML_DSP_INTERFACE *)arg)->g_aNotificationObjects, 1, &index, waitForEventsTimeout);
1746 #endif
1747         if (DSP_SUCCEEDED(status))
1748         {
1749             OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT notofication FROM DSP HANDLE IT \n");
1750 #ifdef __ERROR_PROPAGATION__
1751             if (index == 0){
1752 #endif
1753             /* Pull all available messages out of the message loop */
1754             while (DSP_SUCCEEDED(status))
1755             {
1756                 /* since there is a message waiting, grab it and pass  */
1757                 status = DSPNode_GetMessage(((LCML_DSP_INTERFACE *)arg)->dspCodec->hNode, &msg, getMessageTimeout);
1758                 if (DSP_SUCCEEDED(status))
1759                 {
1760                     OMX_U32 streamId = (msg.dwCmd & 0x000000ff);
1761                     int commandId = msg.dwCmd & 0xffffff00;
1762                     TMMCodecBufferType bufType ;/* = EMMCodecScratchBuffer; */
1763                     TUsnCodecEvent  event = EMMCodecInternalError;
1764                     void * args[10] = {};
1765                     TArmDspCommunicationStruct  *tmpDspStructAddress = NULL;
1766                     LCML_DSP_INTERFACE *hDSPInterface = ((LCML_DSP_INTERFACE *)arg) ;
1767                     DMM_BUFFER_OBJ* pDmmBuf = NULL;
1768 
1769                     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1770                             "GOT MESSAGE FROM DSP HANDLE IT  %d \n", index);
1771                     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1772                             "msg = 0x%lx arg1 = 0x%lx arg2 = 0x%lx", msg.dwCmd, msg.dwArg1, msg.dwArg2);
1773                     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1774                             "Message EMMCodecOuputBuffer outside loop");
1775 #ifdef __PERF_INSTRUMENTATION__
1776                     PERF_ReceivedCommand(hDSPInterface->pPERFcomp,
1777                                          msg.dwCmd, msg.dwArg1,
1778                                          PERF_ModuleSocketNode);
1779 #endif
1780 
1781                     if (commandId == USN_DSPMSG_BUFF_FREE )
1782                     {
1783                         threadState = EMessagingThreadCodecRunning;
1784  #ifdef __PERF_INSTRUMENTATION__
1785                                         PERF_XferingBuffer(hDSPInterface->pPERFcomp,
1786                                                           args [1],
1787                                                           (OMX_U32) args [8],
1788                                                           PERF_ModuleSocketNode,
1789                                                           PERF_ModuleLLMM);
1790 #endif
1791                         pthread_mutex_lock(&hDSPInterface->mutex);
1792                         if (!(streamId % 2))
1793                         {
1794                             int i = 0;
1795                             int j = 0;
1796                             bufType = streamId + EMMCodecStream0;
1797                             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1798                                     "Address Arminputstorage %p \n", ((LCML_DSP_INTERFACE *)arg)->Arminputstorage);
1799                             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1800                                     "Address dspinterface %p \n", ((LCML_DSP_INTERFACE *)arg));
1801 
1802                             hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
1803                             i = hDSPInterface->iBufinputcount;
1804                             while(j++ < QUEUE_SIZE)
1805                             {
1806                                 if (hDSPInterface->Arminputstorage[i] != NULL && hDSPInterface ->Arminputstorage[i]->iArmArg == msg.dwArg1)
1807                                 {
1808                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "InputBuffer loop");
1809                                     tmpDspStructAddress = ((LCML_DSP_INTERFACE *)arg)->Arminputstorage[i] ;
1810                                     hDSPInterface->Arminputstorage[i] =NULL;
1811                                     pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
1812                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
1813                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Address output  matching index= %ld \n ",tmpDspStructAddress->BufInindex);
1814                                     break;
1815                                 }
1816                                 i++;
1817                                 i = i % QUEUE_SIZE;
1818                                 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Message EMMCodecInputBuffer loop");
1819                             }
1820                         }
1821                         else if (streamId % 2)
1822                         {
1823                             int i = 0;
1824                             int j = 0;
1825                             bufType = streamId + EMMCodecStream0;;
1826                             OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Address Armoutputstorage %p \n ",((LCML_DSP_INTERFACE *)arg)->Armoutputstorage);
1827                             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Address dspinterface %p \n ",((LCML_DSP_INTERFACE *)arg));
1828 
1829                             hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
1830                             i = hDSPInterface->iBufoutputcount;
1831                             while(j++ < QUEUE_SIZE)
1832                             {
1833                                 if( hDSPInterface ->Armoutputstorage[i] != NULL
1834                                         && hDSPInterface ->Armoutputstorage[i]->iArmArg == msg.dwArg1)
1835                                 {
1836                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "output buffer loop");
1837                                     tmpDspStructAddress = hDSPInterface->Armoutputstorage[i] ;
1838                                     hDSPInterface ->Armoutputstorage[i] =NULL;
1839                                     pDmmBuf = hDSPInterface ->dspCodec->OutDmmBuffer;
1840                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->Bufoutindex);
1841                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1842                                             "Address output  matching index= %ld\n ",tmpDspStructAddress->Bufoutindex);
1843                                     break;
1844                                 }
1845                                 i++;
1846                                 i = i % QUEUE_SIZE;
1847                                 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1848                                         "Message EMMCodecOuputBuffer loop");
1849                             }
1850                         }
1851 
1852                         if (tmpDspStructAddress != NULL)
1853                         {
1854                             char *tmp2 = NULL;
1855 
1856                             status = DSPProcessor_InvalidateMemory(hDSPInterface->dspCodec->hProc,
1857                                             tmpDspStructAddress, sizeof(TArmDspCommunicationStruct));
1858                             if (DSP_FAILED(status)) {
1859                                 ALOGE("Invalidate for communication structure failed. status = 0x%x\n", status);
1860                             }
1861 
1862                             // Only invalidate the memory when the pointer points to some valid memory region
1863                             // otherwise, we will get logging spam
1864                             if (tmpDspStructAddress->iArmParamArg != NULL && tmpDspStructAddress->iParamSize > 0) {
1865                                 status = DSPProcessor_InvalidateMemory(hDSPInterface->dspCodec->hProc,
1866                                                 tmpDspStructAddress->iArmParamArg, tmpDspStructAddress->iParamSize);
1867                                 if (DSP_FAILED(status)) {
1868                                     ALOGE("Invalidate for arm parameter arguments failed. status = 0x%x\n", status);
1869                                 }
1870                             }
1871 
1872                             event = EMMCodecBufferProcessed;
1873                             args[0] = (void *) bufType;
1874                             args[1] = (void *) tmpDspStructAddress->iArmbufferArg; /* arm address fpr buffer */
1875                             args[2] = (void *) tmpDspStructAddress->iBufferSize;
1876                             args[3] = (void *) tmpDspStructAddress->iArmParamArg; /* arm address for param */
1877                             args[4] = (void *) tmpDspStructAddress->iParamSize;
1878                             args[5] = (void *) tmpDspStructAddress->iArmArg;
1879                             args[6] = (void *) arg;  /* handle */
1880                             args[7] = (void *) tmpDspStructAddress->iUsrArg;  /* user arguments */
1881 
1882                             if (((LCML_DSP_INTERFACE *)arg)->bUsnEos) {
1883                                 ((OMX_BUFFERHEADERTYPE*)args[7])->nFlags |= tmpDspStructAddress->iEOSFlag;
1884                             }
1885                             /* USN updates*/
1886                             args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
1887                             /* managing buffers  and free buffer logic */
1888 
1889                             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1890                                     "GOT MESSAGE EMMCodecBufferProcessed  and now unmapping buffer type %p \n", args[2]);
1891 
1892                             if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
1893                             {
1894                                 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1895                                         "GOT MESSAGE EMMCodecBufferProcessed and now unmapping buufer %lx\n size=%ld",
1896                                              tmpDspStructAddress ->iBufferPtr, tmpDspStructAddress ->iBufferSize);
1897                                 /* 720p implementation */
1898                                 if (!hDSPInterface->ReUseMap)
1899                                 {
1900                                     DmmUnMap(hDSPInterface->dspCodec->hProc,
1901                                             (void*)tmpDspStructAddress->iBufferPtr,
1902                                             pDmmBuf->bufReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
1903                                 }
1904                             }
1905 
1906                             if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
1907                             {
1908                                 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1909                                         "GOT MESSAGE EMMCodecBufferProcessed and now unmapping parameter buufer\n");
1910 
1911                                 DmmUnMap(hDSPInterface ->dspCodec->hProc,
1912                                          (void*)tmpDspStructAddress->iParamPtr,
1913                                          pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
1914                             }
1915 
1916                             OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1917                                     "GOT MESSAGE EMMCodecBufferProcessed  and now unmapping  structure =0x%p\n",tmpDspStructAddress );
1918                             DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
1919                             tmp2 = (char *)tmpDspStructAddress;
1920                             tmp2 = (tmp2 - 128);
1921                             if (tmp2)
1922                             {
1923                                 LCML_FREE(tmp2);
1924                                 tmp2 = NULL;
1925                             }
1926 
1927                             /* free(tmpDspStructAddress); */
1928                             tmpDspStructAddress = NULL;
1929                         }
1930                         pthread_mutex_unlock(&hDSPInterface->mutex);
1931                     } /* End of USN_DSPMSG_BUFF_FREE */
1932 
1933                     else if (commandId == USN_DSPACK_STOP)
1934                     {
1935                         threadState = EMessagingThreadCodecStopped;
1936 
1937                         /* Start of USN_DSPACK_STOP */
1938                         int i = 0;
1939                         int j = 0;
1940                         int k = 0;
1941                         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1942                                 "GOT MESSAGE EMMCodecProcessingStoped \n");
1943                         pthread_mutex_lock(&hDSPInterface->mutex);
1944                         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1945                                 "LCMLSTOP: hDSPInterface->dspCodec->DeviceInfo.TypeofDevice %d\n", hDSPInterface->dspCodec->DeviceInfo.TypeofDevice);
1946                         if (hDSPInterface->dspCodec->DeviceInfo.TypeofDevice == 0)
1947                         {
1948                             j = 0;
1949                             hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
1950                             i = hDSPInterface->iBufinputcount;
1951 
1952                             hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
1953                             k = hDSPInterface->iBufoutputcount;
1954 
1955                             while(j++ < QUEUE_SIZE)
1956                             {
1957                                 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1958                                         "LCMLSTOP: %d hDSPInterface->Arminputstorage[i] = %p\n", i, hDSPInterface->Arminputstorage[i]);
1959                                 if (hDSPInterface->Arminputstorage[i] != NULL)
1960                                 {
1961                                     char *tmp2 = NULL;
1962                                     /* callback the component with the buffers that are being freed */
1963                                     tmpDspStructAddress = hDSPInterface->Arminputstorage[i] ;
1964 
1965                                     pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
1966                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
1967                                     OMX_PRBUFFER1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1968                                             "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
1969 
1970                                     event = EMMCodecBufferProcessed;
1971                                     args[0] = (void *) EMMCodecInputBuffer;
1972                                     args[1] = (void *) tmpDspStructAddress->iArmbufferArg; /* arm address fpr buffer */
1973                                     args[2] = (void *) tmpDspStructAddress->iBufferSize;
1974                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg; /* arm address for param */
1975                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
1976                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
1977                                     args[6] = (void *) arg;  /* handle */
1978                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;  /* user arguments */
1979                                     /* USN updates*/
1980                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
1981 
1982                                     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1983                                             "LCMLSTOP: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
1984                                             (void *)tmpDspStructAddress->iBufferPtr,
1985                                             (void *)tmpDspStructAddress->iParamPtr,
1986                                             (void *)msg.dwArg1);
1987                                     if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
1988                                     {
1989                                         if (!hDSPInterface->ReUseMap)
1990                                         {
1991                                             DmmUnMap(hDSPInterface->dspCodec->hProc,
1992                                                     (void*)tmpDspStructAddress->iBufferPtr,
1993                                                     pDmmBuf->bufReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
1994                                         }
1995                                     }
1996 
1997                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
1998                                     {
1999                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
2000                                                  (void*)tmpDspStructAddress->iParamPtr,
2001                                                  pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2002                                     }
2003                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2004 
2005                                     if (NULL != tmpDspStructAddress)
2006                                     {
2007                                         tmp2 = (char*)tmpDspStructAddress;
2008                                         tmp2 = ( tmp2 - 128);
2009                                     }
2010                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2011                                             "%d :: LCML:: FreeResources\n",__LINE__);
2012                                     if (tmp2)
2013                                     {
2014                                         LCML_FREE(tmp2);
2015                                         tmp2 = NULL;
2016                                     }
2017                                     hDSPInterface->Arminputstorage[i] = NULL;
2018                                     tmpDspStructAddress     = NULL;
2019 #ifdef __PERF_INSTRUMENTATION__
2020                                     PERF_XferingBuffer(hDSPInterface->pPERFcomp,
2021                                                       args [1],
2022                                                       (OMX_U32) args [2],
2023                                                       PERF_ModuleSocketNode,
2024                                                       PERF_ModuleLLMM);
2025 #endif
2026                                     hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2027                                 }
2028 
2029                                 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2030                                         "LCMLSTOP: %d hDSPInterface->Armoutputstorage[k] = %p\n", k, hDSPInterface->Armoutputstorage[k]);
2031                                 if (hDSPInterface->Armoutputstorage[k] != NULL)
2032                                 {
2033                                     char * tmp2 = NULL;
2034                                     tmpDspStructAddress = hDSPInterface->Armoutputstorage[k] ;
2035 
2036                                     pDmmBuf = hDSPInterface ->dspCodec->OutDmmBuffer;
2037                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->Bufoutindex);
2038 
2039                                     event = EMMCodecBufferProcessed;
2040                                     args[0] = (void *) EMMCodecOuputBuffer;
2041                                     args[1] = (void *) tmpDspStructAddress->iArmbufferArg; /* arm address fpr buffer */
2042                                     args[2] = (void *) tmpDspStructAddress->iBufferSize;
2043                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg; /* arm address for param */
2044                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
2045                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
2046                                     args[6] = (void *) arg;  /* handle */
2047                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;  /* user arguments */
2048                                     /* USN updates*/
2049 
2050                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2051                                             "LCMLSTOP: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
2052                                             (void *)tmpDspStructAddress->iBufferPtr,
2053                                             (void *)tmpDspStructAddress->iParamPtr,
2054                                             (void *)msg.dwArg1);
2055                                     if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
2056                                     {
2057                                         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2058                                                 "tmpDspStructAddress ->iBufferPtr is not NULL\n");
2059                                         if (!hDSPInterface->ReUseMap)
2060                                         {
2061                                             DmmUnMap(hDSPInterface->dspCodec->hProc,
2062                                                     (void*)tmpDspStructAddress->iBufferPtr,
2063                                                     pDmmBuf->bufReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2064                                         }
2065                                     }
2066 
2067                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2068                                     {
2069                                         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2070                                                 "tmpDspStructAddress->iParamPtr is not NULL\n");
2071                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
2072                                                  (void*)tmpDspStructAddress->iParamPtr,
2073                                                  pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2074                                     }
2075                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2076 
2077                                     tmp2 = (char *) tmpDspStructAddress;
2078                                     tmp2 = ( tmp2 - 128);
2079                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2080                                             "%d :: LCML:: FreeResources\n",__LINE__);
2081                                     if(tmp2)
2082                                     {
2083                                         LCML_FREE(tmp2);
2084                                         tmp2 = NULL;
2085                                     }
2086                                     tmpDspStructAddress->iBufSizeUsed = 0;
2087                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
2088 
2089                                     hDSPInterface->Armoutputstorage[k] = NULL;
2090                                     tmpDspStructAddress = NULL;
2091 #ifdef __PERF_INSTRUMENTATION__
2092                                     PERF_XferingBuffer(hDSPInterface->pPERFcomp,
2093                                                       args[1],
2094                                                       (OMX_U32) args[2],
2095                                                       PERF_ModuleSocketNode,
2096                                                       PERF_ModuleLLMM);
2097 #endif
2098                                     hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2099                                 }
2100                                 i++;
2101                                 i = i % QUEUE_SIZE;
2102                                 k++;
2103                                 k = k % QUEUE_SIZE;
2104                             }
2105                         }
2106                         pthread_mutex_unlock(&hDSPInterface->mutex);
2107                         args[6] = (void *) arg;  /* handle */
2108                         event = EMMCodecProcessingStoped;
2109 
2110                     } /* end of USN_DSPACK_STOP */
2111                     else if (commandId == USN_DSPACK_PAUSE)
2112                     {
2113 
2114                         event = EMMCodecProcessingPaused;
2115                         OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2116                                 "GOT MESSAGE EMMCodecProcessingPaused \n");
2117                         args[6] = (void *) arg;  /* handle */
2118                     }
2119                     else if (commandId == USN_DSPMSG_EVENT)
2120                     {
2121                         threadState = EMessagingThreadCodecStopped;
2122 
2123                         event = EMMCodecDspError;
2124                         OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2125                                 "GOT MESSAGE EMMCodecDspError \n");
2126                         args[0] = (void *) msg.dwCmd;
2127                         args[4] = (void *) msg.dwArg1;
2128                         args[5] = (void *) msg.dwArg2;
2129                         args[6] = (void *) arg;  /* handle */
2130                     }
2131                     else if (commandId == USN_DSPACK_ALGCTRL)
2132                     {
2133 
2134                         int i;
2135                         event = EMMCodecAlgCtrlAck;
2136                         pthread_mutex_lock(&hDSPInterface->mutex);
2137                         for (i = 0; i < QUEUE_SIZE; i++)
2138                         {
2139                             pDmmBuf = ((LCML_DSP_INTERFACE *)arg)->pAlgcntlDmmBuf[i];
2140                             if ((pDmmBuf) &&
2141                                 (((LCML_DSP_INTERFACE *)arg)->algcntlmapped[i]) &&
2142                                 (pDmmBuf->pMapped == (void *)msg.dwArg2))
2143                             {
2144                                 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2145                                         ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2146                                 LCML_FREE(pDmmBuf);
2147                                 pDmmBuf = NULL;
2148                                 ((LCML_DSP_INTERFACE *)arg)->algcntlmapped[i] = 0;
2149                                 ((LCML_DSP_INTERFACE *)arg)->pAlgcntlDmmBuf[i] = NULL;
2150                                 break;
2151                             }
2152                         }
2153                         args[0] = (void *) msg.dwArg1;
2154                         args[6] = (void *) arg;  /* handle */
2155                         OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE USN_DSPACK_ALGCTRL \n");
2156                         pthread_mutex_unlock(&hDSPInterface->mutex);
2157                     }
2158                     else if (commandId == USN_DSPACK_STRMCTRL)
2159                     {
2160 
2161                         int i = 0;
2162                         int j = 0;
2163                         int ackType = 0;
2164                         pthread_mutex_lock(&hDSPInterface->mutex);
2165                         if (hDSPInterface->flush_pending[0] && (streamId == 0) && (msg.dwArg1 == USN_ERR_NONE))
2166                         {
2167                             hDSPInterface->flush_pending[0] = 0;
2168                             ackType = USN_STRMCMD_FLUSH;
2169                             j = 0;
2170                             hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
2171                             i = hDSPInterface->iBufinputcount;
2172                             while(j++ < QUEUE_SIZE)
2173                             {
2174                                 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2175                                         "LCMLFLUSH: %d hDSPInterface->Arminputstorage[i] = %p\n", i, hDSPInterface->Arminputstorage[i]);
2176                                 if (hDSPInterface->Arminputstorage[i] != NULL)
2177                                 {
2178                                     char *tmp2 = NULL;
2179                                     tmpDspStructAddress = hDSPInterface->Arminputstorage[i] ;
2180 
2181                                     pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
2182                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
2183                                     OMX_PRBUFFER2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2184                                             "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
2185 
2186                                     event = EMMCodecBufferProcessed;
2187                                     args[0] = (void *) EMMCodecInputBuffer;
2188                                     args[1] = (void *) tmpDspStructAddress->iArmbufferArg;
2189                                     args[2] = (void *) tmpDspStructAddress->iBufferSize;
2190                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg;
2191                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
2192                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
2193                                     args[6] = (void *) arg;
2194                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;
2195 
2196                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
2197 
2198                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2199                                             "LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
2200                                             (void *)tmpDspStructAddress->iBufferPtr,
2201                                             (void *)tmpDspStructAddress->iParamPtr,
2202                                             (void *)msg.dwArg1);
2203 
2204                                     if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
2205                                     {
2206                                         /* 720p implementation */
2207                                         if (!hDSPInterface->ReUseMap)
2208                                         {
2209                                             DmmUnMap(hDSPInterface->dspCodec->hProc,
2210                                                     (void*)tmpDspStructAddress->iBufferPtr,
2211                                                     pDmmBuf->bufReserved,
2212                                                     ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2213                                         }
2214                                     }
2215 
2216                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2217                                     {
2218                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
2219                                                  (void*)tmpDspStructAddress->iParamPtr,
2220                                                  pDmmBuf->paramReserved,
2221                                                  ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2222                                     }
2223                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2224                                             ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2225 
2226                                     if (NULL != tmpDspStructAddress)
2227                                     {
2228                                         tmp2 = (char*)tmpDspStructAddress;
2229                                         tmp2 = ( tmp2 - 128);
2230                                     }
2231                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2232                                             "%d :: LCML:: FreeResources\n",__LINE__);
2233                                     if (tmp2)
2234                                     {
2235                                         LCML_FREE(tmp2);
2236                                         tmp2 = NULL;
2237                                     }
2238                                     hDSPInterface->Arminputstorage[i] = NULL;
2239                                     tmpDspStructAddress     = NULL;
2240 #ifdef __PERF_INSTRUMENTATION__
2241                                     PERF_XferingBuffer(hDSPInterface->pPERFcomp,
2242                                                       args [1],
2243                                                       (OMX_U32) args [2],
2244                                                       PERF_ModuleSocketNode,
2245                                                       PERF_ModuleLLMM);
2246 #endif
2247                                     hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2248                                 }
2249                                 i++;
2250                                 i = i % QUEUE_SIZE;
2251                             }
2252                             for (i = 0; i < QUEUE_SIZE; i++)
2253                             {
2254                                 pDmmBuf = ((LCML_DSP_INTERFACE *)arg)->pStrmcntlDmmBuf[i];
2255                                 if ((pDmmBuf) &&
2256                                     (((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i]) &&
2257                                     (pDmmBuf->pMapped == (void *)msg.dwArg2))
2258                                 {
2259                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2260                                             ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2261                                     LCML_FREE(pDmmBuf);
2262                                     pDmmBuf = NULL;
2263                                     ((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i] = 0;
2264                                     ((LCML_DSP_INTERFACE *)arg)->pStrmcntlDmmBuf[i] = NULL;
2265                                     break;
2266                                 }
2267                             }
2268                         }
2269                         else if (hDSPInterface->flush_pending[1] && (streamId == 1) && (msg.dwArg1 == USN_ERR_NONE))
2270                         {
2271                             hDSPInterface->flush_pending[1] = 0;
2272                             ackType = USN_STRMCMD_FLUSH;
2273                             j = 0;
2274                             hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
2275                             i = hDSPInterface->iBufoutputcount;
2276                             while(j++ < QUEUE_SIZE)
2277                             {
2278                                 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2279                                         "LCMLFLUSH: %d hDSPInterface->Armoutputstorage[i] = %p\n", i, hDSPInterface->Armoutputstorage[i]);
2280                                 if (hDSPInterface->Armoutputstorage[i] != NULL)
2281                                 {
2282                                     char * tmp2 = NULL;
2283                                     tmpDspStructAddress = hDSPInterface->Armoutputstorage[i] ;
2284 
2285                                     pDmmBuf = hDSPInterface ->dspCodec->OutDmmBuffer;
2286                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->Bufoutindex);
2287 
2288                                     event = EMMCodecBufferProcessed;
2289                                     args[0] = (void *) EMMCodecOuputBuffer;
2290                                     args[1] = (void *) tmpDspStructAddress->iArmbufferArg;
2291                                     args[2] = (void *) tmpDspStructAddress->iBufferSize;
2292                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg;
2293                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
2294                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
2295                                     args[6] = (void *) arg;
2296                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;
2297 
2298 
2299                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2300                                             "LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
2301                                             (void *)tmpDspStructAddress->iBufferPtr,
2302                                             (void *)tmpDspStructAddress->iParamPtr,
2303                                             (void *)msg.dwArg1);
2304                                     if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
2305                                     {
2306                                         /* 720p implementation */
2307                                         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2308                                                 "tmpDspStructAddress ->iBufferPtr is not NULL\n");
2309                                         if (!hDSPInterface->ReUseMap)
2310                                         {
2311                                             DmmUnMap(hDSPInterface->dspCodec->hProc,
2312                                                     (void*)tmpDspStructAddress->iBufferPtr,
2313                                                     pDmmBuf->bufReserved,
2314                                                     ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2315                                         }
2316                                     }
2317 
2318                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2319                                     {
2320                                         OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2321                                                 "tmpDspStructAddress->iParamPtr is not NULL\n");
2322                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
2323                                                  (void*)tmpDspStructAddress->iParamPtr,
2324                                                  pDmmBuf->paramReserved,
2325                                                  ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2326                                     }
2327                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2328                                             ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2329 
2330                                     tmp2 = (char *) tmpDspStructAddress;
2331                                     tmp2 = ( tmp2 - 128);
2332                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2333                                             "%d :: LCML:: FreeResources\n",__LINE__);
2334                                     if(tmp2)
2335                                     {
2336                                         LCML_FREE(tmp2);
2337                                         tmp2 = NULL;
2338                                     }
2339                                     tmpDspStructAddress->iBufSizeUsed = 0;
2340                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
2341 
2342                                     hDSPInterface->Armoutputstorage[i] = NULL;
2343                                     tmpDspStructAddress = NULL;
2344 #ifdef __PERF_INSTRUMENTATION__
2345                                     PERF_XferingBuffer(hDSPInterface->pPERFcomp,
2346                                                       args[1],
2347                                                       (OMX_U32) args[2],
2348                                                       PERF_ModuleSocketNode,
2349                                                       PERF_ModuleLLMM);
2350 #endif
2351                                     hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2352                                 }
2353                                 i++;
2354                                 i = i % QUEUE_SIZE;
2355                             }
2356                             for (i = 0; i < QUEUE_SIZE; i++)
2357                             {
2358                                 pDmmBuf = ((LCML_DSP_INTERFACE *)arg)->pStrmcntlDmmBuf[i];
2359                                 if ((pDmmBuf) &&
2360                                     (((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i]) &&
2361                                     (pDmmBuf->pMapped == (void *)msg.dwArg2))
2362                                 {
2363                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2364                                             ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2365                                     LCML_FREE(pDmmBuf);
2366                                     pDmmBuf = NULL;
2367                                     ((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i] = 0;
2368                                     ((LCML_DSP_INTERFACE *)arg)->pStrmcntlDmmBuf[i] = NULL;
2369                                     break;
2370                                 }
2371                             }
2372                         }
2373                         if (hDSPInterface->flush_pending[2] && (streamId == 2) && (msg.dwArg1 == USN_ERR_NONE))
2374                         {
2375                             hDSPInterface->flush_pending[0] = 0;
2376                             ackType = USN_STRMCMD_FLUSH;
2377                             j = 0;
2378                             hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
2379                             i = hDSPInterface->iBufinputcount;
2380                             while(j++ < QUEUE_SIZE)
2381                             {
2382                                 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2383                                         "LCMLFLUSH (port 2): %d hDSPInterface->Arminputstorage[i] = %p (stream ID %lu)\n", i, hDSPInterface->Arminputstorage[i], streamId);
2384                                 if ((hDSPInterface->Arminputstorage[i] != NULL) && (hDSPInterface->Arminputstorage[i]->iStreamID == streamId))
2385                                 {
2386                                     char *tmp2 = NULL;
2387                                     tmpDspStructAddress = hDSPInterface->Arminputstorage[i] ;
2388 
2389                                     pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
2390                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
2391                                     OMX_PRBUFFER2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2392                                             "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
2393 
2394                                     event = EMMCodecBufferProcessed;
2395                                     args[0] = (void *) EMMCodecInputBuffer;
2396                                     args[1] = (void *) tmpDspStructAddress->iArmbufferArg;
2397                                     args[2] = (void *) tmpDspStructAddress->iBufferSize;
2398                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg;
2399                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
2400                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
2401                                     args[6] = (void *) arg;
2402                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;
2403 
2404                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
2405 
2406                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2407                                             "LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
2408                                             (void *)tmpDspStructAddress->iBufferPtr,
2409                                             (void *)tmpDspStructAddress->iParamPtr,
2410                                             (void *)msg.dwArg1);
2411                                     if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
2412                                     {
2413                                         /* 720p implementation */
2414                                         if (!hDSPInterface->ReUseMap)
2415                                         {
2416                                             DmmUnMap(hDSPInterface->dspCodec->hProc,
2417                                                     (void*)tmpDspStructAddress->iBufferPtr,
2418                                                     pDmmBuf->bufReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2419                                         }
2420                                     }
2421 
2422                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2423                                     {
2424                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
2425                                                  (void*)tmpDspStructAddress->iParamPtr,
2426                                                  pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2427                                     }
2428                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2429                                             ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2430 
2431                                     tmp2 = (char*)tmpDspStructAddress;
2432                                     tmp2 = ( tmp2 - 128);
2433                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2434                                             "%d :: LCML:: FreeResources\n",__LINE__);
2435                                     if (tmp2)
2436                                     {
2437                                         LCML_FREE(tmp2);
2438                                         tmp2 = NULL;
2439                                     }
2440                                     hDSPInterface->Arminputstorage[i] = NULL;
2441                                     tmpDspStructAddress     = NULL;
2442 #ifdef __PERF_INSTRUMENTATION__
2443                                     PERF_XferingBuffer(hDSPInterface->pPERFcomp,
2444                                                       args [1],
2445                                                       (OMX_U32) args [2],
2446                                                       PERF_ModuleSocketNode,
2447                                                       PERF_ModuleLLMM);
2448 #endif
2449                                     hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2450                                 }
2451                                 i++;
2452                                 i = i % QUEUE_SIZE;
2453                             }
2454                         }
2455                         else if (hDSPInterface->flush_pending[3] && (streamId == 3) && (msg.dwArg1 == USN_ERR_NONE))
2456                         {
2457                             hDSPInterface->flush_pending[1] = 0;
2458                             ackType = USN_STRMCMD_FLUSH;
2459                             j = 0;
2460                             hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
2461                             i = hDSPInterface->iBufoutputcount;
2462                             while(j++ < QUEUE_SIZE)
2463                             {
2464                                 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2465                                         "LCMLFLUSH: %d hDSPInterface->Armoutputstorage[i] = %p (stream id %lu)\n", i, hDSPInterface->Armoutputstorage[i], streamId);
2466                                 if ((hDSPInterface->Armoutputstorage[i] != NULL) && (hDSPInterface->Armoutputstorage[i]->iStreamID == streamId))
2467                                 {
2468                                     char * tmp2 = NULL;
2469                                     tmpDspStructAddress = hDSPInterface->Armoutputstorage[i] ;
2470 
2471                                     pDmmBuf = hDSPInterface ->dspCodec->OutDmmBuffer;
2472                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->Bufoutindex);
2473 
2474                                     event = EMMCodecBufferProcessed;
2475                                     args[0] = (void *) EMMCodecOuputBuffer;
2476                                     args[1] = (void *) tmpDspStructAddress->iArmbufferArg;
2477                                     args[2] = (void *) tmpDspStructAddress->iBufferSize;
2478                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg;
2479                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
2480                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
2481                                     args[6] = (void *) arg;
2482                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;
2483 
2484 
2485                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2486                                             "LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
2487                                             (void *)tmpDspStructAddress->iBufferPtr,
2488                                             (void *)tmpDspStructAddress->iParamPtr,
2489                                             (void *)msg.dwArg1);
2490                                     if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
2491                                     {
2492                                         /* 720p implementation */
2493                                         OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2494                                                 "tmpDspStructAddress ->iBufferPtr is not NULL\n");
2495                                         if (!hDSPInterface->ReUseMap)
2496                                         {
2497                                             DmmUnMap(hDSPInterface->dspCodec->hProc,
2498                                                     (void*)tmpDspStructAddress->iBufferPtr,
2499                                                     pDmmBuf->bufReserved,
2500                                                     ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2501                                         }
2502                                     }
2503 
2504                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2505                                     {
2506                                         OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2507                                                 "tmpDspStructAddress->iParamPtr is not NULL\n");
2508                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
2509                                                  (void*)tmpDspStructAddress->iParamPtr,
2510                                                  pDmmBuf->paramReserved,
2511                                                  ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2512                                     }
2513                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2514                                             ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2515 
2516                                     tmp2 = (char *) tmpDspStructAddress;
2517                                     tmp2 = ( tmp2 - 128);
2518                                     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2519                                             "%d :: LCML:: FreeResources\n",__LINE__);
2520                                     if(tmp2)
2521                                     {
2522                                         LCML_FREE(tmp2);
2523                                         tmp2 = NULL;
2524                                     }
2525                                     tmpDspStructAddress->iBufSizeUsed = 0;
2526                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
2527 
2528                                     hDSPInterface->Armoutputstorage[i] = NULL;
2529                                     tmpDspStructAddress = NULL;
2530 #ifdef __PERF_INSTRUMENTATION__
2531                                     PERF_XferingBuffer(hDSPInterface->pPERFcomp,
2532                                                       args[1],
2533                                                       (OMX_U32) args[2],
2534                                                       PERF_ModuleSocketNode,
2535                                                       PERF_ModuleLLMM);
2536 #endif
2537                                     hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2538                                 }
2539                                 i++;
2540                                 i = i % QUEUE_SIZE;
2541                             }
2542                         }
2543 
2544                         if (ackType != USN_STRMCMD_FLUSH) {
2545                             for (i = 0; i < QUEUE_SIZE; i++)
2546                             {
2547                                 pDmmBuf = ((LCML_DSP_INTERFACE *)arg)->pStrmcntlDmmBuf[i];
2548                                 if ((pDmmBuf) &&
2549                                     (((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i]) &&
2550                                     (pDmmBuf->pMapped == (void *)msg.dwArg2))
2551                                 {
2552                                     DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2553                                             ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
2554                                     LCML_FREE(pDmmBuf);
2555                                     pDmmBuf = NULL;
2556                                     ((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i] = 0;
2557                                     ((LCML_DSP_INTERFACE *)arg)->pStrmcntlDmmBuf[i] = NULL;
2558                                     break;
2559                                 }
2560                             }
2561                         }
2562                         pthread_mutex_unlock(&hDSPInterface->mutex);
2563 
2564                         event = EMMCodecStrmCtrlAck;
2565                         bufType = streamId + EMMCodecStream0;
2566                         args[0] = (void *) msg.dwArg1; /* SN error status */
2567                         args[1] = (void *) ackType;    /* acknowledge Id */
2568                         args[2] = (void *) bufType;    /* port Id */
2569                         args[6] = (void *) arg;        /* handle */
2570                         OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE USN_DSPACK_STRMCTRL \n");
2571                     }
2572                     else
2573                     {
2574                         event = EMMCodecDspMessageRecieved;
2575                         args[0] = (void *) msg.dwCmd;
2576                         args[1] = (void *) msg.dwArg1;
2577                         args[2] = (void *) msg.dwArg2;
2578                         args[6] = (void *) arg;  /* handle */
2579                         OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE EMMCodecDspMessageRecieved \n");
2580                     }
2581 
2582                     /* call callback */
2583                     OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "calling callback in application %p \n",((LCML_DSP_INTERFACE *)arg)->dspCodec);
2584 #ifdef __PERF_INSTRUMENTATION__
2585                     PERF_SendingCommand(hDSPInterface->pPERFcomp,
2586                                         msg.dwCmd,
2587                                         msg.dwArg1,
2588                                         PERF_ModuleLLMM);
2589 #endif
2590                     hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2591 
2592                 }/* end of internal if(DSP_SUCCEEDED(status)) */
2593                 else
2594                 {
2595                     OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "%d :: DSPManager_getmessage() failed: 0x%lx",__LINE__, status);
2596                 }
2597 
2598             }/* end of internal while loop*/
2599 #ifdef __ERROR_PROPAGATION__
2600             }/*end of if(index == 0)*/
2601             if (index == 1){
2602 
2603                 struct DSP_PROCESSORSTATE  procState;
2604                 DSPProcessor_GetState(((LCML_DSP_INTERFACE *)arg)->dspCodec->hProc, &procState, sizeof(procState));
2605 
2606                 /*
2607                 fprintf(stdout, " dwErrMask = %0x \n",procState.errInfo.dwErrMask);
2608                 fprintf(stdout, " dwVal1 = %0x \n",procState.errInfo.dwVal1);
2609                 fprintf(stdout, " dwVal2 = %0x \n",procState.errInfo.dwVal2);
2610                 fprintf(stdout, " dwVal3 = %0x \n",procState.errInfo.dwVal3);
2611                 fprintf(stdout, "MMU Fault Error.\n");
2612                 */
2613 
2614                 TUsnCodecEvent  event = EMMCodecDspError;
2615                 void * args[10];
2616                 LCML_DSP_INTERFACE *hDSPInterface = ((LCML_DSP_INTERFACE *)arg) ;
2617                 args[0] = NULL;
2618                 args[4] = NULL;
2619                 args[5] = NULL;
2620                 args[6] = (void *) arg;  /* handle */
2621                 hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2622 
2623             }
2624             if (index == 2){
2625 
2626                 struct DSP_PROCESSORSTATE  procState;
2627                 DSPProcessor_GetState(((LCML_DSP_INTERFACE *)arg)->dspCodec->hProc, &procState, sizeof(procState));
2628 
2629                 /*
2630                 fprintf(stdout, " dwErrMask = %0x \n",procState.errInfo.dwErrMask);
2631                 fprintf(stdout, " dwVal1 = %0x \n",procState.errInfo.dwVal1);
2632                 fprintf(stdout, " dwVal2 = %0x \n",procState.errInfo.dwVal2);
2633                 fprintf(stdout, " dwVal3 = %0x \n",procState.errInfo.dwVal3);
2634                 fprintf(stdout, "SYS_ERROR Error.\n");
2635                 */
2636 
2637                 TUsnCodecEvent  event = EMMCodecDspError;
2638                 void * args[10];
2639                 LCML_DSP_INTERFACE *hDSPInterface = ((LCML_DSP_INTERFACE *)arg) ;
2640                 args[0] = NULL;
2641                 args[4] = NULL;
2642                 args[5] = NULL;
2643                 args[6] = (void *) arg;  /* handle */
2644                 hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
2645 
2646             }
2647 #endif
2648         } /* end of external if(DSP_SUCCEEDED(status)) */
2649         else
2650         {
2651             OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "%d :: DSPManager_WaitForEvents() failed: 0x%lx",__LINE__, status);
2652         }
2653 
2654     } /* end of external while(1) loop */
2655 
2656 	/* 720p implementation */
2657     if (((LCML_DSP_INTERFACE *)arg)->ReUseMap)
2658     {
2659         pthread_mutex_unlock(&((LCML_DSP_INTERFACE *)arg)->m_isStopped_mutex);
2660     }
2661     OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Exiting LOOP of LCML \n");
2662 #ifdef __PERF_INSTRUMENTATION__
2663     PERF_Done(((LCML_DSP_INTERFACE *)arg)->pPERFcomp);
2664 #endif
2665     return (void*)OMX_ErrorNone;
2666 }
2667 
2668 
append_dsp_path(char * dll64p_name,char * absDLLname)2669 static int append_dsp_path(char * dll64p_name, char *absDLLname)
2670 {
2671     int len = 0;
2672     char *dsp_path = NULL;
2673     if (!(dsp_path = getenv("DSP_PATH")))
2674     {
2675         OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "DSP_PATH Environment variable not set using /system/lib/dsp default");
2676         dsp_path = "/system/lib/dsp";
2677     }
2678     len = strlen(dsp_path) + strlen("/") + strlen(dll64p_name) + 1 /* null terminator */;
2679     if (len >= ABS_DLL_NAME_LENGTH) return -1;
2680 
2681     strcpy(absDLLname,dsp_path);
2682     strcat(absDLLname,"/");
2683     strcat(absDLLname,dll64p_name);
2684     return 0;
2685 }
2686