AOMedia AV1 Codec
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// Work around compiler out of memory issues with Win32 builds. This issue has
19// been observed with Visual Studio 2017 & 2019.
20#if defined(_M_IX86) && _MSC_VER < 1930
21#define AOM_FORCE_INLINE __inline
22#else
23#define AOM_FORCE_INLINE __forceinline
24#endif
25#define AOM_INLINE __inline
26#else
27#define AOM_FORCE_INLINE __inline__ __attribute__((always_inline))
28#define AOM_INLINE inline
29#endif
30
31/* Assume platforms have the C99 standard integer types. */
32
33#if defined(__cplusplus)
34#if !defined(__STDC_FORMAT_MACROS)
35#define __STDC_FORMAT_MACROS
36#endif
37#if !defined(__STDC_LIMIT_MACROS)
38#define __STDC_LIMIT_MACROS
39#endif
40#endif // __cplusplus
41
42#include <stdint.h>
43#include <inttypes.h>
44
45#if defined(__cplusplus)
46extern "C" {
47#endif // __cplusplus
48
49// Returns size of uint64_t when encoded using LEB128.
50size_t aom_uleb_size_in_bytes(uint64_t value);
51
52// Returns 0 on success, -1 on decode failure.
53// On success, 'value' stores the decoded LEB128 value and 'length' stores
54// the number of bytes decoded.
55int aom_uleb_decode(const uint8_t *buffer, size_t available, uint64_t *value,
56 size_t *length);
57
58// Encodes LEB128 integer. Returns 0 when successful, and -1 upon failure.
59int aom_uleb_encode(uint64_t value, size_t available, uint8_t *coded_value,
60 size_t *coded_size);
61
62// Encodes LEB128 integer to size specified. Returns 0 when successful, and -1
63// upon failure.
64// Note: This will write exactly pad_to_size bytes; if the value cannot be
65// encoded in this many bytes, then this will fail.
66int aom_uleb_encode_fixed_size(uint64_t value, size_t available,
67 size_t pad_to_size, uint8_t *coded_value,
68 size_t *coded_size);
69
70#if defined(__cplusplus)
71} // extern "C"
72#endif // __cplusplus
73
74#endif // AOM_AOM_AOM_INTEGER_H_