summaryrefslogtreecommitdiff
path: root/apps/plugins/mpegplayer/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/mpegplayer/alloc.c')
-rw-r--r--apps/plugins/mpegplayer/alloc.c102
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 @@
27 27
28extern struct plugin_api* rb; 28extern struct plugin_api* rb;
29 29
30long mem_ptr; 30/* Main allocator */
31long bufsize; 31static off_t mem_ptr;
32unsigned char* mallocbuf; 32static size_t bufsize;
33 33static unsigned char* mallocbuf;
34void mpeg2_alloc_init(unsigned char* buf, int mallocsize) 34
35/* libmpeg2 allocator */
36static off_t mpeg2_mem_ptr;
37static size_t mpeg2_bufsize;
38static unsigned char *mpeg2_mallocbuf;
39
40static void * mpeg_malloc_internal (unsigned char *mallocbuf,
41 off_t *mem_ptr,
42 size_t bufsize,
43 unsigned size,
44 int reason)
35{ 45{
36 mem_ptr = 0; 46 void *x;
37 bufsize = mallocsize;
38 mallocbuf = buf;
39 rb->memset(buf,0,bufsize);
40 47
41 return; 48 if (*mem_ptr + size > bufsize)
49 {
50 DEBUGF("OUT OF MEMORY\n");
51 return NULL;
52 }
53
54 x = &mallocbuf[*mem_ptr];
55 *mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */
56
57 return x;
58 (void)reason;
42} 59}
43 60
44void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason) 61void *mpeg_malloc(size_t size, mpeg2_alloc_t reason)
45{ 62{
46 void* x; 63 return mpeg_malloc_internal(mallocbuf, &mem_ptr, bufsize, size,
64 reason);
65}
47 66
48 (void)reason; 67size_t mpeg_alloc_init(unsigned char *buf, size_t mallocsize,
68 size_t libmpeg2size)
69{
70 mem_ptr = 0;
71 bufsize = mallocsize;
72 /* Line-align buffer */
73 mallocbuf = (char *)(((intptr_t)buf + 15) & ~15);
74 /* Adjust for real size */
75 bufsize -= mallocbuf - buf;
76 rb->memset(buf,0,bufsize);
49 77
50 DEBUGF("mpeg2_malloc(%d,%d)\n",size,reason); 78 /* Separate allocator for video */
51 if (mem_ptr + (long)size > bufsize) { 79 libmpeg2size = (libmpeg2size + 15) & ~15;
52 DEBUGF("OUT OF MEMORY\n"); 80 if (mpeg_malloc_internal(mallocbuf, &mem_ptr,
53 return NULL; 81 bufsize, libmpeg2size, 0) == NULL)
82 {
83 return 0;
54 } 84 }
55
56 x=&mallocbuf[mem_ptr];
57 mem_ptr+=(size+3)&~3; /* Keep memory 32-bit aligned */
58 85
59 return(x); 86 mpeg2_mallocbuf = mallocbuf;
60} 87 mpeg2_mem_ptr = 0;
88 mpeg2_bufsize = libmpeg2size;
61 89
62void mpeg2_free(void* ptr) { 90#if NUM_CORES > 1
63 (void)ptr; 91 flush_icache();
92#endif
93
94 return bufsize - mpeg2_bufsize;
64} 95}
65 96
66/* gcc may want to use memcpy before rb is initialised, so here's a trivial 97/* 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) {
77 return dest; 108 return dest;
78} 109}
79 110
111void * mpeg2_malloc(unsigned size, mpeg2_alloc_t reason)
112{
113 return mpeg_malloc_internal(mpeg2_mallocbuf, &mpeg2_mem_ptr,
114 mpeg2_bufsize, size, reason);
115}
116
117void mpeg2_free(void *ptr)
118{
119 (void)ptr;
120}
80 121
81/* The following are expected by libmad */ 122/* The following are expected by libmad */
82void* codec_malloc(size_t size) 123void * codec_malloc(size_t size)
83{ 124{
84 return mpeg2_malloc(size,-3); 125 return mpeg_malloc_internal(mallocbuf, &mem_ptr,
126 bufsize, size, -3);
85} 127}
86 128
87void* codec_calloc(size_t nmemb, size_t size) 129void * codec_calloc(size_t nmemb, size_t size)
88{ 130{
89 void* ptr; 131 void* ptr;
90 132
91 ptr = mpeg2_malloc(nmemb*size,-3); 133 ptr = mpeg_malloc_internal(mallocbuf, &mem_ptr,
134 bufsize, nmemb*size, -3);
92 135
93 if (ptr) 136 if (ptr)
94 rb->memset(ptr,0,size); 137 rb->memset(ptr,0,size);
@@ -96,7 +139,8 @@ void* codec_calloc(size_t nmemb, size_t size)
96 return ptr; 139 return ptr;
97} 140}
98 141
99void codec_free(void* ptr) { 142void codec_free(void* ptr)
143{
100 (void)ptr; 144 (void)ptr;
101} 145}
102 146