diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-11-17 17:55:02 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-11-17 17:55:02 +0000 |
commit | 2a8eacdbfc5d98b016c480ddaddff100301f721f (patch) | |
tree | 69c79430463bb43c0e3ce96fbef851de6c35b277 /apps/playback.c | |
parent | 91206954aa0818e0790857f25f46a53d8e737a20 (diff) | |
download | rockbox-2a8eacdbfc5d98b016c480ddaddff100301f721f.tar.gz rockbox-2a8eacdbfc5d98b016c480ddaddff100301f721f.zip |
Buflib: Make shrinking and buflib_available() smarter.
* shrinking now considers freespace just before the alloc-to-be-shrinked,
that means less (or sometimes none at all) is taken from the audio buffer.
* core_available() now searches for the best free space, instead of simply the end,
i.e. it will not return 0 if the audio buffer is allocated and there's free space
before it. It also runs a compaction to ensure maximum contiguous memory.
audio_buffer_available() is also enhanced. It now considers the 256K reserve buffer,
and returns free buflib space instead if the audio buffer is short.
This all fixes the root problem of FS#12344 (Sansa Clip+: PANIC occurred when
dircache is enabled), that alloced from the audio buffer, even if it was very
short and buflib had many more available as free space before it.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31006 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/playback.c')
-rw-r--r-- | apps/playback.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/apps/playback.c b/apps/playback.c index a245091d91..d591998bec 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -733,13 +733,24 @@ static void scratch_mem_init(void *mem) | |||
733 | } | 733 | } |
734 | 734 | ||
735 | static int audiobuf_handle; | 735 | static int audiobuf_handle; |
736 | #define AUDIO_BUFFER_RESERVE (256*1024) | ||
736 | static size_t filebuflen; | 737 | static size_t filebuflen; |
737 | 738 | ||
739 | |||
740 | size_t audio_buffer_size(void) | ||
741 | { | ||
742 | if (audiobuf_handle > 0) | ||
743 | return filebuflen - AUDIO_BUFFER_RESERVE; | ||
744 | return 0; | ||
745 | } | ||
746 | |||
738 | size_t audio_buffer_available(void) | 747 | size_t audio_buffer_available(void) |
739 | { | 748 | { |
740 | if (audiobuf_handle > 0) /* if allocated return what we got */ | 749 | size_t size = 0; |
741 | return filebuflen; | 750 | size_t core_size = core_available(); |
742 | return core_available(); | 751 | if (audiobuf_handle > 0) /* if allocated return what we can give */ |
752 | size = filebuflen - AUDIO_BUFFER_RESERVE - 128; | ||
753 | return MAX(core_size, size); | ||
743 | } | 754 | } |
744 | 755 | ||
745 | /* Set up the audio buffer for playback | 756 | /* Set up the audio buffer for playback |
@@ -840,7 +851,7 @@ static int shrink_callback(int handle, unsigned hints, void* start, size_t old_s | |||
840 | size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK); | 851 | size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK); |
841 | ssize_t size = (ssize_t)old_size - wanted_size; | 852 | ssize_t size = (ssize_t)old_size - wanted_size; |
842 | /* keep at least 256K for the buffering */ | 853 | /* keep at least 256K for the buffering */ |
843 | if ((size - extradata_size) < 256*1024) | 854 | if ((size - extradata_size) < AUDIO_BUFFER_RESERVE) |
844 | return BUFLIB_CB_CANNOT_SHRINK; | 855 | return BUFLIB_CB_CANNOT_SHRINK; |
845 | 856 | ||
846 | 857 | ||