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