OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "vp9/encoder/vp9_variance.h" | 29 #include "vp9/encoder/vp9_variance.h" |
30 #include "vp9/encoder/vp9_mcomp.h" | 30 #include "vp9/encoder/vp9_mcomp.h" |
31 #include "vp9/encoder/vp9_rdopt.h" | 31 #include "vp9/encoder/vp9_rdopt.h" |
32 #include "vp9/encoder/vp9_ratectrl.h" | 32 #include "vp9/encoder/vp9_ratectrl.h" |
33 #include "vpx_mem/vpx_mem.h" | 33 #include "vpx_mem/vpx_mem.h" |
34 #include "vp9/common/vp9_systemdependent.h" | 34 #include "vp9/common/vp9_systemdependent.h" |
35 #include "vp9/encoder/vp9_encodemv.h" | 35 #include "vp9/encoder/vp9_encodemv.h" |
36 #include "vp9/common/vp9_seg_common.h" | 36 #include "vp9/common/vp9_seg_common.h" |
37 #include "vp9/common/vp9_pred_common.h" | 37 #include "vp9/common/vp9_pred_common.h" |
38 #include "vp9/common/vp9_entropy.h" | 38 #include "vp9/common/vp9_entropy.h" |
39 #include "vp9_rtcd.h" | 39 #include "./vp9_rtcd.h" |
40 #include "vp9/common/vp9_mvref_common.h" | 40 #include "vp9/common/vp9_mvref_common.h" |
41 #include "vp9/common/vp9_common.h" | 41 #include "vp9/common/vp9_common.h" |
42 | 42 |
43 #define INVALID_MV 0x80008000 | 43 #define INVALID_MV 0x80008000 |
44 | 44 |
45 /* Factor to weigh the rate for switchable interp filters */ | 45 /* Factor to weigh the rate for switchable interp filters */ |
46 #define SWITCHABLE_INTERP_RATE_FACTOR 1 | 46 #define SWITCHABLE_INTERP_RATE_FACTOR 1 |
47 | 47 |
48 DECLARE_ALIGNED(16, extern const uint8_t, | 48 #define LAST_FRAME_MODE_MASK 0xFFEDCD60 |
49 vp9_pt_energy_class[MAX_ENTROPY_TOKENS]); | 49 #define GOLDEN_FRAME_MODE_MASK 0xFFDA3BB0 |
| 50 #define ALT_REF_MODE_MASK 0xFFC648D0 |
50 | 51 |
51 #define LAST_FRAME_MODE_MASK 0xFFDADCD60 | 52 #define MIN_EARLY_TERM_INDEX 3 |
52 #define GOLDEN_FRAME_MODE_MASK 0xFFB5A3BB0 | |
53 #define ALT_REF_MODE_MASK 0xFF8C648D0 | |
54 | 53 |
55 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { | 54 const MODE_DEFINITION vp9_mode_order[MAX_MODES] = { |
56 {RD_NEARESTMV, LAST_FRAME, NONE}, | 55 {NEARESTMV, LAST_FRAME, NONE}, |
57 {RD_NEARESTMV, ALTREF_FRAME, NONE}, | 56 {NEARESTMV, ALTREF_FRAME, NONE}, |
58 {RD_NEARESTMV, GOLDEN_FRAME, NONE}, | 57 {NEARESTMV, GOLDEN_FRAME, NONE}, |
59 | 58 |
60 {RD_DC_PRED, INTRA_FRAME, NONE}, | 59 {DC_PRED, INTRA_FRAME, NONE}, |
61 | 60 |
62 {RD_NEWMV, LAST_FRAME, NONE}, | 61 {NEWMV, LAST_FRAME, NONE}, |
63 {RD_NEWMV, ALTREF_FRAME, NONE}, | 62 {NEWMV, ALTREF_FRAME, NONE}, |
64 {RD_NEWMV, GOLDEN_FRAME, NONE}, | 63 {NEWMV, GOLDEN_FRAME, NONE}, |
65 | 64 |
66 {RD_NEARMV, LAST_FRAME, NONE}, | 65 {NEARMV, LAST_FRAME, NONE}, |
67 {RD_NEARMV, ALTREF_FRAME, NONE}, | 66 {NEARMV, ALTREF_FRAME, NONE}, |
68 {RD_NEARESTMV, LAST_FRAME, ALTREF_FRAME}, | 67 {NEARESTMV, LAST_FRAME, ALTREF_FRAME}, |
69 {RD_NEARESTMV, GOLDEN_FRAME, ALTREF_FRAME}, | 68 {NEARESTMV, GOLDEN_FRAME, ALTREF_FRAME}, |
70 | 69 |
71 {RD_TM_PRED, INTRA_FRAME, NONE}, | 70 {TM_PRED, INTRA_FRAME, NONE}, |
72 | 71 |
73 {RD_NEARMV, LAST_FRAME, ALTREF_FRAME}, | 72 {NEARMV, LAST_FRAME, ALTREF_FRAME}, |
74 {RD_NEWMV, LAST_FRAME, ALTREF_FRAME}, | 73 {NEWMV, LAST_FRAME, ALTREF_FRAME}, |
75 {RD_NEARMV, GOLDEN_FRAME, NONE}, | 74 {NEARMV, GOLDEN_FRAME, NONE}, |
76 {RD_NEARMV, GOLDEN_FRAME, ALTREF_FRAME}, | 75 {NEARMV, GOLDEN_FRAME, ALTREF_FRAME}, |
77 {RD_NEWMV, GOLDEN_FRAME, ALTREF_FRAME}, | 76 {NEWMV, GOLDEN_FRAME, ALTREF_FRAME}, |
78 | 77 |
79 {RD_SPLITMV, LAST_FRAME, NONE}, | 78 {ZEROMV, LAST_FRAME, NONE}, |
80 {RD_SPLITMV, GOLDEN_FRAME, NONE}, | 79 {ZEROMV, GOLDEN_FRAME, NONE}, |
81 {RD_SPLITMV, ALTREF_FRAME, NONE}, | 80 {ZEROMV, ALTREF_FRAME, NONE}, |
82 {RD_SPLITMV, LAST_FRAME, ALTREF_FRAME}, | 81 {ZEROMV, LAST_FRAME, ALTREF_FRAME}, |
83 {RD_SPLITMV, GOLDEN_FRAME, ALTREF_FRAME}, | 82 {ZEROMV, GOLDEN_FRAME, ALTREF_FRAME}, |
84 | 83 |
85 {RD_ZEROMV, LAST_FRAME, NONE}, | 84 {H_PRED, INTRA_FRAME, NONE}, |
86 {RD_ZEROMV, GOLDEN_FRAME, NONE}, | 85 {V_PRED, INTRA_FRAME, NONE}, |
87 {RD_ZEROMV, ALTREF_FRAME, NONE}, | 86 {D135_PRED, INTRA_FRAME, NONE}, |
88 {RD_ZEROMV, LAST_FRAME, ALTREF_FRAME}, | 87 {D207_PRED, INTRA_FRAME, NONE}, |
89 {RD_ZEROMV, GOLDEN_FRAME, ALTREF_FRAME}, | 88 {D153_PRED, INTRA_FRAME, NONE}, |
| 89 {D63_PRED, INTRA_FRAME, NONE}, |
| 90 {D117_PRED, INTRA_FRAME, NONE}, |
| 91 {D45_PRED, INTRA_FRAME, NONE}, |
| 92 }; |
90 | 93 |
91 {RD_I4X4_PRED, INTRA_FRAME, NONE}, | 94 const REF_DEFINITION vp9_ref_order[MAX_REFS] = { |
92 {RD_H_PRED, INTRA_FRAME, NONE}, | 95 {LAST_FRAME, NONE}, |
93 {RD_V_PRED, INTRA_FRAME, NONE}, | 96 {GOLDEN_FRAME, NONE}, |
94 {RD_D135_PRED, INTRA_FRAME, NONE}, | 97 {ALTREF_FRAME, NONE}, |
95 {RD_D207_PRED, INTRA_FRAME, NONE}, | 98 {LAST_FRAME, ALTREF_FRAME}, |
96 {RD_D153_PRED, INTRA_FRAME, NONE}, | 99 {GOLDEN_FRAME, ALTREF_FRAME}, |
97 {RD_D63_PRED, INTRA_FRAME, NONE}, | 100 {INTRA_FRAME, NONE}, |
98 {RD_D117_PRED, INTRA_FRAME, NONE}, | |
99 {RD_D45_PRED, INTRA_FRAME, NONE}, | |
100 }; | 101 }; |
101 | 102 |
102 // The baseline rd thresholds for breaking out of the rd loop for | 103 // The baseline rd thresholds for breaking out of the rd loop for |
103 // certain modes are assumed to be based on 8x8 blocks. | 104 // certain modes are assumed to be based on 8x8 blocks. |
104 // This table is used to correct for blocks size. | 105 // This table is used to correct for blocks size. |
105 // The factors here are << 2 (2 = x0.5, 32 = x8 etc). | 106 // The factors here are << 2 (2 = x0.5, 32 = x8 etc). |
106 static int rd_thresh_block_size_factor[BLOCK_SIZES] = | 107 static int rd_thresh_block_size_factor[BLOCK_SIZES] = |
107 {2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32}; | 108 {2, 3, 3, 4, 6, 6, 8, 12, 12, 16, 24, 24, 32}; |
108 | 109 |
109 #define MAX_RD_THRESH_FACT 64 | 110 #define RD_THRESH_MAX_FACT 64 |
110 #define RD_THRESH_INC 1 | 111 #define RD_THRESH_INC 1 |
| 112 #define RD_THRESH_POW 1.25 |
| 113 #define RD_MULT_EPB_RATIO 64 |
| 114 |
| 115 #define MV_COST_WEIGHT 108 |
| 116 #define MV_COST_WEIGHT_SUB 120 |
111 | 117 |
112 static void fill_token_costs(vp9_coeff_cost *c, | 118 static void fill_token_costs(vp9_coeff_cost *c, |
113 vp9_coeff_probs_model (*p)[BLOCK_TYPES]) { | 119 vp9_coeff_probs_model (*p)[BLOCK_TYPES]) { |
114 int i, j, k, l; | 120 int i, j, k, l; |
115 TX_SIZE t; | 121 TX_SIZE t; |
116 for (t = TX_4X4; t <= TX_32X32; t++) | 122 for (t = TX_4X4; t <= TX_32X32; t++) |
117 for (i = 0; i < BLOCK_TYPES; i++) | 123 for (i = 0; i < BLOCK_TYPES; i++) |
118 for (j = 0; j < REF_TYPES; j++) | 124 for (j = 0; j < REF_TYPES; j++) |
119 for (k = 0; k < COEF_BANDS; k++) | 125 for (k = 0; k < COEF_BANDS; k++) |
120 for (l = 0; l < PREV_COEF_CONTEXTS; l++) { | 126 for (l = 0; l < PREV_COEF_CONTEXTS; l++) { |
(...skipping 27 matching lines...) Expand all Loading... |
148 // Initialize the sad lut tables using a formulaic calculation for now | 154 // Initialize the sad lut tables using a formulaic calculation for now |
149 // This is to make it easier to resolve the impact of experimental changes | 155 // This is to make it easier to resolve the impact of experimental changes |
150 // to the quantizer tables. | 156 // to the quantizer tables. |
151 for (i = 0; i < QINDEX_RANGE; i++) { | 157 for (i = 0; i < QINDEX_RANGE; i++) { |
152 sad_per_bit16lut[i] = | 158 sad_per_bit16lut[i] = |
153 (int)((0.0418 * vp9_convert_qindex_to_q(i)) + 2.4107); | 159 (int)((0.0418 * vp9_convert_qindex_to_q(i)) + 2.4107); |
154 sad_per_bit4lut[i] = (int)(0.063 * vp9_convert_qindex_to_q(i) + 2.742); | 160 sad_per_bit4lut[i] = (int)(0.063 * vp9_convert_qindex_to_q(i) + 2.742); |
155 } | 161 } |
156 } | 162 } |
157 | 163 |
158 static int compute_rd_mult(int qindex) { | 164 int vp9_compute_rd_mult(VP9_COMP *cpi, int qindex) { |
159 const int q = vp9_dc_quant(qindex, 0); | 165 const int q = vp9_dc_quant(qindex, 0); |
160 return (11 * q * q) >> 2; | 166 // TODO(debargha): Adjust the function below |
| 167 int rdmult = 88 * q * q / 25; |
| 168 if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { |
| 169 if (cpi->twopass.next_iiratio > 31) |
| 170 rdmult += (rdmult * rd_iifactor[31]) >> 4; |
| 171 else |
| 172 rdmult += (rdmult * rd_iifactor[cpi->twopass.next_iiratio]) >> 4; |
| 173 } |
| 174 return rdmult; |
161 } | 175 } |
162 | 176 |
163 static MB_PREDICTION_MODE rd_mode_to_mode(RD_PREDICTION_MODE rd_mode) { | 177 static int compute_rd_thresh_factor(int qindex) { |
164 if (rd_mode == RD_SPLITMV || rd_mode == RD_I4X4_PRED) { | 178 int q; |
165 assert(!"Invalid rd_mode"); | 179 // TODO(debargha): Adjust the function below |
166 return MB_MODE_COUNT; | 180 q = (int)(pow(vp9_dc_quant(qindex, 0) / 4.0, RD_THRESH_POW) * 5.12); |
167 } | 181 if (q < 8) |
168 assert((int)rd_mode < (int)MB_MODE_COUNT); | 182 q = 8; |
169 return (MB_PREDICTION_MODE)rd_mode; | 183 return q; |
170 } | 184 } |
171 | 185 |
172 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) { | 186 void vp9_initialize_me_consts(VP9_COMP *cpi, int qindex) { |
173 cpi->mb.sadperbit16 = sad_per_bit16lut[qindex]; | 187 cpi->mb.sadperbit16 = sad_per_bit16lut[qindex]; |
174 cpi->mb.sadperbit4 = sad_per_bit4lut[qindex]; | 188 cpi->mb.sadperbit4 = sad_per_bit4lut[qindex]; |
175 } | 189 } |
176 | 190 |
| 191 static void set_block_thresholds(VP9_COMP *cpi) { |
| 192 int i, bsize, segment_id; |
| 193 VP9_COMMON *cm = &cpi->common; |
177 | 194 |
178 void vp9_initialize_rd_consts(VP9_COMP *cpi, int qindex) { | 195 for (segment_id = 0; segment_id < MAX_SEGMENTS; ++segment_id) { |
179 int q, i, bsize; | 196 int q; |
| 197 int segment_qindex = vp9_get_qindex(&cm->seg, segment_id, cm->base_qindex); |
| 198 segment_qindex = clamp(segment_qindex + cm->y_dc_delta_q, 0, MAXQ); |
| 199 q = compute_rd_thresh_factor(segment_qindex); |
| 200 |
| 201 for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) { |
| 202 // Threshold here seem unecessarily harsh but fine given actual |
| 203 // range of values used for cpi->sf.thresh_mult[] |
| 204 int thresh_max = INT_MAX / (q * rd_thresh_block_size_factor[bsize]); |
| 205 |
| 206 for (i = 0; i < MAX_MODES; ++i) { |
| 207 if (cpi->sf.thresh_mult[i] < thresh_max) { |
| 208 cpi->rd_threshes[segment_id][bsize][i] = |
| 209 cpi->sf.thresh_mult[i] * q * |
| 210 rd_thresh_block_size_factor[bsize] / 4; |
| 211 } else { |
| 212 cpi->rd_threshes[segment_id][bsize][i] = INT_MAX; |
| 213 } |
| 214 } |
| 215 |
| 216 for (i = 0; i < MAX_REFS; ++i) { |
| 217 if (cpi->sf.thresh_mult_sub8x8[i] < thresh_max) { |
| 218 cpi->rd_thresh_sub8x8[segment_id][bsize][i] = |
| 219 cpi->sf.thresh_mult_sub8x8[i] * q * |
| 220 rd_thresh_block_size_factor[bsize] / 4; |
| 221 } else { |
| 222 cpi->rd_thresh_sub8x8[segment_id][bsize][i] = INT_MAX; |
| 223 } |
| 224 } |
| 225 } |
| 226 } |
| 227 } |
| 228 |
| 229 void vp9_initialize_rd_consts(VP9_COMP *cpi) { |
| 230 VP9_COMMON *cm = &cpi->common; |
| 231 int qindex, i; |
180 | 232 |
181 vp9_clear_system_state(); // __asm emms; | 233 vp9_clear_system_state(); // __asm emms; |
182 | 234 |
183 // Further tests required to see if optimum is different | 235 // Further tests required to see if optimum is different |
184 // for key frames, golden frames and arf frames. | 236 // for key frames, golden frames and arf frames. |
185 // if (cpi->common.refresh_golden_frame || | 237 // if (cpi->common.refresh_golden_frame || |
186 // cpi->common.refresh_alt_ref_frame) | 238 // cpi->common.refresh_alt_ref_frame) |
187 qindex = clamp(qindex, 0, MAXQ); | 239 qindex = clamp(cm->base_qindex + cm->y_dc_delta_q, 0, MAXQ); |
188 | 240 |
189 cpi->RDMULT = compute_rd_mult(qindex); | 241 cpi->RDDIV = RDDIV_BITS; // in bits (to multiply D by 128) |
190 if (cpi->pass == 2 && (cpi->common.frame_type != KEY_FRAME)) { | 242 cpi->RDMULT = vp9_compute_rd_mult(cpi, qindex); |
191 if (cpi->twopass.next_iiratio > 31) | 243 |
192 cpi->RDMULT += (cpi->RDMULT * rd_iifactor[31]) >> 4; | 244 cpi->mb.errorperbit = cpi->RDMULT / RD_MULT_EPB_RATIO; |
193 else | |
194 cpi->RDMULT += | |
195 (cpi->RDMULT * rd_iifactor[cpi->twopass.next_iiratio]) >> 4; | |
196 } | |
197 cpi->mb.errorperbit = cpi->RDMULT >> 6; | |
198 cpi->mb.errorperbit += (cpi->mb.errorperbit == 0); | 245 cpi->mb.errorperbit += (cpi->mb.errorperbit == 0); |
199 | 246 |
200 vp9_set_speed_features(cpi); | 247 vp9_set_speed_features(cpi); |
201 | 248 |
202 q = (int)pow(vp9_dc_quant(qindex, 0) >> 2, 1.25); | 249 set_block_thresholds(cpi); |
203 q <<= 2; | |
204 if (q < 8) | |
205 q = 8; | |
206 | 250 |
207 if (cpi->RDMULT > 1000) { | 251 fill_token_costs(cpi->mb.token_costs, cm->fc.coef_probs); |
208 cpi->RDDIV = 1; | |
209 cpi->RDMULT /= 100; | |
210 | 252 |
211 for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) { | 253 for (i = 0; i < PARTITION_CONTEXTS; i++) |
212 for (i = 0; i < MAX_MODES; ++i) { | |
213 // Threshold here seem unecessarily harsh but fine given actual | |
214 // range of values used for cpi->sf.thresh_mult[] | |
215 int thresh_max = INT_MAX / (q * rd_thresh_block_size_factor[bsize]); | |
216 | |
217 // *4 relates to the scaling of rd_thresh_block_size_factor[] | |
218 if ((int64_t)cpi->sf.thresh_mult[i] < thresh_max) { | |
219 cpi->rd_threshes[bsize][i] = | |
220 cpi->sf.thresh_mult[i] * q * | |
221 rd_thresh_block_size_factor[bsize] / (4 * 100); | |
222 } else { | |
223 cpi->rd_threshes[bsize][i] = INT_MAX; | |
224 } | |
225 } | |
226 } | |
227 } else { | |
228 cpi->RDDIV = 100; | |
229 | |
230 for (bsize = 0; bsize < BLOCK_SIZES; ++bsize) { | |
231 for (i = 0; i < MAX_MODES; i++) { | |
232 // Threshold here seem unecessarily harsh but fine given actual | |
233 // range of values used for cpi->sf.thresh_mult[] | |
234 int thresh_max = INT_MAX / (q * rd_thresh_block_size_factor[bsize]); | |
235 | |
236 if (cpi->sf.thresh_mult[i] < thresh_max) { | |
237 cpi->rd_threshes[bsize][i] = | |
238 cpi->sf.thresh_mult[i] * q * | |
239 rd_thresh_block_size_factor[bsize] / 4; | |
240 } else { | |
241 cpi->rd_threshes[bsize][i] = INT_MAX; | |
242 } | |
243 } | |
244 } | |
245 } | |
246 | |
247 fill_token_costs(cpi->mb.token_costs, cpi->common.fc.coef_probs); | |
248 | |
249 for (i = 0; i < NUM_PARTITION_CONTEXTS; i++) | |
250 vp9_cost_tokens(cpi->mb.partition_cost[i], | 254 vp9_cost_tokens(cpi->mb.partition_cost[i], |
251 cpi->common.fc.partition_prob[cpi->common.frame_type][i], | 255 cm->fc.partition_prob[cm->frame_type][i], |
252 vp9_partition_tree); | 256 vp9_partition_tree); |
253 | 257 |
254 /*rough estimate for costing*/ | 258 /*rough estimate for costing*/ |
255 vp9_init_mode_costs(cpi); | 259 vp9_init_mode_costs(cpi); |
256 | 260 |
257 if (cpi->common.frame_type != KEY_FRAME) { | 261 if (!frame_is_intra_only(cm)) { |
258 vp9_build_nmv_cost_table( | 262 vp9_build_nmv_cost_table( |
259 cpi->mb.nmvjointcost, | 263 cpi->mb.nmvjointcost, |
260 cpi->mb.e_mbd.allow_high_precision_mv ? | 264 cm->allow_high_precision_mv ? cpi->mb.nmvcost_hp : cpi->mb.nmvcost, |
261 cpi->mb.nmvcost_hp : cpi->mb.nmvcost, | 265 &cm->fc.nmvc, |
262 &cpi->common.fc.nmvc, | 266 cm->allow_high_precision_mv, 1, 1); |
263 cpi->mb.e_mbd.allow_high_precision_mv, 1, 1); | |
264 | 267 |
265 for (i = 0; i < INTER_MODE_CONTEXTS; i++) { | 268 for (i = 0; i < INTER_MODE_CONTEXTS; i++) { |
266 MB_PREDICTION_MODE m; | 269 MB_PREDICTION_MODE m; |
267 | 270 |
268 for (m = NEARESTMV; m < MB_MODE_COUNT; m++) | 271 for (m = NEARESTMV; m < MB_MODE_COUNT; m++) |
269 cpi->mb.inter_mode_cost[i][m - NEARESTMV] = | 272 cpi->mb.inter_mode_cost[i][inter_mode_offset(m)] = |
270 cost_token(vp9_inter_mode_tree, | 273 cost_token(vp9_inter_mode_tree, |
271 cpi->common.fc.inter_mode_probs[i], | 274 cm->fc.inter_mode_probs[i], |
272 vp9_inter_mode_encodings - NEARESTMV + m); | 275 &vp9_inter_mode_encodings[inter_mode_offset(m)]); |
273 } | 276 } |
274 } | 277 } |
275 } | 278 } |
276 | 279 |
277 static INLINE void linear_interpolate2(double x, int ntab, int inv_step, | 280 static INLINE void linear_interpolate2(double x, int ntab, int inv_step, |
278 const double *tab1, const double *tab2, | 281 const double *tab1, const double *tab2, |
279 double *v1, double *v2) { | 282 double *v1, double *v2) { |
280 double y = x * inv_step; | 283 double y = x * inv_step; |
281 int d = (int) y; | 284 int d = (int) y; |
282 if (d >= ntab - 1) { | 285 if (d >= ntab - 1) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 * can skip this if the last coefficient in this transform block, e.g. the | 475 * can skip this if the last coefficient in this transform block, e.g. the |
473 * 16th coefficient in a 4x4 block or the 64th coefficient in a 8x8 block, | 476 * 16th coefficient in a 4x4 block or the 64th coefficient in a 8x8 block, |
474 * were non-zero). */ | 477 * were non-zero). */ |
475 static const int16_t band_counts[TX_SIZES][8] = { | 478 static const int16_t band_counts[TX_SIZES][8] = { |
476 { 1, 2, 3, 4, 3, 16 - 13, 0 }, | 479 { 1, 2, 3, 4, 3, 16 - 13, 0 }, |
477 { 1, 2, 3, 4, 11, 64 - 21, 0 }, | 480 { 1, 2, 3, 4, 11, 64 - 21, 0 }, |
478 { 1, 2, 3, 4, 11, 256 - 21, 0 }, | 481 { 1, 2, 3, 4, 11, 256 - 21, 0 }, |
479 { 1, 2, 3, 4, 11, 1024 - 21, 0 }, | 482 { 1, 2, 3, 4, 11, 1024 - 21, 0 }, |
480 }; | 483 }; |
481 | 484 |
482 static INLINE int cost_coeffs(MACROBLOCK *mb, | 485 static INLINE int cost_coeffs(MACROBLOCK *x, |
483 int plane, int block, | 486 int plane, int block, |
484 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, | 487 ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L, |
485 TX_SIZE tx_size, | 488 TX_SIZE tx_size, |
486 const int16_t *scan, const int16_t *nb) { | 489 const int16_t *scan, const int16_t *nb) { |
487 MACROBLOCKD *const xd = &mb->e_mbd; | 490 MACROBLOCKD *const xd = &x->e_mbd; |
488 MB_MODE_INFO *mbmi = &xd->this_mi->mbmi; | 491 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
489 struct macroblockd_plane *pd = &xd->plane[plane]; | 492 struct macroblockd_plane *pd = &xd->plane[plane]; |
490 const PLANE_TYPE type = pd->plane_type; | 493 const PLANE_TYPE type = pd->plane_type; |
491 const int16_t *band_count = &band_counts[tx_size][1]; | 494 const int16_t *band_count = &band_counts[tx_size][1]; |
492 const int eob = pd->eobs[block]; | 495 const int eob = pd->eobs[block]; |
493 const int16_t *const qcoeff_ptr = BLOCK_OFFSET(pd->qcoeff, block); | 496 const int16_t *const qcoeff_ptr = BLOCK_OFFSET(pd->qcoeff, block); |
494 const int ref = mbmi->ref_frame[0] != INTRA_FRAME; | 497 const int ref = mbmi->ref_frame[0] != INTRA_FRAME; |
495 unsigned int (*token_costs)[2][PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS] = | 498 unsigned int (*token_costs)[2][PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS] = |
496 mb->token_costs[tx_size][type][ref]; | 499 x->token_costs[tx_size][type][ref]; |
497 const ENTROPY_CONTEXT above_ec = !!*A, left_ec = !!*L; | 500 const ENTROPY_CONTEXT above_ec = !!*A, left_ec = !!*L; |
498 uint8_t token_cache[1024]; | 501 uint8_t *p_tok = x->token_cache; |
499 int pt = combine_entropy_contexts(above_ec, left_ec); | 502 int pt = combine_entropy_contexts(above_ec, left_ec); |
500 int c, cost; | 503 int c, cost; |
501 | 504 |
502 // Check for consistency of tx_size with mode info | 505 // Check for consistency of tx_size with mode info |
503 assert(type == PLANE_TYPE_Y_WITH_DC ? mbmi->tx_size == tx_size | 506 assert(type == PLANE_TYPE_Y_WITH_DC ? mbmi->tx_size == tx_size |
504 : get_uv_tx_size(mbmi) == tx_size); | 507 : get_uv_tx_size(mbmi) == tx_size); |
505 | 508 |
506 if (eob == 0) { | 509 if (eob == 0) { |
507 // single eob token | 510 // single eob token |
508 cost = token_costs[0][0][pt][DCT_EOB_TOKEN]; | 511 cost = token_costs[0][0][pt][DCT_EOB_TOKEN]; |
509 c = 0; | 512 c = 0; |
510 } else { | 513 } else { |
511 int band_left = *band_count++; | 514 int band_left = *band_count++; |
512 | 515 |
513 // dc token | 516 // dc token |
514 int v = qcoeff_ptr[0]; | 517 int v = qcoeff_ptr[0]; |
515 int prev_t = vp9_dct_value_tokens_ptr[v].token; | 518 int prev_t = vp9_dct_value_tokens_ptr[v].token; |
516 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v]; | 519 cost = (*token_costs)[0][pt][prev_t] + vp9_dct_value_cost_ptr[v]; |
517 token_cache[0] = vp9_pt_energy_class[prev_t]; | 520 p_tok[0] = vp9_pt_energy_class[prev_t]; |
518 ++token_costs; | 521 ++token_costs; |
519 | 522 |
520 // ac tokens | 523 // ac tokens |
521 for (c = 1; c < eob; c++) { | 524 for (c = 1; c < eob; c++) { |
522 const int rc = scan[c]; | 525 const int rc = scan[c]; |
523 int t; | 526 int t; |
524 | 527 |
525 v = qcoeff_ptr[rc]; | 528 v = qcoeff_ptr[rc]; |
526 t = vp9_dct_value_tokens_ptr[v].token; | 529 t = vp9_dct_value_tokens_ptr[v].token; |
527 pt = get_coef_context(nb, token_cache, c); | 530 pt = get_coef_context(nb, p_tok, c); |
528 cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v]; | 531 cost += (*token_costs)[!prev_t][pt][t] + vp9_dct_value_cost_ptr[v]; |
529 token_cache[rc] = vp9_pt_energy_class[t]; | 532 p_tok[rc] = vp9_pt_energy_class[t]; |
530 prev_t = t; | 533 prev_t = t; |
531 if (!--band_left) { | 534 if (!--band_left) { |
532 band_left = *band_count++; | 535 band_left = *band_count++; |
533 ++token_costs; | 536 ++token_costs; |
534 } | 537 } |
535 } | 538 } |
536 | 539 |
537 // eob token | 540 // eob token |
538 if (band_left) { | 541 if (band_left) { |
539 pt = get_coef_context(nb, token_cache, c); | 542 pt = get_coef_context(nb, p_tok, c); |
540 cost += (*token_costs)[0][pt][DCT_EOB_TOKEN]; | 543 cost += (*token_costs)[0][pt][DCT_EOB_TOKEN]; |
541 } | 544 } |
542 } | 545 } |
543 | 546 |
544 // is eob first coefficient; | 547 // is eob first coefficient; |
545 *A = *L = (c > 0); | 548 *A = *L = (c > 0); |
546 | 549 |
547 return cost; | 550 return cost; |
548 } | 551 } |
549 | 552 |
550 struct rdcost_block_args { | |
551 MACROBLOCK *x; | |
552 ENTROPY_CONTEXT t_above[16]; | |
553 ENTROPY_CONTEXT t_left[16]; | |
554 TX_SIZE tx_size; | |
555 int bw; | |
556 int bh; | |
557 int rate; | |
558 int64_t dist; | |
559 int64_t sse; | |
560 int64_t best_rd; | |
561 int skip; | |
562 const int16_t *scan, *nb; | |
563 }; | |
564 | |
565 static void dist_block(int plane, int block, TX_SIZE tx_size, void *arg) { | 553 static void dist_block(int plane, int block, TX_SIZE tx_size, void *arg) { |
566 const int ss_txfrm_size = tx_size << 1; | 554 const int ss_txfrm_size = tx_size << 1; |
567 struct rdcost_block_args* args = arg; | 555 struct rdcost_block_args* args = arg; |
568 MACROBLOCK* const x = args->x; | 556 MACROBLOCK* const x = args->x; |
569 MACROBLOCKD* const xd = &x->e_mbd; | 557 MACROBLOCKD* const xd = &x->e_mbd; |
570 struct macroblock_plane *const p = &x->plane[plane]; | 558 struct macroblock_plane *const p = &x->plane[plane]; |
571 struct macroblockd_plane *const pd = &xd->plane[plane]; | 559 struct macroblockd_plane *const pd = &xd->plane[plane]; |
572 int64_t this_sse; | 560 int64_t this_sse; |
573 int shift = args->tx_size == TX_32X32 ? 0 : 2; | 561 int shift = args->tx_size == TX_32X32 ? 0 : 2; |
574 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); | 562 int16_t *const coeff = BLOCK_OFFSET(p->coeff, block); |
575 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); | 563 int16_t *const dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block); |
576 args->dist += vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, | 564 args->dist = vp9_block_error(coeff, dqcoeff, 16 << ss_txfrm_size, |
577 &this_sse) >> shift; | 565 &this_sse) >> shift; |
578 args->sse += this_sse >> shift; | 566 args->sse = this_sse >> shift; |
579 | 567 |
580 if (x->skip_encode && | 568 if (x->skip_encode && |
581 xd->this_mi->mbmi.ref_frame[0] == INTRA_FRAME) { | 569 xd->mi_8x8[0]->mbmi.ref_frame[0] == INTRA_FRAME) { |
582 // TODO(jingning): tune the model to better capture the distortion. | 570 // TODO(jingning): tune the model to better capture the distortion. |
583 int64_t p = (pd->dequant[1] * pd->dequant[1] * | 571 int64_t p = (pd->dequant[1] * pd->dequant[1] * |
584 (1 << ss_txfrm_size)) >> shift; | 572 (1 << ss_txfrm_size)) >> (shift + 2); |
585 args->dist += p; | 573 args->dist += (p >> 4); |
586 args->sse += p; | 574 args->sse += p; |
587 } | 575 } |
588 } | 576 } |
589 | 577 |
590 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, | 578 static void rate_block(int plane, int block, BLOCK_SIZE plane_bsize, |
591 TX_SIZE tx_size, void *arg) { | 579 TX_SIZE tx_size, void *arg) { |
592 struct rdcost_block_args* args = arg; | 580 struct rdcost_block_args* args = arg; |
593 | 581 |
594 int x_idx, y_idx; | 582 int x_idx, y_idx; |
595 txfrm_block_to_raster_xy(plane_bsize, args->tx_size, block, &x_idx, &y_idx); | 583 txfrm_block_to_raster_xy(plane_bsize, args->tx_size, block, &x_idx, &y_idx); |
596 | 584 |
597 args->rate += cost_coeffs(args->x, plane, block, | 585 args->rate = cost_coeffs(args->x, plane, block, args->t_above + x_idx, |
598 args->t_above + x_idx, | 586 args->t_left + y_idx, args->tx_size, |
599 args->t_left + y_idx, args->tx_size, | 587 args->scan, args->nb); |
600 args->scan, args->nb); | |
601 } | 588 } |
602 | 589 |
603 static void block_yrd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, | 590 static void block_yrd_txfm(int plane, int block, BLOCK_SIZE plane_bsize, |
604 TX_SIZE tx_size, void *arg) { | 591 TX_SIZE tx_size, void *arg) { |
605 struct rdcost_block_args *args = arg; | 592 struct rdcost_block_args *args = arg; |
606 MACROBLOCK *const x = args->x; | 593 MACROBLOCK *const x = args->x; |
607 MACROBLOCKD *const xd = &x->e_mbd; | 594 MACROBLOCKD *const xd = &x->e_mbd; |
608 struct encode_b_args encode_args = {x, NULL}; | 595 struct encode_b_args encode_args = {x, NULL}; |
609 int64_t rd1, rd2, rd; | 596 int64_t rd1, rd2, rd; |
610 | 597 |
611 if (args->skip) | 598 if (args->skip) |
612 return; | 599 return; |
613 rd1 = RDCOST(x->rdmult, x->rddiv, args->rate, args->dist); | |
614 rd2 = RDCOST(x->rdmult, x->rddiv, 0, args->sse); | |
615 rd = MIN(rd1, rd2); | |
616 if (rd > args->best_rd) { | |
617 args->skip = 1; | |
618 args->rate = INT_MAX; | |
619 args->dist = INT64_MAX; | |
620 args->sse = INT64_MAX; | |
621 return; | |
622 } | |
623 | 600 |
624 if (!is_inter_block(&xd->this_mi->mbmi)) | 601 if (!is_inter_block(&xd->mi_8x8[0]->mbmi)) |
625 vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &encode_args); | 602 vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &encode_args); |
626 else | 603 else |
627 vp9_xform_quant(plane, block, plane_bsize, tx_size, &encode_args); | 604 vp9_xform_quant(plane, block, plane_bsize, tx_size, &encode_args); |
628 | 605 |
629 dist_block(plane, block, tx_size, args); | 606 dist_block(plane, block, tx_size, args); |
630 rate_block(plane, block, plane_bsize, tx_size, args); | 607 rate_block(plane, block, plane_bsize, tx_size, args); |
| 608 rd1 = RDCOST(x->rdmult, x->rddiv, args->rate, args->dist); |
| 609 rd2 = RDCOST(x->rdmult, x->rddiv, 0, args->sse); |
| 610 |
| 611 // TODO(jingning): temporarily enabled only for luma component |
| 612 rd = MIN(rd1, rd2); |
| 613 if (plane == 0) |
| 614 x->zcoeff_blk[tx_size][block] = rd1 > rd2 || !xd->plane[plane].eobs[block]; |
| 615 |
| 616 args->this_rate += args->rate; |
| 617 args->this_dist += args->dist; |
| 618 args->this_sse += args->sse; |
| 619 args->this_rd += rd; |
| 620 |
| 621 if (args->this_rd > args->best_rd) { |
| 622 args->skip = 1; |
| 623 return; |
| 624 } |
| 625 } |
| 626 |
| 627 void vp9_get_entropy_contexts(TX_SIZE tx_size, |
| 628 ENTROPY_CONTEXT t_above[16], ENTROPY_CONTEXT t_left[16], |
| 629 const ENTROPY_CONTEXT *above, const ENTROPY_CONTEXT *left, |
| 630 int num_4x4_w, int num_4x4_h) { |
| 631 int i; |
| 632 switch (tx_size) { |
| 633 case TX_4X4: |
| 634 vpx_memcpy(t_above, above, sizeof(ENTROPY_CONTEXT) * num_4x4_w); |
| 635 vpx_memcpy(t_left, left, sizeof(ENTROPY_CONTEXT) * num_4x4_h); |
| 636 break; |
| 637 case TX_8X8: |
| 638 for (i = 0; i < num_4x4_w; i += 2) |
| 639 t_above[i] = !!*(const uint16_t *)&above[i]; |
| 640 for (i = 0; i < num_4x4_h; i += 2) |
| 641 t_left[i] = !!*(const uint16_t *)&left[i]; |
| 642 break; |
| 643 case TX_16X16: |
| 644 for (i = 0; i < num_4x4_w; i += 4) |
| 645 t_above[i] = !!*(const uint32_t *)&above[i]; |
| 646 for (i = 0; i < num_4x4_h; i += 4) |
| 647 t_left[i] = !!*(const uint32_t *)&left[i]; |
| 648 break; |
| 649 case TX_32X32: |
| 650 for (i = 0; i < num_4x4_w; i += 8) |
| 651 t_above[i] = !!*(const uint64_t *)&above[i]; |
| 652 for (i = 0; i < num_4x4_h; i += 8) |
| 653 t_left[i] = !!*(const uint64_t *)&left[i]; |
| 654 break; |
| 655 default: |
| 656 assert(!"Invalid transform size."); |
| 657 } |
| 658 } |
| 659 |
| 660 static void init_rdcost_stack(MACROBLOCK *x, TX_SIZE tx_size, |
| 661 const int num_4x4_w, const int num_4x4_h, |
| 662 const int64_t ref_rdcost, |
| 663 struct rdcost_block_args *arg) { |
| 664 vpx_memset(arg, 0, sizeof(struct rdcost_block_args)); |
| 665 arg->x = x; |
| 666 arg->tx_size = tx_size; |
| 667 arg->bw = num_4x4_w; |
| 668 arg->bh = num_4x4_h; |
| 669 arg->best_rd = ref_rdcost; |
631 } | 670 } |
632 | 671 |
633 static void txfm_rd_in_plane(MACROBLOCK *x, | 672 static void txfm_rd_in_plane(MACROBLOCK *x, |
| 673 struct rdcost_block_args *rd_stack, |
634 int *rate, int64_t *distortion, | 674 int *rate, int64_t *distortion, |
635 int *skippable, int64_t *sse, | 675 int *skippable, int64_t *sse, |
636 int64_t ref_best_rd, int plane, | 676 int64_t ref_best_rd, int plane, |
637 BLOCK_SIZE bsize, TX_SIZE tx_size) { | 677 BLOCK_SIZE bsize, TX_SIZE tx_size) { |
638 MACROBLOCKD *const xd = &x->e_mbd; | 678 MACROBLOCKD *const xd = &x->e_mbd; |
639 struct macroblockd_plane *const pd = &xd->plane[plane]; | 679 struct macroblockd_plane *const pd = &xd->plane[plane]; |
640 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); | 680 const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); |
641 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bs]; | 681 const int num_4x4_w = num_4x4_blocks_wide_lookup[bs]; |
642 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bs]; | 682 const int num_4x4_h = num_4x4_blocks_high_lookup[bs]; |
643 int i; | 683 |
644 struct rdcost_block_args args = { x, { 0 }, { 0 }, tx_size, | 684 init_rdcost_stack(x, tx_size, num_4x4_w, num_4x4_h, |
645 num_4x4_blocks_wide, num_4x4_blocks_high, | 685 ref_best_rd, rd_stack); |
646 0, 0, 0, ref_best_rd, 0 }; | |
647 if (plane == 0) | 686 if (plane == 0) |
648 xd->this_mi->mbmi.tx_size = tx_size; | 687 xd->mi_8x8[0]->mbmi.tx_size = tx_size; |
649 | 688 |
650 switch (tx_size) { | 689 vp9_get_entropy_contexts(tx_size, rd_stack->t_above, rd_stack->t_left, |
651 case TX_4X4: | 690 pd->above_context, pd->left_context, |
652 vpx_memcpy(&args.t_above, pd->above_context, | 691 num_4x4_w, num_4x4_h); |
653 sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_wide); | 692 |
654 vpx_memcpy(&args.t_left, pd->left_context, | 693 get_scan(xd, tx_size, pd->plane_type, 0, &rd_stack->scan, &rd_stack->nb); |
655 sizeof(ENTROPY_CONTEXT) * num_4x4_blocks_high); | 694 |
656 get_scan_nb_4x4(get_tx_type_4x4(pd->plane_type, xd, 0), | 695 foreach_transformed_block_in_plane(xd, bsize, plane, |
657 &args.scan, &args.nb); | 696 block_yrd_txfm, rd_stack); |
658 break; | 697 if (rd_stack->skip) { |
659 case TX_8X8: | 698 *rate = INT_MAX; |
660 for (i = 0; i < num_4x4_blocks_wide; i += 2) | 699 *distortion = INT64_MAX; |
661 args.t_above[i] = !!*(uint16_t *)&pd->above_context[i]; | 700 *sse = INT64_MAX; |
662 for (i = 0; i < num_4x4_blocks_high; i += 2) | 701 *skippable = 0; |
663 args.t_left[i] = !!*(uint16_t *)&pd->left_context[i]; | 702 } else { |
664 get_scan_nb_8x8(get_tx_type_8x8(pd->plane_type, xd), | 703 *distortion = rd_stack->this_dist; |
665 &args.scan, &args.nb); | 704 *rate = rd_stack->this_rate; |
666 break; | 705 *sse = rd_stack->this_sse; |
667 case TX_16X16: | 706 *skippable = vp9_is_skippable_in_plane(xd, bsize, plane); |
668 for (i = 0; i < num_4x4_blocks_wide; i += 4) | |
669 args.t_above[i] = !!*(uint32_t *)&pd->above_context[i]; | |
670 for (i = 0; i < num_4x4_blocks_high; i += 4) | |
671 args.t_left[i] = !!*(uint32_t *)&pd->left_context[i]; | |
672 get_scan_nb_16x16(get_tx_type_16x16(pd->plane_type, xd), | |
673 &args.scan, &args.nb); | |
674 break; | |
675 case TX_32X32: | |
676 for (i = 0; i < num_4x4_blocks_wide; i += 8) | |
677 args.t_above[i] = !!*(uint64_t *)&pd->above_context[i]; | |
678 for (i = 0; i < num_4x4_blocks_high; i += 8) | |
679 args.t_left[i] = !!*(uint64_t *)&pd->left_context[i]; | |
680 args.scan = vp9_default_scan_32x32; | |
681 args.nb = vp9_default_scan_32x32_neighbors; | |
682 break; | |
683 default: | |
684 assert(0); | |
685 } | 707 } |
686 | |
687 foreach_transformed_block_in_plane(xd, bsize, plane, block_yrd_txfm, &args); | |
688 *distortion = args.dist; | |
689 *rate = args.rate; | |
690 *sse = args.sse; | |
691 *skippable = vp9_is_skippable_in_plane(xd, bsize, plane) && (!args.skip); | |
692 } | 708 } |
693 | 709 |
694 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x, | 710 static void choose_largest_txfm_size(VP9_COMP *cpi, MACROBLOCK *x, |
695 int *rate, int64_t *distortion, | 711 int *rate, int64_t *distortion, |
696 int *skip, int64_t *sse, | 712 int *skip, int64_t *sse, |
697 int64_t ref_best_rd, | 713 int64_t ref_best_rd, |
698 BLOCK_SIZE bs) { | 714 BLOCK_SIZE bs) { |
699 const TX_SIZE max_txfm_size = max_txsize_lookup[bs]; | 715 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
700 VP9_COMMON *const cm = &cpi->common; | 716 VP9_COMMON *const cm = &cpi->common; |
| 717 const TX_SIZE largest_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode]; |
701 MACROBLOCKD *const xd = &x->e_mbd; | 718 MACROBLOCKD *const xd = &x->e_mbd; |
702 MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi; | 719 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
703 if (max_txfm_size == TX_32X32 && | 720 |
704 (cm->tx_mode == ALLOW_32X32 || | 721 mbmi->tx_size = MIN(max_tx_size, largest_tx_size); |
705 cm->tx_mode == TX_MODE_SELECT)) { | 722 |
706 mbmi->tx_size = TX_32X32; | 723 txfm_rd_in_plane(x, &cpi->rdcost_stack, rate, distortion, skip, |
707 } else if (max_txfm_size >= TX_16X16 && | |
708 (cm->tx_mode == ALLOW_16X16 || | |
709 cm->tx_mode == ALLOW_32X32 || | |
710 cm->tx_mode == TX_MODE_SELECT)) { | |
711 mbmi->tx_size = TX_16X16; | |
712 } else if (cm->tx_mode != ONLY_4X4) { | |
713 mbmi->tx_size = TX_8X8; | |
714 } else { | |
715 mbmi->tx_size = TX_4X4; | |
716 } | |
717 txfm_rd_in_plane(x, rate, distortion, skip, | |
718 &sse[mbmi->tx_size], ref_best_rd, 0, bs, | 724 &sse[mbmi->tx_size], ref_best_rd, 0, bs, |
719 mbmi->tx_size); | 725 mbmi->tx_size); |
720 cpi->txfm_stepdown_count[0]++; | 726 cpi->tx_stepdown_count[0]++; |
721 } | 727 } |
722 | 728 |
723 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, | 729 static void choose_txfm_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x, |
724 int (*r)[2], int *rate, | 730 int (*r)[2], int *rate, |
725 int64_t *d, int64_t *distortion, | 731 int64_t *d, int64_t *distortion, |
726 int *s, int *skip, | 732 int *s, int *skip, |
727 int64_t tx_cache[TX_MODES], | 733 int64_t tx_cache[TX_MODES], |
728 BLOCK_SIZE bs) { | 734 BLOCK_SIZE bs) { |
729 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; | 735 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
730 VP9_COMMON *const cm = &cpi->common; | 736 VP9_COMMON *const cm = &cpi->common; |
731 MACROBLOCKD *const xd = &x->e_mbd; | 737 MACROBLOCKD *const xd = &x->e_mbd; |
732 MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi; | 738 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
733 vp9_prob skip_prob = vp9_get_pred_prob_mbskip(cm, xd); | 739 vp9_prob skip_prob = vp9_get_pred_prob_mbskip(cm, xd); |
734 int64_t rd[TX_SIZES][2]; | 740 int64_t rd[TX_SIZES][2]; |
735 int n, m; | 741 int n, m; |
736 int s0, s1; | 742 int s0, s1; |
737 | 743 |
738 const vp9_prob *tx_probs = get_tx_probs2(xd, &cm->fc.tx_probs, xd->this_mi); | 744 const vp9_prob *tx_probs = get_tx_probs2(xd, &cm->fc.tx_probs, xd->mi_8x8[0]); |
739 | 745 |
740 for (n = TX_4X4; n <= max_tx_size; n++) { | 746 for (n = TX_4X4; n <= max_tx_size; n++) { |
741 r[n][1] = r[n][0]; | 747 r[n][1] = r[n][0]; |
742 if (r[n][0] == INT_MAX) | 748 if (r[n][0] == INT_MAX) |
743 continue; | 749 continue; |
744 for (m = 0; m <= n - (n == max_tx_size); m++) { | 750 for (m = 0; m <= n - (n == max_tx_size); m++) { |
745 if (m == n) | 751 if (m == n) |
746 r[n][1] += vp9_cost_zero(tx_probs[m]); | 752 r[n][1] += vp9_cost_zero(tx_probs[m]); |
747 else | 753 else |
748 r[n][1] += vp9_cost_one(tx_probs[m]); | 754 r[n][1] += vp9_cost_one(tx_probs[m]); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 rd[TX_16X16][1] < rd[TX_8X8][1] && rd[TX_16X16][1] < rd[TX_4X4][1]) | 810 rd[TX_16X16][1] < rd[TX_8X8][1] && rd[TX_16X16][1] < rd[TX_4X4][1]) |
805 tx_cache[TX_MODE_SELECT] = rd[TX_16X16][1]; | 811 tx_cache[TX_MODE_SELECT] = rd[TX_16X16][1]; |
806 else | 812 else |
807 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1] < rd[TX_8X8][1] ? | 813 tx_cache[TX_MODE_SELECT] = rd[TX_4X4][1] < rd[TX_8X8][1] ? |
808 rd[TX_4X4][1] : rd[TX_8X8][1]; | 814 rd[TX_4X4][1] : rd[TX_8X8][1]; |
809 | 815 |
810 if (max_tx_size == TX_32X32 && | 816 if (max_tx_size == TX_32X32 && |
811 rd[TX_32X32][1] < rd[TX_16X16][1] && | 817 rd[TX_32X32][1] < rd[TX_16X16][1] && |
812 rd[TX_32X32][1] < rd[TX_8X8][1] && | 818 rd[TX_32X32][1] < rd[TX_8X8][1] && |
813 rd[TX_32X32][1] < rd[TX_4X4][1]) { | 819 rd[TX_32X32][1] < rd[TX_4X4][1]) { |
814 cpi->txfm_stepdown_count[0]++; | 820 cpi->tx_stepdown_count[0]++; |
815 } else if (max_tx_size >= TX_16X16 && | 821 } else if (max_tx_size >= TX_16X16 && |
816 rd[TX_16X16][1] < rd[TX_8X8][1] && | 822 rd[TX_16X16][1] < rd[TX_8X8][1] && |
817 rd[TX_16X16][1] < rd[TX_4X4][1]) { | 823 rd[TX_16X16][1] < rd[TX_4X4][1]) { |
818 cpi->txfm_stepdown_count[max_tx_size - TX_16X16]++; | 824 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; |
819 } else if (rd[TX_8X8][1] < rd[TX_4X4][1]) { | 825 } else if (rd[TX_8X8][1] < rd[TX_4X4][1]) { |
820 cpi->txfm_stepdown_count[max_tx_size - TX_8X8]++; | 826 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; |
821 } else { | 827 } else { |
822 cpi->txfm_stepdown_count[max_tx_size - TX_4X4]++; | 828 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; |
823 } | 829 } |
824 } | 830 } |
825 | 831 |
826 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x, | 832 static void choose_txfm_size_from_modelrd(VP9_COMP *cpi, MACROBLOCK *x, |
827 int (*r)[2], int *rate, | 833 int (*r)[2], int *rate, |
828 int64_t *d, int64_t *distortion, | 834 int64_t *d, int64_t *distortion, |
829 int *s, int *skip, int64_t *sse, | 835 int *s, int *skip, int64_t *sse, |
830 int64_t ref_best_rd, | 836 int64_t ref_best_rd, |
831 BLOCK_SIZE bs) { | 837 BLOCK_SIZE bs) { |
832 const TX_SIZE max_txfm_size = max_txsize_lookup[bs]; | 838 const TX_SIZE max_tx_size = max_txsize_lookup[bs]; |
833 VP9_COMMON *const cm = &cpi->common; | 839 VP9_COMMON *const cm = &cpi->common; |
834 MACROBLOCKD *const xd = &x->e_mbd; | 840 MACROBLOCKD *const xd = &x->e_mbd; |
835 MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi; | 841 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
836 vp9_prob skip_prob = vp9_get_pred_prob_mbskip(cm, xd); | 842 vp9_prob skip_prob = vp9_get_pred_prob_mbskip(cm, xd); |
837 int64_t rd[TX_SIZES][2]; | 843 int64_t rd[TX_SIZES][2]; |
838 int n, m; | 844 int n, m; |
839 int s0, s1; | 845 int s0, s1; |
840 double scale_rd[TX_SIZES] = {1.73, 1.44, 1.20, 1.00}; | 846 double scale_rd[TX_SIZES] = {1.73, 1.44, 1.20, 1.00}; |
841 // double scale_r[TX_SIZES] = {2.82, 2.00, 1.41, 1.00}; | 847 // double scale_r[TX_SIZES] = {2.82, 2.00, 1.41, 1.00}; |
842 | 848 |
843 const vp9_prob *tx_probs = get_tx_probs2(xd, &cm->fc.tx_probs, xd->this_mi); | 849 const vp9_prob *tx_probs = get_tx_probs2(xd, &cm->fc.tx_probs, xd->mi_8x8[0]); |
844 | 850 |
845 // for (n = TX_4X4; n <= max_txfm_size; n++) | 851 // for (n = TX_4X4; n <= max_txfm_size; n++) |
846 // r[n][0] = (r[n][0] * scale_r[n]); | 852 // r[n][0] = (r[n][0] * scale_r[n]); |
847 | 853 |
848 for (n = TX_4X4; n <= max_txfm_size; n++) { | 854 for (n = TX_4X4; n <= max_tx_size; n++) { |
849 r[n][1] = r[n][0]; | 855 r[n][1] = r[n][0]; |
850 for (m = 0; m <= n - (n == max_txfm_size); m++) { | 856 for (m = 0; m <= n - (n == max_tx_size); m++) { |
851 if (m == n) | 857 if (m == n) |
852 r[n][1] += vp9_cost_zero(tx_probs[m]); | 858 r[n][1] += vp9_cost_zero(tx_probs[m]); |
853 else | 859 else |
854 r[n][1] += vp9_cost_one(tx_probs[m]); | 860 r[n][1] += vp9_cost_one(tx_probs[m]); |
855 } | 861 } |
856 } | 862 } |
857 | 863 |
858 assert(skip_prob > 0); | 864 assert(skip_prob > 0); |
859 s0 = vp9_cost_bit(skip_prob, 0); | 865 s0 = vp9_cost_bit(skip_prob, 0); |
860 s1 = vp9_cost_bit(skip_prob, 1); | 866 s1 = vp9_cost_bit(skip_prob, 1); |
861 | 867 |
862 for (n = TX_4X4; n <= max_txfm_size; n++) { | 868 for (n = TX_4X4; n <= max_tx_size; n++) { |
863 if (s[n]) { | 869 if (s[n]) { |
864 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]); | 870 rd[n][0] = rd[n][1] = RDCOST(x->rdmult, x->rddiv, s1, d[n]); |
865 } else { | 871 } else { |
866 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]); | 872 rd[n][0] = RDCOST(x->rdmult, x->rddiv, r[n][0] + s0, d[n]); |
867 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]); | 873 rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]); |
868 } | 874 } |
869 } | 875 } |
870 for (n = TX_4X4; n <= max_txfm_size; n++) { | 876 for (n = TX_4X4; n <= max_tx_size; n++) { |
871 rd[n][0] = (int64_t)(scale_rd[n] * rd[n][0]); | 877 rd[n][0] = (int64_t)(scale_rd[n] * rd[n][0]); |
872 rd[n][1] = (int64_t)(scale_rd[n] * rd[n][1]); | 878 rd[n][1] = (int64_t)(scale_rd[n] * rd[n][1]); |
873 } | 879 } |
874 | 880 |
875 if (max_txfm_size == TX_32X32 && | 881 if (max_tx_size == TX_32X32 && |
876 (cm->tx_mode == ALLOW_32X32 || | 882 (cm->tx_mode == ALLOW_32X32 || |
877 (cm->tx_mode == TX_MODE_SELECT && | 883 (cm->tx_mode == TX_MODE_SELECT && |
878 rd[TX_32X32][1] <= rd[TX_16X16][1] && | 884 rd[TX_32X32][1] <= rd[TX_16X16][1] && |
879 rd[TX_32X32][1] <= rd[TX_8X8][1] && | 885 rd[TX_32X32][1] <= rd[TX_8X8][1] && |
880 rd[TX_32X32][1] <= rd[TX_4X4][1]))) { | 886 rd[TX_32X32][1] <= rd[TX_4X4][1]))) { |
881 mbmi->tx_size = TX_32X32; | 887 mbmi->tx_size = TX_32X32; |
882 } else if (max_txfm_size >= TX_16X16 && | 888 } else if (max_tx_size >= TX_16X16 && |
883 (cm->tx_mode == ALLOW_16X16 || | 889 (cm->tx_mode == ALLOW_16X16 || |
884 cm->tx_mode == ALLOW_32X32 || | 890 cm->tx_mode == ALLOW_32X32 || |
885 (cm->tx_mode == TX_MODE_SELECT && | 891 (cm->tx_mode == TX_MODE_SELECT && |
886 rd[TX_16X16][1] <= rd[TX_8X8][1] && | 892 rd[TX_16X16][1] <= rd[TX_8X8][1] && |
887 rd[TX_16X16][1] <= rd[TX_4X4][1]))) { | 893 rd[TX_16X16][1] <= rd[TX_4X4][1]))) { |
888 mbmi->tx_size = TX_16X16; | 894 mbmi->tx_size = TX_16X16; |
889 } else if (cm->tx_mode == ALLOW_8X8 || | 895 } else if (cm->tx_mode == ALLOW_8X8 || |
890 cm->tx_mode == ALLOW_16X16 || | 896 cm->tx_mode == ALLOW_16X16 || |
891 cm->tx_mode == ALLOW_32X32 || | 897 cm->tx_mode == ALLOW_32X32 || |
892 (cm->tx_mode == TX_MODE_SELECT && | 898 (cm->tx_mode == TX_MODE_SELECT && |
893 rd[TX_8X8][1] <= rd[TX_4X4][1])) { | 899 rd[TX_8X8][1] <= rd[TX_4X4][1])) { |
894 mbmi->tx_size = TX_8X8; | 900 mbmi->tx_size = TX_8X8; |
895 } else { | 901 } else { |
896 mbmi->tx_size = TX_4X4; | 902 mbmi->tx_size = TX_4X4; |
897 } | 903 } |
898 | 904 |
899 // Actually encode using the chosen mode if a model was used, but do not | 905 // Actually encode using the chosen mode if a model was used, but do not |
900 // update the r, d costs | 906 // update the r, d costs |
901 txfm_rd_in_plane(x, rate, distortion, skip, &sse[mbmi->tx_size], | 907 txfm_rd_in_plane(x, &cpi->rdcost_stack, rate, distortion, skip, |
902 ref_best_rd, 0, bs, mbmi->tx_size); | 908 &sse[mbmi->tx_size], ref_best_rd, 0, bs, mbmi->tx_size); |
903 | 909 |
904 if (max_txfm_size == TX_32X32 && | 910 if (max_tx_size == TX_32X32 && |
905 rd[TX_32X32][1] <= rd[TX_16X16][1] && | 911 rd[TX_32X32][1] <= rd[TX_16X16][1] && |
906 rd[TX_32X32][1] <= rd[TX_8X8][1] && | 912 rd[TX_32X32][1] <= rd[TX_8X8][1] && |
907 rd[TX_32X32][1] <= rd[TX_4X4][1]) { | 913 rd[TX_32X32][1] <= rd[TX_4X4][1]) { |
908 cpi->txfm_stepdown_count[0]++; | 914 cpi->tx_stepdown_count[0]++; |
909 } else if (max_txfm_size >= TX_16X16 && | 915 } else if (max_tx_size >= TX_16X16 && |
910 rd[TX_16X16][1] <= rd[TX_8X8][1] && | 916 rd[TX_16X16][1] <= rd[TX_8X8][1] && |
911 rd[TX_16X16][1] <= rd[TX_4X4][1]) { | 917 rd[TX_16X16][1] <= rd[TX_4X4][1]) { |
912 cpi->txfm_stepdown_count[max_txfm_size - TX_16X16]++; | 918 cpi->tx_stepdown_count[max_tx_size - TX_16X16]++; |
913 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) { | 919 } else if (rd[TX_8X8][1] <= rd[TX_4X4][1]) { |
914 cpi->txfm_stepdown_count[max_txfm_size - TX_8X8]++; | 920 cpi->tx_stepdown_count[max_tx_size - TX_8X8]++; |
915 } else { | 921 } else { |
916 cpi->txfm_stepdown_count[max_txfm_size - TX_4X4]++; | 922 cpi->tx_stepdown_count[max_tx_size - TX_4X4]++; |
917 } | 923 } |
918 } | 924 } |
919 | 925 |
920 static void super_block_yrd(VP9_COMP *cpi, | 926 static void super_block_yrd(VP9_COMP *cpi, |
921 MACROBLOCK *x, int *rate, int64_t *distortion, | 927 MACROBLOCK *x, int *rate, int64_t *distortion, |
922 int *skip, int64_t *psse, BLOCK_SIZE bs, | 928 int *skip, int64_t *psse, BLOCK_SIZE bs, |
923 int64_t txfm_cache[TX_MODES], | 929 int64_t txfm_cache[TX_MODES], |
924 int64_t ref_best_rd) { | 930 int64_t ref_best_rd) { |
925 int r[TX_SIZES][2], s[TX_SIZES]; | 931 int r[TX_SIZES][2], s[TX_SIZES]; |
926 int64_t d[TX_SIZES], sse[TX_SIZES]; | 932 int64_t d[TX_SIZES], sse[TX_SIZES]; |
927 MACROBLOCKD *xd = &x->e_mbd; | 933 MACROBLOCKD *xd = &x->e_mbd; |
928 MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi; | 934 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
| 935 struct rdcost_block_args *rdcost_stack = &cpi->rdcost_stack; |
| 936 const int b_inter_mode = is_inter_block(mbmi); |
929 | 937 |
930 assert(bs == mbmi->sb_type); | 938 assert(bs == mbmi->sb_type); |
931 if (mbmi->ref_frame[0] > INTRA_FRAME) | 939 if (b_inter_mode) |
932 vp9_subtract_sby(x, bs); | 940 vp9_subtract_sby(x, bs); |
933 | 941 |
934 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || | 942 if (cpi->sf.tx_size_search_method == USE_LARGESTALL || |
935 (cpi->sf.tx_size_search_method != USE_FULL_RD && | 943 (cpi->sf.tx_size_search_method != USE_FULL_RD && |
936 mbmi->ref_frame[0] == INTRA_FRAME)) { | 944 !b_inter_mode)) { |
937 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); | 945 vpx_memset(txfm_cache, 0, TX_MODES * sizeof(int64_t)); |
938 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, | 946 choose_largest_txfm_size(cpi, x, rate, distortion, skip, sse, |
939 ref_best_rd, bs); | 947 ref_best_rd, bs); |
940 if (psse) | 948 if (psse) |
941 *psse = sse[mbmi->tx_size]; | 949 *psse = sse[mbmi->tx_size]; |
942 return; | 950 return; |
943 } | 951 } |
944 | 952 |
945 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER && | 953 if (cpi->sf.tx_size_search_method == USE_LARGESTINTRA_MODELINTER && |
946 mbmi->ref_frame[0] > INTRA_FRAME) { | 954 b_inter_mode) { |
947 if (bs >= BLOCK_32X32) | 955 if (bs >= BLOCK_32X32) |
948 model_rd_for_sb_y_tx(cpi, bs, TX_32X32, x, xd, | 956 model_rd_for_sb_y_tx(cpi, bs, TX_32X32, x, xd, |
949 &r[TX_32X32][0], &d[TX_32X32], &s[TX_32X32]); | 957 &r[TX_32X32][0], &d[TX_32X32], &s[TX_32X32]); |
950 if (bs >= BLOCK_16X16) | 958 if (bs >= BLOCK_16X16) |
951 model_rd_for_sb_y_tx(cpi, bs, TX_16X16, x, xd, | 959 model_rd_for_sb_y_tx(cpi, bs, TX_16X16, x, xd, |
952 &r[TX_16X16][0], &d[TX_16X16], &s[TX_16X16]); | 960 &r[TX_16X16][0], &d[TX_16X16], &s[TX_16X16]); |
953 | 961 |
954 model_rd_for_sb_y_tx(cpi, bs, TX_8X8, x, xd, | 962 model_rd_for_sb_y_tx(cpi, bs, TX_8X8, x, xd, |
955 &r[TX_8X8][0], &d[TX_8X8], &s[TX_8X8]); | 963 &r[TX_8X8][0], &d[TX_8X8], &s[TX_8X8]); |
956 | 964 |
957 model_rd_for_sb_y_tx(cpi, bs, TX_4X4, x, xd, | 965 model_rd_for_sb_y_tx(cpi, bs, TX_4X4, x, xd, |
958 &r[TX_4X4][0], &d[TX_4X4], &s[TX_4X4]); | 966 &r[TX_4X4][0], &d[TX_4X4], &s[TX_4X4]); |
959 | 967 |
960 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, | 968 choose_txfm_size_from_modelrd(cpi, x, r, rate, d, distortion, s, |
961 skip, sse, ref_best_rd, bs); | 969 skip, sse, ref_best_rd, bs); |
962 } else { | 970 } else { |
963 if (bs >= BLOCK_32X32) | 971 if (bs >= BLOCK_32X32) |
964 txfm_rd_in_plane(x, &r[TX_32X32][0], &d[TX_32X32], &s[TX_32X32], | 972 txfm_rd_in_plane(x, rdcost_stack, &r[TX_32X32][0], &d[TX_32X32], |
965 &sse[TX_32X32], ref_best_rd, 0, bs, TX_32X32); | 973 &s[TX_32X32], &sse[TX_32X32], |
| 974 ref_best_rd, 0, bs, TX_32X32); |
966 if (bs >= BLOCK_16X16) | 975 if (bs >= BLOCK_16X16) |
967 txfm_rd_in_plane(x, &r[TX_16X16][0], &d[TX_16X16], &s[TX_16X16], | 976 txfm_rd_in_plane(x, rdcost_stack, &r[TX_16X16][0], &d[TX_16X16], |
968 &sse[TX_16X16], ref_best_rd, 0, bs, TX_16X16); | 977 &s[TX_16X16], &sse[TX_16X16], |
969 txfm_rd_in_plane(x, &r[TX_8X8][0], &d[TX_8X8], &s[TX_8X8], | 978 ref_best_rd, 0, bs, TX_16X16); |
| 979 txfm_rd_in_plane(x, rdcost_stack, &r[TX_8X8][0], &d[TX_8X8], &s[TX_8X8], |
970 &sse[TX_8X8], ref_best_rd, 0, bs, TX_8X8); | 980 &sse[TX_8X8], ref_best_rd, 0, bs, TX_8X8); |
971 txfm_rd_in_plane(x, &r[TX_4X4][0], &d[TX_4X4], &s[TX_4X4], | 981 txfm_rd_in_plane(x, rdcost_stack, &r[TX_4X4][0], &d[TX_4X4], &s[TX_4X4], |
972 &sse[TX_4X4], ref_best_rd, 0, bs, TX_4X4); | 982 &sse[TX_4X4], ref_best_rd, 0, bs, TX_4X4); |
973 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, | 983 choose_txfm_size_from_rd(cpi, x, r, rate, d, distortion, s, |
974 skip, txfm_cache, bs); | 984 skip, txfm_cache, bs); |
975 } | 985 } |
976 if (psse) | 986 if (psse) |
977 *psse = sse[mbmi->tx_size]; | 987 *psse = sse[mbmi->tx_size]; |
978 } | 988 } |
979 | 989 |
980 static int conditional_skipintra(MB_PREDICTION_MODE mode, | 990 static int conditional_skipintra(MB_PREDICTION_MODE mode, |
981 MB_PREDICTION_MODE best_intra_mode) { | 991 MB_PREDICTION_MODE best_intra_mode) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1015 const int src_stride = p->src.stride; | 1025 const int src_stride = p->src.stride; |
1016 const int dst_stride = pd->dst.stride; | 1026 const int dst_stride = pd->dst.stride; |
1017 uint8_t *src_init = raster_block_offset_uint8(BLOCK_8X8, ib, | 1027 uint8_t *src_init = raster_block_offset_uint8(BLOCK_8X8, ib, |
1018 p->src.buf, src_stride); | 1028 p->src.buf, src_stride); |
1019 uint8_t *dst_init = raster_block_offset_uint8(BLOCK_8X8, ib, | 1029 uint8_t *dst_init = raster_block_offset_uint8(BLOCK_8X8, ib, |
1020 pd->dst.buf, dst_stride); | 1030 pd->dst.buf, dst_stride); |
1021 int16_t *src_diff, *coeff; | 1031 int16_t *src_diff, *coeff; |
1022 | 1032 |
1023 ENTROPY_CONTEXT ta[2], tempa[2]; | 1033 ENTROPY_CONTEXT ta[2], tempa[2]; |
1024 ENTROPY_CONTEXT tl[2], templ[2]; | 1034 ENTROPY_CONTEXT tl[2], templ[2]; |
1025 TX_TYPE tx_type = DCT_DCT; | 1035 |
1026 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 1036 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
1027 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 1037 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
1028 int idx, idy, block; | 1038 int idx, idy; |
1029 uint8_t best_dst[8 * 8]; | 1039 uint8_t best_dst[8 * 8]; |
1030 | 1040 |
1031 assert(ib < 4); | 1041 assert(ib < 4); |
1032 | 1042 |
1033 vpx_memcpy(ta, a, sizeof(ta)); | 1043 vpx_memcpy(ta, a, sizeof(ta)); |
1034 vpx_memcpy(tl, l, sizeof(tl)); | 1044 vpx_memcpy(tl, l, sizeof(tl)); |
1035 xd->this_mi->mbmi.tx_size = TX_4X4; | 1045 xd->mi_8x8[0]->mbmi.tx_size = TX_4X4; |
1036 | 1046 |
1037 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { | 1047 for (mode = DC_PRED; mode <= TM_PRED; ++mode) { |
1038 int64_t this_rd; | 1048 int64_t this_rd; |
1039 int ratey = 0; | 1049 int ratey = 0; |
1040 | 1050 |
1041 if (!(cpi->sf.intra_y_mode_mask & (1 << mode))) | 1051 if (!(cpi->sf.intra_y_mode_mask[TX_4X4] & (1 << mode))) |
1042 continue; | 1052 continue; |
1043 | 1053 |
1044 // Only do the oblique modes if the best so far is | 1054 // Only do the oblique modes if the best so far is |
1045 // one of the neighboring directional modes | 1055 // one of the neighboring directional modes |
1046 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { | 1056 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { |
1047 if (conditional_skipintra(mode, *best_mode)) | 1057 if (conditional_skipintra(mode, *best_mode)) |
1048 continue; | 1058 continue; |
1049 } | 1059 } |
1050 | 1060 |
1051 rate = bmode_costs[mode]; | 1061 rate = bmode_costs[mode]; |
1052 distortion = 0; | 1062 distortion = 0; |
1053 | 1063 |
1054 vpx_memcpy(tempa, ta, sizeof(ta)); | 1064 vpx_memcpy(tempa, ta, sizeof(ta)); |
1055 vpx_memcpy(templ, tl, sizeof(tl)); | 1065 vpx_memcpy(templ, tl, sizeof(tl)); |
1056 | 1066 |
1057 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { | 1067 for (idy = 0; idy < num_4x4_blocks_high; ++idy) { |
1058 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { | 1068 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) { |
1059 int64_t ssz; | 1069 int64_t ssz; |
1060 const int16_t *scan; | 1070 const int16_t *scan; |
| 1071 const int16_t *nb; |
1061 uint8_t *src = src_init + idx * 4 + idy * 4 * src_stride; | 1072 uint8_t *src = src_init + idx * 4 + idy * 4 * src_stride; |
1062 uint8_t *dst = dst_init + idx * 4 + idy * 4 * dst_stride; | 1073 uint8_t *dst = dst_init + idx * 4 + idy * 4 * dst_stride; |
1063 | 1074 const int block = ib + idy * 2 + idx; |
1064 block = ib + idy * 2 + idx; | 1075 TX_TYPE tx_type; |
1065 xd->this_mi->bmi[block].as_mode = mode; | 1076 xd->mi_8x8[0]->bmi[block].as_mode = mode; |
1066 src_diff = raster_block_offset_int16(BLOCK_8X8, block, p->src_diff); | 1077 src_diff = raster_block_offset_int16(BLOCK_8X8, block, p->src_diff); |
1067 coeff = BLOCK_OFFSET(x->plane[0].coeff, block); | 1078 coeff = BLOCK_OFFSET(x->plane[0].coeff, block); |
1068 vp9_predict_intra_block(xd, block, 1, | 1079 vp9_predict_intra_block(xd, block, 1, |
1069 TX_4X4, mode, | 1080 TX_4X4, mode, |
1070 x->skip_encode ? src : dst, | 1081 x->skip_encode ? src : dst, |
1071 x->skip_encode ? src_stride : dst_stride, | 1082 x->skip_encode ? src_stride : dst_stride, |
1072 dst, dst_stride); | 1083 dst, dst_stride); |
1073 vp9_subtract_block(4, 4, src_diff, 8, | 1084 vp9_subtract_block(4, 4, src_diff, 8, |
1074 src, src_stride, | 1085 src, src_stride, |
1075 dst, dst_stride); | 1086 dst, dst_stride); |
1076 | 1087 |
1077 tx_type = get_tx_type_4x4(PLANE_TYPE_Y_WITH_DC, xd, block); | 1088 tx_type = get_tx_type_4x4(PLANE_TYPE_Y_WITH_DC, xd, block); |
1078 if (tx_type != DCT_DCT) { | 1089 get_scan_nb_4x4(tx_type, &scan, &nb); |
| 1090 |
| 1091 if (tx_type != DCT_DCT) |
1079 vp9_short_fht4x4(src_diff, coeff, 8, tx_type); | 1092 vp9_short_fht4x4(src_diff, coeff, 8, tx_type); |
1080 x->quantize_b_4x4(x, block, tx_type, 16); | 1093 else |
1081 } else { | 1094 x->fwd_txm4x4(src_diff, coeff, 8); |
1082 x->fwd_txm4x4(src_diff, coeff, 16); | |
1083 x->quantize_b_4x4(x, block, tx_type, 16); | |
1084 } | |
1085 | 1095 |
1086 scan = get_scan_4x4(get_tx_type_4x4(PLANE_TYPE_Y_WITH_DC, xd, block)); | 1096 vp9_regular_quantize_b_4x4(x, 16, block, scan, get_iscan_4x4(tx_type)); |
| 1097 |
1087 ratey += cost_coeffs(x, 0, block, | 1098 ratey += cost_coeffs(x, 0, block, |
1088 tempa + idx, templ + idy, TX_4X4, scan, | 1099 tempa + idx, templ + idy, TX_4X4, scan, nb); |
1089 vp9_get_coef_neighbors_handle(scan)); | |
1090 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block), | 1100 distortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, block), |
1091 16, &ssz) >> 2; | 1101 16, &ssz) >> 2; |
1092 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) | 1102 if (RDCOST(x->rdmult, x->rddiv, ratey, distortion) >= best_rd) |
1093 goto next; | 1103 goto next; |
1094 | 1104 |
1095 if (tx_type != DCT_DCT) | 1105 if (tx_type != DCT_DCT) |
1096 vp9_short_iht4x4_add(BLOCK_OFFSET(pd->dqcoeff, block), | 1106 vp9_iht4x4_16_add(BLOCK_OFFSET(pd->dqcoeff, block), |
1097 dst, pd->dst.stride, tx_type); | 1107 dst, pd->dst.stride, tx_type); |
1098 else | 1108 else |
1099 xd->inv_txm4x4_add(BLOCK_OFFSET(pd->dqcoeff, block), | 1109 xd->itxm_add(BLOCK_OFFSET(pd->dqcoeff, block), dst, pd->dst.stride, |
1100 dst, pd->dst.stride); | 1110 16); |
1101 } | 1111 } |
1102 } | 1112 } |
1103 | 1113 |
1104 rate += ratey; | 1114 rate += ratey; |
1105 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); | 1115 this_rd = RDCOST(x->rdmult, x->rddiv, rate, distortion); |
1106 | 1116 |
1107 if (this_rd < best_rd) { | 1117 if (this_rd < best_rd) { |
1108 *bestrate = rate; | 1118 *bestrate = rate; |
1109 *bestratey = ratey; | 1119 *bestratey = ratey; |
1110 *bestdistortion = distortion; | 1120 *bestdistortion = distortion; |
(...skipping 20 matching lines...) Expand all Loading... |
1131 } | 1141 } |
1132 | 1142 |
1133 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP * const cpi, | 1143 static int64_t rd_pick_intra_sub_8x8_y_mode(VP9_COMP * const cpi, |
1134 MACROBLOCK * const mb, | 1144 MACROBLOCK * const mb, |
1135 int * const rate, | 1145 int * const rate, |
1136 int * const rate_y, | 1146 int * const rate_y, |
1137 int64_t * const distortion, | 1147 int64_t * const distortion, |
1138 int64_t best_rd) { | 1148 int64_t best_rd) { |
1139 int i, j; | 1149 int i, j; |
1140 MACROBLOCKD *const xd = &mb->e_mbd; | 1150 MACROBLOCKD *const xd = &mb->e_mbd; |
1141 MODE_INFO *const mic = xd->this_mi; | 1151 MODE_INFO *const mic = xd->mi_8x8[0]; |
1142 const MODE_INFO *above_mi = xd->mi_8x8[-xd->mode_info_stride]; | 1152 const MODE_INFO *above_mi = xd->mi_8x8[-xd->mode_info_stride]; |
1143 const MODE_INFO *left_mi = xd->mi_8x8[-1]; | 1153 const MODE_INFO *left_mi = xd->left_available ? xd->mi_8x8[-1] : NULL; |
1144 const BLOCK_SIZE bsize = xd->this_mi->mbmi.sb_type; | 1154 const BLOCK_SIZE bsize = xd->mi_8x8[0]->mbmi.sb_type; |
1145 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 1155 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
1146 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 1156 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
1147 int idx, idy; | 1157 int idx, idy; |
1148 int cost = 0; | 1158 int cost = 0; |
1149 int64_t total_distortion = 0; | 1159 int64_t total_distortion = 0; |
1150 int tot_rate_y = 0; | 1160 int tot_rate_y = 0; |
1151 int64_t total_rd = 0; | 1161 int64_t total_rd = 0; |
1152 ENTROPY_CONTEXT t_above[4], t_left[4]; | 1162 ENTROPY_CONTEXT t_above[4], t_left[4]; |
1153 int *bmode_costs; | 1163 int *bmode_costs; |
1154 | 1164 |
1155 vpx_memcpy(t_above, xd->plane[0].above_context, sizeof(t_above)); | 1165 vpx_memcpy(t_above, xd->plane[0].above_context, sizeof(t_above)); |
1156 vpx_memcpy(t_left, xd->plane[0].left_context, sizeof(t_left)); | 1166 vpx_memcpy(t_left, xd->plane[0].left_context, sizeof(t_left)); |
1157 | 1167 |
1158 bmode_costs = mb->mbmode_cost; | 1168 bmode_costs = mb->mbmode_cost; |
1159 | 1169 |
1160 // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block. | 1170 // Pick modes for each sub-block (of size 4x4, 4x8, or 8x4) in an 8x8 block. |
1161 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | 1171 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
1162 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { | 1172 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { |
1163 MB_PREDICTION_MODE best_mode = DC_PRED; | 1173 MB_PREDICTION_MODE best_mode = DC_PRED; |
1164 int r = INT_MAX, ry = INT_MAX; | 1174 int r = INT_MAX, ry = INT_MAX; |
1165 int64_t d = INT64_MAX, this_rd = INT64_MAX; | 1175 int64_t d = INT64_MAX, this_rd = INT64_MAX; |
1166 i = idy * 2 + idx; | 1176 i = idy * 2 + idx; |
1167 if (cpi->common.frame_type == KEY_FRAME) { | 1177 if (cpi->common.frame_type == KEY_FRAME) { |
1168 const MB_PREDICTION_MODE A = above_block_mode(mic, above_mi, i); | 1178 const MB_PREDICTION_MODE A = above_block_mode(mic, above_mi, i); |
1169 const MB_PREDICTION_MODE L = (xd->left_available || idx) ? | 1179 const MB_PREDICTION_MODE L = left_block_mode(mic, left_mi, i); |
1170 left_block_mode(mic, left_mi, i) : | |
1171 DC_PRED; | |
1172 | 1180 |
1173 bmode_costs = mb->y_mode_costs[A][L]; | 1181 bmode_costs = mb->y_mode_costs[A][L]; |
1174 } | 1182 } |
1175 | 1183 |
1176 this_rd = rd_pick_intra4x4block(cpi, mb, i, &best_mode, bmode_costs, | 1184 this_rd = rd_pick_intra4x4block(cpi, mb, i, &best_mode, bmode_costs, |
1177 t_above + idx, t_left + idy, &r, &ry, &d, | 1185 t_above + idx, t_left + idy, &r, &ry, &d, |
1178 bsize, best_rd - total_rd); | 1186 bsize, best_rd - total_rd); |
1179 if (this_rd >= best_rd - total_rd) | 1187 if (this_rd >= best_rd - total_rd) |
1180 return INT64_MAX; | 1188 return INT64_MAX; |
1181 | 1189 |
(...skipping 23 matching lines...) Expand all Loading... |
1205 | 1213 |
1206 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, | 1214 static int64_t rd_pick_intra_sby_mode(VP9_COMP *cpi, MACROBLOCK *x, |
1207 int *rate, int *rate_tokenonly, | 1215 int *rate, int *rate_tokenonly, |
1208 int64_t *distortion, int *skippable, | 1216 int64_t *distortion, int *skippable, |
1209 BLOCK_SIZE bsize, | 1217 BLOCK_SIZE bsize, |
1210 int64_t tx_cache[TX_MODES], | 1218 int64_t tx_cache[TX_MODES], |
1211 int64_t best_rd) { | 1219 int64_t best_rd) { |
1212 MB_PREDICTION_MODE mode; | 1220 MB_PREDICTION_MODE mode; |
1213 MB_PREDICTION_MODE mode_selected = DC_PRED; | 1221 MB_PREDICTION_MODE mode_selected = DC_PRED; |
1214 MACROBLOCKD *const xd = &x->e_mbd; | 1222 MACROBLOCKD *const xd = &x->e_mbd; |
1215 MODE_INFO *const mic = xd->this_mi; | 1223 MODE_INFO *const mic = xd->mi_8x8[0]; |
1216 int this_rate, this_rate_tokenonly, s; | 1224 int this_rate, this_rate_tokenonly, s; |
1217 int64_t this_distortion, this_rd; | 1225 int64_t this_distortion, this_rd; |
1218 TX_SIZE best_tx = TX_4X4; | 1226 TX_SIZE best_tx = TX_4X4; |
1219 int i; | 1227 int i; |
1220 int *bmode_costs = x->mbmode_cost; | 1228 int *bmode_costs = x->mbmode_cost; |
1221 | 1229 |
1222 if (cpi->sf.tx_size_search_method == USE_FULL_RD) | 1230 if (cpi->sf.tx_size_search_method == USE_FULL_RD) |
1223 for (i = 0; i < TX_MODES; i++) | 1231 for (i = 0; i < TX_MODES; i++) |
1224 tx_cache[i] = INT64_MAX; | 1232 tx_cache[i] = INT64_MAX; |
1225 | 1233 |
1226 /* Y Search for intra prediction mode */ | 1234 /* Y Search for intra prediction mode */ |
1227 for (mode = DC_PRED; mode <= TM_PRED; mode++) { | 1235 for (mode = DC_PRED; mode <= TM_PRED; mode++) { |
1228 int64_t local_tx_cache[TX_MODES]; | 1236 int64_t local_tx_cache[TX_MODES]; |
1229 MODE_INFO *above_mi = xd->mi_8x8[-xd->mode_info_stride]; | 1237 MODE_INFO *above_mi = xd->mi_8x8[-xd->mode_info_stride]; |
1230 MODE_INFO *left_mi = xd->mi_8x8[-1]; | 1238 MODE_INFO *left_mi = xd->left_available ? xd->mi_8x8[-1] : NULL; |
1231 | 1239 |
1232 if (!(cpi->sf.intra_y_mode_mask & (1 << mode))) | 1240 if (!(cpi->sf.intra_y_mode_mask[max_txsize_lookup[bsize]] & (1 << mode))) |
1233 continue; | 1241 continue; |
1234 | 1242 |
1235 if (cpi->common.frame_type == KEY_FRAME) { | 1243 if (cpi->common.frame_type == KEY_FRAME) { |
1236 const MB_PREDICTION_MODE A = above_block_mode(mic, above_mi, 0); | 1244 const MB_PREDICTION_MODE A = above_block_mode(mic, above_mi, 0); |
1237 const MB_PREDICTION_MODE L = xd->left_available ? | 1245 const MB_PREDICTION_MODE L = left_block_mode(mic, left_mi, 0); |
1238 left_block_mode(mic, left_mi, 0) : DC_PRED; | |
1239 | 1246 |
1240 bmode_costs = x->y_mode_costs[A][L]; | 1247 bmode_costs = x->y_mode_costs[A][L]; |
1241 } | 1248 } |
1242 mic->mbmi.mode = mode; | 1249 mic->mbmi.mode = mode; |
1243 | 1250 |
1244 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, &s, NULL, | 1251 super_block_yrd(cpi, x, &this_rate_tokenonly, &this_distortion, &s, NULL, |
1245 bsize, local_tx_cache, best_rd); | 1252 bsize, local_tx_cache, best_rd); |
1246 | 1253 |
1247 if (this_rate_tokenonly == INT_MAX) | 1254 if (this_rate_tokenonly == INT_MAX) |
1248 continue; | 1255 continue; |
(...skipping 21 matching lines...) Expand all Loading... |
1270 } | 1277 } |
1271 } | 1278 } |
1272 } | 1279 } |
1273 | 1280 |
1274 mic->mbmi.mode = mode_selected; | 1281 mic->mbmi.mode = mode_selected; |
1275 mic->mbmi.tx_size = best_tx; | 1282 mic->mbmi.tx_size = best_tx; |
1276 | 1283 |
1277 return best_rd; | 1284 return best_rd; |
1278 } | 1285 } |
1279 | 1286 |
1280 static void super_block_uvrd(VP9_COMMON *const cm, MACROBLOCK *x, | 1287 static void super_block_uvrd(VP9_COMP *const cpi, MACROBLOCK *x, |
1281 int *rate, int64_t *distortion, int *skippable, | 1288 int *rate, int64_t *distortion, int *skippable, |
1282 int64_t *sse, BLOCK_SIZE bsize, | 1289 int64_t *sse, BLOCK_SIZE bsize, |
1283 int64_t ref_best_rd) { | 1290 int64_t ref_best_rd) { |
1284 MACROBLOCKD *const xd = &x->e_mbd; | 1291 MACROBLOCKD *const xd = &x->e_mbd; |
1285 MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi; | 1292 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
1286 TX_SIZE uv_txfm_size = get_uv_tx_size(mbmi); | 1293 TX_SIZE uv_txfm_size = get_uv_tx_size(mbmi); |
1287 int plane; | 1294 int plane; |
1288 int pnrate = 0, pnskip = 1; | 1295 int pnrate = 0, pnskip = 1; |
1289 int64_t pndist = 0, pnsse = 0; | 1296 int64_t pndist = 0, pnsse = 0; |
1290 | 1297 |
1291 if (ref_best_rd < 0) | 1298 if (ref_best_rd < 0) |
1292 goto term; | 1299 goto term; |
1293 | 1300 |
1294 if (is_inter_block(mbmi)) | 1301 if (is_inter_block(mbmi)) |
1295 vp9_subtract_sbuv(x, bsize); | 1302 vp9_subtract_sbuv(x, bsize); |
1296 | 1303 |
1297 *rate = 0; | 1304 *rate = 0; |
1298 *distortion = 0; | 1305 *distortion = 0; |
1299 *sse = 0; | 1306 *sse = 0; |
1300 *skippable = 1; | 1307 *skippable = 1; |
1301 | 1308 |
1302 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { | 1309 for (plane = 1; plane < MAX_MB_PLANE; ++plane) { |
1303 txfm_rd_in_plane(x, &pnrate, &pndist, &pnskip, &pnsse, | 1310 txfm_rd_in_plane(x, &cpi->rdcost_stack, &pnrate, &pndist, &pnskip, &pnsse, |
1304 ref_best_rd, plane, bsize, uv_txfm_size); | 1311 ref_best_rd, plane, bsize, uv_txfm_size); |
1305 if (pnrate == INT_MAX) | 1312 if (pnrate == INT_MAX) |
1306 goto term; | 1313 goto term; |
1307 *rate += pnrate; | 1314 *rate += pnrate; |
1308 *distortion += pndist; | 1315 *distortion += pndist; |
1309 *sse += pnsse; | 1316 *sse += pnsse; |
1310 *skippable &= pnskip; | 1317 *skippable &= pnskip; |
1311 } | 1318 } |
1312 return; | 1319 return; |
1313 | 1320 |
(...skipping 11 matching lines...) Expand all Loading... |
1325 BLOCK_SIZE bsize) { | 1332 BLOCK_SIZE bsize) { |
1326 MB_PREDICTION_MODE mode; | 1333 MB_PREDICTION_MODE mode; |
1327 MB_PREDICTION_MODE mode_selected = DC_PRED; | 1334 MB_PREDICTION_MODE mode_selected = DC_PRED; |
1328 int64_t best_rd = INT64_MAX, this_rd; | 1335 int64_t best_rd = INT64_MAX, this_rd; |
1329 int this_rate_tokenonly, this_rate, s; | 1336 int this_rate_tokenonly, this_rate, s; |
1330 int64_t this_distortion, this_sse; | 1337 int64_t this_distortion, this_sse; |
1331 | 1338 |
1332 // int mode_mask = (bsize <= BLOCK_8X8) | 1339 // int mode_mask = (bsize <= BLOCK_8X8) |
1333 // ? ALL_INTRA_MODES : cpi->sf.intra_uv_mode_mask; | 1340 // ? ALL_INTRA_MODES : cpi->sf.intra_uv_mode_mask; |
1334 | 1341 |
1335 for (mode = DC_PRED; mode <= TM_PRED; mode++) { | 1342 for (mode = DC_PRED; mode <= TM_PRED; mode ++) { |
1336 // if (!(mode_mask & (1 << mode))) | 1343 // if (!(mode_mask & (1 << mode))) |
1337 if (!(cpi->sf.intra_uv_mode_mask & (1 << mode))) | 1344 if (!(cpi->sf.intra_uv_mode_mask[max_uv_txsize_lookup[bsize]] |
| 1345 & (1 << mode))) |
1338 continue; | 1346 continue; |
1339 | 1347 |
1340 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = mode; | 1348 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = mode; |
1341 | 1349 |
1342 super_block_uvrd(&cpi->common, x, &this_rate_tokenonly, | 1350 super_block_uvrd(cpi, x, &this_rate_tokenonly, |
1343 &this_distortion, &s, &this_sse, bsize, best_rd); | 1351 &this_distortion, &s, &this_sse, bsize, best_rd); |
1344 if (this_rate_tokenonly == INT_MAX) | 1352 if (this_rate_tokenonly == INT_MAX) |
1345 continue; | 1353 continue; |
1346 this_rate = this_rate_tokenonly + | 1354 this_rate = this_rate_tokenonly + |
1347 x->intra_uv_mode_cost[cpi->common.frame_type][mode]; | 1355 x->intra_uv_mode_cost[cpi->common.frame_type][mode]; |
1348 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); | 1356 this_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_distortion); |
1349 | 1357 |
1350 if (this_rd < best_rd) { | 1358 if (this_rd < best_rd) { |
1351 mode_selected = mode; | 1359 mode_selected = mode; |
1352 best_rd = this_rd; | 1360 best_rd = this_rd; |
(...skipping 10 matching lines...) Expand all Loading... |
1363 } | 1371 } |
1364 | 1372 |
1365 static int64_t rd_sbuv_dcpred(VP9_COMP *cpi, MACROBLOCK *x, | 1373 static int64_t rd_sbuv_dcpred(VP9_COMP *cpi, MACROBLOCK *x, |
1366 int *rate, int *rate_tokenonly, | 1374 int *rate, int *rate_tokenonly, |
1367 int64_t *distortion, int *skippable, | 1375 int64_t *distortion, int *skippable, |
1368 BLOCK_SIZE bsize) { | 1376 BLOCK_SIZE bsize) { |
1369 int64_t this_rd; | 1377 int64_t this_rd; |
1370 int64_t this_sse; | 1378 int64_t this_sse; |
1371 | 1379 |
1372 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = DC_PRED; | 1380 x->e_mbd.mi_8x8[0]->mbmi.uv_mode = DC_PRED; |
1373 super_block_uvrd(&cpi->common, x, rate_tokenonly, | 1381 super_block_uvrd(cpi, x, rate_tokenonly, distortion, |
1374 distortion, skippable, &this_sse, bsize, INT64_MAX); | 1382 skippable, &this_sse, bsize, INT64_MAX); |
1375 *rate = *rate_tokenonly + | 1383 *rate = *rate_tokenonly + |
1376 x->intra_uv_mode_cost[cpi->common.frame_type][DC_PRED]; | 1384 x->intra_uv_mode_cost[cpi->common.frame_type][DC_PRED]; |
1377 this_rd = RDCOST(x->rdmult, x->rddiv, *rate, *distortion); | 1385 this_rd = RDCOST(x->rdmult, x->rddiv, *rate, *distortion); |
1378 | 1386 |
1379 return this_rd; | 1387 return this_rd; |
1380 } | 1388 } |
1381 | 1389 |
1382 static void choose_intra_uv_mode(VP9_COMP *cpi, BLOCK_SIZE bsize, | 1390 static void choose_intra_uv_mode(VP9_COMP *cpi, BLOCK_SIZE bsize, |
1383 int *rate_uv, int *rate_uv_tokenonly, | 1391 int *rate_uv, int *rate_uv_tokenonly, |
1384 int64_t *dist_uv, int *skip_uv, | 1392 int64_t *dist_uv, int *skip_uv, |
(...skipping 12 matching lines...) Expand all Loading... |
1397 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, | 1405 rate_uv, rate_uv_tokenonly, dist_uv, skip_uv, |
1398 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); | 1406 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); |
1399 } | 1407 } |
1400 *mode_uv = x->e_mbd.mi_8x8[0]->mbmi.uv_mode; | 1408 *mode_uv = x->e_mbd.mi_8x8[0]->mbmi.uv_mode; |
1401 } | 1409 } |
1402 | 1410 |
1403 static int cost_mv_ref(VP9_COMP *cpi, MB_PREDICTION_MODE mode, | 1411 static int cost_mv_ref(VP9_COMP *cpi, MB_PREDICTION_MODE mode, |
1404 int mode_context) { | 1412 int mode_context) { |
1405 MACROBLOCK *const x = &cpi->mb; | 1413 MACROBLOCK *const x = &cpi->mb; |
1406 MACROBLOCKD *const xd = &x->e_mbd; | 1414 MACROBLOCKD *const xd = &x->e_mbd; |
1407 const int segment_id = xd->this_mi->mbmi.segment_id; | 1415 const int segment_id = xd->mi_8x8[0]->mbmi.segment_id; |
1408 | 1416 |
1409 // Don't account for mode here if segment skip is enabled. | 1417 // Don't account for mode here if segment skip is enabled. |
1410 if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) { | 1418 if (!vp9_segfeature_active(&cpi->common.seg, segment_id, SEG_LVL_SKIP)) { |
1411 assert(is_inter_mode(mode)); | 1419 assert(is_inter_mode(mode)); |
1412 return x->inter_mode_cost[mode_context][mode - NEARESTMV]; | 1420 return x->inter_mode_cost[mode_context][inter_mode_offset(mode)]; |
1413 } else { | 1421 } else { |
1414 return 0; | 1422 return 0; |
1415 } | 1423 } |
1416 } | 1424 } |
1417 | 1425 |
1418 void vp9_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv) { | 1426 void vp9_set_mbmode_and_mvs(MACROBLOCK *x, MB_PREDICTION_MODE mb, int_mv *mv) { |
1419 x->e_mbd.mi_8x8[0]->mbmi.mode = mb; | 1427 x->e_mbd.mi_8x8[0]->mbmi.mode = mb; |
1420 x->e_mbd.mi_8x8[0]->mbmi.mv[0].as_int = mv->as_int; | 1428 x->e_mbd.mi_8x8[0]->mbmi.mv[0].as_int = mv->as_int; |
1421 } | 1429 } |
1422 | 1430 |
1423 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 1431 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
1424 BLOCK_SIZE bsize, | 1432 BLOCK_SIZE bsize, |
1425 int_mv *frame_mv, | 1433 int_mv *frame_mv, |
1426 int mi_row, int mi_col, | 1434 int mi_row, int mi_col, |
1427 int_mv single_newmv[MAX_REF_FRAMES], | 1435 int_mv single_newmv[MAX_REF_FRAMES], |
1428 int *rate_mv); | 1436 int *rate_mv); |
1429 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | |
1430 BLOCK_SIZE bsize, | |
1431 int mi_row, int mi_col, | |
1432 int_mv *tmp_mv, int *rate_mv); | |
1433 | 1437 |
1434 static int labels2mode(MACROBLOCK *x, int i, | 1438 static int labels2mode(MACROBLOCK *x, int i, |
1435 MB_PREDICTION_MODE this_mode, | 1439 MB_PREDICTION_MODE this_mode, |
1436 int_mv *this_mv, int_mv *this_second_mv, | 1440 int_mv *this_mv, int_mv *this_second_mv, |
1437 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], | 1441 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES], |
1438 int_mv seg_mvs[MAX_REF_FRAMES], | 1442 int_mv seg_mvs[MAX_REF_FRAMES], |
1439 int_mv *best_ref_mv, | 1443 int_mv *best_ref_mv, |
1440 int_mv *second_best_ref_mv, | 1444 int_mv *second_best_ref_mv, |
1441 int *mvjcost, int *mvcost[2], VP9_COMP *cpi) { | 1445 int *mvjcost, int *mvcost[2], VP9_COMP *cpi) { |
1442 MACROBLOCKD *const xd = &x->e_mbd; | 1446 MACROBLOCKD *const xd = &x->e_mbd; |
1443 MODE_INFO *const mic = xd->this_mi; | 1447 MODE_INFO *const mic = xd->mi_8x8[0]; |
1444 MB_MODE_INFO *mbmi = &mic->mbmi; | 1448 MB_MODE_INFO *mbmi = &mic->mbmi; |
1445 int cost = 0, thismvcost = 0; | 1449 int cost = 0, thismvcost = 0; |
1446 int idx, idy; | 1450 int idx, idy; |
1447 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; | 1451 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[mbmi->sb_type]; |
1448 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; | 1452 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[mbmi->sb_type]; |
1449 const int has_second_rf = has_second_ref(mbmi); | 1453 const int has_second_rf = has_second_ref(mbmi); |
1450 | 1454 |
1451 /* We have to be careful retrieving previously-encoded motion vectors. | 1455 /* We have to be careful retrieving previously-encoded motion vectors. |
1452 Ones from this macroblock have to be pulled from the BLOCKD array | 1456 Ones from this macroblock have to be pulled from the BLOCKD array |
1453 as they have not yet made it to the bmi array in our MB_MODE_INFO. */ | 1457 as they have not yet made it to the bmi array in our MB_MODE_INFO. */ |
1454 MB_PREDICTION_MODE m; | 1458 MB_PREDICTION_MODE m; |
1455 | 1459 |
1456 // the only time we should do costing for new motion vector or mode | 1460 // the only time we should do costing for new motion vector or mode |
1457 // is when we are on a new label (jbb May 08, 2007) | 1461 // is when we are on a new label (jbb May 08, 2007) |
1458 switch (m = this_mode) { | 1462 switch (m = this_mode) { |
1459 case NEWMV: | 1463 case NEWMV: |
1460 this_mv->as_int = seg_mvs[mbmi->ref_frame[0]].as_int; | 1464 this_mv->as_int = seg_mvs[mbmi->ref_frame[0]].as_int; |
1461 thismvcost = vp9_mv_bit_cost(this_mv, best_ref_mv, mvjcost, mvcost, | 1465 thismvcost = vp9_mv_bit_cost(&this_mv->as_mv, &best_ref_mv->as_mv, |
1462 102); | 1466 mvjcost, mvcost, MV_COST_WEIGHT_SUB); |
1463 if (has_second_rf) { | 1467 if (has_second_rf) { |
1464 this_second_mv->as_int = seg_mvs[mbmi->ref_frame[1]].as_int; | 1468 this_second_mv->as_int = seg_mvs[mbmi->ref_frame[1]].as_int; |
1465 thismvcost += vp9_mv_bit_cost(this_second_mv, second_best_ref_mv, | 1469 thismvcost += vp9_mv_bit_cost(&this_second_mv->as_mv, |
1466 mvjcost, mvcost, 102); | 1470 &second_best_ref_mv->as_mv, |
| 1471 mvjcost, mvcost, MV_COST_WEIGHT_SUB); |
1467 } | 1472 } |
1468 break; | 1473 break; |
1469 case NEARESTMV: | 1474 case NEARESTMV: |
1470 this_mv->as_int = frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int; | 1475 this_mv->as_int = frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int; |
1471 if (has_second_rf) | 1476 if (has_second_rf) |
1472 this_second_mv->as_int = | 1477 this_second_mv->as_int = |
1473 frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int; | 1478 frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int; |
1474 break; | 1479 break; |
1475 case NEARMV: | 1480 case NEARMV: |
1476 this_mv->as_int = frame_mv[NEARMV][mbmi->ref_frame[0]].as_int; | 1481 this_mv->as_int = frame_mv[NEARMV][mbmi->ref_frame[0]].as_int; |
(...skipping 10 matching lines...) Expand all Loading... |
1487 break; | 1492 break; |
1488 } | 1493 } |
1489 | 1494 |
1490 cost = cost_mv_ref(cpi, this_mode, | 1495 cost = cost_mv_ref(cpi, this_mode, |
1491 mbmi->mode_context[mbmi->ref_frame[0]]); | 1496 mbmi->mode_context[mbmi->ref_frame[0]]); |
1492 | 1497 |
1493 mic->bmi[i].as_mv[0].as_int = this_mv->as_int; | 1498 mic->bmi[i].as_mv[0].as_int = this_mv->as_int; |
1494 if (has_second_rf) | 1499 if (has_second_rf) |
1495 mic->bmi[i].as_mv[1].as_int = this_second_mv->as_int; | 1500 mic->bmi[i].as_mv[1].as_int = this_second_mv->as_int; |
1496 | 1501 |
1497 x->partition_info->bmi[i].mode = m; | 1502 mic->bmi[i].as_mode = m; |
| 1503 |
1498 for (idy = 0; idy < num_4x4_blocks_high; ++idy) | 1504 for (idy = 0; idy < num_4x4_blocks_high; ++idy) |
1499 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) | 1505 for (idx = 0; idx < num_4x4_blocks_wide; ++idx) |
1500 vpx_memcpy(&mic->bmi[i + idy * 2 + idx], | 1506 vpx_memcpy(&mic->bmi[i + idy * 2 + idx], |
1501 &mic->bmi[i], sizeof(mic->bmi[i])); | 1507 &mic->bmi[i], sizeof(mic->bmi[i])); |
1502 | 1508 |
1503 cost += thismvcost; | 1509 cost += thismvcost; |
1504 return cost; | 1510 return cost; |
1505 } | 1511 } |
1506 | 1512 |
1507 static int64_t encode_inter_mb_segment(VP9_COMP *cpi, | 1513 static int64_t encode_inter_mb_segment(VP9_COMP *cpi, |
1508 MACROBLOCK *x, | 1514 MACROBLOCK *x, |
1509 int64_t best_yrd, | 1515 int64_t best_yrd, |
1510 int i, | 1516 int i, |
1511 int *labelyrate, | 1517 int *labelyrate, |
1512 int64_t *distortion, int64_t *sse, | 1518 int64_t *distortion, int64_t *sse, |
1513 ENTROPY_CONTEXT *ta, | 1519 ENTROPY_CONTEXT *ta, |
1514 ENTROPY_CONTEXT *tl) { | 1520 ENTROPY_CONTEXT *tl) { |
1515 int k; | 1521 int k; |
1516 MACROBLOCKD *xd = &x->e_mbd; | 1522 MACROBLOCKD *xd = &x->e_mbd; |
1517 struct macroblockd_plane *const pd = &xd->plane[0]; | 1523 struct macroblockd_plane *const pd = &xd->plane[0]; |
1518 MODE_INFO *const mi = xd->this_mi; | 1524 struct macroblock_plane *const p = &x->plane[0]; |
| 1525 MODE_INFO *const mi = xd->mi_8x8[0]; |
1519 const BLOCK_SIZE bsize = mi->mbmi.sb_type; | 1526 const BLOCK_SIZE bsize = mi->mbmi.sb_type; |
1520 const int width = plane_block_width(bsize, pd); | 1527 const int width = plane_block_width(bsize, pd); |
1521 const int height = plane_block_height(bsize, pd); | 1528 const int height = plane_block_height(bsize, pd); |
1522 int idx, idy; | 1529 int idx, idy; |
1523 const int src_stride = x->plane[0].src.stride; | 1530 |
1524 uint8_t* const src = raster_block_offset_uint8(BLOCK_8X8, i, | 1531 uint8_t *const src = raster_block_offset_uint8(BLOCK_8X8, i, |
1525 x->plane[0].src.buf, | 1532 p->src.buf, p->src.stride); |
1526 src_stride); | 1533 uint8_t *const dst = raster_block_offset_uint8(BLOCK_8X8, i, |
1527 int16_t* src_diff = raster_block_offset_int16(BLOCK_8X8, i, | |
1528 x->plane[0].src_diff); | |
1529 int16_t* coeff = BLOCK_OFFSET(x->plane[0].coeff, i); | |
1530 uint8_t* const dst = raster_block_offset_uint8(BLOCK_8X8, i, | |
1531 pd->dst.buf, pd->dst.stride); | 1534 pd->dst.buf, pd->dst.stride); |
1532 int64_t thisdistortion = 0, thissse = 0; | 1535 int64_t thisdistortion = 0, thissse = 0; |
1533 int thisrate = 0; | 1536 int thisrate = 0, ref; |
1534 int ref, second_ref = has_second_ref(&mi->mbmi); | 1537 const int is_compound = has_second_ref(&mi->mbmi); |
1535 | 1538 for (ref = 0; ref < 1 + is_compound; ++ref) { |
1536 for (ref = 0; ref < 1 + second_ref; ++ref) { | |
1537 const uint8_t *pre = raster_block_offset_uint8(BLOCK_8X8, i, | 1539 const uint8_t *pre = raster_block_offset_uint8(BLOCK_8X8, i, |
1538 pd->pre[ref].buf, pd->pre[ref].stride); | 1540 pd->pre[ref].buf, pd->pre[ref].stride); |
1539 vp9_build_inter_predictor(pre, pd->pre[ref].stride, | 1541 vp9_build_inter_predictor(pre, pd->pre[ref].stride, |
1540 dst, pd->dst.stride, | 1542 dst, pd->dst.stride, |
1541 &mi->bmi[i].as_mv[ref].as_mv, | 1543 &mi->bmi[i].as_mv[ref].as_mv, |
1542 &xd->scale_factor[ref], | 1544 &xd->scale_factor[ref], |
1543 width, height, ref, &xd->subpix, MV_PRECISION_Q3); | 1545 width, height, ref, &xd->subpix, MV_PRECISION_Q3); |
1544 } | 1546 } |
1545 | 1547 |
1546 vp9_subtract_block(height, width, src_diff, 8, src, src_stride, | 1548 vp9_subtract_block(height, width, |
| 1549 raster_block_offset_int16(BLOCK_8X8, i, p->src_diff), 8, |
| 1550 src, p->src.stride, |
1547 dst, pd->dst.stride); | 1551 dst, pd->dst.stride); |
1548 | 1552 |
1549 k = i; | 1553 k = i; |
1550 for (idy = 0; idy < height / 4; ++idy) { | 1554 for (idy = 0; idy < height / 4; ++idy) { |
1551 for (idx = 0; idx < width / 4; ++idx) { | 1555 for (idx = 0; idx < width / 4; ++idx) { |
1552 int64_t ssz, rd, rd1, rd2; | 1556 int64_t ssz, rd, rd1, rd2; |
| 1557 int16_t* coeff; |
1553 | 1558 |
1554 k += (idy * 2 + idx); | 1559 k += (idy * 2 + idx); |
1555 src_diff = raster_block_offset_int16(BLOCK_8X8, k, | 1560 coeff = BLOCK_OFFSET(p->coeff, k); |
1556 x->plane[0].src_diff); | 1561 x->fwd_txm4x4(raster_block_offset_int16(BLOCK_8X8, k, p->src_diff), |
1557 coeff = BLOCK_OFFSET(x->plane[0].coeff, k); | 1562 coeff, 8); |
1558 x->fwd_txm4x4(src_diff, coeff, 16); | 1563 vp9_regular_quantize_b_4x4(x, 16, k, get_scan_4x4(DCT_DCT), |
1559 x->quantize_b_4x4(x, k, DCT_DCT, 16); | 1564 get_iscan_4x4(DCT_DCT)); |
1560 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), | 1565 thisdistortion += vp9_block_error(coeff, BLOCK_OFFSET(pd->dqcoeff, k), |
1561 16, &ssz); | 1566 16, &ssz); |
1562 thissse += ssz; | 1567 thissse += ssz; |
1563 thisrate += cost_coeffs(x, 0, k, | 1568 thisrate += cost_coeffs(x, 0, k, |
1564 ta + (k & 1), | 1569 ta + (k & 1), |
1565 tl + (k >> 1), TX_4X4, | 1570 tl + (k >> 1), TX_4X4, |
1566 vp9_default_scan_4x4, | 1571 vp9_default_scan_4x4, |
1567 vp9_default_scan_4x4_neighbors); | 1572 vp9_default_scan_4x4_neighbors); |
1568 rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2); | 1573 rd1 = RDCOST(x->rdmult, x->rddiv, thisrate, thisdistortion >> 2); |
1569 rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2); | 1574 rd2 = RDCOST(x->rdmult, x->rddiv, 0, thissse >> 2); |
1570 rd = MIN(rd1, rd2); | 1575 rd = MIN(rd1, rd2); |
1571 if (rd >= best_yrd) | 1576 if (rd >= best_yrd) |
1572 return INT64_MAX; | 1577 return INT64_MAX; |
1573 } | 1578 } |
1574 } | 1579 } |
| 1580 |
1575 *distortion = thisdistortion >> 2; | 1581 *distortion = thisdistortion >> 2; |
1576 *labelyrate = thisrate; | 1582 *labelyrate = thisrate; |
1577 *sse = thissse >> 2; | 1583 *sse = thissse >> 2; |
1578 | 1584 |
1579 return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion); | 1585 return RDCOST(x->rdmult, x->rddiv, *labelyrate, *distortion); |
1580 } | 1586 } |
1581 | 1587 |
1582 typedef struct { | 1588 typedef struct { |
1583 int eobs; | 1589 int eobs; |
1584 int brate; | 1590 int brate; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src, | 1638 static INLINE void mi_buf_restore(MACROBLOCK *x, struct buf_2d orig_src, |
1633 struct buf_2d orig_pre[2]) { | 1639 struct buf_2d orig_pre[2]) { |
1634 MB_MODE_INFO *mbmi = &x->e_mbd.mi_8x8[0]->mbmi; | 1640 MB_MODE_INFO *mbmi = &x->e_mbd.mi_8x8[0]->mbmi; |
1635 x->plane[0].src = orig_src; | 1641 x->plane[0].src = orig_src; |
1636 x->e_mbd.plane[0].pre[0] = orig_pre[0]; | 1642 x->e_mbd.plane[0].pre[0] = orig_pre[0]; |
1637 if (has_second_ref(mbmi)) | 1643 if (has_second_ref(mbmi)) |
1638 x->e_mbd.plane[0].pre[1] = orig_pre[1]; | 1644 x->e_mbd.plane[0].pre[1] = orig_pre[1]; |
1639 } | 1645 } |
1640 | 1646 |
1641 static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, | 1647 static void rd_check_segment_txsize(VP9_COMP *cpi, MACROBLOCK *x, |
| 1648 const TileInfo *const tile, |
1642 BEST_SEG_INFO *bsi_buf, int filter_idx, | 1649 BEST_SEG_INFO *bsi_buf, int filter_idx, |
1643 int_mv seg_mvs[4][MAX_REF_FRAMES], | 1650 int_mv seg_mvs[4][MAX_REF_FRAMES], |
1644 int mi_row, int mi_col) { | 1651 int mi_row, int mi_col) { |
1645 int i, j, br = 0, idx, idy; | 1652 int i, br = 0, idx, idy; |
1646 int64_t bd = 0, block_sse = 0; | 1653 int64_t bd = 0, block_sse = 0; |
1647 MB_PREDICTION_MODE this_mode; | 1654 MB_PREDICTION_MODE this_mode; |
1648 MODE_INFO *mi = x->e_mbd.mi_8x8[0]; | 1655 MODE_INFO *mi = x->e_mbd.mi_8x8[0]; |
1649 MB_MODE_INFO *const mbmi = &mi->mbmi; | 1656 MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1657 struct macroblockd_plane *const pd = &x->e_mbd.plane[0]; |
1650 const int label_count = 4; | 1658 const int label_count = 4; |
1651 int64_t this_segment_rd = 0; | 1659 int64_t this_segment_rd = 0; |
1652 int label_mv_thresh; | 1660 int label_mv_thresh; |
1653 int segmentyrate = 0; | 1661 int segmentyrate = 0; |
1654 const BLOCK_SIZE bsize = mbmi->sb_type; | 1662 const BLOCK_SIZE bsize = mbmi->sb_type; |
1655 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; | 1663 const int num_4x4_blocks_wide = num_4x4_blocks_wide_lookup[bsize]; |
1656 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; | 1664 const int num_4x4_blocks_high = num_4x4_blocks_high_lookup[bsize]; |
1657 vp9_variance_fn_ptr_t *v_fn_ptr; | 1665 vp9_variance_fn_ptr_t *v_fn_ptr; |
1658 ENTROPY_CONTEXT t_above[2], t_left[2]; | 1666 ENTROPY_CONTEXT t_above[2], t_left[2]; |
1659 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; | 1667 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; |
1660 int mode_idx; | 1668 int mode_idx; |
1661 int subpelmv = 1, have_ref = 0; | 1669 int subpelmv = 1, have_ref = 0; |
1662 const int has_second_rf = has_second_ref(mbmi); | 1670 const int has_second_rf = has_second_ref(mbmi); |
1663 | 1671 |
1664 vpx_memcpy(t_above, x->e_mbd.plane[0].above_context, sizeof(t_above)); | 1672 vpx_memcpy(t_above, pd->above_context, sizeof(t_above)); |
1665 vpx_memcpy(t_left, x->e_mbd.plane[0].left_context, sizeof(t_left)); | 1673 vpx_memcpy(t_left, pd->left_context, sizeof(t_left)); |
1666 | 1674 |
1667 v_fn_ptr = &cpi->fn_ptr[bsize]; | 1675 v_fn_ptr = &cpi->fn_ptr[bsize]; |
1668 | 1676 |
1669 // 64 makes this threshold really big effectively | 1677 // 64 makes this threshold really big effectively |
1670 // making it so that we very rarely check mvs on | 1678 // making it so that we very rarely check mvs on |
1671 // segments. setting this to 1 would make mv thresh | 1679 // segments. setting this to 1 would make mv thresh |
1672 // roughly equal to what it is for macroblocks | 1680 // roughly equal to what it is for macroblocks |
1673 label_mv_thresh = 1 * bsi->mvthresh / label_count; | 1681 label_mv_thresh = 1 * bsi->mvthresh / label_count; |
1674 | 1682 |
1675 // Segmentation method overheads | 1683 // Segmentation method overheads |
1676 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { | 1684 for (idy = 0; idy < 2; idy += num_4x4_blocks_high) { |
1677 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { | 1685 for (idx = 0; idx < 2; idx += num_4x4_blocks_wide) { |
1678 // TODO(jingning,rbultje): rewrite the rate-distortion optimization | 1686 // TODO(jingning,rbultje): rewrite the rate-distortion optimization |
1679 // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop | 1687 // loop for 4x4/4x8/8x4 block coding. to be replaced with new rd loop |
1680 int_mv mode_mv[MB_MODE_COUNT], second_mode_mv[MB_MODE_COUNT]; | 1688 int_mv mode_mv[MB_MODE_COUNT], second_mode_mv[MB_MODE_COUNT]; |
1681 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 1689 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
1682 MB_PREDICTION_MODE mode_selected = ZEROMV; | 1690 MB_PREDICTION_MODE mode_selected = ZEROMV; |
1683 int64_t best_rd = INT64_MAX; | 1691 int64_t best_rd = INT64_MAX; |
1684 i = idy * 2 + idx; | 1692 i = idy * 2 + idx; |
1685 | 1693 |
1686 frame_mv[ZEROMV][mbmi->ref_frame[0]].as_int = 0; | 1694 frame_mv[ZEROMV][mbmi->ref_frame[0]].as_int = 0; |
1687 frame_mv[ZEROMV][mbmi->ref_frame[1]].as_int = 0; | 1695 vp9_append_sub8x8_mvs_for_idx(&cpi->common, &x->e_mbd, tile, |
1688 vp9_append_sub8x8_mvs_for_idx(&cpi->common, &x->e_mbd, | |
1689 &frame_mv[NEARESTMV][mbmi->ref_frame[0]], | 1696 &frame_mv[NEARESTMV][mbmi->ref_frame[0]], |
1690 &frame_mv[NEARMV][mbmi->ref_frame[0]], | 1697 &frame_mv[NEARMV][mbmi->ref_frame[0]], |
1691 i, 0, mi_row, mi_col); | 1698 i, 0, mi_row, mi_col); |
1692 if (has_second_rf) | 1699 if (has_second_rf) { |
1693 vp9_append_sub8x8_mvs_for_idx(&cpi->common, &x->e_mbd, | 1700 frame_mv[ZEROMV][mbmi->ref_frame[1]].as_int = 0; |
1694 &frame_mv[NEARESTMV][mbmi->ref_frame[1]], | 1701 vp9_append_sub8x8_mvs_for_idx(&cpi->common, &x->e_mbd, tile, |
1695 &frame_mv[NEARMV][mbmi->ref_frame[1]], | 1702 &frame_mv[NEARESTMV][mbmi->ref_frame[1]], |
1696 i, 1, mi_row, mi_col); | 1703 &frame_mv[NEARMV][mbmi->ref_frame[1]], |
1697 | 1704 i, 1, mi_row, mi_col); |
| 1705 } |
1698 // search for the best motion vector on this segment | 1706 // search for the best motion vector on this segment |
1699 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 1707 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
1700 const struct buf_2d orig_src = x->plane[0].src; | 1708 const struct buf_2d orig_src = x->plane[0].src; |
1701 struct buf_2d orig_pre[2]; | 1709 struct buf_2d orig_pre[2]; |
1702 | 1710 |
1703 mode_idx = inter_mode_offset(this_mode); | 1711 mode_idx = inter_mode_offset(this_mode); |
1704 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; | 1712 bsi->rdstat[i][mode_idx].brdcost = INT64_MAX; |
1705 | 1713 |
1706 // if we're near/nearest and mv == 0,0, compare to zeromv | 1714 // if we're near/nearest and mv == 0,0, compare to zeromv |
1707 if ((this_mode == NEARMV || this_mode == NEARESTMV || | 1715 if ((this_mode == NEARMV || this_mode == NEARESTMV || |
(...skipping 25 matching lines...) Expand all Loading... |
1733 frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int == 0 && | 1741 frame_mv[NEARESTMV][mbmi->ref_frame[0]].as_int == 0 && |
1734 frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int == 0) || | 1742 frame_mv[NEARESTMV][mbmi->ref_frame[1]].as_int == 0) || |
1735 (c3 >= c1 && | 1743 (c3 >= c1 && |
1736 frame_mv[NEARMV][mbmi->ref_frame[0]].as_int == 0 && | 1744 frame_mv[NEARMV][mbmi->ref_frame[0]].as_int == 0 && |
1737 frame_mv[NEARMV][mbmi->ref_frame[1]].as_int == 0)) | 1745 frame_mv[NEARMV][mbmi->ref_frame[1]].as_int == 0)) |
1738 continue; | 1746 continue; |
1739 } | 1747 } |
1740 } | 1748 } |
1741 } | 1749 } |
1742 | 1750 |
1743 vpx_memcpy(orig_pre, x->e_mbd.plane[0].pre, sizeof(orig_pre)); | 1751 vpx_memcpy(orig_pre, pd->pre, sizeof(orig_pre)); |
1744 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above, | 1752 vpx_memcpy(bsi->rdstat[i][mode_idx].ta, t_above, |
1745 sizeof(bsi->rdstat[i][mode_idx].ta)); | 1753 sizeof(bsi->rdstat[i][mode_idx].ta)); |
1746 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left, | 1754 vpx_memcpy(bsi->rdstat[i][mode_idx].tl, t_left, |
1747 sizeof(bsi->rdstat[i][mode_idx].tl)); | 1755 sizeof(bsi->rdstat[i][mode_idx].tl)); |
1748 | 1756 |
1749 // motion search for newmv (single predictor case only) | 1757 // motion search for newmv (single predictor case only) |
1750 if (!has_second_rf && this_mode == NEWMV && | 1758 if (!has_second_rf && this_mode == NEWMV && |
1751 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) { | 1759 seg_mvs[i][mbmi->ref_frame[0]].as_int == INVALID_MV) { |
1752 int step_param = 0; | 1760 int step_param = 0; |
1753 int further_steps; | 1761 int further_steps; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1790 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) { | 1798 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) { |
1791 mvp_full.as_mv.row = x->pred_mv[mbmi->ref_frame[0]].as_mv.row >> 3; | 1799 mvp_full.as_mv.row = x->pred_mv[mbmi->ref_frame[0]].as_mv.row >> 3; |
1792 mvp_full.as_mv.col = x->pred_mv[mbmi->ref_frame[0]].as_mv.col >> 3; | 1800 mvp_full.as_mv.col = x->pred_mv[mbmi->ref_frame[0]].as_mv.col >> 3; |
1793 step_param = MAX(step_param, 8); | 1801 step_param = MAX(step_param, 8); |
1794 } | 1802 } |
1795 | 1803 |
1796 further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; | 1804 further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param; |
1797 // adjust src pointer for this block | 1805 // adjust src pointer for this block |
1798 mi_buf_shift(x, i); | 1806 mi_buf_shift(x, i); |
1799 if (cpi->sf.search_method == HEX) { | 1807 if (cpi->sf.search_method == HEX) { |
1800 bestsme = vp9_hex_search(x, &mvp_full, | 1808 bestsme = vp9_hex_search(x, &mvp_full.as_mv, |
1801 step_param, | 1809 step_param, |
1802 sadpb, 1, v_fn_ptr, 1, | 1810 sadpb, 1, v_fn_ptr, 1, |
1803 bsi->ref_mv, &mode_mv[NEWMV]); | 1811 &bsi->ref_mv->as_mv, |
| 1812 &mode_mv[NEWMV].as_mv); |
1804 } else if (cpi->sf.search_method == SQUARE) { | 1813 } else if (cpi->sf.search_method == SQUARE) { |
1805 bestsme = vp9_square_search(x, &mvp_full, | 1814 bestsme = vp9_square_search(x, &mvp_full.as_mv, |
1806 step_param, | 1815 step_param, |
1807 sadpb, 1, v_fn_ptr, 1, | 1816 sadpb, 1, v_fn_ptr, 1, |
1808 bsi->ref_mv, &mode_mv[NEWMV]); | 1817 &bsi->ref_mv->as_mv, |
| 1818 &mode_mv[NEWMV].as_mv); |
1809 } else if (cpi->sf.search_method == BIGDIA) { | 1819 } else if (cpi->sf.search_method == BIGDIA) { |
1810 bestsme = vp9_bigdia_search(x, &mvp_full, | 1820 bestsme = vp9_bigdia_search(x, &mvp_full.as_mv, |
1811 step_param, | 1821 step_param, |
1812 sadpb, 1, v_fn_ptr, 1, | 1822 sadpb, 1, v_fn_ptr, 1, |
1813 bsi->ref_mv, &mode_mv[NEWMV]); | 1823 &bsi->ref_mv->as_mv, |
| 1824 &mode_mv[NEWMV].as_mv); |
1814 } else { | 1825 } else { |
1815 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, | 1826 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, |
1816 sadpb, further_steps, 0, v_fn_ptr, | 1827 sadpb, further_steps, 0, v_fn_ptr, |
1817 bsi->ref_mv, &mode_mv[NEWMV]); | 1828 bsi->ref_mv, &mode_mv[NEWMV]); |
1818 } | 1829 } |
1819 | 1830 |
1820 // Should we do a full search (best quality only) | 1831 // Should we do a full search (best quality only) |
1821 if (cpi->compressor_speed == 0) { | 1832 if (cpi->compressor_speed == 0) { |
1822 /* Check if mvp_full is within the range. */ | 1833 /* Check if mvp_full is within the range. */ |
1823 clamp_mv(&mvp_full.as_mv, x->mv_col_min, x->mv_col_max, | 1834 clamp_mv(&mvp_full.as_mv, x->mv_col_min, x->mv_col_max, |
(...skipping 10 matching lines...) Expand all Loading... |
1834 } else { | 1845 } else { |
1835 /* The full search result is actually worse so re-instate the | 1846 /* The full search result is actually worse so re-instate the |
1836 * previous best vector */ | 1847 * previous best vector */ |
1837 mi->bmi[i].as_mv[0].as_int = mode_mv[NEWMV].as_int; | 1848 mi->bmi[i].as_mv[0].as_int = mode_mv[NEWMV].as_int; |
1838 } | 1849 } |
1839 } | 1850 } |
1840 | 1851 |
1841 if (bestsme < INT_MAX) { | 1852 if (bestsme < INT_MAX) { |
1842 int distortion; | 1853 int distortion; |
1843 unsigned int sse; | 1854 unsigned int sse; |
1844 cpi->find_fractional_mv_step(x, &mode_mv[NEWMV], | 1855 cpi->find_fractional_mv_step(x, |
1845 bsi->ref_mv, x->errorperbit, v_fn_ptr, | 1856 &mode_mv[NEWMV].as_mv, |
| 1857 &bsi->ref_mv->as_mv, |
| 1858 cpi->common.allow_high_precision_mv, |
| 1859 x->errorperbit, v_fn_ptr, |
1846 0, cpi->sf.subpel_iters_per_step, | 1860 0, cpi->sf.subpel_iters_per_step, |
1847 x->nmvjointcost, x->mvcost, | 1861 x->nmvjointcost, x->mvcost, |
1848 &distortion, &sse); | 1862 &distortion, &sse); |
1849 | 1863 |
1850 // save motion search result for use in compound prediction | 1864 // save motion search result for use in compound prediction |
1851 seg_mvs[i][mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int; | 1865 seg_mvs[i][mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int; |
1852 } | 1866 } |
1853 | 1867 |
1854 if (cpi->sf.adaptive_motion_search) | 1868 if (cpi->sf.adaptive_motion_search) |
1855 x->pred_mv[mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int; | 1869 x->pred_mv[mbmi->ref_frame[0]].as_int = mode_mv[NEWMV].as_int; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1931 if (has_second_rf) { | 1945 if (has_second_rf) { |
1932 have_ref &= second_mode_mv[this_mode].as_int == | 1946 have_ref &= second_mode_mv[this_mode].as_int == |
1933 ref_bsi->rdstat[i][mode_idx].mvs[1].as_int; | 1947 ref_bsi->rdstat[i][mode_idx].mvs[1].as_int; |
1934 } | 1948 } |
1935 } | 1949 } |
1936 | 1950 |
1937 if (!subpelmv && have_ref && | 1951 if (!subpelmv && have_ref && |
1938 ref_bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { | 1952 ref_bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { |
1939 vpx_memcpy(&bsi->rdstat[i][mode_idx], &ref_bsi->rdstat[i][mode_idx], | 1953 vpx_memcpy(&bsi->rdstat[i][mode_idx], &ref_bsi->rdstat[i][mode_idx], |
1940 sizeof(SEG_RDSTAT)); | 1954 sizeof(SEG_RDSTAT)); |
| 1955 if (num_4x4_blocks_wide > 1) |
| 1956 bsi->rdstat[i + 1][mode_idx].eobs = |
| 1957 ref_bsi->rdstat[i + 1][mode_idx].eobs; |
| 1958 if (num_4x4_blocks_high > 1) |
| 1959 bsi->rdstat[i + 2][mode_idx].eobs = |
| 1960 ref_bsi->rdstat[i + 2][mode_idx].eobs; |
| 1961 |
1941 if (bsi->rdstat[i][mode_idx].brdcost < best_rd) { | 1962 if (bsi->rdstat[i][mode_idx].brdcost < best_rd) { |
1942 mode_selected = this_mode; | 1963 mode_selected = this_mode; |
1943 best_rd = bsi->rdstat[i][mode_idx].brdcost; | 1964 best_rd = bsi->rdstat[i][mode_idx].brdcost; |
1944 } | 1965 } |
1945 continue; | 1966 continue; |
1946 } | 1967 } |
1947 } | 1968 } |
1948 | 1969 |
1949 bsi->rdstat[i][mode_idx].brdcost = | 1970 bsi->rdstat[i][mode_idx].brdcost = |
1950 encode_inter_mb_segment(cpi, x, | 1971 encode_inter_mb_segment(cpi, x, |
1951 bsi->segment_rd - this_segment_rd, i, | 1972 bsi->segment_rd - this_segment_rd, i, |
1952 &bsi->rdstat[i][mode_idx].byrate, | 1973 &bsi->rdstat[i][mode_idx].byrate, |
1953 &bsi->rdstat[i][mode_idx].bdist, | 1974 &bsi->rdstat[i][mode_idx].bdist, |
1954 &bsi->rdstat[i][mode_idx].bsse, | 1975 &bsi->rdstat[i][mode_idx].bsse, |
1955 bsi->rdstat[i][mode_idx].ta, | 1976 bsi->rdstat[i][mode_idx].ta, |
1956 bsi->rdstat[i][mode_idx].tl); | 1977 bsi->rdstat[i][mode_idx].tl); |
1957 if (bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { | 1978 if (bsi->rdstat[i][mode_idx].brdcost < INT64_MAX) { |
1958 bsi->rdstat[i][mode_idx].brdcost += RDCOST(x->rdmult, x->rddiv, | 1979 bsi->rdstat[i][mode_idx].brdcost += RDCOST(x->rdmult, x->rddiv, |
1959 bsi->rdstat[i][mode_idx].brate, 0); | 1980 bsi->rdstat[i][mode_idx].brate, 0); |
1960 bsi->rdstat[i][mode_idx].brate += bsi->rdstat[i][mode_idx].byrate; | 1981 bsi->rdstat[i][mode_idx].brate += bsi->rdstat[i][mode_idx].byrate; |
1961 bsi->rdstat[i][mode_idx].eobs = x->e_mbd.plane[0].eobs[i]; | 1982 bsi->rdstat[i][mode_idx].eobs = pd->eobs[i]; |
| 1983 if (num_4x4_blocks_wide > 1) |
| 1984 bsi->rdstat[i + 1][mode_idx].eobs = pd->eobs[i + 1]; |
| 1985 if (num_4x4_blocks_high > 1) |
| 1986 bsi->rdstat[i + 2][mode_idx].eobs = pd->eobs[i + 2]; |
1962 } | 1987 } |
1963 | 1988 |
1964 if (bsi->rdstat[i][mode_idx].brdcost < best_rd) { | 1989 if (bsi->rdstat[i][mode_idx].brdcost < best_rd) { |
1965 mode_selected = this_mode; | 1990 mode_selected = this_mode; |
1966 best_rd = bsi->rdstat[i][mode_idx].brdcost; | 1991 best_rd = bsi->rdstat[i][mode_idx].brdcost; |
1967 } | 1992 } |
1968 } /*for each 4x4 mode*/ | 1993 } /*for each 4x4 mode*/ |
1969 | 1994 |
1970 if (best_rd == INT64_MAX) { | 1995 if (best_rd == INT64_MAX) { |
1971 int iy, midx; | 1996 int iy, midx; |
(...skipping 20 matching lines...) Expand all Loading... |
1992 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost; | 2017 this_segment_rd += bsi->rdstat[i][mode_idx].brdcost; |
1993 | 2018 |
1994 if (this_segment_rd > bsi->segment_rd) { | 2019 if (this_segment_rd > bsi->segment_rd) { |
1995 int iy, midx; | 2020 int iy, midx; |
1996 for (iy = i + 1; iy < 4; ++iy) | 2021 for (iy = i + 1; iy < 4; ++iy) |
1997 for (midx = 0; midx < INTER_MODES; ++midx) | 2022 for (midx = 0; midx < INTER_MODES; ++midx) |
1998 bsi->rdstat[iy][midx].brdcost = INT64_MAX; | 2023 bsi->rdstat[iy][midx].brdcost = INT64_MAX; |
1999 bsi->segment_rd = INT64_MAX; | 2024 bsi->segment_rd = INT64_MAX; |
2000 return; | 2025 return; |
2001 } | 2026 } |
2002 | |
2003 for (j = 1; j < num_4x4_blocks_high; ++j) | |
2004 vpx_memcpy(&x->partition_info->bmi[i + j * 2], | |
2005 &x->partition_info->bmi[i], | |
2006 sizeof(x->partition_info->bmi[i])); | |
2007 for (j = 1; j < num_4x4_blocks_wide; ++j) | |
2008 vpx_memcpy(&x->partition_info->bmi[i + j], | |
2009 &x->partition_info->bmi[i], | |
2010 sizeof(x->partition_info->bmi[i])); | |
2011 } | 2027 } |
2012 } /* for each label */ | 2028 } /* for each label */ |
2013 | 2029 |
2014 bsi->r = br; | 2030 bsi->r = br; |
2015 bsi->d = bd; | 2031 bsi->d = bd; |
2016 bsi->segment_yrate = segmentyrate; | 2032 bsi->segment_yrate = segmentyrate; |
2017 bsi->segment_rd = this_segment_rd; | 2033 bsi->segment_rd = this_segment_rd; |
2018 bsi->sse = block_sse; | 2034 bsi->sse = block_sse; |
2019 | 2035 |
2020 // update the coding decisions | 2036 // update the coding decisions |
2021 for (i = 0; i < 4; ++i) | 2037 for (i = 0; i < 4; ++i) |
2022 bsi->modes[i] = x->partition_info->bmi[i].mode; | 2038 bsi->modes[i] = mi->bmi[i].as_mode; |
2023 } | 2039 } |
2024 | 2040 |
2025 static int64_t rd_pick_best_mbsegmentation(VP9_COMP *cpi, MACROBLOCK *x, | 2041 static int64_t rd_pick_best_mbsegmentation(VP9_COMP *cpi, MACROBLOCK *x, |
| 2042 const TileInfo *const tile, |
2026 int_mv *best_ref_mv, | 2043 int_mv *best_ref_mv, |
2027 int_mv *second_best_ref_mv, | 2044 int_mv *second_best_ref_mv, |
2028 int64_t best_rd, | 2045 int64_t best_rd, |
2029 int *returntotrate, | 2046 int *returntotrate, |
2030 int *returnyrate, | 2047 int *returnyrate, |
2031 int64_t *returndistortion, | 2048 int64_t *returndistortion, |
2032 int *skippable, int64_t *psse, | 2049 int *skippable, int64_t *psse, |
2033 int mvthresh, | 2050 int mvthresh, |
2034 int_mv seg_mvs[4][MAX_REF_FRAMES], | 2051 int_mv seg_mvs[4][MAX_REF_FRAMES], |
2035 BEST_SEG_INFO *bsi_buf, | 2052 BEST_SEG_INFO *bsi_buf, |
2036 int filter_idx, | 2053 int filter_idx, |
2037 int mi_row, int mi_col) { | 2054 int mi_row, int mi_col) { |
2038 int i; | 2055 int i; |
2039 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; | 2056 BEST_SEG_INFO *bsi = bsi_buf + filter_idx; |
2040 MACROBLOCKD *xd = &x->e_mbd; | 2057 MACROBLOCKD *xd = &x->e_mbd; |
2041 MODE_INFO *mi = xd->this_mi; | 2058 MODE_INFO *mi = xd->mi_8x8[0]; |
2042 MB_MODE_INFO *mbmi = &mi->mbmi; | 2059 MB_MODE_INFO *mbmi = &mi->mbmi; |
2043 int mode_idx; | 2060 int mode_idx; |
2044 | 2061 |
2045 vp9_zero(*bsi); | 2062 vp9_zero(*bsi); |
2046 | 2063 |
2047 bsi->segment_rd = best_rd; | 2064 bsi->segment_rd = best_rd; |
2048 bsi->ref_mv = best_ref_mv; | 2065 bsi->ref_mv = best_ref_mv; |
2049 bsi->second_ref_mv = second_best_ref_mv; | 2066 bsi->second_ref_mv = second_best_ref_mv; |
2050 bsi->mvp.as_int = best_ref_mv->as_int; | 2067 bsi->mvp.as_int = best_ref_mv->as_int; |
2051 bsi->mvthresh = mvthresh; | 2068 bsi->mvthresh = mvthresh; |
2052 | 2069 |
2053 for (i = 0; i < 4; i++) | 2070 for (i = 0; i < 4; i++) |
2054 bsi->modes[i] = ZEROMV; | 2071 bsi->modes[i] = ZEROMV; |
2055 | 2072 |
2056 rd_check_segment_txsize(cpi, x, bsi_buf, filter_idx, seg_mvs, mi_row, mi_col); | 2073 rd_check_segment_txsize(cpi, x, tile, bsi_buf, filter_idx, seg_mvs, |
| 2074 mi_row, mi_col); |
2057 | 2075 |
2058 if (bsi->segment_rd > best_rd) | 2076 if (bsi->segment_rd > best_rd) |
2059 return INT64_MAX; | 2077 return INT64_MAX; |
2060 /* set it to the best */ | 2078 /* set it to the best */ |
2061 for (i = 0; i < 4; i++) { | 2079 for (i = 0; i < 4; i++) { |
2062 mode_idx = inter_mode_offset(bsi->modes[i]); | 2080 mode_idx = inter_mode_offset(bsi->modes[i]); |
2063 mi->bmi[i].as_mv[0].as_int = bsi->rdstat[i][mode_idx].mvs[0].as_int; | 2081 mi->bmi[i].as_mv[0].as_int = bsi->rdstat[i][mode_idx].mvs[0].as_int; |
2064 if (has_second_ref(mbmi)) | 2082 if (has_second_ref(mbmi)) |
2065 mi->bmi[i].as_mv[1].as_int = bsi->rdstat[i][mode_idx].mvs[1].as_int; | 2083 mi->bmi[i].as_mv[1].as_int = bsi->rdstat[i][mode_idx].mvs[1].as_int; |
2066 xd->plane[0].eobs[i] = bsi->rdstat[i][mode_idx].eobs; | 2084 xd->plane[0].eobs[i] = bsi->rdstat[i][mode_idx].eobs; |
2067 x->partition_info->bmi[i].mode = bsi->modes[i]; | 2085 mi->bmi[i].as_mode = bsi->modes[i]; |
2068 } | 2086 } |
2069 | 2087 |
2070 /* | 2088 /* |
2071 * used to set mbmi->mv.as_int | 2089 * used to set mbmi->mv.as_int |
2072 */ | 2090 */ |
2073 *returntotrate = bsi->r; | 2091 *returntotrate = bsi->r; |
2074 *returndistortion = bsi->d; | 2092 *returndistortion = bsi->d; |
2075 *returnyrate = bsi->segment_yrate; | 2093 *returnyrate = bsi->segment_yrate; |
2076 *skippable = vp9_is_skippable_in_plane(&x->e_mbd, BLOCK_8X8, 0); | 2094 *skippable = vp9_is_skippable_in_plane(&x->e_mbd, BLOCK_8X8, 0); |
2077 *psse = bsi->sse; | 2095 *psse = bsi->sse; |
2078 mbmi->mode = bsi->modes[3]; | 2096 mbmi->mode = bsi->modes[3]; |
2079 | 2097 |
2080 return bsi->segment_rd; | 2098 return bsi->segment_rd; |
2081 } | 2099 } |
2082 | 2100 |
2083 static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x, | 2101 static void mv_pred(VP9_COMP *cpi, MACROBLOCK *x, |
2084 uint8_t *ref_y_buffer, int ref_y_stride, | 2102 uint8_t *ref_y_buffer, int ref_y_stride, |
2085 int ref_frame, BLOCK_SIZE block_size ) { | 2103 int ref_frame, BLOCK_SIZE block_size ) { |
2086 MACROBLOCKD *xd = &x->e_mbd; | 2104 MACROBLOCKD *xd = &x->e_mbd; |
2087 MB_MODE_INFO *mbmi = &xd->this_mi->mbmi; | 2105 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
2088 int_mv this_mv; | 2106 int_mv this_mv; |
2089 int i; | 2107 int i; |
2090 int zero_seen = 0; | 2108 int zero_seen = 0; |
2091 int best_index = 0; | 2109 int best_index = 0; |
2092 int best_sad = INT_MAX; | 2110 int best_sad = INT_MAX; |
2093 int this_sad = INT_MAX; | 2111 int this_sad = INT_MAX; |
2094 unsigned int max_mv = 0; | 2112 unsigned int max_mv = 0; |
2095 | 2113 |
2096 uint8_t *src_y_ptr = x->plane[0].src.buf; | 2114 uint8_t *src_y_ptr = x->plane[0].src.buf; |
2097 uint8_t *ref_y_ptr; | 2115 uint8_t *ref_y_ptr; |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2190 ref_costs_comp[GOLDEN_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 1); | 2208 ref_costs_comp[GOLDEN_FRAME] = base_cost + vp9_cost_bit(ref_comp_p, 1); |
2191 } else { | 2209 } else { |
2192 ref_costs_comp[LAST_FRAME] = 512; | 2210 ref_costs_comp[LAST_FRAME] = 512; |
2193 ref_costs_comp[GOLDEN_FRAME] = 512; | 2211 ref_costs_comp[GOLDEN_FRAME] = 512; |
2194 } | 2212 } |
2195 } | 2213 } |
2196 } | 2214 } |
2197 | 2215 |
2198 static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, | 2216 static void store_coding_context(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx, |
2199 int mode_index, | 2217 int mode_index, |
2200 PARTITION_INFO *partition, | |
2201 int_mv *ref_mv, | 2218 int_mv *ref_mv, |
2202 int_mv *second_ref_mv, | 2219 int_mv *second_ref_mv, |
2203 int64_t comp_pred_diff[NB_PREDICTION_TYPES], | 2220 int64_t comp_pred_diff[NB_PREDICTION_TYPES], |
2204 int64_t tx_size_diff[TX_MODES], | 2221 int64_t tx_size_diff[TX_MODES], |
2205 int64_t best_filter_diff[SWITCHABLE_FILTERS + 1]) { | 2222 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]) { |
2206 MACROBLOCKD *const xd = &x->e_mbd; | 2223 MACROBLOCKD *const xd = &x->e_mbd; |
2207 | 2224 |
2208 // Take a snapshot of the coding context so it can be | 2225 // Take a snapshot of the coding context so it can be |
2209 // restored if we decide to encode this way | 2226 // restored if we decide to encode this way |
2210 ctx->skip = x->skip; | 2227 ctx->skip = x->skip; |
2211 ctx->best_mode_index = mode_index; | 2228 ctx->best_mode_index = mode_index; |
2212 ctx->mic = *xd->this_mi; | 2229 ctx->mic = *xd->mi_8x8[0]; |
2213 | |
2214 if (partition) | |
2215 ctx->partition_info = *partition; | |
2216 | 2230 |
2217 ctx->best_ref_mv.as_int = ref_mv->as_int; | 2231 ctx->best_ref_mv.as_int = ref_mv->as_int; |
2218 ctx->second_best_ref_mv.as_int = second_ref_mv->as_int; | 2232 ctx->second_best_ref_mv.as_int = second_ref_mv->as_int; |
2219 | 2233 |
2220 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_PREDICTION_ONLY]; | 2234 ctx->single_pred_diff = (int)comp_pred_diff[SINGLE_PREDICTION_ONLY]; |
2221 ctx->comp_pred_diff = (int)comp_pred_diff[COMP_PREDICTION_ONLY]; | 2235 ctx->comp_pred_diff = (int)comp_pred_diff[COMP_PREDICTION_ONLY]; |
2222 ctx->hybrid_pred_diff = (int)comp_pred_diff[HYBRID_PREDICTION]; | 2236 ctx->hybrid_pred_diff = (int)comp_pred_diff[HYBRID_PREDICTION]; |
2223 | 2237 |
2224 // FIXME(rbultje) does this memcpy the whole array? I believe sizeof() | 2238 vpx_memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); |
2225 // doesn't actually work this way | 2239 vpx_memcpy(ctx->best_filter_diff, best_filter_diff, |
2226 memcpy(ctx->tx_rd_diff, tx_size_diff, sizeof(ctx->tx_rd_diff)); | 2240 sizeof(*best_filter_diff) * SWITCHABLE_FILTER_CONTEXTS); |
2227 memcpy(ctx->best_filter_diff, best_filter_diff, | |
2228 sizeof(*best_filter_diff) * (SWITCHABLE_FILTERS + 1)); | |
2229 } | 2241 } |
2230 | 2242 |
2231 static void setup_pred_block(const MACROBLOCKD *xd, | 2243 static void setup_pred_block(const MACROBLOCKD *xd, |
2232 struct buf_2d dst[MAX_MB_PLANE], | 2244 struct buf_2d dst[MAX_MB_PLANE], |
2233 const YV12_BUFFER_CONFIG *src, | 2245 const YV12_BUFFER_CONFIG *src, |
2234 int mi_row, int mi_col, | 2246 int mi_row, int mi_col, |
2235 const struct scale_factors *scale, | 2247 const struct scale_factors *scale, |
2236 const struct scale_factors *scale_uv) { | 2248 const struct scale_factors *scale_uv) { |
2237 int i; | 2249 int i; |
2238 | 2250 |
2239 dst[0].buf = src->y_buffer; | 2251 dst[0].buf = src->y_buffer; |
2240 dst[0].stride = src->y_stride; | 2252 dst[0].stride = src->y_stride; |
2241 dst[1].buf = src->u_buffer; | 2253 dst[1].buf = src->u_buffer; |
2242 dst[2].buf = src->v_buffer; | 2254 dst[2].buf = src->v_buffer; |
2243 dst[1].stride = dst[2].stride = src->uv_stride; | 2255 dst[1].stride = dst[2].stride = src->uv_stride; |
2244 #if CONFIG_ALPHA | 2256 #if CONFIG_ALPHA |
2245 dst[3].buf = src->alpha_buffer; | 2257 dst[3].buf = src->alpha_buffer; |
2246 dst[3].stride = src->alpha_stride; | 2258 dst[3].stride = src->alpha_stride; |
2247 #endif | 2259 #endif |
2248 | 2260 |
2249 // TODO(jkoleszar): Make scale factors per-plane data | 2261 // TODO(jkoleszar): Make scale factors per-plane data |
2250 for (i = 0; i < MAX_MB_PLANE; i++) { | 2262 for (i = 0; i < MAX_MB_PLANE; i++) { |
2251 setup_pred_plane(dst + i, dst[i].buf, dst[i].stride, mi_row, mi_col, | 2263 setup_pred_plane(dst + i, dst[i].buf, dst[i].stride, mi_row, mi_col, |
2252 i ? scale_uv : scale, | 2264 i ? scale_uv : scale, |
2253 xd->plane[i].subsampling_x, xd->plane[i].subsampling_y); | 2265 xd->plane[i].subsampling_x, xd->plane[i].subsampling_y); |
2254 } | 2266 } |
2255 } | 2267 } |
2256 | 2268 |
2257 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, | 2269 static void setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, |
| 2270 const TileInfo *const tile, |
2258 int idx, MV_REFERENCE_FRAME frame_type, | 2271 int idx, MV_REFERENCE_FRAME frame_type, |
2259 BLOCK_SIZE block_size, | 2272 BLOCK_SIZE block_size, |
2260 int mi_row, int mi_col, | 2273 int mi_row, int mi_col, |
2261 int_mv frame_nearest_mv[MAX_REF_FRAMES], | 2274 int_mv frame_nearest_mv[MAX_REF_FRAMES], |
2262 int_mv frame_near_mv[MAX_REF_FRAMES], | 2275 int_mv frame_near_mv[MAX_REF_FRAMES], |
2263 struct buf_2d yv12_mb[4][MAX_MB_PLANE], | 2276 struct buf_2d yv12_mb[4][MAX_MB_PLANE], |
2264 struct scale_factors scale[MAX_REF_FRAMES]) { | 2277 struct scale_factors scale[MAX_REF_FRAMES]) { |
2265 VP9_COMMON *cm = &cpi->common; | 2278 VP9_COMMON *cm = &cpi->common; |
2266 YV12_BUFFER_CONFIG *yv12 = &cm->yv12_fb[cpi->common.ref_frame_map[idx]]; | 2279 YV12_BUFFER_CONFIG *yv12 = &cm->yv12_fb[cpi->common.ref_frame_map[idx]]; |
2267 MACROBLOCKD *const xd = &x->e_mbd; | 2280 MACROBLOCKD *const xd = &x->e_mbd; |
2268 MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi; | 2281 MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
2269 | 2282 |
2270 // set up scaling factors | 2283 // set up scaling factors |
2271 scale[frame_type] = cpi->common.active_ref_scale[frame_type - 1]; | 2284 scale[frame_type] = cpi->common.active_ref_scale[frame_type - 1]; |
2272 | 2285 |
2273 scale[frame_type].x_offset_q4 = | 2286 scale[frame_type].sfc->set_scaled_offsets(&scale[frame_type], |
2274 ROUND_POWER_OF_TWO(mi_col * MI_SIZE * scale[frame_type].x_scale_fp, | 2287 mi_row * MI_SIZE, mi_col * MI_SIZE); |
2275 REF_SCALE_SHIFT) & 0xf; | |
2276 scale[frame_type].y_offset_q4 = | |
2277 ROUND_POWER_OF_TWO(mi_row * MI_SIZE * scale[frame_type].y_scale_fp, | |
2278 REF_SCALE_SHIFT) & 0xf; | |
2279 | 2288 |
2280 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this | 2289 // TODO(jkoleszar): Is the UV buffer ever used here? If so, need to make this |
2281 // use the UV scaling factors. | 2290 // use the UV scaling factors. |
2282 setup_pred_block(xd, yv12_mb[frame_type], yv12, mi_row, mi_col, | 2291 setup_pred_block(xd, yv12_mb[frame_type], yv12, mi_row, mi_col, |
2283 &scale[frame_type], &scale[frame_type]); | 2292 &scale[frame_type], &scale[frame_type]); |
2284 | 2293 |
2285 // Gets an initial list of candidate vectors from neighbours and orders them | 2294 // Gets an initial list of candidate vectors from neighbours and orders them |
2286 vp9_find_mv_refs(&cpi->common, xd, xd->this_mi, | 2295 vp9_find_mv_refs(cm, xd, tile, xd->mi_8x8[0], |
2287 xd->last_mi, | 2296 xd->last_mi, |
2288 frame_type, | 2297 frame_type, |
2289 mbmi->ref_mvs[frame_type], mi_row, mi_col); | 2298 mbmi->ref_mvs[frame_type], mi_row, mi_col); |
2290 | 2299 |
2291 // Candidate refinement carried out at encoder and decoder | 2300 // Candidate refinement carried out at encoder and decoder |
2292 vp9_find_best_ref_mvs(xd, | 2301 vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, |
2293 mbmi->ref_mvs[frame_type], | 2302 mbmi->ref_mvs[frame_type], |
2294 &frame_nearest_mv[frame_type], | 2303 &frame_nearest_mv[frame_type], |
2295 &frame_near_mv[frame_type]); | 2304 &frame_near_mv[frame_type]); |
2296 | 2305 |
2297 // Further refinement that is encode side only to test the top few candidates | 2306 // Further refinement that is encode side only to test the top few candidates |
2298 // in full and choose the best as the centre point for subsequent searches. | 2307 // in full and choose the best as the centre point for subsequent searches. |
2299 // The current implementation doesn't support scaling. | 2308 // The current implementation doesn't support scaling. |
2300 if (!vp9_is_scaled(&scale[frame_type])) | 2309 if (!vp9_is_scaled(scale[frame_type].sfc) && block_size >= BLOCK_8X8) |
2301 mv_pred(cpi, x, yv12_mb[frame_type][0].buf, yv12->y_stride, | 2310 mv_pred(cpi, x, yv12_mb[frame_type][0].buf, yv12->y_stride, |
2302 frame_type, block_size); | 2311 frame_type, block_size); |
2303 } | 2312 } |
2304 | 2313 |
2305 static YV12_BUFFER_CONFIG *get_scaled_ref_frame(VP9_COMP *cpi, int ref_frame) { | 2314 static YV12_BUFFER_CONFIG *get_scaled_ref_frame(VP9_COMP *cpi, int ref_frame) { |
2306 YV12_BUFFER_CONFIG *scaled_ref_frame = NULL; | 2315 YV12_BUFFER_CONFIG *scaled_ref_frame = NULL; |
2307 int fb = get_ref_frame_idx(cpi, ref_frame); | 2316 int fb = get_ref_frame_idx(cpi, ref_frame); |
2308 int fb_scale = get_scale_ref_frame_idx(cpi, ref_frame); | 2317 int fb_scale = get_scale_ref_frame_idx(cpi, ref_frame); |
2309 if (cpi->scaled_ref_idx[fb_scale] != cpi->common.ref_frame_map[fb]) | 2318 if (cpi->scaled_ref_idx[fb_scale] != cpi->common.ref_frame_map[fb]) |
2310 scaled_ref_frame = &cpi->common.yv12_fb[cpi->scaled_ref_idx[fb_scale]]; | 2319 scaled_ref_frame = &cpi->common.yv12_fb[cpi->scaled_ref_idx[fb_scale]]; |
2311 return scaled_ref_frame; | 2320 return scaled_ref_frame; |
2312 } | 2321 } |
2313 | 2322 |
2314 static INLINE int get_switchable_rate(const MACROBLOCK *x) { | 2323 static INLINE int get_switchable_rate(const MACROBLOCK *x) { |
2315 const MACROBLOCKD *const xd = &x->e_mbd; | 2324 const MACROBLOCKD *const xd = &x->e_mbd; |
2316 const MB_MODE_INFO *const mbmi = &xd->this_mi->mbmi; | 2325 const MB_MODE_INFO *const mbmi = &xd->mi_8x8[0]->mbmi; |
2317 const int ctx = vp9_get_pred_context_switchable_interp(xd); | 2326 const int ctx = vp9_get_pred_context_switchable_interp(xd); |
2318 return SWITCHABLE_INTERP_RATE_FACTOR * | 2327 return SWITCHABLE_INTERP_RATE_FACTOR * |
2319 x->switchable_interp_costs[ctx][mbmi->interp_filter]; | 2328 x->switchable_interp_costs[ctx][mbmi->interp_filter]; |
2320 } | 2329 } |
2321 | 2330 |
2322 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 2331 static void single_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
| 2332 const TileInfo *const tile, |
2323 BLOCK_SIZE bsize, | 2333 BLOCK_SIZE bsize, |
2324 int mi_row, int mi_col, | 2334 int mi_row, int mi_col, |
2325 int_mv *tmp_mv, int *rate_mv) { | 2335 int_mv *tmp_mv, int *rate_mv) { |
2326 MACROBLOCKD *xd = &x->e_mbd; | 2336 MACROBLOCKD *xd = &x->e_mbd; |
2327 VP9_COMMON *cm = &cpi->common; | 2337 VP9_COMMON *cm = &cpi->common; |
2328 MB_MODE_INFO *mbmi = &xd->this_mi->mbmi; | 2338 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
2329 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; | 2339 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; |
2330 int bestsme = INT_MAX; | 2340 int bestsme = INT_MAX; |
2331 int further_steps, step_param; | 2341 int further_steps, step_param; |
2332 int sadpb = x->sadperbit16; | 2342 int sadpb = x->sadperbit16; |
2333 int_mv mvp_full; | 2343 int_mv mvp_full; |
2334 int ref = mbmi->ref_frame[0]; | 2344 int ref = mbmi->ref_frame[0]; |
2335 int_mv ref_mv = mbmi->ref_mvs[ref][0]; | 2345 int_mv ref_mv = mbmi->ref_mvs[ref][0]; |
2336 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); | 2346 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); |
2337 | 2347 |
2338 int tmp_col_min = x->mv_col_min; | 2348 int tmp_col_min = x->mv_col_min; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2397 mbmi->ref_mvs[ref][x->mv_best_ref_index[ref]].as_int : | 2407 mbmi->ref_mvs[ref][x->mv_best_ref_index[ref]].as_int : |
2398 x->pred_mv[ref].as_int; | 2408 x->pred_mv[ref].as_int; |
2399 | 2409 |
2400 mvp_full.as_mv.col >>= 3; | 2410 mvp_full.as_mv.col >>= 3; |
2401 mvp_full.as_mv.row >>= 3; | 2411 mvp_full.as_mv.row >>= 3; |
2402 | 2412 |
2403 // Further step/diamond searches as necessary | 2413 // Further step/diamond searches as necessary |
2404 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; | 2414 further_steps = (cpi->sf.max_step_search_steps - 1) - step_param; |
2405 | 2415 |
2406 if (cpi->sf.search_method == HEX) { | 2416 if (cpi->sf.search_method == HEX) { |
2407 bestsme = vp9_hex_search(x, &mvp_full, | 2417 bestsme = vp9_hex_search(x, &mvp_full.as_mv, |
2408 step_param, | 2418 step_param, |
2409 sadpb, 1, | 2419 sadpb, 1, |
2410 &cpi->fn_ptr[block_size], 1, | 2420 &cpi->fn_ptr[block_size], 1, |
2411 &ref_mv, tmp_mv); | 2421 &ref_mv.as_mv, &tmp_mv->as_mv); |
2412 } else if (cpi->sf.search_method == SQUARE) { | 2422 } else if (cpi->sf.search_method == SQUARE) { |
2413 bestsme = vp9_square_search(x, &mvp_full, | 2423 bestsme = vp9_square_search(x, &mvp_full.as_mv, |
2414 step_param, | 2424 step_param, |
2415 sadpb, 1, | 2425 sadpb, 1, |
2416 &cpi->fn_ptr[block_size], 1, | 2426 &cpi->fn_ptr[block_size], 1, |
2417 &ref_mv, tmp_mv); | 2427 &ref_mv.as_mv, &tmp_mv->as_mv); |
2418 } else if (cpi->sf.search_method == BIGDIA) { | 2428 } else if (cpi->sf.search_method == BIGDIA) { |
2419 bestsme = vp9_bigdia_search(x, &mvp_full, | 2429 bestsme = vp9_bigdia_search(x, &mvp_full.as_mv, |
2420 step_param, | 2430 step_param, |
2421 sadpb, 1, | 2431 sadpb, 1, |
2422 &cpi->fn_ptr[block_size], 1, | 2432 &cpi->fn_ptr[block_size], 1, |
2423 &ref_mv, tmp_mv); | 2433 &ref_mv.as_mv, &tmp_mv->as_mv); |
2424 } else { | 2434 } else { |
2425 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, | 2435 bestsme = vp9_full_pixel_diamond(cpi, x, &mvp_full, step_param, |
2426 sadpb, further_steps, 1, | 2436 sadpb, further_steps, 1, |
2427 &cpi->fn_ptr[block_size], | 2437 &cpi->fn_ptr[block_size], |
2428 &ref_mv, tmp_mv); | 2438 &ref_mv, tmp_mv); |
2429 } | 2439 } |
2430 | 2440 |
2431 x->mv_col_min = tmp_col_min; | 2441 x->mv_col_min = tmp_col_min; |
2432 x->mv_col_max = tmp_col_max; | 2442 x->mv_col_max = tmp_col_max; |
2433 x->mv_row_min = tmp_row_min; | 2443 x->mv_row_min = tmp_row_min; |
2434 x->mv_row_max = tmp_row_max; | 2444 x->mv_row_max = tmp_row_max; |
2435 | 2445 |
2436 if (bestsme < INT_MAX) { | 2446 if (bestsme < INT_MAX) { |
2437 int dis; /* TODO: use dis in distortion calculation later. */ | 2447 int dis; /* TODO: use dis in distortion calculation later. */ |
2438 unsigned int sse; | 2448 unsigned int sse; |
2439 cpi->find_fractional_mv_step(x, tmp_mv, &ref_mv, | 2449 cpi->find_fractional_mv_step(x, &tmp_mv->as_mv, &ref_mv.as_mv, |
| 2450 cm->allow_high_precision_mv, |
2440 x->errorperbit, | 2451 x->errorperbit, |
2441 &cpi->fn_ptr[block_size], | 2452 &cpi->fn_ptr[block_size], |
2442 0, cpi->sf.subpel_iters_per_step, | 2453 0, cpi->sf.subpel_iters_per_step, |
2443 x->nmvjointcost, x->mvcost, | 2454 x->nmvjointcost, x->mvcost, |
2444 &dis, &sse); | 2455 &dis, &sse); |
2445 } | 2456 } |
2446 *rate_mv = vp9_mv_bit_cost(tmp_mv, &ref_mv, | 2457 *rate_mv = vp9_mv_bit_cost(&tmp_mv->as_mv, &ref_mv.as_mv, |
2447 x->nmvjointcost, x->mvcost, | 2458 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
2448 96); | |
2449 | 2459 |
2450 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) | 2460 if (cpi->sf.adaptive_motion_search && cpi->common.show_frame) |
2451 x->pred_mv[ref].as_int = tmp_mv->as_int; | 2461 x->pred_mv[ref].as_int = tmp_mv->as_int; |
2452 | 2462 |
2453 if (scaled_ref_frame) { | 2463 if (scaled_ref_frame) { |
2454 int i; | 2464 int i; |
2455 for (i = 0; i < MAX_MB_PLANE; i++) | 2465 for (i = 0; i < MAX_MB_PLANE; i++) |
2456 xd->plane[i].pre[0] = backup_yv12[i]; | 2466 xd->plane[i].pre[0] = backup_yv12[i]; |
2457 } | 2467 } |
2458 } | 2468 } |
2459 | 2469 |
2460 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, | 2470 static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, |
2461 BLOCK_SIZE bsize, | 2471 BLOCK_SIZE bsize, |
2462 int_mv *frame_mv, | 2472 int_mv *frame_mv, |
2463 int mi_row, int mi_col, | 2473 int mi_row, int mi_col, |
2464 int_mv single_newmv[MAX_REF_FRAMES], | 2474 int_mv single_newmv[MAX_REF_FRAMES], |
2465 int *rate_mv) { | 2475 int *rate_mv) { |
2466 int pw = 4 << b_width_log2(bsize), ph = 4 << b_height_log2(bsize); | 2476 int pw = 4 << b_width_log2(bsize), ph = 4 << b_height_log2(bsize); |
2467 MACROBLOCKD *xd = &x->e_mbd; | 2477 MACROBLOCKD *xd = &x->e_mbd; |
2468 MB_MODE_INFO *mbmi = &xd->this_mi->mbmi; | 2478 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
2469 int refs[2] = { mbmi->ref_frame[0], | 2479 int refs[2] = { mbmi->ref_frame[0], |
2470 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; | 2480 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; |
2471 int_mv ref_mv[2]; | 2481 int_mv ref_mv[2]; |
2472 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); | 2482 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); |
2473 int ite; | 2483 int ite; |
2474 // Prediction buffer from second frame. | 2484 // Prediction buffer from second frame. |
2475 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); | 2485 uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); |
2476 | 2486 |
2477 // Do joint motion search in compound mode to get more accurate mv. | 2487 // Do joint motion search in compound mode to get more accurate mv. |
2478 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; | 2488 struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; |
(...skipping 15 matching lines...) Expand all Loading... |
2494 for (i = 0; i < MAX_MB_PLANE; i++) | 2504 for (i = 0; i < MAX_MB_PLANE; i++) |
2495 backup_yv12[i] = xd->plane[i].pre[0]; | 2505 backup_yv12[i] = xd->plane[i].pre[0]; |
2496 setup_pre_planes(xd, 0, scaled_ref_frame[0], mi_row, mi_col, NULL); | 2506 setup_pre_planes(xd, 0, scaled_ref_frame[0], mi_row, mi_col, NULL); |
2497 } | 2507 } |
2498 | 2508 |
2499 if (scaled_ref_frame[1]) { | 2509 if (scaled_ref_frame[1]) { |
2500 int i; | 2510 int i; |
2501 for (i = 0; i < MAX_MB_PLANE; i++) | 2511 for (i = 0; i < MAX_MB_PLANE; i++) |
2502 backup_second_yv12[i] = xd->plane[i].pre[1]; | 2512 backup_second_yv12[i] = xd->plane[i].pre[1]; |
2503 | 2513 |
2504 setup_pre_planes(xd, 0, scaled_ref_frame[1], mi_row, mi_col, NULL); | 2514 setup_pre_planes(xd, 1, scaled_ref_frame[1], mi_row, mi_col, NULL); |
2505 } | 2515 } |
2506 | 2516 |
2507 xd->scale_factor[0].set_scaled_offsets(&xd->scale_factor[0], | 2517 xd->scale_factor[0].sfc->set_scaled_offsets(&xd->scale_factor[0], |
2508 mi_row, mi_col); | 2518 mi_row, mi_col); |
2509 xd->scale_factor[1].set_scaled_offsets(&xd->scale_factor[1], | 2519 xd->scale_factor[1].sfc->set_scaled_offsets(&xd->scale_factor[1], |
2510 mi_row, mi_col); | 2520 mi_row, mi_col); |
2511 scaled_first_yv12 = xd->plane[0].pre[0]; | 2521 scaled_first_yv12 = xd->plane[0].pre[0]; |
2512 | 2522 |
2513 // Initialize mv using single prediction mode result. | 2523 // Initialize mv using single prediction mode result. |
2514 frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int; | 2524 frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int; |
2515 frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int; | 2525 frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int; |
2516 | 2526 |
2517 // Allow joint search multiple times iteratively for each ref frame | 2527 // Allow joint search multiple times iteratively for each ref frame |
2518 // and break out the search loop if it couldn't find better mv. | 2528 // and break out the search loop if it couldn't find better mv. |
2519 for (ite = 0; ite < 4; ite++) { | 2529 for (ite = 0; ite < 4; ite++) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2564 x->mv_col_min = tmp_col_min; | 2574 x->mv_col_min = tmp_col_min; |
2565 x->mv_col_max = tmp_col_max; | 2575 x->mv_col_max = tmp_col_max; |
2566 x->mv_row_min = tmp_row_min; | 2576 x->mv_row_min = tmp_row_min; |
2567 x->mv_row_max = tmp_row_max; | 2577 x->mv_row_max = tmp_row_max; |
2568 | 2578 |
2569 if (bestsme < INT_MAX) { | 2579 if (bestsme < INT_MAX) { |
2570 int dis; /* TODO: use dis in distortion calculation later. */ | 2580 int dis; /* TODO: use dis in distortion calculation later. */ |
2571 unsigned int sse; | 2581 unsigned int sse; |
2572 | 2582 |
2573 bestsme = cpi->find_fractional_mv_step_comp( | 2583 bestsme = cpi->find_fractional_mv_step_comp( |
2574 x, &tmp_mv, | 2584 x, &tmp_mv.as_mv, |
2575 &ref_mv[id], | 2585 &ref_mv[id].as_mv, |
| 2586 cpi->common.allow_high_precision_mv, |
2576 x->errorperbit, | 2587 x->errorperbit, |
2577 &cpi->fn_ptr[block_size], | 2588 &cpi->fn_ptr[block_size], |
2578 0, cpi->sf.subpel_iters_per_step, | 2589 0, cpi->sf.subpel_iters_per_step, |
2579 x->nmvjointcost, x->mvcost, | 2590 x->nmvjointcost, x->mvcost, |
2580 &dis, &sse, second_pred, | 2591 &dis, &sse, second_pred, |
2581 pw, ph); | 2592 pw, ph); |
2582 } | 2593 } |
2583 | 2594 |
2584 if (id) | 2595 if (id) |
2585 xd->plane[0].pre[0] = scaled_first_yv12; | 2596 xd->plane[0].pre[0] = scaled_first_yv12; |
(...skipping 11 matching lines...) Expand all Loading... |
2597 int i; | 2608 int i; |
2598 for (i = 0; i < MAX_MB_PLANE; i++) | 2609 for (i = 0; i < MAX_MB_PLANE; i++) |
2599 xd->plane[i].pre[0] = backup_yv12[i]; | 2610 xd->plane[i].pre[0] = backup_yv12[i]; |
2600 } | 2611 } |
2601 | 2612 |
2602 if (scaled_ref_frame[1]) { | 2613 if (scaled_ref_frame[1]) { |
2603 int i; | 2614 int i; |
2604 for (i = 0; i < MAX_MB_PLANE; i++) | 2615 for (i = 0; i < MAX_MB_PLANE; i++) |
2605 xd->plane[i].pre[1] = backup_second_yv12[i]; | 2616 xd->plane[i].pre[1] = backup_second_yv12[i]; |
2606 } | 2617 } |
2607 *rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]], | 2618 *rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv, |
2608 &mbmi->ref_mvs[refs[0]][0], | 2619 &mbmi->ref_mvs[refs[0]][0].as_mv, |
2609 x->nmvjointcost, x->mvcost, 96); | 2620 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
2610 *rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]], | 2621 *rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv, |
2611 &mbmi->ref_mvs[refs[1]][0], | 2622 &mbmi->ref_mvs[refs[1]][0].as_mv, |
2612 x->nmvjointcost, x->mvcost, 96); | 2623 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
2613 | 2624 |
2614 vpx_free(second_pred); | 2625 vpx_free(second_pred); |
2615 } | 2626 } |
2616 | 2627 |
2617 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, | 2628 static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, |
| 2629 const TileInfo *const tile, |
2618 BLOCK_SIZE bsize, | 2630 BLOCK_SIZE bsize, |
2619 int64_t txfm_cache[], | 2631 int64_t txfm_cache[], |
2620 int *rate2, int64_t *distortion, | 2632 int *rate2, int64_t *distortion, |
2621 int *skippable, | 2633 int *skippable, |
2622 int *rate_y, int64_t *distortion_y, | 2634 int *rate_y, int64_t *distortion_y, |
2623 int *rate_uv, int64_t *distortion_uv, | 2635 int *rate_uv, int64_t *distortion_uv, |
2624 int *mode_excluded, int *disable_skip, | 2636 int *mode_excluded, int *disable_skip, |
2625 INTERPOLATIONFILTERTYPE *best_filter, | 2637 INTERPOLATION_TYPE *best_filter, |
2626 int_mv (*mode_mv)[MAX_REF_FRAMES], | 2638 int_mv (*mode_mv)[MAX_REF_FRAMES], |
2627 int mi_row, int mi_col, | 2639 int mi_row, int mi_col, |
2628 int_mv single_newmv[MAX_REF_FRAMES], | 2640 int_mv single_newmv[MAX_REF_FRAMES], |
2629 int64_t *psse, | 2641 int64_t *psse, |
2630 const int64_t ref_best_rd) { | 2642 const int64_t ref_best_rd) { |
2631 VP9_COMMON *cm = &cpi->common; | 2643 VP9_COMMON *cm = &cpi->common; |
2632 MACROBLOCKD *xd = &x->e_mbd; | 2644 MACROBLOCKD *xd = &x->e_mbd; |
2633 MB_MODE_INFO *mbmi = &xd->this_mi->mbmi; | 2645 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
2634 const int is_comp_pred = (mbmi->ref_frame[1] > 0); | 2646 const int is_comp_pred = has_second_ref(mbmi); |
2635 const int num_refs = is_comp_pred ? 2 : 1; | 2647 const int num_refs = is_comp_pred ? 2 : 1; |
2636 const int this_mode = mbmi->mode; | 2648 const int this_mode = mbmi->mode; |
2637 int_mv *frame_mv = mode_mv[this_mode]; | 2649 int_mv *frame_mv = mode_mv[this_mode]; |
2638 int i; | 2650 int i; |
2639 int refs[2] = { mbmi->ref_frame[0], | 2651 int refs[2] = { mbmi->ref_frame[0], |
2640 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; | 2652 (mbmi->ref_frame[1] < 0 ? 0 : mbmi->ref_frame[1]) }; |
2641 int_mv cur_mv[2]; | 2653 int_mv cur_mv[2]; |
2642 int64_t this_rd = 0; | 2654 int64_t this_rd = 0; |
2643 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); | 2655 DECLARE_ALIGNED_ARRAY(16, uint8_t, tmp_buf, MAX_MB_PLANE * 64 * 64); |
2644 int pred_exists = 0; | 2656 int pred_exists = 0; |
2645 int intpel_mv; | 2657 int intpel_mv; |
2646 int64_t rd, best_rd = INT64_MAX; | 2658 int64_t rd, best_rd = INT64_MAX; |
2647 int best_needs_copy = 0; | 2659 int best_needs_copy = 0; |
2648 uint8_t *orig_dst[MAX_MB_PLANE]; | 2660 uint8_t *orig_dst[MAX_MB_PLANE]; |
2649 int orig_dst_stride[MAX_MB_PLANE]; | 2661 int orig_dst_stride[MAX_MB_PLANE]; |
2650 int rs = 0; | 2662 int rs = 0; |
2651 | 2663 |
2652 if (this_mode == NEWMV) { | 2664 if (this_mode == NEWMV) { |
2653 int rate_mv; | 2665 int rate_mv; |
2654 if (is_comp_pred) { | 2666 if (is_comp_pred) { |
2655 // Initialize mv using single prediction mode result. | 2667 // Initialize mv using single prediction mode result. |
2656 frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int; | 2668 frame_mv[refs[0]].as_int = single_newmv[refs[0]].as_int; |
2657 frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int; | 2669 frame_mv[refs[1]].as_int = single_newmv[refs[1]].as_int; |
2658 | 2670 |
2659 if (cpi->sf.comp_inter_joint_search_thresh <= bsize) { | 2671 if (cpi->sf.comp_inter_joint_search_thresh <= bsize) { |
2660 joint_motion_search(cpi, x, bsize, frame_mv, | 2672 joint_motion_search(cpi, x, bsize, frame_mv, |
2661 mi_row, mi_col, single_newmv, &rate_mv); | 2673 mi_row, mi_col, single_newmv, &rate_mv); |
2662 } else { | 2674 } else { |
2663 rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]], | 2675 rate_mv = vp9_mv_bit_cost(&frame_mv[refs[0]].as_mv, |
2664 &mbmi->ref_mvs[refs[0]][0], | 2676 &mbmi->ref_mvs[refs[0]][0].as_mv, |
2665 x->nmvjointcost, x->mvcost, 96); | 2677 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
2666 rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]], | 2678 rate_mv += vp9_mv_bit_cost(&frame_mv[refs[1]].as_mv, |
2667 &mbmi->ref_mvs[refs[1]][0], | 2679 &mbmi->ref_mvs[refs[1]][0].as_mv, |
2668 x->nmvjointcost, x->mvcost, 96); | 2680 x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); |
2669 } | 2681 } |
2670 if (frame_mv[refs[0]].as_int == INVALID_MV || | 2682 if (frame_mv[refs[0]].as_int == INVALID_MV || |
2671 frame_mv[refs[1]].as_int == INVALID_MV) | 2683 frame_mv[refs[1]].as_int == INVALID_MV) |
2672 return INT64_MAX; | 2684 return INT64_MAX; |
2673 *rate2 += rate_mv; | 2685 *rate2 += rate_mv; |
2674 } else { | 2686 } else { |
2675 int_mv tmp_mv; | 2687 int_mv tmp_mv; |
2676 single_motion_search(cpi, x, bsize, mi_row, mi_col, &tmp_mv, &rate_mv); | 2688 single_motion_search(cpi, x, tile, bsize, mi_row, mi_col, |
| 2689 &tmp_mv, &rate_mv); |
2677 *rate2 += rate_mv; | 2690 *rate2 += rate_mv; |
2678 frame_mv[refs[0]].as_int = | 2691 frame_mv[refs[0]].as_int = |
2679 xd->this_mi->bmi[0].as_mv[0].as_int = tmp_mv.as_int; | 2692 xd->mi_8x8[0]->bmi[0].as_mv[0].as_int = tmp_mv.as_int; |
2680 single_newmv[refs[0]].as_int = tmp_mv.as_int; | 2693 single_newmv[refs[0]].as_int = tmp_mv.as_int; |
2681 } | 2694 } |
2682 } | 2695 } |
2683 | 2696 |
2684 // if we're near/nearest and mv == 0,0, compare to zeromv | 2697 // if we're near/nearest and mv == 0,0, compare to zeromv |
2685 if ((this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) && | 2698 if ((this_mode == NEARMV || this_mode == NEARESTMV || this_mode == ZEROMV) && |
2686 frame_mv[refs[0]].as_int == 0 && | 2699 frame_mv[refs[0]].as_int == 0 && |
2687 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) && | 2700 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP) && |
2688 (num_refs == 1 || frame_mv[refs[1]].as_int == 0)) { | 2701 (num_refs == 1 || frame_mv[refs[1]].as_int == 0)) { |
2689 int rfc = mbmi->mode_context[mbmi->ref_frame[0]]; | 2702 int rfc = mbmi->mode_context[mbmi->ref_frame[0]]; |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2996 } | 3009 } |
2997 return INT64_MAX; | 3010 return INT64_MAX; |
2998 } | 3011 } |
2999 | 3012 |
3000 *rate2 += *rate_y; | 3013 *rate2 += *rate_y; |
3001 *distortion += *distortion_y; | 3014 *distortion += *distortion_y; |
3002 | 3015 |
3003 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); | 3016 rdcosty = RDCOST(x->rdmult, x->rddiv, *rate2, *distortion); |
3004 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse)); | 3017 rdcosty = MIN(rdcosty, RDCOST(x->rdmult, x->rddiv, 0, *psse)); |
3005 | 3018 |
3006 super_block_uvrd(cm, x, rate_uv, distortion_uv, &skippable_uv, &sseuv, | 3019 super_block_uvrd(cpi, x, rate_uv, distortion_uv, &skippable_uv, &sseuv, |
3007 bsize, ref_best_rd - rdcosty); | 3020 bsize, ref_best_rd - rdcosty); |
3008 if (*rate_uv == INT_MAX) { | 3021 if (*rate_uv == INT_MAX) { |
3009 *rate2 = INT_MAX; | 3022 *rate2 = INT_MAX; |
3010 *distortion = INT64_MAX; | 3023 *distortion = INT64_MAX; |
3011 for (i = 0; i < MAX_MB_PLANE; i++) { | 3024 for (i = 0; i < MAX_MB_PLANE; i++) { |
3012 xd->plane[i].dst.buf = orig_dst[i]; | 3025 xd->plane[i].dst.buf = orig_dst[i]; |
3013 xd->plane[i].dst.stride = orig_dst_stride[i]; | 3026 xd->plane[i].dst.stride = orig_dst_stride[i]; |
3014 } | 3027 } |
3015 return INT64_MAX; | 3028 return INT64_MAX; |
3016 } | 3029 } |
(...skipping 16 matching lines...) Expand all Loading... |
3033 int *returnrate, int64_t *returndist, | 3046 int *returnrate, int64_t *returndist, |
3034 BLOCK_SIZE bsize, | 3047 BLOCK_SIZE bsize, |
3035 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { | 3048 PICK_MODE_CONTEXT *ctx, int64_t best_rd) { |
3036 VP9_COMMON *const cm = &cpi->common; | 3049 VP9_COMMON *const cm = &cpi->common; |
3037 MACROBLOCKD *const xd = &x->e_mbd; | 3050 MACROBLOCKD *const xd = &x->e_mbd; |
3038 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; | 3051 int rate_y = 0, rate_uv = 0, rate_y_tokenonly = 0, rate_uv_tokenonly = 0; |
3039 int y_skip = 0, uv_skip = 0; | 3052 int y_skip = 0, uv_skip = 0; |
3040 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; | 3053 int64_t dist_y = 0, dist_uv = 0, tx_cache[TX_MODES] = { 0 }; |
3041 x->skip_encode = 0; | 3054 x->skip_encode = 0; |
3042 ctx->skip = 0; | 3055 ctx->skip = 0; |
3043 xd->this_mi->mbmi.ref_frame[0] = INTRA_FRAME; | 3056 xd->mi_8x8[0]->mbmi.ref_frame[0] = INTRA_FRAME; |
3044 if (bsize >= BLOCK_8X8) { | 3057 if (bsize >= BLOCK_8X8) { |
3045 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly, | 3058 if (rd_pick_intra_sby_mode(cpi, x, &rate_y, &rate_y_tokenonly, |
3046 &dist_y, &y_skip, bsize, tx_cache, | 3059 &dist_y, &y_skip, bsize, tx_cache, |
3047 best_rd) >= best_rd) { | 3060 best_rd) >= best_rd) { |
3048 *returnrate = INT_MAX; | 3061 *returnrate = INT_MAX; |
3049 return; | 3062 return; |
3050 } | 3063 } |
3051 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly, | 3064 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv, &rate_uv_tokenonly, |
3052 &dist_uv, &uv_skip, bsize); | 3065 &dist_uv, &uv_skip, bsize); |
3053 } else { | 3066 } else { |
(...skipping 11 matching lines...) Expand all Loading... |
3065 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + | 3078 *returnrate = rate_y + rate_uv - rate_y_tokenonly - rate_uv_tokenonly + |
3066 vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 1); | 3079 vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 1); |
3067 *returndist = dist_y + dist_uv; | 3080 *returndist = dist_y + dist_uv; |
3068 vp9_zero(ctx->tx_rd_diff); | 3081 vp9_zero(ctx->tx_rd_diff); |
3069 } else { | 3082 } else { |
3070 int i; | 3083 int i; |
3071 *returnrate = rate_y + rate_uv + | 3084 *returnrate = rate_y + rate_uv + |
3072 vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 0); | 3085 vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), 0); |
3073 *returndist = dist_y + dist_uv; | 3086 *returndist = dist_y + dist_uv; |
3074 if (cpi->sf.tx_size_search_method == USE_FULL_RD) | 3087 if (cpi->sf.tx_size_search_method == USE_FULL_RD) |
3075 for (i = 0; i < TX_MODES; i++) | 3088 for (i = 0; i < TX_MODES; i++) { |
3076 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; | 3089 if (tx_cache[i] < INT64_MAX && tx_cache[cm->tx_mode] < INT64_MAX) |
| 3090 ctx->tx_rd_diff[i] = tx_cache[i] - tx_cache[cm->tx_mode]; |
| 3091 else |
| 3092 ctx->tx_rd_diff[i] = 0; |
| 3093 } |
3077 } | 3094 } |
3078 | 3095 |
3079 ctx->mic = *xd->this_mi; | 3096 ctx->mic = *xd->mi_8x8[0]; |
3080 } | 3097 } |
3081 | 3098 |
3082 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, | 3099 int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, |
| 3100 const TileInfo *const tile, |
3083 int mi_row, int mi_col, | 3101 int mi_row, int mi_col, |
3084 int *returnrate, | 3102 int *returnrate, |
3085 int64_t *returndistortion, | 3103 int64_t *returndistortion, |
3086 BLOCK_SIZE bsize, | 3104 BLOCK_SIZE bsize, |
3087 PICK_MODE_CONTEXT *ctx, | 3105 PICK_MODE_CONTEXT *ctx, |
3088 int64_t best_rd_so_far) { | 3106 int64_t best_rd_so_far) { |
3089 VP9_COMMON *cm = &cpi->common; | 3107 VP9_COMMON *cm = &cpi->common; |
3090 MACROBLOCKD *xd = &x->e_mbd; | 3108 MACROBLOCKD *xd = &x->e_mbd; |
3091 MB_MODE_INFO *mbmi = &xd->this_mi->mbmi; | 3109 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
3092 const struct segmentation *seg = &cm->seg; | 3110 const struct segmentation *seg = &cm->seg; |
3093 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); | 3111 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); |
3094 RD_PREDICTION_MODE this_mode; | 3112 MB_PREDICTION_MODE this_mode; |
3095 MV_REFERENCE_FRAME ref_frame, second_ref_frame; | 3113 MV_REFERENCE_FRAME ref_frame, second_ref_frame; |
3096 unsigned char segment_id = mbmi->segment_id; | 3114 unsigned char segment_id = mbmi->segment_id; |
3097 int comp_pred, i; | 3115 int comp_pred, i; |
3098 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 3116 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
3099 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 3117 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
3100 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; | 3118 int_mv single_newmv[MAX_REF_FRAMES] = { { 0 } }; |
3101 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 3119 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
3102 VP9_ALT_FLAG }; | 3120 VP9_ALT_FLAG }; |
3103 int idx_list[4] = {0, | 3121 int idx_list[4] = {0, |
3104 cpi->lst_fb_idx, | 3122 cpi->lst_fb_idx, |
3105 cpi->gld_fb_idx, | 3123 cpi->gld_fb_idx, |
3106 cpi->alt_fb_idx}; | 3124 cpi->alt_fb_idx}; |
3107 int64_t best_rd = best_rd_so_far; | 3125 int64_t best_rd = best_rd_so_far; |
3108 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise | |
3109 int64_t best_tx_rd[TX_MODES]; | 3126 int64_t best_tx_rd[TX_MODES]; |
3110 int64_t best_tx_diff[TX_MODES]; | 3127 int64_t best_tx_diff[TX_MODES]; |
3111 int64_t best_pred_diff[NB_PREDICTION_TYPES]; | 3128 int64_t best_pred_diff[NB_PREDICTION_TYPES]; |
3112 int64_t best_pred_rd[NB_PREDICTION_TYPES]; | 3129 int64_t best_pred_rd[NB_PREDICTION_TYPES]; |
3113 int64_t best_filter_rd[SWITCHABLE_FILTERS + 1]; | 3130 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; |
3114 int64_t best_filter_diff[SWITCHABLE_FILTERS + 1]; | 3131 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; |
3115 MB_MODE_INFO best_mbmode = { 0 }; | 3132 MB_MODE_INFO best_mbmode = { 0 }; |
3116 int j; | 3133 int j; |
3117 int mode_index, best_mode_index = 0; | 3134 int mode_index, best_mode_index = 0; |
3118 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; | 3135 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; |
3119 vp9_prob comp_mode_p; | 3136 vp9_prob comp_mode_p; |
3120 int64_t best_intra_rd = INT64_MAX; | 3137 int64_t best_intra_rd = INT64_MAX; |
3121 int64_t best_inter_rd = INT64_MAX; | 3138 int64_t best_inter_rd = INT64_MAX; |
3122 MB_PREDICTION_MODE best_intra_mode = DC_PRED; | 3139 MB_PREDICTION_MODE best_intra_mode = DC_PRED; |
3123 // MB_PREDICTION_MODE best_inter_mode = ZEROMV; | |
3124 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; | 3140 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; |
3125 INTERPOLATIONFILTERTYPE tmp_best_filter = SWITCHABLE; | 3141 INTERPOLATION_TYPE tmp_best_filter = SWITCHABLE; |
3126 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; | 3142 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; |
3127 int64_t dist_uv[TX_SIZES]; | 3143 int64_t dist_uv[TX_SIZES]; |
3128 int skip_uv[TX_SIZES]; | 3144 int skip_uv[TX_SIZES]; |
3129 MB_PREDICTION_MODE mode_uv[TX_SIZES]; | 3145 MB_PREDICTION_MODE mode_uv[TX_SIZES]; |
3130 struct scale_factors scale_factor[4]; | 3146 struct scale_factors scale_factor[4]; |
3131 unsigned int ref_frame_mask = 0; | 3147 unsigned int ref_frame_mask = 0; |
3132 unsigned int mode_mask = 0; | 3148 unsigned int mode_mask = 0; |
3133 int64_t mode_distortions[MB_MODE_COUNT] = {-1}; | 3149 int64_t mode_distortions[MB_MODE_COUNT] = {-1}; |
3134 int64_t frame_distortions[MAX_REF_FRAMES] = {-1}; | 3150 int64_t frame_distortions[MAX_REF_FRAMES] = {-1}; |
3135 int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex, | 3151 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); |
3136 cpi->common.y_dc_delta_q); | |
3137 int_mv seg_mvs[4][MAX_REF_FRAMES]; | |
3138 union b_mode_info best_bmodes[4]; | |
3139 PARTITION_INFO best_partition; | |
3140 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2; | 3152 const int bws = num_8x8_blocks_wide_lookup[bsize] / 2; |
3141 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2; | 3153 const int bhs = num_8x8_blocks_high_lookup[bsize] / 2; |
3142 int best_skip2 = 0; | 3154 int best_skip2 = 0; |
3143 | 3155 |
3144 x->skip_encode = cpi->sf.skip_encode_frame && xd->q_index < QIDX_SKIP_THRESH; | 3156 x->skip_encode = cpi->sf.skip_encode_frame && xd->q_index < QIDX_SKIP_THRESH; |
3145 | 3157 |
3146 for (i = 0; i < 4; i++) { | |
3147 int j; | |
3148 for (j = 0; j < MAX_REF_FRAMES; j++) | |
3149 seg_mvs[i][j].as_int = INVALID_MV; | |
3150 } | |
3151 // Everywhere the flag is set the error is much higher than its neighbors. | 3158 // Everywhere the flag is set the error is much higher than its neighbors. |
3152 ctx->frames_with_high_error = 0; | 3159 ctx->frames_with_high_error = 0; |
3153 ctx->modes_with_high_error = 0; | 3160 ctx->modes_with_high_error = 0; |
3154 | 3161 |
3155 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp, | 3162 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp, |
3156 &comp_mode_p); | 3163 &comp_mode_p); |
3157 | 3164 |
3158 for (i = 0; i < NB_PREDICTION_TYPES; ++i) | 3165 for (i = 0; i < NB_PREDICTION_TYPES; ++i) |
3159 best_pred_rd[i] = INT64_MAX; | 3166 best_pred_rd[i] = INT64_MAX; |
3160 for (i = 0; i < TX_MODES; i++) | 3167 for (i = 0; i < TX_MODES; i++) |
3161 best_tx_rd[i] = INT64_MAX; | 3168 best_tx_rd[i] = INT64_MAX; |
3162 for (i = 0; i <= SWITCHABLE_FILTERS; i++) | 3169 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
3163 best_filter_rd[i] = INT64_MAX; | 3170 best_filter_rd[i] = INT64_MAX; |
3164 for (i = 0; i < TX_SIZES; i++) | 3171 for (i = 0; i < TX_SIZES; i++) |
3165 rate_uv_intra[i] = INT_MAX; | 3172 rate_uv_intra[i] = INT_MAX; |
3166 | 3173 |
3167 *returnrate = INT_MAX; | 3174 *returnrate = INT_MAX; |
3168 | 3175 |
3169 // Create a mask set to 1 for each reference frame used by a smaller | 3176 // Create a mask set to 1 for each reference frame used by a smaller |
3170 // resolution. | 3177 // resolution. |
3171 if (cpi->sf.use_avoid_tested_higherror) { | 3178 if (cpi->sf.use_avoid_tested_higherror) { |
3172 switch (block_size) { | 3179 switch (block_size) { |
(...skipping 21 matching lines...) Expand all Loading... |
3194 ref_frame_mask = 0; | 3201 ref_frame_mask = 0; |
3195 mode_mask = 0; | 3202 mode_mask = 0; |
3196 break; | 3203 break; |
3197 } | 3204 } |
3198 ref_frame_mask = ~ref_frame_mask; | 3205 ref_frame_mask = ~ref_frame_mask; |
3199 mode_mask = ~mode_mask; | 3206 mode_mask = ~mode_mask; |
3200 } | 3207 } |
3201 | 3208 |
3202 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { | 3209 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { |
3203 if (cpi->ref_frame_flags & flag_list[ref_frame]) { | 3210 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
3204 setup_buffer_inter(cpi, x, idx_list[ref_frame], ref_frame, block_size, | 3211 setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame, |
3205 mi_row, mi_col, frame_mv[NEARESTMV], frame_mv[NEARMV], | 3212 block_size, mi_row, mi_col, |
| 3213 frame_mv[NEARESTMV], frame_mv[NEARMV], |
3206 yv12_mb, scale_factor); | 3214 yv12_mb, scale_factor); |
3207 } | 3215 } |
3208 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; | 3216 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
3209 frame_mv[ZEROMV][ref_frame].as_int = 0; | 3217 frame_mv[ZEROMV][ref_frame].as_int = 0; |
3210 } | 3218 } |
3211 | 3219 |
3212 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { | 3220 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { |
3213 int mode_excluded = 0; | 3221 int mode_excluded = 0; |
3214 int64_t this_rd = INT64_MAX; | 3222 int64_t this_rd = INT64_MAX; |
3215 int disable_skip = 0; | 3223 int disable_skip = 0; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3256 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index)) | 3264 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index)) |
3257 continue; | 3265 continue; |
3258 } | 3266 } |
3259 | 3267 |
3260 // Skip if the current reference frame has been masked off | 3268 // Skip if the current reference frame has been masked off |
3261 if (cpi->sf.reference_masking && !cpi->set_ref_frame_mask && | 3269 if (cpi->sf.reference_masking && !cpi->set_ref_frame_mask && |
3262 (cpi->ref_frame_mask & (1 << ref_frame))) | 3270 (cpi->ref_frame_mask & (1 << ref_frame))) |
3263 continue; | 3271 continue; |
3264 | 3272 |
3265 // Test best rd so far against threshold for trying this mode. | 3273 // Test best rd so far against threshold for trying this mode. |
3266 if ((best_rd < ((cpi->rd_threshes[bsize][mode_index] * | 3274 if ((best_rd < ((int64_t)cpi->rd_threshes[segment_id][bsize][mode_index] * |
3267 cpi->rd_thresh_freq_fact[bsize][mode_index]) >> 5)) || | 3275 cpi->rd_thresh_freq_fact[bsize][mode_index] >> 5)) || |
3268 cpi->rd_threshes[bsize][mode_index] == INT_MAX) | 3276 cpi->rd_threshes[segment_id][bsize][mode_index] == INT_MAX) |
3269 continue; | 3277 continue; |
3270 | 3278 |
3271 // Do not allow compound prediction if the segment level reference | 3279 // Do not allow compound prediction if the segment level reference |
3272 // frame feature is in use as in this case there can only be one reference. | 3280 // frame feature is in use as in this case there can only be one reference. |
3273 if ((second_ref_frame > INTRA_FRAME) && | 3281 if ((second_ref_frame > INTRA_FRAME) && |
3274 vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) | 3282 vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) |
3275 continue; | 3283 continue; |
3276 | 3284 |
3277 // Skip some checking based on small partitions' result. | 3285 // Skip some checking based on small partitions' result. |
3278 if (x->fast_ms > 1 && !ref_frame) | 3286 if (x->fast_ms > 1 && !ref_frame) |
(...skipping 29 matching lines...) Expand all Loading... |
3308 comp_pred = second_ref_frame > INTRA_FRAME; | 3316 comp_pred = second_ref_frame > INTRA_FRAME; |
3309 if (comp_pred) { | 3317 if (comp_pred) { |
3310 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) | 3318 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) |
3311 if (vp9_mode_order[best_mode_index].ref_frame == INTRA_FRAME) | 3319 if (vp9_mode_order[best_mode_index].ref_frame == INTRA_FRAME) |
3312 continue; | 3320 continue; |
3313 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) | 3321 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) |
3314 if (ref_frame != best_inter_ref_frame && | 3322 if (ref_frame != best_inter_ref_frame && |
3315 second_ref_frame != best_inter_ref_frame) | 3323 second_ref_frame != best_inter_ref_frame) |
3316 continue; | 3324 continue; |
3317 } | 3325 } |
3318 // TODO(jingning, jkoleszar): scaling reference frame not supported for | |
3319 // SPLITMV. | |
3320 if (ref_frame > 0 && | |
3321 vp9_is_scaled(&scale_factor[ref_frame]) && | |
3322 this_mode == RD_SPLITMV) | |
3323 continue; | |
3324 | |
3325 if (second_ref_frame > 0 && | |
3326 vp9_is_scaled(&scale_factor[second_ref_frame]) && | |
3327 this_mode == RD_SPLITMV) | |
3328 continue; | |
3329 | |
3330 if (bsize >= BLOCK_8X8 && | |
3331 (this_mode == RD_I4X4_PRED || this_mode == RD_SPLITMV)) | |
3332 continue; | |
3333 | |
3334 if (bsize < BLOCK_8X8 && | |
3335 !(this_mode == RD_I4X4_PRED || this_mode == RD_SPLITMV)) | |
3336 continue; | |
3337 | 3326 |
3338 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); | 3327 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); |
3339 mbmi->uv_mode = DC_PRED; | 3328 mbmi->uv_mode = DC_PRED; |
3340 | 3329 |
3341 // Evaluate all sub-pel filters irrespective of whether we can use | 3330 // Evaluate all sub-pel filters irrespective of whether we can use |
3342 // them for this frame. | 3331 // them for this frame. |
3343 mbmi->interp_filter = cm->mcomp_filter_type; | 3332 mbmi->interp_filter = cm->mcomp_filter_type; |
3344 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); | 3333 vp9_setup_interp_filters(xd, mbmi->interp_filter, cm); |
3345 | 3334 |
3346 if (comp_pred) { | 3335 if (comp_pred) { |
3347 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) | 3336 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) |
3348 continue; | 3337 continue; |
3349 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); | 3338 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); |
3350 | 3339 |
3351 mode_excluded = mode_excluded | 3340 mode_excluded = mode_excluded |
3352 ? mode_excluded | 3341 ? mode_excluded |
3353 : cm->comp_pred_mode == SINGLE_PREDICTION_ONLY; | 3342 : cm->comp_pred_mode == SINGLE_PREDICTION_ONLY; |
3354 } else { | 3343 } else { |
(...skipping 13 matching lines...) Expand all Loading... |
3368 | 3357 |
3369 // If the segment reference frame feature is enabled.... | 3358 // If the segment reference frame feature is enabled.... |
3370 // then do nothing if the current ref frame is not allowed.. | 3359 // then do nothing if the current ref frame is not allowed.. |
3371 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && | 3360 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
3372 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != | 3361 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != |
3373 (int)ref_frame) { | 3362 (int)ref_frame) { |
3374 continue; | 3363 continue; |
3375 // If the segment skip feature is enabled.... | 3364 // If the segment skip feature is enabled.... |
3376 // then do nothing if the current mode is not allowed.. | 3365 // then do nothing if the current mode is not allowed.. |
3377 } else if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) && | 3366 } else if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) && |
3378 (this_mode != RD_ZEROMV && ref_frame != INTRA_FRAME)) { | 3367 (this_mode != ZEROMV && ref_frame != INTRA_FRAME)) { |
3379 continue; | 3368 continue; |
3380 // Disable this drop out case if the ref frame | 3369 // Disable this drop out case if the ref frame |
3381 // segment level feature is enabled for this segment. This is to | 3370 // segment level feature is enabled for this segment. This is to |
3382 // prevent the possibility that we end up unable to pick any mode. | 3371 // prevent the possibility that we end up unable to pick any mode. |
3383 } else if (!vp9_segfeature_active(seg, segment_id, | 3372 } else if (!vp9_segfeature_active(seg, segment_id, |
3384 SEG_LVL_REF_FRAME)) { | 3373 SEG_LVL_REF_FRAME)) { |
3385 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, | 3374 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, |
3386 // unless ARNR filtering is enabled in which case we want | 3375 // unless ARNR filtering is enabled in which case we want |
3387 // an unfiltered alternative. We allow near/nearest as well | 3376 // an unfiltered alternative. We allow near/nearest as well |
3388 // because they may result in zero-zero MVs but be cheaper. | 3377 // because they may result in zero-zero MVs but be cheaper. |
3389 if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) { | 3378 if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) { |
3390 if ((this_mode != RD_ZEROMV && | 3379 if ((this_mode != ZEROMV && |
3391 !(this_mode == RD_NEARMV && | 3380 !(this_mode == NEARMV && |
3392 frame_mv[RD_NEARMV][ALTREF_FRAME].as_int == 0) && | 3381 frame_mv[NEARMV][ALTREF_FRAME].as_int == 0) && |
3393 !(this_mode == RD_NEARESTMV && | 3382 !(this_mode == NEARESTMV && |
3394 frame_mv[RD_NEARESTMV][ALTREF_FRAME].as_int == 0)) || | 3383 frame_mv[NEARESTMV][ALTREF_FRAME].as_int == 0)) || |
3395 ref_frame != ALTREF_FRAME) { | 3384 ref_frame != ALTREF_FRAME) { |
3396 continue; | 3385 continue; |
3397 } | 3386 } |
3398 } | 3387 } |
3399 } | 3388 } |
3400 // TODO(JBB): This is to make up for the fact that we don't have sad | 3389 // TODO(JBB): This is to make up for the fact that we don't have sad |
3401 // functions that work when the block size reads outside the umv. We | 3390 // functions that work when the block size reads outside the umv. We |
3402 // should fix this either by making the motion search just work on | 3391 // should fix this either by making the motion search just work on |
3403 // a representative block in the boundary ( first ) and then implement a | 3392 // a representative block in the boundary ( first ) and then implement a |
3404 // function that does sads when inside the border.. | 3393 // function that does sads when inside the border.. |
3405 if (((mi_row + bhs) > cm->mi_rows || (mi_col + bws) > cm->mi_cols) && | 3394 if (((mi_row + bhs) > cm->mi_rows || (mi_col + bws) > cm->mi_cols) && |
3406 this_mode == RD_NEWMV) { | 3395 this_mode == NEWMV) { |
3407 continue; | 3396 continue; |
3408 } | 3397 } |
3409 | 3398 |
3410 #ifdef MODE_TEST_HIT_STATS | 3399 #ifdef MODE_TEST_HIT_STATS |
3411 // TEST/DEBUG CODE | 3400 // TEST/DEBUG CODE |
3412 // Keep a rcord of the number of test hits at each size | 3401 // Keep a rcord of the number of test hits at each size |
3413 cpi->mode_test_hits[bsize]++; | 3402 cpi->mode_test_hits[bsize]++; |
3414 #endif | 3403 #endif |
3415 | 3404 |
3416 if (this_mode == RD_I4X4_PRED) { | |
3417 int rate; | |
3418 | 3405 |
3419 /* | 3406 if (ref_frame == INTRA_FRAME) { |
3420 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) && | |
3421 (vp9_mode_order[best_mode_index].ref_frame > INTRA_FRAME)) | |
3422 continue; | |
3423 */ | |
3424 | |
3425 // RD_I4X4_PRED is only considered for block sizes less than 8x8. | |
3426 mbmi->tx_size = TX_4X4; | |
3427 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate, &rate_y, | |
3428 &distortion_y, best_rd) >= best_rd) | |
3429 continue; | |
3430 rate2 += rate; | |
3431 rate2 += intra_cost_penalty; | |
3432 distortion2 += distortion_y; | |
3433 | |
3434 if (rate_uv_intra[TX_4X4] == INT_MAX) { | |
3435 choose_intra_uv_mode(cpi, bsize, &rate_uv_intra[TX_4X4], | |
3436 &rate_uv_tokenonly[TX_4X4], | |
3437 &dist_uv[TX_4X4], &skip_uv[TX_4X4], | |
3438 &mode_uv[TX_4X4]); | |
3439 } | |
3440 rate2 += rate_uv_intra[TX_4X4]; | |
3441 rate_uv = rate_uv_tokenonly[TX_4X4]; | |
3442 distortion2 += dist_uv[TX_4X4]; | |
3443 distortion_uv = dist_uv[TX_4X4]; | |
3444 mbmi->uv_mode = mode_uv[TX_4X4]; | |
3445 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | |
3446 for (i = 0; i < TX_MODES; ++i) | |
3447 tx_cache[i] = tx_cache[ONLY_4X4]; | |
3448 } else if (ref_frame == INTRA_FRAME) { | |
3449 TX_SIZE uv_tx; | 3407 TX_SIZE uv_tx; |
3450 // Disable intra modes other than DC_PRED for blocks with low variance | 3408 // Disable intra modes other than DC_PRED for blocks with low variance |
3451 // Threshold for intra skipping based on source variance | 3409 // Threshold for intra skipping based on source variance |
3452 // TODO(debargha): Specialize the threshold for super block sizes | 3410 // TODO(debargha): Specialize the threshold for super block sizes |
3453 static const unsigned int skip_intra_var_thresh[BLOCK_SIZES] = { | 3411 static const unsigned int skip_intra_var_thresh[BLOCK_SIZES] = { |
3454 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, | 3412 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, |
3455 }; | 3413 }; |
3456 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) && | 3414 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_LOWVAR) && |
3457 this_mode != RD_DC_PRED && | 3415 this_mode != DC_PRED && |
3458 x->source_variance < skip_intra_var_thresh[mbmi->sb_type]) | 3416 x->source_variance < skip_intra_var_thresh[mbmi->sb_type]) |
3459 continue; | 3417 continue; |
3460 // Only search the oblique modes if the best so far is | 3418 // Only search the oblique modes if the best so far is |
3461 // one of the neighboring directional modes | 3419 // one of the neighboring directional modes |
3462 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) && | 3420 if ((cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_BESTINTER) && |
3463 (this_mode >= RD_D45_PRED && this_mode <= RD_TM_PRED)) { | 3421 (this_mode >= D45_PRED && this_mode <= TM_PRED)) { |
3464 if (vp9_mode_order[best_mode_index].ref_frame > INTRA_FRAME) | 3422 if (vp9_mode_order[best_mode_index].ref_frame > INTRA_FRAME) |
3465 continue; | 3423 continue; |
3466 } | 3424 } |
3467 mbmi->mode = rd_mode_to_mode(this_mode); | 3425 mbmi->mode = this_mode; |
3468 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { | 3426 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_INTRA_DIRMISMATCH) { |
3469 if (conditional_skipintra(mbmi->mode, best_intra_mode)) | 3427 if (conditional_skipintra(mbmi->mode, best_intra_mode)) |
3470 continue; | 3428 continue; |
3471 } | 3429 } |
3472 | 3430 |
3473 super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, NULL, | 3431 super_block_yrd(cpi, x, &rate_y, &distortion_y, &skippable, NULL, |
3474 bsize, tx_cache, best_rd); | 3432 bsize, tx_cache, best_rd); |
3475 | 3433 |
3476 if (rate_y == INT_MAX) | 3434 if (rate_y == INT_MAX) |
3477 continue; | 3435 continue; |
3478 | 3436 |
3479 uv_tx = MIN(mbmi->tx_size, max_uv_txsize_lookup[bsize]); | 3437 uv_tx = MIN(mbmi->tx_size, max_uv_txsize_lookup[bsize]); |
3480 if (rate_uv_intra[uv_tx] == INT_MAX) { | 3438 if (rate_uv_intra[uv_tx] == INT_MAX) { |
3481 choose_intra_uv_mode(cpi, bsize, &rate_uv_intra[uv_tx], | 3439 choose_intra_uv_mode(cpi, bsize, &rate_uv_intra[uv_tx], |
3482 &rate_uv_tokenonly[uv_tx], | 3440 &rate_uv_tokenonly[uv_tx], |
3483 &dist_uv[uv_tx], &skip_uv[uv_tx], | 3441 &dist_uv[uv_tx], &skip_uv[uv_tx], |
3484 &mode_uv[uv_tx]); | 3442 &mode_uv[uv_tx]); |
3485 } | 3443 } |
3486 | 3444 |
3487 rate_uv = rate_uv_tokenonly[uv_tx]; | 3445 rate_uv = rate_uv_tokenonly[uv_tx]; |
3488 distortion_uv = dist_uv[uv_tx]; | 3446 distortion_uv = dist_uv[uv_tx]; |
3489 skippable = skippable && skip_uv[uv_tx]; | 3447 skippable = skippable && skip_uv[uv_tx]; |
3490 mbmi->uv_mode = mode_uv[uv_tx]; | 3448 mbmi->uv_mode = mode_uv[uv_tx]; |
3491 | 3449 |
3492 rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx]; | 3450 rate2 = rate_y + x->mbmode_cost[mbmi->mode] + rate_uv_intra[uv_tx]; |
3493 if (this_mode != RD_DC_PRED && this_mode != RD_TM_PRED) | 3451 if (this_mode != DC_PRED && this_mode != TM_PRED) |
3494 rate2 += intra_cost_penalty; | 3452 rate2 += intra_cost_penalty; |
3495 distortion2 = distortion_y + distortion_uv; | 3453 distortion2 = distortion_y + distortion_uv; |
3496 } else if (this_mode == RD_SPLITMV) { | 3454 } else { |
3497 const int is_comp_pred = second_ref_frame > 0; | 3455 mbmi->mode = this_mode; |
| 3456 compmode_cost = vp9_cost_bit(comp_mode_p, second_ref_frame > INTRA_FRAME); |
| 3457 this_rd = handle_inter_mode(cpi, x, tile, bsize, |
| 3458 tx_cache, |
| 3459 &rate2, &distortion2, &skippable, |
| 3460 &rate_y, &distortion_y, |
| 3461 &rate_uv, &distortion_uv, |
| 3462 &mode_excluded, &disable_skip, |
| 3463 &tmp_best_filter, frame_mv, |
| 3464 mi_row, mi_col, |
| 3465 single_newmv, &total_sse, best_rd); |
| 3466 if (this_rd == INT64_MAX) |
| 3467 continue; |
| 3468 } |
| 3469 |
| 3470 if (cm->comp_pred_mode == HYBRID_PREDICTION) { |
| 3471 rate2 += compmode_cost; |
| 3472 } |
| 3473 |
| 3474 // Estimate the reference frame signaling cost and add it |
| 3475 // to the rolling cost variable. |
| 3476 if (second_ref_frame > INTRA_FRAME) { |
| 3477 rate2 += ref_costs_comp[ref_frame]; |
| 3478 } else { |
| 3479 rate2 += ref_costs_single[ref_frame]; |
| 3480 } |
| 3481 |
| 3482 if (!disable_skip) { |
| 3483 // Test for the condition where skip block will be activated |
| 3484 // because there are no non zero coefficients and make any |
| 3485 // necessary adjustment for rate. Ignore if skip is coded at |
| 3486 // segment level as the cost wont have been added in. |
| 3487 // Is Mb level skip allowed (i.e. not coded at segment level). |
| 3488 const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id, |
| 3489 SEG_LVL_SKIP); |
| 3490 |
| 3491 if (skippable) { |
| 3492 // Back out the coefficient coding costs |
| 3493 rate2 -= (rate_y + rate_uv); |
| 3494 // for best yrd calculation |
| 3495 rate_uv = 0; |
| 3496 |
| 3497 if (mb_skip_allowed) { |
| 3498 int prob_skip_cost; |
| 3499 |
| 3500 // Cost the skip mb case |
| 3501 vp9_prob skip_prob = |
| 3502 vp9_get_pred_prob_mbskip(cm, xd); |
| 3503 |
| 3504 if (skip_prob) { |
| 3505 prob_skip_cost = vp9_cost_bit(skip_prob, 1); |
| 3506 rate2 += prob_skip_cost; |
| 3507 } |
| 3508 } |
| 3509 } else if (mb_skip_allowed && ref_frame != INTRA_FRAME && !xd->lossless) { |
| 3510 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < |
| 3511 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { |
| 3512 // Add in the cost of the no skip flag. |
| 3513 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), |
| 3514 0); |
| 3515 rate2 += prob_skip_cost; |
| 3516 } else { |
| 3517 // FIXME(rbultje) make this work for splitmv also |
| 3518 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), |
| 3519 1); |
| 3520 rate2 += prob_skip_cost; |
| 3521 distortion2 = total_sse; |
| 3522 assert(total_sse >= 0); |
| 3523 rate2 -= (rate_y + rate_uv); |
| 3524 rate_y = 0; |
| 3525 rate_uv = 0; |
| 3526 this_skip2 = 1; |
| 3527 } |
| 3528 } else if (mb_skip_allowed) { |
| 3529 // Add in the cost of the no skip flag. |
| 3530 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), |
| 3531 0); |
| 3532 rate2 += prob_skip_cost; |
| 3533 } |
| 3534 |
| 3535 // Calculate the final RD estimate for this mode. |
| 3536 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
| 3537 } |
| 3538 |
| 3539 // Keep record of best intra rd |
| 3540 if (xd->mi_8x8[0]->mbmi.ref_frame[0] == INTRA_FRAME && |
| 3541 is_intra_mode(xd->mi_8x8[0]->mbmi.mode) && |
| 3542 this_rd < best_intra_rd) { |
| 3543 best_intra_rd = this_rd; |
| 3544 best_intra_mode = xd->mi_8x8[0]->mbmi.mode; |
| 3545 } |
| 3546 // Keep record of best inter rd with single reference |
| 3547 if (xd->mi_8x8[0]->mbmi.ref_frame[0] > INTRA_FRAME && |
| 3548 xd->mi_8x8[0]->mbmi.ref_frame[1] == NONE && |
| 3549 !mode_excluded && |
| 3550 this_rd < best_inter_rd) { |
| 3551 best_inter_rd = this_rd; |
| 3552 best_inter_ref_frame = ref_frame; |
| 3553 } |
| 3554 |
| 3555 if (!disable_skip && ref_frame == INTRA_FRAME) { |
| 3556 for (i = 0; i < NB_PREDICTION_TYPES; ++i) |
| 3557 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); |
| 3558 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
| 3559 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); |
| 3560 } |
| 3561 |
| 3562 // Store the respective mode distortions for later use. |
| 3563 if (mode_distortions[this_mode] == -1 |
| 3564 || distortion2 < mode_distortions[this_mode]) { |
| 3565 mode_distortions[this_mode] = distortion2; |
| 3566 } |
| 3567 if (frame_distortions[ref_frame] == -1 |
| 3568 || distortion2 < frame_distortions[ref_frame]) { |
| 3569 frame_distortions[ref_frame] = distortion2; |
| 3570 } |
| 3571 |
| 3572 // Did this mode help.. i.e. is it the new best mode |
| 3573 if (this_rd < best_rd || x->skip) { |
| 3574 if (!mode_excluded) { |
| 3575 // Note index of best mode so far |
| 3576 best_mode_index = mode_index; |
| 3577 |
| 3578 if (ref_frame == INTRA_FRAME) { |
| 3579 /* required for left and above block mv */ |
| 3580 mbmi->mv[0].as_int = 0; |
| 3581 } |
| 3582 |
| 3583 *returnrate = rate2; |
| 3584 *returndistortion = distortion2; |
| 3585 best_rd = this_rd; |
| 3586 best_mbmode = *mbmi; |
| 3587 best_skip2 = this_skip2; |
| 3588 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], |
| 3589 sizeof(uint8_t) * ctx->num_4x4_blk); |
| 3590 |
| 3591 // TODO(debargha): enhance this test with a better distortion prediction |
| 3592 // based on qp, activity mask and history |
| 3593 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && |
| 3594 (mode_index > MIN_EARLY_TERM_INDEX)) { |
| 3595 const int qstep = xd->plane[0].dequant[1]; |
| 3596 // TODO(debargha): Enhance this by specializing for each mode_index |
| 3597 int scale = 4; |
| 3598 if (x->source_variance < UINT_MAX) { |
| 3599 const int var_adjust = (x->source_variance < 16); |
| 3600 scale -= var_adjust; |
| 3601 } |
| 3602 if (ref_frame > INTRA_FRAME && |
| 3603 distortion2 * scale < qstep * qstep) { |
| 3604 early_term = 1; |
| 3605 } |
| 3606 } |
| 3607 } |
| 3608 } |
| 3609 |
| 3610 /* keep record of best compound/single-only prediction */ |
| 3611 if (!disable_skip && ref_frame != INTRA_FRAME) { |
| 3612 int single_rd, hybrid_rd, single_rate, hybrid_rate; |
| 3613 |
| 3614 if (cm->comp_pred_mode == HYBRID_PREDICTION) { |
| 3615 single_rate = rate2 - compmode_cost; |
| 3616 hybrid_rate = rate2; |
| 3617 } else { |
| 3618 single_rate = rate2; |
| 3619 hybrid_rate = rate2 + compmode_cost; |
| 3620 } |
| 3621 |
| 3622 single_rd = RDCOST(x->rdmult, x->rddiv, single_rate, distortion2); |
| 3623 hybrid_rd = RDCOST(x->rdmult, x->rddiv, hybrid_rate, distortion2); |
| 3624 |
| 3625 if (second_ref_frame <= INTRA_FRAME && |
| 3626 single_rd < best_pred_rd[SINGLE_PREDICTION_ONLY]) { |
| 3627 best_pred_rd[SINGLE_PREDICTION_ONLY] = single_rd; |
| 3628 } else if (second_ref_frame > INTRA_FRAME && |
| 3629 single_rd < best_pred_rd[COMP_PREDICTION_ONLY]) { |
| 3630 best_pred_rd[COMP_PREDICTION_ONLY] = single_rd; |
| 3631 } |
| 3632 if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION]) |
| 3633 best_pred_rd[HYBRID_PREDICTION] = hybrid_rd; |
| 3634 } |
| 3635 |
| 3636 /* keep record of best filter type */ |
| 3637 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && |
| 3638 cm->mcomp_filter_type != BILINEAR) { |
| 3639 int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ? |
| 3640 SWITCHABLE_FILTERS : cm->mcomp_filter_type]; |
| 3641 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
| 3642 int64_t adj_rd; |
| 3643 // In cases of poor prediction, filter_cache[] can contain really big |
| 3644 // values, which actually are bigger than this_rd itself. This can |
| 3645 // cause negative best_filter_rd[] values, which is obviously silly. |
| 3646 // Therefore, if filter_cache < ref, we do an adjusted calculation. |
| 3647 if (cpi->rd_filter_cache[i] >= ref) { |
| 3648 adj_rd = this_rd + cpi->rd_filter_cache[i] - ref; |
| 3649 } else { |
| 3650 // FIXME(rbultje) do this for comppsred also |
| 3651 // |
| 3652 // To prevent out-of-range computation in |
| 3653 // adj_rd = cpi->rd_filter_cache[i] * this_rd / ref |
| 3654 // cpi->rd_filter_cache[i] / ref is converted to a 256 based ratio. |
| 3655 int tmp = cpi->rd_filter_cache[i] * 256 / ref; |
| 3656 adj_rd = (this_rd * tmp) >> 8; |
| 3657 } |
| 3658 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); |
| 3659 } |
| 3660 } |
| 3661 |
| 3662 /* keep record of best txfm size */ |
| 3663 if (bsize < BLOCK_32X32) { |
| 3664 if (bsize < BLOCK_16X16) |
| 3665 tx_cache[ALLOW_16X16] = tx_cache[ALLOW_8X8]; |
| 3666 |
| 3667 tx_cache[ALLOW_32X32] = tx_cache[ALLOW_16X16]; |
| 3668 } |
| 3669 if (!mode_excluded && this_rd != INT64_MAX) { |
| 3670 for (i = 0; i < TX_MODES && tx_cache[i] < INT64_MAX; i++) { |
| 3671 int64_t adj_rd = INT64_MAX; |
| 3672 adj_rd = this_rd + tx_cache[i] - tx_cache[cm->tx_mode]; |
| 3673 |
| 3674 if (adj_rd < best_tx_rd[i]) |
| 3675 best_tx_rd[i] = adj_rd; |
| 3676 } |
| 3677 } |
| 3678 |
| 3679 if (early_term) |
| 3680 break; |
| 3681 |
| 3682 if (x->skip && !comp_pred) |
| 3683 break; |
| 3684 } |
| 3685 |
| 3686 if (best_rd >= best_rd_so_far) |
| 3687 return INT64_MAX; |
| 3688 |
| 3689 // If we used an estimate for the uv intra rd in the loop above... |
| 3690 if (cpi->sf.use_uv_intra_rd_estimate) { |
| 3691 // Do Intra UV best rd mode selection if best mode choice above was intra. |
| 3692 if (vp9_mode_order[best_mode_index].ref_frame == INTRA_FRAME) { |
| 3693 TX_SIZE uv_tx_size = get_uv_tx_size(mbmi); |
| 3694 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_intra[uv_tx_size], |
| 3695 &rate_uv_tokenonly[uv_tx_size], |
| 3696 &dist_uv[uv_tx_size], |
| 3697 &skip_uv[uv_tx_size], |
| 3698 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); |
| 3699 } |
| 3700 } |
| 3701 |
| 3702 // If we are using reference masking and the set mask flag is set then |
| 3703 // create the reference frame mask. |
| 3704 if (cpi->sf.reference_masking && cpi->set_ref_frame_mask) |
| 3705 cpi->ref_frame_mask = ~(1 << vp9_mode_order[best_mode_index].ref_frame); |
| 3706 |
| 3707 // Flag all modes that have a distortion thats > 2x the best we found at |
| 3708 // this level. |
| 3709 for (mode_index = 0; mode_index < MB_MODE_COUNT; ++mode_index) { |
| 3710 if (mode_index == NEARESTMV || mode_index == NEARMV || mode_index == NEWMV) |
| 3711 continue; |
| 3712 |
| 3713 if (mode_distortions[mode_index] > 2 * *returndistortion) { |
| 3714 ctx->modes_with_high_error |= (1 << mode_index); |
| 3715 } |
| 3716 } |
| 3717 |
| 3718 // Flag all ref frames that have a distortion thats > 2x the best we found at |
| 3719 // this level. |
| 3720 for (ref_frame = INTRA_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { |
| 3721 if (frame_distortions[ref_frame] > 2 * *returndistortion) { |
| 3722 ctx->frames_with_high_error |= (1 << ref_frame); |
| 3723 } |
| 3724 } |
| 3725 |
| 3726 assert((cm->mcomp_filter_type == SWITCHABLE) || |
| 3727 (cm->mcomp_filter_type == best_mbmode.interp_filter) || |
| 3728 (best_mbmode.ref_frame[0] == INTRA_FRAME)); |
| 3729 |
| 3730 // Updating rd_thresh_freq_fact[] here means that the different |
| 3731 // partition/block sizes are handled independently based on the best |
| 3732 // choice for the current partition. It may well be better to keep a scaled |
| 3733 // best rd so far value and update rd_thresh_freq_fact based on the mode/size |
| 3734 // combination that wins out. |
| 3735 if (cpi->sf.adaptive_rd_thresh) { |
| 3736 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { |
| 3737 if (mode_index == best_mode_index) { |
| 3738 cpi->rd_thresh_freq_fact[bsize][mode_index] -= |
| 3739 (cpi->rd_thresh_freq_fact[bsize][mode_index] >> 3); |
| 3740 } else { |
| 3741 cpi->rd_thresh_freq_fact[bsize][mode_index] += RD_THRESH_INC; |
| 3742 if (cpi->rd_thresh_freq_fact[bsize][mode_index] > |
| 3743 (cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT)) { |
| 3744 cpi->rd_thresh_freq_fact[bsize][mode_index] = |
| 3745 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT; |
| 3746 } |
| 3747 } |
| 3748 } |
| 3749 } |
| 3750 |
| 3751 // macroblock modes |
| 3752 *mbmi = best_mbmode; |
| 3753 x->skip |= best_skip2; |
| 3754 |
| 3755 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { |
| 3756 if (best_pred_rd[i] == INT64_MAX) |
| 3757 best_pred_diff[i] = INT_MIN; |
| 3758 else |
| 3759 best_pred_diff[i] = best_rd - best_pred_rd[i]; |
| 3760 } |
| 3761 |
| 3762 if (!x->skip) { |
| 3763 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
| 3764 if (best_filter_rd[i] == INT64_MAX) |
| 3765 best_filter_diff[i] = 0; |
| 3766 else |
| 3767 best_filter_diff[i] = best_rd - best_filter_rd[i]; |
| 3768 } |
| 3769 if (cm->mcomp_filter_type == SWITCHABLE) |
| 3770 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); |
| 3771 } else { |
| 3772 vp9_zero(best_filter_diff); |
| 3773 } |
| 3774 |
| 3775 if (!x->skip) { |
| 3776 for (i = 0; i < TX_MODES; i++) { |
| 3777 if (best_tx_rd[i] == INT64_MAX) |
| 3778 best_tx_diff[i] = 0; |
| 3779 else |
| 3780 best_tx_diff[i] = best_rd - best_tx_rd[i]; |
| 3781 } |
| 3782 } else { |
| 3783 vp9_zero(best_tx_diff); |
| 3784 } |
| 3785 |
| 3786 set_scale_factors(xd, mbmi->ref_frame[0], mbmi->ref_frame[1], |
| 3787 scale_factor); |
| 3788 store_coding_context(x, ctx, best_mode_index, |
| 3789 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], |
| 3790 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : |
| 3791 mbmi->ref_frame[1]][0], |
| 3792 best_pred_diff, best_tx_diff, best_filter_diff); |
| 3793 |
| 3794 return best_rd; |
| 3795 } |
| 3796 |
| 3797 |
| 3798 int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, |
| 3799 const TileInfo *const tile, |
| 3800 int mi_row, int mi_col, |
| 3801 int *returnrate, |
| 3802 int64_t *returndistortion, |
| 3803 BLOCK_SIZE bsize, |
| 3804 PICK_MODE_CONTEXT *ctx, |
| 3805 int64_t best_rd_so_far) { |
| 3806 VP9_COMMON *cm = &cpi->common; |
| 3807 MACROBLOCKD *xd = &x->e_mbd; |
| 3808 MB_MODE_INFO *mbmi = &xd->mi_8x8[0]->mbmi; |
| 3809 const struct segmentation *seg = &cm->seg; |
| 3810 const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); |
| 3811 MV_REFERENCE_FRAME ref_frame, second_ref_frame; |
| 3812 unsigned char segment_id = mbmi->segment_id; |
| 3813 int comp_pred, i; |
| 3814 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
| 3815 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
| 3816 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
| 3817 VP9_ALT_FLAG }; |
| 3818 int idx_list[4] = {0, |
| 3819 cpi->lst_fb_idx, |
| 3820 cpi->gld_fb_idx, |
| 3821 cpi->alt_fb_idx}; |
| 3822 int64_t best_rd = best_rd_so_far; |
| 3823 int64_t best_yrd = best_rd_so_far; // FIXME(rbultje) more precise |
| 3824 int64_t best_tx_rd[TX_MODES]; |
| 3825 int64_t best_tx_diff[TX_MODES]; |
| 3826 int64_t best_pred_diff[NB_PREDICTION_TYPES]; |
| 3827 int64_t best_pred_rd[NB_PREDICTION_TYPES]; |
| 3828 int64_t best_filter_rd[SWITCHABLE_FILTER_CONTEXTS]; |
| 3829 int64_t best_filter_diff[SWITCHABLE_FILTER_CONTEXTS]; |
| 3830 MB_MODE_INFO best_mbmode = { 0 }; |
| 3831 int mode_index, best_mode_index = 0; |
| 3832 unsigned int ref_costs_single[MAX_REF_FRAMES], ref_costs_comp[MAX_REF_FRAMES]; |
| 3833 vp9_prob comp_mode_p; |
| 3834 int64_t best_inter_rd = INT64_MAX; |
| 3835 MV_REFERENCE_FRAME best_inter_ref_frame = LAST_FRAME; |
| 3836 INTERPOLATION_TYPE tmp_best_filter = SWITCHABLE; |
| 3837 int rate_uv_intra[TX_SIZES], rate_uv_tokenonly[TX_SIZES]; |
| 3838 int64_t dist_uv[TX_SIZES]; |
| 3839 int skip_uv[TX_SIZES]; |
| 3840 MB_PREDICTION_MODE mode_uv[TX_SIZES] = { 0 }; |
| 3841 struct scale_factors scale_factor[4]; |
| 3842 unsigned int ref_frame_mask = 0; |
| 3843 unsigned int mode_mask = 0; |
| 3844 int intra_cost_penalty = 20 * vp9_dc_quant(cpi->common.base_qindex, |
| 3845 cpi->common.y_dc_delta_q); |
| 3846 int_mv seg_mvs[4][MAX_REF_FRAMES]; |
| 3847 b_mode_info best_bmodes[4]; |
| 3848 int best_skip2 = 0; |
| 3849 |
| 3850 x->skip_encode = cpi->sf.skip_encode_frame && xd->q_index < QIDX_SKIP_THRESH; |
| 3851 vpx_memset(x->zcoeff_blk[TX_4X4], 0, 4); |
| 3852 |
| 3853 for (i = 0; i < 4; i++) { |
| 3854 int j; |
| 3855 for (j = 0; j < MAX_REF_FRAMES; j++) |
| 3856 seg_mvs[i][j].as_int = INVALID_MV; |
| 3857 } |
| 3858 |
| 3859 estimate_ref_frame_costs(cpi, segment_id, ref_costs_single, ref_costs_comp, |
| 3860 &comp_mode_p); |
| 3861 |
| 3862 for (i = 0; i < NB_PREDICTION_TYPES; ++i) |
| 3863 best_pred_rd[i] = INT64_MAX; |
| 3864 for (i = 0; i < TX_MODES; i++) |
| 3865 best_tx_rd[i] = INT64_MAX; |
| 3866 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
| 3867 best_filter_rd[i] = INT64_MAX; |
| 3868 for (i = 0; i < TX_SIZES; i++) |
| 3869 rate_uv_intra[i] = INT_MAX; |
| 3870 |
| 3871 *returnrate = INT_MAX; |
| 3872 |
| 3873 // Create a mask set to 1 for each reference frame used by a smaller |
| 3874 // resolution. |
| 3875 if (cpi->sf.use_avoid_tested_higherror) { |
| 3876 ref_frame_mask = 0; |
| 3877 mode_mask = 0; |
| 3878 ref_frame_mask = ~ref_frame_mask; |
| 3879 mode_mask = ~mode_mask; |
| 3880 } |
| 3881 |
| 3882 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { |
| 3883 if (cpi->ref_frame_flags & flag_list[ref_frame]) { |
| 3884 setup_buffer_inter(cpi, x, tile, idx_list[ref_frame], ref_frame, |
| 3885 block_size, mi_row, mi_col, |
| 3886 frame_mv[NEARESTMV], frame_mv[NEARMV], |
| 3887 yv12_mb, scale_factor); |
| 3888 } |
| 3889 frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; |
| 3890 frame_mv[ZEROMV][ref_frame].as_int = 0; |
| 3891 } |
| 3892 |
| 3893 for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) { |
| 3894 int mode_excluded = 0; |
| 3895 int64_t this_rd = INT64_MAX; |
| 3896 int disable_skip = 0; |
| 3897 int compmode_cost = 0; |
| 3898 int rate2 = 0, rate_y = 0, rate_uv = 0; |
| 3899 int64_t distortion2 = 0, distortion_y = 0, distortion_uv = 0; |
| 3900 int skippable = 0; |
| 3901 int64_t tx_cache[TX_MODES]; |
| 3902 int i; |
| 3903 int this_skip2 = 0; |
| 3904 int64_t total_sse = INT_MAX; |
| 3905 int early_term = 0; |
| 3906 |
| 3907 for (i = 0; i < TX_MODES; ++i) |
| 3908 tx_cache[i] = INT64_MAX; |
| 3909 |
| 3910 x->skip = 0; |
| 3911 ref_frame = vp9_ref_order[mode_index].ref_frame; |
| 3912 second_ref_frame = vp9_ref_order[mode_index].second_ref_frame; |
| 3913 |
| 3914 // Look at the reference frame of the best mode so far and set the |
| 3915 // skip mask to look at a subset of the remaining modes. |
| 3916 if (mode_index > 2 && cpi->sf.mode_skip_start < MAX_MODES) { |
| 3917 if (mode_index == 3) { |
| 3918 switch (vp9_ref_order[best_mode_index].ref_frame) { |
| 3919 case INTRA_FRAME: |
| 3920 cpi->mode_skip_mask = 0; |
| 3921 break; |
| 3922 case LAST_FRAME: |
| 3923 cpi->mode_skip_mask = 0x0010; |
| 3924 break; |
| 3925 case GOLDEN_FRAME: |
| 3926 cpi->mode_skip_mask = 0x0008; |
| 3927 break; |
| 3928 case ALTREF_FRAME: |
| 3929 cpi->mode_skip_mask = 0x0000; |
| 3930 break; |
| 3931 case NONE: |
| 3932 case MAX_REF_FRAMES: |
| 3933 assert(!"Invalid Reference frame"); |
| 3934 } |
| 3935 } |
| 3936 if (cpi->mode_skip_mask & ((int64_t)1 << mode_index)) |
| 3937 continue; |
| 3938 } |
| 3939 |
| 3940 // Skip if the current reference frame has been masked off |
| 3941 if (cpi->sf.reference_masking && !cpi->set_ref_frame_mask && |
| 3942 (cpi->ref_frame_mask & (1 << ref_frame))) |
| 3943 continue; |
| 3944 |
| 3945 // Test best rd so far against threshold for trying this mode. |
| 3946 if ((best_rd < |
| 3947 ((int64_t)cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] * |
| 3948 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 5)) || |
| 3949 cpi->rd_thresh_sub8x8[segment_id][bsize][mode_index] == INT_MAX) |
| 3950 continue; |
| 3951 |
| 3952 // Do not allow compound prediction if the segment level reference |
| 3953 // frame feature is in use as in this case there can only be one reference. |
| 3954 if ((second_ref_frame > INTRA_FRAME) && |
| 3955 vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME)) |
| 3956 continue; |
| 3957 |
| 3958 mbmi->ref_frame[0] = ref_frame; |
| 3959 mbmi->ref_frame[1] = second_ref_frame; |
| 3960 |
| 3961 if (!(ref_frame == INTRA_FRAME |
| 3962 || (cpi->ref_frame_flags & flag_list[ref_frame]))) { |
| 3963 continue; |
| 3964 } |
| 3965 if (!(second_ref_frame == NONE |
| 3966 || (cpi->ref_frame_flags & flag_list[second_ref_frame]))) { |
| 3967 continue; |
| 3968 } |
| 3969 |
| 3970 comp_pred = second_ref_frame > INTRA_FRAME; |
| 3971 if (comp_pred) { |
| 3972 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) |
| 3973 if (vp9_ref_order[best_mode_index].ref_frame == INTRA_FRAME) |
| 3974 continue; |
| 3975 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) |
| 3976 if (ref_frame != best_inter_ref_frame && |
| 3977 second_ref_frame != best_inter_ref_frame) |
| 3978 continue; |
| 3979 } |
| 3980 |
| 3981 // TODO(jingning, jkoleszar): scaling reference frame not supported for |
| 3982 // sub8x8 blocks. |
| 3983 if (ref_frame > 0 && |
| 3984 vp9_is_scaled(scale_factor[ref_frame].sfc)) |
| 3985 continue; |
| 3986 |
| 3987 if (second_ref_frame > 0 && |
| 3988 vp9_is_scaled(scale_factor[second_ref_frame].sfc)) |
| 3989 continue; |
| 3990 |
| 3991 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); |
| 3992 mbmi->uv_mode = DC_PRED; |
| 3993 |
| 3994 // Evaluate all sub-pel filters irrespective of whether we can use |
| 3995 // them for this frame. |
| 3996 mbmi->interp_filter = cm->mcomp_filter_type; |
| 3997 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); |
| 3998 |
| 3999 if (comp_pred) { |
| 4000 if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) |
| 4001 continue; |
| 4002 set_scale_factors(xd, ref_frame, second_ref_frame, scale_factor); |
| 4003 |
| 4004 mode_excluded = mode_excluded |
| 4005 ? mode_excluded |
| 4006 : cm->comp_pred_mode == SINGLE_PREDICTION_ONLY; |
| 4007 } else { |
| 4008 if (ref_frame != INTRA_FRAME && second_ref_frame != INTRA_FRAME) { |
| 4009 mode_excluded = |
| 4010 mode_excluded ? |
| 4011 mode_excluded : cm->comp_pred_mode == COMP_PREDICTION_ONLY; |
| 4012 } |
| 4013 } |
| 4014 |
| 4015 // Select prediction reference frames. |
| 4016 for (i = 0; i < MAX_MB_PLANE; i++) { |
| 4017 xd->plane[i].pre[0] = yv12_mb[ref_frame][i]; |
| 4018 if (comp_pred) |
| 4019 xd->plane[i].pre[1] = yv12_mb[second_ref_frame][i]; |
| 4020 } |
| 4021 |
| 4022 // If the segment reference frame feature is enabled.... |
| 4023 // then do nothing if the current ref frame is not allowed.. |
| 4024 if (vp9_segfeature_active(seg, segment_id, SEG_LVL_REF_FRAME) && |
| 4025 vp9_get_segdata(seg, segment_id, SEG_LVL_REF_FRAME) != |
| 4026 (int)ref_frame) { |
| 4027 continue; |
| 4028 // If the segment skip feature is enabled.... |
| 4029 // then do nothing if the current mode is not allowed.. |
| 4030 } else if (vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) && |
| 4031 ref_frame != INTRA_FRAME) { |
| 4032 continue; |
| 4033 // Disable this drop out case if the ref frame |
| 4034 // segment level feature is enabled for this segment. This is to |
| 4035 // prevent the possibility that we end up unable to pick any mode. |
| 4036 } else if (!vp9_segfeature_active(seg, segment_id, |
| 4037 SEG_LVL_REF_FRAME)) { |
| 4038 // Only consider ZEROMV/ALTREF_FRAME for alt ref frame, |
| 4039 // unless ARNR filtering is enabled in which case we want |
| 4040 // an unfiltered alternative. We allow near/nearest as well |
| 4041 // because they may result in zero-zero MVs but be cheaper. |
| 4042 if (cpi->is_src_frame_alt_ref && (cpi->oxcf.arnr_max_frames == 0)) |
| 4043 continue; |
| 4044 } |
| 4045 |
| 4046 #ifdef MODE_TEST_HIT_STATS |
| 4047 // TEST/DEBUG CODE |
| 4048 // Keep a rcord of the number of test hits at each size |
| 4049 cpi->mode_test_hits[bsize]++; |
| 4050 #endif |
| 4051 |
| 4052 if (ref_frame == INTRA_FRAME) { |
| 4053 int rate; |
| 4054 mbmi->tx_size = TX_4X4; |
| 4055 if (rd_pick_intra_sub_8x8_y_mode(cpi, x, &rate, &rate_y, |
| 4056 &distortion_y, best_rd) >= best_rd) |
| 4057 continue; |
| 4058 rate2 += rate; |
| 4059 rate2 += intra_cost_penalty; |
| 4060 distortion2 += distortion_y; |
| 4061 |
| 4062 if (rate_uv_intra[TX_4X4] == INT_MAX) { |
| 4063 choose_intra_uv_mode(cpi, bsize, &rate_uv_intra[TX_4X4], |
| 4064 &rate_uv_tokenonly[TX_4X4], |
| 4065 &dist_uv[TX_4X4], &skip_uv[TX_4X4], |
| 4066 &mode_uv[TX_4X4]); |
| 4067 } |
| 4068 rate2 += rate_uv_intra[TX_4X4]; |
| 4069 rate_uv = rate_uv_tokenonly[TX_4X4]; |
| 4070 distortion2 += dist_uv[TX_4X4]; |
| 4071 distortion_uv = dist_uv[TX_4X4]; |
| 4072 mbmi->uv_mode = mode_uv[TX_4X4]; |
| 4073 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
| 4074 for (i = 0; i < TX_MODES; ++i) |
| 4075 tx_cache[i] = tx_cache[ONLY_4X4]; |
| 4076 } else { |
3498 int rate; | 4077 int rate; |
3499 int64_t distortion; | 4078 int64_t distortion; |
3500 int64_t this_rd_thresh; | 4079 int64_t this_rd_thresh; |
3501 int64_t tmp_rd, tmp_best_rd = INT64_MAX, tmp_best_rdu = INT64_MAX; | 4080 int64_t tmp_rd, tmp_best_rd = INT64_MAX, tmp_best_rdu = INT64_MAX; |
3502 int tmp_best_rate = INT_MAX, tmp_best_ratey = INT_MAX; | 4081 int tmp_best_rate = INT_MAX, tmp_best_ratey = INT_MAX; |
3503 int64_t tmp_best_distortion = INT_MAX, tmp_best_sse, uv_sse; | 4082 int64_t tmp_best_distortion = INT_MAX, tmp_best_sse, uv_sse; |
3504 int tmp_best_skippable = 0; | 4083 int tmp_best_skippable = 0; |
3505 int switchable_filter_index; | 4084 int switchable_filter_index; |
3506 int_mv *second_ref = is_comp_pred ? | 4085 int_mv *second_ref = comp_pred ? |
3507 &mbmi->ref_mvs[second_ref_frame][0] : NULL; | 4086 &mbmi->ref_mvs[second_ref_frame][0] : NULL; |
3508 union b_mode_info tmp_best_bmodes[16]; | 4087 b_mode_info tmp_best_bmodes[16]; |
3509 MB_MODE_INFO tmp_best_mbmode; | 4088 MB_MODE_INFO tmp_best_mbmode; |
3510 PARTITION_INFO tmp_best_partition; | |
3511 BEST_SEG_INFO bsi[SWITCHABLE_FILTERS]; | 4089 BEST_SEG_INFO bsi[SWITCHABLE_FILTERS]; |
3512 int pred_exists = 0; | 4090 int pred_exists = 0; |
3513 int uv_skippable; | 4091 int uv_skippable; |
3514 if (is_comp_pred) { | |
3515 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_BESTINTRA) | |
3516 if (vp9_mode_order[best_mode_index].ref_frame == INTRA_FRAME) | |
3517 continue; | |
3518 if (cpi->sf.mode_search_skip_flags & FLAG_SKIP_COMP_REFMISMATCH) | |
3519 if (ref_frame != best_inter_ref_frame && | |
3520 second_ref_frame != best_inter_ref_frame) | |
3521 continue; | |
3522 } | |
3523 | 4092 |
3524 this_rd_thresh = (ref_frame == LAST_FRAME) ? | 4093 this_rd_thresh = (ref_frame == LAST_FRAME) ? |
3525 cpi->rd_threshes[bsize][THR_NEWMV] : | 4094 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_LAST] : |
3526 cpi->rd_threshes[bsize][THR_NEWA]; | 4095 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_ALTR]; |
3527 this_rd_thresh = (ref_frame == GOLDEN_FRAME) ? | 4096 this_rd_thresh = (ref_frame == GOLDEN_FRAME) ? |
3528 cpi->rd_threshes[bsize][THR_NEWG] : this_rd_thresh; | 4097 cpi->rd_thresh_sub8x8[segment_id][bsize][THR_GOLD] : this_rd_thresh; |
3529 xd->this_mi->mbmi.tx_size = TX_4X4; | 4098 xd->mi_8x8[0]->mbmi.tx_size = TX_4X4; |
3530 | 4099 |
3531 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = INT64_MAX; | 4100 cpi->rd_filter_cache[SWITCHABLE_FILTERS] = INT64_MAX; |
3532 if (cm->mcomp_filter_type != BILINEAR) { | 4101 if (cm->mcomp_filter_type != BILINEAR) { |
3533 tmp_best_filter = EIGHTTAP; | 4102 tmp_best_filter = EIGHTTAP; |
3534 if (x->source_variance < | 4103 if (x->source_variance < |
3535 cpi->sf.disable_filter_search_var_thresh) { | 4104 cpi->sf.disable_filter_search_var_thresh) { |
3536 tmp_best_filter = EIGHTTAP; | 4105 tmp_best_filter = EIGHTTAP; |
3537 vp9_zero(cpi->rd_filter_cache); | 4106 vp9_zero(cpi->rd_filter_cache); |
3538 } else { | 4107 } else { |
3539 for (switchable_filter_index = 0; | 4108 for (switchable_filter_index = 0; |
3540 switchable_filter_index < SWITCHABLE_FILTERS; | 4109 switchable_filter_index < SWITCHABLE_FILTERS; |
3541 ++switchable_filter_index) { | 4110 ++switchable_filter_index) { |
3542 int newbest, rs; | 4111 int newbest, rs; |
3543 int64_t rs_rd; | 4112 int64_t rs_rd; |
3544 mbmi->interp_filter = switchable_filter_index; | 4113 mbmi->interp_filter = switchable_filter_index; |
3545 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); | 4114 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); |
3546 | 4115 |
3547 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, | 4116 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, |
3548 &mbmi->ref_mvs[ref_frame][0], | 4117 &mbmi->ref_mvs[ref_frame][0], |
3549 second_ref, | 4118 second_ref, |
3550 best_yrd, | 4119 best_yrd, |
3551 &rate, &rate_y, &distortion, | 4120 &rate, &rate_y, &distortion, |
3552 &skippable, &total_sse, | 4121 &skippable, &total_sse, |
3553 (int)this_rd_thresh, seg_mvs, | 4122 (int)this_rd_thresh, seg_mvs, |
3554 bsi, switchable_filter_index, | 4123 bsi, switchable_filter_index, |
3555 mi_row, mi_col); | 4124 mi_row, mi_col); |
3556 | 4125 |
3557 if (tmp_rd == INT64_MAX) | 4126 if (tmp_rd == INT64_MAX) |
(...skipping 15 matching lines...) Expand all Loading... |
3573 if ((newbest && cm->mcomp_filter_type == SWITCHABLE) || | 4142 if ((newbest && cm->mcomp_filter_type == SWITCHABLE) || |
3574 (mbmi->interp_filter == cm->mcomp_filter_type && | 4143 (mbmi->interp_filter == cm->mcomp_filter_type && |
3575 cm->mcomp_filter_type != SWITCHABLE)) { | 4144 cm->mcomp_filter_type != SWITCHABLE)) { |
3576 tmp_best_rdu = tmp_rd; | 4145 tmp_best_rdu = tmp_rd; |
3577 tmp_best_rate = rate; | 4146 tmp_best_rate = rate; |
3578 tmp_best_ratey = rate_y; | 4147 tmp_best_ratey = rate_y; |
3579 tmp_best_distortion = distortion; | 4148 tmp_best_distortion = distortion; |
3580 tmp_best_sse = total_sse; | 4149 tmp_best_sse = total_sse; |
3581 tmp_best_skippable = skippable; | 4150 tmp_best_skippable = skippable; |
3582 tmp_best_mbmode = *mbmi; | 4151 tmp_best_mbmode = *mbmi; |
3583 tmp_best_partition = *x->partition_info; | 4152 for (i = 0; i < 4; i++) { |
3584 for (i = 0; i < 4; i++) | 4153 tmp_best_bmodes[i] = xd->mi_8x8[0]->bmi[i]; |
3585 tmp_best_bmodes[i] = xd->this_mi->bmi[i]; | 4154 x->zcoeff_blk[TX_4X4][i] = !xd->plane[0].eobs[i]; |
| 4155 } |
3586 pred_exists = 1; | 4156 pred_exists = 1; |
3587 if (switchable_filter_index == 0 && | 4157 if (switchable_filter_index == 0 && |
3588 cpi->sf.use_rd_breakout && | 4158 cpi->sf.use_rd_breakout && |
3589 best_rd < INT64_MAX) { | 4159 best_rd < INT64_MAX) { |
3590 if (tmp_best_rdu / 2 > best_rd) { | 4160 if (tmp_best_rdu / 2 > best_rd) { |
3591 // skip searching the other filters if the first is | 4161 // skip searching the other filters if the first is |
3592 // already substantially larger than the best so far | 4162 // already substantially larger than the best so far |
3593 tmp_best_filter = mbmi->interp_filter; | 4163 tmp_best_filter = mbmi->interp_filter; |
3594 tmp_best_rdu = INT64_MAX; | 4164 tmp_best_rdu = INT64_MAX; |
3595 break; | 4165 break; |
3596 } | 4166 } |
3597 } | 4167 } |
3598 } | 4168 } |
3599 } // switchable_filter_index loop | 4169 } // switchable_filter_index loop |
3600 } | 4170 } |
3601 } | 4171 } |
3602 | 4172 |
3603 if (tmp_best_rdu == INT64_MAX) | 4173 if (tmp_best_rdu == INT64_MAX) |
3604 continue; | 4174 continue; |
3605 | 4175 |
3606 mbmi->interp_filter = (cm->mcomp_filter_type == SWITCHABLE ? | 4176 mbmi->interp_filter = (cm->mcomp_filter_type == SWITCHABLE ? |
3607 tmp_best_filter : cm->mcomp_filter_type); | 4177 tmp_best_filter : cm->mcomp_filter_type); |
3608 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); | 4178 vp9_setup_interp_filters(xd, mbmi->interp_filter, &cpi->common); |
3609 if (!pred_exists) { | 4179 if (!pred_exists) { |
3610 // Handles the special case when a filter that is not in the | 4180 // Handles the special case when a filter that is not in the |
3611 // switchable list (bilinear, 6-tap) is indicated at the frame level | 4181 // switchable list (bilinear, 6-tap) is indicated at the frame level |
3612 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, | 4182 tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, |
3613 &mbmi->ref_mvs[ref_frame][0], | 4183 &mbmi->ref_mvs[ref_frame][0], |
3614 second_ref, | 4184 second_ref, |
3615 best_yrd, | 4185 best_yrd, |
3616 &rate, &rate_y, &distortion, | 4186 &rate, &rate_y, &distortion, |
3617 &skippable, &total_sse, | 4187 &skippable, &total_sse, |
3618 (int)this_rd_thresh, seg_mvs, | 4188 (int)this_rd_thresh, seg_mvs, |
3619 bsi, 0, | 4189 bsi, 0, |
3620 mi_row, mi_col); | 4190 mi_row, mi_col); |
3621 if (tmp_rd == INT64_MAX) | 4191 if (tmp_rd == INT64_MAX) |
3622 continue; | 4192 continue; |
3623 } else { | 4193 } else { |
3624 if (cpi->common.mcomp_filter_type == SWITCHABLE) { | 4194 if (cpi->common.mcomp_filter_type == SWITCHABLE) { |
3625 int rs = get_switchable_rate(x); | 4195 int rs = get_switchable_rate(x); |
3626 tmp_best_rdu -= RDCOST(x->rdmult, x->rddiv, rs, 0); | 4196 tmp_best_rdu -= RDCOST(x->rdmult, x->rddiv, rs, 0); |
3627 } | 4197 } |
3628 tmp_rd = tmp_best_rdu; | 4198 tmp_rd = tmp_best_rdu; |
3629 total_sse = tmp_best_sse; | 4199 total_sse = tmp_best_sse; |
3630 rate = tmp_best_rate; | 4200 rate = tmp_best_rate; |
3631 rate_y = tmp_best_ratey; | 4201 rate_y = tmp_best_ratey; |
3632 distortion = tmp_best_distortion; | 4202 distortion = tmp_best_distortion; |
3633 skippable = tmp_best_skippable; | 4203 skippable = tmp_best_skippable; |
3634 *mbmi = tmp_best_mbmode; | 4204 *mbmi = tmp_best_mbmode; |
3635 *x->partition_info = tmp_best_partition; | |
3636 for (i = 0; i < 4; i++) | 4205 for (i = 0; i < 4; i++) |
3637 xd->this_mi->bmi[i] = tmp_best_bmodes[i]; | 4206 xd->mi_8x8[0]->bmi[i] = tmp_best_bmodes[i]; |
3638 } | 4207 } |
3639 | 4208 |
3640 rate2 += rate; | 4209 rate2 += rate; |
3641 distortion2 += distortion; | 4210 distortion2 += distortion; |
3642 | 4211 |
3643 if (cpi->common.mcomp_filter_type == SWITCHABLE) | 4212 if (cpi->common.mcomp_filter_type == SWITCHABLE) |
3644 rate2 += get_switchable_rate(x); | 4213 rate2 += get_switchable_rate(x); |
3645 | 4214 |
3646 if (!mode_excluded) { | 4215 if (!mode_excluded) { |
3647 if (is_comp_pred) | 4216 if (comp_pred) |
3648 mode_excluded = cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY; | 4217 mode_excluded = cpi->common.comp_pred_mode == SINGLE_PREDICTION_ONLY; |
3649 else | 4218 else |
3650 mode_excluded = cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY; | 4219 mode_excluded = cpi->common.comp_pred_mode == COMP_PREDICTION_ONLY; |
3651 } | 4220 } |
3652 compmode_cost = vp9_cost_bit(comp_mode_p, is_comp_pred); | 4221 compmode_cost = vp9_cost_bit(comp_mode_p, comp_pred); |
3653 | 4222 |
3654 tmp_best_rdu = best_rd - | 4223 tmp_best_rdu = best_rd - |
3655 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), | 4224 MIN(RDCOST(x->rdmult, x->rddiv, rate2, distortion2), |
3656 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); | 4225 RDCOST(x->rdmult, x->rddiv, 0, total_sse)); |
3657 | 4226 |
3658 if (tmp_best_rdu > 0) { | 4227 if (tmp_best_rdu > 0) { |
3659 // If even the 'Y' rd value of split is higher than best so far | 4228 // If even the 'Y' rd value of split is higher than best so far |
3660 // then dont bother looking at UV | 4229 // then dont bother looking at UV |
3661 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, | 4230 vp9_build_inter_predictors_sbuv(&x->e_mbd, mi_row, mi_col, |
3662 BLOCK_8X8); | 4231 BLOCK_8X8); |
3663 super_block_uvrd(cm, x, &rate_uv, &distortion_uv, &uv_skippable, | 4232 super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable, |
3664 &uv_sse, BLOCK_8X8, tmp_best_rdu); | 4233 &uv_sse, BLOCK_8X8, tmp_best_rdu); |
3665 if (rate_uv == INT_MAX) | 4234 if (rate_uv == INT_MAX) |
3666 continue; | 4235 continue; |
3667 rate2 += rate_uv; | 4236 rate2 += rate_uv; |
3668 distortion2 += distortion_uv; | 4237 distortion2 += distortion_uv; |
3669 skippable = skippable && uv_skippable; | 4238 skippable = skippable && uv_skippable; |
3670 total_sse += uv_sse; | 4239 total_sse += uv_sse; |
3671 | 4240 |
3672 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | 4241 tx_cache[ONLY_4X4] = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
3673 for (i = 0; i < TX_MODES; ++i) | 4242 for (i = 0; i < TX_MODES; ++i) |
3674 tx_cache[i] = tx_cache[ONLY_4X4]; | 4243 tx_cache[i] = tx_cache[ONLY_4X4]; |
3675 } | 4244 } |
3676 } else { | |
3677 mbmi->mode = rd_mode_to_mode(this_mode); | |
3678 compmode_cost = vp9_cost_bit(comp_mode_p, second_ref_frame > INTRA_FRAME); | |
3679 this_rd = handle_inter_mode(cpi, x, bsize, | |
3680 tx_cache, | |
3681 &rate2, &distortion2, &skippable, | |
3682 &rate_y, &distortion_y, | |
3683 &rate_uv, &distortion_uv, | |
3684 &mode_excluded, &disable_skip, | |
3685 &tmp_best_filter, frame_mv, | |
3686 mi_row, mi_col, | |
3687 single_newmv, &total_sse, best_rd); | |
3688 if (this_rd == INT64_MAX) | |
3689 continue; | |
3690 } | 4245 } |
3691 | 4246 |
3692 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { | 4247 if (cpi->common.comp_pred_mode == HYBRID_PREDICTION) { |
3693 rate2 += compmode_cost; | 4248 rate2 += compmode_cost; |
3694 } | 4249 } |
3695 | 4250 |
3696 // Estimate the reference frame signaling cost and add it | 4251 // Estimate the reference frame signaling cost and add it |
3697 // to the rolling cost variable. | 4252 // to the rolling cost variable. |
3698 if (second_ref_frame > INTRA_FRAME) { | 4253 if (second_ref_frame > INTRA_FRAME) { |
3699 rate2 += ref_costs_comp[ref_frame]; | 4254 rate2 += ref_costs_comp[ref_frame]; |
3700 } else { | 4255 } else { |
3701 rate2 += ref_costs_single[ref_frame]; | 4256 rate2 += ref_costs_single[ref_frame]; |
3702 } | 4257 } |
3703 | 4258 |
3704 if (!disable_skip) { | 4259 if (!disable_skip) { |
3705 // Test for the condition where skip block will be activated | 4260 // Test for the condition where skip block will be activated |
3706 // because there are no non zero coefficients and make any | 4261 // because there are no non zero coefficients and make any |
3707 // necessary adjustment for rate. Ignore if skip is coded at | 4262 // necessary adjustment for rate. Ignore if skip is coded at |
3708 // segment level as the cost wont have been added in. | 4263 // segment level as the cost wont have been added in. |
3709 // Is Mb level skip allowed (i.e. not coded at segment level). | 4264 // Is Mb level skip allowed (i.e. not coded at segment level). |
3710 const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id, | 4265 const int mb_skip_allowed = !vp9_segfeature_active(seg, segment_id, |
3711 SEG_LVL_SKIP); | 4266 SEG_LVL_SKIP); |
3712 | 4267 |
3713 if (skippable && bsize >= BLOCK_8X8) { | 4268 if (mb_skip_allowed && ref_frame != INTRA_FRAME && !xd->lossless) { |
3714 // Back out the coefficient coding costs | |
3715 rate2 -= (rate_y + rate_uv); | |
3716 // for best yrd calculation | |
3717 rate_uv = 0; | |
3718 | |
3719 if (mb_skip_allowed) { | |
3720 int prob_skip_cost; | |
3721 | |
3722 // Cost the skip mb case | |
3723 vp9_prob skip_prob = | |
3724 vp9_get_pred_prob_mbskip(cm, xd); | |
3725 | |
3726 if (skip_prob) { | |
3727 prob_skip_cost = vp9_cost_bit(skip_prob, 1); | |
3728 rate2 += prob_skip_cost; | |
3729 } | |
3730 } | |
3731 } else if (mb_skip_allowed && ref_frame != INTRA_FRAME && !xd->lossless) { | |
3732 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < | 4269 if (RDCOST(x->rdmult, x->rddiv, rate_y + rate_uv, distortion2) < |
3733 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { | 4270 RDCOST(x->rdmult, x->rddiv, 0, total_sse)) { |
3734 // Add in the cost of the no skip flag. | 4271 // Add in the cost of the no skip flag. |
3735 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), | 4272 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), |
3736 0); | 4273 0); |
3737 rate2 += prob_skip_cost; | 4274 rate2 += prob_skip_cost; |
3738 } else { | 4275 } else { |
3739 // FIXME(rbultje) make this work for splitmv also | 4276 // FIXME(rbultje) make this work for splitmv also |
3740 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), | 4277 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), |
3741 1); | 4278 1); |
3742 rate2 += prob_skip_cost; | 4279 rate2 += prob_skip_cost; |
3743 distortion2 = total_sse; | 4280 distortion2 = total_sse; |
3744 assert(total_sse >= 0); | 4281 assert(total_sse >= 0); |
3745 rate2 -= (rate_y + rate_uv); | 4282 rate2 -= (rate_y + rate_uv); |
3746 rate_y = 0; | 4283 rate_y = 0; |
3747 rate_uv = 0; | 4284 rate_uv = 0; |
3748 this_skip2 = 1; | 4285 this_skip2 = 1; |
3749 } | 4286 } |
3750 } else if (mb_skip_allowed) { | 4287 } else if (mb_skip_allowed) { |
3751 // Add in the cost of the no skip flag. | 4288 // Add in the cost of the no skip flag. |
3752 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), | 4289 int prob_skip_cost = vp9_cost_bit(vp9_get_pred_prob_mbskip(cm, xd), |
3753 0); | 4290 0); |
3754 rate2 += prob_skip_cost; | 4291 rate2 += prob_skip_cost; |
3755 } | 4292 } |
3756 | 4293 |
3757 // Calculate the final RD estimate for this mode. | 4294 // Calculate the final RD estimate for this mode. |
3758 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); | 4295 this_rd = RDCOST(x->rdmult, x->rddiv, rate2, distortion2); |
3759 } | 4296 } |
3760 | 4297 |
3761 // Keep record of best intra rd | |
3762 if (xd->this_mi->mbmi.ref_frame[0] == INTRA_FRAME && | |
3763 is_intra_mode(xd->this_mi->mbmi.mode) && | |
3764 this_rd < best_intra_rd) { | |
3765 best_intra_rd = this_rd; | |
3766 best_intra_mode = xd->this_mi->mbmi.mode; | |
3767 } | |
3768 // Keep record of best inter rd with single reference | 4298 // Keep record of best inter rd with single reference |
3769 if (xd->this_mi->mbmi.ref_frame[0] > INTRA_FRAME && | 4299 if (xd->mi_8x8[0]->mbmi.ref_frame[0] > INTRA_FRAME && |
3770 xd->this_mi->mbmi.ref_frame[1] == NONE && | 4300 xd->mi_8x8[0]->mbmi.ref_frame[1] == NONE && |
3771 !mode_excluded && | 4301 !mode_excluded && |
3772 this_rd < best_inter_rd) { | 4302 this_rd < best_inter_rd) { |
3773 best_inter_rd = this_rd; | 4303 best_inter_rd = this_rd; |
3774 best_inter_ref_frame = ref_frame; | 4304 best_inter_ref_frame = ref_frame; |
3775 // best_inter_mode = xd->this_mi->mbmi.mode; | |
3776 } | 4305 } |
3777 | 4306 |
3778 if (!disable_skip && ref_frame == INTRA_FRAME) { | 4307 if (!disable_skip && ref_frame == INTRA_FRAME) { |
3779 for (i = 0; i < NB_PREDICTION_TYPES; ++i) | 4308 for (i = 0; i < NB_PREDICTION_TYPES; ++i) |
3780 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); | 4309 best_pred_rd[i] = MIN(best_pred_rd[i], this_rd); |
3781 for (i = 0; i <= SWITCHABLE_FILTERS; i++) | 4310 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) |
3782 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); | 4311 best_filter_rd[i] = MIN(best_filter_rd[i], this_rd); |
3783 } | 4312 } |
3784 | 4313 |
3785 if (this_mode != RD_I4X4_PRED && this_mode != RD_SPLITMV) { | |
3786 // Store the respective mode distortions for later use. | |
3787 if (mode_distortions[this_mode] == -1 | |
3788 || distortion2 < mode_distortions[this_mode]) { | |
3789 mode_distortions[this_mode] = distortion2; | |
3790 } | |
3791 if (frame_distortions[ref_frame] == -1 | |
3792 || distortion2 < frame_distortions[ref_frame]) { | |
3793 frame_distortions[ref_frame] = distortion2; | |
3794 } | |
3795 } | |
3796 | |
3797 // Did this mode help.. i.e. is it the new best mode | 4314 // Did this mode help.. i.e. is it the new best mode |
3798 if (this_rd < best_rd || x->skip) { | 4315 if (this_rd < best_rd || x->skip) { |
3799 if (!mode_excluded) { | 4316 if (!mode_excluded) { |
3800 // Note index of best mode so far | 4317 // Note index of best mode so far |
3801 best_mode_index = mode_index; | 4318 best_mode_index = mode_index; |
3802 | 4319 |
3803 if (ref_frame == INTRA_FRAME) { | 4320 if (ref_frame == INTRA_FRAME) { |
3804 /* required for left and above block mv */ | 4321 /* required for left and above block mv */ |
3805 mbmi->mv[0].as_int = 0; | 4322 mbmi->mv[0].as_int = 0; |
3806 } | 4323 } |
3807 | 4324 |
3808 *returnrate = rate2; | 4325 *returnrate = rate2; |
3809 *returndistortion = distortion2; | 4326 *returndistortion = distortion2; |
3810 best_rd = this_rd; | 4327 best_rd = this_rd; |
3811 best_yrd = best_rd - | 4328 best_yrd = best_rd - |
3812 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); | 4329 RDCOST(x->rdmult, x->rddiv, rate_uv, distortion_uv); |
3813 best_mbmode = *mbmi; | 4330 best_mbmode = *mbmi; |
3814 best_skip2 = this_skip2; | 4331 best_skip2 = this_skip2; |
3815 best_partition = *x->partition_info; | 4332 vpx_memcpy(ctx->zcoeff_blk, x->zcoeff_blk[mbmi->tx_size], |
| 4333 sizeof(uint8_t) * ctx->num_4x4_blk); |
3816 | 4334 |
3817 if (this_mode == RD_I4X4_PRED || this_mode == RD_SPLITMV) | 4335 for (i = 0; i < 4; i++) |
3818 for (i = 0; i < 4; i++) | 4336 best_bmodes[i] = xd->mi_8x8[0]->bmi[i]; |
3819 best_bmodes[i] = xd->this_mi->bmi[i]; | |
3820 | 4337 |
3821 // TODO(debargha): enhance this test with a better distortion prediction | 4338 // TODO(debargha): enhance this test with a better distortion prediction |
3822 // based on qp, activity mask and history | 4339 // based on qp, activity mask and history |
3823 if (cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) { | 4340 if ((cpi->sf.mode_search_skip_flags & FLAG_EARLY_TERMINATE) && |
| 4341 (mode_index > MIN_EARLY_TERM_INDEX)) { |
3824 const int qstep = xd->plane[0].dequant[1]; | 4342 const int qstep = xd->plane[0].dequant[1]; |
3825 // TODO(debargha): Enhance this by specializing for each mode_index | 4343 // TODO(debargha): Enhance this by specializing for each mode_index |
3826 int scale = 4; | 4344 int scale = 4; |
3827 if (x->source_variance < UINT_MAX) { | 4345 if (x->source_variance < UINT_MAX) { |
3828 const int var_adjust = (x->source_variance < 16); | 4346 const int var_adjust = (x->source_variance < 16); |
3829 scale -= var_adjust; | 4347 scale -= var_adjust; |
3830 } | 4348 } |
3831 if (ref_frame > INTRA_FRAME && | 4349 if (ref_frame > INTRA_FRAME && |
3832 distortion2 * scale < qstep * qstep) { | 4350 distortion2 * scale < qstep * qstep) { |
3833 early_term = 1; | 4351 early_term = 1; |
(...skipping 26 matching lines...) Expand all Loading... |
3860 } | 4378 } |
3861 if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION]) | 4379 if (hybrid_rd < best_pred_rd[HYBRID_PREDICTION]) |
3862 best_pred_rd[HYBRID_PREDICTION] = hybrid_rd; | 4380 best_pred_rd[HYBRID_PREDICTION] = hybrid_rd; |
3863 } | 4381 } |
3864 | 4382 |
3865 /* keep record of best filter type */ | 4383 /* keep record of best filter type */ |
3866 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && | 4384 if (!mode_excluded && !disable_skip && ref_frame != INTRA_FRAME && |
3867 cm->mcomp_filter_type != BILINEAR) { | 4385 cm->mcomp_filter_type != BILINEAR) { |
3868 int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ? | 4386 int64_t ref = cpi->rd_filter_cache[cm->mcomp_filter_type == SWITCHABLE ? |
3869 SWITCHABLE_FILTERS : cm->mcomp_filter_type]; | 4387 SWITCHABLE_FILTERS : cm->mcomp_filter_type]; |
3870 for (i = 0; i <= SWITCHABLE_FILTERS; i++) { | 4388 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
3871 int64_t adj_rd; | 4389 int64_t adj_rd; |
3872 // In cases of poor prediction, filter_cache[] can contain really big | 4390 // In cases of poor prediction, filter_cache[] can contain really big |
3873 // values, which actually are bigger than this_rd itself. This can | 4391 // values, which actually are bigger than this_rd itself. This can |
3874 // cause negative best_filter_rd[] values, which is obviously silly. | 4392 // cause negative best_filter_rd[] values, which is obviously silly. |
3875 // Therefore, if filter_cache < ref, we do an adjusted calculation. | 4393 // Therefore, if filter_cache < ref, we do an adjusted calculation. |
3876 if (cpi->rd_filter_cache[i] >= ref) | 4394 if (cpi->rd_filter_cache[i] >= ref) |
3877 adj_rd = this_rd + cpi->rd_filter_cache[i] - ref; | 4395 adj_rd = this_rd + cpi->rd_filter_cache[i] - ref; |
3878 else // FIXME(rbultje) do this for comppred also | 4396 else // FIXME(rbultje) do this for comppred also |
3879 adj_rd = this_rd - (ref - cpi->rd_filter_cache[i]) * this_rd / ref; | 4397 adj_rd = this_rd - (ref - cpi->rd_filter_cache[i]) * this_rd / ref; |
3880 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); | 4398 best_filter_rd[i] = MIN(best_filter_rd[i], adj_rd); |
3881 } | 4399 } |
3882 } | 4400 } |
3883 | 4401 |
3884 /* keep record of best txfm size */ | 4402 /* keep record of best txfm size */ |
3885 if (bsize < BLOCK_32X32) { | 4403 if (bsize < BLOCK_32X32) { |
3886 if (bsize < BLOCK_16X16) { | 4404 if (bsize < BLOCK_16X16) { |
3887 if (this_mode == RD_SPLITMV || this_mode == RD_I4X4_PRED) | 4405 tx_cache[ALLOW_8X8] = tx_cache[ONLY_4X4]; |
3888 tx_cache[ALLOW_8X8] = tx_cache[ONLY_4X4]; | |
3889 tx_cache[ALLOW_16X16] = tx_cache[ALLOW_8X8]; | 4406 tx_cache[ALLOW_16X16] = tx_cache[ALLOW_8X8]; |
3890 } | 4407 } |
3891 tx_cache[ALLOW_32X32] = tx_cache[ALLOW_16X16]; | 4408 tx_cache[ALLOW_32X32] = tx_cache[ALLOW_16X16]; |
3892 } | 4409 } |
3893 if (!mode_excluded && this_rd != INT64_MAX) { | 4410 if (!mode_excluded && this_rd != INT64_MAX) { |
3894 for (i = 0; i < TX_MODES && tx_cache[i] < INT64_MAX; i++) { | 4411 for (i = 0; i < TX_MODES && tx_cache[i] < INT64_MAX; i++) { |
3895 int64_t adj_rd = INT64_MAX; | 4412 int64_t adj_rd = INT64_MAX; |
3896 if (this_mode != RD_I4X4_PRED) { | 4413 if (ref_frame > INTRA_FRAME) |
3897 adj_rd = this_rd + tx_cache[i] - tx_cache[cm->tx_mode]; | 4414 adj_rd = this_rd + tx_cache[i] - tx_cache[cm->tx_mode]; |
3898 } else { | 4415 else |
3899 adj_rd = this_rd; | 4416 adj_rd = this_rd; |
3900 } | |
3901 | 4417 |
3902 if (adj_rd < best_tx_rd[i]) | 4418 if (adj_rd < best_tx_rd[i]) |
3903 best_tx_rd[i] = adj_rd; | 4419 best_tx_rd[i] = adj_rd; |
3904 } | 4420 } |
3905 } | 4421 } |
3906 | 4422 |
3907 if (early_term) | 4423 if (early_term) |
3908 break; | 4424 break; |
3909 | 4425 |
3910 if (x->skip && !comp_pred) | 4426 if (x->skip && !comp_pred) |
3911 break; | 4427 break; |
3912 } | 4428 } |
3913 | 4429 |
3914 if (best_rd >= best_rd_so_far) | 4430 if (best_rd >= best_rd_so_far) |
3915 return INT64_MAX; | 4431 return INT64_MAX; |
3916 | 4432 |
3917 // If we used an estimate for the uv intra rd in the loop above... | 4433 // If we used an estimate for the uv intra rd in the loop above... |
3918 if (cpi->sf.use_uv_intra_rd_estimate) { | 4434 if (cpi->sf.use_uv_intra_rd_estimate) { |
3919 // Do Intra UV best rd mode selection if best mode choice above was intra. | 4435 // Do Intra UV best rd mode selection if best mode choice above was intra. |
3920 if (vp9_mode_order[best_mode_index].ref_frame == INTRA_FRAME) { | 4436 if (vp9_ref_order[best_mode_index].ref_frame == INTRA_FRAME) { |
3921 TX_SIZE uv_tx_size = get_uv_tx_size(mbmi); | 4437 TX_SIZE uv_tx_size = get_uv_tx_size(mbmi); |
3922 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_intra[uv_tx_size], | 4438 rd_pick_intra_sbuv_mode(cpi, x, &rate_uv_intra[uv_tx_size], |
3923 &rate_uv_tokenonly[uv_tx_size], | 4439 &rate_uv_tokenonly[uv_tx_size], |
3924 &dist_uv[uv_tx_size], | 4440 &dist_uv[uv_tx_size], |
3925 &skip_uv[uv_tx_size], | 4441 &skip_uv[uv_tx_size], |
3926 bsize < BLOCK_8X8 ? BLOCK_8X8 : bsize); | 4442 BLOCK_8X8); |
3927 } | 4443 } |
3928 } | 4444 } |
3929 | 4445 |
3930 // If we are using reference masking and the set mask flag is set then | 4446 // If we are using reference masking and the set mask flag is set then |
3931 // create the reference frame mask. | 4447 // create the reference frame mask. |
3932 if (cpi->sf.reference_masking && cpi->set_ref_frame_mask) | 4448 if (cpi->sf.reference_masking && cpi->set_ref_frame_mask) |
3933 cpi->ref_frame_mask = ~(1 << vp9_mode_order[best_mode_index].ref_frame); | 4449 cpi->ref_frame_mask = ~(1 << vp9_ref_order[best_mode_index].ref_frame); |
3934 | |
3935 // Flag all modes that have a distortion thats > 2x the best we found at | |
3936 // this level. | |
3937 for (mode_index = 0; mode_index < MB_MODE_COUNT; ++mode_index) { | |
3938 if (mode_index == NEARESTMV || mode_index == NEARMV || mode_index == NEWMV) | |
3939 continue; | |
3940 | |
3941 if (mode_distortions[mode_index] > 2 * *returndistortion) { | |
3942 ctx->modes_with_high_error |= (1 << mode_index); | |
3943 } | |
3944 } | |
3945 | |
3946 // Flag all ref frames that have a distortion thats > 2x the best we found at | |
3947 // this level. | |
3948 for (ref_frame = INTRA_FRAME; ref_frame <= ALTREF_FRAME; ref_frame++) { | |
3949 if (frame_distortions[ref_frame] > 2 * *returndistortion) { | |
3950 ctx->frames_with_high_error |= (1 << ref_frame); | |
3951 } | |
3952 } | |
3953 | 4450 |
3954 if (best_rd == INT64_MAX && bsize < BLOCK_8X8) { | 4451 if (best_rd == INT64_MAX && bsize < BLOCK_8X8) { |
3955 *returnrate = INT_MAX; | 4452 *returnrate = INT_MAX; |
3956 *returndistortion = INT_MAX; | 4453 *returndistortion = INT_MAX; |
3957 return best_rd; | 4454 return best_rd; |
3958 } | 4455 } |
3959 | 4456 |
3960 assert((cm->mcomp_filter_type == SWITCHABLE) || | 4457 assert((cm->mcomp_filter_type == SWITCHABLE) || |
3961 (cm->mcomp_filter_type == best_mbmode.interp_filter) || | 4458 (cm->mcomp_filter_type == best_mbmode.interp_filter) || |
3962 (best_mbmode.ref_frame[0] == INTRA_FRAME)); | 4459 (best_mbmode.ref_frame[0] == INTRA_FRAME)); |
3963 | 4460 |
3964 // Updating rd_thresh_freq_fact[] here means that the different | 4461 // Updating rd_thresh_freq_fact[] here means that the different |
3965 // partition/block sizes are handled independently based on the best | 4462 // partition/block sizes are handled independently based on the best |
3966 // choice for the current partition. It may well be better to keep a scaled | 4463 // choice for the current partition. It may well be better to keep a scaled |
3967 // best rd so far value and update rd_thresh_freq_fact based on the mode/size | 4464 // best rd so far value and update rd_thresh_freq_fact based on the mode/size |
3968 // combination that wins out. | 4465 // combination that wins out. |
3969 if (cpi->sf.adaptive_rd_thresh) { | 4466 if (cpi->sf.adaptive_rd_thresh) { |
3970 for (mode_index = 0; mode_index < MAX_MODES; ++mode_index) { | 4467 for (mode_index = 0; mode_index < MAX_REFS; ++mode_index) { |
3971 if (mode_index == best_mode_index) { | 4468 if (mode_index == best_mode_index) { |
3972 cpi->rd_thresh_freq_fact[bsize][mode_index] -= | 4469 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] -= |
3973 (cpi->rd_thresh_freq_fact[bsize][mode_index] >> 3); | 4470 (cpi->rd_thresh_freq_sub8x8[bsize][mode_index] >> 3); |
3974 } else { | 4471 } else { |
3975 cpi->rd_thresh_freq_fact[bsize][mode_index] += RD_THRESH_INC; | 4472 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] += RD_THRESH_INC; |
3976 if (cpi->rd_thresh_freq_fact[bsize][mode_index] > | 4473 if (cpi->rd_thresh_freq_sub8x8[bsize][mode_index] > |
3977 (cpi->sf.adaptive_rd_thresh * MAX_RD_THRESH_FACT)) { | 4474 (cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT)) { |
3978 cpi->rd_thresh_freq_fact[bsize][mode_index] = | 4475 cpi->rd_thresh_freq_sub8x8[bsize][mode_index] = |
3979 cpi->sf.adaptive_rd_thresh * MAX_RD_THRESH_FACT; | 4476 cpi->sf.adaptive_rd_thresh * RD_THRESH_MAX_FACT; |
3980 } | 4477 } |
3981 } | 4478 } |
3982 } | 4479 } |
3983 } | 4480 } |
3984 | 4481 |
3985 // macroblock modes | 4482 // macroblock modes |
3986 *mbmi = best_mbmode; | 4483 *mbmi = best_mbmode; |
3987 x->skip |= best_skip2; | 4484 x->skip |= best_skip2; |
3988 if (best_mbmode.ref_frame[0] == INTRA_FRAME && | 4485 if (best_mbmode.ref_frame[0] == INTRA_FRAME) { |
3989 best_mbmode.sb_type < BLOCK_8X8) { | |
3990 for (i = 0; i < 4; i++) | 4486 for (i = 0; i < 4; i++) |
3991 xd->this_mi->bmi[i].as_mode = best_bmodes[i].as_mode; | 4487 xd->mi_8x8[0]->bmi[i].as_mode = best_bmodes[i].as_mode; |
3992 } | 4488 } else { |
| 4489 for (i = 0; i < 4; ++i) |
| 4490 vpx_memcpy(&xd->mi_8x8[0]->bmi[i], &best_bmodes[i], sizeof(b_mode_info)); |
3993 | 4491 |
3994 if (best_mbmode.ref_frame[0] != INTRA_FRAME && | 4492 mbmi->mv[0].as_int = xd->mi_8x8[0]->bmi[3].as_mv[0].as_int; |
3995 best_mbmode.sb_type < BLOCK_8X8) { | 4493 mbmi->mv[1].as_int = xd->mi_8x8[0]->bmi[3].as_mv[1].as_int; |
3996 for (i = 0; i < 4; i++) | |
3997 xd->this_mi->bmi[i].as_mv[0].as_int = | |
3998 best_bmodes[i].as_mv[0].as_int; | |
3999 | |
4000 if (mbmi->ref_frame[1] > 0) | |
4001 for (i = 0; i < 4; i++) | |
4002 xd->this_mi->bmi[i].as_mv[1].as_int = | |
4003 best_bmodes[i].as_mv[1].as_int; | |
4004 | |
4005 *x->partition_info = best_partition; | |
4006 | |
4007 mbmi->mv[0].as_int = xd->this_mi->bmi[3].as_mv[0].as_int; | |
4008 mbmi->mv[1].as_int = xd->this_mi->bmi[3].as_mv[1].as_int; | |
4009 } | 4494 } |
4010 | 4495 |
4011 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { | 4496 for (i = 0; i < NB_PREDICTION_TYPES; ++i) { |
4012 if (best_pred_rd[i] == INT64_MAX) | 4497 if (best_pred_rd[i] == INT64_MAX) |
4013 best_pred_diff[i] = INT_MIN; | 4498 best_pred_diff[i] = INT_MIN; |
4014 else | 4499 else |
4015 best_pred_diff[i] = best_rd - best_pred_rd[i]; | 4500 best_pred_diff[i] = best_rd - best_pred_rd[i]; |
4016 } | 4501 } |
4017 | 4502 |
4018 if (!x->skip) { | 4503 if (!x->skip) { |
4019 for (i = 0; i <= SWITCHABLE_FILTERS; i++) { | 4504 for (i = 0; i < SWITCHABLE_FILTER_CONTEXTS; i++) { |
4020 if (best_filter_rd[i] == INT64_MAX) | 4505 if (best_filter_rd[i] == INT64_MAX) |
4021 best_filter_diff[i] = 0; | 4506 best_filter_diff[i] = 0; |
4022 else | 4507 else |
4023 best_filter_diff[i] = best_rd - best_filter_rd[i]; | 4508 best_filter_diff[i] = best_rd - best_filter_rd[i]; |
4024 } | 4509 } |
4025 if (cm->mcomp_filter_type == SWITCHABLE) | 4510 if (cm->mcomp_filter_type == SWITCHABLE) |
4026 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); | 4511 assert(best_filter_diff[SWITCHABLE_FILTERS] == 0); |
4027 } else { | 4512 } else { |
4028 vpx_memset(best_filter_diff, 0, sizeof(best_filter_diff)); | 4513 vp9_zero(best_filter_diff); |
4029 } | 4514 } |
4030 | 4515 |
4031 if (!x->skip) { | 4516 if (!x->skip) { |
4032 for (i = 0; i < TX_MODES; i++) { | 4517 for (i = 0; i < TX_MODES; i++) { |
4033 if (best_tx_rd[i] == INT64_MAX) | 4518 if (best_tx_rd[i] == INT64_MAX) |
4034 best_tx_diff[i] = 0; | 4519 best_tx_diff[i] = 0; |
4035 else | 4520 else |
4036 best_tx_diff[i] = best_rd - best_tx_rd[i]; | 4521 best_tx_diff[i] = best_rd - best_tx_rd[i]; |
4037 } | 4522 } |
4038 } else { | 4523 } else { |
4039 vpx_memset(best_tx_diff, 0, sizeof(best_tx_diff)); | 4524 vp9_zero(best_tx_diff); |
4040 } | 4525 } |
4041 | 4526 |
4042 set_scale_factors(xd, mbmi->ref_frame[0], mbmi->ref_frame[1], | 4527 set_scale_factors(xd, mbmi->ref_frame[0], mbmi->ref_frame[1], |
4043 scale_factor); | 4528 scale_factor); |
4044 store_coding_context(x, ctx, best_mode_index, | 4529 store_coding_context(x, ctx, best_mode_index, |
4045 &best_partition, | |
4046 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], | 4530 &mbmi->ref_mvs[mbmi->ref_frame[0]][0], |
4047 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : | 4531 &mbmi->ref_mvs[mbmi->ref_frame[1] < 0 ? 0 : |
4048 mbmi->ref_frame[1]][0], | 4532 mbmi->ref_frame[1]][0], |
4049 best_pred_diff, best_tx_diff, best_filter_diff); | 4533 best_pred_diff, best_tx_diff, best_filter_diff); |
4050 | 4534 |
4051 return best_rd; | 4535 return best_rd; |
4052 } | 4536 } |
OLD | NEW |