vp9_onyx_if.c 107 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
void vp9_coef_tree_initialize();
48

Adrian Grange's avatar
Adrian Grange committed
49
50
#define DEFAULT_INTERP_FILTER SWITCHABLE

51
52
#define SHARP_FILTER_QTHRESH 0          /* Q threshold for 8-tap sharp filter */

Jim Bankoski's avatar
Jim Bankoski committed
53
54
55
56
57
58
#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.
59

Paul Wilkins's avatar
Paul Wilkins committed
60
61
62
63
64
// 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

65
#if CONFIG_INTERNAL_STATS
66
extern double vp9_calc_ssim(YV12_BUFFER_CONFIG *source,
67
68
                            YV12_BUFFER_CONFIG *dest, int lumamask,
                            double *weight);
John Koleszar's avatar
John Koleszar committed
69

70

71
extern double vp9_calc_ssimg(YV12_BUFFER_CONFIG *source,
72
73
                             YV12_BUFFER_CONFIG *dest, double *ssim_y,
                             double *ssim_u, double *ssim_v);
John Koleszar's avatar
John Koleszar committed
74
75
76
77


#endif

John Koleszar's avatar
John Koleszar committed
78
// #define OUTPUT_YUV_REC
John Koleszar's avatar
John Koleszar committed
79
80
81
82

#ifdef OUTPUT_YUV_SRC
FILE *yuv_file;
#endif
83
84
85
#ifdef OUTPUT_YUV_REC
FILE *yuv_rec_file;
#endif
John Koleszar's avatar
John Koleszar committed
86
87
88

#if 0
FILE *framepsnr;
Yaowu Xu's avatar
Yaowu Xu committed
89
FILE *kf_list;
John Koleszar's avatar
John Koleszar committed
90
91
92
FILE *keyfile;
#endif

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

95
static INLINE void Scale2Ratio(VPX_SCALING mode, int *hr, int *hs) {
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
  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
121
static void set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv) {
122
  MACROBLOCK *const mb = &cpi->mb;
Deb Mukherjee's avatar
Deb Mukherjee committed
123
  cpi->common.allow_high_precision_mv = allow_high_precision_mv;
124
  if (cpi->common.allow_high_precision_mv) {
125
126
127
128
129
130
131
    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
132

133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
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];
}

149
void vp9_initialize_enc() {
John Koleszar's avatar
John Koleszar committed
150
151
152
  static int init_done = 0;

  if (!init_done) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
153
154
155
    vp9_init_neighbors();
    vp9_init_quant_tables();

156
    vp9_coef_tree_initialize();
157
158
    vp9_tokenize_initialize();
    vp9_init_me_luts();
159
    vp9_rc_init_minq_luts();
160
    vp9_entropy_mv_init();
161
    vp9_entropy_mode_init();
John Koleszar's avatar
John Koleszar committed
162
163
    init_done = 1;
  }
John Koleszar's avatar
John Koleszar committed
164
165
}

166
static void dealloc_compressor_data(VP9_COMP *cpi) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
167
  VP9_COMMON *const cm = &cpi->common;
168
  int i;
Dmitry Kovalev's avatar
Dmitry Kovalev committed
169

John Koleszar's avatar
John Koleszar committed
170
171
  // Delete sementation map
  vpx_free(cpi->segmentation_map);
Dmitry Kovalev's avatar
Dmitry Kovalev committed
172
173
174
  cpi->segmentation_map = NULL;
  vpx_free(cm->last_frame_seg_map);
  cm->last_frame_seg_map = NULL;
John Koleszar's avatar
John Koleszar committed
175
  vpx_free(cpi->coding_context.last_frame_seg_map_copy);
Dmitry Kovalev's avatar
Dmitry Kovalev committed
176
  cpi->coding_context.last_frame_seg_map_copy = NULL;
John Koleszar's avatar
John Koleszar committed
177

178
  vpx_free(cpi->complexity_map);
179
180
181
182
183
  cpi->complexity_map = NULL;

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

John Koleszar's avatar
John Koleszar committed
184
  vpx_free(cpi->active_map);
185
  cpi->active_map = NULL;
John Koleszar's avatar
John Koleszar committed
186

Dmitry Kovalev's avatar
Dmitry Kovalev committed
187
  vp9_free_frame_buffers(cm);
John Koleszar's avatar
John Koleszar committed
188

189
190
191
  vp9_free_frame_buffer(&cpi->last_frame_uf);
  vp9_free_frame_buffer(&cpi->scaled_source);
  vp9_free_frame_buffer(&cpi->alt_ref_buffer);
192
  vp9_lookahead_destroy(cpi->lookahead);
John Koleszar's avatar
John Koleszar committed
193

John Koleszar's avatar
John Koleszar committed
194
195
  vpx_free(cpi->tok);
  cpi->tok = 0;
John Koleszar's avatar
John Koleszar committed
196

John Koleszar's avatar
John Koleszar committed
197
198
199
200
201
  // 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;
202
203
204
205
206
207
208

  for (i = 0; i < cpi->svc.number_spatial_layers; ++i) {
    LAYER_CONTEXT *const lc = &cpi->svc.layer_context[i];
    vpx_free(lc->rc_twopass_stats_in.buf);
    lc->rc_twopass_stats_in.buf = NULL;
    lc->rc_twopass_stats_in.sz = 0;
  }
John Koleszar's avatar
John Koleszar committed
209
210
}

211
// Computes a q delta (in "q index" terms) to get from a starting q value
212
// to a target q value
Deb Mukherjee's avatar
Deb Mukherjee committed
213
int vp9_compute_qdelta(const VP9_COMP *cpi, double qstart, double qtarget) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
214
215
216
  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
217
218
219
  int i;

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

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

  return target_index - start_index;
234
235
}

236
// Computes a q delta (in "q index" terms) to get from a starting q value
237
238
239
// 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) {
240
241
242
243
  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
244
245
  const int base_bits_per_mb = vp9_rc_bits_per_mb(cpi->common.frame_type,
                                            base_q_index, 1.0);
246
247

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

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

  return target_index - base_q_index;
}

261
static void configure_static_seg_features(VP9_COMP *cpi) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
262
  VP9_COMMON *const cm = &cpi->common;
263
  const RATE_CONTROL *const rc = &cpi->rc;
Dmitry Kovalev's avatar
Dmitry Kovalev committed
264
  struct segmentation *const seg = &cm->seg;
265

266
  int high_q = (int)(rc->avg_q > 48.0);
John Koleszar's avatar
John Koleszar committed
267
  int qi_delta;
268

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

John Koleszar's avatar
John Koleszar committed
277
    // Disable segmentation
278
    vp9_disable_segmentation(seg);
Paul Wilkins's avatar
Paul Wilkins committed
279

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

John Koleszar's avatar
John Koleszar committed
290
    // Disable segmentation and individual segment features by default
291
    vp9_disable_segmentation(seg);
292
    vp9_clearall_segfeatures(seg);
Paul Wilkins's avatar
Paul Wilkins committed
293

John Koleszar's avatar
John Koleszar committed
294
295
    // Scan frames from current to arf frame.
    // This function re-enables segmentation if appropriate.
296
    vp9_update_mbgraph_stats(cpi);
Paul Wilkins's avatar
Paul Wilkins committed
297

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

304
305
      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);
306
      vp9_set_segdata(seg, 1, SEG_LVL_ALT_LF, -2);
Paul Wilkins's avatar
Paul Wilkins committed
307

308
309
      vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
      vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_LF);
310

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

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

325
326
        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);
327
        vp9_enable_segfeature(seg, 1, SEG_LVL_ALT_Q);
Paul Wilkins's avatar
Paul Wilkins committed
328

329
330
        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
331

John Koleszar's avatar
John Koleszar committed
332
333
        // Segment coding disabled for compred testing
        if (high_q || (cpi->static_mb_pct == 100)) {
334
335
336
          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
337
        }
338
339
340
341
      } else {
        // Disable segmentation and clear down features if alt ref
        // is not active for this group

342
        vp9_disable_segmentation(seg);
Paul Wilkins's avatar
Paul Wilkins committed
343

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

346
347
        seg->update_map = 0;
        seg->update_data = 0;
Paul Wilkins's avatar
Paul Wilkins committed
348

349
        vp9_clearall_segfeatures(seg);
John Koleszar's avatar
John Koleszar committed
350
      }
351
    } else if (rc->is_src_frame_alt_ref) {
352
353
354
      // 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
355

Paul Wilkins's avatar
Paul Wilkins committed
356
      // Enable ref frame features for segment 0 as well
357
358
      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
359

Paul Wilkins's avatar
Paul Wilkins committed
360
      // All mbs should use ALTREF_FRAME
361
362
363
364
      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
365

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

John Koleszar's avatar
John Koleszar committed
376
      // No updates.. leave things as they are.
377
378
      seg->update_map = 0;
      seg->update_data = 0;
John Koleszar's avatar
John Koleszar committed
379
380
    }
  }
381
382
383
}

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

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

392
393
  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
394
      fprintf(statsfile, "%10d", cpi->segmentation_map[map_index]);
John Koleszar's avatar
John Koleszar committed
395
      map_index++;
396
397
    }
    fprintf(statsfile, "\n");
John Koleszar's avatar
John Koleszar committed
398
399
  }
  fprintf(statsfile, "\n");
400

John Koleszar's avatar
John Koleszar committed
401
  fclose(statsfile);
402
403
}

404
static void update_reference_segmentation_map(VP9_COMP *cpi) {
Ronald S. Bultje's avatar
Ronald S. Bultje committed
405
  VP9_COMMON *const cm = &cpi->common;
Dmitry Kovalev's avatar
Dmitry Kovalev committed
406
407
  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
408
409
  int row, col;

410
  for (row = 0; row < cm->mi_rows; row++) {
Dmitry Kovalev's avatar
Dmitry Kovalev committed
411
412
    MODE_INFO **mi_8x8 = mi_8x8_ptr;
    uint8_t *cache = cache_ptr;
413
414
415
    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;
416
    cache_ptr += cm->mi_cols;
Ronald S. Bultje's avatar
Ronald S. Bultje committed
417
418
  }
}
419
420
421
static int is_slowest_mode(int mode) {
  return (mode == MODE_SECONDPASS_BEST || mode == MODE_BESTQUALITY);
}
Ronald S. Bultje's avatar
Ronald S. Bultje committed
422

423
static void set_rd_speed_thresholds(VP9_COMP *cpi) {
424
425
426
  int i;

  // Set baseline threshold values
427
  for (i = 0; i < MAX_MODES; ++i)
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
  cpi->rd_thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0;

  cpi->rd_thresh_mult[THR_NEARESTMV] = 0;
  cpi->rd_thresh_mult[THR_NEARESTG] = 0;
  cpi->rd_thresh_mult[THR_NEARESTA] = 0;

  cpi->rd_thresh_mult[THR_DC] += 1000;

  cpi->rd_thresh_mult[THR_NEWMV] += 1000;
  cpi->rd_thresh_mult[THR_NEWA] += 1000;
  cpi->rd_thresh_mult[THR_NEWG] += 1000;

  cpi->rd_thresh_mult[THR_NEARMV] += 1000;
  cpi->rd_thresh_mult[THR_NEARA] += 1000;
  cpi->rd_thresh_mult[THR_COMP_NEARESTLA] += 1000;
  cpi->rd_thresh_mult[THR_COMP_NEARESTGA] += 1000;

  cpi->rd_thresh_mult[THR_TM] += 1000;

  cpi->rd_thresh_mult[THR_COMP_NEARLA] += 1500;
  cpi->rd_thresh_mult[THR_COMP_NEWLA] += 2000;
  cpi->rd_thresh_mult[THR_NEARG] += 1000;
  cpi->rd_thresh_mult[THR_COMP_NEARGA] += 1500;
  cpi->rd_thresh_mult[THR_COMP_NEWGA] += 2000;

  cpi->rd_thresh_mult[THR_ZEROMV] += 2000;
  cpi->rd_thresh_mult[THR_ZEROG] += 2000;
  cpi->rd_thresh_mult[THR_ZEROA] += 2000;
  cpi->rd_thresh_mult[THR_COMP_ZEROLA] += 2500;
  cpi->rd_thresh_mult[THR_COMP_ZEROGA] += 2500;

  cpi->rd_thresh_mult[THR_H_PRED] += 2000;
  cpi->rd_thresh_mult[THR_V_PRED] += 2000;
  cpi->rd_thresh_mult[THR_D45_PRED ] += 2500;
  cpi->rd_thresh_mult[THR_D135_PRED] += 2500;
  cpi->rd_thresh_mult[THR_D117_PRED] += 2500;
  cpi->rd_thresh_mult[THR_D153_PRED] += 2500;
  cpi->rd_thresh_mult[THR_D207_PRED] += 2500;
  cpi->rd_thresh_mult[THR_D63_PRED] += 2500;
467

468
469
  /* disable frame modes if flags not set */
  if (!(cpi->ref_frame_flags & VP9_LAST_FLAG)) {
470
471
472
473
    cpi->rd_thresh_mult[THR_NEWMV    ] = INT_MAX;
    cpi->rd_thresh_mult[THR_NEARESTMV] = INT_MAX;
    cpi->rd_thresh_mult[THR_ZEROMV   ] = INT_MAX;
    cpi->rd_thresh_mult[THR_NEARMV   ] = INT_MAX;
474
475
  }
  if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG)) {
476
477
478
479
    cpi->rd_thresh_mult[THR_NEARESTG ] = INT_MAX;
    cpi->rd_thresh_mult[THR_ZEROG    ] = INT_MAX;
    cpi->rd_thresh_mult[THR_NEARG    ] = INT_MAX;
    cpi->rd_thresh_mult[THR_NEWG     ] = INT_MAX;
480
481
  }
  if (!(cpi->ref_frame_flags & VP9_ALT_FLAG)) {
482
483
484
485
    cpi->rd_thresh_mult[THR_NEARESTA ] = INT_MAX;
    cpi->rd_thresh_mult[THR_ZEROA    ] = INT_MAX;
    cpi->rd_thresh_mult[THR_NEARA    ] = INT_MAX;
    cpi->rd_thresh_mult[THR_NEWA     ] = INT_MAX;
486
487
488
489
  }

  if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
      (VP9_LAST_FLAG | VP9_ALT_FLAG)) {
490
491
492
493
    cpi->rd_thresh_mult[THR_COMP_ZEROLA   ] = INT_MAX;
    cpi->rd_thresh_mult[THR_COMP_NEARESTLA] = INT_MAX;
    cpi->rd_thresh_mult[THR_COMP_NEARLA   ] = INT_MAX;
    cpi->rd_thresh_mult[THR_COMP_NEWLA    ] = INT_MAX;
494
495
496
  }
  if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) !=
      (VP9_GOLD_FLAG | VP9_ALT_FLAG)) {
497
498
499
500
    cpi->rd_thresh_mult[THR_COMP_ZEROGA   ] = INT_MAX;
    cpi->rd_thresh_mult[THR_COMP_NEARESTGA] = INT_MAX;
    cpi->rd_thresh_mult[THR_COMP_NEARGA   ] = INT_MAX;
    cpi->rd_thresh_mult[THR_COMP_NEWGA    ] = INT_MAX;
501
  }
502
}
503

504
static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) {
505
  const SPEED_FEATURES *const sf = &cpi->sf;
506
  int i;
507

508
  for (i = 0; i < MAX_REFS; ++i)
509
    cpi->rd_thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode)  ? -500 : 0;
510

511
512
513
514
515
516
  cpi->rd_thresh_mult_sub8x8[THR_LAST] += 2500;
  cpi->rd_thresh_mult_sub8x8[THR_GOLD] += 2500;
  cpi->rd_thresh_mult_sub8x8[THR_ALTR] += 2500;
  cpi->rd_thresh_mult_sub8x8[THR_INTRA] += 2500;
  cpi->rd_thresh_mult_sub8x8[THR_COMP_LA] += 4500;
  cpi->rd_thresh_mult_sub8x8[THR_COMP_GA] += 4500;
517

518
  // Check for masked out split cases.
519
  for (i = 0; i < MAX_REFS; i++)
520
    if (sf->disable_split_mask & (1 << i))
521
      cpi->rd_thresh_mult_sub8x8[i] = INT_MAX;
522

523
524
  // disable mode test if frame flag is not set
  if (!(cpi->ref_frame_flags & VP9_LAST_FLAG))
525
    cpi->rd_thresh_mult_sub8x8[THR_LAST] = INT_MAX;
526
  if (!(cpi->ref_frame_flags & VP9_GOLD_FLAG))
527
    cpi->rd_thresh_mult_sub8x8[THR_GOLD] = INT_MAX;
528
  if (!(cpi->ref_frame_flags & VP9_ALT_FLAG))
529
    cpi->rd_thresh_mult_sub8x8[THR_ALTR] = INT_MAX;
530
531
  if ((cpi->ref_frame_flags & (VP9_LAST_FLAG | VP9_ALT_FLAG)) !=
      (VP9_LAST_FLAG | VP9_ALT_FLAG))
532
    cpi->rd_thresh_mult_sub8x8[THR_COMP_LA] = INT_MAX;
533
534
  if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) !=
      (VP9_GOLD_FLAG | VP9_ALT_FLAG))
535
    cpi->rd_thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX;
536
537
}

538
static void set_speed_features(VP9_COMP *cpi) {
539
#if CONFIG_INTERNAL_STATS
540
  int i;
541
  for (i = 0; i < MAX_MODES; ++i)
John Koleszar's avatar
John Koleszar committed
542
    cpi->mode_chosen_counts[i] = 0;
543
#endif
John Koleszar's avatar
John Koleszar committed
544

545
  vp9_set_speed_features(cpi);
546

547
  // Set rd thresholds based on mode and speed setting
548
549
  set_rd_speed_thresholds(cpi);
  set_rd_speed_thresholds_sub8x8(cpi);
John Koleszar's avatar
John Koleszar committed
550

551
  cpi->mb.fwd_txm4x4 = vp9_fdct4x4;
Yaowu Xu's avatar
Yaowu Xu committed
552
  if (cpi->oxcf.lossless || cpi->mb.e_mbd.lossless) {
553
    cpi->mb.fwd_txm4x4 = vp9_fwht4x4;
John Koleszar's avatar
John Koleszar committed
554
  }
John Koleszar's avatar
John Koleszar committed
555
}
556

557
static void alloc_raw_frame_buffers(VP9_COMP *cpi) {
558
  VP9_COMMON *cm = &cpi->common;
Dmitry Kovalev's avatar
Dmitry Kovalev committed
559
  const VP9_CONFIG *oxcf = &cpi->oxcf;
560

Dmitry Kovalev's avatar
Dmitry Kovalev committed
561
  cpi->lookahead = vp9_lookahead_init(oxcf->width, oxcf->height,
562
                                      cm->subsampling_x, cm->subsampling_y,
Dmitry Kovalev's avatar
Dmitry Kovalev committed
563
                                      oxcf->lag_in_frames);
John Koleszar's avatar
John Koleszar committed
564
  if (!cpi->lookahead)
565
    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
John Koleszar's avatar
John Koleszar committed
566
                       "Failed to allocate lag buffers");
John Koleszar's avatar
John Koleszar committed
567

568
  if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer,
Dmitry Kovalev's avatar
Dmitry Kovalev committed
569
                               oxcf->width, oxcf->height,
570
                               cm->subsampling_x, cm->subsampling_y,
571
                               VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
572
    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
John Koleszar's avatar
John Koleszar committed
573
                       "Failed to allocate altref buffer");
John Koleszar's avatar
John Koleszar committed
574
}
575

576
577
void vp9_alloc_compressor_data(VP9_COMP *cpi) {
  VP9_COMMON *cm = &cpi->common;
John Koleszar's avatar
John Koleszar committed
578

579
  if (vp9_alloc_frame_buffers(cm, cm->width, cm->height))
580
    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
John Koleszar's avatar
John Koleszar committed
581
                       "Failed to allocate frame buffers");
John Koleszar's avatar
John Koleszar committed
582

583
584
585
  if (vp9_alloc_frame_buffer(&cpi->last_frame_uf,
                             cm->width, cm->height,
                             cm->subsampling_x, cm->subsampling_y,
586
                             VP9_ENC_BORDER_IN_PIXELS))
587
    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
John Koleszar's avatar
John Koleszar committed
588
                       "Failed to allocate last frame buffer");
John Koleszar's avatar
John Koleszar committed
589

590
591
592
  if (vp9_alloc_frame_buffer(&cpi->scaled_source,
                             cm->width, cm->height,
                             cm->subsampling_x, cm->subsampling_y,
593
                             VP9_ENC_BORDER_IN_PIXELS))
594
    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
John Koleszar's avatar
John Koleszar committed
595
                       "Failed to allocate scaled source buffer");
John Koleszar's avatar
John Koleszar committed
596

John Koleszar's avatar
John Koleszar committed
597
  vpx_free(cpi->tok);
John Koleszar's avatar
John Koleszar committed
598

John Koleszar's avatar
John Koleszar committed
599
  {
600
    unsigned int tokens = get_token_alloc(cm->mb_rows, cm->mb_cols);
John Koleszar's avatar
John Koleszar committed
601

602
    CHECK_MEM_ERROR(cm, cpi->tok, vpx_calloc(tokens, sizeof(*cpi->tok)));
John Koleszar's avatar
John Koleszar committed
603
  }
John Koleszar's avatar
John Koleszar committed
604

John Koleszar's avatar
John Koleszar committed
605
  vpx_free(cpi->mb_activity_map);
606
  CHECK_MEM_ERROR(cm, cpi->mb_activity_map,
John Koleszar's avatar
John Koleszar committed
607
608
                  vpx_calloc(sizeof(unsigned int),
                             cm->mb_rows * cm->mb_cols));
609

John Koleszar's avatar
John Koleszar committed
610
  vpx_free(cpi->mb_norm_activity_map);
611
  CHECK_MEM_ERROR(cm, cpi->mb_norm_activity_map,
John Koleszar's avatar
John Koleszar committed
612
613
                  vpx_calloc(sizeof(unsigned int),
                             cm->mb_rows * cm->mb_cols));
John Koleszar's avatar
John Koleszar committed
614
615
616
}


617
static void update_frame_size(VP9_COMP *cpi) {
618
619
  VP9_COMMON *const cm = &cpi->common;
  MACROBLOCKD *const xd = &cpi->mb.e_mbd;
620

621
  vp9_update_frame_size(cm);
622

623
  // Update size of buffers local to this frame
624
625
626
  if (vp9_realloc_frame_buffer(&cpi->last_frame_uf,
                               cm->width, cm->height,
                               cm->subsampling_x, cm->subsampling_y,
627
                               VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
628
    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
629
630
                       "Failed to reallocate last frame buffer");

631
632
633
  if (vp9_realloc_frame_buffer(&cpi->scaled_source,
                               cm->width, cm->height,
                               cm->subsampling_x, cm->subsampling_y,
634
                               VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL))
635
    vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
636
                       "Failed to reallocate scaled source buffer");
637
638
639
640
641
642
643
644
645
646

  {
    int y_stride = cpi->scaled_source.y_stride;

    if (cpi->sf.search_method == NSTEP) {
      vp9_init3smotion_compensation(&cpi->mb, y_stride);
    } else if (cpi->sf.search_method == DIAMOND) {
      vp9_init_dsmotion_compensation(&cpi->mb, y_stride);
    }
  }
647
648
649

  {
    int i;
650
651
652
653

    for (i = 0; i < MAX_MB_PLANE; ++i)
      xd->above_context[i] = cm->above_context +
        i * sizeof(*cm->above_context) * 2 * mi_cols_aligned_to_sb(cm->mi_cols);
654
  }
655
656

  xd->above_seg_context = cpi->common.above_seg_context;
657
658
}

Paul Wilkins's avatar
Paul Wilkins committed
659
660
// Table that converts 0-63 Q range values passed in outside to the Qindex
// range used internally.
661
const int q_trans[] = {
John Koleszar's avatar
John Koleszar committed
662
663
664
665
666
667
668
669
  0,    4,   8,  12,  16,  20,  24,  28,
  32,   36,  40,  44,  48,  52,  56,  60,
  64,   68,  72,  76,  80,  84,  88,  92,
  96,  100, 104, 108, 112, 116, 120, 124,
  128, 132, 136, 140, 144, 148, 152, 156,
  160, 164, 168, 172, 176, 180, 184, 188,
  192, 196, 200, 204, 208, 212, 216, 220,
  224, 228, 232, 236, 240, 244, 249, 255,
Paul Wilkins's avatar
Paul Wilkins committed
670
};
John Koleszar's avatar
John Koleszar committed
671

672
int vp9_reverse_trans(int x) {
John Koleszar's avatar
John Koleszar committed
673
  int i;
John Koleszar's avatar
John Koleszar committed
674

John Koleszar's avatar
John Koleszar committed
675
676
677
  for (i = 0; i < 64; i++)
    if (q_trans[i] >= x)
      return i;
John Koleszar's avatar
John Koleszar committed
678

John Koleszar's avatar
John Koleszar committed
679
  return 63;
John Koleszar's avatar
John Koleszar committed
680
};
681

James Zern's avatar
James Zern committed
682
void vp9_new_framerate(VP9_COMP *cpi, double framerate) {
Paul Wilkins's avatar
Paul Wilkins committed
683
  VP9_COMMON *const cm = &cpi->common;
684
685
  RATE_CONTROL *const rc = &cpi->rc;
  VP9_CONFIG *const oxcf = &cpi->oxcf;
686
  int vbr_max_bits;
Paul Wilkins's avatar
Paul Wilkins committed
687

688
  oxcf->framerate = framerate < 0.1 ? 30 : framerate;
Jim Bankoski's avatar
Jim Bankoski committed
689
  cpi->output_framerate = cpi->oxcf.framerate;
690
691
692
693
  rc->av_per_frame_bandwidth = (int)(oxcf->target_bandwidth /
                                         cpi->output_framerate);
  rc->min_frame_bandwidth = (int)(rc->av_per_frame_bandwidth *
                                      oxcf->two_pass_vbrmin_section / 100);
John Koleszar's avatar
John Koleszar committed
694

695

696
  rc->min_frame_bandwidth = MAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS);
697

Paul Wilkins's avatar
Paul Wilkins committed
698
699
700
701
702
703
704
705
  // A maximum bitrate for a frame is defined.
  // The baseline for this aligns with HW implementations that
  // can support decode of 1080P content up to a bitrate of MAX_MB_RATE bits
  // per 16x16 MB (averaged over a frame). However this limit is extended if
  // a very high rate is given on the command line or the the rate cannnot
  // be acheived because of a user specificed max q (e.g. when the user
  // specifies lossless encode.
  //
706
707
708
709
  vbr_max_bits = (int)(((int64_t)rc->av_per_frame_bandwidth *
      oxcf->two_pass_vbrmax_section) / 100);
  rc->max_frame_bandwidth = MAX(MAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P),
                                vbr_max_bits);
Paul Wilkins's avatar
Paul Wilkins committed
710

John Koleszar's avatar
John Koleszar committed
711
  // Set Maximum gf/arf interval
712
  rc->max_gf_interval = 16;
John Koleszar's avatar
John Koleszar committed
713

John Koleszar's avatar
John Koleszar committed
714
  // Extended interval for genuinely static scenes
715
  rc->static_scene_max_gf_interval = cpi->key_frame_frequency >> 1;
John Koleszar's avatar
John Koleszar committed
716

717
  // Special conditions when alt ref frame enabled in lagged compress mode
718
719
720
  if (oxcf->play_alternate && oxcf->lag_in_frames) {
    if (rc->max_gf_interval > oxcf->lag_in_frames - 1)
      rc->max_gf_interval = oxcf->lag_in_frames - 1;
721

722
723
    if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1)
      rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1;
John Koleszar's avatar
John Koleszar committed
724
  }
725

726
727
  if (rc->max_gf_interval > rc->static_scene_max_gf_interval)
    rc->max_gf_interval = rc->static_scene_max_gf_interval;
John Koleszar's avatar
John Koleszar committed
728
729
}

730
int64_t vp9_rescale(int64_t val, int64_t num, int denom) {
John Koleszar's avatar
John Koleszar committed
731
732
733
  int64_t llnum = num;
  int64_t llden = denom;
  int64_t llval = val;
734

Jingning Han's avatar
Jingning Han committed
735
  return (llval * llnum / llden);
736
737
}

Ronald S. Bultje's avatar
Ronald S. Bultje committed
738
739
static void set_tile_limits(VP9_COMP *cpi) {
  VP9_COMMON *const cm = &cpi->common;
740

Dmitry Kovalev's avatar
Dmitry Kovalev committed
741
742
  int min_log2_tile_cols, max_log2_tile_cols;
  vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols);
743

Dmitry Kovalev's avatar
Dmitry Kovalev committed
744
745
746
  cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns,
                             min_log2_tile_cols, max_log2_tile_cols);
  cm->log2_tile_rows = cpi->oxcf.tile_rows;
747
}
748

749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
static void init_rate_control(const VP9_CONFIG *oxcf, int pass,
                              RATE_CONTROL *rc) {
  if (pass == 0 && oxcf->end_usage == USAGE_STREAM_FROM_SERVER) {
    rc->avg_frame_qindex[0] = oxcf->worst_allowed_q;
    rc->avg_frame_qindex[1] = oxcf->worst_allowed_q;
    rc->avg_frame_qindex[2] = oxcf->worst_allowed_q;
  } else {
    rc->avg_frame_qindex[0] = (oxcf->worst_allowed_q +
                                   oxcf->best_allowed_q) / 2;
    rc->avg_frame_qindex[1] = (oxcf->worst_allowed_q +
                                   oxcf->best_allowed_q) / 2;
    rc->avg_frame_qindex[2] = (oxcf->worst_allowed_q +
                                   oxcf->best_allowed_q) / 2;
  }

  rc->last_q[0] = oxcf->best_allowed_q;
  rc->last_q[1] = oxcf->best_allowed_q;
  rc->last_q[2] = oxcf->best_allowed_q;

  rc->buffer_level =    oxcf->starting_buffer_level;
  rc->bits_off_target = oxcf->starting_buffer_level;

  rc->rolling_target_bits      = rc->av_per_frame_bandwidth;
  rc->rolling_actual_bits      = rc->av_per_frame_bandwidth;
  rc->long_rolling_target_bits = rc->av_per_frame_bandwidth;
  rc->long_rolling_actual_bits = rc->av_per_frame_bandwidth;

  rc->total_actual_bits = 0;
  rc->total_target_vs_actual = 0;
}

Dmitry Kovalev's avatar
Dmitry Kovalev committed
780
static void init_config(struct VP9_COMP *cpi, VP9_CONFIG *oxcf) {
781
  VP9_COMMON *const cm = &cpi->common;
782
  int i;
John Koleszar's avatar
John Koleszar committed
783

John Koleszar's avatar
John Koleszar committed
784
  cpi->oxcf = *oxcf;
John Koleszar's avatar
John Koleszar committed
785

786
  cm->version = oxcf->version;
John Koleszar's avatar
John Koleszar committed
787

788
789
  cm->width = oxcf->width;
  cm->height = oxcf->height;
790
791
792
  cm->subsampling_x = 0;
  cm->subsampling_y = 0;
  vp9_alloc_compressor_data(cpi);
793

794
795
796
797
798
799
800
  // Spatial scalability.
  cpi->svc.number_spatial_layers = oxcf->ss_number_layers;
  // Temporal scalability.
  cpi->svc.number_temporal_layers = oxcf->ts_number_layers;

  if (cpi->svc.number_temporal_layers > 1 &&
      cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) {
801
    vp9_init_layer_context(cpi);
802
803
  }

John Koleszar's avatar
John Koleszar committed
804
  // change includes all joint functionality
Dmitry Kovalev's avatar
Dmitry Kovalev committed
805
  vp9_change_config(cpi, oxcf);
John Koleszar's avatar
John Koleszar committed
806

John Koleszar's avatar
John Koleszar committed
807
  cpi->static_mb_pct = 0;
808

809
810
811
812
  cpi->lst_fb_idx = 0;
  cpi->gld_fb_idx = 1;
  cpi->alt_fb_idx = 2;

Ronald S. Bultje's avatar
Ronald S. Bultje committed
813
  set_tile_limits(cpi);
814

815
816
817
  cpi->fixed_divide[0] = 0;
  for (i = 1; i < 512; i++)
    cpi->fixed_divide[i] = 0x80000 / i;
John Koleszar's avatar
John Koleszar committed
818
819
}

820
void vp9_change_config(struct VP9_COMP *cpi, const VP9_CONFIG *oxcf) {
821
  VP9_COMMON *const cm = &cpi->common;
John Koleszar's avatar
John Koleszar committed
822

823
  if (cm->version != oxcf->version)
824
    cm->version = oxcf->version;
John Koleszar's avatar
John Koleszar committed
825

John Koleszar's avatar
John Koleszar committed
826
  cpi->oxcf = *oxcf;
John Koleszar's avatar
John Koleszar committed
827

828
829
830
  if (cpi->oxcf.cpu_used == -6)
    cpi->oxcf.play_alternate = 0;

Dmitry Kovalev's avatar
Dmitry Kovalev committed
831
  switch (cpi->oxcf.mode) {
John Koleszar's avatar
John Koleszar committed
832
      // Real time and one pass deprecated in test code base
Marco Paniconi's avatar
Marco Paniconi committed
833
834
835
836
837
    case MODE_GOODQUALITY:
      cpi->pass = 0;
      cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5);
      break;

838
839
840
841
    case MODE_BESTQUALITY:
      cpi->pass = 0;
      break;

John Koleszar's avatar
John Koleszar committed
842
    case MODE_FIRSTPASS:
John Koleszar's avatar
John Koleszar committed
843
844
      cpi->pass = 1;
      break;
Paul Wilkins's avatar
Paul Wilkins committed
845

John Koleszar's avatar
John Koleszar committed
846
    case MODE_SECONDPASS:
John Koleszar's avatar
John Koleszar committed
847
      cpi->pas