• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <limits.h>
12 
13 #include "vp9/encoder/vp9_encoder.h"
14 #include "vp9/encoder/vp9_speed_features.h"
15 #include "vp9/encoder/vp9_rdopt.h"
16 #include "vpx_dsp/vpx_dsp_common.h"
17 
18 
19 // Intra only frames, golden frames (except alt ref overlays) and
20 // alt ref frames tend to be coded at a higher than ambient quality
frame_is_boosted(const VP9_COMP * cpi)21 static int frame_is_boosted(const VP9_COMP *cpi) {
22   return frame_is_kf_gf_arf(cpi) || vp9_is_upper_layer_key_frame(cpi);
23 }
24 
25 // Sets a partition size down to which the auto partition code will always
26 // search (can go lower), based on the image dimensions. The logic here
27 // is that the extent to which ringing artefacts are offensive, depends
28 // partly on the screen area that over which they propogate. Propogation is
29 // limited by transform block size but the screen area take up by a given block
30 // size will be larger for a small image format stretched to full screen.
set_partition_min_limit(VP9_COMMON * const cm)31 static BLOCK_SIZE set_partition_min_limit(VP9_COMMON *const cm) {
32   unsigned int screen_area = (cm->width * cm->height);
33 
34   // Select block size based on image format size.
35   if (screen_area < 1280 * 720) {
36     // Formats smaller in area than 720P
37     return BLOCK_4X4;
38   } else if (screen_area < 1920 * 1080) {
39     // Format >= 720P and < 1080P
40     return BLOCK_8X8;
41   } else {
42     // Formats 1080P and up
43     return BLOCK_16X16;
44   }
45 }
46 
set_good_speed_feature_framesize_dependent(VP9_COMP * cpi,SPEED_FEATURES * sf,int speed)47 static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
48                                                        SPEED_FEATURES *sf,
49                                                        int speed) {
50   VP9_COMMON *const cm = &cpi->common;
51 
52   if (speed >= 1) {
53     if (VPXMIN(cm->width, cm->height) >= 720) {
54       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
55                                               : DISABLE_ALL_INTER_SPLIT;
56       sf->partition_search_breakout_dist_thr = (1 << 23);
57     } else {
58       sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
59       sf->partition_search_breakout_dist_thr = (1 << 21);
60     }
61   }
62 
63   if (speed >= 2) {
64     if (VPXMIN(cm->width, cm->height) >= 720) {
65       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
66                                               : DISABLE_ALL_INTER_SPLIT;
67       sf->adaptive_pred_interp_filter = 0;
68       sf->partition_search_breakout_dist_thr = (1 << 24);
69       sf->partition_search_breakout_rate_thr = 120;
70     } else {
71       sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
72       sf->partition_search_breakout_dist_thr = (1 << 22);
73       sf->partition_search_breakout_rate_thr = 100;
74     }
75     sf->rd_auto_partition_min_limit = set_partition_min_limit(cm);
76   }
77 
78   if (speed >= 3) {
79     if (VPXMIN(cm->width, cm->height) >= 720) {
80       sf->disable_split_mask = DISABLE_ALL_SPLIT;
81       sf->schedule_mode_search = cm->base_qindex < 220 ? 1 : 0;
82       sf->partition_search_breakout_dist_thr = (1 << 25);
83       sf->partition_search_breakout_rate_thr = 200;
84     } else {
85       sf->max_intra_bsize = BLOCK_32X32;
86       sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
87       sf->schedule_mode_search = cm->base_qindex < 175 ? 1 : 0;
88       sf->partition_search_breakout_dist_thr = (1 << 23);
89       sf->partition_search_breakout_rate_thr = 120;
90     }
91   }
92 
93   // If this is a two pass clip that fits the criteria for animated or
94   // graphics content then reset disable_split_mask for speeds 1-4.
95   // Also if the image edge is internal to the coded area.
96   if ((speed >= 1) && (cpi->oxcf.pass == 2) &&
97       ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
98        (vp9_internal_image_edge(cpi)))) {
99     sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
100   }
101 
102   if (speed >= 4) {
103     if (VPXMIN(cm->width, cm->height) >= 720) {
104       sf->partition_search_breakout_dist_thr = (1 << 26);
105     } else {
106       sf->partition_search_breakout_dist_thr = (1 << 24);
107     }
108     sf->disable_split_mask = DISABLE_ALL_SPLIT;
109   }
110 }
111 
set_good_speed_feature(VP9_COMP * cpi,VP9_COMMON * cm,SPEED_FEATURES * sf,int speed)112 static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm,
113                                    SPEED_FEATURES *sf, int speed) {
114   const int boosted = frame_is_boosted(cpi);
115 
116   sf->partition_search_breakout_dist_thr = (1 << 20);
117   sf->partition_search_breakout_rate_thr = 80;
118   sf->tx_size_search_breakout = 1;
119   sf->adaptive_rd_thresh = 1;
120   sf->allow_skip_recode = 1;
121   sf->less_rectangular_check = 1;
122   sf->use_square_partition_only = !frame_is_boosted(cpi);
123   sf->use_square_only_threshold = BLOCK_16X16;
124 
125   if (speed >= 1) {
126     if ((cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION) ||
127         vp9_internal_image_edge(cpi)) {
128       sf->use_square_partition_only = !frame_is_boosted(cpi);
129     } else {
130       sf->use_square_partition_only = !frame_is_intra_only(cm);
131     }
132     sf->use_square_only_threshold = BLOCK_4X4;
133 
134     sf->less_rectangular_check  = 1;
135 
136     sf->use_rd_breakout = 1;
137     sf->adaptive_motion_search = 1;
138     sf->mv.auto_mv_step_size = 1;
139     sf->adaptive_rd_thresh = 2;
140     sf->mv.subpel_iters_per_step = 1;
141     sf->mode_skip_start = 10;
142     sf->adaptive_pred_interp_filter = 1;
143 
144     sf->recode_loop = ALLOW_RECODE_KFARFGF;
145     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
146     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
147     sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
148     sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
149   }
150 
151   if (speed >= 2) {
152     sf->tx_size_search_method = frame_is_boosted(cpi) ? USE_FULL_RD
153                                                       : USE_LARGESTALL;
154 
155     // Reference masking is not supported in dynamic scaling mode.
156     sf->reference_masking = cpi->oxcf.resize_mode != RESIZE_DYNAMIC ? 1 : 0;
157 
158     sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
159                                  FLAG_SKIP_INTRA_DIRMISMATCH |
160                                  FLAG_SKIP_INTRA_BESTINTER |
161                                  FLAG_SKIP_COMP_BESTINTRA |
162                                  FLAG_SKIP_INTRA_LOWVAR;
163     sf->disable_filter_search_var_thresh = 100;
164     sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
165     sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
166     sf->allow_partition_search_skip = 1;
167   }
168 
169   if (speed >= 3) {
170     sf->use_square_partition_only = !frame_is_intra_only(cm);
171     sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD
172                                                         : USE_LARGESTALL;
173     sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED;
174     sf->adaptive_pred_interp_filter = 0;
175     sf->adaptive_mode_search = 1;
176     sf->cb_partition_search = !boosted;
177     sf->cb_pred_filter_search = 1;
178     sf->alt_ref_search_fp = 1;
179     sf->recode_loop = ALLOW_RECODE_KFMAXBW;
180     sf->adaptive_rd_thresh = 3;
181     sf->mode_skip_start = 6;
182     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
183     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC;
184     sf->adaptive_interp_filter_search = 1;
185   }
186 
187   if (speed >= 4) {
188     sf->use_square_partition_only = 1;
189     sf->tx_size_search_method = USE_LARGESTALL;
190     sf->mv.search_method = BIGDIA;
191     sf->mv.subpel_search_method = SUBPEL_TREE_PRUNED_MORE;
192     sf->adaptive_rd_thresh = 4;
193     if (cm->frame_type != KEY_FRAME)
194       sf->mode_search_skip_flags |= FLAG_EARLY_TERMINATE;
195     sf->disable_filter_search_var_thresh = 200;
196     sf->use_lp32x32fdct = 1;
197     sf->use_fast_coef_updates = ONE_LOOP_REDUCED;
198     sf->use_fast_coef_costing = 1;
199     sf->motion_field_mode_search = !boosted;
200     sf->partition_search_breakout_rate_thr = 300;
201   }
202 
203   if (speed >= 5) {
204     int i;
205     sf->optimize_coefficients = 0;
206     sf->mv.search_method = HEX;
207     sf->disable_filter_search_var_thresh = 500;
208     for (i = 0; i < TX_SIZES; ++i) {
209       sf->intra_y_mode_mask[i] = INTRA_DC;
210       sf->intra_uv_mode_mask[i] = INTRA_DC;
211     }
212     sf->partition_search_breakout_rate_thr = 500;
213     sf->mv.reduce_first_step_size = 1;
214     sf->simple_model_rd_from_var = 1;
215   }
216 }
217 
set_rt_speed_feature_framesize_dependent(VP9_COMP * cpi,SPEED_FEATURES * sf,int speed)218 static void set_rt_speed_feature_framesize_dependent(VP9_COMP *cpi,
219     SPEED_FEATURES *sf, int speed) {
220   VP9_COMMON *const cm = &cpi->common;
221 
222   if (speed >= 1) {
223     if (VPXMIN(cm->width, cm->height) >= 720) {
224       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
225                                               : DISABLE_ALL_INTER_SPLIT;
226     } else {
227       sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
228     }
229   }
230 
231   if (speed >= 2) {
232     if (VPXMIN(cm->width, cm->height) >= 720) {
233       sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
234                                               : DISABLE_ALL_INTER_SPLIT;
235     } else {
236       sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;
237     }
238   }
239 
240   if (speed >= 5) {
241     if (VPXMIN(cm->width, cm->height) >= 720) {
242       sf->partition_search_breakout_dist_thr = (1 << 25);
243     } else {
244       sf->partition_search_breakout_dist_thr = (1 << 23);
245     }
246   }
247 
248   if (speed >= 7) {
249     sf->encode_breakout_thresh = (VPXMIN(cm->width, cm->height) >= 720) ?
250         800 : 300;
251   }
252 }
253 
set_rt_speed_feature(VP9_COMP * cpi,SPEED_FEATURES * sf,int speed,vp9e_tune_content content)254 static void set_rt_speed_feature(VP9_COMP *cpi, SPEED_FEATURES *sf,
255                                  int speed, vp9e_tune_content content) {
256   VP9_COMMON *const cm = &cpi->common;
257   const int is_keyframe = cm->frame_type == KEY_FRAME;
258   const int frames_since_key = is_keyframe ? 0 : cpi->rc.frames_since_key;
259   sf->static_segmentation = 0;
260   sf->adaptive_rd_thresh = 1;
261   sf->use_fast_coef_costing = 1;
262 
263   if (speed >= 1) {
264     sf->use_square_partition_only = !frame_is_intra_only(cm);
265     sf->less_rectangular_check = 1;
266     sf->tx_size_search_method = frame_is_intra_only(cm) ? USE_FULL_RD
267                                                         : USE_LARGESTALL;
268 
269     sf->use_rd_breakout = 1;
270 
271     sf->adaptive_motion_search = 1;
272     sf->adaptive_pred_interp_filter = 1;
273     sf->mv.auto_mv_step_size = 1;
274     sf->adaptive_rd_thresh = 2;
275     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
276     sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
277     sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
278   }
279 
280   if (speed >= 2) {
281     sf->mode_search_skip_flags = (cm->frame_type == KEY_FRAME) ? 0 :
282                                  FLAG_SKIP_INTRA_DIRMISMATCH |
283                                  FLAG_SKIP_INTRA_BESTINTER |
284                                  FLAG_SKIP_COMP_BESTINTRA |
285                                  FLAG_SKIP_INTRA_LOWVAR;
286     sf->adaptive_pred_interp_filter = 2;
287 
288     // Disable reference masking if using spatial scaling since
289     // pred_mv_sad will not be set (since vp9_mv_pred will not
290     // be called).
291     // TODO(marpan/agrange): Fix this condition.
292     sf->reference_masking = (cpi->oxcf.resize_mode != RESIZE_DYNAMIC &&
293                              cpi->svc.number_spatial_layers == 1) ? 1 : 0;
294 
295     sf->disable_filter_search_var_thresh = 50;
296     sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
297     sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
298     sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
299     sf->adjust_partitioning_from_last_frame = 1;
300     sf->last_partitioning_redo_frequency = 3;
301     sf->use_lp32x32fdct = 1;
302     sf->mode_skip_start = 11;
303     sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
304   }
305 
306   if (speed >= 3) {
307     sf->use_square_partition_only = 1;
308     sf->disable_filter_search_var_thresh = 100;
309     sf->use_uv_intra_rd_estimate = 1;
310     sf->skip_encode_sb = 1;
311     sf->mv.subpel_iters_per_step = 1;
312     sf->adaptive_rd_thresh = 4;
313     sf->mode_skip_start = 6;
314     sf->allow_skip_recode = 0;
315     sf->optimize_coefficients = 0;
316     sf->disable_split_mask = DISABLE_ALL_SPLIT;
317     sf->lpf_pick = LPF_PICK_FROM_Q;
318   }
319 
320   if (speed >= 4) {
321     int i;
322     sf->last_partitioning_redo_frequency = 4;
323     sf->adaptive_rd_thresh = 5;
324     sf->use_fast_coef_costing = 0;
325     sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
326     sf->adjust_partitioning_from_last_frame =
327         cm->last_frame_type != cm->frame_type || (0 ==
328         (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
329     sf->mv.subpel_force_stop = 1;
330     for (i = 0; i < TX_SIZES; i++) {
331       sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
332       sf->intra_uv_mode_mask[i] = INTRA_DC;
333     }
334     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
335     sf->frame_parameter_update = 0;
336     sf->mv.search_method = FAST_HEX;
337 
338     sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
339     sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
340     sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
341     sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
342     sf->max_intra_bsize = BLOCK_32X32;
343     sf->allow_skip_recode = 1;
344   }
345 
346   if (speed >= 5) {
347     sf->use_quant_fp = !is_keyframe;
348     sf->auto_min_max_partition_size = is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX
349                                                   : STRICT_NEIGHBORING_MIN_MAX;
350     sf->default_max_partition_size = BLOCK_32X32;
351     sf->default_min_partition_size = BLOCK_8X8;
352     sf->force_frame_boost = is_keyframe ||
353         (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
354     sf->max_delta_qindex = is_keyframe ? 20 : 15;
355     sf->partition_search_type = REFERENCE_PARTITION;
356     sf->use_nonrd_pick_mode = 1;
357     sf->allow_skip_recode = 0;
358     sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
359     sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
360     sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
361     sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
362     sf->adaptive_rd_thresh = 2;
363     // This feature is only enabled when partition search is disabled.
364     sf->reuse_inter_pred_sby = 1;
365     sf->partition_search_breakout_rate_thr = 200;
366     sf->coeff_prob_appx_step = 4;
367     sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
368     sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
369     sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
370     sf->simple_model_rd_from_var = 1;
371 
372     if (!is_keyframe) {
373       int i;
374       if (content == VP9E_CONTENT_SCREEN) {
375         for (i = 0; i < BLOCK_SIZES; ++i)
376           sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
377       } else {
378         for (i = 0; i < BLOCK_SIZES; ++i)
379           if (i >= BLOCK_16X16)
380             sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
381           else
382             // Use H and V intra mode for block sizes <= 16X16.
383             sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
384       }
385     }
386   }
387 
388   if (speed >= 6) {
389     sf->partition_search_type = VAR_BASED_PARTITION;
390     // Turn on this to use non-RD key frame coding mode.
391     sf->use_nonrd_pick_mode = 1;
392     sf->mv.search_method = NSTEP;
393     sf->mv.reduce_first_step_size = 1;
394     sf->skip_encode_sb = 0;
395   }
396 
397   if (speed >= 7) {
398     sf->adaptive_rd_thresh = 3;
399     sf->mv.search_method = FAST_DIAMOND;
400     sf->mv.fullpel_search_step_param = 10;
401     if (cpi->svc.number_temporal_layers > 2 &&
402         cpi->svc.temporal_layer_id == 0) {
403       sf->mv.search_method = NSTEP;
404       sf->mv.fullpel_search_step_param = 6;
405     }
406   }
407   if (speed >= 8) {
408     sf->adaptive_rd_thresh = 4;
409     sf->mv.subpel_force_stop = 2;
410     sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
411   }
412 }
413 
vp9_set_speed_features_framesize_dependent(VP9_COMP * cpi)414 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
415   SPEED_FEATURES *const sf = &cpi->sf;
416   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
417   RD_OPT *const rd = &cpi->rd;
418   int i;
419 
420   if (oxcf->mode == REALTIME) {
421     set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
422   } else if (oxcf->mode == GOOD) {
423     set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
424   }
425 
426   if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
427     sf->adaptive_pred_interp_filter = 0;
428   }
429 
430   if (cpi->encode_breakout && oxcf->mode == REALTIME &&
431       sf->encode_breakout_thresh > cpi->encode_breakout) {
432     cpi->encode_breakout = sf->encode_breakout_thresh;
433   }
434 
435   // Check for masked out split cases.
436   for (i = 0; i < MAX_REFS; ++i) {
437     if (sf->disable_split_mask & (1 << i)) {
438       rd->thresh_mult_sub8x8[i] = INT_MAX;
439     }
440   }
441 }
442 
vp9_set_speed_features_framesize_independent(VP9_COMP * cpi)443 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
444   SPEED_FEATURES *const sf = &cpi->sf;
445   VP9_COMMON *const cm = &cpi->common;
446   MACROBLOCK *const x = &cpi->td.mb;
447   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
448   int i;
449 
450   // best quality defaults
451   sf->frame_parameter_update = 1;
452   sf->mv.search_method = NSTEP;
453   sf->recode_loop = ALLOW_RECODE;
454   sf->mv.subpel_search_method = SUBPEL_TREE;
455   sf->mv.subpel_iters_per_step = 2;
456   sf->mv.subpel_force_stop = 0;
457   sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
458   sf->mv.reduce_first_step_size = 0;
459   sf->coeff_prob_appx_step = 1;
460   sf->mv.auto_mv_step_size = 0;
461   sf->mv.fullpel_search_step_param = 6;
462   sf->comp_inter_joint_search_thresh = BLOCK_4X4;
463   sf->adaptive_rd_thresh = 0;
464   sf->tx_size_search_method = USE_FULL_RD;
465   sf->use_lp32x32fdct = 0;
466   sf->adaptive_motion_search = 0;
467   sf->adaptive_pred_interp_filter = 0;
468   sf->adaptive_mode_search = 0;
469   sf->cb_pred_filter_search = 0;
470   sf->cb_partition_search = 0;
471   sf->motion_field_mode_search = 0;
472   sf->alt_ref_search_fp = 0;
473   sf->use_quant_fp = 0;
474   sf->reference_masking = 0;
475   sf->partition_search_type = SEARCH_PARTITION;
476   sf->less_rectangular_check = 0;
477   sf->use_square_partition_only = 0;
478   sf->use_square_only_threshold = BLOCK_SIZES;
479   sf->auto_min_max_partition_size = NOT_IN_USE;
480   sf->rd_auto_partition_min_limit = BLOCK_4X4;
481   sf->default_max_partition_size = BLOCK_64X64;
482   sf->default_min_partition_size = BLOCK_4X4;
483   sf->adjust_partitioning_from_last_frame = 0;
484   sf->last_partitioning_redo_frequency = 4;
485   sf->disable_split_mask = 0;
486   sf->mode_search_skip_flags = 0;
487   sf->force_frame_boost = 0;
488   sf->max_delta_qindex = 0;
489   sf->disable_filter_search_var_thresh = 0;
490   sf->adaptive_interp_filter_search = 0;
491   sf->allow_partition_search_skip = 0;
492 
493   for (i = 0; i < TX_SIZES; i++) {
494     sf->intra_y_mode_mask[i] = INTRA_ALL;
495     sf->intra_uv_mode_mask[i] = INTRA_ALL;
496   }
497   sf->use_rd_breakout = 0;
498   sf->skip_encode_sb = 0;
499   sf->use_uv_intra_rd_estimate = 0;
500   sf->allow_skip_recode = 0;
501   sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
502   sf->use_fast_coef_updates = TWO_LOOP;
503   sf->use_fast_coef_costing = 0;
504   sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
505   sf->schedule_mode_search = 0;
506   sf->use_nonrd_pick_mode = 0;
507   for (i = 0; i < BLOCK_SIZES; ++i)
508     sf->inter_mode_mask[i] = INTER_ALL;
509   sf->max_intra_bsize = BLOCK_64X64;
510   sf->reuse_inter_pred_sby = 0;
511   // This setting only takes effect when partition_search_type is set
512   // to FIXED_PARTITION.
513   sf->always_this_block_size = BLOCK_16X16;
514   sf->search_type_check_frequency = 50;
515   sf->encode_breakout_thresh = 0;
516   // Recode loop tolerance %.
517   sf->recode_tolerance = 25;
518   sf->default_interp_filter = SWITCHABLE;
519   sf->tx_size_search_breakout = 0;
520   sf->partition_search_breakout_dist_thr = 0;
521   sf->partition_search_breakout_rate_thr = 0;
522   sf->simple_model_rd_from_var = 0;
523 
524   if (oxcf->mode == REALTIME)
525     set_rt_speed_feature(cpi, sf, oxcf->speed, oxcf->content);
526   else if (oxcf->mode == GOOD)
527     set_good_speed_feature(cpi, cm, sf, oxcf->speed);
528 
529   cpi->full_search_sad = vp9_full_search_sad;
530   cpi->diamond_search_sad = oxcf->mode == BEST ? vp9_full_range_search
531                                                : vp9_diamond_search_sad;
532 
533   // Slow quant, dct and trellis not worthwhile for first pass
534   // so make sure they are always turned off.
535   if (oxcf->pass == 1)
536     sf->optimize_coefficients = 0;
537 
538   // No recode for 1 pass.
539   if (oxcf->pass == 0) {
540     sf->recode_loop = DISALLOW_RECODE;
541     sf->optimize_coefficients = 0;
542   }
543 
544   if (sf->mv.subpel_search_method == SUBPEL_TREE) {
545     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
546   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
547     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
548   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
549     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
550   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
551     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
552   }
553 
554   x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
555 
556   x->min_partition_size = sf->default_min_partition_size;
557   x->max_partition_size = sf->default_max_partition_size;
558 
559   if (!cpi->oxcf.frame_periodic_boost) {
560     sf->max_delta_qindex = 0;
561   }
562 }
563