From b1b4303649dabf90767eab975cb5bb2337f32b6b Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Sat, 4 Aug 2007 17:28:33 +0200 Subject: [PATCH] A few buffer freeing and debug ouptut tweaks. * Only free the buffer when there is data left to be buffered. * First free buffer space from audio data, then move the metadata (more efficient). * A few debug output improvements. --- testplugin.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/testplugin.c b/testplugin.c index f688aa2..737c664 100644 --- a/testplugin.c +++ b/testplugin.c @@ -343,7 +343,6 @@ static ssize_t buffer_handle(int handle_id) part of its data buffer */ static void free_buffer(int handle_id) { - DEBUGF("free_buffer(%d)\n", handle_id); struct memory_handle *h = find_handle(handle_id); if (!h) return; @@ -361,6 +360,8 @@ static void free_buffer(int handle_id) if (!h) return; h->data = RINGBUF_ADD(h->data, delta); h->ridx = RINGBUF_ADD(h->ridx, delta); + DEBUGF("free_buffer(%d): metadata, moved by %ld bytes\n", + handle_id, delta); } else { @@ -370,9 +371,8 @@ static void free_buffer(int handle_id) if (!h) return; h->data = RINGBUF_ADD(h->data, delta); h->available -= delta; + DEBUGF("free_buffer(%d): audio, %ld bytes freed\n", handle_id, delta); } - - graph_view(100); } static void fill_buffer(void) @@ -939,13 +939,21 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) while (!done_playing) { - if (wasted_space() > buffer_len/10) { + if (data_rem() > 0 && wasted_space() > buffer_len/5) { DEBUGF("there is %ld bytes of wasted space\n", wasted_space()); struct memory_handle *m = first_handle; while (m) { - free_buffer(m->id); + if (m->type == TYPE_AUDIO) + free_buffer(m->id); + m = m->next; + } + m = first_handle; + while (m) { + if (m->type != TYPE_AUDIO) + free_buffer(m->id); m = m->next; } + graph_view(100); } if (data_rem() > 0 && BUF_USED < 3*buffer_len/4 && -- 2.11.4.GIT