mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(coreav): fix assert because c-toxcore calls from unexpected thread
c-toxcore calls the groupCallCallback from it's main thread instead of the ToxAV thread as expected, this was triggering an assertion. Aditionally the destructors of Core and CoreAV were fixed, because they now either crashed or deadlocked qTox when it was closed while a group call was still running.
This commit is contained in:
parent
4b9e4a571d
commit
141cbf8870
|
@ -484,12 +484,14 @@ Core::Core(QThread* coreThread)
|
||||||
|
|
||||||
Core::~Core()
|
Core::~Core()
|
||||||
{
|
{
|
||||||
// need to reset av first, because it uses tox
|
/*
|
||||||
av.reset();
|
* First stop the thread to stop the timer and avoid Core emitting callbacks
|
||||||
|
* into an already destructed CoreAV.
|
||||||
|
*/
|
||||||
coreThread->exit(0);
|
coreThread->exit(0);
|
||||||
coreThread->wait();
|
coreThread->wait();
|
||||||
|
|
||||||
|
av.reset();
|
||||||
tox.reset();
|
tox.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,9 +151,16 @@ IAudioControl* CoreAV::getAudio()
|
||||||
|
|
||||||
CoreAV::~CoreAV()
|
CoreAV::~CoreAV()
|
||||||
{
|
{
|
||||||
|
/* Gracefully leave calls and group calls to avoid deadlocks in destructor */
|
||||||
for (const auto& call : calls) {
|
for (const auto& call : calls) {
|
||||||
cancelCall(call.first);
|
cancelCall(call.first);
|
||||||
}
|
}
|
||||||
|
for (const auto& call : groupCalls) {
|
||||||
|
leaveGroupCall(call.first);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(calls.empty());
|
||||||
|
assert(groupCalls.empty());
|
||||||
|
|
||||||
coreavThread->exit(0);
|
coreavThread->exit(0);
|
||||||
coreavThread->wait();
|
coreavThread->wait();
|
||||||
|
@ -452,12 +459,19 @@ void CoreAV::toggleMuteCallOutput(const Friend* f)
|
||||||
void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const int16_t* data,
|
void CoreAV::groupCallCallback(void* tox, uint32_t group, uint32_t peer, const int16_t* data,
|
||||||
unsigned samples, uint8_t channels, uint32_t sample_rate, void* core)
|
unsigned samples, uint8_t channels, uint32_t sample_rate, void* core)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* Currently group call audio decoding is handled in the Tox thread by c-toxcore,
|
||||||
|
* so we can be sure that this function is always called from the Core thread.
|
||||||
|
* To change this, an API change in c-toxcore is needed and this function probably must be
|
||||||
|
* changed.
|
||||||
|
* See https://github.com/TokTok/c-toxcore/issues/1364 for details.
|
||||||
|
*/
|
||||||
|
|
||||||
Q_UNUSED(tox);
|
Q_UNUSED(tox);
|
||||||
Core* c = static_cast<Core*>(core);
|
Core* c = static_cast<Core*>(core);
|
||||||
CoreAV* cav = c->getAv();
|
CoreAV* cav = c->getAv();
|
||||||
|
|
||||||
QReadLocker locker{&cav->callsLock};
|
QReadLocker locker{&cav->callsLock};
|
||||||
assert(QThread::currentThread() == cav->coreavThread.get());
|
|
||||||
|
|
||||||
const ToxPk peerPk = c->getGroupPeerPk(group, peer);
|
const ToxPk peerPk = c->getGroupPeerPk(group, peer);
|
||||||
const Settings& s = Settings::getInstance();
|
const Settings& s = Settings::getInstance();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user