blob: dc9610d642a15da992904044cb1e268327d5240d [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Urvang Joshi8a02d762016-07-28 15:51:12 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Urvang Joshi8a02d762016-07-28 15:51:12 -07004 * 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 Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_ENCODER_ENCODER_H_
13#define AV1_ENCODER_ENCODER_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include <stdio.h>
16
Yaowu Xuf883b422016-08-30 14:01:10 -070017#include "./aom_config.h"
18#include "aom/aomcx.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070019
20#include "av1/common/alloccommon.h"
21#include "av1/common/entropymode.h"
22#include "av1/common/thread_common.h"
23#include "av1/common/onyxc_int.h"
Fergus Simpsond2bcbb52017-05-22 23:15:05 -070024#include "av1/common/resize.h"
Andrey Norkin795ba872018-03-06 13:24:14 -080025#if CONFIG_BUFFER_MODEL
26#include "av1/common/timing.h"
27#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070028#include "av1/encoder/aq_cyclicrefresh.h"
Tom Finegan17ce8b12017-02-08 12:46:31 -080029#include "av1/encoder/av1_quantize.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070030#include "av1/encoder/context_tree.h"
31#include "av1/encoder/encodemb.h"
32#include "av1/encoder/firstpass.h"
33#include "av1/encoder/lookahead.h"
34#include "av1/encoder/mbgraph.h"
35#include "av1/encoder/mcomp.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070036#include "av1/encoder/ratectrl.h"
37#include "av1/encoder/rd.h"
38#include "av1/encoder/speed_features.h"
39#include "av1/encoder/tokenize.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070040
41#if CONFIG_INTERNAL_STATS
42#include "aom_dsp/ssim.h"
43#endif
44#include "aom_dsp/variance.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070045#include "aom/internal/aom_codec_internal.h"
46#include "aom_util/aom_thread.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070047
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52typedef struct {
Jingning Hanf050fc12018-03-09 14:53:33 -080053 int nmv_vec_cost[MV_JOINTS];
54 int nmv_costs[2][MV_VALS];
55 int nmv_costs_hp[2][MV_VALS];
James Zern01a9d702017-08-25 19:09:33 +000056
Yaowu Xuc27fc142016-08-22 16:08:15 -070057 FRAME_CONTEXT fc;
58} CODING_CONTEXT;
59
60typedef enum {
61 // regular inter frame
62 REGULAR_FRAME = 0,
63 // alternate reference frame
64 ARF_FRAME = 1,
65 // overlay frame
66 OVERLAY_FRAME = 2,
67 // golden frame
68 GLD_FRAME = 3,
Yaowu Xuc27fc142016-08-22 16:08:15 -070069 // backward reference frame
70 BRF_FRAME = 4,
71 // extra alternate reference frame
Thomas Daede51020e12017-12-14 20:12:44 -080072 EXT_ARF_FRAME = 5,
73 FRAME_CONTEXT_INDEXES
Yaowu Xuc27fc142016-08-22 16:08:15 -070074} FRAME_CONTEXT_INDEX;
75
76typedef enum {
Yaowu Xuc27fc142016-08-22 16:08:15 -070077 NORMAL = 0,
78 FOURFIVE = 1,
79 THREEFIVE = 2,
80 ONETWO = 3
Yaowu Xuf883b422016-08-30 14:01:10 -070081} AOM_SCALING;
Yaowu Xuc27fc142016-08-22 16:08:15 -070082
83typedef enum {
84 // Good Quality Fast Encoding. The encoder balances quality with the amount of
85 // time it takes to encode the output. Speed setting controls how fast.
Thomas Daede80826142017-03-20 15:44:24 -070086 GOOD
Yaowu Xuc27fc142016-08-22 16:08:15 -070087} MODE;
88
89typedef enum {
90 FRAMEFLAGS_KEY = 1 << 0,
91 FRAMEFLAGS_GOLDEN = 1 << 1,
Yaowu Xuc27fc142016-08-22 16:08:15 -070092 FRAMEFLAGS_BWDREF = 1 << 2,
Zoe Liu3ac20932017-08-30 16:35:55 -070093 // TODO(zoeliu): To determine whether a frame flag is needed for ALTREF2_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -070094 FRAMEFLAGS_ALTREF = 1 << 3,
Yaowu Xuc27fc142016-08-22 16:08:15 -070095} FRAMETYPE_FLAGS;
96
97typedef enum {
98 NO_AQ = 0,
99 VARIANCE_AQ = 1,
100 COMPLEXITY_AQ = 2,
101 CYCLIC_REFRESH_AQ = 3,
102 AQ_MODE_COUNT // This should always be the last member of the enum
103} AQ_MODE;
Fangwen Fu6160df22017-04-24 09:45:51 -0700104typedef enum {
105 NO_DELTA_Q = 0,
106 DELTA_Q_ONLY = 1,
107 DELTA_Q_LF = 2,
108 DELTAQ_MODE_COUNT // This should always be the last member of the enum
109} DELTAQ_MODE;
Debargha Mukherjee3a4959f2018-02-26 15:34:03 -0800110
Yaowu Xuc27fc142016-08-22 16:08:15 -0700111typedef enum {
112 RESIZE_NONE = 0, // No frame resizing allowed.
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700113 RESIZE_FIXED = 1, // All frames are coded at the specified scale.
114 RESIZE_RANDOM = 2, // All frames are coded at a random scale.
115 RESIZE_MODES
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700116} RESIZE_MODE;
Debargha Mukherjee3a4959f2018-02-26 15:34:03 -0800117
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700118typedef enum {
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700119 SUPERRES_NONE = 0, // No frame superres allowed
120 SUPERRES_FIXED = 1, // All frames are coded at the specified scale,
121 // and super-resolved.
122 SUPERRES_RANDOM = 2, // All frames are coded at a random scale,
123 // and super-resolved.
124 SUPERRES_QTHRESH = 3, // Superres scale for a frame is determined based on
125 // q_index
126 SUPERRES_MODES
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700127} SUPERRES_MODE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700128
Yaowu Xuf883b422016-08-30 14:01:10 -0700129typedef struct AV1EncoderConfig {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700130 BITSTREAM_PROFILE profile;
Tom Finegan8ab2bba2018-02-28 07:36:28 -0800131 aom_bit_depth_t bit_depth; // Codec bit-depth.
132 int width; // width of data passed to the compressor
133 int height; // height of data passed to the compressor
134 int forced_max_frame_width; // forced maximum width of frame (if != 0)
135 int forced_max_frame_height; // forced maximum height of frame (if != 0)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700136 unsigned int input_bit_depth; // Input bit depth.
137 double init_framerate; // set to passed in framerate
138 int64_t target_bandwidth; // bandwidth to be used in bits per second
139
140 int noise_sensitivity; // pre processing blur: recommendation 0
141 int sharpness; // sharpening output: recommendation 0:
142 int speed;
Jingning Hanb49c6ae2017-11-27 18:14:05 -0800143 int dev_sf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700144 // maximum allowed bitrate for any intra frame in % of bitrate target.
145 unsigned int rc_max_intra_bitrate_pct;
146 // maximum allowed bitrate for any inter frame in % of bitrate target.
147 unsigned int rc_max_inter_bitrate_pct;
148 // percent of rate boost for golden frame in CBR mode.
149 unsigned int gf_cbr_boost_pct;
150
151 MODE mode;
152 int pass;
153
154 // Key Framing Operations
155 int auto_key; // autodetect cut scenes and set the keyframes
156 int key_freq; // maximum distance to key frame.
Tarek AMARAc9813852018-03-05 18:40:18 -0500157 int sframe_dist;
158 int sframe_mode;
159 int sframe_enabled;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700160 int lag_in_frames; // how many frames lag before we start encoding
161
162 // ----------------------------------------------------------------
163 // DATARATE CONTROL OPTIONS
164
165 // vbr, cbr, constrained quality or constant quality
Yaowu Xuf883b422016-08-30 14:01:10 -0700166 enum aom_rc_mode rc_mode;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700167
168 // buffer targeting aggressiveness
169 int under_shoot_pct;
170 int over_shoot_pct;
171
172 // buffering parameters
173 int64_t starting_buffer_level_ms;
174 int64_t optimal_buffer_level_ms;
175 int64_t maximum_buffer_size_ms;
176
177 // Frame drop threshold.
178 int drop_frames_water_mark;
179
180 // controlling quality
181 int fixed_q;
182 int worst_allowed_q;
183 int best_allowed_q;
184 int cq_level;
185 AQ_MODE aq_mode; // Adaptive Quantization mode
Fangwen Fu6160df22017-04-24 09:45:51 -0700186 DELTAQ_MODE deltaq_mode;
Debargha Mukherjee98a311c2018-03-25 16:33:11 -0700187 int enable_cdef;
188 int enable_restoration;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700189 int using_qm;
Yaowu Xuf7a12422018-01-31 15:29:20 -0800190 int qm_y;
191 int qm_u;
192 int qm_v;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700193 int qm_minlevel;
194 int qm_maxlevel;
Yushin Chod808bfc2017-08-10 15:54:36 -0700195#if CONFIG_DIST_8X8
196 int using_dist_8x8;
197#endif
Thomas Daviesaf6df172016-11-09 14:04:18 +0000198 unsigned int num_tile_groups;
199 unsigned int mtu;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700200
201 // Internal frame size scaling.
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700202 RESIZE_MODE resize_mode;
Urvang Joshide71d142017-10-05 12:12:15 -0700203 uint8_t resize_scale_denominator;
204 uint8_t resize_kf_scale_denominator;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700205
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700206 // Frame Super-Resolution size scaling.
207 SUPERRES_MODE superres_mode;
Urvang Joshide71d142017-10-05 12:12:15 -0700208 uint8_t superres_scale_denominator;
209 uint8_t superres_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700210 int superres_qthresh;
211 int superres_kf_qthresh;
Fergus Simpson3502d082017-04-10 12:25:07 -0700212
Yaowu Xuc27fc142016-08-22 16:08:15 -0700213 // Enable feature to reduce the frame quantization every x frames.
214 int frame_periodic_boost;
215
216 // two pass datarate control
217 int two_pass_vbrbias; // two pass datarate control tweaks
218 int two_pass_vbrmin_section;
219 int two_pass_vbrmax_section;
220 // END DATARATE CONTROL OPTIONS
221 // ----------------------------------------------------------------
222
223 int enable_auto_arf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700224 int enable_auto_brf; // (b)ackward (r)ef (f)rame
Yaowu Xuc27fc142016-08-22 16:08:15 -0700225
Yaowu Xuc27fc142016-08-22 16:08:15 -0700226 /* Bitfield defining the error resiliency features to enable.
227 * Can provide decodable frames after losses in previous
228 * frames and decodable partitions after losses in the same frame.
229 */
230 unsigned int error_resilient_mode;
231
Debargha Mukherjee52fb0472018-03-29 15:48:11 -0700232 unsigned int s_frame_mode;
233
Yaowu Xuc27fc142016-08-22 16:08:15 -0700234 /* Bitfield defining the parallel decoding mode where the
235 * decoding in successive frames may be conducted in parallel
236 * just by decoding the frame headers.
237 */
238 unsigned int frame_parallel_decoding_mode;
239
Debargha Mukherjeec6f24c22018-04-07 08:43:08 -0700240 unsigned int limit;
241
Yaowu Xuc27fc142016-08-22 16:08:15 -0700242 int arnr_max_frames;
243 int arnr_strength;
244
245 int min_gf_interval;
246 int max_gf_interval;
247
248 int tile_columns;
249 int tile_rows;
Dominic Symes26ad0b22017-10-01 16:35:13 +0200250 int tile_width_count;
251 int tile_height_count;
252 int tile_widths[MAX_TILE_COLS];
253 int tile_heights[MAX_TILE_ROWS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700254
255 int max_threads;
256
Yaowu Xuf883b422016-08-30 14:01:10 -0700257 aom_fixed_buf_t two_pass_stats_in;
258 struct aom_codec_pkt_list *output_pkt_list;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700259
260#if CONFIG_FP_MB_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -0700261 aom_fixed_buf_t firstpass_mb_stats_in;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700262#endif
263
Yaowu Xuf883b422016-08-30 14:01:10 -0700264 aom_tune_metric tuning;
265 aom_tune_content content;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700266 int use_highbitdepth;
Andrey Norkin9e694632017-12-21 18:50:57 -0800267 aom_color_primaries_t color_primaries;
268 aom_transfer_characteristics_t transfer_characteristics;
269 aom_matrix_coefficients_t matrix_coefficients;
anorkin76fb1262017-03-22 15:12:12 -0700270 aom_chroma_sample_position_t chroma_sample_position;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700271 int color_range;
272 int render_width;
273 int render_height;
Andrey Norkin795ba872018-03-06 13:24:14 -0800274 aom_timing_info_type_t timing_info_type;
Andrey Norkin28e9ce22018-01-08 10:11:21 -0800275 int timing_info_present;
Andrey Norkin795ba872018-03-06 13:24:14 -0800276#if !CONFIG_BUFFER_MODEL
Andrey Norkin28e9ce22018-01-08 10:11:21 -0800277 uint32_t num_units_in_tick;
278 uint32_t time_scale;
279 int equal_picture_interval;
280 uint32_t num_ticks_per_picture;
Andrey Norkin795ba872018-03-06 13:24:14 -0800281#else
282 aom_timing_info_t timing_info;
283 int decoder_model_info_present_flag;
284 int buffer_removal_delay_present;
285 int operating_points_decoder_model_cnt;
286 aom_dec_model_info_t buffer_model;
287 aom_dec_model_op_parameters_t op_params[MAX_NUM_OPERATING_POINTS + 1];
288 aom_op_timing_info_t op_frame_timing[MAX_NUM_OPERATING_POINTS + 1];
289#endif
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800290 int film_grain_test_vector;
Neil Birkbeckeb895ef2018-03-14 17:51:03 -0700291 const char *film_grain_table_filename;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700292
Hui Su1cb1c002018-02-05 18:21:20 -0800293 uint8_t cdf_update_mode;
Yaowu Xuf883b422016-08-30 14:01:10 -0700294 aom_superblock_size_t superblock_size;
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700295 unsigned int large_scale_tile;
296 unsigned int single_tile_decoding;
Debargha Mukherjeef340fec2018-01-10 18:12:22 -0800297 int monochrome;
Debargha Mukherjee9713ccb2018-04-08 19:09:17 -0700298 unsigned int full_still_picture_hdr;
Jingning Hana446f552018-02-22 15:42:12 -0800299 int enable_dual_filter;
Yunqing Wangff4fa062017-04-21 10:56:08 -0700300 unsigned int motion_vector_unit_test;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100301 const cfg_options_t *cfg;
Debargha Mukherjee0d8368a2018-03-25 12:23:02 -0700302 int enable_order_hint;
Cheng Chene0c918a2018-02-22 19:38:31 -0800303 int enable_jnt_comp;
Debargha Mukherjee0187d7c2018-03-25 11:37:56 -0700304 int enable_ref_frame_mvs;
Debargha Mukherjee0d8368a2018-03-25 12:23:02 -0700305 unsigned int allow_ref_frame_mvs;
Debargha Mukherjee37df9162018-03-25 12:48:24 -0700306 int enable_warped_motion;
307 int allow_warped_motion;
Urvang Joshi2c92b072018-03-19 17:23:31 -0700308 int enable_superres;
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400309 unsigned int save_as_annexb;
Yaowu Xuf883b422016-08-30 14:01:10 -0700310} AV1EncoderConfig;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700311
Yaowu Xuf883b422016-08-30 14:01:10 -0700312static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700313 return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
314}
315
316// TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
317typedef struct TileDataEnc {
318 TileInfo tile_info;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100319 int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES];
320 int mode_map[BLOCK_SIZES_ALL][MAX_MODES];
Yunqing Wang8c1e57c2016-10-25 15:15:23 -0700321 int m_search_count;
322 int ex_search_count;
Luc Trudeauf8164152017-04-11 16:20:51 -0400323 CFL_CTX cfl;
Jingning Han9f07be12017-04-13 09:31:40 -0700324 DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx);
Yunqing Wang0e141b52017-11-02 15:08:58 -0700325 uint8_t allow_update_cdf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700326} TileDataEnc;
327
328typedef struct RD_COUNTS {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700329 int64_t comp_pred_diff[REFERENCE_MODES];
Debargha Mukherjeea575d232017-04-28 17:46:47 -0700330 // Stores number of 4x4 blocks using global motion per reference frame.
Zoe Liu27deb382018-03-27 15:13:56 -0700331 int global_motion_used[REF_FRAMES];
Arild Fuldseth (arilfuld)6c20c782017-06-15 09:45:02 +0200332 int compound_ref_used_flag;
Zoe Liu8a5d3432017-11-30 16:33:44 -0800333 int skip_mode_used_flag;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700334} RD_COUNTS;
335
336typedef struct ThreadData {
337 MACROBLOCK mb;
338 RD_COUNTS rd_counts;
339 FRAME_COUNTS *counts;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700340 PC_TREE *pc_tree;
341 PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1];
Jingning Hand064cf02017-06-01 10:00:39 -0700342 int32_t *wsrc_buf;
343 int32_t *mask_buf;
344 uint8_t *above_pred_buf;
345 uint8_t *left_pred_buf;
hui su5d493142017-05-08 12:06:12 -0700346 PALETTE_BUFFER *palette_buffer;
Hui Su85878782017-11-07 14:56:31 -0800347 int intrabc_used_this_tile;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700348} ThreadData;
349
350struct EncWorkerData;
351
352typedef struct ActiveMap {
353 int enabled;
354 int update;
355 unsigned char *map;
356} ActiveMap;
357
Urvang Joshib5ed3502016-10-17 16:38:05 -0700358#define NUM_STAT_TYPES 4 // types of stats: Y, U, V and ALL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700359
360typedef struct IMAGE_STAT {
Urvang Joshib5ed3502016-10-17 16:38:05 -0700361 double stat[NUM_STAT_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700362 double worst;
363} ImageStat;
364
Urvang Joshib5ed3502016-10-17 16:38:05 -0700365#undef NUM_STAT_TYPES
366
Yaowu Xuc27fc142016-08-22 16:08:15 -0700367typedef struct {
368 int ref_count;
369 YV12_BUFFER_CONFIG buf;
370} EncRefCntBuffer;
371
Yaowu Xuc27fc142016-08-22 16:08:15 -0700372typedef struct TileBufferEnc {
373 uint8_t *data;
374 size_t size;
375} TileBufferEnc;
376
Yaowu Xuf883b422016-08-30 14:01:10 -0700377typedef struct AV1_COMP {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700378 QUANTS quants;
379 ThreadData td;
380 MB_MODE_INFO_EXT *mbmi_ext_base;
Jingning Hanf5a4d3b2017-08-27 23:01:19 -0700381 CB_COEFF_BUFFER *coeff_buffer_base;
Yi Luoc6210232017-05-25 15:09:25 -0700382 Dequants dequants;
Yaowu Xuf883b422016-08-30 14:01:10 -0700383 AV1_COMMON common;
384 AV1EncoderConfig oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700385 struct lookahead_ctx *lookahead;
386 struct lookahead_entry *alt_ref_source;
387
Angie Chiange69a6822018-03-16 13:52:44 -0700388 int optimize_speed_feature;
389 int optimize_seg_arr[MAX_SEGMENTS];
390
Alex Conversef77fd0b2017-04-20 11:00:24 -0700391 YV12_BUFFER_CONFIG *source;
392 YV12_BUFFER_CONFIG *last_source; // NULL for first frame and alt_ref frames
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700393 YV12_BUFFER_CONFIG *unscaled_source;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700394 YV12_BUFFER_CONFIG scaled_source;
395 YV12_BUFFER_CONFIG *unscaled_last_source;
396 YV12_BUFFER_CONFIG scaled_last_source;
397
Yaowu Xuc27fc142016-08-22 16:08:15 -0700398 // For a still frame, this flag is set to 1 to skip partition search.
399 int partition_search_skippable_frame;
RogerZhou3b635242017-09-19 10:06:46 -0700400 double csm_rate_array[32];
401 double m_rate_array[32];
402 int rate_size;
403 int rate_index;
Debargha Mukherjeee41a6672018-02-27 11:56:31 -0800404 hash_table *previous_hash_table;
405 int previous_index;
RogerZhou3b635242017-09-19 10:06:46 -0700406 int cur_poc; // DebugInfo
Yaowu Xuc27fc142016-08-22 16:08:15 -0700407
Zoe Liu27deb382018-03-27 15:13:56 -0700408 int scaled_ref_idx[REF_FRAMES];
Zoe Liu5989a722018-03-29 13:37:36 -0700409 int ref_fb_idx[REF_FRAMES];
Zoe Liu8dd1c982017-09-11 10:14:35 -0700410 int refresh_fb_idx; // ref frame buffer index to refresh
Yaowu Xuc27fc142016-08-22 16:08:15 -0700411
412 int last_show_frame_buf_idx; // last show frame buffer index
413
414 int refresh_last_frame;
415 int refresh_golden_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700416 int refresh_bwd_ref_frame;
Zoe Liue9b15e22017-07-19 15:53:01 -0700417 int refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700418 int refresh_alt_ref_frame;
419
420 int ext_refresh_frame_flags_pending;
421 int ext_refresh_last_frame;
422 int ext_refresh_golden_frame;
Yunqing Wang9a50fec2017-11-02 17:02:00 -0700423 int ext_refresh_bwd_ref_frame;
424 int ext_refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700425 int ext_refresh_alt_ref_frame;
426
427 int ext_refresh_frame_context_pending;
428 int ext_refresh_frame_context;
sarahparker21dbca42018-03-30 17:43:44 -0700429 int ext_use_ref_frame_mvs;
sarahparker27d686a2018-03-30 17:43:44 -0700430 int ext_use_error_resilient;
sarahparker9806fed2018-03-30 17:43:44 -0700431 int ext_use_s_frame;
Sarah Parker50b6d6e2018-04-11 19:21:54 -0700432 int ext_use_primary_ref_none;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700433
434 YV12_BUFFER_CONFIG last_frame_uf;
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800435 YV12_BUFFER_CONFIG trial_frame_rst;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700436
437 // Ambient reconstruction err target for force key frames
438 int64_t ambient_err;
439
440 RD_OPT rd;
441
442 CODING_CONTEXT coding_context;
443
Yue Chenb23d00a2017-07-28 17:01:21 -0700444 int gmtype_cost[TRANS_TYPES];
Zoe Liu27deb382018-03-27 15:13:56 -0700445 int gmparams_cost[REF_FRAMES];
Yue Chenb23d00a2017-07-28 17:01:21 -0700446
Jingning Hanf050fc12018-03-09 14:53:33 -0800447 int nmv_costs[2][MV_VALS];
448 int nmv_costs_hp[2][MV_VALS];
James Zern01a9d702017-08-25 19:09:33 +0000449
Yaowu Xuc27fc142016-08-22 16:08:15 -0700450 int64_t last_time_stamp_seen;
451 int64_t last_end_time_stamp_seen;
452 int64_t first_time_stamp_ever;
453
454 RATE_CONTROL rc;
455 double framerate;
456
457 // NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter
458 // references; Plus the currently coded frame itself, it is needed to allocate
459 // sufficient space to the size of the maximum possible number of frames.
460 int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE];
461
Yaowu Xuf883b422016-08-30 14:01:10 -0700462 struct aom_codec_pkt_list *output_pkt_list;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700463
464 MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
465 int mbgraph_n_frames; // number of frames filled in the above
466 int static_mb_pct; // % forced skip mbs by segmentation
467 int ref_frame_flags;
Yunqing Wangf2e7a392017-11-08 00:27:21 -0800468 int ext_ref_frame_flags;
Zoe Liuf452fdf2017-11-02 23:08:12 -0700469 RATE_FACTOR_LEVEL frame_rf_level[FRAME_BUFFERS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700470
471 SPEED_FEATURES sf;
472
473 unsigned int max_mv_magnitude;
474 int mv_step_param;
475
476 int allow_comp_inter_inter;
Zoe Liu77fb5be2017-11-02 14:36:19 -0700477 int all_one_sided_refs;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700478
Yaowu Xuc27fc142016-08-22 16:08:15 -0700479 uint8_t *segmentation_map;
480
Yaowu Xuc27fc142016-08-22 16:08:15 -0700481 CYCLIC_REFRESH *cyclic_refresh;
482 ActiveMap active_map;
483
484 fractional_mv_step_fp *find_fractional_mv_step;
Yaowu Xuf883b422016-08-30 14:01:10 -0700485 av1_diamond_search_fn_t diamond_search_sad;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100486 aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES_ALL];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700487 uint64_t time_receive_data;
488 uint64_t time_compress_data;
489 uint64_t time_pick_lpf;
490 uint64_t time_encode_sb_row;
491
492#if CONFIG_FP_MB_STATS
493 int use_fp_mb_stats;
494#endif
495
496 TWO_PASS twopass;
497
498 YV12_BUFFER_CONFIG alt_ref_buffer;
499
500#if CONFIG_INTERNAL_STATS
501 unsigned int mode_chosen_counts[MAX_MODES];
502
503 int count;
504 uint64_t total_sq_error;
505 uint64_t total_samples;
506 ImageStat psnr;
507
508 double total_blockiness;
509 double worst_blockiness;
510
511 int bytes;
512 double summed_quality;
513 double summed_weights;
514 unsigned int tot_recode_hits;
515 double worst_ssim;
516
517 ImageStat fastssim;
518 ImageStat psnrhvs;
519
520 int b_calculate_blockiness;
521 int b_calculate_consistency;
522
523 double total_inconsistency;
524 double worst_consistency;
525 Ssimv *ssim_vars;
526 Metrics metrics;
527#endif
528 int b_calculate_psnr;
529
530 int droppable;
531
532 int initial_width;
533 int initial_height;
534 int initial_mbs; // Number of MBs in the full-size frame; to be used to
535 // normalize the firstpass stats. This will differ from the
536 // number of MBs in the current frame when the frame is
537 // scaled.
538
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700539 // When resize is triggered through external control, the desired width/height
540 // are stored here until use in the next frame coded. They are effective only
541 // for
542 // one frame and are reset after use.
543 int resize_pending_width;
544 int resize_pending_height;
545
Yaowu Xuc27fc142016-08-22 16:08:15 -0700546 int frame_flags;
547
548 search_site_config ss_cfg;
549
Yaowu Xuc27fc142016-08-22 16:08:15 -0700550 int multi_arf_allowed;
551 int multi_arf_enabled;
552 int multi_arf_last_grp_enabled;
553
554 TileDataEnc *tile_data;
555 int allocated_tiles; // Keep track of memory allocated for tiles.
556
557 TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS];
558 unsigned int tok_count[MAX_TILE_ROWS][MAX_TILE_COLS];
559
560 TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS];
561
Yaowu Xuc27fc142016-08-22 16:08:15 -0700562 int resize_state;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700563 int resize_avg_qp;
564 int resize_buffer_underflow;
565 int resize_count;
566
Debargha Mukherjeef2e5bb32018-03-26 14:35:24 -0700567 // Sequence parameters have been transmitted already and locked
568 // or not. Once locked av1_change_config cannot change the seq
569 // parameters.
570 int seq_params_locked;
571
Yaowu Xuc27fc142016-08-22 16:08:15 -0700572 // VARIANCE_AQ segment map refresh
573 int vaq_refresh;
574
575 // Multi-threading
576 int num_workers;
Yaowu Xuf883b422016-08-30 14:01:10 -0700577 AVxWorker *workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700578 struct EncWorkerData *tile_thr_data;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700579 int refresh_frame_mask;
580 int existing_fb_idx_to_show;
581 int is_arf_filter_off[MAX_EXT_ARFS + 1];
582 int num_extra_arfs;
583 int arf_map[MAX_EXT_ARFS + 1];
Zoe Liuf271a952017-09-05 15:03:48 -0700584 int arf_pos_in_gf[MAX_EXT_ARFS + 1];
585 int arf_pos_for_ovrly[MAX_EXT_ARFS + 1];
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -0800586 int global_motion_search_done;
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700587 tran_low_t *tcoeff_buf[MAX_MB_PLANE];
Di Chen53a04f62017-06-23 13:47:56 -0700588 int extra_arf_allowed;
589 int bwd_ref_allowed;
Hui Su85878782017-11-07 14:56:31 -0800590 // A flag to indicate if intrabc is ever used in current frame.
591 int intrabc_used;
Hui Sudfcbfbd2017-11-13 12:05:30 -0800592 int dv_cost[2][MV_VALS];
593 // TODO(huisu@google.com): we can update dv_joint_cost per SB.
594 int dv_joint_cost[MV_JOINTS];
Hui Suad7551e2018-03-14 11:13:31 -0700595 int has_lossless_segment;
Yaowu Xuf883b422016-08-30 14:01:10 -0700596} AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700597
Yaowu Xuf883b422016-08-30 14:01:10 -0700598void av1_initialize_enc(void);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700599
Yaowu Xuf883b422016-08-30 14:01:10 -0700600struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
601 BufferPool *const pool);
602void av1_remove_compressor(AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700603
Yaowu Xuf883b422016-08-30 14:01:10 -0700604void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700605
606// receive a frames worth of data. caller can assume that a copy of this
607// frame is made and not just a copy of the pointer..
James Zern3e2613b2017-03-30 23:14:40 -0700608int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
Yaowu Xuf883b422016-08-30 14:01:10 -0700609 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
610 int64_t end_time_stamp);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700611
Andrey Norkin795ba872018-03-06 13:24:14 -0800612#if CONFIG_BUFFER_MODEL
613int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
614 size_t *size, uint8_t *dest, int64_t *time_stamp,
615 int64_t *time_end, int flush,
616 const aom_rational_t *timebase);
617#else
Yaowu Xuf883b422016-08-30 14:01:10 -0700618int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
619 size_t *size, uint8_t *dest, int64_t *time_stamp,
620 int64_t *time_end, int flush);
Andrey Norkin795ba872018-03-06 13:24:14 -0800621#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700622
Yaowu Xuf883b422016-08-30 14:01:10 -0700623int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700624
Yaowu Xuf883b422016-08-30 14:01:10 -0700625int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700626
Yaowu Xuf883b422016-08-30 14:01:10 -0700627int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700628
Yaowu Xuf883b422016-08-30 14:01:10 -0700629void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700630
Thomas Daede497d1952017-08-08 17:33:06 -0700631int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700632
Thomas Daede497d1952017-08-08 17:33:06 -0700633int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700634
Yaowu Xuf883b422016-08-30 14:01:10 -0700635int av1_update_entropy(AV1_COMP *cpi, int update);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700636
Yaowu Xuf883b422016-08-30 14:01:10 -0700637int av1_set_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700638
Yaowu Xuf883b422016-08-30 14:01:10 -0700639int av1_get_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700640
Yaowu Xuf883b422016-08-30 14:01:10 -0700641int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode,
642 AOM_SCALING vert_mode);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700643
Yaowu Xuf883b422016-08-30 14:01:10 -0700644int av1_get_quantizer(struct AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700645
Soo-Chul Han29c46fb2018-03-23 16:02:00 -0400646int av1_convert_sect5obus_to_annexb(uint8_t *buffer, size_t *input_size);
647
Andrey Norkin795ba872018-03-06 13:24:14 -0800648#if CONFIG_BUFFER_MODEL
649int64_t timebase_units_to_ticks(const aom_rational_t *timebase, int64_t n);
650int64_t ticks_to_timebase_units(const aom_rational_t *timebase, int64_t n);
651#endif
652
Yaowu Xuf883b422016-08-30 14:01:10 -0700653static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700654 return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
655 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
656}
657
Yaowu Xuf883b422016-08-30 14:01:10 -0700658static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700659 MV_REFERENCE_FRAME ref_frame) {
Yaowu Xud023b5b2018-04-05 09:26:17 -0700660 return (ref_frame >= 1) ? cpi->ref_fb_idx[ref_frame - 1] : INVALID_IDX;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700661}
662
Urvang Joshi52648442016-10-13 17:27:51 -0700663static INLINE int get_ref_frame_buf_idx(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700664 MV_REFERENCE_FRAME ref_frame) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700665 const AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700666 const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
667 return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
668}
669
Hui Su2d5fd742018-02-21 18:10:37 -0800670// TODO(huisu@google.com, youzhou@microsoft.com): enable hash-me for HBD.
671static INLINE int av1_use_hash_me(const AV1_COMMON *const cm) {
Debargha Mukherjee8112d2f2018-03-01 09:53:11 -0800672 return cm->allow_screen_content_tools;
Hui Su2d5fd742018-02-21 18:10:37 -0800673}
674
675static INLINE hash_table *av1_get_ref_frame_hash_map(
676 const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
RogerZhoucc5d35d2017-08-07 22:20:15 -0700677 const AV1_COMMON *const cm = &cpi->common;
678 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
679 return buf_idx != INVALID_IDX
680 ? &cm->buffer_pool->frame_bufs[buf_idx].hash_table
681 : NULL;
682}
RogerZhoucc5d35d2017-08-07 22:20:15 -0700683
Yaowu Xuc27fc142016-08-22 16:08:15 -0700684static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
Urvang Joshi52648442016-10-13 17:27:51 -0700685 const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
686 const AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700687 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
688 return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf
689 : NULL;
690}
691
Yaowu Xuf883b422016-08-30 14:01:10 -0700692static INLINE int enc_is_ref_frame_buf(AV1_COMP *cpi, RefCntBuffer *frame_buf) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700693 MV_REFERENCE_FRAME ref_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -0700694 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700695 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
696 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
697 if (buf_idx == INVALID_IDX) continue;
698 if (frame_buf == &cm->buffer_pool->frame_bufs[buf_idx]) break;
699 }
700 return (ref_frame <= ALTREF_FRAME);
701}
Yaowu Xuc27fc142016-08-22 16:08:15 -0700702
Hui Su8ac0c982018-04-03 12:17:36 -0700703// Token buffer is only used for palette tokens.
Yaowu Xue39b3b82017-10-31 16:11:59 -0700704static INLINE unsigned int get_token_alloc(int mb_rows, int mb_cols,
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000705 int sb_size_log2,
706 const int num_planes) {
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100707 // Calculate the maximum number of max superblocks in the image.
Yaowu Xue39b3b82017-10-31 16:11:59 -0700708 const int shift = sb_size_log2 - 4;
709 const int sb_size = 1 << sb_size_log2;
710 const int sb_size_square = sb_size * sb_size;
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100711 const int sb_rows = ALIGN_POWER_OF_TWO(mb_rows, shift) >> shift;
712 const int sb_cols = ALIGN_POWER_OF_TWO(mb_cols, shift) >> shift;
713
Hui Su8ac0c982018-04-03 12:17:36 -0700714 // One palette token for each pixel. There can be palettes on two planes.
715 const int sb_palette_toks = AOMMIN(2, num_planes) * sb_size_square;
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100716
Hui Su8ac0c982018-04-03 12:17:36 -0700717 return sb_rows * sb_cols * sb_palette_toks;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700718}
719
720// Get the allocated token size for a tile. It does the same calculation as in
721// the frame token allocation.
Rupert Swarbrickdcb3cff2017-11-09 15:58:33 +0000722static INLINE unsigned int allocated_tokens(TileInfo tile, int sb_size_log2,
723 int num_planes) {
Jingning Haneafbd5f2017-03-07 11:18:17 -0800724 int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 2) >> 2;
725 int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 2) >> 2;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700726
Rupert Swarbrickdcb3cff2017-11-09 15:58:33 +0000727 return get_token_alloc(tile_mb_rows, tile_mb_cols, sb_size_log2, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700728}
729
Yaowu Xuf883b422016-08-30 14:01:10 -0700730void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700731
Yaowu Xu6da42302017-10-10 14:45:06 -0700732#define ALT_MIN_LAG 3
Yaowu Xuf883b422016-08-30 14:01:10 -0700733static INLINE int is_altref_enabled(const AV1_COMP *const cpi) {
Yaowu Xu6da42302017-10-10 14:45:06 -0700734 return cpi->oxcf.lag_in_frames >= ALT_MIN_LAG && cpi->oxcf.enable_auto_arf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700735}
736
737// TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf
Yaowu Xuc27fc142016-08-22 16:08:15 -0700738
Urvang Joshi52648442016-10-13 17:27:51 -0700739static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700740 MV_REFERENCE_FRAME ref0,
741 MV_REFERENCE_FRAME ref1) {
742 xd->block_refs[0] =
743 &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0];
744 xd->block_refs[1] =
745 &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0];
746}
747
Yaowu Xu4ff59b52017-04-24 12:41:56 -0700748static INLINE int get_chessboard_index(int frame_index) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700749 return frame_index & 0x1;
750}
751
Yaowu Xuf883b422016-08-30 14:01:10 -0700752static INLINE int *cond_cost_list(const struct AV1_COMP *cpi, int *cost_list) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700753 return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
754}
755
Yaowu Xuf883b422016-08-30 14:01:10 -0700756void av1_new_framerate(AV1_COMP *cpi, double framerate);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700757
758#define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
759
760// Update up-sampled reference frame index.
761static INLINE void uref_cnt_fb(EncRefCntBuffer *ubufs, int *uidx,
762 int new_uidx) {
763 const int ref_index = *uidx;
764
765 if (ref_index >= 0 && ubufs[ref_index].ref_count > 0)
766 ubufs[ref_index].ref_count--;
767
768 *uidx = new_uidx;
769 ubufs[new_uidx].ref_count++;
770}
771
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700772// Returns 1 if a frame is unscaled and 0 otherwise.
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700773static INLINE int av1_resize_unscaled(const AV1_COMMON *cm) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700774 return cm->superres_upscaled_width == cm->render_width &&
775 cm->superres_upscaled_height == cm->render_height;
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700776}
777
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700778static INLINE int av1_frame_unscaled(const AV1_COMMON *cm) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700779 return av1_superres_unscaled(cm) && av1_resize_unscaled(cm);
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700780}
781
Yaowu Xuc27fc142016-08-22 16:08:15 -0700782#ifdef __cplusplus
783} // extern "C"
784#endif
785
Yaowu Xuf883b422016-08-30 14:01:10 -0700786#endif // AV1_ENCODER_ENCODER_H_