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
|
/* vce_common.c
*
* Copyright (c) 2003-2020 HandBrake Team
* This file is part of the HandBrake source code.
* Homepage: <http://handbrake.fr/>.
* It may be used under the terms of the GNU General Public License v2.
* For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
*/
#include "handbrake/project.h"
#if HB_PROJECT_FEATURE_VCE
#include "AMF/core/Factory.h"
#include "AMF/components/VideoEncoderVCE.h"
#include "AMF/components/VideoEncoderHEVC.h"
#include "handbrake/handbrake.h"
AMF_RESULT check_component_available(const wchar_t *componentID)
{
amf_handle libHandle = NULL;
AMFInit_Fn initFun;
AMFFactory *factory = NULL;
AMFContext *context = NULL;
AMFContext1 *context1 = NULL;
AMFComponent *encoder = NULL;
AMFCaps *encoderCaps = NULL;
AMF_RESULT result = AMF_FAIL;
libHandle = hb_dlopen(AMF_DLL_NAMEA);
if(!libHandle)
{
result = AMF_FAIL;
goto clean;
}
initFun = (AMFInit_Fn)(hb_dlsym(libHandle, AMF_INIT_FUNCTION_NAME));
if(!initFun)
{
result = AMF_FAIL;
hb_error("VCE: Load Library Failed");
goto clean;
}
result = initFun(AMF_FULL_VERSION, &factory);
if(result != AMF_OK)
{
hb_error("VCE: Init Failed");
goto clean;
}
result = factory->pVtbl->CreateContext(factory, &context);
if(result != AMF_OK)
{
hb_error("VCE: Context Failed");
goto clean;
}
result = context->pVtbl->InitDX11(context, NULL, AMF_DX11_1);
if (result != AMF_OK) {
result = context->pVtbl->InitDX9(context, NULL);
if (result != AMF_OK) {
AMFGuid guid = IID_AMFContext1();
result = context->pVtbl->QueryInterface(context, &guid, (void**)&context1);
if (result != AMF_OK) {
hb_error("VCE: CreateContext1() failed");
goto clean;
}
result = context1->pVtbl->InitVulkan(context1, NULL);
if (result != AMF_OK) {
if (result == AMF_NOT_SUPPORTED)
hb_error("VCE: AMF via Vulkan is not supported on the given device.\n");
else
hb_error("VCE: AMF failed to initialise on the given Vulkan device.\n");
goto clean;
}
}
}
result = factory->pVtbl->CreateComponent(factory, context, componentID, &encoder);
if(result != AMF_OK)
{
goto clean;
}
result = encoder->pVtbl->GetCaps(encoder, &encoderCaps);
clean:
if (encoderCaps)
{
encoderCaps->pVtbl->Clear(encoderCaps);
encoderCaps->pVtbl->Release(encoderCaps);
encoderCaps = NULL;
}
if (encoder)
{
encoder->pVtbl->Terminate(encoder);
encoder->pVtbl->Release(encoder);
encoder = NULL;
}
if (context)
{
context->pVtbl->Terminate(context);
context->pVtbl->Release(context);
context = NULL;
}
if (context1)
{
context1->pVtbl->Terminate(context1);
context1->pVtbl->Release(context1);
context1 = NULL;
}
if(libHandle)
{
hb_dlclose(libHandle);
}
return result;
}
int hb_vce_h264_available()
{
if (is_hardware_disabled())
{
return 0;
}
return (check_component_available(AMFVideoEncoderVCE_AVC) == AMF_OK) ? 1 : 0;
}
int hb_vce_h265_available()
{
if (is_hardware_disabled())
{
return 0;
}
return (check_component_available(AMFVideoEncoder_HEVC) == AMF_OK) ? 1 : 0;
}
#else // !HB_PROJECT_FEATURE_VCE
int hb_vce_h264_available()
{
return 0;
}
int hb_vce_h265_available()
{
return 0;
}
#endif // HB_PROJECT_FEATURE_VCE
|