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