diff options
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 9e4621b..fb8575e 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -79,6 +79,7 @@ #include "peakmeter.h" #endif #include "logfdisp.h" +#include "core_alloc.h" #if CONFIG_CODEC == SWCODEC #include "pcmbuf.h" #include "buffering.h" @@ -416,6 +417,22 @@ static bool dbg_buffering_thread(void) #endif /* CONFIG_CODEC */ #endif /* HAVE_LCD_BITMAP */ +static const char* bf_getname(int selected_item, void *data, + char *buffer, size_t buffer_len) +{ + (void)data; + core_print_block_at(selected_item, buffer, buffer_len); + return buffer; +} + +static bool dbg_buflib_allocs(void) +{ + struct simplelist_info info; + simplelist_info_init(&info, "mem allocs", core_get_num_blocks(), NULL); + info.get_name = bf_getname; + return simplelist_show_list(&info); +} + #if (CONFIG_PLATFORM & PLATFORM_NATIVE) static const char* dbg_partitions_getname(int selected_item, void *data, char *buffer, size_t buffer_len) @@ -2040,6 +2057,7 @@ static const struct the_menu_item menuitems[] = { { "pm histogram", peak_meter_histogram}, #endif /* PM_DEBUG */ #endif /* HAVE_LCD_BITMAP */ + { "View buflib allocs", dbg_buflib_allocs }, #ifndef SIMULATOR #if CONFIG_TUNER { "FM Radio", dbg_fm_radio }, @@ -30,7 +30,7 @@ #include "settings.h" #include "replaygain.h" #include "tdspeed.h" -#include "buffer.h" +#include "core_alloc.h" #include "fixedpoint.h" #include "fracmul.h" @@ -325,10 +325,16 @@ void dsp_timestretch_enable(bool enabled) { if (enabled) { + int handle; /* Set up timestretch buffers */ big_sample_buf_count = SMALL_SAMPLE_BUF_COUNT * RESAMPLE_RATIO; big_sample_buf = small_resample_buf; - big_resample_buf = (int32_t *) buffer_alloc(big_sample_buf_count * RESAMPLE_RATIO * sizeof(int32_t)); + handle = core_alloc("resample buf", + big_sample_buf_count * RESAMPLE_RATIO * sizeof(int32_t)); + if (handle > 0) + big_resample_buf = core_get_data(handle); + else + big_sample_buf_count = 0; } else { diff --git a/apps/filetypes.c b/apps/filetypes.c index 17a16db..c52c734 100644 --- a/apps/filetypes.c +++ b/apps/filetypes.c @@ -36,7 +36,7 @@ #include "dir.h" #include "file.h" #include "splash.h" -#include "buffer.h" +#include "core_alloc.h" #include "icons.h" #include "logf.h" @@ -183,12 +183,14 @@ static int filetype_count = 0; static unsigned char highest_attr = 0; static int viewer_count = 0; +static int strdup_handle, strdup_bufsize, strdup_cur_idx; static char *filetypes_strdup(char* string) { - char *buffer = (char*)buffer_alloc(strlen(string)+1); - strcpy(buffer, string); + char *buffer = core_get_data(strdup_handle) + strdup_cur_idx; + strdup_cur_idx += strlcpy(buffer, string, strdup_bufsize-strdup_cur_idx)+1; return buffer; } + static char *filetypes_store_plugin(char *plugin, int n) { int i; @@ -219,7 +221,7 @@ static int find_extension(const char* extension) } static void read_builtin_types(void); -static void read_config(const char* config_file); +static void read_config(int fd); #ifdef HAVE_LCD_COLOR /* Colors file format is similar to icons: * ext:hex_color @@ -312,16 +314,28 @@ void filetype_init(void) filetypes[0].attr = 0; filetypes[0].icon = Icon_Folder; + /* estimate bufsize with the filesize, will not be larger */ viewer_count = 0; filetype_count = 1; + + int fd = open(VIEWERS_CONFIG, O_RDONLY); + if (fd < 0) + return; + + strdup_bufsize = filesize(fd); + strdup_handle = core_alloc("filetypes", strdup_bufsize); + if (strdup_handle <= 0) + return; read_builtin_types(); - read_config(VIEWERS_CONFIG); + read_config(fd); #ifdef HAVE_LCD_BITMAP read_viewer_theme_file(); #endif #ifdef HAVE_LCD_COLOR read_color_theme_file(); #endif + close(fd); + core_shrink(strdup_handle, core_get_data(strdup_handle), strdup_cur_idx); } /* remove all white spaces from string */ @@ -355,13 +369,10 @@ static void read_builtin_types(void) } } -static void read_config(const char* config_file) +static void read_config(int fd) { char line[64], *s, *e; char *extension, *plugin; - int fd = open(config_file, O_RDONLY); - if (fd < 0) - return; /* config file is in the format <extension>,<plugin>,<icon code> 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 fbedbb9..d136f90 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) skins_initialising = false; } #else -static char *skin_buffer = NULL; +static char skin_buffer[SKIN_BUFFER_SIZE]; void theme_init_buffer(void) { - skin_buffer = buffer_alloc(SKIN_BUFFER_SIZE); skins_initialising = false; } #endif diff --git a/apps/main.c b/apps/main.c index 9cb7245..cc9c9e8 100644 --- a/apps/main.c +++ b/apps/main.c @@ -53,7 +53,7 @@ #include "language.h" #include "wps.h" #include "playlist.h" -#include "buffer.h" +#include "core_alloc.h" #include "rolo.h" #include "screens.h" #include "usb_screen.h" @@ -337,7 +337,7 @@ static void init_tagcache(void) static void init(void) { system_init(); - buffer_init(); + core_allocator_init(); kernel_init(); #ifdef APPLICATION paths_init(); @@ -400,9 +400,6 @@ static void init(void) global_settings.mdb_shape, global_settings.mdb_enable, global_settings.superbass); - - /* audio_init must to know the size of voice buffer so init voice first */ - talk_init(); #endif /* CONFIG_CODEC != SWCODEC */ scrobbler_init(); @@ -428,7 +425,7 @@ static void init(void) #endif system_init(); - buffer_init(); + core_allocator_init(); kernel_init(); #ifdef HAVE_ADJUSTABLE_CPU_FREQ @@ -684,9 +681,6 @@ static void init(void) global_settings.mdb_shape, global_settings.mdb_enable, global_settings.superbass); - - /* audio_init must to know the size of voice buffer so init voice first */ - talk_init(); #endif /* CONFIG_CODEC != SWCODEC */ CHART(">audio_init"); diff --git a/apps/menus/main_menu.c b/apps/menus/main_menu.c index c5758d1..e88317a 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, case INFO_BUFFER: /* buffer */ { - long kib = buffer_available() / 1024; /* to KiB */ + long kib = audio_buffer_available() / 1024; /* to KiB */ output_dyn_value(s1, sizeof(s1), kib, kbyte_units, true); snprintf(buffer, buffer_len, "%s %s", str(LANG_BUFFER_STAT), s1); } @@ -272,7 +272,7 @@ static int info_speak_item(int selected_item, void * data) case INFO_BUFFER: /* buffer */ { talk_id(LANG_BUFFER_STAT, false); - long kib = buffer_available() / 1024; /* to KiB */ + long kib = audio_buffer_available() / 1024; /* to KiB */ output_dyn_value(NULL, 0, kib, kbyte_units, true); break; } diff --git a/apps/mpeg.c b/apps/mpeg.c index 6dd55b7..595f943 100644 --- a/apps/mpeg.c +++ b/apps/mpeg.c @@ -35,7 +35,7 @@ #include "thread.h" #include "errno.h" #include "mp3data.h" -#include "buffer.h" +#include "core_alloc.h" #include "mp3_playback.h" #include "talk.h" #include "sound.h" @@ -145,7 +145,8 @@ static unsigned int mpeg_errno; static bool playing = false; /* We are playing an MP3 stream */ static bool is_playing = false; /* We are (attempting to) playing MP3 files */ static bool paused; /* playback is paused */ -static char* mpeg_audiobuf; /* the audio buffer */ +static int audiobuf_handle; /* handle to the audio buffer */ +static char* mpeg_audiobuf; /* poiunter to the audio buffer */ static long audiobuflen; /* length of the audio buffer */ #ifdef SIMULATOR @@ -491,15 +492,27 @@ unsigned long mpeg_get_last_header(void) #endif /* !SIMULATOR */ } - +/* Buffer must not move. And not shrink for now */ +static struct buflib_callbacks ops = { NULL, NULL }; unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) { (void)talk_buf; /* always grab the voice buffer for now */ - audio_hard_stop(); if (buffer_size) /* special case for talk_init() */ - return buffer_get_buffer(buffer_size); - return NULL; + { + size_t bufsize; + audio_hard_stop(); + /* audio_hard_stop() frees audiobuf, so re-aquire */ + audiobuf_handle = core_alloc_maximum("audiobuf", &bufsize, &ops); + audiobuflen = bufsize; + *buffer_size = audiobuflen; + } + mpeg_audiobuf = core_get_data(audiobuf_handle); + + if (!buffer_size) /* special case for talk_init() */ + talkbuf_init(mpeg_audiobuf); + + return mpeg_audiobuf; } @@ -2659,17 +2672,26 @@ void audio_set_recording_options(struct audio_recording_options *options) #endif /* SIMULATOR */ #endif /* CONFIG_CODEC == MAS3587F */ +size_t audio_buffer_available(void) +{ + if (audiobuf_handle > 0) + return audiobuflen; + return core_available(); +} + static void audio_reset_buffer(void) { - size_t bufsize; /* dont break strict-aliasing */ talk_buffer_steal(); /* will use the mp3 buffer */ - /* release buffer on behalf of any audio_get_buffer() caller, - * non-fatal if there was none */ - buffer_release_buffer(0); - /* re-aquire */ - mpeg_audiobuf = buffer_get_buffer(&bufsize); - audiobuflen = bufsize; + /* alloc buffer if it's was never allocated or freed by audio_hard_stop() */ + if (!audiobuf_handle) + { + size_t bufsize; /* dont break strict-aliasing */ + audiobuf_handle = core_alloc_maximum("audiobuf", &bufsize, &ops); + mpeg_audiobuf = core_get_data(audiobuf_handle); + audiobuflen = bufsize; + } + talkbuf_init(mpeg_audiobuf); } void audio_play(long offset) @@ -2742,7 +2764,11 @@ void audio_hard_stop(void) audio_stop(); /* tell voice we obtain the buffer before freeing */ talk_buffer_steal(); - buffer_release_buffer(0); + if (audiobuf_handle > 0) + { + audiobuf_handle = core_free(audiobuf_handle); + mpeg_audiobuf = NULL; + } } void audio_pause(void) @@ -2899,13 +2925,15 @@ void audio_init(void) mpeg_errno = 0; /* cuesheet support */ if (global_settings.cuesheet) - curr_cuesheet = (struct cuesheet*)buffer_alloc(sizeof(struct cuesheet)); + { + int handle = core_alloc("cuesheet", sizeof(struct cuesheet)); + if (handle > 0) + curr_cuesheet = core_get_data(handle); + } + + talk_init(); + audio_reset_buffer(); - size_t bufsize; /* don't break strict-aliasing */ - mpeg_audiobuf = buffer_get_buffer(&bufsize); - audiobuflen = bufsize; - /* give voice buffer until we start to play */ - talkbuf_init(mpeg_audiobuf); #ifndef SIMULATOR queue_init(&mpeg_queue, true); #endif /* !SIMULATOR */ diff --git a/apps/playback.c b/apps/playback.c index 7dad086..e35d652 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -24,7 +24,7 @@ #include "system.h" #include "kernel.h" #include "panic.h" -#include "buffer.h" +#include "core_alloc.h" #include "sound.h" #include "ata.h" #include "usb.h" @@ -732,6 +732,18 @@ static void scratch_mem_init(void *mem) } } +/* Buffer must not move. And not shrink for now */ +static struct buflib_callbacks ops = { NULL, NULL }; +static int audiobuf_handle; +static size_t filebuflen; + +size_t audio_buffer_available(void) +{ + if (audiobuf_handle > 0) /* if allocated return what we got */ + return filebuflen; + return core_available(); +} + /* Set up the audio buffer for playback */ static void audio_reset_buffer(void) { @@ -743,16 +755,17 @@ static void audio_reset_buffer(void) /* see audio_get_recording_buffer if this is modified */ logf("%s()", __func__); - /* release the buffer on behalf of any caller of audio_get_buffer() */ - buffer_release_buffer(0); - /* If the setup of anything allocated before the file buffer is changed, do check the adjustments after the buffer_alloc call as it will likely be affected and need sliding over */ /* Initially set up file buffer as all space available */ - size_t filebuflen, allocsize; - unsigned char *filebuf = buffer_get_buffer(&filebuflen); + size_t allocsize; + if (audiobuf_handle > 0) + audiobuf_handle = core_free(audiobuf_handle); + + audiobuf_handle = core_alloc_maximum("audiobuf", &filebuflen, &ops); + unsigned char *filebuf = core_get_data(audiobuf_handle); /* Subtract whatever voice needs */ allocsize = talkbuf_init(filebuf); @@ -3324,7 +3337,8 @@ void audio_hard_stop(void) #ifdef PLAYBACK_VOICE voice_stop(); #endif - buffer_release_buffer(0); + if (audiobuf_handle > 0) + audiobuf_handle = core_free(audiobuf_handle); } /* Resume playback if paused */ @@ -3447,6 +3461,14 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) return NULL; } + /* make sure buffer is freed and re-allocated to simplify code below + * (audio_hard_stop() likely has done that already) */ + if (audiobuf_handle > 0) + audiobuf_handle = core_free(audiobuf_handle); + + audiobuf_handle = core_alloc_maximum("audiobuf", &filebuflen, &ops); + buf = core_get_data(audiobuf_handle); + if (talk_buf || buffer_state == AUDIOBUF_STATE_TRASHED || !talk_voice_required()) { @@ -3464,27 +3486,24 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) talk_buffer_steal(); buffer_state = AUDIOBUF_STATE_TRASHED; } - buf = buffer_get_buffer(buffer_size); } else { + logf("get buffer: audio"); /* Safe to just return this if already AUDIOBUF_STATE_VOICED_ONLY or still AUDIOBUF_STATE_INITIALIZED */ /* Skip talk buffer and move pcm buffer to end to maximize available contiguous memory - no audio running means voice will not need the swap space */ - size_t siz, talkbuf_size; - logf("get buffer: audio"); - /* call buffer_get_buffer() to make use of the locking mechanism */ - buf = buffer_get_buffer(&siz); + size_t talkbuf_size; buf += talkbuf_size = talkbuf_init(buf); - siz -= talkbuf_size; - siz -= voicebuf_init(buf + siz); - *buffer_size = siz; + filebuflen -= talkbuf_size; + filebuflen -= voicebuf_init(buf + filebuflen); buffer_state = AUDIOBUF_STATE_VOICED_ONLY; } + *buffer_size = filebuflen; return buf; } @@ -3492,11 +3511,8 @@ unsigned char * audio_get_buffer(bool talk_buf, size_t *buffer_size) /* Stop audio, voice and obtain all available buffer space */ unsigned char * audio_get_recording_buffer(size_t *buffer_size) { - talk_buffer_steal(); audio_hard_stop(); - - buffer_state = AUDIOBUF_STATE_TRASHED; - return buffer_get_buffer(buffer_size); + return audio_get_buffer(true, buffer_size); } #endif /* HAVE_RECORDING */ diff --git a/apps/playlist.c b/apps/playlist.c index 3d3b5f4..77d8141 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -84,7 +84,7 @@ #include "status.h" #include "applimits.h" #include "screens.h" -#include "buffer.h" +#include "core_alloc.h" #include "misc.h" #include "filefuncs.h" #include "button.h" @@ -1929,6 +1929,7 @@ static int rotate_index(const struct playlist_info* playlist, int index) */ void playlist_init(void) { + int handle; struct playlist_info* playlist = ¤t_playlist; mutex_init(¤t_playlist_mutex); @@ -1940,18 +1941,19 @@ void playlist_init(void) playlist->fd = -1; playlist->control_fd = -1; playlist->max_playlist_size = global_settings.max_files_in_playlist; - playlist->indices = buffer_alloc( - playlist->max_playlist_size * sizeof(int)); + handle = core_alloc("playlist idx", playlist->max_playlist_size * sizeof(int)); + playlist->indices = core_get_data(handle); playlist->buffer_size = AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir; - playlist->buffer = buffer_alloc(playlist->buffer_size); + handle = core_alloc("playlist buf", playlist->buffer_size); + playlist->buffer = core_get_data(handle); playlist->control_mutex = ¤t_playlist_mutex; empty_playlist(playlist, true); #ifdef HAVE_DIRCACHE - playlist->filenames = buffer_alloc( - playlist->max_playlist_size * sizeof(int)); + handle = core_alloc("playlist dc", playlist->max_playlist_size * sizeof(int)); + playlist->filenames = core_get_data(handle); memset(playlist->filenames, 0xff, playlist->max_playlist_size * sizeof(int)); create_thread(playlist_thread, playlist_stack, sizeof(playlist_stack), @@ -3356,7 +3358,6 @@ int playlist_save(struct playlist_info* playlist, char *filename) char tmp_buf[MAX_PATH+1]; int result = 0; bool overwrite_current = false; - int* index_buf = NULL; char* old_buffer = NULL; size_t old_buffer_size = 0; @@ -3391,10 +3392,6 @@ int playlist_save(struct playlist_info* playlist, char *filename) } } - /* in_ram buffer is unused for m3u files so we'll use for storing - updated indices */ - index_buf = (int*)playlist->buffer; - /* use temporary pathname */ snprintf(path, sizeof(path), "%s_temp", playlist->filename); overwrite_current = true; @@ -3453,7 +3450,7 @@ int playlist_save(struct playlist_info* playlist, char *filename) } if (overwrite_current) - index_buf[count] = lseek(fd, 0, SEEK_CUR); + playlist->seek_buf[count] = lseek(fd, 0, SEEK_CUR); if (fdprintf(fd, "%s\n", tmp_buf) < 0) { @@ -3498,7 +3495,7 @@ int playlist_save(struct playlist_info* playlist, char *filename) { if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK)) { - playlist->indices[index] = index_buf[count]; + playlist->indices[index] = playlist->seek_buf[count]; count++; } index = (index+1)%playlist->amount; diff --git a/apps/playlist.h b/apps/playlist.h index d994f6e..f14b5c6 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -85,7 +85,11 @@ struct playlist_info int max_playlist_size; /* Max number of files in playlist. Mirror of global_settings.max_files_in_playlist */ bool in_ram; /* playlist stored in ram (dirplay) */ - char *buffer; /* buffer for in-ram playlists */ + + union { + char *buffer; /* buffer for in-ram playlists */ + int *seek_buf; /* buffer for seeks in real playlists */ + }; int buffer_size; /* size of buffer */ int buffer_end_pos; /* last position where buffer was written */ int index; /* index of current playing track */ diff --git a/apps/scrobbler.c b/apps/scrobbler.c index 6ed9bbb..a6307d5 100644 --- a/apps/scrobbler.c +++ b/apps/scrobbler.c @@ -30,7 +30,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging #include "metadata.h" #include "kernel.h" #include "audio.h" -#include "buffer.h" +#include "core_alloc.h" #include "settings.h" #include "ata_idle_notify.h" #include "filefuncs.h" @@ -52,7 +52,7 @@ http://www.audioscrobbler.net/wiki/Portable_Player_Logging /* longest entry I've had is 323, add a safety margin */ #define SCROBBLER_CACHE_LEN 512 -static char* scrobbler_cache; +static int scrobbler_cache; static int cache_pos; static struct mp3entry scrobbler_entry; @@ -139,11 +139,16 @@ static void write_cache(void) if(fd >= 0) { logf("SCROBBLER: writing %d entries", cache_pos); - + /* copy data to temporary storage in case data moves during I/O */ + char temp_buf[SCROBBLER_CACHE_LEN]; for ( i=0; i < cache_pos; i++ ) { logf("SCROBBLER: write %d", i); - fdprintf(fd, "%s", scrobbler_cache+(SCROBBLER_CACHE_LEN*i)); + char* scrobbler_buf = core_get_data(scrobbler_cache); + ssize_t len = strlcpy(temp_buf, scrobbler_buf+(SCROBBLER_CACHE_LEN*i), + sizeof(temp_buf)); + if (write(fd, temp_buf, len) != len) + break; } close(fd); } @@ -170,6 +175,7 @@ static void add_to_cache(unsigned long play_length) int ret; char rating = 'S'; /* Skipped */ + char* scrobbler_buf = core_get_data(scrobbler_cache); logf("SCROBBLER: add_to_cache[%d]", cache_pos); @@ -178,7 +184,7 @@ static void add_to_cache(unsigned long play_length) if (scrobbler_entry.tracknum > 0) { - ret = snprintf(scrobbler_cache+(SCROBBLER_CACHE_LEN*cache_pos), + ret = snprintf(scrobbler_buf+(SCROBBLER_CACHE_LEN*cache_pos), SCROBBLER_CACHE_LEN, "%s\t%s\t%s\t%d\t%d\t%c\t%ld\t%s\n", scrobbler_entry.artist, @@ -190,7 +196,7 @@ static void add_to_cache(unsigned long play_length) (long)timestamp, scrobbler_entry.mb_track_id?scrobbler_entry.mb_track_id:""); } else { - ret = snprintf(scrobbler_cache+(SCROBBLER_CACHE_LEN*cache_pos), + ret = snprintf(scrobbler_buf+(SCROBBLER_CACHE_LEN*cache_pos), SCROBBLER_CACHE_LEN, "%s\t%s\t%s\t\t%d\t%c\t%ld\t%s\n", scrobbler_entry.artist, @@ -248,7 +254,7 @@ int scrobbler_init(void) if(!global_settings.audioscrobbler) return -1; - scrobbler_cache = buffer_alloc(SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); + scrobbler_cache = core_alloc("scrobbler", SCROBBLER_MAX_CACHE*SCROBBLER_CACHE_LEN); add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, scrobbler_change_event); cache_pos = 0; diff --git a/apps/tagcache.c b/apps/tagcache.c index 52e059a..753675f 100644 --- a/apps/tagcache.c +++ b/apps/tagcache.c @@ -74,7 +74,7 @@ #include "usb.h" #include "metadata.h" #include "tagcache.h" -#include "buffer.h" +#include "core_alloc.h" #include "crc32.h" #include "misc.h" #include "settings.h" @@ -3082,6 +3082,7 @@ static bool commit(void) return true; } +static int tempbuf_handle; static void allocate_tempbuf(void) { /* Yeah, malloc would be really nice now :) */ @@ -3089,7 +3090,8 @@ static void allocate_tempbuf(void) tempbuf_size = 32*1024*1024; tempbuf = malloc(tempbuf_size); #else - tempbuf = buffer_get_buffer(&tempbuf_size); + tempbuf_handle = core_alloc_maximum("tc tempbuf", &tempbuf_size, NULL); + tempbuf = core_get_data(tempbuf_handle); #endif } @@ -3101,7 +3103,7 @@ static void free_tempbuf(void) #ifdef __PCTOOL__ free(tempbuf); #else - buffer_release_buffer(0); + tempbuf_handle = core_free(tempbuf_handle); #endif tempbuf = NULL; tempbuf_size = 0; @@ -3829,9 +3831,10 @@ static bool allocate_tagcache(void) * Now calculate the required cache size plus * some extra space for alignment fixes. */ - tc_stat.ramcache_allocated = tcmh.tch.datasize + 128 + TAGCACHE_RESERVE + + tc_stat.ramcache_allocated = tcmh.tch.datasize + 256 + TAGCACHE_RESERVE + sizeof(struct ramcache_header) + TAG_COUNT*sizeof(void *); - ramcache_hdr = buffer_alloc(tc_stat.ramcache_allocated + 128); + int handle = core_alloc("tc ramcache", tc_stat.ramcache_allocated); + ramcache_hdr = core_get_data(handle); memset(ramcache_hdr, 0, sizeof(struct ramcache_header)); memcpy(¤t_tcmh, &tcmh, sizeof current_tcmh); logf("tagcache: %d bytes allocated.", tc_stat.ramcache_allocated); @@ -3845,7 +3848,7 @@ static bool tagcache_dumpload(void) struct statefile_header shdr; int fd, rc; long offpos; - int i; + int i, handle; fd = open(TAGCACHE_STATEFILE, O_RDONLY); if (fd < 0) @@ -3855,7 +3858,6 @@ static bool tagcache_dumpload(void) } /* Check the statefile memory placement */ - ramcache_hdr = buffer_alloc(0); rc = read(fd, &shdr, sizeof(struct statefile_header)); if (rc != sizeof(struct statefile_header) || shdr.magic != TAGCACHE_STATEFILE_MAGIC @@ -3867,13 +3869,14 @@ static bool tagcache_dumpload(void) return false; } - offpos = (long)ramcache_hdr - (long)shdr.hdr; /* Lets allocate real memory and load it */ - ramcache_hdr = buffer_alloc(shdr.tc_stat.ramcache_allocated); + handle = core_alloc("tc ramcache", shdr.tc_stat.ramcache_allocated); + ramcache_hdr = core_get_data(handle); rc = read(fd, ramcache_hdr, shdr.tc_stat.ramcache_allocated); close(fd); + offpos = (long)ramcache_hdr - (long)shdr.hdr; if (rc != shdr.tc_stat.ramcache_allocated) { logf("read failure!"); diff --git a/apps/tagtree.c b/apps/tagtree.c index 5012c08..0d4330b 100644 --- a/apps/tagtree.c +++ b/apps/tagtree.c @@ -44,7 +44,7 @@ #include "playlist.h" #include "keyboard.h" #include "gui/list.h" -#include "buffer.h" +#include "core_alloc.h" #include "yesno.h" #include "misc.h" #include "filetypes.h" @@ -176,9 +176,14 @@ static int current_entry_count; static struct tree_context *tc; /* a few memory alloc helper */ +static int tagtree_handle; +static size_t tagtree_bufsize, tagtree_buf_used; static void* tagtree_alloc(size_t size) { - return buffer_alloc(size); + char* buf = core_get_data(tagtree_handle) + tagtree_buf_used; + size = ALIGN_UP(size, sizeof(void*)); + tagtree_buf_used += size; + return buf; } static void* tagtree_alloc0(size_t size) @@ -1035,6 +1040,7 @@ void tagtree_init(void) menu_count = 0; menu = NULL; rootmenu = -1; + tagtree_handle = core_alloc_maximum("tagtree", &tagtree_bufsize, NULL); parse_menu(FILE_SEARCH_INSTRUCTIONS); /* If no root menu is set, assume it's the first single menu @@ -1046,6 +1052,8 @@ void tagtree_init(void) add_event(PLAYBACK_EVENT_TRACK_BUFFER, false, tagtree_buffer_event); add_event(PLAYBACK_EVENT_TRACK_FINISH, false, tagtree_track_finish_event); + + core_shrink(tagtree_handle, core_get_data(tagtree_handle), tagtree_buf_used); } static bool show_search_progress(bool init, int count) diff --git a/apps/talk.c b/apps/talk.c index 0c3b769..2965738 100644 --- a/apps/talk.c +++ b/apps/talk.c @@ -27,7 +27,6 @@ #include <stddef.h> #include "string-extra.h" #include "file.h" -#include "buffer.h" #include "system.h" #include "kernel.h" #include "settings.h" @@ -711,7 +710,7 @@ void talk_init(void) /* test if we can open and if it fits in the audiobuffer */ - size_t audiobufsz = buffer_available(); + size_t audiobufsz = audio_buffer_available(); if (voicefile_size <= audiobufsz) { has_voicefile = true; } else { diff --git a/apps/tdspeed.c b/apps/tdspeed.c index b940c92..476995a 100644 --- a/apps/tdspeed.c +++ b/apps/tdspeed.c @@ -25,7 +25,7 @@ #include <stdio.h> #include <string.h> #include "sound.h" -#include "buffer.h" +#include "core_alloc.h" #include "system.h" #include "tdspeed.h" #include "settings.h" @@ -56,21 +56,32 @@ static int32_t *outbuf[2] = { NULL, NULL }; void tdspeed_init(void) { + int handle; + if (!global_settings.timestretch_enabled) return; /* Allocate buffers */ if (overlap_buffer[0] == NULL) - overlap_buffer[0] = (int32_t *)buffer_alloc(FIXED_BUFSIZE * sizeof(int32_t)); - + { + handle = core_alloc("tdspeed ovl left", FIXED_BUFSIZE * sizeof(int32_t)); + overlap_buffer[0] = core_get_data(handle); + } if (overlap_buffer[1] == NULL) - overlap_buffer[1] = (int32_t *)buffer_alloc(FIXED_BUFSIZE * sizeof(int32_t)); - + { + handle = core_alloc("tdspeed ovl right", FIXED_BUFSIZE * sizeof(int32_t)); + overlap_buffer[1] = core_get_data(handle); + } if (outbuf[0] == NULL) - outbuf[0] = (int32_t *)buffer_alloc(TDSPEED_OUTBUFSIZE * sizeof(int32_t)); - + { + handle = core_alloc("tdspeed left", TDSPEED_OUTBUFSIZE * sizeof(int32_t)); + outbuf[0] = core_get_data(handle); + } if (outbuf[1] == NULL) - outbuf[1] = (int32_t *)buffer_alloc(TDSPEED_OUTBUFSIZE * sizeof(int32_t)); + { + handle = core_alloc("tdspeed right", TDSPEED_OUTBUFSIZE * sizeof(int32_t)); + outbuf[1] = core_get_data(handle); + } } diff --git a/apps/tree.c b/apps/tree.c index e981aee..211ddb2 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -46,7 +46,7 @@ #include "keyboard.h" #include "bookmark.h" #include "onplay.h" -#include "buffer.h" +#include "core_alloc.h" #include "power.h" #include "action.h" #include "talk.h" @@ -1002,6 +1002,7 @@ int rockbox_browse(struct browse_context *browse) void tree_mem_init(void) { /* initialize tree context struct */ + int handle; struct tree_cache* cache = &tc.cache; memset(&tc, 0, sizeof(tc)); tc.dirfilter = &global_settings.dirfilter; @@ -1009,10 +1010,12 @@ void tree_mem_init(void) cache->name_buffer_size = AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir; - cache->name_buffer = buffer_alloc(cache->name_buffer_size); + handle = core_alloc("tree names", cache->name_buffer_size); + cache->name_buffer = core_get_data(handle); cache->max_entries = global_settings.max_files_in_dir; - cache->entries = buffer_alloc(cache->max_entries*(sizeof(struct entry))); + handle = core_alloc("tree entries", cache->max_entries*(sizeof(struct entry))); + cache->entries = core_get_data(handle); tree_get_filetypes(&filetypes, &filetypes_count); } |