Bug 1660336 Implement FFmpegLibWrapper::LinkVAAPILibs() to link VAAPI libraries and use at at FFmpegRuntimeLinker/FFVPXRuntimeLinker, r=jya

Differential Revision: https://phabricator.services.mozilla.com/D90556
This commit is contained in:
Martin Stransky 2020-11-05 07:38:26 +00:00
Родитель 78ed8d65db
Коммит 84655dbdb1
4 изменённых файлов: 55 добавлений и 44 удалений

Просмотреть файл

@ -11,6 +11,9 @@
#include "mozilla/Types.h"
#include "PlatformDecoderModule.h"
#include "prlink.h"
#ifdef MOZ_WAYLAND
# include "gfxPlatformGtk.h"
#endif
#define AV_LOG_DEBUG 48
#define AV_LOG_INFO 32
@ -253,6 +256,52 @@ void FFmpegLibWrapper::Unlink() {
PodZero(this);
}
#ifdef MOZ_WAYLAND
void FFmpegLibWrapper::LinkVAAPILibs() {
if (gfxPlatformGtk::GetPlatform()->UseHardwareVideoDecoding()) {
PRLibSpec lspec;
lspec.type = PR_LibSpec_Pathname;
if (gfxPlatformGtk::GetPlatform()->UseDRMVAAPIDisplay()) {
const char* libDrm = "libva-drm.so.2";
lspec.value.pathname = libDrm;
mVALibDrm = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
if (!mVALibDrm) {
FFMPEG_LOG("VA-API support: Missing or old %s library.\n", libDrm);
}
} else {
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
const char* libWayland = "libva-wayland.so.2";
lspec.value.pathname = libWayland;
mVALibWayland = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
if (!mVALibWayland) {
FFMPEG_LOG("VA-API support: Missing or old %s library.\n",
libWayland);
}
} else {
FFMPEG_LOG("VA-API X11 display is not implemented.\n");
}
}
if (mVALibWayland || mVALibDrm) {
const char* lib = "libva.so.2";
lspec.value.pathname = lib;
mVALib = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
// Don't use libva when it's missing vaExportSurfaceHandle.
if (mVALib && !PR_FindSymbol(mVALib, "vaExportSurfaceHandle")) {
PR_UnloadLibrary(mVALib);
mVALib = nullptr;
}
if (!mVALib) {
FFMPEG_LOG("VA-API support: Missing or old %s library.\n", lib);
}
}
} else {
FFMPEG_LOG("VA-API FFmpeg is disabled by platform");
}
}
#endif
#ifdef MOZ_WAYLAND
bool FFmpegLibWrapper::IsVAAPIAvailable() {
# define VA_FUNC_LOADED(func) (func != nullptr)

Просмотреть файл

@ -56,6 +56,7 @@ struct MOZ_ONLY_USED_TO_AVOID_STATIC_CONSTRUCTORS FFmpegLibWrapper {
#ifdef MOZ_WAYLAND
// Check if mVALib are available and we can use HW decode.
bool IsVAAPIAvailable();
void LinkVAAPILibs();
#endif
// indicate the version of libavcodec linked to.

Просмотреть файл

@ -57,50 +57,7 @@ bool FFmpegRuntimeLinker::Init() {
}
#ifdef MOZ_WAYLAND
if (gfxPlatformGtk::GetPlatform()->UseHardwareVideoDecoding()) {
PRLibSpec lspec;
lspec.type = PR_LibSpec_Pathname;
if (gfxPlatformGtk::GetPlatform()->UseDRMVAAPIDisplay()) {
const char* libDrm = "libva-drm.so.2";
lspec.value.pathname = libDrm;
sLibAV.mVALibDrm =
PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
if (!sLibAV.mVALibDrm) {
FFMPEG_LOG("VA-API support: Missing or old %s library.\n", libDrm);
}
} else {
if (gfxPlatformGtk::GetPlatform()->IsWaylandDisplay()) {
const char* libWayland = "libva-wayland.so.2";
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);
}
} else {
FFMPEG_LOG("VA-API X11 display is not implemented.\n");
}
}
if (sLibAV.mVALibWayland || sLibAV.mVALibDrm) {
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");
}
sLibAV.LinkVAAPILibs();
#endif
// While going through all possible libs, this status will be updated with a

Просмотреть файл

@ -64,6 +64,10 @@ bool FFVPXRuntimeLinker::Init() {
MOZ_ASSERT(NS_IsMainThread());
sLinkStatus = LinkStatus_FAILED;
#ifdef MOZ_WAYLAND
sFFVPXLib.LinkVAAPILibs();
#endif
// We retrieve the path of the lgpllibs library as this is where mozavcodec
// and mozavutil libs are located.
PathString lgpllibsname = GetLibraryName(nullptr, "lgpllibs");