blob: 8ea64628e3033d8abd9f507da3283c94f234b11d [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_COMMON_BLOCKD_H_
13#define AV1_COMMON_BLOCKD_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "./aom_config.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070016
Yaowu Xuf883b422016-08-30 14:01:10 -070017#include "aom_dsp/aom_dsp_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070018#include "aom_ports/mem.h"
19#include "aom_scale/yv12config.h"
20
21#include "av1/common/common_data.h"
22#include "av1/common/quant_common.h"
23#include "av1/common/entropy.h"
24#include "av1/common/entropymode.h"
25#include "av1/common/mv.h"
26#include "av1/common/scale.h"
27#include "av1/common/seg_common.h"
28#include "av1/common/tile_common.h"
Yushin Cho77bba8d2016-11-04 16:36:56 -070029#if CONFIG_PVQ
30#include "av1/common/pvq.h"
31#include "av1/common/pvq_state.h"
32#include "av1/decoder/decint.h"
33#endif
Luc Trudeaubaeb3752017-04-24 11:19:25 -040034#if CONFIG_CFL
35#include "av1/common/cfl.h"
36#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070037#ifdef __cplusplus
38extern "C" {
39#endif
40
Jingning Han69d21012017-05-14 16:51:27 -070041#if (CONFIG_CHROMA_SUB8X8 || CONFIG_CHROMA_2X2)
42#define SUB8X8_COMP_REF 0
43#else
44#define SUB8X8_COMP_REF 1
45#endif
Jingning Hanc41a5492017-02-24 11:18:52 -080046
Yaowu Xuc27fc142016-08-22 16:08:15 -070047#define MAX_MB_PLANE 3
48
David Barkerac37fa32016-12-02 12:30:21 +000049#if CONFIG_EXT_INTER
Sarah Parkerb9f757c2017-01-06 17:12:24 -080050
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080051#if CONFIG_COMPOUND_SEGMENT
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080052// Set COMPOUND_SEGMENT_TYPE to one of the three
53// 0: Uniform
54// 1: Difference weighted
55#define COMPOUND_SEGMENT_TYPE 1
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080056#define MAX_SEG_MASK_BITS 1
Yaowu Xuf35f5272017-05-10 08:00:02 -070057
Sarah Parkerb9f757c2017-01-06 17:12:24 -080058// SEG_MASK_TYPES should not surpass 1 << MAX_SEG_MASK_BITS
59typedef enum {
Yaowu Xuf35f5272017-05-10 08:00:02 -070060#if COMPOUND_SEGMENT_TYPE == 0
Sarah Parkerb9f757c2017-01-06 17:12:24 -080061 UNIFORM_45 = 0,
62 UNIFORM_45_INV,
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080063#elif COMPOUND_SEGMENT_TYPE == 1
Sarah Parker7bb84f32017-05-09 15:17:46 -070064 DIFFWTD_38 = 0,
65 DIFFWTD_38_INV,
Yaowu Xuf35f5272017-05-10 08:00:02 -070066#endif // COMPOUND_SEGMENT_TYPE
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080067 SEG_MASK_TYPES,
68} SEG_MASK_TYPE;
69
Sarah Parkerb9f757c2017-01-06 17:12:24 -080070#endif // CONFIG_COMPOUND_SEGMENT
Debargha Mukherjee1edf9a32017-01-07 18:54:20 -080071#endif // CONFIG_EXT_INTER
David Barkerac37fa32016-12-02 12:30:21 +000072
Yaowu Xuc27fc142016-08-22 16:08:15 -070073typedef enum {
74 KEY_FRAME = 0,
75 INTER_FRAME = 1,
76 FRAME_TYPES,
77} FRAME_TYPE;
78
Yaowu Xuc27fc142016-08-22 16:08:15 -070079static INLINE int is_inter_mode(PREDICTION_MODE mode) {
80#if CONFIG_EXT_INTER
81 return mode >= NEARESTMV && mode <= NEW_NEWMV;
82#else
83 return mode >= NEARESTMV && mode <= NEWMV;
84#endif // CONFIG_EXT_INTER
85}
86
Yushin Cho77bba8d2016-11-04 16:36:56 -070087#if CONFIG_PVQ
88typedef struct PVQ_INFO {
89 int theta[PVQ_MAX_PARTITIONS];
Yushin Cho77bba8d2016-11-04 16:36:56 -070090 int qg[PVQ_MAX_PARTITIONS];
91 int k[PVQ_MAX_PARTITIONS];
Yushin Cho48f84db2016-11-07 21:20:17 -080092 od_coeff y[OD_TXSIZE_MAX * OD_TXSIZE_MAX];
Yushin Cho77bba8d2016-11-04 16:36:56 -070093 int nb_bands;
94 int off[PVQ_MAX_PARTITIONS];
95 int size[PVQ_MAX_PARTITIONS];
96 int skip_rest;
97 int skip_dir;
ltrudeaue1c09292017-01-20 15:42:13 -050098 int bs; // log of the block size minus two,
99 // i.e. equivalent to aom's TX_SIZE
100 // Block skip info, indicating whether DC/AC, is coded.
101 PVQ_SKIP_TYPE ac_dc_coded; // bit0: DC coded, bit1 : AC coded (1 means coded)
Yushin Cho77bba8d2016-11-04 16:36:56 -0700102 tran_low_t dq_dc_residue;
103} PVQ_INFO;
104
105typedef struct PVQ_QUEUE {
106 PVQ_INFO *buf; // buffer for pvq info, stored in encoding order
107 int curr_pos; // curr position to write PVQ_INFO
108 int buf_len; // allocated buffer length
109 int last_pos; // last written position of PVQ_INFO in a tile
110} PVQ_QUEUE;
111#endif
112
David Barkerac37fa32016-12-02 12:30:21 +0000113typedef struct {
114 uint8_t *plane[MAX_MB_PLANE];
115 int stride[MAX_MB_PLANE];
116} BUFFER_SET;
117
Yaowu Xuc27fc142016-08-22 16:08:15 -0700118#if CONFIG_EXT_INTER
119static INLINE int is_inter_singleref_mode(PREDICTION_MODE mode) {
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700120 return mode >= NEARESTMV && mode <= NEWMV;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700121}
Zoe Liu85b66462017-04-20 14:28:19 -0700122static INLINE int is_inter_compound_mode(PREDICTION_MODE mode) {
123 return mode >= NEAREST_NEARESTMV && mode <= NEW_NEWMV;
124}
Zoe Liu239f06b2017-04-20 13:10:55 -0700125#if CONFIG_COMPOUND_SINGLEREF
126static INLINE int is_inter_singleref_comp_mode(PREDICTION_MODE mode) {
127 return mode >= SR_NEAREST_NEARMV && mode <= SR_NEW_NEWMV;
128}
Zoe Liu85b66462017-04-20 14:28:19 -0700129static INLINE int is_inter_anyref_comp_mode(PREDICTION_MODE mode) {
130 return is_inter_compound_mode(mode) || is_inter_singleref_comp_mode(mode);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700131}
Zoe Liu85b66462017-04-20 14:28:19 -0700132#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700133
134static INLINE PREDICTION_MODE compound_ref0_mode(PREDICTION_MODE mode) {
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700135 static PREDICTION_MODE lut[] = {
Urvang Joshi102245d2016-11-28 13:05:36 -0800136 MB_MODE_COUNT, // DC_PRED
137 MB_MODE_COUNT, // V_PRED
138 MB_MODE_COUNT, // H_PRED
139 MB_MODE_COUNT, // D45_PRED
140 MB_MODE_COUNT, // D135_PRED
141 MB_MODE_COUNT, // D117_PRED
142 MB_MODE_COUNT, // D153_PRED
143 MB_MODE_COUNT, // D207_PRED
144 MB_MODE_COUNT, // D63_PRED
145#if CONFIG_ALT_INTRA
146 MB_MODE_COUNT, // SMOOTH_PRED
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700147#if CONFIG_SMOOTH_HV
148 MB_MODE_COUNT, // SMOOTH_V_PRED
149 MB_MODE_COUNT, // SMOOTH_H_PRED
150#endif // CONFIG_SMOOTH_HV
Urvang Joshi102245d2016-11-28 13:05:36 -0800151#endif // CONFIG_ALT_INTRA
152 MB_MODE_COUNT, // TM_PRED
153 MB_MODE_COUNT, // NEARESTMV
154 MB_MODE_COUNT, // NEARMV
155 MB_MODE_COUNT, // ZEROMV
156 MB_MODE_COUNT, // NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700157#if CONFIG_COMPOUND_SINGLEREF
158 NEARESTMV, // SR_NEAREST_NEARMV
Zoe Liu85b66462017-04-20 14:28:19 -0700159 // NEARESTMV, // SR_NEAREST_NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700160 NEARMV, // SR_NEAR_NEWMV
161 ZEROMV, // SR_ZERO_NEWMV
162 NEWMV, // SR_NEW_NEWMV
163#endif // CONFIG_COMPOUND_SINGLEREF
164 NEARESTMV, // NEAREST_NEARESTMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700165 NEARMV, // NEAR_NEARMV
166 NEARESTMV, // NEAREST_NEWMV
167 NEWMV, // NEW_NEARESTMV
168 NEARMV, // NEAR_NEWMV
169 NEWMV, // NEW_NEARMV
170 ZEROMV, // ZERO_ZEROMV
171 NEWMV, // NEW_NEWMV
Yaowu Xuc27fc142016-08-22 16:08:15 -0700172 };
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700173 assert(NELEMENTS(lut) == MB_MODE_COUNT);
Zoe Liu85b66462017-04-20 14:28:19 -0700174#if CONFIG_COMPOUND_SINGLEREF
175 assert(is_inter_anyref_comp_mode(mode));
176#else // !CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700177 assert(is_inter_compound_mode(mode));
Zoe Liu85b66462017-04-20 14:28:19 -0700178#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700179 return lut[mode];
180}
181
182static INLINE PREDICTION_MODE compound_ref1_mode(PREDICTION_MODE mode) {
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700183 static PREDICTION_MODE lut[] = {
Urvang Joshi102245d2016-11-28 13:05:36 -0800184 MB_MODE_COUNT, // DC_PRED
185 MB_MODE_COUNT, // V_PRED
186 MB_MODE_COUNT, // H_PRED
187 MB_MODE_COUNT, // D45_PRED
188 MB_MODE_COUNT, // D135_PRED
189 MB_MODE_COUNT, // D117_PRED
190 MB_MODE_COUNT, // D153_PRED
191 MB_MODE_COUNT, // D207_PRED
192 MB_MODE_COUNT, // D63_PRED
193#if CONFIG_ALT_INTRA
194 MB_MODE_COUNT, // SMOOTH_PRED
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700195#if CONFIG_SMOOTH_HV
196 MB_MODE_COUNT, // SMOOTH_V_PRED
197 MB_MODE_COUNT, // SMOOTH_H_PRED
198#endif // CONFIG_SMOOTH_HV
Urvang Joshi102245d2016-11-28 13:05:36 -0800199#endif // CONFIG_ALT_INTRA
200 MB_MODE_COUNT, // TM_PRED
201 MB_MODE_COUNT, // NEARESTMV
202 MB_MODE_COUNT, // NEARMV
203 MB_MODE_COUNT, // ZEROMV
204 MB_MODE_COUNT, // NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700205#if CONFIG_COMPOUND_SINGLEREF
Zoe Liu85b66462017-04-20 14:28:19 -0700206 NEARMV, // SR_NEAREST_NEARMV
207 // NEWMV, // SR_NEAREST_NEWMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700208 NEWMV, // SR_NEAR_NEWMV
209 NEWMV, // SR_ZERO_NEWMV
210 NEWMV, // SR_NEW_NEWMV
211#endif // CONFIG_COMPOUND_SINGLEREF
212 NEARESTMV, // NEAREST_NEARESTMV
Zoe Liu239f06b2017-04-20 13:10:55 -0700213 NEARMV, // NEAR_NEARMV
214 NEWMV, // NEAREST_NEWMV
215 NEARESTMV, // NEW_NEARESTMV
216 NEWMV, // NEAR_NEWMV
217 NEARMV, // NEW_NEARMV
218 ZEROMV, // ZERO_ZEROMV
219 NEWMV, // NEW_NEWMV
Yaowu Xuc27fc142016-08-22 16:08:15 -0700220 };
Urvang Joshi5a9ea002017-05-22 15:25:18 -0700221 assert(NELEMENTS(lut) == MB_MODE_COUNT);
Zoe Liu85b66462017-04-20 14:28:19 -0700222#if CONFIG_COMPOUND_SINGLEREF
223 assert(is_inter_anyref_comp_mode(mode));
224#else // !CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700225 assert(is_inter_compound_mode(mode));
Zoe Liu85b66462017-04-20 14:28:19 -0700226#endif // CONFIG_COMPOUND_SINGLEREF
Yaowu Xuc27fc142016-08-22 16:08:15 -0700227 return lut[mode];
228}
229
David Barker3dfba992017-04-03 16:10:09 +0100230static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -0700231 return (mode == NEARMV || mode == NEAR_NEARMV || mode == NEAR_NEWMV ||
Zoe Liu85b66462017-04-20 14:28:19 -0700232#if CONFIG_COMPOUND_SINGLEREF
233 mode == SR_NEAREST_NEARMV || mode == SR_NEAR_NEWMV ||
234#endif // CONFIG_COMPOUND_SINGLEREF
Debargha Mukherjeebb6e1342017-04-17 16:05:04 -0700235 mode == NEW_NEARMV);
David Barker3dfba992017-04-03 16:10:09 +0100236}
237
Yaowu Xuc27fc142016-08-22 16:08:15 -0700238static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700239 return (mode == NEWMV || mode == NEW_NEWMV || mode == NEAREST_NEWMV ||
Zoe Liu85b66462017-04-20 14:28:19 -0700240#if CONFIG_COMPOUND_SINGLEREF
241 /* mode == SR_NEAREST_NEWMV || */ mode == SR_NEAR_NEWMV ||
242 mode == SR_ZERO_NEWMV || mode == SR_NEW_NEWMV ||
243#endif // CONFIG_COMPOUND_SINGLEREF
Zoe Liu7f24e1b2017-03-17 17:42:05 -0700244 mode == NEW_NEARESTMV || mode == NEAR_NEWMV || mode == NEW_NEARMV);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700245}
Sarah Parker6fdc8532016-11-16 17:47:13 -0800246
Sarah Parker2e604882017-01-17 17:31:25 -0800247static INLINE int use_masked_motion_search(COMPOUND_TYPE type) {
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000248#if CONFIG_WEDGE
Sarah Parker2e604882017-01-17 17:31:25 -0800249 return (type == COMPOUND_WEDGE);
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000250#else
251 (void)type;
252 return 0;
253#endif
Sarah Parker2e604882017-01-17 17:31:25 -0800254}
255
Sarah Parker6fdc8532016-11-16 17:47:13 -0800256static INLINE int is_masked_compound_type(COMPOUND_TYPE type) {
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000257#if CONFIG_COMPOUND_SEGMENT && CONFIG_WEDGE
Sarah Parker569edda2016-12-14 14:57:38 -0800258 return (type == COMPOUND_WEDGE || type == COMPOUND_SEG);
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000259#elif !CONFIG_COMPOUND_SEGMENT && CONFIG_WEDGE
Sarah Parker6fdc8532016-11-16 17:47:13 -0800260 return (type == COMPOUND_WEDGE);
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000261#elif CONFIG_COMPOUND_SEGMENT && !CONFIG_WEDGE
262 return (type == COMPOUND_SEG);
Sarah Parker569edda2016-12-14 14:57:38 -0800263#endif // CONFIG_COMPOUND_SEGMENT
Debargha Mukherjeec5f735f2017-04-26 03:25:28 +0000264 (void)type;
265 return 0;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800266}
Zoe Liu85b66462017-04-20 14:28:19 -0700267
268#else // !CONFIG_EXT_INTER
Yaowu Xuc27fc142016-08-22 16:08:15 -0700269
David Barker3dfba992017-04-03 16:10:09 +0100270static INLINE int have_nearmv_in_inter_mode(PREDICTION_MODE mode) {
271 return (mode == NEARMV);
272}
273
Yaowu Xuc27fc142016-08-22 16:08:15 -0700274static INLINE int have_newmv_in_inter_mode(PREDICTION_MODE mode) {
275 return (mode == NEWMV);
276}
277#endif // CONFIG_EXT_INTER
278
279/* For keyframes, intra block modes are predicted by the (already decoded)
280 modes for the Y blocks to the left and above us; for interframes, there
281 is a single probability table. */
282
283typedef struct {
284 PREDICTION_MODE as_mode;
285 int_mv as_mv[2]; // first, second inter predictor motion vectors
Yaowu Xuf5bbbfa2016-09-26 09:13:38 -0700286 int_mv pred_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700287#if CONFIG_EXT_INTER
288 int_mv ref_mv[2];
289#endif // CONFIG_EXT_INTER
290} b_mode_info;
291
292typedef int8_t MV_REFERENCE_FRAME;
293
Urvang Joshib100db72016-10-12 16:28:56 -0700294#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700295typedef struct {
296 // Number of base colors for Y (0) and UV (1)
297 uint8_t palette_size[2];
hui sufa4ff852017-05-15 12:20:50 -0700298 // Value of base colors for Y, U, and V
Yaowu Xuc27fc142016-08-22 16:08:15 -0700299 uint16_t palette_colors[3 * PALETTE_MAX_SIZE];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700300} PALETTE_MODE_INFO;
Urvang Joshib100db72016-10-12 16:28:56 -0700301#endif // CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700302
hui su5db97432016-10-14 16:10:14 -0700303#if CONFIG_FILTER_INTRA
Yue Chen8d8638a2017-02-21 13:28:16 +0800304#define USE_3TAP_INTRA_FILTER 1 // 0: 4-tap; 1: 3-tap
Yaowu Xuc27fc142016-08-22 16:08:15 -0700305typedef struct {
306 // 1: an ext intra mode is used; 0: otherwise.
hui su5db97432016-10-14 16:10:14 -0700307 uint8_t use_filter_intra_mode[PLANE_TYPES];
308 FILTER_INTRA_MODE filter_intra_mode[PLANE_TYPES];
309} FILTER_INTRA_MODE_INFO;
310#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700311
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800312#if CONFIG_VAR_TX
Angie Chiang7c2b7f22016-11-07 16:00:00 -0800313#if CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800314#define TXB_COEFF_COST_MAP_SIZE (2 * MAX_MIB_SIZE)
Angie Chiang7c2b7f22016-11-07 16:00:00 -0800315#endif
316#endif
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800317
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800318typedef struct RD_STATS {
319 int rate;
320 int64_t dist;
Angie Chiang7bbd3b12017-04-26 11:06:09 -0700321 // Please be careful of using rdcost, it's not guaranteed to be set all the
322 // time.
323 // TODO(angiebird): Create a set of functions to manipulate the RD_STATS. In
324 // these functions, make sure rdcost is always up-to-date according to
325 // rate/dist.
Angie Chiang2a2a7dd2017-04-25 16:08:47 -0700326 int64_t rdcost;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800327 int64_t sse;
Angie Chiang7bbd3b12017-04-26 11:06:09 -0700328 int skip; // sse should equal to dist when skip == 1
Jingning Han3bce7542017-07-25 10:53:57 -0700329 int64_t ref_rdcost;
330 int zero_rate;
Yushin Chob7b60c52017-07-14 16:18:52 -0700331#if CONFIG_DIST_8X8 && CONFIG_CB4X4
Yushin Cho63927c42017-05-23 15:41:05 -0700332 int64_t dist_y;
333#endif
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800334#if CONFIG_RD_DEBUG
335 int txb_coeff_cost[MAX_MB_PLANE];
Angie Chiang3963d632016-11-10 18:41:40 -0800336#if CONFIG_VAR_TX
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800337 int txb_coeff_cost_map[MAX_MB_PLANE][TXB_COEFF_COST_MAP_SIZE]
338 [TXB_COEFF_COST_MAP_SIZE];
Angie Chiang3963d632016-11-10 18:41:40 -0800339#endif // CONFIG_VAR_TX
340#endif // CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800341} RD_STATS;
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800342
Sarah Parker6fdc8532016-11-16 17:47:13 -0800343#if CONFIG_EXT_INTER
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000344// This struct is used to group function args that are commonly
345// sent together in functions related to interinter compound modes
Sarah Parker6fdc8532016-11-16 17:47:13 -0800346typedef struct {
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000347#if CONFIG_WEDGE
Sarah Parker6fdc8532016-11-16 17:47:13 -0800348 int wedge_index;
349 int wedge_sign;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000350#endif // CONFIG_WEDGE
Sarah Parker569edda2016-12-14 14:57:38 -0800351#if CONFIG_COMPOUND_SEGMENT
Sarah Parkerb9f757c2017-01-06 17:12:24 -0800352 SEG_MASK_TYPE mask_type;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000353 uint8_t *seg_mask;
Sarah Parker569edda2016-12-14 14:57:38 -0800354#endif // CONFIG_COMPOUND_SEGMENT
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000355 COMPOUND_TYPE interinter_compound_type;
Sarah Parker6fdc8532016-11-16 17:47:13 -0800356} INTERINTER_COMPOUND_DATA;
357#endif // CONFIG_EXT_INTER
358
Yaowu Xuc27fc142016-08-22 16:08:15 -0700359// This structure now relates to 8x8 block regions.
Luc Trudeauf5334002017-04-25 12:21:26 -0400360typedef struct MB_MODE_INFO {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700361 // Common for both INTER and INTRA blocks
362 BLOCK_SIZE sb_type;
363 PREDICTION_MODE mode;
364 TX_SIZE tx_size;
365#if CONFIG_VAR_TX
366 // TODO(jingning): This effectively assigned a separate entry for each
367 // 8x8 block. Apparently it takes much more space than needed.
368 TX_SIZE inter_tx_size[MAX_MIB_SIZE][MAX_MIB_SIZE];
Jingning Hane67b38a2016-11-04 10:30:00 -0700369 TX_SIZE min_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700370#endif
371 int8_t skip;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700372 int8_t segment_id;
373#if CONFIG_SUPERTX
374 // Minimum of all segment IDs under the current supertx block.
375 int8_t segment_id_supertx;
376#endif // CONFIG_SUPERTX
377 int8_t seg_id_predicted; // valid only when temporal_update is enabled
378
379 // Only for INTRA blocks
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400380 UV_PREDICTION_MODE uv_mode;
Urvang Joshib100db72016-10-12 16:28:56 -0700381#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700382 PALETTE_MODE_INFO palette_mode_info;
Urvang Joshib100db72016-10-12 16:28:56 -0700383#endif // CONFIG_PALETTE
Alex Converse28744302017-04-13 14:46:22 -0700384#if CONFIG_INTRABC
385 uint8_t use_intrabc;
386#endif // CONFIG_INTRABC
Yaowu Xuc27fc142016-08-22 16:08:15 -0700387
388// Only for INTER blocks
389#if CONFIG_DUAL_FILTER
James Zern7b9407a2016-05-18 23:48:05 -0700390 InterpFilter interp_filter[4];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700391#else
James Zern7b9407a2016-05-18 23:48:05 -0700392 InterpFilter interp_filter;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700393#endif
394 MV_REFERENCE_FRAME ref_frame[2];
395 TX_TYPE tx_type;
Angie Chiangcd9b03f2017-04-16 13:37:13 -0700396#if CONFIG_TXK_SEL
Angie Chiang808d8592017-04-06 18:36:55 -0700397 TX_TYPE txk_type[MAX_SB_SQUARE / (TX_SIZE_W_MIN * TX_SIZE_H_MIN)];
398#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700399
hui su5db97432016-10-14 16:10:14 -0700400#if CONFIG_FILTER_INTRA
401 FILTER_INTRA_MODE_INFO filter_intra_mode_info;
402#endif // CONFIG_FILTER_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700403#if CONFIG_EXT_INTRA
hui sueda3d762016-12-06 16:58:23 -0800404 // The actual prediction angle is the base angle + (angle_delta * step).
Yaowu Xuc27fc142016-08-22 16:08:15 -0700405 int8_t angle_delta[2];
hui sueda3d762016-12-06 16:58:23 -0800406#if CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700407 // To-Do (huisu): this may be replaced by interp_filter
408 INTRA_FILTER intra_filter;
hui sueda3d762016-12-06 16:58:23 -0800409#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700410#endif // CONFIG_EXT_INTRA
411
412#if CONFIG_EXT_INTER
Yue Chen4d26acb2017-05-01 12:28:34 -0700413#if CONFIG_INTERINTRA
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000414 // interintra members
Yaowu Xuc27fc142016-08-22 16:08:15 -0700415 INTERINTRA_MODE interintra_mode;
Yue Chen4d26acb2017-05-01 12:28:34 -0700416#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700417 // TODO(debargha): Consolidate these flags
418 int use_wedge_interintra;
419 int interintra_wedge_index;
420 int interintra_wedge_sign;
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000421 // interinter members
422 COMPOUND_TYPE interinter_compound_type;
423#if CONFIG_WEDGE
424 int wedge_index;
425 int wedge_sign;
426#endif // CONFIG_WEDGE
427#if CONFIG_COMPOUND_SEGMENT
428 SEG_MASK_TYPE mask_type;
429#endif // CONFIG_COMPOUND_SEGMENT
Yaowu Xuc27fc142016-08-22 16:08:15 -0700430#endif // CONFIG_EXT_INTER
Yue Chencb60b182016-10-13 15:18:22 -0700431 MOTION_MODE motion_mode;
Yue Chen5329a2b2017-02-28 17:33:00 +0800432#if CONFIG_MOTION_VAR
433 int overlappable_neighbors[2];
Wei-Ting Lin85a8f702017-06-22 13:55:15 -0700434#if CONFIG_NCOBMC_ADAPT_WEIGHT
435 // Applying different weighting kernels in ncobmc
436 // In current implementation, interpolation modes only defined for squared
437 // blocks. A rectangular block is divided into two squared blocks and each
438 // squared block has an interpolation mode.
439 NCOBMC_MODE ncobmc_mode[2];
440#endif
Yue Chen5329a2b2017-02-28 17:33:00 +0800441#endif // CONFIG_MOTION_VAR
Yaowu Xuc27fc142016-08-22 16:08:15 -0700442 int_mv mv[2];
443 int_mv pred_mv[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700444 uint8_t ref_mv_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700445#if CONFIG_EXT_PARTITION_TYPES
446 PARTITION_TYPE partition;
447#endif
448#if CONFIG_NEW_QUANT
449 int dq_off_index;
450 int send_dq_bit;
451#endif // CONFIG_NEW_QUANT
452 /* deringing gain *per-superblock* */
Jean-Marc Valin5f5c1322017-03-21 16:20:21 -0400453 int8_t cdef_strength;
Arild Fuldseth07441162016-08-15 15:07:52 +0200454#if CONFIG_DELTA_Q
455 int current_q_index;
Fangwen Fu231fe422017-04-24 17:52:29 -0700456#if CONFIG_EXT_DELTA_Q
457 int current_delta_lf_from_base;
458#endif
Arild Fuldseth07441162016-08-15 15:07:52 +0200459#endif
Angie Chiangd4022822016-11-02 18:30:25 -0700460#if CONFIG_RD_DEBUG
Angie Chiang9a44f5f2016-11-06 12:19:06 -0800461 RD_STATS rd_stats;
Angie Chiangd4022822016-11-02 18:30:25 -0700462 int mi_row;
463 int mi_col;
464#endif
Yue Chen69f18e12016-09-08 14:48:15 -0700465#if CONFIG_WARPED_MOTION
466 int num_proj_ref[2];
467 WarpedMotionParams wm_params[2];
468#endif // CONFIG_WARPED_MOTION
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800469
Luc Trudeauf5334002017-04-25 12:21:26 -0400470#if CONFIG_CFL
471 // Index of the alpha Cb and alpha Cr combination
Luc Trudeaua9bd85f2017-05-11 14:37:56 -0400472 int cfl_alpha_idx;
Luc Trudeauf5334002017-04-25 12:21:26 -0400473 // Signs of alpha Cb and alpha Cr
474 CFL_SIGN_TYPE cfl_alpha_signs[CFL_PRED_PLANES];
475#endif
476
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800477 BOUNDARY_TYPE boundary_info;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700478} MB_MODE_INFO;
479
480typedef struct MODE_INFO {
481 MB_MODE_INFO mbmi;
482 b_mode_info bmi[4];
483} MODE_INFO;
484
Alex Converse28744302017-04-13 14:46:22 -0700485#if CONFIG_INTRABC
486static INLINE int is_intrabc_block(const MB_MODE_INFO *mbmi) {
487 return mbmi->use_intrabc;
488}
489#endif
490
Yaowu Xuc27fc142016-08-22 16:08:15 -0700491static INLINE PREDICTION_MODE get_y_mode(const MODE_INFO *mi, int block) {
Jingning Hand7d20472016-12-14 11:13:48 -0800492#if CONFIG_CB4X4
493 (void)block;
494 return mi->mbmi.mode;
495#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700496 return mi->mbmi.sb_type < BLOCK_8X8 ? mi->bmi[block].as_mode : mi->mbmi.mode;
Jingning Hand7d20472016-12-14 11:13:48 -0800497#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700498}
499
Luc Trudeaud6d9eee2017-07-12 12:36:50 -0400500#if CONFIG_CFL
501static INLINE PREDICTION_MODE get_uv_mode(UV_PREDICTION_MODE mode) {
502 static const PREDICTION_MODE uv2y[UV_INTRA_MODES] = {
503 DC_PRED, // UV_DC_PRED
504 V_PRED, // UV_V_PRED
505 H_PRED, // UV_H_PRED
506 D45_PRED, // UV_D45_PRED
507 D135_PRED, // UV_D135_PRED
508 D117_PRED, // UV_D117_PRED
509 D153_PRED, // UV_D153_PRED
510 D207_PRED, // UV_D207_PRED
511 D63_PRED, // UV_D63_PRED
512#if CONFIG_ALT_INTRA
513 SMOOTH_PRED, // UV_SMOOTH_PRED
514#if CONFIG_SMOOTH_HV
515 SMOOTH_V_PRED, // UV_SMOOTH_V_PRED
516 SMOOTH_H_PRED, // UV_SMOOTH_H_PRED
517#endif // CONFIG_SMOOTH_HV
518#endif // CONFIG_ALT_INTRA
519 TM_PRED, // UV_TM_PRED
520 };
521 return uv2y[mode];
522}
523#else
524static INLINE PREDICTION_MODE get_uv_mode(PREDICTION_MODE mode) { return mode; }
525#endif // CONFIG_CFL
526
Yaowu Xuc27fc142016-08-22 16:08:15 -0700527static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) {
Alex Converse28744302017-04-13 14:46:22 -0700528#if CONFIG_INTRABC
529 if (is_intrabc_block(mbmi)) return 1;
530#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700531 return mbmi->ref_frame[0] > INTRA_FRAME;
532}
533
534static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) {
535 return mbmi->ref_frame[1] > INTRA_FRAME;
536}
537
Zoe Liuc082bbc2017-05-17 13:31:37 -0700538#if CONFIG_EXT_COMP_REFS
539static INLINE int has_uni_comp_refs(const MB_MODE_INFO *mbmi) {
540 return has_second_ref(mbmi) && (!((mbmi->ref_frame[0] >= BWDREF_FRAME) ^
541 (mbmi->ref_frame[1] >= BWDREF_FRAME)));
542}
543
544static INLINE MV_REFERENCE_FRAME comp_ref0(int ref_idx) {
545 static const MV_REFERENCE_FRAME lut[] = {
546 LAST_FRAME, // LAST_LAST2_FRAMES,
Zoe Liufcf5fa22017-06-26 16:00:38 -0700547 LAST_FRAME, // LAST_LAST3_FRAMES,
Zoe Liuc082bbc2017-05-17 13:31:37 -0700548 LAST_FRAME, // LAST_GOLDEN_FRAMES,
549 BWDREF_FRAME, // BWDREF_ALTREF_FRAMES,
550 };
551 assert(NELEMENTS(lut) == UNIDIR_COMP_REFS);
552 return lut[ref_idx];
553}
554
555static INLINE MV_REFERENCE_FRAME comp_ref1(int ref_idx) {
556 static const MV_REFERENCE_FRAME lut[] = {
557 LAST2_FRAME, // LAST_LAST2_FRAMES,
Zoe Liufcf5fa22017-06-26 16:00:38 -0700558 LAST3_FRAME, // LAST_LAST3_FRAMES,
Zoe Liuc082bbc2017-05-17 13:31:37 -0700559 GOLDEN_FRAME, // LAST_GOLDEN_FRAMES,
560 ALTREF_FRAME, // BWDREF_ALTREF_FRAMES,
561 };
562 assert(NELEMENTS(lut) == UNIDIR_COMP_REFS);
563 return lut[ref_idx];
564}
565#endif // CONFIG_EXT_COMP_REFS
566
Yaowu Xuf883b422016-08-30 14:01:10 -0700567PREDICTION_MODE av1_left_block_mode(const MODE_INFO *cur_mi,
568 const MODE_INFO *left_mi, int b);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700569
Yaowu Xuf883b422016-08-30 14:01:10 -0700570PREDICTION_MODE av1_above_block_mode(const MODE_INFO *cur_mi,
571 const MODE_INFO *above_mi, int b);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700572
Sarah Parker19234cc2017-03-10 16:43:25 -0800573#if CONFIG_GLOBAL_MOTION
574static INLINE int is_global_mv_block(const MODE_INFO *mi, int block,
575 TransformationType type) {
576 PREDICTION_MODE mode = get_y_mode(mi, block);
577#if GLOBAL_SUB8X8_USED
578 const int block_size_allowed = 1;
579#else
580 const BLOCK_SIZE bsize = mi->mbmi.sb_type;
581 const int block_size_allowed = (bsize >= BLOCK_8X8);
582#endif // GLOBAL_SUB8X8_USED
583#if CONFIG_EXT_INTER
584 return (mode == ZEROMV || mode == ZERO_ZEROMV) && type > TRANSLATION &&
585 block_size_allowed;
586#else
587 return mode == ZEROMV && type > TRANSLATION && block_size_allowed;
588#endif // CONFIG_EXT_INTER
589}
590#endif // CONFIG_GLOBAL_MOTION
591
Yaowu Xuc27fc142016-08-22 16:08:15 -0700592enum mv_precision { MV_PRECISION_Q3, MV_PRECISION_Q4 };
593
594struct buf_2d {
595 uint8_t *buf;
596 uint8_t *buf0;
597 int width;
598 int height;
599 int stride;
600};
601
602typedef struct macroblockd_plane {
603 tran_low_t *dqcoeff;
604 PLANE_TYPE plane_type;
605 int subsampling_x;
606 int subsampling_y;
607 struct buf_2d dst;
608 struct buf_2d pre[2];
609 ENTROPY_CONTEXT *above_context;
610 ENTROPY_CONTEXT *left_context;
611 int16_t seg_dequant[MAX_SEGMENTS][2];
612#if CONFIG_NEW_QUANT
clang-format67948d32016-09-07 22:40:40 -0700613 dequant_val_type_nuq seg_dequant_nuq[MAX_SEGMENTS][QUANT_PROFILES]
614 [COEF_BANDS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700615#endif
Urvang Joshib100db72016-10-12 16:28:56 -0700616#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700617 uint8_t *color_index_map;
Urvang Joshib100db72016-10-12 16:28:56 -0700618#endif // CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700619
620 // number of 4x4s in current block
621 uint16_t n4_w, n4_h;
622 // log2 of n4_w, n4_h
623 uint8_t n4_wl, n4_hl;
Jingning Hanc47fe6c2016-10-21 16:40:47 -0700624 // block size in pixels
625 uint8_t width, height;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700626
627#if CONFIG_AOM_QM
Thomas Davies6675adf2017-05-04 17:39:21 +0100628 const qm_val_t *seg_iqmatrix[MAX_SEGMENTS][2][TX_SIZES_ALL];
629 const qm_val_t *seg_qmatrix[MAX_SEGMENTS][2][TX_SIZES_ALL];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700630#endif
631 // encoder
632 const int16_t *dequant;
633#if CONFIG_NEW_QUANT
634 const dequant_val_type_nuq *dequant_val_nuq[QUANT_PROFILES];
635#endif // CONFIG_NEW_QUANT
Yushin Cho77bba8d2016-11-04 16:36:56 -0700636
Yushin Chob7b60c52017-07-14 16:18:52 -0700637#if CONFIG_PVQ || CONFIG_DIST_8X8
Yushin Cho77bba8d2016-11-04 16:36:56 -0700638 DECLARE_ALIGNED(16, int16_t, pred[MAX_SB_SQUARE]);
Yushin Chob7b60c52017-07-14 16:18:52 -0700639#endif
640#if CONFIG_PVQ
Yushin Cho77bba8d2016-11-04 16:36:56 -0700641 // PVQ: forward transformed predicted image, a reference for PVQ.
642 tran_low_t *pvq_ref_coeff;
643#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700644} MACROBLOCKD_PLANE;
645
Jingning Han3468df12016-12-05 17:53:16 -0800646#define BLOCK_OFFSET(x, i) \
647 ((x) + (i) * (1 << (tx_size_wide_log2[0] + tx_size_high_log2[0])))
Yaowu Xuc27fc142016-08-22 16:08:15 -0700648
649typedef struct RefBuffer {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700650 int idx;
651 YV12_BUFFER_CONFIG *buf;
652 struct scale_factors sf;
Zoe Liu7b1ec7a2017-05-24 22:28:24 -0700653#if CONFIG_VAR_REFS
Zoe Liu7b1ec7a2017-05-24 22:28:24 -0700654 int is_valid;
655#endif // CONFIG_VAR_REFS
Yaowu Xuc27fc142016-08-22 16:08:15 -0700656} RefBuffer;
657
Yi Luo2ab63cb2017-05-11 16:44:22 -0700658#if CONFIG_ADAPT_SCAN
659typedef int16_t EobThresholdMD[TX_TYPES][EOB_THRESHOLD_NUM];
660#endif
Luc Trudeauf8164152017-04-11 16:20:51 -0400661
Yaowu Xuc27fc142016-08-22 16:08:15 -0700662typedef struct macroblockd {
663 struct macroblockd_plane plane[MAX_MB_PLANE];
664 uint8_t bmode_blocks_wl;
665 uint8_t bmode_blocks_hl;
666
667 FRAME_COUNTS *counts;
668 TileInfo tile;
669
670 int mi_stride;
671
672 MODE_INFO **mi;
673 MODE_INFO *left_mi;
674 MODE_INFO *above_mi;
675 MB_MODE_INFO *left_mbmi;
676 MB_MODE_INFO *above_mbmi;
677
678 int up_available;
679 int left_available;
Jingning Han3da18d62017-05-02 12:43:58 -0700680#if CONFIG_CHROMA_SUB8X8
681 int chroma_up_available;
682 int chroma_left_available;
683#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700684
Yaowu Xuf883b422016-08-30 14:01:10 -0700685 const aom_prob (*partition_probs)[PARTITION_TYPES - 1];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700686
687 /* Distance of MB away from frame edges */
688 int mb_to_left_edge;
689 int mb_to_right_edge;
690 int mb_to_top_edge;
691 int mb_to_bottom_edge;
692
693 FRAME_CONTEXT *fc;
694
695 /* pointers to reference frames */
Urvang Joshi52648442016-10-13 17:27:51 -0700696 const RefBuffer *block_refs[2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700697
698 /* pointer to current frame */
699 const YV12_BUFFER_CONFIG *cur_buf;
700
Alex Conversee816b312017-05-01 09:51:24 -0700701#if CONFIG_INTRABC
702 /* Scale of the current frame with respect to itself */
703 struct scale_factors sf_identity;
704#endif
705
Yaowu Xuc27fc142016-08-22 16:08:15 -0700706 ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
707 ENTROPY_CONTEXT left_context[MAX_MB_PLANE][2 * MAX_MIB_SIZE];
708
709 PARTITION_CONTEXT *above_seg_context;
710 PARTITION_CONTEXT left_seg_context[MAX_MIB_SIZE];
711
712#if CONFIG_VAR_TX
713 TXFM_CONTEXT *above_txfm_context;
714 TXFM_CONTEXT *left_txfm_context;
Jingning Han331662e2017-05-30 17:03:32 -0700715 TXFM_CONTEXT left_txfm_context_buffer[2 * MAX_MIB_SIZE];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700716
717 TX_SIZE max_tx_size;
718#if CONFIG_SUPERTX
719 TX_SIZE supertx_size;
720#endif
721#endif
722
Jingning Hanff6ee6a2016-12-07 09:55:21 -0800723 // block dimension in the unit of mode_info.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700724 uint8_t n8_w, n8_h;
725
Yaowu Xuc27fc142016-08-22 16:08:15 -0700726 uint8_t ref_mv_count[MODE_CTX_REF_FRAMES];
727 CANDIDATE_MV ref_mv_stack[MODE_CTX_REF_FRAMES][MAX_REF_MV_STACK_SIZE];
728 uint8_t is_sec_rect;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700729
Yushin Cho77bba8d2016-11-04 16:36:56 -0700730#if CONFIG_PVQ
731 daala_dec_ctx daala_dec;
732#endif
Thomas Daviesf77d4ad2017-01-10 18:55:42 +0000733 FRAME_CONTEXT *tile_ctx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700734 /* Bit depth: 8, 10, 12 */
735 int bd;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700736
Debargha Mukherjee3c42c092016-09-29 09:17:36 -0700737 int qindex[MAX_SEGMENTS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700738 int lossless[MAX_SEGMENTS];
739 int corrupted;
740
Yaowu Xuf883b422016-08-30 14:01:10 -0700741 struct aom_internal_error_info *error_info;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700742#if CONFIG_GLOBAL_MOTION
David Barkercf3d0b02016-11-10 10:14:49 +0000743 WarpedMotionParams *global_motion;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700744#endif // CONFIG_GLOBAL_MOTION
Arild Fuldseth07441162016-08-15 15:07:52 +0200745#if CONFIG_DELTA_Q
746 int prev_qindex;
747 int delta_qindex;
748 int current_qindex;
Fangwen Fu231fe422017-04-24 17:52:29 -0700749#if CONFIG_EXT_DELTA_Q
750 // Since actual frame level loop filtering level value is not available
751 // at the beginning of the tile (only available during actual filtering)
752 // at encoder side.we record the delta_lf (against the frame level loop
753 // filtering level) and code the delta between previous superblock's delta
754 // lf and current delta lf. It is equivalent to the delta between previous
755 // superblock's actual lf and current lf.
756 int prev_delta_lf_from_base;
757 int current_delta_lf_from_base;
758#endif
Arild Fuldseth07441162016-08-15 15:07:52 +0200759#endif
Yi Luof8e87b42017-04-14 17:20:27 -0700760#if CONFIG_ADAPT_SCAN
761 const EobThresholdMD *eob_threshold_md;
762#endif
Luc Trudeauf8164152017-04-11 16:20:51 -0400763
Sarah Parker2d0e9b72017-05-04 01:34:16 +0000764#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SEGMENT
765 DECLARE_ALIGNED(16, uint8_t, seg_mask[2 * MAX_SB_SQUARE]);
766#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SEGMENT
767
Luc Trudeauf8164152017-04-11 16:20:51 -0400768#if CONFIG_CFL
769 CFL_CTX *cfl;
770#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700771} MACROBLOCKD;
772
Yi Luo51281092017-06-26 16:36:15 -0700773static INLINE int get_bitdepth_data_path_index(const MACROBLOCKD *xd) {
774 return xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH ? 1 : 0;
775}
776
Yaowu Xuc27fc142016-08-22 16:08:15 -0700777static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize,
778 PARTITION_TYPE partition) {
779 if (partition == PARTITION_INVALID)
Urvang Joshicb586f32016-09-20 11:36:33 -0700780 return BLOCK_INVALID;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700781 else
782 return subsize_lookup[partition][bsize];
783}
784
785static const TX_TYPE intra_mode_to_tx_type_context[INTRA_MODES] = {
786 DCT_DCT, // DC
787 ADST_DCT, // V
788 DCT_ADST, // H
789 DCT_DCT, // D45
790 ADST_ADST, // D135
791 ADST_DCT, // D117
792 DCT_ADST, // D153
793 DCT_ADST, // D207
794 ADST_DCT, // D63
Urvang Joshi6be4a542016-11-03 15:24:05 -0700795#if CONFIG_ALT_INTRA
796 ADST_ADST, // SMOOTH
Urvang Joshie6ca8e82017-03-15 14:57:41 -0700797#if CONFIG_SMOOTH_HV
798 ADST_DCT, // SMOOTH_V
799 DCT_ADST, // SMOOTH_H
800#endif // CONFIG_SMOOTH_HV
Urvang Joshi6be4a542016-11-03 15:24:05 -0700801#endif // CONFIG_ALT_INTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700802 ADST_ADST, // TM
803};
804
805#if CONFIG_SUPERTX
806static INLINE int supertx_enabled(const MB_MODE_INFO *mbmi) {
Jingning Han93531242016-12-20 11:54:36 -0800807 TX_SIZE max_tx_size = txsize_sqr_map[mbmi->tx_size];
808 return tx_size_wide[max_tx_size] >
809 AOMMIN(block_size_wide[mbmi->sb_type], block_size_high[mbmi->sb_type]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700810}
811#endif // CONFIG_SUPERTX
812
Jingning Hanb83e64b2017-03-01 14:52:04 -0800813#define USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4 1
Debargha Mukherjee5a488a62016-11-22 22:24:10 -0800814
Sarah Parker076437f2017-03-14 17:39:53 -0700815#if CONFIG_RECT_TX
Sarah Parker076437f2017-03-14 17:39:53 -0700816static INLINE int is_rect_tx(TX_SIZE tx_size) { return tx_size >= TX_SIZES; }
817#endif // CONFIG_RECT_TX
818
Jingning Hanb83e64b2017-03-01 14:52:04 -0800819#if CONFIG_EXT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -0700820#define ALLOW_INTRA_EXT_TX 1
Yaowu Xuc27fc142016-08-22 16:08:15 -0700821
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800822typedef enum {
823 // DCT only
824 EXT_TX_SET_DCTONLY = 0,
825 // DCT + Identity only
Sarah Parker53f93db2017-07-11 17:20:04 -0700826 EXT_TX_SET_DCT_IDTX,
827#if CONFIG_MRC_TX
828 // DCT + MRC_DCT
829 EXT_TX_SET_MRC_DCT,
830 // DCT + MRC_DCT + IDTX
831 EXT_TX_SET_MRC_DCT_IDTX,
832#endif // CONFIG_MRC_TX
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800833 // Discrete Trig transforms w/o flip (4) + Identity (1)
Sarah Parker53f93db2017-07-11 17:20:04 -0700834 EXT_TX_SET_DTT4_IDTX,
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800835 // Discrete Trig transforms w/o flip (4) + Identity (1) + 1D Hor/vert DCT (2)
Sarah Parker53f93db2017-07-11 17:20:04 -0700836 EXT_TX_SET_DTT4_IDTX_1DDCT,
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800837 // Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver DCT (2)
Sarah Parker53f93db2017-07-11 17:20:04 -0700838 EXT_TX_SET_DTT9_IDTX_1DDCT,
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800839 // Discrete Trig transforms w/ flip (9) + Identity (1) + 1D Hor/Ver (6)
Sarah Parker53f93db2017-07-11 17:20:04 -0700840 EXT_TX_SET_ALL16,
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800841 EXT_TX_SET_TYPES
842} TxSetType;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700843
Sarah Parker53f93db2017-07-11 17:20:04 -0700844#if CONFIG_MRC_TX
845// Number of transform types in each set type
846static const int num_ext_tx_set[EXT_TX_SET_TYPES] = {
847 1, 2, 2, 3, 5, 7, 12, 16
848};
849
850// Maps intra set index to the set type
851static const int ext_tx_set_type_intra[EXT_TX_SETS_INTRA] = {
852 EXT_TX_SET_DCTONLY, EXT_TX_SET_DTT4_IDTX_1DDCT, EXT_TX_SET_DTT4_IDTX,
853 EXT_TX_SET_MRC_DCT
854};
855
856// Maps inter set index to the set type
857static const int ext_tx_set_type_inter[EXT_TX_SETS_INTER] = {
858 EXT_TX_SET_DCTONLY, EXT_TX_SET_ALL16, EXT_TX_SET_DTT9_IDTX_1DDCT,
859 EXT_TX_SET_DCT_IDTX, EXT_TX_SET_MRC_DCT_IDTX
860};
861
862// Maps set types above to the indices used for intra
863static const int ext_tx_set_index_intra[EXT_TX_SET_TYPES] = { 0, -1, 3, -1,
864 2, 1, -1, -1 };
865
866// Maps set types above to the indices used for inter
867static const int ext_tx_set_index_inter[EXT_TX_SET_TYPES] = { 0, 3, -1, 4,
868 -1, -1, 2, 1 };
869#else // CONFIG_MRC_TX
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800870// Number of transform types in each set type
871static const int num_ext_tx_set[EXT_TX_SET_TYPES] = { 1, 2, 5, 7, 12, 16 };
872
873// Maps intra set index to the set type
874static const int ext_tx_set_type_intra[EXT_TX_SETS_INTRA] = {
875 EXT_TX_SET_DCTONLY, EXT_TX_SET_DTT4_IDTX_1DDCT, EXT_TX_SET_DTT4_IDTX
876};
877
878// Maps inter set index to the set type
879static const int ext_tx_set_type_inter[EXT_TX_SETS_INTER] = {
880 EXT_TX_SET_DCTONLY, EXT_TX_SET_ALL16, EXT_TX_SET_DTT9_IDTX_1DDCT,
881 EXT_TX_SET_DCT_IDTX
882};
883
884// Maps set types above to the indices used for intra
885static const int ext_tx_set_index_intra[EXT_TX_SET_TYPES] = { 0, -1, 2,
886 1, -1, -1 };
887
888// Maps set types above to the indices used for inter
889static const int ext_tx_set_index_inter[EXT_TX_SET_TYPES] = {
890 0, 3, -1, -1, 2, 1
891};
Sarah Parker53f93db2017-07-11 17:20:04 -0700892#endif // CONFIG_MRC_TX
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800893
894static INLINE TxSetType get_ext_tx_set_type(TX_SIZE tx_size, BLOCK_SIZE bs,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800895 int is_inter, int use_reduced_set) {
Yue Chen56e226e2017-05-02 16:21:40 -0700896 const TX_SIZE tx_size_sqr_up = txsize_sqr_up_map[tx_size];
897 const TX_SIZE tx_size_sqr = txsize_sqr_map[tx_size];
Debargha Mukherjee094c9432017-02-22 10:31:25 -0800898#if CONFIG_CB4X4 && USE_TXTYPE_SEARCH_FOR_SUB8X8_IN_CB4X4
Jingning Han1a00cff2016-12-28 14:53:14 -0800899 (void)bs;
Yue Chen56e226e2017-05-02 16:21:40 -0700900 if (tx_size_sqr > TX_32X32) return EXT_TX_SET_DCTONLY;
Jingning Han1a00cff2016-12-28 14:53:14 -0800901#else
Yue Chen56e226e2017-05-02 16:21:40 -0700902 if (tx_size_sqr > TX_32X32 || bs < BLOCK_8X8) return EXT_TX_SET_DCTONLY;
Jingning Han1a00cff2016-12-28 14:53:14 -0800903#endif
Sarah Parker5effe3f2017-02-23 12:49:10 -0800904 if (use_reduced_set)
905 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DTT4_IDTX;
Sarah Parker53f93db2017-07-11 17:20:04 -0700906#if CONFIG_MRC_TX
907 if (tx_size == TX_32X32)
908 return is_inter ? EXT_TX_SET_MRC_DCT_IDTX : EXT_TX_SET_MRC_DCT;
909#endif // CONFIG_MRC_TX
Yue Chen56e226e2017-05-02 16:21:40 -0700910 if (tx_size_sqr_up == TX_32X32)
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800911 return is_inter ? EXT_TX_SET_DCT_IDTX : EXT_TX_SET_DCTONLY;
912 if (is_inter)
Yue Chen56e226e2017-05-02 16:21:40 -0700913 return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT9_IDTX_1DDCT
914 : EXT_TX_SET_ALL16);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800915 else
Yue Chen56e226e2017-05-02 16:21:40 -0700916 return (tx_size_sqr == TX_16X16 ? EXT_TX_SET_DTT4_IDTX
917 : EXT_TX_SET_DTT4_IDTX_1DDCT);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800918}
919
920static INLINE int get_ext_tx_set(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter,
Sarah Parker5effe3f2017-02-23 12:49:10 -0800921 int use_reduced_set) {
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800922 const TxSetType set_type =
Sarah Parker5effe3f2017-02-23 12:49:10 -0800923 get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set);
Debargha Mukherjee08542b92017-02-21 01:08:14 -0800924 return is_inter ? ext_tx_set_index_inter[set_type]
925 : ext_tx_set_index_intra[set_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700926}
927
Sarah Parker53f93db2017-07-11 17:20:04 -0700928#if CONFIG_MRC_TX
929static const int use_intra_ext_tx_for_txsize[EXT_TX_SETS_INTRA][EXT_TX_SIZES] =
930 {
931#if CONFIG_CHROMA_2X2
932 { 1, 1, 1, 1, 1 }, // unused
933 { 0, 1, 1, 0, 0 },
934 { 0, 0, 0, 1, 0 },
935 { 0, 0, 0, 0, 1 },
936#else
937 { 1, 1, 1, 1 }, // unused
938 { 1, 1, 0, 0 },
939 { 0, 0, 1, 0 },
940 { 0, 0, 0, 1 },
941#endif // CONFIG_CHROMA_2X2
942 };
943
944static const int use_inter_ext_tx_for_txsize[EXT_TX_SETS_INTER][EXT_TX_SIZES] =
945 {
946#if CONFIG_CHROMA_2X2
947 { 1, 1, 1, 1, 1 }, // unused
948 { 0, 1, 1, 0, 0 }, { 0, 0, 0, 1, 0 },
949 { 0, 0, 0, 0, 1 }, { 0, 0, 0, 0, 1 },
950#else
951 { 1, 1, 1, 1 }, // unused
952 { 1, 1, 0, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 1 }, { 0, 0, 0, 1 },
953#endif // CONFIG_CHROMA_2X2
954 };
955
956// Transform types used in each intra set
957static const int ext_tx_used_intra[EXT_TX_SETS_INTRA][TX_TYPES] = {
958 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
959 { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0 },
960 { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
961 { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 },
962};
963
964// Numbers of transform types used in each intra set
965static const int ext_tx_cnt_intra[EXT_TX_SETS_INTRA] = { 1, 7, 5, 2 };
966
967// Transform types used in each inter set
968static const int ext_tx_used_inter[EXT_TX_SETS_INTER][TX_TYPES] = {
969 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
970 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
971 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 },
972 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 },
973 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 },
974};
975
976// Numbers of transform types used in each inter set
977static const int ext_tx_cnt_inter[EXT_TX_SETS_INTER] = { 1, 16, 12, 2, 3 };
978
979// 1D Transforms used in inter set, this needs to be changed if
980// ext_tx_used_inter is changed
981static const int ext_tx_used_inter_1D[EXT_TX_SETS_INTER][TX_TYPES_1D] = {
982 { 1, 0, 0, 0 }, { 1, 1, 1, 1 }, { 1, 1, 1, 1 }, { 1, 0, 0, 1 }, { 1, 0, 0, 1 }
983};
984#else // CONFIG_MRC_TX
clang-format55ce9e02017-02-15 22:27:12 -0800985static const int use_intra_ext_tx_for_txsize[EXT_TX_SETS_INTRA][EXT_TX_SIZES] =
986 {
Timothy B. Terriberryfe67ed62017-04-26 16:53:47 -0700987#if CONFIG_CHROMA_2X2
clang-format55ce9e02017-02-15 22:27:12 -0800988 { 1, 1, 1, 1, 1 }, // unused
989 { 0, 1, 1, 0, 0 },
990 { 0, 0, 0, 1, 0 },
Jingning Han1a00cff2016-12-28 14:53:14 -0800991#else
clang-format55ce9e02017-02-15 22:27:12 -0800992 { 1, 1, 1, 1 }, // unused
993 { 1, 1, 0, 0 },
994 { 0, 0, 1, 0 },
Timothy B. Terriberryfe67ed62017-04-26 16:53:47 -0700995#endif // CONFIG_CHROMA_2X2
clang-format55ce9e02017-02-15 22:27:12 -0800996 };
Yaowu Xuc27fc142016-08-22 16:08:15 -0700997
clang-format55ce9e02017-02-15 22:27:12 -0800998static const int use_inter_ext_tx_for_txsize[EXT_TX_SETS_INTER][EXT_TX_SIZES] =
999 {
Timothy B. Terriberryfe67ed62017-04-26 16:53:47 -07001000#if CONFIG_CHROMA_2X2
clang-format55ce9e02017-02-15 22:27:12 -08001001 { 1, 1, 1, 1, 1 }, // unused
1002 { 0, 1, 1, 0, 0 },
1003 { 0, 0, 0, 1, 0 },
1004 { 0, 0, 0, 0, 1 },
Jingning Han1a00cff2016-12-28 14:53:14 -08001005#else
clang-format55ce9e02017-02-15 22:27:12 -08001006 { 1, 1, 1, 1 }, // unused
1007 { 1, 1, 0, 0 },
1008 { 0, 0, 1, 0 },
1009 { 0, 0, 0, 1 },
Timothy B. Terriberryfe67ed62017-04-26 16:53:47 -07001010#endif // CONFIG_CHROMA_2X2
clang-format55ce9e02017-02-15 22:27:12 -08001011 };
Yaowu Xuc27fc142016-08-22 16:08:15 -07001012
1013// Transform types used in each intra set
1014static const int ext_tx_used_intra[EXT_TX_SETS_INTRA][TX_TYPES] = {
1015 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1016 { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0 },
1017 { 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
1018};
1019
Thomas Daviesb1bedf52017-03-17 14:03:28 +00001020// Numbers of transform types used in each intra set
1021static const int ext_tx_cnt_intra[EXT_TX_SETS_INTRA] = { 1, 7, 5 };
1022
Yaowu Xuc27fc142016-08-22 16:08:15 -07001023// Transform types used in each inter set
1024static const int ext_tx_used_inter[EXT_TX_SETS_INTER][TX_TYPES] = {
1025 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
1026 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
1027 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
1028 { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
1029};
1030
Thomas Daviesb1bedf52017-03-17 14:03:28 +00001031// Numbers of transform types used in each inter set
1032static const int ext_tx_cnt_inter[EXT_TX_SETS_INTER] = { 1, 16, 12, 2 };
1033
Yaowu Xuc27fc142016-08-22 16:08:15 -07001034// 1D Transforms used in inter set, this needs to be changed if
1035// ext_tx_used_inter is changed
1036static const int ext_tx_used_inter_1D[EXT_TX_SETS_INTER][TX_TYPES_1D] = {
1037 { 1, 0, 0, 0 }, { 1, 1, 1, 1 }, { 1, 1, 1, 1 }, { 1, 0, 0, 1 },
1038};
Sarah Parker53f93db2017-07-11 17:20:04 -07001039#endif // CONFIG_MRC_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001040
Sarah Parkere68a3e42017-02-16 14:03:24 -08001041static INLINE int get_ext_tx_types(TX_SIZE tx_size, BLOCK_SIZE bs, int is_inter,
Sarah Parker5effe3f2017-02-23 12:49:10 -08001042 int use_reduced_set) {
1043 const int set_type =
1044 get_ext_tx_set_type(tx_size, bs, is_inter, use_reduced_set);
Debargha Mukherjee08542b92017-02-21 01:08:14 -08001045 return num_ext_tx_set[set_type];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001046}
1047
1048#if CONFIG_RECT_TX
1049static INLINE int is_rect_tx_allowed_bsize(BLOCK_SIZE bsize) {
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001050 static const char LUT[BLOCK_SIZES_ALL] = {
Timothy B. Terriberry81ec2612017-04-26 16:53:47 -07001051#if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8
Jingning Hanf4e097b2017-01-20 09:23:58 -08001052 0, // BLOCK_2X2
1053 0, // BLOCK_2X4
1054 0, // BLOCK_4X2
1055#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001056 0, // BLOCK_4X4
1057 1, // BLOCK_4X8
1058 1, // BLOCK_8X4
1059 0, // BLOCK_8X8
1060 1, // BLOCK_8X16
1061 1, // BLOCK_16X8
1062 0, // BLOCK_16X16
1063 1, // BLOCK_16X32
1064 1, // BLOCK_32X16
1065 0, // BLOCK_32X32
1066 0, // BLOCK_32X64
1067 0, // BLOCK_64X32
1068 0, // BLOCK_64X64
1069#if CONFIG_EXT_PARTITION
1070 0, // BLOCK_64X128
1071 0, // BLOCK_128X64
1072 0, // BLOCK_128X128
1073#endif // CONFIG_EXT_PARTITION
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001074 0, // BLOCK_4X16
1075 0, // BLOCK_16X4
1076 0, // BLOCK_8X32
1077 0, // BLOCK_32X8
Yaowu Xuc27fc142016-08-22 16:08:15 -07001078 };
1079
1080 return LUT[bsize];
1081}
1082
Yue Chen49587a72016-09-28 17:09:47 -07001083static INLINE int is_rect_tx_allowed(const MACROBLOCKD *xd,
1084 const MB_MODE_INFO *mbmi) {
Urvang Joshifeb925f2016-12-05 10:37:29 -08001085 return is_rect_tx_allowed_bsize(mbmi->sb_type) &&
Yue Chen49587a72016-09-28 17:09:47 -07001086 !xd->lossless[mbmi->segment_id];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001087}
Yue Chend6bdd462017-07-19 16:05:43 -07001088#endif // CONFIG_RECT_TX
1089#endif // CONFIG_EXT_TX
Yue Chen56e226e2017-05-02 16:21:40 -07001090
Yue Chend6bdd462017-07-19 16:05:43 -07001091#if CONFIG_RECT_TX_EXT && (CONFIG_EXT_TX || CONFIG_VAR_TX)
Yue Chen56e226e2017-05-02 16:21:40 -07001092static INLINE int is_quarter_tx_allowed_bsize(BLOCK_SIZE bsize) {
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001093 static const char LUT_QTTX[BLOCK_SIZES_ALL] = {
Timothy B. Terriberry81ec2612017-04-26 16:53:47 -07001094#if CONFIG_CHROMA_2X2 || CONFIG_CHROMA_SUB8X8
Yue Chen56e226e2017-05-02 16:21:40 -07001095 0, // BLOCK_2X2
1096 0, // BLOCK_2X4
1097 0, // BLOCK_4X2
1098#endif
1099 0, // BLOCK_4X4
1100 0, // BLOCK_4X8
1101 0, // BLOCK_8X4
1102 0, // BLOCK_8X8
1103 1, // BLOCK_8X16
1104 1, // BLOCK_16X8
1105 0, // BLOCK_16X16
1106 0, // BLOCK_16X32
1107 0, // BLOCK_32X16
1108 0, // BLOCK_32X32
1109 0, // BLOCK_32X64
1110 0, // BLOCK_64X32
1111 0, // BLOCK_64X64
1112#if CONFIG_EXT_PARTITION
1113 0, // BLOCK_64X128
1114 0, // BLOCK_128X64
1115 0, // BLOCK_128X128
1116#endif // CONFIG_EXT_PARTITION
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001117 0, // BLOCK_4X16
1118 0, // BLOCK_16X4
1119 0, // BLOCK_8X32
1120 0, // BLOCK_32X8
Yue Chen56e226e2017-05-02 16:21:40 -07001121 };
1122
1123 return LUT_QTTX[bsize];
1124}
1125
1126static INLINE int is_quarter_tx_allowed(const MACROBLOCKD *xd,
1127 const MB_MODE_INFO *mbmi,
1128 int is_inter) {
1129 return is_quarter_tx_allowed_bsize(mbmi->sb_type) && is_inter &&
1130 !xd->lossless[mbmi->segment_id];
1131}
Yue Chend6bdd462017-07-19 16:05:43 -07001132#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001133
1134static INLINE TX_SIZE tx_size_from_tx_mode(BLOCK_SIZE bsize, TX_MODE tx_mode,
1135 int is_inter) {
1136 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
Debargha Mukherjee428bbb22017-03-17 07:30:24 -07001137#if (CONFIG_VAR_TX || CONFIG_EXT_TX) && CONFIG_RECT_TX
Urvang Joshifeb925f2016-12-05 10:37:29 -08001138 const TX_SIZE max_rect_tx_size = max_txsize_rect_lookup[bsize];
Jingning Han70e5f3f2016-11-09 17:03:07 -08001139#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001140 const TX_SIZE max_tx_size = max_txsize_lookup[bsize];
Debargha Mukherjee428bbb22017-03-17 07:30:24 -07001141#endif // (CONFIG_VAR_TX || CONFIG_EXT_TX) && CONFIG_RECT_TX
Urvang Joshifeb925f2016-12-05 10:37:29 -08001142 (void)is_inter;
Debargha Mukherjee428bbb22017-03-17 07:30:24 -07001143#if CONFIG_VAR_TX && CONFIG_RECT_TX
Urvang Joshifeb925f2016-12-05 10:37:29 -08001144#if CONFIG_CB4X4
1145 if (bsize == BLOCK_4X4)
1146 return AOMMIN(max_txsize_lookup[bsize], largest_tx_size);
1147#else
1148 if (bsize < BLOCK_8X8)
1149 return AOMMIN(max_txsize_lookup[bsize], largest_tx_size);
Jingning Han70e5f3f2016-11-09 17:03:07 -08001150#endif
Urvang Joshifeb925f2016-12-05 10:37:29 -08001151 if (txsize_sqr_map[max_rect_tx_size] <= largest_tx_size)
1152 return max_rect_tx_size;
1153 else
1154 return largest_tx_size;
1155#elif CONFIG_EXT_TX && CONFIG_RECT_TX
1156 if (txsize_sqr_up_map[max_rect_tx_size] <= largest_tx_size) {
1157 return max_rect_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001158 } else {
Urvang Joshifeb925f2016-12-05 10:37:29 -08001159 return largest_tx_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001160 }
1161#else
Yaowu Xuf883b422016-08-30 14:01:10 -07001162 return AOMMIN(max_tx_size, largest_tx_size);
Debargha Mukherjee428bbb22017-03-17 07:30:24 -07001163#endif // CONFIG_VAR_TX && CONFIG_RECT_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001164}
1165
hui su5db97432016-10-14 16:10:14 -07001166#if CONFIG_EXT_INTRA
hui su0a6731f2017-04-26 15:23:47 -07001167#define MAX_ANGLE_DELTA 3
1168#define ANGLE_STEP 3
hui su5db97432016-10-14 16:10:14 -07001169extern const int16_t dr_intra_derivative[90];
hui su02c79742017-05-16 17:19:04 -07001170static const uint8_t mode_to_angle_map[] = {
hui su5db97432016-10-14 16:10:14 -07001171 0, 90, 180, 45, 135, 111, 157, 203, 67, 0,
hui su02c79742017-05-16 17:19:04 -07001172#if CONFIG_ALT_INTRA
1173 0,
1174#if CONFIG_SMOOTH_HV
1175 0, 0,
1176#endif // CONFIG_SMOOTH_HV
1177#endif // CONFIG_ALT_INTRA
hui su5db97432016-10-14 16:10:14 -07001178};
hui sueda3d762016-12-06 16:58:23 -08001179#if CONFIG_INTRA_INTERP
hui su5db97432016-10-14 16:10:14 -07001180// Returns whether filter selection is needed for a given
1181// intra prediction angle.
Yaowu Xuf883b422016-08-30 14:01:10 -07001182int av1_is_intra_filter_switchable(int angle);
hui sueda3d762016-12-06 16:58:23 -08001183#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -07001184#endif // CONFIG_EXT_INTRA
1185
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001186#if CONFIG_DCT_ONLY
1187#define FIXED_TX_TYPE 1
1188#else
Yaowu Xuc27fc142016-08-22 16:08:15 -07001189#define FIXED_TX_TYPE 0
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001190#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -07001191
Angie Chiang752ccce2017-04-09 13:41:13 -07001192// Converts block_index for given transform size to index of the block in raster
1193// order.
1194static INLINE int av1_block_index_to_raster_order(TX_SIZE tx_size,
1195 int block_idx) {
1196 // For transform size 4x8, the possible block_idx values are 0 & 2, because
1197 // block_idx values are incremented in steps of size 'tx_width_unit x
1198 // tx_height_unit'. But, for this transform size, block_idx = 2 corresponds to
1199 // block number 1 in raster order, inside an 8x8 MI block.
1200 // For any other transform size, the two indices are equivalent.
1201 return (tx_size == TX_4X8 && block_idx == 2) ? 1 : block_idx;
1202}
1203
1204// Inverse of above function.
1205// Note: only implemented for transform sizes 4x4, 4x8 and 8x4 right now.
1206static INLINE int av1_raster_order_to_block_index(TX_SIZE tx_size,
1207 int raster_order) {
1208 assert(tx_size == TX_4X4 || tx_size == TX_4X8 || tx_size == TX_8X4);
1209 // We ensure that block indices are 0 & 2 if tx size is 4x8 or 8x4.
1210 return (tx_size == TX_4X4) ? raster_order : (raster_order > 0) ? 2 : 0;
1211}
1212
Lester Lu708c1ec2017-06-14 14:54:49 -07001213#if CONFIG_DPCM_INTRA || CONFIG_LGT
1214static INLINE PREDICTION_MODE get_prediction_mode(const MODE_INFO *mi,
1215 int plane, TX_SIZE tx_size,
1216 int block_idx) {
1217 const MB_MODE_INFO *const mbmi = &mi->mbmi;
1218 if (is_inter_block(mbmi)) return mbmi->mode;
1219
1220 int block_raster_idx = av1_block_index_to_raster_order(tx_size, block_idx);
Luc Trudeaud6d9eee2017-07-12 12:36:50 -04001221 return (plane == PLANE_TYPE_Y) ? get_y_mode(mi, block_raster_idx)
1222 : get_uv_mode(mbmi->uv_mode);
Lester Lu708c1ec2017-06-14 14:54:49 -07001223}
1224#endif
1225
Yaowu Xuc27fc142016-08-22 16:08:15 -07001226static INLINE TX_TYPE get_default_tx_type(PLANE_TYPE plane_type,
1227 const MACROBLOCKD *xd, int block_idx,
1228 TX_SIZE tx_size) {
1229 const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
1230
Monty Montgomerycb55dad2017-07-11 16:59:52 -04001231 if (CONFIG_DCT_ONLY || is_inter_block(mbmi) || plane_type != PLANE_TYPE_Y ||
Yaowu Xuc27fc142016-08-22 16:08:15 -07001232 xd->lossless[mbmi->segment_id] || tx_size >= TX_32X32)
1233 return DCT_DCT;
1234
1235 return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y
1236 ? get_y_mode(xd->mi[0], block_idx)
Luc Trudeaud6d9eee2017-07-12 12:36:50 -04001237 : get_uv_mode(mbmi->uv_mode)];
Yaowu Xuc27fc142016-08-22 16:08:15 -07001238}
1239
hui su45b64752017-07-12 16:54:35 -07001240static INLINE TX_TYPE av1_get_tx_type(PLANE_TYPE plane_type,
Jingning Han19b5c8f2017-07-06 15:10:12 -07001241 const MACROBLOCKD *xd, int blk_row,
1242 int blk_col, int block, TX_SIZE tx_size) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001243 const MODE_INFO *const mi = xd->mi[0];
1244 const MB_MODE_INFO *const mbmi = &mi->mbmi;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001245 (void)blk_row;
1246 (void)blk_col;
Alex Conversedaa15e42017-05-02 14:27:16 -07001247#if CONFIG_INTRABC && (!CONFIG_EXT_TX || CONFIG_TXK_SEL)
1248 // TODO(aconverse@google.com): Handle INTRABC + EXT_TX + TXK_SEL
Alex Converse28744302017-04-13 14:46:22 -07001249 if (is_intrabc_block(mbmi)) return DCT_DCT;
Alex Conversedaa15e42017-05-02 14:27:16 -07001250#endif // CONFIG_INTRABC && (!CONFIG_EXT_TX || CONFIG_TXK_SEL)
hui su45b64752017-07-12 16:54:35 -07001251
1252#if CONFIG_TXK_SEL
1253 TX_TYPE tx_type;
Jingning Han19b5c8f2017-07-06 15:10:12 -07001254 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] >= TX_32X32) {
hui su45b64752017-07-12 16:54:35 -07001255 tx_type = DCT_DCT;
1256 } else {
Jingning Han19b5c8f2017-07-06 15:10:12 -07001257 if (plane_type == PLANE_TYPE_Y)
1258 tx_type = mbmi->txk_type[(blk_row << 4) + blk_col];
1259 else if (is_inter_block(mbmi))
1260 tx_type = mbmi->txk_type[(blk_row << 5) + (blk_col << 1)];
1261 else
1262 tx_type = intra_mode_to_tx_type_context[mbmi->uv_mode];
hui su45b64752017-07-12 16:54:35 -07001263 }
1264 assert(tx_type >= DCT_DCT && tx_type < TX_TYPES);
1265 return tx_type;
1266#endif // CONFIG_TXK_SEL
1267
James Zern7cdaa602017-04-20 20:12:46 -07001268#if FIXED_TX_TYPE
Angie Chiangc2ebfbf2017-04-15 13:56:58 -07001269 const int block_raster_idx = av1_block_index_to_raster_order(tx_size, block);
James Zern7cdaa602017-04-20 20:12:46 -07001270 return get_default_tx_type(plane_type, xd, block_raster_idx, tx_size);
hui su45b64752017-07-12 16:54:35 -07001271#endif // FIXED_TX_TYPE
1272
1273#if CONFIG_EXT_TX
Sarah Parker53f93db2017-07-11 17:20:04 -07001274#if CONFIG_MRC_TX
1275 if (mbmi->tx_type == MRC_DCT) {
1276 if (plane_type == PLANE_TYPE_Y) {
1277 assert(tx_size == TX_32X32);
1278 return mbmi->tx_type;
1279 }
1280 return DCT_DCT;
1281 }
1282#endif // CONFIG_MRC_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001283 if (xd->lossless[mbmi->segment_id] || txsize_sqr_map[tx_size] > TX_32X32 ||
1284 (txsize_sqr_map[tx_size] >= TX_32X32 && !is_inter_block(mbmi)))
Yaowu Xuc27fc142016-08-22 16:08:15 -07001285 return DCT_DCT;
Jingning Han8260d8b2016-12-28 13:48:43 -08001286 if (mbmi->sb_type >= BLOCK_8X8 || CONFIG_CB4X4) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001287 if (plane_type == PLANE_TYPE_Y) {
1288#if !ALLOW_INTRA_EXT_TX
1289 if (is_inter_block(mbmi))
1290#endif // ALLOW_INTRA_EXT_TX
1291 return mbmi->tx_type;
1292 }
Jingning Han1a00cff2016-12-28 14:53:14 -08001293
1294 if (is_inter_block(mbmi)) {
1295// UV Inter only
Timothy B. Terriberryfe67ed62017-04-26 16:53:47 -07001296#if CONFIG_CHROMA_2X2
Jingning Han1a00cff2016-12-28 14:53:14 -08001297 if (tx_size < TX_4X4) return DCT_DCT;
1298#endif
Debargha Mukherjee5a488a62016-11-22 22:24:10 -08001299 return (mbmi->tx_type == IDTX && txsize_sqr_map[tx_size] >= TX_32X32)
Yaowu Xuc27fc142016-08-22 16:08:15 -07001300 ? DCT_DCT
1301 : mbmi->tx_type;
Jingning Han1a00cff2016-12-28 14:53:14 -08001302 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001303 }
1304
Jingning Han8260d8b2016-12-28 13:48:43 -08001305#if CONFIG_CB4X4
Thomas Daedeb7e72f32017-04-26 13:40:31 -07001306 (void)block;
Timothy B. Terriberryfe67ed62017-04-26 16:53:47 -07001307#if CONFIG_CHROMA_2X2
Jingning Han1a00cff2016-12-28 14:53:14 -08001308 if (tx_size < TX_4X4)
1309 return DCT_DCT;
1310 else
hui su45b64752017-07-12 16:54:35 -07001311#endif // CONFIG_CHROMA_2X2
Luc Trudeaud6d9eee2017-07-12 12:36:50 -04001312 return intra_mode_to_tx_type_context[get_uv_mode(mbmi->uv_mode)];
Timothy B. Terriberryfe67ed62017-04-26 16:53:47 -07001313#else // CONFIG_CB4X4
Yaowu Xuc27fc142016-08-22 16:08:15 -07001314 // Sub8x8-Inter/Intra OR UV-Intra
hui su45b64752017-07-12 16:54:35 -07001315 if (is_inter_block(mbmi)) { // Sub8x8-Inter
Yaowu Xuc27fc142016-08-22 16:08:15 -07001316 return DCT_DCT;
hui su45b64752017-07-12 16:54:35 -07001317 } else { // Sub8x8 Intra OR UV-Intra
1318 const int block_raster_idx =
1319 av1_block_index_to_raster_order(tx_size, block);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001320 return intra_mode_to_tx_type_context[plane_type == PLANE_TYPE_Y
Angie Chiang752ccce2017-04-09 13:41:13 -07001321 ? get_y_mode(mi, block_raster_idx)
Luc Trudeaud6d9eee2017-07-12 12:36:50 -04001322 : get_uv_mode(mbmi->uv_mode)];
hui su45b64752017-07-12 16:54:35 -07001323 }
Thomas Daedeb7e72f32017-04-26 13:40:31 -07001324#endif // CONFIG_CB4X4
Yaowu Xuc27fc142016-08-22 16:08:15 -07001325#else // CONFIG_EXT_TX
Angie Chiang752ccce2017-04-09 13:41:13 -07001326 (void)block;
Sarah Parker53f93db2017-07-11 17:20:04 -07001327#if CONFIG_MRC_TX
1328 if (mbmi->tx_type == MRC_DCT) {
1329 if (plane_type == PLANE_TYPE_Y && !xd->lossless[mbmi->segment_id]) {
1330 assert(tx_size == TX_32X32);
1331 return mbmi->tx_type;
1332 }
1333 return DCT_DCT;
1334 }
1335#endif // CONFIG_MRC_TX
Yaowu Xuc27fc142016-08-22 16:08:15 -07001336 if (plane_type != PLANE_TYPE_Y || xd->lossless[mbmi->segment_id] ||
1337 txsize_sqr_map[tx_size] >= TX_32X32)
1338 return DCT_DCT;
1339 return mbmi->tx_type;
1340#endif // CONFIG_EXT_TX
1341}
1342
Yaowu Xuf883b422016-08-30 14:01:10 -07001343void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001344
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001345static INLINE int tx_size_to_depth(TX_SIZE tx_size) {
Timothy B. Terriberryfe0fb1d2017-05-18 12:15:16 -07001346 return (int)(tx_size - TX_SIZE_LUMA_MIN);
Jingning Han4e1737a2016-10-25 16:05:02 -07001347}
1348
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001349static INLINE TX_SIZE depth_to_tx_size(int depth) {
Timothy B. Terriberryfe0fb1d2017-05-18 12:15:16 -07001350 return (TX_SIZE)(depth + TX_SIZE_LUMA_MIN);
Jingning Han4e1737a2016-10-25 16:05:02 -07001351}
1352
hui su0c6244b2017-07-12 17:11:43 -07001353static INLINE TX_SIZE av1_get_uv_tx_size(const MB_MODE_INFO *mbmi,
1354 const struct macroblockd_plane *pd) {
Timothy B. Terriberryfe67ed62017-04-26 16:53:47 -07001355#if CONFIG_CHROMA_2X2
Jingning Han93531242016-12-20 11:54:36 -08001356 assert(mbmi->tx_size > TX_2X2);
hui su0c6244b2017-07-12 17:11:43 -07001357#endif // CONFIG_CHROMA_2X2
Jingning Han93531242016-12-20 11:54:36 -08001358
Yaowu Xuc27fc142016-08-22 16:08:15 -07001359#if CONFIG_SUPERTX
1360 if (supertx_enabled(mbmi))
1361 return uvsupertx_size_lookup[txsize_sqr_map[mbmi->tx_size]]
1362 [pd->subsampling_x][pd->subsampling_y];
1363#endif // CONFIG_SUPERTX
Jingning Hancabd9892016-12-01 12:28:42 -08001364
hui su0c6244b2017-07-12 17:11:43 -07001365 const TX_SIZE uv_txsize =
1366 uv_txsize_lookup[mbmi->sb_type][mbmi->tx_size][pd->subsampling_x]
1367 [pd->subsampling_y];
Debargha Mukherjee2f123402016-08-30 17:43:38 -07001368 assert(uv_txsize != TX_INVALID);
1369 return uv_txsize;
Yaowu Xuc27fc142016-08-22 16:08:15 -07001370}
1371
hui su0c6244b2017-07-12 17:11:43 -07001372static INLINE TX_SIZE av1_get_tx_size(int plane, const MACROBLOCKD *xd) {
Angie Chiang80b82262017-02-24 11:39:47 -08001373 const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
hui su0c6244b2017-07-12 17:11:43 -07001374 if (plane == 0) return mbmi->tx_size;
Angie Chiang80b82262017-02-24 11:39:47 -08001375 const MACROBLOCKD_PLANE *pd = &xd->plane[plane];
hui su0c6244b2017-07-12 17:11:43 -07001376 return av1_get_uv_tx_size(mbmi, pd);
Angie Chiang80b82262017-02-24 11:39:47 -08001377}
1378
Yaowu Xuc27fc142016-08-22 16:08:15 -07001379static INLINE BLOCK_SIZE
1380get_plane_block_size(BLOCK_SIZE bsize, const struct macroblockd_plane *pd) {
1381 return ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y];
1382}
1383
Timothy B. Terriberrya2d5cde2017-05-10 18:33:50 -07001384void av1_reset_skip_context(MACROBLOCKD *xd, int mi_row, int mi_col,
1385 BLOCK_SIZE bsize);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001386
1387typedef void (*foreach_transformed_block_visitor)(int plane, int block,
1388 int blk_row, int blk_col,
1389 BLOCK_SIZE plane_bsize,
1390 TX_SIZE tx_size, void *arg);
1391
Yaowu Xuf883b422016-08-30 14:01:10 -07001392void av1_foreach_transformed_block_in_plane(
Yaowu Xuc27fc142016-08-22 16:08:15 -07001393 const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane,
1394 foreach_transformed_block_visitor visit, void *arg);
1395
Angie Chiang0397eda2017-03-15 16:57:14 -07001396#if CONFIG_LV_MAP
1397void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
Jingning Han94652b82017-04-04 09:45:02 -07001398 BLOCK_SIZE bsize, int mi_row, int mi_col,
Angie Chiang0397eda2017-03-15 16:57:14 -07001399 foreach_transformed_block_visitor visit,
1400 void *arg);
1401#endif
1402
iole moccagattaf25a4cf2016-11-11 23:57:57 -08001403#if CONFIG_COEF_INTERLEAVE
1404static INLINE int get_max_4x4_size(int num_4x4, int mb_to_edge,
1405 int subsampling) {
1406 return num_4x4 + (mb_to_edge >= 0 ? 0 : mb_to_edge >> (5 + subsampling));
1407}
1408
1409void av1_foreach_transformed_block_interleave(
1410 const MACROBLOCKD *const xd, BLOCK_SIZE bsize,
1411 foreach_transformed_block_visitor visit, void *arg);
1412#endif
1413
Yaowu Xuf883b422016-08-30 14:01:10 -07001414void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
Jingning Haneee43152016-12-05 09:58:45 -08001415 int plane, TX_SIZE tx_size, int has_eob, int aoff,
1416 int loff);
Yaowu Xuc27fc142016-08-22 16:08:15 -07001417
1418#if CONFIG_EXT_INTER
1419static INLINE int is_interintra_allowed_bsize(const BLOCK_SIZE bsize) {
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001420#if CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001421 // TODO(debargha): Should this be bsize < BLOCK_LARGEST?
1422 return (bsize >= BLOCK_8X8) && (bsize < BLOCK_64X64);
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001423#else
1424 (void)bsize;
1425 return 0;
1426#endif // CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001427}
1428
1429static INLINE int is_interintra_allowed_mode(const PREDICTION_MODE mode) {
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001430#if CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001431 return (mode >= NEARESTMV) && (mode <= NEWMV);
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001432#else
1433 (void)mode;
1434 return 0;
1435#endif // CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001436}
1437
1438static INLINE int is_interintra_allowed_ref(const MV_REFERENCE_FRAME rf[2]) {
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001439#if CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001440 return (rf[0] > INTRA_FRAME) && (rf[1] <= INTRA_FRAME);
Debargha Mukherjee37f6fe62017-02-10 21:44:13 -08001441#else
1442 (void)rf;
1443 return 0;
1444#endif // CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -07001445}
1446
1447static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) {
1448 return is_interintra_allowed_bsize(mbmi->sb_type) &&
1449 is_interintra_allowed_mode(mbmi->mode) &&
1450 is_interintra_allowed_ref(mbmi->ref_frame);
1451}
1452
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001453static INLINE int is_interintra_allowed_bsize_group(int group) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001454 int i;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +01001455 for (i = 0; i < BLOCK_SIZES_ALL; i++) {
Urvang Joshicb586f32016-09-20 11:36:33 -07001456 if (size_group_lookup[i] == group &&
1457 is_interintra_allowed_bsize((BLOCK_SIZE)i)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001458 return 1;
Urvang Joshicb586f32016-09-20 11:36:33 -07001459 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001460 }
1461 return 0;
1462}
1463
1464static INLINE int is_interintra_pred(const MB_MODE_INFO *mbmi) {
1465 return (mbmi->ref_frame[1] == INTRA_FRAME) && is_interintra_allowed(mbmi);
1466}
1467#endif // CONFIG_EXT_INTER
1468
Sarah Parker106b3cb2017-04-21 12:13:37 -07001469#if CONFIG_VAR_TX
1470static INLINE int get_vartx_max_txsize(const MB_MODE_INFO *const mbmi,
1471 BLOCK_SIZE bsize) {
1472#if CONFIG_CB4X4
1473 (void)mbmi;
1474 return max_txsize_rect_lookup[bsize];
1475#endif // CONFIG_C4X4
1476 return mbmi->sb_type < BLOCK_8X8 ? max_txsize_rect_lookup[mbmi->sb_type]
1477 : max_txsize_rect_lookup[bsize];
1478}
1479#endif // CONFIG_VAR_TX
1480
Yue Chencb60b182016-10-13 15:18:22 -07001481#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
1482static INLINE int is_motion_variation_allowed_bsize(BLOCK_SIZE bsize) {
1483 return (bsize >= BLOCK_8X8);
1484}
1485
Yue Chen8636da62017-04-03 01:23:44 -07001486static INLINE int is_motion_variation_allowed_compound(
1487 const MB_MODE_INFO *mbmi) {
Zoe Liu85b66462017-04-20 14:28:19 -07001488#if CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
1489 if (!has_second_ref(mbmi) && !is_inter_singleref_comp_mode(mbmi->mode))
1490#else
Yue Chen8636da62017-04-03 01:23:44 -07001491 if (!has_second_ref(mbmi))
Zoe Liu85b66462017-04-20 14:28:19 -07001492#endif // CONFIG_EXT_INTER && CONFIG_COMPOUND_SINGLEREF
Yue Chen8636da62017-04-03 01:23:44 -07001493 return 1;
1494 else
1495 return 0;
1496}
1497
Yue Chen5329a2b2017-02-28 17:33:00 +08001498#if CONFIG_MOTION_VAR
Yue Chen1bd42be2017-03-15 18:07:04 -07001499// input: log2 of length, 0(4), 1(8), ...
1500static const int max_neighbor_obmc[6] = { 0, 1, 2, 3, 4, 4 };
1501
Yue Chen5329a2b2017-02-28 17:33:00 +08001502static INLINE int check_num_overlappable_neighbors(const MB_MODE_INFO *mbmi) {
Yue Chen1bd42be2017-03-15 18:07:04 -07001503 return !(mbmi->overlappable_neighbors[0] == 0 &&
1504 mbmi->overlappable_neighbors[1] == 0);
Yue Chen5329a2b2017-02-28 17:33:00 +08001505}
1506#endif
1507
Sarah Parker19234cc2017-03-10 16:43:25 -08001508static INLINE MOTION_MODE motion_mode_allowed(
Sarah Parker0eea89f2017-07-11 11:56:36 -07001509#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -08001510 int block, const WarpedMotionParams *gm_params,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001511#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001512#if CONFIG_WARPED_MOTION
1513 const MACROBLOCKD *xd,
1514#endif
Sarah Parker19234cc2017-03-10 16:43:25 -08001515 const MODE_INFO *mi) {
1516 const MB_MODE_INFO *mbmi = &mi->mbmi;
Sarah Parker0eea89f2017-07-11 11:56:36 -07001517#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -08001518 const TransformationType gm_type = gm_params[mbmi->ref_frame[0]].wmtype;
1519 if (is_global_mv_block(mi, block, gm_type)) return SIMPLE_TRANSLATION;
Sarah Parker0eea89f2017-07-11 11:56:36 -07001520#endif // CONFIG_GLOBAL_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07001521#if CONFIG_EXT_INTER
Yue Chen69f18e12016-09-08 14:48:15 -07001522 if (is_motion_variation_allowed_bsize(mbmi->sb_type) &&
Yue Chen8636da62017-04-03 01:23:44 -07001523 is_inter_mode(mbmi->mode) && mbmi->ref_frame[1] != INTRA_FRAME &&
1524 is_motion_variation_allowed_compound(mbmi)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001525#else
Yue Chen69f18e12016-09-08 14:48:15 -07001526 if (is_motion_variation_allowed_bsize(mbmi->sb_type) &&
Yue Chen8636da62017-04-03 01:23:44 -07001527 is_inter_mode(mbmi->mode) && is_motion_variation_allowed_compound(mbmi)) {
Yaowu Xuc27fc142016-08-22 16:08:15 -07001528#endif // CONFIG_EXT_INTER
Yue Chen5329a2b2017-02-28 17:33:00 +08001529#if CONFIG_MOTION_VAR
1530 if (!check_num_overlappable_neighbors(mbmi)) return SIMPLE_TRANSLATION;
1531#endif
Yue Chen69f18e12016-09-08 14:48:15 -07001532#if CONFIG_WARPED_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001533 if (!has_second_ref(mbmi) && mbmi->num_proj_ref[0] >= 1 &&
1534 !av1_is_scaled(&(xd->block_refs[0]->sf)))
Yue Chen69f18e12016-09-08 14:48:15 -07001535 return WARPED_CAUSAL;
1536 else
1537#endif // CONFIG_WARPED_MOTION
1538#if CONFIG_MOTION_VAR
1539 return OBMC_CAUSAL;
1540#else
1541 return SIMPLE_TRANSLATION;
1542#endif // CONFIG_MOTION_VAR
1543 } else {
1544 return SIMPLE_TRANSLATION;
1545 }
Yaowu Xuc27fc142016-08-22 16:08:15 -07001546}
1547
Wei-Ting Lin85a8f702017-06-22 13:55:15 -07001548#if CONFIG_NCOBMC_ADAPT_WEIGHT && CONFIG_MOTION_VAR
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001549static INLINE NCOBMC_MODE ncobmc_mode_allowed_bsize(BLOCK_SIZE bsize) {
1550 if (bsize < BLOCK_8X8 || bsize > BLOCK_64X64)
Wei-Ting Lin85a8f702017-06-22 13:55:15 -07001551 return NO_OVERLAP;
1552 else
1553 return (NCOBMC_MODE)(MAX_NCOBMC_MODES - 1);
1554}
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001555
1556static INLINE MOTION_MODE
1557motion_mode_allowed_wrapper(int for_mv_search,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001558#if CONFIG_GLOBAL_MOTION
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001559 int block, const WarpedMotionParams *gm_params,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001560#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001561#if CONFIG_WARPED_MOTION
1562 const MACROBLOCKD *xd,
1563#endif
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001564 const MODE_INFO *mi) {
1565 const MB_MODE_INFO *mbmi = &mi->mbmi;
1566 MOTION_MODE motion_mode_for_mv_search = motion_mode_allowed(
Sarah Parker0eea89f2017-07-11 11:56:36 -07001567#if CONFIG_GLOBAL_MOTION
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001568 int block, const WarpedMotionParams *gm_params,
1569#endif
Yue Chen52c51732017-07-11 15:08:30 -07001570#if CONFIG_WARPED_MOTION
1571 xd,
1572#endif
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001573 mi);
1574 int ncobmc_mode_allowed =
1575 ncobmc_mode_allowed_bsize(mbmi->sb_type) && is_inter_mode(mbmi->mode);
1576 if (for_mv_search)
1577 return motion_mode_for_mv_search;
1578 else
1579 return ncobmc_mode_allowed ? NCOBMC_ADAPT_WEIGHT
1580 : motion_mode_for_mv_search;
1581}
Wei-Ting Lin85a8f702017-06-22 13:55:15 -07001582#endif
1583
Sarah Parker19234cc2017-03-10 16:43:25 -08001584static INLINE void assert_motion_mode_valid(MOTION_MODE mode,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001585#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -08001586 int block,
1587 const WarpedMotionParams *gm_params,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001588#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001589#if CONFIG_WARPED_MOTION
1590 const MACROBLOCKD *xd,
1591#endif
Sarah Parker19234cc2017-03-10 16:43:25 -08001592 const MODE_INFO *mi) {
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001593#if CONFIG_NCOBMC_ADAPT_WEIGHT
1594 const MOTION_MODE last_motion_mode_allowed =
1595 motion_mode_allowed_wrapper(0,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001596#if CONFIG_GLOBAL_MOTION
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001597 block, gm_params,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001598#endif // CONFIG_GLOBAL_MOTION
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001599 mi);
1600#else
Sarah Parker19234cc2017-03-10 16:43:25 -08001601 const MOTION_MODE last_motion_mode_allowed = motion_mode_allowed(
Sarah Parker0eea89f2017-07-11 11:56:36 -07001602#if CONFIG_GLOBAL_MOTION
Sarah Parker19234cc2017-03-10 16:43:25 -08001603 block, gm_params,
Sarah Parker0eea89f2017-07-11 11:56:36 -07001604#endif // CONFIG_GLOBAL_MOTION
Yue Chen52c51732017-07-11 15:08:30 -07001605#if CONFIG_WARPED_MOTION
1606 xd,
1607#endif
Sarah Parker19234cc2017-03-10 16:43:25 -08001608 mi);
Wei-Ting Lind0f7ba12017-06-30 14:59:57 -07001609#endif
Sarah Parker19234cc2017-03-10 16:43:25 -08001610 // Check that the input mode is not illegal
1611 if (last_motion_mode_allowed < mode)
1612 assert(0 && "Illegal motion mode selected");
1613}
1614
Yue Chencb60b182016-10-13 15:18:22 -07001615#if CONFIG_MOTION_VAR
Yaowu Xuc27fc142016-08-22 16:08:15 -07001616static INLINE int is_neighbor_overlappable(const MB_MODE_INFO *mbmi) {
1617 return (is_inter_block(mbmi));
1618}
Yue Chencb60b182016-10-13 15:18:22 -07001619#endif // CONFIG_MOTION_VAR
1620#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -07001621
Urvang Joshi56ba91b2017-01-10 13:22:09 -08001622// Returns sub-sampled dimensions of the given block.
1623// The output values for 'rows_within_bounds' and 'cols_within_bounds' will
1624// differ from 'height' and 'width' when part of the block is outside the right
1625// and/or bottom image boundary.
1626static INLINE void av1_get_block_dimensions(BLOCK_SIZE bsize, int plane,
1627 const MACROBLOCKD *xd, int *width,
1628 int *height,
1629 int *rows_within_bounds,
1630 int *cols_within_bounds) {
1631 const int block_height = block_size_high[bsize];
1632 const int block_width = block_size_wide[bsize];
1633 const int block_rows = (xd->mb_to_bottom_edge >= 0)
1634 ? block_height
1635 : (xd->mb_to_bottom_edge >> 3) + block_height;
1636 const int block_cols = (xd->mb_to_right_edge >= 0)
1637 ? block_width
1638 : (xd->mb_to_right_edge >> 3) + block_width;
1639 const struct macroblockd_plane *const pd = &xd->plane[plane];
1640 assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_x == 0));
1641 assert(IMPLIES(plane == PLANE_TYPE_Y, pd->subsampling_y == 0));
1642 assert(block_width >= block_cols);
1643 assert(block_height >= block_rows);
1644 if (width) *width = block_width >> pd->subsampling_x;
1645 if (height) *height = block_height >> pd->subsampling_y;
1646 if (rows_within_bounds) *rows_within_bounds = block_rows >> pd->subsampling_y;
1647 if (cols_within_bounds) *cols_within_bounds = block_cols >> pd->subsampling_x;
1648}
1649
Yue Chen19e7aa82016-11-30 14:05:39 -08001650#if CONFIG_GLOBAL_MOTION
1651static INLINE int is_nontrans_global_motion(const MACROBLOCKD *xd) {
1652 const MODE_INFO *mi = xd->mi[0];
1653 const MB_MODE_INFO *const mbmi = &mi->mbmi;
1654 int ref;
1655#if CONFIG_CB4X4
1656 const int unify_bsize = 1;
1657#else
1658 const int unify_bsize = 0;
1659#endif
1660
1661 // First check if all modes are ZEROMV
1662 if (mbmi->sb_type >= BLOCK_8X8 || unify_bsize) {
1663#if CONFIG_EXT_INTER
1664 if (mbmi->mode != ZEROMV && mbmi->mode != ZERO_ZEROMV) return 0;
1665#else
1666 if (mbmi->mode != ZEROMV) return 0;
1667#endif // CONFIG_EXT_INTER
1668 } else {
1669#if CONFIG_EXT_INTER
David Barkera0c16382017-07-07 17:01:30 +01001670 if ((mi->bmi[0].as_mode != ZEROMV && mi->bmi[0].as_mode != ZERO_ZEROMV) ||
1671 (mi->bmi[1].as_mode != ZEROMV && mi->bmi[1].as_mode != ZERO_ZEROMV) ||
1672 (mi->bmi[2].as_mode != ZEROMV && mi->bmi[2].as_mode != ZERO_ZEROMV) ||
1673 (mi->bmi[3].as_mode != ZEROMV && mi->bmi[3].as_mode != ZERO_ZEROMV))
Yue Chen19e7aa82016-11-30 14:05:39 -08001674 return 0;
1675#else
1676 if (mi->bmi[0].as_mode != ZEROMV || mi->bmi[1].as_mode != ZEROMV ||
1677 mi->bmi[2].as_mode != ZEROMV || mi->bmi[3].as_mode != ZEROMV)
1678 return 0;
1679#endif // CONFIG_EXT_INTER
1680 }
Jingning Han3ca0e672017-04-14 19:48:05 -07001681
1682#if !GLOBAL_SUB8X8_USED
1683 if (mbmi->sb_type < BLOCK_8X8) return 0;
1684#endif
1685
Yue Chen19e7aa82016-11-30 14:05:39 -08001686 // Now check if all global motion is non translational
1687 for (ref = 0; ref < 1 + has_second_ref(mbmi); ++ref) {
1688 if (xd->global_motion[mbmi->ref_frame[ref]].wmtype <= TRANSLATION) return 0;
1689 }
1690 return 1;
1691}
1692#endif // CONFIG_GLOBAL_MOTION
1693
Yaowu Xu4ff59b52017-04-24 12:41:56 -07001694static INLINE PLANE_TYPE get_plane_type(int plane) {
Luc Trudeau005feb62017-02-22 13:34:01 -05001695 return (plane == 0) ? PLANE_TYPE_Y : PLANE_TYPE_UV;
1696}
1697
Yaowu Xuc27fc142016-08-22 16:08:15 -07001698#ifdef __cplusplus
1699} // extern "C"
1700#endif
1701
Yaowu Xuf883b422016-08-30 14:01:10 -07001702#endif // AV1_COMMON_BLOCKD_H_