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