mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Add check for vaapi/vdpau libraries before loading them with implib
This commit is contained in:
parent
249f0890df
commit
404ce2e011
1 changed files with 48 additions and 0 deletions
|
@ -18,6 +18,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <libavutil/opt.h>
|
#include <libavutil/opt.h>
|
||||||
|
#if !defined DESKTOP_APP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
|
||||||
|
#include <dlfcn.h>
|
||||||
|
#endif // !DESKTOP_APP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
||||||
namespace FFmpeg {
|
namespace FFmpeg {
|
||||||
|
@ -85,6 +88,47 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
|
||||||
#endif // LIB_FFMPEG_USE_QT_PRIVATE_API
|
#endif // LIB_FFMPEG_USE_QT_PRIVATE_API
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined DESKTOP_APP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
|
||||||
|
[[nodiscard]] auto CheckHwLibs() {
|
||||||
|
auto list = std::deque{
|
||||||
|
AV_PIX_FMT_CUDA,
|
||||||
|
};
|
||||||
|
const auto vdpau = [&] {
|
||||||
|
if (const auto handle = dlopen("libvdpau.so.1", RTLD_LAZY)) {
|
||||||
|
dlclose(handle);
|
||||||
|
}
|
||||||
|
if (dlerror()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
if (vdpau) {
|
||||||
|
list.push_front(AV_PIX_FMT_VDPAU);
|
||||||
|
}
|
||||||
|
const auto va = [&] {
|
||||||
|
const auto list = std::array{
|
||||||
|
"libva-drm.so.1",
|
||||||
|
"libva-x11.so.1",
|
||||||
|
"libva.so.1",
|
||||||
|
"libdrm.so.2",
|
||||||
|
};
|
||||||
|
for (const auto lib : list) {
|
||||||
|
if (const auto handle = dlopen(lib, RTLD_LAZY)) {
|
||||||
|
dlclose(handle);
|
||||||
|
}
|
||||||
|
if (dlerror()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}();
|
||||||
|
if (va) {
|
||||||
|
list.push_front(AV_PIX_FMT_VAAPI);
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
#endif // !DESKTOP_APP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
|
||||||
|
|
||||||
[[nodiscard]] bool InitHw(AVCodecContext *context, AVHWDeviceType type) {
|
[[nodiscard]] bool InitHw(AVCodecContext *context, AVHWDeviceType type) {
|
||||||
AVCodecContext *parent = static_cast<AVCodecContext*>(context->opaque);
|
AVCodecContext *parent = static_cast<AVCodecContext*>(context->opaque);
|
||||||
|
|
||||||
|
@ -125,6 +169,9 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
#if !defined DESKTOP_APP_USE_PACKAGED && !defined Q_OS_WIN && !defined Q_OS_MAC
|
||||||
|
static const auto list = CheckHwLibs();
|
||||||
|
#else // !DESKTOP_APP_USE_PACKAGED && !Q_OS_WIN && !Q_OS_MAC
|
||||||
const auto list = std::array{
|
const auto list = std::array{
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
AV_PIX_FMT_D3D11,
|
AV_PIX_FMT_D3D11,
|
||||||
|
@ -138,6 +185,7 @@ void PremultiplyLine(uchar *dst, const uchar *src, int intsCount) {
|
||||||
AV_PIX_FMT_CUDA,
|
AV_PIX_FMT_CUDA,
|
||||||
#endif // Q_OS_WIN || Q_OS_MAC
|
#endif // Q_OS_WIN || Q_OS_MAC
|
||||||
};
|
};
|
||||||
|
#endif // DESKTOP_APP_USE_PACKAGED || Q_OS_WIN || Q_OS_MAC
|
||||||
for (const auto format : list) {
|
for (const auto format : list) {
|
||||||
if (!has(format)) {
|
if (!has(format)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Add table
Reference in a new issue