[pulseaudio-discuss] [PATCH 2/2] stream: Frame-align divided audio segments

Ahmed S. Darwish darwish.07 at gmail.com
Tue Nov 22 20:18:56 UTC 2016

Executing below command will not produce any audio:

  pacat  --channels=3 /dev/urandom

Turns out that pa_stream_write() breaks large audio buffers into
segments of the maximum memblock size available -- a value which
is not necessarily frame aligned.

Meanwhile the server discards any non-aligned client audio, as a
security measure, due to some earlier reported daemon crashes.
Thus divide sent audio to the expected aligned form.

CommitReference-1: 22827a5e1e62
CommitReference-2: 150ace90f380
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=98475
BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=77595
Signed-off-by: Ahmed S. Darwish <darwish.07 at gmail.com>
 src/pulse/stream.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/pulse/stream.c b/src/pulse/stream.c
index e10ab12..ee95757 100644
--- a/src/pulse/stream.c
+++ b/src/pulse/stream.c
@@ -33,6 +33,7 @@
 #include <pulse/fork-detect.h>
 #include <pulsecore/pstream-util.h>
+#include <pulsecore/sample-util.h>
 #include <pulsecore/log.h>
 #include <pulsecore/hashmap.h>
 #include <pulsecore/macro.h>
@@ -1532,8 +1533,12 @@ int pa_stream_write_ext_free(
                 chunk.length = t_length;
             } else {
                 void *d;
+                size_t blk_size_max;
-                chunk.length = PA_MIN(t_length, pa_mempool_block_size_max(s->context->mempool));
+                /* Break large audio streams into _aligned_ blocks or the
+                 * other endpoint will happily discard them upon arrival. */
+                blk_size_max = pa_frame_align(pa_mempool_block_size_max(s->context->mempool), &s->sample_spec);
+                chunk.length = PA_MIN(t_length, blk_size_max);
                 chunk.memblock = pa_memblock_new(s->context->mempool, chunk.length);
                 d = pa_memblock_acquire(chunk.memblock);


More information about the pulseaudio-discuss mailing list