Skip to content

Commit 282f7a8

Browse files
petterreinholdtsenslouken
authored andcommitted
Changed PULSEAUDIO_FlushRecording() to only flush audio present when called.
When the flushing is not able to keep up with the audio stream coming in, it will end up flushing forever and block API clients from getting any audio. Fixes libsdl-org#9706 (cherry picked from commit 24693ac)
1 parent 9be8c2a commit 282f7a8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/audio/pulseaudio/SDL_pulseaudio.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static void PULSEAUDIO_FlushCapture(_THIS)
497497
{
498498
struct SDL_PrivateAudioData *h = this->hidden;
499499
const void *data = NULL;
500-
size_t nbytes = 0;
500+
size_t nbytes = 0, buflen = 0;
501501

502502
PULSEAUDIO_pa_threaded_mainloop_lock(pulseaudio_threaded_mainloop);
503503

@@ -507,19 +507,19 @@ static void PULSEAUDIO_FlushCapture(_THIS)
507507
h->capturelen = 0;
508508
}
509509

510-
while (SDL_AtomicGet(&this->enabled) && (PULSEAUDIO_pa_stream_readable_size(h->stream) > 0)) {
510+
buflen = PULSEAUDIO_pa_stream_readable_size(h->stream);
511+
while (SDL_AtomicGet(&this->enabled) && (buflen > 0)) {
511512
PULSEAUDIO_pa_threaded_mainloop_wait(pulseaudio_threaded_mainloop);
512513
if ((PULSEAUDIO_pa_context_get_state(pulseaudio_context) != PA_CONTEXT_READY) || (PULSEAUDIO_pa_stream_get_state(h->stream) != PA_STREAM_READY)) {
513514
/*printf("PULSEAUDIO DEVICE FAILURE IN FLUSHCAPTURE!\n");*/
514515
SDL_OpenedAudioDeviceDisconnected(this);
515516
break;
516517
}
517-
518-
if (PULSEAUDIO_pa_stream_readable_size(h->stream) > 0) {
519-
/* a new fragment is available! Just dump it. */
520-
PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
521-
PULSEAUDIO_pa_stream_drop(h->stream); /* drop this fragment. */
522-
}
518+
/* a fragment of audio present before FlushCapture was call is
519+
available! Just drop it. */
520+
PULSEAUDIO_pa_stream_peek(h->stream, &data, &nbytes);
521+
PULSEAUDIO_pa_stream_drop(h->stream);
522+
buflen -= nbytes;
523523
}
524524

525525
PULSEAUDIO_pa_threaded_mainloop_unlock(pulseaudio_threaded_mainloop);

0 commit comments

Comments
 (0)