diff options
-rw-r--r-- | firmware/mpeg.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/firmware/mpeg.c b/firmware/mpeg.c index 329b6abc0d..83f9a38246 100644 --- a/firmware/mpeg.c +++ b/firmware/mpeg.c | |||
@@ -1036,6 +1036,7 @@ static void mpeg_thread(void) | |||
1036 | int start_offset; | 1036 | int start_offset; |
1037 | #ifdef HAVE_MAS3587F | 1037 | #ifdef HAVE_MAS3587F |
1038 | int amount_to_save; | 1038 | int amount_to_save; |
1039 | int writelen; | ||
1039 | #endif | 1040 | #endif |
1040 | 1041 | ||
1041 | is_playing = false; | 1042 | is_playing = false; |
@@ -1622,9 +1623,9 @@ static void mpeg_thread(void) | |||
1622 | wrapped */ | 1623 | wrapped */ |
1623 | if(amount_to_save < 0) | 1624 | if(amount_to_save < 0) |
1624 | { | 1625 | { |
1625 | amount_to_save = mp3buflen - mp3buf_read; | 1626 | amount_to_save += mp3buflen; |
1626 | } | 1627 | } |
1627 | 1628 | ||
1628 | /* Save data only if the buffer is getting full, | 1629 | /* Save data only if the buffer is getting full, |
1629 | or if we should stop recording */ | 1630 | or if we should stop recording */ |
1630 | if(amount_to_save) | 1631 | if(amount_to_save) |
@@ -1632,8 +1633,12 @@ static void mpeg_thread(void) | |||
1632 | if(mp3buflen - amount_to_save < MPEG_LOW_WATER || | 1633 | if(mp3buflen - amount_to_save < MPEG_LOW_WATER || |
1633 | stop_pending) | 1634 | stop_pending) |
1634 | { | 1635 | { |
1636 | /* Only save up to the end of the buffer */ | ||
1637 | writelen = MIN(amount_to_save, | ||
1638 | mp3buflen - mp3buf_read); | ||
1639 | |||
1635 | write(mpeg_file, mp3buf + mp3buf_read, | 1640 | write(mpeg_file, mp3buf + mp3buf_read, |
1636 | amount_to_save); | 1641 | writelen); |
1637 | 1642 | ||
1638 | mp3buf_read += amount_to_save; | 1643 | mp3buf_read += amount_to_save; |
1639 | if(mp3buf_read >= mp3buflen) | 1644 | if(mp3buf_read >= mp3buflen) |