From c5e29938c4c7dfcb1b888bbb3440f8688eb1d165 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Mon, 28 Oct 2002 00:00:07 +0000 Subject: Fast forward near the end of the last song in a playlist didn't activate the DMA if the remaining amount to play was below the watermark git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2754 a1c6a512-1295-4272-9138-f99709370657 --- firmware/mpeg.c | 63 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'firmware') diff --git a/firmware/mpeg.c b/firmware/mpeg.c index e8fd1acbc7..206e67d3d3 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -841,7 +841,35 @@ void hexdump(unsigned char *buf, int len) } #endif -static void swap_one_chunk(void) +static void start_playback_if_ready(void) +{ + /* See if we have started playing yet. If not, do it. */ + if(play_pending || dma_underrun) + { + /* If the filling has stopped, and we still haven't reached + the watermark, the file must be smaller than the + watermark. We must still play it. */ + if(((mp3buf_swapwrite - mp3buf_read) >= MPEG_LOW_WATER) || + !filling) + { + DEBUGF("P\n"); + play_pending = false; + playing = true; + + init_dma(); + if (!paused) + { + last_dma_tick = current_tick; + start_dma(); + } + + /* Tell ourselves that we need more data */ + queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); + } + } +} + +static bool swap_one_chunk(void) { int free_space_left; int amount_to_swap; @@ -849,7 +877,7 @@ static void swap_one_chunk(void) free_space_left = get_unswapped_space(); if(free_space_left == 0 && !play_pending) - return; + return false; /* Swap in larger chunks when the user is waiting for the playback to start */ @@ -873,31 +901,7 @@ static void swap_one_chunk(void) mp3buf_swapwrite = 0; } - /* And while we're at it, see if we have started - playing yet. If not, do it. */ - if(play_pending || dma_underrun) - { - /* If the filling has stopped, and we still haven't reached - the watermark, the file must be smaller than the - watermark. We must still play it. */ - if(((mp3buf_swapwrite - mp3buf_read) >= MPEG_LOW_WATER) || - !filling) - { - DEBUGF("P\n"); - play_pending = false; - playing = true; - - init_dma(); - if (!paused) - { - last_dma_tick = current_tick; - start_dma(); - } - - /* Tell ourselves that we need more data */ - queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); - } - } + return true; } static void mpeg_thread(void) @@ -922,9 +926,8 @@ static void mpeg_thread(void) yield(); /* Swap if necessary, and don't block on the queue_wait() */ - if(get_unswapped_space()) + if(swap_one_chunk()) { - swap_one_chunk(); queue_wait_w_tmo(&mpeg_queue, &ev, 0); } else @@ -933,6 +936,8 @@ static void mpeg_thread(void) mp3buf_read, mp3buf_write, mp3buf_swapwrite); queue_wait(&mpeg_queue, &ev); } + + start_playback_if_ready(); switch(ev.id) { -- cgit v1.2.3