From b0f32f76d2efc8f0c17403b990e3609783eebb64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B5=AE=E7=94=9F=E8=8B=A5=E6=A2=A6?= <1070753498@qq.com> Date: Mon, 17 Jun 2024 11:32:41 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=96=B0=E5=A2=9E=E7=9B=AE=E6=A0=87=E8=89=B2?= =?UTF-8?q?=E5=BD=A9=E7=A9=BA=E9=97=B4=E8=AE=BE=E7=BD=AE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?]=EF=BC=9A=E5=9C=A8=E6=92=AD=E6=94=BE=E5=99=A8=E4=B8=AD?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E7=9B=AE=E6=A0=87=E8=89=B2=E5=BD=A9?= =?UTF-8?q?=E7=A9=BA=E9=97=B4=E7=9A=84=E8=AE=BE=E7=BD=AE=E9=80=89=E9=A1=B9?= =?UTF-8?q?=EF=BC=8C=E5=85=81=E8=AE=B8=E7=94=A8=E6=88=B7=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E9=80=89=E6=8B=A9=E4=B8=8D=E5=90=8C=E7=9A=84?= =?UTF-8?q?=E8=89=B2=E5=BD=A9=E7=A9=BA=E9=97=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在`ffmpegplayer`和`mpvplayer`的`mainwindow`中新增了`createTargetPrimariesMenu`函数,用于创建目标色彩空间的菜单选项。 - 为`ffmpegplayer`的`MainWindow`类新增了连接,当用户选择不同的目标色彩空间时,会更新视频渲染器的色彩空间设置。 - 为`mpvplayer`的`MpvPlayer`类新增了获取、设置目标色彩空间的函数,并在`mpvplayer`的`MainWindow`中使用了这些新函数来响应用户的选择。 - 移除了`ffmpegplayer`中旧的`destPrimarisMenu`函数,并用新的功能替换。 - 更新了`mpvplayer`的`MpvPlayer`类头文件,添加了目标色彩空间相关的公共成员函数声明。 --- examples/ffmpegplayer/mainwindow.cpp | 61 ++++++++++++++-------------- examples/ffmpegplayer/mainwindow.h | 1 - examples/mpvplayer/mainwindow.cc | 22 ++++++++++ src/mpv/mpvplayer.cc | 29 +++++++++++++ src/mpv/mpvplayer.hpp | 4 ++ 5 files changed, 85 insertions(+), 32 deletions(-) diff --git a/examples/ffmpegplayer/mainwindow.cpp b/examples/ffmpegplayer/mainwindow.cpp index 0b7e90a..b0a7404 100644 --- a/examples/ffmpegplayer/mainwindow.cpp +++ b/examples/ffmpegplayer/mainwindow.cpp @@ -106,6 +106,35 @@ class MainWindow::MainWindowPrivate return menu; } + auto createTargetPrimariesMenu() -> QMenu * + { + auto *group = new QActionGroup(q_ptr); + group->setExclusive(true); + auto *menu = new QMenu(QCoreApplication::translate("MainWindowPrivate", "Target Primaries"), + q_ptr); + auto primaris = QMetaEnum::fromType(); + for (int i = 0; i < primaris.keyCount(); ++i) { + auto value = primaris.value(i); + auto *action = new QAction(primaris.key(i), q_ptr); + action->setCheckable(true); + action->setData(value); + group->addAction(action); + menu->addAction(action); + if (value == Ffmpeg::ColorUtils::Primaries::Type::AUTO) { + action->setChecked(true); + } + } + q_ptr->connect(group, &QActionGroup::triggered, q_ptr, [this](QAction *action) { + primarisType = static_cast(action->data().toInt()); + if (videoRender.isNull()) { + return; + } + videoRender->setDestPrimaries(primarisType); + }); + group->checkedAction()->trigger(); + return menu; + } + void resetTrackMenu() { auto actions = audioTracksGroup->actions(); @@ -682,8 +711,7 @@ void MainWindow::initMenu() d_ptr->videoMenu->addAction(equalizerAction); d_ptr->videoMenu->addMenu(d_ptr->createtoneMappingMenu()); - - destPrimarisMenu(); + d_ptr->videoMenu->addMenu(d_ptr->createTargetPrimariesMenu()); connect(d_ptr->audioTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) { d_ptr->playerPtr->addEvent(Ffmpeg::EventPtr( @@ -704,35 +732,6 @@ void MainWindow::initMenu() connect(d_ptr->mediaInfoAction, &QAction::triggered, this, &MainWindow::onShowMediaInfo); } -void MainWindow::destPrimarisMenu() -{ - auto *destPrimarisGroup = new QActionGroup(this); - destPrimarisGroup->setExclusive(true); - auto *destPrimarisMenu = new QMenu(tr("Dest Primaris"), this); - auto destPrimaris = QMetaEnum::fromType(); - for (int i = 0; i < destPrimaris.keyCount(); ++i) { - auto value = destPrimaris.value(i); - auto *action = new QAction(destPrimaris.key(i), this); - action->setCheckable(true); - action->setData(value); - destPrimarisGroup->addAction(action); - destPrimarisMenu->addAction(action); - if (value == Ffmpeg::ColorUtils::Primaries::Type::AUTO) { - action->setChecked(true); - } - } - d_ptr->videoMenu->addMenu(destPrimarisMenu); - connect(destPrimarisGroup, &QActionGroup::triggered, this, [this](QAction *action) { - d_ptr->primarisType = static_cast( - action->data().toInt()); - if (d_ptr->videoRender.isNull()) { - return; - } - d_ptr->videoRender->setDestPrimaries(d_ptr->primarisType); - }); - destPrimarisGroup->checkedAction()->trigger(); -} - void MainWindow::renderMenu() { auto *widgetAction = new QAction(tr("Widget"), this); diff --git a/examples/ffmpegplayer/mainwindow.h b/examples/ffmpegplayer/mainwindow.h index 2df3fdc..8e8e8d9 100644 --- a/examples/ffmpegplayer/mainwindow.h +++ b/examples/ffmpegplayer/mainwindow.h @@ -38,7 +38,6 @@ private slots: void setupUI(); void buildConnect(); void initMenu(); - void destPrimarisMenu(); void renderMenu(); void initPlayListMenu(); void addToPlaylist(const QList &urls); diff --git a/examples/mpvplayer/mainwindow.cc b/examples/mpvplayer/mainwindow.cc index e36316a..1e393fb 100644 --- a/examples/mpvplayer/mainwindow.cc +++ b/examples/mpvplayer/mainwindow.cc @@ -98,6 +98,27 @@ class MainWindow::MainWindowPrivate return menu; } + auto createTargetPrimariesMenu() -> QMenu * + { + auto *group = new QActionGroup(q_ptr); + group->setExclusive(true); + auto *menu = new QMenu(QCoreApplication::translate("MainWindowPrivate", "Target Primaries"), + q_ptr); + auto targetPrimaries = mpvPlayer->targetPrimaries(); + for (const auto &targetPrimary : std::as_const(targetPrimaries)) { + auto *action = new QAction(targetPrimary, q_ptr); + action->setCheckable(true); + group->addAction(action); + menu->addAction(action); + } + group->actions().at(0)->setChecked(true); + q_ptr->connect(group, &QActionGroup::triggered, q_ptr, [this](QAction *action) { + mpvPlayer->setTargetPrimaries(action->text()); + }); + + return menu; + } + void resetTrackMenu() { auto actions = audioTracksGroup->actions(); @@ -730,6 +751,7 @@ void MainWindow::initMenu() connect(equalizerAction, &QAction::triggered, this, &MainWindow::onEqualizer); d_ptr->videoMenu->addAction(equalizerAction); d_ptr->videoMenu->addMenu(d_ptr->createtoneMappingMenu()); + d_ptr->videoMenu->addMenu(d_ptr->createTargetPrimariesMenu()); connect(d_ptr->videoTracksGroup, &QActionGroup::triggered, this, [this](QAction *action) { auto data = action->data().value(); diff --git a/src/mpv/mpvplayer.cc b/src/mpv/mpvplayer.cc index b65c196..2d719e8 100644 --- a/src/mpv/mpvplayer.cc +++ b/src/mpv/mpvplayer.cc @@ -468,6 +468,35 @@ auto MpvPlayer::toneMapping() const -> QString return mpv::qt::get_property(d_ptr->mpv, "tone-mapping").toString(); } +QStringList MpvPlayer::targetPrimaries() const +{ + static QStringList list{"auto", + "bt.470m", + "bt.601-525", + "bt.601-625", + "bt.709", + "bt.2020", + "apple", + "adobe", + "prophoto", + "cie1931", + "dci-p3", + "v-gamut", + "s-gamut"}; + return list; +} + +void MpvPlayer::setTargetPrimaries(const QString &targetPrimaries) +{ + qInfo() << "target-prim: " << targetPrimaries; + mpv::qt::set_property_async(d_ptr->mpv, "target-prim", targetPrimaries); +} + +QString MpvPlayer::targetPrimariesName() const +{ + return mpv::qt::get_property(d_ptr->mpv, "target-prim").toString(); +} + void MpvPlayer::pauseAsync() { auto state = !isPaused(); diff --git a/src/mpv/mpvplayer.hpp b/src/mpv/mpvplayer.hpp index 732bd0b..4e76400 100644 --- a/src/mpv/mpvplayer.hpp +++ b/src/mpv/mpvplayer.hpp @@ -99,6 +99,10 @@ class MPV_LIB_EXPORT MpvPlayer : public QObject void setToneMapping(const QString &toneMapping); [[nodiscard]] auto toneMapping() const -> QString; + [[nodiscard]] auto targetPrimaries() const -> QStringList; + void setTargetPrimaries(const QString &targetPrimaries); + [[nodiscard]] auto targetPrimariesName() const -> QString; + void pauseAsync(); void pauseSync(bool state); auto isPaused() -> bool;