refs #320 Prepare Voice to new vatlib API

This commit is contained in:
Roland Winklmeier
2014-12-25 20:43:56 +01:00
parent 111c539e89
commit 13a05f729e
4 changed files with 45 additions and 25 deletions

View File

@@ -16,7 +16,7 @@
#include "context_settings.h"
#include "context_runtime.h"
#include "dbus_server.h"
#include "voice_vatlib.h"
#include "voice.h"
#include "voice_channel.h"
#include "input_manager.h"
#include "blackinput/keyboard.h"
@@ -163,8 +163,7 @@ namespace BlackCore
//! Connection in transition
bool inTransitionState() const;
// TODO: see #339, MS' comment on deletion in another thread
QScopedPointer<CVoiceVatlib> m_voice; //!< underlying voice lib
std::unique_ptr<CVoiceVatlib> m_voice; //!< underlying voice lib
CInputManager *m_inputManager = nullptr;
CInputManager::RegistrationHandle m_handlePtt;

View File

@@ -13,35 +13,20 @@
#include "../blackmisc/audiodeviceinfolist.h"
#include "../blackmisc/statusmessage.h"
#include <vatlib/vatlib.h>
#include <QObject>
#include <QSet>
#include <QStringList>
#include <QMetaType>
#include <memory>
namespace BlackCore
{
class IVoiceChannel;
/*!
* Interface to a connection to a ATC voice server for use in flight simulation.
*
* \warning If an INetwork signal is connected to a slot, and that slot emits a signal
* which is connected to an INetwork slot, then at least one of those connections
* must be a Qt::QueuedConnection.
* Reason: IVoiceClient implementations are not re-entrant.
*/
//! Interface to a connection to a ATC voice server for use in flight simulation.
class IVoice : public QObject
{
/* TODOS:
* - Find a replacement for comUnit. Maybe map it to the ComUnit in the aircraft as a class
* - Settings: Settings classes to store hardware settings (squelch, background noise, hardware device)
*/
Q_OBJECT
protected:
public:
/*!
* \brief Default constructor with parent
@@ -49,7 +34,6 @@ namespace BlackCore
*/
IVoice(QObject *parent = nullptr);
public:
//! Virtual destructor.
virtual ~IVoice() {}

View File

@@ -8,7 +8,7 @@
#include "blackmisc/logmessage.h"
#include <QDebug>
#include <QTimer>
#include <memory>
#include <mutex>
using namespace BlackMisc;
@@ -21,10 +21,17 @@ namespace BlackCore
* Constructor
*/
CVoiceVatlib::CVoiceVatlib(QObject *parent) :
IVoice(parent)
IVoice(parent),
m_audioService(Vat_CreateAudioService()),
m_udpPort(Vat_CreateUDPAudioPort(m_audioService.data(), 3782))
{
Vat_SetVoiceErrorHandler(CVoiceVatlib::voiceErrorHandler);
this->m_currentInputDevice = this->defaultAudioInputDevice();
this->m_currentOutputDevice = this->defaultAudioOutputDevice();
// do processing
this->startTimer(10);
}
/*
@@ -125,6 +132,8 @@ namespace BlackCore
*/
void CVoiceVatlib::timerEvent(QTimerEvent *)
{
Q_ASSERT_X(m_audioService, "CVoiceVatlib", "VatAudioService invalid!");
Vat_ExecuteTasks(m_audioService.data());
}
/*
@@ -154,4 +163,9 @@ namespace BlackCore
(*iterator)->updateRoomStatus(roomStatus);
}
void CVoiceVatlib::voiceErrorHandler(const char *message)
{
CLogMessage(static_cast<CVoiceVatlib*>(nullptr)).error(message);
}
} // namespace

View File

@@ -7,8 +7,10 @@
#define BLACKCORE_VOICE_VATLIB_H
#include "voice.h"
#include <vatlib/vatlib2.h>
#include <QString>
#include <QScopedPointer>
#ifdef Q_OS_WIN
#ifndef NOMINMAX
@@ -86,11 +88,32 @@ namespace BlackCore
private:
// this struct calls "myCustomDeallocator" to delete the pointer
struct VatAudioServiceDeleter
{
static inline void cleanup(VatAudioService_tag *obj)
{
Vat_DestroyAudioService(obj);
}
};
struct VatUDPAudioPortDeleter
{
static inline void cleanup(VatUDPAudioPort_tag *obj)
{
Vat_DestroyUDPAudioPort(obj);
}
};
static void voiceErrorHandler(const char *message);
// shimlib callbacks
static void onRoomStatusUpdate(Cvatlib_Voice_Simple *obj, Cvatlib_Voice_Simple::roomStatusUpdate upd, qint32 roomIndex, void *cbVar);
void onRoomStatusUpdate(qint32 roomIndex, Cvatlib_Voice_Simple::roomStatusUpdate roomStatus);
QScopedPointer<VatAudioService_tag, VatAudioServiceDeleter> m_audioService;
QScopedPointer<VatUDPAudioPort_tag, VatUDPAudioPortDeleter> m_udpPort;
BlackMisc::Audio::CAudioDeviceInfoList m_devices; /*!< in and output devices */
BlackMisc::Audio::CAudioDeviceInfo m_currentOutputDevice;
BlackMisc::Audio::CAudioDeviceInfo m_currentInputDevice;