From 058f223a99acc1e7f74ff190f43ef6ad4f4a8134 Mon Sep 17 00:00:00 2001 From: "Ahmed S. Darwish" Date: Tue, 22 Nov 2016 22:18:56 +0200 Subject: [PATCH] stream: Frame-align divided audio segments 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 --- 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 e10ab127b..ee95757f7 100644 --- a/src/pulse/stream.c +++ b/src/pulse/stream.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -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);