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