onyx_if.c 195 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
11
 */


12
#include "vpx_config.h"
John Koleszar's avatar
John Koleszar committed
13
#include "vp8/common/onyxc_int.h"
John Koleszar's avatar
John Koleszar committed
14
#include "onyx_int.h"
John Koleszar's avatar
John Koleszar committed
15
#include "vp8/common/systemdependent.h"
John Koleszar's avatar
John Koleszar committed
16
#include "quantize.h"
John Koleszar's avatar
John Koleszar committed
17
#include "vp8/common/alloccommon.h"
John Koleszar's avatar
John Koleszar committed
18
19
20
21
#include "mcomp.h"
#include "firstpass.h"
#include "psnr.h"
#include "vpx_scale/vpxscale.h"
John Koleszar's avatar
John Koleszar committed
22
#include "vp8/common/extend.h"
John Koleszar's avatar
John Koleszar committed
23
#include "ratectrl.h"
John Koleszar's avatar
John Koleszar committed
24
#include "vp8/common/quant_common.h"
25
#include "segmentation.h"
John Koleszar's avatar
John Koleszar committed
26
#include "vp8/common/g_common.h"
John Koleszar's avatar
John Koleszar committed
27
#include "vpx_scale/yv12extend.h"
28
#if CONFIG_POSTPROC
John Koleszar's avatar
John Koleszar committed
29
#include "vp8/common/postproc.h"
30
#endif
John Koleszar's avatar
John Koleszar committed
31
#include "vpx_mem/vpx_mem.h"
John Koleszar's avatar
John Koleszar committed
32
33
#include "vp8/common/swapyv12buffer.h"
#include "vp8/common/threading.h"
John Koleszar's avatar
John Koleszar committed
34
#include "vpx_ports/vpx_timer.h"
Johann's avatar
Johann committed
35
#include "temporal_filter.h"
36

37
//#if CONFIG_SEGFEATURES
38
39
40
#include "vp8/common/seg_common.h"
#include "mbgraph.h"

41
42
43
#if ARCH_ARM
#include "vpx_ports/arm.h"
#endif
44

John Koleszar's avatar
John Koleszar committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <math.h>
#include <stdio.h>
#include <limits.h>

#if CONFIG_RUNTIME_CPU_DETECT
#define IF_RTCD(x) (x)
#define RTCD(x) &cpi->common.rtcd.x
#else
#define IF_RTCD(x) NULL
#define RTCD(x) NULL
#endif

extern void vp8cx_pick_filter_level_fast(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi);
extern void vp8cx_set_alt_lf_level(VP8_COMP *cpi, int filt_val);
extern void vp8cx_pick_filter_level(YV12_BUFFER_CONFIG *sd, VP8_COMP *cpi);

extern void vp8_dmachine_specific_config(VP8_COMP *cpi);
extern void vp8_cmachine_specific_config(VP8_COMP *cpi);
extern void vp8_deblock_frame(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *post, int filt_lvl, int low_var_thresh, int flag);
extern void print_parms(VP8_CONFIG *ocf, char *filenam);
extern unsigned int vp8_get_processor_freq();
extern void print_tree_update_probs();
extern void vp8cx_create_encoder_threads(VP8_COMP *cpi);
extern void vp8cx_remove_encoder_threads(VP8_COMP *cpi);
#if HAVE_ARMV7
extern void vp8_yv12_copy_frame_func_neon(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc);
extern void vp8_yv12_copy_src_frame_func_neon(YV12_BUFFER_CONFIG *src_ybc, YV12_BUFFER_CONFIG *dst_ybc);
#endif

int vp8_estimate_entropy_savings(VP8_COMP *cpi);
int vp8_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, const vp8_variance_rtcd_vtable_t *rtcd);

John Koleszar's avatar
John Koleszar committed
77
extern void vp8_temporal_filter_prepare_c(VP8_COMP *cpi, int distance);
John Koleszar's avatar
John Koleszar committed
78

79
static void set_default_lf_deltas(VP8_COMP *cpi);
John Koleszar's avatar
John Koleszar committed
80
81
82

extern const int vp8_gf_interval_table[101];

83
#if CONFIG_INTERNAL_STATS
John Koleszar's avatar
John Koleszar committed
84
85
86
87
88
89
90
#include "math.h"

extern double vp8_calc_ssim
(
    YV12_BUFFER_CONFIG *source,
    YV12_BUFFER_CONFIG *dest,
    int lumamask,
91
92
    double *weight,
    const vp8_variance_rtcd_vtable_t *rtcd
John Koleszar's avatar
John Koleszar committed
93
94
);

95

John Koleszar's avatar
John Koleszar committed
96
97
98
99
100
101
extern double vp8_calc_ssimg
(
    YV12_BUFFER_CONFIG *source,
    YV12_BUFFER_CONFIG *dest,
    double *ssim_y,
    double *ssim_u,
102
103
    double *ssim_v,
    const vp8_variance_rtcd_vtable_t *rtcd
John Koleszar's avatar
John Koleszar committed
104
105
106
107
108
);


#endif

Yaowu Xu's avatar
Yaowu Xu committed
109
//#define OUTPUT_YUV_REC
John Koleszar's avatar
John Koleszar committed
110
111
112
113

#ifdef OUTPUT_YUV_SRC
FILE *yuv_file;
#endif
114
115
116
#ifdef OUTPUT_YUV_REC
FILE *yuv_rec_file;
#endif
John Koleszar's avatar
John Koleszar committed
117
118
119

#if 0
FILE *framepsnr;
Yaowu Xu's avatar
Yaowu Xu committed
120
FILE *kf_list;
John Koleszar's avatar
John Koleszar committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
FILE *keyfile;
#endif

#if 0
extern int skip_true_count;
extern int skip_false_count;
#endif


#ifdef ENTROPY_STATS
extern int intra_mode_stats[10][10][10];
#endif

#ifdef SPEEDSTATS
unsigned int frames_at_speed[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
unsigned int tot_pm = 0;
unsigned int cnt_pm = 0;
unsigned int tot_ef = 0;
unsigned int cnt_ef = 0;
#endif

142
143
144
#if defined(SECTIONBITS_OUTPUT)
extern unsigned __int64 Sectionbits[500];
#endif
John Koleszar's avatar
John Koleszar committed
145
#ifdef MODE_STATS
Yaowu Xu's avatar
Yaowu Xu committed
146
147
148
149
extern INT64 Sectionbits[500];
extern int y_modes[VP8_YMODES]  ;
extern int i8x8_modes[VP8_I8X8_MODES];
extern int uv_modes[VP8_UV_MODES] ;
150
extern int uv_modes_y[VP8_YMODES][VP8_UV_MODES];
151
152
153
154
extern int b_modes[B_MODE_COUNT];
extern int inter_y_modes[MB_MODE_COUNT] ;
extern int inter_uv_modes[VP8_UV_MODES] ;
extern unsigned int inter_b_modes[B_MODE_COUNT];
John Koleszar's avatar
John Koleszar committed
155
156
157
158
159
160
#endif

extern void (*vp8_short_fdct4x4)(short *input, short *output, int pitch);
extern void (*vp8_short_fdct8x4)(short *input, short *output, int pitch);

extern void vp8cx_init_quantizer(VP8_COMP *cpi);
Paul Wilkins's avatar
Paul Wilkins committed
161
162

int vp8cx_base_skip_false_prob[QINDEX_RANGE];
163

164
// Tables relating active max Q to active min Q
165
166
167
168
169
170
171
172
173
174
175
176
177
static int kf_low_motion_minq[QINDEX_RANGE];
static int kf_high_motion_minq[QINDEX_RANGE];
static int gf_low_motion_minq[QINDEX_RANGE];
static int gf_mid_motion_minq[QINDEX_RANGE];
static int gf_high_motion_minq[QINDEX_RANGE];
static int inter_minq[QINDEX_RANGE];

// Functions to compute the active minq lookup table entries based on a
// formulaic approach to facilitate easier adjustment of the Q tables.
// The formulae were derived from computing a 3rd order polynomial best
// fit to the original data (after plotting real maxq vs minq (not q index))
int calculate_minq_index( double maxq,
                          double x3, double x2, double x, double c )
178
{
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    int i;
    double minqtarget;
    double thisq;

    minqtarget = ( (x3 * maxq * maxq * maxq) +
                   (x2 * maxq * maxq) +
                   (x * maxq) +
                   c );

    if ( minqtarget > maxq )
        maxq = maxq;

    for ( i = 0; i < QINDEX_RANGE; i++ )
    {
        thisq = vp8_convert_qindex_to_q(i);
        if ( minqtarget <= vp8_convert_qindex_to_q(i) )
            return i;
    }
197
198
    if ( i == QINDEX_RANGE )
        return QINDEX_RANGE-1;
199
200
}
void init_minq_luts()
201
{
202
203
204
205
206
207
208
    int i;
    double maxq;

    for ( i = 0; i < QINDEX_RANGE; i++ )
    {
        maxq = vp8_convert_qindex_to_q(i);

Paul Wilkins's avatar
Paul Wilkins committed
209

210
        kf_low_motion_minq[i] = calculate_minq_index( maxq,
Paul Wilkins's avatar
Paul Wilkins committed
211
212
213
                                                      0.0000003,
                                                      -0.000015,
                                                      0.074,
214
                                                      0.0 );
Paul Wilkins's avatar
Paul Wilkins committed
215

216
        kf_high_motion_minq[i] = calculate_minq_index( maxq,
Paul Wilkins's avatar
Paul Wilkins committed
217
218
219
                                                       0.00000034,
                                                       -0.000125,
                                                       0.13,
220
221
                                                       0.0 );
        gf_low_motion_minq[i] = calculate_minq_index( maxq,
Paul Wilkins's avatar
Paul Wilkins committed
222
223
224
                                                      0.0000016,
                                                      -0.00078,
                                                      0.315,
225
226
                                                      0.0 );
        gf_mid_motion_minq[i] = calculate_minq_index( maxq,
Paul Wilkins's avatar
Paul Wilkins committed
227
228
229
                                                      0.00000415,
                                                      -0.0017,
                                                      0.425,
230
231
                                                      0.0 );
        gf_high_motion_minq[i] = calculate_minq_index( maxq,
Paul Wilkins's avatar
Paul Wilkins committed
232
233
234
                                                       0.00000725,
                                                       -0.00235,
                                                       0.47,
235
236
237
238
239
240
241
242
243
244
                                                       0.0  );
        inter_minq[i] = calculate_minq_index( maxq,
                                              0.00000271,
                                              -0.00113,
                                              0.697,
                                              0.0  );

    }
}

Paul Wilkins's avatar
Paul Wilkins committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
void init_base_skip_probs()
{
    int i;
    double q;
    int skip_prob;

    for ( i = 0; i < QINDEX_RANGE; i++ )
    {
        q = vp8_convert_qindex_to_q(i);

        // Exponential decay caluclation of baseline skip prob with clamping
        // Based on crude best fit of old table.
        skip_prob = (int)( 564.25 * pow( 2.71828, (-0.012*q) ) );
        if ( skip_prob < 1 )
            skip_prob = 1;
        else if ( skip_prob > 255 )
            skip_prob = 255;

        vp8cx_base_skip_false_prob[i] = skip_prob;
    }
}

John Koleszar's avatar
John Koleszar committed
267
268
269
270
void vp8_initialize()
{
    static int init_done = 0;

271

John Koleszar's avatar
John Koleszar committed
272
273
274
275
276
277
    if (!init_done)
    {
        vp8_scale_machine_specific_config();
        vp8_initialize_common();
        //vp8_dmachine_specific_config();
        vp8_tokenize_initialize();
278
279
280
#if CONFIG_EXTEND_QRANGE
        vp8_init_quant_tables();
#endif
Paul Wilkins's avatar
Paul Wilkins committed
281
        vp8_init_me_luts();
282
        init_minq_luts();
Paul Wilkins's avatar
Paul Wilkins committed
283
        init_base_skip_probs();
John Koleszar's avatar
John Koleszar committed
284
285
286
287
288
289
290
291
292
        init_done = 1;
    }
}
#ifdef PACKET_TESTING
extern FILE *vpxlogc;
#endif

static void setup_features(VP8_COMP *cpi)
{
Paul Wilkins's avatar
Paul Wilkins committed
293
294
    MACROBLOCKD *xd = &cpi->mb.e_mbd;

John Koleszar's avatar
John Koleszar committed
295
    // Set up default state for MB feature flags
296
297
298

    xd->segmentation_enabled = 0;   // Default segmentation disabled

Paul Wilkins's avatar
Paul Wilkins committed
299
300
301
302
    xd->update_mb_segmentation_map = 0;
    xd->update_mb_segmentation_data = 0;
    vpx_memset(xd->mb_segment_tree_probs, 255, sizeof(xd->mb_segment_tree_probs));

303
//#if CONFIG_SEGFEATURES
Paul Wilkins's avatar
Paul Wilkins committed
304
    clearall_segfeatures( xd );
Paul Wilkins's avatar
Paul Wilkins committed
305
306
307
308
309
310
311

    xd->mode_ref_lf_delta_enabled = 0;
    xd->mode_ref_lf_delta_update = 0;
    vpx_memset(xd->ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
    vpx_memset(xd->mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
    vpx_memset(xd->last_ref_lf_deltas, 0, sizeof(xd->ref_lf_deltas));
    vpx_memset(xd->last_mode_lf_deltas, 0, sizeof(xd->mode_lf_deltas));
John Koleszar's avatar
John Koleszar committed
312

313
    set_default_lf_deltas(cpi);
John Koleszar's avatar
John Koleszar committed
314
315
316
317

}


318
static void dealloc_compressor_data(VP8_COMP *cpi)
John Koleszar's avatar
John Koleszar committed
319
{
320
    vpx_free(cpi->tplist);
321
322
    cpi->tplist = NULL;

323
    // Delete last frame MV storage buffers
324
    vpx_free(cpi->lfmv);
325
326
    cpi->lfmv = 0;

327
    vpx_free(cpi->lf_ref_frame_sign_bias);
328
329
    cpi->lf_ref_frame_sign_bias = 0;

330
    vpx_free(cpi->lf_ref_frame);
331
    cpi->lf_ref_frame = 0;
John Koleszar's avatar
John Koleszar committed
332
333

    // Delete sementation map
334
    vpx_free(cpi->segmentation_map);
John Koleszar's avatar
John Koleszar committed
335
    cpi->segmentation_map = 0;
336
337
    vpx_free(cpi->common.last_frame_seg_map);
    cpi->common.last_frame_seg_map = 0;
John Koleszar's avatar
John Koleszar committed
338

339
    vpx_free(cpi->active_map);
John Koleszar's avatar
John Koleszar committed
340
341
342
343
344
345
346
    cpi->active_map = 0;

    vp8_de_alloc_frame_buffers(&cpi->common);

    vp8_yv12_de_alloc_frame_buffer(&cpi->last_frame_uf);
    vp8_yv12_de_alloc_frame_buffer(&cpi->scaled_source);
#if VP8_TEMPORAL_ALT_REF
John Koleszar's avatar
John Koleszar committed
347
    vp8_yv12_de_alloc_frame_buffer(&cpi->alt_ref_buffer);
John Koleszar's avatar
John Koleszar committed
348
#endif
John Koleszar's avatar
John Koleszar committed
349
    vp8_lookahead_destroy(cpi->lookahead);
John Koleszar's avatar
John Koleszar committed
350
351
352
353

    vpx_free(cpi->tok);
    cpi->tok = 0;

354
    // Structure used to monitor GF usage
355
    vpx_free(cpi->gf_active_flags);
356
357
    cpi->gf_active_flags = 0;

358
359
360
361
362
363
    // 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;

364
    vpx_free(cpi->mb.pip);
365
366
    cpi->mb.pip = 0;

367
#if !(CONFIG_REALTIME_ONLY)
368
369
    vpx_free(cpi->twopass.total_stats);
    cpi->twopass.total_stats = 0;
370

371
372
373
    vpx_free(cpi->twopass.total_left_stats);
    cpi->twopass.total_left_stats = 0;

374
375
    vpx_free(cpi->twopass.this_frame_stats);
    cpi->twopass.this_frame_stats = 0;
376
#endif
John Koleszar's avatar
John Koleszar committed
377
378
379
380
381
382
}

static void segmentation_test_function(VP8_PTR ptr)
{
    VP8_COMP *cpi = (VP8_COMP *)(ptr);
    unsigned char *seg_map;
Paul Wilkins's avatar
Paul Wilkins committed
383
    signed char feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
384
385
    MACROBLOCKD *xd = &cpi->mb.e_mbd;

386
    CHECK_MEM_ERROR(seg_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
387

John Koleszar's avatar
John Koleszar committed
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
    // Create a temporary map for segmentation data.

    // MB loop to set local segmentation map
    /*for ( i = 0; i < cpi->common.mb_rows; i++ )
    {
        for ( j = 0; j < cpi->common.mb_cols; j++ )
        {
            //seg_map[(i*cpi->common.mb_cols) + j] = (j % 2) + ((i%2)* 2);
            //if ( j < cpi->common.mb_cols/2 )

            // Segment 1 around the edge else 0
            if ( (i == 0) || (j == 0) || (i == (cpi->common.mb_rows-1)) || (j == (cpi->common.mb_cols-1)) )
                seg_map[(i*cpi->common.mb_cols) + j] = 1;
            //else if ( (i < 2) || (j < 2) || (i > (cpi->common.mb_rows-3)) || (j > (cpi->common.mb_cols-3)) )
            //  seg_map[(i*cpi->common.mb_cols) + j] = 2;
            //else if ( (i < 5) || (j < 5) || (i > (cpi->common.mb_rows-6)) || (j > (cpi->common.mb_cols-6)) )
            //  seg_map[(i*cpi->common.mb_cols) + j] = 3;
            else
                seg_map[(i*cpi->common.mb_cols) + j] = 0;
        }
    }*/

    // Set the segmentation Map
411
    vp8_set_segmentation_map(ptr, seg_map);
John Koleszar's avatar
John Koleszar committed
412
413

    // Activate segmentation.
414
    vp8_enable_segmentation(ptr);
John Koleszar's avatar
John Koleszar committed
415
416

    // Set up the quant segment data
Paul Wilkins's avatar
Paul Wilkins committed
417
418
419
420
    feature_data[SEG_LVL_ALT_Q][0] = 0;
    feature_data[SEG_LVL_ALT_Q][1] = 4;
    feature_data[SEG_LVL_ALT_Q][2] = 0;
    feature_data[SEG_LVL_ALT_Q][3] = 0;
John Koleszar's avatar
John Koleszar committed
421
    // Set up the loop segment data
Paul Wilkins's avatar
Paul Wilkins committed
422
423
424
425
    feature_data[SEG_LVL_ALT_LF][0] = 0;
    feature_data[SEG_LVL_ALT_LF][1] = 0;
    feature_data[SEG_LVL_ALT_LF][2] = 0;
    feature_data[SEG_LVL_ALT_LF][3] = 0;
John Koleszar's avatar
John Koleszar committed
426

427
//#if CONFIG_SEGFEATURES
428
429
430
    // Enable features as required
    enable_segfeature(xd, 1, SEG_LVL_ALT_Q);

John Koleszar's avatar
John Koleszar committed
431
432
    // Initialise the feature data structure
    // SEGMENT_DELTADATA    0, SEGMENT_ABSDATA      1
433
    vp8_set_segment_data(ptr, &feature_data[0][0], SEGMENT_DELTADATA);
John Koleszar's avatar
John Koleszar committed
434
435

    // Delete sementation map
436
    vpx_free(seg_map);
John Koleszar's avatar
John Koleszar committed
437
438
439
440
441

    seg_map = 0;

}

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
467
468
469
470
// Computes a q delta (in "q index" terms) to get from a starting q value
// to a target value
// target q value
static int compute_qdelta( VP8_COMP *cpi, double qstart, double qtarget )
{
    int i;
    int start_index = cpi->worst_quality;
    int target_index = cpi->worst_quality;
    int retval = 0;

    // Convert the average q value to an index.
    for ( i = cpi->best_quality; i < cpi->worst_quality; i++ )
    {
        start_index = i;
        if ( vp8_convert_qindex_to_q(i) >= qstart )
            break;
    }

    // Convert the q target to an index
    for ( i = cpi->best_quality; i < cpi->worst_quality; i++ )
    {
        target_index = i;
        if ( vp8_convert_qindex_to_q(i) >= qtarget )
            break;
    }

    return target_index - start_index;
}

471
//#if CONFIG_SEGFEATURES
472
473
474
static void init_seg_features(VP8_COMP *cpi)
{
    VP8_COMMON *cm = &cpi->common;
475
    MACROBLOCKD *xd = &cpi->mb.e_mbd;
476

477
478
    int high_q = (int)(cpi->avg_q > 32.0);
    int qi_delta;
479

480
    // For now at least dont enable seg features alongside cyclic refresh.
481
482
    if ( cpi->cyclic_refresh_mode_enabled ||
         (cpi->pass != 2) )
483
    {
484
485
486
        vp8_disable_segmentation((VP8_PTR)cpi);
        vpx_memset( cpi->segmentation_map, 0, (cm->mb_rows * cm->mb_cols));
        return;
487
    }
488

Paul Wilkins's avatar
Paul Wilkins committed
489
490
    // Disable and clear down for KF
    if ( cm->frame_type == KEY_FRAME  )
491
492
493
    {
        // Clear down the global segmentation map
        vpx_memset( cpi->segmentation_map, 0, (cm->mb_rows * cm->mb_cols));
494
495
        xd->update_mb_segmentation_map = 0;
        xd->update_mb_segmentation_data = 0;
496
        cpi->static_mb_pct = 0;
497

498
499
        // Disable segmentation
        vp8_disable_segmentation((VP8_PTR)cpi);
Paul Wilkins's avatar
Paul Wilkins committed
500
501
502

        // Clear down the segment features.
        clearall_segfeatures(xd);
503
    }
504

Paul Wilkins's avatar
Paul Wilkins committed
505
506
    // If this is an alt ref frame
    else if ( cm->refresh_alt_ref_frame )
507
    {
Paul Wilkins's avatar
Paul Wilkins committed
508
509
510
511
        // Clear down the global segmentation map
        vpx_memset( cpi->segmentation_map, 0, (cm->mb_rows * cm->mb_cols));
        xd->update_mb_segmentation_map = 0;
        xd->update_mb_segmentation_data = 0;
512
        cpi->static_mb_pct = 0;
Paul Wilkins's avatar
Paul Wilkins committed
513
514
515
516
517
518
519
520
521
522
523
524

        // Disable segmentation and individual segment features by default
        vp8_disable_segmentation((VP8_PTR)cpi);
        clearall_segfeatures(xd);

        // Scan frames from current to arf frame.
        // This function re-enables segmentation if appropriate.
        vp8_update_mbgraph_stats(cpi);

        // If segmentation was enabled set those features needed for the
        // arf itself.
        if ( xd->segmentation_enabled )
525
        {
Paul Wilkins's avatar
Paul Wilkins committed
526
527
528
            xd->update_mb_segmentation_map = 1;
            xd->update_mb_segmentation_data = 1;

529
530
            qi_delta = compute_qdelta( cpi, cpi->avg_q, (cpi->avg_q * 0.875) );
            set_segdata( xd, 1, SEG_LVL_ALT_Q, (qi_delta - 2) );
Paul Wilkins's avatar
Paul Wilkins committed
531
            set_segdata( xd, 1, SEG_LVL_ALT_LF, -2 );
Paul Wilkins's avatar
Paul Wilkins committed
532

533
534
535
536
537
            enable_segfeature(xd, 1, SEG_LVL_ALT_Q);
            enable_segfeature(xd, 1, SEG_LVL_ALT_LF);

            // Where relevant assume segment data is delta data
            xd->mb_segement_abs_delta = SEGMENT_DELTADATA;
Paul Wilkins's avatar
Paul Wilkins committed
538

539
        }
540
    }
Paul Wilkins's avatar
Paul Wilkins committed
541
    // All other frames if segmentation has been enabled
542
    else if ( xd->segmentation_enabled )
543
    {
544
545
546
547
548
549
550
551
552
553
554
555
556
557
        int i;

        // clears prior frame seg lev refs
        for (i = 0; i < MAX_MB_SEGMENTS; i++)
        {
            // only do it if the force drop the background stuff is off
            if(!segfeature_active(xd, i, SEG_LVL_MODE))
            {
                disable_segfeature(xd,i,SEG_LVL_REF_FRAME);
                set_segdata( xd,i, SEG_LVL_REF_FRAME, 0xffffff);
            }
        }


Paul Wilkins's avatar
Paul Wilkins committed
558
559
        // First normal frame in a valid gf or alt ref group
        if ( cpi->common.frames_since_golden == 0 )
560
        {
Paul Wilkins's avatar
Paul Wilkins committed
561
562
            // Set up segment features for normal frames in an af group
            if ( cpi->source_alt_ref_active )
563
            {
Paul Wilkins's avatar
Paul Wilkins committed
564
                xd->update_mb_segmentation_map = 0;
565
                xd->update_mb_segmentation_data = 1;
Paul Wilkins's avatar
Paul Wilkins committed
566
567
                xd->mb_segement_abs_delta = SEGMENT_DELTADATA;

568
569
570
571
                qi_delta = compute_qdelta( cpi, cpi->avg_q,
                                           (cpi->avg_q * 1.125) );
                set_segdata( xd, 1, SEG_LVL_ALT_Q, (qi_delta + 2) );
                set_segdata( xd, 1, SEG_LVL_ALT_Q, 0 );
Paul Wilkins's avatar
Paul Wilkins committed
572
                enable_segfeature(xd, 1, SEG_LVL_ALT_Q);
Paul Wilkins's avatar
Paul Wilkins committed
573
574

                set_segdata( xd, 1, SEG_LVL_ALT_LF, -2 );
Paul Wilkins's avatar
Paul Wilkins committed
575
576
                enable_segfeature(xd, 1, SEG_LVL_ALT_LF);

577
                if ( high_q || (cpi->static_mb_pct == 100) )
Paul Wilkins's avatar
Paul Wilkins committed
578
                {
Paul Wilkins's avatar
Paul Wilkins committed
579
                    set_segref(xd, 1, ALTREF_FRAME);
Paul Wilkins's avatar
Paul Wilkins committed
580
                    enable_segfeature(xd, 1, SEG_LVL_REF_FRAME);
Paul Wilkins's avatar
Paul Wilkins committed
581
582

                    set_segdata( xd, 1, SEG_LVL_MODE, ZEROMV );
Paul Wilkins's avatar
Paul Wilkins committed
583
                    enable_segfeature(xd, 1, SEG_LVL_MODE);
Paul Wilkins's avatar
Paul Wilkins committed
584

Paul Wilkins's avatar
Paul Wilkins committed
585
586
587
588
589
590
591
                    if ( !segfeature_active( xd, 1, SEG_LVL_TRANSFORM ) ||
                         get_seg_tx_type( xd, 1 ) == TX_4X4 )
                    {
                        // EOB segment coding not fixed for 8x8 yet
                        set_segdata( xd, 1, SEG_LVL_EOB, 0 );
                        enable_segfeature(xd, 1, SEG_LVL_EOB);
                    }
Paul Wilkins's avatar
Paul Wilkins committed
592
                }
593
            }
Paul Wilkins's avatar
Paul Wilkins committed
594
595
596

            // Disable segmentation and clear down features if alt ref
            // is not active for this group
597
598
            else
            {
Paul Wilkins's avatar
Paul Wilkins committed
599
600
                vp8_disable_segmentation((VP8_PTR)cpi);

601
602
                vpx_memset( cpi->segmentation_map, 0,
                            (cm->mb_rows * cm->mb_cols));
Paul Wilkins's avatar
Paul Wilkins committed
603
604
605
606
607

                xd->update_mb_segmentation_map = 0;
                xd->update_mb_segmentation_data = 0;

                clearall_segfeatures(xd);
608
609
            }
        }
Paul Wilkins's avatar
Paul Wilkins committed
610
611
612
613
614
615
616
617
618

        // Special case where we are coding over the top of a previous
        // alt ref frame
        else if ( cpi->is_src_frame_alt_ref )
        {
            // Enable mode and ref frame features for segment 0 as well
            enable_segfeature(xd, 0, SEG_LVL_REF_FRAME);
            enable_segfeature(xd, 0, SEG_LVL_MODE);

Paul Wilkins's avatar
Paul Wilkins committed
619
620
621
622
623
            // All mbs should use ALTREF_FRAME, ZEROMV exclusively
            clear_segref(xd, 0);
            set_segref(xd, 0, ALTREF_FRAME);
            clear_segref(xd, 1);
            set_segref(xd, 1, ALTREF_FRAME);
Paul Wilkins's avatar
Paul Wilkins committed
624
625
            set_segdata( xd, 0, SEG_LVL_MODE, ZEROMV );
            set_segdata( xd, 1, SEG_LVL_MODE, ZEROMV );
Paul Wilkins's avatar
Paul Wilkins committed
626

627
628
629
            // Skip all MBs if high Q
            if ( high_q )
            {
Paul Wilkins's avatar
Paul Wilkins committed
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
                // EOB segment coding not fixed for 8x8 yet
                if ( !segfeature_active( xd, 0, SEG_LVL_TRANSFORM ) ||
                     get_seg_tx_type( xd, 0 ) == TX_4X4 )
                {
                    enable_segfeature(xd, 0, SEG_LVL_EOB);
                    set_segdata( xd, 0, SEG_LVL_EOB, 0 );
                }

                // EOB segment coding not fixed for 8x8 yet
                if ( !segfeature_active( xd, 1, SEG_LVL_TRANSFORM ) ||
                     get_seg_tx_type( xd, 1 ) == TX_4X4 )
                {
                    enable_segfeature(xd, 1, SEG_LVL_EOB);
                    set_segdata( xd, 1, SEG_LVL_EOB, 0 );
                }
645
646
            }

Paul Wilkins's avatar
Paul Wilkins committed
647
648
649
650
            // Enable data udpate
            xd->update_mb_segmentation_data = 1;
        }
        // All other frames.
651
652
        else
        {
Paul Wilkins's avatar
Paul Wilkins committed
653
654
            // No updeates.. leave things as they are.
            xd->update_mb_segmentation_map = 0;
655
            xd->update_mb_segmentation_data = 0;
656
657
658

#if CONFIG_T8X8
            {
Paul Wilkins's avatar
Paul Wilkins committed
659
                vp8_disable_segmentation((VP8_PTR)cpi);
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
                clearall_segfeatures(xd);
                vp8_enable_segmentation((VP8_PTR)cpi);
                // 8x8TX test code.
                // This assignment does not necessarily make sense but is
                // just to test the mechanism for now.
                enable_segfeature(xd, 0, SEG_LVL_TRANSFORM);
                set_segdata( xd, 0, SEG_LVL_TRANSFORM, TX_4X4 );
                enable_segfeature(xd, 1, SEG_LVL_TRANSFORM);
                set_segdata( xd, 1, SEG_LVL_TRANSFORM, TX_8X8 );
                /* force every mb to use 8x8 transform for testing*/
                vpx_memset(cpi->segmentation_map, 1,
                    cpi->common.mb_rows * cpi->common.mb_cols);

            }
#endif
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
        }
    }
}

// DEBUG: Print out the segment id of each MB in the current frame.
static void print_seg_map(VP8_COMP *cpi)
{
    VP8_COMMON *cm = & cpi->common;
    int row,col;
    int map_index = 0;
    FILE *statsfile;

    statsfile = fopen("segmap.stt", "a");

    fprintf(statsfile, "%10d\n",
            cm->current_video_frame );

    for ( row = 0; row < cpi->common.mb_rows; row++ )
    {
        for ( col = 0; col < cpi->common.mb_cols; col++ )
        {
            fprintf(statsfile, "%10d",
                    cpi->segmentation_map[map_index]);
            map_index++;
        }
        fprintf(statsfile, "\n");
    }
    fprintf(statsfile, "\n");

    fclose(statsfile);
}

John Koleszar's avatar
John Koleszar committed
707
708
709
710
// A simple function to cyclically refresh the background at a lower Q
static void cyclic_background_refresh(VP8_COMP *cpi, int Q, int lf_adjustment)
{
    unsigned char *seg_map;
Paul Wilkins's avatar
Paul Wilkins committed
711
    signed char feature_data[SEG_LVL_MAX][MAX_MB_SEGMENTS];
John Koleszar's avatar
John Koleszar committed
712
713
714
    int i;
    int block_count = cpi->cyclic_refresh_mode_max_mbs_perframe;
    int mbs_in_frame = cpi->common.mb_rows * cpi->common.mb_cols;
715
    MACROBLOCKD *xd = &cpi->mb.e_mbd;
John Koleszar's avatar
John Koleszar committed
716
717

    // Create a temporary map for segmentation data.
718
    CHECK_MEM_ERROR(seg_map, vpx_calloc((cpi->common.mb_rows * cpi->common.mb_cols), 1));
John Koleszar's avatar
John Koleszar committed
719
720
721
722
723

    cpi->cyclic_refresh_q = Q;

    for (i = Q; i > 0; i--)
    {
Paul Wilkins's avatar
Paul Wilkins committed
724
725
        if ( vp8_bits_per_mb(cpi->common.frame_type, i) >=
             ((vp8_bits_per_mb(cpi->common.frame_type, Q)*(Q + 128)) / 64))
John Koleszar's avatar
John Koleszar committed
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
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
        {
            break;
        }
    }

    cpi->cyclic_refresh_q = i;

    // Only update for inter frames
    if (cpi->common.frame_type != KEY_FRAME)
    {
        // Cycle through the macro_block rows
        // MB loop to set local segmentation map
        for (i = cpi->cyclic_refresh_mode_index; i < mbs_in_frame; i++)
        {
            // If the MB is as a candidate for clean up then mark it for possible boost/refresh (segment 1)
            // The segment id may get reset to 0 later if the MB gets coded anything other than last frame 0,0
            // as only (last frame 0,0) MBs are eligable for refresh : that is to say Mbs likely to be background blocks.
            if (cpi->cyclic_refresh_map[i] == 0)
            {
                seg_map[i] = 1;
            }
            else
            {
                seg_map[i] = 0;

                // Skip blocks that have been refreshed recently anyway.
                if (cpi->cyclic_refresh_map[i] < 0)
                    //cpi->cyclic_refresh_map[i] = cpi->cyclic_refresh_map[i] / 16;
                    cpi->cyclic_refresh_map[i]++;
            }


            if (block_count > 0)
                block_count--;
            else
                break;

        }

        // If we have gone through the frame reset to the start
        cpi->cyclic_refresh_mode_index = i;

        if (cpi->cyclic_refresh_mode_index >= mbs_in_frame)
            cpi->cyclic_refresh_mode_index = 0;
    }

    // Set the segmentation Map
773
    vp8_set_segmentation_map((VP8_PTR)cpi, seg_map);
John Koleszar's avatar
John Koleszar committed
774
775

    // Activate segmentation.
776
    vp8_enable_segmentation((VP8_PTR)cpi);
John Koleszar's avatar
John Koleszar committed
777
778

    // Set up the quant segment data
Paul Wilkins's avatar
Paul Wilkins committed
779
780
781
782
    feature_data[SEG_LVL_ALT_Q][0] = 0;
    feature_data[SEG_LVL_ALT_Q][1] = (cpi->cyclic_refresh_q - Q);
    feature_data[SEG_LVL_ALT_Q][2] = 0;
    feature_data[SEG_LVL_ALT_Q][3] = 0;
John Koleszar's avatar
John Koleszar committed
783
784

    // Set up the loop segment data
Paul Wilkins's avatar
Paul Wilkins committed
785
786
787
788
    feature_data[SEG_LVL_ALT_LF][0] = 0;
    feature_data[SEG_LVL_ALT_LF][1] = lf_adjustment;
    feature_data[SEG_LVL_ALT_LF][2] = 0;
    feature_data[SEG_LVL_ALT_LF][3] = 0;
John Koleszar's avatar
John Koleszar committed
789

790
//#if CONFIG_SEGFEATURES
791
792
793
794
    // Enable the loop and quant changes in the feature mask
    enable_segfeature(xd, 1, SEG_LVL_ALT_Q);
    enable_segfeature(xd, 1, SEG_LVL_ALT_LF);

John Koleszar's avatar
John Koleszar committed
795
796
    // Initialise the feature data structure
    // SEGMENT_DELTADATA    0, SEGMENT_ABSDATA      1
797
    vp8_set_segment_data((VP8_PTR)cpi, &feature_data[0][0], SEGMENT_DELTADATA);
John Koleszar's avatar
John Koleszar committed
798
799
800
801
802
803
804
805

    // Delete sementation map
        vpx_free(seg_map);

    seg_map = 0;

}

806
static void set_default_lf_deltas(VP8_COMP *cpi)
John Koleszar's avatar
John Koleszar committed
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
{
    cpi->mb.e_mbd.mode_ref_lf_delta_enabled = 1;
    cpi->mb.e_mbd.mode_ref_lf_delta_update = 1;

    vpx_memset(cpi->mb.e_mbd.ref_lf_deltas, 0, sizeof(cpi->mb.e_mbd.ref_lf_deltas));
    vpx_memset(cpi->mb.e_mbd.mode_lf_deltas, 0, sizeof(cpi->mb.e_mbd.mode_lf_deltas));

    // Test of ref frame deltas
    cpi->mb.e_mbd.ref_lf_deltas[INTRA_FRAME] = 2;
    cpi->mb.e_mbd.ref_lf_deltas[LAST_FRAME] = 0;
    cpi->mb.e_mbd.ref_lf_deltas[GOLDEN_FRAME] = -2;
    cpi->mb.e_mbd.ref_lf_deltas[ALTREF_FRAME] = -2;

    cpi->mb.e_mbd.mode_lf_deltas[0] = 4;               // BPRED
    cpi->mb.e_mbd.mode_lf_deltas[1] = -2;              // Zero
    cpi->mb.e_mbd.mode_lf_deltas[2] = 2;               // New mv
    cpi->mb.e_mbd.mode_lf_deltas[3] = 4;               // Split mv
}

void vp8_set_speed_features(VP8_COMP *cpi)
{
    SPEED_FEATURES *sf = &cpi->sf;
    int Mode = cpi->compressor_speed;
    int Speed = cpi->Speed;
    int i;
    VP8_COMMON *cm = &cpi->common;
833
    int last_improved_quant = sf->improved_quant;
John Koleszar's avatar
John Koleszar committed
834
835
836
837
838
839
840
841
842
843

    // Initialise default mode frequency sampling variables
    for (i = 0; i < MAX_MODES; i ++)
    {
        cpi->mode_check_freq[i] = 0;
        cpi->mode_test_hit_counts[i] = 0;
        cpi->mode_chosen_counts[i] = 0;
    }

    cpi->mbs_tested_so_far = 0;
844
    cpi->mbs_dual_count = 0;
John Koleszar's avatar
John Koleszar committed
845

846
    // best quality defaults
John Koleszar's avatar
John Koleszar committed
847
848
849
850
851
852
853
854
855
856
    sf->RD = 1;
    sf->search_method = NSTEP;
    sf->improved_quant = 1;
    sf->improved_dct = 1;
    sf->auto_filter = 1;
    sf->recode_loop = 1;
    sf->quarter_pixel_search = 1;
    sf->half_pixel_search = 1;
    sf->iterative_sub_pixel = 1;
    sf->optimize_coefficients = 1;
857
    sf->use_fastquant_for_pick = 0;
858
    sf->no_skip_block4x4_search = 1;
John Koleszar's avatar
John Koleszar committed
859
860
861

    sf->first_step = 0;
    sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
862
    sf->improved_mv_pred = 1;
John Koleszar's avatar
John Koleszar committed
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886

    // default thresholds to 0
    for (i = 0; i < MAX_MODES; i++)
        sf->thresh_mult[i] = 0;

    switch (Mode)
    {
#if !(CONFIG_REALTIME_ONLY)
    case 0: // best quality mode
        sf->thresh_mult[THR_ZEROMV   ] = 0;
        sf->thresh_mult[THR_ZEROG    ] = 0;
        sf->thresh_mult[THR_ZEROA    ] = 0;
        sf->thresh_mult[THR_NEARESTMV] = 0;
        sf->thresh_mult[THR_NEARESTG ] = 0;
        sf->thresh_mult[THR_NEARESTA ] = 0;
        sf->thresh_mult[THR_NEARMV   ] = 0;
        sf->thresh_mult[THR_NEARG    ] = 0;
        sf->thresh_mult[THR_NEARA    ] = 0;

        sf->thresh_mult[THR_DC       ] = 0;

        sf->thresh_mult[THR_V_PRED   ] = 1000;
        sf->thresh_mult[THR_H_PRED   ] = 1000;
        sf->thresh_mult[THR_B_PRED   ] = 2000;
887
        sf->thresh_mult[THR_I8X8_PRED] = 2000;
John Koleszar's avatar
John Koleszar committed
888
889
890
891
892
893
894
895
896
897
        sf->thresh_mult[THR_TM       ] = 1000;

        sf->thresh_mult[THR_NEWMV    ] = 1000;
        sf->thresh_mult[THR_NEWG     ] = 1000;
        sf->thresh_mult[THR_NEWA     ] = 1000;

        sf->thresh_mult[THR_SPLITMV  ] = 2500;
        sf->thresh_mult[THR_SPLITG   ] = 5000;
        sf->thresh_mult[THR_SPLITA   ] = 5000;

898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
#if CONFIG_DUALPRED
        sf->thresh_mult[THR_DUAL_ZEROLG   ] = 0;
        sf->thresh_mult[THR_DUAL_NEARESTLG] = 0;
        sf->thresh_mult[THR_DUAL_NEARLG   ] = 0;
        sf->thresh_mult[THR_DUAL_ZEROLA   ] = 0;
        sf->thresh_mult[THR_DUAL_NEARESTLA] = 0;
        sf->thresh_mult[THR_DUAL_NEARLA   ] = 0;
        sf->thresh_mult[THR_DUAL_ZEROGA   ] = 0;
        sf->thresh_mult[THR_DUAL_NEARESTGA] = 0;
        sf->thresh_mult[THR_DUAL_NEARGA   ] = 0;

        sf->thresh_mult[THR_DUAL_NEWLG    ] = 1000;
        sf->thresh_mult[THR_DUAL_NEWLA    ] = 1000;
        sf->thresh_mult[THR_DUAL_NEWGA    ] = 1000;
#endif /* CONFIG_DUALPRED */
John Koleszar's avatar
John Koleszar committed
913
914
915
916
917
918
919
920
921
922
923
924
925

        sf->first_step = 0;
        sf->max_step_search_steps = MAX_MVSEARCH_STEPS;
        break;
    case 1:
    case 3:
        sf->thresh_mult[THR_NEARESTMV] = 0;
        sf->thresh_mult[THR_ZEROMV   ] = 0;
        sf->thresh_mult[THR_DC       ] = 0;
        sf->thresh_mult[THR_NEARMV   ] = 0;
        sf->thresh_mult[THR_V_PRED   ] = 1000;
        sf->thresh_mult[THR_H_PRED   ] = 1000;
        sf->thresh_mult[THR_B_PRED   ] = 2500;
926
        sf->thresh_mult[THR_I8X8_PRED] = 2500;
John Koleszar's avatar
John Koleszar committed
927
928
929
930
931
932
933
934
935
936
        sf->thresh_mult[THR_TM       ] = 1000;

        sf->thresh_mult[THR_NEARESTG ] = 1000;
        sf->thresh_mult[THR_NEARESTA ] = 1000;

        sf->thresh_mult[THR_ZEROG    ] = 1000;
        sf->thresh_mult[THR_ZEROA    ] = 1000;
        sf->thresh_mult[THR_NEARG    ] = 1000;
        sf->thresh_mult[THR_NEARA    ] = 1000;

937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
#if 1
        sf->thresh_mult[THR_ZEROMV   ] = 0;
        sf->thresh_mult[THR_ZEROG    ] = 0;
        sf->thresh_mult[THR_ZEROA    ] = 0;
        sf->thresh_mult[THR_NEARESTMV] = 0;
        sf->thresh_mult[THR_NEARESTG ] = 0;
        sf->thresh_mult[THR_NEARESTA ] = 0;
        sf->thresh_mult[THR_NEARMV   ] = 0;
        sf->thresh_mult[THR_NEARG    ] = 0;
        sf->thresh_mult[THR_NEARA    ] = 0;

//        sf->thresh_mult[THR_DC       ] = 0;

//        sf->thresh_mult[THR_V_PRED   ] = 1000;
//        sf->thresh_mult[THR_H_PRED   ] = 1000;
//        sf->thresh_mult[THR_B_PRED   ] = 2000;
//        sf->thresh_mult[THR_TM       ] = 1000;

        sf->thresh_mult[THR_NEWMV    ] = 1000;
        sf->thresh_mult[THR_NEWG     ] = 1000;
        sf->thresh_mult[THR_NEWA     ] = 1000;

        sf->thresh_mult[THR_SPLITMV  ] = 1700;
        sf->thresh_mult[THR_SPLITG   ] = 4500;
        sf->thresh_mult[THR_SPLITA   ] = 4500;
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977

#if CONFIG_DUALPRED
        sf->thresh_mult[THR_DUAL_ZEROLG   ] = 0;
        sf->thresh_mult[THR_DUAL_NEARESTLG] = 0;
        sf->thresh_mult[THR_DUAL_NEARLG   ] = 0;
        sf->thresh_mult[THR_DUAL_ZEROLA   ] = 0;
        sf->thresh_mult[THR_DUAL_NEARESTLA] = 0;
        sf->thresh_mult[THR_DUAL_NEARLA   ] = 0;
        sf->thresh_mult[THR_DUAL_ZEROGA   ] = 0;
        sf->thresh_mult[THR_DUAL_NEARESTGA] = 0;
        sf->thresh_mult[THR_DUAL_NEARGA   ] = 0;

        sf->thresh_mult[THR_DUAL_NEWLG    ] = 1000;
        sf->thresh_mult[THR_DUAL_NEWLA    ] = 1000;
        sf->thresh_mult[THR_DUAL_NEWGA    ] = 1000;
#endif /* CONFIG_DUALPRED */
978
#else
John Koleszar's avatar
John Koleszar committed
979
980
981
982
983
984
985
        sf->thresh_mult[THR_NEWMV    ] = 1500;
        sf->thresh_mult[THR_NEWG     ] = 1500;
        sf->thresh_mult[THR_NEWA     ] = 1500;

        sf->thresh_mult[THR_SPLITMV  ] = 5000;
        sf->thresh_mult[THR_SPLITG   ] = 10000;
        sf->thresh_mult[THR_SPLITA   ] = 10000;
986
#endif
John Koleszar's avatar
John Koleszar committed
987

988
        if (Speed > 0)
John Koleszar's avatar
John Koleszar committed
989
        {
990
991
992
993
            /* Disable coefficient optimization above speed 0 */
            sf->optimize_coefficients = 0;
            sf->use_fastquant_for_pick = 1;
            sf->no_skip_block4x4_search = 0;
994

995
            sf->first_step = 1;
996

997
998
999
            cpi->mode_check_freq[THR_SPLITG] = 2;
            cpi->mode_check_freq[THR_SPLITA] = 2;
            cpi->mode_check_freq[THR_SPLITMV] = 0;
John Koleszar's avatar
John Koleszar committed
1000
1001
        }

1002
        if (Speed > 1)
John Koleszar's avatar
John Koleszar committed
1003
1004
1005
        {
            cpi->mode_check_freq[THR_SPLITG] = 4;
            cpi->mode_check_freq[THR_SPLITA] = 4;
1006
            cpi->mode_check_freq[THR_SPLITMV] = 2;
John Koleszar's avatar
John Koleszar committed
1007
1008
1009
1010
1011

            sf->thresh_mult[THR_TM       ] = 1500;
            sf->thresh_mult[THR_V_PRED   ] = 1500;
            sf->thresh_mult[THR_H_PRED   ] = 1500;
            sf->thresh_mult[THR_B_PRED   ] = 5000;
1012
            sf->thresh_mult[THR_I8X8_PRED] = 5000;
Yaowu Xu's avatar
Yaowu Xu committed
1013

John Koleszar's avatar
John Koleszar committed
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
            if (cpi->ref_frame_flags & VP8_LAST_FLAG)
            {
                sf->thresh_mult[THR_NEWMV    ] = 2000;
                sf->thresh_mult[THR_SPLITMV  ] = 10000;
            }

            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
            {
                sf->thresh_mult[THR_NEARESTG ] = 1500;
                sf->thresh_mult[THR_ZEROG    ] = 1500;
                sf->thresh_mult[THR_NEARG    ] = 1500;
                sf->thresh_mult[THR_NEWG     ] = 2000;
                sf->thresh_mult[THR_SPLITG   ] = 20000;
            }

            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
            {
                sf->thresh_mult[THR_NEARESTA ] = 1500;
                sf->thresh_mult[THR_ZEROA    ] = 1500;
                sf->thresh_mult[THR_NEARA    ] = 1500;
                sf->thresh_mult[THR_NEWA     ] = 2000;
                sf->thresh_mult[THR_SPLITA   ] = 20000;
            }
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052

#if CONFIG_DUALPRED
            sf->thresh_mult[THR_DUAL_ZEROLG   ] = 1500;
            sf->thresh_mult[THR_DUAL_NEARESTLG] = 1500;
            sf->thresh_mult[THR_DUAL_NEARLG   ] = 1500;
            sf->thresh_mult[THR_DUAL_ZEROLA   ] = 1500;
            sf->thresh_mult[THR_DUAL_NEARESTLA] = 1500;
            sf->thresh_mult[THR_DUAL_NEARLA   ] = 1500;
            sf->thresh_mult[THR_DUAL_ZEROGA   ] = 1500;
            sf->thresh_mult[THR_DUAL_NEARESTGA] = 1500;
            sf->thresh_mult[THR_DUAL_NEARGA   ] = 1500;

            sf->thresh_mult[THR_DUAL_NEWLG    ] = 2000;
            sf->thresh_mult[THR_DUAL_NEWLA    ] = 2000;
            sf->thresh_mult[THR_DUAL_NEWGA    ] = 2000;
#endif /* CONFIG_DUALPRED */
John Koleszar's avatar
John Koleszar committed
1053
1054
        }

1055
        if (Speed > 2)
John Koleszar's avatar
John Koleszar committed
1056
1057
1058
1059
1060
1061
1062
1063
1064
        {
            cpi->mode_check_freq[THR_SPLITG] = 15;
            cpi->mode_check_freq[THR_SPLITA] = 15;
            cpi->mode_check_freq[THR_SPLITMV] = 7;

            sf->thresh_mult[THR_TM       ] = 2000;
            sf->thresh_mult[THR_V_PRED   ] = 2000;
            sf->thresh_mult[THR_H_PRED   ] = 2000;
            sf->thresh_mult[THR_B_PRED   ] = 7500;
1065
            sf->thresh_mult[THR_I8X8_PRED] = 7500;
John Koleszar's avatar
John Koleszar committed
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090

            if (cpi->ref_frame_flags & VP8_LAST_FLAG)
            {
                sf->thresh_mult[THR_NEWMV    ] = 2000;
                sf->thresh_mult[THR_SPLITMV  ] = 25000;
            }

            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
            {
                sf->thresh_mult[THR_NEARESTG ] = 2000;
                sf->thresh_mult[THR_ZEROG    ] = 2000;
                sf->thresh_mult[THR_NEARG    ] = 2000;
                sf->thresh_mult[THR_NEWG     ] = 2500;
                sf->thresh_mult[THR_SPLITG   ] = 50000;
            }

            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
            {
                sf->thresh_mult[THR_NEARESTA ] = 2000;
                sf->thresh_mult[THR_ZEROA    ] = 2000;
                sf->thresh_mult[THR_NEARA    ] = 2000;
                sf->thresh_mult[THR_NEWA     ] = 2500;
                sf->thresh_mult[THR_SPLITA   ] = 50000;
            }

1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
#if CONFIG_DUALPRED
            sf->thresh_mult[THR_DUAL_ZEROLG   ] = 2000;
            sf->thresh_mult[THR_DUAL_NEARESTLG] = 2000;
            sf->thresh_mult[THR_DUAL_NEARLG   ] = 2000;
            sf->thresh_mult[THR_DUAL_ZEROLA   ] = 2000;
            sf->thresh_mult[THR_DUAL_NEARESTLA] = 2000;
            sf->thresh_mult[THR_DUAL_NEARLA   ] = 2000;
            sf->thresh_mult[THR_DUAL_ZEROGA   ] = 2000;
            sf->thresh_mult[THR_DUAL_NEARESTGA] = 2000;
            sf->thresh_mult[THR_DUAL_NEARGA   ] = 2000;

            sf->thresh_mult[THR_DUAL_NEWLG    ] = 2500;
            sf->thresh_mult[THR_DUAL_NEWLA    ] = 2500;
            sf->thresh_mult[THR_DUAL_NEWGA    ] = 2500;
#endif /* CONFIG_DUALPRED */

1107
1108
1109
            sf->improved_quant = 0;
            sf->improved_dct = 0;

1110
1111
            // Only do recode loop on key frames, golden frames and
            // alt ref frames
John Koleszar's avatar
John Koleszar committed
1112
1113
1114
1115
            sf->recode_loop = 2;

        }

1116
        if (Speed > 3)
John Koleszar's avatar
John Koleszar committed
1117
1118
1119
1120
1121
1122
1123
1124
        {
            sf->thresh_mult[THR_SPLITA  ] = INT_MAX;
            sf->thresh_mult[THR_SPLITG  ] = INT_MAX;
            sf->thresh_mult[THR_SPLITMV  ] = INT_MAX;

            cpi->mode_check_freq[THR_V_PRED] = 0;
            cpi->mode_check_freq[THR_H_PRED] = 0;
            cpi->mode_check_freq[THR_B_PRED] = 0;
1125
            cpi->mode_check_freq[THR_I8X8_PRED]   = 0;
John Koleszar's avatar
John Koleszar committed
1126
1127
1128
1129
1130
1131
1132
1133
            cpi->mode_check_freq[THR_NEARG] = 0;
            cpi->mode_check_freq[THR_NEWG] = 0;
            cpi->mode_check_freq[THR_NEARA] = 0;
            cpi->mode_check_freq[THR_NEWA] = 0;

            sf->auto_filter = 1;
            sf->recode_loop = 0; // recode loop off
            sf->RD = 0;         // Turn rd off
1134

John Koleszar's avatar
John Koleszar committed
1135
1136
1137
1138
1139
1140
1141
1142
1143
        }

        if (Speed > 4)
        {
            sf->auto_filter = 0;                     // Faster selection of loop filter

            cpi->mode_check_freq[THR_V_PRED] = 2;
            cpi->mode_check_freq[THR_H_PRED] = 2;
            cpi->mode_check_freq[THR_B_PRED] = 2;
1144
            cpi->mode_check_freq[THR_I8X8_PRED]=2;
John Koleszar's avatar
John Koleszar committed
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157

            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
            {
                cpi->mode_check_freq[THR_NEARG] = 2;
                cpi->mode_check_freq[THR_NEWG] = 4;
            }

            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
            {
                cpi->mode_check_freq[THR_NEARA] = 2;
                cpi->mode_check_freq[THR_NEWA] = 4;
            }

1158
1159
1160
1161
1162
1163
1164
1165
1166
#if CONFIG_DUALPRED
            cpi->mode_check_freq[THR_DUAL_NEARLG   ] = 2;
            cpi->mode_check_freq[THR_DUAL_NEARLA   ] = 2;
            cpi->mode_check_freq[THR_DUAL_NEARGA   ] = 2;
            cpi->mode_check_freq[THR_DUAL_NEWLG    ] = 4;
            cpi->mode_check_freq[THR_DUAL_NEWLA    ] = 4;
            cpi->mode_check_freq[THR_DUAL_NEWGA    ] = 4;
#endif /* CONFIG_DUALPRED */

1167
            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
John Koleszar's avatar
John Koleszar committed
1168
1169
1170
1171
1172
1173
1174
            {
                sf->thresh_mult[THR_NEARESTG ] = 2000;
                sf->thresh_mult[THR_ZEROG    ] = 2000;
                sf->thresh_mult[THR_NEARG    ] = 2000;
                sf->thresh_mult[THR_NEWG     ] = 4000;
            }

1175
            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
John Koleszar's avatar
John Koleszar committed
1176
1177
1178
1179
1180
1181
            {
                sf->thresh_mult[THR_NEARESTA ] = 2000;
                sf->thresh_mult[THR_ZEROA    ] = 2000;
                sf->thresh_mult[THR_NEARA    ] = 2000;
                sf->thresh_mult[THR_NEWA     ] = 4000;
            }
1182
1183
1184
1185
1186
1187

#if CONFIG_DUALPRED
            sf->thresh_mult[THR_DUAL_NEWLG    ] = 4000;
            sf->thresh_mult[THR_DUAL_NEWLA    ] = 4000;
            sf->thresh_mult[THR_DUAL_NEWGA    ] = 4000;
#endif /* CONFIG_DUALPRED */
John Koleszar's avatar
John Koleszar committed
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
        }

        break;
#endif
    case 2:
        sf->optimize_coefficients = 0;
        sf->recode_loop = 0;
        sf->auto_filter = 1;
        sf->iterative_sub_pixel = 1;
        sf->thresh_mult[THR_NEARESTMV] = 0;
        sf->thresh_mult[THR_ZEROMV   ] = 0;
        sf->thresh_mult[THR_DC       ] = 0;
        sf->thresh_mult[THR_TM       ] = 0;
        sf->thresh_mult[THR_NEARMV   ] = 0;
        sf->thresh_mult[THR_V_PRED   ] = 1000;
        sf->thresh_mult[THR_H_PRED   ] = 1000;
        sf->thresh_mult[THR_B_PRED   ] = 2500;
Yaowu Xu's avatar
Yaowu Xu committed
1205
        sf->thresh_mult[THR_I8X8_PRED] = 2500;
John Koleszar's avatar
John Koleszar committed
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
        sf->thresh_mult[THR_NEARESTG ] = 1000;
        sf->thresh_mult[THR_ZEROG    ] = 1000;
        sf->thresh_mult[THR_NEARG    ] = 1000;
        sf->thresh_mult[THR_NEARESTA ] = 1000;
        sf->thresh_mult[THR_ZEROA    ] = 1000;
        sf->thresh_mult[THR_NEARA    ] = 1000;
        sf->thresh_mult[THR_NEWMV    ] = 2000;
        sf->thresh_mult[THR_NEWG     ] = 2000;
        sf->thresh_mult[THR_NEWA     ] = 2000;
        sf->thresh_mult[THR_SPLITMV  ] = 5000;
        sf->thresh_mult[THR_SPLITG   ] = 10000;
        sf->thresh_mult[THR_SPLITA   ] = 10000;
        sf->search_method = NSTEP;

1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
#if CONFIG_DUALPRED
        sf->thresh_mult[THR_DUAL_ZEROLG   ] = 1000;
        sf->thresh_mult[THR_DUAL_NEARESTLG] = 1000;
        sf->thresh_mult[THR_DUAL_NEARLG   ] = 1000;
        sf->thresh_mult[THR_DUAL_ZEROLA   ] = 1000;
        sf->thresh_mult[THR_DUAL_NEARESTLA] = 1000;
        sf->thresh_mult[THR_DUAL_NEARLA   ] = 1000;
        sf->thresh_mult[THR_DUAL_ZEROGA   ] = 1000;
        sf->thresh_mult[THR_DUAL_NEARESTGA] = 1000;
        sf->thresh_mult[THR_DUAL_NEARGA   ] = 1000;

        sf->thresh_mult[THR_DUAL_NEWLG    ] = 2000;
        sf->thresh_mult[THR_DUAL_NEWLA    ] = 2000;
        sf->thresh_mult[THR_DUAL_NEWGA    ] = 2000;
#endif /* CONFIG_DUALPRED */

John Koleszar's avatar
John Koleszar committed
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
        if (Speed > 0)
        {
            cpi->mode_check_freq[THR_SPLITG] = 4;
            cpi->mode_check_freq[THR_SPLITA] = 4;
            cpi->mode_check_freq[THR_SPLITMV] = 2;

            sf->thresh_mult[THR_DC       ] = 0;
            sf->thresh_mult[THR_TM       ] = 1000;
            sf->thresh_mult[THR_V_PRED   ] = 2000;
            sf->thresh_mult[THR_H_PRED   ] = 2000;
            sf->thresh_mult[THR_B_PRED   ] = 5000;
1247
            sf->thresh_mult[THR_I8X8_PRED] = 5000;
John Koleszar's avatar
John Koleszar committed
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277

            if (cpi->ref_frame_flags & VP8_LAST_FLAG)
            {
                sf->thresh_mult[THR_NEARESTMV] = 0;
                sf->thresh_mult[THR_ZEROMV   ] = 0;
                sf->thresh_mult[THR_NEARMV   ] = 0;
                sf->thresh_mult[THR_NEWMV    ] = 2000;
                sf->thresh_mult[THR_SPLITMV  ] = 10000;
            }

            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
            {
                sf->thresh_mult[THR_NEARESTG ] = 1000;
                sf->thresh_mult[THR_ZEROG    ] = 1000;
                sf->thresh_mult[THR_NEARG    ] = 1000;
                sf->thresh_mult[THR_NEWG     ] = 2000;
                sf->thresh_mult[THR_SPLITG   ] = 20000;
            }

            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
            {
                sf->thresh_mult[THR_NEARESTA ] = 1000;
                sf->thresh_mult[THR_ZEROA    ] = 1000;
                sf->thresh_mult[THR_NEARA    ] = 1000;
                sf->thresh_mult[THR_NEWA     ] = 2000;
                sf->thresh_mult[THR_SPLITA   ] = 20000;
            }

            sf->improved_quant = 0;
            sf->improved_dct = 0;
1278
1279
1280
1281

            sf->use_fastquant_for_pick = 1;
            sf->no_skip_block4x4_search = 0;
            sf->first_step = 1;
John Koleszar's avatar
John Koleszar committed
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
        }

        if (Speed > 1)
        {
            cpi->mode_check_freq[THR_SPLITMV] = 7;
            cpi->mode_check_freq[THR_SPLITG] = 15;
            cpi->mode_check_freq[THR_SPLITA] = 15;

            sf->thresh_mult[THR_TM       ] = 2000;
            sf->thresh_mult[THR_V_PRED   ] = 2000;
            sf->thresh_mult[THR_H_PRED   ] = 2000;
            sf->thresh_mult[THR_B_PRED   ] = 5000;
1294
            sf->thresh_mult[THR_I8X8_PRED] = 5000;
Yaowu Xu's avatar
Yaowu Xu committed
1295

John Koleszar's avatar
John Koleszar committed
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
            if (cpi->ref_frame_flags & VP8_LAST_FLAG)
            {
                sf->thresh_mult[THR_NEWMV    ] = 2000;
                sf->thresh_mult[THR_SPLITMV  ] = 25000;
            }

            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
            {
                sf->thresh_mult[THR_NEARESTG ] = 2000;
                sf->thresh_mult[THR_ZEROG    ] = 2000;
                sf->thresh_mult[THR_NEARG    ] = 2000;
                sf->thresh_mult[THR_NEWG     ] = 2500;
                sf->thresh_mult[THR_SPLITG   ] = 50000;
            }

            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
            {
                sf->thresh_mult[THR_NEARESTA ] = 2000;
                sf->thresh_mult[THR_ZEROA    ] = 2000;
                sf->thresh_mult[THR_NEARA    ] = 2000;
                sf->thresh_mult[THR_NEWA     ] = 2500;
                sf->thresh_mult[THR_SPLITA   ] = 50000;
            }

1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
#if CONFIG_DUALPRED
            sf->thresh_mult[THR_DUAL_ZEROLG   ] = 2000;
            sf->thresh_mult[THR_DUAL_NEARESTLG] = 2000;
            sf->thresh_mult[THR_DUAL_NEARLG   ] = 2000;
            sf->thresh_mult[THR_DUAL_ZEROLA   ] = 2000;
            sf->thresh_mult[THR_DUAL_NEARESTLA] = 2000;
            sf->thresh_mult[THR_DUAL_NEARLA   ] = 2000;
            sf->thresh_mult[THR_DUAL_ZEROGA   ] = 2000;
            sf->thresh_mult[THR_DUAL_NEARESTGA] = 2000;
            sf->thresh_mult[THR_DUAL_NEARGA   ] = 2000;

            sf->thresh_mult[THR_DUAL_NEWLG    ] = 2500;
            sf->thresh_mult[THR_DUAL_NEWLA    ] = 2500;
            sf->thresh_mult[THR_DUAL_NEWGA    ] = 2500;
#endif /* CONFIG_DUALPRED */
John Koleszar's avatar
John Koleszar committed
1335
1336
1337
1338
1339
1340
1341
1342
1343
        }

        if (Speed > 2)
        {
            sf->auto_filter = 0;                     // Faster selection of loop filter

            cpi->mode_check_freq[THR_V_PRED] = 2;
            cpi->mode_check_freq[THR_H_PRED] = 2;
            cpi->mode_check_freq[THR_B_PRED] = 2;
1344
            cpi->mode_check_freq[THR_I8X8_PRED]=2;
John Koleszar's avatar
John Koleszar committed
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357

            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
            {
                cpi->mode_check_freq[THR_NEARG] = 2;
                cpi->mode_check_freq[THR_NEWG] = 4;
            }

            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
            {
                cpi->mode_check_freq[THR_NEARA] = 2;
                cpi->mode_check_freq[THR_NEWA] = 4;
            }

1358
1359
1360
1361
1362
1363
1364
1365
1366
#if CONFIG_DUALPRED
            cpi->mode_check_freq[THR_DUAL_NEARLG   ] = 2;
            cpi->mode_check_freq[THR_DUAL_NEARLA   ] = 2;
            cpi->mode_check_freq[THR_DUAL_NEARGA   ] = 2;
            cpi->mode_check_freq[THR_DUAL_NEWLG    ] = 4;
            cpi->mode_check_freq[THR_DUAL_NEWLA    ] = 4;
            cpi->mode_check_freq[THR_DUAL_NEWGA    ] = 4;
#endif /* CONFIG_DUALPRED */

John Koleszar's avatar
John Koleszar committed
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
            sf->thresh_mult[THR_SPLITMV  ] = INT_MAX;
            sf->thresh_mult[THR_SPLITG  ] = INT_MAX;
            sf->thresh_mult[THR_SPLITA  ] = INT_MAX;

        }

        if (Speed > 3)
        {
            sf->RD = 0;

            sf->auto_filter = 1;
        }

        if (Speed > 4)
        {
            sf->auto_filter = 0;                     // Faster selection of loop filter

            sf->search_method = HEX;
1385
1386
            //sf->search_method = DIAMOND;

1387
            sf->iterative_sub_pixel = 0;
John Koleszar's avatar
John Koleszar committed
1388
1389
1390
1391

            cpi->mode_check_freq[THR_V_PRED] = 4;
            cpi->mode_check_freq[THR_H_PRED] = 4;
            cpi->mode_check_freq[THR_B_PRED] = 4;
1392
            cpi->mode_check_freq[THR_I8X8_PRED]=4;
Yaowu Xu's avatar
Yaowu Xu committed
1393

John Koleszar's avatar
John Koleszar committed
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
            {
                cpi->mode_check_freq[THR_NEARG] = 2;
                cpi->mode_check_freq[THR_NEWG] = 4;
            }

            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
            {
                cpi->mode_check_freq[THR_NEARA] = 2;
                cpi->mode_check_freq[THR_NEWA] = 4;
            }

            sf->thresh_mult[THR_TM       ] = 2000;
            sf->thresh_mult[THR_B_PRED   ] = 5000;
1408
            sf->thresh_mult[THR_I8X8_PRED] = 5000;
John Koleszar's avatar
John Koleszar committed
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424

            if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
            {
                sf->thresh_mult[THR_NEARESTG ] = 2000;
                sf->thresh_mult[THR_ZEROG    ] = 2000;
                sf->thresh_mult[THR_NEARG    ] = 2000;
                sf->thresh_mult[THR_NEWG     ] = 4000;
            }

            if (cpi->ref_frame_flags & VP8_ALT_FLAG)
            {
                sf->thresh_mult[THR_NEARESTA ] = 2000;
                sf->thresh_mult[THR_ZEROA    ] = 2000;
                sf->thresh_mult[THR_NEARA    ] = 2000;
                sf->thresh_mult[THR_NEWA     ] = 4000;
            }
1425
1426
1427
1428
1429
1430

#if CONFIG_DUALPRED
            sf->thresh_mult[THR_DUAL_NEWLG    ] = 4000;
            sf->thresh_mult[THR_DUAL_NEWLA    ] = 4000;
            sf->thresh_mult[THR_DUAL_NEWGA    ] = 4000;
#endif /* CONFIG_DUALPRED */
John Koleszar's avatar
John Koleszar committed
1431
1432
1433
1434
1435
1436
        }

        if (Speed > 5)
        {
            // Disable split MB intra prediction mode
            sf->thresh_mult[THR_B_PRED] = INT_MAX;
1437
            sf->thresh_mult[THR_I8X8_PRED] = INT_MAX;
John Koleszar's avatar
John Koleszar committed
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452