From 67f95ecb28c8cb0eadd934295cb1139cd8ef8791 Mon Sep 17 00:00:00 2001 From: Hardeep Sidhu Date: Thu, 3 Oct 2002 07:28:28 +0000 Subject: [PATCH] Make sure the buffer data has been swapped before resuming after ffw. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2483 a1c6a512-1295-4272-9138-f99709370657 --- firmware/mpeg.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/firmware/mpeg.c b/firmware/mpeg.c index 6e2cabe172..61a8fc8208 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c @@ -496,6 +496,14 @@ static int get_unplayed_space_current_song(void) return space; } +static int get_unswapped_space(void) +{ + int space = mp3buf_write - mp3buf_swapwrite; + if (space < 0) + space += mp3buflen; + return space; +} + static void init_dma(void) { SAR3 = (unsigned int) mp3buf + mp3buf_read; @@ -884,9 +892,7 @@ static void mpeg_thread(void) last_dma_tick = current_tick; unplayed_space_left = get_unplayed_space(); - unswapped_space_left = mp3buf_write - mp3buf_swapwrite; - if (unswapped_space_left < 0) - unswapped_space_left += mp3buflen; + unswapped_space_left = get_unswapped_space(); /* should we start reading more data? */ if(!filling && (unplayed_space_left < MPEG_LOW_WATER)) { @@ -1050,6 +1056,8 @@ static void mpeg_thread(void) if(!filling && diffpos >= 0 && diffpos < mp3buflen) { + int unplayed_space_left, unswapped_space_left; + /* We are changing to a position that's already in memory */ mp3buf_read = mp3buf_write - diffpos; @@ -1058,13 +1066,21 @@ static void mpeg_thread(void) mp3buf_read += mp3buflen; } - if (get_unplayed_space() < MPEG_LOW_WATER) + unplayed_space_left = get_unplayed_space(); + unswapped_space_left = get_unswapped_space(); + + if (unplayed_space_left < MPEG_LOW_WATER) { /* We need to load more data before starting */ filling = true; queue_post(&mpeg_queue, MPEG_NEED_DATA, 0); play_pending = true; } + else if (unswapped_space_left > unplayed_space_left) + { + mp3buf_swapwrite = mp3buf_read; + play_pending = true; + } else { /* resume will start at new position */ @@ -1143,14 +1159,11 @@ static void mpeg_thread(void) } case MPEG_SWAP_DATA: - free_space_left = mp3buf_write - mp3buf_swapwrite; + free_space_left = get_unswapped_space(); if(free_space_left == 0) break; - if(free_space_left < 0) - free_space_left = mp3buflen + free_space_left; - amount_to_swap = MIN(MPEG_SWAP_CHUNKSIZE, free_space_left); if(mp3buf_write < mp3buf_swapwrite) amount_to_swap = MIN(mp3buflen - mp3buf_swapwrite,