| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 | 11 |
| 12 #ifndef __VPX_MEM_H__ | 12 #ifndef __VPX_MEM_H__ |
| 13 #define __VPX_MEM_H__ | 13 #define __VPX_MEM_H__ |
| 14 | 14 |
| 15 #include "vpx_config.h" |
| 15 #if defined(__uClinux__) | 16 #if defined(__uClinux__) |
| 16 # include <lddk.h> | 17 # include <lddk.h> |
| 17 #endif | 18 #endif |
| 18 | 19 |
| 19 /* vpx_mem version info */ | 20 /* vpx_mem version info */ |
| 20 #define vpx_mem_version "2.2.1.5" | 21 #define vpx_mem_version "2.2.1.5" |
| 21 | 22 |
| 22 #define VPX_MEM_VERSION_CHIEF 2 | 23 #define VPX_MEM_VERSION_CHIEF 2 |
| 23 #define VPX_MEM_VERSION_MAJOR 2 | 24 #define VPX_MEM_VERSION_MAJOR 2 |
| 24 #define VPX_MEM_VERSION_MINOR 1 | 25 #define VPX_MEM_VERSION_MINOR 1 |
| 25 #define VPX_MEM_VERSION_PATCH 5 | 26 #define VPX_MEM_VERSION_PATCH 5 |
| 26 /* end - vpx_mem version info */ | 27 /* end - vpx_mem version info */ |
| 27 | 28 |
| 28 #ifndef VPX_TRACK_MEM_USAGE | 29 #ifndef VPX_TRACK_MEM_USAGE |
| 29 # define VPX_TRACK_MEM_USAGE 0 /* enable memory tracking/integrity checks
*/ | 30 # define VPX_TRACK_MEM_USAGE 0 /* enable memory tracking/integrity checks
*/ |
| 30 #endif | 31 #endif |
| 31 #ifndef VPX_CHECK_MEM_FUNCTIONS | 32 #ifndef VPX_CHECK_MEM_FUNCTIONS |
| 32 # define VPX_CHECK_MEM_FUNCTIONS 0 /* enable basic safety checks in _memcpy, | 33 # define VPX_CHECK_MEM_FUNCTIONS 0 /* enable basic safety checks in _memcpy, |
| 33 _memset, and _memmove */ | 34 _memset, and _memmove */ |
| 34 #endif | 35 #endif |
| 35 #ifndef REPLACE_BUILTIN_FUNCTIONS | 36 #ifndef REPLACE_BUILTIN_FUNCTIONS |
| 36 # define REPLACE_BUILTIN_FUNCTIONS 0 /* replace builtin functions with their | 37 # define REPLACE_BUILTIN_FUNCTIONS 0 /* replace builtin functions with their |
| 37 vpx_ equivalents */ | 38 vpx_ equivalents */ |
| 38 #endif | 39 #endif |
| 39 | 40 |
| 40 #include <stdlib.h> | 41 #include <stdlib.h> |
| 41 #include <stddef.h> | 42 #include <stddef.h> |
| 42 | 43 |
| 43 #if defined(__cplusplus) | 44 #if defined(__cplusplus) |
| 44 extern "C" { | 45 extern "C" { |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 /* | 48 /* |
| 48 vpx_mem_get_version() | 49 vpx_mem_get_version() |
| 49 provided for runtime version checking. Returns an unsigned int of the fo
rm | 50 provided for runtime version checking. Returns an unsigned int of the form |
| 50 CHIEF | MAJOR | MINOR | PATCH, where the chief version number is the hig
h | 51 CHIEF | MAJOR | MINOR | PATCH, where the chief version number is the high |
| 51 order byte. | 52 order byte. |
| 52 */ | 53 */ |
| 53 unsigned int vpx_mem_get_version(void); | 54 unsigned int vpx_mem_get_version(void); |
| 54 | 55 |
| 55 /* | 56 /* |
| 56 vpx_mem_set_heap_size(size_t size) | 57 vpx_mem_set_heap_size(size_t size) |
| 57 size - size in bytes for the memory manager to allocate for its heap | 58 size - size in bytes for the memory manager to allocate for its heap |
| 58 Sets the memory manager's initial heap size | 59 Sets the memory manager's initial heap size |
| 59 Return: | 60 Return: |
| 60 0: on success | 61 0: on success |
| 61 -1: if memory manager calls have not been included in the vpx_mem lib | 62 -1: if memory manager calls have not been included in the vpx_mem lib |
| 62 -2: if the memory manager has been compiled to use static memory | 63 -2: if the memory manager has been compiled to use static memory |
| 63 -3: if the memory manager has already allocated its heap | 64 -3: if the memory manager has already allocated its heap |
| 64 */ | 65 */ |
| 65 int vpx_mem_set_heap_size(size_t size); | 66 int vpx_mem_set_heap_size(size_t size); |
| 66 | 67 |
| 67 void *vpx_memalign(size_t align, size_t size); | 68 void *vpx_memalign(size_t align, size_t size); |
| 68 void *vpx_malloc(size_t size); | 69 void *vpx_malloc(size_t size); |
| 69 void *vpx_calloc(size_t num, size_t size); | 70 void *vpx_calloc(size_t num, size_t size); |
| 70 void *vpx_realloc(void *memblk, size_t size); | 71 void *vpx_realloc(void *memblk, size_t size); |
| 71 void vpx_free(void *memblk); | 72 void vpx_free(void *memblk); |
| 72 | 73 |
| 73 void *vpx_memcpy(void *dest, const void *src, size_t length); | 74 void *vpx_memcpy(void *dest, const void *src, size_t length); |
| 74 void *vpx_memset(void *dest, int val, size_t length); | 75 void *vpx_memset(void *dest, int val, size_t length); |
| 75 void *vpx_memmove(void *dest, const void *src, size_t count); | 76 void *vpx_memmove(void *dest, const void *src, size_t count); |
| 76 | 77 |
| 77 /* special memory functions */ | 78 /* special memory functions */ |
| 78 void *vpx_mem_alloc(int id, size_t size, size_t align); | 79 void *vpx_mem_alloc(int id, size_t size, size_t align); |
| 79 void vpx_mem_free(int id, void *mem, size_t size); | 80 void vpx_mem_free(int id, void *mem, size_t size); |
| 80 | 81 |
| 81 /* Wrappers to standard library functions. */ | 82 /* Wrappers to standard library functions. */ |
| 82 typedef void*(* g_malloc_func)(size_t); | 83 typedef void *(* g_malloc_func)(size_t); |
| 83 typedef void*(* g_calloc_func)(size_t, size_t); | 84 typedef void *(* g_calloc_func)(size_t, size_t); |
| 84 typedef void*(* g_realloc_func)(void *, size_t); | 85 typedef void *(* g_realloc_func)(void *, size_t); |
| 85 typedef void (* g_free_func)(void *); | 86 typedef void (* g_free_func)(void *); |
| 86 typedef void*(* g_memcpy_func)(void *, const void *, size_t); | 87 typedef void *(* g_memcpy_func)(void *, const void *, size_t); |
| 87 typedef void*(* g_memset_func)(void *, int, size_t); | 88 typedef void *(* g_memset_func)(void *, int, size_t); |
| 88 typedef void*(* g_memmove_func)(void *, const void *, size_t); | 89 typedef void *(* g_memmove_func)(void *, const void *, size_t); |
| 89 | 90 |
| 90 int vpx_mem_set_functions(g_malloc_func g_malloc_l | 91 int vpx_mem_set_functions(g_malloc_func g_malloc_l |
| 91 , g_calloc_func g_calloc_l | 92 , g_calloc_func g_calloc_l |
| 92 , g_realloc_func g_realloc_l | 93 , g_realloc_func g_realloc_l |
| 93 , g_free_func g_free_l | 94 , g_free_func g_free_l |
| 94 , g_memcpy_func g_memcpy_l | 95 , g_memcpy_func g_memcpy_l |
| 95 , g_memset_func g_memset_l | 96 , g_memset_func g_memset_l |
| 96 , g_memmove_func g_memmove_l); | 97 , g_memmove_func g_memmove_l); |
| 97 int vpx_mem_unset_functions(void); | 98 int vpx_mem_unset_functions(void); |
| 98 | 99 |
| 99 | 100 |
| 100 /* some defines for backward compatibility */ | 101 /* some defines for backward compatibility */ |
| 101 #define DMEM_GENERAL 0 | 102 #define DMEM_GENERAL 0 |
| 102 | 103 |
| 103 #define duck_memalign(X,Y,Z) vpx_memalign(X,Y) | 104 #define duck_memalign(X,Y,Z) vpx_memalign(X,Y) |
| 104 #define duck_malloc(X,Y) vpx_malloc(X) | 105 #define duck_malloc(X,Y) vpx_malloc(X) |
| 105 #define duck_calloc(X,Y,Z) vpx_calloc(X,Y) | 106 #define duck_calloc(X,Y,Z) vpx_calloc(X,Y) |
| 106 #define duck_realloc vpx_realloc | 107 #define duck_realloc vpx_realloc |
| 107 #define duck_free vpx_free | 108 #define duck_free vpx_free |
| 108 #define duck_memcpy vpx_memcpy | 109 #define duck_memcpy vpx_memcpy |
| 109 #define duck_memmove vpx_memmove | 110 #define duck_memmove vpx_memmove |
| 110 #define duck_memset vpx_memset | 111 #define duck_memset vpx_memset |
| 111 | 112 |
| 112 #if REPLACE_BUILTIN_FUNCTIONS | 113 #if REPLACE_BUILTIN_FUNCTIONS |
| 113 # ifndef __VPX_MEM_C__ | 114 # ifndef __VPX_MEM_C__ |
| 114 # define memalign vpx_memalign | 115 # define memalign vpx_memalign |
| 115 # define malloc vpx_malloc | 116 # define malloc vpx_malloc |
| 116 # define calloc vpx_calloc | 117 # define calloc vpx_calloc |
| 117 # define realloc vpx_realloc | 118 # define realloc vpx_realloc |
| 118 # define free vpx_free | 119 # define free vpx_free |
| 119 # define memcpy vpx_memcpy | 120 # define memcpy vpx_memcpy |
| 120 # define memmove vpx_memmove | 121 # define memmove vpx_memmove |
| 121 # define memset vpx_memset | 122 # define memset vpx_memset |
| 122 # endif | 123 # endif |
| 123 #endif | 124 #endif |
| 124 | 125 |
| 125 #if CONFIG_MEM_TRACKER | 126 #if CONFIG_MEM_TRACKER |
| 126 #include <stdarg.h> | 127 #include <stdarg.h> |
| 127 /*from vpx_mem/vpx_mem_tracker.c*/ | 128 /*from vpx_mem/vpx_mem_tracker.c*/ |
| 128 extern void vpx_memory_tracker_dump(); | 129 extern void vpx_memory_tracker_dump(); |
| 129 extern void vpx_memory_tracker_check_integrity(char *file, unsigned int line
); | 130 extern void vpx_memory_tracker_check_integrity(char *file, unsigned int line); |
| 130 extern int vpx_memory_tracker_set_log_type(int type, char *option); | 131 extern int vpx_memory_tracker_set_log_type(int type, char *option); |
| 131 extern int vpx_memory_tracker_set_log_func(void *userdata, | 132 extern int vpx_memory_tracker_set_log_func(void *userdata, |
| 132 void(*logfunc)(void *userdata, | 133 void(*logfunc)(void *userdata, |
| 133 const char *fmt, va_list args)); | 134 const char *fmt, va_
list args)); |
| 134 # ifndef __VPX_MEM_C__ | 135 # ifndef __VPX_MEM_C__ |
| 135 # define vpx_memalign(align, size) xvpx_memalign((align), (size), __FILE__, __L
INE__) | 136 # define vpx_memalign(align, size) xvpx_memalign((align), (size), __FILE__, __L
INE__) |
| 136 # define vpx_malloc(size) xvpx_malloc((size), __FILE__, __LINE__) | 137 # define vpx_malloc(size) xvpx_malloc((size), __FILE__, __LINE__) |
| 137 # define vpx_calloc(num, size) xvpx_calloc(num, size, __FILE__, __LINE__) | 138 # define vpx_calloc(num, size) xvpx_calloc(num, size, __FILE__, __LINE__) |
| 138 # define vpx_realloc(addr, size) xvpx_realloc(addr, size, __FILE__, __LINE__) | 139 # define vpx_realloc(addr, size) xvpx_realloc(addr, size, __FILE__, __LINE__) |
| 139 # define vpx_free(addr) xvpx_free(addr, __FILE__, __LINE__) | 140 # define vpx_free(addr) xvpx_free(addr, __FILE__, __LINE__) |
| 140 # define vpx_memory_tracker_check_integrity() vpx_memory_tracker_check_integrit
y(__FILE__, __LINE__) | 141 # define vpx_memory_tracker_check_integrity() vpx_memory_tracker_check_integrit
y(__FILE__, __LINE__) |
| 141 # define vpx_mem_alloc(id,size,align) xvpx_mem_alloc(id, size, align, __FILE__,
__LINE__) | 142 # define vpx_mem_alloc(id,size,align) xvpx_mem_alloc(id, size, align, __FILE__,
__LINE__) |
| 142 # define vpx_mem_free(id,mem,size) xvpx_mem_free(id, mem, size, __FILE__, __LIN
E__) | 143 # define vpx_mem_free(id,mem,size) xvpx_mem_free(id, mem, size, __FILE__, __LIN
E__) |
| 143 # endif | 144 # endif |
| 144 | 145 |
| 145 void *xvpx_memalign(size_t align, size_t size, char *file, int line); | 146 void *xvpx_memalign(size_t align, size_t size, char *file, int line); |
| 146 void *xvpx_malloc(size_t size, char *file, int line); | 147 void *xvpx_malloc(size_t size, char *file, int line); |
| 147 void *xvpx_calloc(size_t num, size_t size, char *file, int line); | 148 void *xvpx_calloc(size_t num, size_t size, char *file, int line); |
| 148 void *xvpx_realloc(void *memblk, size_t size, char *file, int line); | 149 void *xvpx_realloc(void *memblk, size_t size, char *file, int line); |
| 149 void xvpx_free(void *memblk, char *file, int line); | 150 void xvpx_free(void *memblk, char *file, int line); |
| 150 void *xvpx_mem_alloc(int id, size_t size, size_t align, char *file, int line
); | 151 void *xvpx_mem_alloc(int id, size_t size, size_t align, char *file, int line); |
| 151 void xvpx_mem_free(int id, void *mem, size_t size, char *file, int line); | 152 void xvpx_mem_free(int id, void *mem, size_t size, char *file, int line); |
| 152 | 153 |
| 153 #else | 154 #else |
| 154 # ifndef __VPX_MEM_C__ | 155 # ifndef __VPX_MEM_C__ |
| 155 # define vpx_memory_tracker_dump() | 156 # define vpx_memory_tracker_dump() |
| 156 # define vpx_memory_tracker_check_integrity() | 157 # define vpx_memory_tracker_check_integrity() |
| 157 # define vpx_memory_tracker_set_log_type(t,o) 0 | 158 # define vpx_memory_tracker_set_log_type(t,o) 0 |
| 158 # define vpx_memory_tracker_set_log_func(u,f) 0 | 159 # define vpx_memory_tracker_set_log_func(u,f) 0 |
| 159 # endif | 160 # endif |
| 160 #endif | 161 #endif |
| 161 | 162 |
| 162 #if !VPX_CHECK_MEM_FUNCTIONS | 163 #if !VPX_CHECK_MEM_FUNCTIONS |
| 163 # ifndef __VPX_MEM_C__ | 164 # ifndef __VPX_MEM_C__ |
| 164 # include <string.h> | 165 # include <string.h> |
| 165 # define vpx_memcpy memcpy | 166 # define vpx_memcpy memcpy |
| 166 # define vpx_memset memset | 167 # define vpx_memset memset |
| 167 # define vpx_memmove memmove | 168 # define vpx_memmove memmove |
| 168 # endif | 169 # endif |
| 169 #endif | 170 #endif |
| 170 | 171 |
| 171 #ifdef VPX_MEM_PLTFRM | 172 #ifdef VPX_MEM_PLTFRM |
| 172 # include VPX_MEM_PLTFRM | 173 # include VPX_MEM_PLTFRM |
| 173 #endif | 174 #endif |
| 174 | 175 |
| 175 #if defined(__cplusplus) | 176 #if defined(__cplusplus) |
| 176 } | 177 } |
| 177 #endif | 178 #endif |
| 178 | 179 |
| 179 #endif /* __VPX_MEM_H__ */ | 180 #endif /* __VPX_MEM_H__ */ |
| OLD | NEW |