mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Fix call start/call invite race condition
Would result in an assert failure
This commit is contained in:
parent
1db17ae1ec
commit
73a4f40744
|
@ -90,7 +90,14 @@ void CoreAV::answerCall(uint32_t friendNum)
|
||||||
|
|
||||||
void CoreAV::startCall(uint32_t friendId, bool video)
|
void CoreAV::startCall(uint32_t friendId, bool video)
|
||||||
{
|
{
|
||||||
assert(!calls.contains(friendId));
|
if(calls.contains(friendId))
|
||||||
|
{
|
||||||
|
qWarning() << QString("Can't start call with %1, we're already in this call!").arg(friendId);
|
||||||
|
emit avCallFailed(friendId);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug() << QString("Starting call with %1").arg(friendId);
|
||||||
uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0;
|
uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0;
|
||||||
if (!toxav_call(toxav, friendId, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr))
|
if (!toxav_call(toxav, friendId, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr))
|
||||||
{
|
{
|
||||||
|
@ -311,10 +318,16 @@ void CoreAV::resetCallSources()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CoreAV::callCallback(ToxAV*, uint32_t friendNum, bool audio, bool video, void *_self)
|
void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool video, void *_self)
|
||||||
{
|
{
|
||||||
CoreAV* self = static_cast<CoreAV*>(_self);
|
CoreAV* self = static_cast<CoreAV*>(_self);
|
||||||
const auto& callIt = calls.insert({friendNum, video, *self});
|
if (self->calls.contains(friendNum))
|
||||||
|
{
|
||||||
|
qWarning() << QString("Rejecting call invite from %1, we're already in that call!").arg(friendNum);
|
||||||
|
toxav_call_control(toxav, friendNum, TOXAV_CALL_CONTROL_CANCEL, nullptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const auto& callIt = self->calls.insert({friendNum, video, *self});
|
||||||
|
|
||||||
// We don't get a state callback when answering, so fill the state ourselves in advance
|
// We don't get a state callback when answering, so fill the state ourselves in advance
|
||||||
int state = 0;
|
int state = 0;
|
||||||
|
|
|
@ -258,8 +258,7 @@ void ChatForm::onAvInvite(uint32_t FriendId, bool video)
|
||||||
|
|
||||||
qDebug() << "onAvInvite";
|
qDebug() << "onAvInvite";
|
||||||
|
|
||||||
callButton->disconnect();
|
disableCallButtons();
|
||||||
videoButton->disconnect();
|
|
||||||
if (video)
|
if (video)
|
||||||
{
|
{
|
||||||
callConfirm = new CallConfirmWidget(videoButton, *f);
|
callConfirm = new CallConfirmWidget(videoButton, *f);
|
||||||
|
@ -310,8 +309,7 @@ void ChatForm::onAvStart(uint32_t FriendId, bool video)
|
||||||
|
|
||||||
audioInputFlag = true;
|
audioInputFlag = true;
|
||||||
audioOutputFlag = true;
|
audioOutputFlag = true;
|
||||||
callButton->disconnect();
|
disableCallButtons();
|
||||||
videoButton->disconnect();
|
|
||||||
|
|
||||||
if (video)
|
if (video)
|
||||||
{
|
{
|
||||||
|
@ -418,8 +416,7 @@ void ChatForm::onAvStarting(uint32_t FriendId, bool video)
|
||||||
|
|
||||||
qDebug() << "onAvStarting";
|
qDebug() << "onAvStarting";
|
||||||
|
|
||||||
callButton->disconnect();
|
disableCallButtons();
|
||||||
videoButton->disconnect();
|
|
||||||
if (video)
|
if (video)
|
||||||
{
|
{
|
||||||
callButton->setObjectName("grey");
|
callButton->setObjectName("grey");
|
||||||
|
@ -489,7 +486,6 @@ void ChatForm::onAvRequestTimeout(uint32_t FriendId)
|
||||||
|
|
||||||
enableCallButtons();
|
enableCallButtons();
|
||||||
stopCounter();
|
stopCounter();
|
||||||
|
|
||||||
hideNetcam();
|
hideNetcam();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,6 +516,7 @@ void ChatForm::onAvRejected(uint32_t FriendId)
|
||||||
callConfirm = nullptr;
|
callConfirm = nullptr;
|
||||||
|
|
||||||
enableCallButtons();
|
enableCallButtons();
|
||||||
|
stopCounter();
|
||||||
|
|
||||||
insertChatMessage(ChatMessage::createChatInfoMessage(tr("Call rejected"),
|
insertChatMessage(ChatMessage::createChatInfoMessage(tr("Call rejected"),
|
||||||
ChatMessage::INFO,
|
ChatMessage::INFO,
|
||||||
|
@ -587,6 +584,7 @@ void ChatForm::onRejectCallTriggered()
|
||||||
emit rejectCall(f->getFriendID());
|
emit rejectCall(f->getFriendID());
|
||||||
|
|
||||||
enableCallButtons();
|
enableCallButtons();
|
||||||
|
stopCounter();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onCallTriggered()
|
void ChatForm::onCallTriggered()
|
||||||
|
@ -643,6 +641,31 @@ void ChatForm::enableCallButtons()
|
||||||
audioInputFlag = false;
|
audioInputFlag = false;
|
||||||
audioOutputFlag = false;
|
audioOutputFlag = false;
|
||||||
|
|
||||||
|
disableCallButtons();
|
||||||
|
|
||||||
|
if (disableCallButtonsTimer == nullptr)
|
||||||
|
{
|
||||||
|
disableCallButtonsTimer = new QTimer();
|
||||||
|
connect(disableCallButtonsTimer, SIGNAL(timeout()),
|
||||||
|
this, SLOT(onEnableCallButtons()));
|
||||||
|
disableCallButtonsTimer->start(1500); // 1.5sec
|
||||||
|
qDebug() << "timer started!!";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatForm::disableCallButtons()
|
||||||
|
{
|
||||||
|
qDebug() << "disableCallButtons";
|
||||||
|
|
||||||
|
// Prevents race enable / disable / onEnable, when it should be disabled
|
||||||
|
if (disableCallButtonsTimer)
|
||||||
|
{
|
||||||
|
disableCallButtonsTimer->stop();
|
||||||
|
delete disableCallButtonsTimer;
|
||||||
|
disableCallButtonsTimer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
micButton->setObjectName("grey");
|
micButton->setObjectName("grey");
|
||||||
micButton->style()->polish(micButton);
|
micButton->style()->polish(micButton);
|
||||||
micButton->setToolTip("");
|
micButton->setToolTip("");
|
||||||
|
@ -660,16 +683,6 @@ void ChatForm::enableCallButtons()
|
||||||
videoButton->style()->polish(videoButton);
|
videoButton->style()->polish(videoButton);
|
||||||
videoButton->setToolTip("");
|
videoButton->setToolTip("");
|
||||||
videoButton->disconnect();
|
videoButton->disconnect();
|
||||||
|
|
||||||
if (disableCallButtonsTimer == nullptr)
|
|
||||||
{
|
|
||||||
disableCallButtonsTimer = new QTimer();
|
|
||||||
connect(disableCallButtonsTimer, SIGNAL(timeout()),
|
|
||||||
this, SLOT(onEnableCallButtons()));
|
|
||||||
disableCallButtonsTimer->start(1500); // 1.5sec
|
|
||||||
qDebug() << "timer started!!";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onEnableCallButtons()
|
void ChatForm::onEnableCallButtons()
|
||||||
|
|
|
@ -128,6 +128,7 @@ private:
|
||||||
QString secondsToDHMS(quint32 duration);
|
QString secondsToDHMS(quint32 duration);
|
||||||
CallConfirmWidget *callConfirm;
|
CallConfirmWidget *callConfirm;
|
||||||
void enableCallButtons();
|
void enableCallButtons();
|
||||||
|
void disableCallButtons();
|
||||||
bool isTyping;
|
bool isTyping;
|
||||||
void SendMessageStr(QString msg);
|
void SendMessageStr(QString msg);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user