• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 VPX_VP8_ENCODER_ONYX_INT_H_
12 #define VPX_VP8_ENCODER_ONYX_INT_H_
13 
14 #include <assert.h>
15 #include <stdio.h>
16 
17 #include "vpx_config.h"
18 #include "vp8/common/onyx.h"
19 #include "treewriter.h"
20 #include "tokenize.h"
21 #include "vp8/common/onyxc_int.h"
22 #include "vpx_dsp/variance.h"
23 #include "encodemb.h"
24 #include "vp8/encoder/quantize.h"
25 #include "vp8/common/entropy.h"
26 #include "vp8/common/threading.h"
27 #include "vpx_ports/mem.h"
28 #include "vpx/internal/vpx_codec_internal.h"
29 #include "vpx/vp8.h"
30 #include "mcomp.h"
31 #include "vp8/common/findnearmv.h"
32 #include "lookahead.h"
33 #if CONFIG_TEMPORAL_DENOISING
34 #include "vp8/encoder/denoising.h"
35 #endif
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #define MIN_GF_INTERVAL 4
42 #define DEFAULT_GF_INTERVAL 7
43 
44 #define KEY_FRAME_CONTEXT 5
45 
46 #define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY ? 1 : 25)
47 
48 #define AF_THRESH 25
49 #define AF_THRESH2 100
50 #define ARF_DECAY_THRESH 12
51 
52 #define MIN_THRESHMULT 32
53 #define MAX_THRESHMULT 512
54 
55 #define GF_ZEROMV_ZBIN_BOOST 12
56 #define LF_ZEROMV_ZBIN_BOOST 6
57 #define MV_ZBIN_BOOST 4
58 #define ZBIN_OQ_MAX 192
59 
60 #define VP8_TEMPORAL_ALT_REF !CONFIG_REALTIME_ONLY
61 
62 /* vp8 uses 10,000,000 ticks/second as time stamp */
63 #define TICKS_PER_SEC 10000000
64 
65 typedef struct {
66   int kf_indicated;
67   unsigned int frames_since_key;
68   unsigned int frames_since_golden;
69   int filter_level;
70   int frames_till_gf_update_due;
71   int recent_ref_frame_usage[MAX_REF_FRAMES];
72 
73   MV_CONTEXT mvc[2];
74   int mvcosts[2][MVvals + 1];
75 
76 #ifdef MODE_STATS
77   int y_modes[5];
78   int uv_modes[4];
79   int b_modes[10];
80   int inter_y_modes[10];
81   int inter_uv_modes[4];
82   int inter_b_modes[10];
83 #endif
84 
85   vp8_prob ymode_prob[4], uv_mode_prob[3]; /* interframe intra mode probs */
86   vp8_prob kf_ymode_prob[4], kf_uv_mode_prob[3]; /* keyframe "" */
87 
88   int ymode_count[5], uv_mode_count[4]; /* intra MB type cts this frame */
89 
90   int count_mb_ref_frame_usage[MAX_REF_FRAMES];
91 
92   int this_frame_percent_intra;
93   int last_frame_percent_intra;
94 
95 } CODING_CONTEXT;
96 
97 typedef struct {
98   double frame;
99   double intra_error;
100   double coded_error;
101   double ssim_weighted_pred_err;
102   double pcnt_inter;
103   double pcnt_motion;
104   double pcnt_second_ref;
105   double pcnt_neutral;
106   double MVr;
107   double mvr_abs;
108   double MVc;
109   double mvc_abs;
110   double MVrv;
111   double MVcv;
112   double mv_in_out_count;
113   double new_mv_count;
114   double duration;
115   double count;
116 } FIRSTPASS_STATS;
117 
118 typedef struct {
119   int frames_so_far;
120   double frame_intra_error;
121   double frame_coded_error;
122   double frame_pcnt_inter;
123   double frame_pcnt_motion;
124   double frame_mvr;
125   double frame_mvr_abs;
126   double frame_mvc;
127   double frame_mvc_abs;
128 
129 } ONEPASS_FRAMESTATS;
130 
131 typedef enum {
132   THR_ZERO1 = 0,
133   THR_DC = 1,
134 
135   THR_NEAREST1 = 2,
136   THR_NEAR1 = 3,
137 
138   THR_ZERO2 = 4,
139   THR_NEAREST2 = 5,
140 
141   THR_ZERO3 = 6,
142   THR_NEAREST3 = 7,
143 
144   THR_NEAR2 = 8,
145   THR_NEAR3 = 9,
146 
147   THR_V_PRED = 10,
148   THR_H_PRED = 11,
149   THR_TM = 12,
150 
151   THR_NEW1 = 13,
152   THR_NEW2 = 14,
153   THR_NEW3 = 15,
154 
155   THR_SPLIT1 = 16,
156   THR_SPLIT2 = 17,
157   THR_SPLIT3 = 18,
158 
159   THR_B_PRED = 19
160 } THR_MODES;
161 
162 typedef enum { DIAMOND = 0, NSTEP = 1, HEX = 2 } SEARCH_METHODS;
163 
164 typedef struct {
165   int RD;
166   SEARCH_METHODS search_method;
167   int improved_quant;
168   int improved_dct;
169   int auto_filter;
170   int recode_loop;
171   int iterative_sub_pixel;
172   int half_pixel_search;
173   int quarter_pixel_search;
174   int thresh_mult[MAX_MODES];
175   int max_step_search_steps;
176   int first_step;
177   int optimize_coefficients;
178 
179   int use_fastquant_for_pick;
180   int no_skip_block4x4_search;
181   int improved_mv_pred;
182 
183 } SPEED_FEATURES;
184 
185 typedef struct {
186   MACROBLOCK mb;
187   int segment_counts[MAX_MB_SEGMENTS];
188   int totalrate;
189 } MB_ROW_COMP;
190 
191 typedef struct {
192   TOKENEXTRA *start;
193   TOKENEXTRA *stop;
194 } TOKENLIST;
195 
196 typedef struct {
197   int ithread;
198   void *ptr1;
199   void *ptr2;
200 } ENCODETHREAD_DATA;
201 typedef struct {
202   int ithread;
203   void *ptr1;
204 } LPFTHREAD_DATA;
205 
206 enum {
207   BLOCK_16X8,
208   BLOCK_8X16,
209   BLOCK_8X8,
210   BLOCK_4X4,
211   BLOCK_16X16,
212   BLOCK_MAX_SEGMENTS
213 };
214 
215 typedef struct {
216   /* Layer configuration */
217   double framerate;
218   int target_bandwidth;
219 
220   /* Layer specific coding parameters */
221   int64_t starting_buffer_level;
222   int64_t optimal_buffer_level;
223   int64_t maximum_buffer_size;
224   int64_t starting_buffer_level_in_ms;
225   int64_t optimal_buffer_level_in_ms;
226   int64_t maximum_buffer_size_in_ms;
227 
228   int avg_frame_size_for_layer;
229 
230   int64_t buffer_level;
231   int64_t bits_off_target;
232 
233   int64_t total_actual_bits;
234   int total_target_vs_actual;
235 
236   int worst_quality;
237   int active_worst_quality;
238   int best_quality;
239   int active_best_quality;
240 
241   int ni_av_qi;
242   int ni_tot_qi;
243   int ni_frames;
244   int avg_frame_qindex;
245 
246   double rate_correction_factor;
247   double key_frame_rate_correction_factor;
248   double gf_rate_correction_factor;
249 
250   int zbin_over_quant;
251 
252   int inter_frame_target;
253   int64_t total_byte_count;
254 
255   int filter_level;
256 
257   int frames_since_last_drop_overshoot;
258 
259   int force_maxqp;
260 
261   int last_frame_percent_intra;
262 
263   int count_mb_ref_frame_usage[MAX_REF_FRAMES];
264 
265   int last_q[2];
266 } LAYER_CONTEXT;
267 
268 typedef struct VP8_COMP {
269   DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]);
270   DECLARE_ALIGNED(16, short, Y1quant_shift[QINDEX_RANGE][16]);
271   DECLARE_ALIGNED(16, short, Y1zbin[QINDEX_RANGE][16]);
272   DECLARE_ALIGNED(16, short, Y1round[QINDEX_RANGE][16]);
273 
274   DECLARE_ALIGNED(16, short, Y2quant[QINDEX_RANGE][16]);
275   DECLARE_ALIGNED(16, short, Y2quant_shift[QINDEX_RANGE][16]);
276   DECLARE_ALIGNED(16, short, Y2zbin[QINDEX_RANGE][16]);
277   DECLARE_ALIGNED(16, short, Y2round[QINDEX_RANGE][16]);
278 
279   DECLARE_ALIGNED(16, short, UVquant[QINDEX_RANGE][16]);
280   DECLARE_ALIGNED(16, short, UVquant_shift[QINDEX_RANGE][16]);
281   DECLARE_ALIGNED(16, short, UVzbin[QINDEX_RANGE][16]);
282   DECLARE_ALIGNED(16, short, UVround[QINDEX_RANGE][16]);
283 
284   DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1[QINDEX_RANGE][16]);
285   DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2[QINDEX_RANGE][16]);
286   DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv[QINDEX_RANGE][16]);
287   DECLARE_ALIGNED(16, short, Y1quant_fast[QINDEX_RANGE][16]);
288   DECLARE_ALIGNED(16, short, Y2quant_fast[QINDEX_RANGE][16]);
289   DECLARE_ALIGNED(16, short, UVquant_fast[QINDEX_RANGE][16]);
290 
291   MACROBLOCK mb;
292   VP8_COMMON common;
293   vp8_writer bc[9]; /* one boolcoder for each partition */
294 
295   VP8_CONFIG oxcf;
296 
297   struct lookahead_ctx *lookahead;
298   struct lookahead_entry *source;
299   struct lookahead_entry *alt_ref_source;
300   struct lookahead_entry *last_source;
301 
302   YV12_BUFFER_CONFIG *Source;
303   YV12_BUFFER_CONFIG *un_scaled_source;
304   YV12_BUFFER_CONFIG scaled_source;
305   YV12_BUFFER_CONFIG *last_frame_unscaled_source;
306 
307   unsigned int frames_till_alt_ref_frame;
308   /* frame in src_buffers has been identified to be encoded as an alt ref */
309   int source_alt_ref_pending;
310   /* an alt ref frame has been encoded and is usable */
311   int source_alt_ref_active;
312   /* source of frame to encode is an exact copy of an alt ref frame */
313   int is_src_frame_alt_ref;
314 
315   /* golden frame same as last frame ( short circuit gold searches) */
316   int gold_is_last;
317   /* Alt reference frame same as last ( short circuit altref search) */
318   int alt_is_last;
319   /* don't do both alt and gold search ( just do gold). */
320   int gold_is_alt;
321 
322   YV12_BUFFER_CONFIG pick_lf_lvl_frame;
323 
324   TOKENEXTRA *tok;
325   unsigned int tok_count;
326 
327   unsigned int frames_since_key;
328   unsigned int key_frame_frequency;
329   unsigned int this_key_frame_forced;
330   unsigned int next_key_frame_forced;
331 
332   /* Ambient reconstruction err target for force key frames */
333   int ambient_err;
334 
335   unsigned int mode_check_freq[MAX_MODES];
336 
337   int rd_baseline_thresh[MAX_MODES];
338 
339   int RDMULT;
340   int RDDIV;
341 
342   CODING_CONTEXT coding_context;
343 
344   /* Rate targeting variables */
345   int64_t last_prediction_error;
346   int64_t last_intra_error;
347 
348   int this_frame_target;
349   int projected_frame_size;
350   int last_q[2]; /* Separate values for Intra/Inter */
351 
352   double rate_correction_factor;
353   double key_frame_rate_correction_factor;
354   double gf_rate_correction_factor;
355 
356   int frames_since_golden;
357   /* Count down till next GF */
358   int frames_till_gf_update_due;
359 
360   /* GF interval chosen when we coded the last GF */
361   int current_gf_interval;
362 
363   /* Total bits overspent becasue of GF boost (cumulative) */
364   int gf_overspend_bits;
365 
366   /* Used in the few frames following a GF to recover the extra bits
367    * spent in that GF
368    */
369   int non_gf_bitrate_adjustment;
370 
371   /* Extra bits spent on key frames that need to be recovered */
372   int kf_overspend_bits;
373 
374   /* Current number of bit s to try and recover on each inter frame. */
375   int kf_bitrate_adjustment;
376   int max_gf_interval;
377   int baseline_gf_interval;
378   int active_arnr_frames;
379 
380   int64_t key_frame_count;
381   int prior_key_frame_distance[KEY_FRAME_CONTEXT];
382   /* Current section per frame bandwidth target */
383   int per_frame_bandwidth;
384   /* Average frame size target for clip */
385   int av_per_frame_bandwidth;
386   /* Minimum allocation that should be used for any frame */
387   int min_frame_bandwidth;
388   int inter_frame_target;
389   double output_framerate;
390   int64_t last_time_stamp_seen;
391   int64_t last_end_time_stamp_seen;
392   int64_t first_time_stamp_ever;
393 
394   int ni_av_qi;
395   int ni_tot_qi;
396   int ni_frames;
397   int avg_frame_qindex;
398 
399   int64_t total_byte_count;
400 
401   int buffered_mode;
402 
403   double framerate;
404   double ref_framerate;
405   int64_t buffer_level;
406   int64_t bits_off_target;
407 
408   int rolling_target_bits;
409   int rolling_actual_bits;
410 
411   int long_rolling_target_bits;
412   int long_rolling_actual_bits;
413 
414   int64_t total_actual_bits;
415   int total_target_vs_actual; /* debug stats */
416 
417   int worst_quality;
418   int active_worst_quality;
419   int best_quality;
420   int active_best_quality;
421 
422   int cq_target_quality;
423 
424   int drop_frames_allowed; /* Are we permitted to drop frames? */
425   int drop_frame;          /* Drop this frame? */
426 #if defined(DROP_UNCODED_FRAMES)
427   int drop_frame_count;
428 #endif
429 
430   vp8_prob frame_coef_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
431                            [ENTROPY_NODES];
432   char update_probs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES];
433 
434   unsigned int frame_branch_ct[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
435                               [ENTROPY_NODES][2];
436 
437   int gfu_boost;
438   int kf_boost;
439   int last_boost;
440 
441   int target_bandwidth;
442   struct vpx_codec_pkt_list *output_pkt_list;
443 
444 #if 0
445     /* Experimental code for lagged and one pass */
446     ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS];
447     int one_pass_frame_index;
448 #endif
449 
450   int decimation_factor;
451   int decimation_count;
452 
453   /* for real time encoding */
454   int avg_encode_time;    /* microsecond */
455   int avg_pick_mode_time; /* microsecond */
456   int Speed;
457   int compressor_speed;
458 
459   int auto_gold;
460   int auto_adjust_gold_quantizer;
461   int auto_worst_q;
462   int cpu_used;
463   int pass;
464 
465   int prob_intra_coded;
466   int prob_last_coded;
467   int prob_gf_coded;
468   int prob_skip_false;
469   int last_skip_false_probs[3];
470   int last_skip_probs_q[3];
471   int recent_ref_frame_usage[MAX_REF_FRAMES];
472 
473   int this_frame_percent_intra;
474   int last_frame_percent_intra;
475 
476   int ref_frame_flags;
477 
478   SPEED_FEATURES sf;
479 
480   /* Count ZEROMV on all reference frames. */
481   int zeromv_count;
482   int lf_zeromv_pct;
483 
484   unsigned char *skin_map;
485 
486   unsigned char *segmentation_map;
487   signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];
488   unsigned int segment_encode_breakout[MAX_MB_SEGMENTS];
489 
490   unsigned char *active_map;
491   unsigned int active_map_enabled;
492 
493   /* Video conferencing cyclic refresh mode flags. This is a mode
494    * designed to clean up the background over time in live encoding
495    * scenarious. It uses segmentation.
496    */
497   int cyclic_refresh_mode_enabled;
498   int cyclic_refresh_mode_max_mbs_perframe;
499   int cyclic_refresh_mode_index;
500   int cyclic_refresh_q;
501   signed char *cyclic_refresh_map;
502   // Count on how many (consecutive) times a macroblock uses ZER0MV_LAST.
503   unsigned char *consec_zero_last;
504   // Counter that is reset when a block is checked for a mode-bias against
505   // ZEROMV_LASTREF.
506   unsigned char *consec_zero_last_mvbias;
507 
508   // Frame counter for the temporal pattern. Counter is rest when the temporal
509   // layers are changed dynamically (run-time change).
510   unsigned int temporal_pattern_counter;
511   // Temporal layer id.
512   int temporal_layer_id;
513 
514   // Measure of average squared difference between source and denoised signal.
515   int mse_source_denoised;
516 
517   int force_maxqp;
518   int frames_since_last_drop_overshoot;
519   int last_pred_err_mb;
520 
521   // GF update for 1 pass cbr.
522   int gf_update_onepass_cbr;
523   int gf_interval_onepass_cbr;
524   int gf_noboost_onepass_cbr;
525 
526 #if CONFIG_MULTITHREAD
527   /* multithread data */
528   vpx_atomic_int *mt_current_mb_col;
529   int mt_sync_range;
530   vpx_atomic_int b_multi_threaded;
531   int encoding_thread_count;
532   int b_lpf_running;
533 
534   pthread_t *h_encoding_thread;
535   pthread_t h_filter_thread;
536 
537   MB_ROW_COMP *mb_row_ei;
538   ENCODETHREAD_DATA *en_thread_data;
539   LPFTHREAD_DATA lpf_thread_data;
540 
541   /* events */
542   sem_t *h_event_start_encoding;
543   sem_t *h_event_end_encoding;
544   sem_t h_event_start_lpf;
545   sem_t h_event_end_lpf;
546 #endif
547 
548   TOKENLIST *tplist;
549   unsigned int partition_sz[MAX_PARTITIONS];
550   unsigned char *partition_d[MAX_PARTITIONS];
551   unsigned char *partition_d_end[MAX_PARTITIONS];
552 
553   fractional_mv_step_fp *find_fractional_mv_step;
554   vp8_refining_search_fn_t refining_search_sad;
555   vp8_diamond_search_fn_t diamond_search_sad;
556   vp8_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SEGMENTS];
557   uint64_t time_receive_data;
558   uint64_t time_compress_data;
559   uint64_t time_pick_lpf;
560   uint64_t time_encode_mb_row;
561 
562   int base_skip_false_prob[128];
563 
564   FRAME_CONTEXT lfc_n; /* last frame entropy */
565   FRAME_CONTEXT lfc_a; /* last alt ref entropy */
566   FRAME_CONTEXT lfc_g; /* last gold ref entropy */
567 
568   struct twopass_rc {
569     unsigned int section_intra_rating;
570     double section_max_qfactor;
571     unsigned int next_iiratio;
572     unsigned int this_iiratio;
573     FIRSTPASS_STATS total_stats;
574     FIRSTPASS_STATS this_frame_stats;
575     FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start;
576     FIRSTPASS_STATS total_left_stats;
577     int first_pass_done;
578     int64_t bits_left;
579     int64_t clip_bits_total;
580     double avg_iiratio;
581     double modified_error_total;
582     double modified_error_used;
583     double modified_error_left;
584     double kf_intra_err_min;
585     double gf_intra_err_min;
586     int frames_to_key;
587     int maxq_max_limit;
588     int maxq_min_limit;
589     int gf_decay_rate;
590     int static_scene_max_gf_interval;
591     int kf_bits;
592     /* Remaining error from uncoded frames in a gf group. */
593     int gf_group_error_left;
594     /* Projected total bits available for a key frame group of frames */
595     int64_t kf_group_bits;
596     /* Error score of frames still to be coded in kf group */
597     int64_t kf_group_error_left;
598     /* Projected Bits available for a group including 1 GF or ARF */
599     int64_t gf_group_bits;
600     /* Bits for the golden frame or ARF */
601     int gf_bits;
602     int alt_extra_bits;
603     double est_max_qcorrection_factor;
604   } twopass;
605 
606 #if VP8_TEMPORAL_ALT_REF
607   YV12_BUFFER_CONFIG alt_ref_buffer;
608   YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS];
609   int fixed_divide[512];
610 #endif
611 
612 #if CONFIG_INTERNAL_STATS
613   int count;
614   double total_y;
615   double total_u;
616   double total_v;
617   double total;
618   double total_sq_error;
619   double totalp_y;
620   double totalp_u;
621   double totalp_v;
622   double totalp;
623   double total_sq_error2;
624   int bytes;
625   double summed_quality;
626   double summed_weights;
627   unsigned int tot_recode_hits;
628 
629   int b_calculate_ssimg;
630 #endif
631   int b_calculate_psnr;
632 
633   /* Per MB activity measurement */
634   unsigned int activity_avg;
635   unsigned int *mb_activity_map;
636 
637   /* Record of which MBs still refer to last golden frame either
638    * directly or through 0,0
639    */
640   unsigned char *gf_active_flags;
641   int gf_active_count;
642 
643   int output_partition;
644 
645   /* Store last frame's MV info for next frame MV prediction */
646   int_mv *lfmv;
647   int *lf_ref_frame_sign_bias;
648   int *lf_ref_frame;
649 
650   /* force next frame to intra when kf_auto says so */
651   int force_next_frame_intra;
652 
653   int droppable;
654 
655   int initial_width;
656   int initial_height;
657 
658 #if CONFIG_TEMPORAL_DENOISING
659   VP8_DENOISER denoiser;
660 #endif
661 
662   /* Coding layer state variables */
663   unsigned int current_layer;
664   LAYER_CONTEXT layer_context[VPX_TS_MAX_LAYERS];
665 
666   int64_t frames_in_layer[VPX_TS_MAX_LAYERS];
667   int64_t bytes_in_layer[VPX_TS_MAX_LAYERS];
668   double sum_psnr[VPX_TS_MAX_LAYERS];
669   double sum_psnr_p[VPX_TS_MAX_LAYERS];
670   double total_error2[VPX_TS_MAX_LAYERS];
671   double total_error2_p[VPX_TS_MAX_LAYERS];
672   double sum_ssim[VPX_TS_MAX_LAYERS];
673   double sum_weights[VPX_TS_MAX_LAYERS];
674 
675   double total_ssimg_y_in_layer[VPX_TS_MAX_LAYERS];
676   double total_ssimg_u_in_layer[VPX_TS_MAX_LAYERS];
677   double total_ssimg_v_in_layer[VPX_TS_MAX_LAYERS];
678   double total_ssimg_all_in_layer[VPX_TS_MAX_LAYERS];
679 
680 #if CONFIG_MULTI_RES_ENCODING
681   /* Number of MBs per row at lower-resolution level */
682   int mr_low_res_mb_cols;
683   /* Indicate if lower-res mv info is available */
684   unsigned char mr_low_res_mv_avail;
685 #endif
686   /* The frame number of each reference frames */
687   unsigned int current_ref_frames[MAX_REF_FRAMES];
688   // Closest reference frame to current frame.
689   MV_REFERENCE_FRAME closest_reference_frame;
690 
691   struct rd_costs_struct {
692     int mvcosts[2][MVvals + 1];
693     int mvsadcosts[2][MVfpvals + 1];
694     int mbmode_cost[2][MB_MODE_COUNT];
695     int intra_uv_mode_cost[2][MB_MODE_COUNT];
696     int bmode_costs[10][10][10];
697     int inter_bmode_costs[B_MODE_COUNT];
698     int token_costs[BLOCK_TYPES][COEF_BANDS][PREV_COEF_CONTEXTS]
699                    [MAX_ENTROPY_TOKENS];
700   } rd_costs;
701 
702   // Use the static threshold from ROI settings.
703   int use_roi_static_threshold;
704 
705   int ext_refresh_frame_flags_pending;
706 
707   // Always update correction factor used for rate control after each frame for
708   // realtime encoding.
709   int rt_always_update_correction_factor;
710 } VP8_COMP;
711 
712 void vp8_initialize_enc(void);
713 
714 void vp8_alloc_compressor_data(VP8_COMP *cpi);
715 int vp8_reverse_trans(int x);
716 void vp8_reset_temporal_layer_change(VP8_COMP *cpi, VP8_CONFIG *oxcf,
717                                      const int prev_num_layers);
718 void vp8_init_temporal_layer_context(VP8_COMP *cpi, VP8_CONFIG *oxcf,
719                                      const int layer,
720                                      double prev_layer_framerate);
721 void vp8_update_layer_contexts(VP8_COMP *cpi);
722 void vp8_save_layer_context(VP8_COMP *cpi);
723 void vp8_restore_layer_context(VP8_COMP *cpi, const int layer);
724 void vp8_new_framerate(VP8_COMP *cpi, double framerate);
725 void vp8_loopfilter_frame(VP8_COMP *cpi, VP8_COMMON *cm);
726 
727 void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest,
728                         unsigned char *dest_end, size_t *size);
729 
730 void vp8_tokenize_mb(VP8_COMP *, MACROBLOCK *, TOKENEXTRA **);
731 
732 void vp8_set_speed_features(VP8_COMP *cpi);
733 
734 #if CONFIG_DEBUG
735 #define CHECK_MEM_ERROR(lval, expr)                                         \
736   do {                                                                      \
737     assert(cpi->common.error.setjmp);                                       \
738     (lval) = (expr);                                                        \
739     if (!(lval))                                                            \
740       vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,           \
741                          "Failed to allocate " #lval " at %s:%d", __FILE__, \
742                          __LINE__);                                         \
743   } while (0)
744 #else
745 #define CHECK_MEM_ERROR(lval, expr)                               \
746   do {                                                            \
747     assert(cpi->common.error.setjmp);                             \
748     (lval) = (expr);                                              \
749     if (!(lval))                                                  \
750       vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR, \
751                          "Failed to allocate " #lval);            \
752   } while (0)
753 #endif
754 #ifdef __cplusplus
755 }  // extern "C"
756 #endif
757 
758 #endif  // VPX_VP8_ENCODER_ONYX_INT_H_
759