From 92c6cdbb57fc634fd61a618a194963486d58a283 Mon Sep 17 00:00:00 2001 From: nico Date: Sun, 8 Jul 2007 20:49:21 +0000 Subject: [PATCH] It works on target ! * Increase stack size and reduce stack usage for the playback thread to prevent panic:stkov crashes on target (test on gigabeat). The files are outputted correctly. * Make bufread() and bufgetdata() return -2 when the data for the handle isn't ready and add the check in the playback thread. git-svn-id: svn://jdgordon.mine.nu/mob@45 9862a28c-4e93-4879-ac26-10afcf840a8f --- testplugin.c | 74 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/testplugin.c b/testplugin.c index cf7bf57..1768e42 100644 --- a/testplugin.c +++ b/testplugin.c @@ -44,6 +44,13 @@ struct plugin_api* rb; #define DEBUGF rb->logf #endif +int num_files = 5; +char *files[] = { "/070623 - David Vendetta.mp3", + "/africanism all stars feat the hard boys - hard (bob sinclair remix).mp3", + "/alan_braxe__kris_menace_-_lumberjack.mp3", + "/Ame - Rej (A Hundred Birds Remix).mp3", + "/Antena - Camino del Sol (Joakim Remix).mp3" }; + struct memory_handle { int id; /* A unique ID for the handle */ //enum data_type type; @@ -455,6 +462,7 @@ int bufadvance(int handle_id, ssize_t offset) if (offset >= 0) { + /* check for access beyond what's available */ if (offset > h->available - RINGBUF_SUB(h->ridx, h->data)) return -2; @@ -462,6 +470,7 @@ int bufadvance(int handle_id, ssize_t offset) } else { + /* check for access before what's available */ if (-offset > RINGBUF_SUB(h->ridx, h->data)) return -2; @@ -479,8 +488,13 @@ int bufread(int handle_id, size_t size, char *dest) size_t buffered_data; if (!h) return -1; - if (h->available == 0) + + if (h->available == 0 && h->filerem > 0) + return -2; + + if (h->available == 0 && h->filerem == 0) return 0; + buffered_data = MIN(size, h->available); if (h->ridx + buffered_data > buffer_len) @@ -504,6 +518,12 @@ long bufgetdata(int handle_id, size_t size, unsigned char **data) if (!h) return -1; + if (h->available == 0 && h->filerem > 0) + return -2; + + if (h->available == 0 && h->filerem == 0) + return 0; + long ret; if (h->ridx + size > buffer_len && @@ -581,6 +601,7 @@ bool test_ll(void) if (cur_handle != m4 || first_handle != m1) return false; +#if 0 m2 = move_handle(RINGBUF_ADD(m2->data, 1024*100), m2); if (cur_handle != m4 || first_handle != m1 || m1->next != m2 || m2->next != m3) @@ -590,6 +611,7 @@ bool test_ll(void) if (cur_handle != m4 || first_handle != m1 || m1->next != m2) return false; +#endif rm_handle(m1); rm_handle(m2); @@ -686,6 +708,7 @@ bool buffer_init(void) return true; } +#if 0 /* returns true if the file still has some on disk unread */ bool handle_has_data(int handle) { @@ -711,6 +734,7 @@ bool need_rebuffer(void) free = buffer_len - BUF_USED; return ((free >= buffer_len/4)); } +#endif bool disk_is_spinning(void) { @@ -719,7 +743,7 @@ bool disk_is_spinning(void) -static long playback_stack[DEFAULT_STACK_SIZE/sizeof(long)]; +static long playback_stack[4*DEFAULT_STACK_SIZE/sizeof(long)]; static struct thread_entry* playbackthread_id; bool done_playing = false; @@ -729,17 +753,11 @@ static int handle_order[MAX_HANDLES]; static int last_handle = -1; #endif -#define MAX_HANDLES 64 +#define MAX_HANDLES 16 void playback_thread(void) { - int num_files = 5; - char *files[] = { "/070623 - David Vendetta.mp3", - "/africanism all stars feat the hard boys - hard (bob sinclair remix).mp3", - "/alan_braxe__kris_menace_-_lumberjack.mp3", - "/Ame - Rej (A Hundred Birds Remix).mp3", - "/Antena - Camino del Sol (Joakim Remix).mp3" }; int handles[MAX_HANDLES]; int idx = 0; int fd = -1; /* used to write the files out as they are read */ @@ -769,27 +787,37 @@ void playback_thread(void) read = bufgetdata(handles[idx], GUARD_SIZE, &data); read = MIN(read, GUARD_SIZE); rb->write(fd, data, read); - total += read; - bufadvance(handles[idx], read); - rb->sleep(HZ/20); + if (read >= 0) { + total += read; + bufadvance(handles[idx], read); + } + rb->sleep(HZ/50); } while (read > 0); - DEBUGF("read %ld bytes from handle %d\n", total, handles[idx]); - - DEBUGF("finished reading %d\n", handles[idx]); - bufclose(handles[idx]); - rb->close(fd); - fd = -1; - idx++; + if (read >= 0 && total >= 0) { + DEBUGF("read %ld bytes from handle %d\n", total, handles[idx]); + } - if (idx >= num_files) { - done_playing = true; - break; + if (read == -2) { + DEBUGF("data for handle %d isn't ready\n", handles[idx]); + } else if (read == -1) { + DEBUGF("couldn't find handle %d\n", handles[idx]); + } else if (read == 0) { + DEBUGF("finished reading handle %d\n", handles[idx]); + bufclose(handles[idx]); + rb->close(fd); + fd = -1; + idx++; + + if (idx >= num_files) { + done_playing = true; + break; + } } } } - rb->sleep(HZ/2); + rb->sleep(HZ/5); } DEBUGF("removing the playback thread\n"); -- 2.11.4.GIT