LCOV - code coverage report
Current view: top level - third_party/aom/av1/encoder - encoder.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 67 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
       3             :  *
       4             :  * This source code is subject to the terms of the BSD 2 Clause License and
       5             :  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
       6             :  * was not distributed with this source code in the LICENSE file, you can
       7             :  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
       8             :  * Media Patent License 1.0 was not distributed with this source code in the
       9             :  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
      10             :  */
      11             : 
      12             : #ifndef AV1_ENCODER_ENCODER_H_
      13             : #define AV1_ENCODER_ENCODER_H_
      14             : 
      15             : #include <stdio.h>
      16             : 
      17             : #include "./aom_config.h"
      18             : #include "aom/aomcx.h"
      19             : 
      20             : #include "av1/common/alloccommon.h"
      21             : #include "av1/common/entropymode.h"
      22             : #include "av1/common/thread_common.h"
      23             : #include "av1/common/onyxc_int.h"
      24             : #include "av1/encoder/aq_cyclicrefresh.h"
      25             : #if CONFIG_ANS
      26             : #include "aom_dsp/ans.h"
      27             : #include "aom_dsp/buf_ans.h"
      28             : #endif
      29             : #include "av1/encoder/av1_quantize.h"
      30             : #include "av1/encoder/context_tree.h"
      31             : #include "av1/encoder/encodemb.h"
      32             : #include "av1/encoder/firstpass.h"
      33             : #include "av1/encoder/lookahead.h"
      34             : #include "av1/encoder/mbgraph.h"
      35             : #include "av1/encoder/mcomp.h"
      36             : #include "av1/encoder/ratectrl.h"
      37             : #include "av1/encoder/rd.h"
      38             : #include "av1/encoder/speed_features.h"
      39             : #include "av1/encoder/tokenize.h"
      40             : #if CONFIG_XIPHRC
      41             : #include "av1/encoder/ratectrl_xiph.h"
      42             : #endif
      43             : 
      44             : #if CONFIG_INTERNAL_STATS
      45             : #include "aom_dsp/ssim.h"
      46             : #endif
      47             : #include "aom_dsp/variance.h"
      48             : #include "aom/internal/aom_codec_internal.h"
      49             : #include "aom_util/aom_thread.h"
      50             : 
      51             : #ifdef __cplusplus
      52             : extern "C" {
      53             : #endif
      54             : 
      55             : typedef struct {
      56             :   int nmv_vec_cost[NMV_CONTEXTS][MV_JOINTS];
      57             :   int nmv_costs[NMV_CONTEXTS][2][MV_VALS];
      58             :   int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS];
      59             : 
      60             :   // 0 = Intra, Last, GF, ARF
      61             :   signed char last_ref_lf_deltas[TOTAL_REFS_PER_FRAME];
      62             :   // 0 = ZERO_MV, MV
      63             :   signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
      64             : 
      65             :   FRAME_CONTEXT fc;
      66             : } CODING_CONTEXT;
      67             : 
      68             : typedef enum {
      69             :   // regular inter frame
      70             :   REGULAR_FRAME = 0,
      71             :   // alternate reference frame
      72             :   ARF_FRAME = 1,
      73             :   // overlay frame
      74             :   OVERLAY_FRAME = 2,
      75             :   // golden frame
      76             :   GLD_FRAME = 3,
      77             : #if CONFIG_EXT_REFS
      78             :   // backward reference frame
      79             :   BRF_FRAME = 4,
      80             :   // extra alternate reference frame
      81             :   EXT_ARF_FRAME = 5
      82             : #endif
      83             : } FRAME_CONTEXT_INDEX;
      84             : 
      85             : typedef enum {
      86             :   NORMAL = 0,
      87             :   FOURFIVE = 1,
      88             :   THREEFIVE = 2,
      89             :   ONETWO = 3
      90             : } AOM_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             : } MODE;
      97             : 
      98             : typedef enum {
      99             :   FRAMEFLAGS_KEY = 1 << 0,
     100             :   FRAMEFLAGS_GOLDEN = 1 << 1,
     101             : #if CONFIG_EXT_REFS
     102             :   FRAMEFLAGS_BWDREF = 1 << 2,
     103             :   FRAMEFLAGS_ALTREF = 1 << 3,
     104             : #else
     105             :   FRAMEFLAGS_ALTREF = 1 << 2,
     106             : #endif  // CONFIG_EXT_REFS
     107             : } FRAMETYPE_FLAGS;
     108             : 
     109             : typedef enum {
     110             :   NO_AQ = 0,
     111             :   VARIANCE_AQ = 1,
     112             :   COMPLEXITY_AQ = 2,
     113             :   CYCLIC_REFRESH_AQ = 3,
     114             : #if CONFIG_DELTA_Q && !CONFIG_EXT_DELTA_Q
     115             :   DELTA_AQ = 4,
     116             : #endif
     117             :   AQ_MODE_COUNT  // This should always be the last member of the enum
     118             : } AQ_MODE;
     119             : #if CONFIG_EXT_DELTA_Q
     120             : typedef enum {
     121             :   NO_DELTA_Q = 0,
     122             :   DELTA_Q_ONLY = 1,
     123             :   DELTA_Q_LF = 2,
     124             :   DELTAQ_MODE_COUNT  // This should always be the last member of the enum
     125             : } DELTAQ_MODE;
     126             : #endif
     127             : typedef enum {
     128             :   RESIZE_NONE = 0,    // No frame resizing allowed.
     129             :   RESIZE_FIXED = 1,   // All frames are coded at the specified dimension.
     130             :   RESIZE_DYNAMIC = 2  // Coded size of each frame is determined by the codec.
     131             : } RESIZE_TYPE;
     132             : 
     133             : typedef struct AV1EncoderConfig {
     134             :   BITSTREAM_PROFILE profile;
     135             :   aom_bit_depth_t bit_depth;     // Codec bit-depth.
     136             :   int width;                     // width of data passed to the compressor
     137             :   int height;                    // height of data passed to the compressor
     138             :   unsigned int input_bit_depth;  // Input bit depth.
     139             :   double init_framerate;         // set to passed in framerate
     140             :   int64_t target_bandwidth;      // bandwidth to be used in bits per second
     141             : 
     142             :   int noise_sensitivity;  // pre processing blur: recommendation 0
     143             :   int sharpness;          // sharpening output: recommendation 0:
     144             :   int speed;
     145             :   // maximum allowed bitrate for any intra frame in % of bitrate target.
     146             :   unsigned int rc_max_intra_bitrate_pct;
     147             :   // maximum allowed bitrate for any inter frame in % of bitrate target.
     148             :   unsigned int rc_max_inter_bitrate_pct;
     149             :   // percent of rate boost for golden frame in CBR mode.
     150             :   unsigned int gf_cbr_boost_pct;
     151             : 
     152             :   MODE mode;
     153             :   int pass;
     154             : 
     155             :   // Key Framing Operations
     156             :   int auto_key;  // autodetect cut scenes and set the keyframes
     157             :   int key_freq;  // maximum distance to key frame.
     158             : 
     159             :   int lag_in_frames;  // how many frames lag before we start encoding
     160             : 
     161             :   // ----------------------------------------------------------------
     162             :   // DATARATE CONTROL OPTIONS
     163             : 
     164             :   // vbr, cbr, constrained quality or constant quality
     165             :   enum aom_rc_mode rc_mode;
     166             : 
     167             :   // buffer targeting aggressiveness
     168             :   int under_shoot_pct;
     169             :   int over_shoot_pct;
     170             : 
     171             :   // buffering parameters
     172             :   int64_t starting_buffer_level_ms;
     173             :   int64_t optimal_buffer_level_ms;
     174             :   int64_t maximum_buffer_size_ms;
     175             : 
     176             :   // Frame drop threshold.
     177             :   int drop_frames_water_mark;
     178             : 
     179             :   // controlling quality
     180             :   int fixed_q;
     181             :   int worst_allowed_q;
     182             :   int best_allowed_q;
     183             :   int cq_level;
     184             :   AQ_MODE aq_mode;  // Adaptive Quantization mode
     185             : #if CONFIG_EXT_DELTA_Q
     186             :   DELTAQ_MODE deltaq_mode;
     187             : #endif
     188             : #if CONFIG_AOM_QM
     189             :   int using_qm;
     190             :   int qm_minlevel;
     191             :   int qm_maxlevel;
     192             : #endif
     193             : #if CONFIG_TILE_GROUPS
     194             :   unsigned int num_tile_groups;
     195             :   unsigned int mtu;
     196             : #endif
     197             : 
     198             : #if CONFIG_TEMPMV_SIGNALING
     199             :   unsigned int disable_tempmv;
     200             : #endif
     201             :   // Internal frame size scaling.
     202             :   RESIZE_TYPE resize_mode;
     203             :   int scaled_frame_width;
     204             :   int scaled_frame_height;
     205             : 
     206             : #if CONFIG_FRAME_SUPERRES
     207             :   // Frame Super-Resolution size scaling
     208             :   int superres_enabled;
     209             : #endif  // CONFIG_FRAME_SUPERRES
     210             : 
     211             :   // Enable feature to reduce the frame quantization every x frames.
     212             :   int frame_periodic_boost;
     213             : 
     214             :   // two pass datarate control
     215             :   int two_pass_vbrbias;  // two pass datarate control tweaks
     216             :   int two_pass_vbrmin_section;
     217             :   int two_pass_vbrmax_section;
     218             :   // END DATARATE CONTROL OPTIONS
     219             :   // ----------------------------------------------------------------
     220             : 
     221             :   int enable_auto_arf;
     222             : #if CONFIG_EXT_REFS
     223             :   int enable_auto_brf;  // (b)ackward (r)ef (f)rame
     224             : #endif                  // CONFIG_EXT_REFS
     225             : 
     226             :   /* Bitfield defining the error resiliency features to enable.
     227             :    * Can provide decodable frames after losses in previous
     228             :    * frames and decodable partitions after losses in the same frame.
     229             :    */
     230             :   unsigned int error_resilient_mode;
     231             : 
     232             :   /* Bitfield defining the parallel decoding mode where the
     233             :    * decoding in successive frames may be conducted in parallel
     234             :    * just by decoding the frame headers.
     235             :    */
     236             :   unsigned int frame_parallel_decoding_mode;
     237             : 
     238             :   int arnr_max_frames;
     239             :   int arnr_strength;
     240             : 
     241             :   int min_gf_interval;
     242             :   int max_gf_interval;
     243             : 
     244             :   int tile_columns;
     245             :   int tile_rows;
     246             : #if CONFIG_DEPENDENT_HORZTILES
     247             :   int dependent_horz_tiles;
     248             : #endif
     249             : #if CONFIG_LOOPFILTERING_ACROSS_TILES
     250             :   int loop_filter_across_tiles_enabled;
     251             : #endif  // CONFIG_LOOPFILTERING_ACROSS_TILES
     252             : 
     253             :   int max_threads;
     254             : 
     255             :   aom_fixed_buf_t two_pass_stats_in;
     256             :   struct aom_codec_pkt_list *output_pkt_list;
     257             : 
     258             : #if CONFIG_FP_MB_STATS
     259             :   aom_fixed_buf_t firstpass_mb_stats_in;
     260             : #endif
     261             : 
     262             :   aom_tune_metric tuning;
     263             :   aom_tune_content content;
     264             : #if CONFIG_HIGHBITDEPTH
     265             :   int use_highbitdepth;
     266             : #endif
     267             :   aom_color_space_t color_space;
     268             :   int color_range;
     269             :   int render_width;
     270             :   int render_height;
     271             : 
     272             : #if CONFIG_EXT_PARTITION
     273             :   aom_superblock_size_t superblock_size;
     274             : #endif  // CONFIG_EXT_PARTITION
     275             : #if CONFIG_ANS && ANS_MAX_SYMBOLS
     276             :   int ans_window_size_log2;
     277             : #endif  // CONFIG_ANS && ANS_MAX_SYMBOLS
     278             : #if CONFIG_EXT_TILE
     279             :   unsigned int tile_encoding_mode;
     280             : #endif  // CONFIG_EXT_TILE
     281             : 
     282             :   unsigned int motion_vector_unit_test;
     283             : } AV1EncoderConfig;
     284             : 
     285           0 : static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) {
     286           0 :   return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
     287             : }
     288             : 
     289             : // TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
     290             : typedef struct TileDataEnc {
     291             :   TileInfo tile_info;
     292             :   int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
     293             :   int mode_map[BLOCK_SIZES][MAX_MODES];
     294             :   int m_search_count;
     295             :   int ex_search_count;
     296             : #if CONFIG_PVQ
     297             :   PVQ_QUEUE pvq_q;
     298             : #endif
     299             : #if CONFIG_CFL
     300             :   CFL_CTX cfl;
     301             : #endif
     302             : #if CONFIG_EC_ADAPT
     303             :   DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx);
     304             : #endif
     305             : } TileDataEnc;
     306             : 
     307             : typedef struct RD_COUNTS {
     308             :   av1_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
     309             :   int64_t comp_pred_diff[REFERENCE_MODES];
     310             : #if CONFIG_GLOBAL_MOTION
     311             :   // Stores number of 4x4 blocks using global motion per reference frame.
     312             :   int global_motion_used[TOTAL_REFS_PER_FRAME];
     313             : #endif  // CONFIG_GLOBAL_MOTION
     314             : } RD_COUNTS;
     315             : 
     316             : typedef struct ThreadData {
     317             :   MACROBLOCK mb;
     318             :   RD_COUNTS rd_counts;
     319             :   FRAME_COUNTS *counts;
     320             : 
     321             :   PICK_MODE_CONTEXT *leaf_tree;
     322             :   PC_TREE *pc_tree;
     323             :   PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1];
     324             : #if CONFIG_MOTION_VAR
     325             :   int32_t *wsrc_buf;
     326             :   int32_t *mask_buf;
     327             :   uint8_t *above_pred_buf;
     328             :   uint8_t *left_pred_buf;
     329             : #endif
     330             : 
     331             : #if CONFIG_PALETTE
     332             :   PALETTE_BUFFER *palette_buffer;
     333             : #endif  // CONFIG_PALETTE
     334             : } ThreadData;
     335             : 
     336             : struct EncWorkerData;
     337             : 
     338             : typedef struct ActiveMap {
     339             :   int enabled;
     340             :   int update;
     341             :   unsigned char *map;
     342             : } ActiveMap;
     343             : 
     344             : #define NUM_STAT_TYPES 4  // types of stats: Y, U, V and ALL
     345             : 
     346             : typedef struct IMAGE_STAT {
     347             :   double stat[NUM_STAT_TYPES];
     348             :   double worst;
     349             : } ImageStat;
     350             : 
     351             : #undef NUM_STAT_TYPES
     352             : 
     353             : typedef struct {
     354             :   int ref_count;
     355             :   YV12_BUFFER_CONFIG buf;
     356             : } EncRefCntBuffer;
     357             : 
     358             : typedef struct TileBufferEnc {
     359             :   uint8_t *data;
     360             :   size_t size;
     361             : } TileBufferEnc;
     362             : 
     363             : typedef struct AV1_COMP {
     364             :   QUANTS quants;
     365             :   ThreadData td;
     366             :   MB_MODE_INFO_EXT *mbmi_ext_base;
     367             :   Dequants dequants;
     368             :   AV1_COMMON common;
     369             :   AV1EncoderConfig oxcf;
     370             :   struct lookahead_ctx *lookahead;
     371             :   struct lookahead_entry *alt_ref_source;
     372             : 
     373             :   YV12_BUFFER_CONFIG *source;
     374             :   YV12_BUFFER_CONFIG *last_source;  // NULL for first frame and alt_ref frames
     375             :   YV12_BUFFER_CONFIG *un_scaled_source;
     376             :   YV12_BUFFER_CONFIG scaled_source;
     377             :   YV12_BUFFER_CONFIG *unscaled_last_source;
     378             :   YV12_BUFFER_CONFIG scaled_last_source;
     379             : 
     380             :   // Up-sampled reference buffers
     381             :   // NOTE(zoeliu): It is needed to allocate sufficient space to the up-sampled
     382             :   // reference buffers, which should include the up-sampled version of all the
     383             :   // possibly stored references plus the currently coded frame itself.
     384             :   EncRefCntBuffer upsampled_ref_bufs[REF_FRAMES + 1];
     385             :   int upsampled_ref_idx[REF_FRAMES + 1];
     386             : 
     387             :   // For a still frame, this flag is set to 1 to skip partition search.
     388             :   int partition_search_skippable_frame;
     389             : 
     390             :   int scaled_ref_idx[TOTAL_REFS_PER_FRAME];
     391             : #if CONFIG_EXT_REFS
     392             :   int lst_fb_idxes[LAST_REF_FRAMES];
     393             : #else
     394             :   int lst_fb_idx;
     395             : #endif  // CONFIG_EXT_REFS
     396             :   int gld_fb_idx;
     397             : #if CONFIG_EXT_REFS
     398             :   int bwd_fb_idx;  // BWD_REF_FRAME
     399             : #endif             // CONFIG_EXT_REFS
     400             :   int alt_fb_idx;
     401             : 
     402             :   int last_show_frame_buf_idx;  // last show frame buffer index
     403             : 
     404             :   int refresh_last_frame;
     405             :   int refresh_golden_frame;
     406             : #if CONFIG_EXT_REFS
     407             :   int refresh_bwd_ref_frame;
     408             : #endif  // CONFIG_EXT_REFS
     409             :   int refresh_alt_ref_frame;
     410             : 
     411             :   int ext_refresh_frame_flags_pending;
     412             :   int ext_refresh_last_frame;
     413             :   int ext_refresh_golden_frame;
     414             :   int ext_refresh_alt_ref_frame;
     415             : 
     416             :   int ext_refresh_frame_context_pending;
     417             :   int ext_refresh_frame_context;
     418             : 
     419             :   YV12_BUFFER_CONFIG last_frame_uf;
     420             : #if CONFIG_LOOP_RESTORATION
     421             :   YV12_BUFFER_CONFIG last_frame_db;
     422             :   YV12_BUFFER_CONFIG trial_frame_rst;
     423             :   uint8_t *extra_rstbuf;  // Extra buffers used in restoration search
     424             :   RestorationInfo rst_search[MAX_MB_PLANE];  // Used for encoder side search
     425             : #endif                                       // CONFIG_LOOP_RESTORATION
     426             : 
     427             :   // Ambient reconstruction err target for force key frames
     428             :   int64_t ambient_err;
     429             : 
     430             :   RD_OPT rd;
     431             : 
     432             :   CODING_CONTEXT coding_context;
     433             : 
     434             :   int nmv_costs[NMV_CONTEXTS][2][MV_VALS];
     435             :   int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS];
     436             : 
     437             :   int64_t last_time_stamp_seen;
     438             :   int64_t last_end_time_stamp_seen;
     439             :   int64_t first_time_stamp_ever;
     440             : 
     441             :   RATE_CONTROL rc;
     442             : #if CONFIG_XIPHRC
     443             :   od_rc_state od_rc;
     444             : #endif
     445             :   double framerate;
     446             : 
     447             :   // NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter
     448             :   // references; Plus the currently coded frame itself, it is needed to allocate
     449             :   // sufficient space to the size of the maximum possible number of frames.
     450             :   int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE];
     451             : 
     452             :   struct aom_codec_pkt_list *output_pkt_list;
     453             : 
     454             :   MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
     455             :   int mbgraph_n_frames;  // number of frames filled in the above
     456             :   int static_mb_pct;     // % forced skip mbs by segmentation
     457             :   int ref_frame_flags;
     458             : 
     459             :   SPEED_FEATURES sf;
     460             : 
     461             :   unsigned int max_mv_magnitude;
     462             :   int mv_step_param;
     463             : 
     464             :   int allow_comp_inter_inter;
     465             : 
     466             :   uint8_t *segmentation_map;
     467             : 
     468             :   CYCLIC_REFRESH *cyclic_refresh;
     469             :   ActiveMap active_map;
     470             : 
     471             :   fractional_mv_step_fp *find_fractional_mv_step;
     472             :   av1_full_search_fn_t full_search_sad;  // It is currently unused.
     473             :   av1_diamond_search_fn_t diamond_search_sad;
     474             :   aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
     475             :   uint64_t time_receive_data;
     476             :   uint64_t time_compress_data;
     477             :   uint64_t time_pick_lpf;
     478             :   uint64_t time_encode_sb_row;
     479             : 
     480             : #if CONFIG_FP_MB_STATS
     481             :   int use_fp_mb_stats;
     482             : #endif
     483             : 
     484             :   TWO_PASS twopass;
     485             : 
     486             :   YV12_BUFFER_CONFIG alt_ref_buffer;
     487             : 
     488             : #if CONFIG_INTERNAL_STATS
     489             :   unsigned int mode_chosen_counts[MAX_MODES];
     490             : 
     491             :   int count;
     492             :   uint64_t total_sq_error;
     493             :   uint64_t total_samples;
     494             :   ImageStat psnr;
     495             : 
     496             :   double total_blockiness;
     497             :   double worst_blockiness;
     498             : 
     499             :   int bytes;
     500             :   double summed_quality;
     501             :   double summed_weights;
     502             :   unsigned int tot_recode_hits;
     503             :   double worst_ssim;
     504             : 
     505             :   ImageStat fastssim;
     506             :   ImageStat psnrhvs;
     507             : 
     508             :   int b_calculate_blockiness;
     509             :   int b_calculate_consistency;
     510             : 
     511             :   double total_inconsistency;
     512             :   double worst_consistency;
     513             :   Ssimv *ssim_vars;
     514             :   Metrics metrics;
     515             : #endif
     516             :   int b_calculate_psnr;
     517             : 
     518             :   int droppable;
     519             : 
     520             :   int initial_width;
     521             :   int initial_height;
     522             :   int initial_mbs;  // Number of MBs in the full-size frame; to be used to
     523             :                     // normalize the firstpass stats. This will differ from the
     524             :                     // number of MBs in the current frame when the frame is
     525             :                     // scaled.
     526             : 
     527             :   int frame_flags;
     528             : 
     529             :   search_site_config ss_cfg;
     530             : 
     531             :   int mbmode_cost[BLOCK_SIZE_GROUPS][INTRA_MODES];
     532             :   int newmv_mode_cost[NEWMV_MODE_CONTEXTS][2];
     533             :   int zeromv_mode_cost[ZEROMV_MODE_CONTEXTS][2];
     534             :   int refmv_mode_cost[REFMV_MODE_CONTEXTS][2];
     535             :   int drl_mode_cost0[DRL_MODE_CONTEXTS][2];
     536             : 
     537             :   unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
     538             : #if CONFIG_EXT_INTER
     539             :   unsigned int inter_compound_mode_cost[INTER_MODE_CONTEXTS]
     540             :                                        [INTER_COMPOUND_MODES];
     541             : #if CONFIG_INTERINTRA
     542             :   unsigned int interintra_mode_cost[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
     543             : #endif  // CONFIG_INTERINTRA
     544             : #endif  // CONFIG_EXT_INTER
     545             : #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
     546             :   int motion_mode_cost[BLOCK_SIZES][MOTION_MODES];
     547             : #if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
     548             :   int motion_mode_cost1[BLOCK_SIZES][2];
     549             : #endif  // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
     550             : #endif  // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
     551             :   int intra_uv_mode_cost[INTRA_MODES][INTRA_MODES];
     552             :   int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
     553             :   int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
     554             : #if CONFIG_EXT_PARTITION_TYPES
     555             :   int partition_cost[PARTITION_CONTEXTS + CONFIG_UNPOISON_PARTITION_CTX]
     556             :                     [EXT_PARTITION_TYPES];
     557             : #else
     558             :   int partition_cost[PARTITION_CONTEXTS + CONFIG_UNPOISON_PARTITION_CTX]
     559             :                     [PARTITION_TYPES];
     560             : #endif
     561             : #if CONFIG_PALETTE
     562             :   int palette_y_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES];
     563             :   int palette_uv_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES];
     564             :   int palette_y_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
     565             :                           [PALETTE_COLORS];
     566             :   int palette_uv_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
     567             :                            [PALETTE_COLORS];
     568             : #endif  // CONFIG_PALETTE
     569             :   int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES];
     570             : #if CONFIG_EXT_TX
     571             :   int inter_tx_type_costs[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES];
     572             :   int intra_tx_type_costs[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
     573             :                          [TX_TYPES];
     574             : #else
     575             :   int intra_tx_type_costs[EXT_TX_SIZES][TX_TYPES][TX_TYPES];
     576             :   int inter_tx_type_costs[EXT_TX_SIZES][TX_TYPES];
     577             : #endif  // CONFIG_EXT_TX
     578             : #if CONFIG_EXT_INTRA
     579             : #if CONFIG_INTRA_INTERP
     580             :   int intra_filter_cost[INTRA_FILTERS + 1][INTRA_FILTERS];
     581             : #endif  // CONFIG_INTRA_INTERP
     582             : #endif  // CONFIG_EXT_INTRA
     583             : #if CONFIG_LOOP_RESTORATION
     584             :   int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES];
     585             : #endif  // CONFIG_LOOP_RESTORATION
     586             : #if CONFIG_GLOBAL_MOTION
     587             :   int gmtype_cost[TRANS_TYPES];
     588             :   int gmparams_cost[TOTAL_REFS_PER_FRAME];
     589             : #endif  // CONFIG_GLOBAL_MOTION
     590             : 
     591             :   int multi_arf_allowed;
     592             :   int multi_arf_enabled;
     593             :   int multi_arf_last_grp_enabled;
     594             : 
     595             :   TileDataEnc *tile_data;
     596             :   int allocated_tiles;  // Keep track of memory allocated for tiles.
     597             : 
     598             :   TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS];
     599             :   unsigned int tok_count[MAX_TILE_ROWS][MAX_TILE_COLS];
     600             : 
     601             :   TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS];
     602             : 
     603             :   int resize_state;
     604             :   int resize_scale_num;
     605             :   int resize_scale_den;
     606             :   int resize_next_scale_num;
     607             :   int resize_next_scale_den;
     608             :   int resize_avg_qp;
     609             :   int resize_buffer_underflow;
     610             :   int resize_count;
     611             : 
     612             : #if CONFIG_FRAME_SUPERRES
     613             :   int superres_pending;
     614             : #endif  // CONFIG_FRAME_SUPERRES
     615             : 
     616             :   // VARIANCE_AQ segment map refresh
     617             :   int vaq_refresh;
     618             : 
     619             :   // Multi-threading
     620             :   int num_workers;
     621             :   AVxWorker *workers;
     622             :   struct EncWorkerData *tile_thr_data;
     623             :   AV1LfSync lf_row_sync;
     624             : #if CONFIG_ANS
     625             :   struct BufAnsCoder buf_ans;
     626             : #endif
     627             : #if CONFIG_EXT_REFS
     628             :   int refresh_frame_mask;
     629             :   int existing_fb_idx_to_show;
     630             :   int is_arf_filter_off[MAX_EXT_ARFS + 1];
     631             :   int num_extra_arfs;
     632             :   int arf_map[MAX_EXT_ARFS + 1];
     633             : #endif  // CONFIG_EXT_REFS
     634             : #if CONFIG_GLOBAL_MOTION
     635             :   int global_motion_search_done;
     636             : #endif
     637             : #if CONFIG_REFERENCE_BUFFER
     638             :   SequenceHeader seq_params;
     639             : #endif
     640             : #if CONFIG_LV_MAP
     641             :   tran_low_t *tcoeff_buf[MAX_MB_PLANE];
     642             : #endif
     643             : } AV1_COMP;
     644             : 
     645             : void av1_initialize_enc(void);
     646             : 
     647             : struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
     648             :                                        BufferPool *const pool);
     649             : void av1_remove_compressor(AV1_COMP *cpi);
     650             : 
     651             : void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf);
     652             : 
     653             : // receive a frames worth of data. caller can assume that a copy of this
     654             : // frame is made and not just a copy of the pointer..
     655             : int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
     656             :                           YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
     657             :                           int64_t end_time_stamp);
     658             : 
     659             : int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
     660             :                             size_t *size, uint8_t *dest, int64_t *time_stamp,
     661             :                             int64_t *time_end, int flush);
     662             : 
     663             : int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest);
     664             : 
     665             : int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame);
     666             : 
     667             : int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags);
     668             : 
     669             : void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags);
     670             : 
     671             : int av1_copy_reference_enc(AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag,
     672             :                            YV12_BUFFER_CONFIG *sd);
     673             : 
     674             : int av1_set_reference_enc(AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag,
     675             :                           YV12_BUFFER_CONFIG *sd);
     676             : 
     677             : int av1_update_entropy(AV1_COMP *cpi, int update);
     678             : 
     679             : int av1_set_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
     680             : 
     681             : int av1_get_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
     682             : 
     683             : int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode,
     684             :                           AOM_SCALING vert_mode);
     685             : 
     686             : // Returns 1 if the assigned width or height was <= 0.
     687             : int av1_set_size_literal(AV1_COMP *cpi, int width, int height);
     688             : 
     689             : int av1_get_quantizer(struct AV1_COMP *cpi);
     690             : 
     691             : void av1_full_to_model_counts(av1_coeff_count_model *model_count,
     692             :                               av1_coeff_count *full_count);
     693             : 
     694           0 : static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) {
     695           0 :   return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
     696           0 :          (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
     697             : }
     698             : 
     699           0 : static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi,
     700             :                                         MV_REFERENCE_FRAME ref_frame) {
     701             : #if CONFIG_EXT_REFS
     702           0 :   if (ref_frame >= LAST_FRAME && ref_frame <= LAST3_FRAME)
     703           0 :     return cpi->lst_fb_idxes[ref_frame - 1];
     704             : #else
     705             :   if (ref_frame == LAST_FRAME) return cpi->lst_fb_idx;
     706             : #endif  // CONFIG_EXT_REFS
     707           0 :   else if (ref_frame == GOLDEN_FRAME)
     708           0 :     return cpi->gld_fb_idx;
     709             : #if CONFIG_EXT_REFS
     710           0 :   else if (ref_frame == BWDREF_FRAME)
     711           0 :     return cpi->bwd_fb_idx;
     712             : #endif  // CONFIG_EXT_REFS
     713             :   else
     714           0 :     return cpi->alt_fb_idx;
     715             : }
     716             : 
     717           0 : static INLINE int get_ref_frame_buf_idx(const AV1_COMP *cpi,
     718             :                                         MV_REFERENCE_FRAME ref_frame) {
     719           0 :   const AV1_COMMON *const cm = &cpi->common;
     720           0 :   const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
     721           0 :   return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
     722             : }
     723             : 
     724           0 : static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
     725             :     const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
     726           0 :   const AV1_COMMON *const cm = &cpi->common;
     727           0 :   const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
     728           0 :   return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf
     729           0 :                                 : NULL;
     730             : }
     731             : 
     732           0 : static INLINE const YV12_BUFFER_CONFIG *get_upsampled_ref(
     733             :     const AV1_COMP *cpi, const MV_REFERENCE_FRAME ref_frame) {
     734             :   // Use up-sampled reference frames.
     735           0 :   const int buf_idx =
     736           0 :       cpi->upsampled_ref_idx[get_ref_frame_map_idx(cpi, ref_frame)];
     737           0 :   return &cpi->upsampled_ref_bufs[buf_idx].buf;
     738             : }
     739             : 
     740             : #if CONFIG_EXT_REFS || CONFIG_TEMPMV_SIGNALING
     741           0 : static INLINE int enc_is_ref_frame_buf(AV1_COMP *cpi, RefCntBuffer *frame_buf) {
     742             :   MV_REFERENCE_FRAME ref_frame;
     743           0 :   AV1_COMMON *const cm = &cpi->common;
     744           0 :   for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
     745           0 :     const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
     746           0 :     if (buf_idx == INVALID_IDX) continue;
     747           0 :     if (frame_buf == &cm->buffer_pool->frame_bufs[buf_idx]) break;
     748             :   }
     749           0 :   return (ref_frame <= ALTREF_FRAME);
     750             : }
     751             : #endif  // CONFIG_EXT_REFS
     752             : 
     753           0 : static INLINE unsigned int get_token_alloc(int mb_rows, int mb_cols) {
     754             :   // We assume 3 planes all at full resolution. We assume up to 1 token per
     755             :   // pixel, and then allow a head room of 1 EOSB token per 4x4 block per plane,
     756             :   // plus EOSB_TOKEN per plane.
     757           0 :   return mb_rows * mb_cols * (16 * 16 + 17) * 3;
     758             : }
     759             : 
     760             : // Get the allocated token size for a tile. It does the same calculation as in
     761             : // the frame token allocation.
     762           0 : static INLINE unsigned int allocated_tokens(TileInfo tile) {
     763             : #if CONFIG_CB4X4
     764           0 :   int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 2) >> 2;
     765           0 :   int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 2) >> 2;
     766             : #else
     767             :   int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
     768             :   int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
     769             : #endif
     770             : 
     771           0 :   return get_token_alloc(tile_mb_rows, tile_mb_cols);
     772             : }
     773             : 
     774             : void av1_alloc_compressor_data(AV1_COMP *cpi);
     775             : 
     776             : void av1_scale_references(AV1_COMP *cpi);
     777             : 
     778             : void av1_update_reference_frames(AV1_COMP *cpi);
     779             : 
     780             : void av1_set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv);
     781             : #if CONFIG_TEMPMV_SIGNALING
     782             : void av1_set_temporal_mv_prediction(AV1_COMP *cpi, int allow_tempmv_prediction);
     783             : #endif
     784             : 
     785             : void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags);
     786             : 
     787           0 : static INLINE int is_altref_enabled(const AV1_COMP *const cpi) {
     788           0 :   return cpi->oxcf.lag_in_frames > 0 && cpi->oxcf.enable_auto_arf;
     789             : }
     790             : 
     791             : // TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf
     792             : #if 0 && CONFIG_EXT_REFS
     793             : static INLINE int is_bwdref_enabled(const AV1_COMP *const cpi) {
     794             :   // NOTE(zoeliu): The enabling of bi-predictive frames depends on the use of
     795             :   //               alt_ref, and now will be off when the alt_ref interval is
     796             :   //               not sufficiently large.
     797             :   return is_altref_enabled(cpi) && cpi->oxcf.enable_auto_brf;
     798             : }
     799             : #endif  // CONFIG_EXT_REFS
     800             : 
     801           0 : static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd,
     802             :                                 MV_REFERENCE_FRAME ref0,
     803             :                                 MV_REFERENCE_FRAME ref1) {
     804           0 :   xd->block_refs[0] =
     805           0 :       &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0];
     806           0 :   xd->block_refs[1] =
     807           0 :       &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0];
     808           0 : }
     809             : 
     810           0 : static INLINE int get_chessboard_index(int frame_index) {
     811           0 :   return frame_index & 0x1;
     812             : }
     813             : 
     814           0 : static INLINE int *cond_cost_list(const struct AV1_COMP *cpi, int *cost_list) {
     815           0 :   return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
     816             : }
     817             : 
     818             : void av1_new_framerate(AV1_COMP *cpi, double framerate);
     819             : 
     820             : #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
     821             : 
     822             : // Update up-sampled reference frame index.
     823           0 : static INLINE void uref_cnt_fb(EncRefCntBuffer *ubufs, int *uidx,
     824             :                                int new_uidx) {
     825           0 :   const int ref_index = *uidx;
     826             : 
     827           0 :   if (ref_index >= 0 && ubufs[ref_index].ref_count > 0)
     828           0 :     ubufs[ref_index].ref_count--;
     829             : 
     830           0 :   *uidx = new_uidx;
     831           0 :   ubufs[new_uidx].ref_count++;
     832           0 : }
     833             : 
     834             : // Returns 1 if a resize is pending and 0 otherwise.
     835           0 : static INLINE int av1_resize_pending(const struct AV1_COMP *cpi) {
     836           0 :   return cpi->resize_scale_num != cpi->resize_next_scale_num ||
     837           0 :          cpi->resize_scale_den != cpi->resize_next_scale_den;
     838             : }
     839             : 
     840             : // Returns 1 if a frame is unscaled and 0 otherwise.
     841           0 : static INLINE int av1_resize_unscaled(const struct AV1_COMP *cpi) {
     842           0 :   return cpi->resize_scale_num == cpi->resize_scale_den;
     843             : }
     844             : 
     845             : // Moves resizing to the next state. This is just setting the numerator and
     846             : // denominator to the next numerator and denominator, causing
     847             : // av1_resize_pending to subsequently return false.
     848           0 : static INLINE void av1_resize_step(struct AV1_COMP *cpi) {
     849           0 :   cpi->resize_scale_num = cpi->resize_next_scale_num;
     850           0 :   cpi->resize_scale_den = cpi->resize_next_scale_den;
     851           0 : }
     852             : 
     853             : #ifdef __cplusplus
     854             : }  // extern "C"
     855             : #endif
     856             : 
     857             : #endif  // AV1_ENCODER_ENCODER_H_

Generated by: LCOV version 1.13