From 5d29b1cb66e8133c31cb6ba430195a2d72b657f2 Mon Sep 17 00:00:00 2001 From: Jaska Uimonen Date: Mon, 4 Mar 2013 09:24:37 +0200 Subject: [PATCH] fix draining not to lose samples in pre buffer --- src/pulsecore/memblockq.c | 13 +++++++++++++ src/pulsecore/memblockq.h | 3 +++ src/pulsecore/protocol-native.c | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c index 5b9a44b..8f4ec7a 100644 --- a/src/pulsecore/memblockq.c +++ b/src/pulsecore/memblockq.c @@ -807,6 +807,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 88906ba..b998828 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 96b6850..dec5920 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -1500,6 +1500,12 @@ 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; break; -- 1.8.1.2