common.h 2.65 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
2
3
4
5
6
7
8
9
10
/*
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

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

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

#include <assert.h>

#include "./vpx_config.h"
Yaowu Xu's avatar
Yaowu Xu committed
19
20
21
22
#include "aom_dsp/vpx_dsp_common.h"
#include "aom_mem/vpx_mem.h"
#include "aom/vpx_integer.h"
#include "aom_ports/bitops.h"
Jingning Han's avatar
Jingning Han committed
23
24
25
26
27
28

#ifdef __cplusplus
extern "C" {
#endif

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

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

#define vp10_zero(dest) memset(&(dest), 0, sizeof(dest))
#define vp10_zero_array(dest, n) memset(dest, 0, n * sizeof(*dest))

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
50
51
52
53
54
55
56
#define CHECK_MEM_ERROR(cm, lval, expr)                                     \
  do {                                                                      \
    lval = (expr);                                                          \
    if (!lval)                                                              \
      vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,                   \
                         "Failed to allocate " #lval " at %s:%d", __FILE__, \
                         __LINE__);                                         \
Jingning Han's avatar
Jingning Han committed
57
58
  } while (0)
#else
clang-format's avatar
clang-format committed
59
60
61
62
63
64
#define CHECK_MEM_ERROR(cm, lval, expr)                   \
  do {                                                    \
    lval = (expr);                                        \
    if (!lval)                                            \
      vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \
                         "Failed to allocate " #lval);    \
Jingning Han's avatar
Jingning Han committed
65
66
  } while (0)
#endif
67
68
69
70
// TODO(yaowu: validate the usage of these codes or develop new ones.)
#define VP10_SYNC_CODE_0 0x49
#define VP10_SYNC_CODE_1 0x83
#define VP10_SYNC_CODE_2 0x43
Jingning Han's avatar
Jingning Han committed
71

72
#define VPX_FRAME_MARKER 0x2
Jingning Han's avatar
Jingning Han committed
73
74
75
76
77

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

78
#endif  // VP10_COMMON_COMMON_H_