From 5150fb4e865ef693c8ca4b760ec01b7285cc019a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 27 Oct 2019 01:47:07 +0200 Subject: [PATCH] [AFV] Ref T739, cmd.line args for "no audio" --- src/blackcore/application.cpp | 8 +++- src/blackcore/application.h | 9 +++-- src/blackcore/context/contextaudio.cpp | 39 ++++++++++++++----- src/blackcore/context/contextaudio.h | 7 ++++ src/swiftcore/main.cpp | 1 + .../swiftguistdapplication.cpp | 1 + 6 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/blackcore/application.cpp b/src/blackcore/application.cpp index c23672b14..b05584c3f 100644 --- a/src/blackcore/application.cpp +++ b/src/blackcore/application.cpp @@ -11,6 +11,7 @@ #include "blackcore/db/networkwatchdog.h" #include "blackcore/context/contextnetwork.h" #include "blackcore/context/contextsimulatorimpl.h" +#include "blackcore/context/contextaudio.h" #include "blackcore/context/contextapplication.h" #include "blackcore/cookiemanager.h" #include "blackcore/corefacade.h" @@ -1312,7 +1313,12 @@ namespace BlackCore void CApplication::addVatlibOptions() { - this->addParserOptions(BlackCore::Context::IContextNetwork::getCmdLineOptions()); + this->addParserOptions(IContextNetwork::getCmdLineOptions()); + } + + void CApplication::addAudioOptions() + { + this->addParserOptions(CContextAudioBase::getCmdLineOptions()); } QString CApplication::getCmdDBusAddressValue() const diff --git a/src/blackcore/application.h b/src/blackcore/application.h index ac0a61191..456536f8e 100644 --- a/src/blackcore/application.h +++ b/src/blackcore/application.h @@ -264,18 +264,21 @@ namespace BlackCore //! Add the VATLIB options void addVatlibOptions(); + //! Add the audio options + void addAudioOptions(); + //! Private resource dir for developer's own resource files QString getCmdSwiftPrivateSharedDir() const; - //! Delegates to QCommandLineParser::isSet - bool isParserOptionSet(const QString &option) const; - //! Called by installer? bool isInstallerOptionSet() const; //! Skip the single application check bool skipSingleApplicationCheck() const; + //! Delegates to QCommandLineParser::isSet + bool isParserOptionSet(const QString &option) const; + //! Delegates to QCommandLineParser::isSet bool isParserOptionSet(const QCommandLineOption &option) const; diff --git a/src/blackcore/context/contextaudio.cpp b/src/blackcore/context/contextaudio.cpp index 783547b2f..8f6fa7fbd 100644 --- a/src/blackcore/context/contextaudio.cpp +++ b/src/blackcore/context/contextaudio.cpp @@ -108,10 +108,17 @@ namespace BlackCore CContextAudioBase::CContextAudioBase(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextAudio(mode, runtime), - CIdentifiable(this), - m_voiceClient(new CAfvClient(CVoiceSetup().getAfvVoiceServerUrl(), this)) + CIdentifiable(this) { - this->initVoiceClient(); + if (CContextAudioBase::isNoAudioSet()) + { + CLogMessage(this).info(u"Voice client disabled"); + } + else + { + this->initVoiceClient(); + } + const CSettings as = m_audioSettings.getThreadLocal(); this->setVoiceOutputVolume(as.getOutVolume()); m_selcalPlayer = new CSelcalPlayer(CAudioDeviceInfo::getDefaultOutputDevice(), this); @@ -132,10 +139,8 @@ namespace BlackCore void CContextAudioBase::initVoiceClient() { - if (!m_voiceClient) - { - m_voiceClient = new CAfvClient(CVoiceSetup().getAfvVoiceServerUrl(), this); - } + if (!m_voiceClient) { return; } + m_voiceClient = new CAfvClient(CVoiceSetup().getAfvVoiceServerUrl(), this); const CVoiceSetup vs = m_voiceSettings.getThreadLocal(); m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl()); @@ -159,7 +164,7 @@ namespace BlackCore #endif Q_ASSERT_X(CThreadUtils::isApplicationThread(m_voiceClient->thread()), Q_FUNC_INFO, "Should be in main thread"); - m_voiceClient->start(); + m_voiceClient->start(); // thread Q_ASSERT_X(m_voiceClient->owner() == this, Q_FUNC_INFO, "Wrong owner"); Q_ASSERT_X(!CThreadUtils::isApplicationThread(m_voiceClient->thread()), Q_FUNC_INFO, "Must NOT be in main thread"); @@ -199,7 +204,8 @@ namespace BlackCore void CContextAudioBase::enableVoiceClientAndStart() { this->initVoiceClient(); - if (m_voiceClient) { + if (m_voiceClient) + { m_voiceClient->startAudio(); this->connectAudioWithNetworkCredentials(); } @@ -255,6 +261,21 @@ namespace BlackCore return m_voiceClient && m_voiceClient->isStarted(); } + const QList &CContextAudioBase::getCmdLineOptions() + { + static const QList opts + { + QCommandLineOption({{"n", "noaudio"}, QCoreApplication::translate("CContextAudioBase", "No audio for GUI or core.", "noaudio")}) + }; + return opts; + } + + bool CContextAudioBase::isNoAudioSet() + { + if (!sApp) { return false; } + return sApp->isParserOptionSet("noaudio"); + } + QString CContextAudioBase::audioRunsWhereInfo() const { const QString s = QStringLiteral("[%1] Audio on '%2', '%3'.").arg(boolToEnabledDisabled(this->isAudioStarted()), audioRunsWhere().getMachineName(), audioRunsWhere().getProcessName()); diff --git a/src/blackcore/context/contextaudio.h b/src/blackcore/context/contextaudio.h index 7be61fdd4..f04821dee 100644 --- a/src/blackcore/context/contextaudio.h +++ b/src/blackcore/context/contextaudio.h @@ -38,6 +38,7 @@ #include #include +#include // clazy:excludeall=const-signal-or-slot @@ -198,6 +199,12 @@ namespace BlackCore //! \todo WORKAROUND to hide the "local signals" Afv::Clients::CAfvClient *afvClient() const { return m_voiceClient; } + //! Cmd.line arguments + static const QList &getCmdLineOptions(); + + //! No audio? + static bool isNoAudioSet(); + // -------- parts which can run in core and GUI, referring to local voice client ------------ public slots: diff --git a/src/swiftcore/main.cpp b/src/swiftcore/main.cpp index 55efdabd0..f66caa69c 100644 --- a/src/swiftcore/main.cpp +++ b/src/swiftcore/main.cpp @@ -36,6 +36,7 @@ int main(int argc, char *argv[]) a.addWindowStateOption(); a.addDBusAddressOption(); a.addVatlibOptions(); + a.addAudioOptions(); if (!a.parseAndSynchronizeSetup()) { return EXIT_FAILURE; } const QString dBusAdress(a.getCmdDBusAddressValue()); diff --git a/src/swiftguistandard/swiftguistdapplication.cpp b/src/swiftguistandard/swiftguistdapplication.cpp index 34b181ef0..b7d2f509e 100644 --- a/src/swiftguistandard/swiftguistdapplication.cpp +++ b/src/swiftguistandard/swiftguistdapplication.cpp @@ -24,6 +24,7 @@ CSwiftGuiStdApplication::CSwiftGuiStdApplication() : this->addParserOption(m_cmdFacadeMode); this->addDBusAddressOption(); this->addVatlibOptions(); + this->addAudioOptions(); } CStatusMessageList CSwiftGuiStdApplication::startHookIn()