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