From af5558a18f21b6d0919eac260047ff196e1c76f6 Mon Sep 17 00:00:00 2001 From: David Henningsson Date: Wed, 21 Jan 2015 08:17:04 +0100 Subject: [PATCH] pstream: Never split a packet in the middle of a frame BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=88452 Signed-off-by: David Henningsson --- src/modules/module-tunnel.c | 2 +- src/pulse/stream.c | 4 ++-- src/pulsecore/protocol-native.c | 4 ++-- src/pulsecore/pstream.c | 8 ++++++-- src/pulsecore/pstream.h | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/module-tunnel.c b/src/modules/module-tunnel.c index 7c233c9..d370f29 100644 --- a/src/modules/module-tunnel.c +++ b/src/modules/module-tunnel.c @@ -562,7 +562,7 @@ static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offse * IO thread context where the rest of the messages are * dispatched. Yeah, ugly, but I am a lazy bastard. */ - pa_pstream_send_memblock(u->pstream, u->channel, 0, PA_SEEK_RELATIVE, chunk); + pa_pstream_send_memblock(u->pstream, u->channel, 0, PA_SEEK_RELATIVE, chunk, &u->sink->sample_spec); u->counter_delta += (int64_t) chunk->length; diff --git a/src/pulse/stream.c b/src/pulse/stream.c index d4ad505..27ca6b2 100644 --- a/src/pulse/stream.c +++ b/src/pulse/stream.c @@ -1503,7 +1503,7 @@ int pa_stream_write_ext_free( s->write_memblock = NULL; s->write_data = NULL; - pa_pstream_send_memblock(s->context->pstream, s->channel, offset, seek, &chunk); + pa_pstream_send_memblock(s->context->pstream, s->channel, offset, seek, &chunk, &s->sample_spec); pa_memblock_unref(chunk.memblock); } else { @@ -1533,7 +1533,7 @@ int pa_stream_write_ext_free( pa_memblock_release(chunk.memblock); } - pa_pstream_send_memblock(s->context->pstream, s->channel, t_offset, t_seek, &chunk); + pa_pstream_send_memblock(s->context->pstream, s->channel, t_offset, t_seek, &chunk, &s->sample_spec); t_offset = 0; t_seek = PA_SEEK_RELATIVE; diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 2059841..e558dc3 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -1398,7 +1398,7 @@ static void native_connection_send_memblock(pa_native_connection *c) { if (schunk.length > r->buffer_attr.fragsize) schunk.length = r->buffer_attr.fragsize; - pa_pstream_send_memblock(c->pstream, r->index, 0, PA_SEEK_RELATIVE, &schunk); + pa_pstream_send_memblock(c->pstream, r->index, 0, PA_SEEK_RELATIVE, &schunk, &r->source_output->sample_spec); pa_memblockq_drop(r->memblockq, schunk.length); pa_memblock_unref(schunk.memblock); @@ -2630,7 +2630,7 @@ static void setup_srbchannel(pa_native_connection *c) { mc.memblock = srbt.memblock; mc.index = 0; mc.length = pa_memblock_get_length(srbt.memblock); - pa_pstream_send_memblock(c->pstream, 0, 0, 0, &mc); + pa_pstream_send_memblock(c->pstream, 0, 0, 0, &mc, NULL); c->srbpending = srb; } diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c index ad8eef1..e396410 100644 --- a/src/pulsecore/pstream.c +++ b/src/pulsecore/pstream.c @@ -353,9 +353,10 @@ void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, const pa_cmsg_ancil p->mainloop->defer_enable(p->defer_event, 1); } -void pa_pstream_send_memblock(pa_pstream*p, uint32_t channel, int64_t offset, pa_seek_mode_t seek_mode, const pa_memchunk *chunk) { +void pa_pstream_send_memblock(pa_pstream*p, uint32_t channel, int64_t offset, pa_seek_mode_t seek_mode, + const pa_memchunk *chunk, pa_sample_spec *ss) { size_t length, idx; - size_t bsm; + size_t bsm, frame_size; pa_assert(p); pa_assert(PA_REFCNT_VALUE(p) > 0); @@ -369,6 +370,9 @@ void pa_pstream_send_memblock(pa_pstream*p, uint32_t channel, int64_t offset, pa length = chunk->length; bsm = pa_mempool_block_size_max(p->mempool); + frame_size = ss ? pa_frame_size(ss) : 0; + if (frame_size) + bsm -= bsm % frame_size; while (length > 0) { struct item_info *i; diff --git a/src/pulsecore/pstream.h b/src/pulsecore/pstream.h index f4e1462..118052e 100644 --- a/src/pulsecore/pstream.h +++ b/src/pulsecore/pstream.h @@ -49,7 +49,7 @@ void pa_pstream_unref(pa_pstream*p); void pa_pstream_unlink(pa_pstream *p); void pa_pstream_send_packet(pa_pstream*p, pa_packet *packet, const pa_cmsg_ancil_data *ancil_data); -void pa_pstream_send_memblock(pa_pstream*p, uint32_t channel, int64_t offset, pa_seek_mode_t seek, const pa_memchunk *chunk); +void pa_pstream_send_memblock(pa_pstream*p, uint32_t channel, int64_t offset, pa_seek_mode_t seek, const pa_memchunk *chunk, pa_sample_spec *ss); void pa_pstream_send_release(pa_pstream *p, uint32_t block_id); void pa_pstream_send_revoke(pa_pstream *p, uint32_t block_id); -- 1.9.1