refs #320 Remove deprecated code

* Mic and squelch tests
* VoiceVatlib threading
* Exception handling
This commit is contained in:
Roland Winklmeier
2014-12-25 16:19:22 +01:00
parent cb7ad005b0
commit 111c539e89
10 changed files with 9 additions and 503 deletions

View File

@@ -19,13 +19,9 @@ Client::Client(QObject *parent) :
QObject(parent), QObject(parent),
m_voice(new BlackCore::CVoiceVatlib()) m_voice(new BlackCore::CVoiceVatlib())
{ {
m_voice->moveToThread(&m_threadVoice);
m_threadVoice.start();
m_channelCom1 = m_voice->getVoiceChannel(0); m_channelCom1 = m_voice->getVoiceChannel(0);
using namespace BlackCore; using namespace BlackCore;
connect(m_voice, &IVoice::squelchTestFinished, this, &Client::onSquelchTestFinished);
connect(m_voice, &IVoice::micTestFinished, this, &Client::onMicTestFinished);
connect(m_channelCom1.data(), &IVoiceChannel::connectionStatusChanged, this, &Client::connectionStatusChanged); connect(m_channelCom1.data(), &IVoiceChannel::connectionStatusChanged, this, &Client::connectionStatusChanged);
connect(m_channelCom1.data(), &IVoiceChannel::audioStarted, this, &Client::audioStartedStream); connect(m_channelCom1.data(), &IVoiceChannel::audioStarted, this, &Client::audioStartedStream);
connect(m_channelCom1.data(), &IVoiceChannel::audioStopped, this, &Client::audioStoppedStream); connect(m_channelCom1.data(), &IVoiceChannel::audioStopped, this, &Client::audioStoppedStream);
@@ -36,8 +32,6 @@ Client::Client(QObject *parent) :
m_commands["help"] = std::bind(&Client::help, this, _1); m_commands["help"] = std::bind(&Client::help, this, _1);
m_commands["echo"] = std::bind(&Client::echo, this, _1); m_commands["echo"] = std::bind(&Client::echo, this, _1);
m_commands["exit"] = std::bind(&Client::exit, this, _1); m_commands["exit"] = std::bind(&Client::exit, this, _1);
m_commands["squelchtest"] = std::bind(&Client::squelchTestCmd, this, _1);
m_commands["mictest"] = std::bind(&Client::micTestCmd, this, _1);
m_commands["setcallsign"] = std::bind(&Client::setCallsignCmd, this, _1); m_commands["setcallsign"] = std::bind(&Client::setCallsignCmd, this, _1);
m_commands["initconnect"] = std::bind(&Client::initiateConnectionCmd, this, _1); m_commands["initconnect"] = std::bind(&Client::initiateConnectionCmd, this, _1);
m_commands["termconnect"] = std::bind(&Client::terminateConnectionCmd, this, _1); m_commands["termconnect"] = std::bind(&Client::terminateConnectionCmd, this, _1);
@@ -97,25 +91,9 @@ void Client::echo(QTextStream &line)
void Client::exit(QTextStream &) void Client::exit(QTextStream &)
{ {
qDebug() << "Shutting down..."; qDebug() << "Shutting down...";
m_threadVoice.quit();
m_threadVoice.wait(5000);
emit quit(); emit quit();
} }
void Client::squelchTestCmd(QTextStream & /** args **/)
{
std::cout << "Running squelch test. Please be quiet for 5 seconds..." << std::endl;
printLinePrefix();
m_voice->runSquelchTest();
}
void Client::micTestCmd(QTextStream & /** args **/)
{
std::cout << "Running mic test. Speak normally for 5 seconds..." << std::endl;
printLinePrefix();
m_voice->runMicrophoneTest();
}
void Client::setCallsignCmd(QTextStream &args) void Client::setCallsignCmd(QTextStream &args)
{ {
QString callsign; QString callsign;
@@ -187,17 +165,6 @@ void Client::disableLoopbackCmd(QTextStream &/*args*/)
std::cout << "Disabling audio loopback." << std::endl; std::cout << "Disabling audio loopback." << std::endl;
m_voice->enableAudioLoopback(false); m_voice->enableAudioLoopback(false);
printLinePrefix(); printLinePrefix();
}
void Client::onSquelchTestFinished()
{
std::cout << "Input squelch: " << m_voice->inputSquelch() << std::endl;
printLinePrefix();
}
void Client::onMicTestFinished()
{
std::cout << "Mic test result: " << (int)m_voice->micTestResult() << std::endl;
printLinePrefix(); printLinePrefix();
} }

View File

@@ -33,8 +33,6 @@ private: //commands
void help(QTextStream &args); void help(QTextStream &args);
void echo(QTextStream &args); void echo(QTextStream &args);
void exit(QTextStream &args); void exit(QTextStream &args);
void squelchTestCmd(QTextStream &args);
void micTestCmd(QTextStream &args);
void setCallsignCmd(QTextStream &args); void setCallsignCmd(QTextStream &args);
void initiateConnectionCmd(QTextStream &args); void initiateConnectionCmd(QTextStream &args);
void terminateConnectionCmd(QTextStream &args); void terminateConnectionCmd(QTextStream &args);
@@ -46,9 +44,6 @@ private: //commands
void printLinePrefix(); void printLinePrefix();
public slots:
void onSquelchTestFinished();
void onMicTestFinished();
private slots: private slots:
void connectionStatusChanged(BlackCore::IVoiceChannel::ConnectionStatus oldStatus, void connectionStatusChanged(BlackCore::IVoiceChannel::ConnectionStatus oldStatus,
@@ -61,7 +56,6 @@ private slots:
private: private:
QMap<QString, std::function<void(QTextStream &)>> m_commands; QMap<QString, std::function<void(QTextStream &)>> m_commands;
BlackCore::IVoice *m_voice; BlackCore::IVoice *m_voice;
QThread m_threadVoice;
QPointer<BlackCore::IVoiceChannel> m_channelCom1; QPointer<BlackCore::IVoiceChannel> m_channelCom1;
}; };

View File

@@ -35,18 +35,11 @@ namespace BlackCore
m_voice(new CVoiceVatlib()) m_voice(new CVoiceVatlib())
{ {
// 1. Init by "voice driver" // 1. Init by "voice driver"
m_voice->moveToThread(&m_threadVoice);
m_threadVoice.start();
// 2. Register PTT hotkey function // 2. Register PTT hotkey function
CVoiceVatlib *voice = m_voice.data();
m_inputManager = CInputManager::getInstance(); m_inputManager = CInputManager::getInstance();
m_handlePtt = m_inputManager->registerHotkeyFunc(CHotkeyFunction::Ptt(), voice, &CVoiceVatlib::handlePushToTalk); m_handlePtt = m_inputManager->registerHotkeyFunc(CHotkeyFunction::Ptt(), voice, &CVoiceVatlib::handlePushToTalk);
// 3. Signal / slots
connect(voice, &CVoiceVatlib::micTestFinished, this, &CContextAudio::audioTestCompleted);
connect(voice, &CVoiceVatlib::squelchTestFinished, this, &CContextAudio::audioTestCompleted);
m_channelCom1 = m_voice->getVoiceChannel(0); m_channelCom1 = m_voice->getVoiceChannel(0);
m_channelCom1->setMyAircraftCallsign(getIContextOwnAircraft()->getOwnAircraft().getCallsign()); m_channelCom1->setMyAircraftCallsign(getIContextOwnAircraft()->getOwnAircraft().getCallsign());
connect(m_channelCom1.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_com1ConnectionStatusChanged); connect(m_channelCom1.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_com1ConnectionStatusChanged);
@@ -64,8 +57,6 @@ namespace BlackCore
CContextAudio::~CContextAudio() CContextAudio::~CContextAudio()
{ {
this->leaveAllVoiceRooms(); this->leaveAllVoiceRooms();
m_threadVoice.quit();
m_threadVoice.wait(1000);
} }
/* /*
@@ -380,7 +371,7 @@ namespace BlackCore
{ {
Q_ASSERT(this->m_voice); Q_ASSERT(this->m_voice);
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
this->m_voice->runMicrophoneTest(); // Deprecated
} }
/* /*
@@ -388,9 +379,7 @@ namespace BlackCore
*/ */
void CContextAudio::runSquelchTest() void CContextAudio::runSquelchTest()
{ {
Q_ASSERT(this->m_voice); CLogMessage(this).warning("This method is deprecated and will be removed soon");
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO;
this->m_voice->runSquelchTest();
} }
/* /*
@@ -398,9 +387,8 @@ namespace BlackCore
*/ */
QString CContextAudio::getMicrophoneTestResult() const QString CContextAudio::getMicrophoneTestResult() const
{ {
Q_ASSERT(this->m_voice); CLogMessage(this).warning("This method is deprecated and will be removed soon");
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; return QString();
return this->m_voice->micTestResultAsString();
} }
/* /*
@@ -408,9 +396,8 @@ namespace BlackCore
*/ */
double CContextAudio::getSquelchValue() const double CContextAudio::getSquelchValue() const
{ {
Q_ASSERT(this->m_voice); CLogMessage(this).warning("This method is deprecated and will be removed soon");
CLogMessage(this, CLogCategory::contextSlot()).debug() << Q_FUNC_INFO; return 0.0;
return static_cast<double>(this->m_voice->inputSquelch());
} }
/* /*

View File

@@ -168,7 +168,6 @@ namespace BlackCore
CInputManager *m_inputManager = nullptr; CInputManager *m_inputManager = nullptr;
CInputManager::RegistrationHandle m_handlePtt; CInputManager::RegistrationHandle m_handlePtt;
QThread m_threadVoice;
QPointer<IVoiceChannel> m_channelCom1; QPointer<IVoiceChannel> m_channelCom1;
QPointer<IVoiceChannel> m_channelCom2; QPointer<IVoiceChannel> m_channelCom2;
}; };

View File

@@ -71,43 +71,9 @@ namespace BlackCore
*/ */
virtual const BlackMisc::Audio::CAudioDeviceInfo defaultAudioOutputDevice() const = 0; virtual const BlackMisc::Audio::CAudioDeviceInfo defaultAudioOutputDevice() const = 0;
/************************************************
* SETUP TESTS
***********************************************/
/*!
* \brief Runs a 5 seconds test, measuring your background noise.
*/
virtual void runSquelchTest() = 0;
/*!
* \brief Runs a 5 seconds test, measuring the qualitiy of your mic input
*/
virtual void runMicrophoneTest() = 0;
/*!
* \brief Value of the measured squelch
* \return
*/
virtual float inputSquelch() const = 0;
/*!
* \brief Result of the mic test.
* \return
*/
virtual qint32 micTestResult() const = 0;
/*!
* \brief Result of the mic test as human readable string
* \return
*/
virtual QString micTestResultAsString() const = 0;
//! Get voice channel object //! Get voice channel object
virtual IVoiceChannel *getVoiceChannel(qint32 channelIndex) const = 0; virtual IVoiceChannel *getVoiceChannel(qint32 channelIndex) const = 0;
public slots:
/*! /*!
* \brief Current input device * \brief Current input device
*/ */
@@ -133,26 +99,6 @@ namespace BlackCore
* \param enable (default true) * \param enable (default true)
*/ */
virtual void enableAudioLoopback(bool enable = true) = 0; virtual void enableAudioLoopback(bool enable = true) = 0;
signals:
// Test signals
/*!
* \brief Squelch test completed
*/
void squelchTestFinished();
/*!
* \brief Microphone test completed
*/
void micTestFinished();
// non protocol related signals
/*!
* We sent a message about the status of the network connection, for the attention of the user.
*/
void statusMessage(const BlackMisc::CStatusMessage &message);
}; };
} // namespace BlackCore } // namespace BlackCore

View File

@@ -46,9 +46,6 @@ namespace BlackCore
//! Leave voice room //! Leave voice room
virtual void leaveVoiceRoom() = 0; virtual void leaveVoiceRoom() = 0;
//! Set room output volume
virtual void setRoomOutputVolume(const qint32 volume) = 0;
//! Start transmitting //! Start transmitting
virtual void startTransmitting() = 0; virtual void startTransmitting() = 0;

View File

@@ -36,7 +36,6 @@ namespace BlackCore
q_ptr(parent) q_ptr(parent)
{ {
m_roomIndex.store(InvalidRoomIndex); m_roomIndex.store(InvalidRoomIndex);
m_volume.store(100);
m_connectionRefCount.store(0); m_connectionRefCount.store(0);
m_outputEnabled.store(true); m_outputEnabled.store(true);
m_roomStatus.store(IVoiceChannel::Disconnected); m_roomStatus.store(IVoiceChannel::Disconnected);
@@ -367,12 +366,6 @@ namespace BlackCore
} }
} }
// Set room volume
void CVoiceChannelVatlib::setRoomOutputVolume(const qint32 volume)
{
d_ptr->setRoomOutputVolume(volume);
}
void CVoiceChannelVatlib::startTransmitting() void CVoiceChannelVatlib::startTransmitting()
{ {
d_ptr->startTransmitting(); d_ptr->startTransmitting();

View File

@@ -43,9 +43,6 @@ namespace BlackCore
//! \copydoc IVoiceChannel::leaveVoiceRoom //! \copydoc IVoiceChannel::leaveVoiceRoom
virtual void leaveVoiceRoom() override; virtual void leaveVoiceRoom() override;
//! \copydoc IVoiceChannel::setRoomOutputVolume
virtual void setRoomOutputVolume(const qint32 volume) override;
//! \copydoc IVoiceChannel::startTransmitting //! \copydoc IVoiceChannel::startTransmitting
virtual void startTransmitting() override; virtual void startTransmitting() override;

View File

@@ -21,41 +21,10 @@ namespace BlackCore
* Constructor * Constructor
*/ */
CVoiceVatlib::CVoiceVatlib(QObject *parent) : CVoiceVatlib::CVoiceVatlib(QObject *parent) :
IVoice(parent), IVoice(parent)
m_vatlib(Cvatlib_Voice_Simple::Create(), Cvatlib_Voice_Simple_Deleter::cleanup),
// m_audioOutput(nullptr), // removed #227
m_inputSquelch(-1),
m_micTestResult(Cvatlib_Voice_Simple::agc_Ok),
m_lockCurrentOutputDevice(QMutex::Recursive),
m_lockCurrentInputDevice(QMutex::Recursive),
m_lockDeviceList(QMutex::Recursive)
{ {
try this->m_currentInputDevice = this->defaultAudioInputDevice();
{ this->m_currentOutputDevice = this->defaultAudioOutputDevice();
// we use reset here until issue #277 is resolved
// easier to find root cause
// m_audioOutput.reset(new QAudioOutput());
m_vatlib->Setup(true, 3290, 2, 1, onRoomStatusUpdate, this);
m_vatlib->GetInputDevices(onInputHardwareDeviceReceived, this);
m_vatlib->GetOutputDevices(onOutputHardwareDeviceReceived, this);
this->m_currentInputDevice = this->defaultAudioInputDevice();
this->m_currentOutputDevice = this->defaultAudioOutputDevice();
for (int ii = 0; ii < 2; ++ii)
{
IVoiceChannel *channel = new CVoiceChannelVatlib(m_vatlib, this);
Q_ASSERT(channel);
m_hashChannelIndex.insert(ii, channel);
}
// do processing
this->startTimer(10);
}
catch (...)
{
this->exceptionDispatcher(Q_FUNC_INFO);
}
} }
/* /*
@@ -68,7 +37,6 @@ namespace BlackCore
*/ */
const BlackMisc::Audio::CAudioDeviceInfoList &CVoiceVatlib::audioDevices() const const BlackMisc::Audio::CAudioDeviceInfoList &CVoiceVatlib::audioDevices() const
{ {
QMutexLocker lockForReading(&m_lockDeviceList);
return m_devices; return m_devices;
} }
@@ -95,7 +63,6 @@ namespace BlackCore
*/ */
CAudioDeviceInfo CVoiceVatlib::getCurrentOutputDevice() const CAudioDeviceInfo CVoiceVatlib::getCurrentOutputDevice() const
{ {
QMutexLocker locker(&m_lockCurrentOutputDevice);
return m_currentOutputDevice; return m_currentOutputDevice;
} }
@@ -104,7 +71,6 @@ namespace BlackCore
*/ */
CAudioDeviceInfo CVoiceVatlib::getCurrentInputDevice() const CAudioDeviceInfo CVoiceVatlib::getCurrentInputDevice() const
{ {
QMutexLocker locker(&m_lockCurrentInputDevice);
return m_currentInputDevice; return m_currentInputDevice;
} }
@@ -113,31 +79,6 @@ namespace BlackCore
*/ */
void CVoiceVatlib::setInputDevice(const BlackMisc::Audio::CAudioDeviceInfo &device) void CVoiceVatlib::setInputDevice(const BlackMisc::Audio::CAudioDeviceInfo &device)
{ {
std::lock_guard<TVatlibPointer> locker(m_vatlib);
Q_ASSERT_X(m_vatlib->IsValid() && m_vatlib->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
if (!device.isValid())
{
qWarning() << "Cannot set invalid input device!";
return;
}
try
{
if (!m_vatlib->SetInputDevice(device.getIndex()))
{
qWarning() << "Setting input device failed";
}
if (!m_vatlib->IsInputDeviceAlive())
{
qWarning() << "Input device hit a fatal error";
}
QMutexLocker writeLocker(&m_lockCurrentInputDevice);
this->m_currentInputDevice = device;
}
catch (...)
{
exceptionDispatcher(Q_FUNC_INFO);
}
} }
/* /*
@@ -145,143 +86,6 @@ namespace BlackCore
*/ */
void CVoiceVatlib::setOutputDevice(const BlackMisc::Audio::CAudioDeviceInfo &device) void CVoiceVatlib::setOutputDevice(const BlackMisc::Audio::CAudioDeviceInfo &device)
{ {
std::lock_guard<TVatlibPointer> locker(m_vatlib);
Q_ASSERT_X(m_vatlib->IsValid() && m_vatlib->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
if (!device.isValid())
{
qWarning() << "Cannot set invalid output device!";
return;
}
try
{
// there is no return value here: https://dev.vatsim-germany.org/issues/115
m_vatlib->SetOutputDevice(0, device.getIndex());
if (!m_vatlib->IsOutputDeviceAlive(0))
{
qWarning() << "Output device hit a fatal error";
}
QMutexLocker writeLocker(&m_lockCurrentOutputDevice);
this->m_currentOutputDevice = device;
}
catch (...)
{
exceptionDispatcher(Q_FUNC_INFO);
}
}
void CVoiceVatlib::enableAudioLoopback(bool enable)
{
if (enable == m_isAudioLoopbackEnabled)
return;
std::lock_guard<TVatlibPointer> locker(m_vatlib);
Q_ASSERT_X(m_vatlib->IsValid() && m_vatlib->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
try
{
m_vatlib->SetAudioLoopback(0, enable);
}
catch (...)
{
this->exceptionDispatcher(Q_FUNC_INFO);
}
// bools are atomic. No need to protect it with a mutex
m_isAudioLoopbackEnabled = enable;
}
/*
* Squelch test
*/
void CVoiceVatlib::runSquelchTest()
{
std::lock_guard<TVatlibPointer> locker(m_vatlib);
Q_ASSERT_X(m_vatlib->IsValid() && m_vatlib->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
try
{
m_vatlib->BeginFindSquelch();
}
catch (...)
{
this->exceptionDispatcher(Q_FUNC_INFO);
}
// Start the timer only if no exception was thrown before
QTimer::singleShot(5000, this, SLOT(onEndFindSquelch()));
}
/*
* Start microphone test
*/
void CVoiceVatlib::runMicrophoneTest()
{
std::lock_guard<TVatlibPointer> locker(m_vatlib);
Q_ASSERT_X(m_vatlib->IsValid() && m_vatlib->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
try
{
m_vatlib->BeginMicTest();
// Start the timer only if no exception was thrown before
QTimer::singleShot(5000, this, SLOT(onEndMicTest()));
}
catch (...)
{
this->exceptionDispatcher(Q_FUNC_INFO);
}
}
/*
* Input squelch volume
*/
float CVoiceVatlib::inputSquelch() const
{
return m_inputSquelch;
}
/*
* Mic test
*/
qint32 CVoiceVatlib::micTestResult() const
{
return m_micTestResult;
}
/*
* Mic test, result as string
*/
QString CVoiceVatlib::micTestResultAsString() const
{
QString result;
// Due to a standard defect, some compilers do not accept two consecutive implicit conversions.
// Hence calling load() here.
// References:
// http://stackoverflow.com/questions/25143860/implicit-convertion-from-class-to-enumeration-type-in-switch-conditional
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3323.pdf
switch (m_micTestResult.load())
{
case Cvatlib_Voice_Simple::agc_Ok:
result = "The test went ok";
break;
case Cvatlib_Voice_Simple::agc_BkgndNoiseLoud:
result = "The overall background noise is very loud and may be a nuisance to others";
break;
case Cvatlib_Voice_Simple::agc_TalkDrownedOut:
result = "The overall background noise is loud enough that others probably wont be able to distinguish speech from it";
break;
case Cvatlib_Voice_Simple::agc_TalkMicHot:
result = "The overall mic volume is too hot, you should lower the volume in the windows volume control panel";
break;
case Cvatlib_Voice_Simple::agc_TalkMicCold:
result = "The overall mic volume is too cold, you should raise the volume in the windows control panel and enable mic boost if needed";
break;
default:
result = "Unknown result.";
break;
}
return result;
} }
IVoiceChannel *CVoiceVatlib::getVoiceChannel(qint32 channelIndex) const IVoiceChannel *CVoiceVatlib::getVoiceChannel(qint32 channelIndex) const
@@ -321,67 +125,6 @@ namespace BlackCore
*/ */
void CVoiceVatlib::timerEvent(QTimerEvent *) void CVoiceVatlib::timerEvent(QTimerEvent *)
{ {
std::lock_guard<TVatlibPointer> locker(m_vatlib);
Q_ASSERT_X(m_vatlib->IsValid() && m_vatlib->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
try
{
this->m_vatlib->DoProcessing();
}
catch (...)
{
this->exceptionDispatcher(Q_FUNC_INFO);
}
}
/*
* Find squelch
*/
void CVoiceVatlib::onEndFindSquelch()
{
std::lock_guard<TVatlibPointer> locker(m_vatlib);
Q_ASSERT_X(m_vatlib->IsValid() && m_vatlib->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
try
{
m_vatlib->EndFindSquelch();
m_inputSquelch = m_vatlib->GetInputSquelch();
emit squelchTestFinished();
}
catch (...)
{
this->exceptionDispatcher(Q_FUNC_INFO);
}
}
void CVoiceVatlib::onEndMicTest()
{
std::lock_guard<TVatlibPointer> locker(m_vatlib);
Q_ASSERT_X(m_vatlib->IsValid() && m_vatlib->IsSetup(), "CVoiceVatlib", "Cvatlib_Voice_Simple invalid or not setup!");
try
{
m_micTestResult = m_vatlib->EndMicTest();
emit micTestFinished();
}
catch (...)
{
this->exceptionDispatcher(Q_FUNC_INFO);
}
}
/********************************** * * * * * * * * * * * * * * * * * * * ************************************/
/********************************** shimlib callbacks ************************************/
/********************************** * * * * * * * * * * * * * * * * * * * ************************************/
/*!
* \brief Cast from *void to *CVoiceVatlib
* \param cbvar
* \return
*/
CVoiceVatlib *cbvar_cast_voice(void *cbvar)
{
return static_cast<CVoiceVatlib *>(cbvar);
} }
/* /*
@@ -394,61 +137,6 @@ namespace BlackCore
vatlibRoom->onRoomStatusUpdate(roomIndex, upd); vatlibRoom->onRoomStatusUpdate(roomIndex, upd);
} }
/*
* Input hardware received
*/
void CVoiceVatlib::onInputHardwareDeviceReceived(Cvatlib_Voice_Simple *obj, const char *name, void *cbVar)
{
Q_UNUSED(obj)
BlackMisc::Audio::CAudioDeviceInfo inputDevice(BlackMisc::Audio::CAudioDeviceInfo::InputDevice, cbvar_cast_voice(cbVar)->m_devices.count(BlackMisc::Audio::CAudioDeviceInfo::InputDevice), QString(name));
QMutexLocker lockForWriting(&(cbvar_cast_voice(cbVar)->m_lockDeviceList));
cbvar_cast_voice(cbVar)->m_devices.push_back(inputDevice);
}
/*
* Output hardware received
*/
void CVoiceVatlib::onOutputHardwareDeviceReceived(Cvatlib_Voice_Simple *obj, const char *name, void *cbVar)
{
Q_UNUSED(obj)
BlackMisc::Audio::CAudioDeviceInfo outputDevice(BlackMisc::Audio::CAudioDeviceInfo::OutputDevice, cbvar_cast_voice(cbVar)->m_devices.count(BlackMisc::Audio::CAudioDeviceInfo::OutputDevice), QString(name));
QMutexLocker lockForWriting(&(cbvar_cast_voice(cbVar)->m_lockDeviceList));
cbvar_cast_voice(cbVar)->m_devices.push_back(outputDevice);
}
/*
* Forward exception as signal
*/
void CVoiceVatlib::exceptionDispatcher(const char *caller)
{
QString msg("Caller: ");
msg.append(caller).append(" ").append("Exception: ");
try
{
throw;
}
catch (const NetworkNotConnectedException &e)
{
// this could be caused by a race condition during normal operation, so not an error
CLogMessage(this).debug() << "NetworkNotConnectedException" << e.what() << "in" << caller;
}
catch (const VatlibException &e)
{
CLogMessage(this).error("VatlibException %1 in %2") << e.what() << caller;
Q_ASSERT(false);
}
catch (const std::exception &e)
{
CLogMessage(this).error("std::exception %1 in %2") << e.what() << caller;
Q_ASSERT(false);
}
catch (...)
{
CLogMessage(this).error("Unknown exception in %1") << caller;
Q_ASSERT(false);
}
}
void CVoiceVatlib::onRoomStatusUpdate(qint32 roomIndex, Cvatlib_Voice_Simple::roomStatusUpdate roomStatus) void CVoiceVatlib::onRoomStatusUpdate(qint32 roomIndex, Cvatlib_Voice_Simple::roomStatusUpdate roomStatus)
{ {
QList<IVoiceChannel *> voiceChannels = m_hashChannelIndex.values(); QList<IVoiceChannel *> voiceChannels = m_hashChannelIndex.values();

View File

@@ -7,18 +7,8 @@
#define BLACKCORE_VOICE_VATLIB_H #define BLACKCORE_VOICE_VATLIB_H
#include "voice.h" #include "voice.h"
#include "../blacksound/soundgenerator.h"
#include "../blackmisc/nwuserlist.h"
#include "../blackmisc/avcallsignlist.h"
#include "../blackmisc/sharedlockablepointer.h"
#include <QMap>
#include <QSet>
#include <QString> #include <QString>
#include <QMutex>
#include <QReadWriteLock>
#include <atomic>
#include <utility>
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#ifndef NOMINMAX #ifndef NOMINMAX
@@ -31,24 +21,6 @@
namespace BlackCore namespace BlackCore
{ {
/*!
* \brief Deleter
*/
struct Cvatlib_Voice_Simple_Deleter
{
/*!
* \brief Cleanup
* \param pointer
*/
static inline void cleanup(Cvatlib_Voice_Simple *pointer)
{
if (pointer) pointer->Destroy();
}
};
//! Shared lockable pointer to Cvatlib_Voice_Simple
typedef BlackMisc::SharedLockablePtr<Cvatlib_Voice_Simple> TVatlibPointer;
/*! /*!
* Vatlib implementation of the IVoice interface. * Vatlib implementation of the IVoice interface.
*/ */
@@ -81,25 +53,6 @@ namespace BlackCore
//! \copydoc IVoice::defaultAudioOutputDevice() //! \copydoc IVoice::defaultAudioOutputDevice()
virtual const BlackMisc::Audio::CAudioDeviceInfo defaultAudioOutputDevice() const override; virtual const BlackMisc::Audio::CAudioDeviceInfo defaultAudioOutputDevice() const override;
/************************************************
* SETUP TESTS
***********************************************/
//! \copydoc IVoice::runSquelchTest
virtual void runSquelchTest() override;
//! \copydoc IVoice::runMicTest
virtual void runMicrophoneTest() override;
//! \copydoc IVoice::inputSquelch
virtual float inputSquelch() const override;
//! \copydoc IVoice::micTestResult()
virtual qint32 micTestResult() const override;
//! \copydoc IVoice::micTestResultAsString
virtual QString micTestResultAsString() const override;
//! \copydoc IVoice::getVoiceChannel //! \copydoc IVoice::getVoiceChannel
virtual IVoiceChannel *getVoiceChannel(qint32 channelIndex) const override; virtual IVoiceChannel *getVoiceChannel(qint32 channelIndex) const override;
@@ -131,34 +84,19 @@ namespace BlackCore
*/ */
virtual void timerEvent(QTimerEvent *); virtual void timerEvent(QTimerEvent *);
private slots:
// slots for Mic tests
void onEndFindSquelch();
void onEndMicTest();
private: private:
// shimlib callbacks // shimlib callbacks
static void onRoomStatusUpdate(Cvatlib_Voice_Simple *obj, Cvatlib_Voice_Simple::roomStatusUpdate upd, qint32 roomIndex, void *cbVar); static void onRoomStatusUpdate(Cvatlib_Voice_Simple *obj, Cvatlib_Voice_Simple::roomStatusUpdate upd, qint32 roomIndex, void *cbVar);
static void onInputHardwareDeviceReceived(Cvatlib_Voice_Simple *obj, const char *name, void *cbVar);
static void onOutputHardwareDeviceReceived(Cvatlib_Voice_Simple *obj, const char *name, void *cbVar);
void exceptionDispatcher(const char *caller);
void onRoomStatusUpdate(qint32 roomIndex, Cvatlib_Voice_Simple::roomStatusUpdate roomStatus); void onRoomStatusUpdate(qint32 roomIndex, Cvatlib_Voice_Simple::roomStatusUpdate roomStatus);
TVatlibPointer m_vatlib;
BlackMisc::Audio::CAudioDeviceInfoList m_devices; /*!< in and output devices */ BlackMisc::Audio::CAudioDeviceInfoList m_devices; /*!< in and output devices */
BlackMisc::Audio::CAudioDeviceInfo m_currentOutputDevice; BlackMisc::Audio::CAudioDeviceInfo m_currentOutputDevice;
BlackMisc::Audio::CAudioDeviceInfo m_currentInputDevice; BlackMisc::Audio::CAudioDeviceInfo m_currentInputDevice;
std::atomic<float> m_inputSquelch;
std::atomic<Cvatlib_Voice_Simple::agc> m_micTestResult;
QHash<qint32, IVoiceChannel *> m_hashChannelIndex; QHash<qint32, IVoiceChannel *> m_hashChannelIndex;
bool m_isAudioLoopbackEnabled; /*!< A flag whether audio loopback is enabled or not */ bool m_isAudioLoopbackEnabled; /*!< A flag whether audio loopback is enabled or not */
// Thread serialization
mutable QMutex m_lockCurrentOutputDevice;
mutable QMutex m_lockCurrentInputDevice;
mutable QMutex m_lockDeviceList;
}; };
} // namespace } // namespace