From bc524c60d7fbd80f5d4758b66a35152e600ef2ad Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 27 Jan 2025 15:38:50 +0000 Subject: [PATCH] Explicit toggle for ffmpeg video player compilation --- CMakeLists.txt | 6 +++++- client/CMakeLists.txt | 5 ++--- client/media/CEmptyVideoPlayer.h | 2 ++ client/media/CVideoHandler.cpp | 6 +++++- client/media/CVideoHandler.h | 2 +- clientapp/CMakeLists.txt | 10 +++++----- clientapp/EntryPoint.cpp | 2 +- 7 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0629cf1ad..e8bdc7471 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,7 @@ endif() option(ENABLE_CLIENT "Enable compilation of game client" ON) option(ENABLE_ERM "Enable compilation of ERM scripting module" OFF) option(ENABLE_LUA "Enable compilation of LUA scripting module" OFF) +option(ENABLE_VIDEO "Enable video support using ffmpeg" ON) option(ENABLE_TRANSLATIONS "Enable generation of translations for launcher and editor" ON) option(ENABLE_NULLKILLER_AI "Enable compilation of Nullkiller AI library" ON) option(ENABLE_MINIMAL_LIB "Build only core parts of vcmi library that are required for game lobby" OFF) @@ -472,8 +473,11 @@ if(NOT FORCE_BUNDLED_MINIZIP) endif() endif() + if (ENABLE_CLIENT) - find_package(ffmpeg COMPONENTS avutil swscale avformat avcodec swresample) + if (ENABLE_VIDEO) + find_package(ffmpeg REQUIRED COMPONENTS avutil swscale avformat avcodec swresample) + endif() find_package(SDL2 REQUIRED) find_package(SDL2_image REQUIRED) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index e44f6ec5e..d0c6d028b 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -470,12 +470,11 @@ target_link_libraries(vcmiclientcommon PUBLIC vcmi SDL2::SDL2 SDL2::Image SDL2::Mixer SDL2::TTF ) -if(ffmpeg_LIBRARIES) +if(ENABLE_VIDEO) + target_compile_definitions(vcmiclientcommon PRIVATE ENABLE_VIDEO) target_link_libraries(vcmiclientcommon PRIVATE ${ffmpeg_LIBRARIES} ) -else() - target_compile_definitions(vcmiclientcommon PRIVATE DISABLE_VIDEO) endif() target_include_directories(vcmiclientcommon PUBLIC diff --git a/client/media/CEmptyVideoPlayer.h b/client/media/CEmptyVideoPlayer.h index 6497f20a2..4fdcb9d39 100644 --- a/client/media/CEmptyVideoPlayer.h +++ b/client/media/CEmptyVideoPlayer.h @@ -17,12 +17,14 @@ public: /// Load video from specified path std::unique_ptr open(const VideoPath & name, float scaleFactor) override { + logGlobal->debug("Failed to open video. Reason: video support disabled in build"); return nullptr; }; /// Extracts audio data from provided video in wav format std::pair, si64> getAudio(const VideoPath & videoToOpen) override { + logGlobal->debug("Failed to open video. Reason: video support disabled in build"); return {nullptr, 0}; }; }; diff --git a/client/media/CVideoHandler.cpp b/client/media/CVideoHandler.cpp index 84edc6943..b7e1a00a7 100644 --- a/client/media/CVideoHandler.cpp +++ b/client/media/CVideoHandler.cpp @@ -10,7 +10,7 @@ #include "StdInc.h" #include "CVideoHandler.h" -#ifndef DISABLE_VIDEO +#ifdef ENABLE_VIDEO #include "ISoundPlayer.h" @@ -671,6 +671,8 @@ std::pair, si64> CAudioInstance::extractAudio(const Vide std::unique_ptr CVideoPlayer::open(const VideoPath & name, float scaleFactor) { + logGlobal->trace("Opening video: %s", name.getOriginalName()); + auto result = std::make_unique(); if (!result->openInput(name)) @@ -687,6 +689,8 @@ std::unique_ptr CVideoPlayer::open(const VideoPath & name, float std::pair, si64> CVideoPlayer::getAudio(const VideoPath & videoToOpen) { + logGlobal->trace("Opening video: %s", videoToOpen.getOriginalName()); + AudioPath audioPath = videoToOpen.toType(); AudioPath audioPathVideoDir = audioPath.addPrefix("VIDEO/"); diff --git a/client/media/CVideoHandler.h b/client/media/CVideoHandler.h index a4229074b..5d7d8ba99 100644 --- a/client/media/CVideoHandler.h +++ b/client/media/CVideoHandler.h @@ -9,7 +9,7 @@ */ #pragma once -#ifndef DISABLE_VIDEO +#ifdef ENABLE_VIDEO #include "../lib/Point.h" #include "IVideoPlayer.h" diff --git a/clientapp/CMakeLists.txt b/clientapp/CMakeLists.txt index 40061748d..2fbed6027 100644 --- a/clientapp/CMakeLists.txt +++ b/clientapp/CMakeLists.txt @@ -42,6 +42,11 @@ target_include_directories(vcmiclient PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) +if(ENABLE_VIDEO) + target_compile_definitions(vcmiclient PRIVATE ENABLE_VIDEO) +endif() + + if(WIN32) target_sources(vcmiclient PRIVATE "VCMI_client.rc") set_target_properties(vcmiclient @@ -56,11 +61,6 @@ if(WIN32) endif() target_compile_definitions(vcmiclient PRIVATE WINDOWS_IGNORE_PACKING_MISMATCH) - if(NOT ffmpeg_LIBRARIES) - target_compile_definitions(vcmiclient PRIVATE DISABLE_VIDEO) - endif() - - # TODO: very hacky, find proper solution to copy AI dlls into bin dir if(MSVC) add_custom_command(TARGET vcmiclient POST_BUILD diff --git a/clientapp/EntryPoint.cpp b/clientapp/EntryPoint.cpp index 64a7043ef..ac1429219 100644 --- a/clientapp/EntryPoint.cpp +++ b/clientapp/EntryPoint.cpp @@ -308,7 +308,7 @@ int main(int argc, char * argv[]) CSH = new CServerHandler(); // Initialize video -#ifdef DISABLE_VIDEO +#ifndef ENABLE_VIDEO CCS->videoh = new CEmptyVideoPlayer(); #else if (!settings["session"]["headless"].Bool() && !vm.count("disable-video"))