Skip to content

Commit

Permalink
Qt6 Port
Browse files Browse the repository at this point in the history
Mostly a sync-up with phonon-vlc to enable multibuild with Qt6.
  • Loading branch information
OpenProgger committed Dec 2, 2023
1 parent 2106128 commit 384ae0a
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 67 deletions.
84 changes: 55 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,75 @@ project(PhononMPV VERSION 0.0.7)

set(CMAKE_CXX_STANDARD 17)

option(PHONON_BUILD_QT5 "Build for Qt5" ON)
option(PHONON_BUILD_QT6 "Build for Qt6" OFF)

set(VERSIONS)
if(PHONON_BUILD_QT5)
list(APPEND VERSIONS "5")
endif()
if(PHONON_BUILD_QT6)
list(APPEND VERSIONS "6")
set(BUILD_WITH_QT6 ON) # necessary on older ECMs
endif()

set(QT_NO_CREATE_VERSIONLESS_TARGETS ON)
set(QT_NO_CREATE_VERSIONLESS_FUNCTIONS ON)

include(FeatureSummary)

# ECM
find_package(ECM 5.60 NO_MODULE)
find_package(ECM 5.90 NO_MODULE)
set(KDE_COMPILERSETTINGS_LEVEL "5.82")
set_package_properties(ECM PROPERTIES
TYPE REQUIRED
DESCRIPTION "Extra CMake Modules"
URL "https://api.kde.org/frameworks/extra-cmake-modules/html/index.html")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})

include(KDEInstallDirs)
include(ECMPoQmTools)
include(KDECMakeSettings)
include(KDECompilerSettings)
include(ECMSetupVersion)

# Phonon
find_package(Phonon4Qt5 4.10.60 NO_MODULE)
set_package_properties(Phonon4Qt5 PROPERTIES
TYPE REQUIRED
DESCRIPTION "Phonon core library"
URL "https://api.kde.org/phonon/html/index.html")

find_package(Phonon4Qt5Experimental 4.10.60 NO_MODULE)
set_package_properties(Phonon4Qt5Experimental PROPERTIES
TYPE OPTIONAL
DESCRIPTION "Phonon experimental library"
URL "https://api.kde.org/phonon/html/index.html")
if(Phonon4Qt5Experimental_FOUND)
set(PHONON_EXPERIMENTAL TRUE)
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH})

# LibMPV
find_package(PkgConfig)
pkg_check_modules(MPV REQUIRED mpv>=1.101.0)

find_package(Qt5X11Extras)
find_package(Qt5Gui)

add_definitions(-DPHONON_MPV_VERSION="${PROJECT_VERSION}")
include_directories(${MPV_INCLUDE_DIR})
ecm_setup_version(PROJECT VARIABLE_PREFIX PHONON_VLC)

add_subdirectory(src)
foreach(version ${VERSIONS})
set(QT_MAJOR_VERSION ${version})

include(KDEInstallDirs${QT_MAJOR_VERSION})
include(ECMPoQmTools)
include(KDECMakeSettings)
include(KDECompilerSettings)
include(ECMSetupVersion)

find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS Core Gui)
if(QT_MAJOR_VERSION STREQUAL "5")
find_package(Qt5X11Extras)
else()
find_package(Qt${QT_MAJOR_VERSION} REQUIRED COMPONENTS OpenGLWidgets)
find_package(Qt6XcbQpaPrivate)
endif()

# Phonon
find_package(Phonon4Qt${QT_MAJOR_VERSION} 4.10.60 NO_MODULE)
set_package_properties(Phonon4Qt${QT_MAJOR_VERSION} PROPERTIES
TYPE REQUIRED
DESCRIPTION "Phonon core library"
URL "https://api.kde.org/phonon/html/index.html")

find_package(Phonon4Qt${QT_MAJOR_VERSION}Experimental 4.10.60 NO_MODULE)
set_package_properties(Phonon4Qt${QT_MAJOR_VERSION}Experimental PROPERTIES
TYPE OPTIONAL
DESCRIPTION "Phonon experimental library"
URL "https://api.kde.org/phonon/html/index.html")
if(Phonon4Qt${QT_MAJOR_VERSION}Experimental_FOUND)
set(PHONON_EXPERIMENTAL TRUE)
endif()

ecm_setup_version(PROJECT VARIABLE_PREFIX PHONON_MPV)
add_subdirectory(src src${version})
unset(QUERY_EXECUTABLE CACHE)
endforeach()

feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
46 changes: 33 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,51 @@ set(phonon_mpv_SRCS
sinknode.cpp
video/videowidget.cpp
utils/debug.cpp

audio/audiooutput.h
audio/audiodataoutput.h
audio/volumefadereffect.h
backend.h
effect.h
effectmanager.h
mediacontroller.h
mediaobject.h
sinknode.h
video/videowidget.h
utils/debug.h
)

add_library(phonon_mpv MODULE ${phonon_mpv_SRCS})
ecm_create_qm_loader(phonon_mpv_SRCS phonon_mpv_qt)
add_library(phonon_mpv_qt${QT_MAJOR_VERSION} MODULE ${phonon_mpv_SRCS})
if(QT_MAJOR_VERSION STREQUAL 5)
set_target_properties(phonon_mpv_qt${QT_MAJOR_VERSION} PROPERTIES INSTALL_NAME "phonon_mpv")
endif()

target_link_libraries(phonon_mpv
Phonon::phonon4qt5
target_link_libraries(phonon_mpv_qt${QT_MAJOR_VERSION}
Phonon::phonon4qt${QT_MAJOR_VERSION}
Qt${QT_MAJOR_VERSION}::Core
Qt${QT_MAJOR_VERSION}::Gui
${MPV_LIBRARIES}
)

if(Qt5Gui_FOUND)
add_definitions(-DWAYLAND_SUPPORT)
if(QT_MAJOR_VERSION STREQUAL "5")
include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS})
target_link_libraries(phonon_mpv Qt5::Gui)
endif()

if(Qt5X11Extras_FOUND)
add_definitions(-DX11_SUPPORT)
target_link_libraries(phonon_mpv Qt5::X11Extras)
if(Qt5X11Extras_FOUND)
add_definitions(-DX11_SUPPORT)
target_link_libraries(phonon_mpv_qt${QT_MAJOR_VERSION} Qt${QT_MAJOR_VERSION}::X11Extras)
endif()
else()
target_link_libraries(phonon_mpv_qt${QT_MAJOR_VERSION} Qt${QT_MAJOR_VERSION}::OpenGLWidgets)
if(Qt6XcbQpaPrivate_FOUND)
add_definitions(-DX11_SUPPORT)
endif()
endif()

if(PHONON_EXPERIMENTAL)
target_link_libraries(phonon_mpv Phonon::phonon4qt5experimental)
target_link_libraries(phonon_mpv_qt${QT_MAJOR_VERSION} Phonon::phonon4qt${QT_MAJOR_VERSION}experimental)
endif()

install(TARGETS phonon_mpv DESTINATION ${PHONON_BACKEND_DIR})
install(TARGETS phonon_mpv_qt${QT_MAJOR_VERSION} DESTINATION ${PHONON_BACKEND_DIR})

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/phonon-mpv.json.in
${CMAKE_CURRENT_BINARY_DIR}/phonon-mpv.json @ONLY)
Expand Down
4 changes: 2 additions & 2 deletions src/audio/audiooutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ namespace Phonon::MPV {

virtual void setCategory(Phonon::Category category) Q_DECL_OVERRIDE;

signals:
Q_SIGNALS:
void volumeChanged(qreal volume);
void audioDeviceFailed();
void mutedChanged(bool mute) Q_DECL_OVERRIDE;

private slots:
private Q_SLOTS:
/**
* Sets the volume to m_volume.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/audio/volumefadereffect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Phonon::MPV {
Q_INTERFACES(Phonon::VolumeFaderInterface)

public:
explicit VolumeFaderEffect(QObject* parent = 0);
explicit VolumeFaderEffect(QObject* parent = nullptr);
~VolumeFaderEffect();

// VolumeFaderInterface:
Expand All @@ -46,7 +46,7 @@ namespace Phonon::MPV {
void setVolume(float v) Q_DECL_OVERRIDE;
QPointer<MediaObject> mediaObject() { return m_mediaObject; }

private slots:
private Q_SLOTS:
void slotSetVolume(qreal v);

private:
Expand Down
1 change: 0 additions & 1 deletion src/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <QDir>
#include <QResizeEvent>
#include <QIcon>
#include <QLatin1Literal>
#include <QMessageBox>
#include <QtPlugin>
#include <QSettings>
Expand Down
2 changes: 1 addition & 1 deletion src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ namespace Phonon::MPV {
*
* \param parent A parent object for the backend (passed to the QObject constructor)
*/
explicit Backend(QObject* parent = 0, const QVariantList& = QVariantList());
explicit Backend(QObject* parent = nullptr, const QVariantList& = QVariantList());
virtual ~Backend();

/// \return The mpv handle that is associated with this backend object
Expand Down
2 changes: 1 addition & 1 deletion src/effectmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ namespace Phonon::MPV {
* \warning Currently it doesn't add any effects, everything is disabled.
* \see EffectInfo
*/
explicit EffectManager(QObject* parent = 0);
explicit EffectManager(QObject* parent = nullptr);

/// Deletes all the effects from the lists and destroys the effect manager.
~EffectManager();
Expand Down
2 changes: 1 addition & 1 deletion src/mediacontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void MediaController::refreshAudioChannels() {
if(i == currentChannelId) {
const QList<AudioChannelDescription> list{GlobalAudioChannels::instance()->listFor(this)};
foreach(const AudioChannelDescription &descriptor, list) {
if(descriptor.name() == id)
if(descriptor.name() == QChar(id))
m_currentAudioChannel = descriptor;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/mediaobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,16 @@ void MediaObject::setSource(const MediaSource &source) {
error() << Q_FUNC_INFO << "the MediaSource::Disc doesn't specify which one (Phonon::NoDisc)";
return;
case Phonon::Cd:
loadMedia(QLatin1Literal("cdda://") % m_mediaSource.deviceName());
loadMedia(QStringLiteral("cdda://") % m_mediaSource.deviceName());
break;
case Phonon::Dvd:
loadMedia(QLatin1Literal("dvd://") % m_mediaSource.deviceName());
loadMedia(QStringLiteral("dvd://") % m_mediaSource.deviceName());
break;
case Phonon::Vcd:
loadMedia(QLatin1Literal("vcd://") % m_mediaSource.deviceName());
loadMedia(QStringLiteral("vcd://") % m_mediaSource.deviceName());
break;
case Phonon::BluRay:
loadMedia(QLatin1Literal("bluray://") % m_mediaSource.deviceName());
loadMedia(QStringLiteral("bluray://") % m_mediaSource.deviceName());
break;
}
break;
Expand All @@ -313,11 +313,11 @@ void MediaObject::setSource(const MediaSource &source) {
deviceName = source.deviceAccessList().first().second;

if (driverName == QByteArray("v4l2"))
loadMedia(QLatin1Literal("v4l2://") % deviceName);
loadMedia(QStringLiteral("v4l2://") % deviceName);
else if (driverName == QByteArray("alsa"))
loadMedia(QLatin1Literal("alsa://") % deviceName);
loadMedia(QStringLiteral("alsa://") % deviceName);
else if (driverName == "screen")
loadMedia(QLatin1Literal("screen://") % deviceName);
loadMedia(QStringLiteral("screen://") % deviceName);
else
error() << Q_FUNC_INFO << "Unsupported MediaSource::CaptureDevice:" << driverName;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mediaobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ namespace Phonon::MPV {
void loadMedia(const QString& mrl);
static void event_cb(void *opaque);

signals:
Q_SIGNALS:
// MediaController signals
void availableSubtitlesChanged() Q_DECL_OVERRIDE;
void availableAudioChannelsChanged() Q_DECL_OVERRIDE;
Expand Down Expand Up @@ -212,7 +212,7 @@ namespace Phonon::MPV {

void moveToNext();

private slots:
private Q_SLOTS:
/**
* If the new state is different from the current state, the current state is
* changed and the corresponding signal is emitted.
Expand Down
4 changes: 2 additions & 2 deletions src/utils/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#define DEBUG_INDENT_OBJECTNAME QLatin1String("Debug_Indent_object")

QMutex Debug::mutex( QMutex::Recursive );
QRecursiveMutex Debug::mutex;

using namespace Debug;

Expand Down Expand Up @@ -218,5 +218,5 @@ Block::~Block()
void Debug::stamp()
{
static int n = 0;
debug() << "| Stamp: " << ++n << endl;
debug() << "| Stamp: " << ++n << Qt::endl;
}
2 changes: 1 addition & 1 deletion src/utils/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
*/
namespace Debug
{
extern QMutex mutex;
extern QRecursiveMutex mutex;

enum DebugLevel {
DEBUG_INFO = 0,
Expand Down
1 change: 1 addition & 0 deletions src/utils/debug_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "debug.h"

#include <QtCore/QString>
#include <QIODevice>

class IndentPrivate
: public QObject
Expand Down
21 changes: 16 additions & 5 deletions src/video/videowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
#include <QtGui/QPaintEvent>
#include <QDir>
#include <QOpenGLContext>
#include <QGuiApplication>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#ifdef X11_SUPPORT
#include <QtX11Extras/QX11Info>
#endif
#ifdef WAYLAND_SUPPORT
#include <QGuiApplication>
#include <qpa/qplatformnativeinterface.h>
#endif

Expand All @@ -56,17 +56,28 @@ static void* get_proc_address(void* ctx, const char* name) {
void VideoWidget::initializeGL() {
mpv_opengl_init_params gl_init_params{get_proc_address, QOpenGLContext::currentContext()};
mpv_render_param display{MPV_RENDER_PARAM_INVALID, nullptr};
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#ifdef X11_SUPPORT
if(QX11Info::isPlatformX11()) {
display.type = MPV_RENDER_PARAM_X11_DISPLAY;
display.data = QX11Info::display();
}
#endif
#ifdef WAYLAND_SUPPORT
if(!display.data) {
display.type = MPV_RENDER_PARAM_WL_DISPLAY;
display.data = (struct wl_display*)QGuiApplication::platformNativeInterface()->nativeResourceForWindow("display", NULL);
}
#else
#ifdef X11_SUPPORT
if(auto *app = qApp->nativeInterface<QNativeInterface::QX11Application>()) {
display.type = MPV_RENDER_PARAM_X11_DISPLAY;
display.data = app->display();
}
#endif
if(auto *app = qApp->nativeInterface<QNativeInterface::QWaylandApplication>()) {
display.type = MPV_RENDER_PARAM_WL_DISPLAY;
display.data = app->display();
}
#endif
mpv_render_param params[]{
{MPV_RENDER_PARAM_API_TYPE, const_cast<char *>(MPV_RENDER_API_TYPE_OPENGL)},
Expand Down Expand Up @@ -348,14 +359,14 @@ bool VideoWidget::enableFilterAdjust(bool adjust) {
QImage VideoWidget::snapshot() const {
DEBUG_BLOCK;
if (m_player) {
const auto path{(QDir::tempPath() + "/" + QLatin1Literal("phonon-mpv-snapshot")).toUtf8()};
const auto path{(QDir::tempPath() + "/" + QStringLiteral("phonon-mpv-snapshot")).toUtf8()};
const char* cmd[]{"screenshot-to-file", path.constData(), nullptr};
auto err{0};
if((err = mpv_command(m_player, cmd))) {
warning() << "Failed to take screenshot:" << mpv_error_string(err);
return QImage();
}
return QImage(QDir::tempPath() + "/" + QLatin1Literal("phonon-mpv-snapshot"));
return QImage(QDir::tempPath() + "/" + QStringLiteral("phonon-mpv-snapshot"));
} else {
return QImage();
}
Expand Down

0 comments on commit 384ae0a

Please sign in to comment.