blob: c2a4c3d509a830fcd99abe57e7c59894e09a5462 [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"
26#if CONFIG_ANS
Alex Converseeb780e72016-12-13 12:46:41 -080027#include "aom_dsp/ans.h"
Alex Converse1ac1ae72016-09-17 15:11:16 -070028#include "aom_dsp/buf_ans.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070029#endif
Tom Finegan17ce8b12017-02-08 12:46:31 -080030#include "av1/encoder/av1_quantize.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070031#include "av1/encoder/context_tree.h"
32#include "av1/encoder/encodemb.h"
33#include "av1/encoder/firstpass.h"
34#include "av1/encoder/lookahead.h"
35#include "av1/encoder/mbgraph.h"
36#include "av1/encoder/mcomp.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070037#include "av1/encoder/ratectrl.h"
38#include "av1/encoder/rd.h"
39#include "av1/encoder/speed_features.h"
40#include "av1/encoder/tokenize.h"
Rostislav Pehlivanov002e7b72017-02-15 19:45:54 +000041#if CONFIG_XIPHRC
42#include "av1/encoder/ratectrl_xiph.h"
43#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070044
45#if CONFIG_INTERNAL_STATS
46#include "aom_dsp/ssim.h"
47#endif
48#include "aom_dsp/variance.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070049#include "aom/internal/aom_codec_internal.h"
50#include "aom_util/aom_thread.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070051
52#ifdef __cplusplus
53extern "C" {
54#endif
55
56typedef struct {
James Zern01a9d702017-08-25 19:09:33 +000057 int nmv_vec_cost[NMV_CONTEXTS][MV_JOINTS];
58 int nmv_costs[NMV_CONTEXTS][2][MV_VALS];
59 int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS];
60
Yaowu Xuc27fc142016-08-22 16:08:15 -070061 // 0 = Intra, Last, GF, ARF
Yaowu Xu0fbe33d2017-08-31 09:34:29 -070062 int8_t last_ref_lf_deltas[TOTAL_REFS_PER_FRAME];
Yaowu Xuc27fc142016-08-22 16:08:15 -070063 // 0 = ZERO_MV, MV
Yaowu Xu0fbe33d2017-08-31 09:34:29 -070064 int8_t last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
Yaowu Xuc27fc142016-08-22 16:08:15 -070065
66 FRAME_CONTEXT fc;
67} CODING_CONTEXT;
68
Thomas Daededa4d8b92017-06-05 15:44:14 -070069#if !CONFIG_NO_FRAME_CONTEXT_SIGNALING
Yaowu Xuc27fc142016-08-22 16:08:15 -070070typedef enum {
71 // regular inter frame
72 REGULAR_FRAME = 0,
73 // alternate reference frame
74 ARF_FRAME = 1,
75 // overlay frame
76 OVERLAY_FRAME = 2,
77 // golden frame
78 GLD_FRAME = 3,
Yaowu Xuc27fc142016-08-22 16:08:15 -070079 // backward reference frame
80 BRF_FRAME = 4,
81 // extra alternate reference frame
82 EXT_ARF_FRAME = 5
Yaowu Xuc27fc142016-08-22 16:08:15 -070083} FRAME_CONTEXT_INDEX;
Thomas Daededa4d8b92017-06-05 15:44:14 -070084#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -070085
86typedef enum {
Yaowu Xuc27fc142016-08-22 16:08:15 -070087 NORMAL = 0,
88 FOURFIVE = 1,
89 THREEFIVE = 2,
90 ONETWO = 3
Yaowu Xuf883b422016-08-30 14:01:10 -070091} AOM_SCALING;
Yaowu Xuc27fc142016-08-22 16:08:15 -070092
93typedef enum {
94 // Good Quality Fast Encoding. The encoder balances quality with the amount of
95 // time it takes to encode the output. Speed setting controls how fast.
Thomas Daede80826142017-03-20 15:44:24 -070096 GOOD
Yaowu Xuc27fc142016-08-22 16:08:15 -070097} MODE;
98
99typedef enum {
100 FRAMEFLAGS_KEY = 1 << 0,
101 FRAMEFLAGS_GOLDEN = 1 << 1,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700102 FRAMEFLAGS_BWDREF = 1 << 2,
Zoe Liu3ac20932017-08-30 16:35:55 -0700103 // TODO(zoeliu): To determine whether a frame flag is needed for ALTREF2_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -0700104 FRAMEFLAGS_ALTREF = 1 << 3,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700105} FRAMETYPE_FLAGS;
106
107typedef enum {
108 NO_AQ = 0,
109 VARIANCE_AQ = 1,
110 COMPLEXITY_AQ = 2,
111 CYCLIC_REFRESH_AQ = 3,
Thomas Davies3ab20b42017-09-19 10:30:53 +0100112#if !CONFIG_EXT_DELTA_Q
Arild Fuldseth07441162016-08-15 15:07:52 +0200113 DELTA_AQ = 4,
114#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700115 AQ_MODE_COUNT // This should always be the last member of the enum
116} AQ_MODE;
Fangwen Fu6160df22017-04-24 09:45:51 -0700117#if CONFIG_EXT_DELTA_Q
118typedef enum {
119 NO_DELTA_Q = 0,
120 DELTA_Q_ONLY = 1,
121 DELTA_Q_LF = 2,
122 DELTAQ_MODE_COUNT // This should always be the last member of the enum
123} DELTAQ_MODE;
124#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700125typedef enum {
126 RESIZE_NONE = 0, // No frame resizing allowed.
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700127 RESIZE_FIXED = 1, // All frames are coded at the specified scale.
128 RESIZE_RANDOM = 2, // All frames are coded at a random scale.
129 RESIZE_MODES
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700130} RESIZE_MODE;
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700131#if CONFIG_FRAME_SUPERRES
132typedef enum {
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700133 SUPERRES_NONE = 0, // No frame superres allowed
134 SUPERRES_FIXED = 1, // All frames are coded at the specified scale,
135 // and super-resolved.
136 SUPERRES_RANDOM = 2, // All frames are coded at a random scale,
137 // and super-resolved.
138 SUPERRES_QTHRESH = 3, // Superres scale for a frame is determined based on
139 // q_index
140 SUPERRES_MODES
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700141} SUPERRES_MODE;
142#endif // CONFIG_FRAME_SUPERRES
Yaowu Xuc27fc142016-08-22 16:08:15 -0700143
Yaowu Xuf883b422016-08-30 14:01:10 -0700144typedef struct AV1EncoderConfig {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700145 BITSTREAM_PROFILE profile;
Yaowu Xuf883b422016-08-30 14:01:10 -0700146 aom_bit_depth_t bit_depth; // Codec bit-depth.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700147 int width; // width of data passed to the compressor
148 int height; // height of data passed to the compressor
149 unsigned int input_bit_depth; // Input bit depth.
150 double init_framerate; // set to passed in framerate
151 int64_t target_bandwidth; // bandwidth to be used in bits per second
152
153 int noise_sensitivity; // pre processing blur: recommendation 0
154 int sharpness; // sharpening output: recommendation 0:
155 int speed;
156 // maximum allowed bitrate for any intra frame in % of bitrate target.
157 unsigned int rc_max_intra_bitrate_pct;
158 // maximum allowed bitrate for any inter frame in % of bitrate target.
159 unsigned int rc_max_inter_bitrate_pct;
160 // percent of rate boost for golden frame in CBR mode.
161 unsigned int gf_cbr_boost_pct;
162
163 MODE mode;
164 int pass;
165
166 // Key Framing Operations
167 int auto_key; // autodetect cut scenes and set the keyframes
168 int key_freq; // maximum distance to key frame.
169
170 int lag_in_frames; // how many frames lag before we start encoding
171
172 // ----------------------------------------------------------------
173 // DATARATE CONTROL OPTIONS
174
175 // vbr, cbr, constrained quality or constant quality
Yaowu Xuf883b422016-08-30 14:01:10 -0700176 enum aom_rc_mode rc_mode;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700177
178 // buffer targeting aggressiveness
179 int under_shoot_pct;
180 int over_shoot_pct;
181
182 // buffering parameters
183 int64_t starting_buffer_level_ms;
184 int64_t optimal_buffer_level_ms;
185 int64_t maximum_buffer_size_ms;
186
187 // Frame drop threshold.
188 int drop_frames_water_mark;
189
190 // controlling quality
191 int fixed_q;
192 int worst_allowed_q;
193 int best_allowed_q;
194 int cq_level;
195 AQ_MODE aq_mode; // Adaptive Quantization mode
Fangwen Fu6160df22017-04-24 09:45:51 -0700196#if CONFIG_EXT_DELTA_Q
197 DELTAQ_MODE deltaq_mode;
198#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700199#if CONFIG_AOM_QM
200 int using_qm;
201 int qm_minlevel;
202 int qm_maxlevel;
203#endif
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#if CONFIG_TEMPMV_SIGNALING
211 unsigned int disable_tempmv;
212#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700213 // Internal frame size scaling.
Debargha Mukherjee29e40a62017-06-14 09:37:12 -0700214 RESIZE_MODE resize_mode;
Urvang Joshide71d142017-10-05 12:12:15 -0700215 uint8_t resize_scale_denominator;
216 uint8_t resize_kf_scale_denominator;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700217
Fergus Simpson3502d082017-04-10 12:25:07 -0700218#if CONFIG_FRAME_SUPERRES
Fergus Simpsonc4e78942017-04-10 14:59:00 -0700219 // Frame Super-Resolution size scaling.
220 SUPERRES_MODE superres_mode;
Urvang Joshide71d142017-10-05 12:12:15 -0700221 uint8_t superres_scale_denominator;
222 uint8_t superres_kf_scale_denominator;
Debargha Mukherjee7166f222017-09-05 21:32:42 -0700223 int superres_qthresh;
224 int superres_kf_qthresh;
Fergus Simpson3502d082017-04-10 12:25:07 -0700225#endif // CONFIG_FRAME_SUPERRES
226
Yaowu Xuc27fc142016-08-22 16:08:15 -0700227 // Enable feature to reduce the frame quantization every x frames.
228 int frame_periodic_boost;
229
230 // two pass datarate control
231 int two_pass_vbrbias; // two pass datarate control tweaks
232 int two_pass_vbrmin_section;
233 int two_pass_vbrmax_section;
234 // END DATARATE CONTROL OPTIONS
235 // ----------------------------------------------------------------
236
237 int enable_auto_arf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700238 int enable_auto_brf; // (b)ackward (r)ef (f)rame
Yaowu Xuc27fc142016-08-22 16:08:15 -0700239
Yaowu Xuc27fc142016-08-22 16:08:15 -0700240 /* Bitfield defining the error resiliency features to enable.
241 * Can provide decodable frames after losses in previous
242 * frames and decodable partitions after losses in the same frame.
243 */
244 unsigned int error_resilient_mode;
245
246 /* Bitfield defining the parallel decoding mode where the
247 * decoding in successive frames may be conducted in parallel
248 * just by decoding the frame headers.
249 */
250 unsigned int frame_parallel_decoding_mode;
251
252 int arnr_max_frames;
253 int arnr_strength;
254
255 int min_gf_interval;
256 int max_gf_interval;
257
258 int tile_columns;
259 int tile_rows;
Dominic Symesf58f1112017-09-25 12:47:40 +0200260#if CONFIG_MAX_TILE
Dominic Symes26ad0b22017-10-01 16:35:13 +0200261 int tile_width_count;
262 int tile_height_count;
263 int tile_widths[MAX_TILE_COLS];
264 int tile_heights[MAX_TILE_ROWS];
Dominic Symesf58f1112017-09-25 12:47:40 +0200265#endif
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800266#if CONFIG_DEPENDENT_HORZTILES
267 int dependent_horz_tiles;
268#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800269#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -0800270 int loop_filter_across_tiles_enabled;
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800271#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -0700272
273 int max_threads;
274
Yaowu Xuf883b422016-08-30 14:01:10 -0700275 aom_fixed_buf_t two_pass_stats_in;
276 struct aom_codec_pkt_list *output_pkt_list;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700277
278#if CONFIG_FP_MB_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -0700279 aom_fixed_buf_t firstpass_mb_stats_in;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700280#endif
281
Yaowu Xuf883b422016-08-30 14:01:10 -0700282 aom_tune_metric tuning;
283 aom_tune_content content;
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200284#if CONFIG_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285 int use_highbitdepth;
286#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700287 aom_color_space_t color_space;
anorkin76fb1262017-03-22 15:12:12 -0700288 aom_transfer_function_t transfer_function;
289 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;
293
294#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700295 aom_superblock_size_t superblock_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700296#endif // CONFIG_EXT_PARTITION
Alex Converseeb780e72016-12-13 12:46:41 -0800297#if CONFIG_ANS && ANS_MAX_SYMBOLS
298 int ans_window_size_log2;
299#endif // CONFIG_ANS && ANS_MAX_SYMBOLS
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800300#if CONFIG_EXT_TILE
Yunqing Wangeeb08a92017-07-07 21:25:18 -0700301 unsigned int large_scale_tile;
302 unsigned int single_tile_decoding;
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800303#endif // CONFIG_EXT_TILE
Yunqing Wangff4fa062017-04-21 10:56:08 -0700304
305 unsigned int motion_vector_unit_test;
Yaowu Xuf883b422016-08-30 14:01:10 -0700306} AV1EncoderConfig;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700307
Yaowu Xuf883b422016-08-30 14:01:10 -0700308static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700309 return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
310}
311
312// TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
313typedef struct TileDataEnc {
314 TileInfo tile_info;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100315 int thresh_freq_fact[BLOCK_SIZES_ALL][MAX_MODES];
316 int mode_map[BLOCK_SIZES_ALL][MAX_MODES];
Yunqing Wang8c1e57c2016-10-25 15:15:23 -0700317 int m_search_count;
318 int ex_search_count;
Luc Trudeauf8164152017-04-11 16:20:51 -0400319#if CONFIG_CFL
320 CFL_CTX cfl;
321#endif
Jingning Han9f07be12017-04-13 09:31:40 -0700322 DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx);
Yunqing Wang0e141b52017-11-02 15:08:58 -0700323 uint8_t allow_update_cdf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700324} TileDataEnc;
325
326typedef struct RD_COUNTS {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700327 int64_t comp_pred_diff[REFERENCE_MODES];
Debargha Mukherjeea575d232017-04-28 17:46:47 -0700328 // Stores number of 4x4 blocks using global motion per reference frame.
329 int global_motion_used[TOTAL_REFS_PER_FRAME];
Arild Fuldseth (arilfuld)6c20c782017-06-15 09:45:02 +0200330 int single_ref_used_flag;
331 int compound_ref_used_flag;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700332} RD_COUNTS;
333
334typedef struct ThreadData {
335 MACROBLOCK mb;
336 RD_COUNTS rd_counts;
337 FRAME_COUNTS *counts;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700338 PC_TREE *pc_tree;
339 PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1];
Jingning Hand064cf02017-06-01 10:00:39 -0700340 int32_t *wsrc_buf;
341 int32_t *mask_buf;
342 uint8_t *above_pred_buf;
343 uint8_t *left_pred_buf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700344
hui su5d493142017-05-08 12:06:12 -0700345 PALETTE_BUFFER *palette_buffer;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700346} ThreadData;
347
348struct EncWorkerData;
349
350typedef struct ActiveMap {
351 int enabled;
352 int update;
353 unsigned char *map;
354} ActiveMap;
355
Urvang Joshib5ed3502016-10-17 16:38:05 -0700356#define NUM_STAT_TYPES 4 // types of stats: Y, U, V and ALL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700357
358typedef struct IMAGE_STAT {
Urvang Joshib5ed3502016-10-17 16:38:05 -0700359 double stat[NUM_STAT_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700360 double worst;
361} ImageStat;
362
Urvang Joshib5ed3502016-10-17 16:38:05 -0700363#undef NUM_STAT_TYPES
364
Yaowu Xuc27fc142016-08-22 16:08:15 -0700365typedef struct {
366 int ref_count;
367 YV12_BUFFER_CONFIG buf;
368} EncRefCntBuffer;
369
Yaowu Xuc27fc142016-08-22 16:08:15 -0700370typedef struct TileBufferEnc {
371 uint8_t *data;
372 size_t size;
373} TileBufferEnc;
374
Yaowu Xuf883b422016-08-30 14:01:10 -0700375typedef struct AV1_COMP {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700376 QUANTS quants;
377 ThreadData td;
378 MB_MODE_INFO_EXT *mbmi_ext_base;
Jingning Hanf5a4d3b2017-08-27 23:01:19 -0700379#if CONFIG_LV_MAP
380 CB_COEFF_BUFFER *coeff_buffer_base;
381#endif
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
Alex Conversef77fd0b2017-04-20 11:00:24 -0700388 YV12_BUFFER_CONFIG *source;
389 YV12_BUFFER_CONFIG *last_source; // NULL for first frame and alt_ref frames
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700390 YV12_BUFFER_CONFIG *unscaled_source;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700391 YV12_BUFFER_CONFIG scaled_source;
392 YV12_BUFFER_CONFIG *unscaled_last_source;
393 YV12_BUFFER_CONFIG scaled_last_source;
394
Yaowu Xuc27fc142016-08-22 16:08:15 -0700395 // For a still frame, this flag is set to 1 to skip partition search.
396 int partition_search_skippable_frame;
RogerZhou3b635242017-09-19 10:06:46 -0700397#if CONFIG_AMVR
398 double csm_rate_array[32];
399 double m_rate_array[32];
400 int rate_size;
401 int rate_index;
402 hash_table *previsou_hash_table;
403 int previsous_index;
404 int cur_poc; // DebugInfo
405#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700406
407 int scaled_ref_idx[TOTAL_REFS_PER_FRAME];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700408 int lst_fb_idxes[LAST_REF_FRAMES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700409 int gld_fb_idx;
Zoe Liu3ac20932017-08-30 16:35:55 -0700410 int bwd_fb_idx; // BWDREF_FRAME
Zoe Liue9b15e22017-07-19 15:53:01 -0700411 int alt2_fb_idx; // ALTREF2_FRAME
Yaowu Xuc27fc142016-08-22 16:08:15 -0700412 int alt_fb_idx;
Zoe Liu8dd1c982017-09-11 10:14:35 -0700413 int ext_fb_idx; // extra ref frame buffer index
414 int refresh_fb_idx; // ref frame buffer index to refresh
Yaowu Xuc27fc142016-08-22 16:08:15 -0700415
416 int last_show_frame_buf_idx; // last show frame buffer index
417
418 int refresh_last_frame;
419 int refresh_golden_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700420 int refresh_bwd_ref_frame;
Zoe Liue9b15e22017-07-19 15:53:01 -0700421 int refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700422 int refresh_alt_ref_frame;
423
424 int ext_refresh_frame_flags_pending;
425 int ext_refresh_last_frame;
426 int ext_refresh_golden_frame;
Yunqing Wang9a50fec2017-11-02 17:02:00 -0700427 int ext_refresh_bwd_ref_frame;
428 int ext_refresh_alt2_ref_frame;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700429 int ext_refresh_alt_ref_frame;
430
431 int ext_refresh_frame_context_pending;
432 int ext_refresh_frame_context;
433
434 YV12_BUFFER_CONFIG last_frame_uf;
435#if CONFIG_LOOP_RESTORATION
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800436 YV12_BUFFER_CONFIG trial_frame_rst;
Rupert Swarbrick1a96c3f2017-10-24 11:55:00 +0100437#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700438
439 // Ambient reconstruction err target for force key frames
440 int64_t ambient_err;
441
442 RD_OPT rd;
443
444 CODING_CONTEXT coding_context;
445
Yue Chenb23d00a2017-07-28 17:01:21 -0700446 int gmtype_cost[TRANS_TYPES];
447 int gmparams_cost[TOTAL_REFS_PER_FRAME];
Yue Chenb23d00a2017-07-28 17:01:21 -0700448
James Zern01a9d702017-08-25 19:09:33 +0000449 int nmv_costs[NMV_CONTEXTS][2][MV_VALS];
450 int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS];
451
Yaowu Xuc27fc142016-08-22 16:08:15 -0700452 int64_t last_time_stamp_seen;
453 int64_t last_end_time_stamp_seen;
454 int64_t first_time_stamp_ever;
455
456 RATE_CONTROL rc;
Rostislav Pehlivanov002e7b72017-02-15 19:45:54 +0000457#if CONFIG_XIPHRC
458 od_rc_state od_rc;
459#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700460 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;
Zoe Liuf452fdf2017-11-02 23:08:12 -0700473#if CONFIG_FRAME_MARKER
474 RATE_FACTOR_LEVEL frame_rf_level[FRAME_BUFFERS];
475#endif // CONFIG_FRAME_MARKER
Yaowu Xuc27fc142016-08-22 16:08:15 -0700476
477 SPEED_FEATURES sf;
478
479 unsigned int max_mv_magnitude;
480 int mv_step_param;
481
482 int allow_comp_inter_inter;
Zoe Liu77fb5be2017-11-02 14:36:19 -0700483#if CONFIG_FRAME_MARKER
484 int all_one_sided_refs;
485#endif // CONFIG_FARME_MARKER
Yaowu Xuc27fc142016-08-22 16:08:15 -0700486
Yaowu Xuc27fc142016-08-22 16:08:15 -0700487 uint8_t *segmentation_map;
488
Yaowu Xuc27fc142016-08-22 16:08:15 -0700489 CYCLIC_REFRESH *cyclic_refresh;
490 ActiveMap active_map;
491
492 fractional_mv_step_fp *find_fractional_mv_step;
Yaowu Xuf883b422016-08-30 14:01:10 -0700493 av1_full_search_fn_t full_search_sad; // It is currently unused.
494 av1_diamond_search_fn_t diamond_search_sad;
Rupert Swarbrick93c39e92017-07-12 11:11:02 +0100495 aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES_ALL];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700496 uint64_t time_receive_data;
497 uint64_t time_compress_data;
498 uint64_t time_pick_lpf;
499 uint64_t time_encode_sb_row;
500
501#if CONFIG_FP_MB_STATS
502 int use_fp_mb_stats;
503#endif
504
505 TWO_PASS twopass;
506
507 YV12_BUFFER_CONFIG alt_ref_buffer;
508
509#if CONFIG_INTERNAL_STATS
510 unsigned int mode_chosen_counts[MAX_MODES];
511
512 int count;
513 uint64_t total_sq_error;
514 uint64_t total_samples;
515 ImageStat psnr;
516
517 double total_blockiness;
518 double worst_blockiness;
519
520 int bytes;
521 double summed_quality;
522 double summed_weights;
523 unsigned int tot_recode_hits;
524 double worst_ssim;
525
526 ImageStat fastssim;
527 ImageStat psnrhvs;
528
529 int b_calculate_blockiness;
530 int b_calculate_consistency;
531
532 double total_inconsistency;
533 double worst_consistency;
534 Ssimv *ssim_vars;
535 Metrics metrics;
536#endif
537 int b_calculate_psnr;
538
539 int droppable;
540
541 int initial_width;
542 int initial_height;
543 int initial_mbs; // Number of MBs in the full-size frame; to be used to
544 // normalize the firstpass stats. This will differ from the
545 // number of MBs in the current frame when the frame is
546 // scaled.
547
Debargha Mukherjeeccb27262017-09-25 14:19:46 -0700548 // When resize is triggered through external control, the desired width/height
549 // are stored here until use in the next frame coded. They are effective only
550 // for
551 // one frame and are reset after use.
552 int resize_pending_width;
553 int resize_pending_height;
554
Yaowu Xuc27fc142016-08-22 16:08:15 -0700555 int frame_flags;
556
557 search_site_config ss_cfg;
558
Yaowu Xuc27fc142016-08-22 16:08:15 -0700559 int multi_arf_allowed;
560 int multi_arf_enabled;
561 int multi_arf_last_grp_enabled;
562
563 TileDataEnc *tile_data;
564 int allocated_tiles; // Keep track of memory allocated for tiles.
565
566 TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS];
567 unsigned int tok_count[MAX_TILE_ROWS][MAX_TILE_COLS];
568
569 TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS];
570
Yaowu Xuc27fc142016-08-22 16:08:15 -0700571 int resize_state;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700572 int resize_avg_qp;
573 int resize_buffer_underflow;
574 int resize_count;
575
Yaowu Xuc27fc142016-08-22 16:08:15 -0700576 // VARIANCE_AQ segment map refresh
577 int vaq_refresh;
578
579 // Multi-threading
580 int num_workers;
Yaowu Xuf883b422016-08-30 14:01:10 -0700581 AVxWorker *workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700582 struct EncWorkerData *tile_thr_data;
Yaowu Xuf883b422016-08-30 14:01:10 -0700583 AV1LfSync lf_row_sync;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700584#if CONFIG_ANS
585 struct BufAnsCoder buf_ans;
586#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700587 int refresh_frame_mask;
588 int existing_fb_idx_to_show;
589 int is_arf_filter_off[MAX_EXT_ARFS + 1];
590 int num_extra_arfs;
591 int arf_map[MAX_EXT_ARFS + 1];
Zoe Liuf271a952017-09-05 15:03:48 -0700592 int arf_pos_in_gf[MAX_EXT_ARFS + 1];
593 int arf_pos_for_ovrly[MAX_EXT_ARFS + 1];
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -0800594 int global_motion_search_done;
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700595#if CONFIG_LV_MAP
596 tran_low_t *tcoeff_buf[MAX_MB_PLANE];
597#endif
Zoe Liud1ac0322017-06-05 13:59:12 -0700598
Di Chen53a04f62017-06-23 13:47:56 -0700599 int extra_arf_allowed;
600 int bwd_ref_allowed;
Todd Nguyen71efd842017-08-09 14:33:42 -0700601
602#if CONFIG_BGSPRITE
603 int bgsprite_allowed;
604#endif // CONFIG_BGSPRITE
Yaowu Xuf883b422016-08-30 14:01:10 -0700605} AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700606
Yaowu Xuf883b422016-08-30 14:01:10 -0700607void av1_initialize_enc(void);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700608
Yaowu Xuf883b422016-08-30 14:01:10 -0700609struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
610 BufferPool *const pool);
611void av1_remove_compressor(AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700612
Yaowu Xuf883b422016-08-30 14:01:10 -0700613void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700614
615// receive a frames worth of data. caller can assume that a copy of this
616// frame is made and not just a copy of the pointer..
James Zern3e2613b2017-03-30 23:14:40 -0700617int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
Yaowu Xuf883b422016-08-30 14:01:10 -0700618 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
619 int64_t end_time_stamp);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700620
Yaowu Xuf883b422016-08-30 14:01:10 -0700621int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
622 size_t *size, uint8_t *dest, int64_t *time_stamp,
623 int64_t *time_end, int flush);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700624
Yaowu Xuf883b422016-08-30 14:01:10 -0700625int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700626
Yaowu Xuf883b422016-08-30 14:01:10 -0700627int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700628
Yaowu Xuf883b422016-08-30 14:01:10 -0700629int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700630
Yaowu Xuf883b422016-08-30 14:01:10 -0700631void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700632
Thomas Daede497d1952017-08-08 17:33:06 -0700633int av1_copy_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700634
Thomas Daede497d1952017-08-08 17:33:06 -0700635int av1_set_reference_enc(AV1_COMP *cpi, int idx, YV12_BUFFER_CONFIG *sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700636
Yaowu Xuf883b422016-08-30 14:01:10 -0700637int av1_update_entropy(AV1_COMP *cpi, int update);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700638
Yaowu Xuf883b422016-08-30 14:01:10 -0700639int av1_set_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_get_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700642
Yaowu Xuf883b422016-08-30 14:01:10 -0700643int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode,
644 AOM_SCALING vert_mode);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700645
Yaowu Xuf883b422016-08-30 14:01:10 -0700646int av1_get_quantizer(struct AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700647
Yaowu Xuf883b422016-08-30 14:01:10 -0700648static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700649 return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
650 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
651}
652
Yaowu Xuf883b422016-08-30 14:01:10 -0700653static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700654 MV_REFERENCE_FRAME ref_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700655 if (ref_frame >= LAST_FRAME && ref_frame <= LAST3_FRAME)
656 return cpi->lst_fb_idxes[ref_frame - 1];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700657 else if (ref_frame == GOLDEN_FRAME)
658 return cpi->gld_fb_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700659 else if (ref_frame == BWDREF_FRAME)
660 return cpi->bwd_fb_idx;
Zoe Liue9b15e22017-07-19 15:53:01 -0700661 else if (ref_frame == ALTREF2_FRAME)
662 return cpi->alt2_fb_idx;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700663 else
664 return cpi->alt_fb_idx;
665}
666
Urvang Joshi52648442016-10-13 17:27:51 -0700667static INLINE int get_ref_frame_buf_idx(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700668 MV_REFERENCE_FRAME ref_frame) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700669 const AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700670 const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
671 return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
672}
673
RogerZhoucc5d35d2017-08-07 22:20:15 -0700674#if CONFIG_HASH_ME
675static INLINE hash_table *get_ref_frame_hash_map(const AV1_COMP *cpi,
676 MV_REFERENCE_FRAME ref_frame) {
677 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}
683#endif
684
Yaowu Xuc27fc142016-08-22 16:08:15 -0700685static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
Urvang Joshi52648442016-10-13 17:27:51 -0700686 const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
687 const AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700688 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
689 return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf
690 : NULL;
691}
692
Yaowu Xuf883b422016-08-30 14:01:10 -0700693static INLINE int enc_is_ref_frame_buf(AV1_COMP *cpi, RefCntBuffer *frame_buf) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700694 MV_REFERENCE_FRAME ref_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -0700695 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700696 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
697 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
698 if (buf_idx == INVALID_IDX) continue;
699 if (frame_buf == &cm->buffer_pool->frame_bufs[buf_idx]) break;
700 }
701 return (ref_frame <= ALTREF_FRAME);
702}
Yaowu Xuc27fc142016-08-22 16:08:15 -0700703
Yaowu Xue39b3b82017-10-31 16:11:59 -0700704static INLINE unsigned int get_token_alloc(int mb_rows, int mb_cols,
705 int sb_size_log2) {
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100706 // Calculate the maximum number of max superblocks in the image.
Yaowu Xue39b3b82017-10-31 16:11:59 -0700707 const int shift = sb_size_log2 - 4;
708 const int sb_size = 1 << sb_size_log2;
709 const int sb_size_square = sb_size * sb_size;
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100710 const int sb_rows = ALIGN_POWER_OF_TWO(mb_rows, shift) >> shift;
711 const int sb_cols = ALIGN_POWER_OF_TWO(mb_cols, shift) >> shift;
712
713 // For transform coefficients, assume 3 planes with no subsampling. We assume
714 // up to 1 token per pixel, and then allow a head room of 1 EOSB token per
715 // 4x4 block per plane, plus EOSB_TOKEN per plane.
Yaowu Xue39b3b82017-10-31 16:11:59 -0700716 const int sb_coeff_toks = 3 * (sb_size_square + (sb_size_square / 16) + 1);
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100717
718 // For palette coefficients, there can be at most one palette for each 8x8
719 // block. If w, h are the width and height of the block, the palette has at
720 // most 1 + h * w tokens (65 for an 8x8 block) without (see
721 // cost_and_tokenize_map). At most, there can be palettes on two planes.
Yaowu Xue39b3b82017-10-31 16:11:59 -0700722 const int sb_palette_toks = 2 * (1 + 64) * (sb_size_square / 64);
Rupert Swarbrickce63e832017-10-25 17:54:17 +0100723
724 return sb_rows * sb_cols * (sb_coeff_toks + sb_palette_toks);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700725}
726
727// Get the allocated token size for a tile. It does the same calculation as in
728// the frame token allocation.
Yaowu Xue39b3b82017-10-31 16:11:59 -0700729static INLINE unsigned int allocated_tokens(TileInfo tile, int sb_size_log2) {
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
Yaowu Xue39b3b82017-10-31 16:11:59 -0700733 return get_token_alloc(tile_mb_rows, tile_mb_cols, sb_size_log2);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700734}
735
Fangwen Fu8d164de2016-12-14 13:40:54 -0800736#if CONFIG_TEMPMV_SIGNALING
737void av1_set_temporal_mv_prediction(AV1_COMP *cpi, int allow_tempmv_prediction);
738#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700739
Yaowu Xuf883b422016-08-30 14:01:10 -0700740void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700741
Yaowu Xu6da42302017-10-10 14:45:06 -0700742#define ALT_MIN_LAG 3
Yaowu Xuf883b422016-08-30 14:01:10 -0700743static INLINE int is_altref_enabled(const AV1_COMP *const cpi) {
Yaowu Xu6da42302017-10-10 14:45:06 -0700744 return cpi->oxcf.lag_in_frames >= ALT_MIN_LAG && cpi->oxcf.enable_auto_arf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700745}
746
747// TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf
748#if 0 && CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -0700749static INLINE int is_bwdref_enabled(const AV1_COMP *const cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700750 // NOTE(zoeliu): The enabling of bi-predictive frames depends on the use of
751 // alt_ref, and now will be off when the alt_ref interval is
752 // not sufficiently large.
753 return is_altref_enabled(cpi) && cpi->oxcf.enable_auto_brf;
754}
755#endif // CONFIG_EXT_REFS
756
Urvang Joshi52648442016-10-13 17:27:51 -0700757static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700758 MV_REFERENCE_FRAME ref0,
759 MV_REFERENCE_FRAME ref1) {
760 xd->block_refs[0] =
761 &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0];
762 xd->block_refs[1] =
763 &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0];
764}
765
Yaowu Xu4ff59b52017-04-24 12:41:56 -0700766static INLINE int get_chessboard_index(int frame_index) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700767 return frame_index & 0x1;
768}
769
Yaowu Xuf883b422016-08-30 14:01:10 -0700770static INLINE int *cond_cost_list(const struct AV1_COMP *cpi, int *cost_list) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700771 return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
772}
773
Yaowu Xuf883b422016-08-30 14:01:10 -0700774void av1_new_framerate(AV1_COMP *cpi, double framerate);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700775
776#define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
777
778// Update up-sampled reference frame index.
779static INLINE void uref_cnt_fb(EncRefCntBuffer *ubufs, int *uidx,
780 int new_uidx) {
781 const int ref_index = *uidx;
782
783 if (ref_index >= 0 && ubufs[ref_index].ref_count > 0)
784 ubufs[ref_index].ref_count--;
785
786 *uidx = new_uidx;
787 ubufs[new_uidx].ref_count++;
788}
789
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700790// Returns 1 if a frame is unscaled and 0 otherwise.
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700791static INLINE int av1_resize_unscaled(const AV1_COMMON *cm) {
792#if CONFIG_FRAME_SUPERRES
793 return cm->superres_upscaled_width == cm->render_width &&
794 cm->superres_upscaled_height == cm->render_height;
795#else
796 return cm->width == cm->render_width && cm->height == cm->render_height;
797#endif // CONFIG_FRAME_SUPERRES
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700798}
799
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700800static INLINE int av1_frame_unscaled(const AV1_COMMON *cm) {
801#if CONFIG_FRAME_SUPERRES
802 return av1_superres_unscaled(cm) && av1_resize_unscaled(cm);
803#else
804 return av1_resize_unscaled(cm);
805#endif // CONFIG_FRAME_SUPERRES
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700806}
807
Yaowu Xuc27fc142016-08-22 16:08:15 -0700808#ifdef __cplusplus
809} // extern "C"
810#endif
811
Yaowu Xuf883b422016-08-30 14:01:10 -0700812#endif // AV1_ENCODER_ENCODER_H_