| 1 |
/* |
| 2 |
* Copyright © 2015 Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the |
| 6 |
* "Software"), to deal in the Software without restriction, including |
| 7 |
* without limitation the rights to use, copy, modify, merge, publish, |
| 8 |
* distribute, sub license, and/or sell copies of the Software, and to |
| 9 |
* permit persons to whom the Software is furnished to do so, subject to |
| 10 |
* the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the |
| 13 |
* next paragraph) shall be included in all copies or substantial portions |
| 14 |
* of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 17 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
| 19 |
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR |
| 20 |
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 |
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 |
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 |
* |
| 24 |
*/ |
| 25 |
/* |
| 26 |
* This file defines some vp9 probability tables, and |
| 27 |
* they are ported from libvpx (https://github.com/webmproject/libvpx/). |
| 28 |
* The original copyright and licence statement as below. |
| 29 |
*/ |
| 30 |
|
| 31 |
/* |
| 32 |
* Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 33 |
* |
| 34 |
* Use of this source code is governed by a BSD-style license |
| 35 |
* that can be found in the LICENSE file in the root of the source |
| 36 |
* tree. An additional intellectual property rights grant can be found |
| 37 |
* in the file PATENTS. All contributing project authors may |
| 38 |
* be found in the AUTHORS file in the root of the source tree. |
| 39 |
*/ |
| 40 |
|
| 41 |
#ifndef VP9_PROBS_H |
| 42 |
#define VP9_PROBS_H |
| 43 |
|
| 44 |
#include <stdbool.h> |
| 45 |
|
| 46 |
#define TX_SIZE_CONTEXTS 2 |
| 47 |
#define TX_SIZES 4 |
| 48 |
#define PLANE_TYPES 2 |
| 49 |
#define SKIP_CONTEXTS 3 |
| 50 |
#define INTER_MODE_CONTEXTS 7 |
| 51 |
#define INTER_MODES 4 |
| 52 |
#define SWITCHABLE_FILTERS 3 |
| 53 |
#define SWITCHABLE_FILTER_CONTEXTS (SWITCHABLE_FILTERS + 1) |
| 54 |
#define MAX_SEGMENTS 8 |
| 55 |
#define PREDICTION_PROBS 3 |
| 56 |
#define SEG_TREE_PROBS (MAX_SEGMENTS-1) |
| 57 |
#define MV_JOINTS 4 |
| 58 |
#define INTRA_INTER_CONTEXTS 4 |
| 59 |
#define COMP_INTER_CONTEXTS 5 |
| 60 |
#define REF_CONTEXTS 5 |
| 61 |
#define BLOCK_SIZE_GROUPS 4 |
| 62 |
#define INTRA_MODES 10 |
| 63 |
#define PARTITION_PLOFFSET 4 // number of probability models per block size |
| 64 |
#define PARTITION_CONTEXTS (4 * PARTITION_PLOFFSET) |
| 65 |
#define PARTITION_TYPES 4 |
| 66 |
#define REF_TYPES 2 // intra=0, inter=1 |
| 67 |
#define COEF_BANDS 6 |
| 68 |
#define COEFF_CONTEXTS 6 |
| 69 |
#define UNCONSTRAINED_NODES 3 |
| 70 |
#define MV_CLASSES 11 |
| 71 |
#define CLASS0_BITS 1 /* bits at integer precision for class 0 */ |
| 72 |
#define CLASS0_SIZE (1 << CLASS0_BITS) |
| 73 |
#define MV_OFFSET_BITS (MV_CLASSES + CLASS0_BITS - 2) |
| 74 |
#define MV_MAX_BITS (MV_CLASSES + CLASS0_BITS + 2) |
| 75 |
#define MV_FP_SIZE 4 |
| 76 |
#define FRAME_CONTEXTS_LOG2 2 |
| 77 |
#define FRAME_CONTEXTS (1 << FRAME_CONTEXTS_LOG2) |
| 78 |
|
| 79 |
#define COEFF_PROB_SIZE 132 |
| 80 |
#define COEFF_PROB_NUM 3 |
| 81 |
|
| 82 |
#define TX_PROBS_IDX 0 |
| 83 |
#define COEFF_PROBS_IDX 64 |
| 84 |
#define INTRA_PROBS_IDX 1603 |
| 85 |
#define SEG_PROBS_IDX 2010 |
| 86 |
|
| 87 |
typedef uint8_t vp9_prob; |
| 88 |
|
| 89 |
#define vpx_memset memset |
| 90 |
#define vpx_memcpy memcpy |
| 91 |
|
| 92 |
#define vp9_zero(dest) memset(&dest, 0, sizeof(dest)) |
| 93 |
|
| 94 |
#define vp9_copy(dest, src) { \ |
| 95 |
assert(sizeof(dest) == sizeof(src)); \ |
| 96 |
vpx_memcpy(dest, src, sizeof(src)); \ |
| 97 |
} |
| 98 |
|
| 99 |
struct tx_probs { |
| 100 |
vp9_prob p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 3]; |
| 101 |
vp9_prob p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 2]; |
| 102 |
vp9_prob p32x32[TX_SIZE_CONTEXTS][TX_SIZES - 1]; |
| 103 |
}; |
| 104 |
|
| 105 |
struct tx_counts { |
| 106 |
unsigned int p32x32[TX_SIZE_CONTEXTS][TX_SIZES]; |
| 107 |
unsigned int p16x16[TX_SIZE_CONTEXTS][TX_SIZES - 1]; |
| 108 |
unsigned int p8x8[TX_SIZE_CONTEXTS][TX_SIZES - 2]; |
| 109 |
unsigned int tx_totals[TX_SIZES]; |
| 110 |
}; |
| 111 |
|
| 112 |
typedef struct { |
| 113 |
vp9_prob sign; |
| 114 |
vp9_prob classes[MV_CLASSES - 1]; |
| 115 |
vp9_prob class0[CLASS0_SIZE - 1]; |
| 116 |
vp9_prob bits[MV_OFFSET_BITS]; |
| 117 |
} nmv_component; |
| 118 |
|
| 119 |
//Modified the nmv_context from libvpx to suit our HW needs |
| 120 |
typedef struct { |
| 121 |
vp9_prob joints[MV_JOINTS - 1]; |
| 122 |
nmv_component comps[2]; |
| 123 |
vp9_prob class0_fp0[CLASS0_SIZE][MV_FP_SIZE - 1]; |
| 124 |
vp9_prob fp0[MV_FP_SIZE - 1]; |
| 125 |
vp9_prob class0_fp1[CLASS0_SIZE][MV_FP_SIZE - 1]; |
| 126 |
vp9_prob fp1[MV_FP_SIZE - 1]; |
| 127 |
vp9_prob class0_hp[2]; |
| 128 |
vp9_prob hp[2]; |
| 129 |
} nmv_context; |
| 130 |
|
| 131 |
//Modified the FRAME_CONTEXT from libvpx to suit our HW needs |
| 132 |
typedef struct frame_contexts { |
| 133 |
struct tx_probs tx_probs; |
| 134 |
vp9_prob dummy1[52]; |
| 135 |
vp9_prob coeff_probs4x4[COEFF_PROB_SIZE][COEFF_PROB_NUM]; |
| 136 |
vp9_prob coeff_probs8x8[COEFF_PROB_SIZE][COEFF_PROB_NUM]; |
| 137 |
vp9_prob coeff_probs16x16[COEFF_PROB_SIZE][COEFF_PROB_NUM]; |
| 138 |
vp9_prob coeff_probs32x32[COEFF_PROB_SIZE][COEFF_PROB_NUM]; |
| 139 |
vp9_prob dummy2[16]; |
| 140 |
vp9_prob skip_probs[SKIP_CONTEXTS]; |
| 141 |
vp9_prob inter_mode_probs[INTER_MODE_CONTEXTS][INTER_MODES - 1]; |
| 142 |
vp9_prob switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS] |
| 143 |
[SWITCHABLE_FILTERS - 1]; |
| 144 |
vp9_prob intra_inter_prob[INTRA_INTER_CONTEXTS]; |
| 145 |
vp9_prob comp_inter_prob[COMP_INTER_CONTEXTS]; |
| 146 |
vp9_prob single_ref_prob[REF_CONTEXTS][2]; |
| 147 |
vp9_prob comp_ref_prob[REF_CONTEXTS]; |
| 148 |
vp9_prob y_mode_prob[BLOCK_SIZE_GROUPS][INTRA_MODES - 1]; |
| 149 |
vp9_prob partition_prob[PARTITION_CONTEXTS][PARTITION_TYPES - 1]; |
| 150 |
nmv_context nmvc; |
| 151 |
vp9_prob dummy3[47]; |
| 152 |
vp9_prob uv_mode_prob[INTRA_MODES][INTRA_MODES - 1]; |
| 153 |
vp9_prob seg_tree_probs[SEG_TREE_PROBS]; |
| 154 |
vp9_prob seg_pred_probs[PREDICTION_PROBS]; |
| 155 |
vp9_prob dummy4[28]; |
| 156 |
int initialized; |
| 157 |
} FRAME_CONTEXT; |
| 158 |
|
| 159 |
|
| 160 |
extern struct tx_probs default_tx_probs; |
| 161 |
|
| 162 |
extern vp9_prob default_skip_probs[SKIP_CONTEXTS]; |
| 163 |
|
| 164 |
extern vp9_prob default_inter_mode_probs[INTER_MODE_CONTEXTS] |
| 165 |
[INTER_MODES - 1]; |
| 166 |
|
| 167 |
extern vp9_prob default_switchable_interp_prob[SWITCHABLE_FILTER_CONTEXTS] |
| 168 |
[SWITCHABLE_FILTERS - 1]; |
| 169 |
|
| 170 |
extern vp9_prob default_intra_inter_p[INTRA_INTER_CONTEXTS]; |
| 171 |
|
| 172 |
extern vp9_prob default_comp_inter_p[COMP_INTER_CONTEXTS]; |
| 173 |
|
| 174 |
extern vp9_prob default_single_ref_p[REF_CONTEXTS][2]; |
| 175 |
|
| 176 |
extern vp9_prob default_comp_ref_p[REF_CONTEXTS]; |
| 177 |
|
| 178 |
extern vp9_prob vp9_kf_uv_mode_prob[INTRA_MODES][INTRA_MODES - 1]; |
| 179 |
|
| 180 |
extern vp9_prob default_if_y_probs[BLOCK_SIZE_GROUPS][INTRA_MODES - 1]; |
| 181 |
|
| 182 |
extern vp9_prob default_if_uv_probs[INTRA_MODES][INTRA_MODES - 1]; |
| 183 |
|
| 184 |
extern vp9_prob default_seg_tree_probs[SEG_TREE_PROBS]; |
| 185 |
|
| 186 |
extern vp9_prob default_seg_pred_probs[PREDICTION_PROBS]; |
| 187 |
|
| 188 |
extern vp9_prob vp9_kf_partition_probs[PARTITION_CONTEXTS] |
| 189 |
[PARTITION_TYPES - 1]; |
| 190 |
|
| 191 |
extern vp9_prob default_partition_probs[PARTITION_CONTEXTS] |
| 192 |
[PARTITION_TYPES - 1]; |
| 193 |
|
| 194 |
extern nmv_context default_nmv_context; |
| 195 |
|
| 196 |
extern vp9_prob default_coef_probs_4x4[COEFF_PROB_SIZE][COEFF_PROB_NUM]; |
| 197 |
|
| 198 |
extern vp9_prob default_coef_probs_8x8[COEFF_PROB_SIZE][COEFF_PROB_NUM]; |
| 199 |
|
| 200 |
extern vp9_prob default_coef_probs_16x16[COEFF_PROB_SIZE][COEFF_PROB_NUM]; |
| 201 |
|
| 202 |
extern vp9_prob default_coef_probs_32x32[COEFF_PROB_SIZE][COEFF_PROB_NUM]; |
| 203 |
|
| 204 |
extern void intel_init_default_vp9_probs(FRAME_CONTEXT *frame_context); |
| 205 |
|
| 206 |
extern void intel_vp9_copy_frame_context(FRAME_CONTEXT *dst, |
| 207 |
FRAME_CONTEXT *src, |
| 208 |
bool inter_flag); |
| 209 |
|
| 210 |
extern void intel_update_intra_frame_context(FRAME_CONTEXT *frame_context); |
| 211 |
|
| 212 |
|
| 213 |
typedef struct _vp9_header_bitoffset_ { |
| 214 |
unsigned int bit_offset_ref_lf_delta; |
| 215 |
unsigned int bit_offset_mode_lf_delta; |
| 216 |
unsigned int bit_offset_lf_level; |
| 217 |
unsigned int bit_offset_qindex; |
| 218 |
unsigned int bit_offset_first_partition_size; |
| 219 |
unsigned int bit_offset_segmentation; |
| 220 |
unsigned int bit_size_segmentation; |
| 221 |
} vp9_header_bitoffset; |
| 222 |
|
| 223 |
struct encode_state; |
| 224 |
extern bool intel_write_uncompressed_header(struct encode_state *encode_state, |
| 225 |
int codec_profile, |
| 226 |
char *header_data, |
| 227 |
int *header_length, |
| 228 |
vp9_header_bitoffset *header_bitoffset); |
| 229 |
|
| 230 |
typedef enum { |
| 231 |
ONLY_4X4 = 0, // only 4x4 transform used |
| 232 |
ALLOW_8X8 = 1, // allow block transform size up to 8x8 |
| 233 |
ALLOW_16X16 = 2, // allow block transform size up to 16x16 |
| 234 |
ALLOW_32X32 = 3, // allow block transform size up to 32x32 |
| 235 |
TX_MODE_SELECT = 4, // transform specified for each block |
| 236 |
TX_MODES = 5, |
| 237 |
} TX_MODE; |
| 238 |
|
| 239 |
typedef enum { |
| 240 |
SINGLE_REFERENCE = 0, |
| 241 |
COMPOUND_REFERENCE = 1, |
| 242 |
REFERENCE_MODE_SELECT = 2, |
| 243 |
REFERENCE_MODES = 3, |
| 244 |
} REFERENCE_MODE; |
| 245 |
|
| 246 |
extern const unsigned short vp9_quant_dc[256]; |
| 247 |
extern const unsigned short vp9_quant_ac[256]; |
| 248 |
|
| 249 |
#endif /*VP9_PROBS_H */ |