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_Component_Register.c
20 * @brief Exynos OpenMAX IL Component Register
21 * @author SeungBeom Kim (sbcrux.kim@samsung.com)
30 #include <sys/types.h>
36 #include "OMX_Component.h"
37 #include "Exynos_OSAL_Memory.h"
38 #include "Exynos_OSAL_ETC.h"
39 #include "Exynos_OSAL_Library.h"
40 #include "Exynos_OMX_Component_Register.h"
41 #include "Exynos_OMX_Macros.h"
44 #define EXYNOS_LOG_TAG "EXYNOS_COMP_REGS"
45 #define EXYNOS_LOG_OFF
46 #include "Exynos_OSAL_Log.h"
48 OMX_ERRORTYPE Exynos_OMX_Component_Register(EXYNOS_OMX_COMPONENT_REGLIST **compList, OMX_U32 *compNum)
50 OMX_ERRORTYPE ret = OMX_ErrorNone;
51 int componentNum = 0, totalCompNum = 0;
57 int (*Exynos_OMX_COMPONENT_Library_Register)(ExynosRegisterComponentType **exynosComponents);
58 ExynosRegisterComponentType **exynosComponentsTemp;
59 EXYNOS_OMX_COMPONENT_REGLIST *componentList;
63 dir = opendir(EXYNOS_OMX_INSTALL_PATH);
65 ret = OMX_ErrorUndefined;
69 componentList = (EXYNOS_OMX_COMPONENT_REGLIST *)Exynos_OSAL_Malloc(sizeof(EXYNOS_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM);
70 Exynos_OSAL_Memset(componentList, 0, sizeof(EXYNOS_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM);
71 libName = Exynos_OSAL_Malloc(MAX_OMX_COMPONENT_LIBNAME_SIZE);
73 while ((d = readdir(dir)) != NULL) {
74 OMX_HANDLETYPE soHandle;
75 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s", d->d_name);
77 if (Exynos_OSAL_Strncmp(d->d_name, "libOMX.Exynos.", Exynos_OSAL_Strlen("libOMX.Exynos.")) == 0) {
78 Exynos_OSAL_Memset(libName, 0, MAX_OMX_COMPONENT_LIBNAME_SIZE);
79 Exynos_OSAL_Strcpy(libName, EXYNOS_OMX_INSTALL_PATH);
80 Exynos_OSAL_Strcat(libName, d->d_name);
81 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Path & libName : %s", libName);
82 if ((soHandle = Exynos_OSAL_dlopen(libName, RTLD_LAZY)) != NULL) {
83 Exynos_OSAL_dlerror(); /* clear error*/
84 if ((Exynos_OMX_COMPONENT_Library_Register = Exynos_OSAL_dlsym(soHandle, "Exynos_OMX_COMPONENT_Library_Register")) != NULL) {
88 componentNum = (*Exynos_OMX_COMPONENT_Library_Register)(NULL);
89 exynosComponentsTemp = (ExynosRegisterComponentType **)Exynos_OSAL_Malloc(sizeof(ExynosRegisterComponentType*) * componentNum);
90 for (i = 0; i < componentNum; i++) {
91 exynosComponentsTemp[i] = Exynos_OSAL_Malloc(sizeof(ExynosRegisterComponentType));
92 Exynos_OSAL_Memset(exynosComponentsTemp[i], 0, sizeof(ExynosRegisterComponentType));
94 (*Exynos_OMX_COMPONENT_Library_Register)(exynosComponentsTemp);
96 for (i = 0; i < componentNum; i++) {
97 Exynos_OSAL_Strcpy(componentList[totalCompNum].component.componentName, exynosComponentsTemp[i]->componentName);
98 for (j = 0; j < exynosComponentsTemp[i]->totalRoleNum; j++)
99 Exynos_OSAL_Strcpy(componentList[totalCompNum].component.roles[j], exynosComponentsTemp[i]->roles[j]);
100 componentList[totalCompNum].component.totalRoleNum = exynosComponentsTemp[i]->totalRoleNum;
102 Exynos_OSAL_Strcpy(componentList[totalCompNum].libName, libName);
106 for (i = 0; i < componentNum; i++) {
107 Exynos_OSAL_Free(exynosComponentsTemp[i]);
110 Exynos_OSAL_Free(exynosComponentsTemp);
112 if ((errorMsg = Exynos_OSAL_dlerror()) != NULL)
113 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "dlsym failed: %s", errorMsg);
115 Exynos_OSAL_dlclose(soHandle);
117 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "dlopen failed: %s", Exynos_OSAL_dlerror());
120 /* not a component name line. skip */
125 Exynos_OSAL_Free(libName);
129 *compList = componentList;
130 *compNum = totalCompNum;
138 OMX_ERRORTYPE Exynos_OMX_Component_Unregister(EXYNOS_OMX_COMPONENT_REGLIST *componentList)
140 Exynos_OSAL_Memset(componentList, 0, sizeof(EXYNOS_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM);
141 Exynos_OSAL_Free(componentList);
143 return OMX_ErrorNone;
146 OMX_ERRORTYPE Exynos_OMX_ComponentAPICheck(OMX_COMPONENTTYPE *component)
148 OMX_ERRORTYPE ret = OMX_ErrorNone;
150 if ((NULL == component->GetComponentVersion) ||
151 (NULL == component->SendCommand) ||
152 (NULL == component->GetParameter) ||
153 (NULL == component->SetParameter) ||
154 (NULL == component->GetConfig) ||
155 (NULL == component->SetConfig) ||
156 (NULL == component->GetExtensionIndex) ||
157 (NULL == component->GetState) ||
158 (NULL == component->ComponentTunnelRequest) ||
159 (NULL == component->UseBuffer) ||
160 (NULL == component->AllocateBuffer) ||
161 (NULL == component->FreeBuffer) ||
162 (NULL == component->EmptyThisBuffer) ||
163 (NULL == component->FillThisBuffer) ||
164 (NULL == component->SetCallbacks) ||
165 (NULL == component->ComponentDeInit) ||
166 (NULL == component->UseEGLImage) ||
167 (NULL == component->ComponentRoleEnum))
168 ret = OMX_ErrorInvalidComponent;
175 OMX_ERRORTYPE Exynos_OMX_ComponentLoad(EXYNOS_OMX_COMPONENT *exynos_component)
177 OMX_ERRORTYPE ret = OMX_ErrorNone;
178 OMX_HANDLETYPE libHandle;
179 OMX_COMPONENTTYPE *pOMXComponent;
183 OMX_ERRORTYPE (*Exynos_OMX_ComponentInit)(OMX_HANDLETYPE hComponent, OMX_STRING componentName);
185 libHandle = Exynos_OSAL_dlopen((OMX_STRING)exynos_component->libName, RTLD_LAZY);
187 ret = OMX_ErrorInvalidComponentName;
188 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInvalidComponentName, Line:%d", __LINE__);
192 Exynos_OMX_ComponentInit = Exynos_OSAL_dlsym(libHandle, "Exynos_OMX_ComponentInit");
193 if (!Exynos_OMX_ComponentInit) {
194 Exynos_OSAL_dlclose(libHandle);
195 ret = OMX_ErrorInvalidComponent;
196 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
200 pOMXComponent = (OMX_COMPONENTTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_COMPONENTTYPE));
201 INIT_SET_SIZE_VERSION(pOMXComponent, OMX_COMPONENTTYPE);
202 ret = (*Exynos_OMX_ComponentInit)((OMX_HANDLETYPE)pOMXComponent, (OMX_STRING)exynos_component->componentName);
203 if (ret != OMX_ErrorNone) {
204 Exynos_OSAL_Free(pOMXComponent);
205 Exynos_OSAL_dlclose(libHandle);
206 ret = OMX_ErrorInvalidComponent;
207 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
210 if (Exynos_OMX_ComponentAPICheck(pOMXComponent) != OMX_ErrorNone) {
211 if (NULL != pOMXComponent->ComponentDeInit)
212 pOMXComponent->ComponentDeInit(pOMXComponent);
213 Exynos_OSAL_Free(pOMXComponent);
214 Exynos_OSAL_dlclose(libHandle);
215 ret = OMX_ErrorInvalidComponent;
216 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
219 exynos_component->libHandle = libHandle;
220 exynos_component->pOMXComponent = pOMXComponent;
230 OMX_ERRORTYPE Exynos_OMX_ComponentUnload(EXYNOS_OMX_COMPONENT *exynos_component)
232 OMX_ERRORTYPE ret = OMX_ErrorNone;
233 OMX_COMPONENTTYPE *pOMXComponent = NULL;
237 if (!exynos_component) {
238 ret = OMX_ErrorBadParameter;
242 pOMXComponent = exynos_component->pOMXComponent;
243 if (pOMXComponent != NULL) {
244 pOMXComponent->ComponentDeInit(pOMXComponent);
245 Exynos_OSAL_Free(pOMXComponent);
246 exynos_component->pOMXComponent = NULL;
249 if (exynos_component->libHandle != NULL) {
250 Exynos_OSAL_dlclose(exynos_component->libHandle);
251 exynos_component->libHandle = NULL;