mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
[AFV] Ref T739, remove implementation details from IContextAudio to keep the DBus interface "pure"
* This was an approach to avoid registration of "local signals" * that part DID NOT work as planned, as all object's signals are registered * the refactoring itself nevertheless is NOT a bad idea and has been kept * as the audio context has this special "concept" and CAfvClient can run on both sides (proxy AND impl.side)
This commit is contained in:
@@ -1532,6 +1532,12 @@ namespace BlackCore
|
||||
return m_coreFacade->getIContextAudio();
|
||||
}
|
||||
|
||||
const CContextAudioBase *CApplication::getCContextAudioBase() const
|
||||
{
|
||||
if (!supportsContexts()) { return nullptr; }
|
||||
return m_coreFacade->getCContextAudioBase();
|
||||
}
|
||||
|
||||
const IContextApplication *CApplication::getIContextApplication() const
|
||||
{
|
||||
if (!supportsContexts()) { return nullptr; }
|
||||
@@ -1562,6 +1568,12 @@ namespace BlackCore
|
||||
return m_coreFacade->getIContextAudio();
|
||||
}
|
||||
|
||||
CContextAudioBase *CApplication::getCContextAudioBase()
|
||||
{
|
||||
if (!supportsContexts()) { return nullptr; }
|
||||
return m_coreFacade->getCContextAudioBase();
|
||||
}
|
||||
|
||||
IContextApplication *CApplication::getIContextApplication()
|
||||
{
|
||||
if (!supportsContexts()) { return nullptr; }
|
||||
|
||||
@@ -64,6 +64,7 @@ namespace BlackCore
|
||||
{
|
||||
class IContextApplication;
|
||||
class IContextAudio;
|
||||
class CContextAudioBase;
|
||||
class IContextNetwork;
|
||||
class IContextOwnAircraft;
|
||||
class IContextSimulator;
|
||||
@@ -368,11 +369,13 @@ namespace BlackCore
|
||||
//! @{
|
||||
const Context::IContextNetwork *getIContextNetwork() const;
|
||||
const Context::IContextAudio *getIContextAudio() const;
|
||||
const Context::CContextAudioBase *getCContextAudioBase() const;
|
||||
const Context::IContextApplication *getIContextApplication() const;
|
||||
const Context::IContextOwnAircraft *getIContextOwnAircraft() const;
|
||||
const Context::IContextSimulator *getIContextSimulator() const;
|
||||
Context::IContextNetwork *getIContextNetwork();
|
||||
Context::IContextAudio *getIContextAudio();
|
||||
Context::CContextAudioBase *getCContextAudioBase();
|
||||
Context::IContextApplication *getIContextApplication();
|
||||
Context::IContextOwnAircraft *getIContextOwnAircraft();
|
||||
Context::IContextSimulator *getIContextSimulator();
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace BlackCore
|
||||
{
|
||||
const CLogCategoryList &IContext::getLogCategories()
|
||||
{
|
||||
static const BlackMisc::CLogCategoryList cats { BlackMisc::CLogCategory::context() };
|
||||
static const CLogCategoryList cats { BlackMisc::CLogCategory::context() };
|
||||
return cats;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,36 +34,9 @@ namespace BlackCore
|
||||
namespace Context
|
||||
{
|
||||
IContextAudio::IContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) :
|
||||
IContext(mode, runtime),
|
||||
CIdentifiable(this),
|
||||
m_voiceClient(new CAfvClient(CVoiceSetup().getAfvVoiceServerUrl(), this))
|
||||
IContext(mode, runtime)
|
||||
{
|
||||
const CVoiceSetup vs = m_voiceSettings.getThreadLocal();
|
||||
m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl());
|
||||
|
||||
Q_ASSERT_X(CThreadUtils::isApplicationThread(m_voiceClient->thread()), Q_FUNC_INFO, "Should be in main thread");
|
||||
m_voiceClient->start();
|
||||
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");
|
||||
|
||||
connect(m_voiceClient, &CAfvClient::outputVolumePeakVU, this, &IContextAudio::outputVolumePeakVU, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::inputVolumePeakVU, this, &IContextAudio::inputVolumePeakVU, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::receivingCallsignsChanged, this, &IContextAudio::receivingCallsignsChanged, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::updatedFromOwnAircraftCockpit, this, &IContextAudio::updatedFromOwnAircraftCockpit, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::startedAudio, this, &IContextAudio::startedAudio, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::ptt, this, &IContextAudio::ptt, Qt::QueuedConnection);
|
||||
|
||||
const CSettings as = m_audioSettings.getThreadLocal();
|
||||
this->setVoiceOutputVolume(as.getOutVolume());
|
||||
m_selcalPlayer = new CSelcalPlayer(CAudioDeviceInfo::getDefaultOutputDevice(), this);
|
||||
|
||||
this->changeDeviceSettings();
|
||||
QPointer<IContextAudio> myself(this);
|
||||
QTimer::singleShot(5000, this, [ = ]
|
||||
{
|
||||
if (!myself || !sApp || sApp->isShuttingDown()) { return; }
|
||||
myself->onChangedAudioSettings();
|
||||
});
|
||||
// void
|
||||
}
|
||||
|
||||
const QString &IContextAudio::InterfaceName()
|
||||
@@ -81,7 +54,7 @@ namespace BlackCore
|
||||
IContextAudio *IContextAudio::create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, CDBusServer *server, QDBusConnection &connection)
|
||||
{
|
||||
// for audio no empty context is available
|
||||
// since IContextAudio provides audio on either side (core/GUI) we do not use ContextAudioEmpty
|
||||
// since CContextAudioBaseImpl provides audio on either side (core/GUI) we do not use ContextAudioEmpty
|
||||
// ContextAudioEmpty would cause issue, as it is initializing "common parts" during shutdown
|
||||
switch (mode)
|
||||
{
|
||||
@@ -97,45 +70,7 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
IContextAudio::~IContextAudio()
|
||||
{
|
||||
gracefulShutdown();
|
||||
}
|
||||
|
||||
void IContextAudio::gracefulShutdown()
|
||||
{
|
||||
if (m_voiceClient)
|
||||
{
|
||||
m_voiceClient->gracefulShutdown();
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(m_voiceClient), Q_FUNC_INFO, "Needs to be back in current thread");
|
||||
m_voiceClient = nullptr;
|
||||
}
|
||||
QObject::disconnect(this);
|
||||
}
|
||||
|
||||
const CIdentifier &IContextAudio::audioRunsWhere() const
|
||||
{
|
||||
static const CIdentifier i("IContextAudio");
|
||||
return i;
|
||||
}
|
||||
|
||||
bool IContextAudio::isEnabledComUnit(CComSystem::ComUnit comUnit) const
|
||||
{
|
||||
return m_voiceClient->isEnabledComUnit(comUnit);
|
||||
}
|
||||
|
||||
bool IContextAudio::isTransmittingComUnit(CComSystem::ComUnit comUnit) const
|
||||
{
|
||||
return m_voiceClient->isTransmittingdComUnit(comUnit);
|
||||
}
|
||||
|
||||
QString IContextAudio::audioRunsWhereInfo() const
|
||||
{
|
||||
static const QString s = QStringLiteral("Audio on '%1', '%2'.").arg(audioRunsWhere().getMachineName(), audioRunsWhere().getProcessName());
|
||||
return s;
|
||||
}
|
||||
|
||||
bool IContextAudio::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
|
||||
bool CContextAudioBase::parseCommandLine(const QString &commandLine, const CIdentifier &originator)
|
||||
{
|
||||
Q_UNUSED(originator)
|
||||
if (commandLine.isEmpty()) { return false; }
|
||||
@@ -166,12 +101,83 @@ namespace BlackCore
|
||||
return false;
|
||||
}
|
||||
|
||||
CAudioDeviceInfoList IContextAudio::getAudioDevices() const
|
||||
CContextAudioBase::CContextAudioBase(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) :
|
||||
IContextAudio(mode, runtime),
|
||||
CIdentifiable(this),
|
||||
m_voiceClient(new CAfvClient(CVoiceSetup().getAfvVoiceServerUrl(), this))
|
||||
{
|
||||
const CVoiceSetup vs = m_voiceSettings.getThreadLocal();
|
||||
m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl());
|
||||
|
||||
Q_ASSERT_X(CThreadUtils::isApplicationThread(m_voiceClient->thread()), Q_FUNC_INFO, "Should be in main thread");
|
||||
m_voiceClient->start();
|
||||
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");
|
||||
|
||||
connect(m_voiceClient, &CAfvClient::outputVolumePeakVU, this, &CContextAudioBase::outputVolumePeakVU, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::inputVolumePeakVU, this, &CContextAudioBase::inputVolumePeakVU, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::receivingCallsignsChanged, this, &CContextAudioBase::receivingCallsignsChanged, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::updatedFromOwnAircraftCockpit, this, &CContextAudioBase::updatedFromOwnAircraftCockpit, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::startedAudio, this, &CContextAudioBase::startedAudio, Qt::QueuedConnection);
|
||||
connect(m_voiceClient, &CAfvClient::ptt, this, &CContextAudioBase::ptt, Qt::QueuedConnection);
|
||||
|
||||
const CSettings as = m_audioSettings.getThreadLocal();
|
||||
this->setVoiceOutputVolume(as.getOutVolume());
|
||||
m_selcalPlayer = new CSelcalPlayer(CAudioDeviceInfo::getDefaultOutputDevice(), this);
|
||||
|
||||
this->changeDeviceSettings();
|
||||
QPointer<CContextAudioBase> myself(this);
|
||||
QTimer::singleShot(5000, this, [ = ]
|
||||
{
|
||||
if (!myself || !sApp || sApp->isShuttingDown()) { return; }
|
||||
myself->onChangedAudioSettings();
|
||||
});
|
||||
}
|
||||
|
||||
CContextAudioBase::~CContextAudioBase()
|
||||
{
|
||||
gracefulShutdown();
|
||||
}
|
||||
|
||||
void CContextAudioBase::gracefulShutdown()
|
||||
{
|
||||
if (m_voiceClient)
|
||||
{
|
||||
m_voiceClient->gracefulShutdown();
|
||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(m_voiceClient), Q_FUNC_INFO, "Needs to be back in current thread");
|
||||
m_voiceClient = nullptr;
|
||||
}
|
||||
QObject::disconnect(this);
|
||||
}
|
||||
|
||||
const CIdentifier &CContextAudioBase::audioRunsWhere() const
|
||||
{
|
||||
static const CIdentifier i("CContextAudioBaseImpl");
|
||||
return i;
|
||||
}
|
||||
|
||||
bool CContextAudioBase::isEnabledComUnit(CComSystem::ComUnit comUnit) const
|
||||
{
|
||||
return m_voiceClient->isEnabledComUnit(comUnit);
|
||||
}
|
||||
|
||||
bool CContextAudioBase::isTransmittingComUnit(CComSystem::ComUnit comUnit) const
|
||||
{
|
||||
return m_voiceClient->isTransmittingdComUnit(comUnit);
|
||||
}
|
||||
|
||||
QString CContextAudioBase::audioRunsWhereInfo() const
|
||||
{
|
||||
static const QString s = QStringLiteral("Audio on '%1', '%2'.").arg(audioRunsWhere().getMachineName(), audioRunsWhere().getProcessName());
|
||||
return s;
|
||||
}
|
||||
|
||||
CAudioDeviceInfoList CContextAudioBase::getAudioDevices() const
|
||||
{
|
||||
return CAudioDeviceInfoList::allDevices();
|
||||
}
|
||||
|
||||
CAudioDeviceInfoList IContextAudio::getCurrentAudioDevices() const
|
||||
CAudioDeviceInfoList CContextAudioBase::getCurrentAudioDevices() const
|
||||
{
|
||||
const QString inputDeviceName = m_inputDeviceSetting.get();
|
||||
const CAudioDeviceInfo inputDevice = this->getAudioInputDevices().findByNameOrDefault(inputDeviceName, CAudioDeviceInfo::getDefaultInputDevice());
|
||||
@@ -185,7 +191,7 @@ namespace BlackCore
|
||||
return devices;
|
||||
}
|
||||
|
||||
void IContextAudio::setCurrentAudioDevices(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice)
|
||||
void CContextAudioBase::setCurrentAudioDevices(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice)
|
||||
{
|
||||
if (!m_voiceClient) { return; }
|
||||
if (!inputDevice.getName().isEmpty()) { m_inputDeviceSetting.setAndSave(inputDevice.getName()); }
|
||||
@@ -194,7 +200,7 @@ namespace BlackCore
|
||||
m_voiceClient->startAudio(inputDevice, outputDevice);
|
||||
}
|
||||
|
||||
void IContextAudio::setVoiceOutputVolume(int volume)
|
||||
void CContextAudioBase::setVoiceOutputVolume(int volume)
|
||||
{
|
||||
if (!m_voiceClient) { return; }
|
||||
|
||||
@@ -224,13 +230,13 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
int IContextAudio::getVoiceOutputVolume() const
|
||||
int CContextAudioBase::getVoiceOutputVolume() const
|
||||
{
|
||||
if (!m_voiceClient) { return 0; }
|
||||
return m_voiceClient->getNormalizedOutputVolume();
|
||||
}
|
||||
|
||||
void IContextAudio::setMute(bool muted)
|
||||
void CContextAudioBase::setMute(bool muted)
|
||||
{
|
||||
if (!m_voiceClient) { return; }
|
||||
if (this->isMuted() == muted) { return; } // avoid roundtrips / unnecessary signals
|
||||
@@ -248,20 +254,20 @@ namespace BlackCore
|
||||
emit this->changedMute(muted);
|
||||
}
|
||||
|
||||
bool IContextAudio::isMuted() const
|
||||
bool CContextAudioBase::isMuted() const
|
||||
{
|
||||
if (!m_voiceClient) { return false; }
|
||||
return m_voiceClient->isMuted();
|
||||
}
|
||||
|
||||
void IContextAudio::playSelcalTone(const CSelcal &selcal)
|
||||
void CContextAudioBase::playSelcalTone(const CSelcal &selcal)
|
||||
{
|
||||
const CTime t = m_selcalPlayer->play(90, selcal);
|
||||
const int ms = t.toMs();
|
||||
if (ms > 10)
|
||||
{
|
||||
// As of https://dev.swift-project.org/T558 play additional notification
|
||||
const QPointer<const IContextAudio> myself(this);
|
||||
const QPointer<const CContextAudioBase> myself(this);
|
||||
QTimer::singleShot(ms, this, [ = ]
|
||||
{
|
||||
if (!sApp || sApp->isShuttingDown() || !myself) { return; }
|
||||
@@ -270,7 +276,7 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
void IContextAudio::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume)
|
||||
void CContextAudioBase::playNotification(CNotificationSounds::NotificationFlag notification, bool considerSettings, int volume)
|
||||
{
|
||||
if (m_debugEnabled) { CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO << notification; }
|
||||
|
||||
@@ -296,51 +302,51 @@ namespace BlackCore
|
||||
m_notificationPlayer.play(notification, volume);
|
||||
}
|
||||
|
||||
void IContextAudio::enableAudioLoopback(bool enable)
|
||||
void CContextAudioBase::enableAudioLoopback(bool enable)
|
||||
{
|
||||
if (!m_voiceClient) { return; }
|
||||
m_voiceClient->setLoopBack(enable);
|
||||
}
|
||||
|
||||
bool IContextAudio::isAudioLoopbackEnabled() const
|
||||
bool CContextAudioBase::isAudioLoopbackEnabled() const
|
||||
{
|
||||
if (!m_voiceClient) { return false; }
|
||||
return m_voiceClient->isLoopback();
|
||||
}
|
||||
|
||||
void IContextAudio::setVoiceSetup(const CVoiceSetup &setup)
|
||||
void CContextAudioBase::setVoiceSetup(const CVoiceSetup &setup)
|
||||
{
|
||||
// could be recycled for some AFV setup
|
||||
Q_UNUSED(setup)
|
||||
}
|
||||
|
||||
CVoiceSetup IContextAudio::getVoiceSetup() const
|
||||
CVoiceSetup CContextAudioBase::getVoiceSetup() const
|
||||
{
|
||||
return CVoiceSetup();
|
||||
}
|
||||
|
||||
void IContextAudio::setVoiceTransmission(bool enable, PTTCOM com)
|
||||
void CContextAudioBase::setVoiceTransmission(bool enable, PTTCOM com)
|
||||
{
|
||||
if (!m_voiceClient) { return; }
|
||||
m_voiceClient->setPttForCom(enable, com);
|
||||
}
|
||||
|
||||
void IContextAudio::setVoiceTransmissionCom1(bool enabled)
|
||||
void CContextAudioBase::setVoiceTransmissionCom1(bool enabled)
|
||||
{
|
||||
this->setVoiceTransmission(enabled, COM1);
|
||||
}
|
||||
|
||||
void IContextAudio::setVoiceTransmissionCom2(bool enabled)
|
||||
void CContextAudioBase::setVoiceTransmissionCom2(bool enabled)
|
||||
{
|
||||
this->setVoiceTransmission(enabled, COM2);
|
||||
}
|
||||
|
||||
void IContextAudio::setVoiceTransmissionComActive(bool enabled)
|
||||
void CContextAudioBase::setVoiceTransmissionComActive(bool enabled)
|
||||
{
|
||||
this->setVoiceTransmission(enabled, COMActive);
|
||||
}
|
||||
|
||||
void IContextAudio::changeDeviceSettings()
|
||||
void CContextAudioBase::changeDeviceSettings()
|
||||
{
|
||||
const QString inputDeviceName = m_inputDeviceSetting.get();
|
||||
const CAudioDeviceInfo input = this->getAudioInputDevices().findByNameOrDefault(inputDeviceName, CAudioDeviceInfo::getDefaultInputDevice());
|
||||
@@ -351,7 +357,7 @@ namespace BlackCore
|
||||
this->setCurrentAudioDevices(input, output);
|
||||
}
|
||||
|
||||
void IContextAudio::onChangedAudioSettings()
|
||||
void CContextAudioBase::onChangedAudioSettings()
|
||||
{
|
||||
const CSettings s = m_audioSettings.get();
|
||||
const QString dir = s.getNotificationSoundDirectory();
|
||||
@@ -359,27 +365,27 @@ namespace BlackCore
|
||||
this->setVoiceOutputVolume(s.getOutVolume());
|
||||
}
|
||||
|
||||
void IContextAudio::onChangedVoiceSettings()
|
||||
void CContextAudioBase::onChangedVoiceSettings()
|
||||
{
|
||||
const CVoiceSetup vs = m_voiceSettings.getThreadLocal();
|
||||
m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl());
|
||||
}
|
||||
|
||||
void IContextAudio::audioIncreaseVolume(bool enabled)
|
||||
void CContextAudioBase::audioIncreaseVolume(bool enabled)
|
||||
{
|
||||
if (!enabled) { return; }
|
||||
const int v = qRound(this->getVoiceOutputVolume() * 1.2);
|
||||
this->setVoiceOutputVolume(v);
|
||||
}
|
||||
|
||||
void IContextAudio::audioDecreaseVolume(bool enabled)
|
||||
void CContextAudioBase::audioDecreaseVolume(bool enabled)
|
||||
{
|
||||
if (!enabled) { return; }
|
||||
const int v = qRound(this->getVoiceOutputVolume() / 1.2);
|
||||
this->setVoiceOutputVolume(v);
|
||||
}
|
||||
|
||||
CComSystem IContextAudio::xCtxGetOwnComSystem(CComSystem::ComUnit unit) const
|
||||
CComSystem CContextAudioBase::xCtxGetOwnComSystem(CComSystem::ComUnit unit) const
|
||||
{
|
||||
if (!this->getIContextOwnAircraft())
|
||||
{
|
||||
@@ -396,21 +402,13 @@ namespace BlackCore
|
||||
return this->getIContextOwnAircraft()->getOwnComSystem(unit);
|
||||
}
|
||||
|
||||
bool IContextAudio::xCtxIsComIntegratedWithSimulator() const
|
||||
bool CContextAudioBase::xCtxIsComIntegratedWithSimulator() const
|
||||
{
|
||||
if (!this->getIContextSimulator()) { return false; }
|
||||
return this->getIContextSimulator()->getSimulatorSettings().isComIntegrated();
|
||||
}
|
||||
|
||||
void IContextAudio::xCtxChangedAircraftCockpit(const CSimulatedAircraft &aircraft, const CIdentifier &originator)
|
||||
{
|
||||
Q_UNUSED(aircraft)
|
||||
Q_UNUSED(originator)
|
||||
|
||||
/** NOT NEEDED as CAfvClient is directly "tracking changes" **/
|
||||
}
|
||||
|
||||
void IContextAudio::xCtxNetworkConnectionStatusChanged(const CConnectionStatus &from, const CConnectionStatus &to)
|
||||
void CContextAudioBase::xCtxNetworkConnectionStatusChanged(const CConnectionStatus &from, const CConnectionStatus &to)
|
||||
{
|
||||
if (!m_voiceClient) { return; }
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "blackmisc/network/connectionstatus.h"
|
||||
#include "blackmisc/network/userlist.h"
|
||||
#include "blackmisc/input/actionhotkeydefs.h"
|
||||
#include "blackmisc/genericdbusinterface.h"
|
||||
#include "blackmisc/identifiable.h"
|
||||
#include "blackmisc/identifier.h"
|
||||
|
||||
@@ -61,19 +62,13 @@ namespace BlackCore
|
||||
namespace Context
|
||||
{
|
||||
//! Audio context interface
|
||||
class BLACKCORE_EXPORT IContextAudio :
|
||||
public IContext,
|
||||
public BlackMisc::CIdentifiable
|
||||
class BLACKCORE_EXPORT IContextAudio : public IContext
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
|
||||
|
||||
friend class BlackCore::CCoreFacade;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
IContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
||||
|
||||
public:
|
||||
//! Interface name
|
||||
static const QString &InterfaceName();
|
||||
@@ -87,8 +82,43 @@ namespace BlackCore
|
||||
//! Factory method
|
||||
static IContextAudio *create(CCoreFacade *runtime, CCoreFacadeConfig::ContextMode mode, BlackMisc::CDBusServer *server, QDBusConnection &connection);
|
||||
|
||||
signals:
|
||||
// only use DBus signals here
|
||||
|
||||
public slots:
|
||||
// ------------- DBus ---------------
|
||||
|
||||
//! Register a device on a machine (for core/GUI it will return all known devices on all machines)
|
||||
virtual void registerDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) = 0;
|
||||
|
||||
//! Unregister devices
|
||||
virtual void unRegisterDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) = 0;
|
||||
|
||||
//! All registered devices
|
||||
virtual BlackMisc::Audio::CAudioDeviceInfoList getRegisteredDevices() const = 0;
|
||||
|
||||
// ------------- DBus ---------------
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
IContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
||||
};
|
||||
|
||||
//! Audio context interface
|
||||
class BLACKCORE_EXPORT CContextAudioBase :
|
||||
public IContextAudio,
|
||||
public BlackMisc::CIdentifiable
|
||||
{
|
||||
Q_OBJECT
|
||||
friend class BlackCore::CCoreFacade;
|
||||
|
||||
protected:
|
||||
//! Constructor
|
||||
CContextAudioBase(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
||||
|
||||
public:
|
||||
//! Destructor
|
||||
virtual ~IContextAudio() override;
|
||||
virtual ~CContextAudioBase() override;
|
||||
|
||||
//! Graceful shutdown
|
||||
void gracefulShutdown();
|
||||
@@ -150,38 +180,6 @@ namespace BlackCore
|
||||
|
||||
// -------- parts which can run in core and GUI, referring to local voice client ------------
|
||||
|
||||
signals:
|
||||
// -------- local settings, not DBus relayed -------
|
||||
|
||||
//! Audio volume changed
|
||||
//! \sa setVoiceOutputVolume
|
||||
void changedAudioVolume(int volume);
|
||||
|
||||
//! PTT status in a particular voice client
|
||||
void ptt(bool active, BlackMisc::Audio::PTTCOM pttcom, const BlackMisc::CIdentifier &identifier);
|
||||
|
||||
//! Mute changed
|
||||
void changedMute(bool muted);
|
||||
|
||||
//! Changed audio devices (e.g. device enabled/disable)
|
||||
void changedAudioDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices);
|
||||
|
||||
//! Audio started with
|
||||
void startedAudio(const BlackMisc::Audio::CAudioDeviceInfo &input, const BlackMisc::Audio::CAudioDeviceInfo &output);
|
||||
|
||||
//! VU levels @{
|
||||
void inputVolumePeakVU(double value);
|
||||
void outputVolumePeakVU(double value);
|
||||
//! @}
|
||||
|
||||
//! Callsigns I receive have changed
|
||||
void receivingCallsignsChanged(const BlackCore::Afv::Audio::TransceiverReceivingCallsignsChangedArgs &args);
|
||||
|
||||
//! Client updated from own aicraft data
|
||||
void updatedFromOwnAircraftCockpit();
|
||||
|
||||
// -------- local settings, not DBus relayed -------
|
||||
|
||||
public slots:
|
||||
// ------------- DBus ---------------
|
||||
|
||||
@@ -194,17 +192,40 @@ namespace BlackCore
|
||||
//! \copydoc IContext::parseCommandLine
|
||||
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override;
|
||||
|
||||
//! Register a device on a machine (for core/GUI it will return all known devices on all machines)
|
||||
virtual void registerDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) = 0;
|
||||
|
||||
//! Unregister devices
|
||||
virtual void unRegisterDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) = 0;
|
||||
|
||||
//! All registered devices
|
||||
virtual BlackMisc::Audio::CAudioDeviceInfoList getRegisteredDevices() const = 0;
|
||||
|
||||
// ------------- DBus ---------------
|
||||
|
||||
|
||||
// ------------ local signals -------
|
||||
signals:
|
||||
//! Audio volume changed
|
||||
//! \sa setVoiceOutputVolume
|
||||
void changedAudioVolume(int volume);
|
||||
|
||||
//! Mute changed
|
||||
void changedMute(bool muted);
|
||||
|
||||
//! Changed audio devices (e.g. device enabled/disable)
|
||||
void changedAudioDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices);
|
||||
|
||||
//! Audio started with
|
||||
void startedAudio(const BlackMisc::Audio::CAudioDeviceInfo &input, const BlackMisc::Audio::CAudioDeviceInfo &output);
|
||||
|
||||
//! PTT in voice client received
|
||||
void ptt(bool active, BlackMisc::Audio::PTTCOM pttcom, const BlackMisc::CIdentifier &identifier);
|
||||
|
||||
//! VU levels @{
|
||||
void inputVolumePeakVU(double value);
|
||||
void outputVolumePeakVU(double value);
|
||||
//! @}
|
||||
|
||||
//! Callsigns I receive have changed
|
||||
void receivingCallsignsChanged(const BlackCore::Afv::Audio::TransceiverReceivingCallsignsChangedArgs &args);
|
||||
|
||||
//! Client updated from own aicraft data
|
||||
void updatedFromOwnAircraftCockpit();
|
||||
|
||||
// ------------ local signals -------
|
||||
|
||||
private:
|
||||
//! Enable/disable voice transmission, nornally used with hotkey
|
||||
//! @{
|
||||
@@ -236,28 +257,24 @@ namespace BlackCore
|
||||
bool xCtxIsComIntegratedWithSimulator() const;
|
||||
//! @}
|
||||
|
||||
//! Changed cockpit
|
||||
//! \remark cross context
|
||||
void xCtxChangedAircraftCockpit(const BlackMisc::Simulation::CSimulatedAircraft &aircraft, const BlackMisc::CIdentifier &originator);
|
||||
|
||||
//! Network connection status
|
||||
void xCtxNetworkConnectionStatusChanged(const BlackMisc::Network::CConnectionStatus &from, const BlackMisc::Network::CConnectionStatus &to);
|
||||
|
||||
CActionBind m_actionPtt { BlackMisc::Input::pttHotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &IContextAudio::setVoiceTransmissionComActive };
|
||||
CActionBind m_actionPttCom1 { BlackMisc::Input::pttCom1HotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &IContextAudio::setVoiceTransmissionCom1 };
|
||||
CActionBind m_actionPttCom2 { BlackMisc::Input::pttCom2HotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &IContextAudio::setVoiceTransmissionCom2 };
|
||||
CActionBind m_actionAudioVolumeIncrease { BlackMisc::Input::audioVolumeIncreaseHotkeyAction(), BlackMisc::Input::audioVolumeIncreaseHotkeyIcon(), this, &IContextAudio::audioIncreaseVolume };
|
||||
CActionBind m_actionAudioVolumeDecrease { BlackMisc::Input::audioVolumeDecreaseHotkeyAction(), BlackMisc::Input::audioVolumeDecreaseHotkeyIcon(), this, &IContextAudio::audioDecreaseVolume };
|
||||
CActionBind m_actionPtt { BlackMisc::Input::pttHotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudioBase::setVoiceTransmissionComActive };
|
||||
CActionBind m_actionPttCom1 { BlackMisc::Input::pttCom1HotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudioBase::setVoiceTransmissionCom1 };
|
||||
CActionBind m_actionPttCom2 { BlackMisc::Input::pttCom2HotkeyAction(), BlackMisc::Input::pttHotkeyIcon(), this, &CContextAudioBase::setVoiceTransmissionCom2 };
|
||||
CActionBind m_actionAudioVolumeIncrease { BlackMisc::Input::audioVolumeIncreaseHotkeyAction(), BlackMisc::Input::audioVolumeIncreaseHotkeyIcon(), this, &CContextAudioBase::audioIncreaseVolume };
|
||||
CActionBind m_actionAudioVolumeDecrease { BlackMisc::Input::audioVolumeDecreaseHotkeyAction(), BlackMisc::Input::audioVolumeDecreaseHotkeyIcon(), this, &CContextAudioBase::audioDecreaseVolume };
|
||||
|
||||
int m_outVolumeBeforeMute = 90;
|
||||
static constexpr int MinUnmuteVolume = 20; //!< minimum volume when unmuted
|
||||
|
||||
// settings
|
||||
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &IContextAudio::onChangedAudioSettings };
|
||||
BlackMisc::CSetting<BlackMisc::Audio::TVoiceSetup> m_voiceSettings { this, &IContextAudio::onChangedVoiceSettings };
|
||||
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &CContextAudioBase::onChangedAudioSettings };
|
||||
BlackMisc::CSetting<BlackMisc::Audio::TVoiceSetup> m_voiceSettings { this, &CContextAudioBase::onChangedVoiceSettings };
|
||||
|
||||
BlackMisc::CSetting<Audio::TInputDevice> m_inputDeviceSetting { this, &IContextAudio::changeDeviceSettings };
|
||||
BlackMisc::CSetting<Audio::TOutputDevice> m_outputDeviceSetting { this, &IContextAudio::changeDeviceSettings };
|
||||
BlackMisc::CSetting<Audio::TInputDevice> m_inputDeviceSetting { this, &CContextAudioBase::changeDeviceSettings };
|
||||
BlackMisc::CSetting<Audio::TOutputDevice> m_outputDeviceSetting { this, &CContextAudioBase::changeDeviceSettings };
|
||||
|
||||
// AFV
|
||||
Afv::Clients::CAfvClient *m_voiceClient = nullptr;
|
||||
|
||||
@@ -7,27 +7,32 @@
|
||||
*/
|
||||
|
||||
#include "blackcore/context/contextaudioimpl.h"
|
||||
#include "blackcore/afv/clients/afvclient.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QtGlobal>
|
||||
#include <QPointer>
|
||||
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Audio;
|
||||
using namespace BlackCore::Afv::Clients;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Context
|
||||
{
|
||||
CContextAudio::CContextAudio(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) :
|
||||
IContextAudio(mode, runtime)
|
||||
{ }
|
||||
CContextAudioBase(mode, runtime)
|
||||
{
|
||||
// void
|
||||
}
|
||||
|
||||
CContextAudio *CContextAudio::registerWithDBus(CDBusServer *server)
|
||||
{
|
||||
if (!server || m_mode != CCoreFacadeConfig::LocalInDBusServer) { return this; }
|
||||
|
||||
// remark that registers all SIGNALS, not only the interface ons
|
||||
server->addObject(IContextAudio::ObjectPath(), this);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ namespace BlackCore
|
||||
namespace Context
|
||||
{
|
||||
//! Audio context implementation
|
||||
class BLACKCORE_EXPORT CContextAudio :
|
||||
public IContextAudio
|
||||
class BLACKCORE_EXPORT CContextAudio : public CContextAudioBase
|
||||
{
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
|
||||
Q_OBJECT
|
||||
@@ -42,7 +41,7 @@ namespace BlackCore
|
||||
friend class IContextAudio;
|
||||
|
||||
public slots:
|
||||
// Interface implementations
|
||||
// Interface implementations for DBus
|
||||
//! \publicsection
|
||||
//! @{
|
||||
virtual void registerDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices) override;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
#include "blackcore/context/contextaudioproxy.h"
|
||||
#include "blackcore/afv/clients/afvclient.h"
|
||||
#include "blackmisc/audio/ptt.h"
|
||||
#include "blackmisc/dbus.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
@@ -20,15 +21,16 @@ using namespace BlackMisc;
|
||||
using namespace BlackMisc::Audio;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackCore::Afv::Clients;
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
namespace Context
|
||||
{
|
||||
CContextAudioProxy::CContextAudioProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextAudio(mode, runtime), m_dBusInterface(nullptr)
|
||||
CContextAudioProxy::CContextAudioProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) :
|
||||
CContextAudioBase(mode, runtime), m_dBusInterface(nullptr)
|
||||
{
|
||||
this->m_dBusInterface = new CGenericDBusInterface(
|
||||
serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), connection, this);
|
||||
m_dBusInterface = new CGenericDBusInterface(serviceName, IContextAudio::ObjectPath(), IContextAudio::InterfaceName(), connection, this);
|
||||
this->relaySignals(serviceName, connection);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace BlackCore
|
||||
{
|
||||
//! Audio context proxy
|
||||
//! \ingroup dbus
|
||||
class BLACKCORE_EXPORT CContextAudioProxy : public IContextAudio
|
||||
class BLACKCORE_EXPORT CContextAudioProxy : public CContextAudioBase
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", BLACKCORE_CONTEXTAUDIO_INTERFACENAME)
|
||||
@@ -58,7 +58,7 @@ namespace BlackCore
|
||||
static void unitTestRelaySignals();
|
||||
|
||||
public slots:
|
||||
//! All Dbus xsinterface overrides
|
||||
//! All DBus interface overrides
|
||||
//! \publicsection
|
||||
//! @{
|
||||
//! Register a device on a machine (for core/GUI it will return all known devices on all machines)
|
||||
@@ -76,7 +76,7 @@ namespace BlackCore
|
||||
|
||||
protected:
|
||||
//! Contructor
|
||||
CContextAudioProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : IContextAudio(mode, runtime), m_dBusInterface(nullptr) {}
|
||||
CContextAudioProxy(CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime) : CContextAudioBase(mode, runtime), m_dBusInterface(nullptr) {}
|
||||
|
||||
//! DBus version constructor
|
||||
CContextAudioProxy(const QString &serviceName, QDBusConnection &connection, CCoreFacadeConfig::ContextMode mode, CCoreFacade *runtime);
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace BlackCore
|
||||
times.insert("Application", time.restart());
|
||||
|
||||
if (m_contextAudio) { m_contextAudio->deleteLater(); }
|
||||
m_contextAudio = IContextAudio::create(this, m_config.getModeAudio(), m_dbusServer, m_dbusConnection);
|
||||
m_contextAudio = qobject_cast<CContextAudioBase *>(IContextAudio::create(this, m_config.getModeAudio(), m_dbusServer, m_dbusConnection));
|
||||
times.insert("Audio", time.restart());
|
||||
|
||||
if (m_contextOwnAircraft) { m_contextOwnAircraft->deleteLater(); }
|
||||
@@ -261,14 +261,6 @@ namespace BlackCore
|
||||
Q_ASSERT(c);
|
||||
}
|
||||
|
||||
// special case for the audio related connection (which mutes audio for a changed cockpit)
|
||||
// hook up with audio if audio context is local
|
||||
if (this->hasLocalAudio() && m_contextOwnAircraft)
|
||||
{
|
||||
c = connect(m_contextOwnAircraft, &IContextOwnAircraft::changedAircraftCockpit, this->getCContextAudio(), &IContextAudio::xCtxChangedAircraftCockpit, Qt::QueuedConnection);
|
||||
Q_ASSERT(c);
|
||||
}
|
||||
|
||||
// times
|
||||
times.insert("Post setup, sim.connects", time.restart());
|
||||
}
|
||||
@@ -288,7 +280,7 @@ namespace BlackCore
|
||||
{
|
||||
Q_ASSERT(m_contextApplication);
|
||||
c = connect(m_contextNetwork, &IContextNetwork::connectionStatusChanged,
|
||||
this->getCContextAudio(), &IContextAudio::xCtxNetworkConnectionStatusChanged, Qt::QueuedConnection);
|
||||
this->getCContextAudio(), &CContextAudio::xCtxNetworkConnectionStatusChanged, Qt::QueuedConnection);
|
||||
Q_ASSERT(c);
|
||||
times.insert("Post setup, connects audio", time.restart());
|
||||
}
|
||||
@@ -350,11 +342,11 @@ namespace BlackCore
|
||||
m_contextNetwork = IContextNetwork::create(this, CCoreFacadeConfig::NotUsed, nullptr, defaultConnection);
|
||||
}
|
||||
|
||||
if (this->getIContextAudio())
|
||||
if (this->getCContextAudioBase())
|
||||
{
|
||||
// there is no empty audio context since AFV
|
||||
disconnect(this->getIContextAudio());
|
||||
this->getIContextAudio()->gracefulShutdown();
|
||||
disconnect(this->getCContextAudioBase());
|
||||
this->getCContextAudioBase()->gracefulShutdown();
|
||||
this->getIContextAudio()->deleteLater();
|
||||
m_contextAudio = nullptr;
|
||||
}
|
||||
@@ -417,6 +409,16 @@ namespace BlackCore
|
||||
return m_contextAudio;
|
||||
}
|
||||
|
||||
CContextAudioBase *CCoreFacade::getCContextAudioBase()
|
||||
{
|
||||
return m_contextAudio;
|
||||
}
|
||||
|
||||
const CContextAudioBase *CCoreFacade::getCContextAudioBase() const
|
||||
{
|
||||
return m_contextAudio;
|
||||
}
|
||||
|
||||
IContextNetwork *CCoreFacade::getIContextNetwork()
|
||||
{
|
||||
return m_contextNetwork;
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
#define BLACKCORE_COREFACADE_H
|
||||
|
||||
#include "corefacadeconfig.h"
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackcore/data/launchersetup.h"
|
||||
#include "blackcore/vatsim/vatsimsettings.h"
|
||||
#include "blackcore/blackcoreexport.h"
|
||||
#include "blackmisc/identifier.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace BlackCore
|
||||
{
|
||||
class CContextApplication;
|
||||
class CContextAudio;
|
||||
class CContextAudioBase;
|
||||
class CContextNetwork;
|
||||
class CContextOwnAircraft;
|
||||
class CContextSimulator;
|
||||
@@ -91,6 +92,12 @@ namespace BlackCore
|
||||
//! Context for audio
|
||||
const Context::IContextAudio *getIContextAudio() const;
|
||||
|
||||
//! Context for audio
|
||||
Context::CContextAudioBase *getCContextAudioBase();
|
||||
|
||||
//! Context for audio
|
||||
const Context::CContextAudioBase *getCContextAudioBase() const;
|
||||
|
||||
//! Context for application
|
||||
Context::IContextApplication *getIContextApplication();
|
||||
|
||||
@@ -178,7 +185,7 @@ namespace BlackCore
|
||||
// There is a reason why we do not use smart pointers here. When the context is deleted
|
||||
// we need to use deleteLater to gracefully shut the context
|
||||
Context::IContextApplication *m_contextApplication = nullptr;
|
||||
Context::IContextAudio *m_contextAudio = nullptr;
|
||||
Context::CContextAudioBase *m_contextAudio = nullptr;
|
||||
Context::IContextNetwork *m_contextNetwork = nullptr;
|
||||
Context::IContextOwnAircraft *m_contextOwnAircraft = nullptr;
|
||||
Context::IContextSimulator *m_contextSimulator = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user