Home | History | Annotate | Download | only in encoder
      1 /*
      2  *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 
     12 #ifndef VP9_ENCODER_VP9_ONYX_INT_H_
     13 #define VP9_ENCODER_VP9_ONYX_INT_H_
     14 
     15 #include <stdio.h>
     16 #include "./vpx_config.h"
     17 #include "vp9/common/vp9_onyx.h"
     18 #include "vp9/encoder/vp9_treewriter.h"
     19 #include "vp9/encoder/vp9_tokenize.h"
     20 #include "vp9/common/vp9_onyxc_int.h"
     21 #include "vp9/encoder/vp9_variance.h"
     22 #include "vp9/encoder/vp9_encodemb.h"
     23 #include "vp9/encoder/vp9_quantize.h"
     24 #include "vp9/common/vp9_entropy.h"
     25 #include "vp9/common/vp9_entropymode.h"
     26 #include "vpx_ports/mem.h"
     27 #include "vpx/internal/vpx_codec_internal.h"
     28 #include "vp9/encoder/vp9_mcomp.h"
     29 #include "vp9/common/vp9_findnearmv.h"
     30 #include "vp9/encoder/vp9_lookahead.h"
     31 
     32 #define DISABLE_RC_LONG_TERM_MEM 0
     33 
     34 // #define MODE_TEST_HIT_STATS
     35 
     36 // #define SPEEDSTATS 1
     37 #if CONFIG_MULTIPLE_ARF
     38 // Set MIN_GF_INTERVAL to 1 for the full decomposition.
     39 #define MIN_GF_INTERVAL             2
     40 #else
     41 #define MIN_GF_INTERVAL             4
     42 #endif
     43 #define DEFAULT_GF_INTERVAL         7
     44 
     45 #define KEY_FRAME_CONTEXT 5
     46 
     47 #define MAX_MODES 30
     48 #define MAX_REFS  6
     49 
     50 #define MIN_THRESHMULT  32
     51 #define MAX_THRESHMULT  512
     52 
     53 #define GF_ZEROMV_ZBIN_BOOST 0
     54 #define LF_ZEROMV_ZBIN_BOOST 0
     55 #define MV_ZBIN_BOOST        0
     56 #define SPLIT_MV_ZBIN_BOOST  0
     57 #define INTRA_ZBIN_BOOST     0
     58 
     59 typedef struct {
     60   int nmvjointcost[MV_JOINTS];
     61   int nmvcosts[2][MV_VALS];
     62   int nmvcosts_hp[2][MV_VALS];
     63 
     64   vp9_prob segment_pred_probs[PREDICTION_PROBS];
     65 
     66   unsigned char *last_frame_seg_map_copy;
     67 
     68   // 0 = Intra, Last, GF, ARF
     69   signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];
     70   // 0 = ZERO_MV, MV
     71   signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
     72 
     73   int inter_mode_counts[INTER_MODE_CONTEXTS][INTER_MODES - 1][2];
     74   FRAME_CONTEXT fc;
     75 } CODING_CONTEXT;
     76 
     77 typedef struct {
     78   double frame;
     79   double intra_error;
     80   double coded_error;
     81   double sr_coded_error;
     82   double ssim_weighted_pred_err;
     83   double pcnt_inter;
     84   double pcnt_motion;
     85   double pcnt_second_ref;
     86   double pcnt_neutral;
     87   double MVr;
     88   double mvr_abs;
     89   double MVc;
     90   double mvc_abs;
     91   double MVrv;
     92   double MVcv;
     93   double mv_in_out_count;
     94   double new_mv_count;
     95   double duration;
     96   double count;
     97 } FIRSTPASS_STATS;
     98 
     99 typedef struct {
    100   int frames_so_far;
    101   double frame_intra_error;
    102   double frame_coded_error;
    103   double frame_pcnt_inter;
    104   double frame_pcnt_motion;
    105   double frame_mvr;
    106   double frame_mvr_abs;
    107   double frame_mvc;
    108   double frame_mvc_abs;
    109 } ONEPASS_FRAMESTATS;
    110 
    111 typedef struct {
    112   struct {
    113     int err;
    114     union {
    115       int_mv mv;
    116       MB_PREDICTION_MODE mode;
    117     } m;
    118   } ref[MAX_REF_FRAMES];
    119 } MBGRAPH_MB_STATS;
    120 
    121 typedef struct {
    122   MBGRAPH_MB_STATS *mb_stats;
    123 } MBGRAPH_FRAME_STATS;
    124 
    125 // This enumerator type needs to be kept aligned with the mode order in
    126 // const MODE_DEFINITION vp9_mode_order[MAX_MODES] used in the rd code.
    127 typedef enum {
    128   THR_NEARESTMV,
    129   THR_NEARESTA,
    130   THR_NEARESTG,
    131 
    132   THR_DC,
    133 
    134   THR_NEWMV,
    135   THR_NEWA,
    136   THR_NEWG,
    137 
    138   THR_NEARMV,
    139   THR_NEARA,
    140   THR_COMP_NEARESTLA,
    141   THR_COMP_NEARESTGA,
    142 
    143   THR_TM,
    144 
    145   THR_COMP_NEARLA,
    146   THR_COMP_NEWLA,
    147   THR_NEARG,
    148   THR_COMP_NEARGA,
    149   THR_COMP_NEWGA,
    150 
    151   THR_ZEROMV,
    152   THR_ZEROG,
    153   THR_ZEROA,
    154   THR_COMP_ZEROLA,
    155   THR_COMP_ZEROGA,
    156 
    157   THR_H_PRED,
    158   THR_V_PRED,
    159   THR_D135_PRED,
    160   THR_D207_PRED,
    161   THR_D153_PRED,
    162   THR_D63_PRED,
    163   THR_D117_PRED,
    164   THR_D45_PRED,
    165 } THR_MODES;
    166 
    167 typedef enum {
    168   THR_LAST,
    169   THR_GOLD,
    170   THR_ALTR,
    171   THR_COMP_LA,
    172   THR_COMP_GA,
    173   THR_INTRA,
    174 } THR_MODES_SUB8X8;
    175 
    176 typedef enum {
    177   DIAMOND = 0,
    178   NSTEP = 1,
    179   HEX = 2,
    180   BIGDIA = 3,
    181   SQUARE = 4
    182 } SEARCH_METHODS;
    183 
    184 typedef enum {
    185   USE_FULL_RD = 0,
    186   USE_LARGESTINTRA,
    187   USE_LARGESTINTRA_MODELINTER,
    188   USE_LARGESTALL
    189 } TX_SIZE_SEARCH_METHOD;
    190 
    191 typedef enum {
    192   // Values should be powers of 2 so that they can be selected as bits of
    193   // an integer flags field
    194 
    195   // terminate search early based on distortion so far compared to
    196   // qp step, distortion in the neighborhood of the frame, etc.
    197   FLAG_EARLY_TERMINATE = 1,
    198 
    199   // skips comp inter modes if the best so far is an intra mode
    200   FLAG_SKIP_COMP_BESTINTRA = 2,
    201 
    202   // skips comp inter modes if the best single intermode so far does
    203   // not have the same reference as one of the two references being
    204   // tested
    205   FLAG_SKIP_COMP_REFMISMATCH = 4,
    206 
    207   // skips oblique intra modes if the best so far is an inter mode
    208   FLAG_SKIP_INTRA_BESTINTER = 8,
    209 
    210   // skips oblique intra modes  at angles 27, 63, 117, 153 if the best
    211   // intra so far is not one of the neighboring directions
    212   FLAG_SKIP_INTRA_DIRMISMATCH = 16,
    213 
    214   // skips intra modes other than DC_PRED if the source variance
    215   // is small
    216   FLAG_SKIP_INTRA_LOWVAR = 32,
    217 } MODE_SEARCH_SKIP_LOGIC;
    218 
    219 typedef enum {
    220   SUBPEL_ITERATIVE = 0,
    221   SUBPEL_TREE = 1,
    222   // Other methods to come
    223 } SUBPEL_SEARCH_METHODS;
    224 
    225 #define ALL_INTRA_MODES 0x3FF
    226 #define INTRA_DC_ONLY 0x01
    227 #define INTRA_DC_TM ((1 << TM_PRED) | (1 << DC_PRED))
    228 #define INTRA_DC_H_V ((1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED))
    229 #define INTRA_DC_TM_H_V (INTRA_DC_TM | (1 << V_PRED) | (1 << H_PRED))
    230 
    231 typedef enum {
    232   LAST_FRAME_PARTITION_OFF = 0,
    233   LAST_FRAME_PARTITION_LOW_MOTION = 1,
    234   LAST_FRAME_PARTITION_ALL = 2
    235 } LAST_FRAME_PARTITION_METHOD;
    236 
    237 typedef struct {
    238   int RD;
    239   SEARCH_METHODS search_method;
    240   int auto_filter;
    241   int recode_loop;
    242   SUBPEL_SEARCH_METHODS subpel_search_method;
    243   int subpel_iters_per_step;
    244   int thresh_mult[MAX_MODES];
    245   int thresh_mult_sub8x8[MAX_REFS];
    246   int max_step_search_steps;
    247   int reduce_first_step_size;
    248   int auto_mv_step_size;
    249   int optimize_coefficients;
    250   int static_segmentation;
    251   int variance_adaptive_quantization;
    252   int comp_inter_joint_search_thresh;
    253   int adaptive_rd_thresh;
    254   int skip_encode_sb;
    255   int skip_encode_frame;
    256   LAST_FRAME_PARTITION_METHOD use_lastframe_partitioning;
    257   TX_SIZE_SEARCH_METHOD tx_size_search_method;
    258   int use_lp32x32fdct;
    259   int use_avoid_tested_higherror;
    260   int use_one_partition_size_always;
    261   int less_rectangular_check;
    262   int use_square_partition_only;
    263   int mode_skip_start;
    264   int reference_masking;
    265   BLOCK_SIZE always_this_block_size;
    266   int auto_min_max_partition_size;
    267   BLOCK_SIZE min_partition_size;
    268   BLOCK_SIZE max_partition_size;
    269   int adjust_partitioning_from_last_frame;
    270   int last_partitioning_redo_frequency;
    271   int disable_split_mask;
    272   int using_small_partition_info;
    273   // TODO(jingning): combine the related motion search speed features
    274   int adaptive_motion_search;
    275 
    276   // Implements various heuristics to skip searching modes
    277   // The heuristics selected are based on  flags
    278   // defined in the MODE_SEARCH_SKIP_HEURISTICS enum
    279   unsigned int mode_search_skip_flags;
    280   // A source variance threshold below which the split mode is disabled
    281   unsigned int disable_split_var_thresh;
    282   // A source variance threshold below which filter search is disabled
    283   // Choose a very large value (UINT_MAX) to use 8-tap always
    284   unsigned int disable_filter_search_var_thresh;
    285   int intra_y_mode_mask[TX_SIZES];
    286   int intra_uv_mode_mask[TX_SIZES];
    287   int use_rd_breakout;
    288   int use_uv_intra_rd_estimate;
    289   int use_fast_lpf_pick;
    290   int use_fast_coef_updates;  // 0: 2-loop, 1: 1-loop, 2: 1-loop reduced
    291 } SPEED_FEATURES;
    292 
    293 typedef struct VP9_COMP {
    294   DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE][8]);
    295   DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE][8]);
    296   DECLARE_ALIGNED(16, int16_t, y_zbin[QINDEX_RANGE][8]);
    297   DECLARE_ALIGNED(16, int16_t, y_round[QINDEX_RANGE][8]);
    298 
    299   DECLARE_ALIGNED(16, int16_t, uv_quant[QINDEX_RANGE][8]);
    300   DECLARE_ALIGNED(16, int16_t, uv_quant_shift[QINDEX_RANGE][8]);
    301   DECLARE_ALIGNED(16, int16_t, uv_zbin[QINDEX_RANGE][8]);
    302   DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE][8]);
    303 
    304 #if CONFIG_ALPHA
    305   DECLARE_ALIGNED(16, int16_t, a_quant[QINDEX_RANGE][8]);
    306   DECLARE_ALIGNED(16, int16_t, a_quant_shift[QINDEX_RANGE][8]);
    307   DECLARE_ALIGNED(16, int16_t, a_zbin[QINDEX_RANGE][8]);
    308   DECLARE_ALIGNED(16, int16_t, a_round[QINDEX_RANGE][8]);
    309 #endif
    310 
    311   MACROBLOCK mb;
    312   VP9_COMMON common;
    313   VP9_CONFIG oxcf;
    314   struct rdcost_block_args rdcost_stack;
    315   struct lookahead_ctx    *lookahead;
    316   struct lookahead_entry  *source;
    317 #if CONFIG_MULTIPLE_ARF
    318   struct lookahead_entry  *alt_ref_source[NUM_REF_FRAMES];
    319 #else
    320   struct lookahead_entry  *alt_ref_source;
    321 #endif
    322 
    323   YV12_BUFFER_CONFIG *Source;
    324   YV12_BUFFER_CONFIG *un_scaled_source;
    325   YV12_BUFFER_CONFIG scaled_source;
    326 
    327   unsigned int frames_till_alt_ref_frame;
    328   int source_alt_ref_pending;
    329   int source_alt_ref_active;
    330 
    331   int is_src_frame_alt_ref;
    332 
    333   int gold_is_last;  // gold same as last frame ( short circuit gold searches)
    334   int alt_is_last;  // Alt same as last ( short circuit altref search)
    335   int gold_is_alt;  // don't do both alt and gold search ( just do gold).
    336 
    337   int scaled_ref_idx[3];
    338   int lst_fb_idx;
    339   int gld_fb_idx;
    340   int alt_fb_idx;
    341 
    342   int current_layer;
    343   int use_svc;
    344 
    345 #if CONFIG_MULTIPLE_ARF
    346   int alt_ref_fb_idx[NUM_REF_FRAMES - 3];
    347 #endif
    348   int refresh_last_frame;
    349   int refresh_golden_frame;
    350   int refresh_alt_ref_frame;
    351   YV12_BUFFER_CONFIG last_frame_uf;
    352 
    353   TOKENEXTRA *tok;
    354   unsigned int tok_count[4][1 << 6];
    355 
    356 
    357   unsigned int frames_since_key;
    358   unsigned int key_frame_frequency;
    359   unsigned int this_key_frame_forced;
    360   unsigned int next_key_frame_forced;
    361 #if CONFIG_MULTIPLE_ARF
    362   // Position within a frame coding order (including any additional ARF frames).
    363   unsigned int sequence_number;
    364   // Next frame in naturally occurring order that has not yet been coded.
    365   int next_frame_in_order;
    366 #endif
    367 
    368   // Ambient reconstruction err target for force key frames
    369   int ambient_err;
    370 
    371   unsigned int mode_chosen_counts[MAX_MODES];
    372   unsigned int sub8x8_mode_chosen_counts[MAX_REFS];
    373   int64_t mode_skip_mask;
    374   int ref_frame_mask;
    375   int set_ref_frame_mask;
    376 
    377   int rd_threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
    378   int rd_thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
    379   int rd_thresh_sub8x8[MAX_SEGMENTS][BLOCK_SIZES][MAX_REFS];
    380   int rd_thresh_freq_sub8x8[BLOCK_SIZES][MAX_REFS];
    381 
    382   int64_t rd_comp_pred_diff[NB_PREDICTION_TYPES];
    383   int64_t rd_prediction_type_threshes[4][NB_PREDICTION_TYPES];
    384   unsigned int intra_inter_count[INTRA_INTER_CONTEXTS][2];
    385   unsigned int comp_inter_count[COMP_INTER_CONTEXTS][2];
    386   unsigned int single_ref_count[REF_CONTEXTS][2][2];
    387   unsigned int comp_ref_count[REF_CONTEXTS][2];
    388 
    389   int64_t rd_tx_select_diff[TX_MODES];
    390   // FIXME(rbultje) can this overflow?
    391   int rd_tx_select_threshes[4][TX_MODES];
    392 
    393   int64_t rd_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
    394   int64_t rd_filter_threshes[4][SWITCHABLE_FILTER_CONTEXTS];
    395   int64_t rd_filter_cache[SWITCHABLE_FILTER_CONTEXTS];
    396 
    397   int RDMULT;
    398   int RDDIV;
    399 
    400   CODING_CONTEXT coding_context;
    401 
    402   // Rate targetting variables
    403   int this_frame_target;
    404   int projected_frame_size;
    405   int last_q[2];                   // Separate values for Intra/Inter
    406   int last_boosted_qindex;         // Last boosted GF/KF/ARF q
    407 
    408   double rate_correction_factor;
    409   double key_frame_rate_correction_factor;
    410   double gf_rate_correction_factor;
    411 
    412   unsigned int frames_since_golden;
    413   int frames_till_gf_update_due;  // Count down till next GF
    414 
    415   int gf_overspend_bits;  // cumulative bits overspent because of GF boost
    416 
    417   int non_gf_bitrate_adjustment;  // Following GF to recover extra bits spent
    418 
    419   int kf_overspend_bits;  // Bits spent on key frames to be recovered on inters
    420   int kf_bitrate_adjustment;  // number of bits to recover on each inter frame.
    421   int max_gf_interval;
    422   int baseline_gf_interval;
    423   int active_arnr_frames;           // <= cpi->oxcf.arnr_max_frames
    424   int active_arnr_strength;         // <= cpi->oxcf.arnr_max_strength
    425 
    426   int64_t key_frame_count;
    427   int prior_key_frame_distance[KEY_FRAME_CONTEXT];
    428   int per_frame_bandwidth;  // Current section per frame bandwidth target
    429   int av_per_frame_bandwidth;  // Average frame size target for clip
    430   int min_frame_bandwidth;  // Minimum allocation used for any frame
    431   int inter_frame_target;
    432   double output_framerate;
    433   int64_t last_time_stamp_seen;
    434   int64_t last_end_time_stamp_seen;
    435   int64_t first_time_stamp_ever;
    436 
    437   int ni_av_qi;
    438   int ni_tot_qi;
    439   int ni_frames;
    440   int avg_frame_qindex;
    441   double tot_q;
    442   double avg_q;
    443 
    444   int zbin_mode_boost;
    445   int zbin_mode_boost_enabled;
    446 
    447   int64_t total_byte_count;
    448 
    449   int buffered_mode;
    450 
    451   int buffer_level;
    452   int bits_off_target;
    453 
    454   int rolling_target_bits;
    455   int rolling_actual_bits;
    456 
    457   int long_rolling_target_bits;
    458   int long_rolling_actual_bits;
    459 
    460   int64_t total_actual_bits;
    461   int total_target_vs_actual;        // debug stats
    462 
    463   int worst_quality;
    464   int active_worst_quality;
    465   int best_quality;
    466   int active_best_quality;
    467 
    468   int cq_target_quality;
    469 
    470   int y_mode_count[4][INTRA_MODES];
    471   int y_uv_mode_count[INTRA_MODES][INTRA_MODES];
    472   unsigned int partition_count[PARTITION_CONTEXTS][PARTITION_TYPES];
    473 
    474   nmv_context_counts NMVcount;
    475 
    476   vp9_coeff_count coef_counts[TX_SIZES][BLOCK_TYPES];
    477   vp9_coeff_probs_model frame_coef_probs[TX_SIZES][BLOCK_TYPES];
    478   vp9_coeff_stats frame_branch_ct[TX_SIZES][BLOCK_TYPES];
    479 
    480   int gfu_boost;
    481   int last_boost;
    482   int kf_boost;
    483   int kf_zeromotion_pct;
    484   int gf_zeromotion_pct;
    485 
    486   int64_t target_bandwidth;
    487   struct vpx_codec_pkt_list  *output_pkt_list;
    488 
    489 #if 0
    490   // Experimental code for lagged and one pass
    491   ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS];
    492   int one_pass_frame_index;
    493 #endif
    494   MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
    495   int mbgraph_n_frames;             // number of frames filled in the above
    496   int static_mb_pct;                // % forced skip mbs by segmentation
    497   int seg0_progress, seg0_idx, seg0_cnt;
    498 
    499   int decimation_factor;
    500   int decimation_count;
    501 
    502   // for real time encoding
    503   int speed;
    504   int compressor_speed;
    505 
    506   int auto_worst_q;
    507   int cpu_used;
    508   int pass;
    509 
    510   vp9_prob last_skip_false_probs[3][MBSKIP_CONTEXTS];
    511   int last_skip_probs_q[3];
    512 
    513   int ref_frame_flags;
    514 
    515   SPEED_FEATURES sf;
    516   int error_bins[1024];
    517 
    518   unsigned int max_mv_magnitude;
    519   int mv_step_param;
    520 
    521   unsigned char *segmentation_map;
    522 
    523   // segment threashold for encode breakout
    524   int  segment_encode_breakout[MAX_SEGMENTS];
    525 
    526   unsigned char *active_map;
    527   unsigned int active_map_enabled;
    528 
    529   fractional_mv_step_fp *find_fractional_mv_step;
    530   fractional_mv_step_comp_fp *find_fractional_mv_step_comp;
    531   vp9_full_search_fn_t full_search_sad;
    532   vp9_refining_search_fn_t refining_search_sad;
    533   vp9_diamond_search_fn_t diamond_search_sad;
    534   vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
    535   uint64_t time_receive_data;
    536   uint64_t time_compress_data;
    537   uint64_t time_pick_lpf;
    538   uint64_t time_encode_sb_row;
    539 
    540   struct twopass_rc {
    541     unsigned int section_intra_rating;
    542     unsigned int next_iiratio;
    543     unsigned int this_iiratio;
    544     FIRSTPASS_STATS total_stats;
    545     FIRSTPASS_STATS this_frame_stats;
    546     FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
    547     FIRSTPASS_STATS total_left_stats;
    548     int first_pass_done;
    549     int64_t bits_left;
    550     int64_t clip_bits_total;
    551     double avg_iiratio;
    552     double modified_error_total;
    553     double modified_error_used;
    554     double modified_error_left;
    555     double kf_intra_err_min;
    556     double gf_intra_err_min;
    557     int frames_to_key;
    558     int maxq_max_limit;
    559     int maxq_min_limit;
    560     int static_scene_max_gf_interval;
    561     int kf_bits;
    562     // Remaining error from uncoded frames in a gf group. Two pass use only
    563     int64_t gf_group_error_left;
    564 
    565     // Projected total bits available for a key frame group of frames
    566     int64_t kf_group_bits;
    567 
    568     // Error score of frames still to be coded in kf group
    569     int64_t kf_group_error_left;
    570 
    571     // Projected Bits available for a group of frames including 1 GF or ARF
    572     int64_t gf_group_bits;
    573     // Bits for the golden frame or ARF - 2 pass only
    574     int gf_bits;
    575     int alt_extra_bits;
    576 
    577     int sr_update_lag;
    578     double est_max_qcorrection_factor;
    579   } twopass;
    580 
    581   YV12_BUFFER_CONFIG alt_ref_buffer;
    582   YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
    583   int fixed_divide[512];
    584 
    585 #if CONFIG_INTERNAL_STATS
    586   int    count;
    587   double total_y;
    588   double total_u;
    589   double total_v;
    590   double total;
    591   double total_sq_error;
    592   double totalp_y;
    593   double totalp_u;
    594   double totalp_v;
    595   double totalp;
    596   double total_sq_error2;
    597   int    bytes;
    598   double summed_quality;
    599   double summed_weights;
    600   double summedp_quality;
    601   double summedp_weights;
    602   unsigned int tot_recode_hits;
    603 
    604 
    605   double total_ssimg_y;
    606   double total_ssimg_u;
    607   double total_ssimg_v;
    608   double total_ssimg_all;
    609 
    610   int b_calculate_ssimg;
    611 #endif
    612   int b_calculate_psnr;
    613 
    614   // Per MB activity measurement
    615   unsigned int activity_avg;
    616   unsigned int *mb_activity_map;
    617   int *mb_norm_activity_map;
    618   int output_partition;
    619 
    620   /* force next frame to intra when kf_auto says so */
    621   int force_next_frame_intra;
    622 
    623   int droppable;
    624 
    625   int dummy_packing;    /* flag to indicate if packing is dummy */
    626 
    627   unsigned int switchable_interp_count[SWITCHABLE_FILTER_CONTEXTS]
    628                                       [SWITCHABLE_FILTERS];
    629 
    630   unsigned int tx_stepdown_count[TX_SIZES];
    631 
    632   int initial_width;
    633   int initial_height;
    634 
    635   int number_spatial_layers;
    636   int enable_encode_breakout;   // Default value is 1. From first pass stats,
    637                                 // encode_breakout may be disabled.
    638 
    639 #if CONFIG_MULTIPLE_ARF
    640   // ARF tracking variables.
    641   int multi_arf_enabled;
    642   unsigned int frame_coding_order_period;
    643   unsigned int new_frame_coding_order_period;
    644   int frame_coding_order[MAX_LAG_BUFFERS * 2];
    645   int arf_buffer_idx[MAX_LAG_BUFFERS * 3 / 2];
    646   int arf_weight[MAX_LAG_BUFFERS];
    647   int arf_buffered;
    648   int this_frame_weight;
    649   int max_arf_level;
    650 #endif
    651 
    652 #ifdef ENTROPY_STATS
    653   int64_t mv_ref_stats[INTER_MODE_CONTEXTS][INTER_MODES - 1][2];
    654 #endif
    655 
    656 
    657 #ifdef MODE_TEST_HIT_STATS
    658   // Debug / test stats
    659   int64_t mode_test_hits[BLOCK_SIZES];
    660 #endif
    661 
    662   /* Y,U,V,(A) */
    663   ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
    664   ENTROPY_CONTEXT left_context[MAX_MB_PLANE][16];
    665 
    666   PARTITION_CONTEXT *above_seg_context;
    667   PARTITION_CONTEXT left_seg_context[8];
    668 } VP9_COMP;
    669 
    670 static int get_ref_frame_idx(VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
    671   if (ref_frame == LAST_FRAME) {
    672     return cpi->lst_fb_idx;
    673   } else if (ref_frame == GOLDEN_FRAME) {
    674     return cpi->gld_fb_idx;
    675   } else {
    676     return cpi->alt_fb_idx;
    677   }
    678 }
    679 
    680 static int get_scale_ref_frame_idx(VP9_COMP *cpi,
    681                                    MV_REFERENCE_FRAME ref_frame) {
    682   if (ref_frame == LAST_FRAME) {
    683     return 0;
    684   } else if (ref_frame == GOLDEN_FRAME) {
    685     return 1;
    686   } else {
    687     return 2;
    688   }
    689 }
    690 
    691 void vp9_encode_frame(VP9_COMP *cpi);
    692 
    693 void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest,
    694                         unsigned long *size);
    695 
    696 void vp9_activity_masking(VP9_COMP *cpi, MACROBLOCK *x);
    697 
    698 void vp9_set_speed_features(VP9_COMP *cpi);
    699 
    700 int vp9_calc_ss_err(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest);
    701 
    702 void vp9_alloc_compressor_data(VP9_COMP *cpi);
    703 
    704 int vp9_compute_qdelta(VP9_COMP *cpi, double qstart, double qtarget);
    705 
    706 static int get_token_alloc(int mb_rows, int mb_cols) {
    707   return mb_rows * mb_cols * (48 * 16 + 4);
    708 }
    709 
    710 #endif  // VP9_ENCODER_VP9_ONYX_INT_H_
    711