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