[AFV] Hide AFV client behind context

This commit is contained in:
Roland Rossgotterer
2019-10-10 15:57:56 +02:00
committed by Mat Sutcliffe
parent 90e5400049
commit 01d144b528
7 changed files with 64 additions and 66 deletions

View File

@@ -168,25 +168,17 @@ namespace BlackCore
this->setNormalizedOutputVolume(mute ? 0 : 50);
}
bool CAfvClient::restartWithNewDevices(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice)
void CAfvClient::restartWithNewDevices(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice)
{
if (!m_isStarted)
{
this->startAudio(inputDevice, outputDevice, allTransceiverIds());
return true;
}
if (QThread::currentThread() != this->thread())
{
// Method needs to be executed in the object thread since it will create new QObject children
QPointer<CAfvClient> myself(this);
QMetaObject::invokeMethod(this, [ = ]() { if (myself) restartWithNewDevices(inputDevice, outputDevice); });
return true;
}
this->stopAudio();
if (m_isStarted) { this->stopAudio(); }
this->startAudio(inputDevice, outputDevice, allTransceiverIds());
return true;
}
void CAfvClient::startAudio(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice, const QVector<quint16> &transceiverIDs)

View File

@@ -107,7 +107,7 @@ namespace BlackCore
//! @}
//! Start/stop client @{
bool restartWithNewDevices(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice);
void restartWithNewDevices(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice);
void startAudio(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice, const QVector<quint16> &transceiverIDs);
Q_INVOKABLE void startAudio(const QString &inputDeviceName, const QString &outputDeviceName);
void stopAudio();

View File

@@ -26,6 +26,9 @@ namespace BlackCore
//! \copydoc BlackMisc::TSettingTrait::humanReadable
static const QString &humanReadable() { static const QString name("Input device"); return name; }
//! \copydoc BlackMisc::TSettingTrait::defaultValue
static const QString &defaultValue() { static const QString device("default"); return device; }
};
//! Audio input device settings
@@ -36,6 +39,9 @@ namespace BlackCore
//! \copydoc BlackMisc::TSettingTrait::humanReadable
static const QString &humanReadable() { static const QString name("Output device"); return name; }
//! \copydoc BlackMisc::TSettingTrait::defaultValue
static const QString &defaultValue() { static const QString device("default"); return device; }
};
} // ns
} // ns

View File

@@ -46,12 +46,16 @@ namespace BlackCore
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.get(), &CAfvClient::outputVolumePeakVU, this, &IContextAudio::outputVolumePeakVU);
connect(m_voiceClient.get(), &CAfvClient::inputVolumePeakVU, this, &IContextAudio::inputVolumePeakVU);
connect(m_voiceClient.get(), &CAfvClient::receivingCallsignsChanged, this, &IContextAudio::receivingCallsignsChanged);
connect(m_voiceClient.get(), &CAfvClient::updatedFromOwnAircraftCockpit, this, &IContextAudio::updatedFromOwnAircraftCockpit);
connect(m_voiceClient.data(), &CAfvClient::ptt, this, &IContextAudio::ptt);
const CSettings as = m_audioSettings.getThreadLocal();
this->setVoiceOutputVolume(as.getOutVolume());
m_selcalPlayer = new CSelcalPlayer(CAudioDeviceInfo::getDefaultOutputDevice(), this);
connect(m_voiceClient.data(), &CAfvClient::ptt, this, &IContextAudio::ptt, Qt::QueuedConnection);
this->changeDeviceSettings();
QPointer<IContextAudio> myself(this);
QTimer::singleShot(5000, this, [ = ]
@@ -114,6 +118,16 @@ namespace BlackCore
return i;
}
bool IContextAudio::isEnabledComUnit(CComSystem::ComUnit comUnit) const
{
return m_voiceClient->isEnabledComUnit(comUnit);
}
bool IContextAudio::isTransmittingdComUnit(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());
@@ -158,14 +172,11 @@ namespace BlackCore
CAudioDeviceInfoList IContextAudio::getCurrentAudioDevices() const
{
if (!m_voiceClient) { return {}; }
const QString inputDeviceName = m_inputDeviceSetting.get();
const CAudioDeviceInfo inputDevice = this->getAudioInputDevices().findByNameOrDefault(inputDeviceName, CAudioDeviceInfo::getDefaultInputDevice());
// either the devices really used, or settings
CAudioDeviceInfo inputDevice = m_voiceClient->getInputDevice();
if (!inputDevice.isValid()) { inputDevice = CAudioDeviceInfo::getDefaultInputDevice(); }
CAudioDeviceInfo outputDevice = m_voiceClient->getOutputDevice();
if (!outputDevice.isValid()) { outputDevice = CAudioDeviceInfo::getDefaultOutputDevice(); }
const QString outputDeviceName = m_outputDeviceSetting.get();
const CAudioDeviceInfo outputDevice = this->getAudioOutputDevices().findByNameOrDefault(outputDeviceName, CAudioDeviceInfo::getDefaultOutputDevice());
CAudioDeviceInfoList devices;
devices.push_back(inputDevice);
@@ -178,14 +189,9 @@ namespace BlackCore
if (!m_voiceClient) { return; }
if (!inputDevice.getName().isEmpty()) { m_inputDeviceSetting.setAndSave(inputDevice.getName()); }
if (!outputDevice.getName().isEmpty()) { m_outputDeviceSetting.setAndSave(outputDevice.getName()); }
const bool changed = m_voiceClient->restartWithNewDevices(inputDevice, outputDevice);
const CVoiceSetup vs = m_voiceSettings.getThreadLocal();
m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl());
if (changed)
{
emit this->changedSelectedAudioDevices(this->getCurrentAudioDevices());
}
m_voiceClient->restartWithNewDevices(inputDevice, outputDevice);
emit this->changedSelectedAudioDevices(this->getCurrentAudioDevices());
}
void IContextAudio::setVoiceOutputVolume(int volume)
@@ -355,7 +361,8 @@ namespace BlackCore
void IContextAudio::onChangedVoiceSettings()
{
// void
const CVoiceSetup vs = m_voiceSettings.getThreadLocal();
m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl());
}
void IContextAudio::audioIncreaseVolume(bool enabled)
@@ -416,15 +423,7 @@ namespace BlackCore
m_voiceClient->updateVoiceServerUrl(vs.getAfvVoiceServerUrl());
const CUser connectedUser = this->getIContextNetwork()->getConnectedServer().getUser();
const QString inputDeviceName = m_inputDeviceSetting.get();
const CAudioDeviceInfo input = this->getAudioInputDevices().findByNameOrDefault(inputDeviceName, CAudioDeviceInfo::getDefaultInputDevice());
const QString outputDeviceName = m_outputDeviceSetting.get();
const CAudioDeviceInfo output = this->getAudioOutputDevices().findByNameOrDefault(outputDeviceName, CAudioDeviceInfo::getDefaultOutputDevice());
m_voiceClient->connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString());
m_voiceClient->startAudio(input, output, {0, 1});
}
else if (to.isDisconnected())
{

View File

@@ -17,6 +17,7 @@
#include "blackcore/corefacade.h"
#include "blackcore/corefacadeconfig.h"
#include "blackcore/blackcoreexport.h"
#include "blackcore/afv/audio/receiversampleprovider.h"
#include "blacksound/selcalplayer.h"
#include "blacksound/notificationplayer.h"
#include "blackmisc/macos/microphoneaccess.h"
@@ -94,9 +95,6 @@ namespace BlackCore
// -------- parts which can run in core and GUI, referring to local voice client ------------
//! Reference to voice client
BlackCore::Afv::Clients::CAfvClient *voiceClient() { return m_voiceClient.data(); }
//! Audio devices
//! @{
BlackMisc::Audio::CAudioDeviceInfoList getAudioDevices() const;
@@ -144,6 +142,9 @@ namespace BlackCore
//! Audio runs where
const BlackMisc::CIdentifier &audioRunsWhere() const;
bool isEnabledComUnit(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const;
bool isTransmittingdComUnit(BlackMisc::Aviation::CComSystem::ComUnit comUnit) const;
// -------- parts which can run in core and GUI, referring to local voice client ------------
signals:
@@ -165,6 +166,16 @@ namespace BlackCore
//! Changed slection of audio devices
void changedSelectedAudioDevices(const BlackMisc::Audio::CAudioDeviceInfoList &devices);
//! VU levels @{
void inputVolumePeakVU(double value);
void outputVolumePeakVU(double value);
//! @}
void receivingCallsignsChanged(const BlackCore::Afv::Audio::TransceiverReceivingCallsignsChangedArgs &args);
//! Client updated from own aicraft data
void updatedFromOwnAircraftCockpit();
// -------- local settings, not DBus relayed -------
public slots:

View File

@@ -9,8 +9,6 @@
#include "blackgui/components/audiodevicevolumesetupcomponent.h"
#include "blackgui/guiapplication.h"
#include "blackgui/guiutility.h"
#include "blackcore/afv/clients/afvclient.h"
#include "blackcore/context/contextaudioimpl.h"
#include "blackmisc/audio/audiodeviceinfo.h"
@@ -27,7 +25,6 @@
#include <QFileDialog>
using namespace BlackCore;
using namespace BlackCore::Afv::Clients;
using namespace BlackCore::Afv::Audio;
using namespace BlackCore::Context;
using namespace BlackMisc;
@@ -115,16 +112,19 @@ namespace BlackGui
c = connect(sGui->getIContextAudio(), &IContextAudio::changedSelectedAudioDevices, this, &CAudioDeviceVolumeSetupComponent::onCurrentAudioDevicesChanged, Qt::QueuedConnection);
Q_ASSERT(c);
CAfvClient *afvClient = CAudioDeviceVolumeSetupComponent::afvClient();
if (afvClient)
{
connect(afvClient, &CAfvClient::outputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onOutputVU);
connect(afvClient, &CAfvClient::inputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onInputVU);
connect(afvClient, &CAfvClient::receivingCallsignsChanged, this, &CAudioDeviceVolumeSetupComponent::onReceivingCallsignsChanged, Qt::QueuedConnection);
connect(afvClient, &CAfvClient::updatedFromOwnAircraftCockpit, this, &CAudioDeviceVolumeSetupComponent::onUpdatedClientWithCockpitData, Qt::QueuedConnection);
c = connect(sGui->getIContextAudio(), &IContextAudio::outputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onOutputVU, Qt::QueuedConnection);
Q_ASSERT(c);
this->onUpdatedClientWithCockpitData();
}
c = connect(sGui->getIContextAudio(), &IContextAudio::inputVolumePeakVU, this, &CAudioDeviceVolumeSetupComponent::onInputVU, Qt::QueuedConnection);
Q_ASSERT(c);
c = connect(sGui->getIContextAudio(), &IContextAudio::receivingCallsignsChanged, this, &CAudioDeviceVolumeSetupComponent::onReceivingCallsignsChanged, Qt::QueuedConnection);
Q_ASSERT(c);
c = connect(sGui->getIContextAudio(), &IContextAudio::updatedFromOwnAircraftCockpit, this, &CAudioDeviceVolumeSetupComponent::onUpdatedClientWithCockpitData, Qt::QueuedConnection);
Q_ASSERT(c);
this->onUpdatedClientWithCockpitData();
}
Q_UNUSED(c)
}
@@ -193,13 +193,11 @@ namespace BlackGui
void CAudioDeviceVolumeSetupComponent::setTransmitReceiveInUiFromVoiceClient()
{
const CAfvClient *client = this->afvClient();
if (!client) { return; }
const bool com1Enabled = client->isEnabledComUnit(CComSystem::Com1);
const bool com2Enabled = client->isEnabledComUnit(CComSystem::Com2);
const bool com1Enabled = sGui->getIContextAudio()->isEnabledComUnit(CComSystem::Com1);
const bool com2Enabled = sGui->getIContextAudio()->isEnabledComUnit(CComSystem::Com2);
const bool com1Tx = com1Enabled && client->isTransmittingdComUnit(CComSystem::Com1);
const bool com2Tx = com2Enabled && client->isTransmittingdComUnit(CComSystem::Com2);
const bool com1Tx = com1Enabled && sGui->getIContextAudio()->isTransmittingdComUnit(CComSystem::Com1);
const bool com2Tx = com2Enabled && sGui->getIContextAudio()->isTransmittingdComUnit(CComSystem::Com2);
// we do not have receiving
const bool com1Rx = com1Enabled;
@@ -298,13 +296,6 @@ namespace BlackGui
return devices.findByName(ui->cb_SetupAudioOutputDevice->currentText());
}
CAfvClient *CAudioDeviceVolumeSetupComponent::afvClient()
{
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return nullptr; }
if (!sGui->getIContextAudio()->isUsingImplementingObject()) { return nullptr; }
return sGui->getCoreFacade()->getCContextAudio()->voiceClient();
}
void CAudioDeviceVolumeSetupComponent::onAudioDeviceSelected(int index)
{
if (!sGui || sGui->isShuttingDown() || !sGui->getIContextAudio()) { return; }

View File

@@ -100,6 +100,7 @@ namespace BlackGui
void onReloadDevices();
void onResetVolumeIn();
void onResetVolumeOut();
// TODO: Move TransceiverReceivingCallsignsChangedArgs to Blackmisc
void onReceivingCallsignsChanged(const BlackCore::Afv::Audio::TransceiverReceivingCallsignsChangedArgs &args);
void onUpdatedClientWithCockpitData();
@@ -111,8 +112,6 @@ namespace BlackGui
void setTransmitReceiveInUiFromVoiceClient();
//! @}
static BlackCore::Afv::Clients::CAfvClient *afvClient();
QScopedPointer<Ui::CAudioDeviceVolumeSetupComponent> ui;
BlackMisc::CDigestSignal m_volumeSliderChanged { this, &CAudioDeviceVolumeSetupComponent::saveVolumes, 1000, 10 };
BlackMisc::CSetting<BlackMisc::Audio::TSettings> m_audioSettings { this, &CAudioDeviceVolumeSetupComponent::reloadSettings };