From 0b644cea4904d596d6c1c4504c3e653fa4233282 Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Sat, 20 Oct 2007 17:46:56 +0200 Subject: [PATCH] Add the "buffering" status indicator For now its purpose is to let codec_advance_buffer_counters() know the difference between the case where data is low because buffering has just started and the case where data is low because although the buffer is (almost) full, nearly all of it has been read. Posting Q_AUDIO_FILL_BUFFER is only needed in the second case, and can even be harmful in the first. --- apps/buffering.c | 5 +++++ apps/buffering.h | 3 +++ apps/debug_menu.c | 3 +++ apps/playback.c | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/buffering.c b/apps/buffering.c index cd09366a6..d2e3bfd7b 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -448,6 +448,7 @@ static ssize_t buffer_handle(int handle_id) lseek(h->fd, h->offset, SEEK_SET); } + buffering = true; trigger_cpu_boost(); ssize_t ret = 0; @@ -507,6 +508,7 @@ static ssize_t buffer_handle(int handle_id) handle_id, (long)ret, (long)h->available, (long)h->filesize, (long)h->filerem, (long)h->offset); + buffering = false; return ret; } @@ -1000,6 +1002,8 @@ bool buffering_init(char *filebuf, size_t filebuflen) if (!filebuf || !filebuflen) return false; + buffering = false; + buffer = filebuf; buffer_len = filebuflen; guard_buffer = buffer + buffer_len; @@ -1151,4 +1155,5 @@ void buffering_get_debugdata(struct buffering_debug *dbgdata) dbgdata->wasted_space = wasted_space(); dbgdata->buffered_data = buffered_data(); dbgdata->useful_data = useful_data(0); + dbgdata->buffering = buffering; } diff --git a/apps/buffering.h b/apps/buffering.h index bd8de9b3b..f541ff0fc 100644 --- a/apps/buffering.h +++ b/apps/buffering.h @@ -40,6 +40,7 @@ struct buffering_debug { size_t wasted_space; size_t data_rem; size_t useful_data; + bool buffering; }; enum data_type { @@ -53,6 +54,8 @@ enum data_type { TYPE_UNKNOWN, }; +bool buffering; + /* Initialise the buffering subsystem */ bool buffering_init(char *filebuf, size_t filebuflen); diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 8107409a3..a2c052a13 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -416,6 +416,9 @@ static bool dbg_buffering_thread(void) filebuflen, 0, d.useful_data, HORIZONTAL); line++; + snprintf(buf, sizeof(buf), "buff: %s", d.buffering ? "y" : ""); + lcd_puts(0, line++, buf); + #ifndef SIMULATOR snprintf(buf, sizeof(buf), "cpu freq: %3dMHz", (int)((FREQ + 500000) / 1000000)); diff --git a/apps/playback.c b/apps/playback.c index c78b2c6c3..137a304a6 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -1509,7 +1509,7 @@ static void codec_advance_buffer_counters(size_t amount) ci.curpos += amount; /* Start buffer filling as necessary. */ - if (!pcmbuf_is_lowdata() && !filling) + if (!pcmbuf_is_lowdata() && !buffering) { if (useful_data(CUR_TI->audio_hid) < conf_watermark && playing && !playlist_end) -- 2.11.4.GIT