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> // IWYU pragma: export 16 17 /* Assume platforms have the C99 standard integer types. */ 18 19 #if defined(__cplusplus) 20 #if !defined(__STDC_FORMAT_MACROS) 21 #define __STDC_FORMAT_MACROS 22 #endif 23 #if !defined(__STDC_LIMIT_MACROS) 24 #define __STDC_LIMIT_MACROS 25 #endif 26 #endif // __cplusplus 27 28 #include <stdint.h> // IWYU pragma: export 29 #include <inttypes.h> // IWYU pragma: export 30 31 #if defined(__cplusplus) 32 extern "C" { 33 #endif // __cplusplus 34 35 // Returns size of uint64_t when encoded using LEB128. 36 size_t aom_uleb_size_in_bytes(uint64_t value); 37 38 // Returns 0 on success, -1 on decode failure. 39 // On success, 'value' stores the decoded LEB128 value and 'length' stores 40 // the number of bytes decoded. 41 int aom_uleb_decode(const uint8_t *buffer, size_t available, uint64_t *value, 42 size_t *length); 43 44 // Encodes LEB128 integer. Returns 0 when successful, and -1 upon failure. 45 int aom_uleb_encode(uint64_t value, size_t available, uint8_t *coded_value, 46 size_t *coded_size); 47 48 // Encodes LEB128 integer to size specified. Returns 0 when successful, and -1 49 // upon failure. 50 // Note: This will write exactly pad_to_size bytes; if the value cannot be 51 // encoded in this many bytes, then this will fail. 52 int aom_uleb_encode_fixed_size(uint64_t value, size_t available, 53 size_t pad_to_size, uint8_t *coded_value, 54 size_t *coded_size); 55 56 #if defined(__cplusplus) 57 } // extern "C" 58 #endif // __cplusplus 59 60 #endif // AOM_AOM_AOM_INTEGER_H_ 61