aom_integer.h 2.1 KB

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