diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index ff92eb8f3..66c823821 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -96,7 +96,12 @@ CoreAV::CoreAV(Tox* tox) toxav_callback_call(toxav, CoreAV::callCallback, this); toxav_callback_call_state(toxav, CoreAV::stateCallback, this); +#if TOX_VERSION_IS_API_COMPATIBLE(0, 2, 0) + toxav_callback_audio_bit_rate(toxav, CoreAV::audioBitrateCallback, this); + toxav_callback_video_bit_rate(toxav, CoreAV::videoBitrateCallback, this); +#else toxav_callback_bit_rate_status(toxav, CoreAV::bitrateCallback, this); +#endif toxav_callback_audio_receive_frame(toxav, CoreAV::audioFrameCallback, this); toxav_callback_video_receive_frame(toxav, CoreAV::videoFrameCallback, this); @@ -824,6 +829,36 @@ void CoreAV::bitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t arate, u << ", ignoring it"; } +void CoreAV::audioBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rate, void* vSelf) +{ + CoreAV* self = static_cast(vSelf); + + // Run this slow path callback asynchronously on the AV thread to avoid deadlocks + if (QThread::currentThread() != self->coreavThread.get()) { + return (void)QMetaObject::invokeMethod(self, "audioBitrateCallback", Qt::QueuedConnection, + Q_ARG(ToxAV*, toxav), Q_ARG(uint32_t, friendNum), + Q_ARG(uint32_t, rate), Q_ARG(void*, vSelf)); + } + + qDebug() << "Recommended audio bitrate with" << friendNum << " is now " << rate + << ", ignoring it"; +} + +void CoreAV::videoBitrateCallback(ToxAV* toxav, uint32_t friendNum, uint32_t rate, void* vSelf) +{ + CoreAV* self = static_cast(vSelf); + + // Run this slow path callback asynchronously on the AV thread to avoid deadlocks + if (QThread::currentThread() != self->coreavThread.get()) { + return (void)QMetaObject::invokeMethod(self, "videoBitrateCallback", Qt::QueuedConnection, + Q_ARG(ToxAV*, toxav), Q_ARG(uint32_t, friendNum), + Q_ARG(uint32_t, rate), Q_ARG(void*, vSelf)); + } + + qDebug() << "Recommended video bitrate with" << friendNum << " is now " << rate + << ", ignoring it"; +} + void CoreAV::audioFrameCallback(ToxAV*, uint32_t friendNum, const int16_t* pcm, size_t sampleCount, uint8_t channels, uint32_t samplingRate, void* vSelf) { diff --git a/src/core/coreav.h b/src/core/coreav.h index 01cd26f1f..894d0d0ff 100644 --- a/src/core/coreav.h +++ b/src/core/coreav.h @@ -99,6 +99,8 @@ private slots: static void stateCallback(ToxAV*, uint32_t friendNum, uint32_t state, void* self); static void bitrateCallback(ToxAV* toxAV, uint32_t friendNum, uint32_t arate, uint32_t vrate, void* self); + static void audioBitrateCallback(ToxAV* toxAV, uint32_t friendNum, uint32_t rate, void* self); + static void videoBitrateCallback(ToxAV* toxAV, uint32_t friendNum, uint32_t rate, void* self); void killTimerFromThread(); private: