• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 #ifndef OSCLCONFIG_H_INCLUDED
19 #include "osclconfig.h"
20 #endif
21 
22 #ifndef PV_OMXDEFS_H_INCLUDED
23 #include "pv_omxdefs.h"
24 #endif
25 
26 #ifndef OMX_PROXY_INTERFACE_H_INCLUDED
27 #include "omx_proxy_interface.h"
28 #endif
29 
30 #ifndef PV_OMXCORE_H_INCLUDED
31 #include "pv_omxcore.h"
32 #endif
33 
34 #ifndef PV_THREADSAFE_MEMPOOL_H_INCLUDED
35 #include "threadsafe_mempool.h"
36 #endif
37 
38 #ifndef OSCL_ERROR_H_INCLUDED
39 #include "oscl_error.h"
40 #endif
41 
42 #if PROXY_INTERFACE
43 
44 // the messages include input and output buffer circulation and cmd msgs into omx
45 // MAX_NUMBER_OF_OMX_PROXY_MSGS must be larger than the sum of:
46 // a) total number of omx output buffers
47 // b) total number of omx input buffers
48 // c) total number of cmds that can be sent at a time to an omx component (typically 1 or 2)
49 // (50 seems enough - this has to be setup up-front before anything is negotiated)
50 #define MAX_NUMBER_OF_OMX_PROXY_MSGS 50
51 #define MAX_SIZE_OF_OMX_PROXY_MSG 256
52 
53 
54 /**********************
55 PROXY APP CLASS FUNCTIONS
56 ***********************/
57 
58 
59 //Constructor function for class ProxyApplication
ProxyApplication_OMX()60 OSCL_EXPORT_REF ProxyApplication_OMX::ProxyApplication_OMX()
61 {
62     iNumMessage = iNumNotice = 0;
63     iMemCmd = 0;
64     iNumClientMsg = 0;
65     ipProxy = NULL;
66     iProxyId = TERM_PROXY_ID;
67     iNumCreate = iNumCreateAppenders = iNumDelete = 0;
68     ReturnValueOmxApi = OMX_ErrorNone;
69 
70     iInitSemOmx.Create();
71     iMemoryPool = NULL;
72     iMemoryPool = ThreadSafeMemPoolFixedChunkAllocator::Create(MAX_NUMBER_OF_OMX_PROXY_MSGS);
73 
74     if (iMemoryPool != NULL)
75     {
76         // do a dummy ALLOC HERE TO Create mempool. Otherwise the mempool may be
77         // created in the 2nd thread and will fail to deallocate properly.
78         OsclAny *dummy = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
79         iMemoryPool->deallocate(dummy);
80     }
81 
82 }
83 
84 //Destructor function for class ProxyApplication
~ProxyApplication_OMX()85 OSCL_EXPORT_REF ProxyApplication_OMX::~ProxyApplication_OMX()
86 {
87     iInitSemOmx.Close();
88     if (iMemoryPool)
89     {
90         iMemoryPool->removeRef();
91         iMemoryPool = NULL;
92     }
93 
94 }
95 
96 /* Initialize the proxy objects & create a new thread */
Start()97 OSCL_EXPORT_REF bool ProxyApplication_OMX::Start()
98 {
99     // if the global lock is NULL, there will be no mem lock control
100     ipProxy = CPVInterfaceProxy_OMX::NewL(*this);
101 
102     if (!ipProxy)
103     {
104         return false;
105     }
106 
107     return ipProxy->StartPVThread();
108 }
109 
110 /* De-Initialize the proxy object & destroy the new thread */
Exit()111 OSCL_EXPORT_REF void ProxyApplication_OMX::Exit()
112 {
113     if (NULL == ipProxy)
114     {
115         return;
116     }
117     //this will stop proxy scheduler and thread.
118     ipProxy->Delete();
119     ipProxy = NULL;
120 }
121 
PVThreadLogon(PVMainProxy_OMX & proxy)122 void ProxyApplication_OMX::PVThreadLogon(PVMainProxy_OMX& proxy)
123 {
124     iNumCreate++;
125     iProxyId = proxy.RegisterProxiedInterface(*this, *this);
126     //ProxyIdVar = iProxyId;
127 }
128 
PVThreadLogoff(PVMainProxy_OMX & proxy)129 void ProxyApplication_OMX::PVThreadLogoff(PVMainProxy_OMX& proxy)
130 {
131     iNumDelete++;
132     proxy.UnregisterProxiedInterface(iProxyId);
133 }
134 
135 /* Unpack the message and call the appropriate OpenMAX API*/
ProcessMessage(TPVCommandId cmdid,OsclAny * cmd)136 void ProxyApplication_OMX::ProcessMessage(TPVCommandId cmdid, OsclAny* cmd)
137 {
138     iNumMessage++;
139 
140     switch (cmdid)
141     {
142         case GET_PARAMS:
143         {
144             GetParameterMsg* Command = (GetParameterMsg*) cmd;
145 
146             ReturnValueOmxApi = ComponentGetParameter(Command->hComponent, Command->nParamIndex, Command->ComponentParameterStructure);
147 
148             iMemoryPool->deallocate((OsclAny*)Command);
149 
150             //delete Command;
151             iMemCmd--;
152             iInitSemOmx.Signal();
153         }
154         break;
155 
156         case SET_PARAMS:
157         {
158             SetParameterMsg* Command = (SetParameterMsg*) cmd;
159             ReturnValueOmxApi = ComponentSetParameter(Command->hComponent, Command->nParamIndex, Command->ComponentParameterStructure);
160             iMemoryPool->deallocate((OsclAny*)Command);
161 
162             //delete Command;
163             iMemCmd--;
164             iInitSemOmx.Signal();
165         }
166         break;
167 
168         case GET_CONFIG:
169         {
170             GetConfigMsg* Command = (GetConfigMsg*) cmd;
171             ReturnValueOmxApi = ComponentGetConfig(Command->hComponent, Command->nIndex, Command->pComponentConfigStructure);
172             //delete Command;
173             iMemoryPool->deallocate((OsclAny*)Command);
174 
175             iMemCmd--;
176             iInitSemOmx.Signal();
177         }
178         break;
179 
180         case SET_CONFIG:
181         {
182             SetConfigMsg* Command = (SetConfigMsg*) cmd;
183             ReturnValueOmxApi = ComponentSetConfig(Command->hComponent, Command->nIndex, Command->pComponentConfigStructure);
184             //delete Command;
185             iMemoryPool->deallocate((OsclAny*)Command);
186 
187             iMemCmd--;
188             iInitSemOmx.Signal();
189         }
190         break;
191 
192         case GET_EXT:
193         {
194             GetExtMsg* Command = (GetExtMsg*) cmd;
195             ReturnValueOmxApi = ComponentGetExtensionIndex(Command->hComponent, Command->cParameterName, Command->pIndexType);
196             //delete Command;
197             iMemoryPool->deallocate((OsclAny*)Command);
198 
199             iMemCmd--;
200             iInitSemOmx.Signal();
201         }
202         break;
203 
204         case GET_ST:
205         {
206             GetStateMsg* Command = (GetStateMsg*) cmd;
207             ReturnValueOmxApi = ComponentGetState(Command->hComponent, Command->pState);
208             //delete Command;
209             iMemoryPool->deallocate((OsclAny*)Command);
210 
211             iMemCmd--;
212             iInitSemOmx.Signal();
213         }
214         break;
215 
216         case USE_BUF:
217         {
218             UseBufMsg* Command = (UseBufMsg*) cmd;
219             ReturnValueOmxApi = ComponentUseBuffer(Command->hComponent, Command->ppBufferHdr, Command->nPortIndex, Command->pAppPrivate, Command->nSizeBytes, Command->pBuffer);
220             //delete Command;
221             iMemoryPool->deallocate((OsclAny*)Command);
222 
223             iMemCmd--;
224             iInitSemOmx.Signal();
225         }
226         break;
227 
228         case ALLOC_BUF:
229         {
230             AllocBufMsg* Command = (AllocBufMsg*) cmd;
231             ReturnValueOmxApi = ComponentAllocateBuffer(Command->hComponent, Command->pBuffer, Command->nPortIndex, Command->pAppPrivate, Command->nSizeBytes);
232             //delete Command;
233             iMemoryPool->deallocate((OsclAny*)Command);
234 
235             iMemCmd--;
236             iInitSemOmx.Signal();
237         }
238         break;
239 
240         case FREE_BUF:
241         {
242             FreeBufMsg* Command = (FreeBufMsg*) cmd;
243             ReturnValueOmxApi = ComponentFreeBuffer(Command->hComponent, Command->nPortIndex, Command->pBuffer);
244             //delete Command;
245             iMemoryPool->deallocate((OsclAny*)Command);
246 
247             iMemCmd--;
248             iInitSemOmx.Signal();
249         }
250         break;
251 
252         case SET_CALL:
253         {
254             SetCallMsg* Command = (SetCallMsg*) cmd;
255             ReturnValueOmxApi = ComponentSetCallbacks(Command->hComponent, Command->pCallbacks, Command->pAppData);
256             //delete Command;
257             iMemoryPool->deallocate((OsclAny*)Command);
258 
259             iMemCmd--;
260             iInitSemOmx.Signal();
261         }
262         break;
263 
264         case SEND_COMM:
265         {
266             SetCommMsg* Command = (SetCommMsg*) cmd;
267             ReturnValueOmxApi = ComponentSendCommand(Command->hComponent, Command->Cmd, Command->nParam, Command->pCmdData);
268             //delete Command;
269             iMemoryPool->deallocate((OsclAny*)Command);
270 
271             iMemCmd--;
272             iInitSemOmx.Signal();
273         }
274         break;
275 
276         case EMPTY_BUF:
277         {
278             EmptyBufMsg* Command = (EmptyBufMsg*) cmd;
279             // Do not use wait/signal semaphore for queuing input/output buffers
280             // allow the client thread to keep going without having to check the status (assume its OK)
281             ReturnValueOmxApi = ComponentEmptyThisBuffer(Command->hComponent, Command->pBuffer);
282             //delete Command;
283             iMemoryPool->deallocate((OsclAny*)Command);
284 
285             iMemCmd--;
286 
287 
288         }
289         break;
290 
291         case FILL_BUF:
292         {
293             FillBufMsg* Command = (FillBufMsg*) cmd;
294             // Do not use wait/signal semaphore for queuing input/output buffers
295             // allow the client thread to keep going without having to check the status (assume its OK)
296             ReturnValueOmxApi = ComponentFillThisBuffer(Command->hComponent, Command->pBuffer);
297             //delete Command;
298             iMemoryPool->deallocate((OsclAny*)Command);
299 
300             iMemCmd--;
301 
302         }
303         break;
304 
305         case GET_HANDLE:
306         {
307             GetHandleMsg* Command = (GetHandleMsg*) cmd;
308 
309             ReturnValueOmxApi = GlobalProxyComponentGetHandle(Command->pHandle, Command->cComponentName,
310                                 Command->pAppData, Command->pCallBacks, (OMX_PTR)this);
311             //delete Command;
312             iMemoryPool->deallocate((OsclAny*)Command);
313 
314             iMemCmd--;
315             iInitSemOmx.Signal();
316         }
317         break;
318 
319         case FREE_HANDLE:
320         {
321             FreeHandleMsg* Command = (FreeHandleMsg*) cmd;
322 
323 
324             ReturnValueOmxApi = GlobalProxyComponentFreeHandle(Command->hComponent);
325             //delete Command;
326             iMemoryPool->deallocate((OsclAny*)Command);
327 
328             iMemCmd--;
329             iInitSemOmx.Signal();
330         }
331         break;
332 
333         default:
334         {
335             //printf("\n Invalid API called");
336         }
337         break;
338     }
339 }
340 
341 
CleanupMessage(OsclAny * Msg)342 void ProxyApplication_OMX::CleanupMessage(OsclAny* Msg)
343 {
344     proxyApplicationCommand* Command = (proxyApplicationCommand*) Msg;
345     //delete Command;
346     iMemoryPool->deallocate((OsclAny*)Command);
347 
348     iMemCmd--;
349 }
350 
HandleCommand(TPVProxyMsgId msgid,TPVCommandId cmdid,OsclAny * aData)351 void ProxyApplication_OMX::HandleCommand(TPVProxyMsgId msgid , TPVCommandId cmdid, OsclAny* aData)
352 {
353     OSCL_UNUSED_ARG(msgid);
354     ProcessMessage(cmdid, (OsclAny*) aData);
355 }
356 
CleanupNotification(TPVProxyMsgId,OsclAny * aData)357 void ProxyApplication_OMX::CleanupNotification(TPVProxyMsgId , OsclAny* aData)
358 {
359     OSCL_UNUSED_ARG(aData);
360     //not required in our case
361 }
362 
HandleNotification(TPVProxyMsgId,OsclAny * aData)363 void ProxyApplication_OMX::HandleNotification(TPVProxyMsgId , OsclAny* aData)
364 {
365     OSCL_UNUSED_ARG(aData);
366     //not required in our case
367 }
368 
CleanupCommand(TPVProxyMsgId,OsclAny * aData)369 void ProxyApplication_OMX::CleanupCommand(TPVProxyMsgId , OsclAny* aData)
370 {
371     CleanupMessage((OsclAny*) aData);
372 }
373 
CreateAppenders()374 void CreateAppenders()
375 {
376     // to output messages we must create an appender.  here we will
377     // use the stderr appender.
378 
379     // to prepend the time and message id to all logged messages
380     // we must add a layout object to the appender
381 
382     PVLoggerAppender* appender = new StdErrAppender<TimeAndIdLayout, 1024>();
383 
384     OsclRefCounterSA<BasicDestructDealloc> *appenderRefCounter =
385         new OsclRefCounterSA<BasicDestructDealloc>(appender);
386 
387     OsclSharedPtr<PVLoggerAppender> appenderPtr(appender, appenderRefCounter);
388 
389     // add the appender to the root node of the tree.  this
390     // will log all messages from all nodes which enable appender inheritance (default)
391 
392     PVLogger* rootnode = PVLogger::GetLoggerObject("");
393     rootnode->AddAppender(appenderPtr);
394 
395     // set the log level for the root node
396 
397     rootnode->SetLogLevel(PVLOGMSG_DEBUG);
398 
399 
400     //force the scheduler logger to be created now, so
401     //it won't mess up the heap checks by getting
402     //created later
403     PVLogger::GetLoggerObject("pvscheduler");
404     PVLogger::GetLoggerObject("pvproxy");
405 }
406 
407 
408 /**************************
409 PROXY API'S OF CLASS PROXYAPPLICATION START FROM HERE
410 THESE API'S ARE BEING CALLED FROM THE WRAPPER FUNCTIONS
411 ****************************/
412 
ProxyGetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_INOUT OMX_PTR pComponentConfigStructure)413 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyGetConfig(
414     OMX_IN  OMX_HANDLETYPE hComponent,
415     OMX_IN  OMX_INDEXTYPE nIndex,
416     OMX_INOUT OMX_PTR pComponentConfigStructure)
417 {
418     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
419 
420     if (NULL == ptr)
421     {
422         return OMX_ErrorInsufficientResources;
423     }
424 
425     GetConfigMsg* Msg = OSCL_PLACEMENT_NEW(ptr, GetConfigMsg(hComponent, nIndex, pComponentConfigStructure));
426 
427     iMemCmd++;
428     iNumClientMsg++;
429 
430     if ((ipProxy->SendCommand(iProxyId, GET_CONFIG, (OsclAny*) Msg)) == false)
431     {
432         return OMX_ErrorUndefined;
433     }
434 
435     iInitSemOmx.Wait();
436 
437     return ReturnValueOmxApi;
438 
439 }
440 
ProxySetConfig(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nIndex,OMX_IN OMX_PTR pComponentConfigStructure)441 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxySetConfig(
442     OMX_IN  OMX_HANDLETYPE hComponent,
443     OMX_IN  OMX_INDEXTYPE nIndex,
444     OMX_IN  OMX_PTR pComponentConfigStructure)
445 {
446     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
447     if (NULL == ptr)
448     {
449         return OMX_ErrorInsufficientResources;
450     }
451 
452     SetConfigMsg* Msg = OSCL_PLACEMENT_NEW(ptr, SetConfigMsg(hComponent, nIndex, pComponentConfigStructure));
453 
454 
455 
456     iMemCmd++;
457     iNumClientMsg++;
458 
459     if ((ipProxy->SendCommand(iProxyId, SET_CONFIG, (OsclAny*) Msg)) == false)
460     {
461         return OMX_ErrorUndefined;
462     }
463 
464     iInitSemOmx.Wait();
465     return ReturnValueOmxApi;
466 }
467 
ProxyGetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_STRING cParameterName,OMX_OUT OMX_INDEXTYPE * pIndexType)468 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyGetExtensionIndex(
469     OMX_IN  OMX_HANDLETYPE hComponent,
470     OMX_IN  OMX_STRING cParameterName,
471     OMX_OUT OMX_INDEXTYPE* pIndexType)
472 {
473 
474     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
475     if (NULL == ptr)
476     {
477         return OMX_ErrorInsufficientResources;
478     }
479 
480     GetExtMsg* Msg = OSCL_PLACEMENT_NEW(ptr, GetExtMsg(hComponent, cParameterName, pIndexType));
481 
482     iMemCmd++;
483     iNumClientMsg++;
484 
485     if ((ipProxy->SendCommand(iProxyId, GET_EXT, (OsclAny*) Msg)) == false)
486     {
487         return OMX_ErrorUndefined;
488     }
489 
490     iInitSemOmx.Wait();
491     return ReturnValueOmxApi;
492 }
493 
ProxyGetState(OMX_IN OMX_HANDLETYPE hComponent,OMX_OUT OMX_STATETYPE * pState)494 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyGetState(
495     OMX_IN  OMX_HANDLETYPE hComponent,
496     OMX_OUT OMX_STATETYPE* pState)
497 {
498 
499     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
500     if (NULL == ptr)
501     {
502         return OMX_ErrorInsufficientResources;
503     }
504 
505     GetStateMsg* Msg = OSCL_PLACEMENT_NEW(ptr, GetStateMsg(hComponent, pState));
506 
507 
508     iMemCmd++;
509     iNumClientMsg++;
510 
511     if ((ipProxy->SendCommand(iProxyId, GET_ST, (OsclAny*) Msg)) == false)
512     {
513         return OMX_ErrorUndefined;
514     }
515 
516     iInitSemOmx.Wait();
517     return ReturnValueOmxApi;
518 }
519 
520 
ProxyGetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_INOUT OMX_PTR ComponentParameterStructure)521 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyGetParameter(
522     OMX_IN  OMX_HANDLETYPE hComponent,
523     OMX_IN  OMX_INDEXTYPE nParamIndex,
524     OMX_INOUT OMX_PTR ComponentParameterStructure)
525 {
526     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
527     if (NULL == ptr)
528     {
529         return OMX_ErrorInsufficientResources;
530     }
531 
532     GetParameterMsg* Msg = OSCL_PLACEMENT_NEW(ptr, GetParameterMsg(hComponent, nParamIndex, ComponentParameterStructure));
533 
534 
535     iMemCmd++;
536     iNumClientMsg++;
537 
538     if ((ipProxy->SendCommand(iProxyId, GET_PARAMS, (OsclAny*) Msg)) == false)
539     {
540         return OMX_ErrorUndefined;
541     }
542 
543     iInitSemOmx.Wait();
544 
545     return ReturnValueOmxApi;
546 }
547 
548 
ProxySetParameter(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_INDEXTYPE nParamIndex,OMX_IN OMX_PTR ComponentParameterStructure)549 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxySetParameter(
550     OMX_IN  OMX_HANDLETYPE hComponent,
551     OMX_IN  OMX_INDEXTYPE nParamIndex,
552     OMX_IN  OMX_PTR ComponentParameterStructure)
553 {
554     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
555     if (NULL == ptr)
556     {
557         return OMX_ErrorInsufficientResources;
558     }
559 
560     SetParameterMsg* Msg = OSCL_PLACEMENT_NEW(ptr, SetParameterMsg(hComponent, nParamIndex, ComponentParameterStructure));
561 
562 
563 
564     iMemCmd++;
565     iNumClientMsg++;
566 
567     if ((ipProxy->SendCommand(iProxyId, SET_PARAMS, (OsclAny*) Msg)) == false)
568     {
569         return OMX_ErrorUndefined;
570     }
571 
572     iInitSemOmx.Wait();
573 
574     return ReturnValueOmxApi;
575 }
576 
577 
ProxyUseBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** ppBufferHdr,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes,OMX_IN OMX_U8 * pBuffer)578 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyUseBuffer(
579     OMX_IN OMX_HANDLETYPE hComponent,
580     OMX_INOUT OMX_BUFFERHEADERTYPE** ppBufferHdr,
581     OMX_IN OMX_U32 nPortIndex,
582     OMX_IN OMX_PTR pAppPrivate,
583     OMX_IN OMX_U32 nSizeBytes,
584     OMX_IN OMX_U8* pBuffer)
585 {
586     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
587     if (NULL == ptr)
588     {
589         return OMX_ErrorInsufficientResources;
590     }
591 
592     UseBufMsg* Msg = OSCL_PLACEMENT_NEW(ptr, UseBufMsg(hComponent, ppBufferHdr, nPortIndex, pAppPrivate, nSizeBytes, pBuffer));
593 
594 
595     iMemCmd++;
596     iNumClientMsg++;
597 
598     if ((ipProxy->SendCommand(iProxyId, USE_BUF, (OsclAny*) Msg)) == false)
599     {
600         return OMX_ErrorUndefined;
601     }
602 
603     iInitSemOmx.Wait();
604 
605     return ReturnValueOmxApi;
606 }
607 
ProxyAllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_INOUT OMX_BUFFERHEADERTYPE ** pBuffer,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_PTR pAppPrivate,OMX_IN OMX_U32 nSizeBytes)608 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyAllocateBuffer(
609     OMX_IN OMX_HANDLETYPE hComponent,
610     OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
611     OMX_IN OMX_U32 nPortIndex,
612     OMX_IN OMX_PTR pAppPrivate,
613     OMX_IN OMX_U32 nSizeBytes)
614 {
615     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
616     if (NULL == ptr)
617     {
618         return OMX_ErrorInsufficientResources;
619     }
620 
621     AllocBufMsg* Msg = OSCL_PLACEMENT_NEW(ptr, AllocBufMsg(hComponent, pBuffer, nPortIndex, pAppPrivate, nSizeBytes));
622 
623 
624     iMemCmd++;
625     iNumClientMsg++;
626 
627     if ((ipProxy->SendCommand(iProxyId, ALLOC_BUF, (OsclAny*) Msg)) == false)
628     {
629         return OMX_ErrorUndefined;
630     }
631 
632     iInitSemOmx.Wait();
633     return ReturnValueOmxApi;
634 }
635 
ProxyFreeBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_U32 nPortIndex,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)636 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyFreeBuffer(
637     OMX_IN  OMX_HANDLETYPE hComponent,
638     OMX_IN  OMX_U32 nPortIndex,
639     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
640 {
641     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
642     if (NULL == ptr)
643     {
644         return OMX_ErrorInsufficientResources;
645     }
646 
647     FreeBufMsg* Msg = OSCL_PLACEMENT_NEW(ptr, FreeBufMsg(hComponent, nPortIndex, pBuffer));
648 
649 
650     iMemCmd++;
651     iNumClientMsg++;
652 
653     if ((ipProxy->SendCommand(iProxyId, FREE_BUF, (OsclAny*) Msg)) == false)
654     {
655         return OMX_ErrorUndefined;
656     }
657 
658     iInitSemOmx.Wait();
659     return ReturnValueOmxApi;
660 }
661 
ProxySetCallbacks(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_CALLBACKTYPE * pCallbacks,OMX_IN OMX_PTR pAppData)662 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxySetCallbacks(
663     OMX_IN  OMX_HANDLETYPE hComponent,
664     OMX_IN  OMX_CALLBACKTYPE* pCallbacks,
665     OMX_IN  OMX_PTR pAppData)
666 {
667     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
668     if (NULL == ptr)
669     {
670         return OMX_ErrorInsufficientResources;
671     }
672 
673     SetCallMsg* Msg = OSCL_PLACEMENT_NEW(ptr, SetCallMsg(hComponent, pCallbacks, pAppData));
674 
675     iMemCmd++;
676     iNumClientMsg++;
677 
678     if ((ipProxy->SendCommand(iProxyId, SET_CALL, (OsclAny*) Msg)) == false)
679     {
680         return OMX_ErrorUndefined;
681     }
682 
683     iInitSemOmx.Wait();
684     return ReturnValueOmxApi;
685 }
686 
ProxySendCommand(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_COMMANDTYPE Cmd,OMX_IN OMX_U32 nParam,OMX_IN OMX_PTR pCmdData)687 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxySendCommand(
688     OMX_IN  OMX_HANDLETYPE hComponent,
689     OMX_IN  OMX_COMMANDTYPE Cmd,
690     OMX_IN  OMX_U32 nParam,
691     OMX_IN  OMX_PTR pCmdData)
692 {
693     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
694     if (NULL == ptr)
695     {
696         return OMX_ErrorInsufficientResources;
697     }
698 
699     SetCommMsg* Msg = OSCL_PLACEMENT_NEW(ptr, SetCommMsg(hComponent, Cmd, nParam, pCmdData));
700 
701     iMemCmd++;
702     iNumClientMsg++;
703 
704     if ((ipProxy->SendCommand(iProxyId, SEND_COMM, (OsclAny*) Msg)) == false)
705     {
706         return OMX_ErrorUndefined;
707     }
708     iInitSemOmx.Wait();
709 
710     return ReturnValueOmxApi;
711 }
712 
ProxyEmptyThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)713 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyEmptyThisBuffer(
714     OMX_IN  OMX_HANDLETYPE hComponent,
715     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
716 {
717     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
718     if (NULL == ptr)
719     {
720         return OMX_ErrorInsufficientResources;
721     }
722 
723     EmptyBufMsg* Msg = OSCL_PLACEMENT_NEW(ptr, EmptyBufMsg(hComponent, pBuffer));
724 
725 
726     iMemCmd++;
727     iNumClientMsg++;
728 
729     if ((ipProxy->SendCommand(iProxyId, EMPTY_BUF, (OsclAny*) Msg)) == false)
730     {
731         return OMX_ErrorUndefined;
732     }
733 
734     // Do not use wait/signal semaphore for queuing input/output buffers
735     // allow the client thread to keep going without having to wait for the status (assume its OK)
736 
737     return ReturnValueOmxApi;
738 }
739 
740 
ProxyFillThisBuffer(OMX_IN OMX_HANDLETYPE hComponent,OMX_IN OMX_BUFFERHEADERTYPE * pBuffer)741 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyFillThisBuffer(
742     OMX_IN  OMX_HANDLETYPE hComponent,
743     OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
744 {
745     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
746     if (NULL == ptr)
747     {
748         return OMX_ErrorInsufficientResources;
749     }
750 
751 
752     FillBufMsg* Msg = OSCL_PLACEMENT_NEW(ptr, FillBufMsg(hComponent, pBuffer));
753 
754     iMemCmd++;
755     iNumClientMsg++;
756 
757     if ((ipProxy->SendCommand(iProxyId, FILL_BUF, (OsclAny*) Msg)) == false)
758     {
759         return OMX_ErrorUndefined;
760     }
761 
762     // Do not use wait/signal semaphore for queuing input/output buffers
763     // allow the client thread to keep going without having to wait for the status (assume its OK)
764 
765 
766 
767     return ReturnValueOmxApi;
768 }
769 
770 
ProxyGetHandle(OMX_OUT OMX_HANDLETYPE * pHandle,OMX_IN OMX_STRING cComponentName,OMX_IN OMX_PTR pAppData,OMX_IN OMX_CALLBACKTYPE * pCallBacks)771 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyGetHandle(
772     OMX_OUT OMX_HANDLETYPE* pHandle,
773     OMX_IN  OMX_STRING cComponentName, OMX_IN  OMX_PTR pAppData,
774     OMX_IN  OMX_CALLBACKTYPE* pCallBacks)
775 {
776     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
777     if (NULL == ptr)
778     {
779         return OMX_ErrorInsufficientResources;
780     }
781 
782     GetHandleMsg* Msg = OSCL_PLACEMENT_NEW(ptr, GetHandleMsg(pHandle, cComponentName, pAppData, pCallBacks));
783 
784 
785     iMemCmd++;
786     iNumClientMsg++;
787 
788     if ((ipProxy->SendCommand(iProxyId, GET_HANDLE, (OsclAny*) Msg)) == false)
789     {
790         return OMX_ErrorUndefined;
791     }
792 
793     iInitSemOmx.Wait();
794     return ReturnValueOmxApi;
795 }
796 
797 
ProxyFreeHandle(OMX_IN OMX_HANDLETYPE hComponent)798 OSCL_EXPORT_REF OMX_ERRORTYPE ProxyApplication_OMX::ProxyFreeHandle(
799     OMX_IN OMX_HANDLETYPE hComponent)
800 {
801     OsclAny *ptr = iMemoryPool->allocate(MAX_SIZE_OF_OMX_PROXY_MSG * sizeof(uint8));
802     if (NULL == ptr)
803     {
804         return OMX_ErrorInsufficientResources;
805     }
806 
807     FreeHandleMsg* Msg = OSCL_PLACEMENT_NEW(ptr, FreeHandleMsg(hComponent));
808 
809 
810     iMemCmd++;
811     iNumClientMsg++;
812 
813     if ((ipProxy->SendCommand(iProxyId, FREE_HANDLE, (OsclAny*) Msg)) == false)
814     {
815         return OMX_ErrorUndefined;
816     }
817 
818     iInitSemOmx.Wait();
819 
820     return ReturnValueOmxApi;
821 }
822 
823 /**********************************
824 COMPONENT HANDLE FUNCTIONS
825 ***********************************/
826 
GlobalProxyComponentGetHandle(OMX_OUT OMX_HANDLETYPE * pHandle,OMX_IN OMX_STRING cComponentName,OMX_IN OMX_PTR pAppData,OMX_IN OMX_CALLBACKTYPE * pCallBacks,OMX_IN OMX_PTR pProxy)827 OSCL_EXPORT_REF OMX_ERRORTYPE OMX_APIENTRY GlobalProxyComponentGetHandle(
828     OMX_OUT OMX_HANDLETYPE* pHandle,
829     OMX_IN  OMX_STRING cComponentName,
830     OMX_IN  OMX_PTR pAppData,
831     OMX_IN  OMX_CALLBACKTYPE* pCallBacks,
832     OMX_IN  OMX_PTR pProxy)
833 {
834     OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
835     int32 error;
836     OMXGlobalData* data = (OMXGlobalData*)OsclSingletonRegistry::lockAndGetInstance(OSCL_SINGLETON_ID_OMX, error);
837     if (!data)
838     {
839         OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
840         ErrorType = OMX_ErrorInvalidState;
841         return ErrorType;
842     }
843 
844     OMX_S32 ii;
845     OMX_U8 componentFoundflag = false;
846 
847     for (ii = 0; ii < MAX_SUPPORTED_COMPONENTS; ii ++)
848     {
849         if (data->ipRegTemplateList[ii] != NULL)
850         {
851             if (!oscl_strcmp(data->ipRegTemplateList[ii]->ComponentName, cComponentName))
852             {
853                 // found a matching name
854                 // call the factory for the component
855                 OMX_STRING aOmxLibName = data->ipRegTemplateList[ii]->SharedLibraryName;
856                 OMX_PTR &aOmxLib = data->ipRegTemplateList[ii]->SharedLibraryPtr;
857                 OMX_PTR aOsclUuid = data->ipRegTemplateList[ii]->SharedLibraryOsclUuid;
858                 OMX_U32 &aRefCount = data->ipRegTemplateList[ii]->SharedLibraryRefCounter;
859                 if ((data->ipRegTemplateList[ii]->FunctionPtrCreateComponent)(pHandle, pAppData, pProxy, aOmxLibName, aOmxLib, aOsclUuid, aRefCount) == OMX_ErrorNone)
860                 {
861                     componentFoundflag = true;
862                     ((OMX_COMPONENTTYPE*)*pHandle)->SetCallbacks(*pHandle, pCallBacks, pAppData);
863                 }
864                 else
865                 {
866                     OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
867                     ErrorType = OMX_ErrorInsufficientResources;
868                     return ErrorType;
869                 }
870             }
871         }
872         else
873         {
874             break;
875         }
876     }
877 
878     // can't find the component after going through all of them
879     if (!componentFoundflag)
880     {
881         ErrorType = OMX_ErrorComponentNotFound;
882     }
883 
884     //Release the singleton.
885     OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
886     return ErrorType;
887 }
888 
GlobalProxyComponentFreeHandle(OMX_IN OMX_HANDLETYPE hComponent)889 OSCL_EXPORT_REF OMX_ERRORTYPE OMX_APIENTRY GlobalProxyComponentFreeHandle(OMX_IN OMX_HANDLETYPE hComponent)
890 {
891     //ThreadLock.Lock();
892     OMX_ERRORTYPE ErrorType = OMX_ErrorNone;
893     int32 error;
894     OMXGlobalData* data = (OMXGlobalData*)OsclSingletonRegistry::lockAndGetInstance(OSCL_SINGLETON_ID_OMX, error);
895     if (!data)
896     {
897         OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
898         ErrorType = OMX_ErrorInvalidState;
899         return ErrorType;
900     }
901 
902     OMX_HANDLETYPE* componentHandle = data->iComponentHandle;
903     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)hComponent;
904     OMX_U32 ii;
905 
906     // find the component index based on handle
907     for (ii = 0; ii < MAX_INSTANTIATED_COMPONENTS; ii++)
908     {
909         if (pHandle == componentHandle[ii])
910             break;
911     }
912     // cannot find the component handle
913     if (ii == MAX_INSTANTIATED_COMPONENTS)
914     {
915         OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
916         ErrorType = OMX_ErrorInvalidComponent;
917         return ErrorType;
918     }
919 
920     // call the component destructor through the function pointer recorder earlier
921     // using hComponent as argument
922 
923     OMX_ERRORTYPE(*destroyComp)(OMX_IN OMX_HANDLETYPE pHandle, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount);
924     // First, obtain the destructor function
925     destroyComp = data->ipInstantiatedComponentReg[ii]->FunctionPtrDestroyComponent;
926 
927     OMX_PTR &aOmxLib = data->ipInstantiatedComponentReg[ii]->SharedLibraryPtr;
928     OMX_PTR aOsclUuid = data->ipInstantiatedComponentReg[ii]->SharedLibraryOsclUuid;
929     OMX_U32 &aRefCount = data->ipInstantiatedComponentReg[ii]->SharedLibraryRefCounter;
930 
931     (*destroyComp)(pHandle, aOmxLib, aOsclUuid, aRefCount);
932 
933     data->iNumBaseInstance--;
934     //ThreadLock.Unlock();
935 
936     ErrorType = OMX_ErrorNone;
937 
938     //Release the singleton.
939     OsclSingletonRegistry::registerInstanceAndUnlock(data, OSCL_SINGLETON_ID_OMX, error);
940     return ErrorType;
941 }
942 
943 #endif // PROXY_INTERFACE
944