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 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AV1_ENCODER_ENCODER_H_ |
| 13 | #define AOM_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, |
Debargha Mukherjee | 5737825 | 2018-09-21 18:29:37 -0700 | [diff] [blame] | 97 | FRAMEFLAGS_INTRAONLY = 1 << 4, |
| 98 | FRAMEFLAGS_SWITCH = 1 << 5, |
| 99 | FRAMEFLAGS_ERROR_RESILIENT = 1 << 6, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 100 | } FRAMETYPE_FLAGS; |
| 101 | |
| 102 | typedef enum { |
| 103 | NO_AQ = 0, |
| 104 | VARIANCE_AQ = 1, |
| 105 | COMPLEXITY_AQ = 2, |
| 106 | CYCLIC_REFRESH_AQ = 3, |
| 107 | AQ_MODE_COUNT // This should always be the last member of the enum |
| 108 | } AQ_MODE; |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 109 | typedef enum { |
| 110 | NO_DELTA_Q = 0, |
| 111 | DELTA_Q_ONLY = 1, |
| 112 | DELTA_Q_LF = 2, |
| 113 | DELTAQ_MODE_COUNT // This should always be the last member of the enum |
| 114 | } DELTAQ_MODE; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 115 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 116 | typedef enum { |
| 117 | RESIZE_NONE = 0, // No frame resizing allowed. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 118 | RESIZE_FIXED = 1, // All frames are coded at the specified scale. |
| 119 | RESIZE_RANDOM = 2, // All frames are coded at a random scale. |
| 120 | RESIZE_MODES |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 121 | } RESIZE_MODE; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 122 | |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 123 | typedef enum { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 124 | SUPERRES_NONE = 0, // No frame superres allowed |
| 125 | SUPERRES_FIXED = 1, // All frames are coded at the specified scale, |
| 126 | // and super-resolved. |
| 127 | SUPERRES_RANDOM = 2, // All frames are coded at a random scale, |
| 128 | // and super-resolved. |
| 129 | SUPERRES_QTHRESH = 3, // Superres scale for a frame is determined based on |
| 130 | // q_index |
| 131 | SUPERRES_MODES |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 132 | } SUPERRES_MODE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 133 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 134 | typedef struct TplDepStats { |
| 135 | int64_t intra_cost; |
| 136 | int64_t inter_cost; |
| 137 | int64_t mc_flow; |
| 138 | int64_t mc_dep_cost; |
| 139 | int64_t mc_ref_cost; |
| 140 | |
| 141 | int ref_frame_index; |
| 142 | int_mv mv; |
| 143 | } TplDepStats; |
| 144 | |
| 145 | typedef struct TplDepFrame { |
| 146 | uint8_t is_valid; |
| 147 | TplDepStats *tpl_stats_ptr; |
| 148 | int stride; |
| 149 | int width; |
| 150 | int height; |
| 151 | int mi_rows; |
| 152 | int mi_cols; |
| 153 | int base_qindex; |
| 154 | } TplDepFrame; |
| 155 | |
| 156 | #define TPL_DEP_COST_SCALE_LOG2 4 |
| 157 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 158 | typedef struct AV1EncoderConfig { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 159 | BITSTREAM_PROFILE profile; |
Tom Finegan | 8ab2bba | 2018-02-28 07:36:28 -0800 | [diff] [blame] | 160 | aom_bit_depth_t bit_depth; // Codec bit-depth. |
| 161 | int width; // width of data passed to the compressor |
| 162 | int height; // height of data passed to the compressor |
| 163 | int forced_max_frame_width; // forced maximum width of frame (if != 0) |
| 164 | int forced_max_frame_height; // forced maximum height of frame (if != 0) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 165 | unsigned int input_bit_depth; // Input bit depth. |
| 166 | double init_framerate; // set to passed in framerate |
| 167 | int64_t target_bandwidth; // bandwidth to be used in bits per second |
| 168 | |
| 169 | int noise_sensitivity; // pre processing blur: recommendation 0 |
| 170 | int sharpness; // sharpening output: recommendation 0: |
| 171 | int speed; |
| 172 | // maximum allowed bitrate for any intra frame in % of bitrate target. |
| 173 | unsigned int rc_max_intra_bitrate_pct; |
| 174 | // maximum allowed bitrate for any inter frame in % of bitrate target. |
| 175 | unsigned int rc_max_inter_bitrate_pct; |
| 176 | // percent of rate boost for golden frame in CBR mode. |
| 177 | unsigned int gf_cbr_boost_pct; |
| 178 | |
| 179 | MODE mode; |
| 180 | int pass; |
| 181 | |
| 182 | // Key Framing Operations |
| 183 | int auto_key; // autodetect cut scenes and set the keyframes |
| 184 | int key_freq; // maximum distance to key frame. |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 185 | int sframe_dist; |
| 186 | int sframe_mode; |
| 187 | int sframe_enabled; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 188 | int lag_in_frames; // how many frames lag before we start encoding |
Sarah Parker | 93c0314 | 2018-05-22 13:35:45 -0700 | [diff] [blame] | 189 | int fwd_kf_enabled; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 190 | |
| 191 | // ---------------------------------------------------------------- |
| 192 | // DATARATE CONTROL OPTIONS |
| 193 | |
| 194 | // vbr, cbr, constrained quality or constant quality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 195 | enum aom_rc_mode rc_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | |
| 197 | // buffer targeting aggressiveness |
| 198 | int under_shoot_pct; |
| 199 | int over_shoot_pct; |
| 200 | |
| 201 | // buffering parameters |
| 202 | int64_t starting_buffer_level_ms; |
| 203 | int64_t optimal_buffer_level_ms; |
| 204 | int64_t maximum_buffer_size_ms; |
| 205 | |
| 206 | // Frame drop threshold. |
| 207 | int drop_frames_water_mark; |
| 208 | |
| 209 | // controlling quality |
| 210 | int fixed_q; |
| 211 | int worst_allowed_q; |
| 212 | int best_allowed_q; |
| 213 | int cq_level; |
| 214 | AQ_MODE aq_mode; // Adaptive Quantization mode |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 215 | DELTAQ_MODE deltaq_mode; |
Debargha Mukherjee | 98a311c | 2018-03-25 16:33:11 -0700 | [diff] [blame] | 216 | int enable_cdef; |
| 217 | int enable_restoration; |
Yue Chen | 4835dc0 | 2018-05-11 15:57:43 -0700 | [diff] [blame] | 218 | int disable_trellis_quant; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 219 | int using_qm; |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 220 | int qm_y; |
| 221 | int qm_u; |
| 222 | int qm_v; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 223 | int qm_minlevel; |
| 224 | int qm_maxlevel; |
Yushin Cho | d808bfc | 2017-08-10 15:54:36 -0700 | [diff] [blame] | 225 | #if CONFIG_DIST_8X8 |
| 226 | int using_dist_8x8; |
| 227 | #endif |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 228 | unsigned int num_tile_groups; |
| 229 | unsigned int mtu; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 230 | |
| 231 | // Internal frame size scaling. |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 232 | RESIZE_MODE resize_mode; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 233 | uint8_t resize_scale_denominator; |
| 234 | uint8_t resize_kf_scale_denominator; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 236 | // Frame Super-Resolution size scaling. |
| 237 | SUPERRES_MODE superres_mode; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 238 | uint8_t superres_scale_denominator; |
| 239 | uint8_t superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 240 | int superres_qthresh; |
| 241 | int superres_kf_qthresh; |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 242 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 243 | // Enable feature to reduce the frame quantization every x frames. |
| 244 | int frame_periodic_boost; |
| 245 | |
| 246 | // two pass datarate control |
| 247 | int two_pass_vbrbias; // two pass datarate control tweaks |
| 248 | int two_pass_vbrmin_section; |
| 249 | int two_pass_vbrmax_section; |
| 250 | // END DATARATE CONTROL OPTIONS |
| 251 | // ---------------------------------------------------------------- |
| 252 | |
| 253 | int enable_auto_arf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 254 | int enable_auto_brf; // (b)ackward (r)ef (f)rame |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 255 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 256 | /* Bitfield defining the error resiliency features to enable. |
| 257 | * Can provide decodable frames after losses in previous |
| 258 | * frames and decodable partitions after losses in the same frame. |
| 259 | */ |
| 260 | unsigned int error_resilient_mode; |
| 261 | |
Debargha Mukherjee | 52fb047 | 2018-03-29 15:48:11 -0700 | [diff] [blame] | 262 | unsigned int s_frame_mode; |
| 263 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 264 | /* Bitfield defining the parallel decoding mode where the |
| 265 | * decoding in successive frames may be conducted in parallel |
| 266 | * just by decoding the frame headers. |
| 267 | */ |
| 268 | unsigned int frame_parallel_decoding_mode; |
| 269 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 270 | unsigned int limit; |
| 271 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 272 | int arnr_max_frames; |
| 273 | int arnr_strength; |
| 274 | |
| 275 | int min_gf_interval; |
| 276 | int max_gf_interval; |
| 277 | |
Ravi Chaudhary | 0ec03a4 | 2018-08-17 18:53:28 +0530 | [diff] [blame] | 278 | int row_mt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 279 | int tile_columns; |
| 280 | int tile_rows; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 281 | int tile_width_count; |
| 282 | int tile_height_count; |
| 283 | int tile_widths[MAX_TILE_COLS]; |
| 284 | int tile_heights[MAX_TILE_ROWS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 286 | int enable_tpl_model; |
| 287 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 288 | int max_threads; |
| 289 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 290 | aom_fixed_buf_t two_pass_stats_in; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 291 | |
| 292 | #if CONFIG_FP_MB_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 293 | aom_fixed_buf_t firstpass_mb_stats_in; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 294 | #endif |
| 295 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 296 | aom_tune_metric tuning; |
| 297 | aom_tune_content content; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 298 | int use_highbitdepth; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 299 | aom_color_primaries_t color_primaries; |
| 300 | aom_transfer_characteristics_t transfer_characteristics; |
| 301 | aom_matrix_coefficients_t matrix_coefficients; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 302 | aom_chroma_sample_position_t chroma_sample_position; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 303 | int color_range; |
| 304 | int render_width; |
| 305 | int render_height; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 306 | int timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 307 | aom_timing_info_t timing_info; |
| 308 | int decoder_model_info_present_flag; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 309 | int display_model_info_present_flag; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 310 | int buffer_removal_time_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 311 | aom_dec_model_info_t buffer_model; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 312 | int film_grain_test_vector; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 313 | const char *film_grain_table_filename; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 314 | |
Hui Su | 1cb1c00 | 2018-02-05 18:21:20 -0800 | [diff] [blame] | 315 | uint8_t cdf_update_mode; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 316 | aom_superblock_size_t superblock_size; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 317 | unsigned int large_scale_tile; |
| 318 | unsigned int single_tile_decoding; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 319 | int monochrome; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 320 | unsigned int full_still_picture_hdr; |
Jingning Han | a446f55 | 2018-02-22 15:42:12 -0800 | [diff] [blame] | 321 | int enable_dual_filter; |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 322 | unsigned int motion_vector_unit_test; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 323 | const cfg_options_t *cfg; |
Debargha Mukherjee | 0d8368a | 2018-03-25 12:23:02 -0700 | [diff] [blame] | 324 | int enable_order_hint; |
Cheng Chen | e0c918a | 2018-02-22 19:38:31 -0800 | [diff] [blame] | 325 | int enable_jnt_comp; |
Debargha Mukherjee | 0187d7c | 2018-03-25 11:37:56 -0700 | [diff] [blame] | 326 | int enable_ref_frame_mvs; |
Debargha Mukherjee | 0d8368a | 2018-03-25 12:23:02 -0700 | [diff] [blame] | 327 | unsigned int allow_ref_frame_mvs; |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame^] | 328 | int enable_masked_comp; |
| 329 | int enable_interintra_comp; |
Debargha Mukherjee | d2e53ca | 2018-12-10 11:34:59 -0800 | [diff] [blame] | 330 | int enable_global_motion; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 331 | int enable_warped_motion; |
| 332 | int allow_warped_motion; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 333 | int enable_superres; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 334 | unsigned int save_as_annexb; |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 335 | |
| 336 | #if CONFIG_DENOISE |
| 337 | float noise_level; |
| 338 | int noise_block_size; |
| 339 | #endif |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 340 | |
| 341 | unsigned int chroma_subsampling_x; |
| 342 | unsigned int chroma_subsampling_y; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 343 | } AV1EncoderConfig; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 344 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 345 | static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 346 | return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0; |
| 347 | } |
| 348 | |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 349 | typedef struct FRAME_COUNTS { |
| 350 | // Note: This structure should only contain 'unsigned int' fields, or |
| 351 | // aggregates built solely from 'unsigned int' fields/elements |
| 352 | #if CONFIG_ENTROPY_STATS |
| 353 | unsigned int kf_y_mode[KF_MODE_CONTEXTS][KF_MODE_CONTEXTS][INTRA_MODES]; |
| 354 | unsigned int angle_delta[DIRECTIONAL_MODES][2 * MAX_ANGLE_DELTA + 1]; |
| 355 | unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES]; |
| 356 | unsigned int uv_mode[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES]; |
| 357 | unsigned int cfl_sign[CFL_JOINT_SIGNS]; |
| 358 | unsigned int cfl_alpha[CFL_ALPHA_CONTEXTS][CFL_ALPHABET_SIZE]; |
| 359 | unsigned int palette_y_mode[PALATTE_BSIZE_CTXS][PALETTE_Y_MODE_CONTEXTS][2]; |
| 360 | unsigned int palette_uv_mode[PALETTE_UV_MODE_CONTEXTS][2]; |
| 361 | unsigned int palette_y_size[PALATTE_BSIZE_CTXS][PALETTE_SIZES]; |
| 362 | unsigned int palette_uv_size[PALATTE_BSIZE_CTXS][PALETTE_SIZES]; |
| 363 | unsigned int palette_y_color_index[PALETTE_SIZES] |
| 364 | [PALETTE_COLOR_INDEX_CONTEXTS] |
| 365 | [PALETTE_COLORS]; |
| 366 | unsigned int palette_uv_color_index[PALETTE_SIZES] |
| 367 | [PALETTE_COLOR_INDEX_CONTEXTS] |
| 368 | [PALETTE_COLORS]; |
| 369 | unsigned int partition[PARTITION_CONTEXTS][EXT_PARTITION_TYPES]; |
| 370 | unsigned int txb_skip[TOKEN_CDF_Q_CTXS][TX_SIZES][TXB_SKIP_CONTEXTS][2]; |
| 371 | unsigned int eob_extra[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 372 | [EOB_COEF_CONTEXTS][2]; |
| 373 | unsigned int dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS][2]; |
| 374 | unsigned int coeff_lps[TX_SIZES][PLANE_TYPES][BR_CDF_SIZE - 1][LEVEL_CONTEXTS] |
| 375 | [2]; |
| 376 | unsigned int eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS][2]; |
| 377 | unsigned int eob_multi16[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][5]; |
| 378 | unsigned int eob_multi32[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][6]; |
| 379 | unsigned int eob_multi64[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][7]; |
| 380 | unsigned int eob_multi128[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][8]; |
| 381 | unsigned int eob_multi256[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][9]; |
| 382 | unsigned int eob_multi512[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][10]; |
| 383 | unsigned int eob_multi1024[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][11]; |
| 384 | unsigned int coeff_lps_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 385 | [LEVEL_CONTEXTS][BR_CDF_SIZE]; |
| 386 | unsigned int coeff_base_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 387 | [SIG_COEF_CONTEXTS][NUM_BASE_LEVELS + 2]; |
| 388 | unsigned int coeff_base_eob_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 389 | [SIG_COEF_CONTEXTS_EOB][NUM_BASE_LEVELS + 1]; |
| 390 | unsigned int newmv_mode[NEWMV_MODE_CONTEXTS][2]; |
| 391 | unsigned int zeromv_mode[GLOBALMV_MODE_CONTEXTS][2]; |
| 392 | unsigned int refmv_mode[REFMV_MODE_CONTEXTS][2]; |
| 393 | unsigned int drl_mode[DRL_MODE_CONTEXTS][2]; |
| 394 | unsigned int inter_compound_mode[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES]; |
| 395 | unsigned int wedge_idx[BLOCK_SIZES_ALL][16]; |
| 396 | unsigned int interintra[BLOCK_SIZE_GROUPS][2]; |
| 397 | unsigned int interintra_mode[BLOCK_SIZE_GROUPS][INTERINTRA_MODES]; |
| 398 | unsigned int wedge_interintra[BLOCK_SIZES_ALL][2]; |
| 399 | unsigned int compound_type[BLOCK_SIZES_ALL][COMPOUND_TYPES - 1]; |
| 400 | unsigned int motion_mode[BLOCK_SIZES_ALL][MOTION_MODES]; |
| 401 | unsigned int obmc[BLOCK_SIZES_ALL][2]; |
| 402 | unsigned int intra_inter[INTRA_INTER_CONTEXTS][2]; |
| 403 | unsigned int comp_inter[COMP_INTER_CONTEXTS][2]; |
| 404 | unsigned int comp_ref_type[COMP_REF_TYPE_CONTEXTS][2]; |
| 405 | unsigned int uni_comp_ref[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1][2]; |
| 406 | unsigned int single_ref[REF_CONTEXTS][SINGLE_REFS - 1][2]; |
| 407 | unsigned int comp_ref[REF_CONTEXTS][FWD_REFS - 1][2]; |
| 408 | unsigned int comp_bwdref[REF_CONTEXTS][BWD_REFS - 1][2]; |
| 409 | unsigned int intrabc[2]; |
| 410 | |
| 411 | unsigned int txfm_partition[TXFM_PARTITION_CONTEXTS][2]; |
| 412 | unsigned int intra_tx_size[MAX_TX_CATS][TX_SIZE_CONTEXTS][MAX_TX_DEPTH + 1]; |
| 413 | unsigned int skip_mode[SKIP_MODE_CONTEXTS][2]; |
| 414 | unsigned int skip[SKIP_CONTEXTS][2]; |
| 415 | unsigned int compound_index[COMP_INDEX_CONTEXTS][2]; |
| 416 | unsigned int comp_group_idx[COMP_GROUP_IDX_CONTEXTS][2]; |
| 417 | unsigned int delta_q[DELTA_Q_PROBS][2]; |
| 418 | unsigned int delta_lf_multi[FRAME_LF_COUNT][DELTA_LF_PROBS][2]; |
| 419 | unsigned int delta_lf[DELTA_LF_PROBS][2]; |
| 420 | |
| 421 | unsigned int inter_ext_tx[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES]; |
| 422 | unsigned int intra_ext_tx[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES] |
| 423 | [TX_TYPES]; |
| 424 | unsigned int filter_intra_mode[FILTER_INTRA_MODES]; |
| 425 | unsigned int filter_intra[BLOCK_SIZES_ALL][2]; |
| 426 | unsigned int switchable_restore[RESTORE_SWITCHABLE_TYPES]; |
| 427 | unsigned int wiener_restore[2]; |
| 428 | unsigned int sgrproj_restore[2]; |
| 429 | #endif // CONFIG_ENTROPY_STATS |
| 430 | |
| 431 | unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS] |
| 432 | [SWITCHABLE_FILTERS]; |
| 433 | } FRAME_COUNTS; |
| 434 | |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 435 | #if CONFIG_COLLECT_INTER_MODE_RD_STATS |
| 436 | #define INTER_MODE_RD_DATA_OVERALL_SIZE 6400 |
| 437 | |
| 438 | typedef struct { |
| 439 | int ready; |
| 440 | double a; |
| 441 | double b; |
| 442 | double dist_mean; |
Angie Chiang | 199f3d4 | 2018-08-14 18:07:02 -0700 | [diff] [blame] | 443 | double ld_mean; |
| 444 | double sse_mean; |
| 445 | double sse_sse_mean; |
| 446 | double sse_ld_mean; |
Angie Chiang | 106fa48 | 2018-08-07 18:28:40 -0700 | [diff] [blame] | 447 | int num; |
| 448 | double dist_sum; |
| 449 | double ld_sum; |
| 450 | double sse_sum; |
| 451 | double sse_sse_sum; |
| 452 | double sse_ld_sum; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 453 | } InterModeRdModel; |
| 454 | |
| 455 | typedef struct { |
| 456 | int idx; |
| 457 | int64_t rd; |
| 458 | } RdIdxPair; |
| 459 | // TODO(angiebird): This is an estimated size. We still need to figure what is |
| 460 | // the maximum number of modes. |
| 461 | #define MAX_INTER_MODES 1024 |
| 462 | typedef struct inter_modes_info { |
| 463 | int num; |
| 464 | MB_MODE_INFO mbmi_arr[MAX_INTER_MODES]; |
| 465 | int mode_rate_arr[MAX_INTER_MODES]; |
| 466 | int64_t sse_arr[MAX_INTER_MODES]; |
| 467 | int64_t est_rd_arr[MAX_INTER_MODES]; |
| 468 | RdIdxPair rd_idx_pair_arr[MAX_INTER_MODES]; |
| 469 | } InterModesInfo; |
| 470 | #endif |
| 471 | |
Ravi Chaudhary | 40cdf13 | 2018-10-08 11:04:16 +0530 | [diff] [blame] | 472 | // Encoder row synchronization |
| 473 | typedef struct AV1RowMTSyncData { |
| 474 | #if CONFIG_MULTITHREAD |
| 475 | pthread_mutex_t *mutex_; |
| 476 | pthread_cond_t *cond_; |
| 477 | #endif |
| 478 | // Allocate memory to store the sb/mb block index in each row. |
| 479 | int *cur_col; |
| 480 | int sync_range; |
| 481 | int rows; |
| 482 | } AV1RowMTSync; |
| 483 | |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 484 | typedef struct AV1RowMTInfo { |
| 485 | int current_mi_row; |
| 486 | int num_threads_working; |
| 487 | } AV1RowMTInfo; |
| 488 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 489 | // TODO(jingning) All spatially adaptive variables should go to TileDataEnc. |
| 490 | typedef struct TileDataEnc { |
| 491 | TileInfo tile_info; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 492 | int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES]; |
| 493 | int mode_map[BLOCK_SIZES_ALL][MAX_MODES]; |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 494 | int m_search_count; |
| 495 | int ex_search_count; |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 496 | CFL_CTX cfl; |
Jingning Han | 9f07be1 | 2017-04-13 09:31:40 -0700 | [diff] [blame] | 497 | DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx); |
Ravi Chaudhary | 84a280a | 2018-09-24 16:09:48 +0530 | [diff] [blame] | 498 | DECLARE_ALIGNED(16, FRAME_CONTEXT, backup_tctx); |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 499 | uint8_t allow_update_cdf; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 500 | #if CONFIG_COLLECT_INTER_MODE_RD_STATS |
| 501 | InterModeRdModel inter_mode_rd_models[BLOCK_SIZES_ALL]; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 502 | #endif |
Ravi Chaudhary | 40cdf13 | 2018-10-08 11:04:16 +0530 | [diff] [blame] | 503 | AV1RowMTSync row_mt_sync; |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 504 | AV1RowMTInfo row_mt_info; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 505 | } TileDataEnc; |
| 506 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 507 | typedef struct { |
| 508 | TOKENEXTRA *start; |
| 509 | TOKENEXTRA *stop; |
| 510 | unsigned int count; |
| 511 | } TOKENLIST; |
| 512 | |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 513 | typedef struct MultiThreadHandle { |
| 514 | int allocated_tile_rows; |
| 515 | int allocated_tile_cols; |
| 516 | int allocated_sb_rows; |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 517 | int thread_id_to_tile_id[MAX_NUM_THREADS]; // Mapping of threads to tiles |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 518 | } MultiThreadHandle; |
| 519 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 520 | typedef struct RD_COUNTS { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 521 | int64_t comp_pred_diff[REFERENCE_MODES]; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 522 | // Stores number of 4x4 blocks using global motion per reference frame. |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 523 | int global_motion_used[REF_FRAMES]; |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 524 | int compound_ref_used_flag; |
Zoe Liu | 8a5d343 | 2017-11-30 16:33:44 -0800 | [diff] [blame] | 525 | int skip_mode_used_flag; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 526 | } RD_COUNTS; |
| 527 | |
| 528 | typedef struct ThreadData { |
| 529 | MACROBLOCK mb; |
| 530 | RD_COUNTS rd_counts; |
| 531 | FRAME_COUNTS *counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 532 | PC_TREE *pc_tree; |
| 533 | PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1]; |
wenyao.liu | 0c6f5fd | 2018-10-23 18:41:16 +0800 | [diff] [blame] | 534 | tran_low_t *tree_coeff_buf[MAX_MB_PLANE]; |
| 535 | tran_low_t *tree_qcoeff_buf[MAX_MB_PLANE]; |
| 536 | tran_low_t *tree_dqcoeff_buf[MAX_MB_PLANE]; |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 537 | #if CONFIG_COLLECT_INTER_MODE_RD_STATS |
| 538 | InterModesInfo *inter_modes_info; |
| 539 | #endif |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 540 | uint32_t *hash_value_buffer[2][2]; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 541 | int32_t *wsrc_buf; |
| 542 | int32_t *mask_buf; |
| 543 | uint8_t *above_pred_buf; |
| 544 | uint8_t *left_pred_buf; |
hui su | 5d49314 | 2017-05-08 12:06:12 -0700 | [diff] [blame] | 545 | PALETTE_BUFFER *palette_buffer; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 546 | CONV_BUF_TYPE *tmp_conv_dst; |
| 547 | uint8_t *tmp_obmc_bufs[2]; |
Ravi Chaudhary | 00525ef | 2018-10-31 19:52:42 +0530 | [diff] [blame] | 548 | int intrabc_used; |
Ravi Chaudhary | 84a280a | 2018-09-24 16:09:48 +0530 | [diff] [blame] | 549 | FRAME_CONTEXT *tctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 550 | } ThreadData; |
| 551 | |
| 552 | struct EncWorkerData; |
| 553 | |
| 554 | typedef struct ActiveMap { |
| 555 | int enabled; |
| 556 | int update; |
| 557 | unsigned char *map; |
| 558 | } ActiveMap; |
| 559 | |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 560 | #if CONFIG_INTERNAL_STATS |
| 561 | // types of stats |
| 562 | typedef enum { |
| 563 | STAT_Y, |
| 564 | STAT_U, |
| 565 | STAT_V, |
| 566 | STAT_ALL, |
| 567 | NUM_STAT_TYPES // This should always be the last member of the enum |
| 568 | } StatType; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 569 | |
| 570 | typedef struct IMAGE_STAT { |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 571 | double stat[NUM_STAT_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 572 | double worst; |
| 573 | } ImageStat; |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 574 | #endif // CONFIG_INTERNAL_STATS |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 575 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 576 | typedef struct { |
| 577 | int ref_count; |
| 578 | YV12_BUFFER_CONFIG buf; |
| 579 | } EncRefCntBuffer; |
| 580 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 581 | typedef struct TileBufferEnc { |
| 582 | uint8_t *data; |
| 583 | size_t size; |
| 584 | } TileBufferEnc; |
| 585 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 586 | typedef struct AV1_COMP { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 587 | QUANTS quants; |
| 588 | ThreadData td; |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 589 | FRAME_COUNTS counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 590 | MB_MODE_INFO_EXT *mbmi_ext_base; |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 591 | CB_COEFF_BUFFER *coeff_buffer_base; |
Yi Luo | c621023 | 2017-05-25 15:09:25 -0700 | [diff] [blame] | 592 | Dequants dequants; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 593 | AV1_COMMON common; |
| 594 | AV1EncoderConfig oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 595 | struct lookahead_ctx *lookahead; |
| 596 | struct lookahead_entry *alt_ref_source; |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 597 | int no_show_kf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 598 | |
Angie Chiang | e69a682 | 2018-03-16 13:52:44 -0700 | [diff] [blame] | 599 | int optimize_speed_feature; |
| 600 | int optimize_seg_arr[MAX_SEGMENTS]; |
| 601 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 602 | YV12_BUFFER_CONFIG *source; |
| 603 | 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] | 604 | YV12_BUFFER_CONFIG *unscaled_source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 605 | YV12_BUFFER_CONFIG scaled_source; |
| 606 | YV12_BUFFER_CONFIG *unscaled_last_source; |
| 607 | YV12_BUFFER_CONFIG scaled_last_source; |
| 608 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 609 | TplDepFrame tpl_stats[MAX_LAG_BUFFERS]; |
| 610 | YV12_BUFFER_CONFIG *tpl_recon_frames[INTER_REFS_PER_FRAME + 1]; |
| 611 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 612 | // For a still frame, this flag is set to 1 to skip partition search. |
| 613 | int partition_search_skippable_frame; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 614 | double csm_rate_array[32]; |
| 615 | double m_rate_array[32]; |
| 616 | int rate_size; |
| 617 | int rate_index; |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 618 | hash_table *previous_hash_table; |
| 619 | int previous_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 620 | |
Ravi Chaudhary | 0ec03a4 | 2018-08-17 18:53:28 +0530 | [diff] [blame] | 621 | unsigned int row_mt; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 622 | RefCntBuffer *scaled_ref_buf[INTER_REFS_PER_FRAME]; |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 623 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 624 | RefCntBuffer *last_show_frame_buf; // last show frame buffer |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 625 | |
Urvang Joshi | 06b3765 | 2018-11-06 11:17:56 -0800 | [diff] [blame] | 626 | // refresh_*_frame are boolean flags. If 'refresh_xyz_frame' is true, then |
| 627 | // after the current frame is encoded, the XYZ reference frame gets refreshed |
| 628 | // (updated) to be the current frame. |
| 629 | // |
| 630 | // Special case: 'refresh_last_frame' specifies that: |
| 631 | // - LAST_FRAME reference should be updated to be the current frame (as usual) |
| 632 | // - Also, LAST2_FRAME and LAST3_FRAME references are implicitly updated to be |
| 633 | // the two past reference frames just before LAST_FRAME that are available. |
| 634 | // |
| 635 | // Note: Usually at most one of these refresh flags is true at a time. |
| 636 | // But a key-frame is special, for which all the flags are true at once. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 637 | int refresh_last_frame; |
| 638 | int refresh_golden_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 639 | int refresh_bwd_ref_frame; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 640 | int refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 641 | int refresh_alt_ref_frame; |
Urvang Joshi | 06b3765 | 2018-11-06 11:17:56 -0800 | [diff] [blame] | 642 | |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 643 | // For each type of reference frame, this contains the index of a reference |
| 644 | // frame buffer for a reference frame of the same type. We use this to |
| 645 | // choose our primary reference frame (which is the most recent reference |
| 646 | // frame of the same type as the current frame). |
| 647 | int fb_of_context_type[REF_FRAMES]; |
| 648 | |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 649 | #if USE_SYMM_MULTI_LAYER |
Urvang Joshi | 06b3765 | 2018-11-06 11:17:56 -0800 | [diff] [blame] | 650 | // When true, a new rule for backward (future) reference frames is in effect: |
| 651 | // - BWDREF_FRAME is always the closest future frame available |
| 652 | // - ALTREF2_FRAME is always the 2nd closest future frame available |
| 653 | // - 'refresh_bwd_ref_frame' flag is used for updating both the BWDREF_FRAME |
| 654 | // and ALTREF2_FRAME. ('refresh_alt2_ref_frame' flag is irrelevant). |
Wei-Ting Lin | bafa11c | 2018-07-10 13:20:59 -0700 | [diff] [blame] | 655 | int new_bwdref_update_rule; |
| 656 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 657 | |
| 658 | int ext_refresh_frame_flags_pending; |
| 659 | int ext_refresh_last_frame; |
| 660 | int ext_refresh_golden_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 661 | int ext_refresh_bwd_ref_frame; |
| 662 | int ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 663 | int ext_refresh_alt_ref_frame; |
| 664 | |
| 665 | int ext_refresh_frame_context_pending; |
| 666 | int ext_refresh_frame_context; |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 667 | int ext_use_ref_frame_mvs; |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 668 | int ext_use_error_resilient; |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 669 | int ext_use_s_frame; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 670 | int ext_use_primary_ref_none; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 671 | |
| 672 | YV12_BUFFER_CONFIG last_frame_uf; |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 673 | YV12_BUFFER_CONFIG trial_frame_rst; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 674 | |
| 675 | // Ambient reconstruction err target for force key frames |
| 676 | int64_t ambient_err; |
| 677 | |
| 678 | RD_OPT rd; |
| 679 | |
| 680 | CODING_CONTEXT coding_context; |
| 681 | |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 682 | int gmtype_cost[TRANS_TYPES]; |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 683 | int gmparams_cost[REF_FRAMES]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 684 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 685 | int nmv_costs[2][MV_VALS]; |
| 686 | int nmv_costs_hp[2][MV_VALS]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 687 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 688 | int64_t last_time_stamp_seen; |
| 689 | int64_t last_end_time_stamp_seen; |
| 690 | int64_t first_time_stamp_ever; |
| 691 | |
| 692 | RATE_CONTROL rc; |
| 693 | double framerate; |
| 694 | |
Urvang Joshi | a130dcc | 2018-11-06 10:27:35 -0800 | [diff] [blame] | 695 | // Relevant for an inter frame. |
| 696 | // - Index '0' corresponds to the values for the currently coded frame. |
Urvang Joshi | 03d8ebe | 2018-11-08 17:13:44 -0800 | [diff] [blame] | 697 | // - Indices LAST_FRAME ... EXTREF_FRAMES are used to store values for all the |
| 698 | // possible inter reference frames. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 699 | int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE]; |
| 700 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 701 | struct aom_codec_pkt_list *output_pkt_list; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 702 | |
| 703 | MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS]; |
| 704 | int mbgraph_n_frames; // number of frames filled in the above |
| 705 | int static_mb_pct; // % forced skip mbs by segmentation |
| 706 | int ref_frame_flags; |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 707 | int ext_ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 708 | |
| 709 | SPEED_FEATURES sf; |
| 710 | |
| 711 | unsigned int max_mv_magnitude; |
| 712 | int mv_step_param; |
| 713 | |
Zoe Liu | 77fb5be | 2017-11-02 14:36:19 -0700 | [diff] [blame] | 714 | int all_one_sided_refs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 715 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 716 | uint8_t *segmentation_map; |
| 717 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 718 | CYCLIC_REFRESH *cyclic_refresh; |
| 719 | ActiveMap active_map; |
| 720 | |
| 721 | fractional_mv_step_fp *find_fractional_mv_step; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 722 | av1_diamond_search_fn_t diamond_search_sad; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 723 | aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES_ALL]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 724 | uint64_t time_receive_data; |
| 725 | uint64_t time_compress_data; |
| 726 | uint64_t time_pick_lpf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 727 | |
| 728 | #if CONFIG_FP_MB_STATS |
| 729 | int use_fp_mb_stats; |
| 730 | #endif |
| 731 | |
| 732 | TWO_PASS twopass; |
| 733 | |
| 734 | YV12_BUFFER_CONFIG alt_ref_buffer; |
| 735 | |
| 736 | #if CONFIG_INTERNAL_STATS |
| 737 | unsigned int mode_chosen_counts[MAX_MODES]; |
| 738 | |
| 739 | int count; |
| 740 | uint64_t total_sq_error; |
| 741 | uint64_t total_samples; |
| 742 | ImageStat psnr; |
| 743 | |
| 744 | double total_blockiness; |
| 745 | double worst_blockiness; |
| 746 | |
| 747 | int bytes; |
| 748 | double summed_quality; |
| 749 | double summed_weights; |
| 750 | unsigned int tot_recode_hits; |
| 751 | double worst_ssim; |
| 752 | |
| 753 | ImageStat fastssim; |
| 754 | ImageStat psnrhvs; |
| 755 | |
| 756 | int b_calculate_blockiness; |
| 757 | int b_calculate_consistency; |
| 758 | |
| 759 | double total_inconsistency; |
| 760 | double worst_consistency; |
| 761 | Ssimv *ssim_vars; |
| 762 | Metrics metrics; |
| 763 | #endif |
| 764 | int b_calculate_psnr; |
| 765 | |
| 766 | int droppable; |
| 767 | |
| 768 | int initial_width; |
| 769 | int initial_height; |
| 770 | int initial_mbs; // Number of MBs in the full-size frame; to be used to |
| 771 | // normalize the firstpass stats. This will differ from the |
| 772 | // number of MBs in the current frame when the frame is |
| 773 | // scaled. |
| 774 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 775 | // When resize is triggered through external control, the desired width/height |
| 776 | // are stored here until use in the next frame coded. They are effective only |
| 777 | // for |
| 778 | // one frame and are reset after use. |
| 779 | int resize_pending_width; |
| 780 | int resize_pending_height; |
| 781 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 782 | int frame_flags; |
| 783 | |
| 784 | search_site_config ss_cfg; |
| 785 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 786 | TileDataEnc *tile_data; |
| 787 | int allocated_tiles; // Keep track of memory allocated for tiles. |
| 788 | |
| 789 | TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS]; |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 790 | TOKENLIST *tplist[MAX_TILE_ROWS][MAX_TILE_COLS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 791 | |
| 792 | TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 793 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 794 | int resize_state; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 795 | int resize_avg_qp; |
| 796 | int resize_buffer_underflow; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 798 | // Sequence parameters have been transmitted already and locked |
| 799 | // or not. Once locked av1_change_config cannot change the seq |
| 800 | // parameters. |
| 801 | int seq_params_locked; |
| 802 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 803 | // VARIANCE_AQ segment map refresh |
| 804 | int vaq_refresh; |
| 805 | |
| 806 | // Multi-threading |
| 807 | int num_workers; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 808 | AVxWorker *workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 809 | struct EncWorkerData *tile_thr_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 810 | int existing_fb_idx_to_show; |
| 811 | int is_arf_filter_off[MAX_EXT_ARFS + 1]; |
| 812 | int num_extra_arfs; |
Zoe Liu | f271a95 | 2017-09-05 15:03:48 -0700 | [diff] [blame] | 813 | int arf_pos_in_gf[MAX_EXT_ARFS + 1]; |
| 814 | int arf_pos_for_ovrly[MAX_EXT_ARFS + 1]; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 815 | int global_motion_search_done; |
Di Chen | 53a04f6 | 2017-06-23 13:47:56 -0700 | [diff] [blame] | 816 | int extra_arf_allowed; |
Hui Su | 8587878 | 2017-11-07 14:56:31 -0800 | [diff] [blame] | 817 | // A flag to indicate if intrabc is ever used in current frame. |
| 818 | int intrabc_used; |
Hui Su | dfcbfbd | 2017-11-13 12:05:30 -0800 | [diff] [blame] | 819 | int dv_cost[2][MV_VALS]; |
| 820 | // TODO(huisu@google.com): we can update dv_joint_cost per SB. |
| 821 | int dv_joint_cost[MV_JOINTS]; |
Hui Su | ad7551e | 2018-03-14 11:13:31 -0700 | [diff] [blame] | 822 | int has_lossless_segment; |
Zoe Liu | 1d90ceb | 2018-04-16 16:53:37 -0700 | [diff] [blame] | 823 | |
Remya | 6924f4a | 2018-11-26 12:27:32 +0530 | [diff] [blame] | 824 | // Factors to control gating of compound type selection based on best |
| 825 | // approximate rd so far |
| 826 | int max_comp_type_rd_threshold_mul; |
| 827 | int max_comp_type_rd_threshold_div; |
| 828 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 829 | AV1LfSync lf_row_sync; |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 830 | AV1LrSync lr_row_sync; |
Ravi Chaudhary | ce0f5fc | 2018-05-30 16:19:32 +0530 | [diff] [blame] | 831 | AV1LrStruct lr_ctxt; |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 832 | |
| 833 | aom_film_grain_table_t *film_grain_table; |
| 834 | #if CONFIG_DENOISE |
| 835 | struct aom_denoise_and_model_t *denoise_and_model; |
| 836 | #endif |
Ranjit Kumar Tulabandu | 8105bf4 | 2018-07-27 14:16:55 +0530 | [diff] [blame] | 837 | // Stores the default value of skip flag depending on chroma format |
| 838 | // Set as 1 for monochrome and 3 for other color formats |
| 839 | int default_interp_skip_flags; |
Wei-Ting Lin | a8c0245 | 2018-08-13 11:04:06 -0700 | [diff] [blame] | 840 | int preserve_arf_as_gld; |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 841 | MultiThreadHandle multi_thread_ctxt; |
Ravi Chaudhary | 40cdf13 | 2018-10-08 11:04:16 +0530 | [diff] [blame] | 842 | void (*row_mt_sync_read_ptr)(AV1RowMTSync *const, int, int); |
| 843 | void (*row_mt_sync_write_ptr)(AV1RowMTSync *const, int, int, const int); |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 844 | #if CONFIG_MULTITHREAD |
| 845 | pthread_mutex_t *row_mt_mutex_; |
| 846 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 847 | } AV1_COMP; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 848 | |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 849 | // Must not be called more than once. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 850 | void av1_initialize_enc(void); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 851 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 852 | struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 853 | BufferPool *const pool); |
| 854 | void av1_remove_compressor(AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 855 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 856 | void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 857 | |
| 858 | // receive a frames worth of data. caller can assume that a copy of this |
| 859 | // frame is made and not just a copy of the pointer.. |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 860 | 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] | 861 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 862 | int64_t end_time_stamp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 863 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 864 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 865 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 866 | int64_t *time_end, int flush, |
| 867 | const aom_rational_t *timebase); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 868 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 869 | 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] | 870 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 871 | 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] | 872 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 873 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 874 | YV12_BUFFER_CONFIG *new_frame, |
| 875 | YV12_BUFFER_CONFIG *sd); |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 876 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 877 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 878 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 879 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 880 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 881 | 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] | 882 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 883 | 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] | 884 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 885 | int av1_update_entropy(AV1_COMP *cpi, int update); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 886 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 887 | 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] | 888 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 889 | 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] | 890 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 891 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 892 | AOM_SCALING vert_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 893 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 894 | int av1_get_quantizer(struct AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 895 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 896 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *input_size); |
| 897 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 898 | int64_t timebase_units_to_ticks(const aom_rational_t *timebase, int64_t n); |
| 899 | 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] | 900 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 901 | static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 902 | return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame || |
| 903 | (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref); |
| 904 | } |
| 905 | |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 906 | // TODO(huisu@google.com, youzhou@microsoft.com): enable hash-me for HBD. |
| 907 | static INLINE int av1_use_hash_me(const AV1_COMMON *const cm) { |
Debargha Mukherjee | 8112d2f | 2018-03-01 09:53:11 -0800 | [diff] [blame] | 908 | return cm->allow_screen_content_tools; |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static INLINE hash_table *av1_get_ref_frame_hash_map( |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 912 | const AV1_COMMON *cm, MV_REFERENCE_FRAME ref_frame) { |
| 913 | const int map_idx = get_ref_frame_map_idx(cm, ref_frame); |
| 914 | RefCntBuffer *buf = |
| 915 | (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : NULL; |
| 916 | return buf ? &buf->hash_table : NULL; |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 917 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 918 | |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 919 | static INLINE const YV12_BUFFER_CONFIG *get_ref_frame_yv12_buf( |
| 920 | const AV1_COMMON *const cm, MV_REFERENCE_FRAME ref_frame) { |
| 921 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 922 | return buf != NULL ? &buf->buf : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 923 | } |
| 924 | |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 925 | static INLINE int enc_is_ref_frame_buf(const AV1_COMMON *const cm, |
| 926 | const RefCntBuffer *const frame_buf) { |
Urvang Joshi | 4058217 | 2018-11-07 11:53:03 -0800 | [diff] [blame] | 927 | MV_REFERENCE_FRAME ref_frame; |
| 928 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 929 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 930 | if (buf == NULL) continue; |
| 931 | if (frame_buf == buf) break; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 932 | } |
Urvang Joshi | 4058217 | 2018-11-07 11:53:03 -0800 | [diff] [blame] | 933 | return (ref_frame <= ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 934 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 935 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 936 | // Token buffer is only used for palette tokens. |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 937 | 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] | 938 | int sb_size_log2, |
| 939 | const int num_planes) { |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 940 | // Calculate the maximum number of max superblocks in the image. |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 941 | const int shift = sb_size_log2 - 4; |
| 942 | const int sb_size = 1 << sb_size_log2; |
| 943 | const int sb_size_square = sb_size * sb_size; |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 944 | const int sb_rows = ALIGN_POWER_OF_TWO(mb_rows, shift) >> shift; |
| 945 | const int sb_cols = ALIGN_POWER_OF_TWO(mb_cols, shift) >> shift; |
| 946 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 947 | // One palette token for each pixel. There can be palettes on two planes. |
| 948 | const int sb_palette_toks = AOMMIN(2, num_planes) * sb_size_square; |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 949 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 950 | return sb_rows * sb_cols * sb_palette_toks; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | } |
| 952 | |
| 953 | // Get the allocated token size for a tile. It does the same calculation as in |
| 954 | // the frame token allocation. |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 955 | static INLINE unsigned int allocated_tokens(TileInfo tile, int sb_size_log2, |
| 956 | int num_planes) { |
Jingning Han | eafbd5f | 2017-03-07 11:18:17 -0800 | [diff] [blame] | 957 | int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 2) >> 2; |
| 958 | 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] | 959 | |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 960 | 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] | 961 | } |
| 962 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 963 | static INLINE void get_start_tok(AV1_COMP *cpi, int tile_row, int tile_col, |
| 964 | int mi_row, TOKENEXTRA **tok, int sb_size_log2, |
| 965 | int num_planes) { |
| 966 | AV1_COMMON *const cm = &cpi->common; |
| 967 | const int tile_cols = cm->tile_cols; |
| 968 | TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 969 | const TileInfo *const tile_info = &this_tile->tile_info; |
| 970 | |
| 971 | const int tile_mb_cols = |
| 972 | (tile_info->mi_col_end - tile_info->mi_col_start + 2) >> 2; |
| 973 | const int tile_mb_row = (mi_row - tile_info->mi_row_start + 2) >> 2; |
| 974 | |
| 975 | *tok = cpi->tile_tok[tile_row][tile_col] + |
| 976 | get_token_alloc(tile_mb_row, tile_mb_cols, sb_size_log2, num_planes); |
| 977 | } |
| 978 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 979 | 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] | 980 | |
Yaowu Xu | 6da4230 | 2017-10-10 14:45:06 -0700 | [diff] [blame] | 981 | #define ALT_MIN_LAG 3 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 982 | static INLINE int is_altref_enabled(const AV1_COMP *const cpi) { |
Yaowu Xu | 6da4230 | 2017-10-10 14:45:06 -0700 | [diff] [blame] | 983 | 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] | 984 | } |
| 985 | |
| 986 | // TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 987 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 988 | static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 989 | MV_REFERENCE_FRAME ref0, |
| 990 | MV_REFERENCE_FRAME ref1) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 991 | xd->block_ref_scale_factors[0] = |
| 992 | get_ref_scale_factors_const(cm, ref0 >= LAST_FRAME ? ref0 : 1); |
| 993 | xd->block_ref_scale_factors[1] = |
| 994 | get_ref_scale_factors_const(cm, ref1 >= LAST_FRAME ? ref1 : 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 997 | static INLINE int get_chessboard_index(int frame_index) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 998 | return frame_index & 0x1; |
| 999 | } |
| 1000 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1001 | 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] | 1002 | return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL; |
| 1003 | } |
| 1004 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1005 | void av1_new_framerate(AV1_COMP *cpi, double framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1006 | |
| 1007 | #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl)) |
| 1008 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 1009 | // Returns 1 if a frame is scaled and 0 otherwise. |
| 1010 | static INLINE int av1_resize_scaled(const AV1_COMMON *cm) { |
| 1011 | return !(cm->superres_upscaled_width == cm->render_width && |
| 1012 | cm->superres_upscaled_height == cm->render_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 1015 | static INLINE int av1_frame_scaled(const AV1_COMMON *cm) { |
| 1016 | return !av1_superres_scaled(cm) && av1_resize_scaled(cm); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 1019 | // Don't allow a show_existing_frame to coincide with an error resilient |
| 1020 | // frame. An exception can be made for a forward keyframe since it has no |
| 1021 | // previous dependencies. |
| 1022 | static INLINE int encode_show_existing_frame(const AV1_COMMON *cm) { |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 1023 | return cm->show_existing_frame && (!cm->error_resilient_mode || |
| 1024 | cm->current_frame.frame_type == KEY_FRAME); |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1027 | // Returns a Sequence Header OBU stored in an aom_fixed_buf_t, or NULL upon |
| 1028 | // failure. When a non-NULL aom_fixed_buf_t pointer is returned by this |
| 1029 | // function, the memory must be freed by the caller. Both the buf member of the |
Tom Finegan | ca1e28f | 2018-08-28 16:55:35 -0700 | [diff] [blame] | 1030 | // aom_fixed_buf_t, and the aom_fixed_buf_t pointer itself must be freed. Memory |
| 1031 | // returned must be freed via call to free(). |
| 1032 | // |
| 1033 | // Note: The OBU returned is in Low Overhead Bitstream Format. Specifically, |
| 1034 | // the obu_has_size_field bit is set, and the buffer contains the obu_size |
| 1035 | // field. |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1036 | aom_fixed_buf_t *av1_get_global_headers(AV1_COMP *cpi); |
| 1037 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1038 | #ifdef __cplusplus |
| 1039 | } // extern "C" |
| 1040 | #endif |
| 1041 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 1042 | #endif // AOM_AV1_ENCODER_ENCODER_H_ |