From 0aaf9e9e20665b03f6dee3c8762ac943a71df958 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Fri, 7 Feb 2025 19:19:26 +0100 Subject: [PATCH] Fixes after rebase with master --- utils/aplay/alsa-pcm.c | 8 ++++---- utils/aplay/aplay.c | 13 ++++++++----- utils/aplay/delay-report.c | 6 ++++++ utils/aplay/delay-report.h | 7 +++++++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/utils/aplay/alsa-pcm.c b/utils/aplay/alsa-pcm.c index 70fce436a..595fc7bf6 100644 --- a/utils/aplay/alsa-pcm.c +++ b/utils/aplay/alsa-pcm.c @@ -121,7 +121,7 @@ static int alsa_pcm_set_sw_params( snd_pcm_sw_params_alloca(¶ms); - if ((err = snd_pcm_sw_params_current(pcm, params)) != 0) { + if ((err = snd_pcm_sw_params_current(snd_pcm, params)) != 0) { snprintf(buf, sizeof(buf), "Get current sw params: %s", snd_strerror(err)); goto fail; } @@ -131,7 +131,7 @@ static int alsa_pcm_set_sw_params( goto fail; } - if ((err = snd_pcm_sw_params(pcm, params)) != 0) { + if ((err = snd_pcm_sw_params(snd_pcm, params)) != 0) { snprintf(buf, sizeof(buf), "Set sw params: %s", snd_strerror(err)); goto fail; } @@ -175,7 +175,7 @@ int alsa_pcm_open( } pcm->format = actual_format; - if ((err = alsa_pcm_set_hw_params(pcm->pcm, format_1, format_2, + if ((err = alsa_pcm_set_hw_params(pcm, format_1, format_2, &actual_format, channels, &actual_rate, exact_rate, &actual_buffer_time, &actual_period_time, &tmp)) != 0) { snprintf(buf, sizeof(buf), "Set HW params: %s", tmp); @@ -195,7 +195,7 @@ int alsa_pcm_open( if (start_threshold > buffer_size) start_threshold = buffer_size; - if ((err = alsa_pcm_set_sw_params(pcm->pcm, start_threshold, &tmp)) != 0) { + if ((err = alsa_pcm_set_sw_params(pcm, start_threshold, &tmp)) != 0) { snprintf(buf, sizeof(buf), "Set SW params: %s", tmp); goto fail; } diff --git a/utils/aplay/aplay.c b/utils/aplay/aplay.c index 383c59112..8a3026cd2 100644 --- a/utils/aplay/aplay.c +++ b/utils/aplay/aplay.c @@ -807,8 +807,6 @@ static void *io_worker_routine(struct io_worker *w) { if (!w->ba_pcm.running) goto device_inactive; - size_t delay_frames = w->alsa_pcm.delay; - if (w->alsa_pcm.underrun) { /* Reset moving delay window buffer. */ delay_report_reset(&dr); @@ -819,12 +817,17 @@ static void *io_worker_routine(struct io_worker *w) { if (w->alsa_pcm.underrun) resampler_reset(resampler, 0); - delay_frames += ffb_len_out(write_buffer) / w->ba_pcm.channels; - delay_frames /= resampler_current_rate_ratio(resampler); + size_t resample_delay_frames; + resample_delay_frames = ffb_len_out(write_buffer) / w->ba_pcm.channels; + resample_delay_frames /= resampler_current_rate_ratio(resampler); } #endif - if (!delay_report_update(&dr, &w->alsa_pcm, w->ba_pcm_fd, &read_buffer, &err)) { + if (!delay_report_update(&dr, &w->alsa_pcm, +#if ENABLE_APLAY_RESAMPLER + resample_delay_frames, +#endif + w->ba_pcm_fd, &read_buffer, &err)) { error("Couldn't update BlueALSA PCM client delay: %s", err.message); dbus_error_free(&err); goto fail; diff --git a/utils/aplay/delay-report.c b/utils/aplay/delay-report.c index f3f632727..19846fbcb 100644 --- a/utils/aplay/delay-report.c +++ b/utils/aplay/delay-report.c @@ -44,6 +44,9 @@ void delay_report_reset( bool delay_report_update( struct delay_report *dr, struct alsa_pcm *pcm, +#if ENABLE_APLAY_RESAMPLER + size_t resample_delay_frames, +#endif int ba_pcm_fd, ffb_t *buffer, DBusError *err) { @@ -59,6 +62,9 @@ bool delay_report_update( const size_t num_values = ARRAYSIZE(dr->values); /* Store the delay calculated from all components. */ dr->values[dr->values_i % num_values] = pcm->delay + ba_pcm_frames + buffer_frames; +#if ENABLE_APLAY_RESAMPLER + dr->values[dr->values_i % num_values] += resample_delay_frames; +#endif dr->values_i++; struct timespec ts_now; diff --git a/utils/aplay/delay-report.h b/utils/aplay/delay-report.h index fde414350..c2cc6c4a1 100644 --- a/utils/aplay/delay-report.h +++ b/utils/aplay/delay-report.h @@ -12,6 +12,10 @@ #ifndef BLUEALSA_APLAY_DELAYREPORT_H_ #define BLUEALSA_APLAY_DELAYREPORT_H_ +#if HAVE_CONFIG_H +# include +#endif + #include #include @@ -48,6 +52,9 @@ void delay_report_reset( bool delay_report_update( struct delay_report *dr, struct alsa_pcm *pcm, +#if ENABLE_APLAY_RESAMPLER + size_t resample_delay_frames, +#endif int ba_pcm_fd, ffb_t *buffer, DBusError *err);