am 5d4fa740: am 17071e43: Fix JPEG thumbnail size check.
[GitHub/LineageOS/android_hardware_samsung_slsi_exynos5.git] / libstagefrighthw / Exynos_OMX_Plugin.cpp
CommitLineData
e26c1540
JC
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 "Exynos_OMX_Plugin.h"
18
19#include <dlfcn.h>
20
4c16017c
DZ
21#include <media/hardware/HardwareAPI.h>
22#include <media/stagefright/foundation/ADebug.h>
e26c1540
JC
23
24namespace android {
25
26OMXPluginBase *createOMXPlugin() {
27 return new ExynosOMXPlugin;
28}
29
30ExynosOMXPlugin::ExynosOMXPlugin()
31 : mLibHandle(dlopen("libExynosOMX_Core.so", RTLD_NOW)),
32 mInit(NULL),
33 mDeinit(NULL),
34 mComponentNameEnum(NULL),
35 mGetHandle(NULL),
36 mFreeHandle(NULL),
37 mGetRolesOfComponentHandle(NULL) {
38 if (mLibHandle != NULL) {
39 mInit = (InitFunc)dlsym(mLibHandle, "Exynos_OMX_Init");
40 mDeinit = (DeinitFunc)dlsym(mLibHandle, "Exynos_OMX_Deinit");
41
42 mComponentNameEnum =
43 (ComponentNameEnumFunc)dlsym(mLibHandle, "Exynos_OMX_ComponentNameEnum");
44
45 mGetHandle = (GetHandleFunc)dlsym(mLibHandle, "Exynos_OMX_GetHandle");
46 mFreeHandle = (FreeHandleFunc)dlsym(mLibHandle, "Exynos_OMX_FreeHandle");
47
48 mGetRolesOfComponentHandle =
49 (GetRolesOfComponentFunc)dlsym(
50 mLibHandle, "Exynos_OMX_GetRolesOfComponent");
51
52 (*mInit)();
53
54 }
55}
56
57ExynosOMXPlugin::~ExynosOMXPlugin() {
58 if (mLibHandle != NULL) {
59 (*mDeinit)();
60
61 dlclose(mLibHandle);
62 mLibHandle = NULL;
63 }
64}
65
66OMX_ERRORTYPE ExynosOMXPlugin::makeComponentInstance(
67 const char *name,
68 const OMX_CALLBACKTYPE *callbacks,
69 OMX_PTR appData,
70 OMX_COMPONENTTYPE **component) {
71 if (mLibHandle == NULL) {
72 return OMX_ErrorUndefined;
73 }
74
75 return (*mGetHandle)(
76 reinterpret_cast<OMX_HANDLETYPE *>(component),
77 const_cast<char *>(name),
78 appData, const_cast<OMX_CALLBACKTYPE *>(callbacks));
79}
80
81OMX_ERRORTYPE ExynosOMXPlugin::destroyComponentInstance(
82 OMX_COMPONENTTYPE *component) {
83 if (mLibHandle == NULL) {
84 return OMX_ErrorUndefined;
85 }
86
87 return (*mFreeHandle)(reinterpret_cast<OMX_HANDLETYPE *>(component));
88}
89
90OMX_ERRORTYPE ExynosOMXPlugin::enumerateComponents(
91 OMX_STRING name,
92 size_t size,
93 OMX_U32 index) {
94 if (mLibHandle == NULL) {
95 return OMX_ErrorUndefined;
96 }
97
98 return (*mComponentNameEnum)(name, size, index);
99}
100
101OMX_ERRORTYPE ExynosOMXPlugin::getRolesOfComponent(
102 const char *name,
103 Vector<String8> *roles) {
104 roles->clear();
105
106 if (mLibHandle == NULL) {
107 return OMX_ErrorUndefined;
108 }
109
110 OMX_U32 numRoles;
111 OMX_ERRORTYPE err = (*mGetRolesOfComponentHandle)(
112 const_cast<OMX_STRING>(name), &numRoles, NULL);
113
114 if (err != OMX_ErrorNone) {
115 return err;
116 }
117
118 if (numRoles > 0) {
119 OMX_U8 **array = new OMX_U8 *[numRoles];
120 for (OMX_U32 i = 0; i < numRoles; ++i) {
121 array[i] = new OMX_U8[OMX_MAX_STRINGNAME_SIZE];
122 }
123
124 OMX_U32 numRoles2;
125 err = (*mGetRolesOfComponentHandle)(
126 const_cast<OMX_STRING>(name), &numRoles2, array);
127
128 CHECK_EQ(err, OMX_ErrorNone);
129 CHECK_EQ(numRoles, numRoles2);
130
131 for (OMX_U32 i = 0; i < numRoles; ++i) {
132 String8 s((const char *)array[i]);
133 roles->push(s);
134
135 delete[] array[i];
136 array[i] = NULL;
137 }
138
139 delete[] array;
140 array = NULL;
141 }
142
143 return OMX_ErrorNone;
144}
145
146} // namespace android
147