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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
diff --git a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
--- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
+++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.h
@@ -116,9 +116,9 @@
#ifdef MOZ_WAYLAND
const AVCodecHWConfig* (*avcodec_get_hw_config)(const AVCodec* codec,
int index);
- int (*av_hwdevice_ctx_create)(AVBufferRef** device_ctx, int type,
- const char* device, AVDictionary* opts,
- int flags);
+ AVBufferRef* (*av_hwdevice_ctx_alloc)(int);
+ int (*av_hwdevice_ctx_init)(AVBufferRef* ref);
+
AVBufferRef* (*av_buffer_ref)(AVBufferRef* buf);
void (*av_buffer_unref)(AVBufferRef** buf);
int (*av_hwframe_transfer_get_formats)(AVBufferRef* hwframe_ctx, int dir,
@@ -132,12 +132,16 @@
int (*vaExportSurfaceHandle)(void*, unsigned int, uint32_t, uint32_t, void*);
int (*vaSyncSurface)(void*, unsigned int);
+ int (*vaInitialize)(void* dpy, int* major_version, int* minor_version);
+ int (*vaTerminate)(void* dpy);
+ void* (*vaGetDisplayWl)(struct wl_display* display);
#endif
PRLibrary* mAVCodecLib;
PRLibrary* mAVUtilLib;
#ifdef MOZ_WAYLAND
PRLibrary* mVALib;
+ PRLibrary* mVALibWayland;
#endif
private:
diff --git a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegLibWrapper.cpp
@@ -159,7 +159,8 @@
AV_FUNC_OPTION(av_frame_get_color_range, AV_FUNC_AVUTIL_ALL)
#ifdef MOZ_WAYLAND
AV_FUNC_OPTION_SILENT(avcodec_get_hw_config, AV_FUNC_58)
- AV_FUNC_OPTION_SILENT(av_hwdevice_ctx_create, AV_FUNC_58)
+ AV_FUNC_OPTION_SILENT(av_hwdevice_ctx_init, AV_FUNC_58)
+ AV_FUNC_OPTION_SILENT(av_hwdevice_ctx_alloc, AV_FUNC_58)
AV_FUNC_OPTION_SILENT(av_buffer_ref, AV_FUNC_AVUTIL_58)
AV_FUNC_OPTION_SILENT(av_buffer_unref, AV_FUNC_AVUTIL_58)
AV_FUNC_OPTION_SILENT(av_hwframe_transfer_get_formats, AV_FUNC_58)
@@ -181,8 +182,21 @@
if (mVALib) {
VA_FUNC_OPTION_SILENT(vaExportSurfaceHandle)
VA_FUNC_OPTION_SILENT(vaSyncSurface)
+ VA_FUNC_OPTION_SILENT(vaInitialize)
+ VA_FUNC_OPTION_SILENT(vaTerminate)
}
-# undef VA_FUNC_OPTION
+# undef VA_FUNC_OPTION_SILENT
+
+# define VAW_FUNC_OPTION_SILENT(func) \
+ if (!(func = (decltype(func))PR_FindSymbol(mVALibWayland, #func))) { \
+ FFMPEG_LOG("Couldn't load function " #func); \
+ }
+
+ // mVALibWayland is optional and may not be present.
+ if (mVALibWayland) {
+ VAW_FUNC_OPTION_SILENT(vaGetDisplayWl)
+ }
+# undef VAW_FUNC_OPTION_SILENT
#endif
avcodec_register_all();
@@ -218,6 +232,9 @@
if (mVALib) {
PR_UnloadLibrary(mVALib);
}
+ if (mVALibWayland) {
+ PR_UnloadLibrary(mVALibWayland);
+ }
#endif
PodZero(this);
}
@@ -226,13 +243,16 @@
bool FFmpegLibWrapper::IsVAAPIAvailable() {
# define VA_FUNC_LOADED(func) (func != nullptr)
return VA_FUNC_LOADED(avcodec_get_hw_config) &&
- VA_FUNC_LOADED(av_hwdevice_ctx_create) &&
+ VA_FUNC_LOADED(av_hwdevice_ctx_alloc) &&
+ VA_FUNC_LOADED(av_hwdevice_ctx_init) &&
VA_FUNC_LOADED(av_buffer_ref) && VA_FUNC_LOADED(av_buffer_unref) &&
VA_FUNC_LOADED(av_hwframe_transfer_get_formats) &&
VA_FUNC_LOADED(av_hwdevice_ctx_create_derived) &&
VA_FUNC_LOADED(av_hwframe_ctx_alloc) && VA_FUNC_LOADED(av_dict_set) &&
VA_FUNC_LOADED(av_dict_free) &&
- VA_FUNC_LOADED(vaExportSurfaceHandle) && VA_FUNC_LOADED(vaSyncSurface);
+ VA_FUNC_LOADED(vaExportSurfaceHandle) &&
+ VA_FUNC_LOADED(vaSyncSurface) && VA_FUNC_LOADED(vaInitialize) &&
+ VA_FUNC_LOADED(vaTerminate) && VA_FUNC_LOADED(vaGetDisplayWl);
}
#endif
diff --git a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegRuntimeLinker.cpp
@@ -9,6 +9,9 @@
#include "mozilla/ArrayUtils.h"
#include "FFmpegLog.h"
#include "prlink.h"
+#ifdef MOZ_WAYLAND
+# include "gfxPlatformGtk.h"
+#endif
namespace mozilla {
@@ -54,21 +57,33 @@
}
#ifdef MOZ_WAYLAND
- {
- const char* lib = "libva.so.2";
+ if (gfxPlatformGtk::GetPlatform()->UseWaylandHardwareVideoDecoding()) {
+ const char* libWayland = "libva-wayland.so.2";
PRLibSpec lspec;
lspec.type = PR_LibSpec_Pathname;
- lspec.value.pathname = lib;
- sLibAV.mVALib = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
- // Don't use libva when it's missing vaExportSurfaceHandle.
- if (sLibAV.mVALib &&
- !PR_FindSymbol(sLibAV.mVALib, "vaExportSurfaceHandle")) {
- PR_UnloadLibrary(sLibAV.mVALib);
- sLibAV.mVALib = nullptr;
+ lspec.value.pathname = libWayland;
+ sLibAV.mVALibWayland =
+ PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
+ if (!sLibAV.mVALibWayland) {
+ FFMPEG_LOG("VA-API support: Missing or old %s library.\n", libWayland);
}
- if (!sLibAV.mVALib) {
- FFMPEG_LOG("VA-API support: Missing or old %s library.\n", lib);
+
+ if (sLibAV.mVALibWayland) {
+ const char* lib = "libva.so.2";
+ lspec.value.pathname = lib;
+ sLibAV.mVALib = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
+ // Don't use libva when it's missing vaExportSurfaceHandle.
+ if (sLibAV.mVALib &&
+ !PR_FindSymbol(sLibAV.mVALib, "vaExportSurfaceHandle")) {
+ PR_UnloadLibrary(sLibAV.mVALib);
+ sLibAV.mVALib = nullptr;
+ }
+ if (!sLibAV.mVALib) {
+ FFMPEG_LOG("VA-API support: Missing or old %s library.\n", lib);
+ }
}
+ } else {
+ FFMPEG_LOG("VA-API FFmpeg is disabled by platform");
}
#endif
diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.h
@@ -111,6 +111,7 @@
#ifdef MOZ_WAYLAND_USE_VAAPI
AVBufferRef* mVAAPIDeviceContext;
const bool mDisableHardwareDecoding;
+ VADisplay mDisplay;
#endif
RefPtr<KnowsCompositor> mImageAllocator;
RefPtr<ImageContainer> mImageContainer;
diff --git a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
--- a/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
+++ b/dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp
@@ -154,14 +154,44 @@
return nullptr;
}
+class VAAPIDisplayHolder {
+ public:
+ VAAPIDisplayHolder(FFmpegLibWrapper* aLib, VADisplay aDisplay)
+ : mLib(aLib), mDisplay(aDisplay){};
+ ~VAAPIDisplayHolder() { mLib->vaTerminate(mDisplay); }
+
+ private:
+ FFmpegLibWrapper* mLib;
+ VADisplay mDisplay;
+};
+
+static void VAAPIDisplayReleaseCallback(struct AVHWDeviceContext* hwctx) {
+ auto displayHolder = static_cast<VAAPIDisplayHolder*>(hwctx->user_opaque);
+ delete displayHolder;
+}
+
bool FFmpegVideoDecoder<LIBAV_VER>::CreateVAAPIDeviceContext() {
- AVDictionary* opts = nullptr;
- mLib->av_dict_set(&opts, "connection_type", "drm", 0);
- bool ret =
- (mLib->av_hwdevice_ctx_create(
- &mVAAPIDeviceContext, AV_HWDEVICE_TYPE_VAAPI, NULL, NULL, 0) == 0);
- mLib->av_dict_free(&opts);
- if (!ret) {
+ mVAAPIDeviceContext = mLib->av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_VAAPI);
+ if (!mVAAPIDeviceContext) {
+ return false;
+ }
+ AVHWDeviceContext* hwctx = (AVHWDeviceContext*)mVAAPIDeviceContext->data;
+ AVVAAPIDeviceContext* vactx = (AVVAAPIDeviceContext*)hwctx->hwctx;
+
+ mDisplay = mLib->vaGetDisplayWl(widget::WaylandDisplayGet()->GetDisplay());
+
+ hwctx->user_opaque = new VAAPIDisplayHolder(mLib, mDisplay);
+ hwctx->free = VAAPIDisplayReleaseCallback;
+
+ int major, minor;
+ int status = mLib->vaInitialize(mDisplay, &major, &minor);
+ if (status != VA_STATUS_SUCCESS) {
+ return false;
+ }
+
+ vactx->display = mDisplay;
+
+ if (mLib->av_hwdevice_ctx_init(mVAAPIDeviceContext) < 0) {
return false;
}
@@ -172,6 +202,11 @@
MediaResult FFmpegVideoDecoder<LIBAV_VER>::InitVAAPIDecoder() {
FFMPEG_LOG("Initialising VA-API FFmpeg decoder");
+ if (!mLib->IsVAAPIAvailable()) {
+ FFMPEG_LOG("libva library or symbols are missing.");
+ return NS_ERROR_NOT_AVAILABLE;
+ }
+
auto layersBackend = mImageAllocator
? mImageAllocator->GetCompositorBackendType()
: layers::LayersBackend::LAYERS_BASIC;
@@ -181,16 +216,6 @@
return NS_ERROR_NOT_AVAILABLE;
}
- if (!mLib->IsVAAPIAvailable()) {
- FFMPEG_LOG("libva library or symbols are missing.");
- return NS_ERROR_NOT_AVAILABLE;
- }
-
- if (!gfxPlatformGtk::GetPlatform()->UseWaylandHardwareVideoDecoding()) {
- FFMPEG_LOG("VA-API FFmpeg is disabled by platform");
- return NS_ERROR_NOT_AVAILABLE;
- }
-
AVCodec* codec = FindVAAPICodec();
if (!codec) {
FFMPEG_LOG("Couldn't find ffmpeg VA-API decoder");
@@ -275,6 +300,7 @@
#ifdef MOZ_WAYLAND_USE_VAAPI
mVAAPIDeviceContext(nullptr),
mDisableHardwareDecoding(aDisableHardwareDecoding),
+ mDisplay(nullptr),
#endif
mImageAllocator(aAllocator),
mImageContainer(aImageContainer),
@@ -606,16 +632,10 @@
" duration=%" PRId64 " opaque=%" PRId64,
aPts, mFrame->pkt_dts, aDuration, mCodecContext->reordered_opaque);
- AVHWDeviceContext* device_ctx = (AVHWDeviceContext*)mVAAPIDeviceContext->data;
- AVVAAPIDeviceContext* VAAPIDeviceContext =
- (AVVAAPIDeviceContext*)device_ctx->hwctx;
VADRMPRIMESurfaceDescriptor va_desc;
-
VASurfaceID surface_id = (VASurfaceID)(uintptr_t)mFrame->data[3];
-
VAStatus vas = mLib->vaExportSurfaceHandle(
- VAAPIDeviceContext->display, surface_id,
- VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
+ mDisplay, surface_id, VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME_2,
VA_EXPORT_SURFACE_READ_ONLY | VA_EXPORT_SURFACE_SEPARATE_LAYERS,
&va_desc);
if (vas != VA_STATUS_SUCCESS) {
@@ -623,7 +643,7 @@
NS_ERROR_OUT_OF_MEMORY,
RESULT_DETAIL("Unable to get frame by vaExportSurfaceHandle()"));
}
- vas = mLib->vaSyncSurface(VAAPIDeviceContext->display, surface_id);
+ vas = mLib->vaSyncSurface(mDisplay, surface_id);
if (vas != VA_STATUS_SUCCESS) {
NS_WARNING("vaSyncSurface() failed.");
}
diff --git a/dom/media/platforms/ffmpeg/moz.build b/dom/media/platforms/ffmpeg/moz.build
--- a/dom/media/platforms/ffmpeg/moz.build
+++ b/dom/media/platforms/ffmpeg/moz.build
@@ -20,4 +20,7 @@
'FFmpegRuntimeLinker.cpp',
]
+if CONFIG['MOZ_WAYLAND']:
+ include('/ipc/chromium/chromium-config.mozbuild')
+
FINAL_LIBRARY = 'xul'
|