From 9d1c7716c0ade92634b41d1ec4bd49c3af177d41 Mon Sep 17 00:00:00 2001 From: Jaska Uimonen Date: Mon, 4 Mar 2013 09:24:37 +0200 Subject: fix draining not to lose samples in pre buffer --- src/pulsecore/memblockq.c | 13 +++++++++++++ src/pulsecore/memblockq.h | 3 +++ src/pulsecore/protocol-native.c | 8 +++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c index 18066f77..2dd08bc7 100644 --- a/src/pulsecore/memblockq.c +++ b/src/pulsecore/memblockq.c @@ -814,6 +814,19 @@ void pa_memblockq_prebuf_disable(pa_memblockq *bq) { bq->in_prebuf = FALSE; } +void pa_memblockq_prebuf_disable_and_adjust(pa_memblockq *bq) { + size_t len; + + pa_assert(bq); + + bq->in_prebuf = FALSE; + + if (bq->prebuf > 0 && (len = pa_memblockq_get_length(bq)) > 0) { + pa_log("adjusting prebuf length to %u", len); + bq->prebuf = len; + } +} + void pa_memblockq_prebuf_force(pa_memblockq *bq) { pa_assert(bq); diff --git a/src/pulsecore/memblockq.h b/src/pulsecore/memblockq.h index 08c0bf04..0a7f9dfa 100644 --- a/src/pulsecore/memblockq.h +++ b/src/pulsecore/memblockq.h @@ -134,6 +134,9 @@ void pa_memblockq_flush_read(pa_memblockq *bq); /* Ignore prebuf for now */ void pa_memblockq_prebuf_disable(pa_memblockq *bq); +/* Ignore prebuf for now and adjust prebuf size to actual size */ +void pa_memblockq_prebuf_disable_and_adjust(pa_memblockq *bq); + /* Force prebuf */ void pa_memblockq_prebuf_force(pa_memblockq *bq); diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 41fc0a02..8c45a339 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -1487,8 +1487,14 @@ static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int break; case SINK_INPUT_MESSAGE_DRAIN: + if (i->thread_info.state == PA_SINK_INPUT_CORKED) + func = pa_memblockq_prebuf_disable_and_adjust; + else + func = pa_memblockq_prebuf_disable; + break; + case SINK_INPUT_MESSAGE_TRIGGER: - func = pa_memblockq_prebuf_disable; + func = pa_memblockq_prebuf_disable; break; default: -- cgit v1.2.3