From f40bfc9267b13b54e6379dfe7539447662879d24 Mon Sep 17 00:00:00 2001 From: Sean Bartell Date: Sat, 25 Jun 2011 21:32:25 -0400 Subject: Add codecs to librbcodec. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97 Reviewed-on: http://gerrit.rockbox.org/137 Reviewed-by: Nils Wallménius Tested-by: Nils Wallménius --- lib/rbcodec/codecs/libtremor/oggmalloc.c | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 lib/rbcodec/codecs/libtremor/oggmalloc.c (limited to 'lib/rbcodec/codecs/libtremor/oggmalloc.c') diff --git a/lib/rbcodec/codecs/libtremor/oggmalloc.c b/lib/rbcodec/codecs/libtremor/oggmalloc.c new file mode 100644 index 0000000000..783e0f7240 --- /dev/null +++ b/lib/rbcodec/codecs/libtremor/oggmalloc.c @@ -0,0 +1,86 @@ +#include "os_types.h" +#include + +#if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS) +#include +extern jmp_buf rb_jump_buf; +#define LONGJMP(x) longjmp(rb_jump_buf, x) +#elif defined(SIMULATOR) +#define LONGJMP(x) do { DEBUGF("Vorbis: allocation failed!\n"); return NULL; } while (false) +#else +#define LONGJMP(x) return NULL +#endif + +void ogg_malloc_init(void) +{ + size_t bufsize; + void* buf = ci->codec_get_buffer(&bufsize); + init_memory_pool(bufsize, buf); +} + +void ogg_malloc_destroy() +{ + size_t bufsize; + void* buf = ci->codec_get_buffer(&bufsize); + destroy_memory_pool(buf); +} + +void *ogg_malloc(size_t size) +{ + void* x = tlsf_malloc(size); + + if (x == NULL) + LONGJMP(1); + + return x; +} + +void *ogg_calloc(size_t nmemb, size_t size) +{ + void *x = tlsf_calloc(nmemb, size); + + if (x == NULL) + LONGJMP(1); + + return x; +} + +void *ogg_realloc(void *ptr, size_t size) +{ + void *x = tlsf_realloc(ptr, size); + + if (x == NULL) + LONGJMP(1); + + return x; +} + +void ogg_free(void* ptr) +{ + tlsf_free(ptr); +} + +#ifdef TREMOR_USE_IRAM +/* Allocate IRAM buffer */ +static unsigned char iram_buff[IRAM_IBSS_SIZE] IBSS_ATTR MEM_ALIGN_ATTR; +static size_t iram_remain; + +void iram_malloc_init(void){ + iram_remain=IRAM_IBSS_SIZE; +} + +void *iram_malloc(size_t size){ + void* x; + + /* always ensure alignment to CACHEALIGN_SIZE byte */ + size = (size + (CACHEALIGN_SIZE-1)) & ~(CACHEALIGN_SIZE-1); + + if(size>iram_remain) + return NULL; + + x = &iram_buff[IRAM_IBSS_SIZE-iram_remain]; + iram_remain-=size; + + return x; +} +#endif -- cgit v1.2.3