From a00af087778c6315ef55ed77c4209cbb63a6323d Mon Sep 17 00:00:00 2001 From: sudden6 Date: Sun, 1 Jul 2018 10:39:33 +0200 Subject: [PATCH] fix(audio): connect the correct audio callbacks --- src/core/toxcall.cpp | 77 ++++++++++++++++++++++--------------- src/core/toxcall.h | 2 +- src/video/corevideosource.h | 2 +- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/core/toxcall.cpp b/src/core/toxcall.cpp index 3daaaeff9..74e43cfd0 100644 --- a/src/core/toxcall.cpp +++ b/src/core/toxcall.cpp @@ -28,39 +28,10 @@ * @brief Keeps sources for users in group calls. */ -ToxCall::ToxCall(uint32_t CallId, bool VideoEnabled, CoreAV& av) +ToxCall::ToxCall(bool VideoEnabled, CoreAV& av) : av{&av} , videoEnabled{VideoEnabled} { - Audio& audio = Audio::getInstance(); - audio.subscribeInput(); - - audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable, - [&av, CallId](const int16_t* pcm, size_t samples, uint8_t chans, - uint32_t rate) { - av.sendCallAudio(CallId, pcm, samples, chans, rate); - }); - - if (!audioInConn) { - qDebug() << "Audio connection not working"; - } - - if (videoEnabled) { - videoSource = new CoreVideoSource(); - CameraSource& source = CameraSource::getInstance(); - - if (source.isNone()) { - source.setupDefault(); - } - source.subscribe(); - videoInConn = QObject::connect(&source, &VideoSource::frameAvailable, - [&av, CallId](std::shared_ptr frame) { - av.sendCallVideo(CallId, frame); - }); - if (!videoInConn) { - qDebug() << "Video connection not working"; - } - } } /** @@ -194,10 +165,40 @@ void ToxFriendCall::setAlSource(const quint32& value) } ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av) - : ToxCall(FriendNum, VideoEnabled, av) + : ToxCall(VideoEnabled, av) { + // register audio Audio& audio = Audio::getInstance(); + audio.subscribeInput(); + audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable, + [&av, FriendNum](const int16_t* pcm, size_t samples, uint8_t chans, + uint32_t rate) { + av.sendCallAudio(FriendNum, pcm, samples, chans, rate); + }); + + if (!audioInConn) { + qDebug() << "Audio input connection not working"; + } + audio.subscribeOutput(alSource); + + // register video + if (videoEnabled) { + videoSource = new CoreVideoSource(); + CameraSource& source = CameraSource::getInstance(); + + if (source.isNone()) { + source.setupDefault(); + } + source.subscribe(); + videoInConn = QObject::connect(&source, &VideoSource::frameAvailable, + [&av, FriendNum](std::shared_ptr frame) { + av.sendCallVideo(FriendNum, frame); + }); + if (!videoInConn) { + qDebug() << "Video connection not working"; + } + } } ToxFriendCall::ToxFriendCall(ToxFriendCall &&other) noexcept @@ -256,8 +257,20 @@ void ToxFriendCall::setState(const TOXAV_FRIEND_CALL_STATE& value) } ToxGroupCall::ToxGroupCall(int GroupNum, CoreAV& av) - : ToxCall(static_cast(GroupNum), false, av) + : ToxCall(false, av) { + // register audio + Audio& audio = Audio::getInstance(); + audio.subscribeInput(); + audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable, + [&av, GroupNum](const int16_t* pcm, size_t samples, uint8_t chans, + uint32_t rate) { + av.sendGroupCallAudio(GroupNum, pcm, samples, chans, rate); + }); + + if (!audioInConn) { + qDebug() << "Audio input connection not working"; + } } ToxGroupCall::ToxGroupCall(ToxGroupCall&& other) noexcept diff --git a/src/core/toxcall.h b/src/core/toxcall.h index 6cb740ffe..2524e4e93 100644 --- a/src/core/toxcall.h +++ b/src/core/toxcall.h @@ -18,7 +18,7 @@ class ToxCall { protected: ToxCall() = delete; - ToxCall(uint32_t CallId, bool VideoEnabled, CoreAV& av); + ToxCall(bool VideoEnabled, CoreAV& av); ~ToxCall(); public: diff --git a/src/video/corevideosource.h b/src/video/corevideosource.h index eb98686ad..d5f2af965 100644 --- a/src/video/corevideosource.h +++ b/src/video/corevideosource.h @@ -50,7 +50,7 @@ private: std::atomic_bool stopped; friend class CoreAV; - friend class ToxCall; + friend class ToxFriendCall; }; #endif // COREVIDEOSOURCE_H