LCOV - code coverage report
Current view: top level - media/libvpx/libvpx/vp9/encoder - vp9_encoder.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 50 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 VP9_ENCODER_VP9_ENCODER_H_
      12             : #define VP9_ENCODER_VP9_ENCODER_H_
      13             : 
      14             : #include <stdio.h>
      15             : 
      16             : #include "./vpx_config.h"
      17             : #include "vpx/internal/vpx_codec_internal.h"
      18             : #include "vpx/vp8cx.h"
      19             : #if CONFIG_INTERNAL_STATS
      20             : #include "vpx_dsp/ssim.h"
      21             : #endif
      22             : #include "vpx_dsp/variance.h"
      23             : #include "vpx_ports/system_state.h"
      24             : #include "vpx_util/vpx_thread.h"
      25             : 
      26             : #include "vp9/common/vp9_alloccommon.h"
      27             : #include "vp9/common/vp9_ppflags.h"
      28             : #include "vp9/common/vp9_entropymode.h"
      29             : #include "vp9/common/vp9_thread_common.h"
      30             : #include "vp9/common/vp9_onyxc_int.h"
      31             : 
      32             : #include "vp9/encoder/vp9_alt_ref_aq.h"
      33             : #include "vp9/encoder/vp9_aq_cyclicrefresh.h"
      34             : #include "vp9/encoder/vp9_context_tree.h"
      35             : #include "vp9/encoder/vp9_encodemb.h"
      36             : #include "vp9/encoder/vp9_firstpass.h"
      37             : #include "vp9/encoder/vp9_lookahead.h"
      38             : #include "vp9/encoder/vp9_mbgraph.h"
      39             : #include "vp9/encoder/vp9_mcomp.h"
      40             : #include "vp9/encoder/vp9_noise_estimate.h"
      41             : #include "vp9/encoder/vp9_quantize.h"
      42             : #include "vp9/encoder/vp9_ratectrl.h"
      43             : #include "vp9/encoder/vp9_rd.h"
      44             : #include "vp9/encoder/vp9_speed_features.h"
      45             : #include "vp9/encoder/vp9_svc_layercontext.h"
      46             : #include "vp9/encoder/vp9_tokenize.h"
      47             : 
      48             : #if CONFIG_VP9_TEMPORAL_DENOISING
      49             : #include "vp9/encoder/vp9_denoiser.h"
      50             : #endif
      51             : 
      52             : #ifdef __cplusplus
      53             : extern "C" {
      54             : #endif
      55             : 
      56             : // vp9 uses 10,000,000 ticks/second as time stamp
      57             : #define TICKS_PER_SEC 10000000
      58             : 
      59             : typedef struct {
      60             :   int nmvjointcost[MV_JOINTS];
      61             :   int nmvcosts[2][MV_VALS];
      62             :   int nmvcosts_hp[2][MV_VALS];
      63             : 
      64             :   vpx_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             :   FRAME_CONTEXT fc;
      74             : } CODING_CONTEXT;
      75             : 
      76             : typedef enum {
      77             :   // encode_breakout is disabled.
      78             :   ENCODE_BREAKOUT_DISABLED = 0,
      79             :   // encode_breakout is enabled.
      80             :   ENCODE_BREAKOUT_ENABLED = 1,
      81             :   // encode_breakout is enabled with small max_thresh limit.
      82             :   ENCODE_BREAKOUT_LIMITED = 2
      83             : } ENCODE_BREAKOUT_TYPE;
      84             : 
      85             : typedef enum {
      86             :   NORMAL = 0,
      87             :   FOURFIVE = 1,
      88             :   THREEFIVE = 2,
      89             :   ONETWO = 3
      90             : } VPX_SCALING;
      91             : 
      92             : typedef enum {
      93             :   // Good Quality Fast Encoding. The encoder balances quality with the amount of
      94             :   // time it takes to encode the output. Speed setting controls how fast.
      95             :   GOOD,
      96             : 
      97             :   // The encoder places priority on the quality of the output over encoding
      98             :   // speed. The output is compressed at the highest possible quality. This
      99             :   // option takes the longest amount of time to encode. Speed setting ignored.
     100             :   BEST,
     101             : 
     102             :   // Realtime/Live Encoding. This mode is optimized for realtime encoding (for
     103             :   // example, capturing a television signal or feed from a live camera). Speed
     104             :   // setting controls how fast.
     105             :   REALTIME
     106             : } MODE;
     107             : 
     108             : typedef enum {
     109             :   FRAMEFLAGS_KEY = 1 << 0,
     110             :   FRAMEFLAGS_GOLDEN = 1 << 1,
     111             :   FRAMEFLAGS_ALTREF = 1 << 2,
     112             : } FRAMETYPE_FLAGS;
     113             : 
     114             : typedef enum {
     115             :   NO_AQ = 0,
     116             :   VARIANCE_AQ = 1,
     117             :   COMPLEXITY_AQ = 2,
     118             :   CYCLIC_REFRESH_AQ = 3,
     119             :   EQUATOR360_AQ = 4,
     120             :   // AQ based on lookahead temporal
     121             :   // variance (only valid for altref frames)
     122             :   LOOKAHEAD_AQ = 5,
     123             :   AQ_MODE_COUNT  // This should always be the last member of the enum
     124             : } AQ_MODE;
     125             : 
     126             : typedef enum {
     127             :   RESIZE_NONE = 0,    // No frame resizing allowed (except for SVC).
     128             :   RESIZE_FIXED = 1,   // All frames are coded at the specified dimension.
     129             :   RESIZE_DYNAMIC = 2  // Coded size of each frame is determined by the codec.
     130             : } RESIZE_TYPE;
     131             : 
     132             : typedef struct VP9EncoderConfig {
     133             :   BITSTREAM_PROFILE profile;
     134             :   vpx_bit_depth_t bit_depth;     // Codec bit-depth.
     135             :   int width;                     // width of data passed to the compressor
     136             :   int height;                    // height of data passed to the compressor
     137             :   unsigned int input_bit_depth;  // Input bit depth.
     138             :   double init_framerate;         // set to passed in framerate
     139             :   int64_t target_bandwidth;      // bandwidth to be used in bits per second
     140             : 
     141             :   int noise_sensitivity;  // pre processing blur: recommendation 0
     142             :   int sharpness;          // sharpening output: recommendation 0:
     143             :   int speed;
     144             :   // maximum allowed bitrate for any intra frame in % of bitrate target.
     145             :   unsigned int rc_max_intra_bitrate_pct;
     146             :   // maximum allowed bitrate for any inter frame in % of bitrate target.
     147             :   unsigned int rc_max_inter_bitrate_pct;
     148             :   // percent of rate boost for golden frame in CBR mode.
     149             :   unsigned int gf_cbr_boost_pct;
     150             : 
     151             :   MODE mode;
     152             :   int pass;
     153             : 
     154             :   // Key Framing Operations
     155             :   int auto_key;  // autodetect cut scenes and set the keyframes
     156             :   int key_freq;  // maximum distance to key frame.
     157             : 
     158             :   int lag_in_frames;  // how many frames lag before we start encoding
     159             : 
     160             :   // ----------------------------------------------------------------
     161             :   // DATARATE CONTROL OPTIONS
     162             : 
     163             :   // vbr, cbr, constrained quality or constant quality
     164             :   enum vpx_rc_mode rc_mode;
     165             : 
     166             :   // buffer targeting aggressiveness
     167             :   int under_shoot_pct;
     168             :   int over_shoot_pct;
     169             : 
     170             :   // buffering parameters
     171             :   int64_t starting_buffer_level_ms;
     172             :   int64_t optimal_buffer_level_ms;
     173             :   int64_t maximum_buffer_size_ms;
     174             : 
     175             :   // Frame drop threshold.
     176             :   int drop_frames_water_mark;
     177             : 
     178             :   // controlling quality
     179             :   int fixed_q;
     180             :   int worst_allowed_q;
     181             :   int best_allowed_q;
     182             :   int cq_level;
     183             :   AQ_MODE aq_mode;  // Adaptive Quantization mode
     184             : 
     185             :   // Special handling of Adaptive Quantization for AltRef frames
     186             :   int alt_ref_aq;
     187             : 
     188             :   // Internal frame size scaling.
     189             :   RESIZE_TYPE resize_mode;
     190             :   int scaled_frame_width;
     191             :   int scaled_frame_height;
     192             : 
     193             :   // Enable feature to reduce the frame quantization every x frames.
     194             :   int frame_periodic_boost;
     195             : 
     196             :   // two pass datarate control
     197             :   int two_pass_vbrbias;  // two pass datarate control tweaks
     198             :   int two_pass_vbrmin_section;
     199             :   int two_pass_vbrmax_section;
     200             :   // END DATARATE CONTROL OPTIONS
     201             :   // ----------------------------------------------------------------
     202             : 
     203             :   // Spatial and temporal scalability.
     204             :   int ss_number_layers;  // Number of spatial layers.
     205             :   int ts_number_layers;  // Number of temporal layers.
     206             :   // Bitrate allocation for spatial layers.
     207             :   int layer_target_bitrate[VPX_MAX_LAYERS];
     208             :   int ss_target_bitrate[VPX_SS_MAX_LAYERS];
     209             :   int ss_enable_auto_arf[VPX_SS_MAX_LAYERS];
     210             :   // Bitrate allocation (CBR mode) and framerate factor, for temporal layers.
     211             :   int ts_rate_decimator[VPX_TS_MAX_LAYERS];
     212             : 
     213             :   int enable_auto_arf;
     214             : 
     215             :   int encode_breakout;  // early breakout : for video conf recommend 800
     216             : 
     217             :   /* Bitfield defining the error resiliency features to enable.
     218             :    * Can provide decodable frames after losses in previous
     219             :    * frames and decodable partitions after losses in the same frame.
     220             :    */
     221             :   unsigned int error_resilient_mode;
     222             : 
     223             :   /* Bitfield defining the parallel decoding mode where the
     224             :    * decoding in successive frames may be conducted in parallel
     225             :    * just by decoding the frame headers.
     226             :    */
     227             :   unsigned int frame_parallel_decoding_mode;
     228             : 
     229             :   int arnr_max_frames;
     230             :   int arnr_strength;
     231             : 
     232             :   int min_gf_interval;
     233             :   int max_gf_interval;
     234             : 
     235             :   int tile_columns;
     236             :   int tile_rows;
     237             : 
     238             :   int max_threads;
     239             : 
     240             :   unsigned int target_level;
     241             : 
     242             :   vpx_fixed_buf_t two_pass_stats_in;
     243             :   struct vpx_codec_pkt_list *output_pkt_list;
     244             : 
     245             : #if CONFIG_FP_MB_STATS
     246             :   vpx_fixed_buf_t firstpass_mb_stats_in;
     247             : #endif
     248             : 
     249             :   vp8e_tuning tuning;
     250             :   vp9e_tune_content content;
     251             : #if CONFIG_VP9_HIGHBITDEPTH
     252             :   int use_highbitdepth;
     253             : #endif
     254             :   vpx_color_space_t color_space;
     255             :   vpx_color_range_t color_range;
     256             :   int render_width;
     257             :   int render_height;
     258             :   VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
     259             : } VP9EncoderConfig;
     260             : 
     261           0 : static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) {
     262           0 :   return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
     263             : }
     264             : 
     265             : // TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
     266             : typedef struct TileDataEnc {
     267             :   TileInfo tile_info;
     268             :   int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
     269             :   int mode_map[BLOCK_SIZES][MAX_MODES];
     270             :   int m_search_count;
     271             :   int ex_search_count;
     272             : } TileDataEnc;
     273             : 
     274             : typedef struct RD_COUNTS {
     275             :   vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
     276             :   int64_t comp_pred_diff[REFERENCE_MODES];
     277             :   int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];
     278             : } RD_COUNTS;
     279             : 
     280             : typedef struct ThreadData {
     281             :   MACROBLOCK mb;
     282             :   RD_COUNTS rd_counts;
     283             :   FRAME_COUNTS *counts;
     284             : 
     285             :   PICK_MODE_CONTEXT *leaf_tree;
     286             :   PC_TREE *pc_tree;
     287             :   PC_TREE *pc_root;
     288             : } ThreadData;
     289             : 
     290             : struct EncWorkerData;
     291             : 
     292             : typedef struct ActiveMap {
     293             :   int enabled;
     294             :   int update;
     295             :   unsigned char *map;
     296             : } ActiveMap;
     297             : 
     298             : typedef enum { Y, U, V, ALL } STAT_TYPE;
     299             : 
     300             : typedef struct IMAGE_STAT {
     301             :   double stat[ALL + 1];
     302             :   double worst;
     303             : } ImageStat;
     304             : 
     305             : // Kf noise filtering currently disabled by default in build.
     306             : // #define ENABLE_KF_DENOISE 1
     307             : 
     308             : #define CPB_WINDOW_SIZE 4
     309             : #define FRAME_WINDOW_SIZE 128
     310             : #define SAMPLE_RATE_GRACE_P 0.015
     311             : #define VP9_LEVELS 14
     312             : 
     313             : typedef enum {
     314             :   LEVEL_UNKNOWN = 0,
     315             :   LEVEL_1 = 10,
     316             :   LEVEL_1_1 = 11,
     317             :   LEVEL_2 = 20,
     318             :   LEVEL_2_1 = 21,
     319             :   LEVEL_3 = 30,
     320             :   LEVEL_3_1 = 31,
     321             :   LEVEL_4 = 40,
     322             :   LEVEL_4_1 = 41,
     323             :   LEVEL_5 = 50,
     324             :   LEVEL_5_1 = 51,
     325             :   LEVEL_5_2 = 52,
     326             :   LEVEL_6 = 60,
     327             :   LEVEL_6_1 = 61,
     328             :   LEVEL_6_2 = 62,
     329             :   LEVEL_MAX = 255
     330             : } VP9_LEVEL;
     331             : 
     332             : typedef struct {
     333             :   VP9_LEVEL level;
     334             :   uint64_t max_luma_sample_rate;
     335             :   uint32_t max_luma_picture_size;
     336             :   double average_bitrate;  // in kilobits per second
     337             :   double max_cpb_size;     // in kilobits
     338             :   double compression_ratio;
     339             :   uint8_t max_col_tiles;
     340             :   uint32_t min_altref_distance;
     341             :   uint8_t max_ref_frame_buffers;
     342             : } Vp9LevelSpec;
     343             : 
     344             : extern const Vp9LevelSpec vp9_level_defs[VP9_LEVELS];
     345             : 
     346             : typedef struct {
     347             :   int64_t ts;  // timestamp
     348             :   uint32_t luma_samples;
     349             :   uint32_t size;  // in bytes
     350             : } FrameRecord;
     351             : 
     352             : typedef struct {
     353             :   FrameRecord buf[FRAME_WINDOW_SIZE];
     354             :   uint8_t start;
     355             :   uint8_t len;
     356             : } FrameWindowBuffer;
     357             : 
     358             : typedef struct {
     359             :   uint8_t seen_first_altref;
     360             :   uint32_t frames_since_last_altref;
     361             :   uint64_t total_compressed_size;
     362             :   uint64_t total_uncompressed_size;
     363             :   double time_encoded;  // in seconds
     364             :   FrameWindowBuffer frame_window_buffer;
     365             :   int ref_refresh_map;
     366             : } Vp9LevelStats;
     367             : 
     368             : typedef struct {
     369             :   Vp9LevelStats level_stats;
     370             :   Vp9LevelSpec level_spec;
     371             : } Vp9LevelInfo;
     372             : 
     373             : typedef enum {
     374             :   BITRATE_TOO_LARGE = 0,
     375             :   LUMA_PIC_SIZE_TOO_LARGE = 1,
     376             :   LUMA_SAMPLE_RATE_TOO_LARGE = 2,
     377             :   CPB_TOO_LARGE = 3,
     378             :   COMPRESSION_RATIO_TOO_SMALL = 4,
     379             :   TOO_MANY_COLUMN_TILE = 5,
     380             :   ALTREF_DIST_TOO_SMALL = 6,
     381             :   TOO_MANY_REF_BUFFER = 7,
     382             :   TARGET_LEVEL_FAIL_IDS = 8
     383             : } TARGET_LEVEL_FAIL_ID;
     384             : 
     385             : typedef struct {
     386             :   int8_t level_index;
     387             :   uint8_t rc_config_updated;
     388             :   uint8_t fail_flag;
     389             :   int max_frame_size;   // in bits
     390             :   double max_cpb_size;  // in bits
     391             : } LevelConstraint;
     392             : 
     393             : typedef struct VP9_COMP {
     394             :   QUANTS quants;
     395             :   ThreadData td;
     396             :   MB_MODE_INFO_EXT *mbmi_ext_base;
     397             :   DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);
     398             :   DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);
     399             :   VP9_COMMON common;
     400             :   VP9EncoderConfig oxcf;
     401             :   struct lookahead_ctx *lookahead;
     402             :   struct lookahead_entry *alt_ref_source;
     403             : 
     404             :   YV12_BUFFER_CONFIG *Source;
     405             :   YV12_BUFFER_CONFIG *Last_Source;  // NULL for first frame and alt_ref frames
     406             :   YV12_BUFFER_CONFIG *un_scaled_source;
     407             :   YV12_BUFFER_CONFIG scaled_source;
     408             :   YV12_BUFFER_CONFIG *unscaled_last_source;
     409             :   YV12_BUFFER_CONFIG scaled_last_source;
     410             : #ifdef ENABLE_KF_DENOISE
     411             :   YV12_BUFFER_CONFIG raw_unscaled_source;
     412             :   YV12_BUFFER_CONFIG raw_scaled_source;
     413             : #endif
     414             :   YV12_BUFFER_CONFIG *raw_source_frame;
     415             : 
     416             :   TileDataEnc *tile_data;
     417             :   int allocated_tiles;  // Keep track of memory allocated for tiles.
     418             : 
     419             :   // For a still frame, this flag is set to 1 to skip partition search.
     420             :   int partition_search_skippable_frame;
     421             : 
     422             :   int scaled_ref_idx[MAX_REF_FRAMES];
     423             :   int lst_fb_idx;
     424             :   int gld_fb_idx;
     425             :   int alt_fb_idx;
     426             : 
     427             :   int refresh_last_frame;
     428             :   int refresh_golden_frame;
     429             :   int refresh_alt_ref_frame;
     430             : 
     431             :   int ext_refresh_frame_flags_pending;
     432             :   int ext_refresh_last_frame;
     433             :   int ext_refresh_golden_frame;
     434             :   int ext_refresh_alt_ref_frame;
     435             : 
     436             :   int ext_refresh_frame_context_pending;
     437             :   int ext_refresh_frame_context;
     438             : 
     439             :   YV12_BUFFER_CONFIG last_frame_uf;
     440             : 
     441             :   TOKENEXTRA *tile_tok[4][1 << 6];
     442             :   uint32_t tok_count[4][1 << 6];
     443             : 
     444             :   // Ambient reconstruction err target for force key frames
     445             :   int64_t ambient_err;
     446             : 
     447             :   RD_OPT rd;
     448             : 
     449             :   CODING_CONTEXT coding_context;
     450             : 
     451             :   int *nmvcosts[2];
     452             :   int *nmvcosts_hp[2];
     453             :   int *nmvsadcosts[2];
     454             :   int *nmvsadcosts_hp[2];
     455             : 
     456             :   int64_t last_time_stamp_seen;
     457             :   int64_t last_end_time_stamp_seen;
     458             :   int64_t first_time_stamp_ever;
     459             : 
     460             :   RATE_CONTROL rc;
     461             :   double framerate;
     462             : 
     463             :   int interp_filter_selected[MAX_REF_FRAMES][SWITCHABLE];
     464             : 
     465             :   struct vpx_codec_pkt_list *output_pkt_list;
     466             : 
     467             :   MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
     468             :   int mbgraph_n_frames;  // number of frames filled in the above
     469             :   int static_mb_pct;     // % forced skip mbs by segmentation
     470             :   int ref_frame_flags;
     471             : 
     472             :   SPEED_FEATURES sf;
     473             : 
     474             :   uint32_t max_mv_magnitude;
     475             :   int mv_step_param;
     476             : 
     477             :   int allow_comp_inter_inter;
     478             : 
     479             :   // Default value is 1. From first pass stats, encode_breakout may be disabled.
     480             :   ENCODE_BREAKOUT_TYPE allow_encode_breakout;
     481             : 
     482             :   // Get threshold from external input. A suggested threshold is 800 for HD
     483             :   // clips, and 300 for < HD clips.
     484             :   int encode_breakout;
     485             : 
     486             :   uint8_t *segmentation_map;
     487             : 
     488             :   // segment threashold for encode breakout
     489             :   int segment_encode_breakout[MAX_SEGMENTS];
     490             : 
     491             :   CYCLIC_REFRESH *cyclic_refresh;
     492             :   ActiveMap active_map;
     493             : 
     494             :   fractional_mv_step_fp *find_fractional_mv_step;
     495             :   vp9_full_search_fn_t full_search_sad;
     496             :   vp9_diamond_search_fn_t diamond_search_sad;
     497             :   vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
     498             :   uint64_t time_receive_data;
     499             :   uint64_t time_compress_data;
     500             :   uint64_t time_pick_lpf;
     501             :   uint64_t time_encode_sb_row;
     502             : 
     503             : #if CONFIG_FP_MB_STATS
     504             :   int use_fp_mb_stats;
     505             : #endif
     506             : 
     507             :   TWO_PASS twopass;
     508             : 
     509             :   // Force recalculation of segment_ids for each mode info
     510             :   uint8_t force_update_segmentation;
     511             : 
     512             :   YV12_BUFFER_CONFIG alt_ref_buffer;
     513             : 
     514             :   // class responsible for adaptive
     515             :   // quantization of altref frames
     516             :   struct ALT_REF_AQ *alt_ref_aq;
     517             : 
     518             : #if CONFIG_INTERNAL_STATS
     519             :   unsigned int mode_chosen_counts[MAX_MODES];
     520             : 
     521             :   int count;
     522             :   uint64_t total_sq_error;
     523             :   uint64_t total_samples;
     524             :   ImageStat psnr;
     525             : 
     526             :   uint64_t totalp_sq_error;
     527             :   uint64_t totalp_samples;
     528             :   ImageStat psnrp;
     529             : 
     530             :   double total_blockiness;
     531             :   double worst_blockiness;
     532             : 
     533             :   int bytes;
     534             :   double summed_quality;
     535             :   double summed_weights;
     536             :   double summedp_quality;
     537             :   double summedp_weights;
     538             :   unsigned int tot_recode_hits;
     539             :   double worst_ssim;
     540             : 
     541             :   ImageStat ssimg;
     542             :   ImageStat fastssim;
     543             :   ImageStat psnrhvs;
     544             : 
     545             :   int b_calculate_ssimg;
     546             :   int b_calculate_blockiness;
     547             : 
     548             :   int b_calculate_consistency;
     549             : 
     550             :   double total_inconsistency;
     551             :   double worst_consistency;
     552             :   Ssimv *ssim_vars;
     553             :   Metrics metrics;
     554             : #endif
     555             :   int b_calculate_psnr;
     556             : 
     557             :   int droppable;
     558             : 
     559             :   int initial_width;
     560             :   int initial_height;
     561             :   int initial_mbs;  // Number of MBs in the full-size frame; to be used to
     562             :                     // normalize the firstpass stats. This will differ from the
     563             :                     // number of MBs in the current frame when the frame is
     564             :                     // scaled.
     565             : 
     566             :   int use_svc;
     567             : 
     568             :   SVC svc;
     569             : 
     570             :   // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type.
     571             :   diff *source_diff_var;
     572             :   // The threshold used in SOURCE_VAR_BASED_PARTITION search type.
     573             :   unsigned int source_var_thresh;
     574             :   int frames_till_next_var_check;
     575             : 
     576             :   int frame_flags;
     577             : 
     578             :   search_site_config ss_cfg;
     579             : 
     580             :   int mbmode_cost[INTRA_MODES];
     581             :   unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
     582             :   int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES][INTRA_MODES];
     583             :   int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
     584             :   int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
     585             :   int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
     586             : 
     587             :   int multi_arf_allowed;
     588             :   int multi_arf_enabled;
     589             :   int multi_arf_last_grp_enabled;
     590             : 
     591             : #if CONFIG_VP9_TEMPORAL_DENOISING
     592             :   VP9_DENOISER denoiser;
     593             : #endif
     594             : 
     595             :   int resize_pending;
     596             :   int resize_state;
     597             :   int external_resize;
     598             :   int resize_scale_num;
     599             :   int resize_scale_den;
     600             :   int resize_avg_qp;
     601             :   int resize_buffer_underflow;
     602             :   int resize_count;
     603             : 
     604             :   int use_skin_detection;
     605             : 
     606             :   int target_level;
     607             : 
     608             :   NOISE_ESTIMATE noise_estimate;
     609             : 
     610             :   // Count on how many consecutive times a block uses small/zeromv for encoding.
     611             :   uint8_t *consec_zero_mv;
     612             : 
     613             :   // VAR_BASED_PARTITION thresholds
     614             :   // 0 - threshold_64x64; 1 - threshold_32x32;
     615             :   // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
     616             :   int64_t vbp_thresholds[4];
     617             :   int64_t vbp_threshold_minmax;
     618             :   int64_t vbp_threshold_sad;
     619             :   // Threshold used for partition copy
     620             :   int64_t vbp_threshold_copy;
     621             :   BLOCK_SIZE vbp_bsize_min;
     622             : 
     623             :   // Multi-threading
     624             :   int num_workers;
     625             :   VPxWorker *workers;
     626             :   struct EncWorkerData *tile_thr_data;
     627             :   VP9LfSync lf_row_sync;
     628             :   struct VP9BitstreamWorkerData *vp9_bitstream_worker_data;
     629             : 
     630             :   int keep_level_stats;
     631             :   Vp9LevelInfo level_info;
     632             : 
     633             :   // Previous Partition Info
     634             :   BLOCK_SIZE *prev_partition;
     635             :   int8_t *prev_segment_id;
     636             : 
     637             :   LevelConstraint level_constraint;
     638             : } VP9_COMP;
     639             : 
     640             : void vp9_initialize_enc(void);
     641             : 
     642             : struct VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
     643             :                                        BufferPool *const pool);
     644             : void vp9_remove_compressor(VP9_COMP *cpi);
     645             : 
     646             : void vp9_change_config(VP9_COMP *cpi, const VP9EncoderConfig *oxcf);
     647             : 
     648             : // receive a frames worth of data. caller can assume that a copy of this
     649             : // frame is made and not just a copy of the pointer..
     650             : int vp9_receive_raw_frame(VP9_COMP *cpi, vpx_enc_frame_flags_t frame_flags,
     651             :                           YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
     652             :                           int64_t end_time_stamp);
     653             : 
     654             : int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
     655             :                             size_t *size, uint8_t *dest, int64_t *time_stamp,
     656             :                             int64_t *time_end, int flush);
     657             : 
     658             : int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
     659             :                               vp9_ppflags_t *flags);
     660             : 
     661             : int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags);
     662             : 
     663             : void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags);
     664             : 
     665             : int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
     666             :                            YV12_BUFFER_CONFIG *sd);
     667             : 
     668             : int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
     669             :                           YV12_BUFFER_CONFIG *sd);
     670             : 
     671             : int vp9_update_entropy(VP9_COMP *cpi, int update);
     672             : 
     673             : int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
     674             : 
     675             : int vp9_get_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
     676             : 
     677             : int vp9_set_internal_size(VP9_COMP *cpi, VPX_SCALING horiz_mode,
     678             :                           VPX_SCALING vert_mode);
     679             : 
     680             : int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
     681             :                          unsigned int height);
     682             : 
     683             : void vp9_set_svc(VP9_COMP *cpi, int use_svc);
     684             : 
     685             : int vp9_get_quantizer(struct VP9_COMP *cpi);
     686             : 
     687           0 : static INLINE int frame_is_kf_gf_arf(const VP9_COMP *cpi) {
     688           0 :   return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
     689           0 :          (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
     690             : }
     691             : 
     692           0 : static INLINE int get_ref_frame_map_idx(const VP9_COMP *cpi,
     693             :                                         MV_REFERENCE_FRAME ref_frame) {
     694           0 :   if (ref_frame == LAST_FRAME) {
     695           0 :     return cpi->lst_fb_idx;
     696           0 :   } else if (ref_frame == GOLDEN_FRAME) {
     697           0 :     return cpi->gld_fb_idx;
     698             :   } else {
     699           0 :     return cpi->alt_fb_idx;
     700             :   }
     701             : }
     702             : 
     703           0 : static INLINE int get_ref_frame_buf_idx(const VP9_COMP *const cpi,
     704             :                                         int ref_frame) {
     705           0 :   const VP9_COMMON *const cm = &cpi->common;
     706           0 :   const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
     707           0 :   return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
     708             : }
     709             : 
     710           0 : static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
     711             :     VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
     712           0 :   VP9_COMMON *const cm = &cpi->common;
     713           0 :   const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
     714           0 :   return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf
     715           0 :                                 : NULL;
     716             : }
     717             : 
     718           0 : static INLINE int get_token_alloc(int mb_rows, int mb_cols) {
     719             :   // TODO(JBB): double check we can't exceed this token count if we have a
     720             :   // 32x32 transform crossing a boundary at a multiple of 16.
     721             :   // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full
     722             :   // resolution. We assume up to 1 token per pixel, and then allow
     723             :   // a head room of 4.
     724           0 :   return mb_rows * mb_cols * (16 * 16 * 3 + 4);
     725             : }
     726             : 
     727             : // Get the allocated token size for a tile. It does the same calculation as in
     728             : // the frame token allocation.
     729           0 : static INLINE int allocated_tokens(TileInfo tile) {
     730           0 :   int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
     731           0 :   int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
     732             : 
     733           0 :   return get_token_alloc(tile_mb_rows, tile_mb_cols);
     734             : }
     735             : 
     736             : int64_t vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b);
     737             : #if CONFIG_VP9_HIGHBITDEPTH
     738             : int64_t vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a,
     739             :                              const YV12_BUFFER_CONFIG *b);
     740             : #endif  // CONFIG_VP9_HIGHBITDEPTH
     741             : 
     742             : void vp9_scale_references(VP9_COMP *cpi);
     743             : 
     744             : void vp9_update_reference_frames(VP9_COMP *cpi);
     745             : 
     746             : void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
     747             : 
     748             : YV12_BUFFER_CONFIG *vp9_svc_twostage_scale(VP9_COMMON *cm,
     749             :                                            YV12_BUFFER_CONFIG *unscaled,
     750             :                                            YV12_BUFFER_CONFIG *scaled,
     751             :                                            YV12_BUFFER_CONFIG *scaled_temp);
     752             : 
     753             : YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
     754             :                                           YV12_BUFFER_CONFIG *unscaled,
     755             :                                           YV12_BUFFER_CONFIG *scaled,
     756             :                                           int use_normative_scaler);
     757             : 
     758             : void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags);
     759             : 
     760           0 : static INLINE int is_two_pass_svc(const struct VP9_COMP *const cpi) {
     761           0 :   return cpi->use_svc && cpi->oxcf.pass != 0;
     762             : }
     763             : 
     764           0 : static INLINE int is_one_pass_cbr_svc(const struct VP9_COMP *const cpi) {
     765           0 :   return (cpi->use_svc && cpi->oxcf.pass == 0);
     766             : }
     767             : 
     768           0 : static INLINE int is_altref_enabled(const VP9_COMP *const cpi) {
     769           0 :   return !(cpi->oxcf.mode == REALTIME && cpi->oxcf.rc_mode == VPX_CBR) &&
     770           0 :          cpi->oxcf.lag_in_frames > 0 &&
     771           0 :          (cpi->oxcf.enable_auto_arf &&
     772           0 :           (!is_two_pass_svc(cpi) ||
     773           0 :            cpi->oxcf.ss_enable_auto_arf[cpi->svc.spatial_layer_id]));
     774             : }
     775             : 
     776           0 : static INLINE void set_ref_ptrs(VP9_COMMON *cm, MACROBLOCKD *xd,
     777             :                                 MV_REFERENCE_FRAME ref0,
     778             :                                 MV_REFERENCE_FRAME ref1) {
     779           0 :   xd->block_refs[0] =
     780           0 :       &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0];
     781           0 :   xd->block_refs[1] =
     782           0 :       &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0];
     783           0 : }
     784             : 
     785           0 : static INLINE int get_chessboard_index(const int frame_index) {
     786           0 :   return frame_index & 0x1;
     787             : }
     788             : 
     789           0 : static INLINE int *cond_cost_list(const struct VP9_COMP *cpi, int *cost_list) {
     790           0 :   return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
     791             : }
     792             : 
     793           0 : static INLINE int get_level_index(VP9_LEVEL level) {
     794             :   int i;
     795           0 :   for (i = 0; i < VP9_LEVELS; ++i) {
     796           0 :     if (level == vp9_level_defs[i].level) return i;
     797             :   }
     798           0 :   return -1;
     799             : }
     800             : 
     801             : VP9_LEVEL vp9_get_level(const Vp9LevelSpec *const level_spec);
     802             : 
     803             : void vp9_new_framerate(VP9_COMP *cpi, double framerate);
     804             : 
     805             : #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
     806             : 
     807             : #ifdef __cplusplus
     808             : }  // extern "C"
     809             : #endif
     810             : 
     811             : #endif  // VP9_ENCODER_VP9_ENCODER_H_

Generated by: LCOV version 1.13