• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "SEC_OMX_Plugin.h"
18 
19 #include <dlfcn.h>
20 
21 #include <HardwareAPI.h>
22 
23 namespace android {
24 
createOMXPlugin()25 OMXPluginBase *createOMXPlugin() {
26     return new SECOMXPlugin;
27 }
28 
SECOMXPlugin()29 SECOMXPlugin::SECOMXPlugin()
30     : mLibHandle(dlopen("libSEC_OMX_Core.so", RTLD_NOW)),
31       mInit(NULL),
32       mDeinit(NULL),
33       mComponentNameEnum(NULL),
34       mGetHandle(NULL),
35       mFreeHandle(NULL),
36       mGetRolesOfComponentHandle(NULL) {
37     if (mLibHandle != NULL) {
38         mInit = (InitFunc)dlsym(mLibHandle, "SEC_OMX_Init");
39         mDeinit = (DeinitFunc)dlsym(mLibHandle, "SEC_OMX_Deinit");
40 
41         mComponentNameEnum =
42             (ComponentNameEnumFunc)dlsym(mLibHandle, "SEC_OMX_ComponentNameEnum");
43 
44         mGetHandle = (GetHandleFunc)dlsym(mLibHandle, "SEC_OMX_GetHandle");
45         mFreeHandle = (FreeHandleFunc)dlsym(mLibHandle, "SEC_OMX_FreeHandle");
46 
47         mGetRolesOfComponentHandle =
48             (GetRolesOfComponentFunc)dlsym(
49                     mLibHandle, "SEC_OMX_GetRolesOfComponent");
50 
51         (*mInit)();
52 
53     }
54 }
55 
~SECOMXPlugin()56 SECOMXPlugin::~SECOMXPlugin() {
57     if (mLibHandle != NULL) {
58         (*mDeinit)();
59 
60         dlclose(mLibHandle);
61         mLibHandle = NULL;
62     }
63 }
64 
makeComponentInstance(const char * name,const OMX_CALLBACKTYPE * callbacks,OMX_PTR appData,OMX_COMPONENTTYPE ** component)65 OMX_ERRORTYPE SECOMXPlugin::makeComponentInstance(
66         const char *name,
67         const OMX_CALLBACKTYPE *callbacks,
68         OMX_PTR appData,
69         OMX_COMPONENTTYPE **component) {
70     if (mLibHandle == NULL) {
71         return OMX_ErrorUndefined;
72     }
73 
74     return (*mGetHandle)(
75             reinterpret_cast<OMX_HANDLETYPE *>(component),
76             const_cast<char *>(name),
77             appData, const_cast<OMX_CALLBACKTYPE *>(callbacks));
78 }
79 
destroyComponentInstance(OMX_COMPONENTTYPE * component)80 OMX_ERRORTYPE SECOMXPlugin::destroyComponentInstance(
81         OMX_COMPONENTTYPE *component) {
82     if (mLibHandle == NULL) {
83         return OMX_ErrorUndefined;
84     }
85 
86     return (*mFreeHandle)(reinterpret_cast<OMX_HANDLETYPE *>(component));
87 }
88 
enumerateComponents(OMX_STRING name,size_t size,OMX_U32 index)89 OMX_ERRORTYPE SECOMXPlugin::enumerateComponents(
90         OMX_STRING name,
91         size_t size,
92         OMX_U32 index) {
93     if (mLibHandle == NULL) {
94         return OMX_ErrorUndefined;
95     }
96 
97     return (*mComponentNameEnum)(name, size, index);
98 }
99 
getRolesOfComponent(const char * name,Vector<String8> * roles)100 OMX_ERRORTYPE SECOMXPlugin::getRolesOfComponent(
101         const char *name,
102         Vector<String8> *roles) {
103     roles->clear();
104 
105     if (mLibHandle == NULL) {
106         return OMX_ErrorUndefined;
107     }
108 
109     OMX_U32 numRoles;
110     OMX_ERRORTYPE err = (*mGetRolesOfComponentHandle)(
111             const_cast<OMX_STRING>(name), &numRoles, NULL);
112 
113     if (err != OMX_ErrorNone) {
114         return err;
115     }
116 
117     if (numRoles > 0) {
118         OMX_U8 **array = new OMX_U8 *[numRoles];
119         for (OMX_U32 i = 0; i < numRoles; ++i) {
120             array[i] = new OMX_U8[OMX_MAX_STRINGNAME_SIZE];
121         }
122 
123         OMX_U32 numRoles2;
124         err = (*mGetRolesOfComponentHandle)(
125                 const_cast<OMX_STRING>(name), &numRoles2, array);
126 
127         if (err == OMX_ErrorNone && numRoles != numRoles2) {
128             err = OMX_ErrorUndefined;
129         }
130 
131         for (OMX_U32 i = 0; i < numRoles; ++i) {
132             if (err == OMX_ErrorNone) {
133                 String8 s((const char *)array[i]);
134                 roles->push(s);
135             }
136 
137             delete[] array[i];
138             array[i] = NULL;
139         }
140 
141         delete[] array;
142         array = NULL;
143     }
144 
145     return err;
146 }
147 
148 }  // namespace android
149 
150