1
0
Fork 0
forked from len0rd/rockbox

Still better loading algorithm, higher watermark

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1386 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2002-07-19 19:07:13 +00:00
parent 4e46ac78ae
commit 0b89507236

View file

@ -34,11 +34,9 @@
#include "file.h" #include "file.h"
#endif #endif
#define MPEG_FIRST_CHUNKSIZE 0x20000
#define MPEG_CHUNKSIZE 0x180000 #define MPEG_CHUNKSIZE 0x180000
#define MPEG_FIRST_SWAP_CHUNKSIZE 0x20000
#define MPEG_SWAP_CHUNKSIZE 0x8000 #define MPEG_SWAP_CHUNKSIZE 0x8000
#define MPEG_HIGHWATER 0x10000 #define MPEG_HIGH_WATER 2
#define MPEG_LOW_WATER 0x30000 #define MPEG_LOW_WATER 0x30000
#define MPEG_PLAY 1 #define MPEG_PLAY 1
@ -507,7 +505,8 @@ static void mpeg_thread(void)
while(1) while(1)
{ {
DEBUGF("S\n"); DEBUGF("S R:%x W:%x SW:%x\n",
mp3buf_read, mp3buf_write, mp3buf_swapwrite);
yield(); yield();
queue_wait(&mpeg_queue, &ev); queue_wait(&mpeg_queue, &ev);
switch(ev.id) switch(ev.id)
@ -627,13 +626,13 @@ static void mpeg_thread(void)
if(free_space_left < 0) if(free_space_left < 0)
free_space_left = mp3buflen + free_space_left; free_space_left = mp3buflen + free_space_left;
if(play_pending) amount_to_swap = MIN(MPEG_SWAP_CHUNKSIZE, free_space_left);
amount_to_swap = MIN(MPEG_FIRST_SWAP_CHUNKSIZE, if(mp3buf_write < mp3buf_swapwrite)
free_space_left); amount_to_swap = MIN(mp3buflen - mp3buf_swapwrite,
else amount_to_swap);
amount_to_swap = MIN(MPEG_SWAP_CHUNKSIZE, free_space_left); else
amount_to_swap = MIN(mp3buflen - mp3buf_swapwrite, amount_to_swap = MIN(mp3buf_write - mp3buf_swapwrite,
amount_to_swap); amount_to_swap);
DEBUGF("B %x\n", amount_to_swap); DEBUGF("B %x\n", amount_to_swap);
bitswap((unsigned short *)(mp3buf + mp3buf_swapwrite), bitswap((unsigned short *)(mp3buf + mp3buf_swapwrite),
@ -653,12 +652,20 @@ static void mpeg_thread(void)
playing yet. If not, do it. */ playing yet. If not, do it. */
if(play_pending) if(play_pending)
{ {
play_pending = false; if((mp3buf_swapwrite - mp3buf_read) >= MPEG_LOW_WATER)
playing = true; {
DEBUGF("P\n");
play_pending = false;
playing = true;
last_dma_tick = current_tick; last_dma_tick = current_tick;
init_dma(); init_dma();
start_dma(); start_dma();
/* Tell ourselves that we need more data */
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
}
} }
break; break;
@ -673,7 +680,7 @@ static void mpeg_thread(void)
free_space_left -= 2; free_space_left -= 2;
/* do we have any more buffer space to fill? */ /* do we have any more buffer space to fill? */
if(free_space_left <= MPEG_HIGHWATER) if(free_space_left <= MPEG_HIGH_WATER)
{ {
DEBUGF("0\n"); DEBUGF("0\n");
filling = false; filling = false;
@ -683,7 +690,7 @@ static void mpeg_thread(void)
if(play_pending) if(play_pending)
{ {
amount_to_read = MIN(MPEG_FIRST_CHUNKSIZE, free_space_left); amount_to_read = MIN(MPEG_LOW_WATER, free_space_left);
} }
else else
{ {
@ -701,6 +708,7 @@ static void mpeg_thread(void)
len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read); len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read);
if(len > 0) if(len > 0)
{ {
DEBUGF("R: %x\n", len);
/* Tell ourselves that we need to swap some data */ /* Tell ourselves that we need to swap some data */
queue_post(&mpeg_queue, MPEG_SWAP_DATA, 0); queue_post(&mpeg_queue, MPEG_SWAP_DATA, 0);
@ -711,8 +719,11 @@ static void mpeg_thread(void)
DEBUGF("W\n"); DEBUGF("W\n");
} }
/* Tell ourselves that we want more data */ if(!play_pending)
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); {
/* Tell ourselves that we want more data */
queue_post(&mpeg_queue, MPEG_NEED_DATA, 0);
}
} }
else else
{ {