vp9_block.h revision 1184aebb761cbeac9124c37189a80a1a58f04b6b
15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  Use of this source code is governed by a BSD-style license
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  that can be found in the LICENSE file in the root of the source
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  tree. An additional intellectual property rights grant can be found
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *  in the file PATENTS.  All contributing project authors may
802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch *  be found in the AUTHORS file in the root of the source tree.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef VP9_ENCODER_VP9_BLOCK_H_
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define VP9_ENCODER_VP9_BLOCK_H_
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch#include "vp9/common/vp9_onyx.h"
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "vp9/common/vp9_entropymv.h"
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "vp9/common/vp9_entropy.h"
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "vpx_ports/mem.h"
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "vp9/common/vp9_onyxc_int.h"
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// motion search site
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef struct {
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  MV mv;
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  int offset;
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} search_site;
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)typedef struct {
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  struct {
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    MB_PREDICTION_MODE mode;
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  } bmi[4];
3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)} PARTITION_INFO;
3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
32e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)// Structure to hold snapshot of coding context during the mode picking process
33e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)// TODO Do we need all of these?
34e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)typedef struct {
355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  MODE_INFO mic;
36c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)  PARTITION_INFO partition_info;
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  int skip;
385d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int_mv best_ref_mv;
395d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int_mv second_best_ref_mv;
405d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
41197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch  int rate;
425d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int distortion;
43197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch  int64_t intra_error;
44197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch  int best_mode_index;
45197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch  int rddiv;
465d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int rdmult;
475d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int hybrid_pred_diff;
485d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int comp_pred_diff;
495d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int single_pred_diff;
505d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int64_t tx_rd_diff[TX_MODES];
515d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int64_t best_filter_diff[SWITCHABLE_FILTERS + 1];
525d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
535d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  // motion vector cache for adaptive motion search control in partition
545d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  // search loop
555d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int_mv pred_mv[MAX_REF_FRAMES];
565d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
575d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  // Bit flag for each mode whether it has high error in comparison to others.
585d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  unsigned int modes_with_high_error;
595d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
605d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  // Bit flag for each ref frame whether it has high error compared to others.
615d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  unsigned int frames_with_high_error;
625d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)} PICK_MODE_CONTEXT;
635d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
645d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)struct macroblock_plane {
655d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  DECLARE_ALIGNED(16, int16_t, src_diff[64*64]);
66197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch  DECLARE_ALIGNED(16, int16_t, coeff[64*64]);
675d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  struct buf_2d src;
685d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
695d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  // Quantizer setings
705d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int16_t *quant;
715d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int16_t *quant_shift;
725d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int16_t *zbin;
735d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int16_t *round;
745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  // Zbin Over Quant value
765d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int16_t zbin_extra;
775d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)};
785d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
795d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)/* The [2] dimension is for whether we skip the EOB node (i.e. if previous
805d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) * coefficient in this block was zero) or not. */
815d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)typedef unsigned int vp9_coeff_cost[BLOCK_TYPES][REF_TYPES][COEF_BANDS][2]
825d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)                                   [PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS];
835d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
845d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)typedef struct macroblock MACROBLOCK;
855d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)struct macroblock {
865d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  struct macroblock_plane plane[MAX_MB_PLANE];
875d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
885d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  MACROBLOCKD e_mbd;
895d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int skip_block;
905d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  PARTITION_INFO *partition_info; /* work pointer */
915d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  PARTITION_INFO *pi;   /* Corresponds to upper left visible macroblock */
925d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  PARTITION_INFO *pip;  /* Base of allocated array */
935d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
945d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  search_site *ss;
955d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int ss_count;
965d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int searches_per_step;
975d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)
985d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int errorperbit;
995d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int sadperbit16;
1005d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  int sadperbit4;
1015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  int rddiv;
1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)  int rdmult;
1035d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles)  unsigned int *mb_activity_ptr;
104  int *mb_norm_activity_ptr;
105  signed int act_zbin_adj;
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
111  int nmvjointcost[MV_JOINTS];
112  int nmvcosts[2][MV_VALS];
113  int *nmvcost[2];
114  int nmvcosts_hp[2][MV_VALS];
115  int *nmvcost_hp[2];
116  int **mvcost;
117
118  int nmvjointsadcost[MV_JOINTS];
119  int nmvsadcosts[2][MV_VALS];
120  int *nmvsadcost[2];
121  int nmvsadcosts_hp[2][MV_VALS];
122  int *nmvsadcost_hp[2];
123  int **mvsadcost;
124
125  int mbmode_cost[MB_MODE_COUNT];
126  unsigned inter_mode_cost[INTER_MODE_CONTEXTS][MB_MODE_COUNT - NEARESTMV];
127  int intra_uv_mode_cost[2][MB_MODE_COUNT];
128  int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
129  int switchable_interp_costs[SWITCHABLE_FILTERS + 1]
130                             [SWITCHABLE_FILTERS];
131
132  // These define limits to motion vector components to prevent them
133  // from extending outside the UMV borders
134  int mv_col_min;
135  int mv_col_max;
136  int mv_row_min;
137  int mv_row_max;
138
139  int skip;
140
141  int encode_breakout;
142
143  unsigned char *active_ptr;
144
145  // note that token_costs is the cost when eob node is skipped
146  vp9_coeff_cost token_costs[TX_SIZES];
147
148  int optimize;
149
150  // indicate if it is in the rd search loop or encoding process
151  int use_lp32x32fdct;
152  int skip_encode;
153
154  // Used to store sub partition's choices.
155  int fast_ms;
156  int_mv pred_mv[MAX_REF_FRAMES];
157  int subblock_ref;
158
159  // TODO(jingning): Need to refactor the structure arrays that buffers the
160  // coding mode decisions of each partition type.
161  PICK_MODE_CONTEXT ab4x4_context[4][4][4];
162  PICK_MODE_CONTEXT sb8x4_context[4][4][4];
163  PICK_MODE_CONTEXT sb4x8_context[4][4][4];
164  PICK_MODE_CONTEXT sb8x8_context[4][4][4];
165  PICK_MODE_CONTEXT sb8x16_context[4][4][2];
166  PICK_MODE_CONTEXT sb16x8_context[4][4][2];
167  PICK_MODE_CONTEXT mb_context[4][4];
168  PICK_MODE_CONTEXT sb32x16_context[4][2];
169  PICK_MODE_CONTEXT sb16x32_context[4][2];
170  // when 4 MBs share coding parameters:
171  PICK_MODE_CONTEXT sb32_context[4];
172  PICK_MODE_CONTEXT sb32x64_context[2];
173  PICK_MODE_CONTEXT sb64x32_context[2];
174  PICK_MODE_CONTEXT sb64_context;
175  int partition_cost[NUM_PARTITION_CONTEXTS][PARTITION_TYPES];
176
177  BLOCK_SIZE b_partitioning[4][4][4];
178  BLOCK_SIZE mb_partitioning[4][4];
179  BLOCK_SIZE sb_partitioning[4];
180  BLOCK_SIZE sb64_partitioning;
181
182  void (*fwd_txm4x4)(int16_t *input, int16_t *output, int pitch);
183  void (*fwd_txm8x4)(int16_t *input, int16_t *output, int pitch);
184  void (*fwd_txm8x8)(int16_t *input, int16_t *output, int pitch);
185  void (*fwd_txm16x16)(int16_t *input, int16_t *output, int pitch);
186  void (*quantize_b_4x4)(MACROBLOCK *x, int b_idx, TX_TYPE tx_type,
187                         int y_blocks);
188};
189
190#endif  // VP9_ENCODER_VP9_BLOCK_H_
191