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