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