Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 12 | #ifndef AOM_AV1_ENCODER_ENCODER_H_ |
| 13 | #define AOM_AV1_ENCODER_ENCODER_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
elliottk | b8becb2 | 2019-03-04 01:01:30 -0800 | [diff] [blame] | 15 | #include <stdbool.h> |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | #include <stdio.h> |
| 17 | |
Tom Finegan | 60e653d | 2018-05-22 11:34:58 -0700 | [diff] [blame] | 18 | #include "config/aom_config.h" |
| 19 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | #include "aom/aomcx.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 21 | |
| 22 | #include "av1/common/alloccommon.h" |
| 23 | #include "av1/common/entropymode.h" |
| 24 | #include "av1/common/thread_common.h" |
| 25 | #include "av1/common/onyxc_int.h" |
Fergus Simpson | d2bcbb5 | 2017-05-22 23:15:05 -0700 | [diff] [blame] | 26 | #include "av1/common/resize.h" |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 27 | #include "av1/common/timing.h" |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 28 | #include "av1/common/blockd.h" |
| 29 | #include "av1/common/enums.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 30 | #include "av1/encoder/aq_cyclicrefresh.h" |
Tom Finegan | 17ce8b1 | 2017-02-08 12:46:31 -0800 | [diff] [blame] | 31 | #include "av1/encoder/av1_quantize.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 32 | #include "av1/encoder/context_tree.h" |
| 33 | #include "av1/encoder/encodemb.h" |
| 34 | #include "av1/encoder/firstpass.h" |
chiyotsai | d16a257 | 2019-03-05 17:48:10 -0800 | [diff] [blame] | 35 | #include "av1/encoder/level.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 36 | #include "av1/encoder/lookahead.h" |
| 37 | #include "av1/encoder/mbgraph.h" |
| 38 | #include "av1/encoder/mcomp.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | #include "av1/encoder/ratectrl.h" |
| 40 | #include "av1/encoder/rd.h" |
| 41 | #include "av1/encoder/speed_features.h" |
Marco Paniconi | 5b1e473 | 2019-08-08 18:57:53 -0700 | [diff] [blame] | 42 | #include "av1/encoder/svc_layercontext.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | #include "av1/encoder/tokenize.h" |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 44 | #include "av1/encoder/block.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 45 | |
| 46 | #if CONFIG_INTERNAL_STATS |
| 47 | #include "aom_dsp/ssim.h" |
| 48 | #endif |
| 49 | #include "aom_dsp/variance.h" |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 50 | #if CONFIG_DENOISE |
| 51 | #include "aom_dsp/noise_model.h" |
| 52 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 53 | #include "aom/internal/aom_codec_internal.h" |
| 54 | #include "aom_util/aom_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 55 | |
| 56 | #ifdef __cplusplus |
| 57 | extern "C" { |
| 58 | #endif |
| 59 | |
Yue Chen | c79fd24 | 2019-04-05 14:49:29 -0700 | [diff] [blame] | 60 | // Rational number with an int64 numerator |
| 61 | // This structure holds a fractional value |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 62 | typedef struct aom_rational64 { |
Yue Chen | c79fd24 | 2019-04-05 14:49:29 -0700 | [diff] [blame] | 63 | int64_t num; // fraction numerator |
| 64 | int den; // fraction denominator |
| 65 | } aom_rational64_t; // alias for struct aom_rational |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 66 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 67 | typedef struct { |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 68 | int nmv_vec_cost[MV_JOINTS]; |
| 69 | int nmv_costs[2][MV_VALS]; |
| 70 | int nmv_costs_hp[2][MV_VALS]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 71 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 72 | FRAME_CONTEXT fc; |
Urvang Joshi | 0e8b6ed | 2019-06-20 15:36:21 -0700 | [diff] [blame] | 73 | |
| 74 | #if CONFIG_SUPERRES_IN_RECODE |
| 75 | struct loopfilter lf; |
| 76 | CdefInfo cdef_info; |
| 77 | YV12_BUFFER_CONFIG copy_buffer; |
| 78 | RATE_CONTROL rc; |
| 79 | #endif // CONFIG_SUPERRES_IN_RECODE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 80 | } CODING_CONTEXT; |
| 81 | |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 82 | enum { |
Urvang Joshi | f70375a | 2019-03-22 23:30:19 -0700 | [diff] [blame] | 83 | REGULAR_FRAME, // regular inter frame |
| 84 | ARF_FRAME, // alternate reference frame |
| 85 | OVERLAY_FRAME, // overlay frame |
| 86 | GLD_FRAME, // golden frame |
| 87 | BRF_FRAME, // backward reference frame |
| 88 | INTERNAL_ARF_FRAME, // internal alternate reference frame |
Thomas Daede | 51020e1 | 2017-12-14 20:12:44 -0800 | [diff] [blame] | 89 | FRAME_CONTEXT_INDEXES |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 90 | } UENUM1BYTE(FRAME_CONTEXT_INDEX); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 91 | |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 92 | enum { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 93 | NORMAL = 0, |
| 94 | FOURFIVE = 1, |
| 95 | THREEFIVE = 2, |
| 96 | ONETWO = 3 |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 97 | } UENUM1BYTE(AOM_SCALING); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 98 | |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 99 | enum { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 100 | // Good Quality Fast Encoding. The encoder balances quality with the amount of |
| 101 | // time it takes to encode the output. Speed setting controls how fast. |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 102 | GOOD, |
| 103 | // Realtime Fast Encoding. Will force some restrictions on bitrate |
| 104 | // constraints. |
| 105 | REALTIME |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 106 | } UENUM1BYTE(MODE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 107 | |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 108 | enum { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 109 | FRAMEFLAGS_KEY = 1 << 0, |
| 110 | FRAMEFLAGS_GOLDEN = 1 << 1, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 111 | FRAMEFLAGS_BWDREF = 1 << 2, |
Zoe Liu | 3ac2093 | 2017-08-30 16:35:55 -0700 | [diff] [blame] | 112 | // 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] | 113 | FRAMEFLAGS_ALTREF = 1 << 3, |
Debargha Mukherjee | 5737825 | 2018-09-21 18:29:37 -0700 | [diff] [blame] | 114 | FRAMEFLAGS_INTRAONLY = 1 << 4, |
| 115 | FRAMEFLAGS_SWITCH = 1 << 5, |
| 116 | FRAMEFLAGS_ERROR_RESILIENT = 1 << 6, |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 117 | } UENUM1BYTE(FRAMETYPE_FLAGS); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 118 | |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 119 | enum { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 120 | NO_AQ = 0, |
| 121 | VARIANCE_AQ = 1, |
| 122 | COMPLEXITY_AQ = 2, |
| 123 | CYCLIC_REFRESH_AQ = 3, |
| 124 | AQ_MODE_COUNT // This should always be the last member of the enum |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 125 | } UENUM1BYTE(AQ_MODE); |
| 126 | enum { |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 127 | NO_DELTA_Q = 0, |
Debargha Mukherjee | 4fef7a5 | 2019-04-04 01:02:06 -0700 | [diff] [blame] | 128 | DELTA_Q_OBJECTIVE = 1, // Modulation to improve objective quality |
| 129 | DELTA_Q_PERCEPTUAL = 2, // Modulation to improve perceptual quality |
| 130 | DELTA_Q_MODE_COUNT // This should always be the last member of the enum |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 131 | } UENUM1BYTE(DELTAQ_MODE); |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 132 | |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 133 | enum { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 134 | RESIZE_NONE = 0, // No frame resizing allowed. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 135 | RESIZE_FIXED = 1, // All frames are coded at the specified scale. |
| 136 | RESIZE_RANDOM = 2, // All frames are coded at a random scale. |
| 137 | RESIZE_MODES |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 138 | } UENUM1BYTE(RESIZE_MODE); |
Debargha Mukherjee | 3a4959f | 2018-02-26 15:34:03 -0800 | [diff] [blame] | 139 | |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 140 | enum { |
Urvang Joshi | 36a8373 | 2019-01-31 15:31:57 -0800 | [diff] [blame] | 141 | SUPERRES_NONE, // No frame superres allowed. |
| 142 | SUPERRES_FIXED, // All frames are coded at the specified scale, |
| 143 | // and super-resolved. |
| 144 | SUPERRES_RANDOM, // All frames are coded at a random scale, |
| 145 | // and super-resolved. |
| 146 | SUPERRES_QTHRESH, // Superres scale for a frame is determined based on |
| 147 | // q_index. |
| 148 | SUPERRES_AUTO, // Automatically select superres for appropriate frames. |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 149 | SUPERRES_MODES |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 150 | } UENUM1BYTE(SUPERRES_MODE); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 151 | |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 152 | typedef enum { |
| 153 | kInvalid = 0, |
| 154 | kLowSadLowSumdiff = 1, |
| 155 | kLowSadHighSumdiff = 2, |
| 156 | kHighSadLowSumdiff = 3, |
| 157 | kHighSadHighSumdiff = 4, |
| 158 | kLowVarHighSumdiff = 5, |
| 159 | kVeryHighSad = 6, |
| 160 | } CONTENT_STATE_SB; |
| 161 | |
Satish Kumar Suman | e6d0be5 | 2019-02-14 14:33:28 +0530 | [diff] [blame] | 162 | enum { |
| 163 | SS_CFG_SRC = 0, |
| 164 | SS_CFG_LOOKAHEAD = 1, |
| 165 | SS_CFG_TOTAL = 2 |
| 166 | } UENUM1BYTE(SS_CFG_OFFSET); |
| 167 | |
Jingning Han | 31a0ee9 | 2019-07-15 13:56:55 -0700 | [diff] [blame] | 168 | #define MAX_LENGTH_TPL_FRAME_STATS (27 + 9) |
Yue Chen | c9b23e0 | 2019-04-10 16:54:03 -0700 | [diff] [blame] | 169 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 170 | typedef struct TplDepStats { |
| 171 | int64_t intra_cost; |
| 172 | int64_t inter_cost; |
| 173 | int64_t mc_flow; |
| 174 | int64_t mc_dep_cost; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 175 | #if !USE_TPL_CLASSIC_MODEL |
Debargha Mukherjee | 88ff738 | 2019-05-01 12:36:10 -0700 | [diff] [blame] | 176 | int64_t mc_count; |
| 177 | int64_t mc_saved; |
Yue Chen | bd93423 | 2019-08-05 14:23:39 -0700 | [diff] [blame] | 178 | #endif // !USE_TPL_CLASSIC_MODEL |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 179 | } TplDepStats; |
| 180 | |
| 181 | typedef struct TplDepFrame { |
| 182 | uint8_t is_valid; |
| 183 | TplDepStats *tpl_stats_ptr; |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 184 | const YV12_BUFFER_CONFIG *gf_picture; |
Jingning Han | 31a0ee9 | 2019-07-15 13:56:55 -0700 | [diff] [blame] | 185 | int ref_map_index[REF_FRAMES]; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 186 | int stride; |
| 187 | int width; |
| 188 | int height; |
| 189 | int mi_rows; |
| 190 | int mi_cols; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 191 | } TplDepFrame; |
| 192 | |
Debargha Mukherjee | 03ad12d | 2019-02-07 11:17:59 -0800 | [diff] [blame] | 193 | typedef enum { |
| 194 | COST_UPD_SB, |
| 195 | COST_UPD_SBROW, |
| 196 | COST_UPD_TILE, |
| 197 | } COST_UPDATE_TYPE; |
| 198 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 199 | #define TPL_DEP_COST_SCALE_LOG2 4 |
| 200 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 201 | typedef struct AV1EncoderConfig { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 202 | BITSTREAM_PROFILE profile; |
Tom Finegan | 8ab2bba | 2018-02-28 07:36:28 -0800 | [diff] [blame] | 203 | aom_bit_depth_t bit_depth; // Codec bit-depth. |
| 204 | int width; // width of data passed to the compressor |
| 205 | int height; // height of data passed to the compressor |
| 206 | int forced_max_frame_width; // forced maximum width of frame (if != 0) |
| 207 | int forced_max_frame_height; // forced maximum height of frame (if != 0) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 208 | unsigned int input_bit_depth; // Input bit depth. |
| 209 | double init_framerate; // set to passed in framerate |
| 210 | int64_t target_bandwidth; // bandwidth to be used in bits per second |
| 211 | |
| 212 | int noise_sensitivity; // pre processing blur: recommendation 0 |
| 213 | int sharpness; // sharpening output: recommendation 0: |
| 214 | int speed; |
| 215 | // maximum allowed bitrate for any intra frame in % of bitrate target. |
| 216 | unsigned int rc_max_intra_bitrate_pct; |
| 217 | // maximum allowed bitrate for any inter frame in % of bitrate target. |
| 218 | unsigned int rc_max_inter_bitrate_pct; |
| 219 | // percent of rate boost for golden frame in CBR mode. |
| 220 | unsigned int gf_cbr_boost_pct; |
| 221 | |
| 222 | MODE mode; |
| 223 | int pass; |
| 224 | |
| 225 | // Key Framing Operations |
| 226 | int auto_key; // autodetect cut scenes and set the keyframes |
| 227 | int key_freq; // maximum distance to key frame. |
Tarek AMARA | c981385 | 2018-03-05 18:40:18 -0500 | [diff] [blame] | 228 | int sframe_dist; |
| 229 | int sframe_mode; |
| 230 | int sframe_enabled; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 231 | int lag_in_frames; // how many frames lag before we start encoding |
Sarah Parker | 93c0314 | 2018-05-22 13:35:45 -0700 | [diff] [blame] | 232 | int fwd_kf_enabled; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 233 | |
| 234 | // ---------------------------------------------------------------- |
| 235 | // DATARATE CONTROL OPTIONS |
| 236 | |
| 237 | // vbr, cbr, constrained quality or constant quality |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 238 | enum aom_rc_mode rc_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 239 | |
| 240 | // buffer targeting aggressiveness |
| 241 | int under_shoot_pct; |
| 242 | int over_shoot_pct; |
| 243 | |
| 244 | // buffering parameters |
| 245 | int64_t starting_buffer_level_ms; |
| 246 | int64_t optimal_buffer_level_ms; |
| 247 | int64_t maximum_buffer_size_ms; |
| 248 | |
| 249 | // Frame drop threshold. |
| 250 | int drop_frames_water_mark; |
| 251 | |
| 252 | // controlling quality |
| 253 | int fixed_q; |
| 254 | int worst_allowed_q; |
| 255 | int best_allowed_q; |
| 256 | int cq_level; |
Yue Chen | c5806c2 | 2019-07-19 17:32:57 -0700 | [diff] [blame] | 257 | int enable_chroma_deltaq; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 258 | AQ_MODE aq_mode; // Adaptive Quantization mode |
Fangwen Fu | 6160df2 | 2017-04-24 09:45:51 -0700 | [diff] [blame] | 259 | DELTAQ_MODE deltaq_mode; |
Debargha Mukherjee | 4fef7a5 | 2019-04-04 01:02:06 -0700 | [diff] [blame] | 260 | int deltalf_mode; |
Debargha Mukherjee | 98a311c | 2018-03-25 16:33:11 -0700 | [diff] [blame] | 261 | int enable_cdef; |
| 262 | int enable_restoration; |
Yaowu Xu | 2a9ac43 | 2019-08-06 14:21:17 -0700 | [diff] [blame] | 263 | int force_video_mode; |
Yue Chen | 5e12951 | 2018-12-10 10:48:54 -0800 | [diff] [blame] | 264 | int enable_obmc; |
Yue Chen | 4835dc0 | 2018-05-11 15:57:43 -0700 | [diff] [blame] | 265 | int disable_trellis_quant; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 266 | int using_qm; |
Yaowu Xu | f7a1242 | 2018-01-31 15:29:20 -0800 | [diff] [blame] | 267 | int qm_y; |
| 268 | int qm_u; |
| 269 | int qm_v; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 270 | int qm_minlevel; |
| 271 | int qm_maxlevel; |
Yushin Cho | d808bfc | 2017-08-10 15:54:36 -0700 | [diff] [blame] | 272 | #if CONFIG_DIST_8X8 |
| 273 | int using_dist_8x8; |
| 274 | #endif |
Thomas Davies | af6df17 | 2016-11-09 14:04:18 +0000 | [diff] [blame] | 275 | unsigned int num_tile_groups; |
| 276 | unsigned int mtu; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 277 | |
| 278 | // Internal frame size scaling. |
Debargha Mukherjee | 29e40a6 | 2017-06-14 09:37:12 -0700 | [diff] [blame] | 279 | RESIZE_MODE resize_mode; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 280 | uint8_t resize_scale_denominator; |
| 281 | uint8_t resize_kf_scale_denominator; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 282 | |
Fergus Simpson | c4e7894 | 2017-04-10 14:59:00 -0700 | [diff] [blame] | 283 | // Frame Super-Resolution size scaling. |
| 284 | SUPERRES_MODE superres_mode; |
Urvang Joshi | de71d14 | 2017-10-05 12:12:15 -0700 | [diff] [blame] | 285 | uint8_t superres_scale_denominator; |
| 286 | uint8_t superres_kf_scale_denominator; |
Debargha Mukherjee | 7166f22 | 2017-09-05 21:32:42 -0700 | [diff] [blame] | 287 | int superres_qthresh; |
| 288 | int superres_kf_qthresh; |
Fergus Simpson | 3502d08 | 2017-04-10 12:25:07 -0700 | [diff] [blame] | 289 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 290 | // Enable feature to reduce the frame quantization every x frames. |
| 291 | int frame_periodic_boost; |
| 292 | |
| 293 | // two pass datarate control |
| 294 | int two_pass_vbrbias; // two pass datarate control tweaks |
| 295 | int two_pass_vbrmin_section; |
| 296 | int two_pass_vbrmax_section; |
| 297 | // END DATARATE CONTROL OPTIONS |
| 298 | // ---------------------------------------------------------------- |
| 299 | |
| 300 | int enable_auto_arf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 301 | int enable_auto_brf; // (b)ackward (r)ef (f)rame |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 302 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 303 | /* Bitfield defining the error resiliency features to enable. |
| 304 | * Can provide decodable frames after losses in previous |
| 305 | * frames and decodable partitions after losses in the same frame. |
| 306 | */ |
| 307 | unsigned int error_resilient_mode; |
| 308 | |
Debargha Mukherjee | 52fb047 | 2018-03-29 15:48:11 -0700 | [diff] [blame] | 309 | unsigned int s_frame_mode; |
| 310 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 311 | /* Bitfield defining the parallel decoding mode where the |
| 312 | * decoding in successive frames may be conducted in parallel |
| 313 | * just by decoding the frame headers. |
| 314 | */ |
| 315 | unsigned int frame_parallel_decoding_mode; |
| 316 | |
Debargha Mukherjee | c6f24c2 | 2018-04-07 08:43:08 -0700 | [diff] [blame] | 317 | unsigned int limit; |
| 318 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 319 | int arnr_max_frames; |
| 320 | int arnr_strength; |
| 321 | |
| 322 | int min_gf_interval; |
| 323 | int max_gf_interval; |
Urvang Joshi | f4e775c | 2018-12-14 11:33:17 -0800 | [diff] [blame] | 324 | int gf_max_pyr_height; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 325 | |
Ravi Chaudhary | 0ec03a4 | 2018-08-17 18:53:28 +0530 | [diff] [blame] | 326 | int row_mt; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 327 | int tile_columns; |
| 328 | int tile_rows; |
Dominic Symes | 26ad0b2 | 2017-10-01 16:35:13 +0200 | [diff] [blame] | 329 | int tile_width_count; |
| 330 | int tile_height_count; |
| 331 | int tile_widths[MAX_TILE_COLS]; |
| 332 | int tile_heights[MAX_TILE_ROWS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 333 | |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 334 | int enable_tpl_model; |
| 335 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 336 | int max_threads; |
| 337 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 338 | aom_fixed_buf_t two_pass_stats_in; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 339 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 340 | aom_tune_metric tuning; |
| 341 | aom_tune_content content; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 342 | int use_highbitdepth; |
Andrey Norkin | 9e69463 | 2017-12-21 18:50:57 -0800 | [diff] [blame] | 343 | aom_color_primaries_t color_primaries; |
| 344 | aom_transfer_characteristics_t transfer_characteristics; |
| 345 | aom_matrix_coefficients_t matrix_coefficients; |
anorkin | 76fb126 | 2017-03-22 15:12:12 -0700 | [diff] [blame] | 346 | aom_chroma_sample_position_t chroma_sample_position; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 347 | int color_range; |
| 348 | int render_width; |
| 349 | int render_height; |
Andrey Norkin | 28e9ce2 | 2018-01-08 10:11:21 -0800 | [diff] [blame] | 350 | int timing_info_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 351 | aom_timing_info_t timing_info; |
| 352 | int decoder_model_info_present_flag; |
Andrey Norkin | 2649551 | 2018-06-20 17:13:11 -0700 | [diff] [blame] | 353 | int display_model_info_present_flag; |
Wan-Teh Chang | f64b3bc | 2018-07-02 09:42:39 -0700 | [diff] [blame] | 354 | int buffer_removal_time_present; |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 355 | aom_dec_model_info_t buffer_model; |
Andrey Norkin | 6f1c2f7 | 2018-01-15 20:08:52 -0800 | [diff] [blame] | 356 | int film_grain_test_vector; |
Neil Birkbeck | eb895ef | 2018-03-14 17:51:03 -0700 | [diff] [blame] | 357 | const char *film_grain_table_filename; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 358 | |
Hui Su | 1cb1c00 | 2018-02-05 18:21:20 -0800 | [diff] [blame] | 359 | uint8_t cdf_update_mode; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 360 | aom_superblock_size_t superblock_size; |
Yunqing Wang | eeb08a9 | 2017-07-07 21:25:18 -0700 | [diff] [blame] | 361 | unsigned int large_scale_tile; |
| 362 | unsigned int single_tile_decoding; |
Yaowu Xu | 76537ca | 2019-01-03 12:41:32 -0800 | [diff] [blame] | 363 | uint8_t monochrome; |
Debargha Mukherjee | 9713ccb | 2018-04-08 19:09:17 -0700 | [diff] [blame] | 364 | unsigned int full_still_picture_hdr; |
Jingning Han | a446f55 | 2018-02-22 15:42:12 -0800 | [diff] [blame] | 365 | int enable_dual_filter; |
Yunqing Wang | ff4fa06 | 2017-04-21 10:56:08 -0700 | [diff] [blame] | 366 | unsigned int motion_vector_unit_test; |
Maxym Dmytrychenko | cc6e0e1 | 2018-02-05 16:35:37 +0100 | [diff] [blame] | 367 | const cfg_options_t *cfg; |
Debargha Mukherjee | 9d9cf19 | 2018-12-17 11:24:21 -0800 | [diff] [blame] | 368 | int enable_rect_partitions; |
Ryan Lei | 9543c70 | 2019-03-11 11:06:14 -0700 | [diff] [blame] | 369 | int enable_ab_partitions; |
| 370 | int enable_1to4_partitions; |
| 371 | int min_partition_size; |
| 372 | int max_partition_size; |
Debargha Mukherjee | 03c43ba | 2018-12-14 13:08:08 -0800 | [diff] [blame] | 373 | int enable_intra_edge_filter; |
Debargha Mukherjee | 8c917b0 | 2018-12-17 13:45:50 -0800 | [diff] [blame] | 374 | int enable_tx64; |
Ryan Lei | 82d0a04 | 2019-03-18 15:02:26 -0700 | [diff] [blame] | 375 | int tx_size_search_method; |
Ryan Lei | 9543c70 | 2019-03-11 11:06:14 -0700 | [diff] [blame] | 376 | int enable_flip_idtx; |
Debargha Mukherjee | 0d8368a | 2018-03-25 12:23:02 -0700 | [diff] [blame] | 377 | int enable_order_hint; |
Debargha Mukherjee | 7ac3eb1 | 2018-12-12 10:26:50 -0800 | [diff] [blame] | 378 | int enable_dist_wtd_comp; |
Debargha Mukherjee | 0187d7c | 2018-03-25 11:37:56 -0700 | [diff] [blame] | 379 | int enable_ref_frame_mvs; |
Urvang Joshi | 9ad9f08 | 2019-01-22 12:31:33 -0800 | [diff] [blame] | 380 | unsigned int max_reference_frames; |
Urvang Joshi | 1a9e27e | 2019-02-19 11:17:23 -0800 | [diff] [blame] | 381 | int enable_reduced_reference_set; |
Debargha Mukherjee | 0d8368a | 2018-03-25 12:23:02 -0700 | [diff] [blame] | 382 | unsigned int allow_ref_frame_mvs; |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame] | 383 | int enable_masked_comp; |
Ryan Lei | 9543c70 | 2019-03-11 11:06:14 -0700 | [diff] [blame] | 384 | int enable_onesided_comp; |
Debargha Mukherjee | 16ea6ba | 2018-12-10 12:01:38 -0800 | [diff] [blame] | 385 | int enable_interintra_comp; |
Yue Chen | 8cbee6c | 2018-12-14 11:54:39 -0800 | [diff] [blame] | 386 | int enable_smooth_interintra; |
Debargha Mukherjee | 78e6b2c | 2018-12-11 07:50:57 -0800 | [diff] [blame] | 387 | int enable_diff_wtd_comp; |
| 388 | int enable_interinter_wedge; |
| 389 | int enable_interintra_wedge; |
Debargha Mukherjee | d2e53ca | 2018-12-10 11:34:59 -0800 | [diff] [blame] | 390 | int enable_global_motion; |
Debargha Mukherjee | 37df916 | 2018-03-25 12:48:24 -0700 | [diff] [blame] | 391 | int enable_warped_motion; |
| 392 | int allow_warped_motion; |
Yue Chen | 8f9ca58 | 2018-12-12 15:11:47 -0800 | [diff] [blame] | 393 | int enable_filter_intra; |
Debargha Mukherjee | 078ae86 | 2018-12-18 11:05:43 -0800 | [diff] [blame] | 394 | int enable_smooth_intra; |
| 395 | int enable_paeth_intra; |
Debargha Mukherjee | 8e25678 | 2018-12-18 13:44:13 -0800 | [diff] [blame] | 396 | int enable_cfl_intra; |
Urvang Joshi | 2c92b07 | 2018-03-19 17:23:31 -0700 | [diff] [blame] | 397 | int enable_superres; |
Hui Su | a9e3d14 | 2018-12-14 15:21:21 -0800 | [diff] [blame] | 398 | int enable_palette; |
Hui Su | 440e6d4 | 2018-12-17 11:47:07 -0800 | [diff] [blame] | 399 | int enable_intrabc; |
Hui Su | 94b3817 | 2018-12-19 10:40:29 -0800 | [diff] [blame] | 400 | int enable_angle_delta; |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 401 | unsigned int save_as_annexb; |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 402 | |
| 403 | #if CONFIG_DENOISE |
| 404 | float noise_level; |
| 405 | int noise_block_size; |
| 406 | #endif |
Tom Finegan | 02b2a84 | 2018-08-24 13:50:00 -0700 | [diff] [blame] | 407 | |
| 408 | unsigned int chroma_subsampling_x; |
| 409 | unsigned int chroma_subsampling_y; |
Sarah Parker | 0b7e590 | 2018-12-10 13:35:25 -0800 | [diff] [blame] | 410 | int reduced_tx_type_set; |
Debargha Mukherjee | db45815 | 2019-01-25 11:04:09 -0800 | [diff] [blame] | 411 | int use_intra_dct_only; |
| 412 | int use_inter_dct_only; |
Debargha Mukherjee | 042af92 | 2019-02-07 05:58:26 -0800 | [diff] [blame] | 413 | int use_intra_default_tx_only; |
Sarah Parker | 740e839 | 2019-01-23 15:47:53 -0800 | [diff] [blame] | 414 | int quant_b_adapt; |
Debargha Mukherjee | 03ad12d | 2019-02-07 11:17:59 -0800 | [diff] [blame] | 415 | COST_UPDATE_TYPE coeff_cost_upd_freq; |
| 416 | COST_UPDATE_TYPE mode_cost_upd_freq; |
Satish Kumar Suman | 2990996 | 2019-01-09 10:31:21 +0530 | [diff] [blame] | 417 | int border_in_pixels; |
Hui Su | 2aa492c | 2019-03-12 15:18:18 -0700 | [diff] [blame] | 418 | AV1_LEVEL target_seq_level_idx[MAX_NUM_OPERATING_POINTS]; |
Hui Su | d909c2c | 2019-03-08 11:51:14 -0800 | [diff] [blame] | 419 | // Bit mask to specify which tier each of the 32 possible operating points |
| 420 | // conforms to. |
| 421 | unsigned int tier_mask; |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 422 | // min_cr / 100 is the target minimum compression ratio for each frame. |
| 423 | unsigned int min_cr; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 424 | } AV1EncoderConfig; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 425 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 426 | static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 427 | return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0; |
| 428 | } |
| 429 | |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 430 | typedef struct FRAME_COUNTS { |
| 431 | // Note: This structure should only contain 'unsigned int' fields, or |
| 432 | // aggregates built solely from 'unsigned int' fields/elements |
| 433 | #if CONFIG_ENTROPY_STATS |
| 434 | unsigned int kf_y_mode[KF_MODE_CONTEXTS][KF_MODE_CONTEXTS][INTRA_MODES]; |
| 435 | unsigned int angle_delta[DIRECTIONAL_MODES][2 * MAX_ANGLE_DELTA + 1]; |
| 436 | unsigned int y_mode[BLOCK_SIZE_GROUPS][INTRA_MODES]; |
| 437 | unsigned int uv_mode[CFL_ALLOWED_TYPES][INTRA_MODES][UV_INTRA_MODES]; |
| 438 | unsigned int cfl_sign[CFL_JOINT_SIGNS]; |
| 439 | unsigned int cfl_alpha[CFL_ALPHA_CONTEXTS][CFL_ALPHABET_SIZE]; |
| 440 | unsigned int palette_y_mode[PALATTE_BSIZE_CTXS][PALETTE_Y_MODE_CONTEXTS][2]; |
| 441 | unsigned int palette_uv_mode[PALETTE_UV_MODE_CONTEXTS][2]; |
| 442 | unsigned int palette_y_size[PALATTE_BSIZE_CTXS][PALETTE_SIZES]; |
| 443 | unsigned int palette_uv_size[PALATTE_BSIZE_CTXS][PALETTE_SIZES]; |
| 444 | unsigned int palette_y_color_index[PALETTE_SIZES] |
| 445 | [PALETTE_COLOR_INDEX_CONTEXTS] |
| 446 | [PALETTE_COLORS]; |
| 447 | unsigned int palette_uv_color_index[PALETTE_SIZES] |
| 448 | [PALETTE_COLOR_INDEX_CONTEXTS] |
| 449 | [PALETTE_COLORS]; |
| 450 | unsigned int partition[PARTITION_CONTEXTS][EXT_PARTITION_TYPES]; |
| 451 | unsigned int txb_skip[TOKEN_CDF_Q_CTXS][TX_SIZES][TXB_SKIP_CONTEXTS][2]; |
| 452 | unsigned int eob_extra[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 453 | [EOB_COEF_CONTEXTS][2]; |
| 454 | unsigned int dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS][2]; |
| 455 | unsigned int coeff_lps[TX_SIZES][PLANE_TYPES][BR_CDF_SIZE - 1][LEVEL_CONTEXTS] |
| 456 | [2]; |
| 457 | unsigned int eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS][2]; |
| 458 | unsigned int eob_multi16[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][5]; |
| 459 | unsigned int eob_multi32[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][6]; |
| 460 | unsigned int eob_multi64[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][7]; |
| 461 | unsigned int eob_multi128[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][8]; |
| 462 | unsigned int eob_multi256[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][9]; |
| 463 | unsigned int eob_multi512[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][10]; |
| 464 | unsigned int eob_multi1024[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][11]; |
| 465 | unsigned int coeff_lps_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 466 | [LEVEL_CONTEXTS][BR_CDF_SIZE]; |
| 467 | unsigned int coeff_base_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 468 | [SIG_COEF_CONTEXTS][NUM_BASE_LEVELS + 2]; |
| 469 | unsigned int coeff_base_eob_multi[TOKEN_CDF_Q_CTXS][TX_SIZES][PLANE_TYPES] |
| 470 | [SIG_COEF_CONTEXTS_EOB][NUM_BASE_LEVELS + 1]; |
| 471 | unsigned int newmv_mode[NEWMV_MODE_CONTEXTS][2]; |
| 472 | unsigned int zeromv_mode[GLOBALMV_MODE_CONTEXTS][2]; |
| 473 | unsigned int refmv_mode[REFMV_MODE_CONTEXTS][2]; |
| 474 | unsigned int drl_mode[DRL_MODE_CONTEXTS][2]; |
| 475 | unsigned int inter_compound_mode[INTER_MODE_CONTEXTS][INTER_COMPOUND_MODES]; |
| 476 | unsigned int wedge_idx[BLOCK_SIZES_ALL][16]; |
| 477 | unsigned int interintra[BLOCK_SIZE_GROUPS][2]; |
| 478 | unsigned int interintra_mode[BLOCK_SIZE_GROUPS][INTERINTRA_MODES]; |
| 479 | unsigned int wedge_interintra[BLOCK_SIZES_ALL][2]; |
Debargha Mukherjee | 54eabb5 | 2019-02-01 16:54:33 -0800 | [diff] [blame] | 480 | unsigned int compound_type[BLOCK_SIZES_ALL][MASKED_COMPOUND_TYPES]; |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 481 | unsigned int motion_mode[BLOCK_SIZES_ALL][MOTION_MODES]; |
| 482 | unsigned int obmc[BLOCK_SIZES_ALL][2]; |
| 483 | unsigned int intra_inter[INTRA_INTER_CONTEXTS][2]; |
| 484 | unsigned int comp_inter[COMP_INTER_CONTEXTS][2]; |
| 485 | unsigned int comp_ref_type[COMP_REF_TYPE_CONTEXTS][2]; |
| 486 | unsigned int uni_comp_ref[UNI_COMP_REF_CONTEXTS][UNIDIR_COMP_REFS - 1][2]; |
| 487 | unsigned int single_ref[REF_CONTEXTS][SINGLE_REFS - 1][2]; |
| 488 | unsigned int comp_ref[REF_CONTEXTS][FWD_REFS - 1][2]; |
| 489 | unsigned int comp_bwdref[REF_CONTEXTS][BWD_REFS - 1][2]; |
| 490 | unsigned int intrabc[2]; |
| 491 | |
| 492 | unsigned int txfm_partition[TXFM_PARTITION_CONTEXTS][2]; |
| 493 | unsigned int intra_tx_size[MAX_TX_CATS][TX_SIZE_CONTEXTS][MAX_TX_DEPTH + 1]; |
| 494 | unsigned int skip_mode[SKIP_MODE_CONTEXTS][2]; |
| 495 | unsigned int skip[SKIP_CONTEXTS][2]; |
| 496 | unsigned int compound_index[COMP_INDEX_CONTEXTS][2]; |
| 497 | unsigned int comp_group_idx[COMP_GROUP_IDX_CONTEXTS][2]; |
| 498 | unsigned int delta_q[DELTA_Q_PROBS][2]; |
| 499 | unsigned int delta_lf_multi[FRAME_LF_COUNT][DELTA_LF_PROBS][2]; |
| 500 | unsigned int delta_lf[DELTA_LF_PROBS][2]; |
| 501 | |
| 502 | unsigned int inter_ext_tx[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES]; |
| 503 | unsigned int intra_ext_tx[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES] |
| 504 | [TX_TYPES]; |
| 505 | unsigned int filter_intra_mode[FILTER_INTRA_MODES]; |
| 506 | unsigned int filter_intra[BLOCK_SIZES_ALL][2]; |
| 507 | unsigned int switchable_restore[RESTORE_SWITCHABLE_TYPES]; |
| 508 | unsigned int wiener_restore[2]; |
| 509 | unsigned int sgrproj_restore[2]; |
| 510 | #endif // CONFIG_ENTROPY_STATS |
| 511 | |
| 512 | unsigned int switchable_interp[SWITCHABLE_FILTER_CONTEXTS] |
| 513 | [SWITCHABLE_FILTERS]; |
| 514 | } FRAME_COUNTS; |
| 515 | |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 516 | #define INTER_MODE_RD_DATA_OVERALL_SIZE 6400 |
| 517 | |
| 518 | typedef struct { |
| 519 | int ready; |
| 520 | double a; |
| 521 | double b; |
| 522 | double dist_mean; |
Angie Chiang | 199f3d4 | 2018-08-14 18:07:02 -0700 | [diff] [blame] | 523 | double ld_mean; |
| 524 | double sse_mean; |
| 525 | double sse_sse_mean; |
| 526 | double sse_ld_mean; |
Angie Chiang | 106fa48 | 2018-08-07 18:28:40 -0700 | [diff] [blame] | 527 | int num; |
| 528 | double dist_sum; |
| 529 | double ld_sum; |
| 530 | double sse_sum; |
| 531 | double sse_sse_sum; |
| 532 | double sse_ld_sum; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 533 | } InterModeRdModel; |
| 534 | |
| 535 | typedef struct { |
| 536 | int idx; |
| 537 | int64_t rd; |
| 538 | } RdIdxPair; |
| 539 | // TODO(angiebird): This is an estimated size. We still need to figure what is |
| 540 | // the maximum number of modes. |
| 541 | #define MAX_INTER_MODES 1024 |
| 542 | typedef struct inter_modes_info { |
| 543 | int num; |
| 544 | MB_MODE_INFO mbmi_arr[MAX_INTER_MODES]; |
| 545 | int mode_rate_arr[MAX_INTER_MODES]; |
| 546 | int64_t sse_arr[MAX_INTER_MODES]; |
| 547 | int64_t est_rd_arr[MAX_INTER_MODES]; |
| 548 | RdIdxPair rd_idx_pair_arr[MAX_INTER_MODES]; |
elliottk | b8becb2 | 2019-03-04 01:01:30 -0800 | [diff] [blame] | 549 | bool true_rd_arr[MAX_INTER_MODES]; |
elliottk | c8da531 | 2019-03-20 23:47:32 -0700 | [diff] [blame] | 550 | uint8_t blk_skip_arr[MAX_INTER_MODES][MAX_MIB_SIZE * MAX_MIB_SIZE]; |
elliottk | b8becb2 | 2019-03-04 01:01:30 -0800 | [diff] [blame] | 551 | RD_STATS rd_cost_arr[MAX_INTER_MODES]; |
| 552 | RD_STATS rd_cost_y_arr[MAX_INTER_MODES]; |
| 553 | RD_STATS rd_cost_uv_arr[MAX_INTER_MODES]; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 554 | } InterModesInfo; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 555 | |
Ravi Chaudhary | 40cdf13 | 2018-10-08 11:04:16 +0530 | [diff] [blame] | 556 | // Encoder row synchronization |
| 557 | typedef struct AV1RowMTSyncData { |
| 558 | #if CONFIG_MULTITHREAD |
| 559 | pthread_mutex_t *mutex_; |
| 560 | pthread_cond_t *cond_; |
| 561 | #endif |
| 562 | // Allocate memory to store the sb/mb block index in each row. |
| 563 | int *cur_col; |
| 564 | int sync_range; |
| 565 | int rows; |
| 566 | } AV1RowMTSync; |
| 567 | |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 568 | typedef struct AV1RowMTInfo { |
| 569 | int current_mi_row; |
| 570 | int num_threads_working; |
| 571 | } AV1RowMTInfo; |
| 572 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 573 | // TODO(jingning) All spatially adaptive variables should go to TileDataEnc. |
| 574 | typedef struct TileDataEnc { |
| 575 | TileInfo tile_info; |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 576 | int m_search_count; |
| 577 | int ex_search_count; |
Luc Trudeau | f816415 | 2017-04-11 16:20:51 -0400 | [diff] [blame] | 578 | CFL_CTX cfl; |
Jingning Han | 9f07be1 | 2017-04-13 09:31:40 -0700 | [diff] [blame] | 579 | DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx); |
Ravi Chaudhary | e521517 | 2018-12-21 18:47:25 +0530 | [diff] [blame] | 580 | FRAME_CONTEXT *row_ctx; |
Yunqing Wang | 0e141b5 | 2017-11-02 15:08:58 -0700 | [diff] [blame] | 581 | uint8_t allow_update_cdf; |
Angie Chiang | 7157216 | 2018-08-06 16:20:36 -0700 | [diff] [blame] | 582 | InterModeRdModel inter_mode_rd_models[BLOCK_SIZES_ALL]; |
Ravi Chaudhary | 40cdf13 | 2018-10-08 11:04:16 +0530 | [diff] [blame] | 583 | AV1RowMTSync row_mt_sync; |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 584 | AV1RowMTInfo row_mt_info; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 585 | } TileDataEnc; |
| 586 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 587 | typedef struct { |
| 588 | TOKENEXTRA *start; |
| 589 | TOKENEXTRA *stop; |
| 590 | unsigned int count; |
| 591 | } TOKENLIST; |
| 592 | |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 593 | typedef struct MultiThreadHandle { |
| 594 | int allocated_tile_rows; |
| 595 | int allocated_tile_cols; |
| 596 | int allocated_sb_rows; |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 597 | int thread_id_to_tile_id[MAX_NUM_THREADS]; // Mapping of threads to tiles |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 598 | } MultiThreadHandle; |
| 599 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 600 | typedef struct RD_COUNTS { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 601 | int64_t comp_pred_diff[REFERENCE_MODES]; |
Debargha Mukherjee | a575d23 | 2017-04-28 17:46:47 -0700 | [diff] [blame] | 602 | // Stores number of 4x4 blocks using global motion per reference frame. |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 603 | int global_motion_used[REF_FRAMES]; |
Arild Fuldseth (arilfuld) | 6c20c78 | 2017-06-15 09:45:02 +0200 | [diff] [blame] | 604 | int compound_ref_used_flag; |
Zoe Liu | 8a5d343 | 2017-11-30 16:33:44 -0800 | [diff] [blame] | 605 | int skip_mode_used_flag; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 606 | } RD_COUNTS; |
| 607 | |
| 608 | typedef struct ThreadData { |
| 609 | MACROBLOCK mb; |
| 610 | RD_COUNTS rd_counts; |
| 611 | FRAME_COUNTS *counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 612 | PC_TREE *pc_tree; |
| 613 | PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1]; |
wenyao.liu | 0c6f5fd | 2018-10-23 18:41:16 +0800 | [diff] [blame] | 614 | tran_low_t *tree_coeff_buf[MAX_MB_PLANE]; |
| 615 | tran_low_t *tree_qcoeff_buf[MAX_MB_PLANE]; |
| 616 | tran_low_t *tree_dqcoeff_buf[MAX_MB_PLANE]; |
Ravi Chaudhary | 5d970f4 | 2018-09-25 11:25:32 +0530 | [diff] [blame] | 617 | InterModesInfo *inter_modes_info; |
Ravi Chaudhary | 783d6a3 | 2018-08-28 18:21:02 +0530 | [diff] [blame] | 618 | uint32_t *hash_value_buffer[2][2]; |
Jingning Han | d064cf0 | 2017-06-01 10:00:39 -0700 | [diff] [blame] | 619 | int32_t *wsrc_buf; |
| 620 | int32_t *mask_buf; |
| 621 | uint8_t *above_pred_buf; |
| 622 | uint8_t *left_pred_buf; |
hui su | 5d49314 | 2017-05-08 12:06:12 -0700 | [diff] [blame] | 623 | PALETTE_BUFFER *palette_buffer; |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 624 | CompoundTypeRdBuffers comp_rd_buffer; |
Urvang Joshi | 0a4cfad | 2018-09-07 11:10:39 -0700 | [diff] [blame] | 625 | CONV_BUF_TYPE *tmp_conv_dst; |
| 626 | uint8_t *tmp_obmc_bufs[2]; |
Ravi Chaudhary | 00525ef | 2018-10-31 19:52:42 +0530 | [diff] [blame] | 627 | int intrabc_used; |
Yue Chen | c87d749 | 2019-05-30 17:22:49 -0700 | [diff] [blame] | 628 | int deltaq_used; |
Ravi Chaudhary | 84a280a | 2018-09-24 16:09:48 +0530 | [diff] [blame] | 629 | FRAME_CONTEXT *tctx; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 630 | } ThreadData; |
| 631 | |
| 632 | struct EncWorkerData; |
| 633 | |
| 634 | typedef struct ActiveMap { |
| 635 | int enabled; |
| 636 | int update; |
| 637 | unsigned char *map; |
| 638 | } ActiveMap; |
| 639 | |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 640 | #if CONFIG_INTERNAL_STATS |
| 641 | // types of stats |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 642 | enum { |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 643 | STAT_Y, |
| 644 | STAT_U, |
| 645 | STAT_V, |
| 646 | STAT_ALL, |
| 647 | NUM_STAT_TYPES // This should always be the last member of the enum |
Satish Kumar Suman | 4667aa1 | 2018-12-14 18:28:19 +0530 | [diff] [blame] | 648 | } UENUM1BYTE(StatType); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 649 | |
| 650 | typedef struct IMAGE_STAT { |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 651 | double stat[NUM_STAT_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 652 | double worst; |
| 653 | } ImageStat; |
Wan-Teh Chang | c25c92a | 2018-04-23 15:04:14 -0700 | [diff] [blame] | 654 | #endif // CONFIG_INTERNAL_STATS |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 655 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 656 | typedef struct { |
| 657 | int ref_count; |
| 658 | YV12_BUFFER_CONFIG buf; |
| 659 | } EncRefCntBuffer; |
| 660 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 661 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 662 | typedef struct PartitionStats { |
| 663 | int partition_decisions[6][EXT_PARTITION_TYPES]; |
| 664 | int partition_attempts[6][EXT_PARTITION_TYPES]; |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 665 | int64_t partition_times[6][EXT_PARTITION_TYPES]; |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 666 | |
| 667 | int partition_redo; |
| 668 | } PartitionStats; |
| 669 | #endif |
| 670 | |
Yunqing Wang | ba25558 | 2019-02-11 16:21:12 -0800 | [diff] [blame] | 671 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 672 | #include "aom_ports/aom_timer.h" |
| 673 | // Adjust the following to add new components. |
| 674 | enum { |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 675 | encode_frame_to_data_rate_time, |
| 676 | encode_with_recode_loop_time, |
| 677 | loop_filter_time, |
| 678 | cdef_time, |
| 679 | loop_restoration_time, |
| 680 | av1_pack_bitstream_final_time, |
| 681 | av1_encode_frame_time, |
| 682 | av1_compute_global_motion_time, |
| 683 | av1_setup_motion_field_time, |
Yunqing Wang | ba25558 | 2019-02-11 16:21:12 -0800 | [diff] [blame] | 684 | encode_sb_time, |
| 685 | rd_pick_partition_time, |
| 686 | rd_pick_sb_modes_time, |
| 687 | av1_rd_pick_intra_mode_sb_time, |
| 688 | av1_rd_pick_inter_mode_sb_time, |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 689 | handle_intra_mode_time, |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 690 | do_tx_search_time, |
| 691 | handle_newmv_time, |
| 692 | compound_type_rd_time, |
| 693 | interpolation_filter_search_time, |
Yunqing Wang | ba25558 | 2019-02-11 16:21:12 -0800 | [diff] [blame] | 694 | motion_mode_rd_time, |
| 695 | kTimingComponents, |
| 696 | } UENUM1BYTE(TIMING_COMPONENT); |
| 697 | |
| 698 | static INLINE char const *get_component_name(int index) { |
| 699 | switch (index) { |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 700 | case encode_frame_to_data_rate_time: |
| 701 | return "encode_frame_to_data_rate_time"; |
| 702 | case encode_with_recode_loop_time: return "encode_with_recode_loop_time"; |
| 703 | case loop_filter_time: return "loop_filter_time"; |
| 704 | case cdef_time: return "cdef_time"; |
| 705 | case loop_restoration_time: return "loop_restoration_time"; |
| 706 | case av1_pack_bitstream_final_time: return "av1_pack_bitstream_final_time"; |
| 707 | case av1_encode_frame_time: return "av1_encode_frame_time"; |
| 708 | case av1_compute_global_motion_time: |
| 709 | return "av1_compute_global_motion_time"; |
| 710 | case av1_setup_motion_field_time: return "av1_setup_motion_field_time"; |
| 711 | case encode_sb_time: return "encode_sb_time"; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 712 | case rd_pick_partition_time: return "rd_pick_partition_time"; |
| 713 | case rd_pick_sb_modes_time: return "rd_pick_sb_modes_time"; |
| 714 | case av1_rd_pick_intra_mode_sb_time: |
| 715 | return "av1_rd_pick_intra_mode_sb_time"; |
| 716 | case av1_rd_pick_inter_mode_sb_time: |
| 717 | return "av1_rd_pick_inter_mode_sb_time"; |
| 718 | case handle_intra_mode_time: return "handle_intra_mode_time"; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 719 | case do_tx_search_time: return "do_tx_search_time"; |
| 720 | case handle_newmv_time: return "handle_newmv_time"; |
| 721 | case compound_type_rd_time: return "compound_type_rd_time"; |
| 722 | case interpolation_filter_search_time: |
| 723 | return "interpolation_filter_search_time"; |
| 724 | case motion_mode_rd_time: return "motion_mode_rd_time"; |
Yunqing Wang | ba25558 | 2019-02-11 16:21:12 -0800 | [diff] [blame] | 725 | default: assert(0); |
| 726 | } |
| 727 | return "error"; |
| 728 | } |
| 729 | #endif |
| 730 | |
Urvang Joshi | f70375a | 2019-03-22 23:30:19 -0700 | [diff] [blame] | 731 | // The maximum number of internal ARFs except ALTREF_FRAME |
| 732 | #define MAX_INTERNAL_ARFS (REF_FRAMES - BWDREF_FRAME - 1) |
| 733 | |
Jingning Han | 42266ca | 2019-07-12 14:37:16 -0700 | [diff] [blame] | 734 | typedef struct { |
| 735 | int arf_stack[FRAME_BUFFERS]; |
| 736 | int arf_stack_size; |
| 737 | int lst_stack[FRAME_BUFFERS]; |
| 738 | int lst_stack_size; |
| 739 | int gld_stack[FRAME_BUFFERS]; |
| 740 | int gld_stack_size; |
| 741 | } RefBufferStack; |
| 742 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 743 | typedef struct AV1_COMP { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 744 | QUANTS quants; |
| 745 | ThreadData td; |
Yue Chen | cc6a6ef | 2018-05-21 16:21:05 -0700 | [diff] [blame] | 746 | FRAME_COUNTS counts; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 747 | MB_MODE_INFO_EXT *mbmi_ext_base; |
Jingning Han | f5a4d3b | 2017-08-27 23:01:19 -0700 | [diff] [blame] | 748 | CB_COEFF_BUFFER *coeff_buffer_base; |
Yi Luo | c621023 | 2017-05-25 15:09:25 -0700 | [diff] [blame] | 749 | Dequants dequants; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 750 | AV1_COMMON common; |
| 751 | AV1EncoderConfig oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 752 | struct lookahead_ctx *lookahead; |
| 753 | struct lookahead_entry *alt_ref_source; |
Sarah Parker | af32a7b | 2018-06-29 14:59:05 -0700 | [diff] [blame] | 754 | int no_show_kf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 755 | |
Angie Chiang | e69a682 | 2018-03-16 13:52:44 -0700 | [diff] [blame] | 756 | int optimize_seg_arr[MAX_SEGMENTS]; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame^] | 757 | int mi_ext_alloc_size; |
Angie Chiang | e69a682 | 2018-03-16 13:52:44 -0700 | [diff] [blame] | 758 | |
Alex Converse | f77fd0b | 2017-04-20 11:00:24 -0700 | [diff] [blame] | 759 | YV12_BUFFER_CONFIG *source; |
| 760 | 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] | 761 | YV12_BUFFER_CONFIG *unscaled_source; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 762 | YV12_BUFFER_CONFIG scaled_source; |
| 763 | YV12_BUFFER_CONFIG *unscaled_last_source; |
| 764 | YV12_BUFFER_CONFIG scaled_last_source; |
| 765 | |
Yue Chen | b4c93f0 | 2019-08-05 13:47:31 -0700 | [diff] [blame] | 766 | uint8_t tpl_stats_block_mis_log2; // block granularity of tpl score storage |
Jingning Han | 81d6fbb | 2019-07-15 10:14:13 -0700 | [diff] [blame] | 767 | TplDepFrame tpl_stats_buffer[MAX_LENGTH_TPL_FRAME_STATS]; |
| 768 | TplDepFrame *tpl_frame; |
Yue Chen | 7cae98f | 2018-08-24 10:43:16 -0700 | [diff] [blame] | 769 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 770 | // For a still frame, this flag is set to 1 to skip partition search. |
| 771 | int partition_search_skippable_frame; |
Yunqing Wang | c3e21ec | 2019-02-28 16:29:27 -0800 | [diff] [blame] | 772 | |
RogerZhou | 3b63524 | 2017-09-19 10:06:46 -0700 | [diff] [blame] | 773 | double csm_rate_array[32]; |
| 774 | double m_rate_array[32]; |
| 775 | int rate_size; |
| 776 | int rate_index; |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 777 | hash_table *previous_hash_table; |
chiyotsai | fc1404d | 2019-08-08 12:09:12 -0700 | [diff] [blame] | 778 | int need_to_clear_prev_hash_table; |
Debargha Mukherjee | e41a667 | 2018-02-27 11:56:31 -0800 | [diff] [blame] | 779 | int previous_index; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 780 | |
Ravi Chaudhary | 0ec03a4 | 2018-08-17 18:53:28 +0530 | [diff] [blame] | 781 | unsigned int row_mt; |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 782 | RefCntBuffer *scaled_ref_buf[INTER_REFS_PER_FRAME]; |
Urvang Joshi | 4d9f15f | 2018-11-05 15:26:22 -0800 | [diff] [blame] | 783 | |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 784 | RefCntBuffer *last_show_frame_buf; // last show frame buffer |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 785 | |
Urvang Joshi | 06b3765 | 2018-11-06 11:17:56 -0800 | [diff] [blame] | 786 | // refresh_*_frame are boolean flags. If 'refresh_xyz_frame' is true, then |
| 787 | // after the current frame is encoded, the XYZ reference frame gets refreshed |
| 788 | // (updated) to be the current frame. |
| 789 | // |
| 790 | // Special case: 'refresh_last_frame' specifies that: |
| 791 | // - LAST_FRAME reference should be updated to be the current frame (as usual) |
| 792 | // - Also, LAST2_FRAME and LAST3_FRAME references are implicitly updated to be |
| 793 | // the two past reference frames just before LAST_FRAME that are available. |
| 794 | // |
| 795 | // Note: Usually at most one of these refresh flags is true at a time. |
| 796 | // But a key-frame is special, for which all the flags are true at once. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 797 | int refresh_last_frame; |
| 798 | int refresh_golden_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 799 | int refresh_bwd_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 800 | int refresh_alt_ref_frame; |
Urvang Joshi | 06b3765 | 2018-11-06 11:17:56 -0800 | [diff] [blame] | 801 | |
David Turner | 99e990e | 2018-12-10 12:54:26 +0000 | [diff] [blame] | 802 | // For each type of reference frame, this contains the index of a reference |
| 803 | // frame buffer for a reference frame of the same type. We use this to |
| 804 | // choose our primary reference frame (which is the most recent reference |
| 805 | // frame of the same type as the current frame). |
| 806 | int fb_of_context_type[REF_FRAMES]; |
| 807 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 808 | int ext_refresh_frame_flags_pending; |
| 809 | int ext_refresh_last_frame; |
| 810 | int ext_refresh_golden_frame; |
Yunqing Wang | 9a50fec | 2017-11-02 17:02:00 -0700 | [diff] [blame] | 811 | int ext_refresh_bwd_ref_frame; |
| 812 | int ext_refresh_alt2_ref_frame; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 813 | int ext_refresh_alt_ref_frame; |
| 814 | |
| 815 | int ext_refresh_frame_context_pending; |
| 816 | int ext_refresh_frame_context; |
sarahparker | 21dbca4 | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 817 | int ext_use_ref_frame_mvs; |
sarahparker | 27d686a | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 818 | int ext_use_error_resilient; |
sarahparker | 9806fed | 2018-03-30 17:43:44 -0700 | [diff] [blame] | 819 | int ext_use_s_frame; |
Sarah Parker | 50b6d6e | 2018-04-11 19:21:54 -0700 | [diff] [blame] | 820 | int ext_use_primary_ref_none; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 821 | |
| 822 | YV12_BUFFER_CONFIG last_frame_uf; |
Debargha Mukherjee | 999d2f6 | 2016-12-15 13:23:21 -0800 | [diff] [blame] | 823 | YV12_BUFFER_CONFIG trial_frame_rst; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 824 | |
| 825 | // Ambient reconstruction err target for force key frames |
| 826 | int64_t ambient_err; |
| 827 | |
| 828 | RD_OPT rd; |
| 829 | |
| 830 | CODING_CONTEXT coding_context; |
| 831 | |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 832 | int gmtype_cost[TRANS_TYPES]; |
Zoe Liu | 27deb38 | 2018-03-27 15:13:56 -0700 | [diff] [blame] | 833 | int gmparams_cost[REF_FRAMES]; |
Yue Chen | b23d00a | 2017-07-28 17:01:21 -0700 | [diff] [blame] | 834 | |
Jingning Han | f050fc1 | 2018-03-09 14:53:33 -0800 | [diff] [blame] | 835 | int nmv_costs[2][MV_VALS]; |
| 836 | int nmv_costs_hp[2][MV_VALS]; |
James Zern | 01a9d70 | 2017-08-25 19:09:33 +0000 | [diff] [blame] | 837 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 838 | int64_t last_time_stamp_seen; |
| 839 | int64_t last_end_time_stamp_seen; |
| 840 | int64_t first_time_stamp_ever; |
| 841 | |
| 842 | RATE_CONTROL rc; |
| 843 | double framerate; |
| 844 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 845 | struct aom_codec_pkt_list *output_pkt_list; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 846 | |
| 847 | MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS]; |
| 848 | int mbgraph_n_frames; // number of frames filled in the above |
| 849 | int static_mb_pct; // % forced skip mbs by segmentation |
| 850 | int ref_frame_flags; |
Yunqing Wang | f2e7a39 | 2017-11-08 00:27:21 -0800 | [diff] [blame] | 851 | int ext_ref_frame_flags; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 852 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 853 | // speed is passed as a per-frame parameter into the encoder |
| 854 | int speed; |
| 855 | // sf contains fine-grained config set internally based on speed |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 856 | SPEED_FEATURES sf; |
| 857 | |
| 858 | unsigned int max_mv_magnitude; |
| 859 | int mv_step_param; |
| 860 | |
Zoe Liu | 77fb5be | 2017-11-02 14:36:19 -0700 | [diff] [blame] | 861 | int all_one_sided_refs; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 862 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 863 | uint8_t *segmentation_map; |
| 864 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 865 | CYCLIC_REFRESH *cyclic_refresh; |
| 866 | ActiveMap active_map; |
| 867 | |
| 868 | fractional_mv_step_fp *find_fractional_mv_step; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 869 | av1_diamond_search_fn_t diamond_search_sad; |
Rupert Swarbrick | 93c39e9 | 2017-07-12 11:11:02 +0100 | [diff] [blame] | 870 | aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES_ALL]; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 871 | |
| 872 | #if CONFIG_INTERNAL_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 873 | uint64_t time_receive_data; |
| 874 | uint64_t time_compress_data; |
Yunqing Wang | d1f32e6 | 2019-02-20 10:37:51 -0800 | [diff] [blame] | 875 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 876 | |
Debargha Mukherjee | e377839 | 2019-05-06 11:44:23 -0700 | [diff] [blame] | 877 | // number of show frames encoded in current gf_group |
| 878 | int num_gf_group_show_frames; |
| 879 | |
| 880 | // when two pass tpl model is used, set to 1 for the |
| 881 | // first pass, then 0 for the final pass. |
| 882 | int tpl_model_pass; |
Debargha Mukherjee | 347c64d | 2019-05-08 13:53:46 -0700 | [diff] [blame] | 883 | // Number of gf_group frames for tpl stats |
| 884 | int tpl_gf_group_frames; |
Debargha Mukherjee | e377839 | 2019-05-06 11:44:23 -0700 | [diff] [blame] | 885 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 886 | TWO_PASS twopass; |
| 887 | |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 888 | GF_GROUP gf_group; |
| 889 | |
Jingning Han | cf6d325 | 2019-07-03 14:26:45 -0700 | [diff] [blame] | 890 | // To control the reference frame buffer and selection. |
Jingning Han | 42266ca | 2019-07-12 14:37:16 -0700 | [diff] [blame] | 891 | RefBufferStack ref_buffer_stack; |
Jingning Han | cf6d325 | 2019-07-03 14:26:45 -0700 | [diff] [blame] | 892 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 893 | YV12_BUFFER_CONFIG alt_ref_buffer; |
| 894 | |
Cheng Chen | 7abe313 | 2019-06-19 11:55:28 -0700 | [diff] [blame] | 895 | YV12_BUFFER_CONFIG source_kf_buffer; |
| 896 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 897 | #if CONFIG_INTERNAL_STATS |
| 898 | unsigned int mode_chosen_counts[MAX_MODES]; |
| 899 | |
| 900 | int count; |
| 901 | uint64_t total_sq_error; |
| 902 | uint64_t total_samples; |
| 903 | ImageStat psnr; |
| 904 | |
| 905 | double total_blockiness; |
| 906 | double worst_blockiness; |
| 907 | |
| 908 | int bytes; |
| 909 | double summed_quality; |
| 910 | double summed_weights; |
| 911 | unsigned int tot_recode_hits; |
| 912 | double worst_ssim; |
| 913 | |
| 914 | ImageStat fastssim; |
| 915 | ImageStat psnrhvs; |
| 916 | |
| 917 | int b_calculate_blockiness; |
| 918 | int b_calculate_consistency; |
| 919 | |
| 920 | double total_inconsistency; |
| 921 | double worst_consistency; |
| 922 | Ssimv *ssim_vars; |
| 923 | Metrics metrics; |
| 924 | #endif |
| 925 | int b_calculate_psnr; |
Debargha Mukherjee | 0857e66 | 2019-01-04 16:22:09 -0800 | [diff] [blame] | 926 | #if CONFIG_SPEED_STATS |
| 927 | unsigned int tx_search_count; |
| 928 | #endif // CONFIG_SPEED_STATS |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 929 | |
| 930 | int droppable; |
| 931 | |
| 932 | int initial_width; |
| 933 | int initial_height; |
| 934 | int initial_mbs; // Number of MBs in the full-size frame; to be used to |
| 935 | // normalize the firstpass stats. This will differ from the |
| 936 | // number of MBs in the current frame when the frame is |
| 937 | // scaled. |
| 938 | |
Debargha Mukherjee | ccb2726 | 2017-09-25 14:19:46 -0700 | [diff] [blame] | 939 | // When resize is triggered through external control, the desired width/height |
| 940 | // are stored here until use in the next frame coded. They are effective only |
| 941 | // for |
| 942 | // one frame and are reset after use. |
| 943 | int resize_pending_width; |
| 944 | int resize_pending_height; |
| 945 | |
Satish Kumar Suman | 1de4688 | 2019-02-27 17:24:18 +0530 | [diff] [blame] | 946 | // ss_cfg[SS_CFG_LOOKAHEAD] : used in following cases |
| 947 | // -> temporal filtering |
| 948 | // -> intrabc |
| 949 | // ss_cfg[SS_CFG_SRC] : used everywhere except above mentioned cases |
Satish Kumar Suman | e6d0be5 | 2019-02-14 14:33:28 +0530 | [diff] [blame] | 950 | search_site_config ss_cfg[SS_CFG_TOTAL]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 951 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 952 | TileDataEnc *tile_data; |
| 953 | int allocated_tiles; // Keep track of memory allocated for tiles. |
| 954 | |
| 955 | TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS]; |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 956 | TOKENLIST *tplist[MAX_TILE_ROWS][MAX_TILE_COLS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 957 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 958 | int resize_state; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 959 | int resize_avg_qp; |
| 960 | int resize_buffer_underflow; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 961 | |
Debargha Mukherjee | f2e5bb3 | 2018-03-26 14:35:24 -0700 | [diff] [blame] | 962 | // Sequence parameters have been transmitted already and locked |
| 963 | // or not. Once locked av1_change_config cannot change the seq |
| 964 | // parameters. |
| 965 | int seq_params_locked; |
| 966 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 967 | // VARIANCE_AQ segment map refresh |
| 968 | int vaq_refresh; |
| 969 | |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 970 | // VAR_BASED_PARTITION thresholds |
| 971 | // 0 - threshold_128x128; 1 - threshold_64x64; |
| 972 | // 2 - threshold_32x32; 3 - threshold_16x16; |
| 973 | // 4 - vbp_threshold_8x8; |
| 974 | int64_t vbp_thresholds[5]; |
| 975 | int64_t vbp_threshold_minmax; |
| 976 | int64_t vbp_threshold_sad; |
| 977 | int64_t vbp_threshold_copy; |
| 978 | BLOCK_SIZE vbp_bsize_min; |
| 979 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 980 | // Multi-threading |
| 981 | int num_workers; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 982 | AVxWorker *workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 983 | struct EncWorkerData *tile_thr_data; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 984 | int existing_fb_idx_to_show; |
Urvang Joshi | f70375a | 2019-03-22 23:30:19 -0700 | [diff] [blame] | 985 | int is_arf_filter_off[MAX_INTERNAL_ARFS + 1]; |
Debargha Mukherjee | b98a702 | 2016-11-15 16:07:12 -0800 | [diff] [blame] | 986 | int global_motion_search_done; |
Urvang Joshi | f70375a | 2019-03-22 23:30:19 -0700 | [diff] [blame] | 987 | int internal_altref_allowed; |
Hui Su | 8587878 | 2017-11-07 14:56:31 -0800 | [diff] [blame] | 988 | // A flag to indicate if intrabc is ever used in current frame. |
| 989 | int intrabc_used; |
Hui Su | dfcbfbd | 2017-11-13 12:05:30 -0800 | [diff] [blame] | 990 | int dv_cost[2][MV_VALS]; |
| 991 | // TODO(huisu@google.com): we can update dv_joint_cost per SB. |
| 992 | int dv_joint_cost[MV_JOINTS]; |
Hui Su | ad7551e | 2018-03-14 11:13:31 -0700 | [diff] [blame] | 993 | int has_lossless_segment; |
Zoe Liu | 1d90ceb | 2018-04-16 16:53:37 -0700 | [diff] [blame] | 994 | |
Remya | 6924f4a | 2018-11-26 12:27:32 +0530 | [diff] [blame] | 995 | // Factors to control gating of compound type selection based on best |
| 996 | // approximate rd so far |
| 997 | int max_comp_type_rd_threshold_mul; |
| 998 | int max_comp_type_rd_threshold_div; |
| 999 | |
Venkat | b62a64b | 2019-01-03 17:50:40 +0530 | [diff] [blame] | 1000 | unsigned int tx_domain_dist_threshold; |
| 1001 | |
Venkat | 4806765 | 2019-01-09 17:59:53 +0530 | [diff] [blame] | 1002 | // Factor to control R-D optimization of coeffs based on block |
| 1003 | // mse. |
Ranjit Kumar Tulabandu | 824f9db | 2019-07-05 15:16:37 +0530 | [diff] [blame] | 1004 | // Index 0 corresponds to the modes where winner mode processing is not |
| 1005 | // applicable (Eg : IntraBc). Index 1 corresponds to the mode evaluation and |
| 1006 | // is applicable when enable_winner_mode_for_coeff_opt speed feature is ON |
| 1007 | unsigned int coeff_opt_dist_threshold[2]; |
Venkat | 4806765 | 2019-01-09 17:59:53 +0530 | [diff] [blame] | 1008 | |
Deepa K G | 964e72e | 2018-05-16 16:56:01 +0530 | [diff] [blame] | 1009 | AV1LfSync lf_row_sync; |
Ravi Chaudhary | e2aa401 | 2018-06-04 14:20:00 +0530 | [diff] [blame] | 1010 | AV1LrSync lr_row_sync; |
Ravi Chaudhary | ce0f5fc | 2018-05-30 16:19:32 +0530 | [diff] [blame] | 1011 | AV1LrStruct lr_ctxt; |
Neil Birkbeck | a2893ab | 2018-06-08 14:45:13 -0700 | [diff] [blame] | 1012 | |
| 1013 | aom_film_grain_table_t *film_grain_table; |
| 1014 | #if CONFIG_DENOISE |
| 1015 | struct aom_denoise_and_model_t *denoise_and_model; |
| 1016 | #endif |
Ranjit Kumar Tulabandu | 8105bf4 | 2018-07-27 14:16:55 +0530 | [diff] [blame] | 1017 | // Stores the default value of skip flag depending on chroma format |
| 1018 | // Set as 1 for monochrome and 3 for other color formats |
| 1019 | int default_interp_skip_flags; |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1020 | int preserve_arf_as_gld; |
Ravi Chaudhary | c5e7469 | 2018-10-08 16:05:38 +0530 | [diff] [blame] | 1021 | MultiThreadHandle multi_thread_ctxt; |
Ravi Chaudhary | 40cdf13 | 2018-10-08 11:04:16 +0530 | [diff] [blame] | 1022 | void (*row_mt_sync_read_ptr)(AV1RowMTSync *const, int, int); |
| 1023 | void (*row_mt_sync_write_ptr)(AV1RowMTSync *const, int, int, const int); |
Ravi Chaudhary | 90a15f4 | 2018-10-11 18:56:35 +0530 | [diff] [blame] | 1024 | #if CONFIG_MULTITHREAD |
| 1025 | pthread_mutex_t *row_mt_mutex_; |
| 1026 | #endif |
Aniket Dhok | f6d7ed8 | 2019-01-04 14:05:57 +0530 | [diff] [blame] | 1027 | // Set if screen content is set or relevant tools are enabled |
| 1028 | int is_screen_content_type; |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 1029 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 1030 | PartitionStats partition_stats; |
| 1031 | #endif |
Yunqing Wang | ba25558 | 2019-02-11 16:21:12 -0800 | [diff] [blame] | 1032 | |
| 1033 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 1034 | // component_time[] are initialized to zero while encoder starts. |
| 1035 | uint64_t component_time[kTimingComponents]; |
| 1036 | struct aom_usec_timer component_timer[kTimingComponents]; |
| 1037 | // frame_component_time[] are initialized to zero at beginning of each frame. |
| 1038 | uint64_t frame_component_time[kTimingComponents]; |
| 1039 | #endif |
Hui Su | 81a59f1 | 2019-03-26 16:47:52 -0700 | [diff] [blame] | 1040 | |
| 1041 | // The following data are for AV1 bitstream levels. |
Hui Su | 2aa492c | 2019-03-12 15:18:18 -0700 | [diff] [blame] | 1042 | AV1_LEVEL target_seq_level_idx[MAX_NUM_OPERATING_POINTS]; |
Hui Su | 72ff048 | 2019-05-28 14:07:37 -0700 | [diff] [blame] | 1043 | // Bit mask to indicate whether to keep level stats for corresponding |
| 1044 | // operating points. |
| 1045 | uint32_t keep_level_stats; |
Hui Su | c3a8d37 | 2019-05-28 15:52:45 -0700 | [diff] [blame] | 1046 | AV1LevelInfo *level_info[MAX_NUM_OPERATING_POINTS]; |
Hui Su | 4fd1176 | 2019-03-26 16:05:07 -0700 | [diff] [blame] | 1047 | // Count the number of OBU_FRAME and OBU_FRAME_HEADER for level calculation. |
| 1048 | int frame_header_count; |
Debargha Mukherjee | 472df41 | 2019-04-29 15:00:02 -0700 | [diff] [blame] | 1049 | |
| 1050 | // whether any no-zero delta_q was actually used |
Yue Chen | c87d749 | 2019-05-30 17:22:49 -0700 | [diff] [blame] | 1051 | int deltaq_used; |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 1052 | |
Lokeshwar Reddy B | ce8b759 | 2019-07-09 18:19:55 +0530 | [diff] [blame] | 1053 | // Indicates the true relative distance of ref frame w.r.t. current frame |
Lokeshwar Reddy B | 6c2c0f9 | 2019-07-31 10:18:58 +0530 | [diff] [blame] | 1054 | int ref_relative_dist[INTER_REFS_PER_FRAME]; |
Lokeshwar Reddy B | ce8b759 | 2019-07-09 18:19:55 +0530 | [diff] [blame] | 1055 | |
Lokeshwar Reddy B | 895efa7 | 2019-07-29 13:44:36 +0530 | [diff] [blame] | 1056 | // Indicate nearest references w.r.t. current frame in past and future |
| 1057 | int8_t nearest_past_ref; |
| 1058 | int8_t nearest_future_ref; |
| 1059 | |
sdeng | c23c7f1 | 2019-06-11 16:56:50 -0700 | [diff] [blame] | 1060 | double *ssim_rdmult_scaling_factors; |
Marco Paniconi | 6714211 | 2019-07-24 15:00:31 -0700 | [diff] [blame] | 1061 | |
| 1062 | int use_svc; |
| 1063 | SVC svc; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1064 | } AV1_COMP; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1065 | |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 1066 | typedef struct { |
| 1067 | YV12_BUFFER_CONFIG *source; |
| 1068 | YV12_BUFFER_CONFIG *last_source; |
| 1069 | int64_t ts_duration; |
| 1070 | } EncodeFrameInput; |
| 1071 | |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 1072 | // EncodeFrameParams contains per-frame encoding parameters decided upon by |
| 1073 | // av1_encode_strategy() and passed down to av1_encode() |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 1074 | struct EncodeFrameParams { |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 1075 | int error_resilient_mode; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 1076 | FRAME_TYPE frame_type; |
David Turner | a7f133c | 2019-01-22 14:47:16 +0000 | [diff] [blame] | 1077 | int primary_ref_frame; |
| 1078 | int order_offset; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 1079 | int show_frame; |
David Turner | 6e8b4d9 | 2019-02-18 15:01:33 +0000 | [diff] [blame] | 1080 | int refresh_frame_flags; |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 1081 | |
David Turner | e86ee0d | 2019-02-18 17:16:28 +0000 | [diff] [blame] | 1082 | int show_existing_frame; |
| 1083 | int existing_fb_idx_to_show; |
| 1084 | |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 1085 | // Bitmask of which reference buffers may be referenced by this frame |
David Turner | 07dbd8e | 2019-01-08 17:16:25 +0000 | [diff] [blame] | 1086 | int ref_frame_flags; |
| 1087 | |
David Turner | 7324576 | 2019-02-11 16:42:34 +0000 | [diff] [blame] | 1088 | // Reference buffer assignment for this frame. |
| 1089 | int remapped_ref_idx[REF_FRAMES]; |
| 1090 | |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 1091 | // Flags which determine which reference buffers are refreshed by this frame |
| 1092 | int refresh_last_frame; |
| 1093 | int refresh_golden_frame; |
| 1094 | int refresh_bwd_ref_frame; |
David Turner | fe3aecb | 2019-02-06 14:42:42 +0000 | [diff] [blame] | 1095 | int refresh_alt_ref_frame; |
| 1096 | |
David Turner | 04b70d8 | 2019-01-24 15:39:19 +0000 | [diff] [blame] | 1097 | // Speed level to use for this frame: Bigger number means faster. |
| 1098 | int speed; |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 1099 | }; |
| 1100 | typedef struct EncodeFrameParams EncodeFrameParams; |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 1101 | |
| 1102 | // EncodeFrameResults contains information about the result of encoding a |
| 1103 | // single frame |
| 1104 | typedef struct { |
| 1105 | size_t size; // Size of resulting bitstream |
| 1106 | } EncodeFrameResults; |
| 1107 | |
Wan-Teh Chang | 3cac454 | 2018-06-29 10:21:39 -0700 | [diff] [blame] | 1108 | // Must not be called more than once. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1109 | void av1_initialize_enc(void); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1110 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1111 | struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 1112 | BufferPool *const pool); |
| 1113 | void av1_remove_compressor(AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1114 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1115 | void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1116 | |
| 1117 | // receive a frames worth of data. caller can assume that a copy of this |
| 1118 | // frame is made and not just a copy of the pointer.. |
James Zern | 3e2613b | 2017-03-30 23:14:40 -0700 | [diff] [blame] | 1119 | 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] | 1120 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 1121 | int64_t end_time_stamp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1122 | |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1123 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 1124 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 1125 | int64_t *time_end, int flush, |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 1126 | const aom_rational64_t *timebase); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1127 | |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 1128 | int av1_encode(AV1_COMP *const cpi, uint8_t *const dest, |
David Turner | cb5e36f | 2019-01-17 17:15:25 +0000 | [diff] [blame] | 1129 | const EncodeFrameInput *const frame_input, |
David Turner | 056f7cd | 2019-01-07 17:48:13 +0000 | [diff] [blame] | 1130 | const EncodeFrameParams *const frame_params, |
| 1131 | EncodeFrameResults *const frame_results); |
| 1132 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1133 | 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] | 1134 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1135 | 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] | 1136 | |
Yunqing Wang | 93b18f3 | 2018-06-08 21:08:29 -0700 | [diff] [blame] | 1137 | aom_codec_err_t av1_copy_new_frame_enc(AV1_COMMON *cm, |
| 1138 | YV12_BUFFER_CONFIG *new_frame, |
| 1139 | YV12_BUFFER_CONFIG *sd); |
Yunqing Wang | ff9bfca | 2018-06-06 11:46:08 -0700 | [diff] [blame] | 1140 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1141 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1142 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 1143 | 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] | 1144 | |
Thomas Daede | 497d195 | 2017-08-08 17:33:06 -0700 | [diff] [blame] | 1145 | 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] | 1146 | |
David Turner | 475a313 | 2019-01-18 15:17:17 +0000 | [diff] [blame] | 1147 | void av1_set_frame_size(AV1_COMP *cpi, int width, int height); |
| 1148 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1149 | int av1_update_entropy(AV1_COMP *cpi, int update); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1150 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1151 | 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] | 1152 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1153 | 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] | 1154 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1155 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 1156 | AOM_SCALING vert_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1157 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1158 | int av1_get_quantizer(struct AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1159 | |
Soo-Chul Han | 29c46fb | 2018-03-23 16:02:00 -0400 | [diff] [blame] | 1160 | int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *input_size); |
| 1161 | |
Hui Su | 38711e7 | 2019-06-11 10:49:47 -0700 | [diff] [blame] | 1162 | void av1_alloc_compound_type_rd_buffers(AV1_COMMON *const cm, |
| 1163 | CompoundTypeRdBuffers *const bufs); |
| 1164 | void av1_release_compound_type_rd_buffers(CompoundTypeRdBuffers *const bufs); |
| 1165 | |
Jingning Han | cf6d325 | 2019-07-03 14:26:45 -0700 | [diff] [blame] | 1166 | // TODO(jingning): Move these functions as primitive members for the new cpi |
| 1167 | // class. |
| 1168 | static INLINE void stack_push(int *stack, int *stack_size, int item) { |
Jingning Han | 0a2af4e | 2019-07-08 19:30:03 -0700 | [diff] [blame] | 1169 | for (int i = *stack_size - 1; i >= 0; --i) stack[i + 1] = stack[i]; |
Jingning Han | cf6d325 | 2019-07-03 14:26:45 -0700 | [diff] [blame] | 1170 | stack[0] = item; |
| 1171 | ++*stack_size; |
| 1172 | } |
| 1173 | |
| 1174 | static INLINE int stack_pop(int *stack, int *stack_size) { |
Jingning Han | f58175c | 2019-07-07 15:02:00 -0700 | [diff] [blame] | 1175 | if (*stack_size <= 0) return -1; |
| 1176 | |
Jingning Han | cf6d325 | 2019-07-03 14:26:45 -0700 | [diff] [blame] | 1177 | int item = stack[0]; |
| 1178 | for (int i = 0; i < *stack_size; ++i) stack[i] = stack[i + 1]; |
| 1179 | --*stack_size; |
| 1180 | |
| 1181 | return item; |
| 1182 | } |
| 1183 | |
| 1184 | static INLINE int stack_pop_end(int *stack, int *stack_size) { |
| 1185 | int item = stack[*stack_size - 1]; |
| 1186 | stack[*stack_size - 1] = -1; |
| 1187 | --*stack_size; |
| 1188 | |
| 1189 | return item; |
| 1190 | } |
| 1191 | |
| 1192 | static INLINE void stack_reset(int *stack, int *stack_size) { |
| 1193 | for (int i = 0; i < *stack_size; ++i) stack[i] = INVALID_IDX; |
| 1194 | *stack_size = 0; |
| 1195 | } |
| 1196 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 1197 | // av1 uses 10,000,000 ticks/second as time stamp |
| 1198 | #define TICKS_PER_SEC 10000000LL |
| 1199 | |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 1200 | static INLINE int64_t |
| 1201 | timebase_units_to_ticks(const aom_rational64_t *timestamp_ratio, int64_t n) { |
| 1202 | return n * timestamp_ratio->num / timestamp_ratio->den; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Yue Chen | 1bc5be6 | 2018-08-24 13:57:32 -0700 | [diff] [blame] | 1205 | static INLINE int64_t |
| 1206 | ticks_to_timebase_units(const aom_rational64_t *timestamp_ratio, int64_t n) { |
| 1207 | int64_t round = timestamp_ratio->num / 2; |
| 1208 | if (round > 0) --round; |
| 1209 | return (n * timestamp_ratio->den + round) / timestamp_ratio->num; |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 1210 | } |
Andrey Norkin | 795ba87 | 2018-03-06 13:24:14 -0800 | [diff] [blame] | 1211 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1212 | static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) { |
Jingning Han | 52af439 | 2019-08-13 11:44:40 -0700 | [diff] [blame] | 1213 | const GF_GROUP *const gf_group = &cpi->gf_group; |
| 1214 | const FRAME_UPDATE_TYPE update_type = gf_group->update_type[gf_group->index]; |
| 1215 | |
| 1216 | return frame_is_intra_only(&cpi->common) || update_type == ARF_UPDATE || |
| 1217 | update_type == GF_UPDATE; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 1220 | // TODO(huisu@google.com, youzhou@microsoft.com): enable hash-me for HBD. |
| 1221 | static INLINE int av1_use_hash_me(const AV1_COMMON *const cm) { |
Debargha Mukherjee | 8112d2f | 2018-03-01 09:53:11 -0800 | [diff] [blame] | 1222 | return cm->allow_screen_content_tools; |
Hui Su | 2d5fd74 | 2018-02-21 18:10:37 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | static INLINE hash_table *av1_get_ref_frame_hash_map( |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 1226 | const AV1_COMMON *cm, MV_REFERENCE_FRAME ref_frame) { |
| 1227 | const int map_idx = get_ref_frame_map_idx(cm, ref_frame); |
| 1228 | RefCntBuffer *buf = |
| 1229 | (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : NULL; |
| 1230 | return buf ? &buf->hash_table : NULL; |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 1231 | } |
RogerZhou | cc5d35d | 2017-08-07 22:20:15 -0700 | [diff] [blame] | 1232 | |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 1233 | static INLINE const YV12_BUFFER_CONFIG *get_ref_frame_yv12_buf( |
| 1234 | const AV1_COMMON *const cm, MV_REFERENCE_FRAME ref_frame) { |
| 1235 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 1236 | return buf != NULL ? &buf->buf : NULL; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 1239 | static INLINE int enc_is_ref_frame_buf(const AV1_COMMON *const cm, |
| 1240 | const RefCntBuffer *const frame_buf) { |
Urvang Joshi | 4058217 | 2018-11-07 11:53:03 -0800 | [diff] [blame] | 1241 | MV_REFERENCE_FRAME ref_frame; |
| 1242 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 1243 | const RefCntBuffer *const buf = get_ref_frame_buf(cm, ref_frame); |
David Turner | e7ebf90 | 2018-12-04 14:04:55 +0000 | [diff] [blame] | 1244 | if (buf == NULL) continue; |
| 1245 | if (frame_buf == buf) break; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1246 | } |
Urvang Joshi | 4058217 | 2018-11-07 11:53:03 -0800 | [diff] [blame] | 1247 | return (ref_frame <= ALTREF_FRAME); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1248 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1249 | |
David Turner | e3e520d | 2019-01-18 14:38:08 +0000 | [diff] [blame] | 1250 | static INLINE void alloc_frame_mvs(AV1_COMMON *const cm, RefCntBuffer *buf) { |
| 1251 | assert(buf != NULL); |
| 1252 | ensure_mv_buffer(buf, cm); |
| 1253 | buf->width = cm->width; |
| 1254 | buf->height = cm->height; |
| 1255 | } |
| 1256 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 1257 | // Token buffer is only used for palette tokens. |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 1258 | 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] | 1259 | int sb_size_log2, |
| 1260 | const int num_planes) { |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 1261 | // Calculate the maximum number of max superblocks in the image. |
Yaowu Xu | e39b3b8 | 2017-10-31 16:11:59 -0700 | [diff] [blame] | 1262 | const int shift = sb_size_log2 - 4; |
| 1263 | const int sb_size = 1 << sb_size_log2; |
| 1264 | const int sb_size_square = sb_size * sb_size; |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 1265 | const int sb_rows = ALIGN_POWER_OF_TWO(mb_rows, shift) >> shift; |
| 1266 | const int sb_cols = ALIGN_POWER_OF_TWO(mb_cols, shift) >> shift; |
| 1267 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 1268 | // One palette token for each pixel. There can be palettes on two planes. |
| 1269 | const int sb_palette_toks = AOMMIN(2, num_planes) * sb_size_square; |
Rupert Swarbrick | ce63e83 | 2017-10-25 17:54:17 +0100 | [diff] [blame] | 1270 | |
Hui Su | 8ac0c98 | 2018-04-03 12:17:36 -0700 | [diff] [blame] | 1271 | return sb_rows * sb_cols * sb_palette_toks; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1272 | } |
| 1273 | |
| 1274 | // Get the allocated token size for a tile. It does the same calculation as in |
| 1275 | // the frame token allocation. |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 1276 | static INLINE unsigned int allocated_tokens(TileInfo tile, int sb_size_log2, |
| 1277 | int num_planes) { |
Jingning Han | eafbd5f | 2017-03-07 11:18:17 -0800 | [diff] [blame] | 1278 | int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 2) >> 2; |
| 1279 | 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] | 1280 | |
Rupert Swarbrick | dcb3cff | 2017-11-09 15:58:33 +0000 | [diff] [blame] | 1281 | 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] | 1282 | } |
| 1283 | |
Ravi Chaudhary | 73cf15b | 2018-08-30 10:52:51 +0530 | [diff] [blame] | 1284 | static INLINE void get_start_tok(AV1_COMP *cpi, int tile_row, int tile_col, |
| 1285 | int mi_row, TOKENEXTRA **tok, int sb_size_log2, |
| 1286 | int num_planes) { |
| 1287 | AV1_COMMON *const cm = &cpi->common; |
| 1288 | const int tile_cols = cm->tile_cols; |
| 1289 | TileDataEnc *this_tile = &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 1290 | const TileInfo *const tile_info = &this_tile->tile_info; |
| 1291 | |
| 1292 | const int tile_mb_cols = |
| 1293 | (tile_info->mi_col_end - tile_info->mi_col_start + 2) >> 2; |
| 1294 | const int tile_mb_row = (mi_row - tile_info->mi_row_start + 2) >> 2; |
| 1295 | |
| 1296 | *tok = cpi->tile_tok[tile_row][tile_col] + |
| 1297 | get_token_alloc(tile_mb_row, tile_mb_cols, sb_size_log2, num_planes); |
| 1298 | } |
| 1299 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1300 | 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] | 1301 | |
Yaowu Xu | 6da4230 | 2017-10-10 14:45:06 -0700 | [diff] [blame] | 1302 | #define ALT_MIN_LAG 3 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1303 | static INLINE int is_altref_enabled(const AV1_COMP *const cpi) { |
Yaowu Xu | 6da4230 | 2017-10-10 14:45:06 -0700 | [diff] [blame] | 1304 | 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] | 1305 | } |
| 1306 | |
| 1307 | // TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1308 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 1309 | static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1310 | MV_REFERENCE_FRAME ref0, |
| 1311 | MV_REFERENCE_FRAME ref1) { |
David Turner | a21966b | 2018-12-05 14:48:49 +0000 | [diff] [blame] | 1312 | xd->block_ref_scale_factors[0] = |
| 1313 | get_ref_scale_factors_const(cm, ref0 >= LAST_FRAME ? ref0 : 1); |
| 1314 | xd->block_ref_scale_factors[1] = |
| 1315 | get_ref_scale_factors_const(cm, ref1 >= LAST_FRAME ? ref1 : 1); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Yaowu Xu | 4ff59b5 | 2017-04-24 12:41:56 -0700 | [diff] [blame] | 1318 | static INLINE int get_chessboard_index(int frame_index) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1319 | return frame_index & 0x1; |
| 1320 | } |
| 1321 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1322 | 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] | 1323 | return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL; |
| 1324 | } |
| 1325 | |
Hui Su | ef139e1 | 2019-05-20 15:51:22 -0700 | [diff] [blame] | 1326 | // Compression ratio of current frame. |
| 1327 | double av1_get_compression_ratio(const AV1_COMMON *const cm, |
| 1328 | size_t encoded_frame_size); |
| 1329 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 1330 | void av1_new_framerate(AV1_COMP *cpi, double framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1331 | |
David Turner | dedd8ff | 2019-01-23 13:59:46 +0000 | [diff] [blame] | 1332 | void av1_setup_frame_size(AV1_COMP *cpi); |
| 1333 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1334 | #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl)) |
| 1335 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 1336 | // Returns 1 if a frame is scaled and 0 otherwise. |
| 1337 | static INLINE int av1_resize_scaled(const AV1_COMMON *cm) { |
| 1338 | return !(cm->superres_upscaled_width == cm->render_width && |
| 1339 | cm->superres_upscaled_height == cm->render_height); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 1340 | } |
| 1341 | |
Cheng Chen | 09c83a5 | 2018-06-05 12:27:36 -0700 | [diff] [blame] | 1342 | static INLINE int av1_frame_scaled(const AV1_COMMON *cm) { |
| 1343 | return !av1_superres_scaled(cm) && av1_resize_scaled(cm); |
Fergus Simpson | fecb2ab | 2017-04-30 15:49:57 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 1346 | // Don't allow a show_existing_frame to coincide with an error resilient |
| 1347 | // frame. An exception can be made for a forward keyframe since it has no |
| 1348 | // previous dependencies. |
| 1349 | static INLINE int encode_show_existing_frame(const AV1_COMMON *cm) { |
David Turner | d2a592e | 2018-11-16 14:59:31 +0000 | [diff] [blame] | 1350 | return cm->show_existing_frame && (!cm->error_resilient_mode || |
| 1351 | cm->current_frame.frame_type == KEY_FRAME); |
Sarah Parker | 3300552 | 2018-07-27 14:46:25 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 1354 | // Lighter version of set_offsets that only sets the mode info |
| 1355 | // pointers. |
| 1356 | static INLINE void set_mode_info_offsets(const AV1_COMP *const cpi, |
| 1357 | MACROBLOCK *const x, |
| 1358 | MACROBLOCKD *const xd, int mi_row, |
| 1359 | int mi_col) { |
| 1360 | const AV1_COMMON *const cm = &cpi->common; |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame^] | 1361 | const int grid_idx = get_mi_grid_idx(cm, mi_row, mi_col); |
| 1362 | const int mi_idx = get_alloc_mi_idx(cm, mi_row, mi_col); |
| 1363 | const int ext_idx = get_mi_ext_idx(cm, mi_row, mi_col); |
chiyotsai | 426c066 | 2019-08-05 16:15:11 -0700 | [diff] [blame] | 1364 | |
chiyotsai | a7091f1 | 2019-08-09 16:48:27 -0700 | [diff] [blame^] | 1365 | xd->mi = cm->mi_grid_base + grid_idx; |
| 1366 | xd->mi[0] = cm->mi + mi_idx; |
| 1367 | |
| 1368 | x->mbmi_ext = cpi->mbmi_ext_base + ext_idx; |
kyslov | 7b9d0d6 | 2018-12-21 11:12:26 -0800 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | // Check to see if the given partition size is allowed for a specified number |
| 1372 | // of mi block rows and columns remaining in the image. |
| 1373 | // If not then return the largest allowed partition size |
| 1374 | static INLINE BLOCK_SIZE find_partition_size(BLOCK_SIZE bsize, int rows_left, |
| 1375 | int cols_left, int *bh, int *bw) { |
| 1376 | int int_size = (int)bsize; |
| 1377 | if (rows_left <= 0 || cols_left <= 0) { |
| 1378 | return AOMMIN(bsize, BLOCK_8X8); |
| 1379 | } else { |
| 1380 | for (; int_size > 0; int_size -= 3) { |
| 1381 | *bh = mi_size_high[int_size]; |
| 1382 | *bw = mi_size_wide[int_size]; |
| 1383 | if ((*bh <= rows_left) && (*bw <= cols_left)) { |
| 1384 | break; |
| 1385 | } |
| 1386 | } |
| 1387 | } |
| 1388 | return (BLOCK_SIZE)int_size; |
| 1389 | } |
| 1390 | |
chiyotsai | dd132d2 | 2019-03-11 14:22:49 -0700 | [diff] [blame] | 1391 | static const uint8_t av1_ref_frame_flag_list[REF_FRAMES] = { 0, |
| 1392 | AOM_LAST_FLAG, |
| 1393 | AOM_LAST2_FLAG, |
| 1394 | AOM_LAST3_FLAG, |
| 1395 | AOM_GOLD_FLAG, |
| 1396 | AOM_BWD_FLAG, |
| 1397 | AOM_ALT2_FLAG, |
| 1398 | AOM_ALT_FLAG }; |
| 1399 | |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1400 | // Returns a Sequence Header OBU stored in an aom_fixed_buf_t, or NULL upon |
| 1401 | // failure. When a non-NULL aom_fixed_buf_t pointer is returned by this |
| 1402 | // function, the memory must be freed by the caller. Both the buf member of the |
Tom Finegan | ca1e28f | 2018-08-28 16:55:35 -0700 | [diff] [blame] | 1403 | // aom_fixed_buf_t, and the aom_fixed_buf_t pointer itself must be freed. Memory |
| 1404 | // returned must be freed via call to free(). |
| 1405 | // |
| 1406 | // Note: The OBU returned is in Low Overhead Bitstream Format. Specifically, |
| 1407 | // the obu_has_size_field bit is set, and the buffer contains the obu_size |
| 1408 | // field. |
Tom Finegan | f8d6a16 | 2018-08-21 10:47:55 -0700 | [diff] [blame] | 1409 | aom_fixed_buf_t *av1_get_global_headers(AV1_COMP *cpi); |
| 1410 | |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 1411 | #define ENABLE_KF_TPL 1 |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 1412 | #define MAX_PYR_LEVEL_FROMTOP_DELTAQ 0 |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 1413 | |
| 1414 | static INLINE int is_frame_kf_and_tpl_eligible(AV1_COMP *const cpi) { |
| 1415 | AV1_COMMON *cm = &cpi->common; |
| 1416 | if (cm->current_frame.frame_type == KEY_FRAME && cm->show_frame) |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 1417 | return 1; |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 1418 | else |
| 1419 | return 0; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | static INLINE int is_frame_arf_and_tpl_eligible(AV1_COMP *const cpi) { |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 1423 | GF_GROUP *const gf_group = &cpi->gf_group; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 1424 | const int max_pyr_level_fromtop_deltaq = 0; |
| 1425 | const int pyr_lev_from_top = |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 1426 | gf_group->pyramid_height - gf_group->pyramid_level[cpi->gf_group.index]; |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 1427 | if (pyr_lev_from_top > max_pyr_level_fromtop_deltaq || |
Sarah Parker | e1b2201 | 2019-06-06 16:35:25 -0700 | [diff] [blame] | 1428 | gf_group->pyramid_height <= max_pyr_level_fromtop_deltaq + 1) |
Debargha Mukherjee | d0c0b77 | 2019-05-27 23:05:06 -0700 | [diff] [blame] | 1429 | return 0; |
| 1430 | else |
| 1431 | return 1; |
| 1432 | } |
| 1433 | |
Yue Chen | 4e585cc | 2019-06-03 14:47:16 -0700 | [diff] [blame] | 1434 | static INLINE int is_frame_tpl_eligible(AV1_COMP *const cpi) { |
| 1435 | #if ENABLE_KF_TPL |
| 1436 | return is_frame_kf_and_tpl_eligible(cpi) || |
| 1437 | is_frame_arf_and_tpl_eligible(cpi); |
| 1438 | #else |
| 1439 | return is_frame_arf_and_tpl_eligible(cpi); |
| 1440 | #endif // ENABLE_KF_TPL |
| 1441 | } |
| 1442 | |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 1443 | #if CONFIG_COLLECT_PARTITION_STATS == 2 |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 1444 | static INLINE void av1_print_partition_stats(PartitionStats *part_stats) { |
| 1445 | FILE *f = fopen("partition_stats.csv", "w"); |
| 1446 | if (!f) { |
| 1447 | return; |
| 1448 | } |
| 1449 | |
| 1450 | fprintf(f, "bsize,redo,"); |
| 1451 | for (int part = 0; part < EXT_PARTITION_TYPES; part++) { |
| 1452 | fprintf(f, "decision_%d,", part); |
| 1453 | } |
| 1454 | for (int part = 0; part < EXT_PARTITION_TYPES; part++) { |
| 1455 | fprintf(f, "attempt_%d,", part); |
| 1456 | } |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 1457 | for (int part = 0; part < EXT_PARTITION_TYPES; part++) { |
| 1458 | fprintf(f, "time_%d,", part); |
| 1459 | } |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 1460 | fprintf(f, "\n"); |
| 1461 | |
| 1462 | const int bsizes[6] = { 128, 64, 32, 16, 8, 4 }; |
| 1463 | |
| 1464 | for (int bsize_idx = 0; bsize_idx < 6; bsize_idx++) { |
| 1465 | fprintf(f, "%d,%d,", bsizes[bsize_idx], part_stats->partition_redo); |
| 1466 | for (int part = 0; part < EXT_PARTITION_TYPES; part++) { |
| 1467 | fprintf(f, "%d,", part_stats->partition_decisions[bsize_idx][part]); |
| 1468 | } |
| 1469 | for (int part = 0; part < EXT_PARTITION_TYPES; part++) { |
| 1470 | fprintf(f, "%d,", part_stats->partition_attempts[bsize_idx][part]); |
| 1471 | } |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 1472 | for (int part = 0; part < EXT_PARTITION_TYPES; part++) { |
| 1473 | fprintf(f, "%ld,", part_stats->partition_times[bsize_idx][part]); |
| 1474 | } |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 1475 | fprintf(f, "\n"); |
| 1476 | } |
| 1477 | fclose(f); |
| 1478 | } |
| 1479 | |
| 1480 | static INLINE int av1_get_bsize_idx_for_part_stats(BLOCK_SIZE bsize) { |
| 1481 | assert(bsize == BLOCK_128X128 || bsize == BLOCK_64X64 || |
chiyotsai | 9c484b3 | 2019-03-07 16:01:50 -0800 | [diff] [blame] | 1482 | bsize == BLOCK_32X32 || bsize == BLOCK_16X16 || bsize == BLOCK_8X8 || |
| 1483 | bsize == BLOCK_4X4); |
chiyotsai | 92ed0dd | 2019-01-25 14:50:14 -0800 | [diff] [blame] | 1484 | switch (bsize) { |
| 1485 | case BLOCK_128X128: return 0; |
| 1486 | case BLOCK_64X64: return 1; |
| 1487 | case BLOCK_32X32: return 2; |
| 1488 | case BLOCK_16X16: return 3; |
| 1489 | case BLOCK_8X8: return 4; |
| 1490 | case BLOCK_4X4: return 5; |
| 1491 | default: assert(0 && "Invalid bsize for partition_stats."); return -1; |
| 1492 | } |
| 1493 | } |
| 1494 | #endif |
| 1495 | |
Yunqing Wang | ba25558 | 2019-02-11 16:21:12 -0800 | [diff] [blame] | 1496 | #if CONFIG_COLLECT_COMPONENT_TIMING |
| 1497 | static INLINE void start_timing(AV1_COMP *cpi, int component) { |
| 1498 | aom_usec_timer_start(&cpi->component_timer[component]); |
| 1499 | } |
| 1500 | static INLINE void end_timing(AV1_COMP *cpi, int component) { |
| 1501 | aom_usec_timer_mark(&cpi->component_timer[component]); |
| 1502 | cpi->frame_component_time[component] += |
| 1503 | aom_usec_timer_elapsed(&cpi->component_timer[component]); |
| 1504 | } |
| 1505 | static INLINE char const *get_frame_type_enum(int type) { |
| 1506 | switch (type) { |
| 1507 | case 0: return "KEY_FRAME"; |
| 1508 | case 1: return "INTER_FRAME"; |
| 1509 | case 2: return "INTRA_ONLY_FRAME"; |
| 1510 | case 3: return "S_FRAME"; |
| 1511 | default: assert(0); |
| 1512 | } |
| 1513 | return "error"; |
| 1514 | } |
| 1515 | #endif |
| 1516 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1517 | #ifdef __cplusplus |
| 1518 | } // extern "C" |
| 1519 | #endif |
| 1520 | |
James Zern | e1cbb13 | 2018-08-22 14:10:36 -0700 | [diff] [blame] | 1521 | #endif // AOM_AV1_ENCODER_ENCODER_H_ |