vp9_onyx_if.c 120 KB
Newer Older
John Koleszar's avatar
John Koleszar committed
1
/*
2
 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar's avatar
John Koleszar committed
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
6
 *  that can be found in the LICENSE file in the root of the source
 *  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.
John Koleszar's avatar
John Koleszar committed
9
10
 */

Jim Bankoski's avatar
Jim Bankoski committed
11
12
13
14
15
16
#include <math.h>
#include <stdio.h>
#include <limits.h>

#include "./vpx_config.h"
#include "./vpx_scale_rtcd.h"
17
18
#include "vpx/internal/vpx_psnr.h"
#include "vpx_ports/vpx_timer.h"
John Koleszar's avatar
John Koleszar committed
19

Jim Bankoski's avatar
Jim Bankoski committed
20
#include "vp9/common/vp9_alloccommon.h"
21
#include "vp9/common/vp9_filter.h"
22
#include "vp9/common/vp9_idct.h"
Jim Bankoski's avatar
Jim Bankoski committed
23
24
25
#if CONFIG_VP9_POSTPROC
#include "vp9/common/vp9_postproc.h"
#endif
26
#include "vp9/common/vp9_reconinter.h"
27
#include "vp9/common/vp9_systemdependent.h"
Jim Bankoski's avatar
Jim Bankoski committed
28
#include "vp9/common/vp9_tile_common.h"
29

30
#include "vp9/encoder/vp9_aq_complexity.h"
Marco Paniconi's avatar
Marco Paniconi committed
31
32
#include "vp9/encoder/vp9_aq_cyclicrefresh.h"
#include "vp9/encoder/vp9_aq_variance.h"
33
#include "vp9/encoder/vp9_bitstream.h"
34
#include "vp9/encoder/vp9_encodeframe.h"
35
#include "vp9/encoder/vp9_encodemv.h"
36
#include "vp9/encoder/vp9_firstpass.h"
Jim Bankoski's avatar
Jim Bankoski committed
37
38
39
#include "vp9/encoder/vp9_mbgraph.h"
#include "vp9/encoder/vp9_onyx_int.h"
#include "vp9/encoder/vp9_picklpf.h"
40
#include "vp9/encoder/vp9_ratectrl.h"
41
#include "vp9/encoder/vp9_rdopt.h"
Jim Bankoski's avatar
Jim Bankoski committed
42
#include "vp9/encoder/vp9_segmentation.h"
43
#include "vp9/encoder/vp9_temporal_filter.h"
44
#include "vp9/encoder/vp9_resize.h"
45
#include "vp9/encoder/vp9_svc_layercontext.h"
Paul Wilkins's avatar
Paul Wilkins committed
46

47
48
49
50
51
52
#define ALL_INTRA_MODES 0x3FF
#define INTRA_DC_ONLY 0x01
#define INTRA_DC_TM ((1 << TM_PRED) | (1 << DC_PRED))
#define INTRA_DC_H_V ((1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED))
#define INTRA_DC_TM_H_V (INTRA_DC_TM | (1 << V_PRED) | (1 << H_PRED))

53
void vp9_coef_tree_initialize();
54

Adrian Grange's avatar
Adrian Grange committed
55
56
#define DEFAULT_INTERP_FILTER SWITCHABLE

57
58
#define SHARP_FILTER_QTHRESH 0          /* Q threshold for 8-tap sharp filter */

Jim Bankoski's avatar
Jim Bankoski committed
59
60
61
62
63
64
#define ALTREF_HIGH_PRECISION_MV 1      // Whether to use high precision mv
                                         //  for altref computation.
#define HIGH_PRECISION_MV_QTHRESH 200   // Q threshold for high precision
                                         // mv. Choose a very high value for
                                         // now so that HIGH_PRECISION is always
                                         // chosen.
65

66
67
68
69
70
71
// Masks for partially or completely disabling split mode
#define DISABLE_ALL_SPLIT         0x3F
#define DISABLE_ALL_INTER_SPLIT   0x1F
#define DISABLE_COMPOUND_SPLIT    0x18
#define LAST_AND_INTRA_SPLIT_ONLY 0x1E

Paul Wilkins's avatar
Paul Wilkins committed
72
73
74
75
76
// Max rate target for 1080P and below encodes under normal circumstances
// (1920 * 1080 / (16 * 16)) * MAX_MB_RATE bits per MB
#define MAX_MB_RATE 250
#define MAXRATE_1080P 2025000

77
#if CONFIG_INTERNAL_STATS
78
extern double vp9_calc_ssim(YV12_BUFFER_CONFIG *source,
79
80
                            YV12_BUFFER_CONFIG *dest, int lumamask,
                            double *weight);
John Koleszar's avatar
John Koleszar committed
81

82

83
extern double vp9_calc_ssimg(YV12_BUFFER_CONFIG *source,
84
85
                             YV12_BUFFER_CONFIG *dest, double *ssim_y,
                             double *ssim_u, double *ssim_v);
John Koleszar's avatar
John Koleszar committed
86
87
88
89


#endif

John Koleszar's avatar
John Koleszar committed
90
// #define OUTPUT_YUV_REC
John Koleszar's avatar
John Koleszar committed
91
92
93
94

#ifdef OUTPUT_YUV_SRC
FILE *yuv_file;
#endif
95
96
97
#ifdef OUTPUT_YUV_REC
FILE *yuv_rec_file;
#endif
John Koleszar's avatar
John Koleszar committed
98
99
100

#if 0
FILE *framepsnr;
Yaowu Xu's avatar
Yaowu Xu committed
101
FILE *kf_list;
John Koleszar's avatar
John Koleszar committed
102
103
104
FILE *keyfile;
#endif

Dmitry Kovalev's avatar
Dmitry Kovalev committed
105
void vp9_init_quantizer(VP9_COMP *cpi);
Paul Wilkins's avatar
Paul Wilkins committed
106

107
static INLINE void Scale2Ratio(VPX_SCALING mode, int *hr, int *hs) {
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  switch (mode) {
    case NORMAL:
      *hr = 1;
      *hs = 1;
      break;
    case FOURFIVE:
      *hr = 4;
      *hs = 5;
      break;
    case THREEFIVE:
      *hr = 3;
      *hs = 5;
    break;
    case ONETWO:
      *hr = 1;
      *hs = 2;
    break;
    default:
      *hr = 1;
      *hs = 1;
       assert(0);
      break;
  }
}

Deb Mukherjee's avatar
Deb Mukherjee committed
133
static void set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv) {
134
  MACROBLOCK *const mb = &cpi->mb;
Deb Mukherjee's avatar
Deb Mukherjee committed
135
  cpi->common.allow_high_precision_mv = allow_high_precision_mv;
136
  if (cpi->common.allow_high_precision_mv) {
137
138
139
140
141
142
143
    mb->mvcost = mb->nmvcost_hp;
    mb->mvsadcost = mb->nmvsadcost_hp;
  } else {
    mb->mvcost = mb->nmvcost;
    mb->mvsadcost = mb->nmvsadcost;
  }
}
Paul Wilkins's avatar
Paul Wilkins committed
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
static void setup_key_frame(VP9_COMP *cpi) {
  vp9_setup_past_independence(&cpi->common);

  // All buffers are implicitly updated on key frames.
  cpi->refresh_golden_frame = 1;
  cpi->refresh_alt_ref_frame = 1;
}

static void setup_inter_frame(VP9_COMMON *cm) {
  if (cm->error_resilient_mode || cm->intra_only)
    vp9_setup_past_independence(cm);

  assert(cm->frame_context_idx < FRAME_CONTEXTS);
  cm->fc = cm->frame_contexts[cm->frame_context_idx];
}

161
void vp9_initialize_enc() {
John Koleszar's avatar
John Koleszar committed
162
163
164
  static int init_done = 0;

  if (!init_done) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
165
166
167
    vp9_init_neighbors();
    vp9_init_quant_tables();

168
    vp9_coef_tree_initialize();
169
170
    vp9_tokenize_initialize();
    vp9_init_me_luts();
171
    vp9_rc_init_minq_luts();
172
    vp9_entropy_mv_init();
173
    vp9_entropy_mode_init();
John Koleszar's avatar
John Koleszar committed
174
175
    init_done = 1;
  }
John Koleszar's avatar
John Koleszar committed
176
177
}

178
static void dealloc_compressor_data(VP9_COMP *cpi) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
179
180
  VP9_COMMON *const cm = &cpi->common;

John Koleszar's avatar
John Koleszar committed
181
182
  // Delete sementation map
  vpx_free(cpi->segmentation_map);
Dmitry Kovalev's avatar
Dmitry Kovalev committed
183
184
185
  cpi->segmentation_map = NULL;
  vpx_free(cm->last_frame_seg_map);
  cm->last_frame_seg_map = NULL;
John Koleszar's avatar
John Koleszar committed
186
  vpx_free(cpi->coding_context.last_frame_seg_map_copy);
Dmitry Kovalev's avatar
Dmitry Kovalev committed
187
  cpi->coding_context.last_frame_seg_map_copy = NULL;
John Koleszar's avatar
John Koleszar committed
188

189
  vpx_free(cpi->complexity_map);
190
191
192
193
194
  cpi->complexity_map = NULL;

  vp9_cyclic_refresh_free(cpi->cyclic_refresh);
  cpi->cyclic_refresh = NULL;

John Koleszar's avatar
John Koleszar committed
195
  vpx_free(cpi->active_map);
196
  cpi->active_map = NULL;
John Koleszar's avatar
John Koleszar committed
197

Dmitry Kovalev's avatar
Dmitry Kovalev committed
198
  vp9_free_frame_buffers(cm);
John Koleszar's avatar
John Koleszar committed
199

200
201
202
  vp9_free_frame_buffer(&cpi->last_frame_uf);
  vp9_free_frame_buffer(&cpi->scaled_source);
  vp9_free_frame_buffer(&cpi->alt_ref_buffer);
203
  vp9_lookahead_destroy(cpi->lookahead);
John Koleszar's avatar
John Koleszar committed
204

John Koleszar's avatar
John Koleszar committed
205
206
  vpx_free(cpi->tok);
  cpi->tok = 0;
John Koleszar's avatar
John Koleszar committed
207

John Koleszar's avatar
John Koleszar committed
208
209
210
211
212
  // Activity mask based per mb zbin adjustments
  vpx_free(cpi->mb_activity_map);
  cpi->mb_activity_map = 0;
  vpx_free(cpi->mb_norm_activity_map);
  cpi->mb_norm_activity_map = 0;
John Koleszar's avatar
John Koleszar committed
213
214
}

215
// Computes a q delta (in "q index" terms) to get from a starting q value
216
// to a target q value
Deb Mukherjee's avatar
Deb Mukherjee committed
217
int vp9_compute_qdelta(const VP9_COMP *cpi, double qstart, double qtarget) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
218
219
220
  const RATE_CONTROL *const rc = &cpi->rc;
  int start_index = rc->worst_quality;
  int target_index = rc->worst_quality;
John Koleszar's avatar
John Koleszar committed
221
222
223
  int i;

  // Convert the average q value to an index.
Dmitry Kovalev's avatar
Dmitry Kovalev committed
224
  for (i = rc->best_quality; i < rc->worst_quality; ++i) {
John Koleszar's avatar
John Koleszar committed
225
    start_index = i;
226
    if (vp9_convert_qindex_to_q(i) >= qstart)
John Koleszar's avatar
John Koleszar committed
227
228
229
230
      break;
  }

  // Convert the q target to an index
Dmitry Kovalev's avatar
Dmitry Kovalev committed
231
  for (i = rc->best_quality; i < rc->worst_quality; ++i) {
John Koleszar's avatar
John Koleszar committed
232
    target_index = i;
233
    if (vp9_convert_qindex_to_q(i) >= qtarget)
John Koleszar's avatar
John Koleszar committed
234
235
236
237
      break;
  }

  return target_index - start_index;
238
239
}

240
// Computes a q delta (in "q index" terms) to get from a starting q value
241
242
243
// to a value that should equate to the given rate ratio.
int vp9_compute_qdelta_by_rate(VP9_COMP *cpi, int base_q_index,
                               double rate_target_ratio) {
244
245
246
247
  int i;
  int target_index = cpi->rc.worst_quality;

  // Look up the current projected bits per block for the base index
Dmitry Kovalev's avatar
Dmitry Kovalev committed
248
249
  const int base_bits_per_mb = vp9_rc_bits_per_mb(cpi->common.frame_type,
                                            base_q_index, 1.0);
250
251

  // Find the target bits per mb based on the base value and given ratio.
Dmitry Kovalev's avatar
Dmitry Kovalev committed
252
  const int target_bits_per_mb = (int)(rate_target_ratio * base_bits_per_mb);
253
254

  // Convert the q target to an index
Dmitry Kovalev's avatar
Dmitry Kovalev committed
255
  for (i = cpi->rc.best_quality; i < cpi->rc.worst_quality; ++i) {
256
    target_index = i;
Dmitry Kovalev's avatar
Dmitry Kovalev committed
257
258
    if (vp9_rc_bits_per_mb(cpi->common.frame_type, i, 1.0) <=
            target_bits_per_mb )
259
260
261
262
263
264
      break;
  }

  return target_index - base_q_index;
}

265
static void configure_static_seg_features(VP9_COMP *cpi) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
266
  VP9_COMMON *const cm = &cpi->common;
267
  const RATE_CONTROL *const rc = &cpi->rc;
Dmitry Kovalev's avatar
Dmitry Kovalev committed
268
  struct segmentation *const seg = &cm->seg;
269

270
  int high_q = (int)(rc->avg_q > 48.0);
John Koleszar's avatar
John Koleszar committed
271
  int qi_delta;
272

John Koleszar's avatar
John Koleszar committed
273
274
275
  // Disable and clear down for KF
  if (cm->frame_type == KEY_FRAME) {
    // Clear down the global segmentation map
276
    vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
277
278
    seg->update_map = 0;
    seg->update_data = 0;
John Koleszar's avatar
John Koleszar committed
279
    cpi->static_mb_pct = 0;
280

John Koleszar's avatar
John Koleszar committed
281
    // Disable segmentation
282
    vp9_disable_segmentation(seg);
Paul Wilkins's avatar
Paul Wilkins committed
283

John Koleszar's avatar
John Koleszar committed
284
    // Clear down the segment features.
285
    vp9_clearall_segfeatures(seg);
286
287
  } else if (cpi->refresh_alt_ref_frame) {
    // If this is an alt ref frame
John Koleszar's avatar
John Koleszar committed
288
    // Clear down the global segmentation map
289
    vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
290
291
    seg->update_map = 0;
    seg->update_data = 0;
John Koleszar's avatar
John Koleszar committed
292
    cpi->static_mb_pct = 0;
Paul Wilkins's avatar
Paul Wilkins committed
293

John Koleszar's avatar
John Koleszar committed
294
    // Disable segmentation and individual segment features by default
295
    vp9_disable_segmentation(seg);
296
    vp9_clearall_segfeatures(seg);
Paul Wilkins's avatar
Paul Wilkins committed
297

John Koleszar's avatar
John Koleszar committed
298
299
    // Scan frames from current to arf frame.
    // This function re-enables segmentation if appropriate.
300
    vp9_update_mbgraph_stats(cpi);
Paul Wilkins's avatar
Paul Wilkins committed
301

John Koleszar's avatar
John Koleszar committed
302
303
    // If segmentation was enabled set those features needed for the
    // arf itself.
304
305
306
    if (seg->enabled) {
      seg->update_map = 1;
      seg->update_data = 1;
Paul Wilkins's avatar
Paul Wilkins committed
307

308
309
      qi_delta = vp9_compute_qdelta(cpi, rc->avg_q, rc->avg_q * 0.875);
      vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta - 2);
310
      vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
Paul Wilkins's avatar
Paul Wilkins committed
311

312
313
      vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
      vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
314

John Koleszar's avatar
John Koleszar committed
315
      // Where relevant assume segment data is delta data
316
      seg->abs_delta = SEGMENT_DELTADATA;
317
    }
318
  } else if (seg->enabled) {
319
320
    // All other frames if segmentation has been enabled

John Koleszar's avatar
John Koleszar committed
321
    // First normal frame in a valid gf or alt ref group
322
    if (rc->frames_since_golden == 0) {
Paul Wilkins's avatar
Paul Wilkins committed
323
      // Set up segment features for normal frames in an arf group
324
      if (rc->source_alt_ref_active) {
325
326
327
        seg->update_map = 0;
        seg->update_data = 1;
        seg->abs_delta = SEGMENT_DELTADATA;
Paul Wilkins's avatar
Paul Wilkins committed
328

329
330
        qi_delta = vp9_compute_qdelta(cpi, rc->avg_q, rc->avg_q * 1.125);
        vp9_set_segdata(seg, 1, SEG_LVL_ALT_Q, qi_delta + 2);
331
        vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
Paul Wilkins's avatar
Paul Wilkins committed
332

333
334
        vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
        vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
Paul Wilkins's avatar
Paul Wilkins committed
335

John Koleszar's avatar
John Koleszar committed
336
337
        // Segment coding disabled for compred testing
        if (high_q || (cpi->static_mb_pct == 100)) {
338
339
340
          vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
          vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
          vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP);
John Koleszar's avatar
John Koleszar committed
341
        }
342
343
344
345
      } else {
        // Disable segmentation and clear down features if alt ref
        // is not active for this group

346
        vp9_disable_segmentation(seg);
Paul Wilkins's avatar
Paul Wilkins committed
347

348
        vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols);
Paul Wilkins's avatar
Paul Wilkins committed
349

350
351
        seg->update_map = 0;
        seg->update_data = 0;
Paul Wilkins's avatar
Paul Wilkins committed
352

353
        vp9_clearall_segfeatures(seg);
John Koleszar's avatar
John Koleszar committed
354
      }
355
    } else if (rc->is_src_frame_alt_ref) {
356
357
358
      // Special case where we are coding over the top of a previous
      // alt ref frame.
      // Segment coding disabled for compred testing
John Koleszar's avatar
John Koleszar committed
359

Paul Wilkins's avatar
Paul Wilkins committed
360
      // Enable ref frame features for segment 0 as well
361
362
      vp9_enable_segfeature(seg, 0, SEG_LVL_REF_FRAME);
      vp9_enable_segfeature(seg, 1, SEG_LVL_REF_FRAME);
John Koleszar's avatar
John Koleszar committed
363

Paul Wilkins's avatar
Paul Wilkins committed
364
      // All mbs should use ALTREF_FRAME
365
366
367
368
      vp9_clear_segdata(seg, 0, SEG_LVL_REF_FRAME);
      vp9_set_segdata(seg, 0, SEG_LVL_REF_FRAME, ALTREF_FRAME);
      vp9_clear_segdata(seg, 1, SEG_LVL_REF_FRAME);
      vp9_set_segdata(seg, 1, SEG_LVL_REF_FRAME, ALTREF_FRAME);
John Koleszar's avatar
John Koleszar committed
369

Paul Wilkins's avatar
Paul Wilkins committed
370
      // Skip all MBs if high Q (0,0 mv and skip coeffs)
John Koleszar's avatar
John Koleszar committed
371
      if (high_q) {
372
373
        vp9_enable_segfeature(seg, 0, SEG_LVL_SKIP);
        vp9_enable_segfeature(seg, 1, SEG_LVL_SKIP);
John Koleszar's avatar
John Koleszar committed
374
      }
Adrian Grange's avatar
Adrian Grange committed
375
      // Enable data update
376
      seg->update_data = 1;
377
378
379
    } else {
      // All other frames.

John Koleszar's avatar
John Koleszar committed
380
      // No updates.. leave things as they are.
381
382
      seg->update_map = 0;
      seg->update_data = 0;
John Koleszar's avatar
John Koleszar committed
383
384
    }
  }
385
386
387
}

// DEBUG: Print out the segment id of each MB in the current frame.
388
389
static void print_seg_map(VP9_COMP *cpi) {
  VP9_COMMON *cm = &cpi->common;
John Koleszar's avatar
John Koleszar committed
390
391
  int row, col;
  int map_index = 0;
Dmitry Kovalev's avatar
Dmitry Kovalev committed
392
  FILE *statsfile = fopen("segmap.stt", "a");
393

Dmitry Kovalev's avatar
Dmitry Kovalev committed
394
  fprintf(statsfile, "%10d\n", cm->current_video_frame);
395

396
397
  for (row = 0; row < cpi->common.mi_rows; row++) {
    for (col = 0; col < cpi->common.mi_cols; col++) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
398
      fprintf(statsfile, "%10d", cpi->segmentation_map[map_index]);
John Koleszar's avatar
John Koleszar committed
399
      map_index++;
400
401
    }
    fprintf(statsfile, "\n");
John Koleszar's avatar
John Koleszar committed
402
403
  }
  fprintf(statsfile, "\n");
404

John Koleszar's avatar
John Koleszar committed
405
  fclose(statsfile);
406
407
}

408
static void update_reference_segmentation_map(VP9_COMP *cpi) {
Ronald S. Bultje's avatar
Ronald S. Bultje committed
409
  VP9_COMMON *const cm = &cpi->common;
Dmitry Kovalev's avatar
Dmitry Kovalev committed
410
411
  MODE_INFO **mi_8x8_ptr = cm->mi_grid_visible;
  uint8_t *cache_ptr = cm->last_frame_seg_map;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
412
413
  int row, col;

414
  for (row = 0; row < cm->mi_rows; row++) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
415
416
    MODE_INFO **mi_8x8 = mi_8x8_ptr;
    uint8_t *cache = cache_ptr;
417
418
419
    for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++)
      cache[0] = mi_8x8[0]->mbmi.segment_id;
    mi_8x8_ptr += cm->mode_info_stride;
420
    cache_ptr += cm->mi_cols;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
421
422
  }
}
423
424
425
static int is_slowest_mode(int mode) {
  return (mode == MODE_SECONDPASS_BEST || mode == MODE_BESTQUALITY);
}
Ronald S. Bultje's avatar
Ronald S. Bultje committed
426

427
static void set_rd_speed_thresholds(VP9_COMP *cpi) {
428
429
430
431
  SPEED_FEATURES *sf = &cpi->sf;
  int i;

  // Set baseline threshold values
432
  for (i = 0; i < MAX_MODES; ++i)
433
    sf->thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0;
434
435

  sf->thresh_mult[THR_NEARESTMV] = 0;
436
437
438
  sf->thresh_mult[THR_NEARESTG] = 0;
  sf->thresh_mult[THR_NEARESTA] = 0;

Deb Mukherjee's avatar
Deb Mukherjee committed
439
440
  sf->thresh_mult[THR_DC] += 1000;

Paul Wilkins's avatar
Paul Wilkins committed
441
  sf->thresh_mult[THR_NEWMV] += 1000;
Deb Mukherjee's avatar
Deb Mukherjee committed
442
  sf->thresh_mult[THR_NEWA] += 1000;
Paul Wilkins's avatar
Paul Wilkins committed
443
444
445
  sf->thresh_mult[THR_NEWG] += 1000;

  sf->thresh_mult[THR_NEARMV] += 1000;
Deb Mukherjee's avatar
Deb Mukherjee committed
446
  sf->thresh_mult[THR_NEARA] += 1000;
Paul Wilkins's avatar
Paul Wilkins committed
447
448
  sf->thresh_mult[THR_COMP_NEARESTLA] += 1000;
  sf->thresh_mult[THR_COMP_NEARESTGA] += 1000;
Deb Mukherjee's avatar
Deb Mukherjee committed
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471

  sf->thresh_mult[THR_TM] += 1000;

  sf->thresh_mult[THR_COMP_NEARLA] += 1500;
  sf->thresh_mult[THR_COMP_NEWLA] += 2000;
  sf->thresh_mult[THR_NEARG] += 1000;
  sf->thresh_mult[THR_COMP_NEARGA] += 1500;
  sf->thresh_mult[THR_COMP_NEWGA] += 2000;

  sf->thresh_mult[THR_ZEROMV] += 2000;
  sf->thresh_mult[THR_ZEROG] += 2000;
  sf->thresh_mult[THR_ZEROA] += 2000;
  sf->thresh_mult[THR_COMP_ZEROLA] += 2500;
  sf->thresh_mult[THR_COMP_ZEROGA] += 2500;

  sf->thresh_mult[THR_H_PRED] += 2000;
  sf->thresh_mult[THR_V_PRED] += 2000;
  sf->thresh_mult[THR_D45_PRED ] += 2500;
  sf->thresh_mult[THR_D135_PRED] += 2500;
  sf->thresh_mult[THR_D117_PRED] += 2500;
  sf->thresh_mult[THR_D153_PRED] += 2500;
  sf->thresh_mult[THR_D207_PRED] += 2500;
  sf->thresh_mult[THR_D63_PRED] += 2500;
472

473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
  /* disable frame modes if flags not set */
  if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) {
    sf->thresh_mult[THR_NEWMV    ] = INT_MAX;
    sf->thresh_mult[THR_NEARESTMV] = INT_MAX;
    sf->thresh_mult[THR_ZEROMV   ] = INT_MAX;
    sf->thresh_mult[THR_NEARMV   ] = INT_MAX;
  }
  if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) {
    sf->thresh_mult[THR_NEARESTG ] = INT_MAX;
    sf->thresh_mult[THR_ZEROG    ] = INT_MAX;
    sf->thresh_mult[THR_NEARG    ] = INT_MAX;
    sf->thresh_mult[THR_NEWG     ] = INT_MAX;
  }
  if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) {
    sf->thresh_mult[THR_NEARESTA ] = INT_MAX;
    sf->thresh_mult[THR_ZEROA    ] = INT_MAX;
    sf->thresh_mult[THR_NEARA    ] = INT_MAX;
    sf->thresh_mult[THR_NEWA     ] = INT_MAX;
  }

  if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
      (VP9_LAST_FLAG | VP9_ALT_FLAG)) {
    sf->thresh_mult[THR_COMP_ZEROLA   ] = INT_MAX;
    sf->thresh_mult[THR_COMP_NEARESTLA] = INT_MAX;
    sf->thresh_mult[THR_COMP_NEARLA   ] = INT_MAX;
    sf->thresh_mult[THR_COMP_NEWLA    ] = INT_MAX;
  }
  if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) !=
      (VP9_GOLD_FLAG | VP9_ALT_FLAG)) {
    sf->thresh_mult[THR_COMP_ZEROGA   ] = INT_MAX;
    sf->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX;
    sf->thresh_mult[THR_COMP_NEARGA   ] = INT_MAX;
    sf->thresh_mult[THR_COMP_NEWGA    ] = INT_MAX;
  }
507
}
508

509
static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) {
510
511
  SPEED_FEATURES *sf = &cpi->sf;
  int i;
512

513
  for (i = 0; i < MAX_REFS; ++i)
514
    sf->thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode)  ? -500 : 0;
515
516
517
518
519
520
521
522

  sf->thresh_mult_sub8x8[THR_LAST] += 2500;
  sf->thresh_mult_sub8x8[THR_GOLD] += 2500;
  sf->thresh_mult_sub8x8[THR_ALTR] += 2500;
  sf->thresh_mult_sub8x8[THR_INTRA] += 2500;
  sf->thresh_mult_sub8x8[THR_COMP_LA] += 4500;
  sf->thresh_mult_sub8x8[THR_COMP_GA] += 4500;

523
524
525
526
527
528
  // Check for masked out split cases.
  for (i = 0; i < MAX_REFS; i++) {
    if (sf->disable_split_mask & (1 << i))
      sf->thresh_mult_sub8x8[i] = INT_MAX;
  }

529
530
531
532
533
534
535
536
537
538
539
540
541
  // disable mode test if frame flag is not set
  if (!(cpi->ref_frame_flags & VP9_LAST_FLAG))
    sf->thresh_mult_sub8x8[THR_LAST] = INT_MAX;
  if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG))
    sf->thresh_mult_sub8x8[THR_GOLD] = INT_MAX;
  if (!(cpi->ref_frame_flags & VP9_ALT_FLAG))
    sf->thresh_mult_sub8x8[THR_ALTR] = INT_MAX;
  if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
      (VP9_LAST_FLAG | VP9_ALT_FLAG))
    sf->thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX;
  if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) !=
      (VP9_GOLD_FLAG | VP9_ALT_FLAG))
    sf->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX;
542
543
}

544
545
546
547
548
static void set_good_speed_feature(VP9_COMMON *cm,
                                   SPEED_FEATURES *sf,
                                   int speed) {
  int i;
  sf->adaptive_rd_thresh = 1;
549
  sf->recode_loop = ((speed < 1) ? ALLOW_RECODE : ALLOW_RECODE_KFMAXBW);
550
  sf->allow_skip_recode = 1;
551
552
553
554
555
556
557
558
559
560
561
562
563
  if (speed == 1) {
    sf->use_square_partition_only = !frame_is_intra_only(cm);
    sf->less_rectangular_check  = 1;
    sf->tx_size_search_method = frame_is_intra_only(cm)
      ? USE_FULL_RD : USE_LARGESTALL;

    if (MIN(cm->width, cm->height) >= 720)
      sf->disable_split_mask = cm->show_frame ?
        DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
    else
      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
    sf->use_rd_breakout = 1;
    sf->adaptive_motion_search = 1;
564
    sf->adaptive_pred_interp_filter = 1;
565
566
    sf->auto_mv_step_size = 1;
    sf->adaptive_rd_thresh = 2;
567
    sf->recode_loop = ALLOW_RECODE_KFARFGF;
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
  }
  if (speed == 2) {
    sf->use_square_partition_only = !frame_is_intra_only(cm);
    sf->less_rectangular_check  = 1;
    sf->tx_size_search_method = frame_is_intra_only(cm)
      ? USE_FULL_RD : USE_LARGESTALL;

    if (MIN(cm->width, cm->height) >= 720)
      sf->disable_split_mask = cm->show_frame ?
        DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
    else
      sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;

    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH |
                                 FLAG_SKIP_INTRA_BESTINTER |
                                 FLAG_SKIP_COMP_BESTINTRA |
                                 FLAG_SKIP_INTRA_LOWVAR;
    sf->use_rd_breakout = 1;
    sf->adaptive_motion_search = 1;
590
    sf->adaptive_pred_interp_filter = 2;
591
592
593
594
595
    sf->reference_masking = 1;
    sf->auto_mv_step_size = 1;
    sf->disable_filter_search_var_thresh = 50;
    sf->comp_inter_joint_search_thresh = BLOCK_SIZES;

Yaowu Xu's avatar
Yaowu Xu committed
596
    sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
597
598
599
600
601
    sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION;
    sf->adjust_partitioning_from_last_frame = 1;
    sf->last_partitioning_redo_frequency = 3;

    sf->adaptive_rd_thresh = 2;
602
    sf->recode_loop = ALLOW_RECODE_KFARFGF;
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
    sf->use_lp32x32fdct = 1;
    sf->mode_skip_start = 11;
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
    sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
  }
  if (speed == 3) {
    sf->use_square_partition_only = 1;
    sf->tx_size_search_method = USE_LARGESTALL;

    if (MIN(cm->width, cm->height) >= 720)
      sf->disable_split_mask = DISABLE_ALL_SPLIT;
    else
      sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;

    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH |
      FLAG_SKIP_INTRA_BESTINTER |
      FLAG_SKIP_COMP_BESTINTRA |
      FLAG_SKIP_INTRA_LOWVAR;

    sf->use_rd_breakout = 1;
    sf->adaptive_motion_search = 1;
626
    sf->adaptive_pred_interp_filter = 2;
627
628
629
    sf->reference_masking = 1;
    sf->auto_mv_step_size = 1;

630
    sf->disable_split_var_thresh = 32;
631
632
633
    sf->disable_filter_search_var_thresh = 100;
    sf->comp_inter_joint_search_thresh = BLOCK_SIZES;

Yaowu Xu's avatar
Yaowu Xu committed
634
    sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
635
636
637
638
639
    sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL;
    sf->adjust_partitioning_from_last_frame = 1;
    sf->last_partitioning_redo_frequency = 3;
    sf->use_uv_intra_rd_estimate = 1;
    sf->skip_encode_sb = 1;
640
    sf->allow_skip_recode = 0;
641
642
643
    sf->use_lp32x32fdct = 1;
    sf->subpel_iters_per_step = 1;
    sf->use_fast_coef_updates = 2;
644
    sf->use_fast_coef_costing = 1;
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662

    sf->adaptive_rd_thresh = 4;
    sf->mode_skip_start = 6;
  }
  if (speed == 4) {
    sf->use_square_partition_only = 1;
    sf->tx_size_search_method = USE_LARGESTALL;
    sf->disable_split_mask = DISABLE_ALL_SPLIT;

    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH |
      FLAG_SKIP_INTRA_BESTINTER |
      FLAG_SKIP_COMP_BESTINTRA |
      FLAG_SKIP_COMP_REFMISMATCH |
      FLAG_SKIP_INTRA_LOWVAR |
      FLAG_EARLY_TERMINATE;

    sf->use_rd_breakout = 1;
    sf->adaptive_motion_search = 1;
663
    sf->adaptive_pred_interp_filter = 2;
664
665
666
    sf->reference_masking = 1;
    sf->auto_mv_step_size = 1;

667
    sf->disable_split_var_thresh = 64;
668
669
670
    sf->disable_filter_search_var_thresh = 200;
    sf->comp_inter_joint_search_thresh = BLOCK_SIZES;

Yaowu Xu's avatar
Yaowu Xu committed
671
    sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
672
673
674
675
676
677
    sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL;
    sf->adjust_partitioning_from_last_frame = 1;
    sf->last_partitioning_redo_frequency = 3;

    sf->use_uv_intra_rd_estimate = 1;
    sf->skip_encode_sb = 1;
678
    sf->allow_skip_recode = 0;
679
680
681
    sf->use_lp32x32fdct = 1;
    sf->subpel_iters_per_step = 1;
    sf->use_fast_coef_updates = 2;
682
    sf->use_fast_coef_costing = 1;
683
684
685
686

    sf->adaptive_rd_thresh = 4;
    sf->mode_skip_start = 6;
  }
687
  if (speed >= 5) {
688
    sf->comp_inter_joint_search_thresh = BLOCK_SIZES;
689
    sf->partition_search_type = FIXED_PARTITION;
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
    sf->tx_size_search_method = frame_is_intra_only(cm) ?
      USE_FULL_RD : USE_LARGESTALL;
    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH |
                                 FLAG_SKIP_INTRA_BESTINTER |
                                 FLAG_SKIP_COMP_BESTINTRA |
                                 FLAG_SKIP_COMP_REFMISMATCH |
                                 FLAG_SKIP_INTRA_LOWVAR |
                                 FLAG_EARLY_TERMINATE;
    sf->use_rd_breakout = 1;
    sf->use_lp32x32fdct = 1;
    sf->optimize_coefficients = 0;
    sf->auto_mv_step_size = 1;
    sf->reference_masking = 1;

    sf->disable_split_mask = DISABLE_ALL_SPLIT;
    sf->search_method = HEX;
    sf->subpel_iters_per_step = 1;
    sf->disable_split_var_thresh = 64;
    sf->disable_filter_search_var_thresh = 500;
    for (i = 0; i < TX_SIZES; i++) {
      sf->intra_y_mode_mask[i] = INTRA_DC_ONLY;
      sf->intra_uv_mode_mask[i] = INTRA_DC_ONLY;
    }
    sf->use_fast_coef_updates = 2;
714
    sf->use_fast_coef_costing = 1;
715
716
    sf->adaptive_rd_thresh = 4;
    sf->mode_skip_start = 6;
717
    sf->allow_skip_recode = 1;
718
719
  }
}
720

721
722
723
724
725
static void set_rt_speed_feature(VP9_COMMON *cm,
                                 SPEED_FEATURES *sf,
                                 int speed) {
  sf->static_segmentation = 0;
  sf->adaptive_rd_thresh = 1;
726
  sf->encode_breakout_thresh = 1;
727
  sf->use_fast_coef_costing = 1;
728

Yaowu Xu's avatar
Yaowu Xu committed
729
  if (speed == 1) {
730
731
732
733
734
735
736
    sf->use_square_partition_only = !frame_is_intra_only(cm);
    sf->less_rectangular_check = 1;
    sf->tx_size_search_method =
        frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;

    if (MIN(cm->width, cm->height) >= 720)
      sf->disable_split_mask = cm->show_frame ?
Yaowu Xu's avatar
Yaowu Xu committed
737
        DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
738
739
740
741
742
    else
      sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;

    sf->use_rd_breakout = 1;
    sf->adaptive_motion_search = 1;
743
    sf->adaptive_pred_interp_filter = 1;
744
745
746
747
748
    sf->auto_mv_step_size = 1;
    sf->adaptive_rd_thresh = 2;
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
749
    sf->encode_breakout_thresh = 8;
750
751
752
753
754
755
756
757
758
  }
  if (speed >= 2) {
    sf->use_square_partition_only = !frame_is_intra_only(cm);
    sf->less_rectangular_check = 1;
    sf->tx_size_search_method =
        frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL;

    if (MIN(cm->width, cm->height) >= 720)
      sf->disable_split_mask = cm->show_frame ?
Yaowu Xu's avatar
Yaowu Xu committed
759
        DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT;
760
761
762
763
764
765
766
767
768
    else
      sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY;

    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH
        | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA
        | FLAG_SKIP_INTRA_LOWVAR;

    sf->use_rd_breakout = 1;
    sf->adaptive_motion_search = 1;
769
    sf->adaptive_pred_interp_filter = 2;
770
    sf->auto_mv_step_size = 1;
771
    sf->reference_masking = 1;
772
773
774
775

    sf->disable_filter_search_var_thresh = 50;
    sf->comp_inter_joint_search_thresh = BLOCK_SIZES;

Yaowu Xu's avatar
Yaowu Xu committed
776
    sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX;
777
778
779
780
781
782
783
784
785
786
787
    sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION;
    sf->adjust_partitioning_from_last_frame = 1;
    sf->last_partitioning_redo_frequency = 3;

    sf->adaptive_rd_thresh = 2;
    sf->use_lp32x32fdct = 1;
    sf->mode_skip_start = 11;
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V;
    sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
    sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
    sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
788
    sf->encode_breakout_thresh = 200;
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
  }
  if (speed >= 3) {
    sf->use_square_partition_only = 1;
    if (MIN(cm->width, cm->height) >= 720)
      sf->disable_split_mask = DISABLE_ALL_SPLIT;
    else
      sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;

    sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH
        | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA
        | FLAG_SKIP_INTRA_LOWVAR;

    sf->disable_filter_search_var_thresh = 100;
    sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL;
    sf->use_uv_intra_rd_estimate = 1;
    sf->skip_encode_sb = 1;
    sf->subpel_iters_per_step = 1;
    sf->use_fast_coef_updates = 2;
    sf->adaptive_rd_thresh = 4;
    sf->mode_skip_start = 6;
809
    sf->encode_breakout_thresh = 400;
810
    sf->allow_skip_recode = 0;
811
812
  }
  if (speed >= 4) {
Yaowu Xu's avatar
Yaowu Xu committed
813
    sf->optimize_coefficients = 0;
Yaowu Xu's avatar
Yaowu Xu committed
814
    sf->disable_split_mask = DISABLE_ALL_SPLIT;
815
    sf->lpf_pick = LPF_PICK_FROM_Q;
816
    sf->encode_breakout_thresh = 700;
817
818
819
  }
  if (speed >= 5) {
    int i;
820
    sf->last_partitioning_redo_frequency = 4;
Yaowu Xu's avatar
Yaowu Xu committed
821
    sf->adaptive_rd_thresh = 5;
822
823
    sf->use_fast_coef_costing = 0;
    sf->auto_min_max_partition_size = STRICT_NEIGHBORING_MIN_MAX;
824
    sf->adjust_partitioning_from_last_frame =
825
        cm->last_frame_type != cm->frame_type || (0 ==
826
        (cm->current_video_frame + 1) % sf->last_partitioning_redo_frequency);
Yaowu Xu's avatar
Yaowu Xu committed
827
    sf->subpel_force_stop = 1;
828
    for (i = 0; i < TX_SIZES; i++) {
Yaowu Xu's avatar
Yaowu Xu committed
829
      sf->intra_y_mode_mask[i] = INTRA_DC_H_V;
830
831
      sf->intra_uv_mode_mask[i] = INTRA_DC_ONLY;
    }
832
    sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_ONLY;
833
    sf->frame_parameter_update = 0;
834
    sf->encode_breakout_thresh = 1000;
835
    sf->search_method = FAST_HEX;
836
837
838
839
840
    sf->disable_inter_mode_mask[BLOCK_32X32] = 1 << INTER_OFFSET(ZEROMV);
    sf->disable_inter_mode_mask[BLOCK_32X64] = ~(1 << INTER_OFFSET(NEARESTMV));
    sf->disable_inter_mode_mask[BLOCK_64X32] = ~(1 << INTER_OFFSET(NEARESTMV));
    sf->disable_inter_mode_mask[BLOCK_64X64] = ~(1 << INTER_OFFSET(NEARESTMV));
    sf->max_intra_bsize = BLOCK_32X32;
841
    sf->allow_skip_recode = 1;
842
  }
843
  if (speed >= 6) {
844
845
    sf->max_partition_size = BLOCK_32X32;
    sf->min_partition_size = BLOCK_8X8;
846
847
848
849
850
    sf->partition_check =
        (cm->current_video_frame % sf->last_partitioning_redo_frequency == 1);
    sf->partition_search_type = REFERENCE_PARTITION;
    sf->use_nonrd_pick_mode = 1;
    sf->search_method = FAST_DIAMOND;
851
    sf->allow_skip_recode = 0;
852
853
  }
  if (speed >= 7) {
854
    sf->partition_search_type = VAR_BASED_FIXED_PARTITION;
855
    sf->use_nonrd_pick_mode = 1;
856
    sf->search_method = FAST_DIAMOND;
857
858
859
860
  }
  if (speed >= 8) {
    int i;
    for (i = 0; i < BLOCK_SIZES; ++i)
861
      sf->disable_inter_mode_mask[i] = 14;    // only search NEARESTMV (0)
862
  }
863
864
}

865
void vp9_set_speed_features(VP9_COMP *cpi) {
John Koleszar's avatar
John Koleszar committed
866
  SPEED_FEATURES *sf = &cpi->sf;
867
  VP9_COMMON *cm = &cpi->common;
868
  int speed = cpi->speed;
John Koleszar's avatar
John Koleszar committed
869
  int i;
870

871
872
873
  // Convert negative speed to positive
  if (speed < 0)
    speed = -speed;
John Koleszar's avatar
John Koleszar committed
874

875
#if CONFIG_INTERNAL_STATS
876
  for (i = 0; i < MAX_MODES; ++i)
John Koleszar's avatar
John Koleszar committed
877
    cpi->mode_chosen_counts[i] = 0;
878
#endif
John Koleszar's avatar
John Koleszar committed
879
880

  // best quality defaults
881
  sf->frame_parameter_update = 1;
John Koleszar's avatar
John Koleszar committed
882
  sf->search_method = NSTEP;
883
  sf->recode_loop = ALLOW_RECODE;
884
885
  sf->subpel_search_method = SUBPEL_TREE;
  sf->subpel_iters_per_step = 2;
Yaowu Xu's avatar
Yaowu Xu committed
886
  sf->subpel_force_stop = 0;
887
  sf->optimize_coefficients = !cpi->oxcf.lossless;
888
  sf->reduce_first_step_size = 0;
Paul Wilkins's avatar
Paul Wilkins committed
889
  sf->auto_mv_step_size = 0;
John Koleszar's avatar
John Koleszar committed
890
  sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
891
  sf->comp_inter_joint_search_thresh = BLOCK_4X4;
892
  sf->adaptive_rd_thresh = 0;
Paul Wilkins's avatar
Paul Wilkins committed
893
  sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_OFF;
Deb Mukherjee's avatar
Deb Mukherjee committed
894
  sf->tx_size_search_method = USE_FULL_RD;
895
  sf->use_lp32x32fdct = 0;
Jingning Han's avatar
Jingning Han committed
896
  sf->adaptive_motion_search = 0;
897
  sf->adaptive_pred_interp_filter = 0;
Paul Wilkins's avatar
Paul Wilkins committed
898
  sf->reference_masking = 0;
899
  sf->partition_search_type = SEARCH_PARTITION;
Yaowu Xu's avatar
Yaowu Xu committed
900
  sf->less_rectangular_check = 0;
901
  sf->use_square_partition_only = 0;
Yaowu Xu's avatar
Yaowu Xu committed
902
  sf->auto_min_max_partition_size = NOT_IN_USE;
903
904
  sf->max_partition_size = BLOCK_64X64;
  sf->min_partition_size = BLOCK_4X4;
905
906
  sf->adjust_partitioning_from_last_frame = 0;
  sf->last_partitioning_redo_frequency = 4;
907
  sf->disable_split_mask = 0;
908
  sf->mode_search_skip_flags = 0;
909
  sf->disable_split_var_thresh = 0;
910
  sf->disable_filter_search_var_thresh = 0;
911
912
913
914
  for (i = 0; i < TX_SIZES; i++) {
    sf->intra_y_mode_mask[i] = ALL_INTRA_MODES;
    sf->intra_uv_mode_mask[i] = ALL_INTRA_MODES;
  }
915
  sf->use_rd_breakout = 0;
916
  sf->skip_encode_sb = 0;
917
  sf->use_uv_intra_rd_estimate = 0;
918
  sf->allow_skip_recode = 0;
919
  sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE;
920
  sf->use_fast_coef_updates = 0;
921
  sf->use_fast_coef_costing = 0;
922
  sf->mode_skip_start = MAX_MODES;  // Mode index at which mode skip mask set
923
  sf->use_nonrd_pick_mode = 0;
924
  sf->encode_breakout_thresh = 0;
925
926
  for (i = 0; i < BLOCK_SIZES; ++i)
    sf->disable_inter_mode_mask[i] = 0;
927
  sf->max_intra_bsize = BLOCK_64X64;
928
929
930
  // This setting only takes effect when partition_search_type is set
  // to FIXED_PARTITION.
  sf->always_this_block_size = BLOCK_16X16;
931

932
933
934
  switch (cpi->oxcf.mode) {
    case MODE_BESTQUALITY:
    case MODE_SECONDPASS_BEST:  // This is the best quality mode.
935
      cpi->diamond_search_sad = vp9_full_range_search;
John Koleszar's avatar
John Koleszar committed
936
      break;
937
938
939
    case MODE_FIRSTPASS:
    case MODE_GOODQUALITY:
    case MODE_SECONDPASS:
940
      set_good_speed_feature(cm, sf, speed);
Deb Mukherjee's avatar
Deb Mukherjee committed
941
      break;
942
    case MODE_REALTIME:
943
944
      set_rt_speed_feature(cm, sf, speed);
      break;
John Koleszar's avatar
John Koleszar committed
945
  }; /* switch */
946

947
  // Set rd thresholds based on mode and speed setting
948
949
  set_rd_speed_thresholds(cpi);
  set_rd_speed_thresholds_sub8x8(cpi);
John Koleszar's avatar
John Koleszar committed
950
951
952
953
954
955

  // Slow quant, dct and trellis not worthwhile for first pass
  // so make sure they are always turned off.
  if (cpi->pass == 1) {
    sf->optimize_coefficients = 0;
  }
956

Marco Paniconi's avatar
Marco Paniconi committed
957
958
  // No recode for 1 pass.
  if (cpi->pass == 0) {