diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2002-07-19 19:07:13 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2002-07-19 19:07:13 +0000 |
commit | 0b895072364bedebb9b89245a466c684bcc08c1c (patch) | |
tree | 7c620c3f0e608a6d328cb9f8df397d675e8aa05e /firmware/mpeg.c | |
parent | 4e46ac78ae5c511db6935b34560a7a2ec8f26b24 (diff) | |
download | rockbox-0b895072364bedebb9b89245a466c684bcc08c1c.tar.gz rockbox-0b895072364bedebb9b89245a466c684bcc08c1c.zip |
Still better loading algorithm, higher watermark
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1386 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/mpeg.c')
-rw-r--r-- | firmware/mpeg.c | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c index f2cdcf6fa9..d58e464a94 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c | |||
@@ -34,11 +34,9 @@ | |||
34 | #include "file.h" | 34 | #include "file.h" |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #define MPEG_FIRST_CHUNKSIZE 0x20000 | ||
38 | #define MPEG_CHUNKSIZE 0x180000 | 37 | #define MPEG_CHUNKSIZE 0x180000 |
39 | #define MPEG_FIRST_SWAP_CHUNKSIZE 0x20000 | ||
40 | #define MPEG_SWAP_CHUNKSIZE 0x8000 | 38 | #define MPEG_SWAP_CHUNKSIZE 0x8000 |
41 | #define MPEG_HIGHWATER 0x10000 | 39 | #define MPEG_HIGH_WATER 2 |
42 | #define MPEG_LOW_WATER 0x30000 | 40 | #define MPEG_LOW_WATER 0x30000 |
43 | 41 | ||
44 | #define MPEG_PLAY 1 | 42 | #define MPEG_PLAY 1 |
@@ -507,7 +505,8 @@ static void mpeg_thread(void) | |||
507 | 505 | ||
508 | while(1) | 506 | while(1) |
509 | { | 507 | { |
510 | DEBUGF("S\n"); | 508 | DEBUGF("S R:%x W:%x SW:%x\n", |
509 | mp3buf_read, mp3buf_write, mp3buf_swapwrite); | ||
511 | yield(); | 510 | yield(); |
512 | queue_wait(&mpeg_queue, &ev); | 511 | queue_wait(&mpeg_queue, &ev); |
513 | switch(ev.id) | 512 | switch(ev.id) |
@@ -627,13 +626,13 @@ static void mpeg_thread(void) | |||
627 | if(free_space_left < 0) | 626 | if(free_space_left < 0) |
628 | free_space_left = mp3buflen + free_space_left; | 627 | free_space_left = mp3buflen + free_space_left; |
629 | 628 | ||
630 | if(play_pending) | 629 | amount_to_swap = MIN(MPEG_SWAP_CHUNKSIZE, free_space_left); |
631 | amount_to_swap = MIN(MPEG_FIRST_SWAP_CHUNKSIZE, | 630 | if(mp3buf_write < mp3buf_swapwrite) |
632 | free_space_left); | 631 | amount_to_swap = MIN(mp3buflen - mp3buf_swapwrite, |
633 | else | 632 | amount_to_swap); |
634 | amount_to_swap = MIN(MPEG_SWAP_CHUNKSIZE, free_space_left); | 633 | else |
635 | amount_to_swap = MIN(mp3buflen - mp3buf_swapwrite, | 634 | amount_to_swap = MIN(mp3buf_write - mp3buf_swapwrite, |
636 | amount_to_swap); | 635 | amount_to_swap); |
637 | 636 | ||
638 | DEBUGF("B %x\n", amount_to_swap); | 637 | DEBUGF("B %x\n", amount_to_swap); |
639 | bitswap((unsigned short *)(mp3buf + mp3buf_swapwrite), | 638 | bitswap((unsigned short *)(mp3buf + mp3buf_swapwrite), |
@@ -653,12 +652,20 @@ static void mpeg_thread(void) | |||
653 | playing yet. If not, do it. */ | 652 | playing yet. If not, do it. */ |
654 | if(play_pending) | 653 | if(play_pending) |
655 | { | 654 | { |
656 | play_pending = false; | 655 | if((mp3buf_swapwrite - mp3buf_read) >= MPEG_LOW_WATER) |
657 | playing = true; | 656 | { |
658 | 657 | DEBUGF("P\n"); | |
659 | last_dma_tick = current_tick; | 658 | play_pending = false; |
660 | init_dma(); | 659 | playing = true; |
661 | start_dma(); | 660 | |
661 | last_dma_tick = current_tick; | ||
662 | init_dma(); | ||
663 | start_dma(); | ||
664 | |||
665 | /* Tell ourselves that we need more data */ | ||
666 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | ||
667 | |||
668 | } | ||
662 | } | 669 | } |
663 | break; | 670 | break; |
664 | 671 | ||
@@ -673,7 +680,7 @@ static void mpeg_thread(void) | |||
673 | free_space_left -= 2; | 680 | free_space_left -= 2; |
674 | 681 | ||
675 | /* do we have any more buffer space to fill? */ | 682 | /* do we have any more buffer space to fill? */ |
676 | if(free_space_left <= MPEG_HIGHWATER) | 683 | if(free_space_left <= MPEG_HIGH_WATER) |
677 | { | 684 | { |
678 | DEBUGF("0\n"); | 685 | DEBUGF("0\n"); |
679 | filling = false; | 686 | filling = false; |
@@ -683,7 +690,7 @@ static void mpeg_thread(void) | |||
683 | 690 | ||
684 | if(play_pending) | 691 | if(play_pending) |
685 | { | 692 | { |
686 | amount_to_read = MIN(MPEG_FIRST_CHUNKSIZE, free_space_left); | 693 | amount_to_read = MIN(MPEG_LOW_WATER, free_space_left); |
687 | } | 694 | } |
688 | else | 695 | else |
689 | { | 696 | { |
@@ -701,6 +708,7 @@ static void mpeg_thread(void) | |||
701 | len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read); | 708 | len = read(mpeg_file, mp3buf+mp3buf_write, amount_to_read); |
702 | if(len > 0) | 709 | if(len > 0) |
703 | { | 710 | { |
711 | DEBUGF("R: %x\n", len); | ||
704 | /* Tell ourselves that we need to swap some data */ | 712 | /* Tell ourselves that we need to swap some data */ |
705 | queue_post(&mpeg_queue, MPEG_SWAP_DATA, 0); | 713 | queue_post(&mpeg_queue, MPEG_SWAP_DATA, 0); |
706 | 714 | ||
@@ -711,8 +719,11 @@ static void mpeg_thread(void) | |||
711 | DEBUGF("W\n"); | 719 | DEBUGF("W\n"); |
712 | } | 720 | } |
713 | 721 | ||
714 | /* Tell ourselves that we want more data */ | 722 | if(!play_pending) |
715 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | 723 | { |
724 | /* Tell ourselves that we want more data */ | ||
725 | queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); | ||
726 | } | ||
716 | } | 727 | } |
717 | else | 728 | else |
718 | { | 729 | { |