1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
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 /* Internal ring buffer helper macros */
44 /* Buffer pointer (p) plus value (v), wrapped if necessary */
45 #define INT_RINGBUF_ADD(h,p,v) ((p+v) < h->data_len ? p+v : p+v - h->data_len)
46 /* Buffer pointer (p) minus value (v), wrapped if necessary */
47 #define INT_RINGBUF_SUB(h,p,v) ((p>=v) ? p-v : p + h->data_len - v)
48 /* How far value (v) plus buffer pointer (p1) will cross buffer pointer (p2) */
49 #define INT_RINGBUF_ADD_CROSS(h,p1,v,p2) \
50 ((p1<p2) ? (int)(p1+v)-(int)p2 : (int)(p1+v-p2)-(int)h->data_len)
51 /* Bytes available in the buffer */
52 #define INT_BUF_USED(h) (INT_RINGBUF_SUB(h, h->widx, h->ridx))
54 #ifdef ROCKBOX_HAS_LOGF
55 #define DEBUGF rb->logf
76 struct memory_handle
{
77 int id
; /* A unique ID for the handle */
81 size_t data
; /* Start index of the handle's data buffer */
82 size_t data_len
; /* Length of the data buffer for the handle */
83 size_t ridx
; /* Current read pointer, relative to the data buffer */
84 size_t widx
; /* Current write pointer */
85 size_t filesize
; /* File total length */
86 size_t filerem
; /* Remaining bytes of file NOT in buffer */
87 size_t available
; /* Available bytes to read from buffer */
88 size_t offset
; /* Offset at which we started reading the file */
89 struct memory_handle
*next
;
94 static char *guard_buffer
;
96 static size_t buffer_len
;
97 static size_t buf_widx
;
98 static size_t buf_ridx
;
100 static size_t conf_filechunk
;
102 /* current memory handle in the linked list. NULL when the list is empty. */
103 static struct memory_handle
*cur_handle
;
104 /* first memory handle in the linked list. NULL when the list is empty. */
105 static struct memory_handle
*first_handle
;
106 static int num_handles
;
108 static void graph_view(int width
);
111 /* add a new handle to the linked list and return it. It will have become the
112 new current handle. The handle will reserve "data_size" bytes or if that's
113 not possible, decrease "data_size" to allow adding the handle. */
114 static struct memory_handle
*add_handle(size_t *data_size
)
116 /* this will give each handle a unique id */
117 static int cur_handle_id
= 1;
119 /* make sure buf_widx is 32-bit aligned so that the handle struct is,
120 but before that we check we can actually align. */
121 if (RINGBUF_ADD_CROSS(buf_widx
, 3, buf_ridx
) >= 0) {
122 DEBUGF("no space to even align\n");
125 buf_widx
= (RINGBUF_ADD(buf_widx
, 3)) & ~3;
127 size_t len
= (data_size
? *data_size
: 0)
128 + sizeof(struct memory_handle
);
130 /* check that we actually can add the handle and its data */
131 int overlap
= RINGBUF_ADD_CROSS(buf_widx
, len
, buf_ridx
);
133 *data_size
-= overlap
+ 1;
136 if (len
< sizeof(struct memory_handle
)) {
137 DEBUGF("no space to add the handle\n");
141 struct memory_handle
*new_handle
= (struct memory_handle
*)(&buffer
[buf_widx
]);
143 /* only advance the buffer write index of the size of the struct */
144 buf_widx
= RINGBUF_ADD(buf_widx
, sizeof(struct memory_handle
));
147 /* the new handle is the first one */
148 first_handle
= new_handle
;
152 cur_handle
->next
= new_handle
;
155 cur_handle
= new_handle
;
156 cur_handle
->id
= cur_handle_id
++;
157 cur_handle
->next
= NULL
;
162 /* delete a given memory handle from the linked list
163 and return true for success. Nothing is actually erased from memory. */
164 static bool rm_handle(struct memory_handle
*h
)
166 if (h
== first_handle
) {
167 first_handle
= h
->next
;
168 if (h
== cur_handle
) {
169 DEBUGF("removing the first and last handle\n");
170 /* h was the first and last handle */
174 buf_ridx
= (void *)first_handle
- (void *)buffer
;
177 struct memory_handle
*m
= first_handle
;
178 while (m
&& m
->next
!= h
) {
181 if (h
&& m
&& m
->next
== h
) {
183 if (h
== cur_handle
) {
195 /* these are unfortunalty needed to be global
196 so move_handle can invalidate them */
197 static int cached_handle_id
= -1;
198 static struct memory_handle
*cached_handle
= NULL
;
200 /* Return a pointer to the memory handle of given ID.
201 NULL if the handle wasn't found */
202 static struct memory_handle
*find_handle(int handle_id
)
204 /* simple caching because most of the time the requested handle
205 will either be the same as the last, or the one after the last */
208 if (cached_handle_id
== handle_id
&& cached_handle_id
== cached_handle
->id
)
209 return cached_handle
;
210 else if (cached_handle
->next
&& (cached_handle
->next
->id
== handle_id
))
212 /* JD's quick testing showd this block was only entered
213 2/1971 calls to find_handle.
214 8/1971 calls to find_handle resulted in a cache miss */
215 cached_handle
= cached_handle
->next
;
216 cached_handle_id
= handle_id
;
217 return cached_handle
;
221 struct memory_handle
*m
= first_handle
;
222 while (m
&& m
->id
!= handle_id
) {
225 cached_handle_id
= handle_id
;
227 return (m
&& m
->id
== handle_id
) ? m
: NULL
;
230 /* Move a memory handle to newpos.
231 Return a pointer to the new location of the handle */
232 static struct memory_handle
*move_handle(size_t *delta
, struct memory_handle
*h
)
235 /* aligning backwards would yield a negative result,
236 and moving the handle of such a small amount is a waste
240 /* make sure delta is 32-bit aligned so that the handle struct is. */
241 *delta
= (*delta
- 3) & ~3;
243 size_t newpos
= RINGBUF_ADD((void *)h
- (void *)buffer
, *delta
);
245 struct memory_handle
*dest
= (struct memory_handle
*)(&buffer
[newpos
]);
247 /* Invalidate the cache to prevent it from keeping the old location of h */
248 if (h
== cached_handle
)
249 cached_handle
= NULL
;
251 /* the cur_handle pointer might need updating */
252 if (h
== cur_handle
) {
256 if (h
== first_handle
) {
260 struct memory_handle
*m
= first_handle
;
261 while (m
&& m
->next
!= h
) {
264 if (h
&& m
&& m
->next
== h
) {
271 rb
->memmove(dest
, h
, sizeof(struct memory_handle
));
275 /* Buffer data for the given handle. Return the amount of data buffered
276 or -1 if the handle wasn't found */
277 static ssize_t
buffer_handle(int handle_id
)
279 DEBUGF("buffer_handle(%d)\n", handle_id
);
280 struct memory_handle
*h
= find_handle(handle_id
);
284 if (h
->filerem
== 0) {
285 /* nothing left to buffer */
289 if (h
->fd
< 0) /* file closed, reopen */
292 h
->fd
= rb
->open(h
->path
, O_RDONLY
);
300 rb
->lseek(h
->fd
, h
->offset
, SEEK_SET
);
304 while (h
->filerem
> 0)
306 /* max amount to copy */
307 size_t copy_n
= MIN(MIN(conf_filechunk
, h
->filerem
),
308 MIN(h
->data_len
- h
->widx
,
309 buffer_len
- RINGBUF_ADD(h
->data
, h
->widx
))
313 DEBUGF("widx: %ld, ridx: %ld copy_n: %ld, writepos: %ld,"
314 "readpos: %ld, add_cross: %d, int_add_cross: %d\n",
315 h
->widx
, h
->ridx
, copy_n
, RINGBUF_ADD(h
->data
, h
->widx
),
316 RINGBUF_ADD(h
->data
, h
->ridx
),
317 RINGBUF_ADD_CROSS( RINGBUF_ADD(h
->data
, h
->widx
),
319 RINGBUF_ADD(h
->data
, h
->ridx
)
321 INT_RINGBUF_ADD_CROSS(h
, h
->widx
, copy_n
, h
->ridx
)
325 /* stop copying if it would overwrite the reading position.
326 buf_widx == buf_ridx is defined as buffer empty, not buffer full.
327 same goes with h->widx == h->ridx. */
328 if (RINGBUF_ADD_CROSS( RINGBUF_ADD(h
->data
, h
->widx
),
330 RINGBUF_ADD(h
->data
, h
->ridx
)
332 INT_RINGBUF_ADD_CROSS(h
, h
->widx
, copy_n
, h
->ridx
) >= 0 )
335 /* rc is the actual amount read */
336 int rc
= rb
->read(h
->fd
, &buffer
[RINGBUF_ADD(h
->data
, h
->widx
)], copy_n
);
340 DEBUGF("File ended %ld bytes early\n", (long)h
->filerem
);
341 h
->filesize
-= h
->filerem
;
347 h
->widx
= INT_RINGBUF_ADD(h
, h
->widx
, rc
);
353 if (h
->filerem
== 0) {
354 /* finished buffering the file */
359 buf_widx
= RINGBUF_ADD(h
->data
, h
->data_len
);
361 DEBUGF("buffered %ld bytes (%ld of %ld available, remaining: %ld)\n",
362 ret
, h
->available
, h
->filesize
, h
->filerem
);
369 /* Free buffer space by moving the handle struct right before the useful
370 part of its data buffer */
371 static void free_buffer(int handle_id
)
373 DEBUGF("free_buffer(%d)\n", handle_id
);
374 struct memory_handle
*h
= find_handle(handle_id
);
378 DEBUGF("old state: data: %ld, data_len: %ld, avail: %ld, ridx: %ld, widx: %ld\n",
379 h
->data
, h
->data_len
, h
->available
, h
->ridx
, h
->widx
);
381 if (h
->widx
!= 0 && h
->ridx
> h
->widx
) {
382 /* We don't want to overwrite a useful part of the buffer */
386 size_t delta
= h
->ridx
;
387 h
= move_handle(&delta
, h
);
389 /* The value of delta might change for alignment reasons */
390 h
->data
= RINGBUF_ADD(h
->data
, delta
);
391 h
->data_len
-= delta
;
393 if (h
->widx
>= delta
) h
->widx
-= delta
;
394 h
->available
-= delta
;
396 DEBUGF("new state: data: %ld, data_len: %ld, avail: %ld, ridx: %ld, widx: %ld\n",
397 h
->data
, h
->data_len
, h
->available
, h
->ridx
, h
->widx
);
402 static void fill_buffer(void)
404 DEBUGF("fill buffer()\n");
405 struct memory_handle
*m
= first_handle
;
407 if (m
->filerem
> 0) {
408 buffer_handle(m
->id
);
415 static size_t data_rem(void)
419 struct memory_handle
*m
= first_handle
;
428 static size_t wasted_space(void)
432 struct memory_handle
*m
= first_handle
;
434 ret
+= (m
->ridx
<= m
->widx
) ? m
->ridx
: 0;
441 static size_t used_space(void)
445 struct memory_handle
*m
= first_handle
;
447 ret
+= INT_BUF_USED(m
);
454 /* Request a file be buffered
455 filename: name of the file t open
456 offset: starting offset to buffer from the file
457 RETURNS: <0 if the file cannot be opened, or one file already
458 queued to be opened, otherwise the handle for the file in the buffer
460 int bufopen(char *file
, size_t offset
)
462 DEBUGF("bufopen: %s (offset: %ld)\n", file
, offset
);
464 int fd
= rb
->open(file
, O_RDONLY
);
468 size_t size
= rb
->filesize(fd
) - offset
+ 1;
469 DEBUGF("we want to allocate %ld bytes\n", size
);
470 struct memory_handle
*h
= add_handle(&size
);
473 DEBUGF("failed to add handle\n");
477 DEBUGF("allocated %ld bytes\n", size
);
479 if (offset
) rb
->lseek(fd
, offset
, SEEK_SET
);
480 rb
->strncpy(h
->path
, file
, MAX_PATH
);
482 h
->filesize
= rb
->filesize(fd
);
483 h
->filerem
= h
->filesize
- offset
;
491 buf_widx
= RINGBUF_ADD(buf_widx
, size
);
493 DEBUGF("added handle : %d\n", h
->id
);
497 /* Close the handle. Return 0 for success and < 0 for failure */
498 int bufclose(int handle_id
)
500 DEBUGF("bufclose(%d)\n", handle_id
);
501 struct memory_handle
*h
= find_handle(handle_id
);
509 /* Set the reading index in a handle (relatively to the start of the handle data).
510 Return 0 for success and < 0 for failure */
511 int bufseek(int handle_id
, size_t offset
)
513 struct memory_handle
*h
= find_handle(handle_id
);
517 if (offset
> h
->available
|| offset
> h
->data_len
)
524 /* Advance the reading index in a handle (relatively to its current position).
525 Return 0 for success and < 0 for failure */
526 int bufadvance(int handle_id
, off_t offset
)
528 struct memory_handle
*h
= find_handle(handle_id
);
532 /* DEBUGF("bufadvance(%ld): h->ridx: %ld, h->widx: %ld\n",
533 offset, h->ridx, h->widx); */
537 /* check for access beyond what's available */
538 if ((size_t)offset
> (h
->available
- h
->ridx
))
541 h
->ridx
= INT_RINGBUF_ADD(h
, h
->ridx
, offset
);
545 /* check for access before what's available */
546 if ((size_t)(-offset
) > h
->ridx
)
549 h
->ridx
= INT_RINGBUF_SUB(h
, h
->ridx
, (size_t)(-offset
));
555 /* Copy data from the given handle to the dest buffer.
556 Return the number of bytes copied or < 0 for failure. */
557 ssize_t
bufread(int handle_id
, size_t size
, char *dest
)
559 struct memory_handle
*h
= find_handle(handle_id
);
560 size_t buffered_data
;
564 if (h
->available
== 0 && h
->filerem
> 0)
567 if (h
->available
== 0 && h
->filerem
== 0)
570 buffered_data
= MIN(size
, h
->available
);
572 if (h
->data
+ h
->ridx
+ buffered_data
> buffer_len
)
574 size_t read
= buffer_len
- (h
->data
+ h
->ridx
);
575 rb
->memcpy(dest
, &buffer
[h
->data
+ h
->ridx
], read
);
576 rb
->memcpy(dest
+read
, buffer
, buffered_data
- read
);
578 else rb
->memcpy(dest
, &buffer
[h
->data
+ h
->ridx
], buffered_data
);
580 h
->ridx
+= buffered_data
;
581 h
->available
-= buffered_data
;
582 return buffered_data
;
585 /* Update the "data" pointer to make the handle's data available to the caller.
586 Return the length of the available linear data or < 0 for failure. */
587 ssize_t
bufgetdata(int handle_id
, size_t size
, unsigned char **data
)
589 struct memory_handle
*h
= find_handle(handle_id
);
593 if (h
->available
== 0 && h
->filerem
> 0)
596 if (h
->available
== 0 && h
->filerem
== 0)
601 *data
= (unsigned char *)&buffer
[RINGBUF_ADD(h
->data
, h
->ridx
)];
603 if (buffer_len
- (h
->data
+ h
->ridx
) > 0 &&
604 buffer_len
- (h
->data
+ h
->ridx
) < size
&&
605 h
->available
- h
->ridx
>= size
)
607 /* use the guard buffer to provide what was requested. */
608 size_t copy_n
= h
->data
+ h
->ridx
+ size
- buffer_len
;
610 if (h
->ridx
+ size
> h
->data_len
) {
611 size_t copy_1
= h
->data_len
- (h
->ridx
+ size
- copy_n
);
612 size_t copy_2
= copy_n
- copy_1
;
613 rb
->memcpy(guard_buffer
,
614 (unsigned char *)buffer
, copy_1
);
615 rb
->memcpy(guard_buffer
+ copy_1
,
616 (unsigned char *)&buffer
[h
->data
], copy_2
);
618 rb
->memcpy(guard_buffer
, (unsigned char *)buffer
, copy_n
);
622 DEBUGF("used the guard buffer to complete\n");
624 else if (h
->ridx
+ size
> h
->data_len
&&
625 h
->available
- h
->ridx
>= size
&&
628 size_t copy_1
= h
->data_len
- h
->ridx
;
629 size_t copy_2
= size
- copy_1
;
630 rb
->memcpy(guard_buffer
,
631 (unsigned char *)&buffer
[RINGBUF_ADD(h
->data
, h
->ridx
)],
633 rb
->memcpy(guard_buffer
+ copy_1
,
634 (unsigned char *)&buffer
[h
->data
], copy_2
);
635 *data
= guard_buffer
;
637 DEBUGF("used the guard buffer for a whole piece\n");
641 ret
= MIN(MIN(h
->available
- h
->ridx
,
643 buffer_len
- (h
->data
+ h
->ridx
));
646 //DEBUGF("bufgetdata(%d): h->ridx=%ld, ret=%ld\n", handle_id, (long)h->ridx, ret);
652 struct memory_handle
*m1
, *m2
, *m3
, *m4
;
654 if (cur_handle
!= NULL
|| first_handle
!= NULL
)
657 m1
= add_handle(NULL
);
659 if (cur_handle
!= m1
|| first_handle
!= m1
|| m1
->next
!= NULL
)
662 m2
= add_handle(NULL
);
664 if (cur_handle
!= m2
|| first_handle
!= m1
|| m1
->next
!= m2
|| m2
->next
!= NULL
)
667 m3
= add_handle(NULL
);
669 if (cur_handle
!= m3
|| first_handle
!= m1
|| m2
->next
!= m3
|| m3
->next
!= NULL
)
674 if (cur_handle
!= m3
|| first_handle
!= m1
|| m1
->next
!= m3
)
679 if (cur_handle
!= m1
|| first_handle
!= m1
|| m1
->next
!= NULL
)
682 m4
= add_handle(NULL
);
684 if (cur_handle
!= m4
|| first_handle
!= m1
|| m1
->next
!= m4
|| m4
->next
!= NULL
)
689 if (cur_handle
!= m4
|| first_handle
!= m4
)
694 if (cur_handle
!= NULL
|| first_handle
!= NULL
)
697 m1
= add_handle(NULL
);
698 m2
= add_handle(NULL
);
699 m3
= add_handle(NULL
);
700 m4
= add_handle(NULL
);
702 if (cur_handle
!= m4
|| first_handle
!= m1
)
705 size_t delta
= 1024*100;
706 m2
= move_handle(&delta
, m2
);
708 if (cur_handle
!= m4
|| first_handle
!= m1
|| m1
->next
!= m2
|| m2
->next
!= m3
)
712 m1
= move_handle(&delta
, m1
);
714 if (cur_handle
!= m4
|| first_handle
!= m1
|| m1
->next
!= m2
)
722 if (cur_handle
!= NULL
|| first_handle
!= NULL
)
728 /* display a nice graphical view of the ringbuffer. */
729 static void graph_view(int width
)
731 #ifndef ROCKBOX_HAS_LOGF
733 r_pos
= buf_ridx
* width
/ buffer_len
;
734 w_pos
= buf_widx
* width
/ buffer_len
;
737 for (i
=0; i
<= width
; i
++)
739 if (i
!= r_pos
&& i
!= w_pos
)
741 if (buf_ridx
<= buf_widx
)
743 if (i
> r_pos
&& i
< w_pos
) {
751 if (i
> r_pos
|| i
< w_pos
) {
760 if (i
== r_pos
&& i
== w_pos
)
762 if (buf_ridx
<= buf_widx
) {
767 } else if (i
== r_pos
) {
769 } else if (i
== w_pos
) {
781 void print_progress(size_t amount
, int file
, int numfiles
)
784 rb
->lcd_clear_display();
785 rb
->snprintf(buf
, sizeof(buf
), "file %d of %d", file
, numfiles
);
786 rb
->lcd_puts(0, 0, buf
);
787 rb
->snprintf(buf
, sizeof(buf
), "read: %ld", amount
);
788 rb
->lcd_puts(0, 1, buf
);
792 bool buffer_init(void)
794 buffer
= rb
->plugin_get_audio_buffer(&buffer_len
);
797 DEBUGF("couldn't allocate buffer\n");
800 buffer_len
-= GUARD_SIZE
;
801 guard_buffer
= buffer
+ buffer_len
;
809 conf_filechunk
= AUDIO_DEFAULT_FILECHUNK
;
814 bool disk_is_spinning(void)
820 static long codec_stack
[4*DEFAULT_STACK_SIZE
/sizeof(long)];
821 static struct thread_entry
* codecthread_id
;
823 static long bufopen_stack
[DEFAULT_STACK_SIZE
/sizeof(long)];
824 static struct thread_entry
* bufopenthread_id
;
826 bool done_playing
= false;
828 #define MAX_HANDLES 16
830 int handles
[MAX_HANDLES
];
832 void codec_thread(void)
835 int fd
= -1; /* used to write the files out as they are read */
837 char outfile
[MAX_PATH
];
838 long read
, total
= 0;
844 if (handles
[idx
] > 0) {
847 rb
->snprintf(outfile
, MAX_PATH
, "/file%d.mp3", idx
);
848 fd
= rb
->open(outfile
, O_CREAT
|O_TRUNC
|O_WRONLY
);
850 DEBUGF("couldn't create file\n");
851 rb
->splash(HZ
, "couldn't create file");
856 read
= bufgetdata(handles
[idx
], GUARD_SIZE
, &data
);
858 read
= MIN(read
, GUARD_SIZE
);
859 rb
->write(fd
, data
, read
);
861 bufadvance(handles
[idx
], read
);
862 print_progress(total
, idx
+1, num_files
);
867 if (read
>= 0 && total
>= 0) {
868 DEBUGF("read %ld bytes from handle %d\n", total
, handles
[idx
]);
872 DEBUGF("data for handle %d isn't ready\n", handles
[idx
]);
873 } else if (read
== -1) {
874 DEBUGF("couldn't find handle %d\n", handles
[idx
]);
875 } else if (read
== 0) {
876 DEBUGF("finished reading handle %d\n", handles
[idx
]);
877 bufclose(handles
[idx
]);
883 if (idx
>= num_files
) {
894 DEBUGF("removing the codec thread\n");
895 rb
->remove_thread(NULL
);
898 void bufopen_thread(void)
901 while (idx
< num_files
)
903 ret
= bufopen(files
[idx
], 0);
905 handles
[idx
++] = ret
;
910 DEBUGF("bufopen thread finished\n");
911 rb
->remove_thread(NULL
);
915 /* this is the plugin entry point */
916 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
925 DEBUGF("linked list test failed\n");
926 rb
->splash(HZ
, "linked list test failed");
930 codecthread_id
= rb
->create_thread(codec_thread
,
934 IF_PRIO(,PRIORITY_PLAYBACK
)
935 IF_COP(, CPU
, false));
937 bufopenthread_id
= rb
->create_thread(bufopen_thread
,
939 sizeof(bufopen_stack
),
941 IF_PRIO(,PRIORITY_BACKGROUND
)
942 IF_COP(, CPU
, false));
946 rb
->splash(HZ
, "failed to create codec thread");
949 else if (!bufopenthread_id
)
951 rb
->splash(HZ
, "failed to create bufopen thread");
957 while (!done_playing
)
959 struct memory_handle
*m
= first_handle
;
961 if (m
->filerem
> 0 &&
962 m
->data_len
- INT_BUF_USED(m
) > m
->data_len
/4)
964 /* there is free space to rebuffer */
965 DEBUGF("handle %d has %ld bytes available to rebuffer\n",
966 m
->id
, m
->data_len
- INT_BUF_USED(m
));
967 buffer_handle(m
->id
);
972 if (wasted_space() > buffer_len
/4) {
973 DEBUGF("there is %ld bytes of wasted space\n", wasted_space());
974 struct memory_handle
*m
= first_handle
;
976 if (m
->filerem
== 0) {
983 if (data_rem() > 0 &&
984 used_space() < buffer_len
/4 &&
987 DEBUGF("%ld bytes left to buffer and the buffer is running low\n",
994 DEBUGF("done playing\n");
999 DEBUGF("end of plugin\n");