Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / libvpx / source / libvpx / vp9 / encoder / vp9_onyx_int.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_ONYX_INT_H_
12 #define VP9_ENCODER_VP9_ONYX_INT_H_
13
14 #include <stdio.h>
15
16 #include "./vpx_config.h"
17 #include "vpx_ports/mem.h"
18 #include "vpx/internal/vpx_codec_internal.h"
19
20 #include "vp9/common/vp9_entropy.h"
21 #include "vp9/common/vp9_entropymode.h"
22 #include "vp9/common/vp9_onyx.h"
23 #include "vp9/common/vp9_onyxc_int.h"
24
25 #include "vp9/encoder/vp9_encodemb.h"
26 #include "vp9/encoder/vp9_firstpass.h"
27 #include "vp9/encoder/vp9_lookahead.h"
28 #include "vp9/encoder/vp9_mbgraph.h"
29 #include "vp9/encoder/vp9_mcomp.h"
30 #include "vp9/encoder/vp9_quantize.h"
31 #include "vp9/encoder/vp9_ratectrl.h"
32 #include "vp9/encoder/vp9_tokenize.h"
33 #include "vp9/encoder/vp9_treewriter.h"
34 #include "vp9/encoder/vp9_variance.h"
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 // #define MODE_TEST_HIT_STATS
41
42 #if CONFIG_MULTIPLE_ARF
43 // Set MIN_GF_INTERVAL to 1 for the full decomposition.
44 #define MIN_GF_INTERVAL             2
45 #else
46 #define MIN_GF_INTERVAL             4
47 #endif
48 #define DEFAULT_GF_INTERVAL         10
49 #define DEFAULT_KF_BOOST            2000
50 #define DEFAULT_GF_BOOST            2000
51
52 #define KEY_FRAME_CONTEXT 5
53
54 #define MAX_MODES 30
55 #define MAX_REFS  6
56
57 #define MIN_THRESHMULT  32
58 #define MAX_THRESHMULT  512
59
60 #define GF_ZEROMV_ZBIN_BOOST 0
61 #define LF_ZEROMV_ZBIN_BOOST 0
62 #define MV_ZBIN_BOOST        0
63 #define SPLIT_MV_ZBIN_BOOST  0
64 #define INTRA_ZBIN_BOOST     0
65
66 typedef struct {
67   int nmvjointcost[MV_JOINTS];
68   int nmvcosts[2][MV_VALS];
69   int nmvcosts_hp[2][MV_VALS];
70
71   vp9_prob segment_pred_probs[PREDICTION_PROBS];
72
73   unsigned char *last_frame_seg_map_copy;
74
75   // 0 = Intra, Last, GF, ARF
76   signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];
77   // 0 = ZERO_MV, MV
78   signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];
79
80   FRAME_CONTEXT fc;
81 } CODING_CONTEXT;
82
83 // This enumerator type needs to be kept aligned with the mode order in
84 // const MODE_DEFINITION vp9_mode_order[MAX_MODES] used in the rd code.
85 typedef enum {
86   THR_NEARESTMV,
87   THR_NEARESTA,
88   THR_NEARESTG,
89
90   THR_DC,
91
92   THR_NEWMV,
93   THR_NEWA,
94   THR_NEWG,
95
96   THR_NEARMV,
97   THR_NEARA,
98   THR_COMP_NEARESTLA,
99   THR_COMP_NEARESTGA,
100
101   THR_TM,
102
103   THR_COMP_NEARLA,
104   THR_COMP_NEWLA,
105   THR_NEARG,
106   THR_COMP_NEARGA,
107   THR_COMP_NEWGA,
108
109   THR_ZEROMV,
110   THR_ZEROG,
111   THR_ZEROA,
112   THR_COMP_ZEROLA,
113   THR_COMP_ZEROGA,
114
115   THR_H_PRED,
116   THR_V_PRED,
117   THR_D135_PRED,
118   THR_D207_PRED,
119   THR_D153_PRED,
120   THR_D63_PRED,
121   THR_D117_PRED,
122   THR_D45_PRED,
123 } THR_MODES;
124
125 typedef enum {
126   THR_LAST,
127   THR_GOLD,
128   THR_ALTR,
129   THR_COMP_LA,
130   THR_COMP_GA,
131   THR_INTRA,
132 } THR_MODES_SUB8X8;
133
134 typedef enum {
135   DIAMOND = 0,
136   NSTEP = 1,
137   HEX = 2,
138   BIGDIA = 3,
139   SQUARE = 4
140 } SEARCH_METHODS;
141
142 typedef enum {
143   USE_FULL_RD = 0,
144   USE_LARGESTINTRA,
145   USE_LARGESTINTRA_MODELINTER,
146   USE_LARGESTALL
147 } TX_SIZE_SEARCH_METHOD;
148
149 typedef enum {
150   NOT_IN_USE = 0,
151   RELAXED_NEIGHBORING_MIN_MAX = 1,
152   STRICT_NEIGHBORING_MIN_MAX = 2
153 } AUTO_MIN_MAX_MODE;
154
155 typedef enum {
156   // Values should be powers of 2 so that they can be selected as bits of
157   // an integer flags field
158
159   // terminate search early based on distortion so far compared to
160   // qp step, distortion in the neighborhood of the frame, etc.
161   FLAG_EARLY_TERMINATE = 1,
162
163   // skips comp inter modes if the best so far is an intra mode
164   FLAG_SKIP_COMP_BESTINTRA = 2,
165
166   // skips comp inter modes if the best single intermode so far does
167   // not have the same reference as one of the two references being
168   // tested
169   FLAG_SKIP_COMP_REFMISMATCH = 4,
170
171   // skips oblique intra modes if the best so far is an inter mode
172   FLAG_SKIP_INTRA_BESTINTER = 8,
173
174   // skips oblique intra modes  at angles 27, 63, 117, 153 if the best
175   // intra so far is not one of the neighboring directions
176   FLAG_SKIP_INTRA_DIRMISMATCH = 16,
177
178   // skips intra modes other than DC_PRED if the source variance
179   // is small
180   FLAG_SKIP_INTRA_LOWVAR = 32,
181 } MODE_SEARCH_SKIP_LOGIC;
182
183 typedef enum {
184   SUBPEL_TREE = 0,
185   // Other methods to come
186 } SUBPEL_SEARCH_METHODS;
187
188 #define ALL_INTRA_MODES 0x3FF
189 #define INTRA_DC_ONLY 0x01
190 #define INTRA_DC_TM ((1 << TM_PRED) | (1 << DC_PRED))
191 #define INTRA_DC_H_V ((1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED))
192 #define INTRA_DC_TM_H_V (INTRA_DC_TM | (1 << V_PRED) | (1 << H_PRED))
193
194 typedef enum {
195   LAST_FRAME_PARTITION_OFF = 0,
196   LAST_FRAME_PARTITION_LOW_MOTION = 1,
197   LAST_FRAME_PARTITION_ALL = 2
198 } LAST_FRAME_PARTITION_METHOD;
199
200 typedef enum {
201   // No recode.
202   DISALLOW_RECODE = 0,
203   // Allow recode for KF and exceeding maximum frame bandwidth.
204   ALLOW_RECODE_KFMAXBW = 1,
205   // Allow recode only for KF/ARF/GF frames.
206   ALLOW_RECODE_KFARFGF = 2,
207   // Allow recode for all frames based on bitrate constraints.
208   ALLOW_RECODE = 3,
209 } RECODE_LOOP_TYPE;
210
211 typedef enum {
212   // encode_breakout is disabled.
213   ENCODE_BREAKOUT_DISABLED = 0,
214   // encode_breakout is enabled.
215   ENCODE_BREAKOUT_ENABLED = 1,
216   // encode_breakout is enabled with small max_thresh limit.
217   ENCODE_BREAKOUT_LIMITED = 2
218 } ENCODE_BREAKOUT_TYPE;
219
220 typedef struct {
221   // Frame level coding parameter update
222   int frame_parameter_update;
223
224   // Motion search method (Diamond, NSTEP, Hex, Big Diamond, Square, etc).
225   SEARCH_METHODS search_method;
226
227   RECODE_LOOP_TYPE recode_loop;
228
229   // Subpel_search_method can only be subpel_tree which does a subpixel
230   // logarithmic search that keeps stepping at 1/2 pixel units until
231   // you stop getting a gain, and then goes on to 1/4 and repeats
232   // the same process. Along the way it skips many diagonals.
233   SUBPEL_SEARCH_METHODS subpel_search_method;
234
235   // Maximum number of steps in logarithmic subpel search before giving up.
236   int subpel_iters_per_step;
237
238   // Control when to stop subpel search
239   int subpel_force_stop;
240
241   // Thresh_mult is used to set a threshold for the rd score. A higher value
242   // means that we will accept the best mode so far more often. This number
243   // is used in combination with the current block size, and thresh_freq_fact
244   // to pick a threshold.
245   int thresh_mult[MAX_MODES];
246   int thresh_mult_sub8x8[MAX_REFS];
247
248   // This parameter controls the number of steps we'll do in a diamond
249   // search.
250   int max_step_search_steps;
251
252   // This parameter controls which step in the n-step process we start at.
253   // It's changed adaptively based on circumstances.
254   int reduce_first_step_size;
255
256   // If this is set to 1, we limit the motion search range to 2 times the
257   // largest motion vector found in the last frame.
258   int auto_mv_step_size;
259
260   // Trellis (dynamic programming) optimization of quantized values (+1, 0).
261   int optimize_coefficients;
262
263   // Always set to 0. If on it enables 0 cost background transmission
264   // (except for the initial transmission of the segmentation). The feature is
265   // disabled because the addition of very large block sizes make the
266   // backgrounds very to cheap to encode, and the segmentation we have
267   // adds overhead.
268   int static_segmentation;
269
270   // If 1 we iterate finding a best reference for 2 ref frames together - via
271   // a log search that iterates 4 times (check around mv for last for best
272   // error of combined predictor then check around mv for alt). If 0 we
273   // we just use the best motion vector found for each frame by itself.
274   int comp_inter_joint_search_thresh;
275
276   // This variable is used to cap the maximum number of times we skip testing a
277   // mode to be evaluated. A high value means we will be faster.
278   int adaptive_rd_thresh;
279
280   // Enables skipping the reconstruction step (idct, recon) in the
281   // intermediate steps assuming the last frame didn't have too many intra
282   // blocks and the q is less than a threshold.
283   int skip_encode_sb;
284   int skip_encode_frame;
285
286   // This variable allows us to reuse the last frames partition choices
287   // (64x64 v 32x32 etc) for this frame. It can be set to only use the last
288   // frame as a starting point in low motion scenes or always use it. If set
289   // we use last partitioning_redo frequency to determine how often to redo
290   // the partitioning from scratch. Adjust_partitioning_from_last_frame
291   // enables us to adjust up or down one partitioning from the last frames
292   // partitioning.
293   LAST_FRAME_PARTITION_METHOD use_lastframe_partitioning;
294
295   // Determine which method we use to determine transform size. We can choose
296   // between options like full rd, largest for prediction size, largest
297   // for intra and model coefs for the rest.
298   TX_SIZE_SEARCH_METHOD tx_size_search_method;
299
300   // Low precision 32x32 fdct keeps everything in 16 bits and thus is less
301   // precise but significantly faster than the non lp version.
302   int use_lp32x32fdct;
303
304   // TODO(JBB): remove this as its no longer used.
305
306   // If set partition size will always be always_this_block_size.
307   int use_one_partition_size_always;
308
309   // Skip rectangular partition test when partition type none gives better
310   // rd than partition type split.
311   int less_rectangular_check;
312
313   // Disable testing non square partitions. (eg 16x32)
314   int use_square_partition_only;
315
316   // After looking at the first set of modes (set by index here), skip
317   // checking modes for reference frames that don't match the reference frame
318   // of the best so far.
319   int mode_skip_start;
320
321   // TODO(JBB): Remove this.
322   int reference_masking;
323
324   // Used in conjunction with use_one_partition_size_always.
325   BLOCK_SIZE always_this_block_size;
326
327   // Sets min and max partition sizes for this 64x64 region based on the
328   // same 64x64 in last encoded frame, and the left and above neighbor.
329   AUTO_MIN_MAX_MODE auto_min_max_partition_size;
330
331   // Min and max partition size we enable (block_size) as per auto
332   // min max, but also used by adjust partitioning, and pick_partitioning.
333   BLOCK_SIZE min_partition_size;
334   BLOCK_SIZE max_partition_size;
335
336   // Whether or not we allow partitions one smaller or one greater than the last
337   // frame's partitioning. Only used if use_lastframe_partitioning is set.
338   int adjust_partitioning_from_last_frame;
339
340   // How frequently we re do the partitioning from scratch. Only used if
341   // use_lastframe_partitioning is set.
342   int last_partitioning_redo_frequency;
343
344   // Disables sub 8x8 blocksizes in different scenarios: Choices are to disable
345   // it always, to allow it for only Last frame and Intra, disable it for all
346   // inter modes or to enable it always.
347   int disable_split_mask;
348
349   // TODO(jingning): combine the related motion search speed features
350   // This allows us to use motion search at other sizes as a starting
351   // point for this motion search and limits the search range around it.
352   int adaptive_motion_search;
353
354   // Allows sub 8x8 modes to use the prediction filter that was determined
355   // best for 8x8 mode. If set to 0 we always re check all the filters for
356   // sizes less than 8x8, 1 means we check all filter modes if no 8x8 filter
357   // was selected, and 2 means we use 8 tap if no 8x8 filter mode was selected.
358   int adaptive_pred_interp_filter;
359
360   // Implements various heuristics to skip searching modes
361   // The heuristics selected are based on  flags
362   // defined in the MODE_SEARCH_SKIP_HEURISTICS enum
363   unsigned int mode_search_skip_flags;
364
365   // A source variance threshold below which the split mode is disabled
366   unsigned int disable_split_var_thresh;
367
368   // A source variance threshold below which filter search is disabled
369   // Choose a very large value (UINT_MAX) to use 8-tap always
370   unsigned int disable_filter_search_var_thresh;
371
372   // These bit masks allow you to enable or disable intra modes for each
373   // transform size separately.
374   int intra_y_mode_mask[TX_SIZES];
375   int intra_uv_mode_mask[TX_SIZES];
376
377   // This variable enables an early break out of mode testing if the model for
378   // rd built from the prediction signal indicates a value that's much
379   // higher than the best rd we've seen so far.
380   int use_rd_breakout;
381
382   // This enables us to use an estimate for intra rd based on dc mode rather
383   // than choosing an actual uv mode in the stage of encoding before the actual
384   // final encode.
385   int use_uv_intra_rd_estimate;
386
387   // This feature controls how the loop filter level is determined:
388   // 0: Try the full image with different values.
389   // 1: Try a small portion of the image with different values.
390   // 2: Estimate the level based on quantizer and frame type
391   int use_fast_lpf_pick;
392
393   // This feature limits the number of coefficients updates we actually do
394   // by only looking at counts from 1/2 the bands.
395   int use_fast_coef_updates;  // 0: 2-loop, 1: 1-loop, 2: 1-loop reduced
396
397   // This flag controls the use of non-RD mode decision.
398   int use_pick_mode;
399
400   // This variable sets the encode_breakout threshold. Currently, it is only
401   // enabled in real time mode.
402   int encode_breakout_thresh;
403 } SPEED_FEATURES;
404
405 typedef struct {
406   RATE_CONTROL rc;
407   int target_bandwidth;
408   int64_t starting_buffer_level;
409   int64_t optimal_buffer_level;
410   int64_t maximum_buffer_size;
411   double framerate;
412   int avg_frame_size;
413 } LAYER_CONTEXT;
414
415 typedef struct VP9_COMP {
416   DECLARE_ALIGNED(16, int16_t, y_quant[QINDEX_RANGE][8]);
417   DECLARE_ALIGNED(16, int16_t, y_quant_shift[QINDEX_RANGE][8]);
418   DECLARE_ALIGNED(16, int16_t, y_zbin[QINDEX_RANGE][8]);
419   DECLARE_ALIGNED(16, int16_t, y_round[QINDEX_RANGE][8]);
420
421   DECLARE_ALIGNED(16, int16_t, uv_quant[QINDEX_RANGE][8]);
422   DECLARE_ALIGNED(16, int16_t, uv_quant_shift[QINDEX_RANGE][8]);
423   DECLARE_ALIGNED(16, int16_t, uv_zbin[QINDEX_RANGE][8]);
424   DECLARE_ALIGNED(16, int16_t, uv_round[QINDEX_RANGE][8]);
425
426 #if CONFIG_ALPHA
427   DECLARE_ALIGNED(16, int16_t, a_quant[QINDEX_RANGE][8]);
428   DECLARE_ALIGNED(16, int16_t, a_quant_shift[QINDEX_RANGE][8]);
429   DECLARE_ALIGNED(16, int16_t, a_zbin[QINDEX_RANGE][8]);
430   DECLARE_ALIGNED(16, int16_t, a_round[QINDEX_RANGE][8]);
431 #endif
432
433   MACROBLOCK mb;
434   VP9_COMMON common;
435   VP9_CONFIG oxcf;
436   struct lookahead_ctx    *lookahead;
437   struct lookahead_entry  *source;
438 #if CONFIG_MULTIPLE_ARF
439   struct lookahead_entry  *alt_ref_source[REF_FRAMES];
440 #else
441   struct lookahead_entry  *alt_ref_source;
442 #endif
443
444   YV12_BUFFER_CONFIG *Source;
445   YV12_BUFFER_CONFIG *un_scaled_source;
446   YV12_BUFFER_CONFIG scaled_source;
447
448   unsigned int key_frame_frequency;
449
450   int gold_is_last;  // gold same as last frame ( short circuit gold searches)
451   int alt_is_last;  // Alt same as last ( short circuit altref search)
452   int gold_is_alt;  // don't do both alt and gold search ( just do gold).
453
454   int scaled_ref_idx[3];
455   int lst_fb_idx;
456   int gld_fb_idx;
457   int alt_fb_idx;
458
459 #if CONFIG_MULTIPLE_ARF
460   int alt_ref_fb_idx[REF_FRAMES - 3];
461 #endif
462   int refresh_last_frame;
463   int refresh_golden_frame;
464   int refresh_alt_ref_frame;
465
466   int ext_refresh_frame_flags_pending;
467   int ext_refresh_last_frame;
468   int ext_refresh_golden_frame;
469   int ext_refresh_alt_ref_frame;
470
471   int ext_refresh_frame_context_pending;
472   int ext_refresh_frame_context;
473
474   YV12_BUFFER_CONFIG last_frame_uf;
475
476   TOKENEXTRA *tok;
477   unsigned int tok_count[4][1 << 6];
478
479 #if CONFIG_MULTIPLE_ARF
480   // Position within a frame coding order (including any additional ARF frames).
481   unsigned int sequence_number;
482   // Next frame in naturally occurring order that has not yet been coded.
483   int next_frame_in_order;
484 #endif
485
486   // Ambient reconstruction err target for force key frames
487   int ambient_err;
488
489   unsigned int mode_chosen_counts[MAX_MODES];
490   unsigned int sub8x8_mode_chosen_counts[MAX_REFS];
491   int64_t mode_skip_mask;
492   int ref_frame_mask;
493   int set_ref_frame_mask;
494
495   int rd_threshes[MAX_SEGMENTS][BLOCK_SIZES][MAX_MODES];
496   int rd_thresh_freq_fact[BLOCK_SIZES][MAX_MODES];
497   int rd_thresh_sub8x8[MAX_SEGMENTS][BLOCK_SIZES][MAX_REFS];
498   int rd_thresh_freq_sub8x8[BLOCK_SIZES][MAX_REFS];
499
500   int64_t rd_comp_pred_diff[REFERENCE_MODES];
501   int64_t rd_prediction_type_threshes[4][REFERENCE_MODES];
502   int64_t rd_tx_select_diff[TX_MODES];
503   // FIXME(rbultje) can this overflow?
504   int rd_tx_select_threshes[4][TX_MODES];
505
506   int64_t rd_filter_diff[SWITCHABLE_FILTER_CONTEXTS];
507   int64_t rd_filter_threshes[4][SWITCHABLE_FILTER_CONTEXTS];
508   int64_t rd_filter_cache[SWITCHABLE_FILTER_CONTEXTS];
509   int64_t mask_filter_rd;
510
511   int RDMULT;
512   int RDDIV;
513
514   CODING_CONTEXT coding_context;
515
516   int zbin_mode_boost;
517   int zbin_mode_boost_enabled;
518   int active_arnr_frames;           // <= cpi->oxcf.arnr_max_frames
519   int active_arnr_strength;         // <= cpi->oxcf.arnr_max_strength
520
521   double output_framerate;
522   int64_t last_time_stamp_seen;
523   int64_t last_end_time_stamp_seen;
524   int64_t first_time_stamp_ever;
525
526   RATE_CONTROL rc;
527
528   int cq_target_quality;
529
530   vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES];
531   vp9_coeff_probs_model frame_coef_probs[TX_SIZES][PLANE_TYPES];
532   vp9_coeff_stats frame_branch_ct[TX_SIZES][PLANE_TYPES];
533
534   struct vpx_codec_pkt_list  *output_pkt_list;
535
536   MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS];
537   int mbgraph_n_frames;             // number of frames filled in the above
538   int static_mb_pct;                // % forced skip mbs by segmentation
539   int seg0_progress, seg0_idx, seg0_cnt;
540
541   // for real time encoding
542   int speed;
543
544   int cpu_used;
545   int pass;
546
547   vp9_prob last_skip_false_probs[3][SKIP_CONTEXTS];
548   int last_skip_probs_q[3];
549
550   int ref_frame_flags;
551
552   SPEED_FEATURES sf;
553
554   unsigned int max_mv_magnitude;
555   int mv_step_param;
556
557   // Default value is 1. From first pass stats, encode_breakout may be disabled.
558   ENCODE_BREAKOUT_TYPE allow_encode_breakout;
559
560   // Get threshold from external input. In real time mode, it can be
561   // overwritten according to encoding speed.
562   int encode_breakout;
563
564   unsigned char *segmentation_map;
565
566   // segment threashold for encode breakout
567   int  segment_encode_breakout[MAX_SEGMENTS];
568
569   unsigned char *complexity_map;
570
571   unsigned char *active_map;
572   unsigned int active_map_enabled;
573
574   fractional_mv_step_fp *find_fractional_mv_step;
575   fractional_mv_step_comp_fp *find_fractional_mv_step_comp;
576   vp9_full_search_fn_t full_search_sad;
577   vp9_refining_search_fn_t refining_search_sad;
578   vp9_diamond_search_fn_t diamond_search_sad;
579   vp9_variance_fn_ptr_t fn_ptr[BLOCK_SIZES];
580   uint64_t time_receive_data;
581   uint64_t time_compress_data;
582   uint64_t time_pick_lpf;
583   uint64_t time_encode_sb_row;
584
585   struct twopass_rc twopass;
586
587   YV12_BUFFER_CONFIG alt_ref_buffer;
588   YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
589   int fixed_divide[512];
590
591 #if CONFIG_INTERNAL_STATS
592   int    count;
593   double total_y;
594   double total_u;
595   double total_v;
596   double total;
597   uint64_t total_sq_error;
598   uint64_t total_samples;
599
600   double totalp_y;
601   double totalp_u;
602   double totalp_v;
603   double totalp;
604   uint64_t totalp_sq_error;
605   uint64_t totalp_samples;
606
607   int    bytes;
608   double summed_quality;
609   double summed_weights;
610   double summedp_quality;
611   double summedp_weights;
612   unsigned int tot_recode_hits;
613
614
615   double total_ssimg_y;
616   double total_ssimg_u;
617   double total_ssimg_v;
618   double total_ssimg_all;
619
620   int b_calculate_ssimg;
621 #endif
622   int b_calculate_psnr;
623
624   // Per MB activity measurement
625   unsigned int activity_avg;
626   unsigned int *mb_activity_map;
627   int *mb_norm_activity_map;
628   int output_partition;
629
630   // Force next frame to intra when kf_auto says so.
631   int force_next_frame_intra;
632
633   int droppable;
634
635   int dummy_packing;    /* flag to indicate if packing is dummy */
636
637   unsigned int tx_stepdown_count[TX_SIZES];
638
639   int initial_width;
640   int initial_height;
641
642   int use_svc;
643
644   struct svc {
645     int spatial_layer_id;
646     int temporal_layer_id;
647     int number_spatial_layers;
648     int number_temporal_layers;
649     // Layer context used for rate control in CBR mode, only defined for
650     // temporal layers for now.
651     LAYER_CONTEXT layer_context[VPX_TS_MAX_LAYERS];
652   } svc;
653
654 #if CONFIG_MULTIPLE_ARF
655   // ARF tracking variables.
656   int multi_arf_enabled;
657   unsigned int frame_coding_order_period;
658   unsigned int new_frame_coding_order_period;
659   int frame_coding_order[MAX_LAG_BUFFERS * 2];
660   int arf_buffer_idx[MAX_LAG_BUFFERS * 3 / 2];
661   int arf_weight[MAX_LAG_BUFFERS];
662   int arf_buffered;
663   int this_frame_weight;
664   int max_arf_level;
665 #endif
666
667 #ifdef ENTROPY_STATS
668   int64_t mv_ref_stats[INTER_MODE_CONTEXTS][INTER_MODES - 1][2];
669 #endif
670
671
672 #ifdef MODE_TEST_HIT_STATS
673   // Debug / test stats
674   int64_t mode_test_hits[BLOCK_SIZES];
675 #endif
676
677   // Y,U,V,(A)
678   ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
679   ENTROPY_CONTEXT left_context[MAX_MB_PLANE][16];
680
681   PARTITION_CONTEXT *above_seg_context;
682   PARTITION_CONTEXT left_seg_context[8];
683 } VP9_COMP;
684
685 static int get_ref_frame_idx(const VP9_COMP *cpi,
686                              MV_REFERENCE_FRAME ref_frame) {
687   if (ref_frame == LAST_FRAME) {
688     return cpi->lst_fb_idx;
689   } else if (ref_frame == GOLDEN_FRAME) {
690     return cpi->gld_fb_idx;
691   } else {
692     return cpi->alt_fb_idx;
693   }
694 }
695
696 static YV12_BUFFER_CONFIG *get_ref_frame_buffer(VP9_COMP *cpi,
697                                                 MV_REFERENCE_FRAME ref_frame) {
698   VP9_COMMON *const cm = &cpi->common;
699   return &cm->frame_bufs[cm->ref_frame_map[get_ref_frame_idx(cpi,
700                                                              ref_frame)]].buf;
701 }
702
703 void vp9_encode_frame(VP9_COMP *cpi);
704
705 void vp9_pack_bitstream(VP9_COMP *cpi, uint8_t *dest, size_t *size);
706
707 void vp9_set_speed_features(VP9_COMP *cpi);
708
709 int vp9_calc_ss_err(const YV12_BUFFER_CONFIG *source,
710                     const YV12_BUFFER_CONFIG *reference);
711
712 void vp9_alloc_compressor_data(VP9_COMP *cpi);
713
714 int vp9_compute_qdelta(const VP9_COMP *cpi, double qstart, double qtarget);
715
716 static int get_token_alloc(int mb_rows, int mb_cols) {
717   return mb_rows * mb_cols * (48 * 16 + 4);
718 }
719
720 static void set_ref_ptrs(VP9_COMMON *cm, MACROBLOCKD *xd,
721                          MV_REFERENCE_FRAME ref0, MV_REFERENCE_FRAME ref1) {
722   xd->block_refs[0] = &cm->frame_refs[ref0 >= LAST_FRAME ? ref0 - LAST_FRAME
723                                                          : 0];
724   xd->block_refs[1] = &cm->frame_refs[ref1 >= LAST_FRAME ? ref1 - LAST_FRAME
725                                                          : 0];
726 }
727
728 #ifdef __cplusplus
729 }  // extern "C"
730 #endif
731
732 #endif  // VP9_ENCODER_VP9_ONYX_INT_H_