1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef VP9_ENCODER_VP9_ENCODER_H_
12 #define VP9_ENCODER_VP9_ENCODER_H_
13
14 #include <stdio.h>
15
16 #include "./vpx_config.h"
17 #include "vpx/internal/vpx_codec_internal.h"
18 #include "vpx/vp8cx.h"
19 #if CONFIG_INTERNAL_STATS
20 #include "vpx_dsp/ssim.h"
21 #endif
22 #include "vpx_dsp/variance.h"
23 #include "vpx_util/vpx_thread.h"
24
25 #include "vp9/common/vp9_alloccommon.h"
26 #include "vp9/common/vp9_ppflags.h"
27 #include "vp9/common/vp9_entropymode.h"
28 #include "vp9/common/vp9_thread_common.h"
29 #include "vp9/common/vp9_onyxc_int.h"
30
31 #include "vp9/encoder/vp9_aq_cyclicrefresh.h"
32 #include "vp9/encoder/vp9_context_tree.h"
33 #include "vp9/encoder/vp9_encodemb.h"
34 #include "vp9/encoder/vp9_firstpass.h"
35 #include "vp9/encoder/vp9_lookahead.h"
36 #include "vp9/encoder/vp9_mbgraph.h"
37 #include "vp9/encoder/vp9_mcomp.h"
38 #include "vp9/encoder/vp9_quantize.h"
39 #include "vp9/encoder/vp9_ratectrl.h"
40 #include "vp9/encoder/vp9_rd.h"
41 #include "vp9/encoder/vp9_speed_features.h"
42 #include "vp9/encoder/vp9_svc_layercontext.h"
43 #include "vp9/encoder/vp9_tokenize.h"
44
45 #if CONFIG_VP9_TEMPORAL_DENOISING
46 #include "vp9/encoder/vp9_denoiser.h"
47 #endif
48
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52
53 typedef struct {
54 int nmvjointcost[MV_JOINTS];
55 int nmvcosts[2][MV_VALS];
56 int nmvcosts_hp[2][MV_VALS];
57
58 vpx_prob segment_pred_probs[PREDICTION_PROBS];
59
60 unsigned char *last_frame_seg_map_copy;
61
62 // 0 = Intra, Last, GF, ARF
63 signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];
64 // 0 = ZERO_MV, MV
65 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
66
67 FRAME_CONTEXT fc;
68 } CODING_CONTEXT;
69
70
71 typedef enum {
72 // encode_breakout is disabled.
73 ENCODE_BREAKOUT_DISABLED = 0,
74 // encode_breakout is enabled.
75 ENCODE_BREAKOUT_ENABLED = 1,
76 // encode_breakout is enabled with small max_thresh limit.
77 ENCODE_BREAKOUT_LIMITED = 2
78 } ENCODE_BREAKOUT_TYPE;
79
80 typedef enum {
81 NORMAL = 0,
82 FOURFIVE = 1,
83 THREEFIVE = 2,
84 ONETWO = 3
85 } VPX_SCALING;
86
87 typedef enum {
88 // Good Quality Fast Encoding. The encoder balances quality with the amount of
89 // time it takes to encode the output. Speed setting controls how fast.
90 GOOD,
91
92 // The encoder places priority on the quality of the output over encoding
93 // speed. The output is compressed at the highest possible quality. This
94 // option takes the longest amount of time to encode. Speed setting ignored.
95 BEST,
96
97 // Realtime/Live Encoding. This mode is optimized for realtime encoding (for
98 // example, capturing a television signal or feed from a live camera). Speed
99 // setting controls how fast.
100 REALTIME
101 } MODE;
102
103 typedef enum {
104 FRAMEFLAGS_KEY = 1 << 0,
105 FRAMEFLAGS_GOLDEN = 1 << 1,
106 FRAMEFLAGS_ALTREF = 1 << 2,
107 } FRAMETYPE_FLAGS;
108
109 typedef enum {
110 NO_AQ = 0,
111 VARIANCE_AQ = 1,
112 COMPLEXITY_AQ = 2,
113 CYCLIC_REFRESH_AQ = 3,
114 AQ_MODE_COUNT // This should always be the last member of the enum
115 } AQ_MODE;
116
117 typedef enum {
118 RESIZE_NONE = 0, // No frame resizing allowed (except for SVC).
119 RESIZE_FIXED = 1, // All frames are coded at the specified dimension.
120 RESIZE_DYNAMIC = 2 // Coded size of each frame is determined by the codec.
121 } RESIZE_TYPE;
122
123 typedef struct VP9EncoderConfig {
124 BITSTREAM_PROFILE profile;
125 vpx_bit_depth_t bit_depth; // Codec bit-depth.
126 int width; // width of data passed to the compressor
127 int height; // height of data passed to the compressor
128 unsigned int input_bit_depth; // Input bit depth.
129 double init_framerate; // set to passed in framerate
130 int64_t target_bandwidth; // bandwidth to be used in kilobits per second
131
132 int noise_sensitivity; // pre processing blur: recommendation 0
133 int sharpness; // sharpening output: recommendation 0:
134 int speed;
135 // maximum allowed bitrate for any intra frame in % of bitrate target.
136 unsigned int rc_max_intra_bitrate_pct;
137 // maximum allowed bitrate for any inter frame in % of bitrate target.
138 unsigned int rc_max_inter_bitrate_pct;
139 // percent of rate boost for golden frame in CBR mode.
140 unsigned int gf_cbr_boost_pct;
141
142 MODE mode;
143 int pass;
144
145 // Key Framing Operations
146 int auto_key; // autodetect cut scenes and set the keyframes
147 int key_freq; // maximum distance to key frame.
148
149 int lag_in_frames; // how many frames lag before we start encoding
150
151 // ----------------------------------------------------------------
152 // DATARATE CONTROL OPTIONS
153
154 // vbr, cbr, constrained quality or constant quality
155 enum vpx_rc_mode rc_mode;
156
157 // buffer targeting aggressiveness
158 int under_shoot_pct;
159 int over_shoot_pct;
160
161 // buffering parameters
162 int64_t starting_buffer_level_ms;
163 int64_t optimal_buffer_level_ms;
164 int64_t maximum_buffer_size_ms;
165
166 // Frame drop threshold.
167 int drop_frames_water_mark;
168
169 // controlling quality
170 int fixed_q;
171 int worst_allowed_q;
172 int best_allowed_q;
173 int cq_level;
174 AQ_MODE aq_mode; // Adaptive Quantization mode
175
176 // Internal frame size scaling.
177 RESIZE_TYPE resize_mode;
178 int scaled_frame_width;
179 int scaled_frame_height;
180
181 // Enable feature to reduce the frame quantization every x frames.
182 int frame_periodic_boost;
183
184 // two pass datarate control
185 int two_pass_vbrbias; // two pass datarate control tweaks
186 int two_pass_vbrmin_section;
187 int two_pass_vbrmax_section;
188 // END DATARATE CONTROL OPTIONS
189 // ----------------------------------------------------------------
190
191 // Spatial and temporal scalability.
192 int ss_number_layers; // Number of spatial layers.
193 int ts_number_layers; // Number of temporal layers.
194 // Bitrate allocation for spatial layers.
195 int layer_target_bitrate[VPX_MAX_LAYERS];
196 int ss_target_bitrate[VPX_SS_MAX_LAYERS];
197 int ss_enable_auto_arf[VPX_SS_MAX_LAYERS];
198 // Bitrate allocation (CBR mode) and framerate factor, for temporal layers.
199 int ts_rate_decimator[VPX_TS_MAX_LAYERS];
200
201 int enable_auto_arf;
202
203 int encode_breakout; // early breakout : for video conf recommend 800
204
205 /* Bitfield defining the error resiliency features to enable.
206 * Can provide decodable frames after losses in previous
207 * frames and decodable partitions after losses in the same frame.
208 */
209 unsigned int error_resilient_mode;
210
211 /* Bitfield defining the parallel decoding mode where the
212 * decoding in successive frames may be conducted in parallel
213 * just by decoding the frame headers.
214 */
215 unsigned int frame_parallel_decoding_mode;
216
217 int arnr_max_frames;
218 int arnr_strength;
219
220 int min_gf_interval;
221 int max_gf_interval;
222
223 int tile_columns;
224 int tile_rows;
225
226 int max_threads;
227
228 vpx_fixed_buf_t two_pass_stats_in;
229 struct vpx_codec_pkt_list *output_pkt_list;
230
231 #if CONFIG_FP_MB_STATS
232 vpx_fixed_buf_t firstpass_mb_stats_in;
233 #endif
234
235 vp8e_tuning tuning;
236 vp9e_tune_content content;
237 #if CONFIG_VP9_HIGHBITDEPTH
238 int use_highbitdepth;
239 #endif
240 vpx_color_space_t color_space;
241 vpx_color_range_t color_range;
242 int render_width;
243 int render_height;
244 VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
245 } VP9EncoderConfig;
246
is_lossless_requested(const VP9EncoderConfig * cfg)247 static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) {
248 return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
249 }
250
251 // TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
252 typedef struct TileDataEnc {
253 TileInfo tile_info;
254 int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
255 int mode_map[BLOCK_SIZES][MAX_MODES];
256 } TileDataEnc;
257
258 typedef struct RD_COUNTS {
259 vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
260 int64_t comp_pred_diff[REFERENCE_MODES];
261 int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];
262 } RD_COUNTS;
263
264 typedef struct ThreadData {
265 MACROBLOCK mb;
266 RD_COUNTS rd_counts;
267 FRAME_COUNTS *counts;
268
269 PICK_MODE_CONTEXT *leaf_tree;
270 PC_TREE *pc_tree;
271 PC_TREE *pc_root;
272 } ThreadData;
273
274 struct EncWorkerData;
275
276 typedef struct ActiveMap {
277 int enabled;
278 int update;
279 unsigned char *map;
280 } ActiveMap;
281
282 typedef enum {
283 Y,
284 U,
285 V,
286 ALL
287 } STAT_TYPE;
288
289 typedef struct IMAGE_STAT {
290 double stat[ALL+1];
291 double worst;
292 } ImageStat;
293
294 typedef struct VP9_COMP {
295 QUANTS quants;
296 ThreadData td;
297 MB_MODE_INFO_EXT *mbmi_ext_base;
298 DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);
299 DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);
300 VP9_COMMON common;
301 VP9EncoderConfig oxcf;
302 struct lookahead_ctx *lookahead;
303 struct lookahead_entry *alt_ref_source;
304
305 YV12_BUFFER_CONFIG *Source;
306 YV12_BUFFER_CONFIG *Last_Source; // NULL for first frame and alt_ref frames
307 YV12_BUFFER_CONFIG *un_scaled_source;
308 YV12_BUFFER_CONFIG scaled_source;
309 YV12_BUFFER_CONFIG *unscaled_last_source;
310 YV12_BUFFER_CONFIG scaled_last_source;
311
312 TileDataEnc *tile_data;
313 int allocated_tiles; // Keep track of memory allocated for tiles.
314
315 // For a still frame, this flag is set to 1 to skip partition search.
316 int partition_search_skippable_frame;
317
318 int scaled_ref_idx[MAX_REF_FRAMES];
319 int lst_fb_idx;
320 int gld_fb_idx;
321 int alt_fb_idx;
322
323 int refresh_last_frame;
324 int refresh_golden_frame;
325 int refresh_alt_ref_frame;
326
327 int ext_refresh_frame_flags_pending;
328 int ext_refresh_last_frame;
329 int ext_refresh_golden_frame;
330 int ext_refresh_alt_ref_frame;
331
332 int ext_refresh_frame_context_pending;
333 int ext_refresh_frame_context;
334
335 YV12_BUFFER_CONFIG last_frame_uf;
336
337 TOKENEXTRA *tile_tok[4][1 << 6];
338 unsigned int tok_count[4][1 << 6];
339
340 // Ambient reconstruction err target for force key frames
341 int64_t ambient_err;
342
343 RD_OPT rd;
344
345 CODING_CONTEXT coding_context;
346
347 int *nmvcosts[2];
348 int *nmvcosts_hp[2];
349 int *nmvsadcosts[2];
350 int *nmvsadcosts_hp[2];
351
352 int64_t last_time_stamp_seen;
353 int64_t last_end_time_stamp_seen;
354 int64_t first_time_stamp_ever;
355
356 RATE_CONTROL rc;
357 double framerate;
358
359 int interp_filter_selected[MAX_REF_FRAMES][SWITCHABLE];
360
361 struct vpx_codec_pkt_list *output_pkt_list;
362
363 MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
364 int mbgraph_n_frames; // number of frames filled in the above
365 int static_mb_pct; // % forced skip mbs by segmentation
366 int ref_frame_flags;
367
368 SPEED_FEATURES sf;
369
370 unsigned int max_mv_magnitude;
371 int mv_step_param;
372
373 int allow_comp_inter_inter;
374
375 // Default value is 1. From first pass stats, encode_breakout may be disabled.
376 ENCODE_BREAKOUT_TYPE allow_encode_breakout;
377
378 // Get threshold from external input. A suggested threshold is 800 for HD
379 // clips, and 300 for < HD clips.
380 int encode_breakout;
381
382 unsigned char *segmentation_map;
383
384 // segment threashold for encode breakout
385 int segment_encode_breakout[MAX_SEGMENTS];
386
387 CYCLIC_REFRESH *cyclic_refresh;
388 ActiveMap active_map;
389
390 fractional_mv_step_fp *find_fractional_mv_step;
391 vp9_full_search_fn_t full_search_sad;
392 vp9_diamond_search_fn_t diamond_search_sad;
393 vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
394 uint64_t time_receive_data;
395 uint64_t time_compress_data;
396 uint64_t time_pick_lpf;
397 uint64_t time_encode_sb_row;
398
399 #if CONFIG_FP_MB_STATS
400 int use_fp_mb_stats;
401 #endif
402
403 TWO_PASS twopass;
404
405 YV12_BUFFER_CONFIG alt_ref_buffer;
406
407
408 #if CONFIG_INTERNAL_STATS
409 unsigned int mode_chosen_counts[MAX_MODES];
410
411 int count;
412 uint64_t total_sq_error;
413 uint64_t total_samples;
414 ImageStat psnr;
415
416 uint64_t totalp_sq_error;
417 uint64_t totalp_samples;
418 ImageStat psnrp;
419
420 double total_blockiness;
421 double worst_blockiness;
422
423 int bytes;
424 double summed_quality;
425 double summed_weights;
426 double summedp_quality;
427 double summedp_weights;
428 unsigned int tot_recode_hits;
429 double worst_ssim;
430
431 ImageStat ssimg;
432 ImageStat fastssim;
433 ImageStat psnrhvs;
434
435 int b_calculate_ssimg;
436 int b_calculate_blockiness;
437
438 int b_calculate_consistency;
439
440 double total_inconsistency;
441 double worst_consistency;
442 Ssimv *ssim_vars;
443 Metrics metrics;
444 #endif
445 int b_calculate_psnr;
446
447 int droppable;
448
449 int initial_width;
450 int initial_height;
451 int initial_mbs; // Number of MBs in the full-size frame; to be used to
452 // normalize the firstpass stats. This will differ from the
453 // number of MBs in the current frame when the frame is
454 // scaled.
455
456 int use_svc;
457
458 SVC svc;
459
460 // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type.
461 diff *source_diff_var;
462 // The threshold used in SOURCE_VAR_BASED_PARTITION search type.
463 unsigned int source_var_thresh;
464 int frames_till_next_var_check;
465
466 int frame_flags;
467
468 search_site_config ss_cfg;
469
470 int mbmode_cost[INTRA_MODES];
471 unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
472 int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES];
473 int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
474 int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
475 int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
476
477 int multi_arf_allowed;
478 int multi_arf_enabled;
479 int multi_arf_last_grp_enabled;
480
481 #if CONFIG_VP9_TEMPORAL_DENOISING
482 VP9_DENOISER denoiser;
483 #endif
484
485 int resize_pending;
486 int resize_state;
487 int resize_scale_num;
488 int resize_scale_den;
489 int resize_avg_qp;
490 int resize_buffer_underflow;
491 int resize_count;
492
493 // VAR_BASED_PARTITION thresholds
494 // 0 - threshold_64x64; 1 - threshold_32x32;
495 // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
496 int64_t vbp_thresholds[4];
497 int64_t vbp_threshold_minmax;
498 int64_t vbp_threshold_sad;
499 BLOCK_SIZE vbp_bsize_min;
500
501 // Multi-threading
502 int num_workers;
503 VPxWorker *workers;
504 struct EncWorkerData *tile_thr_data;
505 VP9LfSync lf_row_sync;
506 } VP9_COMP;
507
508 void vp9_initialize_enc(void);
509
510 struct VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
511 BufferPool *const pool);
512 void vp9_remove_compressor(VP9_COMP *cpi);
513
514 void vp9_change_config(VP9_COMP *cpi, const VP9EncoderConfig *oxcf);
515
516 // receive a frames worth of data. caller can assume that a copy of this
517 // frame is made and not just a copy of the pointer..
518 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
519 YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
520 int64_t end_time_stamp);
521
522 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
523 size_t *size, uint8_t *dest,
524 int64_t *time_stamp, int64_t *time_end, int flush);
525
526 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
527 vp9_ppflags_t *flags);
528
529 int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags);
530
531 void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags);
532
533 int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
534 YV12_BUFFER_CONFIG *sd);
535
536 int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
537 YV12_BUFFER_CONFIG *sd);
538
539 int vp9_update_entropy(VP9_COMP *cpi, int update);
540
541 int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
542
543 int vp9_get_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
544
545 int vp9_set_internal_size(VP9_COMP *cpi,
546 VPX_SCALING horiz_mode, VPX_SCALING vert_mode);
547
548 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
549 unsigned int height);
550
551 void vp9_set_svc(VP9_COMP *cpi, int use_svc);
552
553 int vp9_get_quantizer(struct VP9_COMP *cpi);
554
frame_is_kf_gf_arf(const VP9_COMP * cpi)555 static INLINE int frame_is_kf_gf_arf(const VP9_COMP *cpi) {
556 return frame_is_intra_only(&cpi->common) ||
557 cpi->refresh_alt_ref_frame ||
558 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
559 }
560
get_ref_frame_map_idx(const VP9_COMP * cpi,MV_REFERENCE_FRAME ref_frame)561 static INLINE int get_ref_frame_map_idx(const VP9_COMP *cpi,
562 MV_REFERENCE_FRAME ref_frame) {
563 if (ref_frame == LAST_FRAME) {
564 return cpi->lst_fb_idx;
565 } else if (ref_frame == GOLDEN_FRAME) {
566 return cpi->gld_fb_idx;
567 } else {
568 return cpi->alt_fb_idx;
569 }
570 }
571
get_ref_frame_buf_idx(const VP9_COMP * const cpi,int ref_frame)572 static INLINE int get_ref_frame_buf_idx(const VP9_COMP *const cpi,
573 int ref_frame) {
574 const VP9_COMMON *const cm = &cpi->common;
575 const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
576 return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
577 }
578
get_ref_frame_buffer(VP9_COMP * cpi,MV_REFERENCE_FRAME ref_frame)579 static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
580 VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
581 VP9_COMMON *const cm = &cpi->common;
582 const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
583 return
584 buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf : NULL;
585 }
586
get_token_alloc(int mb_rows,int mb_cols)587 static INLINE int get_token_alloc(int mb_rows, int mb_cols) {
588 // TODO(JBB): double check we can't exceed this token count if we have a
589 // 32x32 transform crossing a boundary at a multiple of 16.
590 // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full
591 // resolution. We assume up to 1 token per pixel, and then allow
592 // a head room of 4.
593 return mb_rows * mb_cols * (16 * 16 * 3 + 4);
594 }
595
596 // Get the allocated token size for a tile. It does the same calculation as in
597 // the frame token allocation.
allocated_tokens(TileInfo tile)598 static INLINE int allocated_tokens(TileInfo tile) {
599 int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
600 int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
601
602 return get_token_alloc(tile_mb_rows, tile_mb_cols);
603 }
604
605 int64_t vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b);
606 #if CONFIG_VP9_HIGHBITDEPTH
607 int64_t vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a,
608 const YV12_BUFFER_CONFIG *b);
609 #endif // CONFIG_VP9_HIGHBITDEPTH
610
611 void vp9_scale_references(VP9_COMP *cpi);
612
613 void vp9_update_reference_frames(VP9_COMP *cpi);
614
615 void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
616
617 YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
618 YV12_BUFFER_CONFIG *unscaled,
619 YV12_BUFFER_CONFIG *scaled,
620 int use_normative_scaler);
621
622 void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags);
623
is_two_pass_svc(const struct VP9_COMP * const cpi)624 static INLINE int is_two_pass_svc(const struct VP9_COMP *const cpi) {
625 return cpi->use_svc && cpi->oxcf.pass != 0;
626 }
627
is_one_pass_cbr_svc(const struct VP9_COMP * const cpi)628 static INLINE int is_one_pass_cbr_svc(const struct VP9_COMP *const cpi) {
629 return (cpi->use_svc && cpi->oxcf.pass == 0);
630 }
631
is_altref_enabled(const VP9_COMP * const cpi)632 static INLINE int is_altref_enabled(const VP9_COMP *const cpi) {
633 return cpi->oxcf.mode != REALTIME && cpi->oxcf.lag_in_frames > 0 &&
634 (cpi->oxcf.enable_auto_arf &&
635 (!is_two_pass_svc(cpi) ||
636 cpi->oxcf.ss_enable_auto_arf[cpi->svc.spatial_layer_id]));
637 }
638
set_ref_ptrs(VP9_COMMON * cm,MACROBLOCKD * xd,MV_REFERENCE_FRAME ref0,MV_REFERENCE_FRAME ref1)639 static INLINE void set_ref_ptrs(VP9_COMMON *cm, MACROBLOCKD *xd,
640 MV_REFERENCE_FRAME ref0,
641 MV_REFERENCE_FRAME ref1) {
642 xd->block_refs[0] = &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME
643 : 0];
644 xd->block_refs[1] = &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME
645 : 0];
646 }
647
get_chessboard_index(const int frame_index)648 static INLINE int get_chessboard_index(const int frame_index) {
649 return frame_index & 0x1;
650 }
651
cond_cost_list(const struct VP9_COMP * cpi,int * cost_list)652 static INLINE int *cond_cost_list(const struct VP9_COMP *cpi, int *cost_list) {
653 return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
654 }
655
656 void vp9_new_framerate(VP9_COMP *cpi, double framerate);
657
658 #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
659
660 #ifdef __cplusplus
661 } // extern "C"
662 #endif
663
664 #endif // VP9_ENCODER_VP9_ENCODER_H_
665