Merge "Reduce mem copies in encoder loopfilter level picking"
[profile/ivi/libvpx.git] / vp8 / encoder / onyx_int.h
index ee519fa..68ec3ab 100644 (file)
 #define VP8_TEMPORAL_ALT_REF 1
 #endif
 
+#define MAX_PERIODICITY 16
+
+#define MAX(x,y) (((x)>(y))?(x):(y))
+#define MIN(x,y) (((x)<(y))?(x):(y))
+
 typedef struct
 {
     int kf_indicated;
@@ -131,32 +136,32 @@ typedef struct
 
 typedef enum
 {
-    THR_ZEROMV         = 0,
+    THR_ZERO         = 0,
     THR_DC             = 1,
 
-    THR_NEARESTMV      = 2,
-    THR_NEARMV         = 3,
+    THR_NEAREST      = 2,
+    THR_NEAR         = 3,
 
-    THR_ZEROG          = 4,
-    THR_NEARESTG       = 5,
+    THR_ZERO2          = 4,
+    THR_NEAREST2       = 5,
 
-    THR_ZEROA          = 6,
-    THR_NEARESTA       = 7,
+    THR_ZERO3          = 6,
+    THR_NEAREST3       = 7,
 
-    THR_NEARG          = 8,
-    THR_NEARA          = 9,
+    THR_NEAR2          = 8,
+    THR_NEAR3          = 9,
 
     THR_V_PRED         = 10,
     THR_H_PRED         = 11,
     THR_TM             = 12,
 
-    THR_NEWMV          = 13,
-    THR_NEWG           = 14,
-    THR_NEWA           = 15,
+    THR_NEW          = 13,
+    THR_NEW2           = 14,
+    THR_NEW3           = 15,
 
-    THR_SPLITMV        = 16,
-    THR_SPLITG         = 17,
-    THR_SPLITA         = 18,
+    THR_SPLIT        = 16,
+    THR_SPLIT2         = 17,
+    THR_SPLIT3         = 18,
 
     THR_B_PRED         = 19,
 }
@@ -238,6 +243,52 @@ enum
     BLOCK_MAX_SEGMENTS
 };
 
+typedef struct
+{
+    // Layer configuration
+    double frame_rate;
+    int target_bandwidth;
+
+    // Layer specific coding parameters
+    int starting_buffer_level;
+    int optimal_buffer_level;
+    int maximum_buffer_size;
+
+    int avg_frame_size_for_layer;
+
+    int buffer_level;
+    int bits_off_target;
+
+    long long total_actual_bits;
+    int total_target_vs_actual;
+
+    int worst_quality;
+    int active_worst_quality;
+    int best_quality;
+    int active_best_quality;
+
+    int ni_av_qi;
+    int ni_tot_qi;
+    int ni_frames;
+    int avg_frame_qindex;
+
+    double rate_correction_factor;
+    double key_frame_rate_correction_factor;
+    double gf_rate_correction_factor;
+
+    int zbin_over_quant;
+
+    int inter_frame_target;
+    INT64 total_byte_count;
+
+    int filter_level;
+
+    int last_frame_percent_intra;
+
+    int count_mb_ref_frame_usage[MAX_REF_FRAMES];
+
+} LAYER_CONTEXT;
+
 typedef struct VP8_COMP
 {
 
@@ -266,8 +317,7 @@ typedef struct VP8_COMP
 
     MACROBLOCK mb;
     VP8_COMMON common;
-    vp8_writer bc, bc2;
-    // bool_writer *bc2;
+    vp8_writer bc[9]; // one boolcoder for each partition
 
     VP8_CONFIG oxcf;
 
@@ -289,7 +339,7 @@ typedef struct VP8_COMP
     int gold_is_alt;  // don't do both alt and gold search ( just do gold).
 
     //int refresh_alt_ref_frame;
-    YV12_BUFFER_CONFIG last_frame_uf;
+    YV12_BUFFER_CONFIG pick_lf_lvl_frame;
 
     TOKENEXTRA *tok;
     unsigned int tok_count;
@@ -363,12 +413,15 @@ typedef struct VP8_COMP
     int zbin_over_quant;
     int zbin_mode_boost;
     int zbin_mode_boost_enabled;
+    int last_zbin_over_quant;
+    int last_zbin_mode_boost;
 
     int64_t total_byte_count;
 
     int buffered_mode;
 
-    int buffer_level;
+    double frame_rate;
+    int64_t buffer_level;
     int bits_off_target;
 
     int rolling_target_bits;
@@ -610,13 +663,37 @@ typedef struct VP8_COMP
     int force_next_frame_intra; /* force next frame to intra when kf_auto says so */
 
     int droppable;
+
+    // Coding layer state variables
+    unsigned int current_layer;
+    LAYER_CONTEXT layer_context[MAX_LAYERS];
+
+    long long frames_in_layer[MAX_LAYERS];
+    long long bytes_in_layer[MAX_LAYERS];
+    double sum_psnr[MAX_LAYERS];
+    double sum_psnr_p[MAX_LAYERS];
+    double total_error2[MAX_LAYERS];
+    double total_error2_p[MAX_LAYERS];
+    double sum_ssim[MAX_LAYERS];
+    double sum_weights[MAX_LAYERS];
+
+    double total_ssimg_y_in_layer[MAX_LAYERS];
+    double total_ssimg_u_in_layer[MAX_LAYERS];
+    double total_ssimg_v_in_layer[MAX_LAYERS];
+    double total_ssimg_all_in_layer[MAX_LAYERS];
+
+#if CONFIG_MULTI_RES_ENCODING
+    /* Number of MBs per row at lower-resolution level */
+    int    mr_low_res_mb_cols;
+#endif
+
 } VP8_COMP;
 
 void control_data_rate(VP8_COMP *cpi);
 
 void vp8_encode_frame(VP8_COMP *cpi);
 
-void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size);
+void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned char *dest_end, unsigned long *size);
 
 void vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x);