John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 1 | /* |
John Koleszar | c2140b8 | 2010-09-09 08:16:39 -0400 | [diff] [blame] | 2 | * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 3 | * |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 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 |
John Koleszar | 94c52e4 | 2010-06-18 12:39:21 -0400 | [diff] [blame] | 7 | * in the file PATENTS. All contributing project authors may |
John Koleszar | 09202d8 | 2010-06-04 16:19:40 -0400 | [diff] [blame] | 8 | * be found in the AUTHORS file in the root of the source tree. |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | |
| 12 | #ifndef __INC_VP8_INT_H |
| 13 | #define __INC_VP8_INT_H |
| 14 | |
| 15 | #include <stdio.h> |
| 16 | #include "vpx_ports/config.h" |
| 17 | #include "onyx.h" |
| 18 | #include "treewriter.h" |
| 19 | #include "tokenize.h" |
| 20 | #include "onyxc_int.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 21 | #include "variance.h" |
| 22 | #include "dct.h" |
| 23 | #include "encodemb.h" |
| 24 | #include "quantize.h" |
| 25 | #include "entropy.h" |
| 26 | #include "threading.h" |
| 27 | #include "vpx_ports/mem.h" |
John Koleszar | b749234 | 2010-05-24 11:39:59 -0400 | [diff] [blame] | 28 | #include "vpx/internal/vpx_codec_internal.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 29 | #include "mcomp.h" |
Johann | 092b5be | 2010-11-29 14:21:11 -0500 | [diff] [blame] | 30 | #include "temporal_filter.h" |
Yunqing Wang | cac5440 | 2011-01-26 12:03:13 -0500 | [diff] [blame] | 31 | #include "findnearmv.h" |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 32 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 33 | //#define SPEEDSTATS 1 |
| 34 | #define MIN_GF_INTERVAL 4 |
| 35 | #define DEFAULT_GF_INTERVAL 7 |
| 36 | |
| 37 | #define KEY_FRAME_CONTEXT 5 |
| 38 | |
| 39 | #define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY? 1 : 25) |
| 40 | |
| 41 | #define AF_THRESH 25 |
| 42 | #define AF_THRESH2 100 |
| 43 | #define ARF_DECAY_THRESH 12 |
| 44 | #define MAX_MODES 20 |
| 45 | |
| 46 | #define MIN_THRESHMULT 32 |
| 47 | #define MAX_THRESHMULT 512 |
| 48 | |
| 49 | #define GF_ZEROMV_ZBIN_BOOST 24 |
Paul Wilkins | 6adbe09 | 2010-11-08 15:28:54 +0000 | [diff] [blame] | 50 | #define LF_ZEROMV_ZBIN_BOOST 12 |
| 51 | #define MV_ZBIN_BOOST 4 |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 52 | #define ZBIN_OQ_MAX 192 |
| 53 | |
| 54 | #define VP8_TEMPORAL_ALT_REF 1 |
| 55 | |
| 56 | typedef struct |
| 57 | { |
| 58 | int kf_indicated; |
| 59 | unsigned int frames_since_key; |
| 60 | unsigned int frames_since_golden; |
| 61 | int filter_level; |
| 62 | int frames_till_gf_update_due; |
| 63 | int recent_ref_frame_usage[MAX_REF_FRAMES]; |
| 64 | |
| 65 | MV_CONTEXT mvc[2]; |
| 66 | int mvcosts[2][MVvals+1]; |
| 67 | |
| 68 | #ifdef MODE_STATS |
| 69 | // Stats |
| 70 | int y_modes[5]; |
| 71 | int uv_modes[4]; |
| 72 | int b_modes[10]; |
| 73 | int inter_y_modes[10]; |
| 74 | int inter_uv_modes[4]; |
| 75 | int inter_b_modes[10]; |
| 76 | #endif |
| 77 | |
| 78 | vp8_prob ymode_prob[4], uv_mode_prob[3]; /* interframe intra mode probs */ |
| 79 | vp8_prob kf_ymode_prob[4], kf_uv_mode_prob[3]; /* keyframe "" */ |
| 80 | |
| 81 | int ymode_count[5], uv_mode_count[4]; /* intra MB type cts this frame */ |
| 82 | |
| 83 | int count_mb_ref_frame_usage[MAX_REF_FRAMES]; |
| 84 | |
| 85 | int this_frame_percent_intra; |
| 86 | int last_frame_percent_intra; |
| 87 | |
| 88 | |
| 89 | } CODING_CONTEXT; |
| 90 | |
| 91 | typedef struct |
| 92 | { |
| 93 | double frame; |
| 94 | double intra_error; |
| 95 | double coded_error; |
| 96 | double ssim_weighted_pred_err; |
| 97 | double pcnt_inter; |
| 98 | double pcnt_motion; |
| 99 | double pcnt_second_ref; |
| 100 | double MVr; |
| 101 | double mvr_abs; |
| 102 | double MVc; |
| 103 | double mvc_abs; |
| 104 | double MVrv; |
| 105 | double MVcv; |
| 106 | double mv_in_out_count; |
| 107 | double duration; |
| 108 | double count; |
| 109 | } |
| 110 | FIRSTPASS_STATS; |
| 111 | |
| 112 | typedef struct |
| 113 | { |
| 114 | int frames_so_far; |
| 115 | double frame_intra_error; |
| 116 | double frame_coded_error; |
| 117 | double frame_pcnt_inter; |
| 118 | double frame_pcnt_motion; |
| 119 | double frame_mvr; |
| 120 | double frame_mvr_abs; |
| 121 | double frame_mvc; |
| 122 | double frame_mvc_abs; |
| 123 | |
| 124 | } ONEPASS_FRAMESTATS; |
| 125 | |
| 126 | |
| 127 | typedef enum |
| 128 | { |
| 129 | THR_ZEROMV = 0, |
| 130 | THR_DC = 1, |
| 131 | |
| 132 | THR_NEARESTMV = 2, |
| 133 | THR_NEARMV = 3, |
| 134 | |
| 135 | THR_ZEROG = 4, |
| 136 | THR_NEARESTG = 5, |
| 137 | |
| 138 | THR_ZEROA = 6, |
| 139 | THR_NEARESTA = 7, |
| 140 | |
| 141 | THR_NEARG = 8, |
| 142 | THR_NEARA = 9, |
| 143 | |
| 144 | THR_V_PRED = 10, |
| 145 | THR_H_PRED = 11, |
| 146 | THR_TM = 12, |
| 147 | |
| 148 | THR_NEWMV = 13, |
| 149 | THR_NEWG = 14, |
| 150 | THR_NEWA = 15, |
| 151 | |
| 152 | THR_SPLITMV = 16, |
| 153 | THR_SPLITG = 17, |
| 154 | THR_SPLITA = 18, |
| 155 | |
| 156 | THR_B_PRED = 19, |
| 157 | } |
| 158 | THR_MODES; |
| 159 | |
| 160 | typedef enum |
| 161 | { |
| 162 | DIAMOND = 0, |
| 163 | NSTEP = 1, |
| 164 | HEX = 2 |
| 165 | } SEARCH_METHODS; |
| 166 | |
| 167 | typedef struct |
| 168 | { |
| 169 | int RD; |
| 170 | SEARCH_METHODS search_method; |
| 171 | int improved_quant; |
| 172 | int improved_dct; |
| 173 | int auto_filter; |
| 174 | int recode_loop; |
| 175 | int iterative_sub_pixel; |
| 176 | int half_pixel_search; |
| 177 | int quarter_pixel_search; |
| 178 | int thresh_mult[MAX_MODES]; |
| 179 | int full_freq[2]; |
| 180 | int min_fs_radius; |
| 181 | int max_fs_radius; |
| 182 | int max_step_search_steps; |
| 183 | int first_step; |
| 184 | int optimize_coefficients; |
| 185 | |
Scott LaVarnway | 516ea84 | 2010-12-28 14:51:46 -0500 | [diff] [blame] | 186 | int use_fastquant_for_pick; |
Yunqing Wang | 1546e6a | 2011-01-10 17:21:55 -0500 | [diff] [blame] | 187 | int no_skip_block4x4_search; |
Yunqing Wang | 9d0b2cb | 2011-02-11 09:43:37 -0500 | [diff] [blame^] | 188 | int improved_mv_pred; |
Scott LaVarnway | 516ea84 | 2010-12-28 14:51:46 -0500 | [diff] [blame] | 189 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 190 | } SPEED_FEATURES; |
| 191 | |
| 192 | typedef struct |
| 193 | { |
| 194 | MACROBLOCK mb; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 195 | int segment_counts[MAX_MB_SEGMENTS]; |
| 196 | int totalrate; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 197 | } MB_ROW_COMP; |
| 198 | |
| 199 | typedef struct |
| 200 | { |
| 201 | TOKENEXTRA *start; |
| 202 | TOKENEXTRA *stop; |
| 203 | } TOKENLIST; |
| 204 | |
| 205 | typedef struct |
| 206 | { |
| 207 | int ithread; |
| 208 | void *ptr1; |
| 209 | void *ptr2; |
| 210 | } ENCODETHREAD_DATA; |
| 211 | typedef struct |
| 212 | { |
| 213 | int ithread; |
| 214 | void *ptr1; |
| 215 | } LPFTHREAD_DATA; |
| 216 | |
| 217 | typedef struct |
| 218 | { |
| 219 | INT64 source_time_stamp; |
| 220 | INT64 source_end_time_stamp; |
| 221 | |
| 222 | DECLARE_ALIGNED(16, YV12_BUFFER_CONFIG, source_buffer); |
| 223 | unsigned int source_frame_flags; |
| 224 | } SOURCE_SAMPLE; |
| 225 | |
| 226 | typedef struct VP8_ENCODER_RTCD |
| 227 | { |
| 228 | VP8_COMMON_RTCD *common; |
| 229 | vp8_variance_rtcd_vtable_t variance; |
| 230 | vp8_fdct_rtcd_vtable_t fdct; |
| 231 | vp8_encodemb_rtcd_vtable_t encodemb; |
| 232 | vp8_quantize_rtcd_vtable_t quantize; |
| 233 | vp8_search_rtcd_vtable_t search; |
Johann | 092b5be | 2010-11-29 14:21:11 -0500 | [diff] [blame] | 234 | vp8_temporal_rtcd_vtable_t temporal; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 235 | } VP8_ENCODER_RTCD; |
| 236 | |
John Koleszar | 209d82a | 2010-10-26 15:34:16 -0400 | [diff] [blame] | 237 | enum |
| 238 | { |
| 239 | BLOCK_16X8, |
| 240 | BLOCK_8X16, |
| 241 | BLOCK_8X8, |
| 242 | BLOCK_4X4, |
| 243 | BLOCK_16X16, |
| 244 | BLOCK_MAX_SEGMENTS |
| 245 | }; |
| 246 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 247 | typedef struct |
| 248 | { |
| 249 | |
Timothy B. Terriberry | 8f75ea6 | 2010-10-21 17:04:30 -0700 | [diff] [blame] | 250 | DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]); |
| 251 | DECLARE_ALIGNED(16, short, Y1quant_shift[QINDEX_RANGE][16]); |
| 252 | DECLARE_ALIGNED(16, short, Y1zbin[QINDEX_RANGE][16]); |
| 253 | DECLARE_ALIGNED(16, short, Y1round[QINDEX_RANGE][16]); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 254 | |
Timothy B. Terriberry | 8f75ea6 | 2010-10-21 17:04:30 -0700 | [diff] [blame] | 255 | DECLARE_ALIGNED(16, short, Y2quant[QINDEX_RANGE][16]); |
| 256 | DECLARE_ALIGNED(16, short, Y2quant_shift[QINDEX_RANGE][16]); |
| 257 | DECLARE_ALIGNED(16, short, Y2zbin[QINDEX_RANGE][16]); |
| 258 | DECLARE_ALIGNED(16, short, Y2round[QINDEX_RANGE][16]); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 259 | |
Timothy B. Terriberry | 8f75ea6 | 2010-10-21 17:04:30 -0700 | [diff] [blame] | 260 | DECLARE_ALIGNED(16, short, UVquant[QINDEX_RANGE][16]); |
| 261 | DECLARE_ALIGNED(16, short, UVquant_shift[QINDEX_RANGE][16]); |
| 262 | DECLARE_ALIGNED(16, short, UVzbin[QINDEX_RANGE][16]); |
| 263 | DECLARE_ALIGNED(16, short, UVround[QINDEX_RANGE][16]); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 264 | |
| 265 | DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1[QINDEX_RANGE][16]); |
| 266 | DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2[QINDEX_RANGE][16]); |
| 267 | DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv[QINDEX_RANGE][16]); |
Scott LaVarnway | 516ea84 | 2010-12-28 14:51:46 -0500 | [diff] [blame] | 268 | DECLARE_ALIGNED(16, short, Y1quant_fast[QINDEX_RANGE][16]); |
| 269 | DECLARE_ALIGNED(16, short, Y2quant_fast[QINDEX_RANGE][16]); |
| 270 | DECLARE_ALIGNED(16, short, UVquant_fast[QINDEX_RANGE][16]); |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 271 | |
| 272 | |
| 273 | MACROBLOCK mb; |
| 274 | VP8_COMMON common; |
| 275 | vp8_writer bc, bc2; |
| 276 | // bool_writer *bc2; |
| 277 | |
| 278 | VP8_CONFIG oxcf; |
| 279 | |
| 280 | YV12_BUFFER_CONFIG *Source; |
| 281 | YV12_BUFFER_CONFIG *un_scaled_source; |
| 282 | INT64 source_time_stamp; |
| 283 | INT64 source_end_time_stamp; |
| 284 | unsigned int source_frame_flags; |
| 285 | YV12_BUFFER_CONFIG scaled_source; |
| 286 | |
Fritz Koenig | 69ee697 | 2010-11-16 15:16:24 -0800 | [diff] [blame] | 287 | int source_buffer_count; // number of src_buffers in use for lagged encoding |
| 288 | int source_encode_index; // index of buffer in src_buffer to encode |
| 289 | int source_alt_ref_pending; // frame in src_buffers has been identified to be encoded as an alt ref |
| 290 | int source_alt_ref_active; // an alt ref frame has been encoded and is usable |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 291 | |
Fritz Koenig | 69ee697 | 2010-11-16 15:16:24 -0800 | [diff] [blame] | 292 | int last_alt_ref_sei; // index into src_buffers of frame used as alt reference |
| 293 | int is_src_frame_alt_ref; // source of frame to encode is an exact copy of an alt ref frame |
| 294 | int is_next_src_alt_ref; // source of next frame to encode is an exact copy of an alt ref frame |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 295 | |
| 296 | int gold_is_last; // golden frame same as last frame ( short circuit gold searches) |
| 297 | int alt_is_last; // Alt reference frame same as last ( short circuit altref search) |
| 298 | int gold_is_alt; // don't do both alt and gold search ( just do gold). |
| 299 | |
| 300 | //int refresh_alt_ref_frame; |
| 301 | SOURCE_SAMPLE src_buffer[MAX_LAG_BUFFERS]; |
| 302 | |
| 303 | YV12_BUFFER_CONFIG last_frame_uf; |
| 304 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 305 | TOKENEXTRA *tok; |
| 306 | unsigned int tok_count; |
| 307 | |
| 308 | |
| 309 | unsigned int frames_since_key; |
| 310 | unsigned int key_frame_frequency; |
Paul Wilkins | 55acda9 | 2011-01-12 17:08:42 +0000 | [diff] [blame] | 311 | unsigned int this_key_frame_forced; |
| 312 | unsigned int next_key_frame_forced; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 313 | |
Paul Wilkins | 339c512 | 2011-01-17 17:23:11 +0000 | [diff] [blame] | 314 | // Ambient reconstruction err target for force key frames |
| 315 | int ambient_err; |
| 316 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 317 | unsigned int mode_check_freq[MAX_MODES]; |
| 318 | unsigned int mode_test_hit_counts[MAX_MODES]; |
| 319 | unsigned int mode_chosen_counts[MAX_MODES]; |
| 320 | unsigned int mbs_tested_so_far; |
| 321 | |
| 322 | unsigned int check_freq[2]; |
| 323 | unsigned int do_full[2]; |
| 324 | |
| 325 | int rd_thresh_mult[MAX_MODES]; |
| 326 | int rd_baseline_thresh[MAX_MODES]; |
| 327 | int rd_threshes[MAX_MODES]; |
| 328 | int mvcostbase; |
| 329 | int mvcostmultiplier; |
| 330 | int subseqblockweight; |
| 331 | int errthresh; |
Timothy B. Terriberry | 8d0f7a0 | 2010-10-11 14:37:27 -0700 | [diff] [blame] | 332 | unsigned int activity_avg; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 333 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 334 | int RDMULT; |
| 335 | int RDDIV ; |
| 336 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 337 | CODING_CONTEXT coding_context; |
| 338 | |
| 339 | // Rate targetting variables |
| 340 | long long prediction_error; |
| 341 | long long last_prediction_error; |
| 342 | long long intra_error; |
| 343 | long long last_intra_error; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 344 | |
| 345 | #if 0 |
| 346 | // Experimental RD code |
| 347 | long long frame_distortion; |
| 348 | long long last_frame_distortion; |
| 349 | #endif |
| 350 | |
| 351 | int last_mb_distortion; |
| 352 | |
| 353 | int frames_since_auto_filter; |
| 354 | |
| 355 | int this_frame_target; |
| 356 | int projected_frame_size; |
| 357 | int last_q[2]; // Separate values for Intra/Inter |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 358 | |
| 359 | double rate_correction_factor; |
| 360 | double key_frame_rate_correction_factor; |
| 361 | double gf_rate_correction_factor; |
| 362 | double est_max_qcorrection_factor; |
| 363 | |
| 364 | int frames_till_gf_update_due; // Count down till next GF |
| 365 | int current_gf_interval; // GF interval chosen when we coded the last GF |
| 366 | |
| 367 | int gf_overspend_bits; // Total bits overspent becasue of GF boost (cumulative) |
| 368 | |
| 369 | int gf_group_bits; // Projected Bits available for a group of frames including 1 GF or ARF |
| 370 | int gf_bits; // Bits for the golden frame or ARF - 2 pass only |
| 371 | int mid_gf_extra_bits; // A few extra bits for the frame half way between two gfs. |
| 372 | |
Paul Wilkins | 9404c7d | 2010-07-23 17:01:12 +0100 | [diff] [blame] | 373 | // Projected total bits available for a key frame group of frames |
| 374 | long long kf_group_bits; |
| 375 | |
| 376 | // Error score of frames still to be coded in kf group |
| 377 | long long kf_group_error_left; |
| 378 | |
| 379 | // Bits for the key frame in a key frame group - 2 pass only |
| 380 | int kf_bits; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 381 | |
| 382 | int non_gf_bitrate_adjustment; // Used in the few frames following a GF to recover the extra bits spent in that GF |
| 383 | int initial_gf_use; // percentage use of gf 2 frames after gf |
| 384 | |
| 385 | int gf_group_error_left; // Remaining error from uncoded frames in a gf group. Two pass use only |
| 386 | |
| 387 | int kf_overspend_bits; // Extra bits spent on key frames that need to be recovered on inter frames |
| 388 | int kf_bitrate_adjustment; // Current number of bit s to try and recover on each inter frame. |
| 389 | int max_gf_interval; |
Paul Wilkins | 57136a2 | 2011-01-18 15:19:05 +0000 | [diff] [blame] | 390 | int static_scene_max_gf_interval; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 391 | int baseline_gf_interval; |
| 392 | int gf_decay_rate; |
Adrian Grange | 1b2f830 | 2010-09-28 15:23:41 +0100 | [diff] [blame] | 393 | int active_arnr_frames; // <= cpi->oxcf.arnr_max_frames |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 394 | |
| 395 | INT64 key_frame_count; |
| 396 | INT64 tot_key_frame_bits; |
| 397 | int prior_key_frame_size[KEY_FRAME_CONTEXT]; |
| 398 | int prior_key_frame_distance[KEY_FRAME_CONTEXT]; |
| 399 | int per_frame_bandwidth; // Current section per frame bandwidth target |
| 400 | int av_per_frame_bandwidth; // Average frame size target for clip |
| 401 | int min_frame_bandwidth; // Minimum allocation that should be used for any frame |
| 402 | int last_key_frame_size; |
| 403 | int intra_frame_target; |
| 404 | int inter_frame_target; |
| 405 | double output_frame_rate; |
| 406 | long long last_time_stamp_seen; |
John Koleszar | f7e187d | 2010-11-04 15:05:45 -0400 | [diff] [blame] | 407 | long long last_end_time_stamp_seen; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 408 | long long first_time_stamp_ever; |
| 409 | |
| 410 | int ni_av_qi; |
| 411 | int ni_tot_qi; |
| 412 | int ni_frames; |
| 413 | int avg_frame_qindex; |
| 414 | |
| 415 | int zbin_over_quant; |
| 416 | int zbin_mode_boost; |
| 417 | int zbin_mode_boost_enabled; |
| 418 | |
| 419 | INT64 total_byte_count; |
| 420 | |
| 421 | int buffered_mode; |
| 422 | |
| 423 | int buffer_level; |
| 424 | int bits_off_target; |
| 425 | |
| 426 | int rolling_target_bits; |
| 427 | int rolling_actual_bits; |
| 428 | |
| 429 | int long_rolling_target_bits; |
| 430 | int long_rolling_actual_bits; |
| 431 | |
| 432 | long long total_actual_bits; |
| 433 | int total_target_vs_actual; // debug stats |
| 434 | |
| 435 | int worst_quality; |
| 436 | int active_worst_quality; |
| 437 | int best_quality; |
| 438 | int active_best_quality; |
| 439 | |
Paul Wilkins | e0846c9 | 2011-01-07 18:29:37 +0000 | [diff] [blame] | 440 | int cq_target_quality; |
Paul Wilkins | 3af3593 | 2011-01-07 16:33:59 +0000 | [diff] [blame] | 441 | int maxq_max_limit; |
| 442 | int maxq_min_limit; |
| 443 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 444 | int drop_frames_allowed; // Are we permitted to drop frames? |
| 445 | int drop_frame; // Drop this frame? |
| 446 | int drop_count; // How many frames have we dropped? |
| 447 | int max_drop_count; // How many frames should we drop? |
| 448 | int max_consec_dropped_frames; // Limit number of consecutive frames that can be dropped. |
| 449 | |
| 450 | |
| 451 | int ymode_count [VP8_YMODES]; /* intra MB type cts this frame */ |
| 452 | int uv_mode_count[VP8_UV_MODES]; /* intra MB type cts this frame */ |
| 453 | |
| 454 | unsigned int MVcount [2] [MVvals]; /* (row,col) MV cts this frame */ |
| 455 | |
| 456 | unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens]; /* for this frame */ |
| 457 | //DECLARE_ALIGNED(16, int, coef_counts_backup [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens]); //not used any more |
| 458 | //save vp8_tree_probs_from_distribution result for each frame to avoid repeat calculation |
| 459 | vp8_prob frame_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1]; |
| 460 | unsigned int frame_branch_ct [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [vp8_coef_tokens-1][2]; |
| 461 | |
| 462 | /* Second compressed data partition contains coefficient data. */ |
| 463 | |
| 464 | unsigned char *output_partition2; |
| 465 | size_t output_partition2size; |
| 466 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 467 | int frames_to_key; |
| 468 | int gfu_boost; |
| 469 | int kf_boost; |
| 470 | int last_boost; |
| 471 | double total_error_left; |
| 472 | double total_intra_error_left; |
| 473 | double total_coded_error_left; |
| 474 | double start_tot_err_left; |
| 475 | double min_error; |
Paul Wilkins | b095d9d | 2011-01-04 17:55:49 +0000 | [diff] [blame] | 476 | double kf_intra_err_min; |
| 477 | double gf_intra_err_min; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 478 | |
Paul Wilkins | 70b885a | 2010-11-12 11:35:30 +0000 | [diff] [blame] | 479 | double modified_error_total; |
| 480 | double modified_error_used; |
| 481 | double modified_error_left; |
| 482 | double clip_bpe; |
| 483 | double observed_bpe; |
| 484 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 485 | double avg_iiratio; |
| 486 | |
| 487 | int target_bandwidth; |
| 488 | long long bits_left; |
Paul Wilkins | 70b885a | 2010-11-12 11:35:30 +0000 | [diff] [blame] | 489 | long long clip_bits_total; |
John Koleszar | bb7dd5b | 2010-10-14 16:40:12 -0400 | [diff] [blame] | 490 | FIRSTPASS_STATS *total_stats; |
| 491 | FIRSTPASS_STATS *this_frame_stats; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 492 | FIRSTPASS_STATS *stats_in, *stats_in_end; |
| 493 | struct vpx_codec_pkt_list *output_pkt_list; |
| 494 | int first_pass_done; |
| 495 | unsigned char *fp_motion_map; |
John Koleszar | bb7dd5b | 2010-10-14 16:40:12 -0400 | [diff] [blame] | 496 | |
| 497 | unsigned char *fp_motion_map_stats, *fp_motion_map_stats_save; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 498 | |
| 499 | #if 0 |
| 500 | // Experimental code for lagged and one pass |
| 501 | ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS]; |
| 502 | int one_pass_frame_index; |
| 503 | #endif |
| 504 | |
| 505 | int decimation_factor; |
| 506 | int decimation_count; |
| 507 | |
| 508 | // for real time encoding |
| 509 | int avg_encode_time; //microsecond |
| 510 | int avg_pick_mode_time; //microsecond |
| 511 | int Speed; |
| 512 | unsigned int cpu_freq; //Mhz |
| 513 | int compressor_speed; |
| 514 | |
| 515 | int interquantizer; |
| 516 | int auto_gold; |
| 517 | int auto_adjust_gold_quantizer; |
| 518 | int goldquantizer; |
| 519 | int goldfreq; |
| 520 | int auto_adjust_key_quantizer; |
| 521 | int keyquantizer; |
| 522 | int auto_worst_q; |
| 523 | int filter_type; |
| 524 | int cpu_used; |
| 525 | int chroma_boost; |
| 526 | int horiz_scale; |
| 527 | int vert_scale; |
| 528 | int pass; |
| 529 | |
| 530 | |
| 531 | int prob_intra_coded; |
| 532 | int prob_last_coded; |
| 533 | int prob_gf_coded; |
| 534 | int prob_skip_false; |
| 535 | int last_skip_false_probs[3]; |
| 536 | int last_skip_probs_q[3]; |
| 537 | int recent_ref_frame_usage[MAX_REF_FRAMES]; |
| 538 | |
| 539 | int count_mb_ref_frame_usage[MAX_REF_FRAMES]; |
| 540 | int this_frame_percent_intra; |
| 541 | int last_frame_percent_intra; |
| 542 | |
| 543 | int last_key_frame_q; |
| 544 | int last_kffilt_lvl; |
| 545 | |
| 546 | int ref_frame_flags; |
| 547 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 548 | SPEED_FEATURES sf; |
| 549 | int error_bins[1024]; |
| 550 | |
| 551 | int inter_lvl; |
| 552 | int intra_lvl; |
| 553 | int motion_lvl; |
| 554 | int motion_speed; |
| 555 | int motion_var; |
John Koleszar | cd475da | 2010-06-12 14:11:51 -0400 | [diff] [blame] | 556 | unsigned int next_iiratio; |
| 557 | unsigned int this_iiratio; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 558 | int this_frame_modified_error; |
| 559 | |
| 560 | double norm_intra_err_per_mb; |
| 561 | double norm_inter_err_per_mb; |
| 562 | double norm_iidiff_per_mb; |
| 563 | |
| 564 | int last_best_mode_index; // Record of mode index chosen for previous macro block. |
| 565 | int last_auto_filt_val; |
| 566 | int last_auto_filt_q; |
| 567 | |
| 568 | // Data used for real time conferencing mode to help determine if it would be good to update the gf |
| 569 | int inter_zz_count; |
| 570 | int gf_bad_count; |
| 571 | int gf_update_recommended; |
| 572 | int skip_true_count; |
| 573 | int skip_false_count; |
| 574 | |
| 575 | int alt_qcount; |
| 576 | |
| 577 | int ready_for_new_frame; |
| 578 | |
| 579 | unsigned char *segmentation_map; |
| 580 | signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS]; // Segment data (can be deltas or absolute values) |
| 581 | int segment_encode_breakout[MAX_MB_SEGMENTS]; // segment threashold for encode breakout |
| 582 | |
| 583 | unsigned char *active_map; |
| 584 | unsigned int active_map_enabled; |
| 585 | // Video conferencing cyclic refresh mode flags etc |
| 586 | // This is a mode designed to clean up the background over time in live encoding scenarious. It uses segmentation |
| 587 | int cyclic_refresh_mode_enabled; |
| 588 | int cyclic_refresh_mode_max_mbs_perframe; |
| 589 | int cyclic_refresh_mode_index; |
| 590 | int cyclic_refresh_q; |
| 591 | signed char *cyclic_refresh_map; |
| 592 | |
Gaute Strokkenes | 315e3c2 | 2011-02-05 05:29:25 +0000 | [diff] [blame] | 593 | #if CONFIG_MULTITHREAD |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 594 | // multithread data |
Attila Nagy | 385c2a7 | 2011-01-26 10:29:46 +0200 | [diff] [blame] | 595 | int * mt_current_mb_col; |
| 596 | int mt_sync_range; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 597 | int processor_core_count; |
| 598 | int b_multi_threaded; |
| 599 | int encoding_thread_count; |
| 600 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 601 | pthread_t *h_encoding_thread; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 602 | MB_ROW_COMP *mb_row_ei; |
| 603 | ENCODETHREAD_DATA *en_thread_data; |
| 604 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 605 | //events |
Attila Nagy | 385c2a7 | 2011-01-26 10:29:46 +0200 | [diff] [blame] | 606 | sem_t *h_event_start_encoding; |
| 607 | sem_t h_event_end_encoding; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 608 | #endif |
| 609 | |
| 610 | TOKENLIST *tplist; |
| 611 | // end of multithread data |
| 612 | |
| 613 | |
| 614 | fractional_mv_step_fp *find_fractional_mv_step; |
| 615 | vp8_full_search_fn_t full_search_sad; |
| 616 | vp8_diamond_search_fn_t diamond_search_sad; |
John Koleszar | 209d82a | 2010-10-26 15:34:16 -0400 | [diff] [blame] | 617 | vp8_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SEGMENTS]; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 618 | unsigned int time_receive_data; |
| 619 | unsigned int time_compress_data; |
| 620 | unsigned int time_pick_lpf; |
| 621 | unsigned int time_encode_mb_row; |
| 622 | |
| 623 | unsigned int tempdata1; |
| 624 | unsigned int tempdata2; |
| 625 | |
| 626 | int base_skip_false_prob[128]; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 627 | unsigned int section_intra_rating; |
| 628 | |
| 629 | double section_max_qfactor; |
| 630 | |
| 631 | |
| 632 | #if CONFIG_RUNTIME_CPU_DETECT |
| 633 | VP8_ENCODER_RTCD rtcd; |
| 634 | #endif |
| 635 | #if VP8_TEMPORAL_ALT_REF |
| 636 | SOURCE_SAMPLE alt_ref_buffer; |
Adrian Grange | 1b2f830 | 2010-09-28 15:23:41 +0100 | [diff] [blame] | 637 | YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS]; |
| 638 | int fixed_divide[512]; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 639 | #endif |
Adrian Grange | 1b2f830 | 2010-09-28 15:23:41 +0100 | [diff] [blame] | 640 | // Flag to indicate temporal filter method |
| 641 | int use_weighted_temporal_filter; |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 642 | |
| 643 | #if CONFIG_PSNR |
| 644 | int count; |
| 645 | double total_y; |
| 646 | double total_u; |
| 647 | double total_v; |
| 648 | double total ; |
| 649 | double total_sq_error; |
| 650 | double totalp_y; |
| 651 | double totalp_u; |
| 652 | double totalp_v; |
| 653 | double totalp; |
| 654 | double total_sq_error2; |
| 655 | int bytes; |
| 656 | double summed_quality; |
| 657 | double summed_weights; |
| 658 | unsigned int tot_recode_hits; |
| 659 | |
| 660 | |
| 661 | double total_ssimg_y; |
| 662 | double total_ssimg_u; |
| 663 | double total_ssimg_v; |
| 664 | double total_ssimg_all; |
| 665 | |
| 666 | int b_calculate_ssimg; |
| 667 | #endif |
| 668 | int b_calculate_psnr; |
Scott LaVarnway | 99f46d6 | 2010-08-11 11:02:31 -0400 | [diff] [blame] | 669 | |
| 670 | |
| 671 | unsigned char *gf_active_flags; // Record of which MBs still refer to last golden frame either directly or through 0,0 |
| 672 | int gf_active_count; |
| 673 | |
Yunqing Wang | c3bbb29 | 2010-12-03 11:26:21 -0500 | [diff] [blame] | 674 | //Store last frame's MV info for next frame MV prediction |
| 675 | int_mv *lfmv; |
| 676 | int *lf_ref_frame_sign_bias; |
| 677 | int *lf_ref_frame; |
Scott LaVarnway | 99f46d6 | 2010-08-11 11:02:31 -0400 | [diff] [blame] | 678 | |
Attila Nagy | e5904f2 | 2011-02-02 13:10:27 +0200 | [diff] [blame] | 679 | #if CONFIG_REALTIME_ONLY |
| 680 | int force_next_frame_intra; /* force next frame to intra when kf_auto says so */ |
| 681 | #endif |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 682 | } VP8_COMP; |
| 683 | |
| 684 | void control_data_rate(VP8_COMP *cpi); |
| 685 | |
| 686 | void vp8_encode_frame(VP8_COMP *cpi); |
| 687 | |
| 688 | void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size); |
| 689 | |
Timothy B. Terriberry | 8d0f7a0 | 2010-10-11 14:37:27 -0700 | [diff] [blame] | 690 | unsigned int vp8_activity_masking(VP8_COMP *cpi, MACROBLOCK *x); |
| 691 | |
John Koleszar | 0ea50ce | 2010-05-18 11:58:33 -0400 | [diff] [blame] | 692 | int rd_cost_intra_mb(MACROBLOCKD *x); |
| 693 | |
| 694 | void vp8_tokenize_mb(VP8_COMP *, MACROBLOCKD *, TOKENEXTRA **); |
| 695 | |
| 696 | void vp8_set_speed_features(VP8_COMP *cpi); |
| 697 | |
| 698 | #if CONFIG_DEBUG |
| 699 | #define CHECK_MEM_ERROR(lval,expr) do {\ |
| 700 | lval = (expr); \ |
| 701 | if(!lval) \ |
| 702 | vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\ |
| 703 | "Failed to allocate "#lval" at %s:%d", \ |
| 704 | __FILE__,__LINE__);\ |
| 705 | } while(0) |
| 706 | #else |
| 707 | #define CHECK_MEM_ERROR(lval,expr) do {\ |
| 708 | lval = (expr); \ |
| 709 | if(!lval) \ |
| 710 | vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\ |
| 711 | "Failed to allocate "#lval);\ |
| 712 | } while(0) |
| 713 | #endif |
| 714 | #endif |