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/mpeg.c | |
parent | c940811ade7d99a0e0d414df7c6509672413684a (diff) |
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/mpeg.c')
-rw-r--r-- | apps/mpeg.c | 68 |
1 files changed, 48 insertions, 20 deletions
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 @@ #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 */ |