]> granicus.if.org Git - libvpx/blob - vp10/encoder/encoder.h
a957b6382bc337cb7539e3558408240231c3beea
[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/tokenize.h"
37
38 #if CONFIG_VP9_TEMPORAL_DENOISING
39 #include "vp10/encoder/denoiser.h"
40 #endif
41
42 #if CONFIG_INTERNAL_STATS
43 #include "vpx_dsp/ssim.h"
44 #endif
45 #include "vpx_dsp/variance.h"
46 #include "vpx/internal/vpx_codec_internal.h"
47 #include "vpx_util/vpx_thread.h"
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_FRAMES];
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.
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 VP10EncoderConfig {
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   int enable_auto_arf;
192
193   int encode_breakout;  // early breakout : for video conf recommend 800
194
195   /* Bitfield defining the error resiliency features to enable.
196    * Can provide decodable frames after losses in previous
197    * frames and decodable partitions after losses in the same frame.
198    */
199   unsigned int error_resilient_mode;
200
201   /* Bitfield defining the parallel decoding mode where the
202    * decoding in successive frames may be conducted in parallel
203    * just by decoding the frame headers.
204    */
205   unsigned int frame_parallel_decoding_mode;
206
207   int arnr_max_frames;
208   int arnr_strength;
209
210   int min_gf_interval;
211   int max_gf_interval;
212
213   int tile_columns;
214   int tile_rows;
215
216   int max_threads;
217
218   vpx_fixed_buf_t two_pass_stats_in;
219   struct vpx_codec_pkt_list *output_pkt_list;
220
221 #if CONFIG_FP_MB_STATS
222   vpx_fixed_buf_t firstpass_mb_stats_in;
223 #endif
224
225   vp8e_tuning tuning;
226   vp9e_tune_content content;
227 #if CONFIG_VP9_HIGHBITDEPTH
228   int use_highbitdepth;
229 #endif
230   vpx_color_space_t color_space;
231   int color_range;
232   int render_width;
233   int render_height;
234 } VP10EncoderConfig;
235
236 static INLINE int is_lossless_requested(const VP10EncoderConfig *cfg) {
237   return cfg->best_allowed_q == 0 && cfg->worst_allowed_q == 0;
238 }
239
240 // TODO(jingning) All spatially adaptive variables should go to TileDataEnc.
241 typedef struct TileDataEnc {
242   TileInfo tile_info;
243   int thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
244   int mode_map[BLOCK_SIZES][MAX_MODES];
245 } TileDataEnc;
246
247 typedef struct RD_COUNTS {
248   vp10_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
249   int64_t comp_pred_diff[REFERENCE_MODES];
250   int64_t filter_diff[SWITCHABLE_FILTER_CONTEXTS];
251 } RD_COUNTS;
252
253 typedef struct ThreadData {
254   MACROBLOCK mb;
255   RD_COUNTS rd_counts;
256   FRAME_COUNTS *counts;
257
258   PICK_MODE_CONTEXT *leaf_tree;
259   PC_TREE *pc_tree;
260   PC_TREE *pc_root;
261 } ThreadData;
262
263 struct EncWorkerData;
264
265 typedef struct ActiveMap {
266   int enabled;
267   int update;
268   unsigned char *map;
269 } ActiveMap;
270
271 typedef enum {
272   Y,
273   U,
274   V,
275   ALL
276 } STAT_TYPE;
277
278 typedef struct IMAGE_STAT {
279   double stat[ALL+1];
280   double worst;
281 } ImageStat;
282
283 typedef struct VP10_COMP {
284   QUANTS quants;
285   ThreadData td;
286   MB_MODE_INFO_EXT *mbmi_ext_base;
287   DECLARE_ALIGNED(16, int16_t, y_dequant[QINDEX_RANGE][8]);
288   DECLARE_ALIGNED(16, int16_t, uv_dequant[QINDEX_RANGE][8]);
289   VP10_COMMON common;
290   VP10EncoderConfig oxcf;
291   struct lookahead_ctx    *lookahead;
292   struct lookahead_entry  *alt_ref_source;
293
294   YV12_BUFFER_CONFIG *Source;
295   YV12_BUFFER_CONFIG *Last_Source;  // NULL for first frame and alt_ref frames
296   YV12_BUFFER_CONFIG *un_scaled_source;
297   YV12_BUFFER_CONFIG scaled_source;
298   YV12_BUFFER_CONFIG *unscaled_last_source;
299   YV12_BUFFER_CONFIG scaled_last_source;
300
301   TileDataEnc *tile_data;
302   int allocated_tiles;  // Keep track of memory allocated for tiles.
303
304   // For a still frame, this flag is set to 1 to skip partition search.
305   int partition_search_skippable_frame;
306
307   int scaled_ref_idx[MAX_REF_FRAMES];
308   int lst_fb_idx;
309   int gld_fb_idx;
310   int alt_fb_idx;
311
312   int refresh_last_frame;
313   int refresh_golden_frame;
314   int refresh_alt_ref_frame;
315
316   int ext_refresh_frame_flags_pending;
317   int ext_refresh_last_frame;
318   int ext_refresh_golden_frame;
319   int ext_refresh_alt_ref_frame;
320
321   int ext_refresh_frame_context_pending;
322   int ext_refresh_frame_context;
323
324   YV12_BUFFER_CONFIG last_frame_uf;
325
326   TOKENEXTRA *tile_tok[4][1 << 6];
327   unsigned int tok_count[4][1 << 6];
328
329   // Ambient reconstruction err target for force key frames
330   int64_t ambient_err;
331
332   RD_OPT rd;
333
334   CODING_CONTEXT coding_context;
335
336   int *nmvcosts[2];
337   int *nmvcosts_hp[2];
338   int *nmvsadcosts[2];
339   int *nmvsadcosts_hp[2];
340
341   int64_t last_time_stamp_seen;
342   int64_t last_end_time_stamp_seen;
343   int64_t first_time_stamp_ever;
344
345   RATE_CONTROL rc;
346   double framerate;
347
348   int interp_filter_selected[MAX_REF_FRAMES][SWITCHABLE];
349
350   struct vpx_codec_pkt_list  *output_pkt_list;
351
352   MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
353   int mbgraph_n_frames;             // number of frames filled in the above
354   int static_mb_pct;                // % forced skip mbs by segmentation
355   int ref_frame_flags;
356
357   SPEED_FEATURES sf;
358
359   unsigned int max_mv_magnitude;
360   int mv_step_param;
361
362   int allow_comp_inter_inter;
363
364   // Default value is 1. From first pass stats, encode_breakout may be disabled.
365   ENCODE_BREAKOUT_TYPE allow_encode_breakout;
366
367   // Get threshold from external input. A suggested threshold is 800 for HD
368   // clips, and 300 for < HD clips.
369   int encode_breakout;
370
371   unsigned char *segmentation_map;
372
373   // segment threashold for encode breakout
374   int  segment_encode_breakout[MAX_SEGMENTS];
375
376   CYCLIC_REFRESH *cyclic_refresh;
377   ActiveMap active_map;
378
379   fractional_mv_step_fp *find_fractional_mv_step;
380   vp10_full_search_fn_t full_search_sad;
381   vp10_diamond_search_fn_t diamond_search_sad;
382   vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
383   uint64_t time_receive_data;
384   uint64_t time_compress_data;
385   uint64_t time_pick_lpf;
386   uint64_t time_encode_sb_row;
387
388 #if CONFIG_FP_MB_STATS
389   int use_fp_mb_stats;
390 #endif
391
392   TWO_PASS twopass;
393
394   YV12_BUFFER_CONFIG alt_ref_buffer;
395
396
397 #if CONFIG_INTERNAL_STATS
398   unsigned int mode_chosen_counts[MAX_MODES];
399
400   int    count;
401   uint64_t total_sq_error;
402   uint64_t total_samples;
403   ImageStat psnr;
404
405   uint64_t totalp_sq_error;
406   uint64_t totalp_samples;
407   ImageStat psnrp;
408
409   double total_blockiness;
410   double worst_blockiness;
411
412   int    bytes;
413   double summed_quality;
414   double summed_weights;
415   double summedp_quality;
416   double summedp_weights;
417   unsigned int tot_recode_hits;
418   double worst_ssim;
419
420   ImageStat ssimg;
421   ImageStat fastssim;
422   ImageStat psnrhvs;
423
424   int b_calculate_ssimg;
425   int b_calculate_blockiness;
426
427   int b_calculate_consistency;
428
429   double total_inconsistency;
430   double worst_consistency;
431   Ssimv *ssim_vars;
432   Metrics metrics;
433 #endif
434   int b_calculate_psnr;
435
436   int droppable;
437
438   int initial_width;
439   int initial_height;
440   int initial_mbs;  // Number of MBs in the full-size frame; to be used to
441                     // normalize the firstpass stats. This will differ from the
442                     // number of MBs in the current frame when the frame is
443                     // scaled.
444
445   // Store frame variance info in SOURCE_VAR_BASED_PARTITION search type.
446   diff *source_diff_var;
447   // The threshold used in SOURCE_VAR_BASED_PARTITION search type.
448   unsigned int source_var_thresh;
449   int frames_till_next_var_check;
450
451   int frame_flags;
452
453   search_site_config ss_cfg;
454
455   int mbmode_cost[INTRA_MODES];
456   unsigned int inter_mode_cost[INTER_MODE_CONTEXTS][INTER_MODES];
457   int intra_uv_mode_cost[FRAME_TYPES][INTRA_MODES];
458   int y_mode_costs[INTRA_MODES][INTRA_MODES][INTRA_MODES];
459   int switchable_interp_costs[SWITCHABLE_FILTER_CONTEXTS][SWITCHABLE_FILTERS];
460   int partition_cost[PARTITION_CONTEXTS][PARTITION_TYPES];
461   int palette_y_size_cost[10][PALETTE_SIZES];
462   int palette_uv_size_cost[10][PALETTE_SIZES];
463   int palette_y_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS]
464                                                  [PALETTE_COLORS];
465   int palette_uv_color_cost[PALETTE_MAX_SIZE - 1][PALETTE_COLOR_CONTEXTS]
466                                                   [PALETTE_COLORS];
467
468   int multi_arf_allowed;
469   int multi_arf_enabled;
470   int multi_arf_last_grp_enabled;
471
472 #if CONFIG_VP9_TEMPORAL_DENOISING
473   VP9_DENOISER denoiser;
474 #endif
475
476   int resize_pending;
477   int resize_state;
478   int resize_scale_num;
479   int resize_scale_den;
480   int resize_avg_qp;
481   int resize_buffer_underflow;
482   int resize_count;
483
484   // VAR_BASED_PARTITION thresholds
485   // 0 - threshold_64x64; 1 - threshold_32x32;
486   // 2 - threshold_16x16; 3 - vbp_threshold_8x8;
487   int64_t vbp_thresholds[4];
488   int64_t vbp_threshold_minmax;
489   int64_t vbp_threshold_sad;
490   BLOCK_SIZE vbp_bsize_min;
491
492   // Multi-threading
493   int num_workers;
494   VPxWorker *workers;
495   struct EncWorkerData *tile_thr_data;
496   VP9LfSync lf_row_sync;
497 } VP10_COMP;
498
499 void vp10_initialize_enc(void);
500
501 struct VP10_COMP *vp10_create_compressor(VP10EncoderConfig *oxcf,
502                                        BufferPool *const pool);
503 void vp10_remove_compressor(VP10_COMP *cpi);
504
505 void vp10_change_config(VP10_COMP *cpi, const VP10EncoderConfig *oxcf);
506
507   // receive a frames worth of data. caller can assume that a copy of this
508   // frame is made and not just a copy of the pointer..
509 int vp10_receive_raw_frame(VP10_COMP *cpi, unsigned int frame_flags,
510                           YV12_BUFFER_CONFIG *sd, int64_t time_stamp,
511                           int64_t end_time_stamp);
512
513 int vp10_get_compressed_data(VP10_COMP *cpi, unsigned int *frame_flags,
514                             size_t *size, uint8_t *dest,
515                             int64_t *time_stamp, int64_t *time_end, int flush);
516
517 int vp10_get_preview_raw_frame(VP10_COMP *cpi, YV12_BUFFER_CONFIG *dest,
518                               vp10_ppflags_t *flags);
519
520 int vp10_use_as_reference(VP10_COMP *cpi, int ref_frame_flags);
521
522 void vp10_update_reference(VP10_COMP *cpi, int ref_frame_flags);
523
524 int vp10_copy_reference_enc(VP10_COMP *cpi, VP9_REFFRAME ref_frame_flag,
525                            YV12_BUFFER_CONFIG *sd);
526
527 int vp10_set_reference_enc(VP10_COMP *cpi, VP9_REFFRAME ref_frame_flag,
528                           YV12_BUFFER_CONFIG *sd);
529
530 int vp10_update_entropy(VP10_COMP *cpi, int update);
531
532 int vp10_set_active_map(VP10_COMP *cpi, unsigned char *map, int rows, int cols);
533
534 int vp10_get_active_map(VP10_COMP *cpi, unsigned char *map, int rows, int cols);
535
536 int vp10_set_internal_size(VP10_COMP *cpi,
537                           VPX_SCALING horiz_mode, VPX_SCALING vert_mode);
538
539 int vp10_set_size_literal(VP10_COMP *cpi, unsigned int width,
540                          unsigned int height);
541
542 int vp10_get_quantizer(struct VP10_COMP *cpi);
543
544 static INLINE int frame_is_kf_gf_arf(const VP10_COMP *cpi) {
545   return frame_is_intra_only(&cpi->common) ||
546          cpi->refresh_alt_ref_frame ||
547          (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref);
548 }
549
550 static INLINE int get_ref_frame_map_idx(const VP10_COMP *cpi,
551                                         MV_REFERENCE_FRAME ref_frame) {
552   if (ref_frame == LAST_FRAME) {
553     return cpi->lst_fb_idx;
554   } else if (ref_frame == GOLDEN_FRAME) {
555     return cpi->gld_fb_idx;
556   } else {
557     return cpi->alt_fb_idx;
558   }
559 }
560
561 static INLINE int get_ref_frame_buf_idx(const VP10_COMP *const cpi,
562                                         int ref_frame) {
563   const VP10_COMMON *const cm = &cpi->common;
564   const int map_idx = get_ref_frame_map_idx(cpi, ref_frame);
565   return (map_idx != INVALID_IDX) ? cm->ref_frame_map[map_idx] : INVALID_IDX;
566 }
567
568 static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
569     VP10_COMP *cpi, MV_REFERENCE_FRAME ref_frame) {
570   VP10_COMMON *const cm = &cpi->common;
571   const int buf_idx = get_ref_frame_buf_idx(cpi, ref_frame);
572   return
573       buf_idx != INVALID_IDX ? &cm->buffer_pool->frame_bufs[buf_idx].buf : NULL;
574 }
575
576 static INLINE int get_token_alloc(int mb_rows, int mb_cols) {
577   // TODO(JBB): double check we can't exceed this token count if we have a
578   // 32x32 transform crossing a boundary at a multiple of 16.
579   // mb_rows, cols are in units of 16 pixels. We assume 3 planes all at full
580   // resolution. We assume up to 1 token per pixel, and then allow
581   // a head room of 1 EOSB token per 8x8 block per plane.
582   return mb_rows * mb_cols * (16 * 16 + 4) * 3;
583 }
584
585 // Get the allocated token size for a tile. It does the same calculation as in
586 // the frame token allocation.
587 static INLINE int allocated_tokens(TileInfo tile) {
588   int tile_mb_rows = (tile.mi_row_end - tile.mi_row_start + 1) >> 1;
589   int tile_mb_cols = (tile.mi_col_end - tile.mi_col_start + 1) >> 1;
590
591   return get_token_alloc(tile_mb_rows, tile_mb_cols);
592 }
593
594 int64_t vp10_get_y_sse(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b);
595 #if CONFIG_VP9_HIGHBITDEPTH
596 int64_t vp10_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a,
597                              const YV12_BUFFER_CONFIG *b);
598 #endif  // CONFIG_VP9_HIGHBITDEPTH
599
600 void vp10_alloc_compressor_data(VP10_COMP *cpi);
601
602 void vp10_scale_references(VP10_COMP *cpi);
603
604 void vp10_update_reference_frames(VP10_COMP *cpi);
605
606 void vp10_set_high_precision_mv(VP10_COMP *cpi, int allow_high_precision_mv);
607
608 YV12_BUFFER_CONFIG *vp10_scale_if_required_fast(VP10_COMMON *cm,
609                                                YV12_BUFFER_CONFIG *unscaled,
610                                                YV12_BUFFER_CONFIG *scaled);
611
612 YV12_BUFFER_CONFIG *vp10_scale_if_required(VP10_COMMON *cm,
613                                           YV12_BUFFER_CONFIG *unscaled,
614                                           YV12_BUFFER_CONFIG *scaled);
615
616 void vp10_apply_encoding_flags(VP10_COMP *cpi, vpx_enc_frame_flags_t flags);
617
618 static INLINE int is_altref_enabled(const VP10_COMP *const cpi) {
619   return cpi->oxcf.mode != REALTIME && cpi->oxcf.lag_in_frames > 0 &&
620          cpi->oxcf.enable_auto_arf;
621 }
622
623 static INLINE void set_ref_ptrs(VP10_COMMON *cm, MACROBLOCKD *xd,
624                                 MV_REFERENCE_FRAME ref0,
625                                 MV_REFERENCE_FRAME ref1) {
626   xd->block_refs[0] = &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME
627                                                          : 0];
628   xd->block_refs[1] = &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME
629                                                          : 0];
630 }
631
632 static INLINE int get_chessboard_index(const int frame_index) {
633   return frame_index & 0x1;
634 }
635
636 static INLINE int *cond_cost_list(const struct VP10_COMP *cpi, int *cost_list) {
637   return cpi->sf.mv.subpel_search_method != SUBPEL_TREE ? cost_list : NULL;
638 }
639
640 void vp10_new_framerate(VP10_COMP *cpi, double framerate);
641
642 #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
643
644 #ifdef __cplusplus
645 }  // extern "C"
646 #endif
647
648 #endif  // VP10_ENCODER_ENCODER_H_