From 09bce70f17614563df09dedd82cff31298fb1a09 Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Tue, 30 Oct 2007 17:24:31 +0000 Subject: Slight rework of the buffering logic: * Don't rely only on ata_disk_is_active, and also do buffer filling after buffer handle requests. Should fix FS#8049. * Shrink the handles at the last possible moment. This allows more seeking without rebuffering for long tracks and minimises buffer waste. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15377 a1c6a512-1295-4272-9138-f99709370657 --- apps/buffering.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'apps/buffering.c') diff --git a/apps/buffering.c b/apps/buffering.c index 0325d4e4f3..65070a3556 100644 --- a/apps/buffering.c +++ b/apps/buffering.c @@ -1209,37 +1209,34 @@ void buffering_thread(void) #if MEM > 8 /* If the disk is spinning, take advantage by filling the buffer */ - if (ata_disk_is_active() && queue_empty(&buffering_queue) && - data_counters.remaining > 0 && - data_counters.buffered < high_watermark) + if ((ata_disk_is_active() || ev.id == Q_BUFFER_HANDLE) && + queue_empty(&buffering_queue)) { - fill_buffer(); - update_data_counters(); - } + if (data_counters.remaining > 0 && + data_counters.buffered < high_watermark) + { + fill_buffer(); + update_data_counters(); + } - if (ata_disk_is_active() && queue_empty(&buffering_queue) && - num_handles > 0 && data_counters.useful < high_watermark) - { - call_buffer_low_callbacks(); + if (num_handles > 0 && data_counters.useful < high_watermark) + { + call_buffer_low_callbacks(); + } } #endif if (ev.id == SYS_TIMEOUT && queue_empty(&buffering_queue)) { if (data_counters.remaining > 0 && - data_counters.wasted > data_counters.buffered/2) + data_counters.useful < conf_watermark) { /* First work forward, shrinking any unmoveable handles */ shrink_buffer(true,false); /* Then work forward following those up with moveable handles */ shrink_buffer(false,true); - update_data_counters(); - } - - if (data_counters.remaining > 0 && - data_counters.buffered < conf_watermark) - { fill_buffer(); + update_data_counters(); } } } -- cgit v1.2.3