Browse Source

fix(coreav): prevent racy access to call variable

reviewable/pr5926/r10
sudden6 6 years ago
parent
commit
c507d2665d
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 14
      src/core/coreav.cpp

14
src/core/coreav.cpp

@ -731,9 +731,10 @@ void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool vid @@ -731,9 +731,10 @@ void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool vid
state |= TOXAV_FRIEND_CALL_STATE_SENDING_V | TOXAV_FRIEND_CALL_STATE_ACCEPTING_V;
it.first->second->setState(static_cast<TOXAV_FRIEND_CALL_STATE>(state));
// Must explicitely unlock, because a deadlock can happen via ChatForm/Audio
locker.unlock();
emit reinterpret_cast<CoreAV*>(self)->avInvite(friendNum, video);
emit self->avInvite(friendNum, video);
}
void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, void* vSelf)
@ -741,6 +742,7 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi @@ -741,6 +742,7 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi
Q_UNUSED(toxav);
CoreAV* self = static_cast<CoreAV*>(vSelf);
// we must unlock this lock before emitting any signals
QWriteLocker locker{&self->callsLock};
auto it = self->calls.find(friendNum);
@ -765,14 +767,18 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi @@ -765,14 +767,18 @@ 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.getState() && state) {
call.setActive(true);
bool videoEnabled = call.getVideoEnabled();
call.setState(static_cast<TOXAV_FRIEND_CALL_STATE>(state));
locker.unlock();
emit self->avStart(friendNum, call.getVideoEnabled());
emit self->avStart(friendNum, videoEnabled);
} else if ((call.getState() & TOXAV_FRIEND_CALL_STATE_SENDING_V)
&& !(state & TOXAV_FRIEND_CALL_STATE_SENDING_V)) {
qDebug() << "Friend" << friendNum << "stopped sending video";
if (call.getVideoSource()) {
call.getVideoSource()->stopSource();
}
call.setState(static_cast<TOXAV_FRIEND_CALL_STATE>(state));
} else if (!(call.getState() & TOXAV_FRIEND_CALL_STATE_SENDING_V)
&& (state & TOXAV_FRIEND_CALL_STATE_SENDING_V)) {
// Workaround toxav sometimes firing callbacks for "send last frame" -> "stop sending
@ -783,9 +789,9 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi @@ -783,9 +789,9 @@ void CoreAV::stateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t state, voi
if (call.getVideoSource()) {
call.getVideoSource()->restartSource();
}
}
call.setState(static_cast<TOXAV_FRIEND_CALL_STATE>(state));
call.setState(static_cast<TOXAV_FRIEND_CALL_STATE>(state));
}
}
}

Loading…
Cancel
Save