Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_ENCODER_ENCODER_H_ |
| 13 | #define AV1_ENCODER_ENCODER_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include <stdio.h> |
| 16 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 17 | #include "config/aom_config.h" |
| 18 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 19 | #include "aom/aomcx.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | |
| 21 | #include "av1/common/alloccommon.h" |
| 22 | #include "av1/common/entropymode.h" |
| 23 | #include "av1/common/thread_common.h" |
| 24 | #include "av1/common/onyxc_int.h" |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 25 | #include "av1/common/resize.h" |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 26 | #include "av1/common/timing.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | #include "av1/encoder/aq_cyclicrefresh.h" |
Tom Finegan | 17ce8b1 | 2017-02-08 12:46:31 -0800 | [diff] [blame] | 28 | #include "av1/encoder/av1_quantize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | #include "av1/encoder/context_tree.h" |
| 30 | #include "av1/encoder/encodemb.h" |
| 31 | #include "av1/encoder/firstpass.h" |
| 32 | #include "av1/encoder/lookahead.h" |
| 33 | #include "av1/encoder/mbgraph.h" |
| 34 | #include "av1/encoder/mcomp.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 35 | #include "av1/encoder/ratectrl.h" |
| 36 | #include "av1/encoder/rd.h" |
| 37 | #include "av1/encoder/speed_features.h" |
| 38 | #include "av1/encoder/tokenize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | |
| 40 | #if CONFIG_INTERNAL_STATS |
| 41 | #include "aom_dsp/ssim.h" |
| 42 | #endif |
| 43 | #include "aom_dsp/variance.h" |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 44 | #if CONFIG_DENOISE |
| 45 | #include "aom_dsp/noise_model.h" |
| 46 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 47 | #include "aom/internal/aom_codec_internal.h" |
| 48 | #include "aom_util/aom_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 49 | |
| 50 | #ifdef __cplusplus |
| 51 | extern "C" { |
| 52 | #endif |
| 53 | |
| 54 | typedef struct { |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 55 | int nmv_vec_cost[MV_JOINTS]; |
| 56 | int nmv_costs[2][MV_VALS]; |
| 57 | int nmv_costs_hp[2][MV_VALS]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 58 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 59 | FRAME_CONTEXT fc; |
| 60 | } CODING_CONTEXT; |
| 61 | |
| 62 | typedef enum { |
| 63 | // regular inter frame |
| 64 | REGULAR_FRAME = 0, |
| 65 | // alternate reference frame |
| 66 | ARF_FRAME = 1, |
| 67 | // overlay frame |
| 68 | OVERLAY_FRAME = 2, |
| 69 | // golden frame |
| 70 | GLD_FRAME = 3, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 71 | // backward reference frame |
| 72 | BRF_FRAME = 4, |
| 73 | // extra alternate reference frame |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 74 | EXT_ARF_FRAME = 5, |
| 75 | FRAME_CONTEXT_INDEXES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 76 | } FRAME_CONTEXT_INDEX; |
| 77 | |
| 78 | typedef enum { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | NORMAL = 0, |
| 80 | FOURFIVE = 1, |
| 81 | THREEFIVE = 2, |
| 82 | ONETWO = 3 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 83 | } AOM_SCALING; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 84 | |
| 85 | typedef enum { |
| 86 | // Good Quality Fast Encoding. The encoder balances quality with the amount of |
| 87 | // time it takes to encode the output. Speed setting controls how fast. |
Thomas Daede | 8082614 | 2017-03-20 15:44:24 -0700 | [diff] [blame] | 88 | GOOD |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 89 | } MODE; |
| 90 | |
| 91 | typedef enum { |
| 92 | FRAMEFLAGS_KEY = 1 << 0, |
| 93 | FRAMEFLAGS_GOLDEN = 1 << 1, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 94 | FRAMEFLAGS_BWDREF = 1 << 2, |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 95 | // TODO(zoeliu): To determine whether a frame flag is needed for ALTREF2_FRAME |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 96 | FRAMEFLAGS_ALTREF = 1 << 3, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 97 | } FRAMETYPE_FLAGS; |
| 98 | |
| 99 | typedef enum { |
| 100 | NO_AQ = 0, |
| 101 | VARIANCE_AQ = 1, |
| 102 | COMPLEXITY_AQ = 2, |
| 103 | CYCLIC_REFRESH_AQ = 3, |
| 104 | AQ_MODE_COUNT // This should always be the last member of the enum |
| 105 | } AQ_MODE; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 106 | typedef enum { |
| 107 | NO_DELTA_Q = 0, |
| 108 | DELTA_Q_ONLY = 1, |
| 109 | DELTA_Q_LF = 2, |
| 110 | DELTAQ_MODE_COUNT // This should always be the last member of the enum |
| 111 | } DELTAQ_MODE; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 112 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 113 | typedef enum { |
| 114 | RESIZE_NONE = 0, // No frame resizing allowed. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 115 | RESIZE_FIXED = 1, // All frames are coded at the specified scale. |
| 116 | RESIZE_RANDOM = 2, // All frames are coded at a random scale. |
| 117 | RESIZE_MODES |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 118 | } RESIZE_MODE; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 119 | |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 120 | typedef enum { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 121 | SUPERRES_NONE = 0, // No frame superres allowed |
| 122 | SUPERRES_FIXED = 1, // All frames are coded at the specified scale, |
| 123 | // and super-resolved. |
| 124 | SUPERRES_RANDOM = 2, // All frames are coded at a random scale, |
| 125 | // and super-resolved. |
| 126 | SUPERRES_QTHRESH = 3, // Superres scale for a frame is determined based on |
| 127 | // q_index |
| 128 | SUPERRES_MODES |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 129 | } SUPERRES_MODE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 130 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 131 | typedef struct AV1EncoderConfig { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 132 | BITSTREAM_PROFILE profile; |
Tom Finegan | 8ab2bba | 2018-02-28 07:36:28 -0800 | [diff] [blame] | 133 | aom_bit_depth_t bit_depth; // Codec bit-depth. |
| 134 | int width; // width of data passed to the compressor |
| 135 | int height; // height of data passed to the compressor |
| 136 | int forced_max_frame_width; // forced maximum width of frame (if != 0) |
| 137 | int forced_max_frame_height; // forced maximum height of frame (if != 0) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 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. |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 158 | int sframe_dist; |
| 159 | int sframe_mode; |
| 160 | int sframe_enabled; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 161 | int lag_in_frames; // how many frames lag before we start encoding |
Sarah Parker | 93c0314 | 2018-05-22 13:35:45 -0700 | [diff] [blame] | 162 | int fwd_kf_enabled; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 163 | |
| 164 | // ---------------------------------------------------------------- |
| 165 | // DATARATE CONTROL OPTIONS |
| 166 | |
| 167 | // vbr, cbr, constrained quality or constant quality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 168 | enum aom_rc_mode rc_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 169 | |
| 170 | // buffer targeting aggressiveness |
| 171 | int under_shoot_pct; |
| 172 | int over_shoot_pct; |
| 173 | |
| 174 | // buffering parameters |
| 175 | int64_t starting_buffer_level_ms; |
| 176 | int64_t optimal_buffer_level_ms; |
| 177 | int64_t maximum_buffer_size_ms; |
| 178 | |
| 179 | // Frame drop threshold. |
| 180 | int drop_frames_water_mark; |
| 181 | |
| 182 | // controlling quality |
| 183 | int fixed_q; |
| 184 | int worst_allowed_q; |
| 185 | int best_allowed_q; |
| 186 | int cq_level; |
| 187 | AQ_MODE aq_mode; // Adaptive Quantization mode |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 188 | DELTAQ_MODE deltaq_mode; |
Debargha Mukherjee | 98a311c | 2018-03-25 16:33:11 -0700 | [diff] [blame] | 189 | int enable_cdef; |
| 190 | int enable_restoration; |
Yue Chen | 4835dc0 | 2018-05-11 15:57:43 -0700 | [diff] [blame] | 191 | int disable_trellis_quant; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 192 | int using_qm; |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 193 | int qm_y; |
| 194 | int qm_u; |
| 195 | int qm_v; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | int qm_minlevel; |
| 197 | int qm_maxlevel; |
Yushin Cho | d808bfc | 2017-08-10 15:54:36 -0700 | [diff] [blame] | 198 | #if CONFIG_DIST_8X8 |
| 199 | int using_dist_8x8; |
| 200 | #endif |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 201 | unsigned int num_tile_groups; |
| 202 | unsigned int mtu; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 203 | |
| 204 | // Internal frame size scaling. |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 205 | RESIZE_MODE resize_mode; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 206 | uint8_t resize_scale_denominator; |
| 207 | uint8_t resize_kf_scale_denominator; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 208 | |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 209 | // Frame Super-Resolution size scaling. |
| 210 | SUPERRES_MODE superres_mode; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 211 | uint8_t superres_scale_denominator; |
| 212 | uint8_t superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 213 | int superres_qthresh; |
| 214 | int superres_kf_qthresh; |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 215 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 216 | // Enable feature to reduce the frame quantization every x frames. |
| 217 | int frame_periodic_boost; |
| 218 | |
| 219 | // two pass datarate control |
| 220 | int two_pass_vbrbias; // two pass datarate control tweaks |
| 221 | int two_pass_vbrmin_section; |
| 222 | int two_pass_vbrmax_section; |
| 223 | // END DATARATE CONTROL OPTIONS |
| 224 | // ---------------------------------------------------------------- |
| 225 | |
| 226 | int enable_auto_arf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 227 | int enable_auto_brf; // (b)ackward (r)ef (f)rame |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 228 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 229 | /* Bitfield defining the error resiliency features to enable. |
| 230 | * Can provide decodable frames after losses in previous |
| 231 | * frames and decodable partitions after losses in the same frame. |
| 232 | */ |
| 233 | unsigned int error_resilient_mode; |
| 234 | |
Debargha Mukherjee | 52fb047 | 2018-03-29 15:48:11 -0700 | [diff] [blame] | 235 | unsigned int s_frame_mode; |
| 236 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 237 | /* Bitfield defining the parallel decoding mode where the |
| 238 | * decoding in successive frames may be conducted in parallel |
| 239 | * just by decoding the frame headers. |
| 240 | */ |
| 241 | unsigned int frame_parallel_decoding_mode; |
| 242 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 243 | unsigned int limit; |
| 244 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 245 | int arnr_max_frames; |
| 246 | int arnr_strength; |
| 247 | |
| 248 | int min_gf_interval; |
| 249 | int max_gf_interval; |
| 250 | |
Ravi Chaudhary | 0ec03a4 | 2018-08-17 18:53:28 +0530 | [diff] [blame] | 251 | int row_mt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 252 | int tile_columns; |
| 253 | int tile_rows; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 254 | int tile_width_count; |
| 255 | int tile_height_count; |
| 256 | int tile_widths[MAX_TILE_COLS]; |
| 257 | int tile_heights[MAX_TILE_ROWS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 258 | |
| 259 | int max_threads; |
| 260 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 261 | aom_fixed_buf_t two_pass_stats_in; |
| 262 | struct aom_codec_pkt_list *output_pkt_list; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 263 | |
| 264 | #if CONFIG_FP_MB_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 265 | aom_fixed_buf_t firstpass_mb_stats_in; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 266 | #endif |
| 267 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 268 | aom_tune_metric tuning; |
| 269 | aom_tune_content content; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 270 | int use_highbitdepth; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 271 | aom_color_primaries_t color_primaries; |
| 272 | aom_transfer_characteristics_t transfer_characteristics; |
| 273 | aom_matrix_coefficients_t matrix_coefficients; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 274 | aom_chroma_sample_position_t chroma_sample_position; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 275 | int color_range; |
| 276 | int render_width; |
| 277 | int render_height; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 278 | aom_timing_info_type_t timing_info_type; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 279 | int timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 280 | aom_timing_info_t timing_info; |
| 281 | int decoder_model_info_present_flag; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 282 | int display_model_info_present_flag; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 283 | int buffer_removal_time_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 284 | aom_dec_model_info_t buffer_model; |
| 285 | aom_dec_model_op_parameters_t op_params[MAX_NUM_OPERATING_POINTS + 1]; |
| 286 | aom_op_timing_info_t op_frame_timing[MAX_NUM_OPERATING_POINTS + 1]; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 287 | int film_grain_test_vector; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 288 | const char *film_grain_table_filename; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 289 | |
Hui Su | 1cb1c00 | 2018-02-05 18:21:20 -0800 | [diff] [blame] | 290 | uint8_t cdf_update_mode; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 291 | aom_superblock_size_t superblock_size; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 292 | unsigned int large_scale_tile; |
| 293 | unsigned int single_tile_decoding; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 294 | int monochrome; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 295 | unsigned int full_still_picture_hdr; |
Jingning Han | a446f55 | 2018-02-22 15:42:12 -0800 | [diff] [blame] | 296 | int enable_dual_filter; |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 297 | unsigned int motion_vector_unit_test; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 298 | const cfg_options_t *cfg; |
Debargha Mukherjee | 0d8368a | 2018-03-25 12:23:02 -0700 | [diff] [blame] | 299 | int enable_order_hint; |
Cheng Chen | e0c918a | 2018-02-22 19:38:31 -0800 | [diff] [blame] | 300 | int enable_jnt_comp; |
Debargha Mukherjee | 0187d7c | 2018-03-25 11:37:56 -0700 | [diff] [blame] | 301 | int enable_ref_frame_mvs; |
Debargha Mukherjee | 0d8368a | 2018-03-25 12:23:02 -0700 | [diff] [blame] | 302 | unsigned int allow_ref_frame_mvs; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 303 | int enable_warped_motion; |
| 304 | int allow_warped_motion; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 305 | int enable_superres; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 306 | unsigned int save_as_annexb; |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 307 | |
| 308 | #if CONFIG_DENOISE |
| 309 | float noise_level; |
| 310 | int noise_block_size; |
| 311 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 312 | } AV1EncoderConfig; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 313 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 314 | static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 315 | return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0; |
| 316 | } |
| 317 | |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 318 | typedef struct FRAME_COUNTS { |
| 319 | // Note: This structure should only contain 'unsigned int' fields, or |
| 320 | // aggregates built solely from 'unsigned int' fields/elements |
| 321 | #if CONFIG_ENTROPY_STATS |
| 322 | unsigned int kf_y_mode[KF_MODE_CONTEXTS][KF_MODE_CONTEXTS][INTRA_MODES]; |
| 323 | unsigned int angle_delta[DIRECTIONAL_MODES][2 * MAX_ANGLE_DELTA + 1]; |
| 324 | unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES]; |
| 325 | unsigned int uv_mode[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES]; |
| 326 | unsigned int cfl_sign[CFL_JOINT_SIGNS]; |
| 327 | unsigned int cfl_alpha[CFL_ALPHA_CONTEXTS][CFL_ALPHABET_SIZE]; |
| 328 | unsigned int palette_y_mode[PALATTE_BSIZE_CTXS][PALETTE_Y_MODE_CONTEXTS][2]; |
| 329 | unsigned int palette_uv_mode[PALETTE_UV_MODE_CONTEXTS][2]; |
| 330 | unsigned int palette_y_size[PALATTE_BSIZE_CTXS][PALETTE_SIZES]; |
| 331 | unsigned int palette_uv_size[PALATTE_BSIZE_CTXS][PALETTE_SIZES]; |
| 332 | unsigned int palette_y_color_index[PALETTE_SIZES] |
| 333 | [PALETTE_COLOR_INDEX_CONTEXTS] |
| 334 | [PALETTE_COLORS]; |
| 335 | unsigned int palette_uv_color_index[PALETTE_SIZES] |
| 336 | [PALETTE_COLOR_INDEX_CONTEXTS] |
| 337 | [PALETTE_COLORS]; |
| 338 | unsigned int partition[PARTITION_CONTEXTS][EXT_PARTITION_TYPES]; |
| 339 | unsigned int txb_skip[TOKEN_CDF_Q_CTXS][TX_SIZES][TXB_SKIP_CONTEXTS][2]; |
| 340 | unsigned int eob_extra[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 341 | [EOB_COEF_CONTEXTS][2]; |
| 342 | unsigned int dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS][2]; |
| 343 | unsigned int coeff_lps[TX_SIZES][PLANE_TYPES][BR_CDF_SIZE - 1][LEVEL_CONTEXTS] |
| 344 | [2]; |
| 345 | unsigned int eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS][2]; |
| 346 | unsigned int eob_multi16[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][5]; |
| 347 | unsigned int eob_multi32[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][6]; |
| 348 | unsigned int eob_multi64[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][7]; |
| 349 | unsigned int eob_multi128[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][8]; |
| 350 | unsigned int eob_multi256[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][9]; |
| 351 | unsigned int eob_multi512[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][10]; |
| 352 | unsigned int eob_multi1024[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][11]; |
| 353 | unsigned int coeff_lps_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 354 | [LEVEL_CONTEXTS][BR_CDF_SIZE]; |
| 355 | unsigned int coeff_base_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 356 | [SIG_COEF_CONTEXTS][NUM_BASE_LEVELS + 2]; |
| 357 | unsigned int coeff_base_eob_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 358 | [SIG_COEF_CONTEXTS_EOB][NUM_BASE_LEVELS + 1]; |
| 359 | unsigned int newmv_mode[NEWMV_MODE_CONTEXTS][2]; |
| 360 | unsigned int zeromv_mode[GLOBALMV_MODE_CONTEXTS][2]; |
| 361 | unsigned int refmv_mode[REFMV_MODE_CONTEXTS][2]; |
| 362 | unsigned int drl_mode[DRL_MODE_CONTEXTS][2]; |
| 363 | unsigned int inter_compound_mode[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES]; |
| 364 | unsigned int wedge_idx[BLOCK_SIZES_ALL][16]; |
| 365 | unsigned int interintra[BLOCK_SIZE_GROUPS][2]; |
| 366 | unsigned int interintra_mode[BLOCK_SIZE_GROUPS][INTERINTRA_MODES]; |
| 367 | unsigned int wedge_interintra[BLOCK_SIZES_ALL][2]; |
| 368 | unsigned int compound_type[BLOCK_SIZES_ALL][COMPOUND_TYPES - 1]; |
| 369 | unsigned int motion_mode[BLOCK_SIZES_ALL][MOTION_MODES]; |
| 370 | unsigned int obmc[BLOCK_SIZES_ALL][2]; |
| 371 | unsigned int intra_inter[INTRA_INTER_CONTEXTS][2]; |
| 372 | unsigned int comp_inter[COMP_INTER_CONTEXTS][2]; |
| 373 | unsigned int comp_ref_type[COMP_REF_TYPE_CONTEXTS][2]; |
| 374 | unsigned int uni_comp_ref[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1][2]; |
| 375 | unsigned int single_ref[REF_CONTEXTS][SINGLE_REFS - 1][2]; |
| 376 | unsigned int comp_ref[REF_CONTEXTS][FWD_REFS - 1][2]; |
| 377 | unsigned int comp_bwdref[REF_CONTEXTS][BWD_REFS - 1][2]; |
| 378 | unsigned int intrabc[2]; |
| 379 | |
| 380 | unsigned int txfm_partition[TXFM_PARTITION_CONTEXTS][2]; |
| 381 | unsigned int intra_tx_size[MAX_TX_CATS][TX_SIZE_CONTEXTS][MAX_TX_DEPTH + 1]; |
| 382 | unsigned int skip_mode[SKIP_MODE_CONTEXTS][2]; |
| 383 | unsigned int skip[SKIP_CONTEXTS][2]; |
| 384 | unsigned int compound_index[COMP_INDEX_CONTEXTS][2]; |
| 385 | unsigned int comp_group_idx[COMP_GROUP_IDX_CONTEXTS][2]; |
| 386 | unsigned int delta_q[DELTA_Q_PROBS][2]; |
| 387 | unsigned int delta_lf_multi[FRAME_LF_COUNT][DELTA_LF_PROBS][2]; |
| 388 | unsigned int delta_lf[DELTA_LF_PROBS][2]; |
| 389 | |
| 390 | unsigned int inter_ext_tx[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES]; |
| 391 | unsigned int intra_ext_tx[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES] |
| 392 | [TX_TYPES]; |
| 393 | unsigned int filter_intra_mode[FILTER_INTRA_MODES]; |
| 394 | unsigned int filter_intra[BLOCK_SIZES_ALL][2]; |
| 395 | unsigned int switchable_restore[RESTORE_SWITCHABLE_TYPES]; |
| 396 | unsigned int wiener_restore[2]; |
| 397 | unsigned int sgrproj_restore[2]; |
| 398 | #endif // CONFIG_ENTROPY_STATS |
| 399 | |
| 400 | unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS] |
| 401 | [SWITCHABLE_FILTERS]; |
| 402 | } FRAME_COUNTS; |
| 403 | |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 404 | #if CONFIG_COLLECT_INTER_MODE_RD_STATS |
| 405 | #define INTER_MODE_RD_DATA_OVERALL_SIZE 6400 |
| 406 | |
| 407 | typedef struct { |
| 408 | int ready; |
| 409 | double a; |
| 410 | double b; |
| 411 | double dist_mean; |
Angie Chiang | 199f3d4 | 2018-08-14 18:07:02 -0700 | [diff] [blame] | 412 | double ld_mean; |
| 413 | double sse_mean; |
| 414 | double sse_sse_mean; |
| 415 | double sse_ld_mean; |
Angie Chiang | 106fa48 | 2018-08-07 18:28:40 -0700 | [diff] [blame] | 416 | int num; |
| 417 | double dist_sum; |
| 418 | double ld_sum; |
| 419 | double sse_sum; |
| 420 | double sse_sse_sum; |
| 421 | double sse_ld_sum; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 422 | } InterModeRdModel; |
| 423 | |
| 424 | typedef struct { |
| 425 | int idx; |
| 426 | int64_t rd; |
| 427 | } RdIdxPair; |
| 428 | // TODO(angiebird): This is an estimated size. We still need to figure what is |
| 429 | // the maximum number of modes. |
| 430 | #define MAX_INTER_MODES 1024 |
| 431 | typedef struct inter_modes_info { |
| 432 | int num; |
| 433 | MB_MODE_INFO mbmi_arr[MAX_INTER_MODES]; |
| 434 | int mode_rate_arr[MAX_INTER_MODES]; |
| 435 | int64_t sse_arr[MAX_INTER_MODES]; |
| 436 | int64_t est_rd_arr[MAX_INTER_MODES]; |
| 437 | RdIdxPair rd_idx_pair_arr[MAX_INTER_MODES]; |
| 438 | } InterModesInfo; |
| 439 | #endif |
| 440 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 441 | // TODO(jingning) All spatially adaptive variables should go to TileDataEnc. |
| 442 | typedef struct TileDataEnc { |
| 443 | TileInfo tile_info; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 444 | int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES]; |
| 445 | int mode_map[BLOCK_SIZES_ALL][MAX_MODES]; |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 446 | int m_search_count; |
| 447 | int ex_search_count; |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 448 | CFL_CTX cfl; |
Jingning Han | 9f07be1 | 2017-04-13 09:31:40 -0700 | [diff] [blame] | 449 | DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx); |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 450 | uint8_t allow_update_cdf; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 451 | #if CONFIG_COLLECT_INTER_MODE_RD_STATS |
| 452 | InterModeRdModel inter_mode_rd_models[BLOCK_SIZES_ALL]; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 453 | InterModesInfo inter_modes_info; |
| 454 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 455 | } TileDataEnc; |
| 456 | |
| 457 | typedef struct RD_COUNTS { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 458 | int64_t comp_pred_diff[REFERENCE_MODES]; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 459 | // Stores number of 4x4 blocks using global motion per reference frame. |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 460 | int global_motion_used[REF_FRAMES]; |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 461 | int compound_ref_used_flag; |
Zoe Liu | 8a5d343 | 2017-11-30 16:33:44 -0800 | [diff] [blame] | 462 | int skip_mode_used_flag; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 463 | } RD_COUNTS; |
| 464 | |
| 465 | typedef struct ThreadData { |
| 466 | MACROBLOCK mb; |
| 467 | RD_COUNTS rd_counts; |
| 468 | FRAME_COUNTS *counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 469 | PC_TREE *pc_tree; |
| 470 | PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1]; |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame^] | 471 | uint32_t *hash_value_buffer[2][2]; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 472 | int32_t *wsrc_buf; |
| 473 | int32_t *mask_buf; |
| 474 | uint8_t *above_pred_buf; |
| 475 | uint8_t *left_pred_buf; |
hui su | 5d49314 | 2017-05-08 12:06:12 -0700 | [diff] [blame] | 476 | PALETTE_BUFFER *palette_buffer; |
Hui Su | 8587878 | 2017-11-07 14:56:31 -0800 | [diff] [blame] | 477 | int intrabc_used_this_tile; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 478 | } ThreadData; |
| 479 | |
| 480 | struct EncWorkerData; |
| 481 | |
| 482 | typedef struct ActiveMap { |
| 483 | int enabled; |
| 484 | int update; |
| 485 | unsigned char *map; |
| 486 | } ActiveMap; |
| 487 | |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 488 | #if CONFIG_INTERNAL_STATS |
| 489 | // types of stats |
| 490 | typedef enum { |
| 491 | STAT_Y, |
| 492 | STAT_U, |
| 493 | STAT_V, |
| 494 | STAT_ALL, |
| 495 | NUM_STAT_TYPES // This should always be the last member of the enum |
| 496 | } StatType; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 497 | |
| 498 | typedef struct IMAGE_STAT { |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 499 | double stat[NUM_STAT_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 500 | double worst; |
| 501 | } ImageStat; |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 502 | #endif // CONFIG_INTERNAL_STATS |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 503 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 504 | typedef struct { |
| 505 | int ref_count; |
| 506 | YV12_BUFFER_CONFIG buf; |
| 507 | } EncRefCntBuffer; |
| 508 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 509 | typedef struct TileBufferEnc { |
| 510 | uint8_t *data; |
| 511 | size_t size; |
| 512 | } TileBufferEnc; |
| 513 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 514 | typedef struct AV1_COMP { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 515 | QUANTS quants; |
| 516 | ThreadData td; |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 517 | FRAME_COUNTS counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 518 | MB_MODE_INFO_EXT *mbmi_ext_base; |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 519 | CB_COEFF_BUFFER *coeff_buffer_base; |
Yi Luo | c621023 | 2017-05-25 15:09:25 -0700 | [diff] [blame] | 520 | Dequants dequants; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 521 | AV1_COMMON common; |
| 522 | AV1EncoderConfig oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 523 | struct lookahead_ctx *lookahead; |
| 524 | struct lookahead_entry *alt_ref_source; |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 525 | int no_show_kf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 526 | |
Angie Chiang | e69a682 | 2018-03-16 13:52:44 -0700 | [diff] [blame] | 527 | int optimize_speed_feature; |
| 528 | int optimize_seg_arr[MAX_SEGMENTS]; |
| 529 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 530 | YV12_BUFFER_CONFIG *source; |
| 531 | YV12_BUFFER_CONFIG *last_source; // NULL for first frame and alt_ref frames |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 532 | YV12_BUFFER_CONFIG *unscaled_source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 533 | YV12_BUFFER_CONFIG scaled_source; |
| 534 | YV12_BUFFER_CONFIG *unscaled_last_source; |
| 535 | YV12_BUFFER_CONFIG scaled_last_source; |
| 536 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 537 | // For a still frame, this flag is set to 1 to skip partition search. |
| 538 | int partition_search_skippable_frame; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 539 | double csm_rate_array[32]; |
| 540 | double m_rate_array[32]; |
| 541 | int rate_size; |
| 542 | int rate_index; |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 543 | hash_table *previous_hash_table; |
| 544 | int previous_index; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 545 | int cur_poc; // DebugInfo |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 546 | |
Ravi Chaudhary | 0ec03a4 | 2018-08-17 18:53:28 +0530 | [diff] [blame] | 547 | unsigned int row_mt; |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 548 | int scaled_ref_idx[REF_FRAMES]; |
Zoe Liu | 5989a72 | 2018-03-29 13:37:36 -0700 | [diff] [blame] | 549 | int ref_fb_idx[REF_FRAMES]; |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 550 | int refresh_fb_idx; // ref frame buffer index to refresh |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 551 | |
| 552 | int last_show_frame_buf_idx; // last show frame buffer index |
| 553 | |
| 554 | int refresh_last_frame; |
| 555 | int refresh_golden_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 556 | int refresh_bwd_ref_frame; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 557 | int refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 558 | int refresh_alt_ref_frame; |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 559 | #if USE_SYMM_MULTI_LAYER |
| 560 | int new_bwdref_update_rule; |
| 561 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 562 | |
| 563 | int ext_refresh_frame_flags_pending; |
| 564 | int ext_refresh_last_frame; |
| 565 | int ext_refresh_golden_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 566 | int ext_refresh_bwd_ref_frame; |
| 567 | int ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 568 | int ext_refresh_alt_ref_frame; |
| 569 | |
| 570 | int ext_refresh_frame_context_pending; |
| 571 | int ext_refresh_frame_context; |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 572 | int ext_use_ref_frame_mvs; |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 573 | int ext_use_error_resilient; |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 574 | int ext_use_s_frame; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 575 | int ext_use_primary_ref_none; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 576 | |
| 577 | YV12_BUFFER_CONFIG last_frame_uf; |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 578 | YV12_BUFFER_CONFIG trial_frame_rst; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 579 | |
| 580 | // Ambient reconstruction err target for force key frames |
| 581 | int64_t ambient_err; |
| 582 | |
| 583 | RD_OPT rd; |
| 584 | |
| 585 | CODING_CONTEXT coding_context; |
| 586 | |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 587 | int gmtype_cost[TRANS_TYPES]; |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 588 | int gmparams_cost[REF_FRAMES]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 589 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 590 | int nmv_costs[2][MV_VALS]; |
| 591 | int nmv_costs_hp[2][MV_VALS]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 592 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 593 | int64_t last_time_stamp_seen; |
| 594 | int64_t last_end_time_stamp_seen; |
| 595 | int64_t first_time_stamp_ever; |
| 596 | |
| 597 | RATE_CONTROL rc; |
| 598 | double framerate; |
| 599 | |
| 600 | // NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter |
| 601 | // references; Plus the currently coded frame itself, it is needed to allocate |
| 602 | // sufficient space to the size of the maximum possible number of frames. |
| 603 | int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE]; |
| 604 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 605 | struct aom_codec_pkt_list *output_pkt_list; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 606 | |
| 607 | MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS]; |
| 608 | int mbgraph_n_frames; // number of frames filled in the above |
| 609 | int static_mb_pct; // % forced skip mbs by segmentation |
| 610 | int ref_frame_flags; |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 611 | int ext_ref_frame_flags; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 612 | RATE_FACTOR_LEVEL frame_rf_level[FRAME_BUFFERS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 613 | |
| 614 | SPEED_FEATURES sf; |
| 615 | |
| 616 | unsigned int max_mv_magnitude; |
| 617 | int mv_step_param; |
| 618 | |
| 619 | int allow_comp_inter_inter; |
Zoe Liu | 77fb5be | 2017-11-02 14:36:19 -0700 | [diff] [blame] | 620 | int all_one_sided_refs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 621 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 622 | uint8_t *segmentation_map; |
| 623 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 624 | CYCLIC_REFRESH *cyclic_refresh; |
| 625 | ActiveMap active_map; |
| 626 | |
| 627 | fractional_mv_step_fp *find_fractional_mv_step; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 628 | av1_diamond_search_fn_t diamond_search_sad; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 629 | aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES_ALL]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 630 | uint64_t time_receive_data; |
| 631 | uint64_t time_compress_data; |
| 632 | uint64_t time_pick_lpf; |
| 633 | uint64_t time_encode_sb_row; |
| 634 | |
| 635 | #if CONFIG_FP_MB_STATS |
| 636 | int use_fp_mb_stats; |
| 637 | #endif |
| 638 | |
| 639 | TWO_PASS twopass; |
| 640 | |
| 641 | YV12_BUFFER_CONFIG alt_ref_buffer; |
| 642 | |
| 643 | #if CONFIG_INTERNAL_STATS |
| 644 | unsigned int mode_chosen_counts[MAX_MODES]; |
| 645 | |
| 646 | int count; |
| 647 | uint64_t total_sq_error; |
| 648 | uint64_t total_samples; |
| 649 | ImageStat psnr; |
| 650 | |
| 651 | double total_blockiness; |
| 652 | double worst_blockiness; |
| 653 | |
| 654 | int bytes; |
| 655 | double summed_quality; |
| 656 | double summed_weights; |
| 657 | unsigned int tot_recode_hits; |
| 658 | double worst_ssim; |
| 659 | |
| 660 | ImageStat fastssim; |
| 661 | ImageStat psnrhvs; |
| 662 | |
| 663 | int b_calculate_blockiness; |
| 664 | int b_calculate_consistency; |
| 665 | |
| 666 | double total_inconsistency; |
| 667 | double worst_consistency; |
| 668 | Ssimv *ssim_vars; |
| 669 | Metrics metrics; |
| 670 | #endif |
| 671 | int b_calculate_psnr; |
| 672 | |
| 673 | int droppable; |
| 674 | |
| 675 | int initial_width; |
| 676 | int initial_height; |
| 677 | int initial_mbs; // Number of MBs in the full-size frame; to be used to |
| 678 | // normalize the firstpass stats. This will differ from the |
| 679 | // number of MBs in the current frame when the frame is |
| 680 | // scaled. |
| 681 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 682 | // When resize is triggered through external control, the desired width/height |
| 683 | // are stored here until use in the next frame coded. They are effective only |
| 684 | // for |
| 685 | // one frame and are reset after use. |
| 686 | int resize_pending_width; |
| 687 | int resize_pending_height; |
| 688 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 689 | int frame_flags; |
| 690 | |
| 691 | search_site_config ss_cfg; |
| 692 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 693 | TileDataEnc *tile_data; |
| 694 | int allocated_tiles; // Keep track of memory allocated for tiles. |
| 695 | |
| 696 | TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 697 | unsigned int tok_count[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 698 | |
| 699 | TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 700 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 701 | int resize_state; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | int resize_avg_qp; |
| 703 | int resize_buffer_underflow; |
| 704 | int resize_count; |
| 705 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 706 | // Sequence parameters have been transmitted already and locked |
| 707 | // or not. Once locked av1_change_config cannot change the seq |
| 708 | // parameters. |
| 709 | int seq_params_locked; |
| 710 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 711 | // VARIANCE_AQ segment map refresh |
| 712 | int vaq_refresh; |
| 713 | |
| 714 | // Multi-threading |
| 715 | int num_workers; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 716 | AVxWorker *workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 717 | struct EncWorkerData *tile_thr_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 718 | int refresh_frame_mask; |
| 719 | int existing_fb_idx_to_show; |
| 720 | int is_arf_filter_off[MAX_EXT_ARFS + 1]; |
| 721 | int num_extra_arfs; |
Zoe Liu | f271a95 | 2017-09-05 15:03:48 -0700 | [diff] [blame] | 722 | int arf_pos_in_gf[MAX_EXT_ARFS + 1]; |
| 723 | int arf_pos_for_ovrly[MAX_EXT_ARFS + 1]; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 724 | int global_motion_search_done; |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 725 | tran_low_t *tcoeff_buf[MAX_MB_PLANE]; |
Di Chen | 53a04f6 | 2017-06-23 13:47:56 -0700 | [diff] [blame] | 726 | int extra_arf_allowed; |
Hui Su | 8587878 | 2017-11-07 14:56:31 -0800 | [diff] [blame] | 727 | // A flag to indicate if intrabc is ever used in current frame. |
| 728 | int intrabc_used; |
Hui Su | dfcbfbd | 2017-11-13 12:05:30 -0800 | [diff] [blame] | 729 | int dv_cost[2][MV_VALS]; |
| 730 | // TODO(huisu@google.com): we can update dv_joint_cost per SB. |
| 731 | int dv_joint_cost[MV_JOINTS]; |
Hui Su | ad7551e | 2018-03-14 11:13:31 -0700 | [diff] [blame] | 732 | int has_lossless_segment; |
Zoe Liu | 1d90ceb | 2018-04-16 16:53:37 -0700 | [diff] [blame] | 733 | |
| 734 | // For frame refs short signaling: |
| 735 | // A mapping of each reference frame from its encoder side value to the |
| 736 | // decoder side value obtained following the short signaling procedure. |
| 737 | int ref_conv[REF_FRAMES]; |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 738 | |
| 739 | AV1LfSync lf_row_sync; |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 740 | AV1LrSync lr_row_sync; |
Ravi Chaudhary | ce0f5fc | 2018-05-30 16:19:32 +0530 | [diff] [blame] | 741 | AV1LrStruct lr_ctxt; |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 742 | |
| 743 | aom_film_grain_table_t *film_grain_table; |
| 744 | #if CONFIG_DENOISE |
| 745 | struct aom_denoise_and_model_t *denoise_and_model; |
| 746 | #endif |
Ranjit Kumar Tulabandu | 8105bf4 | 2018-07-27 14:16:55 +0530 | [diff] [blame] | 747 | // Stores the default value of skip flag depending on chroma format |
| 748 | // Set as 1 for monochrome and 3 for other color formats |
| 749 | int default_interp_skip_flags; |
Wei-Ting Lin | a8c0245 | 2018-08-13 11:04:06 -0700 | [diff] [blame] | 750 | int preserve_arf_as_gld; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 751 | } AV1_COMP; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 753 | // Must not be called more than once. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 754 | void av1_initialize_enc(void); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 755 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 756 | struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 757 | BufferPool *const pool); |
| 758 | void av1_remove_compressor(AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 759 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 760 | void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 761 | |
| 762 | // receive a frames worth of data. caller can assume that a copy of this |
| 763 | // frame is made and not just a copy of the pointer.. |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 764 | int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 765 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 766 | int64_t end_time_stamp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 767 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 768 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 769 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 770 | int64_t *time_end, int flush, |
| 771 | const aom_rational_t *timebase); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 772 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 773 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 774 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 775 | int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 776 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 777 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 778 | YV12_BUFFER_CONFIG *new_frame, |
| 779 | YV12_BUFFER_CONFIG *sd); |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 780 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 781 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 782 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 783 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 784 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 785 | int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 786 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 787 | int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 788 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 789 | int av1_update_entropy(AV1_COMP *cpi, int update); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 790 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 791 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 792 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 793 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 794 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 795 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 796 | AOM_SCALING vert_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 798 | int av1_get_quantizer(struct AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 799 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 800 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *input_size); |
| 801 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 802 | int64_t timebase_units_to_ticks(const aom_rational_t *timebase, int64_t n); |
| 803 | int64_t ticks_to_timebase_units(const aom_rational_t *timebase, int64_t n); |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 804 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 805 | static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 806 | return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame || |
| 807 | (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref); |
| 808 | } |
| 809 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 810 | static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 811 | MV_REFERENCE_FRAME ref_frame) { |
Yaowu Xu | d023b5b | 2018-04-05 09:26:17 -0700 | [diff] [blame] | 812 | return (ref_frame >= 1) ? cpi->ref_fb_idx[ref_frame - 1] : INVALID_IDX; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 813 | } |
| 814 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 815 | static INLINE int get_ref_frame_buf_idx(const AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 816 | MV_REFERENCE_FRAME ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 817 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 818 | const int map_idx = get_ref_frame_map_idx(cpi, ref_frame); |
| 819 | return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX; |
| 820 | } |
| 821 | |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 822 | // TODO(huisu@google.com, youzhou@microsoft.com): enable hash-me for HBD. |
| 823 | static INLINE int av1_use_hash_me(const AV1_COMMON *const cm) { |
Debargha Mukherjee | 8112d2f | 2018-03-01 09:53:11 -0800 | [diff] [blame] | 824 | return cm->allow_screen_content_tools; |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | static INLINE hash_table *av1_get_ref_frame_hash_map( |
| 828 | const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) { |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 829 | const AV1_COMMON *const cm = &cpi->common; |
| 830 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 831 | return buf_idx != INVALID_IDX |
| 832 | ? &cm->buffer_pool->frame_bufs[buf_idx].hash_table |
| 833 | : NULL; |
| 834 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 835 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 836 | static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer( |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 837 | const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) { |
| 838 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 839 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 840 | return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf |
| 841 | : NULL; |
| 842 | } |
| 843 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 844 | static INLINE int enc_is_ref_frame_buf(AV1_COMP *cpi, RefCntBuffer *frame_buf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 845 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 846 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 847 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 848 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 849 | if (buf_idx == INVALID_IDX) continue; |
| 850 | if (frame_buf == &cm->buffer_pool->frame_bufs[buf_idx]) break; |
| 851 | } |
| 852 | return (ref_frame <= ALTREF_FRAME); |
| 853 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 854 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 855 | // Token buffer is only used for palette tokens. |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 856 | static INLINE unsigned int get_token_alloc(int mb_rows, int mb_cols, |
Imdad Sardharwalla | af8e264 | 2018-01-19 11:46:34 +0000 | [diff] [blame] | 857 | int sb_size_log2, |
| 858 | const int num_planes) { |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 859 | // Calculate the maximum number of max superblocks in the image. |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 860 | const int shift = sb_size_log2 - 4; |
| 861 | const int sb_size = 1 << sb_size_log2; |
| 862 | const int sb_size_square = sb_size * sb_size; |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 863 | const int sb_rows = ALIGN_POWER_OF_TWO(mb_rows, shift) >> shift; |
| 864 | const int sb_cols = ALIGN_POWER_OF_TWO(mb_cols, shift) >> shift; |
| 865 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 866 | // One palette token for each pixel. There can be palettes on two planes. |
| 867 | const int sb_palette_toks = AOMMIN(2, num_planes) * sb_size_square; |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 868 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 869 | return sb_rows * sb_cols * sb_palette_toks; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | // Get the allocated token size for a tile. It does the same calculation as in |
| 873 | // the frame token allocation. |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 874 | static INLINE unsigned int allocated_tokens(TileInfo tile, int sb_size_log2, |
| 875 | int num_planes) { |
Jingning Han | eafbd5f | 2017-03-07 11:18:17 -0800 | [diff] [blame] | 876 | int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 2) >> 2; |
| 877 | int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 2) >> 2; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 878 | |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 879 | return get_token_alloc(tile_mb_rows, tile_mb_cols, sb_size_log2, num_planes); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 880 | } |
| 881 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 882 | void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 883 | |
Yaowu Xu | 6da4230 | 2017-10-10 14:45:06 -0700 | [diff] [blame] | 884 | #define ALT_MIN_LAG 3 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 885 | static INLINE int is_altref_enabled(const AV1_COMP *const cpi) { |
Yaowu Xu | 6da4230 | 2017-10-10 14:45:06 -0700 | [diff] [blame] | 886 | return cpi->oxcf.lag_in_frames >= ALT_MIN_LAG && cpi->oxcf.enable_auto_arf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | // TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 890 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 891 | static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 892 | MV_REFERENCE_FRAME ref0, |
| 893 | MV_REFERENCE_FRAME ref1) { |
| 894 | xd->block_refs[0] = |
| 895 | &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0]; |
| 896 | xd->block_refs[1] = |
| 897 | &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0]; |
| 898 | } |
| 899 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 900 | static INLINE int get_chessboard_index(int frame_index) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 901 | return frame_index & 0x1; |
| 902 | } |
| 903 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 904 | static INLINE int *cond_cost_list(const struct AV1_COMP *cpi, int *cost_list) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 905 | return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL; |
| 906 | } |
| 907 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 908 | void av1_new_framerate(AV1_COMP *cpi, double framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 909 | |
| 910 | #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl)) |
| 911 | |
| 912 | // Update up-sampled reference frame index. |
| 913 | static INLINE void uref_cnt_fb(EncRefCntBuffer *ubufs, int *uidx, |
| 914 | int new_uidx) { |
| 915 | const int ref_index = *uidx; |
| 916 | |
| 917 | if (ref_index >= 0 && ubufs[ref_index].ref_count > 0) |
| 918 | ubufs[ref_index].ref_count--; |
| 919 | |
| 920 | *uidx = new_uidx; |
| 921 | ubufs[new_uidx].ref_count++; |
| 922 | } |
| 923 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 924 | // Returns 1 if a frame is scaled and 0 otherwise. |
| 925 | static INLINE int av1_resize_scaled(const AV1_COMMON *cm) { |
| 926 | return !(cm->superres_upscaled_width == cm->render_width && |
| 927 | cm->superres_upscaled_height == cm->render_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 930 | static INLINE int av1_frame_scaled(const AV1_COMMON *cm) { |
| 931 | return !av1_superres_scaled(cm) && av1_resize_scaled(cm); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 932 | } |
| 933 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 934 | // Don't allow a show_existing_frame to coincide with an error resilient |
| 935 | // frame. An exception can be made for a forward keyframe since it has no |
| 936 | // previous dependencies. |
| 937 | static INLINE int encode_show_existing_frame(const AV1_COMMON *cm) { |
| 938 | return cm->show_existing_frame && |
| 939 | (!cm->error_resilient_mode || cm->frame_type == KEY_FRAME); |
| 940 | } |
| 941 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 942 | #ifdef __cplusplus |
| 943 | } // extern "C" |
| 944 | #endif |
| 945 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 946 | #endif // AV1_ENCODER_ENCODER_H_ |