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, roleNum = 0, totalCompNum = 0;
59 int (*Exynos_OMX_COMPONENT_Library_Register)(ExynosRegisterComponentType **exynosComponents);
60 ExynosRegisterComponentType **exynosComponentsTemp;
61 EXYNOS_OMX_COMPONENT_REGLIST *componentList;
65 dir = opendir(EXYNOS_OMX_INSTALL_PATH);
67 ret = OMX_ErrorUndefined;
71 componentList = (EXYNOS_OMX_COMPONENT_REGLIST *)Exynos_OSAL_Malloc(sizeof(EXYNOS_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM);
72 Exynos_OSAL_Memset(componentList, 0, sizeof(EXYNOS_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM);
73 libName = Exynos_OSAL_Malloc(MAX_OMX_COMPONENT_LIBNAME_SIZE);
75 while ((d = readdir(dir)) != NULL) {
76 OMX_HANDLETYPE soHandle;
77 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s", d->d_name);
79 if (Exynos_OSAL_Strncmp(d->d_name, "libOMX.Exynos.", Exynos_OSAL_Strlen("libOMX.Exynos.")) == 0) {
80 Exynos_OSAL_Memset(libName, 0, MAX_OMX_COMPONENT_LIBNAME_SIZE);
81 Exynos_OSAL_Strcpy(libName, EXYNOS_OMX_INSTALL_PATH);
82 Exynos_OSAL_Strcat(libName, d->d_name);
83 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "Path & libName : %s", libName);
84 if ((soHandle = Exynos_OSAL_dlopen(libName, RTLD_LAZY)) != NULL) {
85 Exynos_OSAL_dlerror(); /* clear error*/
86 if ((Exynos_OMX_COMPONENT_Library_Register = Exynos_OSAL_dlsym(soHandle, "Exynos_OMX_COMPONENT_Library_Register")) != NULL) {
90 componentNum = (*Exynos_OMX_COMPONENT_Library_Register)(NULL);
91 exynosComponentsTemp = (ExynosRegisterComponentType **)Exynos_OSAL_Malloc(sizeof(ExynosRegisterComponentType*) * componentNum);
92 for (i = 0; i < componentNum; i++) {
93 exynosComponentsTemp[i] = Exynos_OSAL_Malloc(sizeof(ExynosRegisterComponentType));
94 Exynos_OSAL_Memset(exynosComponentsTemp[i], 0, sizeof(ExynosRegisterComponentType));
96 (*Exynos_OMX_COMPONENT_Library_Register)(exynosComponentsTemp);
98 for (i = 0; i < componentNum; i++) {
99 Exynos_OSAL_Strcpy(componentList[totalCompNum].component.componentName, exynosComponentsTemp[i]->componentName);
100 for (j = 0; j < exynosComponentsTemp[i]->totalRoleNum; j++)
101 Exynos_OSAL_Strcpy(componentList[totalCompNum].component.roles[j], exynosComponentsTemp[i]->roles[j]);
102 componentList[totalCompNum].component.totalRoleNum = exynosComponentsTemp[i]->totalRoleNum;
104 Exynos_OSAL_Strcpy(componentList[totalCompNum].libName, libName);
108 for (i = 0; i < componentNum; i++) {
109 Exynos_OSAL_Free(exynosComponentsTemp[i]);
112 Exynos_OSAL_Free(exynosComponentsTemp);
114 if ((errorMsg = Exynos_OSAL_dlerror()) != NULL)
115 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "dlsym failed: %s", errorMsg);
117 Exynos_OSAL_dlclose(soHandle);
119 Exynos_OSAL_Log(EXYNOS_LOG_WARNING, "dlopen failed: %s", Exynos_OSAL_dlerror());
122 /* not a component name line. skip */
127 Exynos_OSAL_Free(libName);
131 *compList = componentList;
132 *compNum = totalCompNum;
140 OMX_ERRORTYPE Exynos_OMX_Component_Unregister(EXYNOS_OMX_COMPONENT_REGLIST *componentList)
142 OMX_ERRORTYPE ret = OMX_ErrorNone;
144 Exynos_OSAL_Memset(componentList, 0, sizeof(EXYNOS_OMX_COMPONENT_REGLIST) * MAX_OMX_COMPONENT_NUM);
145 Exynos_OSAL_Free(componentList);
151 OMX_ERRORTYPE Exynos_OMX_ComponentAPICheck(OMX_COMPONENTTYPE *component)
153 OMX_ERRORTYPE ret = OMX_ErrorNone;
155 if ((NULL == component->GetComponentVersion) ||
156 (NULL == component->SendCommand) ||
157 (NULL == component->GetParameter) ||
158 (NULL == component->SetParameter) ||
159 (NULL == component->GetConfig) ||
160 (NULL == component->SetConfig) ||
161 (NULL == component->GetExtensionIndex) ||
162 (NULL == component->GetState) ||
163 (NULL == component->ComponentTunnelRequest) ||
164 (NULL == component->UseBuffer) ||
165 (NULL == component->AllocateBuffer) ||
166 (NULL == component->FreeBuffer) ||
167 (NULL == component->EmptyThisBuffer) ||
168 (NULL == component->FillThisBuffer) ||
169 (NULL == component->SetCallbacks) ||
170 (NULL == component->ComponentDeInit) ||
171 (NULL == component->UseEGLImage) ||
172 (NULL == component->ComponentRoleEnum))
173 ret = OMX_ErrorInvalidComponent;
180 OMX_ERRORTYPE Exynos_OMX_ComponentLoad(EXYNOS_OMX_COMPONENT *exynos_component)
182 OMX_ERRORTYPE ret = OMX_ErrorNone;
183 OMX_HANDLETYPE libHandle;
184 OMX_COMPONENTTYPE *pOMXComponent;
188 OMX_ERRORTYPE (*Exynos_OMX_ComponentInit)(OMX_HANDLETYPE hComponent, OMX_STRING componentName);
190 libHandle = Exynos_OSAL_dlopen((OMX_STRING)exynos_component->libName, RTLD_LAZY);
192 ret = OMX_ErrorInvalidComponentName;
193 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInvalidComponentName, Line:%d", __LINE__);
197 Exynos_OMX_ComponentInit = Exynos_OSAL_dlsym(libHandle, "Exynos_OMX_ComponentInit");
198 if (!Exynos_OMX_ComponentInit) {
199 Exynos_OSAL_dlclose(libHandle);
200 ret = OMX_ErrorInvalidComponent;
201 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
205 pOMXComponent = (OMX_COMPONENTTYPE *)Exynos_OSAL_Malloc(sizeof(OMX_COMPONENTTYPE));
206 INIT_SET_SIZE_VERSION(pOMXComponent, OMX_COMPONENTTYPE);
207 ret = (*Exynos_OMX_ComponentInit)((OMX_HANDLETYPE)pOMXComponent, (OMX_STRING)exynos_component->componentName);
208 if (ret != OMX_ErrorNone) {
209 Exynos_OSAL_Free(pOMXComponent);
210 Exynos_OSAL_dlclose(libHandle);
211 ret = OMX_ErrorInvalidComponent;
212 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
215 if (Exynos_OMX_ComponentAPICheck(pOMXComponent) != OMX_ErrorNone) {
216 if (NULL != pOMXComponent->ComponentDeInit)
217 pOMXComponent->ComponentDeInit(pOMXComponent);
218 Exynos_OSAL_Free(pOMXComponent);
219 Exynos_OSAL_dlclose(libHandle);
220 ret = OMX_ErrorInvalidComponent;
221 Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "OMX_ErrorInvalidComponent, Line:%d", __LINE__);
224 exynos_component->libHandle = libHandle;
225 exynos_component->pOMXComponent = pOMXComponent;
235 OMX_ERRORTYPE Exynos_OMX_ComponentUnload(EXYNOS_OMX_COMPONENT *exynos_component)
237 OMX_ERRORTYPE ret = OMX_ErrorNone;
238 OMX_COMPONENTTYPE *pOMXComponent = NULL;
242 if (!exynos_component) {
243 ret = OMX_ErrorBadParameter;
247 pOMXComponent = exynos_component->pOMXComponent;
248 if (pOMXComponent != NULL) {
249 pOMXComponent->ComponentDeInit(pOMXComponent);
250 Exynos_OSAL_Free(pOMXComponent);
251 exynos_component->pOMXComponent = NULL;
254 if (exynos_component->libHandle != NULL) {
255 Exynos_OSAL_dlclose(exynos_component->libHandle);
256 exynos_component->libHandle = NULL;