]> granicus.if.org Git - libvpx/blob - vp9/encoder/vp9_encoder.h
vp9_aq_complexity.c: remove unused macros
[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 #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_noise_estimate.h"
39 #include "vp9/encoder/vp9_quantize.h"
40 #include "vp9/encoder/vp9_ratectrl.h"
41 #include "vp9/encoder/vp9_rd.h"
42 #include "vp9/encoder/vp9_speed_features.h"
43 #include "vp9/encoder/vp9_svc_layercontext.h"
44 #include "vp9/encoder/vp9_tokenize.h"
45
46 #if CONFIG_VP9_TEMPORAL_DENOISING
47 #include "vp9/encoder/vp9_denoiser.h"
48 #endif
49
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53
54 typedef struct {
55   int nmvjointcost[MV_JOINTS];
56   int nmvcosts[2][MV_VALS];
57   int nmvcosts_hp[2][MV_VALS];
58
59   vpx_prob segment_pred_probs[PREDICTION_PROBS];
60
61   unsigned char *last_frame_seg_map_copy;
62
63   // 0 = Intra, Last, GF, ARF
64   signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];
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
72 typedef enum {
73   // encode_breakout is disabled.
74   ENCODE_BREAKOUT_DISABLED = 0,
75   // encode_breakout is enabled.
76   ENCODE_BREAKOUT_ENABLED = 1,
77   // encode_breakout is enabled with small max_thresh limit.
78   ENCODE_BREAKOUT_LIMITED = 2
79 } ENCODE_BREAKOUT_TYPE;
80
81 typedef enum {
82   NORMAL      = 0,
83   FOURFIVE    = 1,
84   THREEFIVE   = 2,
85   ONETWO      = 3
86 } VPX_SCALING;
87
88 typedef enum {
89   // Good Quality Fast Encoding. The encoder balances quality with the amount of
90   // time it takes to encode the output. Speed setting controls how fast.
91   GOOD,
92
93   // The encoder places priority on the quality of the output over encoding
94   // speed. The output is compressed at the highest possible quality. This
95   // option takes the longest amount of time to encode. Speed setting ignored.
96   BEST,
97
98   // Realtime/Live Encoding. This mode is optimized for realtime encoding (for
99   // example, capturing a television signal or feed from a live camera). Speed
100   // setting controls how fast.
101   REALTIME
102 } MODE;
103
104 typedef enum {
105   FRAMEFLAGS_KEY    = 1 << 0,
106   FRAMEFLAGS_GOLDEN = 1 << 1,
107   FRAMEFLAGS_ALTREF = 1 << 2,
108 } FRAMETYPE_FLAGS;
109
110 typedef enum {
111   NO_AQ = 0,
112   VARIANCE_AQ = 1,
113   COMPLEXITY_AQ = 2,
114   CYCLIC_REFRESH_AQ = 3,
115   EQUATOR360_AQ = 4,
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 min_gf_interval;
223   int max_gf_interval;
224
225   int tile_columns;
226   int tile_rows;
227
228   int max_threads;
229
230   vpx_fixed_buf_t two_pass_stats_in;
231   struct vpx_codec_pkt_list *output_pkt_list;
232
233 #if CONFIG_FP_MB_STATS
234   vpx_fixed_buf_t firstpass_mb_stats_in;
235 #endif
236
237   vp8e_tuning tuning;
238   vp9e_tune_content content;
239 #if CONFIG_VP9_HIGHBITDEPTH
240   int use_highbitdepth;
241 #endif
242   vpx_color_space_t color_space;
243   vpx_color_range_t color_range;
244   int render_width;
245   int render_height;
246   VP9E_TEMPORAL_LAYERING_MODE temporal_layering_mode;
247 } VP9EncoderConfig;
248
249 static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) {
250   return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
251 }
252
253 // TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
254 typedef struct TileDataEnc {
255   TileInfo tile_info;
256   int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
257   int mode_map[BLOCK_SIZES][MAX_MODES];
258 } TileDataEnc;
259
260 typedef struct RD_COUNTS {
261   vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
262   int64_t comp_pred_diff[REFERENCE_MODES];
263   int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];
264   int m_search_count;
265   int ex_search_count;
266 } RD_COUNTS;
267
268 typedef struct ThreadData {
269   MACROBLOCK mb;
270   RD_COUNTS rd_counts;
271   FRAME_COUNTS *counts;
272
273   PICK_MODE_CONTEXT *leaf_tree;
274   PC_TREE *pc_tree;
275   PC_TREE *pc_root;
276 } ThreadData;
277
278 struct EncWorkerData;
279
280 typedef struct ActiveMap {
281   int enabled;
282   int update;
283   unsigned char *map;
284 } ActiveMap;
285
286 typedef enum {
287   Y,
288   U,
289   V,
290   ALL
291 } STAT_TYPE;
292
293 typedef struct IMAGE_STAT {
294   double stat[ALL+1];
295   double worst;
296 } ImageStat;
297
298 typedef struct VP9_COMP {
299   QUANTS quants;
300   ThreadData td;
301   MB_MODE_INFO_EXT *mbmi_ext_base;
302   DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);
303   DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);
304   VP9_COMMON common;
305   VP9EncoderConfig oxcf;
306   struct lookahead_ctx    *lookahead;
307   struct lookahead_entry  *alt_ref_source;
308
309   YV12_BUFFER_CONFIG *Source;
310   YV12_BUFFER_CONFIG *Last_Source;  // NULL for first frame and alt_ref frames
311   YV12_BUFFER_CONFIG *un_scaled_source;
312   YV12_BUFFER_CONFIG scaled_source;
313   YV12_BUFFER_CONFIG *unscaled_last_source;
314   YV12_BUFFER_CONFIG scaled_last_source;
315
316   TileDataEnc *tile_data;
317   int allocated_tiles;  // Keep track of memory allocated for tiles.
318
319   // For a still frame, this flag is set to 1 to skip partition search.
320   int partition_search_skippable_frame;
321
322   int scaled_ref_idx[MAX_REF_FRAMES];
323   int lst_fb_idx;
324   int gld_fb_idx;
325   int alt_fb_idx;
326
327   int refresh_last_frame;
328   int refresh_golden_frame;
329   int refresh_alt_ref_frame;
330
331   int ext_refresh_frame_flags_pending;
332   int ext_refresh_last_frame;
333   int ext_refresh_golden_frame;
334   int ext_refresh_alt_ref_frame;
335
336   int ext_refresh_frame_context_pending;
337   int ext_refresh_frame_context;
338
339   YV12_BUFFER_CONFIG last_frame_uf;
340
341   TOKENEXTRA *tile_tok[4][1 << 6];
342   unsigned int tok_count[4][1 << 6];
343
344   // Ambient reconstruction err target for force key frames
345   int64_t ambient_err;
346
347   RD_OPT rd;
348
349   CODING_CONTEXT coding_context;
350
351   int *nmvcosts[2];
352   int *nmvcosts_hp[2];
353   int *nmvsadcosts[2];
354   int *nmvsadcosts_hp[2];
355
356   int64_t last_time_stamp_seen;
357   int64_t last_end_time_stamp_seen;
358   int64_t first_time_stamp_ever;
359
360   RATE_CONTROL rc;
361   double framerate;
362
363   int interp_filter_selected[MAX_REF_FRAMES][SWITCHABLE];
364
365   struct vpx_codec_pkt_list  *output_pkt_list;
366
367   MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
368   int mbgraph_n_frames;             // number of frames filled in the above
369   int static_mb_pct;                // % forced skip mbs by segmentation
370   int ref_frame_flags;
371
372   SPEED_FEATURES sf;
373
374   unsigned int max_mv_magnitude;
375   int mv_step_param;
376
377   int allow_comp_inter_inter;
378
379   // Default value is 1. From first pass stats, encode_breakout may be disabled.
380   ENCODE_BREAKOUT_TYPE allow_encode_breakout;
381
382   // Get threshold from external input. A suggested threshold is 800 for HD
383   // clips, and 300 for < HD clips.
384   int encode_breakout;
385
386   unsigned char *segmentation_map;
387
388   // segment threashold for encode breakout
389   int  segment_encode_breakout[MAX_SEGMENTS];
390
391   CYCLIC_REFRESH *cyclic_refresh;
392   ActiveMap active_map;
393
394   fractional_mv_step_fp *find_fractional_mv_step;
395   vp9_full_search_fn_t full_search_sad;
396   vp9_diamond_search_fn_t diamond_search_sad;
397   vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
398   uint64_t time_receive_data;
399   uint64_t time_compress_data;
400   uint64_t time_pick_lpf;
401   uint64_t time_encode_sb_row;
402
403 #if CONFIG_FP_MB_STATS
404   int use_fp_mb_stats;
405 #endif
406
407   TWO_PASS twopass;
408
409   YV12_BUFFER_CONFIG alt_ref_buffer;
410
411
412 #if CONFIG_INTERNAL_STATS
413   unsigned int mode_chosen_counts[MAX_MODES];
414
415   int    count;
416   uint64_t total_sq_error;
417   uint64_t total_samples;
418   ImageStat psnr;
419
420   uint64_t totalp_sq_error;
421   uint64_t totalp_samples;
422   ImageStat psnrp;
423
424   double total_blockiness;
425   double worst_blockiness;
426
427   int    bytes;
428   double summed_quality;
429   double summed_weights;
430   double summedp_quality;
431   double summedp_weights;
432   unsigned int tot_recode_hits;
433   double worst_ssim;
434
435   ImageStat ssimg;
436   ImageStat fastssim;
437   ImageStat psnrhvs;
438
439   int b_calculate_ssimg;
440   int b_calculate_blockiness;
441
442   int b_calculate_consistency;
443
444   double total_inconsistency;
445   double worst_consistency;
446   Ssimv *ssim_vars;
447   Metrics metrics;
448 #endif
449   int b_calculate_psnr;
450
451   int droppable;
452
453   int initial_width;
454   int initial_height;
455   int initial_mbs;  // Number of MBs in the full-size frame; to be used to
456                     // normalize the firstpass stats. This will differ from the
457                     // number of MBs in the current frame when the frame is
458                     // scaled.
459
460   int use_svc;
461
462   SVC svc;
463
464   // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type.
465   diff *source_diff_var;
466   // The threshold used in SOURCE_VAR_BASED_PARTITION search type.
467   unsigned int source_var_thresh;
468   int frames_till_next_var_check;
469
470   int frame_flags;
471
472   search_site_config ss_cfg;
473
474   int mbmode_cost[INTRA_MODES];
475   unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
476   int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES][INTRA_MODES];
477   int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
478   int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
479   int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
480
481   int multi_arf_allowed;
482   int multi_arf_enabled;
483   int multi_arf_last_grp_enabled;
484
485 #if CONFIG_VP9_TEMPORAL_DENOISING
486   VP9_DENOISER denoiser;
487 #endif
488
489   int resize_pending;
490   int resize_state;
491   int resize_scale_num;
492   int resize_scale_den;
493   int resize_avg_qp;
494   int resize_buffer_underflow;
495   int resize_count;
496
497   int use_skin_detection;
498
499   NOISE_ESTIMATE noise_estimate;
500
501   // VAR_BASED_PARTITION thresholds
502   // 0 - threshold_64x64; 1 - threshold_32x32;
503   // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
504   int64_t vbp_thresholds[4];
505   int64_t vbp_threshold_minmax;
506   int64_t vbp_threshold_sad;
507   BLOCK_SIZE vbp_bsize_min;
508
509   // Multi-threading
510   int num_workers;
511   VPxWorker *workers;
512   struct EncWorkerData *tile_thr_data;
513   VP9LfSync lf_row_sync;
514 } VP9_COMP;
515
516 void vp9_initialize_enc(void);
517
518 struct VP9_COMP *vp9_create_compressor(VP9EncoderConfig *oxcf,
519                                        BufferPool *const pool);
520 void vp9_remove_compressor(VP9_COMP *cpi);
521
522 void vp9_change_config(VP9_COMP *cpi, const VP9EncoderConfig *oxcf);
523
524   // receive a frames worth of data. caller can assume that a copy of this
525   // frame is made and not just a copy of the pointer..
526 int vp9_receive_raw_frame(VP9_COMP *cpi, unsigned int frame_flags,
527                           YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
528                           int64_t end_time_stamp);
529
530 int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
531                             size_t *size, uint8_t *dest,
532                             int64_t *time_stamp, int64_t *time_end, int flush);
533
534 int vp9_get_preview_raw_frame(VP9_COMP *cpi, YV12_BUFFER_CONFIG *dest,
535                               vp9_ppflags_t *flags);
536
537 int vp9_use_as_reference(VP9_COMP *cpi, int ref_frame_flags);
538
539 void vp9_update_reference(VP9_COMP *cpi, int ref_frame_flags);
540
541 int vp9_copy_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
542                            YV12_BUFFER_CONFIG *sd);
543
544 int vp9_set_reference_enc(VP9_COMP *cpi, VP9_REFFRAME ref_frame_flag,
545                           YV12_BUFFER_CONFIG *sd);
546
547 int vp9_update_entropy(VP9_COMP *cpi, int update);
548
549 int vp9_set_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
550
551 int vp9_get_active_map(VP9_COMP *cpi, unsigned char *map, int rows, int cols);
552
553 int vp9_set_internal_size(VP9_COMP *cpi,
554                           VPX_SCALING horiz_mode, VPX_SCALING vert_mode);
555
556 int vp9_set_size_literal(VP9_COMP *cpi, unsigned int width,
557                          unsigned int height);
558
559 void vp9_set_svc(VP9_COMP *cpi, int use_svc);
560
561 int vp9_get_quantizer(struct VP9_COMP *cpi);
562
563 static INLINE int frame_is_kf_gf_arf(const VP9_COMP *cpi) {
564   return frame_is_intra_only(&cpi->common) ||
565          cpi->refresh_alt_ref_frame ||
566          (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
567 }
568
569 static INLINE int get_ref_frame_map_idx(const VP9_COMP *cpi,
570                                         MV_REFERENCE_FRAME ref_frame) {
571   if (ref_frame == LAST_FRAME) {
572     return cpi->lst_fb_idx;
573   } else if (ref_frame == GOLDEN_FRAME) {
574     return cpi->gld_fb_idx;
575   } else {
576     return cpi->alt_fb_idx;
577   }
578 }
579
580 static INLINE int get_ref_frame_buf_idx(const VP9_COMP *const cpi,
581                                         int ref_frame) {
582   const VP9_COMMON *const cm = &cpi->common;
583   const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
584   return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
585 }
586
587 static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
588     VP9_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
589   VP9_COMMON *const cm = &cpi->common;
590   const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
591   return
592       buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf : NULL;
593 }
594
595 static INLINE int get_token_alloc(int mb_rows, int mb_cols) {
596   // TODO(JBB): double check we can't exceed this token count if we have a
597   // 32x32 transform crossing a boundary at a multiple of 16.
598   // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full
599   // resolution. We assume up to 1 token per pixel, and then allow
600   // a head room of 4.
601   return mb_rows * mb_cols * (16 * 16 * 3 + 4);
602 }
603
604 // Get the allocated token size for a tile. It does the same calculation as in
605 // the frame token allocation.
606 static INLINE int allocated_tokens(TileInfo tile) {
607   int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
608   int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
609
610   return get_token_alloc(tile_mb_rows, tile_mb_cols);
611 }
612
613 int64_t vp9_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b);
614 #if CONFIG_VP9_HIGHBITDEPTH
615 int64_t vp9_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a,
616                              const YV12_BUFFER_CONFIG *b);
617 #endif  // CONFIG_VP9_HIGHBITDEPTH
618
619 void vp9_scale_references(VP9_COMP *cpi);
620
621 void vp9_update_reference_frames(VP9_COMP *cpi);
622
623 void vp9_set_high_precision_mv(VP9_COMP *cpi, int allow_high_precision_mv);
624
625 YV12_BUFFER_CONFIG *vp9_scale_if_required(VP9_COMMON *cm,
626                                           YV12_BUFFER_CONFIG *unscaled,
627                                           YV12_BUFFER_CONFIG *scaled,
628                                           int use_normative_scaler);
629
630 void vp9_apply_encoding_flags(VP9_COMP *cpi, vpx_enc_frame_flags_t flags);
631
632 static INLINE int is_two_pass_svc(const struct VP9_COMP *const cpi) {
633   return cpi->use_svc && cpi->oxcf.pass != 0;
634 }
635
636 static INLINE int is_one_pass_cbr_svc(const struct VP9_COMP *const cpi) {
637   return (cpi->use_svc && cpi->oxcf.pass == 0);
638 }
639
640 static INLINE int is_altref_enabled(const VP9_COMP *const cpi) {
641   return cpi->oxcf.mode != REALTIME && cpi->oxcf.lag_in_frames > 0 &&
642          (cpi->oxcf.enable_auto_arf &&
643           (!is_two_pass_svc(cpi) ||
644            cpi->oxcf.ss_enable_auto_arf[cpi->svc.spatial_layer_id]));
645 }
646
647 static INLINE void set_ref_ptrs(VP9_COMMON *cm, MACROBLOCKD *xd,
648                                 MV_REFERENCE_FRAME ref0,
649                                 MV_REFERENCE_FRAME ref1) {
650   xd->block_refs[0] = &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME
651                                                          : 0];
652   xd->block_refs[1] = &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME
653                                                          : 0];
654 }
655
656 static INLINE int get_chessboard_index(const int frame_index) {
657   return frame_index & 0x1;
658 }
659
660 static INLINE int *cond_cost_list(const struct VP9_COMP *cpi, int *cost_list) {
661   return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
662 }
663
664 void vp9_new_framerate(VP9_COMP *cpi, double framerate);
665
666 #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
667
668 #ifdef __cplusplus
669 }  // extern "C"
670 #endif
671
672 #endif  // VP9_ENCODER_VP9_ENCODER_H_