From 13a05f729e5373f424c0ac9b83ee5a9d3125f565 Mon Sep 17 00:00:00 2001 From: Roland Winklmeier Date: Thu, 25 Dec 2014 20:43:56 +0100 Subject: [PATCH] refs #320 Prepare Voice to new vatlib API --- src/blackcore/context_audio_impl.h | 5 ++--- src/blackcore/voice.h | 24 ++++-------------------- src/blackcore/voice_vatlib.cpp | 18 ++++++++++++++++-- src/blackcore/voice_vatlib.h | 23 +++++++++++++++++++++++ 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/blackcore/context_audio_impl.h b/src/blackcore/context_audio_impl.h index ff77256ea..d69146caf 100644 --- a/src/blackcore/context_audio_impl.h +++ b/src/blackcore/context_audio_impl.h @@ -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 m_voice; //!< underlying voice lib + std::unique_ptr m_voice; //!< underlying voice lib CInputManager *m_inputManager = nullptr; CInputManager::RegistrationHandle m_handlePtt; diff --git a/src/blackcore/voice.h b/src/blackcore/voice.h index ec3254f41..25a55231d 100644 --- a/src/blackcore/voice.h +++ b/src/blackcore/voice.h @@ -13,35 +13,20 @@ #include "../blackmisc/audiodeviceinfolist.h" #include "../blackmisc/statusmessage.h" -#include #include -#include -#include -#include + +#include 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() {} diff --git a/src/blackcore/voice_vatlib.cpp b/src/blackcore/voice_vatlib.cpp index 303dfbe74..9bec3d5f3 100644 --- a/src/blackcore/voice_vatlib.cpp +++ b/src/blackcore/voice_vatlib.cpp @@ -8,7 +8,7 @@ #include "blackmisc/logmessage.h" #include #include - +#include #include 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(nullptr)).error(message); + } + } // namespace diff --git a/src/blackcore/voice_vatlib.h b/src/blackcore/voice_vatlib.h index cbc214e0b..4cb89d695 100644 --- a/src/blackcore/voice_vatlib.h +++ b/src/blackcore/voice_vatlib.h @@ -7,8 +7,10 @@ #define BLACKCORE_VOICE_VATLIB_H #include "voice.h" +#include #include +#include #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 m_audioService; + QScopedPointer m_udpPort; BlackMisc::Audio::CAudioDeviceInfoList m_devices; /*!< in and output devices */ BlackMisc::Audio::CAudioDeviceInfo m_currentOutputDevice; BlackMisc::Audio::CAudioDeviceInfo m_currentInputDevice;