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 #ifndef VP8_ENCODER_ONYX_INT_H_
     12 #define VP8_ENCODER_ONYX_INT_H_
     13 
     14 #include <stdio.h>
     15 #include "vpx_config.h"
     16 #include "vp8/common/onyx.h"
     17 #include "treewriter.h"
     18 #include "tokenize.h"
     19 #include "vp8/common/onyxc_int.h"
     20 #include "vpx_dsp/variance.h"
     21 #include "encodemb.h"
     22 #include "vp8/encoder/quantize.h"
     23 #include "vp8/common/entropy.h"
     24 #include "vp8/common/threading.h"
     25 #include "vpx_ports/mem.h"
     26 #include "vpx/internal/vpx_codec_internal.h"
     27 #include "vpx/vp8.h"
     28 #include "mcomp.h"
     29 #include "vp8/common/findnearmv.h"
     30 #include "lookahead.h"
     31 #if CONFIG_TEMPORAL_DENOISING
     32 #include "vp8/encoder/denoising.h"
     33 #endif
     34 
     35 #ifdef __cplusplus
     36 extern "C" {
     37 #endif
     38 
     39 #define MIN_GF_INTERVAL 4
     40 #define DEFAULT_GF_INTERVAL 7
     41 
     42 #define KEY_FRAME_CONTEXT 5
     43 
     44 #define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY ? 1 : 25)
     45 
     46 #define AF_THRESH 25
     47 #define AF_THRESH2 100
     48 #define ARF_DECAY_THRESH 12
     49 
     50 #define MIN_THRESHMULT 32
     51 #define MAX_THRESHMULT 512
     52 
     53 #define GF_ZEROMV_ZBIN_BOOST 12
     54 #define LF_ZEROMV_ZBIN_BOOST 6
     55 #define MV_ZBIN_BOOST 4
     56 #define ZBIN_OQ_MAX 192
     57 
     58 #define VP8_TEMPORAL_ALT_REF !CONFIG_REALTIME_ONLY
     59 
     60 typedef struct {
     61   int kf_indicated;
     62   unsigned int frames_since_key;
     63   unsigned int frames_since_golden;
     64   int filter_level;
     65   int frames_till_gf_update_due;
     66   int recent_ref_frame_usage[MAX_REF_FRAMES];
     67 
     68   MV_CONTEXT mvc[2];
     69   int mvcosts[2][MVvals + 1];
     70 
     71 #ifdef MODE_STATS
     72   int y_modes[5];
     73   int uv_modes[4];
     74   int b_modes[10];
     75   int inter_y_modes[10];
     76   int inter_uv_modes[4];
     77   int inter_b_modes[10];
     78 #endif
     79 
     80   vp8_prob ymode_prob[4], uv_mode_prob[3]; /* interframe intra mode probs */
     81   vp8_prob kf_ymode_prob[4], kf_uv_mode_prob[3]; /* keyframe "" */
     82 
     83   int ymode_count[5], uv_mode_count[4]; /* intra MB type cts this frame */
     84 
     85   int count_mb_ref_frame_usage[MAX_REF_FRAMES];
     86 
     87   int this_frame_percent_intra;
     88   int last_frame_percent_intra;
     89 
     90 } CODING_CONTEXT;
     91 
     92 typedef struct {
     93   double frame;
     94   double intra_error;
     95   double coded_error;
     96   double ssim_weighted_pred_err;
     97   double pcnt_inter;
     98   double pcnt_motion;
     99   double pcnt_second_ref;
    100   double pcnt_neutral;
    101   double MVr;
    102   double mvr_abs;
    103   double MVc;
    104   double mvc_abs;
    105   double MVrv;
    106   double MVcv;
    107   double mv_in_out_count;
    108   double new_mv_count;
    109   double duration;
    110   double count;
    111 } FIRSTPASS_STATS;
    112 
    113 typedef struct {
    114   int frames_so_far;
    115   double frame_intra_error;
    116   double frame_coded_error;
    117   double frame_pcnt_inter;
    118   double frame_pcnt_motion;
    119   double frame_mvr;
    120   double frame_mvr_abs;
    121   double frame_mvc;
    122   double frame_mvc_abs;
    123 
    124 } ONEPASS_FRAMESTATS;
    125 
    126 typedef enum {
    127   THR_ZERO1 = 0,
    128   THR_DC = 1,
    129 
    130   THR_NEAREST1 = 2,
    131   THR_NEAR1 = 3,
    132 
    133   THR_ZERO2 = 4,
    134   THR_NEAREST2 = 5,
    135 
    136   THR_ZERO3 = 6,
    137   THR_NEAREST3 = 7,
    138 
    139   THR_NEAR2 = 8,
    140   THR_NEAR3 = 9,
    141 
    142   THR_V_PRED = 10,
    143   THR_H_PRED = 11,
    144   THR_TM = 12,
    145 
    146   THR_NEW1 = 13,
    147   THR_NEW2 = 14,
    148   THR_NEW3 = 15,
    149 
    150   THR_SPLIT1 = 16,
    151   THR_SPLIT2 = 17,
    152   THR_SPLIT3 = 18,
    153 
    154   THR_B_PRED = 19
    155 } THR_MODES;
    156 
    157 typedef enum { DIAMOND = 0, NSTEP = 1, HEX = 2 } SEARCH_METHODS;
    158 
    159 typedef struct {
    160   int RD;
    161   SEARCH_METHODS search_method;
    162   int improved_quant;
    163   int improved_dct;
    164   int auto_filter;
    165   int recode_loop;
    166   int iterative_sub_pixel;
    167   int half_pixel_search;
    168   int quarter_pixel_search;
    169   int thresh_mult[MAX_MODES];
    170   int max_step_search_steps;
    171   int first_step;
    172   int optimize_coefficients;
    173 
    174   int use_fastquant_for_pick;
    175   int no_skip_block4x4_search;
    176   int improved_mv_pred;
    177 
    178 } SPEED_FEATURES;
    179 
    180 typedef struct {
    181   MACROBLOCK mb;
    182   int segment_counts[MAX_MB_SEGMENTS];
    183   int totalrate;
    184 } MB_ROW_COMP;
    185 
    186 typedef struct {
    187   TOKENEXTRA *start;
    188   TOKENEXTRA *stop;
    189 } TOKENLIST;
    190 
    191 typedef struct {
    192   int ithread;
    193   void *ptr1;
    194   void *ptr2;
    195 } ENCODETHREAD_DATA;
    196 typedef struct {
    197   int ithread;
    198   void *ptr1;
    199 } LPFTHREAD_DATA;
    200 
    201 enum {
    202   BLOCK_16X8,
    203   BLOCK_8X16,
    204   BLOCK_8X8,
    205   BLOCK_4X4,
    206   BLOCK_16X16,
    207   BLOCK_MAX_SEGMENTS
    208 };
    209 
    210 typedef struct {
    211   /* Layer configuration */
    212   double framerate;
    213   int target_bandwidth;
    214 
    215   /* Layer specific coding parameters */
    216   int64_t starting_buffer_level;
    217   int64_t optimal_buffer_level;
    218   int64_t maximum_buffer_size;
    219   int64_t starting_buffer_level_in_ms;
    220   int64_t optimal_buffer_level_in_ms;
    221   int64_t maximum_buffer_size_in_ms;
    222 
    223   int avg_frame_size_for_layer;
    224 
    225   int64_t buffer_level;
    226   int64_t bits_off_target;
    227 
    228   int64_t total_actual_bits;
    229   int total_target_vs_actual;
    230 
    231   int worst_quality;
    232   int active_worst_quality;
    233   int best_quality;
    234   int active_best_quality;
    235 
    236   int ni_av_qi;
    237   int ni_tot_qi;
    238   int ni_frames;
    239   int avg_frame_qindex;
    240 
    241   double rate_correction_factor;
    242   double key_frame_rate_correction_factor;
    243   double gf_rate_correction_factor;
    244 
    245   int zbin_over_quant;
    246 
    247   int inter_frame_target;
    248   int64_t total_byte_count;
    249 
    250   int filter_level;
    251 
    252   int frames_since_last_drop_overshoot;
    253 
    254   int force_maxqp;
    255 
    256   int last_frame_percent_intra;
    257 
    258   int count_mb_ref_frame_usage[MAX_REF_FRAMES];
    259 
    260 } LAYER_CONTEXT;
    261 
    262 typedef struct VP8_COMP {
    263   DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]);
    264   DECLARE_ALIGNED(16, short, Y1quant_shift[QINDEX_RANGE][16]);
    265   DECLARE_ALIGNED(16, short, Y1zbin[QINDEX_RANGE][16]);
    266   DECLARE_ALIGNED(16, short, Y1round[QINDEX_RANGE][16]);
    267 
    268   DECLARE_ALIGNED(16, short, Y2quant[QINDEX_RANGE][16]);
    269   DECLARE_ALIGNED(16, short, Y2quant_shift[QINDEX_RANGE][16]);
    270   DECLARE_ALIGNED(16, short, Y2zbin[QINDEX_RANGE][16]);
    271   DECLARE_ALIGNED(16, short, Y2round[QINDEX_RANGE][16]);
    272 
    273   DECLARE_ALIGNED(16, short, UVquant[QINDEX_RANGE][16]);
    274   DECLARE_ALIGNED(16, short, UVquant_shift[QINDEX_RANGE][16]);
    275   DECLARE_ALIGNED(16, short, UVzbin[QINDEX_RANGE][16]);
    276   DECLARE_ALIGNED(16, short, UVround[QINDEX_RANGE][16]);
    277 
    278   DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1[QINDEX_RANGE][16]);
    279   DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2[QINDEX_RANGE][16]);
    280   DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv[QINDEX_RANGE][16]);
    281   DECLARE_ALIGNED(16, short, Y1quant_fast[QINDEX_RANGE][16]);
    282   DECLARE_ALIGNED(16, short, Y2quant_fast[QINDEX_RANGE][16]);
    283   DECLARE_ALIGNED(16, short, UVquant_fast[QINDEX_RANGE][16]);
    284 
    285   MACROBLOCK mb;
    286   VP8_COMMON common;
    287   vp8_writer bc[9]; /* one boolcoder for each partition */
    288 
    289   VP8_CONFIG oxcf;
    290 
    291   struct lookahead_ctx *lookahead;
    292   struct lookahead_entry *source;
    293   struct lookahead_entry *alt_ref_source;
    294   struct lookahead_entry *last_source;
    295 
    296   YV12_BUFFER_CONFIG *Source;
    297   YV12_BUFFER_CONFIG *un_scaled_source;
    298   YV12_BUFFER_CONFIG scaled_source;
    299   YV12_BUFFER_CONFIG *last_frame_unscaled_source;
    300 
    301   unsigned int frames_till_alt_ref_frame;
    302   /* frame in src_buffers has been identified to be encoded as an alt ref */
    303   int source_alt_ref_pending;
    304   /* an alt ref frame has been encoded and is usable */
    305   int source_alt_ref_active;
    306   /* source of frame to encode is an exact copy of an alt ref frame */
    307   int is_src_frame_alt_ref;
    308 
    309   /* golden frame same as last frame ( short circuit gold searches) */
    310   int gold_is_last;
    311   /* Alt reference frame same as last ( short circuit altref search) */
    312   int alt_is_last;
    313   /* don't do both alt and gold search ( just do gold). */
    314   int gold_is_alt;
    315 
    316   YV12_BUFFER_CONFIG pick_lf_lvl_frame;
    317 
    318   TOKENEXTRA *tok;
    319   unsigned int tok_count;
    320 
    321   unsigned int frames_since_key;
    322   unsigned int key_frame_frequency;
    323   unsigned int this_key_frame_forced;
    324   unsigned int next_key_frame_forced;
    325 
    326   /* Ambient reconstruction err target for force key frames */
    327   int ambient_err;
    328 
    329   unsigned int mode_check_freq[MAX_MODES];
    330 
    331   int rd_baseline_thresh[MAX_MODES];
    332 
    333   int RDMULT;
    334   int RDDIV;
    335 
    336   CODING_CONTEXT coding_context;
    337 
    338   /* Rate targetting variables */
    339   int64_t last_prediction_error;
    340   int64_t last_intra_error;
    341 
    342   int this_frame_target;
    343   int projected_frame_size;
    344   int last_q[2]; /* Separate values for Intra/Inter */
    345 
    346   double rate_correction_factor;
    347   double key_frame_rate_correction_factor;
    348   double gf_rate_correction_factor;
    349 
    350   int frames_since_golden;
    351   /* Count down till next GF */
    352   int frames_till_gf_update_due;
    353 
    354   /* GF interval chosen when we coded the last GF */
    355   int current_gf_interval;
    356 
    357   /* Total bits overspent becasue of GF boost (cumulative) */
    358   int gf_overspend_bits;
    359 
    360   /* Used in the few frames following a GF to recover the extra bits
    361    * spent in that GF
    362    */
    363   int non_gf_bitrate_adjustment;
    364 
    365   /* Extra bits spent on key frames that need to be recovered */
    366   int kf_overspend_bits;
    367 
    368   /* Current number of bit s to try and recover on each inter frame. */
    369   int kf_bitrate_adjustment;
    370   int max_gf_interval;
    371   int baseline_gf_interval;
    372   int active_arnr_frames;
    373 
    374   int64_t key_frame_count;
    375   int prior_key_frame_distance[KEY_FRAME_CONTEXT];
    376   /* Current section per frame bandwidth target */
    377   int per_frame_bandwidth;
    378   /* Average frame size target for clip */
    379   int av_per_frame_bandwidth;
    380   /* Minimum allocation that should be used for any frame */
    381   int min_frame_bandwidth;
    382   int inter_frame_target;
    383   double output_framerate;
    384   int64_t last_time_stamp_seen;
    385   int64_t last_end_time_stamp_seen;
    386   int64_t first_time_stamp_ever;
    387 
    388   int ni_av_qi;
    389   int ni_tot_qi;
    390   int ni_frames;
    391   int avg_frame_qindex;
    392 
    393   int64_t total_byte_count;
    394 
    395   int buffered_mode;
    396 
    397   double framerate;
    398   double ref_framerate;
    399   int64_t buffer_level;
    400   int64_t bits_off_target;
    401 
    402   int rolling_target_bits;
    403   int rolling_actual_bits;
    404 
    405   int long_rolling_target_bits;
    406   int long_rolling_actual_bits;
    407 
    408   int64_t total_actual_bits;
    409   int total_target_vs_actual; /* debug stats */
    410 
    411   int worst_quality;
    412   int active_worst_quality;
    413   int best_quality;
    414   int active_best_quality;
    415 
    416   int cq_target_quality;
    417 
    418   int drop_frames_allowed; /* Are we permitted to drop frames? */
    419   int drop_frame;          /* Drop this frame? */
    420 #if defined(DROP_UNCODED_FRAMES)
    421   int drop_frame_count;
    422 #endif
    423 
    424   vp8_prob frame_coef_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
    425                            [ENTROPY_NODES];
    426   char update_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES];
    427 
    428   unsigned int frame_branch_ct[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
    429                               [ENTROPY_NODES][2];
    430 
    431   int gfu_boost;
    432   int kf_boost;
    433   int last_boost;
    434 
    435   int target_bandwidth;
    436   struct vpx_codec_pkt_list *output_pkt_list;
    437 
    438 #if 0
    439     /* Experimental code for lagged and one pass */
    440     ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS];
    441     int one_pass_frame_index;
    442 #endif
    443 
    444   int decimation_factor;
    445   int decimation_count;
    446 
    447   /* for real time encoding */
    448   int avg_encode_time;    /* microsecond */
    449   int avg_pick_mode_time; /* microsecond */
    450   int Speed;
    451   int compressor_speed;
    452 
    453   int auto_gold;
    454   int auto_adjust_gold_quantizer;
    455   int auto_worst_q;
    456   int cpu_used;
    457   int pass;
    458 
    459   int prob_intra_coded;
    460   int prob_last_coded;
    461   int prob_gf_coded;
    462   int prob_skip_false;
    463   int last_skip_false_probs[3];
    464   int last_skip_probs_q[3];
    465   int recent_ref_frame_usage[MAX_REF_FRAMES];
    466 
    467   int this_frame_percent_intra;
    468   int last_frame_percent_intra;
    469 
    470   int ref_frame_flags;
    471 
    472   SPEED_FEATURES sf;
    473 
    474   /* Count ZEROMV on all reference frames. */
    475   int zeromv_count;
    476   int lf_zeromv_pct;
    477 
    478   unsigned char *skin_map;
    479 
    480   unsigned char *segmentation_map;
    481   signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
    482   int segment_encode_breakout[MAX_MB_SEGMENTS];
    483 
    484   unsigned char *active_map;
    485   unsigned int active_map_enabled;
    486 
    487   /* Video conferencing cyclic refresh mode flags. This is a mode
    488    * designed to clean up the background over time in live encoding
    489    * scenarious. It uses segmentation.
    490    */
    491   int cyclic_refresh_mode_enabled;
    492   int cyclic_refresh_mode_max_mbs_perframe;
    493   int cyclic_refresh_mode_index;
    494   int cyclic_refresh_q;
    495   signed char *cyclic_refresh_map;
    496   // Count on how many (consecutive) times a macroblock uses ZER0MV_LAST.
    497   unsigned char *consec_zero_last;
    498   // Counter that is reset when a block is checked for a mode-bias against
    499   // ZEROMV_LASTREF.
    500   unsigned char *consec_zero_last_mvbias;
    501 
    502   // Frame counter for the temporal pattern. Counter is rest when the temporal
    503   // layers are changed dynamically (run-time change).
    504   unsigned int temporal_pattern_counter;
    505   // Temporal layer id.
    506   int temporal_layer_id;
    507 
    508   // Measure of average squared difference between source and denoised signal.
    509   int mse_source_denoised;
    510 
    511   int force_maxqp;
    512   int frames_since_last_drop_overshoot;
    513 
    514   // GF update for 1 pass cbr.
    515   int gf_update_onepass_cbr;
    516   int gf_interval_onepass_cbr;
    517   int gf_noboost_onepass_cbr;
    518 
    519 #if CONFIG_MULTITHREAD
    520   /* multithread data */
    521   vpx_atomic_int *mt_current_mb_col;
    522   int mt_sync_range;
    523   vpx_atomic_int b_multi_threaded;
    524   int encoding_thread_count;
    525   int b_lpf_running;
    526 
    527   pthread_t *h_encoding_thread;
    528   pthread_t h_filter_thread;
    529 
    530   MB_ROW_COMP *mb_row_ei;
    531   ENCODETHREAD_DATA *en_thread_data;
    532   LPFTHREAD_DATA lpf_thread_data;
    533 
    534   /* events */
    535   sem_t *h_event_start_encoding;
    536   sem_t *h_event_end_encoding;
    537   sem_t h_event_start_lpf;
    538   sem_t h_event_end_lpf;
    539 #endif
    540 
    541   TOKENLIST *tplist;
    542   unsigned int partition_sz[MAX_PARTITIONS];
    543   unsigned char *partition_d[MAX_PARTITIONS];
    544   unsigned char *partition_d_end[MAX_PARTITIONS];
    545 
    546   fractional_mv_step_fp *find_fractional_mv_step;
    547   vp8_full_search_fn_t full_search_sad;
    548   vp8_refining_search_fn_t refining_search_sad;
    549   vp8_diamond_search_fn_t diamond_search_sad;
    550   vp8_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SEGMENTS];
    551   uint64_t time_receive_data;
    552   uint64_t time_compress_data;
    553   uint64_t time_pick_lpf;
    554   uint64_t time_encode_mb_row;
    555 
    556   int base_skip_false_prob[128];
    557 
    558   FRAME_CONTEXT lfc_n; /* last frame entropy */
    559   FRAME_CONTEXT lfc_a; /* last alt ref entropy */
    560   FRAME_CONTEXT lfc_g; /* last gold ref entropy */
    561 
    562   struct twopass_rc {
    563     unsigned int section_intra_rating;
    564     double section_max_qfactor;
    565     unsigned int next_iiratio;
    566     unsigned int this_iiratio;
    567     FIRSTPASS_STATS total_stats;
    568     FIRSTPASS_STATS this_frame_stats;
    569     FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
    570     FIRSTPASS_STATS total_left_stats;
    571     int first_pass_done;
    572     int64_t bits_left;
    573     int64_t clip_bits_total;
    574     double avg_iiratio;
    575     double modified_error_total;
    576     double modified_error_used;
    577     double modified_error_left;
    578     double kf_intra_err_min;
    579     double gf_intra_err_min;
    580     int frames_to_key;
    581     int maxq_max_limit;
    582     int maxq_min_limit;
    583     int gf_decay_rate;
    584     int static_scene_max_gf_interval;
    585     int kf_bits;
    586     /* Remaining error from uncoded frames in a gf group. */
    587     int gf_group_error_left;
    588     /* Projected total bits available for a key frame group of frames */
    589     int64_t kf_group_bits;
    590     /* Error score of frames still to be coded in kf group */
    591     int64_t kf_group_error_left;
    592     /* Projected Bits available for a group including 1 GF or ARF */
    593     int64_t gf_group_bits;
    594     /* Bits for the golden frame or ARF */
    595     int gf_bits;
    596     int alt_extra_bits;
    597     double est_max_qcorrection_factor;
    598   } twopass;
    599 
    600 #if VP8_TEMPORAL_ALT_REF
    601   YV12_BUFFER_CONFIG alt_ref_buffer;
    602   YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
    603   int fixed_divide[512];
    604 #endif
    605 
    606 #if CONFIG_INTERNAL_STATS
    607   int count;
    608   double total_y;
    609   double total_u;
    610   double total_v;
    611   double total;
    612   double total_sq_error;
    613   double totalp_y;
    614   double totalp_u;
    615   double totalp_v;
    616   double totalp;
    617   double total_sq_error2;
    618   int bytes;
    619   double summed_quality;
    620   double summed_weights;
    621   unsigned int tot_recode_hits;
    622 
    623   int b_calculate_ssimg;
    624 #endif
    625   int b_calculate_psnr;
    626 
    627   /* Per MB activity measurement */
    628   unsigned int activity_avg;
    629   unsigned int *mb_activity_map;
    630 
    631   /* Record of which MBs still refer to last golden frame either
    632    * directly or through 0,0
    633    */
    634   unsigned char *gf_active_flags;
    635   int gf_active_count;
    636 
    637   int output_partition;
    638 
    639   /* Store last frame's MV info for next frame MV prediction */
    640   int_mv *lfmv;
    641   int *lf_ref_frame_sign_bias;
    642   int *lf_ref_frame;
    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 initial_width;
    650   int initial_height;
    651 
    652 #if CONFIG_TEMPORAL_DENOISING
    653   VP8_DENOISER denoiser;
    654 #endif
    655 
    656   /* Coding layer state variables */
    657   unsigned int current_layer;
    658   LAYER_CONTEXT layer_context[VPX_TS_MAX_LAYERS];
    659 
    660   int64_t frames_in_layer[VPX_TS_MAX_LAYERS];
    661   int64_t bytes_in_layer[VPX_TS_MAX_LAYERS];
    662   double sum_psnr[VPX_TS_MAX_LAYERS];
    663   double sum_psnr_p[VPX_TS_MAX_LAYERS];
    664   double total_error2[VPX_TS_MAX_LAYERS];
    665   double total_error2_p[VPX_TS_MAX_LAYERS];
    666   double sum_ssim[VPX_TS_MAX_LAYERS];
    667   double sum_weights[VPX_TS_MAX_LAYERS];
    668 
    669   double total_ssimg_y_in_layer[VPX_TS_MAX_LAYERS];
    670   double total_ssimg_u_in_layer[VPX_TS_MAX_LAYERS];
    671   double total_ssimg_v_in_layer[VPX_TS_MAX_LAYERS];
    672   double total_ssimg_all_in_layer[VPX_TS_MAX_LAYERS];
    673 
    674 #if CONFIG_MULTI_RES_ENCODING
    675   /* Number of MBs per row at lower-resolution level */
    676   int mr_low_res_mb_cols;
    677   /* Indicate if lower-res mv info is available */
    678   unsigned char mr_low_res_mv_avail;
    679 #endif
    680   /* The frame number of each reference frames */
    681   unsigned int current_ref_frames[MAX_REF_FRAMES];
    682   // Closest reference frame to current frame.
    683   MV_REFERENCE_FRAME closest_reference_frame;
    684 
    685   struct rd_costs_struct {
    686     int mvcosts[2][MVvals + 1];
    687     int mvsadcosts[2][MVfpvals + 1];
    688     int mbmode_cost[2][MB_MODE_COUNT];
    689     int intra_uv_mode_cost[2][MB_MODE_COUNT];
    690     int bmode_costs[10][10][10];
    691     int inter_bmode_costs[B_MODE_COUNT];
    692     int token_costs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
    693                    [MAX_ENTROPY_TOKENS];
    694   } rd_costs;
    695 
    696   // Use the static threshold from ROI settings.
    697   int use_roi_static_threshold;
    698 } VP8_COMP;
    699 
    700 void vp8_initialize_enc(void);
    701 
    702 void vp8_alloc_compressor_data(VP8_COMP *cpi);
    703 int vp8_reverse_trans(int x);
    704 void vp8_new_framerate(VP8_COMP *cpi, double framerate);
    705 void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm);
    706 
    707 void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest,
    708                         unsigned char *dest_end, size_t *size);
    709 
    710 void vp8_tokenize_mb(VP8_COMP *, MACROBLOCK *, TOKENEXTRA **);
    711 
    712 void vp8_set_speed_features(VP8_COMP *cpi);
    713 
    714 #if CONFIG_DEBUG
    715 #define CHECK_MEM_ERROR(lval, expr)                                         \
    716   do {                                                                      \
    717     lval = (expr);                                                          \
    718     if (!lval)                                                              \
    719       vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,           \
    720                          "Failed to allocate " #lval " at %s:%d", __FILE__, \
    721                          __LINE__);                                         \
    722   } while (0)
    723 #else
    724 #define CHECK_MEM_ERROR(lval, expr)                               \
    725   do {                                                            \
    726     lval = (expr);                                                \
    727     if (!lval)                                                    \
    728       vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, \
    729                          "Failed to allocate " #lval);            \
    730   } while (0)
    731 #endif
    732 #ifdef __cplusplus
    733 }  // extern "C"
    734 #endif
    735 
    736 #endif  // VP8_ENCODER_ONYX_INT_H_
    737