From 9ea4446369e53936032668d483aede39e49c84c1 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 9 Jun 2024 19:25:32 +0200 Subject: [PATCH] Release the audio lock early The final write from the writer thread does not require a lock: it is guaranteed that enough space is available since the reader thread never writes. --- app/src/audio_player.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/audio_player.c b/app/src/audio_player.c index bd799c51..dac85bf9 100644 --- a/app/src/audio_player.c +++ b/app/src/audio_player.c @@ -194,7 +194,11 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink, // Still insufficient, drop old samples to make space skipped_samples = sc_audiobuf_read(&ap->buf, NULL, remaining); assert(skipped_samples == remaining); + } + SDL_UnlockAudioDevice(ap->device); + + if (written < samples) { // Now there is enough space uint32_t w = sc_audiobuf_write(&ap->buf, swr_buf + TO_BYTES(written), @@ -202,8 +206,6 @@ sc_audio_player_frame_sink_push(struct sc_frame_sink *sink, assert(w == remaining); (void) w; } - - SDL_UnlockAudioDevice(ap->device); } uint32_t underflow = 0;