1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #ifndef AOM_AOM_MEM_AOM_MEM_H_
13 #define AOM_AOM_MEM_AOM_MEM_H_
14
15 #include "aom/aom_integer.h"
16 #include "config/aom_config.h"
17
18 #if defined(__uClinux__)
19 #include <lddk.h>
20 #endif
21
22 #if defined(__cplusplus)
23 extern "C" {
24 #endif
25
26 #ifndef AOM_MAX_ALLOCABLE_MEMORY
27 #if SIZE_MAX > (1ULL << 32)
28 #define AOM_MAX_ALLOCABLE_MEMORY 8589934592 // 8 GB
29 #else
30 // For 32-bit targets keep this below INT_MAX to avoid valgrind warnings.
31 #define AOM_MAX_ALLOCABLE_MEMORY ((1ULL << 31) - (1 << 16))
32 #endif
33 #endif
34
35 void *aom_memalign(size_t align, size_t size);
36 void *aom_malloc(size_t size);
37 void *aom_calloc(size_t num, size_t size);
38 void aom_free(void *memblk);
39
aom_memset16(void * dest,int val,size_t length)40 static inline void *aom_memset16(void *dest, int val, size_t length) {
41 size_t i;
42 uint16_t *dest16 = (uint16_t *)dest;
43 for (i = 0; i < length; i++) *dest16++ = val;
44 return dest;
45 }
46
47 /*returns an addr aligned to the byte boundary specified by align*/
48 #define aom_align_addr(addr, align) \
49 (void *)(((uintptr_t)(addr) + ((align)-1)) & ~(uintptr_t)((align)-1))
50
51 #include <string.h>
52
53 #ifdef AOM_MEM_PLTFRM
54 #include AOM_MEM_PLTFRM
55 #endif
56
57 #if CONFIG_DEBUG
58 #define AOM_CHECK_MEM_ERROR(error_info, lval, expr) \
59 do { \
60 lval = (expr); \
61 if (!lval) \
62 aom_internal_error(error_info, AOM_CODEC_MEM_ERROR, \
63 "Failed to allocate " #lval " at %s:%d", __FILE__, \
64 __LINE__); \
65 } while (0)
66 #else
67 #define AOM_CHECK_MEM_ERROR(error_info, lval, expr) \
68 do { \
69 lval = (expr); \
70 if (!lval) \
71 aom_internal_error(error_info, AOM_CODEC_MEM_ERROR, \
72 "Failed to allocate " #lval); \
73 } while (0)
74 #endif
75
76 #if defined(__cplusplus)
77 }
78 #endif
79
80 #endif // AOM_AOM_MEM_AOM_MEM_H_
81