Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(core): Use new callback API for bitrate set
Browse files Browse the repository at this point in the history
  • Loading branch information
Diadlo committed Jan 31, 2018
1 parent 2c8f03d commit d2deec7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/core/coreav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<CoreAV*>(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<CoreAV*>(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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/core/coreav.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit d2deec7

Please sign in to comment.