Share resolution dependent frame rate menus for capture settings
This commit is contained in:
1 parent
7ed6626fe1
commit
68031b4ddd
2 files changed
+30
-25
No files matched your search
@@ -12,6 +12,8 @@
|
||||
#include <QStyleOptionMenuItem>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include "stream_video_modes.h"
|
||||
#include "debug_config.h"
|
||||
|
||||
namespace CaptureControls {
|
||||
class MenuStyle : public QProxyStyle {
|
||||
@@ -62,6 +64,33 @@ inline QAction* addOption(QMenu* menu, const QString& label, const QVariant& dat
|
||||
}
|
||||
inline void clearOptions(QMenu* menu, const char* heading) { menu->clear(); menu->addSection(QCoreApplication::translate("ChatGui", heading)); }
|
||||
|
||||
/* Все стандартные и аппаратные FPS остаются в меню; доступность зависит от точного size.
|
||||
* Сохраняет previous, иначе выбирает 30 либо первый доступный; без режимов снимает выбор. */
|
||||
inline void populateFrameRates(QMenu* menu, const QList<StreamVideoMode>& modes, QSize size, int previous) {
|
||||
clearOptions(menu, "Frame rate"); QList<int> rates{15, 24, 25, 30, 50, 60};
|
||||
for (const auto& mode : modes) if (!rates.contains(mode.fps)) rates.append(mode.fps);
|
||||
std::sort(rates.begin(), rates.end()); int fallback = -1;
|
||||
for (int fps : rates) {
|
||||
auto* action = addOption(menu, QCoreApplication::translate("ChatGui", "%1 fps").arg(fps), fps);
|
||||
bool available = modes.contains({size, fps}); action->setEnabled(available);
|
||||
if (available && (fallback < 0 || fps == 30)) fallback = fps;
|
||||
}
|
||||
auto* requested = option(menu, previous);
|
||||
if (requested && requested->isEnabled()) select(menu, previous);
|
||||
else if (fallback >= 0) {
|
||||
select(menu, fallback);
|
||||
DEBUG_WARN(DEBUG_CATEGORY_VIDEO, "desktop capture FPS adjusted resolution=%dx%d requested=%d selected=%d",
|
||||
size.width(), size.height(), previous, fallback);
|
||||
} else {
|
||||
auto* group = menu->findChild<QActionGroup*>(); group->setExclusive(false);
|
||||
if (auto* action = selected(menu)) action->setChecked(false);
|
||||
group->setExclusive(true);
|
||||
DEBUG_WARN(DEBUG_CATEGORY_VIDEO, "desktop capture resolution has no available FPS width=%d height=%d", size.width(), size.height());
|
||||
}
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO, "desktop capture FPS choices width=%d height=%d choices=%lld selected=%d",
|
||||
size.width(), size.height(), (long long)rates.size(), value(menu).toInt());
|
||||
}
|
||||
|
||||
/* Компактные векторные значки с текущим значением, читаемые в обеих темах. */
|
||||
inline QIcon controlIcon(const QPalette& palette, const QString& shape, const QString& label = {}, const QString& detail = {}, int rotation = 0) {
|
||||
QPixmap pixmap(80, 72); pixmap.fill(Qt::transparent); QPainter painter(&pixmap); painter.scale(2, 2);
|
||||
|
||||
@@ -378,31 +378,7 @@ void StreamPublishWindow::refreshModes(const StreamPublishConfig& previous, bool
|
||||
}
|
||||
|
||||
void StreamPublishWindow::refreshFrameRates(int previous) {
|
||||
clearOptions(m_fps, "Frame rate");
|
||||
QList<int> rates{15, 24, 25, 30, 50, 60};
|
||||
for (const auto& mode : m_modes) if (!rates.contains(mode.fps)) rates.append(mode.fps);
|
||||
std::sort(rates.begin(), rates.end());
|
||||
QSize size = value(m_resolution).toSize();
|
||||
int fallback = -1;
|
||||
for (int fps : rates) {
|
||||
auto* action = addOption(m_fps, text("%1 fps").arg(fps), fps);
|
||||
bool available = selected(m_resolution) && m_modes.contains({size, fps}); action->setEnabled(available);
|
||||
if (available && (fallback < 0 || fps == 30)) fallback = fps;
|
||||
}
|
||||
auto* requested = option(m_fps, previous);
|
||||
if (requested && requested->isEnabled()) select(m_fps, previous);
|
||||
else if (fallback >= 0) {
|
||||
select(m_fps, fallback);
|
||||
DEBUG_WARN(DEBUG_CATEGORY_VIDEO, "desktop stream FPS adjusted resolution=%dx%d requested=%d selected=%d",
|
||||
size.width(), size.height(), previous, fallback);
|
||||
} else {
|
||||
auto* group = m_fps->findChild<QActionGroup*>(); group->setExclusive(false);
|
||||
if (auto* action = selected(m_fps)) action->setChecked(false);
|
||||
group->setExclusive(true);
|
||||
DEBUG_WARN(DEBUG_CATEGORY_VIDEO, "desktop stream resolution has no available FPS width=%d height=%d", size.width(), size.height());
|
||||
}
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_VIDEO, "desktop stream FPS choices width=%d height=%d choices=%lld selected=%d",
|
||||
size.width(), size.height(), (long long)rates.size(), value(m_fps).toInt());
|
||||
populateFrameRates(m_fps, m_modes, value(m_resolution).toSize(), previous);
|
||||
}
|
||||
void StreamPublishWindow::refreshCodecs() {
|
||||
QScopedValueRollback<bool> updating(m_updating, true);
|
||||
|
||||
Reference in new issue
Block a user