diff options
Diffstat (limited to 'apps/codecs/Tremor/oggmalloc.c')
-rw-r--r-- | apps/codecs/Tremor/oggmalloc.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/apps/codecs/Tremor/oggmalloc.c b/apps/codecs/Tremor/oggmalloc.c new file mode 100644 index 0000000000..eae3d3f1ee --- /dev/null +++ b/apps/codecs/Tremor/oggmalloc.c | |||
@@ -0,0 +1,71 @@ | |||
1 | #include <os_types.h> | ||
2 | |||
3 | static unsigned char *mallocbuf; | ||
4 | static long bufsize, tmp_ptr, mem_ptr; | ||
5 | |||
6 | void ogg_malloc_init(void) | ||
7 | { | ||
8 | mallocbuf = (unsigned char *)ci->get_codec_memory((size_t *)&bufsize); | ||
9 | tmp_ptr = bufsize & ~3; | ||
10 | mem_ptr = 0; | ||
11 | } | ||
12 | |||
13 | void *ogg_malloc(size_t size) | ||
14 | { | ||
15 | void* x; | ||
16 | |||
17 | if (mem_ptr + (long)size > tmp_ptr) | ||
18 | return NULL; | ||
19 | |||
20 | x = &mallocbuf[mem_ptr]; | ||
21 | mem_ptr += (size + 3) & ~3; /* Keep memory 32-bit aligned */ | ||
22 | |||
23 | return x; | ||
24 | } | ||
25 | |||
26 | void *ogg_tmpmalloc(size_t size) | ||
27 | { | ||
28 | if (mem_ptr + (long)size > tmp_ptr) | ||
29 | return NULL; | ||
30 | |||
31 | tmp_ptr -= (size + 3) & ~3; | ||
32 | return &mallocbuf[tmp_ptr]; | ||
33 | } | ||
34 | |||
35 | void *ogg_calloc(size_t nmemb, size_t size) | ||
36 | { | ||
37 | void *x; | ||
38 | x = ogg_malloc(nmemb * size); | ||
39 | if (x == NULL) | ||
40 | return NULL; | ||
41 | ci->memset(x, 0, nmemb * size); | ||
42 | return x; | ||
43 | } | ||
44 | |||
45 | void *ogg_tmpcalloc(size_t nmemb, size_t size) | ||
46 | { | ||
47 | void *x; | ||
48 | x = ogg_tmpmalloc(nmemb * size); | ||
49 | if (x == NULL) | ||
50 | return NULL; | ||
51 | ci->memset(x, 0, nmemb * size); | ||
52 | return x; | ||
53 | } | ||
54 | |||
55 | void *ogg_realloc(void *ptr, size_t size) | ||
56 | { | ||
57 | void *x; | ||
58 | (void)ptr; | ||
59 | x = ogg_malloc(size); | ||
60 | return x; | ||
61 | } | ||
62 | |||
63 | long ogg_tmpmalloc_pos(void) | ||
64 | { | ||
65 | return tmp_ptr; | ||
66 | } | ||
67 | |||
68 | void ogg_tmpmalloc_free(long pos) | ||
69 | { | ||
70 | tmp_ptr = pos; | ||
71 | } | ||