vp9_common.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef VP9_COMMON_VP9_COMMON_H_
  11. #define VP9_COMMON_VP9_COMMON_H_
  12. /* Interface header for common constant data structures and lookup tables */
  13. #include <assert.h>
  14. #include "./vpx_config.h"
  15. #include "vpx_dsp/vpx_dsp_common.h"
  16. #include "vpx_mem/vpx_mem.h"
  17. #include "vpx/vpx_integer.h"
  18. #include "vpx_ports/bitops.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. // Only need this for fixed-size arrays, for structs just assign.
  23. #define vp9_copy(dest, src) \
  24. { \
  25. assert(sizeof(dest) == sizeof(src)); \
  26. memcpy(dest, src, sizeof(src)); \
  27. }
  28. // Use this for variably-sized arrays.
  29. #define vp9_copy_array(dest, src, n) \
  30. { \
  31. assert(sizeof(*dest) == sizeof(*src)); \
  32. memcpy(dest, src, n * sizeof(*src)); \
  33. }
  34. #define vp9_zero(dest) memset(&(dest), 0, sizeof(dest))
  35. #define vp9_zero_array(dest, n) memset(dest, 0, n * sizeof(*dest))
  36. static INLINE int get_unsigned_bits(unsigned int num_values) {
  37. return num_values > 0 ? get_msb(num_values) + 1 : 0;
  38. }
  39. #if CONFIG_DEBUG
  40. #define CHECK_MEM_ERROR(cm, lval, expr) \
  41. do { \
  42. lval = (expr); \
  43. if (!lval) \
  44. vpx_internal_error(&(cm)->error, VPX_CODEC_MEM_ERROR, \
  45. "Failed to allocate " #lval " at %s:%d", __FILE__, \
  46. __LINE__); \
  47. } while (0)
  48. #else
  49. #define CHECK_MEM_ERROR(cm, lval, expr) \
  50. do { \
  51. lval = (expr); \
  52. if (!lval) \
  53. vpx_internal_error(&(cm)->error, VPX_CODEC_MEM_ERROR, \
  54. "Failed to allocate " #lval); \
  55. } while (0)
  56. #endif
  57. #define VP9_SYNC_CODE_0 0x49
  58. #define VP9_SYNC_CODE_1 0x83
  59. #define VP9_SYNC_CODE_2 0x42
  60. #define VP9_FRAME_MARKER 0x2
  61. #ifdef __cplusplus
  62. } // extern "C"
  63. #endif
  64. #endif // VP9_COMMON_VP9_COMMON_H_