AOMedia Codec SDK: aom/aom_integer.h Source File

AOMedia Codec SDK

aom_integer.h
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 #ifndef AOM_AOM_AOM_INTEGER_H_
12 #define AOM_AOM_AOM_INTEGER_H_
13
14 /* get ptrdiff_t, size_t, wchar_t, NULL */
15 #include <stddef.h>
16
17 #if defined(_MSC_VER)
18 #define AOM_FORCE_INLINE __forceinline
19 #define AOM_INLINE __inline
20 #else
21 #define AOM_FORCE_INLINE __inline__ __attribute__((always_inline))
22 // TODO(jbb): Allow a way to force inline off for older compilers.
23 #define AOM_INLINE inline
24 #endif
25
26 #if defined(AOM_EMULATE_INTTYPES)
27 typedef signed char int8_t;
28 typedef signed short int16_t;
29 typedef signed int int32_t;
30
31 typedef unsigned char uint8_t;
32 typedef unsigned short uint16_t;
33 typedef unsigned int uint32_t;
34
35 #ifndef _UINTPTR_T_DEFINED
36 typedef size_t uintptr_t;
37 #endif
38
39 #else
40
41 /* Most platforms have the C99 standard integer types. */
42
43 #if defined(__cplusplus)
44 #if !defined(__STDC_FORMAT_MACROS)
45 #define __STDC_FORMAT_MACROS
46 #endif
47 #if !defined(__STDC_LIMIT_MACROS)
48 #define __STDC_LIMIT_MACROS
49 #endif
50 #endif // __cplusplus
51
52 #include <stdint.h>
53
54 #endif
55
56 /* VS2010 defines stdint.h, but not inttypes.h */
57 #if defined(_MSC_VER) && _MSC_VER < 1800
58 #define PRId64 "I64d"
59 #else
60 #include <inttypes.h>
61 #endif
62
63 #if !defined(INT8_MAX)
64 #define INT8_MAX 127
65 #endif
66
67 #if !defined(INT32_MAX)
68 #define INT32_MAX 2147483647
69 #endif
70
71 #if !defined(INT32_MIN)
72 #define INT32_MIN (-2147483647 - 1)
73 #endif
74
75 #define NELEMENTS(x) (int)(sizeof(x) / sizeof(x[0]))
76
77 #if defined(__cplusplus)
78 extern "C" {
79 #endif // __cplusplus
80
81 // Returns size of uint64_t when encoded using LEB128.
82 size_t aom_uleb_size_in_bytes(uint64_t value);
83
84 // Returns 0 on success, -1 on decode failure.
85 // On success, 'value' stores the decoded LEB128 value and 'length' stores
86 // the number of bytes decoded.
87 int aom_uleb_decode(const uint8_t *buffer, size_t available, uint64_t *value,
88 size_t *length);
89
90 // Encodes LEB128 integer. Returns 0 when successful, and -1 upon failure.
91 int aom_uleb_encode(uint64_t value, size_t available, uint8_t *coded_value,
92 size_t *coded_size);
93
94 // Encodes LEB128 integer to size specified. Returns 0 when successful, and -1
95 // upon failure.
96 // Note: This will write exactly pad_to_size bytes; if the value cannot be
97 // encoded in this many bytes, then this will fail.
98 int aom_uleb_encode_fixed_size(uint64_t value, size_t available,
99 size_t pad_to_size, uint8_t *coded_value,
100 size_t *coded_size);
101
102 #if defined(__cplusplus)
103 } // extern "C"
104 #endif // __cplusplus
105
106 #endif // AOM_AOM_AOM_INTEGER_H_