diff options
| author | Nils Wallménius <nils@rockbox.org> | 2008-10-19 12:35:53 +0000 |
|---|---|---|
| committer | Nils Wallménius <nils@rockbox.org> | 2008-10-19 12:35:53 +0000 |
| commit | 2f50cd58b9fb7cd75448622b5ac222cdcad6bc6f (patch) | |
| tree | 880a25472bfa6ce2fcda13a334c17607aa1ad419 /apps | |
| parent | 01177055425776fadbdd6cf167111105b118754a (diff) | |
| download | rockbox-2f50cd58b9fb7cd75448622b5ac222cdcad6bc6f.zip rockbox-2f50cd58b9fb7cd75448622b5ac222cdcad6bc6f.tar.gz rockbox-2f50cd58b9fb7cd75448622b5ac222cdcad6bc6f.tar.bz2 rockbox-2f50cd58b9fb7cd75448622b5ac222cdcad6bc6f.tar.xz | |
Codec memory reorganization
Based on a patch by Tomasz Malesinski
* Merge Codec buffer and Malloc buffer into one large buffer.
* The new merged buffer is now 1MB on targets with lots of memory.
* Renamed codec_get_memory to codec_get_buffer and made it behave more.
like plugin_get_buffer.
* Bumped Codec api and min api versions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18834 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/codecs.c | 13 | ||||
| -rw-r--r-- | apps/codecs.h | 9 | ||||
| -rw-r--r-- | apps/codecs/Tremor/oggmalloc.c | 2 | ||||
| -rw-r--r-- | apps/codecs/lib/codeclib.c | 2 | ||||
| -rw-r--r-- | apps/codecs/lib/codeclib.h | 2 | ||||
| -rw-r--r-- | apps/playback.c | 17 |
6 files changed, 27 insertions, 18 deletions
diff --git a/apps/codecs.c b/apps/codecs.c index 417b546..8e9e55a 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -66,6 +66,8 @@ void sim_codec_close(void *pd); extern unsigned char codecbuf[]; #endif +size_t codec_size; + extern void* plugin_get_audio_buffer(size_t *buffer_size); struct codec_api ci = { @@ -78,7 +80,7 @@ struct codec_api ci = { 0, /* new_track */ 0, /* seek_time */ NULL, /* struct dsp_config *dsp */ - NULL, /* get_codec_memory */ + NULL, /* codec_get_buffer */ NULL, /* pcmbuf_insert */ NULL, /* set_elapsed */ NULL, /* read_filebuf */ @@ -193,6 +195,9 @@ static int codec_load_ram(int size, struct codec_api *api) logf("codec header error"); return CODEC_ERROR; } + + codec_size = hdr->end_addr - codecbuf; + #else /* SIMULATOR */ void *pd; @@ -211,6 +216,9 @@ static int codec_load_ram(int size, struct codec_api *api) sim_codec_close(pd); return CODEC_ERROR; } + + codec_size = codecbuf - codecbuf; + #endif /* SIMULATOR */ if (hdr->api_version > CODEC_API_VERSION || hdr->api_version < CODEC_MIN_API_VERSION) { @@ -226,7 +234,8 @@ static int codec_load_ram(int size, struct codec_api *api) return status; } -int codec_load_buf(unsigned int hid, struct codec_api *api) { +int codec_load_buf(unsigned int hid, struct codec_api *api) +{ int rc; rc = bufread(hid, CODEC_SIZE, codecbuf); if (rc < 0) { diff --git a/apps/codecs.h b/apps/codecs.h index becb73c..6d8c101 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -82,12 +82,12 @@ #define CODEC_ENC_MAGIC 0x52454E43 /* RENC */ /* increase this every time the api struct changes */ -#define CODEC_API_VERSION 25 +#define CODEC_API_VERSION 26 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any new function which are "waiting" at the end of the function table) */ -#define CODEC_MIN_API_VERSION 25 +#define CODEC_MIN_API_VERSION 26 /* codec return codes */ enum codec_status { @@ -125,7 +125,7 @@ struct codec_api { struct dsp_config *dsp; /* Returns buffer to malloc array. Only codeclib should need this. */ - void* (*get_codec_memory)(size_t *size); + void* (*codec_get_buffer)(size_t *size); /* Insert PCM data into audio buffer for playback. Playback will start automatically. */ bool (*pcmbuf_insert)(const void *ch1, const void *ch2, int count); @@ -256,6 +256,9 @@ struct codec_header { enum codec_status(*entry_point)(struct codec_api*); }; +extern unsigned char codecbuf[]; +extern size_t codec_size; + #ifdef CODEC #ifndef SIMULATOR /* plugin_* is correct, codecs use the plugin linker script */ diff --git a/apps/codecs/Tremor/oggmalloc.c b/apps/codecs/Tremor/oggmalloc.c index d7e903b..b11eaa5 100644 --- a/apps/codecs/Tremor/oggmalloc.c +++ b/apps/codecs/Tremor/oggmalloc.c @@ -5,7 +5,7 @@ static size_t bufsize, tmp_ptr, mem_ptr; void ogg_malloc_init(void) { - mallocbuf = ci->get_codec_memory(&bufsize); + mallocbuf = ci->codec_get_buffer(&bufsize); tmp_ptr = bufsize & ~3; mem_ptr = 0; } diff --git a/apps/codecs/lib/codeclib.c b/apps/codecs/lib/codeclib.c index e537995..6e11eb1 100644 --- a/apps/codecs/lib/codeclib.c +++ b/apps/codecs/lib/codeclib.c @@ -36,7 +36,7 @@ unsigned char* filebuf; // The rest of the MP3 buffer int codec_init(void) { mem_ptr = 0; - mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize); + mallocbuf = (unsigned char *)ci->codec_get_buffer((size_t *)&bufsize); return 0; } diff --git a/apps/codecs/lib/codeclib.h b/apps/codecs/lib/codeclib.h index 87cc926..744accb 100644 --- a/apps/codecs/lib/codeclib.h +++ b/apps/codecs/lib/codeclib.h @@ -24,8 +24,6 @@ #include "system.h" #include <sys/types.h> -#define MALLOC_BUFSIZE (512*1024) - extern struct codec_api *ci; extern long mem_ptr; extern long bufsize; diff --git a/apps/playback.c b/apps/playback.c index f41cca6..bfad1a2 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -166,10 +166,8 @@ enum filling_state { /* As defined in plugins/lib/xxx2wav.h */ #if MEM > 1 -#define MALLOC_BUFSIZE (512*1024) #define GUARD_BUFSIZE (32*1024) #else -#define MALLOC_BUFSIZE (100*1024) #define GUARD_BUFSIZE (8*1024) #endif @@ -924,10 +922,12 @@ static bool codec_pcmbuf_insert_callback( return true; } /* codec_pcmbuf_insert_callback */ -static void* codec_get_memory_callback(size_t *size) +static void* codec_get_buffer(size_t *size) { - *size = MALLOC_BUFSIZE; - return malloc_buf; + if (codec_size >= CODEC_SIZE) + return NULL; + *size = CODEC_SIZE - codec_size; + return &codecbuf[codec_size]; } /* Between the codec and PCM track change, we need to keep updating the @@ -2297,7 +2297,7 @@ static void audio_finalise_track_change(void) /* * Layout audio buffer as follows - iram buffer depends on target: - * [|SWAP:iram][|TALK]|MALLOC|FILE|GUARD|PCM|[SWAP:dram[|iram]|] + * [|SWAP:iram][|TALK]|FILE|GUARD|PCM|[SWAP:dram[|iram]|] */ static void audio_reset_buffer(void) { @@ -2313,7 +2313,7 @@ static void audio_reset_buffer(void) /* Align the malloc buf to line size. Especially important to cf targets that do line reads/writes. */ malloc_buf = (unsigned char *)(((uintptr_t)malloc_buf + 15) & ~15); - filebuf = malloc_buf + MALLOC_BUFSIZE; /* filebuf line align implied */ + filebuf = malloc_buf; /* filebuf line align implied */ filebuflen = audiobufend - filebuf; filebuflen &= ~15; @@ -2338,7 +2338,6 @@ static void audio_reset_buffer(void) size_t pcmbufsize; const unsigned char *pcmbuf = pcmbuf_get_meminfo(&pcmbufsize); logf("mabuf: %08X", (unsigned)malloc_buf); - logf("mabufe: %08X", (unsigned)(malloc_buf + MALLOC_BUFSIZE)); logf("fbuf: %08X", (unsigned)filebuf); logf("fbufe: %08X", (unsigned)(filebuf + filebuflen)); logf("gbuf: %08X", (unsigned)(filebuf + filebuflen)); @@ -2513,7 +2512,7 @@ void audio_init(void) /* Initialize codec api. */ ci.read_filebuf = codec_filebuf_callback; ci.pcmbuf_insert = codec_pcmbuf_insert_callback; - ci.get_codec_memory = codec_get_memory_callback; + ci.codec_get_buffer = codec_get_buffer; ci.request_buffer = codec_request_buffer_callback; ci.advance_buffer = codec_advance_buffer_callback; ci.advance_buffer_loc = codec_advance_buffer_loc_callback; |