3 * Copyright 2012 Samsung Electronics S.LSI Co. LTD
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @file Exynos_OMX_Core.c
20 * @brief Exynos OpenMAX IL Core
21 * @author SeungBeom Kim (sbcrux.kim@samsung.com)
22 * HyeYeon Chung (hyeon.chung@samsung.com)
23 * Yunji Kim (yunji.kim@samsung.com)
33 #include "Exynos_OMX_Core.h"
34 #include "Exynos_OMX_Component_Register.h"
35 #include "Exynos_OSAL_Memory.h"
36 #include "Exynos_OSAL_Mutex.h"
37 #include "Exynos_OSAL_ETC.h"
38 #include "Exynos_OMX_Resourcemanager.h"
41 #define EXYNOS_LOG_TAG "EXYNOS_OMX_CORE"
42 #define EXYNOS_LOG_OFF
43 #include "Exynos_OSAL_Log.h"
46 static int gInitialized
= 0;
47 static OMX_U32 gComponentNum
= 0;
49 static EXYNOS_OMX_COMPONENT_REGLIST
*gComponentList
= NULL
;
50 static EXYNOS_OMX_COMPONENT
*gLoadComponentList
= NULL
;
51 static OMX_HANDLETYPE ghLoadComponentListMutex
= NULL
;
54 OMX_API OMX_ERRORTYPE OMX_APIENTRY
Exynos_OMX_Init(void)
56 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
60 if (gInitialized
== 0) {
61 if (Exynos_OMX_Component_Register(&gComponentList
, &gComponentNum
)) {
62 ret
= OMX_ErrorInsufficientResources
;
63 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "Exynos_OMX_Init : %s", "OMX_ErrorInsufficientResources");
67 ret
= Exynos_OMX_ResourceManager_Init();
68 if (OMX_ErrorNone
!= ret
) {
69 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "Exynos_OMX_Init : Exynos_OMX_ResourceManager_Init failed");
73 ret
= Exynos_OSAL_MutexCreate(&ghLoadComponentListMutex
);
74 if (OMX_ErrorNone
!= ret
) {
75 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "Exynos_OMX_Init : Exynos_OSAL_MutexCreate(&ghLoadComponentListMutex) failed");
80 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "Exynos_OMX_Init : %s", "OMX_ErrorNone");
89 OMX_API OMX_ERRORTYPE OMX_APIENTRY
Exynos_OMX_Deinit(void)
91 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
95 Exynos_OSAL_MutexTerminate(ghLoadComponentListMutex
);
96 ghLoadComponentListMutex
= NULL
;
98 Exynos_OMX_ResourceManager_Deinit();
100 if (OMX_ErrorNone
!= Exynos_OMX_Component_Unregister(gComponentList
)) {
101 ret
= OMX_ErrorUndefined
;
104 gComponentList
= NULL
;
114 OMX_API OMX_ERRORTYPE OMX_APIENTRY
Exynos_OMX_ComponentNameEnum(
115 OMX_OUT OMX_STRING cComponentName
,
116 OMX_IN OMX_U32 nNameLength
,
117 OMX_IN OMX_U32 nIndex
)
119 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
123 if (nIndex
>= gComponentNum
) {
124 ret
= OMX_ErrorNoMore
;
128 snprintf(cComponentName
, nNameLength
, "%s", gComponentList
[nIndex
].component
.componentName
);
137 OMX_API OMX_ERRORTYPE OMX_APIENTRY
Exynos_OMX_GetHandle(
138 OMX_OUT OMX_HANDLETYPE
*pHandle
,
139 OMX_IN OMX_STRING cComponentName
,
140 OMX_IN OMX_PTR pAppData
,
141 OMX_IN OMX_CALLBACKTYPE
*pCallBacks
)
143 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
144 EXYNOS_OMX_COMPONENT
*loadComponent
;
145 EXYNOS_OMX_COMPONENT
*currentComponent
;
150 if (gInitialized
!= 1) {
151 ret
= OMX_ErrorNotReady
;
155 if ((pHandle
== NULL
) || (cComponentName
== NULL
) || (pCallBacks
== NULL
)) {
156 ret
= OMX_ErrorBadParameter
;
159 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "ComponentName : %s", cComponentName
);
161 for (i
= 0; i
< gComponentNum
; i
++) {
162 if (Exynos_OSAL_Strcmp(cComponentName
, gComponentList
[i
].component
.componentName
) == 0) {
163 loadComponent
= Exynos_OSAL_Malloc(sizeof(EXYNOS_OMX_COMPONENT
));
164 Exynos_OSAL_Memset(loadComponent
, 0, sizeof(EXYNOS_OMX_COMPONENT
));
166 Exynos_OSAL_Strcpy(loadComponent
->libName
, gComponentList
[i
].libName
);
167 Exynos_OSAL_Strcpy(loadComponent
->componentName
, gComponentList
[i
].component
.componentName
);
168 ret
= Exynos_OMX_ComponentLoad(loadComponent
);
169 if (ret
!= OMX_ErrorNone
) {
170 Exynos_OSAL_Free(loadComponent
);
171 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "OMX_Error, Line:%d", __LINE__
);
175 ret
= loadComponent
->pOMXComponent
->SetCallbacks(loadComponent
->pOMXComponent
, pCallBacks
, pAppData
);
176 if (ret
!= OMX_ErrorNone
) {
177 Exynos_OMX_ComponentUnload(loadComponent
);
178 Exynos_OSAL_Free(loadComponent
);
179 Exynos_OSAL_Log(EXYNOS_LOG_ERROR
, "OMX_Error, Line:%d", __LINE__
);
183 Exynos_OSAL_MutexLock(ghLoadComponentListMutex
);
184 if (gLoadComponentList
== NULL
) {
185 gLoadComponentList
= loadComponent
;
187 currentComponent
= gLoadComponentList
;
188 while (currentComponent
->nextOMXComp
!= NULL
) {
189 currentComponent
= currentComponent
->nextOMXComp
;
191 currentComponent
->nextOMXComp
= loadComponent
;
193 Exynos_OSAL_MutexUnlock(ghLoadComponentListMutex
);
195 *pHandle
= loadComponent
->pOMXComponent
;
197 Exynos_OSAL_Log(EXYNOS_LOG_TRACE
, "Exynos_OMX_GetHandle : %s", "OMX_ErrorNone");
202 ret
= OMX_ErrorComponentNotFound
;
210 OMX_API OMX_ERRORTYPE OMX_APIENTRY
Exynos_OMX_FreeHandle(OMX_IN OMX_HANDLETYPE hComponent
)
212 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
213 EXYNOS_OMX_COMPONENT
*currentComponent
= NULL
;
214 EXYNOS_OMX_COMPONENT
*deleteComponent
= NULL
;
218 if ((gInitialized
!= 1) ||
219 (gLoadComponentList
== NULL
)) {
220 ret
= OMX_ErrorNotReady
;
225 ret
= OMX_ErrorBadParameter
;
229 Exynos_OSAL_MutexLock(ghLoadComponentListMutex
);
230 if (gLoadComponentList
->pOMXComponent
== hComponent
) {
231 deleteComponent
= gLoadComponentList
;
232 gLoadComponentList
= gLoadComponentList
->nextOMXComp
;
234 currentComponent
= gLoadComponentList
;
236 while ((currentComponent
!= NULL
) &&
237 (currentComponent
->nextOMXComp
!= NULL
)) {
238 if (currentComponent
->nextOMXComp
->pOMXComponent
== hComponent
) {
239 deleteComponent
= currentComponent
->nextOMXComp
;
240 currentComponent
->nextOMXComp
= deleteComponent
->nextOMXComp
;
243 currentComponent
= currentComponent
->nextOMXComp
;
246 if (deleteComponent
== NULL
) {
247 ret
= OMX_ErrorComponentNotFound
;
248 Exynos_OSAL_MutexUnlock(ghLoadComponentListMutex
);
252 Exynos_OSAL_MutexUnlock(ghLoadComponentListMutex
);
254 Exynos_OMX_ComponentUnload(deleteComponent
);
255 Exynos_OSAL_Free(deleteComponent
);
263 OMX_API OMX_ERRORTYPE OMX_APIENTRY
Exynos_OMX_SetupTunnel(
264 OMX_IN OMX_HANDLETYPE hOutput
,
265 OMX_IN OMX_U32 nPortOutput
,
266 OMX_IN OMX_HANDLETYPE hInput
,
267 OMX_IN OMX_U32 nPortInput
)
269 OMX_ERRORTYPE ret
= OMX_ErrorNotImplemented
;
275 OMX_API OMX_ERRORTYPE
Exynos_OMX_GetContentPipe(
276 OMX_OUT OMX_HANDLETYPE
*hPipe
,
277 OMX_IN OMX_STRING szURI
)
279 OMX_ERRORTYPE ret
= OMX_ErrorNotImplemented
;
285 OMX_API OMX_ERRORTYPE
Exynos_OMX_GetComponentsOfRole (
286 OMX_IN OMX_STRING role
,
287 OMX_INOUT OMX_U32
*pNumComps
,
288 OMX_INOUT OMX_U8
**compNames
)
290 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
291 int max_role_num
= 0;
292 OMX_STRING RoleString
[MAX_OMX_COMPONENT_ROLE_SIZE
];
297 if (gInitialized
!= 1) {
298 ret
= OMX_ErrorNotReady
;
304 for (i
= 0; i
< MAX_OMX_COMPONENT_NUM
; i
++) {
305 max_role_num
= gComponentList
[i
].component
.totalRoleNum
;
307 for (j
= 0; j
< max_role_num
; j
++) {
308 if (Exynos_OSAL_Strcmp(gComponentList
[i
].component
.roles
[j
], role
) == 0) {
309 if (compNames
!= NULL
) {
310 Exynos_OSAL_Strcpy((OMX_STRING
)compNames
[*pNumComps
], gComponentList
[i
].component
.componentName
);
312 *pNumComps
= (*pNumComps
+ 1);
323 OMX_API OMX_ERRORTYPE
Exynos_OMX_GetRolesOfComponent (
324 OMX_IN OMX_STRING compName
,
325 OMX_INOUT OMX_U32
*pNumRoles
,
326 OMX_OUT OMX_U8
**roles
)
328 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
329 OMX_BOOL detectComp
= OMX_FALSE
;
330 int compNum
= 0, totalRoleNum
= 0;
335 if (gInitialized
!= 1) {
336 ret
= OMX_ErrorNotReady
;
340 for (i
= 0; i
< MAX_OMX_COMPONENT_NUM
; i
++) {
341 if (gComponentList
!= NULL
) {
342 if (Exynos_OSAL_Strcmp(gComponentList
[i
].component
.componentName
, compName
) == 0) {
343 *pNumRoles
= totalRoleNum
= gComponentList
[i
].component
.totalRoleNum
;
345 detectComp
= OMX_TRUE
;
349 ret
= OMX_ErrorUndefined
;
354 if (detectComp
== OMX_FALSE
) {
356 ret
= OMX_ErrorComponentNotFound
;
361 for (i
= 0; i
< totalRoleNum
; i
++) {
362 Exynos_OSAL_Strcpy(roles
[i
], gComponentList
[compNum
].component
.roles
[i
]);