Skip to content

Commit

Permalink
Increase audio thread priority
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rom1v committed Mar 10, 2023
1 parent 5ee59e0 commit aa450ff
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/src/audio_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aa450ff

Please sign in to comment.