diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-11-03 21:51:46 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-11-03 21:51:46 +0000 |
commit | cf01d23d0d940e74ef77f86df328ce9b6411e97a (patch) | |
tree | 480e147a775b05be5745fd4a7f5df970b64b4dd9 /apps/playback.c | |
parent | 00c536878e62c85db5556fbd29cb05292f70e94f (diff) | |
download | rockbox-cf01d23d0d940e74ef77f86df328ce9b6411e97a.tar.gz rockbox-cf01d23d0d940e74ef77f86df328ce9b6411e97a.zip |
In the playback buflib shrink callback, ensure a minimum buffer remains for
audio playback. If it goes below 256K new buflib allocations fail.
This prevents buffer underruns as the new buffer size wasn't actually
checked at all.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30893 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playback.c')
-rw-r--r-- | apps/playback.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/apps/playback.c b/apps/playback.c index d2150f6a00..9bbce17a0a 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -828,6 +828,16 @@ bufpanic: | |||
828 | /* Buffer must not move. */ | 828 | /* Buffer must not move. */ |
829 | static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size) | 829 | static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size) |
830 | { | 830 | { |
831 | /* filebuflen is, at this point, the buffering.c buffer size, | ||
832 | * i.e. the audiobuf except voice, scratch mem, pcm, ... */ | ||
833 | ssize_t extradata_size = old_size - filebuflen; | ||
834 | /* check what buflib requests */ | ||
835 | size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK); | ||
836 | ssize_t size = (ssize_t)old_size - wanted_size; | ||
837 | /* keep at least 256K for the buffering */ | ||
838 | if ((size - extradata_size) < 256*1024) | ||
839 | return BUFLIB_CB_CANNOT_SHRINK; | ||
840 | |||
831 | long offset = audio_current_track()->offset; | 841 | long offset = audio_current_track()->offset; |
832 | int status = audio_status(); | 842 | int status = audio_status(); |
833 | /* TODO: Do it without stopping playback, if possible */ | 843 | /* TODO: Do it without stopping playback, if possible */ |
@@ -843,10 +853,9 @@ static int shrink_callback(int handle, unsigned hints, void* start, size_t old_s | |||
843 | #ifdef PLAYBACK_VOICE | 853 | #ifdef PLAYBACK_VOICE |
844 | voice_stop(); | 854 | voice_stop(); |
845 | #endif | 855 | #endif |
846 | /* we should be free to change the buffer now */ | 856 | /* we should be free to change the buffer now |
847 | size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK); | 857 | * set final buffer size before calling audio_reset_buffer_noalloc() |
848 | ssize_t size = (ssize_t)old_size - wanted_size; | 858 | * (now it's the total size, the call will subtract voice etc) */ |
849 | /* set final buffer size before calling audio_reset_buffer_noalloc() */ | ||
850 | filebuflen = size; | 859 | filebuflen = size; |
851 | switch (hints & BUFLIB_SHRINK_POS_MASK) | 860 | switch (hints & BUFLIB_SHRINK_POS_MASK) |
852 | { | 861 | { |