if we fail to import a memblock fill in silence to guarantee stability of timing

This commit is contained in:
Lennart Poettering 2009-02-18 21:55:55 +01:00
parent 1737a19c86
commit be81a681ac
3 changed files with 29 additions and 21 deletions

View file

@ -335,8 +335,7 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o
pa_assert(p); pa_assert(p);
pa_assert(chunk); pa_assert(chunk);
pa_assert(chunk->memblock); pa_assert(chunk->length > 0);
pa_assert(chunk->length);
pa_assert(c); pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1); 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))) { if ((s = pa_dynarray_get(c->record_streams, channel))) {
pa_assert(seek == PA_SEEK_RELATIVE); if (chunk->memblock) {
pa_assert(offset == 0); pa_memblockq_seek(s->record_memblockq, offset, seek);
pa_memblockq_push_align(s->record_memblockq, chunk);
pa_memblockq_seek(s->record_memblockq, offset, seek); } else
pa_memblockq_push_align(s->record_memblockq, chunk); pa_memblockq_seek(s->record_memblockq, offset+chunk->length, seek);
if (s->read_callback) { if (s->read_callback) {
size_t l; size_t l;

View file

@ -4144,17 +4144,20 @@ static void pstream_memblock_callback(pa_pstream *p, uint32_t channel, int64_t o
if (playback_stream_isinstance(stream)) { if (playback_stream_isinstance(stream)) {
playback_stream *ps = PLAYBACK_STREAM(stream); playback_stream *ps = PLAYBACK_STREAM(stream);
if (seek != PA_SEEK_RELATIVE || offset != 0) if (chunk->memblock) {
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 (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 { } else {
upload_stream *u = UPLOAD_STREAM(stream); upload_stream *u = UPLOAD_STREAM(stream);
size_t l; size_t l;
if (!u->memchunk.memblock) { if (!u->memchunk.memblock) {
if (u->length == chunk->length) { if (u->length == chunk->length && chunk->memblock) {
u->memchunk = *chunk; u->memchunk = *chunk;
pa_memblock_ref(u->memchunk.memblock); pa_memblock_ref(u->memchunk.memblock);
u->length = 0; 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) if (l > chunk->length)
l = chunk->length; l = chunk->length;
if (l > 0) { if (l > 0) {
void *src, *dst; void *dst;
dst = pa_memblock_acquire(u->memchunk.memblock); dst = pa_memblock_acquire(u->memchunk.memblock);
src = pa_memblock_acquire(chunk->memblock);
memcpy((uint8_t*) dst + u->memchunk.index + u->memchunk.length, if (chunk->memblock) {
(uint8_t*) src+chunk->index, l); 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(u->memchunk.memblock);
pa_memblock_release(chunk->memblock);
u->memchunk.length += l; u->memchunk.length += l;
u->length -= l; u->length -= l;

View file

@ -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_INDEX]),
ntohl(p->read.shm_info[PA_PSTREAM_SHM_LENGTH])))) { ntohl(p->read.shm_info[PA_PSTREAM_SHM_LENGTH])))) {
pa_log_warn("Failed to import memory block."); if (pa_log_ratelimit())
return -1; pa_log_debug("Failed to import memory block.");
} }
if (p->recieve_memblock_callback) { if (p->recieve_memblock_callback) {
@ -842,7 +842,7 @@ static int do_read(pa_pstream *p) {
chunk.memblock = b; chunk.memblock = b;
chunk.index = 0; 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) ( offset = (int64_t) (
(((uint64_t) ntohl(p->read.descriptor[PA_PSTREAM_DESCRIPTOR_OFFSET_HI])) << 32) | (((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); p->recieve_memblock_callback_userdata);
} }
pa_memblock_unref(b); if (b)
pa_memblock_unref(b);
} }
goto frame_done; goto frame_done;