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