From 8d5728097b69bd65af02bb08545f681edf9bc4fe Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 6 Jun 2023 18:24:58 +1000 Subject: [PATCH] CMake: Add USE_LINKED_FFMPEG option --- cmake/BuildParameters.cmake | 1 + pcsx2/CMakeLists.txt | 5 +++++ pcsx2/GS/GSCapture.cpp | 29 +++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/cmake/BuildParameters.cmake b/cmake/BuildParameters.cmake index 83a919e1ab..86faa71939 100644 --- a/cmake/BuildParameters.cmake +++ b/cmake/BuildParameters.cmake @@ -36,6 +36,7 @@ if(UNIX AND NOT APPLE) option(X11_API "Enable X11 support" ON) option(WAYLAND_API "Enable Wayland support" ON) option(DBUS_API "Enable DBus support for screensaver inhibiting" ON) + option(USE_LINKED_FFMPEG "Links with ffmpeg instead of using dynamic loading" OFF) endif() if(APPLE) diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index 462ca37249..6c12e7e75c 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -51,6 +51,11 @@ if(USE_LEGACY_USER_DIRECTORY) target_compile_definitions(PCSX2_FLAGS INTERFACE USE_LEGACY_USER_DIRECTORY) endif() +if(USE_LINKED_FFMPEG) + target_compile_definitions(PCSX2_FLAGS INTERFACE USE_LINKED_FFMPEG) + target_link_libraries(PCSX2_FLAGS INTERFACE FFMPEG::avcodec FFMPEG::avformat FFMPEG::avutil FFMPEG::swscale FFMPEG::swresample) +endif() + if(TARGET SDL2::SDL2 OR TARGET SDL2::SDL2-static) target_compile_definitions(PCSX2_FLAGS INTERFACE SDL_BUILD) if ("${SDL2_TYPE}" STREQUAL Bundled) diff --git a/pcsx2/GS/GSCapture.cpp b/pcsx2/GS/GSCapture.cpp index 4248c27b82..b821385bd3 100644 --- a/pcsx2/GS/GSCapture.cpp +++ b/pcsx2/GS/GSCapture.cpp @@ -93,9 +93,7 @@ extern "C" { X(av_frame_make_writable) \ X(av_strerror) \ X(av_reduce) \ - X(av_dict_get_string) \ X(av_dict_parse_string) \ - X(av_dict_set) \ X(av_dict_free) \ X(av_opt_set_int) \ X(av_opt_set_sample_fmt) \ @@ -139,7 +137,6 @@ namespace GSCapture static void LogAVError(int errnum, const char* format, ...); static bool LoadFFmpeg(bool report_errors); - static void UnloadFFmpeg(std::unique_lock& lock); static void UnloadFFmpeg(); static std::string GetCaptureTypeForMessage(bool capture_video, bool capture_audio); static void ProcessFramePendingMap(std::unique_lock& lock); @@ -198,7 +195,11 @@ namespace GSCapture alignas(64) static u32 s_audio_buffer_read_pos = 0; } // namespace GSCapture +#ifndef USE_LINKED_FFMPEG #define DECLARE_IMPORT(X) static decltype(X)* wrap_##X; +#else +#define DECLARE_IMPORT(X) static constexpr decltype(X)* wrap_##X = X; +#endif VISIT_AVCODEC_IMPORTS(DECLARE_IMPORT); VISIT_AVFORMAT_IMPORTS(DECLARE_IMPORT); VISIT_AVUTIL_IMPORTS(DECLARE_IMPORT); @@ -208,6 +209,9 @@ VISIT_SWRESAMPLE_IMPORTS(DECLARE_IMPORT); // We could refcount this, but really, may as well just load it and pay the cost once. // Not like we need to save a few megabytes of memory... +#ifndef USE_LINKED_FFMPEG +static void UnloadFFmpegFunctions(std::unique_lock& lock); + static Common::DynamicLibrary s_avcodec_library; static Common::DynamicLibrary s_avformat_library; static Common::DynamicLibrary s_avutil_library; @@ -261,7 +265,7 @@ bool GSCapture::LoadFFmpeg(bool report_errors) return true; } - UnloadFFmpeg(lock); + UnloadFFmpegFunctions(lock); lock.unlock(); if (report_errors) @@ -279,7 +283,7 @@ bool GSCapture::LoadFFmpeg(bool report_errors) return false; } -void GSCapture::UnloadFFmpeg(std::unique_lock& lock) +void UnloadFFmpegFunctions(std::unique_lock& lock) { #define CLEAR_IMPORT(X) wrap_##X = nullptr; VISIT_AVCODEC_IMPORTS(CLEAR_IMPORT); @@ -303,9 +307,22 @@ void GSCapture::UnloadFFmpeg() return; s_library_loaded = false; - UnloadFFmpeg(lock); + UnloadFFmpegFunctions(lock); } +#else + +bool GSCapture::LoadFFmpeg(bool report_errors) +{ + return true; +} + +void GSCapture::UnloadFFmpeg() +{ +} + +#endif + void GSCapture::LogAVError(int errnum, const char* format, ...) { va_list ap;