-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_loader.h
executable file
·238 lines (213 loc) · 7.8 KB
/
plugin_loader.h
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
/*********************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or nondisclosure
agreement with Intel Corporation and may not be copied or disclosed except in
accordance with the terms of that agreement
Copyright(c) 2013-2014 Intel Corporation. All Rights Reserved.
**********************************************************************************/
#pragma once
#ifndef __PLUGIN_LOADER_H__
#define __PLUGIN_LOADER_H__
#include "so_defs.h"
//#include "sample_utils.h"
//#include "mfx_plugin_module.h"
#include <iostream>
#include <iomanip> // for std::setfill, std::setw
#include <memory> // for std::auto_ptr
class MsdkSoModule
{
protected:
msdk_so_handle m_module;
public:
MsdkSoModule()
: m_module(NULL)
{
}
MsdkSoModule(const msdk_string & pluginName)
: m_module(NULL)
{
m_module = msdk_so_load(pluginName.c_str());
if (NULL == m_module)
{
MSDK_TRACE_ERROR(msdk_tstring(MSDK_CHAR("Failed to load shared module: ")) + pluginName);
}
}
template <class T>
T GetAddr(const std::string & fncName)
{
T pCreateFunc = reinterpret_cast<T>(msdk_so_get_addr(m_module, fncName.c_str()));
if (NULL == pCreateFunc) {
MSDK_TRACE_ERROR(msdk_tstring("Failed to get function addres: ") + fncName.c_str());
}
return pCreateFunc;
}
virtual ~MsdkSoModule()
{
if (m_module)
{
msdk_so_free(m_module);
m_module = NULL;
}
}
};
/*
* Rationale: class to load+register any mediasdk plugin decoder/encoder/generic by given name
*/
class PluginLoader : public MFXPlugin
{
protected:
mfxPluginType ePluginType;
mfxSession m_session;
mfxPluginUID m_uid;
private:
const msdk_char* msdkGetPluginName(const mfxPluginUID& guid)
{
if (AreGuidsEqual(guid, MFX_PLUGINID_HEVCD_SW))
return MSDK_STRING("Intel (R) Media SDK plugin for HEVC DECODE");
else if(AreGuidsEqual(guid, MFX_PLUGINID_HEVCD_HW))
return MSDK_STRING("Intel (R) Media SDK HW plugin for HEVC DECODE");
else if(AreGuidsEqual(guid, MFX_PLUGINID_HEVCE_SW))
return MSDK_STRING("Intel (R) Media SDK plugin for HEVC ENCODE");
else if(AreGuidsEqual(guid, MFX_PLUGINID_H264LA_HW))
return MSDK_STRING("Intel (R) Media SDK plugin for LA ENC");
else
return MSDK_STRING("Unknown plugin");
}
public:
PluginLoader(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version, const mfxChar *pluginName, mfxU32 len)
: m_session()
, m_uid()
, ePluginType(type)
{
len; pluginName;
mfxStatus sts = MFX_ERR_NONE;
msdk_stringstream strStream;
MSDK_MEMCPY(&m_uid, &uid, sizeof(mfxPluginUID));
for (size_t i = 0; i != sizeof(mfxPluginUID); i++)
{
strStream << MSDK_STRING("0x") << std::setfill(MSDK_CHAR('0')) << std::setw(2) << std::hex << (int)m_uid.Data[i];
if (i != (sizeof(mfxPluginUID)-1)) strStream << MSDK_STRING(", ");
}
if ((ePluginType == MFX_PLUGINTYPE_AUDIO_DECODE) ||
(ePluginType == MFX_PLUGINTYPE_AUDIO_ENCODE))
{
// Audio plugins are not loaded by path
sts = MFX_ERR_UNSUPPORTED;
}
else
{
sts = MFXVideoUSER_LoadByPath(session, &m_uid, version, pluginName, len);
}
if (MFX_ERR_NONE != sts)
{
MSDK_TRACE_ERROR(MSDK_STRING("Failed to load plugin from GUID, sts=") << sts << MSDK_STRING(": { ") << strStream.str().c_str() << MSDK_STRING(" } (") << msdkGetPluginName(m_uid) << MSDK_STRING(")"));
}
else
{
MSDK_TRACE_INFO(MSDK_STRING("Plugin was loaded from GUID"));
m_session = session;
}
}
PluginLoader(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version)
: m_session()
, m_uid()
, ePluginType(type)
{
mfxStatus sts = MFX_ERR_NONE;
msdk_stringstream strStream;
MSDK_MEMCPY(&m_uid, &uid, sizeof(mfxPluginUID));
for (size_t i = 0; i != sizeof(mfxPluginUID); i++)
{
strStream << MSDK_STRING("0x") << std::setfill(MSDK_CHAR('0')) << std::setw(2) << std::hex << (int)m_uid.Data[i];
if (i != (sizeof(mfxPluginUID)-1)) strStream << MSDK_STRING(", ");
}
if ((ePluginType == MFX_PLUGINTYPE_AUDIO_DECODE) ||
(ePluginType == MFX_PLUGINTYPE_AUDIO_ENCODE))
{
sts = MFXAudioUSER_Load(session, &m_uid, version);
}
else
{
sts = MFXVideoUSER_Load(session, &m_uid, version);
}
if (MFX_ERR_NONE != sts)
{
MSDK_TRACE_ERROR(MSDK_STRING("Failed to load plugin from GUID, sts=") << sts << MSDK_STRING(": { ") << strStream.str().c_str() << MSDK_STRING(" } (") << msdkGetPluginName(m_uid) << MSDK_STRING(")"));
}
else
{
MSDK_TRACE_INFO(MSDK_STRING("Plugin was loaded from GUID"));
m_session = session;
}
}
virtual ~PluginLoader()
{
mfxStatus sts = MFX_ERR_NONE;
if (m_session)
{
if ((ePluginType == MFX_PLUGINTYPE_AUDIO_DECODE) ||
(ePluginType == MFX_PLUGINTYPE_AUDIO_ENCODE))
{
sts = MFXAudioUSER_UnLoad(m_session, &m_uid);
}
else
{
sts = MFXVideoUSER_UnLoad(m_session, &m_uid);
}
if (sts != MFX_ERR_NONE)
{
MSDK_TRACE_ERROR(MSDK_STRING("Failed to unload plugin from GUID, sts=") << sts);
}
else
{
MSDK_TRACE_INFO(MSDK_STRING("MFXBaseUSER_UnLoad(session=0x") << m_session << MSDK_STRING("), sts=") << sts);
}
}
}
bool IsOk() {
return m_session != 0;
}
virtual mfxStatus PluginInit( mfxCoreInterface *core ) {
core;
return MFX_ERR_NULL_PTR;
}
virtual mfxStatus PluginClose() {
return MFX_ERR_NULL_PTR;
}
virtual mfxStatus GetPluginParam( mfxPluginParam *par ) {
par;
return MFX_ERR_NULL_PTR;
}
virtual mfxStatus Execute( mfxThreadTask task, mfxU32 uid_p, mfxU32 uid_a ) {
task; uid_p; uid_a;
return MFX_ERR_NULL_PTR;
}
virtual mfxStatus FreeResources( mfxThreadTask task, mfxStatus sts ) {
task; sts;
return MFX_ERR_NULL_PTR;
}
virtual void Release() {
}
virtual mfxStatus Close() {
return MFX_ERR_NULL_PTR;
}
virtual mfxStatus SetAuxParams( void* auxParam, int auxParamSize ) {
auxParam; auxParamSize;
return MFX_ERR_NULL_PTR;
}
};
inline MFXPlugin * LoadPluginByType(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version, const mfxChar *pluginName, mfxU32 len) {
std::auto_ptr<PluginLoader> plg(new PluginLoader (type, session, uid, version, pluginName, len));
return plg->IsOk() ? plg.release() : NULL;
}
inline MFXPlugin * LoadPluginByGUID(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version) {
std::auto_ptr<PluginLoader> plg(new PluginLoader (type, session, uid, version));
return plg->IsOk() ? plg.release() : NULL;
}
inline MFXPlugin * LoadPlugin(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version, const mfxChar *pluginName, mfxU32 len) {
return LoadPluginByType(type, session, uid, version, pluginName, len);
}
inline MFXPlugin * LoadPlugin(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version) {
return LoadPluginByGUID(type, session, uid, version);
}
#endif // PLUGIN_LOADER