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
;
214 EXYNOS_OMX_COMPONENT
*deleteComponent
;
218 if (gInitialized
!= 1) {
219 ret
= OMX_ErrorNotReady
;
224 ret
= OMX_ErrorBadParameter
;
228 Exynos_OSAL_MutexLock(ghLoadComponentListMutex
);
229 currentComponent
= gLoadComponentList
;
230 if (gLoadComponentList
->pOMXComponent
== hComponent
) {
231 deleteComponent
= gLoadComponentList
;
232 gLoadComponentList
= gLoadComponentList
->nextOMXComp
;
234 while ((currentComponent
!= NULL
) && (((EXYNOS_OMX_COMPONENT
*)(currentComponent
->nextOMXComp
))->pOMXComponent
!= hComponent
))
235 currentComponent
= currentComponent
->nextOMXComp
;
237 if (((EXYNOS_OMX_COMPONENT
*)(currentComponent
->nextOMXComp
))->pOMXComponent
== hComponent
) {
238 deleteComponent
= currentComponent
->nextOMXComp
;
239 currentComponent
->nextOMXComp
= deleteComponent
->nextOMXComp
;
240 } else if (currentComponent
== NULL
) {
241 ret
= OMX_ErrorComponentNotFound
;
242 Exynos_OSAL_MutexUnlock(ghLoadComponentListMutex
);
246 Exynos_OSAL_MutexUnlock(ghLoadComponentListMutex
);
248 Exynos_OMX_ComponentUnload(deleteComponent
);
249 Exynos_OSAL_Free(deleteComponent
);
257 OMX_API OMX_ERRORTYPE OMX_APIENTRY
Exynos_OMX_SetupTunnel(
258 OMX_IN OMX_HANDLETYPE hOutput
,
259 OMX_IN OMX_U32 nPortOutput
,
260 OMX_IN OMX_HANDLETYPE hInput
,
261 OMX_IN OMX_U32 nPortInput
)
263 OMX_ERRORTYPE ret
= OMX_ErrorNotImplemented
;
269 OMX_API OMX_ERRORTYPE
Exynos_OMX_GetContentPipe(
270 OMX_OUT OMX_HANDLETYPE
*hPipe
,
271 OMX_IN OMX_STRING szURI
)
273 OMX_ERRORTYPE ret
= OMX_ErrorNotImplemented
;
279 OMX_API OMX_ERRORTYPE
Exynos_OMX_GetComponentsOfRole (
280 OMX_IN OMX_STRING role
,
281 OMX_INOUT OMX_U32
*pNumComps
,
282 OMX_INOUT OMX_U8
**compNames
)
284 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
285 int max_role_num
= 0;
286 OMX_STRING RoleString
[MAX_OMX_COMPONENT_ROLE_SIZE
];
291 if (gInitialized
!= 1) {
292 ret
= OMX_ErrorNotReady
;
298 for (i
= 0; i
< MAX_OMX_COMPONENT_NUM
; i
++) {
299 max_role_num
= gComponentList
[i
].component
.totalRoleNum
;
301 for (j
= 0; j
< max_role_num
; j
++) {
302 if (Exynos_OSAL_Strcmp(gComponentList
[i
].component
.roles
[j
], role
) == 0) {
303 if (compNames
!= NULL
) {
304 Exynos_OSAL_Strcpy((OMX_STRING
)compNames
[*pNumComps
], gComponentList
[i
].component
.componentName
);
306 *pNumComps
= (*pNumComps
+ 1);
317 OMX_API OMX_ERRORTYPE
Exynos_OMX_GetRolesOfComponent (
318 OMX_IN OMX_STRING compName
,
319 OMX_INOUT OMX_U32
*pNumRoles
,
320 OMX_OUT OMX_U8
**roles
)
322 OMX_ERRORTYPE ret
= OMX_ErrorNone
;
323 OMX_BOOL detectComp
= OMX_FALSE
;
324 int compNum
= 0, totalRoleNum
= 0;
329 if (gInitialized
!= 1) {
330 ret
= OMX_ErrorNotReady
;
334 for (i
= 0; i
< MAX_OMX_COMPONENT_NUM
; i
++) {
335 if (gComponentList
!= NULL
) {
336 if (Exynos_OSAL_Strcmp(gComponentList
[i
].component
.componentName
, compName
) == 0) {
337 *pNumRoles
= totalRoleNum
= gComponentList
[i
].component
.totalRoleNum
;
339 detectComp
= OMX_TRUE
;
343 ret
= OMX_ErrorUndefined
;
348 if (detectComp
== OMX_FALSE
) {
350 ret
= OMX_ErrorComponentNotFound
;
355 for (i
= 0; i
< totalRoleNum
; i
++) {
356 Exynos_OSAL_Strcpy(roles
[i
], gComponentList
[compNum
].component
.roles
[i
]);