summaryrefslogtreecommitdiff
path: root/apps/buffering.c
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2008-04-03 17:51:53 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2008-04-03 17:51:53 +0000
commit33f522de8b36985401c1a17831b5ef8501039953 (patch)
treefe87d8b5e095f73fff04bbca133afe31d8787734 /apps/buffering.c
parent81efd6c36d7f424b1c8e6e36f799fe1a047d8f38 (diff)
downloadrockbox-33f522de8b36985401c1a17831b5ef8501039953.tar.gz
rockbox-33f522de8b36985401c1a17831b5ef8501039953.zip
Migrate the buffering code to the new events system.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16950 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/buffering.c')
-rw-r--r--apps/buffering.c65
1 files changed, 6 insertions, 59 deletions
diff --git a/apps/buffering.c b/apps/buffering.c
index 6d4192443c..99a4a3b058 100644
--- a/apps/buffering.c
+++ b/apps/buffering.c
@@ -49,6 +49,7 @@
49#include "pcmbuf.h" 49#include "pcmbuf.h"
50#include "buffer.h" 50#include "buffer.h"
51#include "bmp.h" 51#include "bmp.h"
52#include "events.h"
52 53
53#ifdef SIMULATOR 54#ifdef SIMULATOR
54#define ata_disk_is_active() 1 55#define ata_disk_is_active() 1
@@ -153,9 +154,6 @@ static struct mutex llist_mutex;
153 This is global so that move_handle and rm_handle can invalidate it. */ 154 This is global so that move_handle and rm_handle can invalidate it. */
154static struct memory_handle *cached_handle = NULL; 155static struct memory_handle *cached_handle = NULL;
155 156
156static buffering_callback buffering_callback_funcs[MAX_BUF_CALLBACKS];
157static int buffer_callback_count = 0;
158
159static struct { 157static struct {
160 size_t remaining; /* Amount of data needing to be buffered */ 158 size_t remaining; /* Amount of data needing to be buffered */
161 size_t wasted; /* Amount of space available for freeing */ 159 size_t wasted; /* Amount of space available for freeing */
@@ -190,8 +188,6 @@ static struct event_queue buffering_queue;
190static struct queue_sender_list buffering_queue_sender_list; 188static struct queue_sender_list buffering_queue_sender_list;
191 189
192 190
193static void call_buffering_callbacks(enum callback_event ev, int value);
194
195 191
196/* 192/*
197LINKED LIST MANAGEMENT 193LINKED LIST MANAGEMENT
@@ -659,7 +655,7 @@ static bool buffer_handle(int handle_id)
659 /* finished buffering the file */ 655 /* finished buffering the file */
660 close(h->fd); 656 close(h->fd);
661 h->fd = -1; 657 h->fd = -1;
662 call_buffering_callbacks(EVENT_HANDLE_FINISHED, h->id); 658 send_event(EVENT_HANDLE_FINISHED, &h->id);
663 } 659 }
664 660
665 return true; 661 return true;
@@ -715,7 +711,7 @@ static void rebuffer_handle(int handle_id, size_t newpos)
715 /* There isn't enough space to rebuffer all of the track from its new 711 /* There isn't enough space to rebuffer all of the track from its new
716 offset, so we ask the user to free some */ 712 offset, so we ask the user to free some */
717 DEBUGF("rebuffer_handle: space is needed\n"); 713 DEBUGF("rebuffer_handle: space is needed\n");
718 call_buffering_callbacks(EVENT_HANDLE_REBUFFER, handle_id); 714 send_event(EVENT_HANDLE_REBUFFER, &handle_id);
719 } 715 }
720 716
721 /* Now we ask for a rebuffer */ 717 /* Now we ask for a rebuffer */
@@ -1269,52 +1265,6 @@ void buf_set_watermark(size_t bytes)
1269 queue_post(&buffering_queue, Q_SET_WATERMARK, bytes); 1265 queue_post(&buffering_queue, Q_SET_WATERMARK, bytes);
1270} 1266}
1271 1267
1272bool register_buffering_callback(buffering_callback func)
1273{
1274 int i;
1275 if (buffer_callback_count >= MAX_BUF_CALLBACKS)
1276 return false;
1277 for (i = 0; i < MAX_BUF_CALLBACKS; i++)
1278 {
1279 if (buffering_callback_funcs[i] == NULL)
1280 {
1281 buffering_callback_funcs[i] = func;
1282 buffer_callback_count++;
1283 return true;
1284 }
1285 else if (buffering_callback_funcs[i] == func)
1286 return true;
1287 }
1288 return false;
1289}
1290
1291void unregister_buffering_callback(buffering_callback func)
1292{
1293 int i;
1294 for (i = 0; i < MAX_BUF_CALLBACKS; i++)
1295 {
1296 if (buffering_callback_funcs[i] == func)
1297 {
1298 buffering_callback_funcs[i] = NULL;
1299 buffer_callback_count--;
1300 }
1301 }
1302 return;
1303}
1304
1305static void call_buffering_callbacks(enum callback_event ev, int value)
1306{
1307 logf("call_buffering_callbacks()");
1308 int i;
1309 for (i = 0; i < MAX_BUF_CALLBACKS; i++)
1310 {
1311 if (buffering_callback_funcs[i])
1312 {
1313 buffering_callback_funcs[i](ev, value);
1314 }
1315 }
1316}
1317
1318static void shrink_buffer_inner(struct memory_handle *h) 1268static void shrink_buffer_inner(struct memory_handle *h)
1319{ 1269{
1320 if (h == NULL) 1270 if (h == NULL)
@@ -1350,7 +1300,7 @@ void buffering_thread(void)
1350 LOGFQUEUE("buffering < Q_START_FILL"); 1300 LOGFQUEUE("buffering < Q_START_FILL");
1351 /* Call buffer callbacks here because this is one of two ways 1301 /* Call buffer callbacks here because this is one of two ways
1352 * to begin a full buffer fill */ 1302 * to begin a full buffer fill */
1353 call_buffering_callbacks(EVENT_BUFFER_LOW, 0); 1303 send_event(EVENT_BUFFER_LOW, 0);
1354 shrink_buffer(); 1304 shrink_buffer();
1355 queue_reply(&buffering_queue, 1); 1305 queue_reply(&buffering_queue, 1);
1356 filling |= buffer_handle((int)ev.data); 1306 filling |= buffer_handle((int)ev.data);
@@ -1412,7 +1362,7 @@ void buffering_thread(void)
1412 1362
1413 /* If the buffer is low, call the callbacks to get new data */ 1363 /* If the buffer is low, call the callbacks to get new data */
1414 if (num_handles > 0 && data_counters.useful <= conf_watermark) 1364 if (num_handles > 0 && data_counters.useful <= conf_watermark)
1415 call_buffering_callbacks(EVENT_BUFFER_LOW, 0); 1365 send_event(EVENT_BUFFER_LOW, 0);
1416 1366
1417#if 0 1367#if 0
1418 /* TODO: This needs to be fixed to use the idle callback, disable it 1368 /* TODO: This needs to be fixed to use the idle callback, disable it
@@ -1422,7 +1372,7 @@ void buffering_thread(void)
1422 else if (ata_disk_is_active() && queue_empty(&buffering_queue)) 1372 else if (ata_disk_is_active() && queue_empty(&buffering_queue))
1423 { 1373 {
1424 if (num_handles > 0 && data_counters.useful <= high_watermark) 1374 if (num_handles > 0 && data_counters.useful <= high_watermark)
1425 call_buffering_callbacks(EVENT_BUFFER_LOW, 0); 1375 send_event(EVENT_BUFFER_LOW, 0);
1426 1376
1427 if (data_counters.remaining > 0 && BUF_USED <= high_watermark) 1377 if (data_counters.remaining > 0 && BUF_USED <= high_watermark)
1428 { 1378 {
@@ -1492,9 +1442,6 @@ bool buffering_reset(char *buf, size_t buflen)
1492 num_handles = 0; 1442 num_handles = 0;
1493 base_handle_id = -1; 1443 base_handle_id = -1;
1494 1444
1495 buffer_callback_count = 0;
1496 memset(buffering_callback_funcs, 0, sizeof(buffering_callback_funcs));
1497
1498 /* Set the high watermark as 75% full...or 25% empty :) */ 1445 /* Set the high watermark as 75% full...or 25% empty :) */
1499#if MEM > 8 1446#if MEM > 8
1500 high_watermark = 3*buflen / 4; 1447 high_watermark = 3*buflen / 4;