190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber/*
2f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber *
4f71323e297a928af368937089d3ed71239786f86Andreas Huber *  Use of this source code is governed by a BSD-style license
5f71323e297a928af368937089d3ed71239786f86Andreas Huber *  that can be found in the LICENSE file in the root of the source
6f71323e297a928af368937089d3ed71239786f86Andreas Huber *  tree. An additional intellectual property rights grant can be found
7f71323e297a928af368937089d3ed71239786f86Andreas Huber *  in the file PATENTS.  All contributing project authors may
8f71323e297a928af368937089d3ed71239786f86Andreas Huber *  be found in the AUTHORS file in the root of the source tree.
990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber */
1090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
12b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifndef VP8_ENCODER_ONYX_INT_H_
13b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#define VP8_ENCODER_ONYX_INT_H_
1490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include <stdio.h>
161b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx_config.h"
1779f15823c34ae1e423108295e416213200bb280fAndreas Huber#include "vp8/common/onyx.h"
1890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "treewriter.h"
1990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "tokenize.h"
2079f15823c34ae1e423108295e416213200bb280fAndreas Huber#include "vp8/common/onyxc_int.h"
211b362b15af34006e6a11974088a46d42b903418eJohann#include "vp8/common/variance.h"
2290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "encodemb.h"
2390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "quantize.h"
2479f15823c34ae1e423108295e416213200bb280fAndreas Huber#include "vp8/common/entropy.h"
2579f15823c34ae1e423108295e416213200bb280fAndreas Huber#include "vp8/common/threading.h"
2690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "vpx_ports/mem.h"
27f71323e297a928af368937089d3ed71239786f86Andreas Huber#include "vpx/internal/vpx_codec_internal.h"
281b362b15af34006e6a11974088a46d42b903418eJohann#include "vpx/vp8.h"
2990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include "mcomp.h"
3079f15823c34ae1e423108295e416213200bb280fAndreas Huber#include "vp8/common/findnearmv.h"
311b362b15af34006e6a11974088a46d42b903418eJohann#include "lookahead.h"
321b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_TEMPORAL_DENOISING
331b362b15af34006e6a11974088a46d42b903418eJohann#include "vp8/encoder/denoising.h"
341b362b15af34006e6a11974088a46d42b903418eJohann#endif
3590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
36b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifdef __cplusplus
37b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanianextern "C" {
38b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#endif
39b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
4090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define MIN_GF_INTERVAL             4
4190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define DEFAULT_GF_INTERVAL         7
4290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define KEY_FRAME_CONTEXT 5
4490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY? 1 : 25)
4690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define AF_THRESH   25
4890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define AF_THRESH2  100
4990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define ARF_DECAY_THRESH 12
50ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
5190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define MIN_THRESHMULT  32
5390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define MAX_THRESHMULT  512
5490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
551b362b15af34006e6a11974088a46d42b903418eJohann#define GF_ZEROMV_ZBIN_BOOST 12
561b362b15af34006e6a11974088a46d42b903418eJohann#define LF_ZEROMV_ZBIN_BOOST 6
5779f15823c34ae1e423108295e416213200bb280fAndreas Huber#define MV_ZBIN_BOOST        4
5890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define ZBIN_OQ_MAX 192
5990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6079f15823c34ae1e423108295e416213200bb280fAndreas Huber#if !(CONFIG_REALTIME_ONLY)
6190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define VP8_TEMPORAL_ALT_REF 1
6279f15823c34ae1e423108295e416213200bb280fAndreas Huber#endif
6390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
641b362b15af34006e6a11974088a46d42b903418eJohann#define MAX(x,y) (((x)>(y))?(x):(y))
651b362b15af34006e6a11974088a46d42b903418eJohann#define MIN(x,y) (((x)<(y))?(x):(y))
661b362b15af34006e6a11974088a46d42b903418eJohann
6790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
6890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
6990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int kf_indicated;
7090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned int frames_since_key;
7190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned int frames_since_golden;
7290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int filter_level;
7390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int frames_till_gf_update_due;
7490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int recent_ref_frame_usage[MAX_REF_FRAMES];
7590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
7690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    MV_CONTEXT mvc[2];
7790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int mvcosts[2][MVvals+1];
7890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
7990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#ifdef MODE_STATS
8090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int y_modes[5];
8190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int uv_modes[4];
8290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int b_modes[10];
8390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int inter_y_modes[10];
8490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int inter_uv_modes[4];
8590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int inter_b_modes[10];
8690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
8790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
8890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    vp8_prob ymode_prob[4], uv_mode_prob[3];   /* interframe intra mode probs */
8990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    vp8_prob kf_ymode_prob[4], kf_uv_mode_prob[3];   /* keyframe "" */
9090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int ymode_count[5], uv_mode_count[4];  /* intra MB type cts this frame */
9290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int count_mb_ref_frame_usage[MAX_REF_FRAMES];
9490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int this_frame_percent_intra;
9690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int last_frame_percent_intra;
9790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
9990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} CODING_CONTEXT;
10090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
10190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
10290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
10390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame;
10490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double intra_error;
10590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double coded_error;
10690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double ssim_weighted_pred_err;
10790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double pcnt_inter;
10890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double pcnt_motion;
10990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double pcnt_second_ref;
11079f15823c34ae1e423108295e416213200bb280fAndreas Huber    double pcnt_neutral;
11190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double MVr;
11290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double mvr_abs;
11390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double MVc;
11490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double mvc_abs;
11590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double MVrv;
11690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double MVcv;
11790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double mv_in_out_count;
1181b362b15af34006e6a11974088a46d42b903418eJohann    double new_mv_count;
11990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double duration;
12090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double count;
12190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
12290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas HuberFIRSTPASS_STATS;
12390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
12490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
12590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
12690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int frames_so_far;
12790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame_intra_error;
12890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame_coded_error;
12990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame_pcnt_inter;
13090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame_pcnt_motion;
13190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame_mvr;
13290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame_mvr_abs;
13390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame_mvc;
13490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double frame_mvc_abs;
13590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
13690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} ONEPASS_FRAMESTATS;
13790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
13890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
13990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef enum
14090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
1411b362b15af34006e6a11974088a46d42b903418eJohann    THR_ZERO1          = 0,
14290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    THR_DC             = 1,
14390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1441b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEAREST1       = 2,
1451b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEAR1          = 3,
14690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1471b362b15af34006e6a11974088a46d42b903418eJohann    THR_ZERO2          = 4,
1481b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEAREST2       = 5,
14990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1501b362b15af34006e6a11974088a46d42b903418eJohann    THR_ZERO3          = 6,
1511b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEAREST3       = 7,
15290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1531b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEAR2          = 8,
1541b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEAR3          = 9,
15590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
15690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    THR_V_PRED         = 10,
15790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    THR_H_PRED         = 11,
15890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    THR_TM             = 12,
15990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1601b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEW1           = 13,
1611b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEW2           = 14,
1621b362b15af34006e6a11974088a46d42b903418eJohann    THR_NEW3           = 15,
16390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1641b362b15af34006e6a11974088a46d42b903418eJohann    THR_SPLIT1         = 16,
1651b362b15af34006e6a11974088a46d42b903418eJohann    THR_SPLIT2         = 17,
1661b362b15af34006e6a11974088a46d42b903418eJohann    THR_SPLIT3         = 18,
16790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
1681b362b15af34006e6a11974088a46d42b903418eJohann    THR_B_PRED         = 19
16990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber}
17090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas HuberTHR_MODES;
17190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
17290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef enum
17390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
17490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    DIAMOND = 0,
17590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    NSTEP = 1,
17690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    HEX = 2
17790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} SEARCH_METHODS;
17890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
17990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
18090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
18190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int RD;
18290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    SEARCH_METHODS search_method;
18390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int improved_quant;
18490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int improved_dct;
18590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int auto_filter;
18690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int recode_loop;
18790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int iterative_sub_pixel;
18890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int half_pixel_search;
18990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int quarter_pixel_search;
19090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int thresh_mult[MAX_MODES];
19190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int max_step_search_steps;
19290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int first_step;
19390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int optimize_coefficients;
19490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
19579f15823c34ae1e423108295e416213200bb280fAndreas Huber    int use_fastquant_for_pick;
19679f15823c34ae1e423108295e416213200bb280fAndreas Huber    int no_skip_block4x4_search;
19779f15823c34ae1e423108295e416213200bb280fAndreas Huber    int improved_mv_pred;
19879f15823c34ae1e423108295e416213200bb280fAndreas Huber
19990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} SPEED_FEATURES;
20090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
20190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
20290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
20390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    MACROBLOCK  mb;
20490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int segment_counts[MAX_MB_SEGMENTS];
20590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int totalrate;
20690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} MB_ROW_COMP;
20790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
20890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
20990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
21090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    TOKENEXTRA *start;
21190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    TOKENEXTRA *stop;
21290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} TOKENLIST;
21390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
21490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
21590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
21690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int ithread;
21790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    void *ptr1;
21890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    void *ptr2;
21990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} ENCODETHREAD_DATA;
22090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
22190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
22290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int ithread;
22390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    void *ptr1;
22490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber} LPFTHREAD_DATA;
22590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
226538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huberenum
227538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber{
228538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    BLOCK_16X8,
229538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    BLOCK_8X16,
230538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    BLOCK_8X8,
231538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    BLOCK_4X4,
232538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    BLOCK_16X16,
233538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    BLOCK_MAX_SEGMENTS
234538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber};
235538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber
23690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubertypedef struct
23790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber{
2381b362b15af34006e6a11974088a46d42b903418eJohann    /* Layer configuration */
23991037db265ecdd914a26e056cf69207b4f50924ehkuang    double framerate;
2401b362b15af34006e6a11974088a46d42b903418eJohann    int target_bandwidth;
2411b362b15af34006e6a11974088a46d42b903418eJohann
2421b362b15af34006e6a11974088a46d42b903418eJohann    /* Layer specific coding parameters */
2431b362b15af34006e6a11974088a46d42b903418eJohann    int64_t starting_buffer_level;
2441b362b15af34006e6a11974088a46d42b903418eJohann    int64_t optimal_buffer_level;
2451b362b15af34006e6a11974088a46d42b903418eJohann    int64_t maximum_buffer_size;
2461b362b15af34006e6a11974088a46d42b903418eJohann    int64_t starting_buffer_level_in_ms;
2471b362b15af34006e6a11974088a46d42b903418eJohann    int64_t optimal_buffer_level_in_ms;
2481b362b15af34006e6a11974088a46d42b903418eJohann    int64_t maximum_buffer_size_in_ms;
2491b362b15af34006e6a11974088a46d42b903418eJohann
2501b362b15af34006e6a11974088a46d42b903418eJohann    int avg_frame_size_for_layer;
2511b362b15af34006e6a11974088a46d42b903418eJohann
2521b362b15af34006e6a11974088a46d42b903418eJohann    int64_t buffer_level;
2531b362b15af34006e6a11974088a46d42b903418eJohann    int64_t bits_off_target;
2541b362b15af34006e6a11974088a46d42b903418eJohann
2551b362b15af34006e6a11974088a46d42b903418eJohann    int64_t total_actual_bits;
2561b362b15af34006e6a11974088a46d42b903418eJohann    int total_target_vs_actual;
2571b362b15af34006e6a11974088a46d42b903418eJohann
2581b362b15af34006e6a11974088a46d42b903418eJohann    int worst_quality;
2591b362b15af34006e6a11974088a46d42b903418eJohann    int active_worst_quality;
2601b362b15af34006e6a11974088a46d42b903418eJohann    int best_quality;
2611b362b15af34006e6a11974088a46d42b903418eJohann    int active_best_quality;
2621b362b15af34006e6a11974088a46d42b903418eJohann
2631b362b15af34006e6a11974088a46d42b903418eJohann    int ni_av_qi;
2641b362b15af34006e6a11974088a46d42b903418eJohann    int ni_tot_qi;
2651b362b15af34006e6a11974088a46d42b903418eJohann    int ni_frames;
2661b362b15af34006e6a11974088a46d42b903418eJohann    int avg_frame_qindex;
2671b362b15af34006e6a11974088a46d42b903418eJohann
2681b362b15af34006e6a11974088a46d42b903418eJohann    double rate_correction_factor;
2691b362b15af34006e6a11974088a46d42b903418eJohann    double key_frame_rate_correction_factor;
2701b362b15af34006e6a11974088a46d42b903418eJohann    double gf_rate_correction_factor;
2711b362b15af34006e6a11974088a46d42b903418eJohann
2721b362b15af34006e6a11974088a46d42b903418eJohann    int zbin_over_quant;
2731b362b15af34006e6a11974088a46d42b903418eJohann
2741b362b15af34006e6a11974088a46d42b903418eJohann    int inter_frame_target;
2751b362b15af34006e6a11974088a46d42b903418eJohann    int64_t total_byte_count;
2761b362b15af34006e6a11974088a46d42b903418eJohann
2771b362b15af34006e6a11974088a46d42b903418eJohann    int filter_level;
2781b362b15af34006e6a11974088a46d42b903418eJohann
2791b362b15af34006e6a11974088a46d42b903418eJohann    int last_frame_percent_intra;
2801b362b15af34006e6a11974088a46d42b903418eJohann
2811b362b15af34006e6a11974088a46d42b903418eJohann    int count_mb_ref_frame_usage[MAX_REF_FRAMES];
2821b362b15af34006e6a11974088a46d42b903418eJohann
2831b362b15af34006e6a11974088a46d42b903418eJohann} LAYER_CONTEXT;
2841b362b15af34006e6a11974088a46d42b903418eJohann
2851b362b15af34006e6a11974088a46d42b903418eJohanntypedef struct VP8_COMP
2861b362b15af34006e6a11974088a46d42b903418eJohann{
28790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
288538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]);
289ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    DECLARE_ALIGNED(16, short, Y1quant_shift[QINDEX_RANGE][16]);
290538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, Y1zbin[QINDEX_RANGE][16]);
291538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, Y1round[QINDEX_RANGE][16]);
29290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
293538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, Y2quant[QINDEX_RANGE][16]);
294ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    DECLARE_ALIGNED(16, short, Y2quant_shift[QINDEX_RANGE][16]);
295538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, Y2zbin[QINDEX_RANGE][16]);
296538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, Y2round[QINDEX_RANGE][16]);
29790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
298538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, UVquant[QINDEX_RANGE][16]);
299ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    DECLARE_ALIGNED(16, short, UVquant_shift[QINDEX_RANGE][16]);
300538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, UVzbin[QINDEX_RANGE][16]);
301538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    DECLARE_ALIGNED(16, short, UVround[QINDEX_RANGE][16]);
30290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
30390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1[QINDEX_RANGE][16]);
30490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2[QINDEX_RANGE][16]);
30590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv[QINDEX_RANGE][16]);
30679f15823c34ae1e423108295e416213200bb280fAndreas Huber    DECLARE_ALIGNED(16, short, Y1quant_fast[QINDEX_RANGE][16]);
30779f15823c34ae1e423108295e416213200bb280fAndreas Huber    DECLARE_ALIGNED(16, short, Y2quant_fast[QINDEX_RANGE][16]);
30879f15823c34ae1e423108295e416213200bb280fAndreas Huber    DECLARE_ALIGNED(16, short, UVquant_fast[QINDEX_RANGE][16]);
30990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
31090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
31190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    MACROBLOCK mb;
31290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    VP8_COMMON common;
3131b362b15af34006e6a11974088a46d42b903418eJohann    vp8_writer bc[9]; /* one boolcoder for each partition */
31490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
31590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    VP8_CONFIG oxcf;
31690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3171b362b15af34006e6a11974088a46d42b903418eJohann    struct lookahead_ctx    *lookahead;
3181b362b15af34006e6a11974088a46d42b903418eJohann    struct lookahead_entry  *source;
3191b362b15af34006e6a11974088a46d42b903418eJohann    struct lookahead_entry  *alt_ref_source;
3201b362b15af34006e6a11974088a46d42b903418eJohann    struct lookahead_entry  *last_source;
3211b362b15af34006e6a11974088a46d42b903418eJohann
32290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    YV12_BUFFER_CONFIG *Source;
32390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    YV12_BUFFER_CONFIG *un_scaled_source;
32490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    YV12_BUFFER_CONFIG scaled_source;
3251b362b15af34006e6a11974088a46d42b903418eJohann    YV12_BUFFER_CONFIG *last_frame_unscaled_source;
32690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
32791037db265ecdd914a26e056cf69207b4f50924ehkuang    unsigned int frames_till_alt_ref_frame;
3281b362b15af34006e6a11974088a46d42b903418eJohann    /* frame in src_buffers has been identified to be encoded as an alt ref */
3291b362b15af34006e6a11974088a46d42b903418eJohann    int source_alt_ref_pending;
3301b362b15af34006e6a11974088a46d42b903418eJohann    /* an alt ref frame has been encoded and is usable */
3311b362b15af34006e6a11974088a46d42b903418eJohann    int source_alt_ref_active;
3321b362b15af34006e6a11974088a46d42b903418eJohann    /* source of frame to encode is an exact copy of an alt ref frame */
3331b362b15af34006e6a11974088a46d42b903418eJohann    int is_src_frame_alt_ref;
33490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3351b362b15af34006e6a11974088a46d42b903418eJohann    /* golden frame same as last frame ( short circuit gold searches) */
3361b362b15af34006e6a11974088a46d42b903418eJohann    int gold_is_last;
3371b362b15af34006e6a11974088a46d42b903418eJohann    /* Alt reference frame same as last ( short circuit altref search) */
3381b362b15af34006e6a11974088a46d42b903418eJohann    int alt_is_last;
3391b362b15af34006e6a11974088a46d42b903418eJohann    /* don't do both alt and gold search ( just do gold). */
3401b362b15af34006e6a11974088a46d42b903418eJohann    int gold_is_alt;
34190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3421b362b15af34006e6a11974088a46d42b903418eJohann    YV12_BUFFER_CONFIG pick_lf_lvl_frame;
34390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
34490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    TOKENEXTRA *tok;
34590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned int tok_count;
34690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
34790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
34890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned int frames_since_key;
34990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned int key_frame_frequency;
35079f15823c34ae1e423108295e416213200bb280fAndreas Huber    unsigned int this_key_frame_forced;
35179f15823c34ae1e423108295e416213200bb280fAndreas Huber    unsigned int next_key_frame_forced;
35279f15823c34ae1e423108295e416213200bb280fAndreas Huber
3531b362b15af34006e6a11974088a46d42b903418eJohann    /* Ambient reconstruction err target for force key frames */
35479f15823c34ae1e423108295e416213200bb280fAndreas Huber    int ambient_err;
35590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
35690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned int mode_check_freq[MAX_MODES];
35790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
35890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int rd_baseline_thresh[MAX_MODES];
35990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
36090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int RDMULT;
36190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int RDDIV ;
36290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
36390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    CODING_CONTEXT coding_context;
36490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3651b362b15af34006e6a11974088a46d42b903418eJohann    /* Rate targetting variables */
3661b362b15af34006e6a11974088a46d42b903418eJohann    int64_t last_prediction_error;
3671b362b15af34006e6a11974088a46d42b903418eJohann    int64_t last_intra_error;
36890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
36990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int this_frame_target;
37090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int projected_frame_size;
3711b362b15af34006e6a11974088a46d42b903418eJohann    int last_q[2];                   /* Separate values for Intra/Inter */
37290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
37390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double rate_correction_factor;
37490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double key_frame_rate_correction_factor;
37590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double gf_rate_correction_factor;
37690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
37791037db265ecdd914a26e056cf69207b4f50924ehkuang    unsigned int frames_since_golden;
3781b362b15af34006e6a11974088a46d42b903418eJohann    /* Count down till next GF */
3791b362b15af34006e6a11974088a46d42b903418eJohann    int frames_till_gf_update_due;
380f71323e297a928af368937089d3ed71239786f86Andreas Huber
3811b362b15af34006e6a11974088a46d42b903418eJohann    /* GF interval chosen when we coded the last GF */
3821b362b15af34006e6a11974088a46d42b903418eJohann    int current_gf_interval;
383f71323e297a928af368937089d3ed71239786f86Andreas Huber
3841b362b15af34006e6a11974088a46d42b903418eJohann    /* Total bits overspent becasue of GF boost (cumulative) */
3851b362b15af34006e6a11974088a46d42b903418eJohann    int gf_overspend_bits;
38690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3871b362b15af34006e6a11974088a46d42b903418eJohann    /* Used in the few frames following a GF to recover the extra bits
3881b362b15af34006e6a11974088a46d42b903418eJohann     * spent in that GF
3891b362b15af34006e6a11974088a46d42b903418eJohann     */
3901b362b15af34006e6a11974088a46d42b903418eJohann    int non_gf_bitrate_adjustment;
39190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3921b362b15af34006e6a11974088a46d42b903418eJohann    /* Extra bits spent on key frames that need to be recovered */
3931b362b15af34006e6a11974088a46d42b903418eJohann    int kf_overspend_bits;
39490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
3951b362b15af34006e6a11974088a46d42b903418eJohann    /* Current number of bit s to try and recover on each inter frame. */
3961b362b15af34006e6a11974088a46d42b903418eJohann    int kf_bitrate_adjustment;
39790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int max_gf_interval;
39890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int baseline_gf_interval;
3991b362b15af34006e6a11974088a46d42b903418eJohann    int active_arnr_frames;
40090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4011b362b15af34006e6a11974088a46d42b903418eJohann    int64_t key_frame_count;
40290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int prior_key_frame_distance[KEY_FRAME_CONTEXT];
4031b362b15af34006e6a11974088a46d42b903418eJohann    /* Current section per frame bandwidth target */
4041b362b15af34006e6a11974088a46d42b903418eJohann    int per_frame_bandwidth;
4051b362b15af34006e6a11974088a46d42b903418eJohann    /* Average frame size target for clip */
4061b362b15af34006e6a11974088a46d42b903418eJohann    int av_per_frame_bandwidth;
4071b362b15af34006e6a11974088a46d42b903418eJohann    /* Minimum allocation that should be used for any frame */
4081b362b15af34006e6a11974088a46d42b903418eJohann    int min_frame_bandwidth;
40990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int inter_frame_target;
41091037db265ecdd914a26e056cf69207b4f50924ehkuang    double output_framerate;
4111b362b15af34006e6a11974088a46d42b903418eJohann    int64_t last_time_stamp_seen;
4121b362b15af34006e6a11974088a46d42b903418eJohann    int64_t last_end_time_stamp_seen;
4131b362b15af34006e6a11974088a46d42b903418eJohann    int64_t first_time_stamp_ever;
41490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
41590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int ni_av_qi;
41690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int ni_tot_qi;
41790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int ni_frames;
41890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int avg_frame_qindex;
41990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4201b362b15af34006e6a11974088a46d42b903418eJohann    int64_t total_byte_count;
42190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
42290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int buffered_mode;
42390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
42491037db265ecdd914a26e056cf69207b4f50924ehkuang    double framerate;
42591037db265ecdd914a26e056cf69207b4f50924ehkuang    double ref_framerate;
4261b362b15af34006e6a11974088a46d42b903418eJohann    int64_t buffer_level;
4271b362b15af34006e6a11974088a46d42b903418eJohann    int64_t bits_off_target;
42890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
42990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int rolling_target_bits;
43090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int rolling_actual_bits;
43190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
43290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int long_rolling_target_bits;
43390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int long_rolling_actual_bits;
43490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4351b362b15af34006e6a11974088a46d42b903418eJohann    int64_t total_actual_bits;
4361b362b15af34006e6a11974088a46d42b903418eJohann    int total_target_vs_actual; /* debug stats */
43790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
43890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int worst_quality;
43990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int active_worst_quality;
44090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int best_quality;
44190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int active_best_quality;
44290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
44379f15823c34ae1e423108295e416213200bb280fAndreas Huber    int cq_target_quality;
44490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4451b362b15af34006e6a11974088a46d42b903418eJohann    int drop_frames_allowed; /* Are we permitted to drop frames? */
4461b362b15af34006e6a11974088a46d42b903418eJohann    int drop_frame;          /* Drop this frame? */
44790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4481b362b15af34006e6a11974088a46d42b903418eJohann    vp8_prob frame_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
4491b362b15af34006e6a11974088a46d42b903418eJohann    char update_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES];
45090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4511b362b15af34006e6a11974088a46d42b903418eJohann    unsigned int frame_branch_ct [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES][2];
45290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
45390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int gfu_boost;
45490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int kf_boost;
45590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int last_boost;
45690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
45790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int target_bandwidth;
45890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    struct vpx_codec_pkt_list  *output_pkt_list;
45990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
46090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#if 0
4611b362b15af34006e6a11974088a46d42b903418eJohann    /* Experimental code for lagged and one pass */
46290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS];
46390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int one_pass_frame_index;
46490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
46590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
46690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int decimation_factor;
46790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int decimation_count;
46890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4691b362b15af34006e6a11974088a46d42b903418eJohann    /* for real time encoding */
4701b362b15af34006e6a11974088a46d42b903418eJohann    int avg_encode_time;     /* microsecond */
4711b362b15af34006e6a11974088a46d42b903418eJohann    int avg_pick_mode_time;  /* microsecond */
47290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int Speed;
47390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int compressor_speed;
47490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
47590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int auto_gold;
47690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int auto_adjust_gold_quantizer;
47790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int auto_worst_q;
47890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int cpu_used;
47990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int pass;
48090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
48190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
48290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int prob_intra_coded;
48390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int prob_last_coded;
48490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int prob_gf_coded;
48590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int prob_skip_false;
48690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int last_skip_false_probs[3];
48790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int last_skip_probs_q[3];
48890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int recent_ref_frame_usage[MAX_REF_FRAMES];
48990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
49090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int this_frame_percent_intra;
49190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int last_frame_percent_intra;
49290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
49390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int ref_frame_flags;
49490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
49590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    SPEED_FEATURES sf;
49690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
4971b362b15af34006e6a11974088a46d42b903418eJohann    /* Count ZEROMV on all reference frames. */
4981b362b15af34006e6a11974088a46d42b903418eJohann    int zeromv_count;
4991b362b15af34006e6a11974088a46d42b903418eJohann    int lf_zeromv_pct;
50090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
50190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned char *segmentation_map;
5021b362b15af34006e6a11974088a46d42b903418eJohann    signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
5031b362b15af34006e6a11974088a46d42b903418eJohann    int  segment_encode_breakout[MAX_MB_SEGMENTS];
50490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
50590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned char *active_map;
50690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned int active_map_enabled;
5071b362b15af34006e6a11974088a46d42b903418eJohann
5081b362b15af34006e6a11974088a46d42b903418eJohann    /* Video conferencing cyclic refresh mode flags. This is a mode
5091b362b15af34006e6a11974088a46d42b903418eJohann     * designed to clean up the background over time in live encoding
5101b362b15af34006e6a11974088a46d42b903418eJohann     * scenarious. It uses segmentation.
5111b362b15af34006e6a11974088a46d42b903418eJohann     */
51290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int cyclic_refresh_mode_enabled;
51390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int cyclic_refresh_mode_max_mbs_perframe;
51490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int cyclic_refresh_mode_index;
51590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int cyclic_refresh_q;
51690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    signed char *cyclic_refresh_map;
51790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
518ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    // Frame counter for the temporal pattern. Counter is rest when the temporal
519ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    // layers are changed dynamically (run-time change).
520ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang    unsigned int temporal_pattern_counter;
521ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang
52279f15823c34ae1e423108295e416213200bb280fAndreas Huber#if CONFIG_MULTITHREAD
5231b362b15af34006e6a11974088a46d42b903418eJohann    /* multithread data */
52479f15823c34ae1e423108295e416213200bb280fAndreas Huber    int * mt_current_mb_col;
52579f15823c34ae1e423108295e416213200bb280fAndreas Huber    int mt_sync_range;
52690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int b_multi_threaded;
52790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int encoding_thread_count;
5281b362b15af34006e6a11974088a46d42b903418eJohann    int b_lpf_running;
52990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
53090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    pthread_t *h_encoding_thread;
53179f15823c34ae1e423108295e416213200bb280fAndreas Huber    pthread_t h_filter_thread;
53279f15823c34ae1e423108295e416213200bb280fAndreas Huber
53390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    MB_ROW_COMP *mb_row_ei;
53490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    ENCODETHREAD_DATA *en_thread_data;
53579f15823c34ae1e423108295e416213200bb280fAndreas Huber    LPFTHREAD_DATA lpf_thread_data;
53690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5371b362b15af34006e6a11974088a46d42b903418eJohann    /* events */
53879f15823c34ae1e423108295e416213200bb280fAndreas Huber    sem_t *h_event_start_encoding;
53979f15823c34ae1e423108295e416213200bb280fAndreas Huber    sem_t h_event_end_encoding;
54079f15823c34ae1e423108295e416213200bb280fAndreas Huber    sem_t h_event_start_lpf;
54179f15823c34ae1e423108295e416213200bb280fAndreas Huber    sem_t h_event_end_lpf;
54290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
54390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
54490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    TOKENLIST *tplist;
5451b362b15af34006e6a11974088a46d42b903418eJohann    unsigned int partition_sz[MAX_PARTITIONS];
5461b362b15af34006e6a11974088a46d42b903418eJohann    unsigned char *partition_d[MAX_PARTITIONS];
5471b362b15af34006e6a11974088a46d42b903418eJohann    unsigned char *partition_d_end[MAX_PARTITIONS];
54890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
54990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
55090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    fractional_mv_step_fp *find_fractional_mv_step;
55190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    vp8_full_search_fn_t full_search_sad;
5521b362b15af34006e6a11974088a46d42b903418eJohann    vp8_refining_search_fn_t refining_search_sad;
55390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    vp8_diamond_search_fn_t diamond_search_sad;
554538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    vp8_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SEGMENTS];
5551b362b15af34006e6a11974088a46d42b903418eJohann    uint64_t time_receive_data;
5561b362b15af34006e6a11974088a46d42b903418eJohann    uint64_t time_compress_data;
5571b362b15af34006e6a11974088a46d42b903418eJohann    uint64_t time_pick_lpf;
5581b362b15af34006e6a11974088a46d42b903418eJohann    uint64_t time_encode_mb_row;
55990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
56090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int base_skip_false_prob[128];
56190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
5621b362b15af34006e6a11974088a46d42b903418eJohann    FRAME_CONTEXT lfc_n; /* last frame entropy */
5631b362b15af34006e6a11974088a46d42b903418eJohann    FRAME_CONTEXT lfc_a; /* last alt ref entropy */
5641b362b15af34006e6a11974088a46d42b903418eJohann    FRAME_CONTEXT lfc_g; /* last gold ref entropy */
5651b362b15af34006e6a11974088a46d42b903418eJohann
5661b362b15af34006e6a11974088a46d42b903418eJohann
5671b362b15af34006e6a11974088a46d42b903418eJohann    struct twopass_rc
5681b362b15af34006e6a11974088a46d42b903418eJohann    {
5691b362b15af34006e6a11974088a46d42b903418eJohann        unsigned int section_intra_rating;
5701b362b15af34006e6a11974088a46d42b903418eJohann        double section_max_qfactor;
5711b362b15af34006e6a11974088a46d42b903418eJohann        unsigned int next_iiratio;
5721b362b15af34006e6a11974088a46d42b903418eJohann        unsigned int this_iiratio;
5731b362b15af34006e6a11974088a46d42b903418eJohann        FIRSTPASS_STATS total_stats;
5741b362b15af34006e6a11974088a46d42b903418eJohann        FIRSTPASS_STATS this_frame_stats;
5751b362b15af34006e6a11974088a46d42b903418eJohann        FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
5761b362b15af34006e6a11974088a46d42b903418eJohann        FIRSTPASS_STATS total_left_stats;
5771b362b15af34006e6a11974088a46d42b903418eJohann        int first_pass_done;
5781b362b15af34006e6a11974088a46d42b903418eJohann        int64_t bits_left;
5791b362b15af34006e6a11974088a46d42b903418eJohann        int64_t clip_bits_total;
5801b362b15af34006e6a11974088a46d42b903418eJohann        double avg_iiratio;
5811b362b15af34006e6a11974088a46d42b903418eJohann        double modified_error_total;
5821b362b15af34006e6a11974088a46d42b903418eJohann        double modified_error_used;
5831b362b15af34006e6a11974088a46d42b903418eJohann        double modified_error_left;
5841b362b15af34006e6a11974088a46d42b903418eJohann        double kf_intra_err_min;
5851b362b15af34006e6a11974088a46d42b903418eJohann        double gf_intra_err_min;
5861b362b15af34006e6a11974088a46d42b903418eJohann        int frames_to_key;
5871b362b15af34006e6a11974088a46d42b903418eJohann        int maxq_max_limit;
5881b362b15af34006e6a11974088a46d42b903418eJohann        int maxq_min_limit;
5891b362b15af34006e6a11974088a46d42b903418eJohann        int gf_decay_rate;
5901b362b15af34006e6a11974088a46d42b903418eJohann        int static_scene_max_gf_interval;
5911b362b15af34006e6a11974088a46d42b903418eJohann        int kf_bits;
5921b362b15af34006e6a11974088a46d42b903418eJohann        /* Remaining error from uncoded frames in a gf group. */
5931b362b15af34006e6a11974088a46d42b903418eJohann        int gf_group_error_left;
5941b362b15af34006e6a11974088a46d42b903418eJohann        /* Projected total bits available for a key frame group of frames */
5951b362b15af34006e6a11974088a46d42b903418eJohann        int64_t kf_group_bits;
5961b362b15af34006e6a11974088a46d42b903418eJohann        /* Error score of frames still to be coded in kf group */
5971b362b15af34006e6a11974088a46d42b903418eJohann        int64_t kf_group_error_left;
5981b362b15af34006e6a11974088a46d42b903418eJohann        /* Projected Bits available for a group including 1 GF or ARF */
599ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang        int64_t gf_group_bits;
6001b362b15af34006e6a11974088a46d42b903418eJohann        /* Bits for the golden frame or ARF */
6011b362b15af34006e6a11974088a46d42b903418eJohann        int gf_bits;
6021b362b15af34006e6a11974088a46d42b903418eJohann        int alt_extra_bits;
6031b362b15af34006e6a11974088a46d42b903418eJohann        double est_max_qcorrection_factor;
6041b362b15af34006e6a11974088a46d42b903418eJohann    } twopass;
60590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
60690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#if VP8_TEMPORAL_ALT_REF
6071b362b15af34006e6a11974088a46d42b903418eJohann    YV12_BUFFER_CONFIG alt_ref_buffer;
608538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
609538f6170b788de7408b06efc6613dc98579aa6a6Andreas Huber    int fixed_divide[512];
61090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
61190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6121b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_INTERNAL_STATS
61390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int    count;
61490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_y;
61590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_u;
61690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_v;
61790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total ;
61890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_sq_error;
61990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double totalp_y;
62090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double totalp_u;
62190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double totalp_v;
62290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double totalp;
62390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_sq_error2;
62490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int    bytes;
62590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double summed_quality;
62690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double summed_weights;
62790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    unsigned int tot_recode_hits;
62890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
62990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
63090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_ssimg_y;
63190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_ssimg_u;
63290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_ssimg_v;
63390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    double total_ssimg_all;
63490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
63590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int b_calculate_ssimg;
63690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
63790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    int b_calculate_psnr;
638f71323e297a928af368937089d3ed71239786f86Andreas Huber
6391b362b15af34006e6a11974088a46d42b903418eJohann    /* Per MB activity measurement */
6401b362b15af34006e6a11974088a46d42b903418eJohann    unsigned int activity_avg;
6411b362b15af34006e6a11974088a46d42b903418eJohann    unsigned int * mb_activity_map;
642f71323e297a928af368937089d3ed71239786f86Andreas Huber
6431b362b15af34006e6a11974088a46d42b903418eJohann    /* Record of which MBs still refer to last golden frame either
6441b362b15af34006e6a11974088a46d42b903418eJohann     * directly or through 0,0
6451b362b15af34006e6a11974088a46d42b903418eJohann     */
6461b362b15af34006e6a11974088a46d42b903418eJohann    unsigned char *gf_active_flags;
647f71323e297a928af368937089d3ed71239786f86Andreas Huber    int gf_active_count;
648f71323e297a928af368937089d3ed71239786f86Andreas Huber
6491b362b15af34006e6a11974088a46d42b903418eJohann    int output_partition;
6501b362b15af34006e6a11974088a46d42b903418eJohann
6511b362b15af34006e6a11974088a46d42b903418eJohann    /* Store last frame's MV info for next frame MV prediction */
65279f15823c34ae1e423108295e416213200bb280fAndreas Huber    int_mv *lfmv;
65379f15823c34ae1e423108295e416213200bb280fAndreas Huber    int *lf_ref_frame_sign_bias;
65479f15823c34ae1e423108295e416213200bb280fAndreas Huber    int *lf_ref_frame;
655f71323e297a928af368937089d3ed71239786f86Andreas Huber
6561b362b15af34006e6a11974088a46d42b903418eJohann    /* force next frame to intra when kf_auto says so */
6571b362b15af34006e6a11974088a46d42b903418eJohann    int force_next_frame_intra;
6581b362b15af34006e6a11974088a46d42b903418eJohann
6591b362b15af34006e6a11974088a46d42b903418eJohann    int droppable;
6601b362b15af34006e6a11974088a46d42b903418eJohann
6611b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_TEMPORAL_DENOISING
6621b362b15af34006e6a11974088a46d42b903418eJohann    VP8_DENOISER denoiser;
66379f15823c34ae1e423108295e416213200bb280fAndreas Huber#endif
66490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6651b362b15af34006e6a11974088a46d42b903418eJohann    /* Coding layer state variables */
6661b362b15af34006e6a11974088a46d42b903418eJohann    unsigned int current_layer;
6671b362b15af34006e6a11974088a46d42b903418eJohann    LAYER_CONTEXT layer_context[VPX_TS_MAX_LAYERS];
6681b362b15af34006e6a11974088a46d42b903418eJohann
6691b362b15af34006e6a11974088a46d42b903418eJohann    int64_t frames_in_layer[VPX_TS_MAX_LAYERS];
6701b362b15af34006e6a11974088a46d42b903418eJohann    int64_t bytes_in_layer[VPX_TS_MAX_LAYERS];
6711b362b15af34006e6a11974088a46d42b903418eJohann    double sum_psnr[VPX_TS_MAX_LAYERS];
6721b362b15af34006e6a11974088a46d42b903418eJohann    double sum_psnr_p[VPX_TS_MAX_LAYERS];
6731b362b15af34006e6a11974088a46d42b903418eJohann    double total_error2[VPX_TS_MAX_LAYERS];
6741b362b15af34006e6a11974088a46d42b903418eJohann    double total_error2_p[VPX_TS_MAX_LAYERS];
6751b362b15af34006e6a11974088a46d42b903418eJohann    double sum_ssim[VPX_TS_MAX_LAYERS];
6761b362b15af34006e6a11974088a46d42b903418eJohann    double sum_weights[VPX_TS_MAX_LAYERS];
6771b362b15af34006e6a11974088a46d42b903418eJohann
6781b362b15af34006e6a11974088a46d42b903418eJohann    double total_ssimg_y_in_layer[VPX_TS_MAX_LAYERS];
6791b362b15af34006e6a11974088a46d42b903418eJohann    double total_ssimg_u_in_layer[VPX_TS_MAX_LAYERS];
6801b362b15af34006e6a11974088a46d42b903418eJohann    double total_ssimg_v_in_layer[VPX_TS_MAX_LAYERS];
6811b362b15af34006e6a11974088a46d42b903418eJohann    double total_ssimg_all_in_layer[VPX_TS_MAX_LAYERS];
6821b362b15af34006e6a11974088a46d42b903418eJohann
6831b362b15af34006e6a11974088a46d42b903418eJohann#if CONFIG_MULTI_RES_ENCODING
6841b362b15af34006e6a11974088a46d42b903418eJohann    /* Number of MBs per row at lower-resolution level */
6851b362b15af34006e6a11974088a46d42b903418eJohann    int    mr_low_res_mb_cols;
6861b362b15af34006e6a11974088a46d42b903418eJohann    /* Indicate if lower-res mv info is available */
6871b362b15af34006e6a11974088a46d42b903418eJohann    unsigned char  mr_low_res_mv_avail;
6881b362b15af34006e6a11974088a46d42b903418eJohann    /* The frame number of each reference frames */
6891b362b15af34006e6a11974088a46d42b903418eJohann    unsigned int current_ref_frames[MAX_REF_FRAMES];
6901b362b15af34006e6a11974088a46d42b903418eJohann#endif
69190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
6921b362b15af34006e6a11974088a46d42b903418eJohann    struct rd_costs_struct
6931b362b15af34006e6a11974088a46d42b903418eJohann    {
6941b362b15af34006e6a11974088a46d42b903418eJohann        int mvcosts[2][MVvals+1];
6951b362b15af34006e6a11974088a46d42b903418eJohann        int mvsadcosts[2][MVfpvals+1];
6961b362b15af34006e6a11974088a46d42b903418eJohann        int mbmode_cost[2][MB_MODE_COUNT];
6971b362b15af34006e6a11974088a46d42b903418eJohann        int intra_uv_mode_cost[2][MB_MODE_COUNT];
6981b362b15af34006e6a11974088a46d42b903418eJohann        int bmode_costs[10][10][10];
6991b362b15af34006e6a11974088a46d42b903418eJohann        int inter_bmode_costs[B_MODE_COUNT];
7001b362b15af34006e6a11974088a46d42b903418eJohann        int token_costs[BLOCK_TYPES][COEF_BANDS]
7011b362b15af34006e6a11974088a46d42b903418eJohann        [PREV_COEF_CONTEXTS][MAX_ENTROPY_TOKENS];
7021b362b15af34006e6a11974088a46d42b903418eJohann    } rd_costs;
7031b362b15af34006e6a11974088a46d42b903418eJohann} VP8_COMP;
70490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
705ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangvoid vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest,
706ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang                        unsigned char *dest_end, unsigned long *size);
70790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
7081b362b15af34006e6a11974088a46d42b903418eJohannvoid vp8_tokenize_mb(VP8_COMP *, MACROBLOCK *, TOKENEXTRA **);
70990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
71090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubervoid vp8_set_speed_features(VP8_COMP *cpi);
71190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber
71290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#if CONFIG_DEBUG
71390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define CHECK_MEM_ERROR(lval,expr) do {\
71490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        lval = (expr); \
71590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        if(!lval) \
71690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber            vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\
71790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber                               "Failed to allocate "#lval" at %s:%d", \
71890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber                               __FILE__,__LINE__);\
71990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    } while(0)
72090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#else
72190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#define CHECK_MEM_ERROR(lval,expr) do {\
72290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        lval = (expr); \
72390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber        if(!lval) \
72490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber            vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\
72590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber                               "Failed to allocate "#lval);\
72690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber    } while(0)
72790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
728b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#ifdef __cplusplus
729b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian}  // extern "C"
73090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#endif
731b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian
732b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian#endif  // VP8_ENCODER_ONYX_INT_H_
733