1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Add 45s call ringing timeout

This commit is contained in:
tux3 2015-10-24 01:53:10 +02:00
parent 51ffd94e68
commit 1dc7e4cca5
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
4 changed files with 68 additions and 3 deletions

View File

@ -160,7 +160,8 @@ bool CoreAV::startCall(uint32_t friendNum, bool video)
if (!toxav_call(toxav, friendNum, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr))
return false;
calls.insert({friendNum, video, *this});
auto call = calls.insert({friendNum, video, *this});
call->startTimeout();
return true;
}
@ -184,6 +185,23 @@ bool CoreAV::cancelCall(uint32_t friendNum)
return true;
}
void CoreAV::timeoutCall(uint32_t friendNum)
{
if (QThread::currentThread() != coreavThread.get())
{
(void)QMetaObject::invokeMethod(this, "timeoutCall", Qt::BlockingQueuedConnection,
Q_ARG(uint32_t, friendNum));
return;
}
if (!cancelCall(friendNum))
{
qWarning() << QString("Failed to timeout call with %1").arg(friendNum);
return;
}
qDebug() << "Call with friend"<<friendNum<<"timed out";
emit avEnd(friendNum);
}
bool CoreAV::sendCallAudio(uint32_t callId)
{
if (!calls.contains(callId))
@ -459,6 +477,7 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi
// If our state was null, we started the call and were still ringing
if (!call.state && state)
{
call.stopTimeout();
call.inactive = false;
emit self->avStart(friendNum, call.videoEnabled);
}

View File

@ -84,6 +84,7 @@ public slots:
bool startCall(uint32_t friendNum, bool video=false);
bool answerCall(uint32_t friendNum);
bool cancelCall(uint32_t friendNum);
void timeoutCall(uint32_t friendNum);
/// Starts the CoreAV main loop that calls toxav's main loop
void start();
/// Stops the main loop

View File

@ -93,10 +93,38 @@ const ToxCall& ToxCall::operator=(ToxCall&& other)
return *this;
}
void ToxFriendCall::startTimeout()
{
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);
});
}
if (!timeoutTimer->isActive())
timeoutTimer->start(CALL_TIMEOUT);
}
void ToxFriendCall::stopTimeout()
{
if (!timeoutTimer)
return;
timeoutTimer->stop();
delete timeoutTimer;
timeoutTimer = nullptr;
}
ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av)
: ToxCall(FriendNum),
videoEnabled{VideoEnabled}, videoSource{nullptr},
state{static_cast<TOXAV_FRIEND_CALL_STATE>(0)}
state{static_cast<TOXAV_FRIEND_CALL_STATE>(0)},
av{&av}, timeoutTimer{nullptr}
{
auto audioTimerCopy = sendAudioTimer; // this might change after a move, but not sendAudioTimer
QObject::connect(sendAudioTimer, &QTimer::timeout, [FriendNum,&av,audioTimerCopy]()
@ -122,14 +150,18 @@ ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av)
ToxFriendCall::ToxFriendCall(ToxFriendCall&& other)
: ToxCall(move(other)),
videoEnabled{other.videoEnabled}, videoSource{other.videoSource},
state{other.state}
state{other.state}, av{other.av}, timeoutTimer{other.timeoutTimer}
{
other.videoEnabled = false;
other.videoSource = nullptr;
other.timeoutTimer = nullptr;
}
ToxFriendCall::~ToxFriendCall()
{
if (timeoutTimer)
delete timeoutTimer;
if (videoEnabled)
{
// This destructor could be running in a toxav callback while holding toxav locks.
@ -152,6 +184,9 @@ const ToxFriendCall& ToxFriendCall::operator=(ToxFriendCall&& other)
videoSource = other.videoSource;
other.videoSource = nullptr;
state = other.state;
timeoutTimer = other.timeoutTimer;
other.timeoutTimer = nullptr;
av = other.av;
return *this;
}

View File

@ -60,6 +60,16 @@ struct ToxFriendCall : public ToxCall
bool videoEnabled; ///< True if our user asked for a video call, sending and recving
CoreVideoSource* videoSource;
TOXAV_FRIEND_CALL_STATE state; ///< State of the peer (not ours!)
void startTimeout();
void stopTimeout();
protected:
CoreAV* av;
QTimer* timeoutTimer;
private:
static constexpr int CALL_TIMEOUT = 45000;
};
struct ToxGroupCall : public ToxCall