OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 for (i = 0; i < MAX_MB_PLANE; i++) | 72 for (i = 0; i < MAX_MB_PLANE; i++) |
73 xd->plane[i].pre[0] = backup_yv12[i]; | 73 xd->plane[i].pre[0] = backup_yv12[i]; |
74 } | 74 } |
75 return; | 75 return; |
76 } | 76 } |
77 } | 77 } |
78 assert(x->mv_best_ref_index[ref] <= 2); | 78 assert(x->mv_best_ref_index[ref] <= 2); |
79 if (x->mv_best_ref_index[ref] < 2) | 79 if (x->mv_best_ref_index[ref] < 2) |
80 mvp_full = mbmi->ref_mvs[ref][x->mv_best_ref_index[ref]].as_mv; | 80 mvp_full = mbmi->ref_mvs[ref][x->mv_best_ref_index[ref]].as_mv; |
81 else | 81 else |
82 mvp_full = x->pred_mv[ref].as_mv; | 82 mvp_full = x->pred_mv[ref]; |
83 | 83 |
84 mvp_full.col >>= 3; | 84 mvp_full.col >>= 3; |
85 mvp_full.row >>= 3; | 85 mvp_full.row >>= 3; |
86 | 86 |
87 full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb, &ref_mv, | 87 vp9_full_pixel_search(cpi, x, bsize, &mvp_full, step_param, sadpb, &ref_mv, |
88 &tmp_mv->as_mv, INT_MAX, 0); | 88 &tmp_mv->as_mv, INT_MAX, 0); |
89 | 89 |
90 x->mv_col_min = tmp_col_min; | 90 x->mv_col_min = tmp_col_min; |
91 x->mv_col_max = tmp_col_max; | 91 x->mv_col_max = tmp_col_max; |
92 x->mv_row_min = tmp_row_min; | 92 x->mv_row_min = tmp_row_min; |
93 x->mv_row_max = tmp_row_max; | 93 x->mv_row_max = tmp_row_max; |
94 | 94 |
95 if (scaled_ref_frame) { | 95 if (scaled_ref_frame) { |
96 int i; | 96 int i; |
97 for (i = 0; i < MAX_MB_PLANE; i++) | 97 for (i = 0; i < MAX_MB_PLANE; i++) |
98 xd->plane[i].pre[0] = backup_yv12[i]; | 98 xd->plane[i].pre[0] = backup_yv12[i]; |
(...skipping 26 matching lines...) Expand all Loading... |
125 for (i = 0; i < MAX_MB_PLANE; i++) | 125 for (i = 0; i < MAX_MB_PLANE; i++) |
126 backup_yv12[i] = xd->plane[i].pre[0]; | 126 backup_yv12[i] = xd->plane[i].pre[0]; |
127 | 127 |
128 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); | 128 vp9_setup_pre_planes(xd, 0, scaled_ref_frame, mi_row, mi_col, NULL); |
129 } | 129 } |
130 | 130 |
131 cpi->find_fractional_mv_step(x, tmp_mv, &ref_mv, | 131 cpi->find_fractional_mv_step(x, tmp_mv, &ref_mv, |
132 cpi->common.allow_high_precision_mv, | 132 cpi->common.allow_high_precision_mv, |
133 x->errorperbit, | 133 x->errorperbit, |
134 &cpi->fn_ptr[bsize], | 134 &cpi->fn_ptr[bsize], |
135 cpi->sf.subpel_force_stop, | 135 cpi->sf.mv.subpel_force_stop, |
136 cpi->sf.subpel_iters_per_step, | 136 cpi->sf.mv.subpel_iters_per_step, |
137 x->nmvjointcost, x->mvcost, | 137 x->nmvjointcost, x->mvcost, |
138 &dis, &x->pred_sse[ref]); | 138 &dis, &x->pred_sse[ref]); |
139 | 139 |
140 if (scaled_ref_frame) { | 140 if (scaled_ref_frame) { |
141 int i; | 141 int i; |
142 for (i = 0; i < MAX_MB_PLANE; i++) | 142 for (i = 0; i < MAX_MB_PLANE; i++) |
143 xd->plane[i].pre[0] = backup_yv12[i]; | 143 xd->plane[i].pre[0] = backup_yv12[i]; |
144 } | 144 } |
145 | 145 |
146 x->pred_mv[ref].as_mv = *tmp_mv; | 146 x->pred_mv[ref] = *tmp_mv; |
147 } | 147 } |
148 | 148 |
149 static void model_rd_for_sb_y(VP9_COMP *cpi, BLOCK_SIZE bsize, | 149 static void model_rd_for_sb_y(VP9_COMP *cpi, BLOCK_SIZE bsize, |
150 MACROBLOCK *x, MACROBLOCKD *xd, | 150 MACROBLOCK *x, MACROBLOCKD *xd, |
151 int *out_rate_sum, int64_t *out_dist_sum) { | 151 int *out_rate_sum, int64_t *out_dist_sum, |
| 152 unsigned int *var_y, unsigned int *sse_y) { |
152 // Note our transform coeffs are 8 times an orthogonal transform. | 153 // Note our transform coeffs are 8 times an orthogonal transform. |
153 // Hence quantizer step is also 8 times. To get effective quantizer | 154 // Hence quantizer step is also 8 times. To get effective quantizer |
154 // we need to divide by 8 before sending to modeling function. | 155 // we need to divide by 8 before sending to modeling function. |
155 unsigned int sse; | 156 unsigned int sse; |
156 int rate; | 157 int rate; |
157 int64_t dist; | 158 int64_t dist; |
158 | |
159 struct macroblock_plane *const p = &x->plane[0]; | 159 struct macroblock_plane *const p = &x->plane[0]; |
160 struct macroblockd_plane *const pd = &xd->plane[0]; | 160 struct macroblockd_plane *const pd = &xd->plane[0]; |
161 | 161 const uint32_t dc_quant = pd->dequant[0]; |
| 162 const uint32_t ac_quant = pd->dequant[1]; |
162 unsigned int var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride, | 163 unsigned int var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride, |
163 pd->dst.buf, pd->dst.stride, &sse); | 164 pd->dst.buf, pd->dst.stride, &sse); |
| 165 *var_y = var; |
| 166 *sse_y = sse; |
164 | 167 |
165 // TODO(jingning) This is a temporary solution to account for frames with | 168 if (sse < dc_quant * dc_quant >> 6) |
166 // light changes. Need to customize the rate-distortion modeling for non-RD | 169 x->skip_txfm = 1; |
167 // mode decision. | 170 else if (var < ac_quant * ac_quant >> 6) |
168 if ((sse >> 3) > var) | 171 x->skip_txfm = 2; |
169 sse = var; | 172 else |
| 173 x->skip_txfm = 0; |
170 | 174 |
171 vp9_model_rd_from_var_lapndz(var + sse, 1 << num_pels_log2_lookup[bsize], | 175 vp9_model_rd_from_var_lapndz(sse - var, 1 << num_pels_log2_lookup[bsize], |
172 pd->dequant[1] >> 3, &rate, &dist); | 176 dc_quant >> 3, &rate, &dist); |
173 *out_rate_sum = rate; | 177 *out_rate_sum = rate >> 1; |
174 *out_dist_sum = dist << 3; | 178 *out_dist_sum = dist << 3; |
| 179 |
| 180 vp9_model_rd_from_var_lapndz(var, 1 << num_pels_log2_lookup[bsize], |
| 181 ac_quant >> 3, &rate, &dist); |
| 182 *out_rate_sum += rate; |
| 183 *out_dist_sum += dist << 4; |
175 } | 184 } |
176 | 185 |
177 // TODO(jingning) placeholder for inter-frame non-RD mode decision. | 186 // TODO(jingning) placeholder for inter-frame non-RD mode decision. |
178 // this needs various further optimizations. to be continued.. | 187 // this needs various further optimizations. to be continued.. |
179 int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, | 188 int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, |
180 const TileInfo *const tile, | 189 const TileInfo *const tile, |
181 int mi_row, int mi_col, | 190 int mi_row, int mi_col, |
182 int *returnrate, | 191 int *returnrate, |
183 int64_t *returndistortion, | 192 int64_t *returndistortion, |
184 BLOCK_SIZE bsize) { | 193 BLOCK_SIZE bsize) { |
185 MACROBLOCKD *xd = &x->e_mbd; | 194 MACROBLOCKD *xd = &x->e_mbd; |
186 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; | 195 MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; |
187 struct macroblock_plane *const p = &x->plane[0]; | 196 struct macroblock_plane *const p = &x->plane[0]; |
188 struct macroblockd_plane *const pd = &xd->plane[0]; | 197 struct macroblockd_plane *const pd = &xd->plane[0]; |
189 PREDICTION_MODE this_mode, best_mode = ZEROMV; | 198 PREDICTION_MODE this_mode, best_mode = ZEROMV; |
190 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; | 199 MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; |
191 INTERP_FILTER best_pred_filter = EIGHTTAP; | 200 INTERP_FILTER best_pred_filter = EIGHTTAP; |
192 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; | 201 int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; |
193 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; | 202 struct buf_2d yv12_mb[4][MAX_MB_PLANE]; |
194 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, | 203 static const int flag_list[4] = { 0, VP9_LAST_FLAG, VP9_GOLD_FLAG, |
195 VP9_ALT_FLAG }; | 204 VP9_ALT_FLAG }; |
196 int64_t best_rd = INT64_MAX; | 205 int64_t best_rd = INT64_MAX; |
197 int64_t this_rd = INT64_MAX; | 206 int64_t this_rd = INT64_MAX; |
| 207 int skip_txfm = 0; |
198 | 208 |
199 int rate = INT_MAX; | 209 int rate = INT_MAX; |
200 int64_t dist = INT64_MAX; | 210 int64_t dist = INT64_MAX; |
| 211 // var_y and sse_y are saved to be used in skipping checking |
| 212 unsigned int var_y = UINT_MAX; |
| 213 unsigned int sse_y = UINT_MAX; |
201 | 214 |
202 VP9_COMMON *cm = &cpi->common; | 215 VP9_COMMON *cm = &cpi->common; |
203 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); | 216 int intra_cost_penalty = 20 * vp9_dc_quant(cm->base_qindex, cm->y_dc_delta_q); |
204 | 217 |
205 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, | 218 const int64_t inter_mode_thresh = RDCOST(x->rdmult, x->rddiv, |
206 intra_cost_penalty, 0); | 219 intra_cost_penalty, 0); |
207 const int64_t intra_mode_cost = 50; | 220 const int64_t intra_mode_cost = 50; |
208 | 221 |
209 unsigned char segment_id = mbmi->segment_id; | 222 unsigned char segment_id = mbmi->segment_id; |
210 const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize]; | 223 const int *const rd_threshes = cpi->rd.threshes[segment_id][bsize]; |
211 const int *const rd_thresh_freq_fact = cpi->rd.thresh_freq_fact[bsize]; | 224 const int *const rd_thresh_freq_fact = cpi->rd.thresh_freq_fact[bsize]; |
212 // Mode index conversion form THR_MODES to PREDICTION_MODE for a ref frame. | 225 // Mode index conversion form THR_MODES to PREDICTION_MODE for a ref frame. |
213 int mode_idx[MB_MODE_COUNT] = {0}; | 226 int mode_idx[MB_MODE_COUNT] = {0}; |
214 INTERP_FILTER filter_ref = SWITCHABLE; | 227 INTERP_FILTER filter_ref = SWITCHABLE; |
215 int bsl = mi_width_log2_lookup[bsize]; | 228 int bsl = mi_width_log2_lookup[bsize]; |
216 int pred_filter_search = (((mi_row + mi_col) >> bsl) + | 229 const int pred_filter_search = (((mi_row + mi_col) >> bsl) + |
217 cpi->sf.chessboard_index) & 0x01; | 230 get_chessboard_index(cm)) % 2; |
218 | 231 |
219 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; | 232 x->skip_encode = cpi->sf.skip_encode_frame && x->q_index < QIDX_SKIP_THRESH; |
220 | 233 |
221 x->skip = 0; | 234 x->skip = 0; |
222 if (!x->in_active_map) | 235 |
223 x->skip = 1; | |
224 // initialize mode decisions | 236 // initialize mode decisions |
225 *returnrate = INT_MAX; | 237 *returnrate = INT_MAX; |
226 *returndistortion = INT64_MAX; | 238 *returndistortion = INT64_MAX; |
227 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO)); | 239 vpx_memset(mbmi, 0, sizeof(MB_MODE_INFO)); |
228 mbmi->sb_type = bsize; | 240 mbmi->sb_type = bsize; |
229 mbmi->ref_frame[0] = NONE; | 241 mbmi->ref_frame[0] = NONE; |
230 mbmi->ref_frame[1] = NONE; | 242 mbmi->ref_frame[1] = NONE; |
231 mbmi->tx_size = MIN(max_txsize_lookup[bsize], | 243 mbmi->tx_size = MIN(max_txsize_lookup[bsize], |
232 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); | 244 tx_mode_to_biggest_tx_size[cpi->common.tx_mode]); |
233 mbmi->interp_filter = cpi->common.interp_filter == SWITCHABLE ? | 245 mbmi->interp_filter = cpi->common.interp_filter == SWITCHABLE ? |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 if (ref_frame == LAST_FRAME) { | 279 if (ref_frame == LAST_FRAME) { |
268 mode_idx[NEARESTMV] = THR_NEARESTMV; // LAST_FRAME, NEARESTMV | 280 mode_idx[NEARESTMV] = THR_NEARESTMV; // LAST_FRAME, NEARESTMV |
269 mode_idx[NEARMV] = THR_NEARMV; // LAST_FRAME, NEARMV | 281 mode_idx[NEARMV] = THR_NEARMV; // LAST_FRAME, NEARMV |
270 mode_idx[ZEROMV] = THR_ZEROMV; // LAST_FRAME, ZEROMV | 282 mode_idx[ZEROMV] = THR_ZEROMV; // LAST_FRAME, ZEROMV |
271 mode_idx[NEWMV] = THR_NEWMV; // LAST_FRAME, NEWMV | 283 mode_idx[NEWMV] = THR_NEWMV; // LAST_FRAME, NEWMV |
272 } | 284 } |
273 | 285 |
274 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { | 286 for (this_mode = NEARESTMV; this_mode <= NEWMV; ++this_mode) { |
275 int rate_mv = 0; | 287 int rate_mv = 0; |
276 | 288 |
277 if (cpi->sf.disable_inter_mode_mask[bsize] & | 289 if (!(cpi->sf.inter_mode_mask[bsize] & (1 << this_mode))) |
278 (1 << INTER_OFFSET(this_mode))) | |
279 continue; | 290 continue; |
280 | 291 |
281 if (best_rd < ((int64_t)rd_threshes[mode_idx[this_mode]] * | 292 if (rd_less_than_thresh(best_rd, rd_threshes[mode_idx[this_mode]], |
282 rd_thresh_freq_fact[this_mode] >> 5) || | 293 rd_thresh_freq_fact[this_mode])) |
283 rd_threshes[mode_idx[this_mode]] == INT_MAX) | |
284 continue; | 294 continue; |
285 | 295 |
286 if (this_mode == NEWMV) { | 296 if (this_mode == NEWMV) { |
287 int rate_mode = 0; | 297 int rate_mode = 0; |
288 if (this_rd < (int64_t)(1 << num_pels_log2_lookup[bsize])) | 298 if (this_rd < (int64_t)(1 << num_pels_log2_lookup[bsize])) |
289 continue; | 299 continue; |
290 | 300 |
291 full_pixel_motion_search(cpi, x, bsize, mi_row, mi_col, | 301 full_pixel_motion_search(cpi, x, bsize, mi_row, mi_col, |
292 &frame_mv[NEWMV][ref_frame], &rate_mv); | 302 &frame_mv[NEWMV][ref_frame], &rate_mv); |
293 | 303 |
(...skipping 17 matching lines...) Expand all Loading... |
311 mbmi->mode = this_mode; | 321 mbmi->mode = this_mode; |
312 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; | 322 mbmi->mv[0].as_int = frame_mv[this_mode][ref_frame].as_int; |
313 | 323 |
314 // Search for the best prediction filter type, when the resulting | 324 // Search for the best prediction filter type, when the resulting |
315 // motion vector is at sub-pixel accuracy level for luma component, i.e., | 325 // motion vector is at sub-pixel accuracy level for luma component, i.e., |
316 // the last three bits are all zeros. | 326 // the last three bits are all zeros. |
317 if ((this_mode == NEWMV || filter_ref == SWITCHABLE) && | 327 if ((this_mode == NEWMV || filter_ref == SWITCHABLE) && |
318 pred_filter_search && | 328 pred_filter_search && |
319 ((mbmi->mv[0].as_mv.row & 0x07) != 0 || | 329 ((mbmi->mv[0].as_mv.row & 0x07) != 0 || |
320 (mbmi->mv[0].as_mv.col & 0x07) != 0)) { | 330 (mbmi->mv[0].as_mv.col & 0x07) != 0)) { |
321 int64_t tmp_rdcost1 = INT64_MAX; | |
322 int64_t tmp_rdcost2 = INT64_MAX; | |
323 int64_t tmp_rdcost3 = INT64_MAX; | |
324 int pf_rate[3]; | 331 int pf_rate[3]; |
325 int64_t pf_dist[3]; | 332 int64_t pf_dist[3]; |
| 333 unsigned int pf_var[3]; |
| 334 unsigned int pf_sse[3]; |
| 335 int64_t best_cost = INT64_MAX; |
| 336 INTERP_FILTER best_filter = SWITCHABLE, filter; |
326 | 337 |
327 mbmi->interp_filter = EIGHTTAP; | 338 for (filter = EIGHTTAP; filter <= EIGHTTAP_SHARP; ++filter) { |
328 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); | 339 int64_t cost; |
329 model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[EIGHTTAP], | 340 mbmi->interp_filter = filter; |
330 &pf_dist[EIGHTTAP]); | 341 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); |
331 tmp_rdcost1 = RDCOST(x->rdmult, x->rddiv, | 342 model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[filter], |
332 vp9_get_switchable_rate(cpi) + pf_rate[EIGHTTAP], | 343 &pf_dist[filter], &pf_var[filter], &pf_sse[filter]); |
333 pf_dist[EIGHTTAP]); | 344 cost = RDCOST(x->rdmult, x->rddiv, |
334 | 345 vp9_get_switchable_rate(cpi) + pf_rate[filter], |
335 mbmi->interp_filter = EIGHTTAP_SHARP; | 346 pf_dist[filter]); |
336 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); | 347 if (cost < best_cost) { |
337 model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[EIGHTTAP_SHARP], | 348 best_filter = filter; |
338 &pf_dist[EIGHTTAP_SHARP]); | 349 best_cost = cost; |
339 tmp_rdcost2 = RDCOST(x->rdmult, x->rddiv, vp9_get_switchable_rate(cpi) + | 350 skip_txfm = x->skip_txfm; |
340 pf_rate[EIGHTTAP_SHARP], | 351 } |
341 pf_dist[EIGHTTAP_SHARP]); | |
342 | |
343 mbmi->interp_filter = EIGHTTAP_SMOOTH; | |
344 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); | |
345 model_rd_for_sb_y(cpi, bsize, x, xd, &pf_rate[EIGHTTAP_SMOOTH], | |
346 &pf_dist[EIGHTTAP_SMOOTH]); | |
347 tmp_rdcost3 = RDCOST(x->rdmult, x->rddiv, vp9_get_switchable_rate(cpi) + | |
348 pf_rate[EIGHTTAP_SMOOTH], | |
349 pf_dist[EIGHTTAP_SMOOTH]); | |
350 | |
351 if (tmp_rdcost2 < tmp_rdcost1) { | |
352 if (tmp_rdcost2 < tmp_rdcost3) | |
353 mbmi->interp_filter = EIGHTTAP_SHARP; | |
354 else | |
355 mbmi->interp_filter = EIGHTTAP_SMOOTH; | |
356 } else { | |
357 if (tmp_rdcost1 < tmp_rdcost3) | |
358 mbmi->interp_filter = EIGHTTAP; | |
359 else | |
360 mbmi->interp_filter = EIGHTTAP_SMOOTH; | |
361 } | 352 } |
362 | 353 |
| 354 mbmi->interp_filter = best_filter; |
363 rate = pf_rate[mbmi->interp_filter]; | 355 rate = pf_rate[mbmi->interp_filter]; |
364 dist = pf_dist[mbmi->interp_filter]; | 356 dist = pf_dist[mbmi->interp_filter]; |
| 357 var_y = pf_var[mbmi->interp_filter]; |
| 358 sse_y = pf_sse[mbmi->interp_filter]; |
| 359 x->skip_txfm = skip_txfm; |
365 } else { | 360 } else { |
366 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref; | 361 mbmi->interp_filter = (filter_ref == SWITCHABLE) ? EIGHTTAP: filter_ref; |
367 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); | 362 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, bsize); |
368 model_rd_for_sb_y(cpi, bsize, x, xd, &rate, &dist); | 363 model_rd_for_sb_y(cpi, bsize, x, xd, &rate, &dist, &var_y, &sse_y); |
369 } | 364 } |
370 | 365 |
371 rate += rate_mv; | 366 rate += rate_mv; |
372 rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] | 367 rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] |
373 [INTER_OFFSET(this_mode)]; | 368 [INTER_OFFSET(this_mode)]; |
374 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); | 369 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); |
375 | 370 |
376 if (this_rd < best_rd) { | 371 // Skipping checking: test to see if this block can be reconstructed by |
| 372 // prediction only. |
| 373 if (!x->in_active_map) { |
| 374 x->skip = 1; |
| 375 } else if (cpi->allow_encode_breakout && x->encode_breakout) { |
| 376 const BLOCK_SIZE uv_size = get_plane_block_size(bsize, &xd->plane[1]); |
| 377 unsigned int var = var_y, sse = sse_y; |
| 378 // Skipping threshold for ac. |
| 379 unsigned int thresh_ac; |
| 380 // Skipping threshold for dc. |
| 381 unsigned int thresh_dc; |
| 382 // Set a maximum for threshold to avoid big PSNR loss in low bit rate |
| 383 // case. Use extreme low threshold for static frames to limit skipping. |
| 384 const unsigned int max_thresh = 36000; |
| 385 // The encode_breakout input |
| 386 const unsigned int min_thresh = |
| 387 MIN(((unsigned int)x->encode_breakout << 4), max_thresh); |
| 388 |
| 389 // Calculate threshold according to dequant value. |
| 390 thresh_ac = (xd->plane[0].dequant[1] * xd->plane[0].dequant[1]) / 9; |
| 391 thresh_ac = clamp(thresh_ac, min_thresh, max_thresh); |
| 392 |
| 393 // Adjust ac threshold according to partition size. |
| 394 thresh_ac >>= 8 - (b_width_log2_lookup[bsize] + |
| 395 b_height_log2_lookup[bsize]); |
| 396 |
| 397 thresh_dc = (xd->plane[0].dequant[0] * xd->plane[0].dequant[0] >> 6); |
| 398 |
| 399 // Y skipping condition checking for ac and dc. |
| 400 if (var <= thresh_ac && (sse - var) <= thresh_dc) { |
| 401 unsigned int sse_u, sse_v; |
| 402 unsigned int var_u, var_v; |
| 403 |
| 404 // Skip u v prediction for less calculation, that won't affect |
| 405 // result much. |
| 406 var_u = cpi->fn_ptr[uv_size].vf(x->plane[1].src.buf, |
| 407 x->plane[1].src.stride, |
| 408 xd->plane[1].dst.buf, |
| 409 xd->plane[1].dst.stride, &sse_u); |
| 410 |
| 411 // U skipping condition checking |
| 412 if ((var_u * 4 <= thresh_ac) && (sse_u - var_u <= thresh_dc)) { |
| 413 var_v = cpi->fn_ptr[uv_size].vf(x->plane[2].src.buf, |
| 414 x->plane[2].src.stride, |
| 415 xd->plane[2].dst.buf, |
| 416 xd->plane[2].dst.stride, &sse_v); |
| 417 |
| 418 // V skipping condition checking |
| 419 if ((var_v * 4 <= thresh_ac) && (sse_v - var_v <= thresh_dc)) { |
| 420 x->skip = 1; |
| 421 |
| 422 // The cost of skip bit needs to be added. |
| 423 rate = rate_mv; |
| 424 rate += cpi->inter_mode_cost[mbmi->mode_context[ref_frame]] |
| 425 [INTER_OFFSET(this_mode)]; |
| 426 |
| 427 // More on this part of rate |
| 428 // rate += vp9_cost_bit(vp9_get_skip_prob(cm, xd), 1); |
| 429 |
| 430 // Scaling factor for SSE from spatial domain to frequency |
| 431 // domain is 16. Adjust distortion accordingly. |
| 432 // TODO(yunqingwang): In this function, only y-plane dist is |
| 433 // calculated. |
| 434 dist = (sse << 4); // + ((sse_u + sse_v) << 4); |
| 435 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); |
| 436 // *disable_skip = 1; |
| 437 } |
| 438 } |
| 439 } |
| 440 } |
| 441 |
| 442 #if CONFIG_DENOISING |
| 443 vp9_denoiser_update_frame_stats(); |
| 444 #endif |
| 445 |
| 446 if (this_rd < best_rd || x->skip) { |
377 best_rd = this_rd; | 447 best_rd = this_rd; |
378 *returnrate = rate; | 448 *returnrate = rate; |
379 *returndistortion = dist; | 449 *returndistortion = dist; |
380 best_mode = this_mode; | 450 best_mode = this_mode; |
381 best_pred_filter = mbmi->interp_filter; | 451 best_pred_filter = mbmi->interp_filter; |
382 best_ref_frame = ref_frame; | 452 best_ref_frame = ref_frame; |
| 453 skip_txfm = x->skip_txfm; |
383 } | 454 } |
| 455 |
| 456 if (x->skip) |
| 457 break; |
384 } | 458 } |
385 } | 459 } |
386 | 460 |
| 461 |
387 mbmi->mode = best_mode; | 462 mbmi->mode = best_mode; |
388 mbmi->interp_filter = best_pred_filter; | 463 mbmi->interp_filter = best_pred_filter; |
389 mbmi->ref_frame[0] = best_ref_frame; | 464 mbmi->ref_frame[0] = best_ref_frame; |
390 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; | 465 mbmi->mv[0].as_int = frame_mv[best_mode][best_ref_frame].as_int; |
391 xd->mi[0]->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; | 466 xd->mi[0]->bmi[0].as_mv[0].as_int = mbmi->mv[0].as_int; |
| 467 x->skip_txfm = skip_txfm; |
392 | 468 |
393 // Perform intra prediction search, if the best SAD is above a certain | 469 // Perform intra prediction search, if the best SAD is above a certain |
394 // threshold. | 470 // threshold. |
395 if (best_rd > inter_mode_thresh && bsize < cpi->sf.max_intra_bsize) { | 471 if (!x->skip && best_rd > inter_mode_thresh && |
| 472 bsize <= cpi->sf.max_intra_bsize) { |
396 for (this_mode = DC_PRED; this_mode <= DC_PRED; ++this_mode) { | 473 for (this_mode = DC_PRED; this_mode <= DC_PRED; ++this_mode) { |
397 vp9_predict_intra_block(xd, 0, b_width_log2(bsize), | 474 vp9_predict_intra_block(xd, 0, b_width_log2(bsize), |
398 mbmi->tx_size, this_mode, | 475 mbmi->tx_size, this_mode, |
399 &p->src.buf[0], p->src.stride, | 476 &p->src.buf[0], p->src.stride, |
400 &pd->dst.buf[0], pd->dst.stride, 0, 0, 0); | 477 &pd->dst.buf[0], pd->dst.stride, 0, 0, 0); |
401 | 478 |
402 model_rd_for_sb_y(cpi, bsize, x, xd, &rate, &dist); | 479 model_rd_for_sb_y(cpi, bsize, x, xd, &rate, &dist, &var_y, &sse_y); |
403 rate += cpi->mbmode_cost[this_mode]; | 480 rate += cpi->mbmode_cost[this_mode]; |
404 rate += intra_cost_penalty; | 481 rate += intra_cost_penalty; |
405 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); | 482 this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist); |
406 | 483 |
407 if (this_rd + intra_mode_cost < best_rd) { | 484 if (this_rd + intra_mode_cost < best_rd) { |
408 best_rd = this_rd; | 485 best_rd = this_rd; |
409 *returnrate = rate; | 486 *returnrate = rate; |
410 *returndistortion = dist; | 487 *returndistortion = dist; |
411 mbmi->mode = this_mode; | 488 mbmi->mode = this_mode; |
412 mbmi->ref_frame[0] = INTRA_FRAME; | 489 mbmi->ref_frame[0] = INTRA_FRAME; |
413 mbmi->uv_mode = this_mode; | 490 mbmi->uv_mode = this_mode; |
414 mbmi->mv[0].as_int = INVALID_MV; | 491 mbmi->mv[0].as_int = INVALID_MV; |
| 492 } else { |
| 493 x->skip_txfm = skip_txfm; |
415 } | 494 } |
416 } | 495 } |
417 } | 496 } |
| 497 #if CONFIG_DENOISING |
| 498 vp9_denoiser_denoise(&cpi->denoiser, x, mi_row, mi_col, bsize); |
| 499 #endif |
418 | 500 |
419 return INT64_MAX; | 501 return INT64_MAX; |
420 } | 502 } |
OLD | NEW |