From 8fe8d70ea7c9cf44391a13ffec5c70c2ab4de1d1 Mon Sep 17 00:00:00 2001 From: Davide Beatrici Date: Sat, 28 Sep 2019 20:41:08 +0200 Subject: [PATCH] PulseAudio: Don't send empty data into the stream if there's no audio to send https://maemo.org/api_refs/5.0/5.0-final/pulseaudio/paplay_8c-example.html In the example the stream writer callback does nothing and returns in case there is no data to send. Our code, instead, creates a buffer, fills it with zeroes and writes it to the stream if audio output is not enabled. This commit changes the callback function's code so that it returns immediately in such case. The change has been tested by setting an underflow callback function (using pa_stream_set_underflow_callback()) and checking whether underflows occurred. --- src/mumble/PulseAudio.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/mumble/PulseAudio.cpp b/src/mumble/PulseAudio.cpp index e93d86f7b..5e8dee36a 100644 --- a/src/mumble/PulseAudio.cpp +++ b/src/mumble/PulseAudio.cpp @@ -529,13 +529,7 @@ void PulseAudioSystem::write_callback(pa_stream *s, size_t bytes, void *userdata AudioOutputPtr ao = g.ao; PulseAudioOutput *pao = dynamic_cast(ao.get()); - unsigned char buffer[bytes]; - if (! pao) { - // Transitioning, but most likely transitions back, so just zero. - memset(buffer, 0, bytes); - pa_stream_write(s, buffer, bytes, NULL, 0, PA_SEEK_RELATIVE); - pas->wakeup(); return; } @@ -600,6 +594,7 @@ void PulseAudioSystem::write_callback(pa_stream *s, size_t bytes, void *userdata const unsigned int samples = static_cast(bytes) / iSampleSize; bool oldAttenuation = pas->bAttenuating; + unsigned char buffer[bytes]; // do we have some mixed output? if (pao->mix(buffer, samples)) { // attenuate if instructed to or it's in settings