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