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 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "./aom_config.h" |
| 18 | #include "aom/aomcx.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | |
| 20 | #include "av1/common/alloccommon.h" |
| 21 | #include "av1/common/entropymode.h" |
| 22 | #include "av1/common/thread_common.h" |
| 23 | #include "av1/common/onyxc_int.h" |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 24 | #include "av1/common/resize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | #include "av1/encoder/aq_cyclicrefresh.h" |
Tom Finegan | 17ce8b1 | 2017-02-08 12:46:31 -0800 | [diff] [blame] | 26 | #include "av1/encoder/av1_quantize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | #include "av1/encoder/context_tree.h" |
| 28 | #include "av1/encoder/encodemb.h" |
| 29 | #include "av1/encoder/firstpass.h" |
| 30 | #include "av1/encoder/lookahead.h" |
| 31 | #include "av1/encoder/mbgraph.h" |
| 32 | #include "av1/encoder/mcomp.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | #include "av1/encoder/ratectrl.h" |
| 34 | #include "av1/encoder/rd.h" |
| 35 | #include "av1/encoder/speed_features.h" |
| 36 | #include "av1/encoder/tokenize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 37 | |
| 38 | #if CONFIG_INTERNAL_STATS |
| 39 | #include "aom_dsp/ssim.h" |
| 40 | #endif |
| 41 | #include "aom_dsp/variance.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 42 | #include "aom/internal/aom_codec_internal.h" |
| 43 | #include "aom_util/aom_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 44 | |
| 45 | #ifdef __cplusplus |
| 46 | extern "C" { |
| 47 | #endif |
| 48 | |
| 49 | typedef struct { |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame^] | 50 | int nmv_vec_cost[MV_JOINTS]; |
| 51 | int nmv_costs[2][MV_VALS]; |
| 52 | int nmv_costs_hp[2][MV_VALS]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 53 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 54 | // 0 = Intra, Last, GF, ARF |
Yaowu Xu | 0fbe33d | 2017-08-31 09:34:29 -0700 | [diff] [blame] | 55 | int8_t last_ref_lf_deltas[TOTAL_REFS_PER_FRAME]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 56 | // 0 = ZERO_MV, MV |
Yaowu Xu | 0fbe33d | 2017-08-31 09:34:29 -0700 | [diff] [blame] | 57 | int8_t last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | |
| 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, |
Thomas Davies | 3ab20b4 | 2017-09-19 10:30:53 +0100 | [diff] [blame] | 104 | #if !CONFIG_EXT_DELTA_Q |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 105 | DELTA_AQ = 4, |
| 106 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 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 | #if CONFIG_EXT_DELTA_Q |
| 110 | typedef enum { |
| 111 | NO_DELTA_Q = 0, |
| 112 | DELTA_Q_ONLY = 1, |
| 113 | DELTA_Q_LF = 2, |
| 114 | DELTAQ_MODE_COUNT // This should always be the last member of the enum |
| 115 | } DELTAQ_MODE; |
| 116 | #endif |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 117 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 118 | typedef enum { |
| 119 | RESIZE_NONE = 0, // No frame resizing allowed. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 120 | RESIZE_FIXED = 1, // All frames are coded at the specified scale. |
| 121 | RESIZE_RANDOM = 2, // All frames are coded at a random scale. |
| 122 | RESIZE_MODES |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 123 | } RESIZE_MODE; |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 124 | |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 125 | typedef enum { |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 126 | SUPERRES_NONE = 0, // No frame superres allowed |
| 127 | SUPERRES_FIXED = 1, // All frames are coded at the specified scale, |
| 128 | // and super-resolved. |
| 129 | SUPERRES_RANDOM = 2, // All frames are coded at a random scale, |
| 130 | // and super-resolved. |
| 131 | SUPERRES_QTHRESH = 3, // Superres scale for a frame is determined based on |
| 132 | // q_index |
| 133 | SUPERRES_MODES |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 134 | } SUPERRES_MODE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 135 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 136 | typedef struct AV1EncoderConfig { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 137 | BITSTREAM_PROFILE profile; |
Tom Finegan | 8ab2bba | 2018-02-28 07:36:28 -0800 | [diff] [blame] | 138 | aom_bit_depth_t bit_depth; // Codec bit-depth. |
| 139 | int width; // width of data passed to the compressor |
| 140 | int height; // height of data passed to the compressor |
| 141 | int forced_max_frame_width; // forced maximum width of frame (if != 0) |
| 142 | int forced_max_frame_height; // forced maximum height of frame (if != 0) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 143 | unsigned int input_bit_depth; // Input bit depth. |
| 144 | double init_framerate; // set to passed in framerate |
| 145 | int64_t target_bandwidth; // bandwidth to be used in bits per second |
| 146 | |
| 147 | int noise_sensitivity; // pre processing blur: recommendation 0 |
| 148 | int sharpness; // sharpening output: recommendation 0: |
| 149 | int speed; |
Jingning Han | b49c6ae | 2017-11-27 18:14:05 -0800 | [diff] [blame] | 150 | int dev_sf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 151 | // maximum allowed bitrate for any intra frame in % of bitrate target. |
| 152 | unsigned int rc_max_intra_bitrate_pct; |
| 153 | // maximum allowed bitrate for any inter frame in % of bitrate target. |
| 154 | unsigned int rc_max_inter_bitrate_pct; |
| 155 | // percent of rate boost for golden frame in CBR mode. |
| 156 | unsigned int gf_cbr_boost_pct; |
| 157 | |
| 158 | MODE mode; |
| 159 | int pass; |
| 160 | |
| 161 | // Key Framing Operations |
| 162 | int auto_key; // autodetect cut scenes and set the keyframes |
| 163 | int key_freq; // maximum distance to key frame. |
| 164 | |
| 165 | int lag_in_frames; // how many frames lag before we start encoding |
| 166 | |
| 167 | // ---------------------------------------------------------------- |
| 168 | // DATARATE CONTROL OPTIONS |
| 169 | |
| 170 | // vbr, cbr, constrained quality or constant quality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 171 | enum aom_rc_mode rc_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | |
| 173 | // buffer targeting aggressiveness |
| 174 | int under_shoot_pct; |
| 175 | int over_shoot_pct; |
| 176 | |
| 177 | // buffering parameters |
| 178 | int64_t starting_buffer_level_ms; |
| 179 | int64_t optimal_buffer_level_ms; |
| 180 | int64_t maximum_buffer_size_ms; |
| 181 | |
| 182 | // Frame drop threshold. |
| 183 | int drop_frames_water_mark; |
| 184 | |
| 185 | // controlling quality |
| 186 | int fixed_q; |
| 187 | int worst_allowed_q; |
| 188 | int best_allowed_q; |
| 189 | int cq_level; |
| 190 | AQ_MODE aq_mode; // Adaptive Quantization mode |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 191 | #if CONFIG_EXT_DELTA_Q |
| 192 | DELTAQ_MODE deltaq_mode; |
| 193 | #endif |
Steinar Midtskogen | e44c622 | 2017-11-09 13:22:09 +0100 | [diff] [blame] | 194 | int using_cdef; |
Sebastien Alaiwan | 1ed2024 | 2018-02-20 14:47:18 +0100 | [diff] [blame] | 195 | int using_restoration; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 196 | int using_qm; |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 197 | #if CONFIG_AOM_QM_EXT |
| 198 | int qm_y; |
| 199 | int qm_u; |
| 200 | int qm_v; |
| 201 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 202 | int qm_minlevel; |
| 203 | int qm_maxlevel; |
Yushin Cho | d808bfc | 2017-08-10 15:54:36 -0700 | [diff] [blame] | 204 | #if CONFIG_DIST_8X8 |
| 205 | int using_dist_8x8; |
| 206 | #endif |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 207 | unsigned int num_tile_groups; |
| 208 | unsigned int mtu; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 209 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 210 | unsigned int disable_tempmv; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 211 | // Internal frame size scaling. |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 212 | RESIZE_MODE resize_mode; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 213 | uint8_t resize_scale_denominator; |
| 214 | uint8_t resize_kf_scale_denominator; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 215 | |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 216 | // Frame Super-Resolution size scaling. |
| 217 | SUPERRES_MODE superres_mode; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 218 | uint8_t superres_scale_denominator; |
| 219 | uint8_t superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 220 | int superres_qthresh; |
| 221 | int superres_kf_qthresh; |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 222 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 223 | // Enable feature to reduce the frame quantization every x frames. |
| 224 | int frame_periodic_boost; |
| 225 | |
| 226 | // two pass datarate control |
| 227 | int two_pass_vbrbias; // two pass datarate control tweaks |
| 228 | int two_pass_vbrmin_section; |
| 229 | int two_pass_vbrmax_section; |
| 230 | // END DATARATE CONTROL OPTIONS |
| 231 | // ---------------------------------------------------------------- |
| 232 | |
| 233 | int enable_auto_arf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 234 | int enable_auto_brf; // (b)ackward (r)ef (f)rame |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 235 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 236 | /* Bitfield defining the error resiliency features to enable. |
| 237 | * Can provide decodable frames after losses in previous |
| 238 | * frames and decodable partitions after losses in the same frame. |
| 239 | */ |
| 240 | unsigned int error_resilient_mode; |
| 241 | |
| 242 | /* Bitfield defining the parallel decoding mode where the |
| 243 | * decoding in successive frames may be conducted in parallel |
| 244 | * just by decoding the frame headers. |
| 245 | */ |
| 246 | unsigned int frame_parallel_decoding_mode; |
| 247 | |
| 248 | int arnr_max_frames; |
| 249 | int arnr_strength; |
| 250 | |
| 251 | int min_gf_interval; |
| 252 | int max_gf_interval; |
| 253 | |
| 254 | int tile_columns; |
| 255 | int tile_rows; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 256 | #if CONFIG_MAX_TILE |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 257 | int tile_width_count; |
| 258 | int tile_height_count; |
| 259 | int tile_widths[MAX_TILE_COLS]; |
| 260 | int tile_heights[MAX_TILE_ROWS]; |
Dominic Symes | f58f111 | 2017-09-25 12:47:40 +0200 | [diff] [blame] | 261 | #endif |
Fangwen Fu | 7b9f2b3 | 2017-01-17 14:01:52 -0800 | [diff] [blame] | 262 | #if CONFIG_DEPENDENT_HORZTILES |
| 263 | int dependent_horz_tiles; |
| 264 | #endif |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 265 | #if CONFIG_LOOPFILTERING_ACROSS_TILES |
Lei | 7bb501d | 2017-12-13 15:10:34 -0800 | [diff] [blame] | 266 | #if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT |
| 267 | int loop_filter_across_tiles_v_enabled; |
| 268 | int loop_filter_across_tiles_h_enabled; |
| 269 | #else |
Ryan Lei | 7386eda | 2016-12-08 21:08:31 -0800 | [diff] [blame] | 270 | int loop_filter_across_tiles_enabled; |
Lei | 7bb501d | 2017-12-13 15:10:34 -0800 | [diff] [blame] | 271 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT |
Ryan Lei | 9b02b0e | 2017-01-30 15:52:20 -0800 | [diff] [blame] | 272 | #endif // CONFIG_LOOPFILTERING_ACROSS_TILES |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 273 | |
| 274 | int max_threads; |
| 275 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 276 | aom_fixed_buf_t two_pass_stats_in; |
| 277 | struct aom_codec_pkt_list *output_pkt_list; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 278 | |
| 279 | #if CONFIG_FP_MB_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 280 | aom_fixed_buf_t firstpass_mb_stats_in; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 281 | #endif |
| 282 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 283 | aom_tune_metric tuning; |
| 284 | aom_tune_content content; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 285 | int use_highbitdepth; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 286 | aom_color_primaries_t color_primaries; |
| 287 | aom_transfer_characteristics_t transfer_characteristics; |
| 288 | aom_matrix_coefficients_t matrix_coefficients; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 289 | aom_chroma_sample_position_t chroma_sample_position; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 290 | int color_range; |
| 291 | int render_width; |
| 292 | int render_height; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 293 | aom_timing_info_t timing_info; |
| 294 | int timing_info_present; |
| 295 | uint32_t num_units_in_tick; |
| 296 | uint32_t time_scale; |
| 297 | int equal_picture_interval; |
| 298 | uint32_t num_ticks_per_picture; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 299 | #if CONFIG_FILM_GRAIN |
| 300 | int film_grain_test_vector; |
| 301 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 302 | |
Hui Su | 1cb1c00 | 2018-02-05 18:21:20 -0800 | [diff] [blame] | 303 | #if CONFIG_CDF_UPDATE_MODE |
| 304 | uint8_t cdf_update_mode; |
| 305 | #endif // CONFIG_CDF_UPDATE_MODE |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 306 | aom_superblock_size_t superblock_size; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 307 | unsigned int large_scale_tile; |
| 308 | unsigned int single_tile_decoding; |
Debargha Mukherjee | f340fec | 2018-01-10 18:12:22 -0800 | [diff] [blame] | 309 | int monochrome; |
Jingning Han | a446f55 | 2018-02-22 15:42:12 -0800 | [diff] [blame] | 310 | int enable_dual_filter; |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 311 | unsigned int motion_vector_unit_test; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 312 | const cfg_options_t *cfg; |
Cheng Chen | e0c918a | 2018-02-22 19:38:31 -0800 | [diff] [blame] | 313 | int enable_jnt_comp; |
Cheng Chen | fecd9a7 | 2018-03-08 15:23:51 -0800 | [diff] [blame] | 314 | int enable_order_hint; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 315 | } AV1EncoderConfig; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 316 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 317 | static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 318 | return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0; |
| 319 | } |
| 320 | |
| 321 | // TODO(jingning) All spatially adaptive variables should go to TileDataEnc. |
| 322 | typedef struct TileDataEnc { |
| 323 | TileInfo tile_info; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 324 | int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES]; |
| 325 | int mode_map[BLOCK_SIZES_ALL][MAX_MODES]; |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 326 | int m_search_count; |
| 327 | int ex_search_count; |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 328 | CFL_CTX cfl; |
Jingning Han | 9f07be1 | 2017-04-13 09:31:40 -0700 | [diff] [blame] | 329 | DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx); |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 330 | uint8_t allow_update_cdf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 331 | } TileDataEnc; |
| 332 | |
| 333 | typedef struct RD_COUNTS { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 334 | int64_t comp_pred_diff[REFERENCE_MODES]; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 335 | // Stores number of 4x4 blocks using global motion per reference frame. |
| 336 | int global_motion_used[TOTAL_REFS_PER_FRAME]; |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 337 | int compound_ref_used_flag; |
Zoe Liu | 8a5d343 | 2017-11-30 16:33:44 -0800 | [diff] [blame] | 338 | int skip_mode_used_flag; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 339 | } RD_COUNTS; |
| 340 | |
| 341 | typedef struct ThreadData { |
| 342 | MACROBLOCK mb; |
| 343 | RD_COUNTS rd_counts; |
| 344 | FRAME_COUNTS *counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 345 | PC_TREE *pc_tree; |
| 346 | PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1]; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 347 | int32_t *wsrc_buf; |
| 348 | int32_t *mask_buf; |
| 349 | uint8_t *above_pred_buf; |
| 350 | uint8_t *left_pred_buf; |
hui su | 5d49314 | 2017-05-08 12:06:12 -0700 | [diff] [blame] | 351 | PALETTE_BUFFER *palette_buffer; |
Hui Su | 8587878 | 2017-11-07 14:56:31 -0800 | [diff] [blame] | 352 | int intrabc_used_this_tile; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 353 | } ThreadData; |
| 354 | |
| 355 | struct EncWorkerData; |
| 356 | |
| 357 | typedef struct ActiveMap { |
| 358 | int enabled; |
| 359 | int update; |
| 360 | unsigned char *map; |
| 361 | } ActiveMap; |
| 362 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 363 | #define NUM_STAT_TYPES 4 // types of stats: Y, U, V and ALL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 364 | |
| 365 | typedef struct IMAGE_STAT { |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 366 | double stat[NUM_STAT_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 367 | double worst; |
| 368 | } ImageStat; |
| 369 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 370 | #undef NUM_STAT_TYPES |
| 371 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 372 | typedef struct { |
| 373 | int ref_count; |
| 374 | YV12_BUFFER_CONFIG buf; |
| 375 | } EncRefCntBuffer; |
| 376 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 377 | typedef struct TileBufferEnc { |
| 378 | uint8_t *data; |
| 379 | size_t size; |
| 380 | } TileBufferEnc; |
| 381 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 382 | typedef struct AV1_COMP { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 383 | QUANTS quants; |
| 384 | ThreadData td; |
| 385 | MB_MODE_INFO_EXT *mbmi_ext_base; |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 386 | CB_COEFF_BUFFER *coeff_buffer_base; |
Yi Luo | c621023 | 2017-05-25 15:09:25 -0700 | [diff] [blame] | 387 | Dequants dequants; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 388 | AV1_COMMON common; |
| 389 | AV1EncoderConfig oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 390 | struct lookahead_ctx *lookahead; |
| 391 | struct lookahead_entry *alt_ref_source; |
| 392 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 393 | YV12_BUFFER_CONFIG *source; |
| 394 | 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] | 395 | YV12_BUFFER_CONFIG *unscaled_source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 396 | YV12_BUFFER_CONFIG scaled_source; |
| 397 | YV12_BUFFER_CONFIG *unscaled_last_source; |
| 398 | YV12_BUFFER_CONFIG scaled_last_source; |
| 399 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 400 | // For a still frame, this flag is set to 1 to skip partition search. |
| 401 | int partition_search_skippable_frame; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 402 | #if CONFIG_AMVR |
| 403 | double csm_rate_array[32]; |
| 404 | double m_rate_array[32]; |
| 405 | int rate_size; |
| 406 | int rate_index; |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 407 | hash_table *previous_hash_table; |
| 408 | int previous_index; |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 409 | int cur_poc; // DebugInfo |
| 410 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 411 | |
| 412 | int scaled_ref_idx[TOTAL_REFS_PER_FRAME]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 413 | int lst_fb_idxes[LAST_REF_FRAMES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 414 | int gld_fb_idx; |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 415 | int bwd_fb_idx; // BWDREF_FRAME |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 416 | int alt2_fb_idx; // ALTREF2_FRAME |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 417 | int alt_fb_idx; |
Zoe Liu | 8dd1c98 | 2017-09-11 10:14:35 -0700 | [diff] [blame] | 418 | int ext_fb_idx; // extra ref frame buffer index |
| 419 | int refresh_fb_idx; // ref frame buffer index to refresh |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 420 | |
| 421 | int last_show_frame_buf_idx; // last show frame buffer index |
| 422 | |
| 423 | int refresh_last_frame; |
| 424 | int refresh_golden_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 425 | int refresh_bwd_ref_frame; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 426 | int refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 427 | int refresh_alt_ref_frame; |
| 428 | |
| 429 | int ext_refresh_frame_flags_pending; |
| 430 | int ext_refresh_last_frame; |
| 431 | int ext_refresh_golden_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 432 | int ext_refresh_bwd_ref_frame; |
| 433 | int ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 434 | int ext_refresh_alt_ref_frame; |
| 435 | |
| 436 | int ext_refresh_frame_context_pending; |
| 437 | int ext_refresh_frame_context; |
| 438 | |
| 439 | YV12_BUFFER_CONFIG last_frame_uf; |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 440 | YV12_BUFFER_CONFIG trial_frame_rst; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 441 | |
| 442 | // Ambient reconstruction err target for force key frames |
| 443 | int64_t ambient_err; |
| 444 | |
| 445 | RD_OPT rd; |
| 446 | |
| 447 | CODING_CONTEXT coding_context; |
| 448 | |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 449 | int gmtype_cost[TRANS_TYPES]; |
| 450 | int gmparams_cost[TOTAL_REFS_PER_FRAME]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 451 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame^] | 452 | int nmv_costs[2][MV_VALS]; |
| 453 | int nmv_costs_hp[2][MV_VALS]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 454 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 455 | int64_t last_time_stamp_seen; |
| 456 | int64_t last_end_time_stamp_seen; |
| 457 | int64_t first_time_stamp_ever; |
| 458 | |
| 459 | RATE_CONTROL rc; |
| 460 | double framerate; |
| 461 | |
| 462 | // NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter |
| 463 | // references; Plus the currently coded frame itself, it is needed to allocate |
| 464 | // sufficient space to the size of the maximum possible number of frames. |
| 465 | int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE]; |
| 466 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 467 | struct aom_codec_pkt_list *output_pkt_list; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 468 | |
| 469 | MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS]; |
| 470 | int mbgraph_n_frames; // number of frames filled in the above |
| 471 | int static_mb_pct; // % forced skip mbs by segmentation |
| 472 | int ref_frame_flags; |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 473 | int ext_ref_frame_flags; |
Zoe Liu | f452fdf | 2017-11-02 23:08:12 -0700 | [diff] [blame] | 474 | RATE_FACTOR_LEVEL frame_rf_level[FRAME_BUFFERS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 475 | |
| 476 | SPEED_FEATURES sf; |
| 477 | |
| 478 | unsigned int max_mv_magnitude; |
| 479 | int mv_step_param; |
| 480 | |
| 481 | int allow_comp_inter_inter; |
Zoe Liu | 77fb5be | 2017-11-02 14:36:19 -0700 | [diff] [blame] | 482 | int all_one_sided_refs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 483 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 484 | uint8_t *segmentation_map; |
| 485 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 486 | CYCLIC_REFRESH *cyclic_refresh; |
| 487 | ActiveMap active_map; |
| 488 | |
| 489 | fractional_mv_step_fp *find_fractional_mv_step; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 490 | av1_full_search_fn_t full_search_sad; // It is currently unused. |
| 491 | av1_diamond_search_fn_t diamond_search_sad; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 492 | aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES_ALL]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 493 | uint64_t time_receive_data; |
| 494 | uint64_t time_compress_data; |
| 495 | uint64_t time_pick_lpf; |
| 496 | uint64_t time_encode_sb_row; |
| 497 | |
| 498 | #if CONFIG_FP_MB_STATS |
| 499 | int use_fp_mb_stats; |
| 500 | #endif |
| 501 | |
| 502 | TWO_PASS twopass; |
| 503 | |
| 504 | YV12_BUFFER_CONFIG alt_ref_buffer; |
| 505 | |
| 506 | #if CONFIG_INTERNAL_STATS |
| 507 | unsigned int mode_chosen_counts[MAX_MODES]; |
| 508 | |
| 509 | int count; |
| 510 | uint64_t total_sq_error; |
| 511 | uint64_t total_samples; |
| 512 | ImageStat psnr; |
| 513 | |
| 514 | double total_blockiness; |
| 515 | double worst_blockiness; |
| 516 | |
| 517 | int bytes; |
| 518 | double summed_quality; |
| 519 | double summed_weights; |
| 520 | unsigned int tot_recode_hits; |
| 521 | double worst_ssim; |
| 522 | |
| 523 | ImageStat fastssim; |
| 524 | ImageStat psnrhvs; |
| 525 | |
| 526 | int b_calculate_blockiness; |
| 527 | int b_calculate_consistency; |
| 528 | |
| 529 | double total_inconsistency; |
| 530 | double worst_consistency; |
| 531 | Ssimv *ssim_vars; |
| 532 | Metrics metrics; |
| 533 | #endif |
| 534 | int b_calculate_psnr; |
| 535 | |
| 536 | int droppable; |
| 537 | |
| 538 | int initial_width; |
| 539 | int initial_height; |
| 540 | int initial_mbs; // Number of MBs in the full-size frame; to be used to |
| 541 | // normalize the firstpass stats. This will differ from the |
| 542 | // number of MBs in the current frame when the frame is |
| 543 | // scaled. |
| 544 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 545 | // When resize is triggered through external control, the desired width/height |
| 546 | // are stored here until use in the next frame coded. They are effective only |
| 547 | // for |
| 548 | // one frame and are reset after use. |
| 549 | int resize_pending_width; |
| 550 | int resize_pending_height; |
| 551 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 552 | int frame_flags; |
| 553 | |
| 554 | search_site_config ss_cfg; |
| 555 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 556 | int multi_arf_allowed; |
| 557 | int multi_arf_enabled; |
| 558 | int multi_arf_last_grp_enabled; |
| 559 | |
| 560 | TileDataEnc *tile_data; |
| 561 | int allocated_tiles; // Keep track of memory allocated for tiles. |
| 562 | |
| 563 | TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 564 | unsigned int tok_count[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 565 | |
| 566 | TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 567 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 568 | int resize_state; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 569 | int resize_avg_qp; |
| 570 | int resize_buffer_underflow; |
| 571 | int resize_count; |
| 572 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 573 | // VARIANCE_AQ segment map refresh |
| 574 | int vaq_refresh; |
| 575 | |
| 576 | // Multi-threading |
| 577 | int num_workers; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 578 | AVxWorker *workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 579 | struct EncWorkerData *tile_thr_data; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 580 | AV1LfSync lf_row_sync; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 581 | int refresh_frame_mask; |
| 582 | int existing_fb_idx_to_show; |
| 583 | int is_arf_filter_off[MAX_EXT_ARFS + 1]; |
| 584 | int num_extra_arfs; |
| 585 | int arf_map[MAX_EXT_ARFS + 1]; |
Zoe Liu | f271a95 | 2017-09-05 15:03:48 -0700 | [diff] [blame] | 586 | int arf_pos_in_gf[MAX_EXT_ARFS + 1]; |
| 587 | int arf_pos_for_ovrly[MAX_EXT_ARFS + 1]; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 588 | int global_motion_search_done; |
Angie Chiang | f0fbf9d | 2017-03-15 15:01:22 -0700 | [diff] [blame] | 589 | tran_low_t *tcoeff_buf[MAX_MB_PLANE]; |
Di Chen | 53a04f6 | 2017-06-23 13:47:56 -0700 | [diff] [blame] | 590 | int extra_arf_allowed; |
| 591 | int bwd_ref_allowed; |
Hui Su | 8587878 | 2017-11-07 14:56:31 -0800 | [diff] [blame] | 592 | // A flag to indicate if intrabc is ever used in current frame. |
| 593 | int intrabc_used; |
Hui Su | dfcbfbd | 2017-11-13 12:05:30 -0800 | [diff] [blame] | 594 | int dv_cost[2][MV_VALS]; |
| 595 | // TODO(huisu@google.com): we can update dv_joint_cost per SB. |
| 596 | int dv_joint_cost[MV_JOINTS]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 597 | } AV1_COMP; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 598 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 599 | void av1_initialize_enc(void); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 600 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 601 | struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 602 | BufferPool *const pool); |
| 603 | void av1_remove_compressor(AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 604 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 605 | void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 606 | |
| 607 | // receive a frames worth of data. caller can assume that a copy of this |
| 608 | // frame is made and not just a copy of the pointer.. |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 609 | 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] | 610 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 611 | int64_t end_time_stamp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 612 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 613 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 614 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 615 | int64_t *time_end, int flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 616 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 617 | 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] | 618 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 619 | 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] | 620 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 621 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 622 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 623 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 624 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 625 | 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] | 626 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 627 | 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] | 628 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 629 | int av1_update_entropy(AV1_COMP *cpi, int update); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 630 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 631 | 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] | 632 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 633 | 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] | 634 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 635 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 636 | AOM_SCALING vert_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 637 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 638 | int av1_get_quantizer(struct AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 639 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 640 | static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 641 | return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame || |
| 642 | (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref); |
| 643 | } |
| 644 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 645 | static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 646 | MV_REFERENCE_FRAME ref_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 647 | if (ref_frame >= LAST_FRAME && ref_frame <= LAST3_FRAME) |
| 648 | return cpi->lst_fb_idxes[ref_frame - 1]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 649 | else if (ref_frame == GOLDEN_FRAME) |
| 650 | return cpi->gld_fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 651 | else if (ref_frame == BWDREF_FRAME) |
| 652 | return cpi->bwd_fb_idx; |
Zoe Liu | e9b15e2 | 2017-07-19 15:53:01 -0700 | [diff] [blame] | 653 | else if (ref_frame == ALTREF2_FRAME) |
| 654 | return cpi->alt2_fb_idx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 655 | else |
| 656 | return cpi->alt_fb_idx; |
| 657 | } |
| 658 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 659 | static INLINE int get_ref_frame_buf_idx(const AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 660 | MV_REFERENCE_FRAME ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 661 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 662 | const int map_idx = get_ref_frame_map_idx(cpi, ref_frame); |
| 663 | return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX; |
| 664 | } |
| 665 | |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 666 | #if CONFIG_HASH_ME |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 667 | // TODO(huisu@google.com, youzhou@microsoft.com): enable hash-me for HBD. |
| 668 | static INLINE int av1_use_hash_me(const AV1_COMMON *const cm) { |
Debargha Mukherjee | 8112d2f | 2018-03-01 09:53:11 -0800 | [diff] [blame] | 669 | return cm->allow_screen_content_tools; |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static INLINE hash_table *av1_get_ref_frame_hash_map( |
| 673 | const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) { |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 674 | const AV1_COMMON *const cm = &cpi->common; |
| 675 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 676 | return buf_idx != INVALID_IDX |
| 677 | ? &cm->buffer_pool->frame_bufs[buf_idx].hash_table |
| 678 | : NULL; |
| 679 | } |
| 680 | #endif |
| 681 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 682 | static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer( |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 683 | const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) { |
| 684 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 685 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 686 | return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf |
| 687 | : NULL; |
| 688 | } |
| 689 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 690 | 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] | 691 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 692 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 693 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 694 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 695 | if (buf_idx == INVALID_IDX) continue; |
| 696 | if (frame_buf == &cm->buffer_pool->frame_bufs[buf_idx]) break; |
| 697 | } |
| 698 | return (ref_frame <= ALTREF_FRAME); |
| 699 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 700 | |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 701 | 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] | 702 | int sb_size_log2, |
| 703 | const int num_planes) { |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 704 | // Calculate the maximum number of max superblocks in the image. |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 705 | const int shift = sb_size_log2 - 4; |
| 706 | const int sb_size = 1 << sb_size_log2; |
| 707 | const int sb_size_square = sb_size * sb_size; |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 708 | const int sb_rows = ALIGN_POWER_OF_TWO(mb_rows, shift) >> shift; |
| 709 | const int sb_cols = ALIGN_POWER_OF_TWO(mb_cols, shift) >> shift; |
| 710 | |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 711 | // For transform coefficients, assume planes with no subsampling. We assume |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 712 | // up to 1 token per pixel, and then allow a head room of 1 EOSB token per |
| 713 | // 4x4 block per plane, plus EOSB_TOKEN per plane. |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 714 | const int sb_coeff_toks = |
| 715 | num_planes * (sb_size_square + (sb_size_square / 16) + 1); |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 716 | |
| 717 | // For palette coefficients, there can be at most one palette for each 8x8 |
| 718 | // block. If w, h are the width and height of the block, the palette has at |
| 719 | // most 1 + h * w tokens (65 for an 8x8 block) without (see |
| 720 | // cost_and_tokenize_map). At most, there can be palettes on two planes. |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 721 | const int sb_palette_toks = 2 * (1 + 64) * (sb_size_square / 64); |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 722 | |
| 723 | return sb_rows * sb_cols * (sb_coeff_toks + sb_palette_toks); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | // Get the allocated token size for a tile. It does the same calculation as in |
| 727 | // the frame token allocation. |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 728 | static INLINE unsigned int allocated_tokens(TileInfo tile, int sb_size_log2, |
| 729 | int num_planes) { |
Jingning Han | eafbd5f | 2017-03-07 11:18:17 -0800 | [diff] [blame] | 730 | int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 2) >> 2; |
| 731 | 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] | 732 | |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 733 | 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] | 734 | } |
| 735 | |
Fangwen Fu | 8d164de | 2016-12-14 13:40:54 -0800 | [diff] [blame] | 736 | void av1_set_temporal_mv_prediction(AV1_COMP *cpi, int allow_tempmv_prediction); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 737 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 738 | 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] | 739 | |
Yaowu Xu | 6da4230 | 2017-10-10 14:45:06 -0700 | [diff] [blame] | 740 | #define ALT_MIN_LAG 3 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 741 | static INLINE int is_altref_enabled(const AV1_COMP *const cpi) { |
Yaowu Xu | 6da4230 | 2017-10-10 14:45:06 -0700 | [diff] [blame] | 742 | 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] | 743 | } |
| 744 | |
| 745 | // TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 746 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 747 | static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 748 | MV_REFERENCE_FRAME ref0, |
| 749 | MV_REFERENCE_FRAME ref1) { |
| 750 | xd->block_refs[0] = |
| 751 | &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0]; |
| 752 | xd->block_refs[1] = |
| 753 | &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0]; |
| 754 | } |
| 755 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 756 | static INLINE int get_chessboard_index(int frame_index) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 757 | return frame_index & 0x1; |
| 758 | } |
| 759 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 760 | 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] | 761 | return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL; |
| 762 | } |
| 763 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 764 | void av1_new_framerate(AV1_COMP *cpi, double framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 765 | |
| 766 | #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl)) |
| 767 | |
| 768 | // Update up-sampled reference frame index. |
| 769 | static INLINE void uref_cnt_fb(EncRefCntBuffer *ubufs, int *uidx, |
| 770 | int new_uidx) { |
| 771 | const int ref_index = *uidx; |
| 772 | |
| 773 | if (ref_index >= 0 && ubufs[ref_index].ref_count > 0) |
| 774 | ubufs[ref_index].ref_count--; |
| 775 | |
| 776 | *uidx = new_uidx; |
| 777 | ubufs[new_uidx].ref_count++; |
| 778 | } |
| 779 | |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 780 | // Returns 1 if a frame is unscaled and 0 otherwise. |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 781 | static INLINE int av1_resize_unscaled(const AV1_COMMON *cm) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 782 | return cm->superres_upscaled_width == cm->render_width && |
| 783 | cm->superres_upscaled_height == cm->render_height; |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 784 | } |
| 785 | |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 786 | static INLINE int av1_frame_unscaled(const AV1_COMMON *cm) { |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 787 | return av1_superres_unscaled(cm) && av1_resize_unscaled(cm); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 788 | } |
| 789 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 790 | #ifdef __cplusplus |
| 791 | } // extern "C" |
| 792 | #endif |
| 793 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 794 | #endif // AV1_ENCODER_ENCODER_H_ |