mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(toxcall): remove callId from ToxCall members
This commit is contained in:
parent
4149b5b252
commit
b07ea763cd
@ -79,7 +79,7 @@ std::map<uint32_t, ToxFriendCall> CoreAV::calls;
|
||||
* @brief Maps group IDs to ToxGroupCalls.
|
||||
* @note Need to use STL container here, because Qt containers need a copy constructor.
|
||||
*/
|
||||
std::map<uint32_t, ToxGroupCall> CoreAV::groupCalls;
|
||||
std::map<int, ToxGroupCall> CoreAV::groupCalls;
|
||||
|
||||
CoreAV::CoreAV(Tox* tox)
|
||||
: coreavThread{new QThread}
|
||||
@ -275,8 +275,8 @@ bool CoreAV::startCall(uint32_t friendNum, bool video)
|
||||
if (!toxav_call(toxav, friendNum, Settings::getInstance().getAudioBitrate(), videoBitrate, nullptr))
|
||||
return false;
|
||||
|
||||
calls[friendNum]= ToxFriendCall{friendNum, video, *this};
|
||||
calls[friendNum].startTimeout();
|
||||
calls[friendNum] = ToxFriendCall{friendNum, video, *this};
|
||||
calls[friendNum].startTimeout(friendNum);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -378,7 +378,7 @@ void CoreAV::sendCallVideo(uint32_t callId, std::shared_ptr<VideoFrame> vframe)
|
||||
|
||||
if (call.nullVideoBitrate) {
|
||||
qDebug() << "Restarting video stream to friend" << callId;
|
||||
toxav_bit_rate_set(toxav, call.callId, -1, VIDEO_DEFAULT_BITRATE, nullptr);
|
||||
toxav_bit_rate_set(toxav, callId, -1, VIDEO_DEFAULT_BITRATE, nullptr);
|
||||
call.nullVideoBitrate = false;
|
||||
}
|
||||
|
||||
@ -649,7 +649,7 @@ void CoreAV::sendNoVideo()
|
||||
qDebug() << "CoreAV: Signaling end of video sending";
|
||||
for (auto& kv : calls) {
|
||||
ToxFriendCall& call = kv.second;
|
||||
toxav_bit_rate_set(toxav, call.callId, -1, 0, nullptr);
|
||||
toxav_bit_rate_set(toxav, kv.first, -1, 0, nullptr);
|
||||
call.nullVideoBitrate = true;
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ private:
|
||||
std::unique_ptr<QThread> coreavThread;
|
||||
std::unique_ptr<QTimer> iterateTimer;
|
||||
static std::map<uint32_t, ToxFriendCall> calls;
|
||||
static std::map<uint32_t, ToxGroupCall> groupCalls;
|
||||
static std::map<int, ToxGroupCall> groupCalls;
|
||||
std::atomic_flag threadSwitchLock;
|
||||
|
||||
friend class Audio;
|
||||
|
@ -31,8 +31,7 @@
|
||||
using namespace std;
|
||||
|
||||
ToxCall::ToxCall(uint32_t CallId)
|
||||
: callId{CallId}
|
||||
, alSource{0}
|
||||
: alSource{0}
|
||||
, inactive{true}
|
||||
, muteMic{false}
|
||||
, muteVol{false}
|
||||
@ -43,14 +42,12 @@ ToxCall::ToxCall(uint32_t CallId)
|
||||
}
|
||||
|
||||
ToxCall::ToxCall(ToxCall&& other) noexcept : audioInConn{other.audioInConn},
|
||||
callId{other.callId},
|
||||
alSource{other.alSource},
|
||||
inactive{other.inactive},
|
||||
muteMic{other.muteMic},
|
||||
muteVol{other.muteVol}
|
||||
{
|
||||
other.audioInConn = QMetaObject::Connection();
|
||||
other.callId = numeric_limits<decltype(callId)>::max();
|
||||
other.alSource = 0;
|
||||
|
||||
// required -> ownership of audio input is moved to new instance
|
||||
@ -71,8 +68,6 @@ ToxCall& ToxCall::operator=(ToxCall&& other) noexcept
|
||||
{
|
||||
audioInConn = other.audioInConn;
|
||||
other.audioInConn = QMetaObject::Connection();
|
||||
callId = other.callId;
|
||||
other.callId = numeric_limits<decltype(callId)>::max();
|
||||
inactive = other.inactive;
|
||||
muteMic = other.muteMic;
|
||||
muteVol = other.muteVol;
|
||||
@ -86,15 +81,14 @@ ToxCall& ToxCall::operator=(ToxCall&& other) noexcept
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ToxFriendCall::startTimeout()
|
||||
void ToxFriendCall::startTimeout(uint32_t callId)
|
||||
{
|
||||
if (!timeoutTimer) {
|
||||
timeoutTimer = new QTimer();
|
||||
// We might move, so we need copies of members. CoreAV won't move while we're alive
|
||||
CoreAV* avCopy = av;
|
||||
auto callIdCopy = callId;
|
||||
QObject::connect(timeoutTimer, &QTimer::timeout,
|
||||
[avCopy, callIdCopy]() { avCopy->timeoutCall(callIdCopy); });
|
||||
[avCopy, callId]() { avCopy->timeoutCall(callId); });
|
||||
}
|
||||
|
||||
if (!timeoutTimer->isActive())
|
||||
@ -193,10 +187,10 @@ ToxFriendCall& ToxFriendCall::operator=(ToxFriendCall&& other) noexcept
|
||||
}
|
||||
|
||||
ToxGroupCall::ToxGroupCall(int GroupNum, CoreAV& av)
|
||||
: ToxCall(static_cast<decltype(callId)>(GroupNum))
|
||||
: ToxCall(static_cast<uint32_t>(GroupNum))
|
||||
{
|
||||
static_assert(
|
||||
numeric_limits<decltype(callId)>::max() >= numeric_limits<decltype(GroupNum)>::max(),
|
||||
numeric_limits<uint32_t>::max() >= numeric_limits<decltype(GroupNum)>::max(),
|
||||
"The callId must be able to represent any group number, change its type if needed");
|
||||
|
||||
audioInConn = QObject::connect(&Audio::getInstance(), &Audio::frameAvailable,
|
||||
|
@ -31,7 +31,6 @@ protected:
|
||||
QMetaObject::Connection audioInConn;
|
||||
|
||||
public:
|
||||
uint32_t callId;
|
||||
quint32 alSource;
|
||||
bool inactive;
|
||||
bool muteMic;
|
||||
@ -52,7 +51,7 @@ struct ToxFriendCall : public ToxCall
|
||||
CoreVideoSource* videoSource;
|
||||
TOXAV_FRIEND_CALL_STATE state;
|
||||
|
||||
void startTimeout();
|
||||
void startTimeout(uint32_t callId);
|
||||
void stopTimeout();
|
||||
|
||||
protected:
|
||||
|
Loading…
x
Reference in New Issue
Block a user