Skip to content

Commit

Permalink
fix ngc opus encoder division by zero (was used in log message)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Dec 24, 2023
1 parent aedd0dd commit b439822
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 21 additions & 4 deletions amalgamation/toxcore_amalgamation.c
Original file line number Diff line number Diff line change
Expand Up @@ -77074,13 +77074,17 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u
return;
}

if (call->active == 0) {
if (!call->av) {
return;
}

if (!call->av) {
pthread_mutex_lock(call->toxav_call_mutex);
if (call->active == 0) {
pthread_mutex_unlock(call->toxav_call_mutex);
return;
}
pthread_mutex_unlock(call->toxav_call_mutex);


if (pthread_mutex_trylock(call->av->mutex) != 0) {
LOGGER_API_DEBUG(call->av->tox, "could not lock call->av->mutex, returning without processing BWC data");
Expand All @@ -77095,23 +77099,32 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u


pthread_mutex_lock(call->toxav_call_mutex);
if (call->active == 0) {
pthread_mutex_unlock(call->toxav_call_mutex);
pthread_mutex_unlock(call->mutex_video);
pthread_mutex_unlock(call->av->mutex);
return;
}

if (call->video_bit_rate == 0) {
// HINT: video is turned off -> just do nothing
pthread_mutex_unlock(call->toxav_call_mutex);
pthread_mutex_unlock(call->mutex_video);
pthread_mutex_unlock(call->av->mutex);
return;
}

if (!call->video) {
pthread_mutex_unlock(call->toxav_call_mutex);
pthread_mutex_unlock(call->mutex_video);
pthread_mutex_unlock(call->av->mutex);
return;
}

if (call->video->video_bitrate_autoset == 0) {
// HINT: client does not want bitrate autoset
pthread_mutex_unlock(call->toxav_call_mutex);
pthread_mutex_unlock(call->mutex_video);
pthread_mutex_unlock(call->av->mutex);
return;
}
Expand Down Expand Up @@ -77680,11 +77693,11 @@ static void call_kill_transmission(ToxAVCall *call)
return;
}

pthread_mutex_lock(call->toxav_call_mutex);
if (call->active == 0) {
pthread_mutex_unlock(call->toxav_call_mutex);
return;
}

pthread_mutex_lock(call->toxav_call_mutex);
call->active = 0;
pthread_mutex_unlock(call->toxav_call_mutex);

Expand Down Expand Up @@ -78363,6 +78376,10 @@ void* toxav_ngc_audio_init(const int32_t bit_rate, const int32_t sampling_rate,
ngc_audio_coders->ngc__opus_encoder = opus_encoder;
}

ngc_audio_coders->ngc__a_encoder_sampling_rate = sampling_rate;
ngc_audio_coders->ngc__a_encoder_channel_count = channel_count;
ngc_audio_coders->ngc__a_encoder_bitrate = bit_rate;

// bitrate in bits per second !!
// Rates from 500 to 512000 bits per second are meaningful
status_enc = opus_encoder_ctl(opus_encoder, OPUS_SET_BITRATE(bit_rate));
Expand Down
4 changes: 4 additions & 0 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -3321,6 +3321,10 @@ void* toxav_ngc_audio_init(const int32_t bit_rate, const int32_t sampling_rate,
ngc_audio_coders->ngc__opus_encoder = opus_encoder;
}

ngc_audio_coders->ngc__a_encoder_sampling_rate = sampling_rate;
ngc_audio_coders->ngc__a_encoder_channel_count = channel_count;
ngc_audio_coders->ngc__a_encoder_bitrate = bit_rate;

// bitrate in bits per second !!
// Rates from 500 to 512000 bits per second are meaningful
status_enc = opus_encoder_ctl(opus_encoder, OPUS_SET_BITRATE(bit_rate));
Expand Down

0 comments on commit b439822

Please sign in to comment.