]> granicus.if.org Git - libvpx/blob - vp9/encoder/vp9_block.h
Fix the decoder seg fault when frame is corrupted.
[libvpx] / vp9 / encoder / vp9_block.h
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
11 #ifndef VP9_ENCODER_VP9_BLOCK_H_
12 #define VP9_ENCODER_VP9_BLOCK_H_
13
14 #include "vpx_util/vpx_thread.h"
15
16 #include "vp9/common/vp9_entropymv.h"
17 #include "vp9/common/vp9_entropy.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 typedef struct {
24   unsigned int sse;
25   int sum;
26   unsigned int var;
27 } diff;
28
29 struct macroblock_plane {
30   DECLARE_ALIGNED(16, int16_t, src_diff[64 * 64]);
31   tran_low_t *qcoeff;
32   tran_low_t *coeff;
33   uint16_t *eobs;
34   struct buf_2d src;
35
36   // Quantizer setings
37   int16_t *quant_fp;
38   int16_t *round_fp;
39   int16_t *quant;
40   int16_t *quant_shift;
41   int16_t *zbin;
42   int16_t *round;
43
44   int64_t quant_thred[2];
45 };
46
47 /* The [2] dimension is for whether we skip the EOB node (i.e. if previous
48  * coefficient in this block was zero) or not. */
49 typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2]
50                                    [COEFF_CONTEXTS][ENTROPY_TOKENS];
51
52 typedef struct {
53   int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
54   uint8_t mode_context[MAX_REF_FRAMES];
55 } MB_MODE_INFO_EXT;
56
57 typedef struct {
58   int col_min;
59   int col_max;
60   int row_min;
61   int row_max;
62 } MvLimits;
63
64 typedef struct macroblock MACROBLOCK;
65 struct macroblock {
66 // cf. https://bugs.chromium.org/p/webm/issues/detail?id=1054
67 #if defined(_MSC_VER) && _MSC_VER < 1900
68   int64_t bsse[MAX_MB_PLANE << 2];
69 #endif
70
71   struct macroblock_plane plane[MAX_MB_PLANE];
72
73   MACROBLOCKD e_mbd;
74   MB_MODE_INFO_EXT *mbmi_ext;
75   MB_MODE_INFO_EXT *mbmi_ext_base;
76   int skip_block;
77   int select_tx_size;
78   int skip_recode;
79   int skip_optimize;
80   int q_index;
81   int block_qcoeff_opt;
82   int block_tx_domain;
83
84   // The equivalent error at the current rdmult of one whole bit (not one
85   // bitcost unit).
86   int errorperbit;
87   // The equivalend SAD error of one (whole) bit at the current quantizer
88   // for large blocks.
89   int sadperbit16;
90   // The equivalend SAD error of one (whole) bit at the current quantizer
91   // for sub-8x8 blocks.
92   int sadperbit4;
93   int rddiv;
94   int rdmult;
95   int mb_energy;
96   int *m_search_count_ptr;
97   int *ex_search_count_ptr;
98 #if CONFIG_MULTITHREAD
99   pthread_mutex_t *search_count_mutex;
100 #endif
101
102   // These are set to their default values at the beginning, and then adjusted
103   // further in the encoding process.
104   BLOCK_SIZE min_partition_size;
105   BLOCK_SIZE max_partition_size;
106
107   int mv_best_ref_index[MAX_REF_FRAMES];
108   unsigned int max_mv_context[MAX_REF_FRAMES];
109   unsigned int source_variance;
110   unsigned int pred_sse[MAX_REF_FRAMES];
111   int pred_mv_sad[MAX_REF_FRAMES];
112
113   int nmvjointcost[MV_JOINTS];
114   int *nmvcost[2];
115   int *nmvcost_hp[2];
116   int **mvcost;
117
118   int nmvjointsadcost[MV_JOINTS];
119   int *nmvsadcost[2];
120   int *nmvsadcost_hp[2];
121   int **mvsadcost;
122
123   // These define limits to motion vector components to prevent them
124   // from extending outside the UMV borders
125   MvLimits mv_limits;
126
127   // Notes transform blocks where no coefficents are coded.
128   // Set during mode selection. Read during block encoding.
129   uint8_t zcoeff_blk[TX_SIZES][256];
130
131   // Accumulate the tx block eobs in a partition block.
132   int32_t sum_y_eobs[TX_SIZES];
133
134   int skip;
135
136   int encode_breakout;
137
138   // note that token_costs is the cost when eob node is skipped
139   vp9_coeff_cost token_costs[TX_SIZES];
140
141   int optimize;
142
143   // indicate if it is in the rd search loop or encoding process
144   int use_lp32x32fdct;
145   int skip_encode;
146
147   // In first pass, intra prediction is done based on source pixels
148   // at tile boundaries
149   int fp_src_pred;
150
151   // use fast quantization process
152   int quant_fp;
153
154   // skip forward transform and quantization
155   uint8_t skip_txfm[MAX_MB_PLANE << 2];
156 #define SKIP_TXFM_NONE 0
157 #define SKIP_TXFM_AC_DC 1
158 #define SKIP_TXFM_AC_ONLY 2
159
160 // cf. https://bugs.chromium.org/p/webm/issues/detail?id=1054
161 #if !defined(_MSC_VER) || _MSC_VER >= 1900
162   int64_t bsse[MAX_MB_PLANE << 2];
163 #endif
164
165   // Used to store sub partition's choices.
166   MV pred_mv[MAX_REF_FRAMES];
167
168   // Strong color activity detection. Used in RTC coding mode to enhance
169   // the visual quality at the boundary of moving color objects.
170   uint8_t color_sensitivity[2];
171
172   uint8_t sb_is_skin;
173
174   uint8_t skip_low_source_sad;
175
176   uint8_t last_sb_high_content;
177
178   // For each superblock: saves the content value (e.g., low/high sad/sumdiff)
179   // based on source sad, prior to encoding the frame.
180   uint8_t content_state_sb;
181
182   // Used to save the status of whether a block has a low variance in
183   // choose_partitioning. 0 for 64x64, 1~2 for 64x32, 3~4 for 32x64, 5~8 for
184   // 32x32, 9~24 for 16x16.
185   uint8_t variance_low[25];
186
187   void (*fwd_txm4x4)(const int16_t *input, tran_low_t *output, int stride);
188   void (*itxm_add)(const tran_low_t *input, uint8_t *dest, int stride, int eob);
189 #if CONFIG_VP9_HIGHBITDEPTH
190   void (*highbd_itxm_add)(const tran_low_t *input, uint8_t *dest, int stride,
191                           int eob, int bd);
192 #endif
193 };
194
195 #ifdef __cplusplus
196 }  // extern "C"
197 #endif
198
199 #endif  // VP9_ENCODER_VP9_BLOCK_H_