1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vp9/common/vp9_common.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 +#ifndef VP9_COMMON_VP9_COMMON_H_ 1.15 +#define VP9_COMMON_VP9_COMMON_H_ 1.16 + 1.17 +/* Interface header for common constant data structures and lookup tables */ 1.18 + 1.19 +#include <assert.h> 1.20 + 1.21 +#include "./vpx_config.h" 1.22 +#include "vpx_mem/vpx_mem.h" 1.23 +#include "vpx/vpx_integer.h" 1.24 + 1.25 +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) 1.26 +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) 1.27 + 1.28 +#define ROUND_POWER_OF_TWO(value, n) \ 1.29 + (((value) + (1 << ((n) - 1))) >> (n)) 1.30 + 1.31 +#define ALIGN_POWER_OF_TWO(value, n) \ 1.32 + (((value) + ((1 << (n)) - 1)) & ~((1 << (n)) - 1)) 1.33 + 1.34 +// Only need this for fixed-size arrays, for structs just assign. 1.35 +#define vp9_copy(dest, src) { \ 1.36 + assert(sizeof(dest) == sizeof(src)); \ 1.37 + vpx_memcpy(dest, src, sizeof(src)); \ 1.38 + } 1.39 + 1.40 +// Use this for variably-sized arrays. 1.41 +#define vp9_copy_array(dest, src, n) { \ 1.42 + assert(sizeof(*dest) == sizeof(*src)); \ 1.43 + vpx_memcpy(dest, src, n * sizeof(*src)); \ 1.44 + } 1.45 + 1.46 +#define vp9_zero(dest) vpx_memset(&dest, 0, sizeof(dest)) 1.47 +#define vp9_zero_array(dest, n) vpx_memset(dest, 0, n * sizeof(*dest)) 1.48 + 1.49 +static INLINE uint8_t clip_pixel(int val) { 1.50 + return (val > 255) ? 255u : (val < 0) ? 0u : val; 1.51 +} 1.52 + 1.53 +static INLINE int clamp(int value, int low, int high) { 1.54 + return value < low ? low : (value > high ? high : value); 1.55 +} 1.56 + 1.57 +static INLINE double fclamp(double value, double low, double high) { 1.58 + return value < low ? low : (value > high ? high : value); 1.59 +} 1.60 + 1.61 +static int get_unsigned_bits(unsigned int num_values) { 1.62 + int cat = 0; 1.63 + if (num_values <= 1) 1.64 + return 0; 1.65 + num_values--; 1.66 + while (num_values > 0) { 1.67 + cat++; 1.68 + num_values >>= 1; 1.69 + } 1.70 + return cat; 1.71 +} 1.72 + 1.73 +#if CONFIG_DEBUG 1.74 +#define CHECK_MEM_ERROR(cm, lval, expr) do { \ 1.75 + lval = (expr); \ 1.76 + if (!lval) \ 1.77 + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \ 1.78 + "Failed to allocate "#lval" at %s:%d", \ 1.79 + __FILE__, __LINE__); \ 1.80 + } while (0) 1.81 +#else 1.82 +#define CHECK_MEM_ERROR(cm, lval, expr) do { \ 1.83 + lval = (expr); \ 1.84 + if (!lval) \ 1.85 + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, \ 1.86 + "Failed to allocate "#lval); \ 1.87 + } while (0) 1.88 +#endif 1.89 + 1.90 +#define VP9_SYNC_CODE_0 0x49 1.91 +#define VP9_SYNC_CODE_1 0x83 1.92 +#define VP9_SYNC_CODE_2 0x42 1.93 + 1.94 +#define VP9_FRAME_MARKER 0x2 1.95 + 1.96 + 1.97 +#endif // VP9_COMMON_VP9_COMMON_H_