Index: apps/codecs/vorbis.c =================================================================== --- apps/codecs/vorbis.c (revision 22020) +++ apps/codecs/vorbis.c (working copy) @@ -22,6 +22,9 @@ #include "codeclib.h" #include "libtremor/ivorbisfile.h" #include "libtremor/ogg.h" +#ifdef SIMULATOR +#include "libtremor/tlsf/tlsf.h" +#endif CODEC_HEADER @@ -114,9 +117,6 @@ int current_section; int previous_section; int eof; - ogg_int64_t vf_offsets[2]; - ogg_int64_t vf_dataoffsets; - ogg_uint32_t vf_serialnos; ogg_int64_t vf_pcmlengths[2]; ci->configure(DSP_SET_SAMPLE_DEPTH, 24); @@ -124,7 +124,7 @@ * they should be set differently based on quality setting */ -#if defined(CPU_ARM) || defined(CPU_COLDFIRE) +#if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS) if (setjmp(rb_jump_buf) != 0) { /* malloc failed; skip to next track */ @@ -133,14 +133,13 @@ } #endif -/* We need to flush reserver memory every track load. */ -next_track: if (codec_init()) { error = CODEC_ERROR; goto exit; } ogg_malloc_init(); +next_track: while (!*ci->taginfo_ready && !ci->stop_codec) ci->sleep(1); @@ -166,17 +165,12 @@ * get here. */ if (!error) { - vf.offsets = vf_offsets; - vf.dataoffsets = &vf_dataoffsets; - vf.serialnos = &vf_serialnos; vf.pcmlengths = vf_pcmlengths; vf.offsets[0] = 0; - vf.offsets[1] = ci->id3->filesize; vf.dataoffsets[0] = vf.offset; vf.pcmlengths[0] = 0; vf.pcmlengths[1] = ci->id3->samples; - vf.serialnos[0] = vf.current_serialno; vf.callbacks.seek_func = seek_handler; vf.seekable = 1; vf.end = ci->id3->filesize; @@ -235,17 +229,22 @@ error = CODEC_OK; done: +#ifdef SIMULATOR + { + size_t bufsize; + void* buf = ci->codec_get_buffer(&bufsize); + DEBUGF("Vorbis memory max: %u\n", get_max_size(buf)); + } +#endif + if (ci->request_next_track()) { /* Clean things up for the next track */ - vf.dataoffsets = NULL; - vf.offsets = NULL; - vf.serialnos = NULL; vf.pcmlengths = NULL; ov_clear(&vf); goto next_track; } exit: + ogg_malloc_destroy(); return error; } - Index: apps/codecs/libtremor/os_types.h =================================================================== --- apps/codecs/libtremor/os_types.h (revision 22020) +++ apps/codecs/libtremor/os_types.h (working copy) @@ -38,16 +38,15 @@ #define _ogg_malloc ogg_malloc #define _ogg_calloc ogg_calloc #define _ogg_realloc ogg_realloc -#define _ogg_free(x) do { } while(0) +// #define _ogg_free(x) do { } while(0) +#define _ogg_free ogg_free void ogg_malloc_init(void); +void ogg_malloc_destroy(); void *ogg_malloc(size_t size); -void *ogg_tmpmalloc(size_t size); void *ogg_calloc(size_t nmemb, size_t size); -void *ogg_tmpcalloc(size_t nmemb, size_t size); void *ogg_realloc(void *ptr, size_t size); -long ogg_tmpmalloc_pos(void); -void ogg_tmpmalloc_free(long pos); +void ogg_free(void *ptr); void iram_malloc_init(void); void *iram_malloc(size_t size); Index: apps/codecs/libtremor/SOURCES =================================================================== --- apps/codecs/libtremor/SOURCES (revision 22020) +++ apps/codecs/libtremor/SOURCES (working copy) @@ -14,3 +14,4 @@ window.c ctype.c oggmalloc.c +tlsf/tlsf.c Index: apps/codecs/libtremor/vorbisfile.c =================================================================== --- apps/codecs/libtremor/vorbisfile.c (revision 22020) +++ apps/codecs/libtremor/vorbisfile.c (working copy) @@ -937,7 +937,7 @@ for second stage of seekable stream open; this saves having to seek/reread first link's serialnumber data then. */ vf->serialnos=_ogg_calloc(serialno_list_size+2,sizeof(*vf->serialnos)); - vf->serialnos[0]=vf->current_serialno; + vf->serialnos[0]=vf->os->serialno; vf->serialnos[1]=serialno_list_size; memcpy(vf->serialnos+2,serialno_list,serialno_list_size*sizeof(*vf->serialnos)); Index: apps/codecs/libtremor/oggmalloc.c =================================================================== --- apps/codecs/libtremor/oggmalloc.c (revision 22020) +++ apps/codecs/libtremor/oggmalloc.c (working copy) @@ -1,87 +1,69 @@ #include "os_types.h" +#include "tlsf/tlsf.h" -#if defined(CPU_ARM) || defined(CPU_COLDFIRE) +#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) +#else +#define LONGJMP(x) return NULL #endif -static size_t tmp_ptr; void ogg_malloc_init(void) { - mallocbuf = ci->codec_get_buffer(&bufsize); - tmp_ptr = bufsize & ~3; - mem_ptr = 0; + size_t bufsize; + void* buf = ci->codec_get_buffer(&bufsize); + init_memory_pool(bufsize, buf); } -void *ogg_malloc(size_t size) +void ogg_malloc_destroy() { - void* x; - - size = (size + 3) & ~3; - - if (mem_ptr + size > tmp_ptr) -#if defined(CPU_ARM) || defined(CPU_COLDFIRE) - longjmp(rb_jump_buf, 1); -#else - return NULL; -#endif - - x = &mallocbuf[mem_ptr]; - mem_ptr += size; /* Keep memory 32-bit aligned */ - - return x; + size_t bufsize; + destroy_memory_pool(ci->codec_get_buffer(&bufsize)); } -void *ogg_tmpmalloc(size_t size) +void *ogg_malloc(size_t size) { - size = (size + 3) & ~3; + void* x = tlsf_malloc(size); - if (mem_ptr + size > tmp_ptr) - return NULL; + if (x == NULL) + LONGJMP(1); - tmp_ptr -= size; - return &mallocbuf[tmp_ptr]; + //printf("ogg_malloc: %d => %08x\n", size, x); + return x; } void *ogg_calloc(size_t nmemb, size_t size) { void *x; - x = ogg_malloc(nmemb * size); - if (x == NULL) - return NULL; - ci->memset(x, 0, nmemb * size); - return x; -} + x = tlsf_calloc(nmemb, size); -void *ogg_tmpcalloc(size_t nmemb, size_t size) -{ - void *x; - x = ogg_tmpmalloc(nmemb * size); if (x == NULL) - return NULL; - ci->memset(x, 0, nmemb * size); + LONGJMP(1); + + //printf("ogg_calloc: %d => %08x\n", nmemb * size, x); return x; } void *ogg_realloc(void *ptr, size_t size) { void *x; - (void)ptr; - x = ogg_malloc(size); + x = tlsf_realloc(ptr, size); + + if (x == NULL) + LONGJMP(1); + + //printf("ogg_realloc: %d, %08x => %08x\n", size, ptr, x); return x; } -long ogg_tmpmalloc_pos(void) +void ogg_free(void* ptr) { - return tmp_ptr; + //printf("ogg_free: %08x\n", ptr); + tlsf_free(ptr); } -void ogg_tmpmalloc_free(long pos) -{ - tmp_ptr = pos; -} - /* Allocate IRAM buffer */ static unsigned char iram_buff[IRAM_IBSS_SIZE] IBSS_ATTR __attribute__ ((aligned (16))); static size_t iram_remain; Index: apps/codecs/libtremor/sharedbook.c =================================================================== --- apps/codecs/libtremor/sharedbook.c (revision 22020) +++ apps/codecs/libtremor/sharedbook.c (working copy) @@ -71,7 +71,7 @@ static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ long i,j,count=0; ogg_uint32_t marker[33]; - ogg_uint32_t *r=(ogg_uint32_t *)ogg_tmpmalloc((sparsecount?sparsecount:n)*sizeof(*r)); + ogg_uint32_t *r=(ogg_uint32_t *)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r)); memset(marker,0,sizeof(marker)); for(i=0;i>length)){ /* error condition; the lengths must specify an overpopulated tree */ - /* _ogg_free(r); */ + _ogg_free(r); return(NULL); } r[count++]=entry; @@ -188,9 +188,8 @@ ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); - int *rp=(int *)ogg_tmpcalloc(n*b->dim,sizeof(*rp)); + int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp)); - memset(rp, 0, n*b->dim*sizeof(*rp)); *maxpoint=minpoint; /* maptype 1 and 2 both use a quantized value vector, but @@ -277,7 +276,7 @@ if(rp[j]<*maxpoint) r[j]>>=*maxpoint-rp[j]; - /* _ogg_free(rp); */ + _ogg_free(rp); return(r); } return(NULL); @@ -325,7 +324,6 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ int i,j,n=0,tabn; int *sortindex; - long pos = ogg_tmpmalloc_pos(); memset(c,0,sizeof(*c)); /* count actually used entries */ @@ -350,9 +348,13 @@ /* perform sort */ ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); - ogg_uint32_t **codep=(ogg_uint32_t **)ogg_tmpmalloc(sizeof(*codep)*n); + ogg_uint32_t **codep=(ogg_uint32_t **)_ogg_malloc(sizeof(*codep)*n); - if(codes==NULL||codep==NULL)goto err_out; + if(codes==NULL||codep==NULL){ + _ogg_free(codep); + _ogg_free(codes); + goto err_out; + } for(i=0;icodelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); /* the index is a reverse index */ for(i=0;icodelist[sortindex[i]]=codes[i]; - /* _ogg_free(codes); */ + _ogg_free(codep); + _ogg_free(codes); @@ -387,6 +390,7 @@ if(s->lengthlist[i]>0) c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; + _ogg_free(sortindex); c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ if(c->dec_firsttablen<5)c->dec_firsttablen=5; if(c->dec_firsttablen>8)c->dec_firsttablen=8; @@ -434,10 +438,8 @@ } } - ogg_tmpmalloc_free(pos); return(0); err_out: - ogg_tmpmalloc_free(pos); vorbis_book_clear(c); return(-1); } Index: apps/codecs/libtremor/libtremor.make =================================================================== --- apps/codecs/libtremor/libtremor.make (revision 22020) +++ apps/codecs/libtremor/libtremor.make (working copy) @@ -32,6 +32,10 @@ TREMORFLAGS += -O2 endif +ifdef SIMVER + TREMORFLAGS += -DTLSF_STATISTIC=1 +endif + $(CODECDIR)/libtremor/%.o: $(ROOTDIR)/apps/codecs/libtremor/%.c $(SILENT)mkdir -p $(dir $@) $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(TREMORFLAGS) -c $< -o $@ Index: apps/codecs/libtremor/block.c =================================================================== --- apps/codecs/libtremor/block.c (revision 22020) +++ apps/codecs/libtremor/block.c (working copy) @@ -283,7 +283,7 @@ codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); private_state *b=(private_state *)v->backend_state; - if(NULL == v->iram_double_pcm) + if(NULL == v->iram_double_pcm && vi != NULL) { /* pcm buffer came from oggmalloc rather than iram */ for(i=0;ichannels;i++)