Skip to content

Commit

Permalink
[新增目标色彩空间设置功能]:在播放器中增加了目标色彩空间的设置选项,允许用户根据需要选择不同的色彩空间。
Browse files Browse the repository at this point in the history
- 在`ffmpegplayer`和`mpvplayer`的`mainwindow`中新增了`createTargetPrimariesMenu`函数,用于创建目标色彩空间的菜单选项。
- 为`ffmpegplayer`的`MainWindow`类新增了连接,当用户选择不同的目标色彩空间时,会更新视频渲染器的色彩空间设置。
- 为`mpvplayer`的`MpvPlayer`类新增了获取、设置目标色彩空间的函数,并在`mpvplayer`的`MainWindow`中使用了这些新函数来响应用户的选择。
- 移除了`ffmpegplayer`中旧的`destPrimarisMenu`函数,并用新的功能替换。
- 更新了`mpvplayer`的`MpvPlayer`类头文件,添加了目标色彩空间相关的公共成员函数声明。
  • Loading branch information
RealChuan committed Jun 17, 2024
1 parent 82591a4 commit b0f32f7
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 32 deletions.
61 changes: 30 additions & 31 deletions examples/ffmpegplayer/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ffmpeg::ColorUtils::Primaries::Type>();
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<Ffmpeg::ColorUtils::Primaries::Type>(action->data().toInt());
if (videoRender.isNull()) {
return;
}
videoRender->setDestPrimaries(primarisType);
});
group->checkedAction()->trigger();
return menu;
}

void resetTrackMenu()
{
auto actions = audioTracksGroup->actions();
Expand Down Expand Up @@ -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(
Expand All @@ -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<Ffmpeg::ColorUtils::Primaries::Type>();
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<Ffmpeg::ColorUtils::Primaries::Type>(
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);
Expand Down
1 change: 0 additions & 1 deletion examples/ffmpegplayer/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ private slots:
void setupUI();
void buildConnect();
void initMenu();
void destPrimarisMenu();
void renderMenu();
void initPlayListMenu();
void addToPlaylist(const QList<QUrl> &urls);
Expand Down
22 changes: 22 additions & 0 deletions examples/mpvplayer/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<Mpv::TraskInfo>();
Expand Down
29 changes: 29 additions & 0 deletions src/mpv/mpvplayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/mpv/mpvplayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit b0f32f7

Please sign in to comment.