From 287b54b283bc3ca11cf2c2b0311a9411c90e8a85 Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 28 Oct 2026 13:55:45 +0100 Subject: [PATCH] Allow and remember stream audio toggling before publication starts --- tools/chatgui/src/stream_publish_window.cpp | 17 ++++++++++++----- tools/chatgui/src/stream_publish_window.h | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tools/chatgui/src/stream_publish_window.cpp b/tools/chatgui/src/stream_publish_window.cpp index 01178f86..333333b9 100644 --- a/tools/chatgui/src/stream_publish_window.cpp +++ b/tools/chatgui/src/stream_publish_window.cpp @@ -209,6 +209,7 @@ StreamPublishWindow::StreamPublishWindow(StreamPublishEngine* engine, uint64_t g DEBUG_WARN(DEBUG_CATEGORY_STREAM, "desktop capture settings invalid: %s", qPrintable(error.errorString())); else m_settings = document.object(); } + m_audioMuted = m_settings.value("muted").toBool(); setWindowTitle(text("Broadcast stream")); resize(900, 620); setMinimumSize(780, 360); auto* escape = new QShortcut(QKeySequence(Qt::Key_Escape), this); escape->setContext(Qt::WidgetWithChildrenShortcut); connect(escape, &QShortcut::activated, this, &QWidget::close); @@ -278,8 +279,10 @@ StreamPublishWindow::StreamPublishWindow(StreamPublishEngine* engine, uint64_t g "Gradually raise the QP ceiling above the selected value when bitrate is too high, then return it. Requires live QP adjustment.")); form->addRow(m_adaptiveQp); connect(m_sound, &QToolButton::toggled, this, [this](bool enabled) { - DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop stream audio enabled=%d", enabled); - m_engine->setMuted(!enabled); + m_audioMuted = !enabled; + DEBUG_INFO(DEBUG_CATEGORY_STREAM, "desktop stream audio enabled=%d active=%d", enabled, m_engine->active()); + if (m_engine->active()) m_engine->setMuted(!enabled); + else { updateMenuButtons(); saveSettings(); } }); m_status = new QLabel(this); m_status->setWordWrap(true); layout->addWidget(m_status); m_stats = new QLabel(this); m_stats->setObjectName(QStringLiteral("streamPublishStats")); @@ -408,6 +411,7 @@ void StreamPublishWindow::saveSettings() { if (selected(m_codec)) saved["codec"] = config.video.codec; saved["bitrate"] = value(m_bitrate).toInt(); saved["rotation"] = config.video.rotation; saved["audio"] = config.audio; saved["microphone"] = config.microphone; + saved["muted"] = m_audioMuted; saved["show_cursor"] = config.showCursor; saved["max_qp"] = value(m_maxQp).toInt(); saved["adaptive_qp"] = m_adaptiveQp->isChecked(); if (saved == m_settings) return; @@ -535,7 +539,8 @@ StreamPublishConfig StreamPublishWindow::selection() const { config.adaptiveQp = config.video.maxQp >= 0 && m_adaptiveQp->isChecked(); } config.showCursor = m_cursor->isChecked(); - config.microphone = value(m_microphone).toString(); config.audio = selected(m_microphone) != m_noAudio; return config; + config.microphone = value(m_microphone).toString(); config.audio = selected(m_microphone) != m_noAudio; + config.startMuted = m_audioMuted; return config; } void StreamPublishWindow::apply() { if (m_updating || !selected(m_resolution) || !selected(m_fps)) return; @@ -552,8 +557,10 @@ void StreamPublishWindow::synchronize() { for (auto* menu : {m_source, m_resolution, m_fps, m_codec, m_bitrate, m_rotation}) menu->menuAction()->setEnabled(!active || m_engine->running()); m_microphone->menuAction()->setEnabled(!active); - m_sound->setEnabled(m_engine->running() && m_engine->config().audio); - { QSignalBlocker blocked(m_sound); m_sound->setChecked(active ? !m_engine->muted() && m_engine->config().audio : selection().audio); } + if (active) m_audioMuted = m_engine->muted(); + bool audio = active ? m_engine->config().audio : selection().audio; + m_sound->setEnabled(audio && (!active || m_engine->running())); + { QSignalBlocker blocked(m_sound); m_sound->setChecked(audio && !m_audioMuted); } if (active) { auto config = m_engine->config(); for (int i = 0; i < m_sources.size(); i++) if (m_sources[i].sameSource(config.source)) { diff --git a/tools/chatgui/src/stream_publish_window.h b/tools/chatgui/src/stream_publish_window.h index 9ea3adc6..f5674aaa 100644 --- a/tools/chatgui/src/stream_publish_window.h +++ b/tools/chatgui/src/stream_publish_window.h @@ -43,6 +43,7 @@ private: StreamBufferIndicator* m_buffer; // Диапазоны получателей по истории source: oldest → live; tooltip содержит peer/subflows. QWidget* m_preview; // QVideoWidget при HAVE_STREAM_CAPTURE, иначе текст о недоступности capture. bool m_updating = false; // Защита от применения/сохранения промежуточного состояния при перестроении controls. + bool m_audioMuted = false; // Сохранённый mute для следующего запуска; во время трансляции синхронизируется с engine. QJsonObject m_settings; // Последний сохранённый выбор; source id в base64, окно по имени, режим/codec/audio/cursor/QP отдельно. StreamPublishConfig selection() const; // Снимок controls: auto bitrate рассчитан, screen nativeSize и допустимость QP учтены. void refreshSources(); // Сохраняет выбранный handle; пропавший active-source не подменяется другим, до start возможен первый доступный.