diff options
Diffstat (limited to 'apps/codecs/libtremor')
-rw-r--r-- | apps/codecs/libtremor/block.c | 2 | ||||
-rw-r--r-- | apps/codecs/libtremor/oggmalloc.c | 80 | ||||
-rw-r--r-- | apps/codecs/libtremor/os_types.h | 8 | ||||
-rw-r--r-- | apps/codecs/libtremor/sharedbook.c | 26 |
4 files changed, 47 insertions, 69 deletions
diff --git a/apps/codecs/libtremor/block.c b/apps/codecs/libtremor/block.c index 3947b90239..8a461e325f 100644 --- a/apps/codecs/libtremor/block.c +++ b/apps/codecs/libtremor/block.c | |||
@@ -283,7 +283,7 @@ void vorbis_dsp_clear(vorbis_dsp_state *v){ | |||
283 | codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); | 283 | codec_setup_info *ci=(codec_setup_info *)(vi?vi->codec_setup:NULL); |
284 | private_state *b=(private_state *)v->backend_state; | 284 | private_state *b=(private_state *)v->backend_state; |
285 | 285 | ||
286 | if(NULL == v->iram_double_pcm) | 286 | if(NULL == v->iram_double_pcm && vi != NULL) |
287 | { | 287 | { |
288 | /* pcm buffer came from oggmalloc rather than iram */ | 288 | /* pcm buffer came from oggmalloc rather than iram */ |
289 | for(i=0;i<vi->channels;i++) | 289 | for(i=0;i<vi->channels;i++) |
diff --git a/apps/codecs/libtremor/oggmalloc.c b/apps/codecs/libtremor/oggmalloc.c index 6da7cfcedc..3d60370641 100644 --- a/apps/codecs/libtremor/oggmalloc.c +++ b/apps/codecs/libtremor/oggmalloc.c | |||
@@ -1,85 +1,63 @@ | |||
1 | #include "os_types.h" | 1 | #include "os_types.h" |
2 | #include "../lib/tlsf/src/tlsf.h" | ||
2 | 3 | ||
3 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) | 4 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) || defined(CPU_MIPS) |
4 | #include <setjmp.h> | 5 | #include <setjmp.h> |
5 | extern jmp_buf rb_jump_buf; | 6 | extern jmp_buf rb_jump_buf; |
7 | #define LONGJMP(x) longjmp(rb_jump_buf, x) | ||
8 | #elif defined(SIMULATOR) | ||
9 | #define LONGJMP(x) do { DEBUGF("Vorbis: allocation failed!\n"); return NULL; } while (false) | ||
10 | #else | ||
11 | #define LONGJMP(x) return NULL | ||
6 | #endif | 12 | #endif |
7 | 13 | ||
8 | static size_t tmp_ptr; | ||
9 | |||
10 | void ogg_malloc_init(void) | 14 | void ogg_malloc_init(void) |
11 | { | 15 | { |
12 | mallocbuf = ci->codec_get_buffer(&bufsize); | 16 | size_t bufsize; |
13 | tmp_ptr = bufsize & ~3; | 17 | void* buf = ci->codec_get_buffer(&bufsize); |
14 | mem_ptr = 0; | 18 | init_memory_pool(bufsize, buf); |
15 | } | 19 | } |
16 | 20 | ||
17 | void *ogg_malloc(size_t size) | 21 | void ogg_malloc_destroy() |
18 | { | 22 | { |
19 | void* x; | 23 | size_t bufsize; |
20 | 24 | void* buf = ci->codec_get_buffer(&bufsize); | |
21 | size = (size + 3) & ~3; | 25 | destroy_memory_pool(buf); |
22 | |||
23 | if (mem_ptr + size > tmp_ptr) | ||
24 | #if defined(CPU_ARM) || defined(CPU_COLDFIRE) | ||
25 | longjmp(rb_jump_buf, 1); | ||
26 | #else | ||
27 | return NULL; | ||
28 | #endif | ||
29 | |||
30 | x = &mallocbuf[mem_ptr]; | ||
31 | mem_ptr += size; /* Keep memory 32-bit aligned */ | ||
32 | |||
33 | return x; | ||
34 | } | 26 | } |
35 | 27 | ||
36 | void *ogg_tmpmalloc(size_t size) | 28 | void *ogg_malloc(size_t size) |
37 | { | 29 | { |
38 | size = (size + 3) & ~3; | 30 | void* x = tlsf_malloc(size); |
39 | 31 | ||
40 | if (mem_ptr + size > tmp_ptr) | 32 | if (x == NULL) |
41 | return NULL; | 33 | LONGJMP(1); |
42 | 34 | ||
43 | tmp_ptr -= size; | 35 | return x; |
44 | return &mallocbuf[tmp_ptr]; | ||
45 | } | 36 | } |
46 | 37 | ||
47 | void *ogg_calloc(size_t nmemb, size_t size) | 38 | void *ogg_calloc(size_t nmemb, size_t size) |
48 | { | 39 | { |
49 | void *x; | 40 | void *x = tlsf_calloc(nmemb, size); |
50 | x = ogg_malloc(nmemb * size); | ||
51 | if (x == NULL) | ||
52 | return NULL; | ||
53 | ci->memset(x, 0, nmemb * size); | ||
54 | return x; | ||
55 | } | ||
56 | 41 | ||
57 | void *ogg_tmpcalloc(size_t nmemb, size_t size) | ||
58 | { | ||
59 | void *x; | ||
60 | x = ogg_tmpmalloc(nmemb * size); | ||
61 | if (x == NULL) | 42 | if (x == NULL) |
62 | return NULL; | 43 | LONGJMP(1); |
63 | ci->memset(x, 0, nmemb * size); | 44 | |
64 | return x; | 45 | return x; |
65 | } | 46 | } |
66 | 47 | ||
67 | void *ogg_realloc(void *ptr, size_t size) | 48 | void *ogg_realloc(void *ptr, size_t size) |
68 | { | 49 | { |
69 | void *x; | 50 | void *x = tlsf_realloc(ptr, size); |
70 | (void)ptr; | ||
71 | x = ogg_malloc(size); | ||
72 | return x; | ||
73 | } | ||
74 | 51 | ||
75 | long ogg_tmpmalloc_pos(void) | 52 | if (x == NULL) |
76 | { | 53 | LONGJMP(1); |
77 | return tmp_ptr; | 54 | |
55 | return x; | ||
78 | } | 56 | } |
79 | 57 | ||
80 | void ogg_tmpmalloc_free(long pos) | 58 | void ogg_free(void* ptr) |
81 | { | 59 | { |
82 | tmp_ptr = pos; | 60 | tlsf_free(ptr); |
83 | } | 61 | } |
84 | 62 | ||
85 | /* Allocate IRAM buffer */ | 63 | /* Allocate IRAM buffer */ |
diff --git a/apps/codecs/libtremor/os_types.h b/apps/codecs/libtremor/os_types.h index 4c7d17ef3a..337c055d54 100644 --- a/apps/codecs/libtremor/os_types.h +++ b/apps/codecs/libtremor/os_types.h | |||
@@ -38,16 +38,14 @@ | |||
38 | #define _ogg_malloc ogg_malloc | 38 | #define _ogg_malloc ogg_malloc |
39 | #define _ogg_calloc ogg_calloc | 39 | #define _ogg_calloc ogg_calloc |
40 | #define _ogg_realloc ogg_realloc | 40 | #define _ogg_realloc ogg_realloc |
41 | #define _ogg_free(x) do { } while(0) | 41 | #define _ogg_free ogg_free |
42 | 42 | ||
43 | void ogg_malloc_init(void); | 43 | void ogg_malloc_init(void); |
44 | void ogg_malloc_destroy(void); | ||
44 | void *ogg_malloc(size_t size); | 45 | void *ogg_malloc(size_t size); |
45 | void *ogg_tmpmalloc(size_t size); | ||
46 | void *ogg_calloc(size_t nmemb, size_t size); | 46 | void *ogg_calloc(size_t nmemb, size_t size); |
47 | void *ogg_tmpcalloc(size_t nmemb, size_t size); | ||
48 | void *ogg_realloc(void *ptr, size_t size); | 47 | void *ogg_realloc(void *ptr, size_t size); |
49 | long ogg_tmpmalloc_pos(void); | 48 | void ogg_free(void *ptr); |
50 | void ogg_tmpmalloc_free(long pos); | ||
51 | void iram_malloc_init(void); | 49 | void iram_malloc_init(void); |
52 | void *iram_malloc(size_t size); | 50 | void *iram_malloc(size_t size); |
53 | 51 | ||
diff --git a/apps/codecs/libtremor/sharedbook.c b/apps/codecs/libtremor/sharedbook.c index edabf3ccb3..853d1f5d61 100644 --- a/apps/codecs/libtremor/sharedbook.c +++ b/apps/codecs/libtremor/sharedbook.c | |||
@@ -71,7 +71,7 @@ static ogg_int32_t _float32_unpack(long val,int *point){ | |||
71 | static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ | 71 | static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ |
72 | long i,j,count=0; | 72 | long i,j,count=0; |
73 | ogg_uint32_t marker[33]; | 73 | ogg_uint32_t marker[33]; |
74 | ogg_uint32_t *r=(ogg_uint32_t *)ogg_tmpmalloc((sparsecount?sparsecount:n)*sizeof(*r)); | 74 | ogg_uint32_t *r=(ogg_uint32_t *)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r)); |
75 | memset(marker,0,sizeof(marker)); | 75 | memset(marker,0,sizeof(marker)); |
76 | 76 | ||
77 | for(i=0;i<n;i++){ | 77 | for(i=0;i<n;i++){ |
@@ -87,7 +87,7 @@ static ogg_uint32_t *_make_words(long *l,long n,long sparsecount){ | |||
87 | /* update ourself */ | 87 | /* update ourself */ |
88 | if(length<32 && (entry>>length)){ | 88 | if(length<32 && (entry>>length)){ |
89 | /* error condition; the lengths must specify an overpopulated tree */ | 89 | /* error condition; the lengths must specify an overpopulated tree */ |
90 | /* _ogg_free(r); */ | 90 | _ogg_free(r); |
91 | return(NULL); | 91 | return(NULL); |
92 | } | 92 | } |
93 | r[count++]=entry; | 93 | r[count++]=entry; |
@@ -188,9 +188,8 @@ static ogg_int32_t *_book_unquantize(const static_codebook *b,int n, | |||
188 | ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); | 188 | ogg_int32_t mindel=_float32_unpack(b->q_min,&minpoint); |
189 | ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); | 189 | ogg_int32_t delta=_float32_unpack(b->q_delta,&delpoint); |
190 | ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); | 190 | ogg_int32_t *r=(ogg_int32_t *)_ogg_calloc(n*b->dim,sizeof(*r)); |
191 | int *rp=(int *)ogg_tmpcalloc(n*b->dim,sizeof(*rp)); | 191 | int *rp=(int *)_ogg_calloc(n*b->dim,sizeof(*rp)); |
192 | 192 | ||
193 | memset(rp, 0, n*b->dim*sizeof(*rp)); | ||
194 | *maxpoint=minpoint; | 193 | *maxpoint=minpoint; |
195 | 194 | ||
196 | /* maptype 1 and 2 both use a quantized value vector, but | 195 | /* maptype 1 and 2 both use a quantized value vector, but |
@@ -277,7 +276,7 @@ static ogg_int32_t *_book_unquantize(const static_codebook *b,int n, | |||
277 | if(rp[j]<*maxpoint) | 276 | if(rp[j]<*maxpoint) |
278 | r[j]>>=*maxpoint-rp[j]; | 277 | r[j]>>=*maxpoint-rp[j]; |
279 | 278 | ||
280 | /* _ogg_free(rp); */ | 279 | _ogg_free(rp); |
281 | return(r); | 280 | return(r); |
282 | } | 281 | } |
283 | return(NULL); | 282 | return(NULL); |
@@ -325,7 +324,6 @@ static int sort32a(const void *a,const void *b){ | |||
325 | int vorbis_book_init_decode(codebook *c,const static_codebook *s){ | 324 | int vorbis_book_init_decode(codebook *c,const static_codebook *s){ |
326 | int i,j,n=0,tabn; | 325 | int i,j,n=0,tabn; |
327 | int *sortindex; | 326 | int *sortindex; |
328 | long pos = ogg_tmpmalloc_pos(); | ||
329 | memset(c,0,sizeof(*c)); | 327 | memset(c,0,sizeof(*c)); |
330 | 328 | ||
331 | /* count actually used entries */ | 329 | /* count actually used entries */ |
@@ -350,9 +348,13 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ | |||
350 | 348 | ||
351 | /* perform sort */ | 349 | /* perform sort */ |
352 | ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); | 350 | ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries); |
353 | ogg_uint32_t **codep=(ogg_uint32_t **)ogg_tmpmalloc(sizeof(*codep)*n); | 351 | ogg_uint32_t **codep=(ogg_uint32_t **)_ogg_malloc(sizeof(*codep)*n); |
354 | 352 | ||
355 | if(codes==NULL||codep==NULL)goto err_out; | 353 | if(codes==NULL||codep==NULL){ |
354 | _ogg_free(codep); | ||
355 | _ogg_free(codes); | ||
356 | goto err_out; | ||
357 | } | ||
356 | 358 | ||
357 | for(i=0;i<n;i++){ | 359 | for(i=0;i<n;i++){ |
358 | codes[i]=bitreverse(codes[i]); | 360 | codes[i]=bitreverse(codes[i]); |
@@ -361,7 +363,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ | |||
361 | 363 | ||
362 | qsort(codep,n,sizeof(*codep),sort32a); | 364 | qsort(codep,n,sizeof(*codep),sort32a); |
363 | 365 | ||
364 | sortindex=(int *)ogg_tmpmalloc(n*sizeof(*sortindex)); | 366 | sortindex=(int *)_ogg_malloc(n*sizeof(*sortindex)); |
365 | c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); | 367 | c->codelist=(ogg_uint32_t *)_ogg_malloc(n*sizeof(*c->codelist)); |
366 | /* the index is a reverse index */ | 368 | /* the index is a reverse index */ |
367 | for(i=0;i<n;i++){ | 369 | for(i=0;i<n;i++){ |
@@ -371,7 +373,8 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ | |||
371 | 373 | ||
372 | for(i=0;i<n;i++) | 374 | for(i=0;i<n;i++) |
373 | c->codelist[sortindex[i]]=codes[i]; | 375 | c->codelist[sortindex[i]]=codes[i]; |
374 | /* _ogg_free(codes); */ | 376 | _ogg_free(codep); |
377 | _ogg_free(codes); | ||
375 | 378 | ||
376 | 379 | ||
377 | 380 | ||
@@ -387,6 +390,7 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ | |||
387 | if(s->lengthlist[i]>0) | 390 | if(s->lengthlist[i]>0) |
388 | c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; | 391 | c->dec_codelengths[sortindex[n++]]=s->lengthlist[i]; |
389 | 392 | ||
393 | _ogg_free(sortindex); | ||
390 | c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ | 394 | c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */ |
391 | if(c->dec_firsttablen<5)c->dec_firsttablen=5; | 395 | if(c->dec_firsttablen<5)c->dec_firsttablen=5; |
392 | if(c->dec_firsttablen>8)c->dec_firsttablen=8; | 396 | if(c->dec_firsttablen>8)c->dec_firsttablen=8; |
@@ -434,10 +438,8 @@ int vorbis_book_init_decode(codebook *c,const static_codebook *s){ | |||
434 | } | 438 | } |
435 | } | 439 | } |
436 | 440 | ||
437 | ogg_tmpmalloc_free(pos); | ||
438 | return(0); | 441 | return(0); |
439 | err_out: | 442 | err_out: |
440 | ogg_tmpmalloc_free(pos); | ||
441 | vorbis_book_clear(c); | 443 | vorbis_book_clear(c); |
442 | return(-1); | 444 | return(-1); |
443 | } | 445 | } |