From aa450ffc3f618a286c0eb7a5f60244b53d650e75 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Wed, 8 Mar 2023 21:37:27 +0100 Subject: [PATCH] Increase audio thread priority The audio demuxer thread is the one filling the audio buffer read by the SDL audio thread. It is time critical to avoid buffer underflow. --- app/src/audio_player.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/audio_player.c b/app/src/audio_player.c index de218f1e..85de0620 100644 --- a/app/src/audio_player.c +++ b/app/src/audio_player.c @@ -382,6 +382,14 @@ sc_audio_player_frame_sink_open(struct sc_frame_sink *sink, ap->received = false; ap->played = false; + // The thread calling open() is the thread calling push(), which fills the + // audio buffer consumed by the SDL audio thread. + ok = sc_thread_set_priority(SC_THREAD_PRIORITY_TIME_CRITICAL); + if (!ok) { + ok = sc_thread_set_priority(SC_THREAD_PRIORITY_HIGH); + (void) ok; // We don't care if it worked, at least we tried + } + SDL_PauseAudioDevice(ap->device, 0); return true;