]> granicus.if.org Git - libvpx/blob - vp9/encoder/vp9_speed_features.c
vp9-resize: Force reference masking off for external dynamic-resizing.
[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 or for dynamic
307     // resizing (internal or external) since pred_mv_sad will not be set
308     // (since vp9_mv_pred will not be called).
309     // TODO(marpan): Fix this condition to allow reference masking for when
310     // all references have same resolution as source frame.
311     sf->reference_masking = (cpi->external_resize == 0 &&
312                              cpi->oxcf.resize_mode != RESIZE_DYNAMIC &&
313                              cpi->svc.number_spatial_layers == 1) ? 1 : 0;
314
315     sf->disable_filter_search_var_thresh = 50;
316     sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
317     sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
318     sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
319     sf->adjust_partitioning_from_last_frame = 1;
320     sf->last_partitioning_redo_frequency = 3;
321     sf->use_lp32x32fdct = 1;
322     sf->mode_skip_start = 11;
323     sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
324   }
325
326   if (speed >= 3) {
327     sf->use_square_partition_only = 1;
328     sf->disable_filter_search_var_thresh = 100;
329     sf->use_uv_intra_rd_estimate = 1;
330     sf->skip_encode_sb = 1;
331     sf->mv.subpel_iters_per_step = 1;
332     sf->adaptive_rd_thresh = 4;
333     sf->mode_skip_start = 6;
334     sf->allow_skip_recode = 0;
335     sf->optimize_coefficients = 0;
336     sf->disable_split_mask = DISABLE_ALL_SPLIT;
337     sf->lpf_pick = LPF_PICK_FROM_Q;
338   }
339
340   if (speed >= 4) {
341     int i;
342     sf->last_partitioning_redo_frequency = 4;
343     sf->adaptive_rd_thresh = 5;
344     sf->use_fast_coef_costing = 0;
345     sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
346     sf->adjust_partitioning_from_last_frame =
347         cm->last_frame_type != cm->frame_type || (0 ==
348         (frames_since_key + 1) % sf->last_partitioning_redo_frequency);
349     sf->mv.subpel_force_stop = 1;
350     for (i = 0; i < TX_SIZES; i++) {
351       sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
352       sf->intra_uv_mode_mask[i] = INTRA_DC;
353     }
354     sf->intra_y_mode_mask[TX_32X32] = INTRA_DC;
355     sf->frame_parameter_update = 0;
356     sf->mv.search_method = FAST_HEX;
357
358     sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEAR_NEW;
359     sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST;
360     sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST;
361     sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST;
362     sf->max_intra_bsize = BLOCK_32X32;
363     sf->allow_skip_recode = 1;
364   }
365
366   if (speed >= 5) {
367     sf->use_quant_fp = !is_keyframe;
368     sf->auto_min_max_partition_size = is_keyframe ? RELAXED_NEIGHBORING_MIN_MAX
369                                                   : STRICT_NEIGHBORING_MIN_MAX;
370     sf->default_max_partition_size = BLOCK_32X32;
371     sf->default_min_partition_size = BLOCK_8X8;
372     sf->force_frame_boost = is_keyframe ||
373         (frames_since_key % (sf->last_partitioning_redo_frequency << 1) == 1);
374     sf->max_delta_qindex = is_keyframe ? 20 : 15;
375     sf->partition_search_type = REFERENCE_PARTITION;
376     sf->use_nonrd_pick_mode = 1;
377     sf->allow_skip_recode = 0;
378     sf->inter_mode_mask[BLOCK_32X32] = INTER_NEAREST_NEW_ZERO;
379     sf->inter_mode_mask[BLOCK_32X64] = INTER_NEAREST_NEW_ZERO;
380     sf->inter_mode_mask[BLOCK_64X32] = INTER_NEAREST_NEW_ZERO;
381     sf->inter_mode_mask[BLOCK_64X64] = INTER_NEAREST_NEW_ZERO;
382     sf->adaptive_rd_thresh = 2;
383     // This feature is only enabled when partition search is disabled.
384     sf->reuse_inter_pred_sby = 1;
385     sf->partition_search_breakout_rate_thr = 200;
386     sf->coeff_prob_appx_step = 4;
387     sf->use_fast_coef_updates = is_keyframe ? TWO_LOOP : ONE_LOOP_REDUCED;
388     sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH;
389     sf->tx_size_search_method = is_keyframe ? USE_LARGESTALL : USE_TX_8X8;
390     sf->simple_model_rd_from_var = 1;
391
392     if (!is_keyframe) {
393       int i;
394       if (content == VP9E_CONTENT_SCREEN) {
395         for (i = 0; i < BLOCK_SIZES; ++i)
396           sf->intra_y_mode_bsize_mask[i] = INTRA_DC_TM_H_V;
397       } else {
398         for (i = 0; i < BLOCK_SIZES; ++i)
399           if (i > BLOCK_16X16)
400             sf->intra_y_mode_bsize_mask[i] = INTRA_DC;
401           else
402             // Use H and V intra mode for block sizes <= 16X16.
403             sf->intra_y_mode_bsize_mask[i] = INTRA_DC_H_V;
404       }
405     }
406     if (content == VP9E_CONTENT_SCREEN) {
407       sf->short_circuit_flat_blocks = 1;
408     }
409   }
410
411   if (speed >= 6) {
412     sf->partition_search_type = VAR_BASED_PARTITION;
413     // Turn on this to use non-RD key frame coding mode.
414     sf->use_nonrd_pick_mode = 1;
415     sf->mv.search_method = NSTEP;
416     sf->mv.reduce_first_step_size = 1;
417     sf->skip_encode_sb = 0;
418   }
419
420   if (speed >= 7) {
421     sf->adaptive_rd_thresh = 3;
422     sf->mv.search_method = FAST_DIAMOND;
423     sf->mv.fullpel_search_step_param = 10;
424     if (cpi->svc.number_temporal_layers > 2 &&
425         cpi->svc.temporal_layer_id == 0) {
426       sf->mv.search_method = NSTEP;
427       sf->mv.fullpel_search_step_param = 6;
428     }
429   }
430   if (speed >= 8) {
431     sf->adaptive_rd_thresh = 4;
432     sf->mv.subpel_force_stop = 2;
433     sf->lpf_pick = LPF_PICK_MINIMAL_LPF;
434   }
435 }
436
437 void vp9_set_speed_features_framesize_dependent(VP9_COMP *cpi) {
438   SPEED_FEATURES *const sf = &cpi->sf;
439   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
440   RD_OPT *const rd = &cpi->rd;
441   int i;
442
443   if (oxcf->mode == REALTIME) {
444     set_rt_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
445   } else if (oxcf->mode == GOOD) {
446     set_good_speed_feature_framesize_dependent(cpi, sf, oxcf->speed);
447   }
448
449   if (sf->disable_split_mask == DISABLE_ALL_SPLIT) {
450     sf->adaptive_pred_interp_filter = 0;
451   }
452
453   if (cpi->encode_breakout && oxcf->mode == REALTIME &&
454       sf->encode_breakout_thresh > cpi->encode_breakout) {
455     cpi->encode_breakout = sf->encode_breakout_thresh;
456   }
457
458   // Check for masked out split cases.
459   for (i = 0; i < MAX_REFS; ++i) {
460     if (sf->disable_split_mask & (1 << i)) {
461       rd->thresh_mult_sub8x8[i] = INT_MAX;
462     }
463   }
464 }
465
466 void vp9_set_speed_features_framesize_independent(VP9_COMP *cpi) {
467   SPEED_FEATURES *const sf = &cpi->sf;
468   VP9_COMMON *const cm = &cpi->common;
469   MACROBLOCK *const x = &cpi->td.mb;
470   const VP9EncoderConfig *const oxcf = &cpi->oxcf;
471   int i;
472
473   // best quality defaults
474   sf->frame_parameter_update = 1;
475   sf->mv.search_method = NSTEP;
476   sf->recode_loop = ALLOW_RECODE;
477   sf->mv.subpel_search_method = SUBPEL_TREE;
478   sf->mv.subpel_iters_per_step = 2;
479   sf->mv.subpel_force_stop = 0;
480   sf->optimize_coefficients = !is_lossless_requested(&cpi->oxcf);
481   sf->mv.reduce_first_step_size = 0;
482   sf->coeff_prob_appx_step = 1;
483   sf->mv.auto_mv_step_size = 0;
484   sf->mv.fullpel_search_step_param = 6;
485   sf->comp_inter_joint_search_thresh = BLOCK_4X4;
486   sf->tx_size_search_method = USE_FULL_RD;
487   sf->use_lp32x32fdct = 0;
488   sf->adaptive_motion_search = 0;
489   sf->adaptive_pred_interp_filter = 0;
490   sf->adaptive_mode_search = 0;
491   sf->cb_pred_filter_search = 0;
492   sf->cb_partition_search = 0;
493   sf->motion_field_mode_search = 0;
494   sf->alt_ref_search_fp = 0;
495   sf->use_quant_fp = 0;
496   sf->reference_masking = 0;
497   sf->partition_search_type = SEARCH_PARTITION;
498   sf->less_rectangular_check = 0;
499   sf->use_square_partition_only = 0;
500   sf->use_square_only_threshold = BLOCK_SIZES;
501   sf->auto_min_max_partition_size = NOT_IN_USE;
502   sf->rd_auto_partition_min_limit = BLOCK_4X4;
503   sf->default_max_partition_size = BLOCK_64X64;
504   sf->default_min_partition_size = BLOCK_4X4;
505   sf->adjust_partitioning_from_last_frame = 0;
506   sf->last_partitioning_redo_frequency = 4;
507   sf->disable_split_mask = 0;
508   sf->mode_search_skip_flags = 0;
509   sf->force_frame_boost = 0;
510   sf->max_delta_qindex = 0;
511   sf->disable_filter_search_var_thresh = 0;
512   sf->adaptive_interp_filter_search = 0;
513   sf->allow_partition_search_skip = 0;
514
515   for (i = 0; i < TX_SIZES; i++) {
516     sf->intra_y_mode_mask[i] = INTRA_ALL;
517     sf->intra_uv_mode_mask[i] = INTRA_ALL;
518   }
519   sf->use_rd_breakout = 0;
520   sf->skip_encode_sb = 0;
521   sf->use_uv_intra_rd_estimate = 0;
522   sf->allow_skip_recode = 0;
523   sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
524   sf->use_fast_coef_updates = TWO_LOOP;
525   sf->use_fast_coef_costing = 0;
526   sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
527   sf->schedule_mode_search = 0;
528   sf->use_nonrd_pick_mode = 0;
529   for (i = 0; i < BLOCK_SIZES; ++i)
530     sf->inter_mode_mask[i] = INTER_ALL;
531   sf->max_intra_bsize = BLOCK_64X64;
532   sf->reuse_inter_pred_sby = 0;
533   // This setting only takes effect when partition_search_type is set
534   // to FIXED_PARTITION.
535   sf->always_this_block_size = BLOCK_16X16;
536   sf->search_type_check_frequency = 50;
537   sf->encode_breakout_thresh = 0;
538   // Recode loop tolerance %.
539   sf->recode_tolerance = 25;
540   sf->default_interp_filter = SWITCHABLE;
541   sf->simple_model_rd_from_var = 0;
542   sf->short_circuit_flat_blocks = 0;
543
544   // Some speed-up features even for best quality as minimal impact on quality.
545   sf->adaptive_rd_thresh = 1;
546   sf->tx_size_search_breakout = 1;
547   sf->partition_search_breakout_dist_thr = (1 << 19);
548   sf->partition_search_breakout_rate_thr = 80;
549
550   if (oxcf->mode == REALTIME)
551     set_rt_speed_feature(cpi, sf, oxcf->speed, oxcf->content);
552   else if (oxcf->mode == GOOD)
553     set_good_speed_feature(cpi, cm, sf, oxcf->speed);
554
555   cpi->full_search_sad = vp9_full_search_sad;
556   cpi->diamond_search_sad = vp9_diamond_search_sad;
557
558   sf->allow_exhaustive_searches = 1;
559   if (oxcf->mode == BEST) {
560     if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
561       sf->exhaustive_searches_thresh = (1 << 20);
562     else
563       sf->exhaustive_searches_thresh = (1 << 21);
564     sf->max_exaustive_pct = 100;
565     for (i = 0; i < MAX_MESH_STEP; ++i) {
566       sf->mesh_patterns[i].range = best_quality_mesh_pattern[i].range;
567       sf->mesh_patterns[i].interval = best_quality_mesh_pattern[i].interval;
568     }
569   } else {
570     int speed = (oxcf->speed > MAX_MESH_SPEED) ? MAX_MESH_SPEED : oxcf->speed;
571     if (cpi->twopass.fr_content_type == FC_GRAPHICS_ANIMATION)
572       sf->exhaustive_searches_thresh = (1 << 22);
573     else
574       sf->exhaustive_searches_thresh = (1 << 23);
575     sf->max_exaustive_pct = good_quality_max_mesh_pct[speed];
576     if (speed > 0)
577       sf->exhaustive_searches_thresh = sf->exhaustive_searches_thresh << 1;
578
579     for (i = 0; i < MAX_MESH_STEP; ++i) {
580       sf->mesh_patterns[i].range =
581           good_quality_mesh_patterns[speed][i].range;
582       sf->mesh_patterns[i].interval =
583           good_quality_mesh_patterns[speed][i].interval;
584     }
585   }
586
587   // Slow quant, dct and trellis not worthwhile for first pass
588   // so make sure they are always turned off.
589   if (oxcf->pass == 1)
590     sf->optimize_coefficients = 0;
591
592   // No recode for 1 pass.
593   if (oxcf->pass == 0) {
594     sf->recode_loop = DISALLOW_RECODE;
595     sf->optimize_coefficients = 0;
596   }
597
598   if (sf->mv.subpel_search_method == SUBPEL_TREE) {
599     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree;
600   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED) {
601     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned;
602   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_MORE) {
603     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_more;
604   } else if (sf->mv.subpel_search_method == SUBPEL_TREE_PRUNED_EVENMORE) {
605     cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree_pruned_evenmore;
606   }
607
608   x->optimize = sf->optimize_coefficients == 1 && oxcf->pass != 1;
609
610   x->min_partition_size = sf->default_min_partition_size;
611   x->max_partition_size = sf->default_max_partition_size;
612
613   if (!cpi->oxcf.frame_periodic_boost) {
614     sf->max_delta_qindex = 0;
615   }
616 }