From 1514d138353f04578d885d9cb18c528d9b562a83 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 26 Jun 2008 00:39:31 +0200 Subject: split pa_memblockq_flush() into two flush commands, one which fixes up the read ptr, and one which fixes up the write ptr --- src/modules/module-combine.c | 4 ++-- src/pulsecore/memblockq.c | 17 +++++++++++++++- src/pulsecore/memblockq.h | 43 +++++++++++++++++++++++------------------ src/pulsecore/protocol-native.c | 4 ++-- src/pulsecore/sink-input.c | 2 +- 5 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/modules/module-combine.c b/src/modules/module-combine.c index cef7a99a..8c155da0 100644 --- a/src/modules/module-combine.c +++ b/src/modules/module-combine.c @@ -525,7 +525,7 @@ static int sink_input_process_msg(pa_msgobject *obj, int code, void *data, int64 if (PA_SINK_IS_OPENED(o->sink_input->sink->thread_info.state)) pa_memblockq_push_align(o->memblockq, chunk); else - pa_memblockq_flush(o->memblockq); + pa_memblockq_flush_write(o->memblockq); return 0; } @@ -555,7 +555,7 @@ static void enable_output(struct output *o) { if (output_create_sink_input(o) >= 0) { - pa_memblockq_flush(o->memblockq); + pa_memblockq_flush_write(o->memblockq); pa_sink_input_put(o->sink_input); diff --git a/src/pulsecore/memblockq.c b/src/pulsecore/memblockq.c index 9ce3372c..841b9075 100644 --- a/src/pulsecore/memblockq.c +++ b/src/pulsecore/memblockq.c @@ -638,7 +638,7 @@ void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek) { bq->missing -= delta; } -void pa_memblockq_flush(pa_memblockq *bq) { +void pa_memblockq_flush_write(pa_memblockq *bq) { int64_t old, delta; pa_assert(bq); @@ -662,6 +662,21 @@ void pa_memblockq_flush(pa_memblockq *bq) { bq->missing -= delta; } +void pa_memblockq_flush_read(pa_memblockq *bq) { + int64_t old, delta; + pa_assert(bq); + + pa_memblockq_silence(bq); + + old = bq->read_index; + bq->read_index = bq->write_index; + + pa_memblockq_prebuf_force(bq); + + delta = bq->read_index - old; + bq->missing += delta; +} + size_t pa_memblockq_get_tlength(pa_memblockq *bq) { pa_assert(bq); diff --git a/src/pulsecore/memblockq.h b/src/pulsecore/memblockq.h index ad3eea49..4b9450f6 100644 --- a/src/pulsecore/memblockq.h +++ b/src/pulsecore/memblockq.h @@ -84,6 +84,9 @@ int pa_memblockq_push(pa_memblockq* bq, const pa_memchunk *chunk); * you know what you do. */ int pa_memblockq_push_align(pa_memblockq* bq, const pa_memchunk *chunk); +/* Manipulate the write pointer */ +void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek); + /* Return a copy of the next memory chunk in the queue. It is not * removed from the queue. There are two reasons this function might * fail: 1. prebuffering is active, 2. queue is empty and no silence @@ -95,6 +98,9 @@ int pa_memblockq_peek(pa_memblockq* bq, pa_memchunk *chunk); /* Drop the specified bytes from the queue. */ void pa_memblockq_drop(pa_memblockq *bq, size_t length); +/* Rewind the read index. If the history is shorter than the specified length we'll point to silence afterwards. */ +void pa_memblockq_rewind(pa_memblockq *bq, size_t length); + /* Test if the pa_memblockq is currently readable, that is, more data than base */ pa_bool_t pa_memblockq_is_readable(pa_memblockq *bq); @@ -111,26 +117,11 @@ size_t pa_memblockq_pop_missing(pa_memblockq *bq); /* Directly moves the data from the source memblockq into bq */ int pa_memblockq_splice(pa_memblockq *bq, pa_memblockq *source); -/* Returns the minimal request value */ -size_t pa_memblockq_get_minreq(pa_memblockq *bq); - -/* Manipulate the write pointer */ -void pa_memblockq_seek(pa_memblockq *bq, int64_t offset, pa_seek_mode_t seek); - /* Set the queue to silence, set write index to read index */ -void pa_memblockq_flush(pa_memblockq *bq); - -/* Get Target length */ -size_t pa_memblockq_get_tlength(pa_memblockq *bq); - -/* Return the current read index */ -int64_t pa_memblockq_get_read_index(pa_memblockq *bq); - -/* Return the current write index */ -int64_t pa_memblockq_get_write_index(pa_memblockq *bq); +void pa_memblockq_flush_write(pa_memblockq *bq); -/* Rewind the read index. If the history is shorter than the specified length we'll point to silence afterwards. */ -void pa_memblockq_rewind(pa_memblockq *bq, size_t length); +/* Set the queue to silence, set write read index to write index*/ +void pa_memblockq_flush_read(pa_memblockq *bq); /* Ignore prebuf for now */ void pa_memblockq_prebuf_disable(pa_memblockq *bq); @@ -141,9 +132,24 @@ void pa_memblockq_prebuf_force(pa_memblockq *bq); /* Return the maximum length of the queue in bytes */ size_t pa_memblockq_get_maxlength(pa_memblockq *bq); +/* Get Target length */ +size_t pa_memblockq_get_tlength(pa_memblockq *bq); + /* Return the prebuffer length in bytes */ size_t pa_memblockq_get_prebuf(pa_memblockq *bq); +/* Returns the minimal request value */ +size_t pa_memblockq_get_minreq(pa_memblockq *bq); + +/* Return the base unit in bytes */ +size_t pa_memblockq_get_base(pa_memblockq *bq); + +/* Return the current read index */ +int64_t pa_memblockq_get_read_index(pa_memblockq *bq); + +/* Return the current write index */ +int64_t pa_memblockq_get_write_index(pa_memblockq *bq); + /* Change metrics. Always call in order. */ void pa_memblockq_set_maxlength(pa_memblockq *memblockq, size_t maxlength); /* might modify tlength, prebuf, minreq too */ void pa_memblockq_set_tlength(pa_memblockq *memblockq, size_t tlength); /* might modify minreq, too */ @@ -169,6 +175,5 @@ pa_bool_t pa_memblockq_prebuf_active(pa_memblockq *bq); /* Return how many items are currently stored in the queue */ unsigned pa_memblockq_get_nblocks(pa_memblockq *bq); -size_t pa_memblockq_get_base(pa_memblockq *bq); #endif diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c index 923a5665..862b062e 100644 --- a/src/pulsecore/protocol-native.c +++ b/src/pulsecore/protocol-native.c @@ -1196,7 +1196,7 @@ static int sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int switch (code) { case SINK_INPUT_MESSAGE_FLUSH: - func = pa_memblockq_flush; + func = pa_memblockq_flush_write; break; case SINK_INPUT_MESSAGE_PREBUF_FORCE: @@ -3072,7 +3072,7 @@ static void command_flush_record_stream(PA_GCC_UNUSED pa_pdispatch *pd, PA_GCC_U s = pa_idxset_get_by_index(c->record_streams, idx); CHECK_VALIDITY(c->pstream, s, tag, PA_ERR_NOENTITY); - pa_memblockq_flush(s->memblockq); + pa_memblockq_flush_read(s->memblockq); pa_pstream_send_simple_ack(c->pstream, tag); } diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index 43e7bb21..be169709 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -664,7 +664,7 @@ void pa_sink_input_process_rewind(pa_sink_input *i, size_t nbytes /* in sink sam /* We were asked to drop all buffered data, and rerequest new * data from implementor the next time push() is called */ - pa_memblockq_flush(i->thread_info.render_memblockq); + pa_memblockq_flush_write(i->thread_info.render_memblockq); } else if (i->thread_info.rewrite_nbytes > 0) { size_t max_rewrite, amount; -- cgit