From 1f17f32b076f9f22fafa087095e446b3167f8d74 Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Mon, 26 Nov 2018 19:03:37 +0000 Subject: [PATCH] [Backend+Cmake] Improved newer MPV version checking. --- CMakeLists.txt | 9 +++++++-- src/MpvPlayerBackend.cpp | 3 --- src/MpvPlayerBackend.h | 11 ++--------- src/main.cpp | 40 +++++++++++++++++++++------------------- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a78ebc8..50cb1f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,15 +21,20 @@ pkg_check_modules(MPV REQUIRED mpv) pkg_check_modules(X11 REQUIRED x11) pkg_check_modules(Xext REQUIRED xext) - set(SOURCES src/main.cpp - src/MpvPlayerBackend.cpp src/DirectMpvPlayerBackend.cpp src/utils.cpp src/enums.hpp ) + +if(MPV_VERSION VERSION_GREATER_EQUAL "1.28.0") +set(SOURCES ${SOURCES} src/MpvPlayerBackend.cpp) +else() +add_definitions(-DDISABLE_MpvPlayerBackend) +endif(MPV_VERSION VERSION_GREATER_EQUAL "1.28.0") + find_program(CCACHE_FOUND ccache) if(CCACHE_FOUND) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index 1e659fe..6f31b6c 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -4,8 +4,6 @@ #include "MpvPlayerBackend.h" -#ifndef DISABLE_MpvPlayerBackend - #include "utils.hpp" #include #include @@ -584,4 +582,3 @@ MpvPlayerBackend::createRenderer() const return new MpvRenderer(const_cast(this)); } -#endif diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h index ee59b92..c8161b8 100644 --- a/src/MpvPlayerBackend.h +++ b/src/MpvPlayerBackend.h @@ -1,13 +1,8 @@ -#include -#include - -#if MPV_CLIENT_API_VERSION <= MPV_MAKE_VERSION(1, 27) -#define DISABLE_MpvPlayerBackend -#endif - #ifndef MpvPlayerBackend_H #define MpvPlayerBackend_H +#include +#include #include @@ -30,9 +25,7 @@ class MpvPlayerBackend Q_OBJECT mpv_handle* mpv; -#ifndef DISABLE_MpvPlayerBackend mpv_render_context* mpv_gl; -#endif bool onTop = false; QString totalDurationString; diff --git a/src/main.cpp b/src/main.cpp index 609f5b7..5de26f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,9 @@ #endif #include "DirectMpvPlayerBackend.h" +#ifndef DISABLE_MpvPlayerBackend #include "MpvPlayerBackend.h" +#endif #include "enums.hpp" #include "utils.hpp" @@ -104,22 +106,23 @@ main(int argc, char* argv[]) QSettings settings; QString backendSetting = settings.value("Backend/backend", "").toString(); if (backendSetting.length() == 0) { -#ifndef DISABLE_MpvPlayerBackend - settings.setValue("Backend/backend", "mpv"); -#else - settings.setValue("Backend/backend", "direct-mpv"); -#endif + #ifndef DISABLE_MpvPlayerBackend + settings.setValue("Backend/backend", "mpv"); + #else + settings.setValue("Backend/backend", "direct-mpv"); + #endif } - qDebug() << backendSetting; + qDebug() << backendSetting; for (int i = 1; i < argc; ++i) { if (!qstrcmp(argv[i], "--update")) { Utils::updateAppImage(); - } else if (!qstrcmp(argv[i], "--backend=mpv") || backendSetting == "mpv") { + } + else if (!qstrcmp(argv[i], "--backend=mpv") || backendSetting == "mpv") { backend = Enums::Backends::MpvBackend; - } else if (!qstrcmp(argv[i], "--backend=direct-mpv") || - backendSetting == "direct-mpv") { + } + else if (!qstrcmp(argv[i], "--backend=direct-mpv") || backendSetting == "direct-mpv") { backend = Enums::Backends::DirectMpvBackend; } } @@ -138,20 +141,19 @@ main(int argc, char* argv[]) qRegisterMetaType("Enums.Backends"); qRegisterMetaType("Enums.Commands"); - + qmlRegisterType("player", 1, 0, "Utils"); switch (backend) { case Enums::Backends::MpvBackend: { -#ifndef DISABLE_MpvPlayerBackend - qmlRegisterType("player", 1, 0, "PlayerBackend"); -#else - qDebug() << "Normal MPV backend not available, resetting backend option " - "to blank."; - settings.setValue("Backend/backend", "direct-mpv"); - app.exit(); -#endif - break; + #ifndef DISABLE_MpvPlayerBackend + qmlRegisterType("player", 1, 0, "PlayerBackend"); + #else + qDebug() << "Normal MPV backend not available, resetting backend option to blank."; + settings.setValue("Backend/backend", "direct-mpv"); + app.exit(); + #endif + break; } case Enums::Backends::DirectMpvBackend: { qmlRegisterType("player", 1, 0, "PlayerBackend");