blob: 70de507a9a2713f5f59a7f7c4a518cfc3ea6c7af [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 {
Yaowu Xuc27fc142016-08-22 16:08:15 -070057 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];
Yaowu Xuc27fc142016-08-22 16:08:15 -070060
Yaowu Xuc27fc142016-08-22 16:08:15 -070061 // 0 = Intra, Last, GF, ARF
62 signed char last_ref_lf_deltas[TOTAL_REFS_PER_FRAME];
63 // 0 = ZERO_MV, MV
64 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
65
66 FRAME_CONTEXT fc;
67} CODING_CONTEXT;
68
69typedef enum {
70 // regular inter frame
71 REGULAR_FRAME = 0,
72 // alternate reference frame
73 ARF_FRAME = 1,
74 // overlay frame
75 OVERLAY_FRAME = 2,
76 // golden frame
77 GLD_FRAME = 3,
78#if CONFIG_EXT_REFS
79 // backward reference frame
80 BRF_FRAME = 4,
81 // extra alternate reference frame
82 EXT_ARF_FRAME = 5
83#endif
84} FRAME_CONTEXT_INDEX;
85
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,
102#if CONFIG_EXT_REFS
103 FRAMEFLAGS_BWDREF = 1 << 2,
104 FRAMEFLAGS_ALTREF = 1 << 3,
105#else
106 FRAMEFLAGS_ALTREF = 1 << 2,
107#endif // CONFIG_EXT_REFS
108} FRAMETYPE_FLAGS;
109
110typedef enum {
111 NO_AQ = 0,
112 VARIANCE_AQ = 1,
113 COMPLEXITY_AQ = 2,
114 CYCLIC_REFRESH_AQ = 3,
Fangwen Fu6160df22017-04-24 09:45:51 -0700115#if CONFIG_DELTA_Q && !CONFIG_EXT_DELTA_Q
Arild Fuldseth07441162016-08-15 15:07:52 +0200116 DELTA_AQ = 4,
117#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700118 AQ_MODE_COUNT // This should always be the last member of the enum
119} AQ_MODE;
Fangwen Fu6160df22017-04-24 09:45:51 -0700120#if CONFIG_EXT_DELTA_Q
121typedef enum {
122 NO_DELTA_Q = 0,
123 DELTA_Q_ONLY = 1,
124 DELTA_Q_LF = 2,
125 DELTAQ_MODE_COUNT // This should always be the last member of the enum
126} DELTAQ_MODE;
127#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700128typedef enum {
129 RESIZE_NONE = 0, // No frame resizing allowed.
130 RESIZE_FIXED = 1, // All frames are coded at the specified dimension.
131 RESIZE_DYNAMIC = 2 // Coded size of each frame is determined by the codec.
132} RESIZE_TYPE;
133
Yaowu Xuf883b422016-08-30 14:01:10 -0700134typedef struct AV1EncoderConfig {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700135 BITSTREAM_PROFILE profile;
Yaowu Xuf883b422016-08-30 14:01:10 -0700136 aom_bit_depth_t bit_depth; // Codec bit-depth.
Yaowu Xuc27fc142016-08-22 16:08:15 -0700137 int width; // width of data passed to the compressor
138 int height; // height of data passed to the compressor
139 unsigned int input_bit_depth; // Input bit depth.
140 double init_framerate; // set to passed in framerate
141 int64_t target_bandwidth; // bandwidth to be used in bits per second
142
143 int noise_sensitivity; // pre processing blur: recommendation 0
144 int sharpness; // sharpening output: recommendation 0:
145 int speed;
146 // maximum allowed bitrate for any intra frame in % of bitrate target.
147 unsigned int rc_max_intra_bitrate_pct;
148 // maximum allowed bitrate for any inter frame in % of bitrate target.
149 unsigned int rc_max_inter_bitrate_pct;
150 // percent of rate boost for golden frame in CBR mode.
151 unsigned int gf_cbr_boost_pct;
152
153 MODE mode;
154 int pass;
155
156 // Key Framing Operations
157 int auto_key; // autodetect cut scenes and set the keyframes
158 int key_freq; // maximum distance to key frame.
159
160 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#if CONFIG_EXT_DELTA_Q
187 DELTAQ_MODE deltaq_mode;
188#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700189#if CONFIG_AOM_QM
190 int using_qm;
191 int qm_minlevel;
192 int qm_maxlevel;
193#endif
Thomas Daviesaf6df172016-11-09 14:04:18 +0000194#if CONFIG_TILE_GROUPS
195 unsigned int num_tile_groups;
196 unsigned int mtu;
197#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700198
Fangwen Fu8d164de2016-12-14 13:40:54 -0800199#if CONFIG_TEMPMV_SIGNALING
200 unsigned int disable_tempmv;
201#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700202 // Internal frame size scaling.
203 RESIZE_TYPE resize_mode;
204 int scaled_frame_width;
205 int scaled_frame_height;
206
Fergus Simpson3502d082017-04-10 12:25:07 -0700207#if CONFIG_FRAME_SUPERRES
208 // Frame Super-Resolution size scaling
209 int superres_enabled;
210#endif // CONFIG_FRAME_SUPERRES
211
Yaowu Xuc27fc142016-08-22 16:08:15 -0700212 // Enable feature to reduce the frame quantization every x frames.
213 int frame_periodic_boost;
214
215 // two pass datarate control
216 int two_pass_vbrbias; // two pass datarate control tweaks
217 int two_pass_vbrmin_section;
218 int two_pass_vbrmax_section;
219 // END DATARATE CONTROL OPTIONS
220 // ----------------------------------------------------------------
221
222 int enable_auto_arf;
223#if CONFIG_EXT_REFS
224 int enable_auto_brf; // (b)ackward (r)ef (f)rame
225#endif // CONFIG_EXT_REFS
226
Yaowu Xuc27fc142016-08-22 16:08:15 -0700227 /* Bitfield defining the error resiliency features to enable.
228 * Can provide decodable frames after losses in previous
229 * frames and decodable partitions after losses in the same frame.
230 */
231 unsigned int error_resilient_mode;
232
233 /* Bitfield defining the parallel decoding mode where the
234 * decoding in successive frames may be conducted in parallel
235 * just by decoding the frame headers.
236 */
237 unsigned int frame_parallel_decoding_mode;
238
239 int arnr_max_frames;
240 int arnr_strength;
241
242 int min_gf_interval;
243 int max_gf_interval;
244
245 int tile_columns;
246 int tile_rows;
Fangwen Fu7b9f2b32017-01-17 14:01:52 -0800247#if CONFIG_DEPENDENT_HORZTILES
248 int dependent_horz_tiles;
249#endif
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800250#if CONFIG_LOOPFILTERING_ACROSS_TILES
Ryan Lei7386eda2016-12-08 21:08:31 -0800251 int loop_filter_across_tiles_enabled;
Ryan Lei9b02b0e2017-01-30 15:52:20 -0800252#endif // CONFIG_LOOPFILTERING_ACROSS_TILES
Yaowu Xuc27fc142016-08-22 16:08:15 -0700253
254 int max_threads;
255
Yaowu Xuf883b422016-08-30 14:01:10 -0700256 aom_fixed_buf_t two_pass_stats_in;
257 struct aom_codec_pkt_list *output_pkt_list;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700258
259#if CONFIG_FP_MB_STATS
Yaowu Xuf883b422016-08-30 14:01:10 -0700260 aom_fixed_buf_t firstpass_mb_stats_in;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700261#endif
262
Yaowu Xuf883b422016-08-30 14:01:10 -0700263 aom_tune_metric tuning;
264 aom_tune_content content;
Sebastien Alaiwan71e87842017-04-12 16:03:28 +0200265#if CONFIG_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -0700266 int use_highbitdepth;
267#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700268 aom_color_space_t color_space;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700269 int color_range;
270 int render_width;
271 int render_height;
272
273#if CONFIG_EXT_PARTITION
Yaowu Xuf883b422016-08-30 14:01:10 -0700274 aom_superblock_size_t superblock_size;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700275#endif // CONFIG_EXT_PARTITION
Alex Converseeb780e72016-12-13 12:46:41 -0800276#if CONFIG_ANS && ANS_MAX_SYMBOLS
277 int ans_window_size_log2;
278#endif // CONFIG_ANS && ANS_MAX_SYMBOLS
Yunqing Wangd8cd55f2017-02-27 12:16:00 -0800279#if CONFIG_EXT_TILE
280 unsigned int tile_encoding_mode;
281#endif // CONFIG_EXT_TILE
Yunqing Wangff4fa062017-04-21 10:56:08 -0700282
283 unsigned int motion_vector_unit_test;
Yaowu Xuf883b422016-08-30 14:01:10 -0700284} AV1EncoderConfig;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700285
Yaowu Xuf883b422016-08-30 14:01:10 -0700286static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700287 return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
288}
289
290// TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
291typedef struct TileDataEnc {
292 TileInfo tile_info;
293 int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
294 int mode_map[BLOCK_SIZES][MAX_MODES];
Yunqing Wang8c1e57c2016-10-25 15:15:23 -0700295 int m_search_count;
296 int ex_search_count;
Yushin Cho77bba8d2016-11-04 16:36:56 -0700297#if CONFIG_PVQ
298 PVQ_QUEUE pvq_q;
299#endif
Luc Trudeauf8164152017-04-11 16:20:51 -0400300#if CONFIG_CFL
301 CFL_CTX cfl;
302#endif
Thomas Daviesf77d4ad2017-01-10 18:55:42 +0000303#if CONFIG_EC_ADAPT
Jingning Han9f07be12017-04-13 09:31:40 -0700304 DECLARE_ALIGNED(16, FRAME_CONTEXT, tctx);
Thomas Daviesf77d4ad2017-01-10 18:55:42 +0000305#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700306} TileDataEnc;
307
308typedef struct RD_COUNTS {
Yaowu Xuf883b422016-08-30 14:01:10 -0700309 av1_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700310 int64_t comp_pred_diff[REFERENCE_MODES];
Debargha Mukherjeea575d232017-04-28 17:46:47 -0700311#if CONFIG_GLOBAL_MOTION
312 // Stores number of 4x4 blocks using global motion per reference frame.
313 int global_motion_used[TOTAL_REFS_PER_FRAME];
314#endif // CONFIG_GLOBAL_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700315} RD_COUNTS;
316
317typedef struct ThreadData {
318 MACROBLOCK mb;
319 RD_COUNTS rd_counts;
320 FRAME_COUNTS *counts;
321
322 PICK_MODE_CONTEXT *leaf_tree;
323 PC_TREE *pc_tree;
324 PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1];
Jingning Hand064cf02017-06-01 10:00:39 -0700325#if CONFIG_MOTION_VAR
326 int32_t *wsrc_buf;
327 int32_t *mask_buf;
328 uint8_t *above_pred_buf;
329 uint8_t *left_pred_buf;
330#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700331
hui su5d493142017-05-08 12:06:12 -0700332#if CONFIG_PALETTE
333 PALETTE_BUFFER *palette_buffer;
334#endif // CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700335} ThreadData;
336
337struct EncWorkerData;
338
339typedef struct ActiveMap {
340 int enabled;
341 int update;
342 unsigned char *map;
343} ActiveMap;
344
Urvang Joshib5ed3502016-10-17 16:38:05 -0700345#define NUM_STAT_TYPES 4 // types of stats: Y, U, V and ALL
Yaowu Xuc27fc142016-08-22 16:08:15 -0700346
347typedef struct IMAGE_STAT {
Urvang Joshib5ed3502016-10-17 16:38:05 -0700348 double stat[NUM_STAT_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700349 double worst;
350} ImageStat;
351
Urvang Joshib5ed3502016-10-17 16:38:05 -0700352#undef NUM_STAT_TYPES
353
Yaowu Xuc27fc142016-08-22 16:08:15 -0700354typedef struct {
355 int ref_count;
356 YV12_BUFFER_CONFIG buf;
357} EncRefCntBuffer;
358
Yaowu Xuc27fc142016-08-22 16:08:15 -0700359typedef struct TileBufferEnc {
360 uint8_t *data;
361 size_t size;
362} TileBufferEnc;
363
Yaowu Xuf883b422016-08-30 14:01:10 -0700364typedef struct AV1_COMP {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700365 QUANTS quants;
366 ThreadData td;
367 MB_MODE_INFO_EXT *mbmi_ext_base;
Yi Luoc6210232017-05-25 15:09:25 -0700368 Dequants dequants;
Yaowu Xuf883b422016-08-30 14:01:10 -0700369 AV1_COMMON common;
370 AV1EncoderConfig oxcf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700371 struct lookahead_ctx *lookahead;
372 struct lookahead_entry *alt_ref_source;
373
Alex Conversef77fd0b2017-04-20 11:00:24 -0700374 YV12_BUFFER_CONFIG *source;
375 YV12_BUFFER_CONFIG *last_source; // NULL for first frame and alt_ref frames
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700376 YV12_BUFFER_CONFIG *unscaled_source;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700377 YV12_BUFFER_CONFIG scaled_source;
378 YV12_BUFFER_CONFIG *unscaled_last_source;
379 YV12_BUFFER_CONFIG scaled_last_source;
380
381 // Up-sampled reference buffers
382 // NOTE(zoeliu): It is needed to allocate sufficient space to the up-sampled
383 // reference buffers, which should include the up-sampled version of all the
384 // possibly stored references plus the currently coded frame itself.
385 EncRefCntBuffer upsampled_ref_bufs[REF_FRAMES + 1];
386 int upsampled_ref_idx[REF_FRAMES + 1];
387
388 // For a still frame, this flag is set to 1 to skip partition search.
389 int partition_search_skippable_frame;
390
391 int scaled_ref_idx[TOTAL_REFS_PER_FRAME];
392#if CONFIG_EXT_REFS
393 int lst_fb_idxes[LAST_REF_FRAMES];
394#else
395 int lst_fb_idx;
396#endif // CONFIG_EXT_REFS
397 int gld_fb_idx;
398#if CONFIG_EXT_REFS
399 int bwd_fb_idx; // BWD_REF_FRAME
400#endif // CONFIG_EXT_REFS
401 int alt_fb_idx;
402
403 int last_show_frame_buf_idx; // last show frame buffer index
404
405 int refresh_last_frame;
406 int refresh_golden_frame;
407#if CONFIG_EXT_REFS
408 int refresh_bwd_ref_frame;
409#endif // CONFIG_EXT_REFS
410 int refresh_alt_ref_frame;
411
412 int ext_refresh_frame_flags_pending;
413 int ext_refresh_last_frame;
414 int ext_refresh_golden_frame;
415 int ext_refresh_alt_ref_frame;
416
417 int ext_refresh_frame_context_pending;
418 int ext_refresh_frame_context;
419
420 YV12_BUFFER_CONFIG last_frame_uf;
421#if CONFIG_LOOP_RESTORATION
422 YV12_BUFFER_CONFIG last_frame_db;
Debargha Mukherjee999d2f62016-12-15 13:23:21 -0800423 YV12_BUFFER_CONFIG trial_frame_rst;
Debargha Mukherjeea43a2d92017-01-03 15:14:57 -0800424 uint8_t *extra_rstbuf; // Extra buffers used in restoration search
425 RestorationInfo rst_search[MAX_MB_PLANE]; // Used for encoder side search
426#endif // CONFIG_LOOP_RESTORATION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700427
428 // Ambient reconstruction err target for force key frames
429 int64_t ambient_err;
430
431 RD_OPT rd;
432
433 CODING_CONTEXT coding_context;
434
Urvang Joshibffc0b52016-07-25 13:38:49 -0700435 int nmv_costs[NMV_CONTEXTS][2][MV_VALS];
436 int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700437
Yaowu Xuc27fc142016-08-22 16:08:15 -0700438 int64_t last_time_stamp_seen;
439 int64_t last_end_time_stamp_seen;
440 int64_t first_time_stamp_ever;
441
442 RATE_CONTROL rc;
Rostislav Pehlivanov002e7b72017-02-15 19:45:54 +0000443#if CONFIG_XIPHRC
444 od_rc_state od_rc;
445#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700446 double framerate;
447
448 // NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter
449 // references; Plus the currently coded frame itself, it is needed to allocate
450 // sufficient space to the size of the maximum possible number of frames.
451 int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE];
452
Yaowu Xuf883b422016-08-30 14:01:10 -0700453 struct aom_codec_pkt_list *output_pkt_list;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700454
455 MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
456 int mbgraph_n_frames; // number of frames filled in the above
457 int static_mb_pct; // % forced skip mbs by segmentation
458 int ref_frame_flags;
459
460 SPEED_FEATURES sf;
461
462 unsigned int max_mv_magnitude;
463 int mv_step_param;
464
465 int allow_comp_inter_inter;
466
Yaowu Xuc27fc142016-08-22 16:08:15 -0700467 uint8_t *segmentation_map;
468
Yaowu Xuc27fc142016-08-22 16:08:15 -0700469 CYCLIC_REFRESH *cyclic_refresh;
470 ActiveMap active_map;
471
472 fractional_mv_step_fp *find_fractional_mv_step;
Yaowu Xuf883b422016-08-30 14:01:10 -0700473 av1_full_search_fn_t full_search_sad; // It is currently unused.
474 av1_diamond_search_fn_t diamond_search_sad;
475 aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700476 uint64_t time_receive_data;
477 uint64_t time_compress_data;
478 uint64_t time_pick_lpf;
479 uint64_t time_encode_sb_row;
480
481#if CONFIG_FP_MB_STATS
482 int use_fp_mb_stats;
483#endif
484
485 TWO_PASS twopass;
486
487 YV12_BUFFER_CONFIG alt_ref_buffer;
488
489#if CONFIG_INTERNAL_STATS
490 unsigned int mode_chosen_counts[MAX_MODES];
491
492 int count;
493 uint64_t total_sq_error;
494 uint64_t total_samples;
495 ImageStat psnr;
496
497 double total_blockiness;
498 double worst_blockiness;
499
500 int bytes;
501 double summed_quality;
502 double summed_weights;
503 unsigned int tot_recode_hits;
504 double worst_ssim;
505
506 ImageStat fastssim;
507 ImageStat psnrhvs;
508
509 int b_calculate_blockiness;
510 int b_calculate_consistency;
511
512 double total_inconsistency;
513 double worst_consistency;
514 Ssimv *ssim_vars;
515 Metrics metrics;
516#endif
517 int b_calculate_psnr;
518
519 int droppable;
520
521 int initial_width;
522 int initial_height;
523 int initial_mbs; // Number of MBs in the full-size frame; to be used to
524 // normalize the firstpass stats. This will differ from the
525 // number of MBs in the current frame when the frame is
526 // scaled.
527
Yaowu Xuc27fc142016-08-22 16:08:15 -0700528 int frame_flags;
529
530 search_site_config ss_cfg;
531
532 int mbmode_cost[BLOCK_SIZE_GROUPS][INTRA_MODES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700533 int newmv_mode_cost[NEWMV_MODE_CONTEXTS][2];
534 int zeromv_mode_cost[ZEROMV_MODE_CONTEXTS][2];
535 int refmv_mode_cost[REFMV_MODE_CONTEXTS][2];
536 int drl_mode_cost0[DRL_MODE_CONTEXTS][2];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700537
538 unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
539#if CONFIG_EXT_INTER
clang-format67948d32016-09-07 22:40:40 -0700540 unsigned int inter_compound_mode_cost[INTER_MODE_CONTEXTS]
541 [INTER_COMPOUND_MODES];
Yue Chen4d26acb2017-05-01 12:28:34 -0700542#if CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700543 unsigned int interintra_mode_cost[BLOCK_SIZE_GROUPS][INTERINTRA_MODES];
Yue Chen4d26acb2017-05-01 12:28:34 -0700544#endif // CONFIG_INTERINTRA
Yaowu Xuc27fc142016-08-22 16:08:15 -0700545#endif // CONFIG_EXT_INTER
Yue Chencb60b182016-10-13 15:18:22 -0700546#if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
547 int motion_mode_cost[BLOCK_SIZES][MOTION_MODES];
Yue Chen69f18e12016-09-08 14:48:15 -0700548#if CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
549 int motion_mode_cost1[BLOCK_SIZES][2];
550#endif // CONFIG_MOTION_VAR && CONFIG_WARPED_MOTION
Yue Chencb60b182016-10-13 15:18:22 -0700551#endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700552 int intra_uv_mode_cost[INTRA_MODES][INTRA_MODES];
553 int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
554 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
555#if CONFIG_EXT_PARTITION_TYPES
Alex Converse55c6bde2017-01-12 15:55:31 -0800556 int partition_cost[PARTITION_CONTEXTS + CONFIG_UNPOISON_PARTITION_CTX]
557 [EXT_PARTITION_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700558#else
Alex Converse55c6bde2017-01-12 15:55:31 -0800559 int partition_cost[PARTITION_CONTEXTS + CONFIG_UNPOISON_PARTITION_CTX]
560 [PARTITION_TYPES];
Yaowu Xuc27fc142016-08-22 16:08:15 -0700561#endif
Urvang Joshib100db72016-10-12 16:28:56 -0700562#if CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700563 int palette_y_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES];
564 int palette_uv_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES];
Alex Converse92109812017-02-22 10:21:40 -0800565 int palette_y_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
clang-format67948d32016-09-07 22:40:40 -0700566 [PALETTE_COLORS];
Alex Converse92109812017-02-22 10:21:40 -0800567 int palette_uv_color_cost[PALETTE_SIZES][PALETTE_COLOR_INDEX_CONTEXTS]
clang-format67948d32016-09-07 22:40:40 -0700568 [PALETTE_COLORS];
Urvang Joshib100db72016-10-12 16:28:56 -0700569#endif // CONFIG_PALETTE
Yaowu Xuc27fc142016-08-22 16:08:15 -0700570 int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES];
571#if CONFIG_EXT_TX
572 int inter_tx_type_costs[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES];
573 int intra_tx_type_costs[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES]
574 [TX_TYPES];
575#else
576 int intra_tx_type_costs[EXT_TX_SIZES][TX_TYPES][TX_TYPES];
577 int inter_tx_type_costs[EXT_TX_SIZES][TX_TYPES];
578#endif // CONFIG_EXT_TX
579#if CONFIG_EXT_INTRA
hui sueda3d762016-12-06 16:58:23 -0800580#if CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700581 int intra_filter_cost[INTRA_FILTERS + 1][INTRA_FILTERS];
hui sueda3d762016-12-06 16:58:23 -0800582#endif // CONFIG_INTRA_INTERP
Yaowu Xuc27fc142016-08-22 16:08:15 -0700583#endif // CONFIG_EXT_INTRA
Debargha Mukherjee5cd2ab92016-09-08 15:15:17 -0700584#if CONFIG_LOOP_RESTORATION
585 int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES];
586#endif // CONFIG_LOOP_RESTORATION
Debargha Mukherjee9febfc12016-12-07 13:20:44 -0800587#if CONFIG_GLOBAL_MOTION
588 int gmtype_cost[TRANS_TYPES];
Debargha Mukherjee265db6d2017-03-28 11:15:27 -0700589 int gmparams_cost[TOTAL_REFS_PER_FRAME];
Debargha Mukherjee9febfc12016-12-07 13:20:44 -0800590#endif // CONFIG_GLOBAL_MOTION
Yaowu Xuc27fc142016-08-22 16:08:15 -0700591
592 int multi_arf_allowed;
593 int multi_arf_enabled;
594 int multi_arf_last_grp_enabled;
595
596 TileDataEnc *tile_data;
597 int allocated_tiles; // Keep track of memory allocated for tiles.
598
599 TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS];
600 unsigned int tok_count[MAX_TILE_ROWS][MAX_TILE_COLS];
601
602 TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS];
603
Yaowu Xuc27fc142016-08-22 16:08:15 -0700604 int resize_state;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700605 int resize_avg_qp;
606 int resize_buffer_underflow;
607 int resize_count;
608
Yaowu Xuc27fc142016-08-22 16:08:15 -0700609 // VARIANCE_AQ segment map refresh
610 int vaq_refresh;
611
612 // Multi-threading
613 int num_workers;
Yaowu Xuf883b422016-08-30 14:01:10 -0700614 AVxWorker *workers;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700615 struct EncWorkerData *tile_thr_data;
Yaowu Xuf883b422016-08-30 14:01:10 -0700616 AV1LfSync lf_row_sync;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700617#if CONFIG_ANS
618 struct BufAnsCoder buf_ans;
619#endif
620#if CONFIG_EXT_REFS
621 int refresh_frame_mask;
622 int existing_fb_idx_to_show;
623 int is_arf_filter_off[MAX_EXT_ARFS + 1];
624 int num_extra_arfs;
625 int arf_map[MAX_EXT_ARFS + 1];
626#endif // CONFIG_EXT_REFS
627#if CONFIG_GLOBAL_MOTION
Debargha Mukherjeeb98a7022016-11-15 16:07:12 -0800628 int global_motion_search_done;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700629#endif
Arild Fuldseth (arilfuld)5114b7b2016-11-09 13:32:54 +0100630#if CONFIG_REFERENCE_BUFFER
631 SequenceHeader seq_params;
632#endif
Angie Chiangf0fbf9d2017-03-15 15:01:22 -0700633#if CONFIG_LV_MAP
634 tran_low_t *tcoeff_buf[MAX_MB_PLANE];
635#endif
Yaowu Xuf883b422016-08-30 14:01:10 -0700636} AV1_COMP;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700637
Yaowu Xuf883b422016-08-30 14:01:10 -0700638void av1_initialize_enc(void);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700639
Yaowu Xuf883b422016-08-30 14:01:10 -0700640struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf,
641 BufferPool *const pool);
642void av1_remove_compressor(AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700643
Yaowu Xuf883b422016-08-30 14:01:10 -0700644void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700645
646// receive a frames worth of data. caller can assume that a copy of this
647// frame is made and not just a copy of the pointer..
James Zern3e2613b2017-03-30 23:14:40 -0700648int av1_receive_raw_frame(AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags,
Yaowu Xuf883b422016-08-30 14:01:10 -0700649 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
650 int64_t end_time_stamp);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700651
Yaowu Xuf883b422016-08-30 14:01:10 -0700652int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags,
653 size_t *size, uint8_t *dest, int64_t *time_stamp,
654 int64_t *time_end, int flush);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700655
Yaowu Xuf883b422016-08-30 14:01:10 -0700656int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700657
Yaowu Xuf883b422016-08-30 14:01:10 -0700658int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700659
Yaowu Xuf883b422016-08-30 14:01:10 -0700660int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700661
Yaowu Xuf883b422016-08-30 14:01:10 -0700662void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700663
Yaowu Xuf883b422016-08-30 14:01:10 -0700664int av1_copy_reference_enc(AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700665 YV12_BUFFER_CONFIG *sd);
666
Yaowu Xuf883b422016-08-30 14:01:10 -0700667int av1_set_reference_enc(AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag,
668 YV12_BUFFER_CONFIG *sd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700669
Yaowu Xuf883b422016-08-30 14:01:10 -0700670int av1_update_entropy(AV1_COMP *cpi, int update);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700671
Yaowu Xuf883b422016-08-30 14:01:10 -0700672int av1_set_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700673
Yaowu Xuf883b422016-08-30 14:01:10 -0700674int av1_get_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700675
Yaowu Xuf883b422016-08-30 14:01:10 -0700676int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode,
677 AOM_SCALING vert_mode);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700678
Fergus Simpson0a30c882017-05-16 16:54:51 -0700679// Returns 1 if the assigned width or height was <= 0.
680int av1_set_size_literal(AV1_COMP *cpi, int width, int height);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700681
Yaowu Xuf883b422016-08-30 14:01:10 -0700682int av1_get_quantizer(struct AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700683
Yaowu Xuf883b422016-08-30 14:01:10 -0700684void av1_full_to_model_counts(av1_coeff_count_model *model_count,
685 av1_coeff_count *full_count);
686
687static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700688 return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
689 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
690}
691
Yaowu Xuf883b422016-08-30 14:01:10 -0700692static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700693 MV_REFERENCE_FRAME ref_frame) {
694#if CONFIG_EXT_REFS
695 if (ref_frame >= LAST_FRAME && ref_frame <= LAST3_FRAME)
696 return cpi->lst_fb_idxes[ref_frame - 1];
697#else
698 if (ref_frame == LAST_FRAME) return cpi->lst_fb_idx;
699#endif // CONFIG_EXT_REFS
700 else if (ref_frame == GOLDEN_FRAME)
701 return cpi->gld_fb_idx;
702#if CONFIG_EXT_REFS
703 else if (ref_frame == BWDREF_FRAME)
704 return cpi->bwd_fb_idx;
705#endif // CONFIG_EXT_REFS
706 else
707 return cpi->alt_fb_idx;
708}
709
Urvang Joshi52648442016-10-13 17:27:51 -0700710static INLINE int get_ref_frame_buf_idx(const AV1_COMP *cpi,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700711 MV_REFERENCE_FRAME ref_frame) {
Yaowu Xuf883b422016-08-30 14:01:10 -0700712 const AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700713 const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
714 return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
715}
716
717static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
Urvang Joshi52648442016-10-13 17:27:51 -0700718 const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
719 const AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700720 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
721 return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf
722 : NULL;
723}
724
725static INLINE const YV12_BUFFER_CONFIG *get_upsampled_ref(
Urvang Joshi52648442016-10-13 17:27:51 -0700726 const AV1_COMP *cpi, const MV_REFERENCE_FRAME ref_frame) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700727 // Use up-sampled reference frames.
728 const int buf_idx =
729 cpi->upsampled_ref_idx[get_ref_frame_map_idx(cpi, ref_frame)];
730 return &cpi->upsampled_ref_bufs[buf_idx].buf;
731}
732
Jingning Han3c4556c2017-05-19 11:27:17 -0700733#if CONFIG_EXT_REFS || CONFIG_TEMPMV_SIGNALING
Yaowu Xuf883b422016-08-30 14:01:10 -0700734static INLINE int enc_is_ref_frame_buf(AV1_COMP *cpi, RefCntBuffer *frame_buf) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700735 MV_REFERENCE_FRAME ref_frame;
Yaowu Xuf883b422016-08-30 14:01:10 -0700736 AV1_COMMON *const cm = &cpi->common;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700737 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) {
738 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
739 if (buf_idx == INVALID_IDX) continue;
740 if (frame_buf == &cm->buffer_pool->frame_bufs[buf_idx]) break;
741 }
742 return (ref_frame <= ALTREF_FRAME);
743}
744#endif // CONFIG_EXT_REFS
745
746static INLINE unsigned int get_token_alloc(int mb_rows, int mb_cols) {
Jingning Han7f76d472016-07-29 10:48:34 -0700747 // We assume 3 planes all at full resolution. We assume up to 1 token per
748 // pixel, and then allow a head room of 1 EOSB token per 4x4 block per plane,
749 // plus EOSB_TOKEN per plane.
750 return mb_rows * mb_cols * (16 * 16 + 17) * 3;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700751}
752
753// Get the allocated token size for a tile. It does the same calculation as in
754// the frame token allocation.
755static INLINE unsigned int allocated_tokens(TileInfo tile) {
Jingning Haneafbd5f2017-03-07 11:18:17 -0800756#if CONFIG_CB4X4
757 int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 2) >> 2;
758 int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 2) >> 2;
759#else
Yaowu Xuc27fc142016-08-22 16:08:15 -0700760 int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
761 int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
Jingning Haneafbd5f2017-03-07 11:18:17 -0800762#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700763
764 return get_token_alloc(tile_mb_rows, tile_mb_cols);
765}
766
Yaowu Xuf883b422016-08-30 14:01:10 -0700767void av1_alloc_compressor_data(AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700768
Yaowu Xuf883b422016-08-30 14:01:10 -0700769void av1_scale_references(AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700770
Yaowu Xuf883b422016-08-30 14:01:10 -0700771void av1_update_reference_frames(AV1_COMP *cpi);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700772
Yaowu Xuf883b422016-08-30 14:01:10 -0700773void av1_set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv);
Fangwen Fu8d164de2016-12-14 13:40:54 -0800774#if CONFIG_TEMPMV_SIGNALING
775void av1_set_temporal_mv_prediction(AV1_COMP *cpi, int allow_tempmv_prediction);
776#endif
Yaowu Xuc27fc142016-08-22 16:08:15 -0700777
Yaowu Xuf883b422016-08-30 14:01:10 -0700778void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700779
Yaowu Xuf883b422016-08-30 14:01:10 -0700780static INLINE int is_altref_enabled(const AV1_COMP *const cpi) {
Thomas Daede80826142017-03-20 15:44:24 -0700781 return cpi->oxcf.lag_in_frames > 0 && cpi->oxcf.enable_auto_arf;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700782}
783
784// TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf
785#if 0 && CONFIG_EXT_REFS
Yaowu Xuf883b422016-08-30 14:01:10 -0700786static INLINE int is_bwdref_enabled(const AV1_COMP *const cpi) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700787 // NOTE(zoeliu): The enabling of bi-predictive frames depends on the use of
788 // alt_ref, and now will be off when the alt_ref interval is
789 // not sufficiently large.
790 return is_altref_enabled(cpi) && cpi->oxcf.enable_auto_brf;
791}
792#endif // CONFIG_EXT_REFS
793
Urvang Joshi52648442016-10-13 17:27:51 -0700794static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd,
Yaowu Xuc27fc142016-08-22 16:08:15 -0700795 MV_REFERENCE_FRAME ref0,
796 MV_REFERENCE_FRAME ref1) {
797 xd->block_refs[0] =
798 &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0];
799 xd->block_refs[1] =
800 &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0];
801}
802
Yaowu Xu4ff59b52017-04-24 12:41:56 -0700803static INLINE int get_chessboard_index(int frame_index) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700804 return frame_index & 0x1;
805}
806
Yaowu Xuf883b422016-08-30 14:01:10 -0700807static INLINE int *cond_cost_list(const struct AV1_COMP *cpi, int *cost_list) {
Yaowu Xuc27fc142016-08-22 16:08:15 -0700808 return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
809}
810
Yaowu Xuf883b422016-08-30 14:01:10 -0700811void av1_new_framerate(AV1_COMP *cpi, double framerate);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700812
813#define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
814
815// Update up-sampled reference frame index.
816static INLINE void uref_cnt_fb(EncRefCntBuffer *ubufs, int *uidx,
817 int new_uidx) {
818 const int ref_index = *uidx;
819
820 if (ref_index >= 0 && ubufs[ref_index].ref_count > 0)
821 ubufs[ref_index].ref_count--;
822
823 *uidx = new_uidx;
824 ubufs[new_uidx].ref_count++;
825}
826
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700827// Returns 1 if a frame is unscaled and 0 otherwise.
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700828static INLINE int av1_resize_unscaled(const AV1_COMMON *cm) {
829#if CONFIG_FRAME_SUPERRES
830 return cm->superres_upscaled_width == cm->render_width &&
831 cm->superres_upscaled_height == cm->render_height;
832#else
833 return cm->width == cm->render_width && cm->height == cm->render_height;
834#endif // CONFIG_FRAME_SUPERRES
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700835}
836
Fergus Simpsond2bcbb52017-05-22 23:15:05 -0700837static INLINE int av1_frame_unscaled(const AV1_COMMON *cm) {
838#if CONFIG_FRAME_SUPERRES
839 return av1_superres_unscaled(cm) && av1_resize_unscaled(cm);
840#else
841 return av1_resize_unscaled(cm);
842#endif // CONFIG_FRAME_SUPERRES
Fergus Simpsonfecb2ab2017-04-30 15:49:57 -0700843}
844
Yaowu Xuc27fc142016-08-22 16:08:15 -0700845#ifdef __cplusplus
846} // extern "C"
847#endif
848
Yaowu Xuf883b422016-08-30 14:01:10 -0700849#endif // AV1_ENCODER_ENCODER_H_