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:
parent
51ffd94e68
commit
1dc7e4cca5
|
@ -160,7 +160,8 @@ bool CoreAV::startCall(uint32_t friendNum, bool video)
|
||||||
if (!toxav_call(toxav, friendNum, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr))
|
if (!toxav_call(toxav, friendNum, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
calls.insert({friendNum, video, *this});
|
auto call = calls.insert({friendNum, video, *this});
|
||||||
|
call->startTimeout();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +185,23 @@ bool CoreAV::cancelCall(uint32_t friendNum)
|
||||||
return true;
|
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)
|
bool CoreAV::sendCallAudio(uint32_t callId)
|
||||||
{
|
{
|
||||||
if (!calls.contains(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 our state was null, we started the call and were still ringing
|
||||||
if (!call.state && state)
|
if (!call.state && state)
|
||||||
{
|
{
|
||||||
|
call.stopTimeout();
|
||||||
call.inactive = false;
|
call.inactive = false;
|
||||||
emit self->avStart(friendNum, call.videoEnabled);
|
emit self->avStart(friendNum, call.videoEnabled);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,7 @@ public slots:
|
||||||
bool startCall(uint32_t friendNum, bool video=false);
|
bool startCall(uint32_t friendNum, bool video=false);
|
||||||
bool answerCall(uint32_t friendNum);
|
bool answerCall(uint32_t friendNum);
|
||||||
bool cancelCall(uint32_t friendNum);
|
bool cancelCall(uint32_t friendNum);
|
||||||
|
void timeoutCall(uint32_t friendNum);
|
||||||
/// Starts the CoreAV main loop that calls toxav's main loop
|
/// Starts the CoreAV main loop that calls toxav's main loop
|
||||||
void start();
|
void start();
|
||||||
/// Stops the main loop
|
/// Stops the main loop
|
||||||
|
|
|
@ -93,10 +93,38 @@ const ToxCall& ToxCall::operator=(ToxCall&& other)
|
||||||
return *this;
|
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)
|
ToxFriendCall::ToxFriendCall(uint32_t FriendNum, bool VideoEnabled, CoreAV& av)
|
||||||
: ToxCall(FriendNum),
|
: ToxCall(FriendNum),
|
||||||
videoEnabled{VideoEnabled}, videoSource{nullptr},
|
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
|
auto audioTimerCopy = sendAudioTimer; // this might change after a move, but not sendAudioTimer
|
||||||
QObject::connect(sendAudioTimer, &QTimer::timeout, [FriendNum,&av,audioTimerCopy]()
|
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)
|
ToxFriendCall::ToxFriendCall(ToxFriendCall&& other)
|
||||||
: ToxCall(move(other)),
|
: ToxCall(move(other)),
|
||||||
videoEnabled{other.videoEnabled}, videoSource{other.videoSource},
|
videoEnabled{other.videoEnabled}, videoSource{other.videoSource},
|
||||||
state{other.state}
|
state{other.state}, av{other.av}, timeoutTimer{other.timeoutTimer}
|
||||||
{
|
{
|
||||||
other.videoEnabled = false;
|
other.videoEnabled = false;
|
||||||
other.videoSource = nullptr;
|
other.videoSource = nullptr;
|
||||||
|
other.timeoutTimer = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToxFriendCall::~ToxFriendCall()
|
ToxFriendCall::~ToxFriendCall()
|
||||||
{
|
{
|
||||||
|
if (timeoutTimer)
|
||||||
|
delete timeoutTimer;
|
||||||
|
|
||||||
if (videoEnabled)
|
if (videoEnabled)
|
||||||
{
|
{
|
||||||
// This destructor could be running in a toxav callback while holding toxav locks.
|
// 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;
|
videoSource = other.videoSource;
|
||||||
other.videoSource = nullptr;
|
other.videoSource = nullptr;
|
||||||
state = other.state;
|
state = other.state;
|
||||||
|
timeoutTimer = other.timeoutTimer;
|
||||||
|
other.timeoutTimer = nullptr;
|
||||||
|
av = other.av;
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,16 @@ struct ToxFriendCall : public ToxCall
|
||||||
bool videoEnabled; ///< True if our user asked for a video call, sending and recving
|
bool videoEnabled; ///< True if our user asked for a video call, sending and recving
|
||||||
CoreVideoSource* videoSource;
|
CoreVideoSource* videoSource;
|
||||||
TOXAV_FRIEND_CALL_STATE state; ///< State of the peer (not ours!)
|
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
|
struct ToxGroupCall : public ToxCall
|
||||||
|
|
Loading…
Reference in New Issue
Block a user