Write to the handle's current position and not the buffer writing position.
[Rockbox-MoB.git] / testplugin.c
blobd7b6550ee01bdae55d0c884af71efe5472d21b91
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2007 Nicolas Pennequin
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
21 #include "plugin.h"
23 PLUGIN_HEADER
25 struct plugin_api* rb;
27 #define GUARD_SIZE (32*1024)
29 /* amount of data to read in one read() call */
30 #define AUDIO_DEFAULT_FILECHUNK (1024*32)
32 /* Ring buffer helper macros */
33 /* Buffer pointer (p) plus value (v), wrapped if necessary */
34 #define RINGBUF_ADD(p,v) ((p+v)<buffer_len ? p+v : p+v-buffer_len)
35 /* Buffer pointer (p) minus value (v), wrapped if necessary */
36 #define RINGBUF_SUB(p,v) ((p>=v) ? p-v : p+buffer_len-v)
37 /* How far value (v) plus buffer pointer (p1) will cross buffer pointer (p2) */
38 #define RINGBUF_ADD_CROSS(p1,v,p2) \
39 ((p1<p2) ? (int)(p1+v)-(int)p2 : (int)(p1+v-p2)-(int)buffer_len)
40 /* Bytes available in the buffer */
41 #define BUF_USED RINGBUF_SUB(buf_widx, buf_ridx)
43 #ifdef ROCKBOX_HAS_LOGF
44 #define DEBUGF rb->logf
45 #endif
47 int num_files = 5;
48 char *files[] = {
49 "/a.mp3",
50 "/b.mp3",
51 "/c.mp3",
52 "/d.mp3",
53 "/e.mp3" };
55 enum data_type {
56 TYPE_CODEC,
57 TYPE_AUDIO,
58 TYPE_ID3,
59 TYPE_CUESHEET,
60 TYPE_IMAGE,
61 TYPE_BUFFER,
62 TYPE_UNKNOWN,
65 struct memory_handle {
66 int id; /* A unique ID for the handle */
67 enum data_type type;
68 char path[MAX_PATH];
69 int fd;
70 size_t data; /* Start index of the handle's data buffer */
71 size_t ridx; /* Current read pointer, relative to the main buffer */
72 size_t widx; /* Current write pointer */
73 size_t filesize; /* File total length */
74 size_t filerem; /* Remaining bytes of file NOT in buffer */
75 size_t available; /* Available bytes to read from buffer */
76 size_t offset; /* Offset at which we started reading the file */
77 struct memory_handle *next;
81 static char *buffer;
82 static char *guard_buffer;
84 static size_t buffer_len;
85 static size_t buf_widx;
86 static size_t buf_ridx;
88 static size_t conf_filechunk;
90 /* current memory handle in the linked list. NULL when the list is empty. */
91 static struct memory_handle *cur_handle;
92 /* first memory handle in the linked list. NULL when the list is empty. */
93 static struct memory_handle *first_handle;
94 static int num_handles;
96 static void graph_view(int width);
99 /* add a new handle to the linked list and return it. It will have become the
100 new current handle. The handle will reserve "data_size" bytes or if that's
101 not possible, decrease "data_size" to allow adding the handle. */
102 static struct memory_handle *add_handle(size_t *data_size)
104 /* this will give each handle a unique id */
105 static int cur_handle_id = 1;
107 /* make sure buf_widx is 32-bit aligned so that the handle struct is,
108 but before that we check we can actually align. */
109 if (RINGBUF_ADD_CROSS(buf_widx, 3, buf_ridx) >= 0) {
110 return NULL;
112 buf_widx = (RINGBUF_ADD(buf_widx, 3)) & ~3;
114 size_t len = (data_size ? *data_size : 0)
115 + sizeof(struct memory_handle);
117 /* check that we actually can add the handle and its data */
118 int overlap = RINGBUF_ADD_CROSS(buf_widx, len, buf_ridx);
119 if (overlap >= 0) {
120 *data_size -= overlap;
121 len -= overlap;
123 if (len < sizeof(struct memory_handle)) {
124 return NULL;
127 struct memory_handle *new_handle = (struct memory_handle *)(&buffer[buf_widx]);
129 /* only advance the buffer write index of the size of the struct */
130 buf_widx = RINGBUF_ADD(buf_widx, sizeof(struct memory_handle));
132 if (!first_handle) {
133 /* the new handle is the first one */
134 first_handle = new_handle;
137 if (cur_handle) {
138 cur_handle->next = new_handle;
141 cur_handle = new_handle;
142 cur_handle->id = cur_handle_id++;
143 cur_handle->next = NULL;
144 num_handles++;
145 return cur_handle;
148 /* delete a given memory handle from the linked list
149 and return true for success. Nothing is actually erased from memory. */
150 static bool rm_handle(struct memory_handle *h)
152 if (h == first_handle) {
153 first_handle = h->next;
154 if (h == cur_handle) {
155 DEBUGF("removing the first and last handle\n");
156 /* h was the first and last handle */
157 cur_handle = NULL;
158 buf_ridx = buf_widx;
159 } else {
160 buf_ridx = (void *)first_handle - (void *)buffer;
162 } else {
163 struct memory_handle *m = first_handle;
164 while (m && m->next != h) {
165 m = m->next;
167 if (h && m && m->next == h) {
168 m->next = h->next;
169 if (h == cur_handle) {
170 cur_handle = m;
172 } else {
173 return false;
177 num_handles--;
178 return true;
181 /* these are unfortunalty needed to be global
182 so move_handle can invalidate them */
183 static int cached_handle_id = -1;
184 static struct memory_handle *cached_handle = NULL;
186 /* Return a pointer to the memory handle of given ID.
187 NULL if the handle wasn't found */
188 static struct memory_handle *find_handle(int handle_id)
190 /* simple caching because most of the time the requested handle
191 will either be the same as the last, or the one after the last */
192 if (cached_handle)
194 if (cached_handle_id == handle_id && cached_handle_id == cached_handle->id)
195 return cached_handle;
196 else if (cached_handle->next && (cached_handle->next->id == handle_id))
198 /* JD's quick testing showd this block was only entered
199 2/1971 calls to find_handle.
200 8/1971 calls to find_handle resulted in a cache miss */
201 cached_handle = cached_handle->next;
202 cached_handle_id = handle_id;
203 return cached_handle;
207 struct memory_handle *m = first_handle;
208 while (m && m->id != handle_id) {
209 m = m->next;
211 cached_handle_id = handle_id;
212 cached_handle = m;
213 return (m && m->id == handle_id) ? m : NULL;
216 /* Move a memory handle to newpos.
217 Return a pointer to the new location of the handle */
218 static struct memory_handle *move_handle(size_t *delta, struct memory_handle *h)
220 if (*delta < 4) {
221 /* aligning backwards would yield a negative result,
222 and moving the handle of such a small amount is a waste
223 of time anyway. */
224 return NULL;
226 /* make sure delta is 32-bit aligned so that the handle struct is. */
227 *delta = (*delta - 3) & ~3;
229 size_t newpos = RINGBUF_ADD((void *)h - (void *)buffer, *delta);
231 struct memory_handle *dest = (struct memory_handle *)(&buffer[newpos]);
233 /* Invalidate the cache to prevent it from keeping the old location of h */
234 if (h == cached_handle)
235 cached_handle = NULL;
237 /* the cur_handle pointer might need updating */
238 if (h == cur_handle) {
239 cur_handle = dest;
242 if (h == first_handle) {
243 first_handle = dest;
244 buf_ridx = newpos;
245 } else {
246 struct memory_handle *m = first_handle;
247 while (m && m->next != h) {
248 m = m->next;
250 if (h && m && m->next == h) {
251 m->next = dest;
252 } else {
253 return NULL;
257 rb->memmove(dest, h, sizeof(struct memory_handle));
259 return dest;
262 /* Buffer data for the given handle. Return the amount of data buffered
263 or -1 if the handle wasn't found */
264 static ssize_t buffer_handle(int handle_id)
266 DEBUGF("buffer_handle(%d)\n", handle_id);
267 struct memory_handle *h = find_handle(handle_id);
268 if (!h)
269 return -1;
271 if (h->filerem == 0) {
272 /* nothing left to buffer */
273 return 0;
276 if (h->fd < 0) /* file closed, reopen */
278 if (*h->path)
279 h->fd = rb->open(h->path, O_RDONLY);
280 else
281 return -1;
283 if (h->fd < 0)
284 return -1;
286 if (h->offset)
287 rb->lseek(h->fd, h->offset, SEEK_SET);
290 ssize_t ret = 0;
291 while (h->filerem > 0)
293 //DEBUGF("h: %d\n", (void *)h - (void *)buffer);
294 //DEBUGF("buf_widx: %ld\n", (long)buf_widx);
295 /* max amount to copy */
296 size_t copy_n = MIN(conf_filechunk, buffer_len - h->widx);
298 /* stop copying if it would overwrite the reading position */
299 if (RINGBUF_ADD_CROSS(h->widx, copy_n, buf_ridx) >= 0)
300 break;
302 /* rc is the actual amount read */
303 int rc = rb->read(h->fd, &buffer[h->widx], copy_n);
305 if (rc < 0)
307 //DEBUGF("failed on fd %d at buf_widx = %ld for handle %d\n", h->fd, (long)buf_widx, h->id);
308 DEBUGF("File ended %ld bytes early\n", (long)h->filerem);
309 h->filesize -= h->filerem;
310 h->filerem = 0;
311 break;
314 /* Advance buffer */
315 h->widx = RINGBUF_ADD(h->widx, rc);
316 if (h == cur_handle)
317 buf_widx = h->widx;
318 h->available += rc;
319 ret += rc;
320 h->filerem -= rc;
323 if (h->filerem == 0) {
324 /* finished buffering the file */
325 rb->close(h->fd);
328 DEBUGF("buffered %ld bytes (%ld of %ld available, remaining: %ld)\n",
329 ret, h->available, h->filesize, h->filerem);
331 graph_view(100);
333 return ret;
336 /* Free buffer space by moving the handle struct right before the useful
337 part of its data buffer */
338 static void free_buffer(int handle_id)
340 DEBUGF("free_buffer(%d)\n", handle_id);
341 struct memory_handle *h = find_handle(handle_id);
342 if (!h)
343 return;
345 size_t delta = RINGBUF_SUB(h->ridx, h->data);
346 h = move_handle(&delta, h);
347 if (!h) return;
348 /* The value of delta might change for alignment reasons */
349 h->data = RINGBUF_ADD(h->data, delta);
350 h->available -= delta;
352 graph_view(100);
355 static void fill_buffer(void)
357 DEBUGF("fill buffer()\n");
358 struct memory_handle *m = first_handle;
359 while (m) {
360 if (m->filerem > 0) {
361 buffer_handle(m->id);
362 return;
364 m = m->next;
368 static size_t data_rem(void)
370 size_t ret = 0;
372 struct memory_handle *m = first_handle;
373 while (m) {
374 ret += m->filerem;
375 m = m->next;
378 return ret;
381 static size_t wasted_space(void)
383 size_t ret = 0;
385 struct memory_handle *m = first_handle;
386 while (m) {
387 ret += RINGBUF_SUB(m->ridx, m->data);
388 m = m->next;
391 return ret;
394 /* Request a file be buffered
395 filename: name of the file t open
396 offset: starting offset to buffer from the file
397 RETURNS: <0 if the file cannot be opened, or one file already
398 queued to be opened, otherwise the handle for the file in the buffer
400 int bufopen(char *file, size_t offset)
402 if (cur_handle && cur_handle->filerem > 0) {
403 return -1;
406 int fd = rb->open(file, O_RDONLY);
407 if (fd < 0)
408 return -1;
410 size_t size = rb->filesize(fd) - offset;
412 DEBUGF("bufopen: %s (offset: %ld) (%ld bytes needed)...\n",
413 file, offset, size);
415 struct memory_handle *h = add_handle(&size);
416 if (!h)
418 DEBUGF("failed to add handle\n");
419 rb->close(fd);
420 return -1;
423 if (offset) rb->lseek(fd, offset, SEEK_SET);
424 rb->strncpy(h->path, file, MAX_PATH);
425 h->fd = fd;
426 h->filesize = rb->filesize(fd);
427 h->filerem = h->filesize - offset;
428 h->offset = offset;
429 h->ridx = buf_widx;
430 h->widx = buf_widx;
431 h->data = buf_widx;
432 h->available = 0;
434 DEBUGF("allocated %ld bytes. ID: %d\n", size, h->id);
435 return h->id;
438 /* Close the handle. Return 0 for success and < 0 for failure */
439 int bufclose(int handle_id)
441 DEBUGF("bufclose(%d)\n", handle_id);
442 struct memory_handle *h = find_handle(handle_id);
443 if (!h)
444 return -1;
446 rm_handle(h);
447 return 0;
450 /* Set the reading index in a handle (relatively to the start of the handle data).
451 Return 0 for success and < 0 for failure */
452 int bufseek(int handle_id, size_t offset)
454 struct memory_handle *h = find_handle(handle_id);
455 if (!h)
456 return -1;
458 if (offset > h->available)
459 return -2;
461 h->ridx = RINGBUF_ADD(h->data, offset);
462 return 0;
465 /* Advance the reading index in a handle (relatively to its current position).
466 Return 0 for success and < 0 for failure */
467 int bufadvance(int handle_id, off_t offset)
469 struct memory_handle *h = find_handle(handle_id);
470 if (!h)
471 return -1;
473 if (offset >= 0)
475 /* check for access beyond what's available */
476 if ((size_t)offset > (h->available - RINGBUF_SUB(h->ridx, h->data)))
477 return -2;
479 h->ridx = RINGBUF_ADD(h->ridx, offset);
481 else
483 /* check for access before what's available */
484 if ((size_t)(-offset) > RINGBUF_SUB(h->ridx, h->data))
485 return -2;
487 h->ridx = RINGBUF_SUB(h->ridx, (size_t)(-offset));
490 return 0;
493 /* Copy data from the given handle to the dest buffer.
494 Return the number of bytes copied or < 0 for failure. */
495 ssize_t bufread(int handle_id, size_t size, char *dest)
497 struct memory_handle *h = find_handle(handle_id);
498 size_t buffered_data;
499 if (!h)
500 return -1;
502 if (h->available == 0 && h->filerem > 0)
503 return -2;
505 if (h->available == 0 && h->filerem == 0)
506 return 0;
508 buffered_data = MIN(size, h->available);
510 if (h->ridx + buffered_data > buffer_len)
512 size_t read = buffer_len - h->ridx;
513 rb->memcpy(dest, &buffer[h->ridx], read);
514 rb->memcpy(dest+read, buffer, buffered_data - read);
516 else rb->memcpy(dest, &buffer[h->ridx], buffered_data);
518 h->ridx = RINGBUF_ADD(h->ridx, buffered_data);
519 h->available -= buffered_data;
520 return buffered_data;
523 /* Update the "data" pointer to make the handle's data available to the caller.
524 Return the length of the available linear data or < 0 for failure. */
525 ssize_t bufgetdata(int handle_id, size_t size, unsigned char **data)
527 struct memory_handle *h = find_handle(handle_id);
528 if (!h)
529 return -1;
531 if (h->available == 0 && h->filerem > 0)
532 return -2;
534 if (h->available == 0 && h->filerem == 0)
535 return 0;
537 ssize_t ret;
539 if (h->ridx + size > buffer_len &&
540 h->available - RINGBUF_SUB(h->ridx, h->data) >= size)
542 /* use the guard buffer to provide what was requested. */
543 size_t copy_n = h->ridx + size - buffer_len;
544 rb->memcpy(guard_buffer, (unsigned char *)buffer, copy_n);
545 ret = size;
546 DEBUGF("used the guard buffer to complete\n");
548 else
550 ret = MIN(h->available - RINGBUF_SUB(h->ridx, h->data),
551 buffer_len - h->ridx);
554 *data = (unsigned char *)&buffer[h->ridx];
556 //DEBUGF("bufgetdata(%d): h->ridx=%ld, ret=%ld\n", handle_id, (long)h->ridx, ret);
557 return ret;
560 bool test_ll(void)
562 struct memory_handle *m1, *m2, *m3, *m4;
564 if (cur_handle != NULL || first_handle != NULL)
565 return false;
567 m1 = add_handle(NULL);
569 if (cur_handle != m1 || first_handle != m1 || m1->next != NULL)
570 return false;
572 m2 = add_handle(NULL);
574 if (cur_handle != m2 || first_handle != m1 || m1->next != m2 || m2->next != NULL)
575 return false;
577 m3 = add_handle(NULL);
579 if (cur_handle != m3 || first_handle != m1 || m2->next != m3 || m3->next != NULL)
580 return false;
582 rm_handle(m2);
584 if (cur_handle != m3 || first_handle != m1 || m1->next != m3)
585 return false;
587 rm_handle(m3);
589 if (cur_handle != m1 || first_handle != m1 || m1->next != NULL)
590 return false;
592 m4 = add_handle(NULL);
594 if (cur_handle != m4 || first_handle != m1 || m1->next != m4 || m4->next != NULL)
595 return false;
597 rm_handle(m1);
599 if (cur_handle != m4 || first_handle != m4)
600 return false;
602 rm_handle(m4);
604 if (cur_handle != NULL || first_handle != NULL)
605 return false;
607 m1 = add_handle(NULL);
608 m2 = add_handle(NULL);
609 m3 = add_handle(NULL);
610 m4 = add_handle(NULL);
612 if (cur_handle != m4 || first_handle != m1)
613 return false;
615 #if 0
616 m2 = move_handle(1024*100, m2);
618 if (cur_handle != m4 || first_handle != m1 || m1->next != m2 || m2->next != m3)
619 return false;
621 m1 = move_handle(1024*100*3, m1);
623 if (cur_handle != m4 || first_handle != m1 || m1->next != m2)
624 return false;
625 #endif
627 rm_handle(m1);
628 rm_handle(m2);
629 rm_handle(m3);
630 rm_handle(m4);
632 if (cur_handle != NULL || first_handle != NULL)
633 return false;
635 return true;
638 /* display a nice graphical view of the ringbuffer. */
639 static void graph_view(int width)
641 #ifndef ROCKBOX_HAS_LOGF
642 int i, r_pos, w_pos;
643 r_pos = buf_ridx * width / buffer_len;
644 w_pos = buf_widx * width / buffer_len;
646 DEBUGF("|");
647 for (i=0; i <= width; i++)
649 if (i != r_pos && i != w_pos)
651 if (buf_ridx <= buf_widx)
653 if (i > r_pos && i < w_pos) {
654 DEBUGF(">");
655 } else {
656 DEBUGF("-");
659 else
661 if (i > r_pos || i < w_pos) {
662 DEBUGF(">");
663 } else {
664 DEBUGF("-");
668 else
670 if (i == r_pos && i == w_pos)
672 if (buf_ridx <= buf_widx) {
673 DEBUGF("RW");
674 } else {
675 DEBUGF("WR");
677 } else if (i == r_pos) {
678 DEBUGF("R");
679 } else if (i == w_pos) {
680 DEBUGF("W");
684 DEBUGF("|");
685 DEBUGF("\n");
686 #else
687 (void)width;
688 #endif
691 void print_progress(size_t amount, int file, int numfiles)
693 char buf[32];
694 rb->lcd_clear_display();
695 rb->snprintf(buf, sizeof(buf), "file %d of %d", file, numfiles);
696 rb->lcd_puts(0, 0, buf);
697 rb->snprintf(buf, sizeof(buf), "read: %ld", amount);
698 rb->lcd_puts(0, 1, buf);
699 rb->lcd_update();
702 bool buffer_init(void)
704 buffer = rb->plugin_get_audio_buffer(&buffer_len);
705 if (!buffer)
707 DEBUGF("couldn't allocate buffer\n");
708 return false;
710 buffer_len -= GUARD_SIZE;
711 guard_buffer = buffer + buffer_len;
713 buf_widx = 0;
714 buf_ridx = 0;
716 first_handle = NULL;
717 num_handles = 0;
719 conf_filechunk = AUDIO_DEFAULT_FILECHUNK;
721 return true;
724 bool disk_is_spinning(void)
726 return true;
731 static long codec_stack[4*DEFAULT_STACK_SIZE/sizeof(long)];
732 static struct thread_entry* codecthread_id;
734 static long bufopen_stack[DEFAULT_STACK_SIZE/sizeof(long)];
735 static struct thread_entry* bufopenthread_id;
737 bool done_playing = false;
739 #define MAX_HANDLES 16
741 int handles[MAX_HANDLES];
743 void codec_thread(void)
745 int idx = 0;
746 int fd = -1; /* used to write the files out as they are read */
747 unsigned char *data;
748 char outfile[MAX_PATH];
749 long read, total = 0;
751 while (1)
753 if (!done_playing)
755 if (handles[idx] > 0) {
757 if (fd < 0) {
758 rb->snprintf(outfile, MAX_PATH, "/file%d.mp3", idx);
759 fd = rb->open(outfile, O_CREAT|O_TRUNC|O_WRONLY);
760 if (fd < 0) {
761 DEBUGF("couldn't create file\n");
762 rb->splash(HZ, "couldn't create file");
766 do {
767 read = bufgetdata(handles[idx], GUARD_SIZE, &data);
768 if (read >= 0) {
769 read = MIN(read, GUARD_SIZE);
770 rb->write(fd, data, read);
771 total += read;
772 bufadvance(handles[idx], read);
773 print_progress(total, idx+1, num_files);
775 rb->sleep(HZ/20);
776 } while (read > 0);
778 if (read >= 0 && total >= 0) {
779 DEBUGF("read %ld bytes from handle %d\n", total, handles[idx]);
782 if (read == -2) {
783 DEBUGF("data for handle %d isn't ready\n", handles[idx]);
784 } else if (read == -1) {
785 DEBUGF("couldn't find handle %d\n", handles[idx]);
786 } else if (read == 0) {
787 DEBUGF("finished reading handle %d\n", handles[idx]);
788 bufclose(handles[idx]);
789 rb->close(fd);
790 fd = -1;
791 total = 0;
792 idx++;
794 if (idx >= num_files) {
795 done_playing = true;
796 break;
802 rb->sleep(HZ/4);
805 DEBUGF("removing the codec thread\n");
806 rb->remove_thread(NULL);
809 void bufopen_thread(void)
811 int idx = 0, ret;
812 while (idx < num_files)
814 ret = bufopen(files[idx], 0);
815 if (ret > 0) {
816 handles[idx++] = ret;
818 rb->sleep(HZ*8);
821 DEBUGF("bufopen thread finished\n");
822 rb->remove_thread(NULL);
826 /* this is the plugin entry point */
827 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
829 (void)parameter;
830 rb = api;
832 buffer_init();
834 if (!test_ll())
836 DEBUGF("linked list test failed\n");
837 rb->splash(HZ, "linked list test failed");
838 return PLUGIN_ERROR;
841 codecthread_id = rb->create_thread(codec_thread,
842 codec_stack,
843 sizeof(codec_stack),
844 "codec"
845 IF_PRIO(,PRIORITY_PLAYBACK)
846 IF_COP(, CPU, false));
848 bufopenthread_id = rb->create_thread(bufopen_thread,
849 bufopen_stack,
850 sizeof(bufopen_stack),
851 "bufopen"
852 IF_PRIO(,PRIORITY_BACKGROUND)
853 IF_COP(, CPU, false));
855 if (!codecthread_id)
857 rb->splash(HZ, "failed to create codec thread");
858 return PLUGIN_ERROR;
860 else if (!bufopenthread_id)
862 rb->splash(HZ, "failed to create bufopen thread");
863 return PLUGIN_ERROR;
865 else
868 while (!done_playing)
870 if (wasted_space() > buffer_len/4) {
871 DEBUGF("there is %ld bytes of wasted space\n", wasted_space());
872 struct memory_handle *m = first_handle;
873 while (m) {
874 free_buffer(m->id);
875 m = m->next;
879 if (data_rem() > 0 && BUF_USED < buffer_len/4 && disk_is_spinning()) {
880 DEBUGF("%ld bytes left to buffer and the buffer is running low\n", data_rem());
881 fill_buffer();
882 } else {
883 rb->sleep(HZ/2);
886 DEBUGF("done playing\n");
887 rb->yield();
890 rb->backlight_on();
891 DEBUGF("end of plugin\n");
892 return PLUGIN_OK;