common.h 2.75 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10 11
 */

12 13
#ifndef AV1_COMMON_COMMON_H_
#define AV1_COMMON_COMMON_H_
Jingning Han's avatar
Jingning Han committed
14 15 16 17 18

/* Interface header for common constant data structures and lookup tables */

#include <assert.h>

Adrian Grange's avatar
Adrian Grange committed
19 20 21 22
#include "./aom_config.h"
#include "aom_dsp/aom_dsp_common.h"
#include "aom_mem/aom_mem.h"
#include "aom/aom_integer.h"
Yaowu Xu's avatar
Yaowu Xu committed
23
#include "aom_ports/bitops.h"
Jingning Han's avatar
Jingning Han committed
24 25 26 27 28 29

#ifdef __cplusplus
extern "C" {
#endif

// Only need this for fixed-size arrays, for structs just assign.
clang-format's avatar
clang-format committed
30
#define av1_copy(dest, src)              \
clang-format's avatar
clang-format committed
31
  {                                      \
Jingning Han's avatar
Jingning Han committed
32
    assert(sizeof(dest) == sizeof(src)); \
clang-format's avatar
clang-format committed
33
    memcpy(dest, src, sizeof(src));      \
Jingning Han's avatar
Jingning Han committed
34 35 36
  }

// Use this for variably-sized arrays.
clang-format's avatar
clang-format committed
37
#define av1_copy_array(dest, src, n)       \
clang-format's avatar
clang-format committed
38 39 40
  {                                        \
    assert(sizeof(*dest) == sizeof(*src)); \
    memcpy(dest, src, n * sizeof(*src));   \
Jingning Han's avatar
Jingning Han committed
41 42
  }

43 44
#define av1_zero(dest) memset(&(dest), 0, sizeof(dest))
#define av1_zero_array(dest, n) memset(dest, 0, n * sizeof(*dest))
Jingning Han's avatar
Jingning Han committed
45 46 47 48 49 50

static INLINE int get_unsigned_bits(unsigned int num_values) {
  return num_values > 0 ? get_msb(num_values) + 1 : 0;
}

#if CONFIG_DEBUG
clang-format's avatar
clang-format committed
51 52 53 54
#define CHECK_MEM_ERROR(cm, lval, expr)                                     \
  do {                                                                      \
    lval = (expr);                                                          \
    if (!lval)                                                              \
Adrian Grange's avatar
Adrian Grange committed
55
      aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR,                   \
clang-format's avatar
clang-format committed
56 57
                         "Failed to allocate " #lval " at %s:%d", __FILE__, \
                         __LINE__);                                         \
Jingning Han's avatar
Jingning Han committed
58 59
  } while (0)
#else
clang-format's avatar
clang-format committed
60 61 62 63
#define CHECK_MEM_ERROR(cm, lval, expr)                   \
  do {                                                    \
    lval = (expr);                                        \
    if (!lval)                                            \
Adrian Grange's avatar
Adrian Grange committed
64
      aom_internal_error(&cm->error, AOM_CODEC_MEM_ERROR, \
clang-format's avatar
clang-format committed
65
                         "Failed to allocate " #lval);    \
Jingning Han's avatar
Jingning Han committed
66 67
  } while (0)
#endif
68
// TODO(yaowu: validate the usage of these codes or develop new ones.)
69 70 71
#define AV1_SYNC_CODE_0 0x49
#define AV1_SYNC_CODE_1 0x83
#define AV1_SYNC_CODE_2 0x43
Jingning Han's avatar
Jingning Han committed
72

Adrian Grange's avatar
Adrian Grange committed
73
#define AOM_FRAME_MARKER 0x2
Jingning Han's avatar
Jingning Han committed
74 75 76 77 78

#ifdef __cplusplus
}  // extern "C"
#endif

79
#endif  // AV1_COMMON_COMMON_H_