From be81a681ac84ac56208c3bb315e04d04c2e53606 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 18 Feb 2009 21:55:55 +0100 Subject: if we fail to import a memblock fill in silence to guarantee stability of timing --- src/pulse/context.c | 13 ++++++------- src/pulsecore/protocol-native.c | 28 ++++++++++++++++++---------- src/pulsecore/pstream.c | 9 +++++---- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/pulse/context.c b/src/pulse/context.c index 8686e0de..d8d0a51d 100644 --- a/src/pulse/context.c +++ b/src/pulse/context.c @@ -335,8 +335,7 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o pa_assert(p); pa_assert(chunk); - pa_assert(chunk->memblock); - pa_assert(chunk->length); + pa_assert(chunk->length > 0); pa_assert(c); pa_assert(PA_REFCNT_VALUE(c) >= 1); @@ -344,11 +343,11 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o if ((s = pa_dynarray_get(c->record_streams, channel))) { - pa_assert(seek == PA_SEEK_RELATIVE); - pa_assert(offset == 0); - - pa_memblockq_seek(s->record_memblockq, offset, seek); - pa_memblockq_push_align(s->record_memblockq, chunk); + if (chunk->memblock) { + pa_memblockq_seek(s->record_memblockq, offset, seek); + pa_memblockq_push_align(s->record_memblockq, chunk); + } else + pa_memblockq_seek(s->record_memblockq, offset+chunk->length, seek); if (s->read_callback) { size_t l; diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index c3032618..fd7d9368 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -4144,17 +4144,20 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o if (playback_stream_isinstance(stream)) { playback_stream *ps = PLAYBACK_STREAM(stream); - if (seek != PA_SEEK_RELATIVE || offset != 0) - pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_SEEK, PA_UINT_TO_PTR(seek), offset, NULL, NULL); + if (chunk->memblock) { + if (seek != PA_SEEK_RELATIVE || offset != 0) + pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_SEEK, PA_UINT_TO_PTR(seek), offset, NULL, NULL); - pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, chunk, NULL); + pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_POST_DATA, NULL, 0, chunk, NULL); + } else + pa_asyncmsgq_post(ps->sink_input->sink->asyncmsgq, PA_MSGOBJECT(ps->sink_input), SINK_INPUT_MESSAGE_SEEK, PA_UINT_TO_PTR(seek), offset+chunk->length, NULL, NULL); } else { upload_stream *u = UPLOAD_STREAM(stream); size_t l; if (!u->memchunk.memblock) { - if (u->length == chunk->length) { + if (u->length == chunk->length && chunk->memblock) { u->memchunk = *chunk; pa_memblock_ref(u->memchunk.memblock); u->length = 0; @@ -4170,17 +4173,22 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o if (l > chunk->length) l = chunk->length; - if (l > 0) { - void *src, *dst; + void *dst; dst = pa_memblock_acquire(u->memchunk.memblock); - src = pa_memblock_acquire(chunk->memblock); - memcpy((uint8_t*) dst + u->memchunk.index + u->memchunk.length, - (uint8_t*) src+chunk->index, l); + if (chunk->memblock) { + void *src; + src = pa_memblock_acquire(chunk->memblock); + + memcpy((uint8_t*) dst + u->memchunk.index + u->memchunk.length, + (uint8_t*) src + chunk->index, l); + + pa_memblock_release(chunk->memblock); + } else + pa_silence_memory((uint8_t*) dst + u->memchunk.index + u->memchunk.length, l, &u->sample_spec); pa_memblock_release(u->memchunk.memblock); - pa_memblock_release(chunk->memblock); u->memchunk.length += l; u->length -= l; diff --git a/src/pulsecore/pstream.c b/src/pulsecore/pstream.c index 7ff8edc9..ef1105ba 100644 --- a/src/pulsecore/pstream.c +++ b/src/pulsecore/pstream.c @@ -832,8 +832,8 @@ static int do_read(pa_pstream *p) { ntohl(p->read.shm_info[PA_PSTREAM_SHM_INDEX]), ntohl(p->read.shm_info[PA_PSTREAM_SHM_LENGTH])))) { - pa_log_warn("Failed to import memory block."); - return -1; + if (pa_log_ratelimit()) + pa_log_debug("Failed to import memory block."); } if (p->recieve_memblock_callback) { @@ -842,7 +842,7 @@ static int do_read(pa_pstream *p) { chunk.memblock = b; chunk.index = 0; - chunk.length = pa_memblock_get_length(b); + chunk.length = b ? pa_memblock_get_length(b) : ntohl(p->read.shm_info[PA_PSTREAM_SHM_LENGTH]); offset = (int64_t) ( (((uint64_t) ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI])) << 32) | @@ -857,7 +857,8 @@ static int do_read(pa_pstream *p) { p->recieve_memblock_callback_userdata); } - pa_memblock_unref(b); + if (b) + pa_memblock_unref(b); } goto frame_done; -- cgit