refs #255 update context and sample to use the new IVoiceChannel API

This commit is contained in:
Roland Winklmeier
2014-07-23 13:28:18 +01:00
parent c05b8808b8
commit ff65f3f39d
4 changed files with 136 additions and 70 deletions

View File

@@ -21,15 +21,16 @@ Client::Client(QObject *parent) :
{
m_voice->moveToThread(&m_threadVoice);
m_threadVoice.start();
m_channelCom1 = m_voice->getVoiceChannel(0);
using namespace BlackCore;
connect(m_voice, &IVoice::squelchTestFinished, this, &Client::onSquelchTestFinished);
connect(m_voice, &IVoice::micTestFinished, this, &Client::onMicTestFinished);
connect(m_voice, &IVoice::connectionStatusChanged, this, &Client::connectionStatusChanged);
connect(m_voice, &IVoice::audioStarted, this, &Client::audioStartedStream);
connect(m_voice, &IVoice::audioStopped, this, &Client::audioStoppedStream);
connect(m_voice, &IVoice::userJoinedRoom, this, &Client::userJoinedRoom);
connect(m_voice, &IVoice::userLeftRoom, this, &Client::userLeftRoom);
connect(m_channelCom1.data(), &IVoiceChannel::connectionStatusChanged, this, &Client::connectionStatusChanged);
connect(m_channelCom1.data(), &IVoiceChannel::audioStarted, this, &Client::audioStartedStream);
connect(m_channelCom1.data(), &IVoiceChannel::audioStopped, this, &Client::audioStoppedStream);
connect(m_channelCom1.data(), &IVoiceChannel::userJoinedRoom, this, &Client::userJoinedRoom);
connect(m_channelCom1.data(), &IVoiceChannel::userLeftRoom, this, &Client::userLeftRoom);
using namespace std::placeholders;
m_commands["help"] = std::bind(&Client::help, this, _1);
@@ -119,7 +120,7 @@ void Client::setCallsignCmd(QTextStream &args)
{
QString callsign;
args >> callsign;
m_voice->setMyAircraftCallsign(BlackMisc::Aviation::CCallsign(callsign));
m_channelCom1->setMyAircraftCallsign(BlackMisc::Aviation::CCallsign(callsign));
}
void Client::initiateConnectionCmd(QTextStream &args)
@@ -128,14 +129,14 @@ void Client::initiateConnectionCmd(QTextStream &args)
QString channel;
args >> hostname >> channel;
std::cout << "Joining voice room: " << hostname.toStdString() << "/" << channel.toStdString() << std::endl;
m_voice->joinVoiceRoom(BlackCore::IVoice::COM1, BlackMisc::Audio::CVoiceRoom(hostname, channel));
m_channelCom1->joinVoiceRoom(BlackMisc::Audio::CVoiceRoom(hostname, channel));
printLinePrefix();
}
void Client::terminateConnectionCmd(QTextStream & /** args **/)
{
std::cout << "Leaving room." << std::endl;
m_voice->leaveVoiceRoom(BlackCore::IVoice::COM1);
m_channelCom1->leaveVoiceRoom();
printLinePrefix();
}
@@ -166,7 +167,7 @@ void Client::outputDevicesCmd(QTextStream & /** args **/)
void Client::listCallsignsCmd(QTextStream &args)
{
Q_UNUSED(args)
CCallsignList callsigns = m_voice->getVoiceRoomCallsigns(BlackCore::IVoice::COM1);
CCallsignList callsigns = m_channelCom1->getVoiceRoomCallsigns();
foreach(CCallsign callsign, callsigns)
{
std::cout << " " << callsign.toStdString() << std::endl;
@@ -200,49 +201,48 @@ void Client::onMicTestFinished()
printLinePrefix();
}
void Client::connectionStatusChanged(BlackCore::IVoice::ComUnit /** comUnit **/,
BlackCore::IVoice::ConnectionStatus /** oldStatus **/,
BlackCore::IVoice::ConnectionStatus newStatus)
void Client::connectionStatusChanged( BlackCore::IVoiceChannel::ConnectionStatus /** oldStatus **/,
BlackCore::IVoiceChannel::ConnectionStatus newStatus)
{
switch (newStatus)
{
case BlackCore::IVoice::Disconnected:
case BlackCore::IVoiceChannel::Disconnected:
std::cout << "CONN_STATUS_DISCONNECTED" << std::endl;
break;
case BlackCore::IVoice::Disconnecting:
case BlackCore::IVoiceChannel::Disconnecting:
std::cout << "CONN_STATUS_DISCONNECTING" << std::endl;
break;
case BlackCore::IVoice::DisconnectedError:
case BlackCore::IVoiceChannel::DisconnectedError:
std::cout << "CONN_STATUS_DISCONNECTED_ERROR" << std::endl;
break;
case BlackCore::IVoice::Connecting:
case BlackCore::IVoiceChannel::Connecting:
std::cout << "CONN_STATUS_CONNECTING" << std::endl;
break;
case BlackCore::IVoice::Connected:
case BlackCore::IVoiceChannel::Connected:
std::cout << "CONN_STATUS_CONNECTED" << std::endl;
break;
case BlackCore::IVoice::ConnectingFailed:
case BlackCore::IVoiceChannel::ConnectingFailed:
std::cout << "CONN_STATUS_CONNECTING_FAILED" << std::endl;
break;
}
printLinePrefix();
}
void Client::audioStartedStream(const BlackCore::IVoice::ComUnit comUnit)
void Client::audioStartedStream()
{
std::cout << "Started stream in room index " << static_cast<qint32>(comUnit) << std::endl;
std::cout << "Started stream in room index " << std::endl;
printLinePrefix();
}
void Client::audioStoppedStream(const BlackCore::IVoice::ComUnit comUnit)
void Client::audioStoppedStream()
{
std::cout << "Stopped stream in room index " << static_cast<qint32>(comUnit) << std::endl;
std::cout << "Stopped stream in room index " << std::endl;
printLinePrefix();
}
void Client::userJoinedRoom(const CCallsign &callsign)
{
std::cout << callsign.toStdString() << " joined the voice room." << std::endl;
std::cout << ": " << callsign.toStdString() << " joined the voice room." << std::endl;
printLinePrefix();
}

View File

@@ -7,8 +7,10 @@
#define SAMPLE_VOICECLIENT
#include "blackcore/voice.h"
#include "blackcore/voice_channel.h"
#include <QObject>
#include <QPointer>
#include <functional>
#include <QMap>
#include <QThread>
@@ -49,11 +51,10 @@ public slots:
void onMicTestFinished();
private slots:
void connectionStatusChanged(BlackCore::IVoice::ComUnit comUnit,
BlackCore::IVoice::ConnectionStatus oldStatus,
BlackCore::IVoice::ConnectionStatus newStatus);
void audioStartedStream(const BlackCore::IVoice::ComUnit comUnit);
void audioStoppedStream(const BlackCore::IVoice::ComUnit comUnit);
void connectionStatusChanged(BlackCore::IVoiceChannel::ConnectionStatus oldStatus,
BlackCore::IVoiceChannel::ConnectionStatus newStatus);
void audioStartedStream();
void audioStoppedStream();
void userJoinedRoom(const BlackMisc::Aviation::CCallsign &callsign);
void userLeftRoom(const BlackMisc::Aviation::CCallsign &callsign);
@@ -61,6 +62,7 @@ private:
QMap<QString, std::function<void(QTextStream &)>> m_commands;
BlackCore::IVoice *m_voice;
QThread m_threadVoice;
QPointer<BlackCore::IVoiceChannel> m_channelCom1;
};

View File

@@ -7,10 +7,10 @@
#include "context_network.h"
#include "context_ownaircraft.h"
#include "context_application.h"
#include "voice_channel.h"
#include "blacksound/soundgenerator.h"
#include "blackmisc/notificationsounds.h"
#include "blackmisc/voiceroomlist.h"
#include <QTimer>
@@ -37,14 +37,21 @@ namespace BlackCore
m_keyboard = BlackInput::IKeyboard::getInstance();
// 3. own aircraft, if possible
if (this->getIContextOwnAircraft()) m_voice->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
//if (this->getIContextOwnAircraft()) m_voice->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
// 4. Signal / slots
connect(this->m_voice, &CVoiceVatlib::micTestFinished, this, &CContextAudio::audioTestCompleted);
connect(this->m_voice, &CVoiceVatlib::squelchTestFinished, this, &CContextAudio::audioTestCompleted);
connect(this->m_voice, &CVoiceVatlib::connectionStatusChanged, this, &CContextAudio::ps_connectionStatusChanged);
//connect(this->m_voice, &CVoiceVatlib::connectionStatusChanged, this, &CContextAudio::ps_connectionStatusChanged);
if (this->getIContextApplication()) this->connect(this->m_voice, &IVoice::statusMessage, this->getIContextApplication(), &IContextApplication::sendStatusMessage);
m_channelCom1 = m_voice->getVoiceChannel(0);
m_channelCom1->setMyAircraftCallsign(getIContextOwnAircraft()->getOwnAircraft().getCallsign());
connect(m_channelCom1.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_com1ConnectionStatusChanged);
m_channelCom2 = m_voice->getVoiceChannel(1);
m_channelCom2->setMyAircraftCallsign(getIContextOwnAircraft()->getOwnAircraft().getCallsign());
connect(m_channelCom2.data(), &IVoiceChannel::connectionStatusChanged, this, &CContextAudio::ps_com2ConnectionStatusChanged);
// 5. load sounds (init), not possible in own thread
QTimer::singleShot(10 * 1000, this, SLOT(ps_initNotificationSounds()));
}
@@ -66,7 +73,7 @@ namespace BlackCore
{
Q_ASSERT(this->m_voice);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
return this->m_voice->getComVoiceRoomsWithAudioStatus();
return getComVoiceRooms();
}
/*
@@ -76,10 +83,8 @@ namespace BlackCore
{
Q_ASSERT(this->m_voice);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, withAudioStatus);
if (withAudioStatus)
return this->m_voice->getComVoiceRoomsWithAudioStatus()[0];
else
return this->m_voice->getComVoiceRooms()[0];
// We always have the audio status due to shared status
return m_channelCom1->getVoiceRoom();
}
/*
@@ -89,10 +94,8 @@ namespace BlackCore
{
Q_ASSERT(this->m_voice);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, withAudioStatus);
if (withAudioStatus)
return this->m_voice->getComVoiceRoomsWithAudioStatus()[1];
else
return this->m_voice->getComVoiceRooms()[1];
// We always have the audio status due to shared status
return m_channelCom2->getVoiceRoom();
}
/*
@@ -102,7 +105,10 @@ namespace BlackCore
{
Q_ASSERT(this->m_voice);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
return this->m_voice->getComVoiceRooms();
CVoiceRoomList voiceRoomList;
voiceRoomList.push_back(m_channelCom1->getVoiceRoom());
voiceRoomList.push_back(m_channelCom2->getVoiceRoom());
return voiceRoomList;
}
/*
@@ -112,7 +118,8 @@ namespace BlackCore
{
Q_ASSERT(this->m_voice);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
this->m_voice->leaveAllVoiceRooms();
m_channelCom1->leaveVoiceRoom();
m_channelCom2->leaveVoiceRoom();
}
/*
@@ -167,12 +174,12 @@ namespace BlackCore
// volumes
qint32 vol1 = com1.getVolumeOutput();
qint32 vol2 = com2.getVolumeOutput();
this->m_voice->setRoomOutputVolume(IVoice::COM1, vol1);
this->m_voice->setRoomOutputVolume(IVoice::COM2, vol2);
m_channelCom1->setRoomOutputVolume(vol1);
m_channelCom2->setRoomOutputVolume(vol2);
// enable / disable in the same step
this->m_voice->switchAudioOutput(IVoice::COM1, com1.isEnabled());
this->m_voice->switchAudioOutput(IVoice::COM2, com2.isEnabled());
m_channelCom1->switchAudioOutput(com1.isEnabled());
m_channelCom2->switchAudioOutput(com2.isEnabled());
}
/*
@@ -182,7 +189,7 @@ namespace BlackCore
{
Q_ASSERT(this->m_voice);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
return this->m_voice->isMuted();
return m_channelCom1->isMuted() && m_channelCom2->isMuted();
}
/*
@@ -194,7 +201,7 @@ namespace BlackCore
Q_ASSERT(newRooms.size() == 2);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, newRooms.toQString());
CVoiceRoomList currentRooms = this->m_voice->getComVoiceRooms();
CVoiceRoomList currentRooms = getComVoiceRooms();
CVoiceRoom currentRoom1 = currentRooms[0];
CVoiceRoom currentRoom2 = currentRooms[1];
CVoiceRoom newRoom1 = newRooms[0];
@@ -205,14 +212,20 @@ namespace BlackCore
// changed rooms? But only compare on "URL", not status as connected etc.
if (currentRoom1.getVoiceRoomUrl() != newRoom1.getVoiceRoomUrl())
{
this->m_voice->leaveVoiceRoom(IVoice::COM1);
if (newRoom1.isValid()) this->m_voice->joinVoiceRoom(IVoice::COM1, newRoom1);
m_channelCom1->leaveVoiceRoom();
if (newRoom1.isValid())
{
m_channelCom1->joinVoiceRoom(newRoom1);
}
changed = true;
}
if (currentRoom2.getVoiceRoomUrl() != newRoom2.getVoiceRoomUrl())
{
this->m_voice->leaveVoiceRoom(IVoice::COM2);
if (newRoom2.isValid()) this->m_voice->joinVoiceRoom(IVoice::COM2, newRoom2);
m_channelCom2->leaveVoiceRoom();
if (newRoom2.isValid())
{
m_channelCom2->joinVoiceRoom(newRoom2);
}
changed = true;
}
@@ -228,8 +241,7 @@ namespace BlackCore
{
Q_ASSERT(this->m_voice);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
CCallsignList callsigns = this->m_voice->getVoiceRoomCallsigns(IVoice::COM1);
return callsigns;
return m_channelCom1->getVoiceRoomCallsigns();
}
/*
@@ -239,8 +251,7 @@ namespace BlackCore
{
Q_ASSERT(this->m_voice);
if (this->getRuntime()->isSlotLogForAudioEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO);
CCallsignList callsigns = this->m_voice->getVoiceRoomCallsigns(IVoice::COM2);
return callsigns;
return m_channelCom2->getVoiceRoomCallsigns();
}
/*
@@ -360,7 +371,11 @@ namespace BlackCore
*/
void CContextAudio::ps_settingsChanged(uint typeValue)
{
if (this->getIContextOwnAircraft()) m_voice->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
if (this->getIContextOwnAircraft())
{
m_channelCom1->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
m_channelCom2->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
}
if (!this->getIContextSettings()) return;
IContextSettings::SettingsType type = static_cast<IContextSettings::SettingsType>(typeValue);
if (type == IContextSettings::SettingsHotKeys)
@@ -376,32 +391,70 @@ namespace BlackCore
/*
* Connection status changed
*/
void CContextAudio::ps_connectionStatusChanged(IVoice::ComUnit comUnit, IVoice::ConnectionStatus oldStatus, IVoice::ConnectionStatus newStatus)
void CContextAudio::ps_com1ConnectionStatusChanged(IVoiceChannel::ConnectionStatus oldStatus, IVoiceChannel::ConnectionStatus newStatus)
{
Q_UNUSED(comUnit);
Q_UNUSED(oldStatus);
switch (newStatus)
{
case IVoice::Connected:
emit this->changedVoiceRooms(this->m_voice->getComVoiceRooms(), true);
case IVoiceChannel::Connected:
emit this->changedVoiceRooms(getComVoiceRooms(), true);
break;
case IVoice::Disconnecting:
case IVoiceChannel::Disconnecting:
break;
case IVoice::Connecting:
case IVoiceChannel::Connecting:
break;
case IVoice::ConnectingFailed:
case IVoice::DisconnectedError:
case IVoiceChannel::ConnectingFailed:
case IVoiceChannel::DisconnectedError:
{
const QString e = QString("Voice room %1 error").arg(comUnit);
const QString e = QString("Voice room COM1 error");
qWarning(e.toUtf8().constData());
// no break here!
}
case IVoice::Disconnected:
case IVoiceChannel::Disconnected:
// good chance to update aircraft
if (this->getIContextOwnAircraft()) m_voice->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
emit this->changedVoiceRooms(this->m_voice->getComVoiceRooms(), false);
if (this->getIContextOwnAircraft())
{
m_channelCom1->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
m_channelCom2->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
}
emit this->changedVoiceRooms(getComVoiceRooms(), false);
break;
default:
break;
}
}
void CContextAudio::ps_com2ConnectionStatusChanged(IVoiceChannel::ConnectionStatus oldStatus, IVoiceChannel::ConnectionStatus newStatus)
{
Q_UNUSED(oldStatus);
switch (newStatus)
{
case IVoiceChannel::Connected:
emit this->changedVoiceRooms(getComVoiceRooms(), true);
break;
case IVoiceChannel::Disconnecting:
break;
case IVoiceChannel::Connecting:
break;
case IVoiceChannel::ConnectingFailed:
case IVoiceChannel::DisconnectedError:
{
const QString e = QString("Voice room COM2 error");
qWarning(e.toUtf8().constData());
// no break here!
}
case IVoiceChannel::Disconnected:
// good chance to update aircraft
if (this->getIContextOwnAircraft())
{
m_channelCom1->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
m_channelCom2->setMyAircraftCallsign(this->getIContextOwnAircraft()->getOwnAircraft().getCallsign());
}
emit this->changedVoiceRooms(getComVoiceRooms(), false);
break;
default:
break;

View File

@@ -11,13 +11,18 @@
#include "context_runtime.h"
#include "dbus_server.h"
#include "voice_vatlib.h"
#include "voice_channel.h"
#include "blackinput/keyboard.h"
#include "blackmisc/voiceroomlist.h"
#include <QThread>
#include <QQueue>
#include <QPointer>
namespace BlackCore
{
class IVoiceChannel;
//! Audio context implementation
class CContextAudio : public IContextAudio
{
@@ -117,7 +122,11 @@ namespace BlackCore
//! \copydoc IVoice::connectionStatusChanged
//! \sa IContextAudio::changedVoiceRooms
void ps_connectionStatusChanged(IVoice::ComUnit comUnit, IVoice::ConnectionStatus oldStatus, IVoice::ConnectionStatus newStatus);
void ps_com1ConnectionStatusChanged(IVoiceChannel::ConnectionStatus oldStatus, IVoiceChannel::ConnectionStatus newStatus);
//! \copydoc IVoice::connectionStatusChanged
//! \sa IContextAudio::changedVoiceRooms
void ps_com2ConnectionStatusChanged(IVoiceChannel::ConnectionStatus oldStatus, IVoiceChannel::ConnectionStatus newStatus);
//! Init notification sounds
void ps_initNotificationSounds();
@@ -130,6 +139,8 @@ namespace BlackCore
BlackInput::IKeyboard *m_keyboard;
BlackInput::IKeyboard::RegistrationHandle m_handlePtt;
QThread m_threadVoice;
QPointer<IVoiceChannel> m_channelCom1;
QPointer<IVoiceChannel> m_channelCom2;
};
}