forked from projectceladon/libstagefrighthw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WrsOMXPlugin.cpp
241 lines (210 loc) · 8.18 KB
/
WrsOMXPlugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/*************************************************************************************
* INTEL CONFIDENTIAL
* Copyright 2011 Intel Corporation All Rights Reserved.
* The source code contained or described herein and all documents related
* to the source code ("Material") are owned by Intel Corporation or its
* suppliers or licensors. Title to the Material remains with Intel
* Corporation or its suppliers and licensors. The Material contains trade
* secrets and proprietary and confidential information of Intel or its
* suppliers and licensors. The Material is protected by worldwide copyright
* and trade secret laws and treaty provisions. No part of the Material may
* be used, copied, reproduced, modified, published, uploaded, posted,
* transmitted, distributed, or disclosed in any way without Intel’s prior
* express written permission.
*
* No license under any patent, copyright, trade secret or other intellectual
* property right is granted to or conferred upon you by disclosure or delivery
* of the Materials, either expressly, by implication, inducement, estoppel or
* otherwise. Any license under such intellectual property rights must be express
* and approved by Intel in writing.
************************************************************************************/
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "WrsOMXPlugin.h"
#include <dlfcn.h>
#include <HardwareAPI.h>
#include <media/stagefright/foundation/ADebug.h>
namespace android {
OMXPluginBase *createOMXPlugin() {
return new WrsOMXPlugin;
}
WrsOMXPlugin::WrsOMXPlugin()
{
#if defined(USE_HANTRO_OMX_CORE)
AddCore("libhantro_omx_core.so");
#endif
#if defined(USE_ALLEGRO_OMX_CORE)
AddCore("libOMX.allegro.core.so");
#endif
#ifdef TARGET_HAS_ISV
AddCore("libisv_omx_core.so");
#else
AddCore("libmfx_omx_core.so");
#endif
#if defined(USE_INTEL_MDP)
AddCore("libmdp_omx_core.so");
#endif
}
OMX_ERRORTYPE WrsOMXPlugin::AddCore(const char* coreName)
{
void* libHandle = dlopen(coreName, RTLD_NOW);
if (libHandle != NULL) {
WrsOMXCore* core = (WrsOMXCore*)calloc(1,sizeof(WrsOMXCore));
if (!core) {
dlclose(libHandle);
return OMX_ErrorUndefined;
}
// set plugin lib handle and methods
core->mLibHandle = libHandle;
core->mInit = (WrsOMXCore::InitFunc)dlsym(libHandle, "OMX_Init");
core->mDeinit = (WrsOMXCore::DeinitFunc)dlsym(libHandle, "OMX_Deinit");
core->mComponentNameEnum =
(WrsOMXCore::ComponentNameEnumFunc)dlsym(libHandle, "OMX_ComponentNameEnum");
core->mGetHandle = (WrsOMXCore::GetHandleFunc)dlsym(libHandle, "OMX_GetHandle");
core->mFreeHandle = (WrsOMXCore::FreeHandleFunc)dlsym(libHandle, "OMX_FreeHandle");
core->mGetRolesOfComponentHandle =
(WrsOMXCore::GetRolesOfComponentFunc)dlsym(
libHandle, "OMX_GetRolesOfComponent");
if (core->mInit != NULL) {
(*(core->mInit))();
}
if (core->mComponentNameEnum != NULL) {
// calculating number of components registered inside given OMX core
char tmpComponentName[OMX_MAX_STRINGNAME_SIZE] = { 0 };
OMX_U32 tmpIndex = 0;
while (OMX_ErrorNone == ((*(core->mComponentNameEnum))(tmpComponentName, OMX_MAX_STRINGNAME_SIZE, tmpIndex))) {
tmpIndex++;
ALOGI("OMX IL core %s: declares component %s", coreName, tmpComponentName);
}
core->mNumComponents = tmpIndex;
ALOGI("OMX IL core %s: contains %d components", coreName, core->mNumComponents);
}
// add plugin to the vector
mCores.push_back(core);
}
else {
ALOGW("OMX IL core %s not found", coreName);
return OMX_ErrorUndefined; // Do we need to return error message
}
return OMX_ErrorNone;
}
WrsOMXPlugin::~WrsOMXPlugin() {
for (OMX_U32 i = 0; i < mCores.size(); i++) {
if (mCores[i] != NULL && mCores[i]->mLibHandle != NULL) {
(*(mCores[i]->mDeinit))();
dlclose(mCores[i]->mLibHandle);
free(mCores[i]);
}
}
}
OMX_ERRORTYPE WrsOMXPlugin::makeComponentInstance(
const char *name,
const OMX_CALLBACKTYPE *callbacks,
OMX_PTR appData,
OMX_COMPONENTTYPE **component) {
for (OMX_U32 i = 0; i < mCores.size(); i++) {
if (mCores[i] != NULL) {
if (mCores[i]->mLibHandle == NULL) {
continue;
}
OMX_ERRORTYPE omx_res = (*(mCores[i]->mGetHandle))(
reinterpret_cast<OMX_HANDLETYPE *>(component),
const_cast<char *>(name),
appData, const_cast<OMX_CALLBACKTYPE *>(callbacks));
if(omx_res == OMX_ErrorNone) {
Mutex::Autolock autoLock(mMutex);
WrsOMXComponent comp;
comp.mComponent = *component;
comp.mCore = mCores[i];
mComponents.push_back(comp);
return OMX_ErrorNone;
}
else if(omx_res == OMX_ErrorInsufficientResources)
{
return omx_res;
}
}
}
return OMX_ErrorInvalidComponentName;
}
OMX_ERRORTYPE WrsOMXPlugin::destroyComponentInstance(
OMX_COMPONENTTYPE *component) {
Mutex::Autolock autoLock(mMutex);
for (OMX_U32 i = 0; i < mComponents.size(); i++) {
if (mComponents[i].mComponent == component) {
if (mComponents[i].mCore == NULL || mComponents[i].mCore->mLibHandle == NULL) {
return OMX_ErrorUndefined;
}
OMX_ERRORTYPE omx_res = (*(mComponents[i].mCore->mFreeHandle))(reinterpret_cast<OMX_HANDLETYPE *>(component));
mComponents.erase(mComponents.begin() + i);
return omx_res;
}
}
return OMX_ErrorInvalidComponent;
}
OMX_ERRORTYPE WrsOMXPlugin::enumerateComponents(
OMX_STRING name,
size_t size,
OMX_U32 index) {
// returning components
OMX_U32 relativeIndex = index;
for (OMX_U32 i = 0; i < mCores.size(); i++) {
if (mCores[i]->mLibHandle == NULL) {
continue;
}
if (relativeIndex < mCores[i]->mNumComponents) return ((*(mCores[i]->mComponentNameEnum))(name, size, relativeIndex));
else relativeIndex -= mCores[i]->mNumComponents;
}
return OMX_ErrorNoMore;
}
OMX_ERRORTYPE WrsOMXPlugin::getRolesOfComponent(
const char *name,
Vector<String8> *roles) {
roles->clear();
for (OMX_U32 j = 0; j < mCores.size(); j++) {
if (mCores[j]->mLibHandle == NULL) {
continue;
}
OMX_U32 numRoles;
OMX_ERRORTYPE err = (*(mCores[j]->mGetRolesOfComponentHandle))(
const_cast<OMX_STRING>(name), &numRoles, NULL);
if (err != OMX_ErrorNone) {
continue;
}
if (numRoles > 0) {
OMX_U8 **array = new OMX_U8 *[numRoles];
for (OMX_U32 i = 0; i < numRoles; ++i) {
array[i] = new OMX_U8[OMX_MAX_STRINGNAME_SIZE];
}
OMX_U32 numRoles2 = numRoles;
err = (*(mCores[j]->mGetRolesOfComponentHandle))(
const_cast<OMX_STRING>(name), &numRoles2, array);
CHECK_EQ(err, OMX_ErrorNone);
CHECK_EQ(numRoles, numRoles2);
for (OMX_U32 i = 0; i < numRoles; ++i) {
String8 s((const char *)array[i]);
roles->push(s);
delete[] array[i];
array[i] = NULL;
}
delete[] array;
array = NULL;
}
return OMX_ErrorNone;
}
return OMX_ErrorInvalidComponent;
}
} // namespace android