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