split pa_memblockq_flush() into two flush commands, one which fixes up the read ptr, and one which fixes up the write ptr

This commit is contained in:
Lennart Poettering 2008-06-26 00:39:31 +02:00
parent 5fccac94e7
commit 1514d13835
5 changed files with 45 additions and 25 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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);
void pa_memblockq_flush_write(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);
/* 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

View file

@ -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);
}

View file

@ -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;