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: 22827a5e1e
CommitReference-2: 150ace90f3
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@gmail.com>
This commit is contained in:
Ahmed S. Darwish 2016-11-22 22:18:56 +02:00 committed by Tanu Kaskinen
parent f5315113a5
commit 058f223a99

View file

@ -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);