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 "vp9/common/vp9_entropymv.h"
15 #include "vp9/common/vp9_entropy.h"
16 #include "vpx_ports/mem.h"
17 #include "vp9/common/vp9_onyxc_int.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   int16_t *qcoeff;
32   int16_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   // Zbin Over Quant value
46   int16_t zbin_extra;
47 };
48 
49 /* The [2] dimension is for whether we skip the EOB node (i.e. if previous
50  * coefficient in this block was zero) or not. */
51 typedef unsigned int vp9_coeff_cost[PLANE_TYPES][REF_TYPES][COEF_BANDS][2]
52                                    [COEFF_CONTEXTS][ENTROPY_TOKENS];
53 
54 typedef struct macroblock MACROBLOCK;
55 struct macroblock {
56   struct macroblock_plane plane[MAX_MB_PLANE];
57 
58   MACROBLOCKD e_mbd;
59   int skip_block;
60   int select_tx_size;
61   int skip_recode;
62   int skip_optimize;
63   int q_index;
64 
65   int errorperbit;
66   int sadperbit16;
67   int sadperbit4;
68   int rddiv;
69   int rdmult;
70   int mb_energy;
71 
72   int mv_best_ref_index[MAX_REF_FRAMES];
73   unsigned int max_mv_context[MAX_REF_FRAMES];
74   unsigned int source_variance;
75   unsigned int pred_sse[MAX_REF_FRAMES];
76   int pred_mv_sad[MAX_REF_FRAMES];
77 
78   int nmvjointcost[MV_JOINTS];
79   int nmvcosts[2][MV_VALS];
80   int *nmvcost[2];
81   int nmvcosts_hp[2][MV_VALS];
82   int *nmvcost_hp[2];
83   int **mvcost;
84 
85   int nmvjointsadcost[MV_JOINTS];
86   int nmvsadcosts[2][MV_VALS];
87   int *nmvsadcost[2];
88   int nmvsadcosts_hp[2][MV_VALS];
89   int *nmvsadcost_hp[2];
90   int **mvsadcost;
91 
92   // These define limits to motion vector components to prevent them
93   // from extending outside the UMV borders
94   int mv_col_min;
95   int mv_col_max;
96   int mv_row_min;
97   int mv_row_max;
98 
99   uint8_t zcoeff_blk[TX_SIZES][256];
100   int skip;
101 
102   int encode_breakout;
103 
104   // note that token_costs is the cost when eob node is skipped
105   vp9_coeff_cost token_costs[TX_SIZES];
106 
107   int in_static_area;
108 
109   int optimize;
110 
111   // indicate if it is in the rd search loop or encoding process
112   int use_lp32x32fdct;
113   int skip_encode;
114 
115   // use fast quantization process
116   int quant_fp;
117 
118   // skip forward transform and quantization
119   int skip_txfm[MAX_MB_PLANE];
120 
121   int64_t bsse[MAX_MB_PLANE];
122 
123   // Used to store sub partition's choices.
124   MV pred_mv[MAX_REF_FRAMES];
125 
126   void (*fwd_txm4x4)(const int16_t *input, int16_t *output, int stride);
127   void (*itxm_add)(const int16_t *input, uint8_t *dest, int stride, int eob);
128 };
129 
130 #ifdef __cplusplus
131 }  // extern "C"
132 #endif
133 
134 #endif  // VP9_ENCODER_VP9_BLOCK_H_
135