blob: 91589092dddc107516cfcac0934aed3997925f29 [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"
Yaowu Xuc27fc142016-08-22 16:08:15 -070025#include "av1/encoder/aq_cyclicrefresh.h"
Tom Finegan17ce8b12017-02-08 12:46:31 -080026#include "av1/encoder/av1_quantize.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070027#include "av1/encoder/context_tree.h"
28#include "av1/encoder/encodemb.h"
29#include "av1/encoder/firstpass.h"
30#include "av1/encoder/lookahead.h"
31#include "av1/encoder/mbgraph.h"
32#include "av1/encoder/mcomp.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070033#include "av1/encoder/ratectrl.h"
34#include "av1/encoder/rd.h"
35#include "av1/encoder/speed_features.h"
36#include "av1/encoder/tokenize.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070037
38#if CONFIG_INTERNAL_STATS
39#include "aom_dsp/ssim.h"
40#endif
41#include "aom_dsp/variance.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070042#include "aom/internal/aom_codec_internal.h"
43#include "aom_util/aom_thread.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070044
45#ifdef __cplusplus
46extern "C" {
47#endif
48
49typedef struct {
Jingning Hanf050fc12018-03-09 14:53:33 -080050 int nmv_vec_cost[MV_JOINTS];
51 int nmv_costs[2][MV_VALS];
52 int nmv_costs_hp[2][MV_VALS];
James Zern01a9d702017-08-25 19:09:33 +000053
Yaowu Xuc27fc142016-08-22 16:08:15 -070054 // 0 = Intra, Last, GF, ARF
Yaowu Xu0fbe33d2017-08-31 09:34:29 -070055 int8_t last_ref_lf_deltas[TOTAL_REFS_PER_FRAME];
Yaowu Xuc27fc142016-08-22 16:08:15 -070056 // 0 = ZERO_MV, MV
Yaowu Xu0fbe33d2017-08-31 09:34:29 -070057 int8_t last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
Yaowu Xuc27fc142016-08-22 16:08:15 -070058
59 FRAME_CONTEXT fc;
60} CODING_CONTEXT;
61
62typedef enum {
63 // regular inter frame
64 REGULAR_FRAME = 0,
65 // alternate reference frame
66 ARF_FRAME = 1,
67 // overlay frame
68 OVERLAY_FRAME = 2,
69 // golden frame
70 GLD_FRAME = 3,
Yaowu Xuc27fc142016-08-22 16:08:15 -070071 // backward reference frame
72 BRF_FRAME = 4,
73 // extra alternate reference frame
Thomas Daede51020e12017-12-14 20:12:44 -080074 EXT_ARF_FRAME = 5,
75 FRAME_CONTEXT_INDEXES
Yaowu Xuc27fc142016-08-22 16:08:15 -070076} FRAME_CONTEXT_INDEX;
77
78typedef enum {
Yaowu Xuc27fc142016-08-22 16:08:15 -070079 NORMAL = 0,
80 FOURFIVE = 1,
81 THREEFIVE = 2,
82 ONETWO = 3
Yaowu Xuf883b422016-08-30 14:01:10 -070083} AOM_SCALING;
Yaowu Xuc27fc142016-08-22 16:08:15 -070084
85typedef enum {
86 // Good Quality Fast Encoding. The encoder balances quality with the amount of
87 // time it takes to encode the output. Speed setting controls how fast.
Thomas Daede80826142017-03-20 15:44:24 -070088 GOOD
Yaowu Xuc27fc142016-08-22 16:08:15 -070089} MODE;
90
91typedef enum {
92 FRAMEFLAGS_KEY = 1 << 0,
93 FRAMEFLAGS_GOLDEN = 1 << 1,
Yaowu Xuc27fc142016-08-22 16:08:15 -070094 FRAMEFLAGS_BWDREF = 1 << 2,
Zoe Liu3ac20932017-08-30 16:35:55 -070095 // TODO(zoeliu): To determine whether a frame flag is needed for ALTREF2_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -070096 FRAMEFLAGS_ALTREF = 1 << 3,
Yaowu Xuc27fc142016-08-22 16:08:15 -070097} FRAMETYPE_FLAGS;
98
99typedef enum {
100 NO_AQ = 0,
101 VARIANCE_AQ = 1,
102 COMPLEXITY_AQ = 2,
103 CYCLIC_REFRESH_AQ = 3,
Thomas Davies3ab20b42017-09-19 10:30:53 +0100104#if !CONFIG_EXT_DELTA_Q
Arild Fuldseth07441162016-08-15 15:07:52 +0200105 DELTA_AQ = 4,
106#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700107 AQ_MODE_COUNT // This should always be the last member of the enum
108} AQ_MODE;
Fangwen Fu6160df22017-04-24 09:45:51 -0700109#if CONFIG_EXT_DELTA_Q
110typedef enum {
111 NO_DELTA_Q = 0,
112 DELTA_Q_ONLY = 1,
113 DELTA_Q_LF = 2,
114 DELTAQ_MODE_COUNT // This should always be the last member of the enum
115} DELTAQ_MODE;
116#endif
Debargha Mukherjee3a4959f2018-02-26 15:34:03 -0800117
Yaowu Xuc27fc142016-08-22 16:08:15 -0700118typedef enum {
119 RESIZE_NONE = 0, // No frame resizing allowed.
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700120 RESIZE_FIXED = 1, // All frames are coded at the specified scale.
121 RESIZE_RANDOM = 2, // All frames are coded at a random scale.
122 RESIZE_MODES
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700123} RESIZE_MODE;
Debargha Mukherjee3a4959f2018-02-26 15:34:03 -0800124
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700125typedef enum {
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700126 SUPERRES_NONE = 0, // No frame superres allowed
127 SUPERRES_FIXED = 1, // All frames are coded at the specified scale,
128 // and super-resolved.
129 SUPERRES_RANDOM = 2, // All frames are coded at a random scale,
130 // and super-resolved.
131 SUPERRES_QTHRESH = 3, // Superres scale for a frame is determined based on
132 // q_index
133 SUPERRES_MODES
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700134} SUPERRES_MODE;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700135
Yaowu Xuf883b422016-08-30 14:01:10 -0700136typedef struct AV1EncoderConfig {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137 BITSTREAM_PROFILE profile;
Tom Finegan8ab2bba2018-02-28 07:36:28 -0800138 aom_bit_depth_t bit_depth; // Codec bit-depth.
139 int width; // width of data passed to the compressor
140 int height; // height of data passed to the compressor
141 int forced_max_frame_width; // forced maximum width of frame (if != 0)
142 int forced_max_frame_height; // forced maximum height of frame (if != 0)
Yaowu Xuc27fc142016-08-22 16:08:15 -0700143 unsigned int input_bit_depth; // Input bit depth.
144 double init_framerate; // set to passed in framerate
145 int64_t target_bandwidth; // bandwidth to be used in bits per second
146
147 int noise_sensitivity; // pre processing blur: recommendation 0
148 int sharpness; // sharpening output: recommendation 0:
149 int speed;
Jingning Hanb49c6ae2017-11-27 18:14:05 -0800150 int dev_sf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700151 // maximum allowed bitrate for any intra frame in % of bitrate target.
152 unsigned int rc_max_intra_bitrate_pct;
153 // maximum allowed bitrate for any inter frame in % of bitrate target.
154 unsigned int rc_max_inter_bitrate_pct;
155 // percent of rate boost for golden frame in CBR mode.
156 unsigned int gf_cbr_boost_pct;
157
158 MODE mode;
159 int pass;
160
161 // Key Framing Operations
162 int auto_key; // autodetect cut scenes and set the keyframes
163 int key_freq; // maximum distance to key frame.
164
165 int lag_in_frames; // how many frames lag before we start encoding
166
167 // ----------------------------------------------------------------
168 // DATARATE CONTROL OPTIONS
169
170 // vbr, cbr, constrained quality or constant quality
Yaowu Xuf883b422016-08-30 14:01:10 -0700171 enum aom_rc_mode rc_mode;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700172
173 // buffer targeting aggressiveness
174 int under_shoot_pct;
175 int over_shoot_pct;
176
177 // buffering parameters
178 int64_t starting_buffer_level_ms;
179 int64_t optimal_buffer_level_ms;
180 int64_t maximum_buffer_size_ms;
181
182 // Frame drop threshold.
183 int drop_frames_water_mark;
184
185 // controlling quality
186 int fixed_q;
187 int worst_allowed_q;
188 int best_allowed_q;
189 int cq_level;
190 AQ_MODE aq_mode; // Adaptive Quantization mode
Fangwen Fu6160df22017-04-24 09:45:51 -0700191#if CONFIG_EXT_DELTA_Q
192 DELTAQ_MODE deltaq_mode;
193#endif
Steinar Midtskogene44c6222017-11-09 13:22:09 +0100194 int using_cdef;
Sebastien Alaiwan1ed20242018-02-20 14:47:18 +0100195 int using_restoration;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700196 int using_qm;
Yaowu Xuf7a12422018-01-31 15:29:20 -0800197#if CONFIG_AOM_QM_EXT
198 int qm_y;
199 int qm_u;
200 int qm_v;
201#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700202 int qm_minlevel;
203 int qm_maxlevel;
Yushin Chod808bfc2017-08-10 15:54:36 -0700204#if CONFIG_DIST_8X8
205 int using_dist_8x8;
206#endif
Thomas Daviesaf6df172016-11-09 14:04:18 +0000207 unsigned int num_tile_groups;
208 unsigned int mtu;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700209
Fangwen Fu8d164de2016-12-14 13:40:54 -0800210 unsigned int disable_tempmv;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700211 // Internal frame size scaling.
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700212 RESIZE_MODE resize_mode;
Urvang Joshide71d142017-10-05 12:12:15 -0700213 uint8_t resize_scale_denominator;
214 uint8_t resize_kf_scale_denominator;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700215
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700216 // Frame Super-Resolution size scaling.
217 SUPERRES_MODE superres_mode;
Urvang Joshide71d142017-10-05 12:12:15 -0700218 uint8_t superres_scale_denominator;
219 uint8_t superres_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700220 int superres_qthresh;
221 int superres_kf_qthresh;
Fergus Simpson3502d082017-04-10 12:25:07 -0700222
Yaowu Xuc27fc142016-08-22 16:08:15 -0700223 // Enable feature to reduce the frame quantization every x frames.
224 int frame_periodic_boost;
225
226 // two pass datarate control
227 int two_pass_vbrbias; // two pass datarate control tweaks
228 int two_pass_vbrmin_section;
229 int two_pass_vbrmax_section;
230 // END DATARATE CONTROL OPTIONS
231 // ----------------------------------------------------------------
232
233 int enable_auto_arf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700234 int enable_auto_brf; // (b)ackward (r)ef (f)rame
Yaowu Xuc27fc142016-08-22 16:08:15 -0700235
Yaowu Xuc27fc142016-08-22 16:08:15 -0700236 /* Bitfield defining the error resiliency features to enable.
237 * Can provide decodable frames after losses in previous
238 * frames and decodable partitions after losses in the same frame.
239 */
240 unsigned int error_resilient_mode;
241
242 /* Bitfield defining the parallel decoding mode where the
243 * decoding in successive frames may be conducted in parallel
244 * just by decoding the frame headers.
245 */
246 unsigned int frame_parallel_decoding_mode;
247
248 int arnr_max_frames;
249 int arnr_strength;
250
251 int min_gf_interval;
252 int max_gf_interval;
253
254 int tile_columns;
255 int tile_rows;
Dominic Symesf58f1112017-09-25 12:47:40 +0200256#if CONFIG_MAX_TILE
Dominic Symes26ad0b22017-10-01 16:35:13 +0200257 int tile_width_count;
258 int tile_height_count;
259 int tile_widths[MAX_TILE_COLS];
260 int tile_heights[MAX_TILE_ROWS];
Dominic Symesf58f1112017-09-25 12:47:40 +0200261#endif
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800262#if CONFIG_DEPENDENT_HORZTILES
263 int dependent_horz_tiles;
264#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800265#if CONFIG_LOOPFILTERING_ACROSS_TILES
Lei7bb501d2017-12-13 15:10:34 -0800266#if CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
267 int loop_filter_across_tiles_v_enabled;
268 int loop_filter_across_tiles_h_enabled;
269#else
Ryan Lei7386eda2016-12-08 21:08:31 -0800270 int loop_filter_across_tiles_enabled;
Lei7bb501d2017-12-13 15:10:34 -0800271#endif // CONFIG_LOOPFILTERING_ACROSS_TILES_EXT
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800272#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -0700273
274 int max_threads;
275
Yaowu Xuf883b422016-08-30 14:01:10 -0700276 aom_fixed_buf_t two_pass_stats_in;
277 struct aom_codec_pkt_list *output_pkt_list;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700278
279#if CONFIG_FP_MB_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -0700280 aom_fixed_buf_t firstpass_mb_stats_in;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700281#endif
282
Yaowu Xuf883b422016-08-30 14:01:10 -0700283 aom_tune_metric tuning;
284 aom_tune_content content;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285 int use_highbitdepth;
Andrey Norkin9e694632017-12-21 18:50:57 -0800286 aom_color_primaries_t color_primaries;
287 aom_transfer_characteristics_t transfer_characteristics;
288 aom_matrix_coefficients_t matrix_coefficients;
anorkin76fb1262017-03-22 15:12:12 -0700289 aom_chroma_sample_position_t chroma_sample_position;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700290 int color_range;
291 int render_width;
292 int render_height;
Andrey Norkin28e9ce22018-01-08 10:11:21 -0800293 aom_timing_info_t timing_info;
294 int timing_info_present;
295 uint32_t num_units_in_tick;
296 uint32_t time_scale;
297 int equal_picture_interval;
298 uint32_t num_ticks_per_picture;
Andrey Norkin6f1c2f72018-01-15 20:08:52 -0800299#if CONFIG_FILM_GRAIN
300 int film_grain_test_vector;
301#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700302
Hui Su1cb1c002018-02-05 18:21:20 -0800303#if CONFIG_CDF_UPDATE_MODE
304 uint8_t cdf_update_mode;
305#endif // CONFIG_CDF_UPDATE_MODE
Yaowu Xuf883b422016-08-30 14:01:10 -0700306 aom_superblock_size_t superblock_size;
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700307 unsigned int large_scale_tile;
308 unsigned int single_tile_decoding;
Debargha Mukherjeef340fec2018-01-10 18:12:22 -0800309 int monochrome;
Jingning Hana446f552018-02-22 15:42:12 -0800310 int enable_dual_filter;
Yunqing Wangff4fa062017-04-21 10:56:08 -0700311 unsigned int motion_vector_unit_test;
Maxym Dmytrychenkocc6e0e12018-02-05 16:35:37 +0100312 const cfg_options_t *cfg;
Cheng Chene0c918a2018-02-22 19:38:31 -0800313 int enable_jnt_comp;
Cheng Chenfecd9a72018-03-08 15:23:51 -0800314 int enable_order_hint;
Yaowu Xuf883b422016-08-30 14:01:10 -0700315} AV1EncoderConfig;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700316
Yaowu Xuf883b422016-08-30 14:01:10 -0700317static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700318 return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
319}
320
321// TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
322typedef struct TileDataEnc {
323 TileInfo tile_info;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100324 int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES];
325 int mode_map[BLOCK_SIZES_ALL][MAX_MODES];
Yunqing Wang8c1e57c2016-10-25 15:15:23 -0700326 int m_search_count;
327 int ex_search_count;
Luc Trudeauf8164152017-04-11 16:20:51 -0400328 CFL_CTX cfl;
Jingning Han9f07be12017-04-13 09:31:40 -0700329 DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx);
Yunqing Wang0e141b52017-11-02 15:08:58 -0700330 uint8_t allow_update_cdf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700331} TileDataEnc;
332
333typedef struct RD_COUNTS {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700334 int64_t comp_pred_diff[REFERENCE_MODES];
Debargha Mukherjeea575d232017-04-28 17:46:47 -0700335 // Stores number of 4x4 blocks using global motion per reference frame.
336 int global_motion_used[TOTAL_REFS_PER_FRAME];
Arild Fuldseth (arilfuld)6c20c782017-06-15 09:45:02 +0200337 int compound_ref_used_flag;
Zoe Liu8a5d3432017-11-30 16:33:44 -0800338 int skip_mode_used_flag;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700339} RD_COUNTS;
340
341typedef struct ThreadData {
342 MACROBLOCK mb;
343 RD_COUNTS rd_counts;
344 FRAME_COUNTS *counts;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700345 PC_TREE *pc_tree;
346 PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1];
Jingning Hand064cf02017-06-01 10:00:39 -0700347 int32_t *wsrc_buf;
348 int32_t *mask_buf;
349 uint8_t *above_pred_buf;
350 uint8_t *left_pred_buf;
hui su5d493142017-05-08 12:06:12 -0700351 PALETTE_BUFFER *palette_buffer;
Hui Su85878782017-11-07 14:56:31 -0800352 int intrabc_used_this_tile;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700353} ThreadData;
354
355struct EncWorkerData;
356
357typedef struct ActiveMap {
358 int enabled;
359 int update;
360 unsigned char *map;
361} ActiveMap;
362
Urvang Joshib5ed3502016-10-17 16:38:05 -0700363#define NUM_STAT_TYPES 4 // types of stats: Y, U, V and ALL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700364
365typedef struct IMAGE_STAT {
Urvang Joshib5ed3502016-10-17 16:38:05 -0700366 double stat[NUM_STAT_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700367 double worst;
368} ImageStat;
369
Urvang Joshib5ed3502016-10-17 16:38:05 -0700370#undef NUM_STAT_TYPES
371
Yaowu Xuc27fc142016-08-22 16:08:15 -0700372typedef struct {
373 int ref_count;
374 YV12_BUFFER_CONFIG buf;
375} EncRefCntBuffer;
376
Yaowu Xuc27fc142016-08-22 16:08:15 -0700377typedef struct TileBufferEnc {
378 uint8_t *data;
379 size_t size;
380} TileBufferEnc;
381
Yaowu Xuf883b422016-08-30 14:01:10 -0700382typedef struct AV1_COMP {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700383 QUANTS quants;
384 ThreadData td;
385 MB_MODE_INFO_EXT *mbmi_ext_base;
Jingning Hanf5a4d3b2017-08-27 23:01:19 -0700386 CB_COEFF_BUFFER *coeff_buffer_base;
Yi Luoc6210232017-05-25 15:09:25 -0700387 Dequants dequants;
Yaowu Xuf883b422016-08-30 14:01:10 -0700388 AV1_COMMON common;
389 AV1EncoderConfig oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700390 struct lookahead_ctx *lookahead;
391 struct lookahead_entry *alt_ref_source;
392
Alex Conversef77fd0b2017-04-20 11:00:24 -0700393 YV12_BUFFER_CONFIG *source;
394 YV12_BUFFER_CONFIG *last_source; // NULL for first frame and alt_ref frames
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700395 YV12_BUFFER_CONFIG *unscaled_source;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700396 YV12_BUFFER_CONFIG scaled_source;
397 YV12_BUFFER_CONFIG *unscaled_last_source;
398 YV12_BUFFER_CONFIG scaled_last_source;
399
Yaowu Xuc27fc142016-08-22 16:08:15 -0700400 // For a still frame, this flag is set to 1 to skip partition search.
401 int partition_search_skippable_frame;
RogerZhou3b635242017-09-19 10:06:46 -0700402#if CONFIG_AMVR
403 double csm_rate_array[32];
404 double m_rate_array[32];
405 int rate_size;
406 int rate_index;
Debargha Mukherjeee41a6672018-02-27 11:56:31 -0800407 hash_table *previous_hash_table;
408 int previous_index;
RogerZhou3b635242017-09-19 10:06:46 -0700409 int cur_poc; // DebugInfo
410#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700411
412 int scaled_ref_idx[TOTAL_REFS_PER_FRAME];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700413 int lst_fb_idxes[LAST_REF_FRAMES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700414 int gld_fb_idx;
Zoe Liu3ac20932017-08-30 16:35:55 -0700415 int bwd_fb_idx; // BWDREF_FRAME
Zoe Liue9b15e22017-07-19 15:53:01 -0700416 int alt2_fb_idx; // ALTREF2_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -0700417 int alt_fb_idx;
Zoe Liu8dd1c982017-09-11 10:14:35 -0700418 int ext_fb_idx; // extra ref frame buffer index
419 int refresh_fb_idx; // ref frame buffer index to refresh
Yaowu Xuc27fc142016-08-22 16:08:15 -0700420
421 int last_show_frame_buf_idx; // last show frame buffer index
422
423 int refresh_last_frame;
424 int refresh_golden_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700425 int refresh_bwd_ref_frame;
Zoe Liue9b15e22017-07-19 15:53:01 -0700426 int refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700427 int refresh_alt_ref_frame;
428
429 int ext_refresh_frame_flags_pending;
430 int ext_refresh_last_frame;
431 int ext_refresh_golden_frame;
Yunqing Wang9a50fec2017-11-02 17:02:00 -0700432 int ext_refresh_bwd_ref_frame;
433 int ext_refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700434 int ext_refresh_alt_ref_frame;
435
436 int ext_refresh_frame_context_pending;
437 int ext_refresh_frame_context;
438
439 YV12_BUFFER_CONFIG last_frame_uf;
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800440 YV12_BUFFER_CONFIG trial_frame_rst;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700441
442 // Ambient reconstruction err target for force key frames
443 int64_t ambient_err;
444
445 RD_OPT rd;
446
447 CODING_CONTEXT coding_context;
448
Yue Chenb23d00a2017-07-28 17:01:21 -0700449 int gmtype_cost[TRANS_TYPES];
450 int gmparams_cost[TOTAL_REFS_PER_FRAME];
Yue Chenb23d00a2017-07-28 17:01:21 -0700451
Jingning Hanf050fc12018-03-09 14:53:33 -0800452 int nmv_costs[2][MV_VALS];
453 int nmv_costs_hp[2][MV_VALS];
James Zern01a9d702017-08-25 19:09:33 +0000454
Yaowu Xuc27fc142016-08-22 16:08:15 -0700455 int64_t last_time_stamp_seen;
456 int64_t last_end_time_stamp_seen;
457 int64_t first_time_stamp_ever;
458
459 RATE_CONTROL rc;
460 double framerate;
461
462 // NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter
463 // references; Plus the currently coded frame itself, it is needed to allocate
464 // sufficient space to the size of the maximum possible number of frames.
465 int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE];
466
Yaowu Xuf883b422016-08-30 14:01:10 -0700467 struct aom_codec_pkt_list *output_pkt_list;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700468
469 MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
470 int mbgraph_n_frames; // number of frames filled in the above
471 int static_mb_pct; // % forced skip mbs by segmentation
472 int ref_frame_flags;
Yunqing Wangf2e7a392017-11-08 00:27:21 -0800473 int ext_ref_frame_flags;
Zoe Liuf452fdf2017-11-02 23:08:12 -0700474 RATE_FACTOR_LEVEL frame_rf_level[FRAME_BUFFERS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700475
476 SPEED_FEATURES sf;
477
478 unsigned int max_mv_magnitude;
479 int mv_step_param;
480
481 int allow_comp_inter_inter;
Zoe Liu77fb5be2017-11-02 14:36:19 -0700482 int all_one_sided_refs;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700483
Yaowu Xuc27fc142016-08-22 16:08:15 -0700484 uint8_t *segmentation_map;
485
Yaowu Xuc27fc142016-08-22 16:08:15 -0700486 CYCLIC_REFRESH *cyclic_refresh;
487 ActiveMap active_map;
488
489 fractional_mv_step_fp *find_fractional_mv_step;
Yaowu Xuf883b422016-08-30 14:01:10 -0700490 av1_full_search_fn_t full_search_sad; // It is currently unused.
491 av1_diamond_search_fn_t diamond_search_sad;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100492 aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES_ALL];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700493 uint64_t time_receive_data;
494 uint64_t time_compress_data;
495 uint64_t time_pick_lpf;
496 uint64_t time_encode_sb_row;
497
498#if CONFIG_FP_MB_STATS
499 int use_fp_mb_stats;
500#endif
501
502 TWO_PASS twopass;
503
504 YV12_BUFFER_CONFIG alt_ref_buffer;
505
506#if CONFIG_INTERNAL_STATS
507 unsigned int mode_chosen_counts[MAX_MODES];
508
509 int count;
510 uint64_t total_sq_error;
511 uint64_t total_samples;
512 ImageStat psnr;
513
514 double total_blockiness;
515 double worst_blockiness;
516
517 int bytes;
518 double summed_quality;
519 double summed_weights;
520 unsigned int tot_recode_hits;
521 double worst_ssim;
522
523 ImageStat fastssim;
524 ImageStat psnrhvs;
525
526 int b_calculate_blockiness;
527 int b_calculate_consistency;
528
529 double total_inconsistency;
530 double worst_consistency;
531 Ssimv *ssim_vars;
532 Metrics metrics;
533#endif
534 int b_calculate_psnr;
535
536 int droppable;
537
538 int initial_width;
539 int initial_height;
540 int initial_mbs; // Number of MBs in the full-size frame; to be used to
541 // normalize the firstpass stats. This will differ from the
542 // number of MBs in the current frame when the frame is
543 // scaled.
544
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700545 // When resize is triggered through external control, the desired width/height
546 // are stored here until use in the next frame coded. They are effective only
547 // for
548 // one frame and are reset after use.
549 int resize_pending_width;
550 int resize_pending_height;
551
Yaowu Xuc27fc142016-08-22 16:08:15 -0700552 int frame_flags;
553
554 search_site_config ss_cfg;
555
Yaowu Xuc27fc142016-08-22 16:08:15 -0700556 int multi_arf_allowed;
557 int multi_arf_enabled;
558 int multi_arf_last_grp_enabled;
559
560 TileDataEnc *tile_data;
561 int allocated_tiles; // Keep track of memory allocated for tiles.
562
563 TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS];
564 unsigned int tok_count[MAX_TILE_ROWS][MAX_TILE_COLS];
565
566 TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS];
567
Yaowu Xuc27fc142016-08-22 16:08:15 -0700568 int resize_state;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700569 int resize_avg_qp;
570 int resize_buffer_underflow;
571 int resize_count;
572
Yaowu Xuc27fc142016-08-22 16:08:15 -0700573 // VARIANCE_AQ segment map refresh
574 int vaq_refresh;
575
576 // Multi-threading
577 int num_workers;
Yaowu Xuf883b422016-08-30 14:01:10 -0700578 AVxWorker *workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700579 struct EncWorkerData *tile_thr_data;
Yaowu Xuf883b422016-08-30 14:01:10 -0700580 AV1LfSync lf_row_sync;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700581 int refresh_frame_mask;
582 int existing_fb_idx_to_show;
583 int is_arf_filter_off[MAX_EXT_ARFS + 1];
584 int num_extra_arfs;
585 int arf_map[MAX_EXT_ARFS + 1];
Zoe Liuf271a952017-09-05 15:03:48 -0700586 int arf_pos_in_gf[MAX_EXT_ARFS + 1];
587 int arf_pos_for_ovrly[MAX_EXT_ARFS + 1];
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -0800588 int global_motion_search_done;
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700589 tran_low_t *tcoeff_buf[MAX_MB_PLANE];
Di Chen53a04f62017-06-23 13:47:56 -0700590 int extra_arf_allowed;
591 int bwd_ref_allowed;
Hui Su85878782017-11-07 14:56:31 -0800592 // A flag to indicate if intrabc is ever used in current frame.
593 int intrabc_used;
Hui Sudfcbfbd2017-11-13 12:05:30 -0800594 int dv_cost[2][MV_VALS];
595 // TODO(huisu@google.com): we can update dv_joint_cost per SB.
596 int dv_joint_cost[MV_JOINTS];
Yaowu Xuf883b422016-08-30 14:01:10 -0700597} AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700598
Yaowu Xuf883b422016-08-30 14:01:10 -0700599void av1_initialize_enc(void);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700600
Yaowu Xuf883b422016-08-30 14:01:10 -0700601struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
602 BufferPool *const pool);
603void av1_remove_compressor(AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700604
Yaowu Xuf883b422016-08-30 14:01:10 -0700605void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700606
607// receive a frames worth of data. caller can assume that a copy of this
608// frame is made and not just a copy of the pointer..
James Zern3e2613b2017-03-30 23:14:40 -0700609int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
Yaowu Xuf883b422016-08-30 14:01:10 -0700610 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
611 int64_t end_time_stamp);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700612
Yaowu Xuf883b422016-08-30 14:01:10 -0700613int 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);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700616
Yaowu Xuf883b422016-08-30 14:01:10 -0700617int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700618
Yaowu Xuf883b422016-08-30 14:01:10 -0700619int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700620
Yaowu Xuf883b422016-08-30 14:01:10 -0700621int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700622
Yaowu Xuf883b422016-08-30 14:01:10 -0700623void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700624
Thomas Daede497d1952017-08-08 17:33:06 -0700625int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700626
Thomas Daede497d1952017-08-08 17:33:06 -0700627int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700628
Yaowu Xuf883b422016-08-30 14:01:10 -0700629int av1_update_entropy(AV1_COMP *cpi, int update);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700630
Yaowu Xuf883b422016-08-30 14:01:10 -0700631int av1_set_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700632
Yaowu Xuf883b422016-08-30 14:01:10 -0700633int av1_get_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700634
Yaowu Xuf883b422016-08-30 14:01:10 -0700635int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode,
636 AOM_SCALING vert_mode);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700637
Yaowu Xuf883b422016-08-30 14:01:10 -0700638int av1_get_quantizer(struct AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700639
Yaowu Xuf883b422016-08-30 14:01:10 -0700640static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700641 return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
642 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
643}
644
Yaowu Xuf883b422016-08-30 14:01:10 -0700645static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700646 MV_REFERENCE_FRAME ref_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700647 if (ref_frame >= LAST_FRAME && ref_frame <= LAST3_FRAME)
648 return cpi->lst_fb_idxes[ref_frame - 1];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700649 else if (ref_frame == GOLDEN_FRAME)
650 return cpi->gld_fb_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700651 else if (ref_frame == BWDREF_FRAME)
652 return cpi->bwd_fb_idx;
Zoe Liue9b15e22017-07-19 15:53:01 -0700653 else if (ref_frame == ALTREF2_FRAME)
654 return cpi->alt2_fb_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700655 else
656 return cpi->alt_fb_idx;
657}
658
Urvang Joshi52648442016-10-13 17:27:51 -0700659static INLINE int get_ref_frame_buf_idx(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700660 MV_REFERENCE_FRAME ref_frame) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700661 const AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700662 const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
663 return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
664}
665
RogerZhoucc5d35d2017-08-07 22:20:15 -0700666#if CONFIG_HASH_ME
Hui Su2d5fd742018-02-21 18:10:37 -0800667// TODO(huisu@google.com, youzhou@microsoft.com): enable hash-me for HBD.
668static INLINE int av1_use_hash_me(const AV1_COMMON *const cm) {
Debargha Mukherjee8112d2f2018-03-01 09:53:11 -0800669 return cm->allow_screen_content_tools;
Hui Su2d5fd742018-02-21 18:10:37 -0800670}
671
672static INLINE hash_table *av1_get_ref_frame_hash_map(
673 const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
RogerZhoucc5d35d2017-08-07 22:20:15 -0700674 const AV1_COMMON *const cm = &cpi->common;
675 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
676 return buf_idx != INVALID_IDX
677 ? &cm->buffer_pool->frame_bufs[buf_idx].hash_table
678 : NULL;
679}
680#endif
681
Yaowu Xuc27fc142016-08-22 16:08:15 -0700682static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
Urvang Joshi52648442016-10-13 17:27:51 -0700683 const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
684 const AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700685 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
686 return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf
687 : NULL;
688}
689
Yaowu Xuf883b422016-08-30 14:01:10 -0700690static INLINE int enc_is_ref_frame_buf(AV1_COMP *cpi, RefCntBuffer *frame_buf) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700691 MV_REFERENCE_FRAME ref_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -0700692 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700693 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
694 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
695 if (buf_idx == INVALID_IDX) continue;
696 if (frame_buf == &cm->buffer_pool->frame_bufs[buf_idx]) break;
697 }
698 return (ref_frame <= ALTREF_FRAME);
699}
Yaowu Xuc27fc142016-08-22 16:08:15 -0700700
Yaowu Xue39b3b82017-10-31 16:11:59 -0700701static INLINE unsigned int get_token_alloc(int mb_rows, int mb_cols,
Imdad Sardharwallaaf8e2642018-01-19 11:46:34 +0000702 int sb_size_log2,
703 const int num_planes) {
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100704 // Calculate the maximum number of max superblocks in the image.
Yaowu Xue39b3b82017-10-31 16:11:59 -0700705 const int shift = sb_size_log2 - 4;
706 const int sb_size = 1 << sb_size_log2;
707 const int sb_size_square = sb_size * sb_size;
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100708 const int sb_rows = ALIGN_POWER_OF_TWO(mb_rows, shift) >> shift;
709 const int sb_cols = ALIGN_POWER_OF_TWO(mb_cols, shift) >> shift;
710
Rupert Swarbrickdcb3cff2017-11-09 15:58:33 +0000711 // For transform coefficients, assume planes with no subsampling. We assume
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100712 // up to 1 token per pixel, and then allow a head room of 1 EOSB token per
713 // 4x4 block per plane, plus EOSB_TOKEN per plane.
Rupert Swarbrickdcb3cff2017-11-09 15:58:33 +0000714 const int sb_coeff_toks =
715 num_planes * (sb_size_square + (sb_size_square / 16) + 1);
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100716
717 // For palette coefficients, there can be at most one palette for each 8x8
718 // block. If w, h are the width and height of the block, the palette has at
719 // most 1 + h * w tokens (65 for an 8x8 block) without (see
720 // cost_and_tokenize_map). At most, there can be palettes on two planes.
Yaowu Xue39b3b82017-10-31 16:11:59 -0700721 const int sb_palette_toks = 2 * (1 + 64) * (sb_size_square / 64);
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100722
723 return sb_rows * sb_cols * (sb_coeff_toks + sb_palette_toks);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700724}
725
726// Get the allocated token size for a tile. It does the same calculation as in
727// the frame token allocation.
Rupert Swarbrickdcb3cff2017-11-09 15:58:33 +0000728static INLINE unsigned int allocated_tokens(TileInfo tile, int sb_size_log2,
729 int num_planes) {
Jingning Haneafbd5f2017-03-07 11:18:17 -0800730 int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 2) >> 2;
731 int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 2) >> 2;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700732
Rupert Swarbrickdcb3cff2017-11-09 15:58:33 +0000733 return get_token_alloc(tile_mb_rows, tile_mb_cols, sb_size_log2, num_planes);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700734}
735
Fangwen Fu8d164de2016-12-14 13:40:54 -0800736void av1_set_temporal_mv_prediction(AV1_COMP *cpi, int allow_tempmv_prediction);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700737
Yaowu Xuf883b422016-08-30 14:01:10 -0700738void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700739
Yaowu Xu6da42302017-10-10 14:45:06 -0700740#define ALT_MIN_LAG 3
Yaowu Xuf883b422016-08-30 14:01:10 -0700741static INLINE int is_altref_enabled(const AV1_COMP *const cpi) {
Yaowu Xu6da42302017-10-10 14:45:06 -0700742 return cpi->oxcf.lag_in_frames >= ALT_MIN_LAG && cpi->oxcf.enable_auto_arf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700743}
744
745// TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf
Yaowu Xuc27fc142016-08-22 16:08:15 -0700746
Urvang Joshi52648442016-10-13 17:27:51 -0700747static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700748 MV_REFERENCE_FRAME ref0,
749 MV_REFERENCE_FRAME ref1) {
750 xd->block_refs[0] =
751 &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0];
752 xd->block_refs[1] =
753 &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0];
754}
755
Yaowu Xu4ff59b52017-04-24 12:41:56 -0700756static INLINE int get_chessboard_index(int frame_index) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700757 return frame_index & 0x1;
758}
759
Yaowu Xuf883b422016-08-30 14:01:10 -0700760static INLINE int *cond_cost_list(const struct AV1_COMP *cpi, int *cost_list) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700761 return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
762}
763
Yaowu Xuf883b422016-08-30 14:01:10 -0700764void av1_new_framerate(AV1_COMP *cpi, double framerate);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700765
766#define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
767
768// Update up-sampled reference frame index.
769static INLINE void uref_cnt_fb(EncRefCntBuffer *ubufs, int *uidx,
770 int new_uidx) {
771 const int ref_index = *uidx;
772
773 if (ref_index >= 0 && ubufs[ref_index].ref_count > 0)
774 ubufs[ref_index].ref_count--;
775
776 *uidx = new_uidx;
777 ubufs[new_uidx].ref_count++;
778}
779
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700780// Returns 1 if a frame is unscaled and 0 otherwise.
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700781static INLINE int av1_resize_unscaled(const AV1_COMMON *cm) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700782 return cm->superres_upscaled_width == cm->render_width &&
783 cm->superres_upscaled_height == cm->render_height;
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700784}
785
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700786static INLINE int av1_frame_unscaled(const AV1_COMMON *cm) {
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700787 return av1_superres_unscaled(cm) && av1_resize_unscaled(cm);
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700788}
789
Yaowu Xuc27fc142016-08-22 16:08:15 -0700790#ifdef __cplusplus
791} // extern "C"
792#endif
793
Yaowu Xuf883b422016-08-30 14:01:10 -0700794#endif // AV1_ENCODER_ENCODER_H_