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