From 811998b8df6058f2f698fedbf99519c2cbc956ce Mon Sep 17 00:00:00 2001 From: sudden6 Date: Sat, 30 Jun 2018 13:09:29 +0200 Subject: [PATCH] refactor(toxcall): move alSource into ToxFriendCall --- src/core/toxcall.cpp | 38 ++++++++++++++++++++++++++++---------- src/core/toxcall.h | 13 +++++++------ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/core/toxcall.cpp b/src/core/toxcall.cpp index be4131024..8d35ccf3d 100644 --- a/src/core/toxcall.cpp +++ b/src/core/toxcall.cpp @@ -34,7 +34,6 @@ ToxCall::ToxCall(uint32_t CallId, bool VideoEnabled, CoreAV& av) { Audio& audio = Audio::getInstance(); audio.subscribeInput(); - audio.subscribeOutput(alSource); audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable, [&av, CallId](const int16_t* pcm, size_t samples, uint8_t chans, @@ -73,7 +72,6 @@ ToxCall::ToxCall(ToxCall&& other) noexcept : active{other.active}, audioInConn{other.audioInConn}, muteMic{other.muteMic}, muteVol{other.muteVol}, - alSource{other.alSource}, videoSource{other.videoSource}, videoInConn{other.videoInConn}, videoEnabled{other.videoEnabled}, @@ -82,7 +80,6 @@ ToxCall::ToxCall(ToxCall&& other) noexcept : active{other.active}, Audio& audio = Audio::getInstance(); audio.subscribeInput(); other.audioInConn = QMetaObject::Connection(); - other.alSource = 0; other.videoInConn = QMetaObject::Connection(); other.videoEnabled = false; // we don't need to subscribe video because other won't unsubscribe other.videoSource = nullptr; @@ -95,7 +92,6 @@ ToxCall::~ToxCall() QObject::disconnect(audioInConn); audio.unsubscribeInput(); - audio.unsubscribeOutput(alSource); if (videoEnabled) { QObject::disconnect(videoInConn); CameraSource::getInstance().unsubscribe(); @@ -117,9 +113,6 @@ ToxCall& ToxCall::operator=(ToxCall&& other) noexcept muteMic = other.muteMic; muteVol = other.muteVol; - alSource = other.alSource; - other.alSource = 0; - Audio::getInstance().subscribeInput(); videoInConn = other.videoInConn; @@ -190,12 +183,12 @@ CoreVideoSource* ToxCall::getVideoSource() const return videoSource; } -quint32 ToxCall::getAlSource() const +quint32 ToxFriendCall::getAlSource() const { return alSource; } -void ToxCall::setAlSource(const quint32& value) +void ToxFriendCall::setAlSource(const quint32& value) { alSource = value; } @@ -203,6 +196,30 @@ void ToxCall::setAlSource(const quint32& value) ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av) : ToxCall(FriendNum, VideoEnabled, av) { + Audio& audio = Audio::getInstance(); + audio.subscribeOutput(alSource); +} + +ToxFriendCall::ToxFriendCall(ToxFriendCall &&other) noexcept + : ToxCall(std::move(other)) + , alSource{other.alSource} +{ + other.alSource = 0; +} + +ToxFriendCall& ToxFriendCall::operator=(ToxFriendCall &&other) noexcept +{ + ToxCall::operator=(std::move(other)); + alSource = other.alSource; + other.alSource = 0; + + return *this; +} + +ToxFriendCall::~ToxFriendCall() +{ + auto& audio = Audio::getInstance(); + audio.unsubscribeOutput(alSource); } void ToxFriendCall::startTimeout(uint32_t callId) @@ -243,7 +260,8 @@ ToxGroupCall::ToxGroupCall(int GroupNum, CoreAV& av) { } -ToxGroupCall::ToxGroupCall(ToxGroupCall&& other) noexcept : ToxCall(std::move(other)), peers{other.peers} +ToxGroupCall::ToxGroupCall(ToxGroupCall&& other) noexcept + : ToxCall(std::move(other)), peers{other.peers} { // all peers were moved, this ensures audio output is unsubscribed only once other.peers.clear(); diff --git a/src/core/toxcall.h b/src/core/toxcall.h index d4b60462c..de8a5b939 100644 --- a/src/core/toxcall.h +++ b/src/core/toxcall.h @@ -45,9 +45,6 @@ public: CoreVideoSource* getVideoSource() const; - quint32 getAlSource() const; - void setAlSource(const quint32& value); - protected: bool active{false}; CoreAV* av{nullptr}; @@ -55,7 +52,6 @@ protected: QMetaObject::Connection audioInConn; bool muteMic{false}; bool muteVol{false}; - quint32 alSource{0}; // video CoreVideoSource* videoSource{nullptr}; QMetaObject::Connection videoInConn; @@ -68,8 +64,9 @@ class ToxFriendCall : public ToxCall public: ToxFriendCall() = delete; ToxFriendCall(uint32_t friendId, bool VideoEnabled, CoreAV& av); - ToxFriendCall(ToxFriendCall&& other) noexcept = default; - ToxFriendCall& operator=(ToxFriendCall&& other) noexcept = default; + ToxFriendCall(ToxFriendCall&& other) noexcept; + ToxFriendCall& operator=(ToxFriendCall&& other) noexcept; + ~ToxFriendCall(); void startTimeout(uint32_t callId); void stopTimeout(); @@ -77,12 +74,16 @@ public: TOXAV_FRIEND_CALL_STATE getState() const; void setState(const TOXAV_FRIEND_CALL_STATE& value); + quint32 getAlSource() const; + void setAlSource(const quint32& value); + protected: std::unique_ptr timeoutTimer; private: TOXAV_FRIEND_CALL_STATE state{TOXAV_FRIEND_CALL_STATE_NONE}; static constexpr int CALL_TIMEOUT = 45000; + quint32 alSource{0}; }; class ToxGroupCall : public ToxCall