summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libopus/ogg/os_types.h
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2013-05-18 19:48:08 +0200
committerNils Wallménius <nils@rockbox.org>2013-05-18 23:38:23 +0200
commitc7124b552044ef92a128481d32df081d1210cbe1 (patch)
tree4e596edb09396ef96ab93d064fddcae179d51ef7 /lib/rbcodec/codecs/libopus/ogg/os_types.h
parentfc0cf8d91b1710d7843981d56ef2ac9a6dfeb294 (diff)
downloadrockbox-c7124b552044ef92a128481d32df081d1210cbe1.tar.gz
rockbox-c7124b552044ef92a128481d32df081d1210cbe1.zip
Fix opus craches with large embedded album art
Use the tlsf malloc and friends instead of the silly codec_malloc to get actually working free and saner realloc that doesn't leak memory. Makes files with moderately sized embedded AA play on targets with large enough codec buffers and files with too large AA are now skipped rather than crashing. Fixes crash when playing example file in FS#12842. Change-Id: I06562955c4d9a95bd90f55738214fba462092b71
Diffstat (limited to 'lib/rbcodec/codecs/libopus/ogg/os_types.h')
-rw-r--r--lib/rbcodec/codecs/libopus/ogg/os_types.h66
1 files changed, 32 insertions, 34 deletions
diff --git a/lib/rbcodec/codecs/libopus/ogg/os_types.h b/lib/rbcodec/codecs/libopus/ogg/os_types.h
index 55f0bf559c..c97f4072a3 100644
--- a/lib/rbcodec/codecs/libopus/ogg/os_types.h
+++ b/lib/rbcodec/codecs/libopus/ogg/os_types.h
@@ -1,56 +1,54 @@
1#include "config.h" 1#ifndef OS_TYPES_H
2#include <stdint.h> 2#define OS_TYPES_H
3#include "codeclib.h" 3#include "codeclib.h"
4#include <stdint.h>
5#include <tlsf.h>
4 6
5#ifdef SIMULATOR 7static inline void ogg_malloc_init(void)
6
7#include <stdio.h>
8
9static inline void* _ogg_malloc(size_t size)
10{ 8{
11 void *buf; 9 size_t bufsize;
12 10 void* buf = ci->codec_get_buffer(&bufsize);
13 printf("ogg_malloc %d", size); 11 init_memory_pool(bufsize, buf);
14 buf = codec_malloc(size);
15 printf(" = %p\n", buf);
16
17 return buf;
18} 12}
19 13
20static inline void* _ogg_calloc(size_t nmemb, size_t size) 14static inline void ogg_malloc_destroy(void)
21{ 15{
22 printf("ogg_calloc %d %d\n", nmemb, size); 16 size_t bufsize;
23 return codec_calloc(nmemb, size); 17 void* buf = ci->codec_get_buffer(&bufsize);
18 destroy_memory_pool(buf);
24} 19}
25 20
26static inline void* _ogg_realloc(void *ptr, size_t size) 21static inline void *_ogg_malloc(size_t size)
27{ 22{
28 void *buf; 23 void* x = tlsf_malloc(size);
29 24 DEBUGF("ogg_malloc %zu = %p\n", size, x);
30 printf("ogg_realloc %p %d", ptr, size); 25 return x;
31 buf = codec_realloc(ptr, size);
32 printf(" = %p\n", buf);
33 return buf;
34} 26}
35 27
36static inline void _ogg_free(void *ptr) 28static inline void *_ogg_calloc(size_t nmemb, size_t size)
37{ 29{
38 printf("ogg_free %p\n", ptr); 30 void *x = tlsf_calloc(nmemb, size);
39 codec_free(ptr); 31 DEBUGF("ogg_calloc %zu %zu\n", nmemb, size);
32 return x;
40} 33}
41 34
42#else 35static inline void *_ogg_realloc(void *ptr, size_t size)
43 36{
44#define _ogg_malloc codec_malloc 37 void *x = tlsf_realloc(ptr, size);
45#define _ogg_calloc codec_calloc 38 DEBUGF("ogg_realloc %p %zu = %p\n", ptr, size, x);
46#define _ogg_realloc codec_realloc 39 return x;
47#define _ogg_free codec_free 40}
48 41
49#endif 42static inline void _ogg_free(void* ptr)
43{
44 DEBUGF("ogg_free %p\n", ptr);
45 tlsf_free(ptr);
46}
50 47
51typedef int16_t ogg_int16_t; 48typedef int16_t ogg_int16_t;
52typedef uint16_t ogg_uint16_t; 49typedef uint16_t ogg_uint16_t;
53typedef int32_t ogg_int32_t; 50typedef int32_t ogg_int32_t;
54typedef uint32_t ogg_uint32_t; 51typedef uint32_t ogg_uint32_t;
55typedef int64_t ogg_int64_t; 52typedef int64_t ogg_int64_t;
53#endif /* OS_TYPES_H */
56 54