summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Stransky <stransky@redhat.com>2020-05-05 14:01:50 +0200
committerMartin Stransky <stransky@redhat.com>2020-05-05 14:01:50 +0200
commitcb1655cd55c2837ce98fd7ec62e577c833cfeef9 (patch)
treee3f20d8294810fb86973e255b5c227c03cb13fe0
parentDon't use google safe browsing api key for the geolocation (diff)
downloadlibrewolf-fedora-ff-cb1655cd55c2837ce98fd7ec62e577c833cfeef9.tar.gz
librewolf-fedora-ff-cb1655cd55c2837ce98fd7ec62e577c833cfeef9.tar.bz2
librewolf-fedora-ff-cb1655cd55c2837ce98fd7ec62e577c833cfeef9.zip
Added va-api patches
-rw-r--r--firefox.spec13
-rw-r--r--mozilla-1619543.patch97
-rw-r--r--mozilla-1625431.patch20
-rw-r--r--mozilla-1628690.patch67
-rw-r--r--mozilla-1630754.patch298
-rw-r--r--mozilla-1632059.patch41
6 files changed, 536 insertions, 0 deletions
diff --git a/firefox.spec b/firefox.spec
index 21c1d1f..67449a5 100644
--- a/firefox.spec
+++ b/firefox.spec
@@ -187,6 +187,13 @@ Patch422: mozilla-1580174-webrtc-popup.patch
# Wayland specific upstream patches
Patch574: firefox-pipewire.patch
+#VA-API patches
+Patch579: mozilla-1625431.patch
+Patch580: mozilla-1628690.patch
+Patch581: mozilla-1630754.patch
+Patch582: mozilla-1619543.patch
+Patch583: mozilla-1632059.patch
+
# PGO/LTO patches
Patch600: pgo.patch
Patch601: mozilla-1516081.patch
@@ -392,6 +399,12 @@ This package contains results of tests executed during build.
# Wayland specific upstream patches
%patch574 -p1 -b .firefox-pipewire
+%patch580 -p1 -b .mozilla-1628690
+%patch582 -p1 -b .mozilla-1619543
+%patch579 -p1 -b .mozilla-1625431
+%patch581 -p1 -b .mozilla-1630754
+%patch583 -p1 -b .mozilla-1632059
+
# PGO patches
%patch600 -p1 -b .pgo
#fix
diff --git a/mozilla-1619543.patch b/mozilla-1619543.patch
new file mode 100644
index 0000000..7dc1e86
--- /dev/null
+++ b/mozilla-1619543.patch
@@ -0,0 +1,97 @@
+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
+@@ -101,17 +101,22 @@
+ : LinkResult::UnknownFutureLibAVVersion;
+ }
+
+-#define AV_FUNC_OPTION(func, ver) \
++#define AV_FUNC_OPTION_SILENT(func, ver) \
+ if ((ver)&version) { \
+ if (!(func = (decltype(func))PR_FindSymbol( \
+ ((ver)&AV_FUNC_AVUTIL_MASK) ? mAVUtilLib : mAVCodecLib, \
+ #func))) { \
+- FFMPEG_LOG("Couldn't load function " #func); \
+ } \
+ } else { \
+ func = (decltype(func)) nullptr; \
+ }
+
++#define AV_FUNC_OPTION(func, ver) \
++ AV_FUNC_OPTION_SILENT(func, ver) \
++ if ((ver)&version && (func) == (decltype(func)) nullptr) { \
++ FFMPEG_LOG("Couldn't load function " #func); \
++ }
++
+ #define AV_FUNC(func, ver) \
+ AV_FUNC_OPTION(func, ver) \
+ if ((ver)&version && !func) { \
+@@ -153,30 +158,29 @@
+ AV_FUNC_OPTION(av_frame_get_colorspace, AV_FUNC_AVUTIL_ALL)
+ AV_FUNC_OPTION(av_frame_get_color_range, AV_FUNC_AVUTIL_ALL)
+ #ifdef MOZ_WAYLAND
+- AV_FUNC_OPTION(avcodec_get_hw_config, AV_FUNC_58)
+- AV_FUNC_OPTION(av_hwdevice_ctx_create, AV_FUNC_58)
+- AV_FUNC_OPTION(av_buffer_ref, AV_FUNC_AVUTIL_58)
+- AV_FUNC_OPTION(av_buffer_unref, AV_FUNC_AVUTIL_58)
+- AV_FUNC_OPTION(av_hwframe_transfer_get_formats, AV_FUNC_58)
+- AV_FUNC_OPTION(av_hwdevice_ctx_create_derived, AV_FUNC_58)
+- AV_FUNC_OPTION(av_hwframe_ctx_alloc, AV_FUNC_58)
+- AV_FUNC_OPTION(av_dict_set, AV_FUNC_58)
+- AV_FUNC_OPTION(av_dict_free, AV_FUNC_58)
++ 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_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)
++ AV_FUNC_OPTION_SILENT(av_hwdevice_ctx_create_derived, AV_FUNC_58)
++ AV_FUNC_OPTION_SILENT(av_hwframe_ctx_alloc, AV_FUNC_58)
++ AV_FUNC_OPTION_SILENT(av_dict_set, AV_FUNC_58)
++ AV_FUNC_OPTION_SILENT(av_dict_free, AV_FUNC_58)
+ #endif
+ #undef AV_FUNC
+ #undef AV_FUNC_OPTION
+
+ #ifdef MOZ_WAYLAND
+-# define VA_FUNC_OPTION(func) \
++# define VA_FUNC_OPTION_SILENT(func) \
+ if (!(func = (decltype(func))PR_FindSymbol(mVALib, #func))) { \
+- FFMPEG_LOG("Couldn't load function " #func); \
+ func = (decltype(func)) nullptr; \
+ }
+
+ // mVALib is optional and may not be present.
+ if (mVALib) {
+- VA_FUNC_OPTION(vaExportSurfaceHandle)
+- VA_FUNC_OPTION(vaSyncSurface)
++ VA_FUNC_OPTION_SILENT(vaExportSurfaceHandle)
++ VA_FUNC_OPTION_SILENT(vaSyncSurface)
+ }
+ # undef VA_FUNC_OPTION
+ #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
+@@ -66,6 +66,9 @@
+ PR_UnloadLibrary(sLibAV.mVALib);
+ sLibAV.mVALib = nullptr;
+ }
++ if (!sLibAV.mVALib) {
++ FFMPEG_LOG("VA-API support: Missing or old %s library.\n", lib);
++ }
+ }
+ #endif
+
+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
+@@ -173,7 +173,7 @@
+ FFMPEG_LOG("Initialising VA-API FFmpeg decoder");
+
+ if (!mLib->IsVAAPIAvailable()) {
+- FFMPEG_LOG("libva library is missing");
++ FFMPEG_LOG("libva library or symbols are missing.");
+ return NS_ERROR_NOT_AVAILABLE;
+ }
+
+
diff --git a/mozilla-1625431.patch b/mozilla-1625431.patch
new file mode 100644
index 0000000..c0e6d3a
--- /dev/null
+++ b/mozilla-1625431.patch
@@ -0,0 +1,20 @@
+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
+@@ -172,6 +172,15 @@
+ MediaResult FFmpegVideoDecoder<LIBAV_VER>::InitVAAPIDecoder() {
+ FFMPEG_LOG("Initialising VA-API FFmpeg decoder");
+
++ auto layersBackend = mImageAllocator
++ ? mImageAllocator->GetCompositorBackendType()
++ : layers::LayersBackend::LAYERS_BASIC;
++ if (layersBackend != layers::LayersBackend::LAYERS_OPENGL &&
++ layersBackend != layers::LayersBackend::LAYERS_WR) {
++ FFMPEG_LOG("VA-API works with HW accelerated backend only!");
++ return NS_ERROR_NOT_AVAILABLE;
++ }
++
+ if (!mLib->IsVAAPIAvailable()) {
+ FFMPEG_LOG("libva library or symbols are missing.");
+ return NS_ERROR_NOT_AVAILABLE;
+
diff --git a/mozilla-1628690.patch b/mozilla-1628690.patch
new file mode 100644
index 0000000..3a1757d
--- /dev/null
+++ b/mozilla-1628690.patch
@@ -0,0 +1,67 @@
+diff --git a/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h b/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h
+--- a/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h
++++ b/dom/media/platforms/ffmpeg/FFmpegDecoderModule.h
+@@ -49,7 +49,9 @@
+ RefPtr<MediaDataDecoder> decoder = new FFmpegVideoDecoder<V>(
+ mLib, aParams.mTaskQueue, aParams.VideoConfig(),
+ aParams.mKnowsCompositor, aParams.mImageContainer,
+- aParams.mOptions.contains(CreateDecoderParams::Option::LowLatency));
++ aParams.mOptions.contains(CreateDecoderParams::Option::LowLatency),
++ aParams.mOptions.contains(
++ CreateDecoderParams::Option::HardwareDecoderNotAllowed));
+ return decoder.forget();
+ }
+
+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
+@@ -48,7 +48,8 @@
+ public:
+ FFmpegVideoDecoder(FFmpegLibWrapper* aLib, TaskQueue* aTaskQueue,
+ const VideoInfo& aConfig, KnowsCompositor* aAllocator,
+- ImageContainer* aImageContainer, bool aLowLatency);
++ ImageContainer* aImageContainer, bool aLowLatency,
++ bool aDisableHardwareDecoding);
+
+ RefPtr<InitPromise> Init() override;
+ void InitCodecContext() override;
+@@ -109,6 +110,7 @@
+
+ #ifdef MOZ_WAYLAND_USE_VAAPI
+ AVBufferRef* mVAAPIDeviceContext;
++ const bool mDisableHardwareDecoding;
+ #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
+@@ -270,10 +270,11 @@
+ FFmpegVideoDecoder<LIBAV_VER>::FFmpegVideoDecoder(
+ FFmpegLibWrapper* aLib, TaskQueue* aTaskQueue, const VideoInfo& aConfig,
+ KnowsCompositor* aAllocator, ImageContainer* aImageContainer,
+- bool aLowLatency)
++ bool aLowLatency, bool aDisableHardwareDecoding)
+ : FFmpegDataDecoder(aLib, aTaskQueue, GetCodecId(aConfig.mMimeType)),
+ #ifdef MOZ_WAYLAND_USE_VAAPI
+ mVAAPIDeviceContext(nullptr),
++ mDisableHardwareDecoding(aDisableHardwareDecoding),
+ #endif
+ mImageAllocator(aAllocator),
+ mImageContainer(aImageContainer),
+@@ -289,9 +290,11 @@
+ MediaResult rv;
+
+ #ifdef MOZ_WAYLAND_USE_VAAPI
+- rv = InitVAAPIDecoder();
+- if (NS_SUCCEEDED(rv)) {
+- return InitPromise::CreateAndResolve(TrackInfo::kVideoTrack, __func__);
++ if (!mDisableHardwareDecoding) {
++ rv = InitVAAPIDecoder();
++ if (NS_SUCCEEDED(rv)) {
++ return InitPromise::CreateAndResolve(TrackInfo::kVideoTrack, __func__);
++ }
+ }
+ #endif
+
+
diff --git a/mozilla-1630754.patch b/mozilla-1630754.patch
new file mode 100644
index 0000000..b8b9922
--- /dev/null
+++ b/mozilla-1630754.patch
@@ -0,0 +1,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'
+
diff --git a/mozilla-1632059.patch b/mozilla-1632059.patch
new file mode 100644
index 0000000..b051e98
--- /dev/null
+++ b/mozilla-1632059.patch
@@ -0,0 +1,41 @@
+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
+@@ -178,7 +178,12 @@
+ AVHWDeviceContext* hwctx = (AVHWDeviceContext*)mVAAPIDeviceContext->data;
+ AVVAAPIDeviceContext* vactx = (AVVAAPIDeviceContext*)hwctx->hwctx;
+
+- mDisplay = mLib->vaGetDisplayWl(widget::WaylandDisplayGet()->GetDisplay());
++ wl_display* display = widget::WaylandDisplayGetWLDisplay();
++ if (!display) {
++ FFMPEG_LOG("Can't get default wayland display.");
++ return false;
++ }
++ mDisplay = mLib->vaGetDisplayWl(display);
+
+ hwctx->user_opaque = new VAAPIDisplayHolder(mLib, mDisplay);
+ hwctx->free = VAAPIDisplayReleaseCallback;
+diff --git a/widget/gtk/nsWaylandDisplay.cpp b/widget/gtk/nsWaylandDisplay.cpp
+--- a/widget/gtk/nsWaylandDisplay.cpp
++++ b/widget/gtk/nsWaylandDisplay.cpp
+@@ -35,6 +35,9 @@
+ wl_display* WaylandDisplayGetWLDisplay(GdkDisplay* aGdkDisplay) {
+ if (!aGdkDisplay) {
+ aGdkDisplay = gdk_display_get_default();
++ if (!aGdkDisplay || GDK_IS_X11_DISPLAY(aGdkDisplay)) {
++ return nullptr;
++ }
+ }
+
+ // Available as of GTK 3.8+
+@@ -537,8 +540,7 @@
+ StaticPrefs::widget_wayland_dmabuf_webgl_enabled();
+ }
+ bool nsWaylandDisplay::IsDMABufVAAPIEnabled() {
+- return IsDMABufEnabled() &&
+- StaticPrefs::widget_wayland_dmabuf_vaapi_enabled();
++ return StaticPrefs::widget_wayland_dmabuf_vaapi_enabled();
+ }
+
+ void* nsGbmLib::sGbmLibHandle = nullptr;
+
bgstack15