diff options
author | Thomas Martitz <kugel@rockbox.org> | 2011-08-30 14:01:33 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2011-08-30 14:01:33 +0000 |
commit | d0b72e25903574acb1cf9184a6052cdd646dbc37 (patch) | |
tree | 5be8db5ee00b2a727e4821cf51a5f7bcf3991073 /apps | |
parent | c940811ade7d99a0e0d414df7c6509672413684a (diff) | |
download | rockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.tar.gz rockbox-d0b72e25903574acb1cf9184a6052cdd646dbc37.zip |
GSoC/Buflib: Add buflib memory alocator to the core.
The buflib memory allocator is handle based and can free and
compact, move or resize memory on demand. This allows to effeciently
allocate memory dynamically without an MMU, by avoiding fragmentation
through memory compaction.
This patch adds the buflib library to the core, along with
convinience wrappers to omit the context parameter. Compaction is
not yet enabled, but will be in a later patch. Therefore, this acts as a
replacement for buffer_alloc/buffer_get_buffer() with the benifit of a debug
menu.
See buflib.h for some API documentation.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30380 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/debug_menu.c | 18 | ||||
-rw-r--r-- | apps/dsp.c | 10 | ||||
-rw-r--r-- | apps/filetypes.c | 29 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_engine.c | 3 | ||||
-rw-r--r-- | apps/main.c | 12 | ||||
-rw-r--r-- | apps/menus/main_menu.c | 4 | ||||
-rw-r--r-- | apps/mpeg.c | 68 | ||||
-rw-r--r-- | apps/playback.c | 54 | ||||
-rw-r--r-- | apps/playlist.c | 23 | ||||
-rw-r--r-- | apps/playlist.h | 6 | ||||
-rw-r--r-- | apps/scrobbler.c | 20 | ||||
-rw-r--r-- | apps/tagcache.c | 21 | ||||
-rw-r--r-- | apps/tagtree.c | 12 | ||||
-rw-r--r-- | apps/talk.c | 3 | ||||
-rw-r--r-- | apps/tdspeed.c | 27 | ||||
-rw-r--r-- | apps/tree.c | 9 |
16 files changed, 211 insertions, 108 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 9e4621b749..fb8575ec62 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -79,6 +79,7 @@ | |||
79 | #include "peakmeter.h" | 79 | #include "peakmeter.h" |
80 | #endif | 80 | #endif |
81 | #include "logfdisp.h" | 81 | #include "logfdisp.h" |
82 | #include "core_alloc.h" | ||
82 | #if CONFIG_CODEC == SWCODEC | 83 | #if CONFIG_CODEC == SWCODEC |
83 | #include "pcmbuf.h" | 84 | #include "pcmbuf.h" |
84 | #include "buffering.h" | 85 | #include "buffering.h" |
@@ -416,6 +417,22 @@ static bool dbg_buffering_thread(void) | |||
416 | #endif /* CONFIG_CODEC */ | 417 | #endif /* CONFIG_CODEC */ |
417 | #endif /* HAVE_LCD_BITMAP */ | 418 | #endif /* HAVE_LCD_BITMAP */ |
418 | 419 | ||
420 | static const char* bf_getname(int selected_item, void *data, | ||
421 | char *buffer, size_t buffer_len) | ||
422 | { | ||
423 | (void)data; | ||
424 | core_print_block_at(selected_item, buffer, buffer_len); | ||
425 | return buffer; | ||
426 | } | ||
427 | |||
428 | static bool dbg_buflib_allocs(void) | ||
429 | { | ||
430 | struct simplelist_info info; | ||
431 | simplelist_info_init(&info, "mem allocs", core_get_num_blocks(), NULL); | ||
432 | info.get_name = bf_getname; | ||
433 | return simplelist_show_list(&info); | ||
434 | } | ||
435 | |||
419 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) | 436 | #if (CONFIG_PLATFORM & PLATFORM_NATIVE) |
420 | static const char* dbg_partitions_getname(int selected_item, void *data, | 437 | static const char* dbg_partitions_getname(int selected_item, void *data, |
421 | char *buffer, size_t buffer_len) | 438 | char *buffer, size_t buffer_len) |
@@ -2040,6 +2057,7 @@ static const struct the_menu_item menuitems[] = { | |||
2040 | { "pm histogram", peak_meter_histogram}, | 2057 | { "pm histogram", peak_meter_histogram}, |
2041 | #endif /* PM_DEBUG */ | 2058 | #endif /* PM_DEBUG */ |
2042 | #endif /* HAVE_LCD_BITMAP */ | 2059 | #endif /* HAVE_LCD_BITMAP */ |
2060 | { "View buflib allocs", dbg_buflib_allocs }, | ||
2043 | #ifndef SIMULATOR | 2061 | #ifndef SIMULATOR |
2044 | #if CONFIG_TUNER | 2062 | #if CONFIG_TUNER |
2045 | { "FM Radio", dbg_fm_radio }, | 2063 | { "FM Radio", dbg_fm_radio }, |
diff --git a/apps/dsp.c b/apps/dsp.c index 3cff1918d7..a728dd75ea 100644 --- a/apps/dsp.c +++ b/apps/dsp.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include "settings.h" | 30 | #include "settings.h" |
31 | #include "replaygain.h" | 31 | #include "replaygain.h" |
32 | #include "tdspeed.h" | 32 | #include "tdspeed.h" |
33 | #include "buffer.h" | 33 | #include "core_alloc.h" |
34 | #include "fixedpoint.h" | 34 | #include "fixedpoint.h" |
35 | #include "fracmul.h" | 35 | #include "fracmul.h" |
36 | 36 | ||
@@ -325,10 +325,16 @@ void dsp_timestretch_enable(bool enabled) | |||
325 | { | 325 | { |
326 | if (enabled) | 326 | if (enabled) |
327 | { | 327 | { |
328 | int handle; | ||
328 | /* Set up timestretch buffers */ | 329 | /* Set up timestretch buffers */ |
329 | big_sample_buf_count = SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO; | 330 | big_sample_buf_count = SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO; |
330 | big_sample_buf = small_resample_buf; | 331 | big_sample_buf = small_resample_buf; |
331 | big_resample_buf = (int32_t *) buffer_alloc(big_sample_buf_count * RESAMPLE_RATIO * sizeof(int32_t)); | 332 | handle = core_alloc("resample buf", |
333 | big_sample_buf_count * RESAMPLE_RATIO * sizeof(int32_t)); | ||
334 | if (handle > 0) | ||
335 | big_resample_buf = core_get_data(handle); | ||
336 | else | ||
337 | big_sample_buf_count = 0; | ||
332 | } | 338 | } |
333 | else | 339 | else |
334 | { | 340 | { |
diff --git a/apps/filetypes.c b/apps/filetypes.c index 17a16db4ec..c52c734a1d 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c | |||
@@ -36,7 +36,7 @@ | |||
36 | #include "dir.h" | 36 | #include "dir.h" |
37 | #include "file.h" | 37 | #include "file.h" |
38 | #include "splash.h" | 38 | #include "splash.h" |
39 | #include "buffer.h" | 39 | #include "core_alloc.h" |
40 | #include "icons.h" | 40 | #include "icons.h" |
41 | #include "logf.h" | 41 | #include "logf.h" |
42 | 42 | ||
@@ -183,12 +183,14 @@ static int filetype_count = 0; | |||
183 | static unsigned char highest_attr = 0; | 183 | static unsigned char highest_attr = 0; |
184 | static int viewer_count = 0; | 184 | static int viewer_count = 0; |
185 | 185 | ||
186 | static int strdup_handle, strdup_bufsize, strdup_cur_idx; | ||
186 | static char *filetypes_strdup(char* string) | 187 | static char *filetypes_strdup(char* string) |
187 | { | 188 | { |
188 | char *buffer = (char*)buffer_alloc(strlen(string)+1); | 189 | char *buffer = core_get_data(strdup_handle) + strdup_cur_idx; |
189 | strcpy(buffer, string); | 190 | strdup_cur_idx += strlcpy(buffer, string, strdup_bufsize-strdup_cur_idx)+1; |
190 | return buffer; | 191 | return buffer; |
191 | } | 192 | } |
193 | |||
192 | static char *filetypes_store_plugin(char *plugin, int n) | 194 | static char *filetypes_store_plugin(char *plugin, int n) |
193 | { | 195 | { |
194 | int i; | 196 | int i; |
@@ -219,7 +221,7 @@ static int find_extension(const char* extension) | |||
219 | } | 221 | } |
220 | 222 | ||
221 | static void read_builtin_types(void); | 223 | static void read_builtin_types(void); |
222 | static void read_config(const char* config_file); | 224 | static void read_config(int fd); |
223 | #ifdef HAVE_LCD_COLOR | 225 | #ifdef HAVE_LCD_COLOR |
224 | /* Colors file format is similar to icons: | 226 | /* Colors file format is similar to icons: |
225 | * ext:hex_color | 227 | * ext:hex_color |
@@ -312,16 +314,28 @@ void filetype_init(void) | |||
312 | filetypes[0].attr = 0; | 314 | filetypes[0].attr = 0; |
313 | filetypes[0].icon = Icon_Folder; | 315 | filetypes[0].icon = Icon_Folder; |
314 | 316 | ||
317 | /* estimate bufsize with the filesize, will not be larger */ | ||
315 | viewer_count = 0; | 318 | viewer_count = 0; |
316 | filetype_count = 1; | 319 | filetype_count = 1; |
320 | |||
321 | int fd = open(VIEWERS_CONFIG, O_RDONLY); | ||
322 | if (fd < 0) | ||
323 | return; | ||
324 | |||
325 | strdup_bufsize = filesize(fd); | ||
326 | strdup_handle = core_alloc("filetypes", strdup_bufsize); | ||
327 | if (strdup_handle <= 0) | ||
328 | return; | ||
317 | read_builtin_types(); | 329 | read_builtin_types(); |
318 | read_config(VIEWERS_CONFIG); | 330 | read_config(fd); |
319 | #ifdef HAVE_LCD_BITMAP | 331 | #ifdef HAVE_LCD_BITMAP |
320 | read_viewer_theme_file(); | 332 | read_viewer_theme_file(); |
321 | #endif | 333 | #endif |
322 | #ifdef HAVE_LCD_COLOR | 334 | #ifdef HAVE_LCD_COLOR |
323 | read_color_theme_file(); | 335 | read_color_theme_file(); |
324 | #endif | 336 | #endif |
337 | close(fd); | ||
338 | core_shrink(strdup_handle, core_get_data(strdup_handle), strdup_cur_idx); | ||
325 | } | 339 | } |
326 | 340 | ||
327 | /* remove all white spaces from string */ | 341 | /* remove all white spaces from string */ |
@@ -355,13 +369,10 @@ static void read_builtin_types(void) | |||
355 | } | 369 | } |
356 | } | 370 | } |
357 | 371 | ||
358 | static void read_config(const char* config_file) | 372 | static void read_config(int fd) |
359 | { | 373 | { |
360 | char line[64], *s, *e; | 374 | char line[64], *s, *e; |
361 | char *extension, *plugin; | 375 | char *extension, *plugin; |
362 | int fd = open(config_file, O_RDONLY); | ||
363 | if (fd < 0) | ||
364 | return; | ||
365 | /* config file is in the format | 376 | /* config file is in the format |
366 | <extension>,<plugin>,<icon code> | 377 | <extension>,<plugin>,<icon code> |
367 | ignore line if either of the first two are missing */ | 378 | ignore line if either of the first two are missing */ |
diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c index fbedbb96fd..d136f90aa5 100644 --- a/apps/gui/skin_engine/skin_engine.c +++ b/apps/gui/skin_engine/skin_engine.c | |||
@@ -48,10 +48,9 @@ void theme_init_buffer(void) | |||
48 | skins_initialising = false; | 48 | skins_initialising = false; |
49 | } | 49 | } |
50 | #else | 50 | #else |
51 | static char *skin_buffer = NULL; | 51 | static char skin_buffer[SKIN_BUFFER_SIZE]; |
52 | void theme_init_buffer(void) | 52 | void theme_init_buffer(void) |
53 | { | 53 | { |
54 | skin_buffer = buffer_alloc(SKIN_BUFFER_SIZE); | ||
55 | skins_initialising = false; | 54 | skins_initialising = false; |
56 | } | 55 | } |
57 | #endif | 56 | #endif |
diff --git a/apps/main.c b/apps/main.c index 9cb724562c..cc9c9e8d8e 100644 --- a/apps/main.c +++ b/apps/main.c | |||
@@ -53,7 +53,7 @@ | |||
53 | #include "language.h" | 53 | #include "language.h" |
54 | #include "wps.h" | 54 | #include "wps.h" |
55 | #include "playlist.h" | 55 | #include "playlist.h" |
56 | #include "buffer.h" | 56 | #include "core_alloc.h" |
57 | #include "rolo.h" | 57 | #include "rolo.h" |
58 | #include "screens.h" | 58 | #include "screens.h" |
59 | #include "usb_screen.h" | 59 | #include "usb_screen.h" |
@@ -337,7 +337,7 @@ static void init_tagcache(void) | |||
337 | static void init(void) | 337 | static void init(void) |
338 | { | 338 | { |
339 | system_init(); | 339 | system_init(); |
340 | buffer_init(); | 340 | core_allocator_init(); |
341 | kernel_init(); | 341 | kernel_init(); |
342 | #ifdef APPLICATION | 342 | #ifdef APPLICATION |
343 | paths_init(); | 343 | paths_init(); |
@@ -400,9 +400,6 @@ static void init(void) | |||
400 | global_settings.mdb_shape, | 400 | global_settings.mdb_shape, |
401 | global_settings.mdb_enable, | 401 | global_settings.mdb_enable, |
402 | global_settings.superbass); | 402 | global_settings.superbass); |
403 | |||
404 | /* audio_init must to know the size of voice buffer so init voice first */ | ||
405 | talk_init(); | ||
406 | #endif /* CONFIG_CODEC != SWCODEC */ | 403 | #endif /* CONFIG_CODEC != SWCODEC */ |
407 | 404 | ||
408 | scrobbler_init(); | 405 | scrobbler_init(); |
@@ -428,7 +425,7 @@ static void init(void) | |||
428 | #endif | 425 | #endif |
429 | 426 | ||
430 | system_init(); | 427 | system_init(); |
431 | buffer_init(); | 428 | core_allocator_init(); |
432 | kernel_init(); | 429 | kernel_init(); |
433 | 430 | ||
434 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ | 431 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
@@ -684,9 +681,6 @@ static void init(void) | |||
684 | global_settings.mdb_shape, | 681 | global_settings.mdb_shape, |
685 | global_settings.mdb_enable, | 682 | global_settings.mdb_enable, |
686 | global_settings.superbass); | 683 | global_settings.superbass); |
687 | |||
688 | /* audio_init must to know the size of voice buffer so init voice first */ | ||
689 | talk_init(); | ||
690 | #endif /* CONFIG_CODEC != SWCODEC */ | 684 | #endif /* CONFIG_CODEC != SWCODEC */ |
691 | 685 | ||
692 | CHART(">audio_init"); | 686 | CHART(">audio_init"); |
diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index c5758d1274..e88317aeab 100644 --- a/apps/menus/main_menu.c +++ b/apps/menus/main_menu.c | |||
@@ -182,7 +182,7 @@ static const char* info_getname(int selected_item, void *data, | |||
182 | 182 | ||
183 | case INFO_BUFFER: /* buffer */ | 183 | case INFO_BUFFER: /* buffer */ |
184 | { | 184 | { |
185 | long kib = buffer_available() / 1024; /* to KiB */ | 185 | long kib = audio_buffer_available() / 1024; /* to KiB */ |
186 | output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true); | 186 | output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true); |
187 | snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1); | 187 | snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1); |
188 | } | 188 | } |
@@ -272,7 +272,7 @@ static int info_speak_item(int selected_item, void * data) | |||
272 | case INFO_BUFFER: /* buffer */ | 272 | case INFO_BUFFER: /* buffer */ |
273 | { | 273 | { |
274 | talk_id(LANG_BUFFER_STAT, false); | 274 | talk_id(LANG_BUFFER_STAT, false); |
275 | long kib = buffer_available() / 1024; /* to KiB */ | 275 | long kib = audio_buffer_available() / 1024; /* to KiB */ |
276 | output_dyn_value(NULL, 0, kib, kbyte_units, true); | 276 | output_dyn_value(NULL, 0, kib, kbyte_units, true); |
277 | break; | 277 | break; |
278 | } | 278 | } |
diff --git a/apps/mpeg.c b/apps/mpeg.c index 6dd55b741c..595f943545 100644 --- a/apps/mpeg.c +++ b/apps/mpeg.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include "thread.h" | 35 | #include "thread.h" |
36 | #include "errno.h" | 36 | #include "errno.h" |
37 | #include "mp3data.h" | 37 | #include "mp3data.h" |
38 | #include "buffer.h" | 38 | #include "core_alloc.h" |
39 | #include "mp3_playback.h" | 39 | #include "mp3_playback.h" |
40 | #include "talk.h" | 40 | #include "talk.h" |
41 | #include "sound.h" | 41 | #include "sound.h" |
@@ -145,7 +145,8 @@ static unsigned int mpeg_errno; | |||
145 | static bool playing = false; /* We are playing an MP3 stream */ | 145 | static bool playing = false; /* We are playing an MP3 stream */ |
146 | static bool is_playing = false; /* We are (attempting to) playing MP3 files */ | 146 | static bool is_playing = false; /* We are (attempting to) playing MP3 files */ |
147 | static bool paused; /* playback is paused */ | 147 | static bool paused; /* playback is paused */ |
148 | static char* mpeg_audiobuf; /* the audio buffer */ | 148 | static int audiobuf_handle; /* handle to the audio buffer */ |
149 | static char* mpeg_audiobuf; /* poiunter to the audio buffer */ | ||
149 | static long audiobuflen; /* length of the audio buffer */ | 150 | static long audiobuflen; /* length of the audio buffer */ |
150 | 151 | ||
151 | #ifdef SIMULATOR | 152 | #ifdef SIMULATOR |
@@ -491,15 +492,27 @@ unsigned long mpeg_get_last_header(void) | |||
491 | #endif /* !SIMULATOR */ | 492 | #endif /* !SIMULATOR */ |
492 | } | 493 | } |
493 | 494 | ||
494 | 495 | /* Buffer must not move. And not shrink for now */ | |
496 | static struct buflib_callbacks ops = { NULL, NULL }; | ||
495 | unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) | 497 | unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) |
496 | { | 498 | { |
497 | (void)talk_buf; /* always grab the voice buffer for now */ | 499 | (void)talk_buf; /* always grab the voice buffer for now */ |
498 | 500 | ||
499 | audio_hard_stop(); | ||
500 | if (buffer_size) /* special case for talk_init() */ | 501 | if (buffer_size) /* special case for talk_init() */ |
501 | return buffer_get_buffer(buffer_size); | 502 | { |
502 | return NULL; | 503 | size_t bufsize; |
504 | audio_hard_stop(); | ||
505 | /* audio_hard_stop() frees audiobuf, so re-aquire */ | ||
506 | audiobuf_handle = core_alloc_maximum("audiobuf", &bufsize, &ops); | ||
507 | audiobuflen = bufsize; | ||
508 | *buffer_size = audiobuflen; | ||
509 | } | ||
510 | mpeg_audiobuf = core_get_data(audiobuf_handle); | ||
511 | |||
512 | if (!buffer_size) /* special case for talk_init() */ | ||
513 | talkbuf_init(mpeg_audiobuf); | ||
514 | |||
515 | return mpeg_audiobuf; | ||
503 | } | 516 | } |
504 | 517 | ||
505 | 518 | ||
@@ -2659,17 +2672,26 @@ void audio_set_recording_options(struct audio_recording_options *options) | |||
2659 | #endif /* SIMULATOR */ | 2672 | #endif /* SIMULATOR */ |
2660 | #endif /* CONFIG_CODEC == MAS3587F */ | 2673 | #endif /* CONFIG_CODEC == MAS3587F */ |
2661 | 2674 | ||
2675 | size_t audio_buffer_available(void) | ||
2676 | { | ||
2677 | if (audiobuf_handle > 0) | ||
2678 | return audiobuflen; | ||
2679 | return core_available(); | ||
2680 | } | ||
2681 | |||
2662 | static void audio_reset_buffer(void) | 2682 | static void audio_reset_buffer(void) |
2663 | { | 2683 | { |
2664 | size_t bufsize; /* dont break strict-aliasing */ | ||
2665 | talk_buffer_steal(); /* will use the mp3 buffer */ | 2684 | talk_buffer_steal(); /* will use the mp3 buffer */ |
2666 | 2685 | ||
2667 | /* release buffer on behalf of any audio_get_buffer() caller, | 2686 | /* alloc buffer if it's was never allocated or freed by audio_hard_stop() */ |
2668 | * non-fatal if there was none */ | 2687 | if (!audiobuf_handle) |
2669 | buffer_release_buffer(0); | 2688 | { |
2670 | /* re-aquire */ | 2689 | size_t bufsize; /* dont break strict-aliasing */ |
2671 | mpeg_audiobuf = buffer_get_buffer(&bufsize); | 2690 | audiobuf_handle = core_alloc_maximum("audiobuf", &bufsize, &ops); |
2672 | audiobuflen = bufsize; | 2691 | mpeg_audiobuf = core_get_data(audiobuf_handle); |
2692 | audiobuflen = bufsize; | ||
2693 | } | ||
2694 | talkbuf_init(mpeg_audiobuf); | ||
2673 | } | 2695 | } |
2674 | 2696 | ||
2675 | void audio_play(long offset) | 2697 | void audio_play(long offset) |
@@ -2742,7 +2764,11 @@ void audio_hard_stop(void) | |||
2742 | audio_stop(); | 2764 | audio_stop(); |
2743 | /* tell voice we obtain the buffer before freeing */ | 2765 | /* tell voice we obtain the buffer before freeing */ |
2744 | talk_buffer_steal(); | 2766 | talk_buffer_steal(); |
2745 | buffer_release_buffer(0); | 2767 | if (audiobuf_handle > 0) |
2768 | { | ||
2769 | audiobuf_handle = core_free(audiobuf_handle); | ||
2770 | mpeg_audiobuf = NULL; | ||
2771 | } | ||
2746 | } | 2772 | } |
2747 | 2773 | ||
2748 | void audio_pause(void) | 2774 | void audio_pause(void) |
@@ -2899,13 +2925,15 @@ void audio_init(void) | |||
2899 | mpeg_errno = 0; | 2925 | mpeg_errno = 0; |
2900 | /* cuesheet support */ | 2926 | /* cuesheet support */ |
2901 | if (global_settings.cuesheet) | 2927 | if (global_settings.cuesheet) |
2902 | curr_cuesheet = (struct cuesheet*)buffer_alloc(sizeof(struct cuesheet)); | 2928 | { |
2929 | int handle = core_alloc("cuesheet", sizeof(struct cuesheet)); | ||
2930 | if (handle > 0) | ||
2931 | curr_cuesheet = core_get_data(handle); | ||
2932 | } | ||
2933 | |||
2934 | talk_init(); | ||
2935 | audio_reset_buffer(); | ||
2903 | 2936 | ||
2904 | size_t bufsize; /* don't break strict-aliasing */ | ||
2905 | mpeg_audiobuf = buffer_get_buffer(&bufsize); | ||
2906 | audiobuflen = bufsize; | ||
2907 | /* give voice buffer until we start to play */ | ||
2908 | talkbuf_init(mpeg_audiobuf); | ||
2909 | #ifndef SIMULATOR | 2937 | #ifndef SIMULATOR |
2910 | queue_init(&mpeg_queue, true); | 2938 | queue_init(&mpeg_queue, true); |
2911 | #endif /* !SIMULATOR */ | 2939 | #endif /* !SIMULATOR */ |
diff --git a/apps/playback.c b/apps/playback.c index 7dad08644a..e35d652ffb 100644 --- a/apps/playback.c +++ b/apps/playback.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "system.h" | 24 | #include "system.h" |
25 | #include "kernel.h" | 25 | #include "kernel.h" |
26 | #include "panic.h" | 26 | #include "panic.h" |
27 | #include "buffer.h" | 27 | #include "core_alloc.h" |
28 | #include "sound.h" | 28 | #include "sound.h" |
29 | #include "ata.h" | 29 | #include "ata.h" |
30 | #include "usb.h" | 30 | #include "usb.h" |
@@ -732,6 +732,18 @@ static void scratch_mem_init(void *mem) | |||
732 | } | 732 | } |
733 | } | 733 | } |
734 | 734 | ||
735 | /* Buffer must not move. And not shrink for now */ | ||
736 | static struct buflib_callbacks ops = { NULL, NULL }; | ||
737 | static int audiobuf_handle; | ||
738 | static size_t filebuflen; | ||
739 | |||
740 | size_t audio_buffer_available(void) | ||
741 | { | ||
742 | if (audiobuf_handle > 0) /* if allocated return what we got */ | ||
743 | return filebuflen; | ||
744 | return core_available(); | ||
745 | } | ||
746 | |||
735 | /* Set up the audio buffer for playback */ | 747 | /* Set up the audio buffer for playback */ |
736 | static void audio_reset_buffer(void) | 748 | static void audio_reset_buffer(void) |
737 | { | 749 | { |
@@ -743,16 +755,17 @@ static void audio_reset_buffer(void) | |||
743 | /* see audio_get_recording_buffer if this is modified */ | 755 | /* see audio_get_recording_buffer if this is modified */ |
744 | logf("%s()", __func__); | 756 | logf("%s()", __func__); |
745 | 757 | ||
746 | /* release the buffer on behalf of any caller of audio_get_buffer() */ | ||
747 | buffer_release_buffer(0); | ||
748 | |||
749 | /* If the setup of anything allocated before the file buffer is | 758 | /* If the setup of anything allocated before the file buffer is |
750 | changed, do check the adjustments after the buffer_alloc call | 759 | changed, do check the adjustments after the buffer_alloc call |
751 | as it will likely be affected and need sliding over */ | 760 | as it will likely be affected and need sliding over */ |
752 | 761 | ||
753 | /* Initially set up file buffer as all space available */ | 762 | /* Initially set up file buffer as all space available */ |
754 | size_t filebuflen, allocsize; | 763 | size_t allocsize; |
755 | unsigned char *filebuf = buffer_get_buffer(&filebuflen); | 764 | if (audiobuf_handle > 0) |
765 | audiobuf_handle = core_free(audiobuf_handle); | ||
766 | |||
767 | audiobuf_handle = core_alloc_maximum("audiobuf", &filebuflen, &ops); | ||
768 | unsigned char *filebuf = core_get_data(audiobuf_handle); | ||
756 | 769 | ||
757 | /* Subtract whatever voice needs */ | 770 | /* Subtract whatever voice needs */ |
758 | allocsize = talkbuf_init(filebuf); | 771 | allocsize = talkbuf_init(filebuf); |
@@ -3324,7 +3337,8 @@ void audio_hard_stop(void) | |||
3324 | #ifdef PLAYBACK_VOICE | 3337 | #ifdef PLAYBACK_VOICE |
3325 | voice_stop(); | 3338 | voice_stop(); |
3326 | #endif | 3339 | #endif |
3327 | buffer_release_buffer(0); | 3340 | if (audiobuf_handle > 0) |
3341 | audiobuf_handle = core_free(audiobuf_handle); | ||
3328 | } | 3342 | } |
3329 | 3343 | ||
3330 | /* Resume playback if paused */ | 3344 | /* Resume playback if paused */ |
@@ -3447,6 +3461,14 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) | |||
3447 | return NULL; | 3461 | return NULL; |
3448 | } | 3462 | } |
3449 | 3463 | ||
3464 | /* make sure buffer is freed and re-allocated to simplify code below | ||
3465 | * (audio_hard_stop() likely has done that already) */ | ||
3466 | if (audiobuf_handle > 0) | ||
3467 | audiobuf_handle = core_free(audiobuf_handle); | ||
3468 | |||
3469 | audiobuf_handle = core_alloc_maximum("audiobuf", &filebuflen, &ops); | ||
3470 | buf = core_get_data(audiobuf_handle); | ||
3471 | |||
3450 | if (talk_buf || buffer_state == AUDIOBUF_STATE_TRASHED | 3472 | if (talk_buf || buffer_state == AUDIOBUF_STATE_TRASHED |
3451 | || !talk_voice_required()) | 3473 | || !talk_voice_required()) |
3452 | { | 3474 | { |
@@ -3464,27 +3486,24 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) | |||
3464 | talk_buffer_steal(); | 3486 | talk_buffer_steal(); |
3465 | buffer_state = AUDIOBUF_STATE_TRASHED; | 3487 | buffer_state = AUDIOBUF_STATE_TRASHED; |
3466 | } | 3488 | } |
3467 | buf = buffer_get_buffer(buffer_size); | ||
3468 | } | 3489 | } |
3469 | else | 3490 | else |
3470 | { | 3491 | { |
3492 | logf("get buffer: audio"); | ||
3471 | /* Safe to just return this if already AUDIOBUF_STATE_VOICED_ONLY or | 3493 | /* Safe to just return this if already AUDIOBUF_STATE_VOICED_ONLY or |
3472 | still AUDIOBUF_STATE_INITIALIZED */ | 3494 | still AUDIOBUF_STATE_INITIALIZED */ |
3473 | /* Skip talk buffer and move pcm buffer to end to maximize available | 3495 | /* Skip talk buffer and move pcm buffer to end to maximize available |
3474 | contiguous memory - no audio running means voice will not need the | 3496 | contiguous memory - no audio running means voice will not need the |
3475 | swap space */ | 3497 | swap space */ |
3476 | size_t siz, talkbuf_size; | 3498 | size_t talkbuf_size; |
3477 | logf("get buffer: audio"); | ||
3478 | /* call buffer_get_buffer() to make use of the locking mechanism */ | ||
3479 | buf = buffer_get_buffer(&siz); | ||
3480 | buf += talkbuf_size = talkbuf_init(buf); | 3499 | buf += talkbuf_size = talkbuf_init(buf); |
3481 | siz -= talkbuf_size; | 3500 | filebuflen -= talkbuf_size; |
3482 | siz -= voicebuf_init(buf + siz); | 3501 | filebuflen -= voicebuf_init(buf + filebuflen); |
3483 | *buffer_size = siz; | ||
3484 | 3502 | ||
3485 | buffer_state = AUDIOBUF_STATE_VOICED_ONLY; | 3503 | buffer_state = AUDIOBUF_STATE_VOICED_ONLY; |
3486 | } | 3504 | } |
3487 | 3505 | ||
3506 | *buffer_size = filebuflen; | ||
3488 | return buf; | 3507 | return buf; |
3489 | } | 3508 | } |
3490 | 3509 | ||
@@ -3492,11 +3511,8 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) | |||
3492 | /* Stop audio, voice and obtain all available buffer space */ | 3511 | /* Stop audio, voice and obtain all available buffer space */ |
3493 | unsigned char * audio_get_recording_buffer(size_t *buffer_size) | 3512 | unsigned char * audio_get_recording_buffer(size_t *buffer_size) |
3494 | { | 3513 | { |
3495 | talk_buffer_steal(); | ||
3496 | audio_hard_stop(); | 3514 | audio_hard_stop(); |
3497 | 3515 | return audio_get_buffer(true, buffer_size); | |
3498 | buffer_state = AUDIOBUF_STATE_TRASHED; | ||
3499 | return buffer_get_buffer(buffer_size); | ||
3500 | } | 3516 | } |
3501 | #endif /* HAVE_RECORDING */ | 3517 | #endif /* HAVE_RECORDING */ |
3502 | 3518 | ||
diff --git a/apps/playlist.c b/apps/playlist.c index 3d3b5f44f8..77d8141af8 100644 --- a/apps/playlist.c +++ b/apps/playlist.c | |||
@@ -84,7 +84,7 @@ | |||
84 | #include "status.h" | 84 | #include "status.h" |
85 | #include "applimits.h" | 85 | #include "applimits.h" |
86 | #include "screens.h" | 86 | #include "screens.h" |
87 | #include "buffer.h" | 87 | #include "core_alloc.h" |
88 | #include "misc.h" | 88 | #include "misc.h" |
89 | #include "filefuncs.h" | 89 | #include "filefuncs.h" |
90 | #include "button.h" | 90 | #include "button.h" |
@@ -1929,6 +1929,7 @@ static int rotate_index(const struct playlist_info* playlist, int index) | |||
1929 | */ | 1929 | */ |
1930 | void playlist_init(void) | 1930 | void playlist_init(void) |
1931 | { | 1931 | { |
1932 | int handle; | ||
1932 | struct playlist_info* playlist = ¤t_playlist; | 1933 | struct playlist_info* playlist = ¤t_playlist; |
1933 | 1934 | ||
1934 | mutex_init(¤t_playlist_mutex); | 1935 | mutex_init(¤t_playlist_mutex); |
@@ -1940,18 +1941,19 @@ void playlist_init(void) | |||
1940 | playlist->fd = -1; | 1941 | playlist->fd = -1; |
1941 | playlist->control_fd = -1; | 1942 | playlist->control_fd = -1; |
1942 | playlist->max_playlist_size = global_settings.max_files_in_playlist; | 1943 | playlist->max_playlist_size = global_settings.max_files_in_playlist; |
1943 | playlist->indices = buffer_alloc( | 1944 | handle = core_alloc("playlist idx", playlist->max_playlist_size * sizeof(int)); |
1944 | playlist->max_playlist_size * sizeof(int)); | 1945 | playlist->indices = core_get_data(handle); |
1945 | playlist->buffer_size = | 1946 | playlist->buffer_size = |
1946 | AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir; | 1947 | AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir; |
1947 | playlist->buffer = buffer_alloc(playlist->buffer_size); | 1948 | handle = core_alloc("playlist buf", playlist->buffer_size); |
1949 | playlist->buffer = core_get_data(handle); | ||
1948 | playlist->control_mutex = ¤t_playlist_mutex; | 1950 | playlist->control_mutex = ¤t_playlist_mutex; |
1949 | 1951 | ||
1950 | empty_playlist(playlist, true); | 1952 | empty_playlist(playlist, true); |
1951 | 1953 | ||
1952 | #ifdef HAVE_DIRCACHE | 1954 | #ifdef HAVE_DIRCACHE |
1953 | playlist->filenames = buffer_alloc( | 1955 | handle = core_alloc("playlist dc", playlist->max_playlist_size * sizeof(int)); |
1954 | playlist->max_playlist_size * sizeof(int)); | 1956 | playlist->filenames = core_get_data(handle); |
1955 | memset(playlist->filenames, 0xff, | 1957 | memset(playlist->filenames, 0xff, |
1956 | playlist->max_playlist_size * sizeof(int)); | 1958 | playlist->max_playlist_size * sizeof(int)); |
1957 | create_thread(playlist_thread, playlist_stack, sizeof(playlist_stack), | 1959 | create_thread(playlist_thread, playlist_stack, sizeof(playlist_stack), |
@@ -3356,7 +3358,6 @@ int playlist_save(struct playlist_info* playlist, char *filename) | |||
3356 | char tmp_buf[MAX_PATH+1]; | 3358 | char tmp_buf[MAX_PATH+1]; |
3357 | int result = 0; | 3359 | int result = 0; |
3358 | bool overwrite_current = false; | 3360 | bool overwrite_current = false; |
3359 | int* index_buf = NULL; | ||
3360 | char* old_buffer = NULL; | 3361 | char* old_buffer = NULL; |
3361 | size_t old_buffer_size = 0; | 3362 | size_t old_buffer_size = 0; |
3362 | 3363 | ||
@@ -3391,10 +3392,6 @@ int playlist_save(struct playlist_info* playlist, char *filename) | |||
3391 | } | 3392 | } |
3392 | } | 3393 | } |
3393 | 3394 | ||
3394 | /* in_ram buffer is unused for m3u files so we'll use for storing | ||
3395 | updated indices */ | ||
3396 | index_buf = (int*)playlist->buffer; | ||
3397 | |||
3398 | /* use temporary pathname */ | 3395 | /* use temporary pathname */ |
3399 | snprintf(path, sizeof(path), "%s_temp", playlist->filename); | 3396 | snprintf(path, sizeof(path), "%s_temp", playlist->filename); |
3400 | overwrite_current = true; | 3397 | overwrite_current = true; |
@@ -3453,7 +3450,7 @@ int playlist_save(struct playlist_info* playlist, char *filename) | |||
3453 | } | 3450 | } |
3454 | 3451 | ||
3455 | if (overwrite_current) | 3452 | if (overwrite_current) |
3456 | index_buf[count] = lseek(fd, 0, SEEK_CUR); | 3453 | playlist->seek_buf[count] = lseek(fd, 0, SEEK_CUR); |
3457 | 3454 | ||
3458 | if (fdprintf(fd, "%s\n", tmp_buf) < 0) | 3455 | if (fdprintf(fd, "%s\n", tmp_buf) < 0) |
3459 | { | 3456 | { |
@@ -3498,7 +3495,7 @@ int playlist_save(struct playlist_info* playlist, char *filename) | |||
3498 | { | 3495 | { |
3499 | if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK)) | 3496 | if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK)) |
3500 | { | 3497 | { |
3501 | playlist->indices[index] = index_buf[count]; | 3498 | playlist->indices[index] = playlist->seek_buf[count]; |
3502 | count++; | 3499 | count++; |
3503 | } | 3500 | } |
3504 | index = (index+1)%playlist->amount; | 3501 | index = (index+1)%playlist->amount; |
diff --git a/apps/playlist.h b/apps/playlist.h index d994f6e800..f14b5c6460 100644 --- a/apps/playlist.h +++ b/apps/playlist.h | |||
@@ -85,7 +85,11 @@ struct playlist_info | |||
85 | int max_playlist_size; /* Max number of files in playlist. Mirror of | 85 | int max_playlist_size; /* Max number of files in playlist. Mirror of |
86 | global_settings.max_files_in_playlist */ | 86 | global_settings.max_files_in_playlist */ |
87 | bool in_ram; /* playlist stored in ram (dirplay) */ | 87 | bool in_ram; /* playlist stored in ram (dirplay) */ |
88 | char *buffer; /* buffer for in-ram playlists */ | 88 | |
89 | union { | ||
90 | char *buffer; /* buffer for in-ram playlists */ | ||
91 | int *seek_buf; /* buffer for seeks in real playlists */ | ||
92 | }; | ||
89 | int buffer_size; /* size of buffer */ | 93 | int buffer_size; /* size of buffer */ |
90 | int buffer_end_pos; /* last position where buffer was written */ | 94 | int buffer_end_pos; /* last position where buffer was written */ |
91 | int index; /* index of current playing track */ | 95 | int index; /* index of current playing track */ |
diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 6ed9bbb037..a6307d5dd7 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c | |||
@@ -30,7 +30,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging | |||
30 | #include "metadata.h" | 30 | #include "metadata.h" |
31 | #include "kernel.h" | 31 | #include "kernel.h" |
32 | #include "audio.h" | 32 | #include "audio.h" |
33 | #include "buffer.h" | 33 | #include "core_alloc.h" |
34 | #include "settings.h" | 34 | #include "settings.h" |
35 | #include "ata_idle_notify.h" | 35 | #include "ata_idle_notify.h" |
36 | #include "filefuncs.h" | 36 | #include "filefuncs.h" |
@@ -52,7 +52,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging | |||
52 | /* longest entry I've had is 323, add a safety margin */ | 52 | /* longest entry I've had is 323, add a safety margin */ |
53 | #define SCROBBLER_CACHE_LEN 512 | 53 | #define SCROBBLER_CACHE_LEN 512 |
54 | 54 | ||
55 | static char* scrobbler_cache; | 55 | static int scrobbler_cache; |
56 | 56 | ||
57 | static int cache_pos; | 57 | static int cache_pos; |
58 | static struct mp3entry scrobbler_entry; | 58 | static struct mp3entry scrobbler_entry; |
@@ -139,11 +139,16 @@ static void write_cache(void) | |||
139 | if(fd >= 0) | 139 | if(fd >= 0) |
140 | { | 140 | { |
141 | logf("SCROBBLER: writing %d entries", cache_pos); | 141 | logf("SCROBBLER: writing %d entries", cache_pos); |
142 | 142 | /* copy data to temporary storage in case data moves during I/O */ | |
143 | char temp_buf[SCROBBLER_CACHE_LEN]; | ||
143 | for ( i=0; i < cache_pos; i++ ) | 144 | for ( i=0; i < cache_pos; i++ ) |
144 | { | 145 | { |
145 | logf("SCROBBLER: write %d", i); | 146 | logf("SCROBBLER: write %d", i); |
146 | fdprintf(fd, "%s", scrobbler_cache+(SCROBBLER_CACHE_LEN*i)); | 147 | char* scrobbler_buf = core_get_data(scrobbler_cache); |
148 | ssize_t len = strlcpy(temp_buf, scrobbler_buf+(SCROBBLER_CACHE_LEN*i), | ||
149 | sizeof(temp_buf)); | ||
150 | if (write(fd, temp_buf, len) != len) | ||
151 | break; | ||
147 | } | 152 | } |
148 | close(fd); | 153 | close(fd); |
149 | } | 154 | } |
@@ -170,6 +175,7 @@ static void add_to_cache(unsigned long play_length) | |||
170 | 175 | ||
171 | int ret; | 176 | int ret; |
172 | char rating = 'S'; /* Skipped */ | 177 | char rating = 'S'; /* Skipped */ |
178 | char* scrobbler_buf = core_get_data(scrobbler_cache); | ||
173 | 179 | ||
174 | logf("SCROBBLER: add_to_cache[%d]", cache_pos); | 180 | logf("SCROBBLER: add_to_cache[%d]", cache_pos); |
175 | 181 | ||
@@ -178,7 +184,7 @@ static void add_to_cache(unsigned long play_length) | |||
178 | 184 | ||
179 | if (scrobbler_entry.tracknum > 0) | 185 | if (scrobbler_entry.tracknum > 0) |
180 | { | 186 | { |
181 | ret = snprintf(scrobbler_cache+(SCROBBLER_CACHE_LEN*cache_pos), | 187 | ret = snprintf(scrobbler_buf+(SCROBBLER_CACHE_LEN*cache_pos), |
182 | SCROBBLER_CACHE_LEN, | 188 | SCROBBLER_CACHE_LEN, |
183 | "%s\t%s\t%s\t%d\t%d\t%c\t%ld\t%s\n", | 189 | "%s\t%s\t%s\t%d\t%d\t%c\t%ld\t%s\n", |
184 | scrobbler_entry.artist, | 190 | scrobbler_entry.artist, |
@@ -190,7 +196,7 @@ static void add_to_cache(unsigned long play_length) | |||
190 | (long)timestamp, | 196 | (long)timestamp, |
191 | scrobbler_entry.mb_track_id?scrobbler_entry.mb_track_id:""); | 197 | scrobbler_entry.mb_track_id?scrobbler_entry.mb_track_id:""); |
192 | } else { | 198 | } else { |
193 | ret = snprintf(scrobbler_cache+(SCROBBLER_CACHE_LEN*cache_pos), | 199 | ret = snprintf(scrobbler_buf+(SCROBBLER_CACHE_LEN*cache_pos), |
194 | SCROBBLER_CACHE_LEN, | 200 | SCROBBLER_CACHE_LEN, |
195 | "%s\t%s\t%s\t\t%d\t%c\t%ld\t%s\n", | 201 | "%s\t%s\t%s\t\t%d\t%c\t%ld\t%s\n", |
196 | scrobbler_entry.artist, | 202 | scrobbler_entry.artist, |
@@ -248,7 +254,7 @@ int scrobbler_init(void) | |||
248 | if(!global_settings.audioscrobbler) | 254 | if(!global_settings.audioscrobbler) |
249 | return -1; | 255 | return -1; |
250 | 256 | ||
251 | scrobbler_cache = buffer_alloc(SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); | 257 | scrobbler_cache = core_alloc("scrobbler", SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); |
252 | 258 | ||
253 | add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, scrobbler_change_event); | 259 | add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, scrobbler_change_event); |
254 | cache_pos = 0; | 260 | cache_pos = 0; |
diff --git a/apps/tagcache.c b/apps/tagcache.c index 52e059a04a..753675f906 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c | |||
@@ -74,7 +74,7 @@ | |||
74 | #include "usb.h" | 74 | #include "usb.h" |
75 | #include "metadata.h" | 75 | #include "metadata.h" |
76 | #include "tagcache.h" | 76 | #include "tagcache.h" |
77 | #include "buffer.h" | 77 | #include "core_alloc.h" |
78 | #include "crc32.h" | 78 | #include "crc32.h" |
79 | #include "misc.h" | 79 | #include "misc.h" |
80 | #include "settings.h" | 80 | #include "settings.h" |
@@ -3082,6 +3082,7 @@ static bool commit(void) | |||
3082 | return true; | 3082 | return true; |
3083 | } | 3083 | } |
3084 | 3084 | ||
3085 | static int tempbuf_handle; | ||
3085 | static void allocate_tempbuf(void) | 3086 | static void allocate_tempbuf(void) |
3086 | { | 3087 | { |
3087 | /* Yeah, malloc would be really nice now :) */ | 3088 | /* Yeah, malloc would be really nice now :) */ |
@@ -3089,7 +3090,8 @@ static void allocate_tempbuf(void) | |||
3089 | tempbuf_size = 32*1024*1024; | 3090 | tempbuf_size = 32*1024*1024; |
3090 | tempbuf = malloc(tempbuf_size); | 3091 | tempbuf = malloc(tempbuf_size); |
3091 | #else | 3092 | #else |
3092 | tempbuf = buffer_get_buffer(&tempbuf_size); | 3093 | tempbuf_handle = core_alloc_maximum("tc tempbuf", &tempbuf_size, NULL); |
3094 | tempbuf = core_get_data(tempbuf_handle); | ||
3093 | #endif | 3095 | #endif |
3094 | } | 3096 | } |
3095 | 3097 | ||
@@ -3101,7 +3103,7 @@ static void free_tempbuf(void) | |||
3101 | #ifdef __PCTOOL__ | 3103 | #ifdef __PCTOOL__ |
3102 | free(tempbuf); | 3104 | free(tempbuf); |
3103 | #else | 3105 | #else |
3104 | buffer_release_buffer(0); | 3106 | tempbuf_handle = core_free(tempbuf_handle); |
3105 | #endif | 3107 | #endif |
3106 | tempbuf = NULL; | 3108 | tempbuf = NULL; |
3107 | tempbuf_size = 0; | 3109 | tempbuf_size = 0; |
@@ -3829,9 +3831,10 @@ static bool allocate_tagcache(void) | |||
3829 | * Now calculate the required cache size plus | 3831 | * Now calculate the required cache size plus |
3830 | * some extra space for alignment fixes. | 3832 | * some extra space for alignment fixes. |
3831 | */ | 3833 | */ |
3832 | tc_stat.ramcache_allocated = tcmh.tch.datasize + 128 + TAGCACHE_RESERVE + | 3834 | tc_stat.ramcache_allocated = tcmh.tch.datasize + 256 + TAGCACHE_RESERVE + |
3833 | sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); | 3835 | sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); |
3834 | ramcache_hdr = buffer_alloc(tc_stat.ramcache_allocated + 128); | 3836 | int handle = core_alloc("tc ramcache", tc_stat.ramcache_allocated); |
3837 | ramcache_hdr = core_get_data(handle); | ||
3835 | memset(ramcache_hdr, 0, sizeof(struct ramcache_header)); | 3838 | memset(ramcache_hdr, 0, sizeof(struct ramcache_header)); |
3836 | memcpy(¤t_tcmh, &tcmh, sizeof current_tcmh); | 3839 | memcpy(¤t_tcmh, &tcmh, sizeof current_tcmh); |
3837 | logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated); | 3840 | logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated); |
@@ -3845,7 +3848,7 @@ static bool tagcache_dumpload(void) | |||
3845 | struct statefile_header shdr; | 3848 | struct statefile_header shdr; |
3846 | int fd, rc; | 3849 | int fd, rc; |
3847 | long offpos; | 3850 | long offpos; |
3848 | int i; | 3851 | int i, handle; |
3849 | 3852 | ||
3850 | fd = open(TAGCACHE_STATEFILE, O_RDONLY); | 3853 | fd = open(TAGCACHE_STATEFILE, O_RDONLY); |
3851 | if (fd < 0) | 3854 | if (fd < 0) |
@@ -3855,7 +3858,6 @@ static bool tagcache_dumpload(void) | |||
3855 | } | 3858 | } |
3856 | 3859 | ||
3857 | /* Check the statefile memory placement */ | 3860 | /* Check the statefile memory placement */ |
3858 | ramcache_hdr = buffer_alloc(0); | ||
3859 | rc = read(fd, &shdr, sizeof(struct statefile_header)); | 3861 | rc = read(fd, &shdr, sizeof(struct statefile_header)); |
3860 | if (rc != sizeof(struct statefile_header) | 3862 | if (rc != sizeof(struct statefile_header) |
3861 | || shdr.magic != TAGCACHE_STATEFILE_MAGIC | 3863 | || shdr.magic != TAGCACHE_STATEFILE_MAGIC |
@@ -3867,13 +3869,14 @@ static bool tagcache_dumpload(void) | |||
3867 | return false; | 3869 | return false; |
3868 | } | 3870 | } |
3869 | 3871 | ||
3870 | offpos = (long)ramcache_hdr - (long)shdr.hdr; | ||
3871 | 3872 | ||
3872 | /* Lets allocate real memory and load it */ | 3873 | /* Lets allocate real memory and load it */ |
3873 | ramcache_hdr = buffer_alloc(shdr.tc_stat.ramcache_allocated); | 3874 | handle = core_alloc("tc ramcache", shdr.tc_stat.ramcache_allocated); |
3875 | ramcache_hdr = core_get_data(handle); | ||
3874 | rc = read(fd, ramcache_hdr, shdr.tc_stat.ramcache_allocated); | 3876 | rc = read(fd, ramcache_hdr, shdr.tc_stat.ramcache_allocated); |
3875 | close(fd); | 3877 | close(fd); |
3876 | 3878 | ||
3879 | offpos = (long)ramcache_hdr - (long)shdr.hdr; | ||
3877 | if (rc != shdr.tc_stat.ramcache_allocated) | 3880 | if (rc != shdr.tc_stat.ramcache_allocated) |
3878 | { | 3881 | { |
3879 | logf("read failure!"); | 3882 | logf("read failure!"); |
diff --git a/apps/tagtree.c b/apps/tagtree.c index 5012c084d0..0d4330bac8 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c | |||
@@ -44,7 +44,7 @@ | |||
44 | #include "playlist.h" | 44 | #include "playlist.h" |
45 | #include "keyboard.h" | 45 | #include "keyboard.h" |
46 | #include "gui/list.h" | 46 | #include "gui/list.h" |
47 | #include "buffer.h" | 47 | #include "core_alloc.h" |
48 | #include "yesno.h" | 48 | #include "yesno.h" |
49 | #include "misc.h" | 49 | #include "misc.h" |
50 | #include "filetypes.h" | 50 | #include "filetypes.h" |
@@ -176,9 +176,14 @@ static int current_entry_count; | |||
176 | static struct tree_context *tc; | 176 | static struct tree_context *tc; |
177 | 177 | ||
178 | /* a few memory alloc helper */ | 178 | /* a few memory alloc helper */ |
179 | static int tagtree_handle; | ||
180 | static size_t tagtree_bufsize, tagtree_buf_used; | ||
179 | static void* tagtree_alloc(size_t size) | 181 | static void* tagtree_alloc(size_t size) |
180 | { | 182 | { |
181 | return buffer_alloc(size); | 183 | char* buf = core_get_data(tagtree_handle) + tagtree_buf_used; |
184 | size = ALIGN_UP(size, sizeof(void*)); | ||
185 | tagtree_buf_used += size; | ||
186 | return buf; | ||
182 | } | 187 | } |
183 | 188 | ||
184 | static void* tagtree_alloc0(size_t size) | 189 | static void* tagtree_alloc0(size_t size) |
@@ -1035,6 +1040,7 @@ void tagtree_init(void) | |||
1035 | menu_count = 0; | 1040 | menu_count = 0; |
1036 | menu = NULL; | 1041 | menu = NULL; |
1037 | rootmenu = -1; | 1042 | rootmenu = -1; |
1043 | tagtree_handle = core_alloc_maximum("tagtree", &tagtree_bufsize, NULL); | ||
1038 | parse_menu(FILE_SEARCH_INSTRUCTIONS); | 1044 | parse_menu(FILE_SEARCH_INSTRUCTIONS); |
1039 | 1045 | ||
1040 | /* If no root menu is set, assume it's the first single menu | 1046 | /* If no root menu is set, assume it's the first single menu |
@@ -1046,6 +1052,8 @@ void tagtree_init(void) | |||
1046 | 1052 | ||
1047 | add_event(PLAYBACK_EVENT_TRACK_BUFFER, false, tagtree_buffer_event); | 1053 | add_event(PLAYBACK_EVENT_TRACK_BUFFER, false, tagtree_buffer_event); |
1048 | add_event(PLAYBACK_EVENT_TRACK_FINISH, false, tagtree_track_finish_event); | 1054 | add_event(PLAYBACK_EVENT_TRACK_FINISH, false, tagtree_track_finish_event); |
1055 | |||
1056 | core_shrink(tagtree_handle, core_get_data(tagtree_handle), tagtree_buf_used); | ||
1049 | } | 1057 | } |
1050 | 1058 | ||
1051 | static bool show_search_progress(bool init, int count) | 1059 | static bool show_search_progress(bool init, int count) |
diff --git a/apps/talk.c b/apps/talk.c index 0c3b769d82..29657385a7 100644 --- a/apps/talk.c +++ b/apps/talk.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <stddef.h> | 27 | #include <stddef.h> |
28 | #include "string-extra.h" | 28 | #include "string-extra.h" |
29 | #include "file.h" | 29 | #include "file.h" |
30 | #include "buffer.h" | ||
31 | #include "system.h" | 30 | #include "system.h" |
32 | #include "kernel.h" | 31 | #include "kernel.h" |
33 | #include "settings.h" | 32 | #include "settings.h" |
@@ -711,7 +710,7 @@ void talk_init(void) | |||
711 | 710 | ||
712 | 711 | ||
713 | /* test if we can open and if it fits in the audiobuffer */ | 712 | /* test if we can open and if it fits in the audiobuffer */ |
714 | size_t audiobufsz = buffer_available(); | 713 | size_t audiobufsz = audio_buffer_available(); |
715 | if (voicefile_size <= audiobufsz) { | 714 | if (voicefile_size <= audiobufsz) { |
716 | has_voicefile = true; | 715 | has_voicefile = true; |
717 | } else { | 716 | } else { |
diff --git a/apps/tdspeed.c b/apps/tdspeed.c index b940c928fc..476995a271 100644 --- a/apps/tdspeed.c +++ b/apps/tdspeed.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <stdio.h> | 25 | #include <stdio.h> |
26 | #include <string.h> | 26 | #include <string.h> |
27 | #include "sound.h" | 27 | #include "sound.h" |
28 | #include "buffer.h" | 28 | #include "core_alloc.h" |
29 | #include "system.h" | 29 | #include "system.h" |
30 | #include "tdspeed.h" | 30 | #include "tdspeed.h" |
31 | #include "settings.h" | 31 | #include "settings.h" |
@@ -56,21 +56,32 @@ static int32_t *outbuf[2] = { NULL, NULL }; | |||
56 | 56 | ||
57 | void tdspeed_init(void) | 57 | void tdspeed_init(void) |
58 | { | 58 | { |
59 | int handle; | ||
60 | |||
59 | if (!global_settings.timestretch_enabled) | 61 | if (!global_settings.timestretch_enabled) |
60 | return; | 62 | return; |
61 | 63 | ||
62 | /* Allocate buffers */ | 64 | /* Allocate buffers */ |
63 | if (overlap_buffer[0] == NULL) | 65 | if (overlap_buffer[0] == NULL) |
64 | overlap_buffer[0] = (int32_t *)buffer_alloc(FIXED_BUFSIZE * sizeof(int32_t)); | 66 | { |
65 | 67 | handle = core_alloc("tdspeed ovl left", FIXED_BUFSIZE * sizeof(int32_t)); | |
68 | overlap_buffer[0] = core_get_data(handle); | ||
69 | } | ||
66 | if (overlap_buffer[1] == NULL) | 70 | if (overlap_buffer[1] == NULL) |
67 | overlap_buffer[1] = (int32_t *)buffer_alloc(FIXED_BUFSIZE * sizeof(int32_t)); | 71 | { |
68 | 72 | handle = core_alloc("tdspeed ovl right", FIXED_BUFSIZE * sizeof(int32_t)); | |
73 | overlap_buffer[1] = core_get_data(handle); | ||
74 | } | ||
69 | if (outbuf[0] == NULL) | 75 | if (outbuf[0] == NULL) |
70 | outbuf[0] = (int32_t *)buffer_alloc(TDSPEED_OUTBUFSIZE * sizeof(int32_t)); | 76 | { |
71 | 77 | handle = core_alloc("tdspeed left", TDSPEED_OUTBUFSIZE * sizeof(int32_t)); | |
78 | outbuf[0] = core_get_data(handle); | ||
79 | } | ||
72 | if (outbuf[1] == NULL) | 80 | if (outbuf[1] == NULL) |
73 | outbuf[1] = (int32_t *)buffer_alloc(TDSPEED_OUTBUFSIZE * sizeof(int32_t)); | 81 | { |
82 | handle = core_alloc("tdspeed right", TDSPEED_OUTBUFSIZE * sizeof(int32_t)); | ||
83 | outbuf[1] = core_get_data(handle); | ||
84 | } | ||
74 | } | 85 | } |
75 | 86 | ||
76 | 87 | ||
diff --git a/apps/tree.c b/apps/tree.c index e981aeecfc..211ddb2f9b 100644 --- a/apps/tree.c +++ b/apps/tree.c | |||
@@ -46,7 +46,7 @@ | |||
46 | #include "keyboard.h" | 46 | #include "keyboard.h" |
47 | #include "bookmark.h" | 47 | #include "bookmark.h" |
48 | #include "onplay.h" | 48 | #include "onplay.h" |
49 | #include "buffer.h" | 49 | #include "core_alloc.h" |
50 | #include "power.h" | 50 | #include "power.h" |
51 | #include "action.h" | 51 | #include "action.h" |
52 | #include "talk.h" | 52 | #include "talk.h" |
@@ -1002,6 +1002,7 @@ int rockbox_browse(struct browse_context *browse) | |||
1002 | void tree_mem_init(void) | 1002 | void tree_mem_init(void) |
1003 | { | 1003 | { |
1004 | /* initialize tree context struct */ | 1004 | /* initialize tree context struct */ |
1005 | int handle; | ||
1005 | struct tree_cache* cache = &tc.cache; | 1006 | struct tree_cache* cache = &tc.cache; |
1006 | memset(&tc, 0, sizeof(tc)); | 1007 | memset(&tc, 0, sizeof(tc)); |
1007 | tc.dirfilter = &global_settings.dirfilter; | 1008 | tc.dirfilter = &global_settings.dirfilter; |
@@ -1009,10 +1010,12 @@ void tree_mem_init(void) | |||
1009 | 1010 | ||
1010 | cache->name_buffer_size = AVERAGE_FILENAME_LENGTH * | 1011 | cache->name_buffer_size = AVERAGE_FILENAME_LENGTH * |
1011 | global_settings.max_files_in_dir; | 1012 | global_settings.max_files_in_dir; |
1012 | cache->name_buffer = buffer_alloc(cache->name_buffer_size); | 1013 | handle = core_alloc("tree names", cache->name_buffer_size); |
1014 | cache->name_buffer = core_get_data(handle); | ||
1013 | 1015 | ||
1014 | cache->max_entries = global_settings.max_files_in_dir; | 1016 | cache->max_entries = global_settings.max_files_in_dir; |
1015 | cache->entries = buffer_alloc(cache->max_entries*(sizeof(struct entry))); | 1017 | handle = core_alloc("tree entries", cache->max_entries*(sizeof(struct entry))); |
1018 | cache->entries = core_get_data(handle); | ||
1016 | tree_get_filetypes(&filetypes, &filetypes_count); | 1019 | tree_get_filetypes(&filetypes, &filetypes_count); |
1017 | } | 1020 | } |
1018 | 1021 | ||