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