summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-11-17 17:55:02 +0000
committerThomas Martitz <kugel@rockbox.org>2011-11-17 17:55:02 +0000
commit2a8eacdbfc5d98b016c480ddaddff100301f721f (patch)
tree69c79430463bb43c0e3ce96fbef851de6c35b277 /apps
parent91206954aa0818e0790857f25f46a53d8e737a20 (diff)
downloadrockbox-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')
-rw-r--r--apps/menus/main_menu.c4
-rw-r--r--apps/mpeg.c29
-rw-r--r--apps/playback.c19
3 files changed, 38 insertions, 14 deletions
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c
index 8053bf0cf8..bb8ea276fb 100644
--- a/apps/menus/main_menu.c
+++ b/apps/menus/main_menu.c
@@ -179,7 +179,7 @@ static const char* info_getname(int selected_item, void *data,
179 179
180 case INFO_BUFFER: /* buffer */ 180 case INFO_BUFFER: /* buffer */
181 { 181 {
182 long kib = audio_buffer_available() / 1024; /* to KiB */ 182 long kib = audio_buffer_size() / 1024; /* to KiB */
183 output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true); 183 output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true);
184 snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1); 184 snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1);
185 } 185 }
@@ -261,7 +261,7 @@ static int info_speak_item(int selected_item, void * data)
261 case INFO_BUFFER: /* buffer */ 261 case INFO_BUFFER: /* buffer */
262 { 262 {
263 talk_id(LANG_BUFFER_STAT, false); 263 talk_id(LANG_BUFFER_STAT, false);
264 long kib = audio_buffer_available() / 1024; /* to KiB */ 264 long kib = audio_buffer_size() / 1024; /* to KiB */
265 output_dyn_value(NULL, 0, kib, kbyte_units, true); 265 output_dyn_value(NULL, 0, kib, kbyte_units, true);
266 break; 266 break;
267 } 267 }
diff --git a/apps/mpeg.c b/apps/mpeg.c
index ae33ccc1bf..698695b72d 100644
--- a/apps/mpeg.c
+++ b/apps/mpeg.c
@@ -151,7 +151,7 @@ static bool paused; /* playback is paused */
151static int audiobuf_handle; /* handle to the audio buffer */ 151static int audiobuf_handle; /* handle to the audio buffer */
152static char* mpeg_audiobuf; /* poiunter to the audio buffer */ 152static char* mpeg_audiobuf; /* poiunter to the audio buffer */
153static long audiobuflen; /* length of the audio buffer */ 153static long audiobuflen; /* length of the audio buffer */
154 154#define AUDIO_BUFFER_RESERVE (256*1024)
155#ifdef SIMULATOR 155#ifdef SIMULATOR
156static char mpeg_stack[DEFAULT_STACK_SIZE]; 156static char mpeg_stack[DEFAULT_STACK_SIZE];
157static struct mp3entry taginfo; 157static struct mp3entry taginfo;
@@ -515,9 +515,16 @@ static void audio_reset_buffer_noalloc(void* buf, size_t bufsize);
515/* Buffer must not move. */ 515/* Buffer must not move. */
516static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size) 516static int shrink_callback(int handle, unsigned hints, void* start, size_t old_size)
517{ 517{
518 long offset = audio_current_track()->offset; 518 ssize_t extradata_size = old_size - audiobuflen;
519 bool playing = (audio_status() & AUDIO_STATUS_PLAY) == AUDIO_STATUS_PLAY; 519 /* check what buflib requests */
520 size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK);
521 ssize_t size = (ssize_t)old_size - wanted_size;
522 /* keep at least 256K for the buffering */
523 if ((size - extradata_size) < AUDIO_BUFFER_RESERVE)
524 return BUFLIB_CB_CANNOT_SHRINK;
520 /* TODO: Do it without stopping playback, if possible */ 525 /* TODO: Do it without stopping playback, if possible */
526 bool playing = (audio_status() & AUDIO_STATUS_PLAY) == AUDIO_STATUS_PLAY;
527 long offset = audio_current_track()->offset;
521 /* don't call audio_hard_stop() as it frees this handle */ 528 /* don't call audio_hard_stop() as it frees this handle */
522 if (thread_self() == audio_thread_id) 529 if (thread_self() == audio_thread_id)
523 { /* inline case MPEG_STOP (audio_stop()) response 530 { /* inline case MPEG_STOP (audio_stop()) response
@@ -528,9 +535,6 @@ static int shrink_callback(int handle, unsigned hints, void* start, size_t old_s
528 audio_stop(); 535 audio_stop();
529 talk_buffer_steal(); /* we obtain control over the buffer */ 536 talk_buffer_steal(); /* we obtain control over the buffer */
530 537
531 /* we should be free to change the buffer now */
532 size_t wanted_size = (hints & BUFLIB_SHRINK_SIZE_MASK);
533 ssize_t size = (ssize_t)old_size - wanted_size;
534 switch (hints & BUFLIB_SHRINK_POS_MASK) 538 switch (hints & BUFLIB_SHRINK_POS_MASK)
535 { 539 {
536 case BUFLIB_SHRINK_POS_BACK: 540 case BUFLIB_SHRINK_POS_BACK:
@@ -2742,11 +2746,20 @@ void audio_set_recording_options(struct audio_recording_options *options)
2742#endif /* SIMULATOR */ 2746#endif /* SIMULATOR */
2743#endif /* CONFIG_CODEC == MAS3587F */ 2747#endif /* CONFIG_CODEC == MAS3587F */
2744 2748
2745size_t audio_buffer_available(void) 2749size_t audio_buffer_size(void)
2746{ 2750{
2747 if (audiobuf_handle > 0) 2751 if (audiobuf_handle > 0)
2748 return audiobuflen; 2752 return audiobuflen;
2749 return core_available(); 2753 return 0;
2754}
2755
2756size_t audio_buffer_available(void)
2757{
2758 size_t size = 0;
2759 size_t core_size = core_available();
2760 if (audiobuf_handle > 0)
2761 return audiobuflen - AUDIO_BUFFER_RESERVE - 128;
2762 return MAX(core_size, size);
2750} 2763}
2751 2764
2752static void audio_reset_buffer_noalloc(void* buf, size_t bufsize) 2765static void audio_reset_buffer_noalloc(void* buf, size_t bufsize)
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
735static int audiobuf_handle; 735static int audiobuf_handle;
736#define AUDIO_BUFFER_RESERVE (256*1024)
736static size_t filebuflen; 737static size_t filebuflen;
737 738
739
740size_t audio_buffer_size(void)
741{
742 if (audiobuf_handle > 0)
743 return filebuflen - AUDIO_BUFFER_RESERVE;
744 return 0;
745}
746
738size_t audio_buffer_available(void) 747size_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