Apply new compensation only if it changed

If the compensation is the same (typically when it is 0), do not reapply
it.
This commit is contained in:
Romain Vimont 2023-03-11 23:00:48 +01:00
parent 73727e7fdf
commit 0bf866fa8d
2 changed files with 13 additions and 4 deletions

View file

@ -258,10 +258,15 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink,
LOGV("[Audio] Buffering: target=%" PRIu32 " avg=%f cur=%" PRIu32
" compensation=%d", ap->target_buffering, avg,
buffered_samples, diff);
if (diff != ap->compensation) {
int ret = swr_set_compensation(swr_ctx, diff, distance);
if (ret < 0) {
LOGW("Resampling compensation failed: %d", ret);
// not fatal
} else {
ap->compensation = diff;
}
}
}
}
@ -369,6 +374,7 @@ sc_audio_player_frame_sink_open(struct sc_frame_sink *sink,
ap->received = false;
ap->played = false;
ap->underflow = 0;
ap->compensation = 0;
// The thread calling open() is the thread calling push(), which fills the
// audio buffer consumed by the SDL audio thread.

View file

@ -60,6 +60,9 @@ struct sc_audio_player {
// (protected by SDL_AudioDeviceLock())
uint32_t underflow;
// Current applied compensation value (only used by the receiver thread)
int compensation;
// Set to true the first time a sample is received (protected by
// SDL_AudioDeviceLock())
bool received;