15
15
* and limitations under the License.
16
16
* -------------------------------------------------------------------
17
17
*/
18
+
19
+ #include < utils/threads.h>
20
+
18
21
#include " pv_omxdefs.h"
19
22
#include " omx_component.h"
20
23
#include " pv_omxcore.h"
26
29
#include " qc_omxcore.h"
27
30
28
31
// Number of base instances
29
- OsclMutex g_OMX_Mutex;
32
+ android::Mutex g_OMX_Mutex;
30
33
OMX_U32 g_NumMasterOMXInstances = 0 ;
31
34
void *g_Wrapper = NULL ;
32
35
void *g_MasterRegistry = NULL ;
@@ -62,7 +65,7 @@ OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_Init()
62
65
OMX_U32 index ;
63
66
OMX_U32 master_index = 0 ;
64
67
65
- g_OMX_Mutex. Lock ( );
68
+ android::Mutex::Autolock l (g_OMX_Mutex );
66
69
g_NumMasterOMXInstances++;
67
70
68
71
if (g_NumMasterOMXInstances == 1 )
@@ -72,7 +75,6 @@ OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_Init()
72
75
PV_OMX_WrapperBase **pWrapper = (PV_OMX_WrapperBase **)malloc (NUMBER_OF_OMX_CORES * sizeof (PV_OMX_WrapperBase *));
73
76
if (pWrapper == NULL )
74
77
{
75
- g_OMX_Mutex.Unlock ();
76
78
return OMX_ErrorInsufficientResources;
77
79
}
78
80
// set the global ptr to this array
@@ -81,15 +83,13 @@ OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_Init()
81
83
PVOMXMasterRegistryStruct *pOMXMasterRegistry = (PVOMXMasterRegistryStruct *)malloc (MAX_NUMBER_OF_OMX_COMPONENTS * sizeof (PVOMXMasterRegistryStruct));
82
84
if (pOMXMasterRegistry == NULL )
83
85
{
84
- g_OMX_Mutex.Unlock ();
85
86
return OMX_ErrorInsufficientResources;
86
87
}
87
88
g_MasterRegistry = (void *)pOMXMasterRegistry;
88
89
89
90
PVOMXCompHandles *pOMXCompHandles = (PVOMXCompHandles *)malloc (MAX_NUMBER_OF_OMX_COMPONENTS * sizeof (PVOMXCompHandles));
90
91
if (pOMXCompHandles == NULL )
91
92
{
92
- g_OMX_Mutex.Unlock ();
93
93
return OMX_ErrorInsufficientResources;
94
94
}
95
95
g_OMXCompHandles = (void *)pOMXCompHandles;
@@ -191,7 +191,6 @@ OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_Init()
191
191
g_TotalNumOMXComponents = master_index;
192
192
}
193
193
194
- g_OMX_Mutex.Unlock ();
195
194
return OMX_ErrorNone;
196
195
}
197
196
@@ -200,7 +199,7 @@ OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_Deinit()
200
199
OMX_U32 jj;
201
200
OMX_ERRORTYPE Status = OMX_ErrorNone;
202
201
203
- g_OMX_Mutex. Lock ( );
202
+ android::Mutex::Autolock l (g_OMX_Mutex );
204
203
g_NumMasterOMXInstances--;
205
204
if (g_NumMasterOMXInstances == 0 )
206
205
{
@@ -232,7 +231,6 @@ OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_Deinit()
232
231
233
232
234
233
}
235
- g_OMX_Mutex.Unlock ();
236
234
return OMX_ErrorNone;
237
235
}
238
236
@@ -246,11 +244,10 @@ OMX_API OMX_ERRORTYPE PV_MasterOMX_GetComponentsOfRole(
246
244
OMX_U32 ii;
247
245
// initialize
248
246
*pNumComps = 0 ;
249
- g_OMX_Mutex. Lock ( );
247
+ android::Mutex::Autolock l (g_OMX_Mutex );
250
248
PVOMXMasterRegistryStruct *pOMXMasterRegistry = (PVOMXMasterRegistryStruct *) g_MasterRegistry;
251
249
if (pOMXMasterRegistry == NULL )
252
250
{
253
- g_OMX_Mutex.Unlock ();
254
251
return OMX_ErrorNone;
255
252
}
256
253
@@ -272,7 +269,6 @@ OMX_API OMX_ERRORTYPE PV_MasterOMX_GetComponentsOfRole(
272
269
}
273
270
}
274
271
275
- g_OMX_Mutex.Unlock ();
276
272
return OMX_ErrorNone;
277
273
278
274
}
@@ -287,17 +283,15 @@ OMX_API OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_GetHandle(
287
283
OMX_ERRORTYPE Status = OMX_ErrorNone;
288
284
OMX_U32 ii, kk;
289
285
290
- g_OMX_Mutex. Lock ( );
286
+ android::Mutex::Autolock l (g_OMX_Mutex );
291
287
PVOMXMasterRegistryStruct *pOMXMasterRegistry = (PVOMXMasterRegistryStruct *) g_MasterRegistry;
292
288
if (pOMXMasterRegistry == NULL )
293
289
{
294
- g_OMX_Mutex.Unlock ();
295
290
return OMX_ErrorComponentNotFound;
296
291
}
297
292
PVOMXCompHandles *pOMXCompHandles = (PVOMXCompHandles *)g_OMXCompHandles;
298
293
if (pOMXCompHandles == NULL )
299
294
{
300
- g_OMX_Mutex.Unlock ();
301
295
return OMX_ErrorComponentNotFound;
302
296
}
303
297
@@ -315,7 +309,6 @@ OMX_API OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_GetHandle(
315
309
if (ii == g_TotalNumOMXComponents)
316
310
{
317
311
// could not find a component with the given name
318
- g_OMX_Mutex.Unlock ();
319
312
return OMX_ErrorComponentNotFound;
320
313
}
321
314
@@ -335,7 +328,6 @@ OMX_API OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_GetHandle(
335
328
}
336
329
if (kk == MAX_NUMBER_OF_OMX_COMPONENTS)
337
330
{
338
- g_OMX_Mutex.Unlock ();
339
331
return OMX_ErrorComponentNotFound;
340
332
}
341
333
@@ -347,12 +339,10 @@ OMX_API OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_GetHandle(
347
339
pOMXCompHandles[kk].handle = *pHandle;
348
340
pOMXCompHandles[kk].OMXCoreIndex = index ;
349
341
}
350
- g_OMX_Mutex.Unlock ();
351
342
return Status;
352
343
}
353
344
else
354
345
{
355
- g_OMX_Mutex.Unlock ();
356
346
return OMX_ErrorInsufficientResources;
357
347
}
358
348
@@ -366,11 +356,10 @@ OMX_API OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_FreeHandle(OMX_IN OMX_HANDLETYPE
366
356
// here, we need to first find the handle among instantiated components
367
357
// then we retrieve the core based on component handle
368
358
// finally, call the OMX_FreeHandle for appropriate core
369
- g_OMX_Mutex. Lock ( );
359
+ android::Mutex::Autolock l (g_OMX_Mutex );
370
360
PVOMXCompHandles *pOMXCompHandles = (PVOMXCompHandles *)g_OMXCompHandles;
371
361
if (pOMXCompHandles == NULL )
372
362
{
373
- g_OMX_Mutex.Unlock ();
374
363
return OMX_ErrorComponentNotFound;
375
364
}
376
365
for (ii = 0 ; ii < MAX_NUMBER_OF_OMX_COMPONENTS; ii ++)
@@ -386,7 +375,6 @@ OMX_API OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_FreeHandle(OMX_IN OMX_HANDLETYPE
386
375
if (ii == MAX_NUMBER_OF_OMX_COMPONENTS)
387
376
{
388
377
// could not find a component with the given name
389
- g_OMX_Mutex.Unlock ();
390
378
return OMX_ErrorComponentNotFound;
391
379
}
392
380
@@ -398,12 +386,10 @@ OMX_API OMX_ERRORTYPE OMX_APIENTRY PV_MasterOMX_FreeHandle(OMX_IN OMX_HANDLETYPE
398
386
Status = (*(pWrapper[index ]->GetpOMX_FreeHandle ()))(hComponent);
399
387
// we're done with this, so get rid of the component handle
400
388
pOMXCompHandles[ii].handle = NULL ;
401
- g_OMX_Mutex.Unlock ();
402
389
return Status;
403
390
}
404
391
else
405
392
{
406
- g_OMX_Mutex.Unlock ();
407
393
return OMX_ErrorInsufficientResources;
408
394
}
409
395
0 commit comments