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