diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2007-09-28 11:12:45 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2007-09-28 11:12:45 +0000 |
commit | d7cb90722f2cbda4c10c1552248a54633d30820c (patch) | |
tree | 99521bf3557f7ad9f59d7084f84658afa91deb8d /apps/plugins/mpegplayer/alloc.c | |
parent | a13a1d5492ce30c51f4b2277819d2a6736705c90 (diff) | |
download | rockbox-d7cb90722f2cbda4c10c1552248a54633d30820c.tar.gz rockbox-d7cb90722f2cbda4c10c1552248a54633d30820c.zip |
Get the plugins synced up with the threading changes.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14881 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/mpegplayer/alloc.c')
-rw-r--r-- | apps/plugins/mpegplayer/alloc.c | 102 |
1 files changed, 73 insertions, 29 deletions
diff --git a/apps/plugins/mpegplayer/alloc.c b/apps/plugins/mpegplayer/alloc.c index 3bdf7ecb0a..b8f68458c0 100644 --- a/apps/plugins/mpegplayer/alloc.c +++ b/apps/plugins/mpegplayer/alloc.c @@ -27,40 +27,71 @@ extern struct plugin_api* rb; -long mem_ptr; -long bufsize; -unsigned char* mallocbuf; - -void mpeg2_alloc_init(unsigned char* buf, int mallocsize) +/* Main allocator */ +static off_t mem_ptr; +static size_t bufsize; +static unsigned char* mallocbuf; + +/* libmpeg2 allocator */ +static off_t mpeg2_mem_ptr; +static size_t mpeg2_bufsize; +static unsigned char *mpeg2_mallocbuf; + +static void * mpeg_malloc_internal (unsigned char *mallocbuf, + off_t *mem_ptr, + size_t bufsize, + unsigned size, + int reason) { - mem_ptr = 0; - bufsize = mallocsize; - mallocbuf = buf; - rb->memset(buf,0,bufsize); + void *x; - return; + if (*mem_ptr + size > bufsize) + { + DEBUGF("OUT OF MEMORY\n"); + return NULL; + } + + x = &mallocbuf[*mem_ptr]; + *mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */ + + return x; + (void)reason; } -void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason) +void *mpeg_malloc(size_t size, mpeg2_alloc_t reason) { - void* x; + return mpeg_malloc_internal(mallocbuf, &mem_ptr, bufsize, size, + reason); +} - (void)reason; +size_t mpeg_alloc_init(unsigned char *buf, size_t mallocsize, + size_t libmpeg2size) +{ + mem_ptr = 0; + bufsize = mallocsize; + /* Line-align buffer */ + mallocbuf = (char *)(((intptr_t)buf + 15) & ~15); + /* Adjust for real size */ + bufsize -= mallocbuf - buf; + rb->memset(buf,0,bufsize); - DEBUGF("mpeg2_malloc(%d,%d)\n",size,reason); - if (mem_ptr + (long)size > bufsize) { - DEBUGF("OUT OF MEMORY\n"); - return NULL; + /* Separate allocator for video */ + libmpeg2size = (libmpeg2size + 15) & ~15; + if (mpeg_malloc_internal(mallocbuf, &mem_ptr, + bufsize, libmpeg2size, 0) == NULL) + { + return 0; } - - x=&mallocbuf[mem_ptr]; - mem_ptr+=(size+3)&~3; /* Keep memory 32-bit aligned */ - return(x); -} + mpeg2_mallocbuf = mallocbuf; + mpeg2_mem_ptr = 0; + mpeg2_bufsize = libmpeg2size; -void mpeg2_free(void* ptr) { - (void)ptr; +#if NUM_CORES > 1 + flush_icache(); +#endif + + return bufsize - mpeg2_bufsize; } /* gcc may want to use memcpy before rb is initialised, so here's a trivial @@ -77,18 +108,30 @@ void *memcpy(void *dest, const void *src, size_t n) { return dest; } +void * mpeg2_malloc(unsigned size, mpeg2_alloc_t reason) +{ + return mpeg_malloc_internal(mpeg2_mallocbuf, &mpeg2_mem_ptr, + mpeg2_bufsize, size, reason); +} + +void mpeg2_free(void *ptr) +{ + (void)ptr; +} /* The following are expected by libmad */ -void* codec_malloc(size_t size) +void * codec_malloc(size_t size) { - return mpeg2_malloc(size,-3); + return mpeg_malloc_internal(mallocbuf, &mem_ptr, + bufsize, size, -3); } -void* codec_calloc(size_t nmemb, size_t size) +void * codec_calloc(size_t nmemb, size_t size) { void* ptr; - ptr = mpeg2_malloc(nmemb*size,-3); + ptr = mpeg_malloc_internal(mallocbuf, &mem_ptr, + bufsize, nmemb*size, -3); if (ptr) rb->memset(ptr,0,size); @@ -96,7 +139,8 @@ void* codec_calloc(size_t nmemb, size_t size) return ptr; } -void codec_free(void* ptr) { +void codec_free(void* ptr) +{ (void)ptr; } |