blob: ec01e73906eb5821356c6c69b891faddba272668 [file] [log] [blame]
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001
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
Andreas Huber5807caa2010-03-12 14:20:45 -080051#ifdef ANDROID
Elliott Hughes05460082014-07-18 18:03:06 -070052#include <sys/prctl.h>
Andreas Huber5807caa2010-03-12 14:20:45 -080053#endif
54
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -070055#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>
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -070062#include "usn.h"
63#include <sys/time.h>
64
65#define CEXEC_DONE 1
66/*DSP_HNODE hDasfNode;*/
Anu Sundararajan69ee5a12009-09-27 09:17:41 -050067#define ABS_DLL_NAME_LENGTH 128
James Dongb65f2532010-02-04 11:00:34 -080068#undef LOG_TAG
69#define LOG_TAG "TI_LCML"
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -070070
Anu Sundararajan69ee5a12009-09-27 09:17:41 -050071#define LCML_MALLOC(p,s,t) \
72 p = (t*)malloc(s); \
73 if (NULL == p){ \
James Dongb65f2532010-02-04 11:00:34 -080074 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); \
Anu Sundararajan69ee5a12009-09-27 09:17:41 -050075 }else { \
James Dongb65f2532010-02-04 11:00:34 -080076 OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "LCML:::::::: (#%d F:%s)Success to allocate %d bytes ... pointer %p\n",__LINE__,__FUNCTION__,s,p); \
Anu Sundararajan69ee5a12009-09-27 09:17:41 -050077 }
78
79#define LCML_FREE(p) \
James Dongb65f2532010-02-04 11:00:34 -080080 OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "LCML:::::::: (#%d F:%s)Freeing pointer %p done",__LINE__,__FUNCTION__,p); \
Anu Sundararajan69ee5a12009-09-27 09:17:41 -050081 free(p);
82
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -070083/*Prototyping*/
84static OMX_ERRORTYPE InitMMCodec(OMX_HANDLETYPE hInt,
85 OMX_STRING codecName,
86 void *toCodecInitParams,
87 void *fromCodecInfoStruct,
88 LCML_CALLBACKTYPE *pCallbacks);
89static OMX_ERRORTYPE InitMMCodecEx(OMX_HANDLETYPE hInt,
90 OMX_STRING codecName,
91 void *toCodecInitParams,
92 void *fromCodecInfoStruct,
93 LCML_CALLBACKTYPE *pCallbacks,
94 OMX_STRING Args);
95static OMX_ERRORTYPE WaitForEvent(OMX_HANDLETYPE hComponent,
96 TUsnCodecEvent event,
97 void *args[10]);
98static 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);
106static OMX_ERRORTYPE ControlCodec(OMX_HANDLETYPE hComponent,
107 TControlCmd iCodecCmd,
108 void *args[10]);
109static OMX_ERRORTYPE DmmMap(DSP_HPROCESSOR ProcHandle,
110 OMX_U32 size,
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700111 void* pArmPtr,
Rebecca Schultz Zavinb44cdb12009-07-29 17:23:50 -0700112 DMM_BUFFER_OBJ* pDmmBuf,
James Dongb65f2532010-02-04 11:00:34 -0800113 struct OMX_TI_Debug dbg);
114
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700115static OMX_ERRORTYPE DmmUnMap(DSP_HPROCESSOR ProcHandle,
116 void *pMapPtr,
James Dongb65f2532010-02-04 11:00:34 -0800117 void *pResPtr,
118 struct OMX_TI_Debug dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700119static OMX_ERRORTYPE DeleteDspResource(LCML_DSP_INTERFACE *hInterface);
120static OMX_ERRORTYPE FreeResources(LCML_DSP_INTERFACE *hInterface);
121
122void* MessagingThread(void *arg);
123
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500124static int append_dsp_path(char * dll64p_name, char *absDLLname);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700125
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** =========================================================================*/
134OMX_ERRORTYPE GetHandle(OMX_HANDLETYPE *hInterface )
135{
136 OMX_ERRORTYPE err = 0 ;
137 LCML_DSP_INTERFACE* pHandle;
138 struct LCML_CODEC_INTERFACE *dspcodecinterface ;
139
James Dongb65f2532010-02-04 11:00:34 -0800140 OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "%d :: GetHandle application\n",__LINE__);
141 LCML_MALLOC(*hInterface,sizeof(LCML_DSP_INTERFACE),LCML_DSP_INTERFACE);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500142
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700143 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
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500152 LCML_MALLOC(dspcodecinterface,sizeof(LCML_CODEC_INTERFACE),LCML_CODEC_INTERFACE);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700153 if (dspcodecinterface == NULL)
154 {
155 err = OMX_ErrorInsufficientResources;
156 goto EXIT;
157 }
158 memset(dspcodecinterface, 0, sizeof(LCML_CODEC_INTERFACE));
James Dongb65f2532010-02-04 11:00:34 -0800159 OMX_DBG_INIT (dspcodecinterface->dbg, "TI_LCML");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700160
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
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500168 LCML_MALLOC(pHandle->dspCodec,sizeof(LCML_DSP),LCML_DSP);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700169 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700177 dspcodecinterface->pCodec = *hInterface;
James Dongb65f2532010-02-04 11:00:34 -0800178 OMX_PRINT2 (dspcodecinterface->dbg, "GetHandle application handle %p dspCodec %p",pHandle, pHandle->dspCodec);
179
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700180EXIT:
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* ==========================================================================*/
201static 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
James Dongb65f2532010-02-04 11:00:34 -0800213 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: InitMMCodecEx application\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700214
James Dongc22b4b52009-09-28 13:27:45 -0700215 if (hInt == NULL )
216 {
217 eError = OMX_ErrorInsufficientResources;
218 goto ERROR;
219 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700220 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;
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500229 int i = 0, k = 0;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700230 struct DSP_NODEATTRIN NodeAttrIn;
231 struct DSP_CBDATA *pArgs;
232 BYTE argsBuf[32 + sizeof(ULONG)];
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500233 char abs_dsp_path[ABS_DLL_NAME_LENGTH];
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700234#ifndef CEXEC_DONE
235 UINT argc = 1;
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500236 char argv[ABS_DLL_NAME_LENGTH];
237 k = append_dsp_path(DSP_DOF_IMAGE, argv);
238 if (k < 0)
239 {
James Dongb65f2532010-02-04 11:00:34 -0800240 OMX_PRDSP4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500241 eError = OMX_ErrorBadParameter;
242 goto ERROR;
243 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700244#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
James Dongb65f2532010-02-04 11:00:34 -0800258 /* 720p implementation */
259 {
260 pthread_mutex_init(&phandle->m_isStopped_mutex, NULL);
261 phandle->mapped_buffer_count = 0;
262 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700263 /* 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 */
James Dongb65f2532010-02-04 11:00:34 -0800273 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Entering Init_DSPSubSystem\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700274 status = DspManager_Open(0, NULL);
275 DSP_ERROR_EXIT(status, "DSP Manager Open", ERROR);
James Dongb65f2532010-02-04 11:00:34 -0800276 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DspManager_Open Successful\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700277
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);
James Dongb65f2532010-02-04 11:00:34 -0800281 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");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700283
284 for (dllinfo=0; dllinfo < phandle->dspCodec->NodeInfo.nNumOfDLLs; dllinfo++)
285 {
James Dongb65f2532010-02-04 11:00:34 -0800286 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Register Component Node\n",phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500287
288 k = append_dsp_path((char*)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].DllName, abs_dsp_path);
289 if (k < 0)
290 {
James Dongb65f2532010-02-04 11:00:34 -0800291 OMX_PRDSP4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500292 eError = OMX_ErrorBadParameter;
293 goto ERROR;
294 }
295
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700296 status = DSPManager_RegisterObject((struct DSP_UUID *)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].uuid,
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500297 phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType, abs_dsp_path);
298
299 DSP_ERROR_EXIT (status, "Register Component Library", ERROR);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700300 }
301
302 /* NODE specific data */
303 NodeAttrIn.cbStruct = sizeof(struct DSP_NODEATTRIN);
304 NodeAttrIn.iPriority = phandle->dspCodec->Priority;
305 NodeAttrIn.uTimeout = phandle->dspCodec->Timeout;
James Dongb65f2532010-02-04 11:00:34 -0800306 NodeAttrIn.uTimeout = 1000; /* WORKAROUND */
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700307 NodeAttrIn.uProfileID= phandle->dspCodec->ProfileID;
308 /* Prepare Create Phase Argument */
James Dongb65f2532010-02-04 11:00:34 -0800309 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Prepare Create Phase Argument \n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700310 /* TO DO check is application setting it properly */
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500311 i = 0;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700312 if(phandle->dspCodec->pCrPhArgs !=NULL)
313 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500314 while((phandle->dspCodec->pCrPhArgs[i] != END_OF_CR_PHASE_ARGS) && (i < LCML_DATA_SIZE))
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700315 {
James Dongb65f2532010-02-04 11:00:34 -0800316 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: copying Create Phase Argument \n", i);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700317 crData.cData[i] = phandle->dspCodec->pCrPhArgs[i];
James Dongb65f2532010-02-04 11:00:34 -0800318 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: CR PH arg[%d] = %d \n",__LINE__, i, crData.cData[i]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700319 i++;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700320 }
321 }
322 else
323 {
James Dongb65f2532010-02-04 11:00:34 -0800324 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL CREATEPHASE SET IT ..\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700325 eError = OMX_ErrorBadParameter;
326 goto ERROR;
327 }
328
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500329 if (i >= LCML_DATA_SIZE)
330 {
James Dongb65f2532010-02-04 11:00:34 -0800331 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__);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500333 eError = OMX_ErrorBadParameter;
334 goto ERROR;
335 }
336
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700337 /* LCML_DPRINT("Create Phase args strlen = %d\n",strlen(crData.cData)); */
338 /* crData.cbData = sizeof (ULONG) + strlen(crData.cData); */
339 crData.cbData = i*2;
James Dongb65f2532010-02-04 11:00:34 -0800340 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Create Phase args strlen = %ld\n", crData.cbData);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700341
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);
James Dongb65f2532010-02-04 11:00:34 -0800347 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Allocate Successfully\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700348
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 */
James Dongb65f2532010-02-04 11:00:34 -0800354 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "[LCML] - struct DSP_CBDATA.cbData (length): %d %s\n", (int)pArgs->cbData, (char *)pArgs->cData);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700355
356 if (phandle->dspCodec->DeviceInfo.TypeofDevice == 1)
357 {
James Dongb65f2532010-02-04 11:00:34 -0800358 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Audio Device Selected\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700359 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
James Dongb65f2532010-02-04 11:00:34 -0800367 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700368 if(phandle->dspCodec->DeviceInfo.DspStream != NULL)
369 {
370 if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
371 {
372 /* render for playback */
James Dongb65f2532010-02-04 11:00:34 -0800373 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for playback\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700374 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 */
James Dongb65f2532010-02-04 11:00:34 -0800385 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for record\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700386 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 {
James Dongb65f2532010-02-04 11:00:34 -0800397 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL STREAM PARAMETER SET IT ..\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700398 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);
James Dongb65f2532010-02-04 11:00:34 -0800405 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: After DSPNode_Create !!! \n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700406
407 status = DSPNode_Run(phandle->dspCodec->hNode);
408 DSP_ERROR_EXIT (status, "Goto RUN mode", ERROR);
James Dongb65f2532010-02-04 11:00:34 -0800409 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Run Successfully\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700410
411 if ((phandle->dspCodec->In_BufInfo.DataTrMethod == DMM_METHOD) || (phandle->dspCodec->Out_BufInfo.DataTrMethod == DMM_METHOD))
412 {
413 struct DSP_NOTIFICATION* notification;
James Dongb65f2532010-02-04 11:00:34 -0800414 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700415
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500416 LCML_MALLOC(notification,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION)
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700417 if(notification == NULL)
418 {
James Dongb65f2532010-02-04 11:00:34 -0800419 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700420 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;
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500427#ifdef __ERROR_PROPAGATION__
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700428 struct DSP_NOTIFICATION* notification_mmufault;
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500429
James Dongb65f2532010-02-04 11:00:34 -0800430 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700431
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500432 LCML_MALLOC(notification_mmufault,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700433 if(notification_mmufault == NULL)
434 {
James Dongb65f2532010-02-04 11:00:34 -0800435 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700436 goto ERROR;
437 }
438 memset(notification_mmufault,0,sizeof(struct DSP_NOTIFICATION));
James Dongb65f2532010-02-04 11:00:34 -0800439
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700440 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;
James Dongb65f2532010-02-04 11:00:34 -0800443
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700444 struct DSP_NOTIFICATION* notification_syserror ;
James Dongb65f2532010-02-04 11:00:34 -0800445
446 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700447
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500448 LCML_MALLOC(notification_syserror,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700449 if(notification_syserror == NULL)
450 {
James Dongb65f2532010-02-04 11:00:34 -0800451 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700452 goto ERROR;
453 }
454 memset(notification_syserror,0,sizeof(struct DSP_NOTIFICATION));
James Dongb65f2532010-02-04 11:00:34 -0800455
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700456 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;
James Dongb65f2532010-02-04 11:00:34 -0800459#endif
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700460 }
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);
Andreas Huber5807caa2010-03-12 14:20:45 -0800470
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700471 if (tmperr || !phandle->g_tidMessageThread)
472 {
James Dongb65f2532010-02-04 11:00:34 -0800473 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Thread creation failed: 0x%x",tmperr);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700474 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;
James Dongb65f2532010-02-04 11:00:34 -0800486
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700487 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
502ERROR:
503#ifndef CEXEC_DONE
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500504 LCML_FREE(argv);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700505#endif
James Dongb65f2532010-02-04 11:00:34 -0800506 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Exiting Init_DSPSubSystem\n error = %x\n", __LINE__, eError);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700507 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* ==========================================================================*/
524static 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;
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500535 char argv[ABS_DLL_NAME_LENGTH];
536 k = append_dsp_path(DSP_DOF_IMAGE, argv);
537 if (k < 0)
538 {
James Dongb65f2532010-02-04 11:00:34 -0800539 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500540 eError = OMX_ErrorBadParameter;
541 goto ERROR;
542 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700543#endif
544 LCML_CREATEPHASEARGS crData;
545 DSP_STATUS status;
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500546 int i = 0, k =0;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700547 struct DSP_NODEATTRIN NodeAttrIn;
548 int tmperr;
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500549 char abs_dsp_path[ABS_DLL_NAME_LENGTH];
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700550
James Dongb65f2532010-02-04 11:00:34 -0800551 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: InitMMCodec application\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700552
James Dongc22b4b52009-09-28 13:27:45 -0700553 if (hInt == NULL )
554 {
555 eError = OMX_ErrorInsufficientResources;
556 goto ERROR;
557 }
558
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700559 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
James Dongb65f2532010-02-04 11:00:34 -0800570 /* 720p implementation */
571 {
572 pthread_mutex_init(&phandle->m_isStopped_mutex, NULL);
573 phandle->mapped_buffer_count = 0;
574 }
575
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700576 /* 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 */
James Dongb65f2532010-02-04 11:00:34 -0800588 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Entering Init_DSPSubSystem\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700589 status = DspManager_Open(0, NULL);
590 DSP_ERROR_EXIT(status, "DSP Manager Open", ERROR);
James Dongb65f2532010-02-04 11:00:34 -0800591 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DspManager_Open Successful\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700592
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);
James Dongb65f2532010-02-04 11:00:34 -0800596 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");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700598
599 for(dllinfo=0; dllinfo < phandle->dspCodec->NodeInfo.nNumOfDLLs; dllinfo++)
600 {
James Dongb65f2532010-02-04 11:00:34 -0800601 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Register Component Node\n",phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500602
603 k = append_dsp_path((char*)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].DllName, abs_dsp_path);
604 if (k < 0)
605 {
James Dongb65f2532010-02-04 11:00:34 -0800606 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500607 eError = OMX_ErrorBadParameter;
608 goto ERROR;
609 }
610
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700611 status = DSPManager_RegisterObject((struct DSP_UUID *)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].uuid,
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500612 phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType,
613 abs_dsp_path);
614
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700615 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
James Dongb65f2532010-02-04 11:00:34 -0800627 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Prepare Create Phase Argument \n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700628 /* TO DO check is application setting it properly */
629 if(phandle->dspCodec->pCrPhArgs !=NULL)
630 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500631 while((phandle->dspCodec->pCrPhArgs[i] != END_OF_CR_PHASE_ARGS) && (i < LCML_DATA_SIZE))
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700632 {
James Dongb65f2532010-02-04 11:00:34 -0800633 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: copying Create Phase Argument \n",i);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700634 crData.cData[i] =phandle->dspCodec->pCrPhArgs[i];
James Dongb65f2532010-02-04 11:00:34 -0800635 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: CR PH arg[%d] = %d \n",__LINE__,i,crData.cData[i]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700636 i++;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700637 }
638 }
639 else
640 {
James Dongb65f2532010-02-04 11:00:34 -0800641 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL CREATEPHASE SET IT ..\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700642 eError = OMX_ErrorBadParameter;
643 goto ERROR;
644 }
645
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500646 if (i >= LCML_DATA_SIZE)
647 {
James Dongb65f2532010-02-04 11:00:34 -0800648 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__);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500650 eError = OMX_ErrorBadParameter;
651 goto ERROR;
652 }
653
654
James Dongb65f2532010-02-04 11:00:34 -0800655 /* LCML_DPRINT ("Create Phase args strlen = %d\n",strlen(crData.cData)); */
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700656 /* crData.cbData = sizeof (ULONG) + strlen(crData.cData); */
657 crData.cbData = i * 2;
James Dongb65f2532010-02-04 11:00:34 -0800658 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Create Phase args strlen = %ld\n", crData.cbData);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700659
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);
James Dongb65f2532010-02-04 11:00:34 -0800665 OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Allocate Successfully\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700666
667 if(phandle->dspCodec->DeviceInfo.TypeofDevice == 1)
668 {
James Dongb65f2532010-02-04 11:00:34 -0800669 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Audio Device Selected\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700670 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
James Dongb65f2532010-02-04 11:00:34 -0800677 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700678 if(phandle->dspCodec->DeviceInfo.DspStream !=NULL)
679 {
680 if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
681 {
682 /* render for playback */
James Dongb65f2532010-02-04 11:00:34 -0800683 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for playback\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700684 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 */
James Dongb65f2532010-02-04 11:00:34 -0800694 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for record\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700695 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 {
James Dongb65f2532010-02-04 11:00:34 -0800705 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL STREAM PARAMETER SET IT ..\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700706 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);
James Dongb65f2532010-02-04 11:00:34 -0800713 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: After DSPNode_Create !!! \n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700714
715 status = DSPNode_Run (phandle->dspCodec->hNode);
716 DSP_ERROR_EXIT (status, "Goto RUN mode", ERROR);
James Dongb65f2532010-02-04 11:00:34 -0800717 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Run Successfully\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700718
719 if ((phandle->dspCodec->In_BufInfo.DataTrMethod == DMM_METHOD) ||
720 (phandle->dspCodec->Out_BufInfo.DataTrMethod == DMM_METHOD))
721 {
722 struct DSP_NOTIFICATION* notification;
James Dongb65f2532010-02-04 11:00:34 -0800723 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700724
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500725 LCML_MALLOC(notification,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700726 if(notification == NULL)
727 {
James Dongb65f2532010-02-04 11:00:34 -0800728 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700729 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;
James Dongb65f2532010-02-04 11:00:34 -0800736#ifdef __ERROR_PROPAGATION__
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700737 struct DSP_NOTIFICATION* notification_mmufault;
James Dongb65f2532010-02-04 11:00:34 -0800738
739 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700740
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500741 LCML_MALLOC(notification_mmufault,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700742 if(notification_mmufault == NULL)
743 {
James Dongb65f2532010-02-04 11:00:34 -0800744 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700745 goto ERROR;
746 }
747 memset(notification_mmufault,0,sizeof(struct DSP_NOTIFICATION));
James Dongb65f2532010-02-04 11:00:34 -0800748
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700749 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;
James Dongb65f2532010-02-04 11:00:34 -0800752
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700753 struct DSP_NOTIFICATION* notification_syserror ;
James Dongb65f2532010-02-04 11:00:34 -0800754
755 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700756
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500757 LCML_MALLOC(notification_syserror,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700758 if(notification_syserror == NULL)
759 {
James Dongb65f2532010-02-04 11:00:34 -0800760 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700761 goto ERROR;
762 }
763 memset(notification_syserror,0,sizeof(struct DSP_NOTIFICATION));
James Dongb65f2532010-02-04 11:00:34 -0800764
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700765 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;
James Dongb65f2532010-02-04 11:00:34 -0800768#endif
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700769 }
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);
Andreas Huber5807caa2010-03-12 14:20:45 -0800779
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700780 if(tmperr || !phandle->g_tidMessageThread)
781 {
James Dongb65f2532010-02-04 11:00:34 -0800782 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Thread creation failed: 0x%x",tmperr);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700783 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;
James Dongb65f2532010-02-04 11:00:34 -0800795
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700796 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
Rebecca Schultz Zavinb44cdb12009-07-29 17:23:50 -0700810
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700811ERROR:
812#ifndef CEXEC_DONE
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500813 LCML_FREE(argv);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700814#endif
James Dongb65f2532010-02-04 11:00:34 -0800815 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Exiting Init_DSPSubSystem\n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700816 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** ==========================================================================*/
833static OMX_ERRORTYPE WaitForEvent(OMX_HANDLETYPE hComponent,
834 TUsnCodecEvent event,
835 void * args[10] )
836{
837 OMX_ERRORTYPE eError = OMX_ErrorUndefined;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700838 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* ==========================================================================*/
858static 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;
James Dongb65f2532010-02-04 11:00:34 -0800865 OMX_U32 streamId = 0;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700866 DSP_STATUS status;
867 OMX_ERRORTYPE eError = OMX_ErrorNone;
Anu Sundararajan75763072009-10-08 22:21:48 -0500868 char * tmp2=NULL;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700869 DMM_BUFFER_OBJ* pDmmBuf=NULL;
870 int commandId;
871 struct DSP_MSG msg;
Rebecca Schultz Zavinb44cdb12009-07-29 17:23:50 -0700872 OMX_U32 MapBufLen=0;
James Dongb65f2532010-02-04 11:00:34 -0800873 OMX_BOOL mappedBufferFound = false;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700874
James Dongb65f2532010-02-04 11:00:34 -0800875 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: QueueBuffer application\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700876
James Dongb65f2532010-02-04 11:00:34 -0800877 if (hComponent == NULL )
James Dongc22b4b52009-09-28 13:27:45 -0700878 {
879 eError = OMX_ErrorInsufficientResources;
James Dongb65f2532010-02-04 11:00:34 -0800880 goto EXIT;
James Dongc22b4b52009-09-28 13:27:45 -0700881 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700882
883 phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)hComponent)->pCodec);
884
James Dongb65f2532010-02-04 11:00:34 -0800885 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "LCML QueueBuffer: phandle->iBufinputcount is %lu (%p) \n", phandle->iBufinputcount, phandle);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700886
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);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500895 LCML_MALLOC(tmp2,sizeof(TArmDspCommunicationStruct) + 256,char);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700896 if (tmp2 == NULL)
897 {
898 eError = OMX_ErrorInsufficientResources;
James Dongb65f2532010-02-04 11:00:34 -0800899 goto MUTEX_UNLOCK;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700900 }
Anu Sundararajan69ee5a12009-09-27 09:17:41 -0500901 memset(tmp2,0,sizeof(TArmDspCommunicationStruct)+256);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700902 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 }
James Dongb65f2532010-02-04 11:00:34 -0800916 else {
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700917 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;
James Dongb65f2532010-02-04 11:00:34 -0800924 switch (bufType)
Rebecca Schultz Zavinb44cdb12009-07-29 17:23:50 -0700925 {
James Dongb65f2532010-02-04 11:00:34 -0800926 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;
Rebecca Schultz Zavinb44cdb12009-07-29 17:23:50 -0700944 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700945
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;
James Dongb65f2532010-02-04 11:00:34 -0800960 OMX_PRBUFFER1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "VPP port %lu use InDmmBuffer (%lu) %p\n", streamId, phandle->iBufinputcount, pDmmBuf);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700961
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 {
James Dongb65f2532010-02-04 11:00:34 -0800973 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Unrecognized buffer type..");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700974 eError = OMX_ErrorBadParameter;
Anu Sundararajan75763072009-10-08 22:21:48 -0500975 if(tmp2)
976 {
977 free(tmp2);
978 phandle->commStruct = NULL;
979 }
James Dongb65f2532010-02-04 11:00:34 -0800980 goto MUTEX_UNLOCK;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700981 }
982 commandId = USN_GPPMSG_SET_BUFF|streamId;
James Dongb65f2532010-02-04 11:00:34 -0800983 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending command ID 0x%x",commandId);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700984 if( pDmmBuf == NULL)
985 {
986 eError = OMX_ErrorInsufficientResources;
James Dongb65f2532010-02-04 11:00:34 -0800987 goto MUTEX_UNLOCK;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700988 }
James Dongb65f2532010-02-04 11:00:34 -0800989 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "buffer = 0x%p bufferlen = %ld auxInfo = 0x%p auxInfoLen %ld\n",
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700990 buffer, bufferLen, auxInfo, auxInfoLen );
991
992 phandle->commStruct->iArmbufferArg = (OMX_U32)buffer;
993 if ((buffer != NULL) && (bufferLen != 0))
994 {
James Dongb65f2532010-02-04 11:00:34 -0800995 OMX_U32 i;
996 DSP_STATUS status;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700997
James Dongb65f2532010-02-04 11:00:34 -0800998 if (phandle->ReUseMap)
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -0700999 {
James Dongb65f2532010-02-04 11:00:34 -08001000 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;
James Dongeaaadaf2010-02-01 17:29:02 -08001098 }
James Dong36733d62010-01-28 13:53:05 -08001099
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001100 }
1101
1102 if (auxInfoLen != 0 && auxInfo != NULL )
1103 {
James Dongb65f2532010-02-04 11:00:34 -08001104 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001106 if (eError != OMX_ErrorNone)
1107 {
James Dongb65f2532010-02-04 11:00:34 -08001108 goto MUTEX_UNLOCK;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001109 }
1110
1111 phandle->commStruct->iParamPtr = (OMX_U32 )pDmmBuf->pMapped ;
1112 /* storing reserve address for param */
1113 pDmmBuf->paramReserved = pDmmBuf->pReserved;
1114 }
1115
James Dongb65f2532010-02-04 11:00:34 -08001116 eError = DmmMap(phandle->dspCodec->hProc, sizeof(TArmDspCommunicationStruct),(void *)phandle->commStruct, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001117 if (eError != OMX_ErrorNone)
1118 {
James Dongb65f2532010-02-04 11:00:34 -08001119 goto MUTEX_UNLOCK;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001120 }
James Dongb65f2532010-02-04 11:00:34 -08001121
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001122 /* storing mapped address of struct */
1123 phandle->commStruct->iArmArg = (OMX_U32)pDmmBuf->pMapped;
James Dongb65f2532010-02-04 11:00:34 -08001124
1125 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "sending SETBUFF \n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001126 msg.dwCmd = commandId;
1127 msg.dwArg1 = (int)pDmmBuf->pMapped;
1128 msg.dwArg2 = 0;
1129
1130 status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
James Dongb65f2532010-02-04 11:00:34 -08001131 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "after SETBUFF \n");
1132 DSP_ERROR_EXIT (status, "Send message to node", MUTEX_UNLOCK);
1133MUTEX_UNLOCK:
James Dongeaaadaf2010-02-01 17:29:02 -08001134 pthread_mutex_unlock(&phandle->mutex);
James Dongb65f2532010-02-04 11:00:34 -08001135EXIT:
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001136 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** ==========================================================================*/
1153static 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
James Dongb65f2532010-02-04 11:00:34 -08001161 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: ControlCodec application\n",__LINE__);
James Dongc22b4b52009-09-28 13:27:45 -07001162 if (hComponent == NULL )
1163 {
1164 eError= OMX_ErrorInsufficientResources;
James Dongb65f2532010-02-04 11:00:34 -08001165 goto EXIT;
James Dongc22b4b52009-09-28 13:27:45 -07001166 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001167 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};
James Dongb65f2532010-02-04 11:00:34 -08001180 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending PAUSE command");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001181#ifdef __PERF_INSTRUMENTATION__
1182 PERF_SendingCommand(phandle->pPERF,
1183 msg.dwCmd,
1184 msg.dwArg1,
James Dongb65f2532010-02-04 11:00:34 -08001185 PERF_ModuleSocketNode);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001186#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};
James Dongb65f2532010-02-04 11:00:34 -08001194 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending PLAY --1 command");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001195#ifdef __PERF_INSTRUMENTATION__
1196 PERF_SendingCommand(phandle->pPERF,
1197 msg.dwCmd,
1198 msg.dwArg1,
James Dongb65f2532010-02-04 11:00:34 -08001199 PERF_ModuleSocketNode);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001200#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};
James Dongb65f2532010-02-04 11:00:34 -08001208 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending STOP command\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001209#ifdef __PERF_INSTRUMENTATION__
1210 PERF_SendingCommand(phandle->pPERF,
1211 msg.dwCmd,
1212 msg.dwArg1,
James Dongb65f2532010-02-04 11:00:34 -08001213 PERF_ModuleSocketNode);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001214#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;
James Dongb65f2532010-02-04 11:00:34 -08001222 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Destroy the codec");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001223#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;
James Dongb65f2532010-02-04 11:00:34 -08001234 OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: Error while closing Component Thread\n", pthreadError);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001235 }
James Dongb65f2532010-02-04 11:00:34 -08001236 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
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001270 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]};
James Dongb65f2532010-02-04 11:00:34 -08001291 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "message to codec");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001292#ifdef __PERF_INSTRUMENTATION__
1293 PERF_SendingCommand(phandle->pPERF,
1294 msg.dwCmd,
1295 msg.dwArg1,
James Dongb65f2532010-02-04 11:00:34 -08001296 PERF_ModuleSocketNode);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001297#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;
Anu Sundararajan75763072009-10-08 22:21:48 -05001306 pthread_mutex_lock(&phandle->mutex);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001307 for (i = 0; i < QUEUE_SIZE; i++)
1308 {
1309 /* searching for empty slot */
1310 if (phandle->pAlgcntlDmmBuf[i] == NULL)
1311 break;
1312 }
James Dongb65f2532010-02-04 11:00:34 -08001313 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;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001340#ifdef __PERF_INSTRUMENTATION__
James Dongb65f2532010-02-04 11:00:34 -08001341 PERF_SendingCommand(phandle->pPERF,
1342 msg.dwCmd,
1343 msg.dwArg1,
1344 PERF_ModuleSocketNode);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001345#endif
James Dongb65f2532010-02-04 11:00:34 -08001346 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001351 case EMMCodecControlStrmCtrl:
1352 {
1353 struct DSP_MSG msg;
James Dongeaaadaf2010-02-01 17:29:02 -08001354
James Dongb65f2532010-02-04 11:00:34 -08001355 pthread_mutex_lock(&phandle->mutex);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001356 if ((int)args[0] == USN_STRMCMD_FLUSH) {
James Dongb65f2532010-02-04 11:00:34 -08001357 msg.dwCmd = USN_GPPMSG_STRMCTRL | (int)args[1];
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001358 msg.dwArg1 = USN_STRMCMD_FLUSH;
1359 msg.dwArg2 = 0;
1360 phandle->flush_pending[(int)args[1]]= 1;
James Dongb65f2532010-02-04 11:00:34 -08001361#ifdef __PERF_INSTRUMENTATION__
1362 PERF_SendingCommand(phandle->pPERF,
1363 msg.dwCmd,
1364 msg.dwArg1,
1365 PERF_ModuleSocketNode);
1366#endif
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001367 }
James Dongb65f2532010-02-04 11:00:34 -08001368 else
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001369 {
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 }
James Dongb65f2532010-02-04 11:00:34 -08001377 if(i >= QUEUE_SIZE)
1378 {
1379 eError=OMX_ErrorUndefined;
1380 pthread_mutex_unlock(&phandle->mutex);
1381 goto EXIT;
1382 }
Anu Sundararajan75763072009-10-08 22:21:48 -05001383
James Dongb65f2532010-02-04 11:00:34 -08001384 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001415 }
1416#ifdef __PERF_INSTRUMENTATION__
James Dongb65f2532010-02-04 11:00:34 -08001417 PERF_SendingCommand(phandle->pPERF,
1418 msg.dwCmd,
1419 msg.dwArg1,
1420 PERF_ModuleSocketNode);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001421#endif
1422 status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
Anu Sundararajan75763072009-10-08 22:21:48 -05001423 pthread_mutex_unlock(&phandle->mutex);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001424 DSP_ERROR_EXIT (status, "Send message to node", EXIT);
1425
James Dongb65f2532010-02-04 11:00:34 -08001426 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]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001429 break;
1430 }
1431 case EMMCodecControlUsnEos:
1432 {
1433 phandle->bUsnEos = OMX_TRUE;
1434 break;
1435 }
James Dongb65f2532010-02-04 11:00:34 -08001436
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001437 }
1438
1439EXIT:
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** ==========================================================================*/
1455OMX_ERRORTYPE DmmMap(DSP_HPROCESSOR ProcHandle,
1456 OMX_U32 size,
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001457 void* pArmPtr,
James Dongb65f2532010-02-04 11:00:34 -08001458 DMM_BUFFER_OBJ* pDmmBuf,
1459 struct OMX_TI_Debug dbg)
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001460{
1461 OMX_ERRORTYPE eError = OMX_ErrorUndefined;
1462 DSP_STATUS status;
1463 int nSizeReserved = 0;
1464
1465 if(pDmmBuf == NULL)
1466 {
James Dongb65f2532010-02-04 11:00:34 -08001467 OMX_ERROR4 (dbg, "pBuf is NULL\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001468 eError = OMX_ErrorBadParameter;
1469 goto EXIT;
1470 }
1471
1472 if(pArmPtr == NULL)
1473 {
James Dongb65f2532010-02-04 11:00:34 -08001474 OMX_ERROR4 (dbg, "pBuf is NULL\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001475 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 {
James Dongb65f2532010-02-04 11:00:34 -08001487 OMX_ERROR4 (dbg, "DSPProcessor_ReserveMemory() failed - error 0x%x", (int)status);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001488 eError = OMX_ErrorInsufficientResources;
1489 goto EXIT;
1490 }
1491 pDmmBuf->nSize = size;
1492
James Dongb65f2532010-02-04 11:00:34 -08001493
1494 OMX_PRBUFFER2 (dbg, " DMM MAP Reserved: %p (for buf %p), size 0x%x (%d)", pDmmBuf->pReserved, pArmPtr, nSizeReserved,nSizeReserved);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001495
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 {
James Dongb65f2532010-02-04 11:00:34 -08001505 OMX_ERROR4 (dbg, "DSPProcessor_Map() failed - error 0x%x", (int)status);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001506 eError = OMX_ErrorInsufficientResources;
1507 goto EXIT;
1508 }
James Dongb65f2532010-02-04 11:00:34 -08001509 OMX_PRBUFFER1 (dbg, "DMM Mapped: %p, size 0x%lx (%ld)",pDmmBuf->pMapped, size,size);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001510
Rebecca Schultz Zavinb44cdb12009-07-29 17:23:50 -07001511 /* Previously we used to Flush or Invalidate the mapped buffer. This was
1512 * removed due to bridge is now handling the flush/invalidate operation */
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001513 eError = OMX_ErrorNone;
1514
1515EXIT:
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** ==========================================================================*/
James Dongb65f2532010-02-04 11:00:34 -08001530OMX_ERRORTYPE DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg )
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001531{
1532 DSP_STATUS status = DSP_SOK;
1533 OMX_ERRORTYPE eError = OMX_ErrorNone;
1534
1535 if(pMapPtr == NULL)
1536 {
James Dongb65f2532010-02-04 11:00:34 -08001537 OMX_ERROR4 (dbg, "pMapPtr is NULL\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001538 eError = OMX_ErrorBadParameter;
1539 goto EXIT;
1540 }
1541 if(pResPtr == NULL)
1542 {
James Dongb65f2532010-02-04 11:00:34 -08001543 OMX_ERROR4 (dbg, "pResPtr is NULL\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001544 eError = OMX_ErrorBadParameter;
1545 goto EXIT;
1546 }
1547 status = DSPProcessor_UnMap(ProcHandle,pMapPtr);
1548 if(DSP_FAILED(status))
1549 {
James Dongb65f2532010-02-04 11:00:34 -08001550 OMX_PRDSP4 (dbg, "DSPProcessor_UnMap() failed - error 0x%x",(int)status);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001551 }
1552
James Dongb65f2532010-02-04 11:00:34 -08001553 OMX_PRINT2 (dbg, "unreserving structure =0x%p\n",pResPtr );
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001554 status = DSPProcessor_UnReserveMemory(ProcHandle,pResPtr);
1555 if(DSP_FAILED(status))
1556 {
James Dongb65f2532010-02-04 11:00:34 -08001557 OMX_PRDSP4 (dbg, "DSPProcessor_UnReserveMemory() failed - error 0x%x", (int)status);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001558 }
1559
1560EXIT:
1561 return eError;
1562}
1563
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001564/** ========================================================================
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** ==========================================================================*/
1572OMX_ERRORTYPE FreeResources (LCML_DSP_INTERFACE *hInterface)
1573{
1574 OMX_ERRORTYPE eError = OMX_ErrorNone;
1575 LCML_DSP_INTERFACE *codec;
1576
James Dongb65f2532010-02-04 11:00:34 -08001577 OMX_PRINT1 ((struct OMX_TI_Debug)(((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg), "%d :: LCML:: FreeResources\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001578 if(hInterface->dspCodec != NULL)
1579 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05001580 LCML_FREE(hInterface->dspCodec);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001581 hInterface->dspCodec = NULL;
1582 }
1583 codec = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle)->pCodec);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001584 if(codec != NULL)
1585 {
James Dongb65f2532010-02-04 11:00:34 -08001586 pthread_mutex_destroy(&codec->m_isStopped_mutex);
Anu Sundararajan75763072009-10-08 22:21:48 -05001587 pthread_mutex_lock(&codec->mutex);
James Dongb65f2532010-02-04 11:00:34 -08001588
1589 OMX_PRINT1 ((struct OMX_TI_Debug)(((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg), "%d :: LCML:: FreeResources\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001590 if(codec->g_aNotificationObjects[0]!= NULL)
1591 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05001592 LCML_FREE(codec->g_aNotificationObjects[0]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001593 codec->g_aNotificationObjects[0] = NULL;
1594#ifdef __ERROR_PROPAGATION__
1595 if(codec->g_aNotificationObjects[1]!= NULL)
1596 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05001597 LCML_FREE(codec->g_aNotificationObjects[1]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001598 codec->g_aNotificationObjects[1] = NULL;
1599 }
1600 if(codec->g_aNotificationObjects[2]!= NULL)
1601 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05001602 LCML_FREE(codec->g_aNotificationObjects[2]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001603 codec->g_aNotificationObjects[2] = NULL;
1604 }
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05001605 #endif
James Dongb65f2532010-02-04 11:00:34 -08001606 OMX_DBG_CLOSE((struct OMX_TI_Debug )(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle)->dbg));
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05001607 LCML_FREE(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle));
Rebecca Schultz Zavinb44cdb12009-07-29 17:23:50 -07001608 hInterface->pCodecinterfacehandle = NULL;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001609 }
Anu Sundararajan75763072009-10-08 22:21:48 -05001610 pthread_mutex_unlock(&codec->mutex);
1611 pthread_mutex_destroy (&codec->mutex);
1612 LCML_FREE(codec);
1613 codec = NULL;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001614 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001615 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** ==========================================================================*/
1626OMX_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 */
James Dongb65f2532010-02-04 11:00:34 -08001636
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001637 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);
James Dongb65f2532010-02-04 11:00:34 -08001640 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: LCML:: Node Has Been Terminated --1\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001641 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 }
James Dongb65f2532010-02-04 11:00:34 -08001651#endif
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001652 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);
James Dongb65f2532010-02-04 11:00:34 -08001656 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Deleted the DASF node Successfully\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001657 }
1658 /* delete SN */
James Dongb65f2532010-02-04 11:00:34 -08001659 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__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001662
James Dongb65f2532010-02-04 11:00:34 -08001663 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Entering UnLoadDLLs \n", __LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001664 for(dllinfo=0;dllinfo < hInterface->dspCodec->NodeInfo.nNumOfDLLs ;dllinfo++)
1665 {
James Dongb65f2532010-02-04 11:00:34 -08001666 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Register Component Node\n",hInterface->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001667 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
1679EXIT:
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** ==========================================================================*/
1693void* 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;
James Dong9c3bf942010-02-05 16:30:43 -08001701
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;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001706
Andreas Huber5807caa2010-03-12 14:20:45 -08001707#ifdef ANDROID
1708 prctl(PR_SET_NAME, (unsigned long)"Messaging", 0, 0, 0);
1709#endif
1710
James Dongb65f2532010-02-04 11:00:34 -08001711 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Inside the Messaging thread\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001712#ifdef __PERF_INSTRUMENTATION__
James Dongb65f2532010-02-04 11:00:34 -08001713 ((LCML_DSP_INTERFACE *)arg)->pPERFcomp =
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001714 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
James Dongb65f2532010-02-04 11:00:34 -08001720 if (((LCML_DSP_INTERFACE *)arg)->ReUseMap)
1721 {
1722 pthread_mutex_lock(&((LCML_DSP_INTERFACE *)arg)->m_isStopped_mutex);
1723 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001724
1725 /* get message from DSP */
1726 while (1)
1727 {
1728 if (((LCML_DSP_INTERFACE *)arg)->pshutdownFlag == 1)
1729 {
James Dongb65f2532010-02-04 11:00:34 -08001730 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Breaking out of loop inmessaging thread \n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001731 break;
1732 }
1733
1734 if (threadState == EMessagingThreadCodecRunning) {
1735 waitForEventsTimeout = 10000;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001736 }
James Dongb65f2532010-02-04 11:00:34 -08001737 /* set the timeouts lower when the codec is stopped so that thread deletion response will be faster */
1738 else if (threadState == EMessagingThreadCodecStopped) {
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001739 waitForEventsTimeout = 10;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001740 }
1741
James Dongb65f2532010-02-04 11:00:34 -08001742#ifdef __ERROR_PROPAGATION__
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001743 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);
James Dongb65f2532010-02-04 11:00:34 -08001746#endif
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001747 if (DSP_SUCCEEDED(status))
1748 {
James Dongb65f2532010-02-04 11:00:34 -08001749 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT notofication FROM DSP HANDLE IT \n");
1750#ifdef __ERROR_PROPAGATION__
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001751 if (index == 0){
James Dongb65f2532010-02-04 11:00:34 -08001752#endif
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001753 /* 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 {
James Dongb65f2532010-02-04 11:00:34 -08001760 OMX_U32 streamId = (msg.dwCmd & 0x000000ff);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001761 int commandId = msg.dwCmd & 0xffffff00;
1762 TMMCodecBufferType bufType ;/* = EMMCodecScratchBuffer; */
1763 TUsnCodecEvent event = EMMCodecInternalError;
James Dongb65f2532010-02-04 11:00:34 -08001764 void * args[10] = {};
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001765 TArmDspCommunicationStruct *tmpDspStructAddress = NULL;
1766 LCML_DSP_INTERFACE *hDSPInterface = ((LCML_DSP_INTERFACE *)arg) ;
1767 DMM_BUFFER_OBJ* pDmmBuf = NULL;
1768
James Dongb65f2532010-02-04 11:00:34 -08001769 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");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001775#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 {
James Dongb65f2532010-02-04 11:00:34 -08001783 threadState = EMessagingThreadCodecRunning;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001784 #ifdef __PERF_INSTRUMENTATION__
1785 PERF_XferingBuffer(hDSPInterface->pPERFcomp,
1786 args [1],
1787 (OMX_U32) args [8],
1788 PERF_ModuleSocketNode,
1789 PERF_ModuleLLMM);
James Dongb65f2532010-02-04 11:00:34 -08001790#endif
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001791 pthread_mutex_lock(&hDSPInterface->mutex);
1792 if (!(streamId % 2))
1793 {
1794 int i = 0;
1795 int j = 0;
1796 bufType = streamId + EMMCodecStream0;
James Dongb65f2532010-02-04 11:00:34 -08001797 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));
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001801
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 {
James Dongb65f2532010-02-04 11:00:34 -08001808 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "InputBuffer loop");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001809 tmpDspStructAddress = ((LCML_DSP_INTERFACE *)arg)->Arminputstorage[i] ;
1810 hDSPInterface->Arminputstorage[i] =NULL;
1811 pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
1812 pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
James Dongb65f2532010-02-04 11:00:34 -08001813 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Address output matching index= %ld \n ",tmpDspStructAddress->BufInindex);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001814 break;
1815 }
1816 i++;
1817 i = i % QUEUE_SIZE;
James Dongb65f2532010-02-04 11:00:34 -08001818 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Message EMMCodecInputBuffer loop");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001819 }
1820 }
1821 else if (streamId % 2)
1822 {
1823 int i = 0;
1824 int j = 0;
1825 bufType = streamId + EMMCodecStream0;;
James Dongb65f2532010-02-04 11:00:34 -08001826 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));
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001828
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 {
James Dongb65f2532010-02-04 11:00:34 -08001836 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "output buffer loop");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001837 tmpDspStructAddress = hDSPInterface->Armoutputstorage[i] ;
1838 hDSPInterface ->Armoutputstorage[i] =NULL;
1839 pDmmBuf = hDSPInterface ->dspCodec->OutDmmBuffer;
1840 pDmmBuf = pDmmBuf + (tmpDspStructAddress->Bufoutindex);
James Dongb65f2532010-02-04 11:00:34 -08001841 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1842 "Address output matching index= %ld\n ",tmpDspStructAddress->Bufoutindex);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001843 break;
1844 }
1845 i++;
1846 i = i % QUEUE_SIZE;
James Dongb65f2532010-02-04 11:00:34 -08001847 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1848 "Message EMMCodecOuputBuffer loop");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001849 }
1850 }
1851
1852 if (tmpDspStructAddress != NULL)
1853 {
1854 char *tmp2 = NULL;
James Dongb65f2532010-02-04 11:00:34 -08001855
James Dong2ad89412010-04-07 12:55:43 -07001856 status = DSPProcessor_InvalidateMemory(hDSPInterface->dspCodec->hProc,
1857 tmpDspStructAddress, sizeof(TArmDspCommunicationStruct));
1858 if (DSP_FAILED(status)) {
Steve Blocka0a88cf2012-01-08 10:18:17 +00001859 ALOGE("Invalidate for communication structure failed. status = 0x%x\n", status);
James Dong2ad89412010-04-07 12:55:43 -07001860 }
James Dong08cf2e82010-03-09 16:23:46 -08001861
James Dong2ad89412010-04-07 12:55:43 -07001862 // 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)) {
Steve Blocka0a88cf2012-01-08 10:18:17 +00001868 ALOGE("Invalidate for arm parameter arguments failed. status = 0x%x\n", status);
James Dong2ad89412010-04-07 12:55:43 -07001869 }
1870 }
James Dong08cf2e82010-03-09 16:23:46 -08001871
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001872 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
James Dongb65f2532010-02-04 11:00:34 -08001889 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1890 "GOT MESSAGE EMMCodecBufferProcessed and now unmapping buffer type %p \n", args[2]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001891
1892 if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
1893 {
James Dongb65f2532010-02-04 11:00:34 -08001894 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1895 "GOT MESSAGE EMMCodecBufferProcessed and now unmapping buufer %lx\n size=%ld",
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001896 tmpDspStructAddress ->iBufferPtr, tmpDspStructAddress ->iBufferSize);
James Dongb65f2532010-02-04 11:00:34 -08001897 /* 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001904 }
1905
1906 if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
1907 {
James Dongb65f2532010-02-04 11:00:34 -08001908 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1909 "GOT MESSAGE EMMCodecBufferProcessed and now unmapping parameter buufer\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001910
1911 DmmUnMap(hDSPInterface ->dspCodec->hProc,
1912 (void*)tmpDspStructAddress->iParamPtr,
James Dongb65f2532010-02-04 11:00:34 -08001913 pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001914 }
1915
James Dongb65f2532010-02-04 11:00:34 -08001916 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001919 tmp2 = (char *)tmpDspStructAddress;
1920 tmp2 = (tmp2 - 128);
1921 if (tmp2)
1922 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05001923 LCML_FREE(tmp2);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001924 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 {
James Dongb65f2532010-02-04 11:00:34 -08001935 threadState = EMessagingThreadCodecStopped;
1936
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001937 /* Start of USN_DSPACK_STOP */
1938 int i = 0;
1939 int j = 0;
1940 int k = 0;
James Dongb65f2532010-02-04 11:00:34 -08001941 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1942 "GOT MESSAGE EMMCodecProcessingStoped \n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001943 pthread_mutex_lock(&hDSPInterface->mutex);
James Dongb65f2532010-02-04 11:00:34 -08001944 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1945 "LCMLSTOP: hDSPInterface->dspCodec->DeviceInfo.TypeofDevice %d\n", hDSPInterface->dspCodec->DeviceInfo.TypeofDevice);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001946 if (hDSPInterface->dspCodec->DeviceInfo.TypeofDevice == 0)
1947 {
1948 j = 0;
1949 hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
1950 i = hDSPInterface->iBufinputcount;
James Dongb65f2532010-02-04 11:00:34 -08001951
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001952 hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
1953 k = hDSPInterface->iBufoutputcount;
1954
1955 while(j++ < QUEUE_SIZE)
1956 {
James Dongb65f2532010-02-04 11:00:34 -08001957 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1958 "LCMLSTOP: %d hDSPInterface->Arminputstorage[i] = %p\n", i, hDSPInterface->Arminputstorage[i]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001959 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);
James Dongb65f2532010-02-04 11:00:34 -08001967 OMX_PRBUFFER1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
1968 "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001969
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;
James Dongb65f2532010-02-04 11:00:34 -08001977 args[6] = (void *) arg; /* handle */
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001978 args[7] = (void *) tmpDspStructAddress->iUsrArg; /* user arguments */
1979 /* USN updates*/
1980 args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
1981
James Dongb65f2532010-02-04 11:00:34 -08001982 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001987 if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
1988 {
James Dongb65f2532010-02-04 11:00:34 -08001989 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07001995 }
1996
1997 if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
1998 {
1999 DmmUnMap(hDSPInterface ->dspCodec->hProc,
2000 (void*)tmpDspStructAddress->iParamPtr,
James Dongb65f2532010-02-04 11:00:34 -08002001 pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002002 }
James Dongb65f2532010-02-04 11:00:34 -08002003 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002004
James Dongb65f2532010-02-04 11:00:34 -08002005 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__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002012 if (tmp2)
2013 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002014 LCML_FREE(tmp2);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002015 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 }
James Dongb65f2532010-02-04 11:00:34 -08002028
2029 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2030 "LCMLSTOP: %d hDSPInterface->Armoutputstorage[k] = %p\n", k, hDSPInterface->Armoutputstorage[k]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002031 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;
James Dongb65f2532010-02-04 11:00:34 -08002046 args[6] = (void *) arg; /* handle */
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002047 args[7] = (void *) tmpDspStructAddress->iUsrArg; /* user arguments */
2048 /* USN updates*/
2049
James Dongb65f2532010-02-04 11:00:34 -08002050 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002055 if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
2056 {
James Dongb65f2532010-02-04 11:00:34 -08002057 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002065 }
2066
2067 if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2068 {
James Dongb65f2532010-02-04 11:00:34 -08002069 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2070 "tmpDspStructAddress->iParamPtr is not NULL\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002071 DmmUnMap(hDSPInterface ->dspCodec->hProc,
2072 (void*)tmpDspStructAddress->iParamPtr,
James Dongb65f2532010-02-04 11:00:34 -08002073 pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002074 }
James Dongb65f2532010-02-04 11:00:34 -08002075 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002076
2077 tmp2 = (char *) tmpDspStructAddress;
2078 tmp2 = ( tmp2 - 128);
James Dongb65f2532010-02-04 11:00:34 -08002079 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2080 "%d :: LCML:: FreeResources\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002081 if(tmp2)
2082 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002083 LCML_FREE(tmp2);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002084 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;
James Dongb65f2532010-02-04 11:00:34 -08002109
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002110 } /* end of USN_DSPACK_STOP */
2111 else if (commandId == USN_DSPACK_PAUSE)
2112 {
James Dongb65f2532010-02-04 11:00:34 -08002113
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002114 event = EMMCodecProcessingPaused;
James Dongb65f2532010-02-04 11:00:34 -08002115 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2116 "GOT MESSAGE EMMCodecProcessingPaused \n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002117 args[6] = (void *) arg; /* handle */
2118 }
2119 else if (commandId == USN_DSPMSG_EVENT)
2120 {
James Dongb65f2532010-02-04 11:00:34 -08002121 threadState = EMessagingThreadCodecStopped;
2122
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002123 event = EMMCodecDspError;
James Dongb65f2532010-02-04 11:00:34 -08002124 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2125 "GOT MESSAGE EMMCodecDspError \n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002126 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 {
James Dongb65f2532010-02-04 11:00:34 -08002133
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002134 int i;
2135 event = EMMCodecAlgCtrlAck;
Anu Sundararajan75763072009-10-08 22:21:48 -05002136 pthread_mutex_lock(&hDSPInterface->mutex);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002137 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 {
James Dongb65f2532010-02-04 11:00:34 -08002144 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2145 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002146 LCML_FREE(pDmmBuf);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002147 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 */
James Dongb65f2532010-02-04 11:00:34 -08002155 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE USN_DSPACK_ALGCTRL \n");
Anu Sundararajan75763072009-10-08 22:21:48 -05002156 pthread_mutex_unlock(&hDSPInterface->mutex);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002157 }
2158 else if (commandId == USN_DSPACK_STRMCTRL)
2159 {
James Dongb65f2532010-02-04 11:00:34 -08002160
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002161 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 {
James Dongb65f2532010-02-04 11:00:34 -08002174 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2175 "LCMLFLUSH: %d hDSPInterface->Arminputstorage[i] = %p\n", i, hDSPInterface->Arminputstorage[i]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002176 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);
James Dongb65f2532010-02-04 11:00:34 -08002183 OMX_PRBUFFER2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2184 "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002185
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;
James Dongb65f2532010-02-04 11:00:34 -08002193 args[6] = (void *) arg;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002194 args[7] = (void *) tmpDspStructAddress->iUsrArg;
2195
2196 args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
2197
James Dongb65f2532010-02-04 11:00:34 -08002198 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
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002204 if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
2205 {
James Dongb65f2532010-02-04 11:00:34 -08002206 /* 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002214 }
2215
2216 if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2217 {
2218 DmmUnMap(hDSPInterface ->dspCodec->hProc,
2219 (void*)tmpDspStructAddress->iParamPtr,
James Dongb65f2532010-02-04 11:00:34 -08002220 pDmmBuf->paramReserved,
2221 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002222 }
James Dongb65f2532010-02-04 11:00:34 -08002223 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2224 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002225
James Dongb65f2532010-02-04 11:00:34 -08002226 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__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002233 if (tmp2)
2234 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002235 LCML_FREE(tmp2);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002236 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 {
James Dongb65f2532010-02-04 11:00:34 -08002259 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2260 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002261 LCML_FREE(pDmmBuf);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002262 pDmmBuf = NULL;
2263 ((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i] = 0;
2264 ((LCML_DSP_INTERFACE *)arg)->pStrmcntlDmmBuf[i] = NULL;
2265 break;
2266 }
2267 }
James Dongb65f2532010-02-04 11:00:34 -08002268 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002269 else if (hDSPInterface->flush_pending[1] && (streamId == 1) && (msg.dwArg1 == USN_ERR_NONE))
2270 {
2271 hDSPInterface->flush_pending[1] = 0;
James Dongb65f2532010-02-04 11:00:34 -08002272 ackType = USN_STRMCMD_FLUSH;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002273 j = 0;
2274 hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
2275 i = hDSPInterface->iBufoutputcount;
2276 while(j++ < QUEUE_SIZE)
2277 {
James Dongb65f2532010-02-04 11:00:34 -08002278 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2279 "LCMLFLUSH: %d hDSPInterface->Armoutputstorage[i] = %p\n", i, hDSPInterface->Armoutputstorage[i]);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002280 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;
James Dongb65f2532010-02-04 11:00:34 -08002295 args[6] = (void *) arg;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002296 args[7] = (void *) tmpDspStructAddress->iUsrArg;
2297
2298
James Dongb65f2532010-02-04 11:00:34 -08002299 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002304 if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
2305 {
James Dongb65f2532010-02-04 11:00:34 -08002306 /* 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002316 }
2317
2318 if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2319 {
James Dongb65f2532010-02-04 11:00:34 -08002320 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2321 "tmpDspStructAddress->iParamPtr is not NULL\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002322 DmmUnMap(hDSPInterface ->dspCodec->hProc,
2323 (void*)tmpDspStructAddress->iParamPtr,
James Dongb65f2532010-02-04 11:00:34 -08002324 pDmmBuf->paramReserved,
2325 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002326 }
James Dongb65f2532010-02-04 11:00:34 -08002327 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2328 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002329
2330 tmp2 = (char *) tmpDspStructAddress;
2331 tmp2 = ( tmp2 - 128);
James Dongb65f2532010-02-04 11:00:34 -08002332 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2333 "%d :: LCML:: FreeResources\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002334 if(tmp2)
2335 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002336 LCML_FREE(tmp2);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002337 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 {
James Dongb65f2532010-02-04 11:00:34 -08002363 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2364 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002365 LCML_FREE(pDmmBuf);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002366 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;
James Dongb65f2532010-02-04 11:00:34 -08002376 ackType = USN_STRMCMD_FLUSH;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002377 j = 0;
2378 hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
2379 i = hDSPInterface->iBufinputcount;
2380 while(j++ < QUEUE_SIZE)
2381 {
James Dongb65f2532010-02-04 11:00:34 -08002382 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002384 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);
James Dongb65f2532010-02-04 11:00:34 -08002391 OMX_PRBUFFER2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2392 "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002393
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;
James Dongb65f2532010-02-04 11:00:34 -08002401 args[6] = (void *) arg;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002402 args[7] = (void *) tmpDspStructAddress->iUsrArg;
2403
2404 args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
2405
James Dongb65f2532010-02-04 11:00:34 -08002406 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002411 if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
2412 {
James Dongb65f2532010-02-04 11:00:34 -08002413 /* 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002420 }
2421
2422 if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2423 {
2424 DmmUnMap(hDSPInterface ->dspCodec->hProc,
2425 (void*)tmpDspStructAddress->iParamPtr,
James Dongb65f2532010-02-04 11:00:34 -08002426 pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002427 }
James Dongb65f2532010-02-04 11:00:34 -08002428 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2429 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002430
2431 tmp2 = (char*)tmpDspStructAddress;
2432 tmp2 = ( tmp2 - 128);
James Dongb65f2532010-02-04 11:00:34 -08002433 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2434 "%d :: LCML:: FreeResources\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002435 if (tmp2)
2436 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002437 LCML_FREE(tmp2);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002438 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 }
James Dongb65f2532010-02-04 11:00:34 -08002454 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002455 else if (hDSPInterface->flush_pending[3] && (streamId == 3) && (msg.dwArg1 == USN_ERR_NONE))
2456 {
2457 hDSPInterface->flush_pending[1] = 0;
James Dongb65f2532010-02-04 11:00:34 -08002458 ackType = USN_STRMCMD_FLUSH;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002459 j = 0;
2460 hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
2461 i = hDSPInterface->iBufoutputcount;
2462 while(j++ < QUEUE_SIZE)
2463 {
James Dongb65f2532010-02-04 11:00:34 -08002464 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002466 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;
James Dongb65f2532010-02-04 11:00:34 -08002481 args[6] = (void *) arg;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002482 args[7] = (void *) tmpDspStructAddress->iUsrArg;
2483
2484
James Dongb65f2532010-02-04 11:00:34 -08002485 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);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002490 if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
2491 {
James Dongb65f2532010-02-04 11:00:34 -08002492 /* 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 }
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002502 }
2503
2504 if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
2505 {
James Dongb65f2532010-02-04 11:00:34 -08002506 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2507 "tmpDspStructAddress->iParamPtr is not NULL\n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002508 DmmUnMap(hDSPInterface ->dspCodec->hProc,
2509 (void*)tmpDspStructAddress->iParamPtr,
James Dongb65f2532010-02-04 11:00:34 -08002510 pDmmBuf->paramReserved,
2511 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002512 }
James Dongb65f2532010-02-04 11:00:34 -08002513 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2514 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002515
2516 tmp2 = (char *) tmpDspStructAddress;
2517 tmp2 = ( tmp2 - 128);
James Dongb65f2532010-02-04 11:00:34 -08002518 OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
2519 "%d :: LCML:: FreeResources\n",__LINE__);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002520 if(tmp2)
2521 {
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002522 LCML_FREE(tmp2);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002523 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 {
James Dongb65f2532010-02-04 11:00:34 -08002552 DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
2553 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002554 LCML_FREE(pDmmBuf);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002555 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);
James Dongb65f2532010-02-04 11:00:34 -08002563
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002564 event = EMMCodecStrmCtrlAck;
James Dongb65f2532010-02-04 11:00:34 -08002565 bufType = streamId + EMMCodecStream0;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002566 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 */
James Dongb65f2532010-02-04 11:00:34 -08002570 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE USN_DSPACK_STRMCTRL \n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002571 }
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 */
James Dongb65f2532010-02-04 11:00:34 -08002579 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE EMMCodecDspMessageRecieved \n");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002580 }
2581
2582 /* call callback */
James Dongb65f2532010-02-04 11:00:34 -08002583 OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "calling callback in application %p \n",((LCML_DSP_INTERFACE *)arg)->dspCodec);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002584#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 {
James Dongb65f2532010-02-04 11:00:34 -08002595 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "%d :: DSPManager_getmessage() failed: 0x%lx",__LINE__, status);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002596 }
2597
2598 }/* end of internal while loop*/
James Dongb65f2532010-02-04 11:00:34 -08002599#ifdef __ERROR_PROPAGATION__
2600 }/*end of if(index == 0)*/
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002601 if (index == 1){
James Dongb65f2532010-02-04 11:00:34 -08002602
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002603 struct DSP_PROCESSORSTATE procState;
2604 DSPProcessor_GetState(((LCML_DSP_INTERFACE *)arg)->dspCodec->hProc, &procState, sizeof(procState));
James Dongb65f2532010-02-04 11:00:34 -08002605
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002606 /*
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 */
James Dongb65f2532010-02-04 11:00:34 -08002613
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002614 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);
James Dongb65f2532010-02-04 11:00:34 -08002622
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002623 }
2624 if (index == 2){
James Dongb65f2532010-02-04 11:00:34 -08002625
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002626 struct DSP_PROCESSORSTATE procState;
2627 DSPProcessor_GetState(((LCML_DSP_INTERFACE *)arg)->dspCodec->hProc, &procState, sizeof(procState));
James Dongb65f2532010-02-04 11:00:34 -08002628
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002629 /*
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 */
James Dongb65f2532010-02-04 11:00:34 -08002636
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002637 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);
James Dongb65f2532010-02-04 11:00:34 -08002645
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002646 }
James Dongb65f2532010-02-04 11:00:34 -08002647#endif
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002648 } /* end of external if(DSP_SUCCEEDED(status)) */
2649 else
2650 {
James Dongb65f2532010-02-04 11:00:34 -08002651 OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "%d :: DSPManager_WaitForEvents() failed: 0x%lx",__LINE__, status);
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002652 }
2653
2654 } /* end of external while(1) loop */
2655
James Dongb65f2532010-02-04 11:00:34 -08002656 /* 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");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002662#ifdef __PERF_INSTRUMENTATION__
2663 PERF_Done(((LCML_DSP_INTERFACE *)arg)->pPERFcomp);
2664#endif
2665 return (void*)OMX_ErrorNone;
2666}
2667
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002668
2669static int append_dsp_path(char * dll64p_name, char *absDLLname)
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002670{
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002671 int len = 0;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002672 char *dsp_path = NULL;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002673 if (!(dsp_path = getenv("DSP_PATH")))
2674 {
James Dongb65f2532010-02-04 11:00:34 -08002675 OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "DSP_PATH Environment variable not set using /system/lib/dsp default");
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002676 dsp_path = "/system/lib/dsp";
2677 }
Anu Sundararajan69ee5a12009-09-27 09:17:41 -05002678 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;
Rebecca Schultz Zavinfb3766f2009-07-16 17:22:42 -07002685}