Apply new compensation only if it changed

If the compensation is the same (typically when it is 0), do not reapply
it.
pull/3774/head
Romain Vimont 1 year ago
parent 73727e7fdf
commit 0bf866fa8d

@ -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);
int ret = swr_set_compensation(swr_ctx, diff, distance);
if (ret < 0) {
LOGW("Resampling compensation failed: %d", ret);
// not fatal
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.

@ -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;

Loading…
Cancel
Save