Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Urvang Joshi | 8a02d76 | 2016-07-28 15:51:12 -0700 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_ENCODER_ENCODER_H_ |
| 13 | #define AV1_ENCODER_ENCODER_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include <stdio.h> |
| 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "./aom_config.h" |
| 18 | #include "aom/aomcx.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 19 | |
| 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" |
| 24 | #include "av1/encoder/aq_cyclicrefresh.h" |
| 25 | #if CONFIG_ANS |
Alex Converse | 1ac1ae7 | 2016-09-17 15:11:16 -0700 | [diff] [blame] | 26 | #include "aom_dsp/buf_ans.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 27 | #endif |
| 28 | #include "av1/encoder/context_tree.h" |
| 29 | #include "av1/encoder/encodemb.h" |
| 30 | #include "av1/encoder/firstpass.h" |
| 31 | #include "av1/encoder/lookahead.h" |
| 32 | #include "av1/encoder/mbgraph.h" |
| 33 | #include "av1/encoder/mcomp.h" |
| 34 | #include "av1/encoder/quantize.h" |
| 35 | #include "av1/encoder/ratectrl.h" |
| 36 | #include "av1/encoder/rd.h" |
| 37 | #include "av1/encoder/speed_features.h" |
| 38 | #include "av1/encoder/tokenize.h" |
| 39 | #include "av1/encoder/variance_tree.h" |
| 40 | |
| 41 | #if CONFIG_INTERNAL_STATS |
| 42 | #include "aom_dsp/ssim.h" |
| 43 | #endif |
| 44 | #include "aom_dsp/variance.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 45 | #include "aom/internal/aom_codec_internal.h" |
| 46 | #include "aom_util/aom_thread.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | |
| 48 | #ifdef __cplusplus |
| 49 | extern "C" { |
| 50 | #endif |
| 51 | |
| 52 | typedef struct { |
| 53 | int nmvjointcost[MV_JOINTS]; |
| 54 | int nmvcosts[2][MV_VALS]; |
| 55 | int nmvcosts_hp[2][MV_VALS]; |
| 56 | |
| 57 | #if CONFIG_REF_MV |
| 58 | int nmv_vec_cost[NMV_CONTEXTS][MV_JOINTS]; |
| 59 | int nmv_costs[NMV_CONTEXTS][2][MV_VALS]; |
| 60 | int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS]; |
| 61 | #endif |
| 62 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 63 | // 0 = Intra, Last, GF, ARF |
| 64 | signed char last_ref_lf_deltas[TOTAL_REFS_PER_FRAME]; |
| 65 | // 0 = ZERO_MV, MV |
| 66 | signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; |
| 67 | |
| 68 | FRAME_CONTEXT fc; |
| 69 | } CODING_CONTEXT; |
| 70 | |
| 71 | typedef enum { |
| 72 | // regular inter frame |
| 73 | REGULAR_FRAME = 0, |
| 74 | // alternate reference frame |
| 75 | ARF_FRAME = 1, |
| 76 | // overlay frame |
| 77 | OVERLAY_FRAME = 2, |
| 78 | // golden frame |
| 79 | GLD_FRAME = 3, |
| 80 | #if CONFIG_EXT_REFS |
| 81 | // backward reference frame |
| 82 | BRF_FRAME = 4, |
| 83 | // extra alternate reference frame |
| 84 | EXT_ARF_FRAME = 5 |
| 85 | #endif |
| 86 | } FRAME_CONTEXT_INDEX; |
| 87 | |
| 88 | typedef enum { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 89 | NORMAL = 0, |
| 90 | FOURFIVE = 1, |
| 91 | THREEFIVE = 2, |
| 92 | ONETWO = 3 |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 93 | } AOM_SCALING; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 94 | |
| 95 | typedef enum { |
| 96 | // Good Quality Fast Encoding. The encoder balances quality with the amount of |
| 97 | // time it takes to encode the output. Speed setting controls how fast. |
| 98 | GOOD, |
| 99 | |
| 100 | // The encoder places priority on the quality of the output over encoding |
| 101 | // speed. The output is compressed at the highest possible quality. This |
| 102 | // option takes the longest amount of time to encode. Speed setting ignored. |
| 103 | BEST, |
| 104 | |
| 105 | // Realtime/Live Encoding. This mode is optimized for realtime encoding (for |
| 106 | // example, capturing a television signal or feed from a live camera). Speed |
| 107 | // setting controls how fast. |
| 108 | REALTIME |
| 109 | } MODE; |
| 110 | |
| 111 | typedef enum { |
| 112 | FRAMEFLAGS_KEY = 1 << 0, |
| 113 | FRAMEFLAGS_GOLDEN = 1 << 1, |
| 114 | #if CONFIG_EXT_REFS |
| 115 | FRAMEFLAGS_BWDREF = 1 << 2, |
| 116 | FRAMEFLAGS_ALTREF = 1 << 3, |
| 117 | #else |
| 118 | FRAMEFLAGS_ALTREF = 1 << 2, |
| 119 | #endif // CONFIG_EXT_REFS |
| 120 | } FRAMETYPE_FLAGS; |
| 121 | |
| 122 | typedef enum { |
| 123 | NO_AQ = 0, |
| 124 | VARIANCE_AQ = 1, |
| 125 | COMPLEXITY_AQ = 2, |
| 126 | CYCLIC_REFRESH_AQ = 3, |
Arild Fuldseth | 0744116 | 2016-08-15 15:07:52 +0200 | [diff] [blame] | 127 | #if CONFIG_DELTA_Q |
| 128 | DELTA_AQ = 4, |
| 129 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 130 | AQ_MODE_COUNT // This should always be the last member of the enum |
| 131 | } AQ_MODE; |
| 132 | |
| 133 | typedef enum { |
| 134 | RESIZE_NONE = 0, // No frame resizing allowed. |
| 135 | RESIZE_FIXED = 1, // All frames are coded at the specified dimension. |
| 136 | RESIZE_DYNAMIC = 2 // Coded size of each frame is determined by the codec. |
| 137 | } RESIZE_TYPE; |
| 138 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 139 | typedef struct AV1EncoderConfig { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 140 | BITSTREAM_PROFILE profile; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 141 | aom_bit_depth_t bit_depth; // Codec bit-depth. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 142 | int width; // width of data passed to the compressor |
| 143 | int height; // height of data passed to the compressor |
| 144 | unsigned int input_bit_depth; // Input bit depth. |
| 145 | double init_framerate; // set to passed in framerate |
| 146 | int64_t target_bandwidth; // bandwidth to be used in bits per second |
| 147 | |
| 148 | int noise_sensitivity; // pre processing blur: recommendation 0 |
| 149 | int sharpness; // sharpening output: recommendation 0: |
| 150 | int speed; |
| 151 | // 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 Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 171 | enum aom_rc_mode rc_mode; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 172 | |
| 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 |
| 191 | #if CONFIG_AOM_QM |
| 192 | int using_qm; |
| 193 | int qm_minlevel; |
| 194 | int qm_maxlevel; |
| 195 | #endif |
| 196 | |
| 197 | // Internal frame size scaling. |
| 198 | RESIZE_TYPE resize_mode; |
| 199 | int scaled_frame_width; |
| 200 | int scaled_frame_height; |
| 201 | |
| 202 | // Enable feature to reduce the frame quantization every x frames. |
| 203 | int frame_periodic_boost; |
| 204 | |
| 205 | // two pass datarate control |
| 206 | int two_pass_vbrbias; // two pass datarate control tweaks |
| 207 | int two_pass_vbrmin_section; |
| 208 | int two_pass_vbrmax_section; |
| 209 | // END DATARATE CONTROL OPTIONS |
| 210 | // ---------------------------------------------------------------- |
| 211 | |
| 212 | int enable_auto_arf; |
| 213 | #if CONFIG_EXT_REFS |
| 214 | int enable_auto_brf; // (b)ackward (r)ef (f)rame |
| 215 | #endif // CONFIG_EXT_REFS |
| 216 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 217 | /* Bitfield defining the error resiliency features to enable. |
| 218 | * Can provide decodable frames after losses in previous |
| 219 | * frames and decodable partitions after losses in the same frame. |
| 220 | */ |
| 221 | unsigned int error_resilient_mode; |
| 222 | |
| 223 | /* Bitfield defining the parallel decoding mode where the |
| 224 | * decoding in successive frames may be conducted in parallel |
| 225 | * just by decoding the frame headers. |
| 226 | */ |
| 227 | unsigned int frame_parallel_decoding_mode; |
| 228 | |
| 229 | int arnr_max_frames; |
| 230 | int arnr_strength; |
| 231 | |
| 232 | int min_gf_interval; |
| 233 | int max_gf_interval; |
| 234 | |
| 235 | int tile_columns; |
| 236 | int tile_rows; |
| 237 | |
| 238 | int max_threads; |
| 239 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 240 | aom_fixed_buf_t two_pass_stats_in; |
| 241 | struct aom_codec_pkt_list *output_pkt_list; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 242 | |
| 243 | #if CONFIG_FP_MB_STATS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 244 | aom_fixed_buf_t firstpass_mb_stats_in; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 245 | #endif |
| 246 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 247 | aom_tune_metric tuning; |
| 248 | aom_tune_content content; |
| 249 | #if CONFIG_AOM_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 250 | int use_highbitdepth; |
| 251 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 252 | aom_color_space_t color_space; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 253 | int color_range; |
| 254 | int render_width; |
| 255 | int render_height; |
| 256 | |
| 257 | #if CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 258 | aom_superblock_size_t superblock_size; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 259 | #endif // CONFIG_EXT_PARTITION |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 260 | } AV1EncoderConfig; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 261 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 262 | static INLINE int is_lossless_requested(const AV1EncoderConfig *cfg) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 263 | return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0; |
| 264 | } |
| 265 | |
| 266 | // TODO(jingning) All spatially adaptive variables should go to TileDataEnc. |
| 267 | typedef struct TileDataEnc { |
| 268 | TileInfo tile_info; |
| 269 | int thresh_freq_fact[BLOCK_SIZES][MAX_MODES]; |
| 270 | int mode_map[BLOCK_SIZES][MAX_MODES]; |
Yunqing Wang | 8c1e57c | 2016-10-25 15:15:23 -0700 | [diff] [blame] | 271 | int m_search_count; |
| 272 | int ex_search_count; |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 273 | #if CONFIG_PVQ |
| 274 | PVQ_QUEUE pvq_q; |
| 275 | #endif |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 276 | } TileDataEnc; |
| 277 | |
| 278 | typedef struct RD_COUNTS { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 279 | av1_coeff_count coef_counts[TX_SIZES][PLANE_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 280 | int64_t comp_pred_diff[REFERENCE_MODES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 281 | } RD_COUNTS; |
| 282 | |
| 283 | typedef struct ThreadData { |
| 284 | MACROBLOCK mb; |
| 285 | RD_COUNTS rd_counts; |
| 286 | FRAME_COUNTS *counts; |
| 287 | |
| 288 | PICK_MODE_CONTEXT *leaf_tree; |
| 289 | PC_TREE *pc_tree; |
| 290 | PC_TREE *pc_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1]; |
| 291 | |
| 292 | VAR_TREE *var_tree; |
| 293 | VAR_TREE *var_root[MAX_MIB_SIZE_LOG2 - MIN_MIB_SIZE_LOG2 + 1]; |
| 294 | } ThreadData; |
| 295 | |
| 296 | struct EncWorkerData; |
| 297 | |
| 298 | typedef struct ActiveMap { |
| 299 | int enabled; |
| 300 | int update; |
| 301 | unsigned char *map; |
| 302 | } ActiveMap; |
| 303 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 304 | #define NUM_STAT_TYPES 4 // types of stats: Y, U, V and ALL |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 305 | |
| 306 | typedef struct IMAGE_STAT { |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 307 | double stat[NUM_STAT_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 308 | double worst; |
| 309 | } ImageStat; |
| 310 | |
Urvang Joshi | b5ed350 | 2016-10-17 16:38:05 -0700 | [diff] [blame] | 311 | #undef NUM_STAT_TYPES |
| 312 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 313 | typedef struct { |
| 314 | int ref_count; |
| 315 | YV12_BUFFER_CONFIG buf; |
| 316 | } EncRefCntBuffer; |
| 317 | |
| 318 | #if CONFIG_ENTROPY |
| 319 | typedef struct SUBFRAME_STATS { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 320 | av1_coeff_probs_model coef_probs_buf[COEF_PROBS_BUFS][TX_SIZES][PLANE_TYPES]; |
| 321 | av1_coeff_count coef_counts_buf[COEF_PROBS_BUFS][TX_SIZES][PLANE_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 322 | unsigned int eob_counts_buf[COEF_PROBS_BUFS][TX_SIZES][PLANE_TYPES][REF_TYPES] |
| 323 | [COEF_BANDS][COEFF_CONTEXTS]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 324 | av1_coeff_probs_model enc_starting_coef_probs[TX_SIZES][PLANE_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 325 | } SUBFRAME_STATS; |
| 326 | #endif // CONFIG_ENTROPY |
| 327 | |
| 328 | typedef struct TileBufferEnc { |
| 329 | uint8_t *data; |
| 330 | size_t size; |
| 331 | } TileBufferEnc; |
| 332 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 333 | typedef struct AV1_COMP { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 334 | QUANTS quants; |
| 335 | ThreadData td; |
| 336 | MB_MODE_INFO_EXT *mbmi_ext_base; |
| 337 | DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]); // 8: SIMD width |
| 338 | DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]); // 8: SIMD width |
| 339 | #if CONFIG_NEW_QUANT |
| 340 | DECLARE_ALIGNED(16, dequant_val_type_nuq, |
| 341 | y_dequant_val_nuq[QUANT_PROFILES][QINDEX_RANGE][COEF_BANDS]); |
| 342 | DECLARE_ALIGNED(16, dequant_val_type_nuq, |
| 343 | uv_dequant_val_nuq[QUANT_PROFILES][QINDEX_RANGE][COEF_BANDS]); |
| 344 | #endif // CONFIG_NEW_QUANT |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 345 | AV1_COMMON common; |
| 346 | AV1EncoderConfig oxcf; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 347 | struct lookahead_ctx *lookahead; |
| 348 | struct lookahead_entry *alt_ref_source; |
| 349 | |
| 350 | YV12_BUFFER_CONFIG *Source; |
| 351 | YV12_BUFFER_CONFIG *Last_Source; // NULL for first frame and alt_ref frames |
| 352 | YV12_BUFFER_CONFIG *un_scaled_source; |
| 353 | YV12_BUFFER_CONFIG scaled_source; |
| 354 | YV12_BUFFER_CONFIG *unscaled_last_source; |
| 355 | YV12_BUFFER_CONFIG scaled_last_source; |
| 356 | |
| 357 | // Up-sampled reference buffers |
| 358 | // NOTE(zoeliu): It is needed to allocate sufficient space to the up-sampled |
| 359 | // reference buffers, which should include the up-sampled version of all the |
| 360 | // possibly stored references plus the currently coded frame itself. |
| 361 | EncRefCntBuffer upsampled_ref_bufs[REF_FRAMES + 1]; |
| 362 | int upsampled_ref_idx[REF_FRAMES + 1]; |
| 363 | |
| 364 | // For a still frame, this flag is set to 1 to skip partition search. |
| 365 | int partition_search_skippable_frame; |
| 366 | |
| 367 | int scaled_ref_idx[TOTAL_REFS_PER_FRAME]; |
| 368 | #if CONFIG_EXT_REFS |
| 369 | int lst_fb_idxes[LAST_REF_FRAMES]; |
| 370 | #else |
| 371 | int lst_fb_idx; |
| 372 | #endif // CONFIG_EXT_REFS |
| 373 | int gld_fb_idx; |
| 374 | #if CONFIG_EXT_REFS |
| 375 | int bwd_fb_idx; // BWD_REF_FRAME |
| 376 | #endif // CONFIG_EXT_REFS |
| 377 | int alt_fb_idx; |
| 378 | |
| 379 | int last_show_frame_buf_idx; // last show frame buffer index |
| 380 | |
| 381 | int refresh_last_frame; |
| 382 | int refresh_golden_frame; |
| 383 | #if CONFIG_EXT_REFS |
| 384 | int refresh_bwd_ref_frame; |
| 385 | #endif // CONFIG_EXT_REFS |
| 386 | int refresh_alt_ref_frame; |
| 387 | |
| 388 | int ext_refresh_frame_flags_pending; |
| 389 | int ext_refresh_last_frame; |
| 390 | int ext_refresh_golden_frame; |
| 391 | int ext_refresh_alt_ref_frame; |
| 392 | |
| 393 | int ext_refresh_frame_context_pending; |
| 394 | int ext_refresh_frame_context; |
| 395 | |
| 396 | YV12_BUFFER_CONFIG last_frame_uf; |
| 397 | #if CONFIG_LOOP_RESTORATION |
| 398 | YV12_BUFFER_CONFIG last_frame_db; |
| 399 | #endif // CONFIG_LOOP_RESTORATION |
| 400 | |
| 401 | // Ambient reconstruction err target for force key frames |
| 402 | int64_t ambient_err; |
| 403 | |
| 404 | RD_OPT rd; |
| 405 | |
| 406 | CODING_CONTEXT coding_context; |
| 407 | |
| 408 | #if CONFIG_REF_MV |
Urvang Joshi | bffc0b5 | 2016-07-25 13:38:49 -0700 | [diff] [blame] | 409 | int nmv_costs[NMV_CONTEXTS][2][MV_VALS]; |
| 410 | int nmv_costs_hp[NMV_CONTEXTS][2][MV_VALS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 411 | #endif |
| 412 | |
Urvang Joshi | bffc0b5 | 2016-07-25 13:38:49 -0700 | [diff] [blame] | 413 | int nmvcosts[2][MV_VALS]; |
| 414 | int nmvcosts_hp[2][MV_VALS]; |
| 415 | int nmvsadcosts[2][MV_VALS]; |
| 416 | int nmvsadcosts_hp[2][MV_VALS]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 417 | |
| 418 | int64_t last_time_stamp_seen; |
| 419 | int64_t last_end_time_stamp_seen; |
| 420 | int64_t first_time_stamp_ever; |
| 421 | |
| 422 | RATE_CONTROL rc; |
| 423 | double framerate; |
| 424 | |
| 425 | // NOTE(zoeliu): Any inter frame allows maximum of REF_FRAMES inter |
| 426 | // references; Plus the currently coded frame itself, it is needed to allocate |
| 427 | // sufficient space to the size of the maximum possible number of frames. |
| 428 | int interp_filter_selected[REF_FRAMES + 1][SWITCHABLE]; |
| 429 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 430 | struct aom_codec_pkt_list *output_pkt_list; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 431 | |
| 432 | MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS]; |
| 433 | int mbgraph_n_frames; // number of frames filled in the above |
| 434 | int static_mb_pct; // % forced skip mbs by segmentation |
| 435 | int ref_frame_flags; |
| 436 | |
| 437 | SPEED_FEATURES sf; |
| 438 | |
| 439 | unsigned int max_mv_magnitude; |
| 440 | int mv_step_param; |
| 441 | |
| 442 | int allow_comp_inter_inter; |
| 443 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 444 | uint8_t *segmentation_map; |
| 445 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 446 | CYCLIC_REFRESH *cyclic_refresh; |
| 447 | ActiveMap active_map; |
| 448 | |
| 449 | fractional_mv_step_fp *find_fractional_mv_step; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 450 | av1_full_search_fn_t full_search_sad; // It is currently unused. |
| 451 | av1_diamond_search_fn_t diamond_search_sad; |
| 452 | aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 453 | uint64_t time_receive_data; |
| 454 | uint64_t time_compress_data; |
| 455 | uint64_t time_pick_lpf; |
| 456 | uint64_t time_encode_sb_row; |
| 457 | |
| 458 | #if CONFIG_FP_MB_STATS |
| 459 | int use_fp_mb_stats; |
| 460 | #endif |
| 461 | |
| 462 | TWO_PASS twopass; |
| 463 | |
| 464 | YV12_BUFFER_CONFIG alt_ref_buffer; |
| 465 | |
| 466 | #if CONFIG_INTERNAL_STATS |
| 467 | unsigned int mode_chosen_counts[MAX_MODES]; |
| 468 | |
| 469 | int count; |
| 470 | uint64_t total_sq_error; |
| 471 | uint64_t total_samples; |
| 472 | ImageStat psnr; |
| 473 | |
| 474 | double total_blockiness; |
| 475 | double worst_blockiness; |
| 476 | |
| 477 | int bytes; |
| 478 | double summed_quality; |
| 479 | double summed_weights; |
| 480 | unsigned int tot_recode_hits; |
| 481 | double worst_ssim; |
| 482 | |
| 483 | ImageStat fastssim; |
| 484 | ImageStat psnrhvs; |
| 485 | |
| 486 | int b_calculate_blockiness; |
| 487 | int b_calculate_consistency; |
| 488 | |
| 489 | double total_inconsistency; |
| 490 | double worst_consistency; |
| 491 | Ssimv *ssim_vars; |
| 492 | Metrics metrics; |
| 493 | #endif |
| 494 | int b_calculate_psnr; |
| 495 | |
| 496 | int droppable; |
| 497 | |
| 498 | int initial_width; |
| 499 | int initial_height; |
| 500 | int initial_mbs; // Number of MBs in the full-size frame; to be used to |
| 501 | // normalize the firstpass stats. This will differ from the |
| 502 | // number of MBs in the current frame when the frame is |
| 503 | // scaled. |
| 504 | |
| 505 | // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type. |
Urvang Joshi | 454280d | 2016-10-14 16:51:44 -0700 | [diff] [blame] | 506 | DIFF *source_diff_var; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 507 | // The threshold used in SOURCE_VAR_BASED_PARTITION search type. |
| 508 | unsigned int source_var_thresh; |
| 509 | int frames_till_next_var_check; |
| 510 | |
| 511 | int frame_flags; |
| 512 | |
| 513 | search_site_config ss_cfg; |
| 514 | |
| 515 | int mbmode_cost[BLOCK_SIZE_GROUPS][INTRA_MODES]; |
| 516 | #if CONFIG_REF_MV |
| 517 | int newmv_mode_cost[NEWMV_MODE_CONTEXTS][2]; |
| 518 | int zeromv_mode_cost[ZEROMV_MODE_CONTEXTS][2]; |
| 519 | int refmv_mode_cost[REFMV_MODE_CONTEXTS][2]; |
| 520 | int drl_mode_cost0[DRL_MODE_CONTEXTS][2]; |
| 521 | #if CONFIG_EXT_INTER |
| 522 | int new2mv_mode_cost[2]; |
| 523 | #endif // CONFIG_EXT_INTER |
| 524 | #endif |
| 525 | |
| 526 | unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES]; |
| 527 | #if CONFIG_EXT_INTER |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 528 | unsigned int inter_compound_mode_cost[INTER_MODE_CONTEXTS] |
| 529 | [INTER_COMPOUND_MODES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 530 | unsigned int interintra_mode_cost[BLOCK_SIZE_GROUPS][INTERINTRA_MODES]; |
| 531 | #endif // CONFIG_EXT_INTER |
Yue Chen | cb60b18 | 2016-10-13 15:18:22 -0700 | [diff] [blame] | 532 | #if CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
| 533 | int motion_mode_cost[BLOCK_SIZES][MOTION_MODES]; |
| 534 | #endif // CONFIG_MOTION_VAR || CONFIG_WARPED_MOTION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 535 | int intra_uv_mode_cost[INTRA_MODES][INTRA_MODES]; |
| 536 | int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES]; |
| 537 | int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS]; |
| 538 | #if CONFIG_EXT_PARTITION_TYPES |
| 539 | int partition_cost[PARTITION_CONTEXTS][EXT_PARTITION_TYPES]; |
| 540 | #else |
| 541 | int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES]; |
| 542 | #endif |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 543 | #if CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 544 | int palette_y_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES]; |
| 545 | int palette_uv_size_cost[PALETTE_BLOCK_SIZES][PALETTE_SIZES]; |
clang-format | 67948d3 | 2016-09-07 22:40:40 -0700 | [diff] [blame] | 546 | int palette_y_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS] |
| 547 | [PALETTE_COLORS]; |
| 548 | int palette_uv_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS] |
| 549 | [PALETTE_COLORS]; |
Urvang Joshi | b100db7 | 2016-10-12 16:28:56 -0700 | [diff] [blame] | 550 | #endif // CONFIG_PALETTE |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 551 | int tx_size_cost[TX_SIZES - 1][TX_SIZE_CONTEXTS][TX_SIZES]; |
| 552 | #if CONFIG_EXT_TX |
| 553 | int inter_tx_type_costs[EXT_TX_SETS_INTER][EXT_TX_SIZES][TX_TYPES]; |
| 554 | int intra_tx_type_costs[EXT_TX_SETS_INTRA][EXT_TX_SIZES][INTRA_MODES] |
| 555 | [TX_TYPES]; |
| 556 | #else |
| 557 | int intra_tx_type_costs[EXT_TX_SIZES][TX_TYPES][TX_TYPES]; |
| 558 | int inter_tx_type_costs[EXT_TX_SIZES][TX_TYPES]; |
| 559 | #endif // CONFIG_EXT_TX |
| 560 | #if CONFIG_EXT_INTRA |
| 561 | int intra_filter_cost[INTRA_FILTERS + 1][INTRA_FILTERS]; |
| 562 | #endif // CONFIG_EXT_INTRA |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 563 | #if CONFIG_LOOP_RESTORATION |
| 564 | int switchable_restore_cost[RESTORE_SWITCHABLE_TYPES]; |
| 565 | #endif // CONFIG_LOOP_RESTORATION |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 566 | |
| 567 | int multi_arf_allowed; |
| 568 | int multi_arf_enabled; |
| 569 | int multi_arf_last_grp_enabled; |
| 570 | |
| 571 | TileDataEnc *tile_data; |
| 572 | int allocated_tiles; // Keep track of memory allocated for tiles. |
| 573 | |
| 574 | TOKENEXTRA *tile_tok[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 575 | unsigned int tok_count[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 576 | |
| 577 | TileBufferEnc tile_buffers[MAX_TILE_ROWS][MAX_TILE_COLS]; |
| 578 | |
| 579 | int resize_pending; |
| 580 | int resize_state; |
| 581 | int resize_scale_num; |
| 582 | int resize_scale_den; |
| 583 | int resize_avg_qp; |
| 584 | int resize_buffer_underflow; |
| 585 | int resize_count; |
| 586 | |
| 587 | // VAR_BASED_PARTITION thresholds |
| 588 | // 0 - threshold_128x128; |
| 589 | // 1 - threshold_64x64; |
| 590 | // 2 - threshold_32x32; |
| 591 | // 3 - threshold_16x16; |
| 592 | // 4 - threshold_8x8; |
| 593 | int64_t vbp_thresholds[5]; |
| 594 | int64_t vbp_threshold_minmax; |
| 595 | int64_t vbp_threshold_sad; |
| 596 | BLOCK_SIZE vbp_bsize_min; |
| 597 | |
| 598 | // VARIANCE_AQ segment map refresh |
| 599 | int vaq_refresh; |
| 600 | |
| 601 | // Multi-threading |
| 602 | int num_workers; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 603 | AVxWorker *workers; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 604 | struct EncWorkerData *tile_thr_data; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 605 | AV1LfSync lf_row_sync; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 606 | #if CONFIG_ENTROPY |
| 607 | SUBFRAME_STATS subframe_stats; |
| 608 | // TODO(yaowu): minimize the size of count buffers |
| 609 | SUBFRAME_STATS wholeframe_stats; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 610 | av1_coeff_stats branch_ct_buf[COEF_PROBS_BUFS][TX_SIZES][PLANE_TYPES]; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 611 | #endif // CONFIG_ENTROPY |
| 612 | #if CONFIG_ANS |
| 613 | struct BufAnsCoder buf_ans; |
| 614 | #endif |
| 615 | #if CONFIG_EXT_REFS |
| 616 | int refresh_frame_mask; |
| 617 | int existing_fb_idx_to_show; |
| 618 | int is_arf_filter_off[MAX_EXT_ARFS + 1]; |
| 619 | int num_extra_arfs; |
| 620 | int arf_map[MAX_EXT_ARFS + 1]; |
| 621 | #endif // CONFIG_EXT_REFS |
| 622 | #if CONFIG_GLOBAL_MOTION |
| 623 | int global_motion_used[TOTAL_REFS_PER_FRAME]; |
| 624 | #endif |
Arild Fuldseth (arilfuld) | 5114b7b | 2016-11-09 13:32:54 +0100 | [diff] [blame^] | 625 | #if CONFIG_REFERENCE_BUFFER |
| 626 | SequenceHeader seq_params; |
| 627 | #endif |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 628 | } AV1_COMP; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 629 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 630 | void av1_initialize_enc(void); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 631 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 632 | struct AV1_COMP *av1_create_compressor(AV1EncoderConfig *oxcf, |
| 633 | BufferPool *const pool); |
| 634 | void av1_remove_compressor(AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 635 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 636 | void av1_change_config(AV1_COMP *cpi, const AV1EncoderConfig *oxcf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 637 | |
| 638 | // receive a frames worth of data. caller can assume that a copy of this |
| 639 | // frame is made and not just a copy of the pointer.. |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 640 | int av1_receive_raw_frame(AV1_COMP *cpi, unsigned int frame_flags, |
| 641 | YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 642 | int64_t end_time_stamp); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 643 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 644 | int av1_get_compressed_data(AV1_COMP *cpi, unsigned int *frame_flags, |
| 645 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| 646 | int64_t *time_end, int flush); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 647 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 648 | int av1_get_preview_raw_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *dest); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 649 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 650 | int av1_get_last_show_frame(AV1_COMP *cpi, YV12_BUFFER_CONFIG *frame); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 651 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 652 | int av1_use_as_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 653 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 654 | void av1_update_reference(AV1_COMP *cpi, int ref_frame_flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 655 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 656 | int av1_copy_reference_enc(AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 657 | YV12_BUFFER_CONFIG *sd); |
| 658 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 659 | int av1_set_reference_enc(AV1_COMP *cpi, AOM_REFFRAME ref_frame_flag, |
| 660 | YV12_BUFFER_CONFIG *sd); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 661 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 662 | int av1_update_entropy(AV1_COMP *cpi, int update); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 663 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 664 | int av1_set_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 665 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 666 | int av1_get_active_map(AV1_COMP *cpi, unsigned char *map, int rows, int cols); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 667 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 668 | int av1_set_internal_size(AV1_COMP *cpi, AOM_SCALING horiz_mode, |
| 669 | AOM_SCALING vert_mode); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 670 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 671 | int av1_set_size_literal(AV1_COMP *cpi, unsigned int width, |
| 672 | unsigned int height); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 673 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 674 | int av1_get_quantizer(struct AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 675 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 676 | void av1_full_to_model_counts(av1_coeff_count_model *model_count, |
| 677 | av1_coeff_count *full_count); |
| 678 | |
| 679 | static INLINE int frame_is_kf_gf_arf(const AV1_COMP *cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 680 | return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame || |
| 681 | (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref); |
| 682 | } |
| 683 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 684 | static INLINE int get_ref_frame_map_idx(const AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 685 | MV_REFERENCE_FRAME ref_frame) { |
| 686 | #if CONFIG_EXT_REFS |
| 687 | if (ref_frame >= LAST_FRAME && ref_frame <= LAST3_FRAME) |
| 688 | return cpi->lst_fb_idxes[ref_frame - 1]; |
| 689 | #else |
| 690 | if (ref_frame == LAST_FRAME) return cpi->lst_fb_idx; |
| 691 | #endif // CONFIG_EXT_REFS |
| 692 | else if (ref_frame == GOLDEN_FRAME) |
| 693 | return cpi->gld_fb_idx; |
| 694 | #if CONFIG_EXT_REFS |
| 695 | else if (ref_frame == BWDREF_FRAME) |
| 696 | return cpi->bwd_fb_idx; |
| 697 | #endif // CONFIG_EXT_REFS |
| 698 | else |
| 699 | return cpi->alt_fb_idx; |
| 700 | } |
| 701 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 702 | static INLINE int get_ref_frame_buf_idx(const AV1_COMP *cpi, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 703 | MV_REFERENCE_FRAME ref_frame) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 704 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 705 | const int map_idx = get_ref_frame_map_idx(cpi, ref_frame); |
| 706 | return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX; |
| 707 | } |
| 708 | |
| 709 | static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer( |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 710 | const AV1_COMP *cpi, MV_REFERENCE_FRAME ref_frame) { |
| 711 | const AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 712 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 713 | return buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf |
| 714 | : NULL; |
| 715 | } |
| 716 | |
| 717 | static INLINE const YV12_BUFFER_CONFIG *get_upsampled_ref( |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 718 | const AV1_COMP *cpi, const MV_REFERENCE_FRAME ref_frame) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 719 | // Use up-sampled reference frames. |
| 720 | const int buf_idx = |
| 721 | cpi->upsampled_ref_idx[get_ref_frame_map_idx(cpi, ref_frame)]; |
| 722 | return &cpi->upsampled_ref_bufs[buf_idx].buf; |
| 723 | } |
| 724 | |
| 725 | #if CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 726 | static INLINE int enc_is_ref_frame_buf(AV1_COMP *cpi, RefCntBuffer *frame_buf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 727 | MV_REFERENCE_FRAME ref_frame; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 728 | AV1_COMMON *const cm = &cpi->common; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 729 | for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 730 | const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame); |
| 731 | if (buf_idx == INVALID_IDX) continue; |
| 732 | if (frame_buf == &cm->buffer_pool->frame_bufs[buf_idx]) break; |
| 733 | } |
| 734 | return (ref_frame <= ALTREF_FRAME); |
| 735 | } |
| 736 | #endif // CONFIG_EXT_REFS |
| 737 | |
| 738 | static INLINE unsigned int get_token_alloc(int mb_rows, int mb_cols) { |
Jingning Han | 7f76d47 | 2016-07-29 10:48:34 -0700 | [diff] [blame] | 739 | // We assume 3 planes all at full resolution. We assume up to 1 token per |
| 740 | // pixel, and then allow a head room of 1 EOSB token per 4x4 block per plane, |
| 741 | // plus EOSB_TOKEN per plane. |
| 742 | return mb_rows * mb_cols * (16 * 16 + 17) * 3; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | // Get the allocated token size for a tile. It does the same calculation as in |
| 746 | // the frame token allocation. |
| 747 | static INLINE unsigned int allocated_tokens(TileInfo tile) { |
| 748 | int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1; |
| 749 | int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1; |
| 750 | |
| 751 | return get_token_alloc(tile_mb_rows, tile_mb_cols); |
| 752 | } |
| 753 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 754 | void av1_alloc_compressor_data(AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 755 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 756 | void av1_scale_references(AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 757 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 758 | void av1_update_reference_frames(AV1_COMP *cpi); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 759 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 760 | void av1_set_high_precision_mv(AV1_COMP *cpi, int allow_high_precision_mv); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 761 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 762 | YV12_BUFFER_CONFIG *av1_scale_if_required_fast(AV1_COMMON *cm, |
| 763 | YV12_BUFFER_CONFIG *unscaled, |
| 764 | YV12_BUFFER_CONFIG *scaled); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 765 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 766 | YV12_BUFFER_CONFIG *av1_scale_if_required(AV1_COMMON *cm, |
| 767 | YV12_BUFFER_CONFIG *unscaled, |
| 768 | YV12_BUFFER_CONFIG *scaled); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 769 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 770 | void av1_apply_encoding_flags(AV1_COMP *cpi, aom_enc_frame_flags_t flags); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 771 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 772 | static INLINE int is_altref_enabled(const AV1_COMP *const cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 773 | return cpi->oxcf.mode != REALTIME && cpi->oxcf.lag_in_frames > 0 && |
| 774 | cpi->oxcf.enable_auto_arf; |
| 775 | } |
| 776 | |
| 777 | // TODO(zoeliu): To set up cpi->oxcf.enable_auto_brf |
| 778 | #if 0 && CONFIG_EXT_REFS |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 779 | static INLINE int is_bwdref_enabled(const AV1_COMP *const cpi) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 780 | // NOTE(zoeliu): The enabling of bi-predictive frames depends on the use of |
| 781 | // alt_ref, and now will be off when the alt_ref interval is |
| 782 | // not sufficiently large. |
| 783 | return is_altref_enabled(cpi) && cpi->oxcf.enable_auto_brf; |
| 784 | } |
| 785 | #endif // CONFIG_EXT_REFS |
| 786 | |
Urvang Joshi | 5264844 | 2016-10-13 17:27:51 -0700 | [diff] [blame] | 787 | static INLINE void set_ref_ptrs(const AV1_COMMON *cm, MACROBLOCKD *xd, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 788 | MV_REFERENCE_FRAME ref0, |
| 789 | MV_REFERENCE_FRAME ref1) { |
| 790 | xd->block_refs[0] = |
| 791 | &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME : 0]; |
| 792 | xd->block_refs[1] = |
| 793 | &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME : 0]; |
| 794 | } |
| 795 | |
| 796 | static INLINE int get_chessboard_index(const int frame_index) { |
| 797 | return frame_index & 0x1; |
| 798 | } |
| 799 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 800 | static INLINE int *cond_cost_list(const struct AV1_COMP *cpi, int *cost_list) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 801 | return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL; |
| 802 | } |
| 803 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 804 | void av1_new_framerate(AV1_COMP *cpi, double framerate); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 805 | |
| 806 | #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl)) |
| 807 | |
| 808 | // Update up-sampled reference frame index. |
| 809 | static INLINE void uref_cnt_fb(EncRefCntBuffer *ubufs, int *uidx, |
| 810 | int new_uidx) { |
| 811 | const int ref_index = *uidx; |
| 812 | |
| 813 | if (ref_index >= 0 && ubufs[ref_index].ref_count > 0) |
| 814 | ubufs[ref_index].ref_count--; |
| 815 | |
| 816 | *uidx = new_uidx; |
| 817 | ubufs[new_uidx].ref_count++; |
| 818 | } |
| 819 | |
| 820 | #ifdef __cplusplus |
| 821 | } // extern "C" |
| 822 | #endif |
| 823 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 824 | #endif // AV1_ENCODER_ENCODER_H_ |