OLD | NEW |
(Empty) | |
| 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 VP9_ENCODER_VP9_ONYX_INT_H_ |
| 13 #define VP9_ENCODER_VP9_ONYX_INT_H_ |
| 14 |
| 15 #include <stdio.h> |
| 16 #include "vpx_ports/config.h" |
| 17 #include "vp9/common/vp9_onyx.h" |
| 18 #include "vp9/encoder/vp9_treewriter.h" |
| 19 #include "vp9/encoder/vp9_tokenize.h" |
| 20 #include "vp9/common/vp9_onyxc_int.h" |
| 21 #include "vp9/encoder/vp9_variance.h" |
| 22 #include "vp9/encoder/vp9_encodemb.h" |
| 23 #include "vp9/encoder/vp9_quantize.h" |
| 24 #include "vp9/common/vp9_entropy.h" |
| 25 #include "vp9/common/vp9_entropymode.h" |
| 26 #include "vpx_ports/mem.h" |
| 27 #include "vpx/internal/vpx_codec_internal.h" |
| 28 #include "vp9/encoder/vp9_mcomp.h" |
| 29 #include "vp9/common/vp9_findnearmv.h" |
| 30 #include "vp9/encoder/vp9_lookahead.h" |
| 31 |
| 32 // #define SPEEDSTATS 1 |
| 33 #define MIN_GF_INTERVAL 4 |
| 34 #define DEFAULT_GF_INTERVAL 7 |
| 35 |
| 36 #define KEY_FRAME_CONTEXT 5 |
| 37 |
| 38 #define MAX_LAG_BUFFERS 25 |
| 39 |
| 40 #define AF_THRESH 25 |
| 41 #define AF_THRESH2 100 |
| 42 #define ARF_DECAY_THRESH 12 |
| 43 |
| 44 #if CONFIG_PRED_FILTER |
| 45 #if CONFIG_COMP_INTERINTRA_PRED |
| 46 #define MAX_MODES 66 |
| 47 #else |
| 48 #define MAX_MODES 54 |
| 49 #endif |
| 50 #else // CONFIG_PRED_FILTER |
| 51 #if CONFIG_COMP_INTERINTRA_PRED |
| 52 #define MAX_MODES 54 |
| 53 #else |
| 54 #define MAX_MODES 42 |
| 55 #endif |
| 56 #endif // CONFIG_PRED_FILTER |
| 57 |
| 58 #define MIN_THRESHMULT 32 |
| 59 #define MAX_THRESHMULT 512 |
| 60 |
| 61 #define GF_ZEROMV_ZBIN_BOOST 12 |
| 62 #define LF_ZEROMV_ZBIN_BOOST 6 |
| 63 #define MV_ZBIN_BOOST 4 |
| 64 #define ZBIN_OQ_MAX 192 |
| 65 |
| 66 #define VP9_TEMPORAL_ALT_REF 1 |
| 67 |
| 68 typedef struct { |
| 69 nmv_context nmvc; |
| 70 int nmvjointcost[MV_JOINTS]; |
| 71 int nmvcosts[2][MV_VALS]; |
| 72 int nmvcosts_hp[2][MV_VALS]; |
| 73 |
| 74 #ifdef MODE_STATS |
| 75 // Stats |
| 76 int y_modes[VP9_YMODES]; |
| 77 int uv_modes[VP9_UV_MODES]; |
| 78 int i8x8_modes[VP9_I8X8_MODES]; |
| 79 int b_modes[B_MODE_COUNT]; |
| 80 int inter_y_modes[MB_MODE_COUNT]; |
| 81 int inter_uv_modes[VP9_UV_MODES]; |
| 82 int inter_b_modes[B_MODE_COUNT]; |
| 83 #endif |
| 84 |
| 85 vp9_prob segment_pred_probs[PREDICTION_PROBS]; |
| 86 unsigned char ref_pred_probs_update[PREDICTION_PROBS]; |
| 87 vp9_prob ref_pred_probs[PREDICTION_PROBS]; |
| 88 vp9_prob prob_comppred[COMP_PRED_CONTEXTS]; |
| 89 |
| 90 unsigned char *last_frame_seg_map_copy; |
| 91 |
| 92 // 0 = Intra, Last, GF, ARF |
| 93 signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS]; |
| 94 // 0 = BPRED, ZERO_MV, MV, SPLIT |
| 95 signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS]; |
| 96 |
| 97 vp9_prob coef_probs[BLOCK_TYPES] |
| 98 [COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; |
| 99 vp9_prob hybrid_coef_probs[BLOCK_TYPES] |
| 100 [COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; |
| 101 |
| 102 vp9_prob coef_probs_8x8[BLOCK_TYPES_8X8] |
| 103 [COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; |
| 104 vp9_prob hybrid_coef_probs_8x8[BLOCK_TYPES_8X8] |
| 105 [COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; |
| 106 |
| 107 vp9_prob coef_probs_16x16[BLOCK_TYPES_16X16] |
| 108 [COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; |
| 109 vp9_prob hybrid_coef_probs_16x16[BLOCK_TYPES_16X16] |
| 110 [COEF_BANDS][PREV_COEF_CONTEXTS][ENTROPY_NODES]; |
| 111 |
| 112 #if CONFIG_SUPERBLOCKS |
| 113 vp9_prob sb_ymode_prob[VP9_I32X32_MODES - 1]; |
| 114 #endif |
| 115 vp9_prob ymode_prob[VP9_YMODES - 1]; /* interframe intra mode probs */ |
| 116 vp9_prob uv_mode_prob[VP9_YMODES][VP9_UV_MODES - 1]; |
| 117 vp9_prob bmode_prob[VP9_NKF_BINTRAMODES - 1]; |
| 118 vp9_prob i8x8_mode_prob[VP9_I8X8_MODES - 1]; |
| 119 vp9_prob sub_mv_ref_prob[SUBMVREF_COUNT][VP9_SUBMVREFS - 1]; |
| 120 vp9_prob mbsplit_prob[VP9_NUMMBSPLITS - 1]; |
| 121 |
| 122 vp9_prob switchable_interp_prob[VP9_SWITCHABLE_FILTERS + 1] |
| 123 [VP9_SWITCHABLE_FILTERS - 1]; |
| 124 #if CONFIG_COMP_INTERINTRA_PRED |
| 125 vp9_prob interintra_prob; |
| 126 #endif |
| 127 |
| 128 int mv_ref_ct[INTER_MODE_CONTEXTS][4][2]; |
| 129 int vp9_mode_contexts[INTER_MODE_CONTEXTS][4]; |
| 130 |
| 131 } CODING_CONTEXT; |
| 132 |
| 133 typedef struct { |
| 134 double frame; |
| 135 double intra_error; |
| 136 double coded_error; |
| 137 double sr_coded_error; |
| 138 double ssim_weighted_pred_err; |
| 139 double pcnt_inter; |
| 140 double pcnt_motion; |
| 141 double pcnt_second_ref; |
| 142 double pcnt_neutral; |
| 143 double MVr; |
| 144 double mvr_abs; |
| 145 double MVc; |
| 146 double mvc_abs; |
| 147 double MVrv; |
| 148 double MVcv; |
| 149 double mv_in_out_count; |
| 150 double new_mv_count; |
| 151 double duration; |
| 152 double count; |
| 153 } |
| 154 FIRSTPASS_STATS; |
| 155 |
| 156 typedef struct { |
| 157 int frames_so_far; |
| 158 double frame_intra_error; |
| 159 double frame_coded_error; |
| 160 double frame_pcnt_inter; |
| 161 double frame_pcnt_motion; |
| 162 double frame_mvr; |
| 163 double frame_mvr_abs; |
| 164 double frame_mvc; |
| 165 double frame_mvc_abs; |
| 166 |
| 167 } ONEPASS_FRAMESTATS; |
| 168 |
| 169 typedef struct { |
| 170 struct { |
| 171 int err; |
| 172 union { |
| 173 int_mv mv; |
| 174 MB_PREDICTION_MODE mode; |
| 175 } m; |
| 176 } ref[MAX_REF_FRAMES]; |
| 177 } MBGRAPH_MB_STATS; |
| 178 |
| 179 typedef struct { |
| 180 MBGRAPH_MB_STATS *mb_stats; |
| 181 } MBGRAPH_FRAME_STATS; |
| 182 |
| 183 #if CONFIG_PRED_FILTER |
| 184 typedef enum { |
| 185 THR_ZEROMV, |
| 186 THR_ZEROMV_FILT, |
| 187 THR_DC, |
| 188 |
| 189 THR_NEARESTMV, |
| 190 THR_NEARESTMV_FILT, |
| 191 THR_NEARMV, |
| 192 THR_NEARMV_FILT, |
| 193 |
| 194 THR_ZEROG, |
| 195 THR_ZEROG_FILT, |
| 196 THR_NEARESTG, |
| 197 THR_NEARESTG_FILT, |
| 198 |
| 199 THR_ZEROA, |
| 200 THR_ZEROA_FILT, |
| 201 THR_NEARESTA, |
| 202 THR_NEARESTA_FILT, |
| 203 |
| 204 THR_NEARG, |
| 205 THR_NEARG_FILT, |
| 206 THR_NEARA, |
| 207 THR_NEARA_FILT, |
| 208 |
| 209 THR_V_PRED, |
| 210 THR_H_PRED, |
| 211 THR_D45_PRED, |
| 212 THR_D135_PRED, |
| 213 THR_D117_PRED, |
| 214 THR_D153_PRED, |
| 215 THR_D27_PRED, |
| 216 THR_D63_PRED, |
| 217 THR_TM, |
| 218 |
| 219 THR_NEWMV, |
| 220 THR_NEWMV_FILT, |
| 221 THR_NEWG, |
| 222 THR_NEWG_FILT, |
| 223 THR_NEWA, |
| 224 THR_NEWA_FILT, |
| 225 |
| 226 THR_SPLITMV, |
| 227 THR_SPLITG, |
| 228 THR_SPLITA, |
| 229 |
| 230 THR_B_PRED, |
| 231 THR_I8X8_PRED, |
| 232 |
| 233 THR_COMP_ZEROLG, |
| 234 THR_COMP_NEARESTLG, |
| 235 THR_COMP_NEARLG, |
| 236 |
| 237 THR_COMP_ZEROLA, |
| 238 THR_COMP_NEARESTLA, |
| 239 THR_COMP_NEARLA, |
| 240 |
| 241 THR_COMP_ZEROGA, |
| 242 THR_COMP_NEARESTGA, |
| 243 THR_COMP_NEARGA, |
| 244 |
| 245 THR_COMP_NEWLG, |
| 246 THR_COMP_NEWLA, |
| 247 THR_COMP_NEWGA, |
| 248 |
| 249 THR_COMP_SPLITLG, |
| 250 THR_COMP_SPLITLA, |
| 251 THR_COMP_SPLITGA, |
| 252 #if CONFIG_COMP_INTERINTRA_PRED |
| 253 THR_COMP_INTERINTRA_ZEROL, |
| 254 THR_COMP_INTERINTRA_NEARESTL, |
| 255 THR_COMP_INTERINTRA_NEARL, |
| 256 THR_COMP_INTERINTRA_NEWL, |
| 257 |
| 258 THR_COMP_INTERINTRA_ZEROG, |
| 259 THR_COMP_INTERINTRA_NEARESTG, |
| 260 THR_COMP_INTERINTRA_NEARG, |
| 261 THR_COMP_INTERINTRA_NEWG, |
| 262 |
| 263 THR_COMP_INTERINTRA_ZEROA, |
| 264 THR_COMP_INTERINTRA_NEARESTA, |
| 265 THR_COMP_INTERINTRA_NEARA, |
| 266 THR_COMP_INTERINTRA_NEWA, |
| 267 #endif |
| 268 } |
| 269 THR_MODES; |
| 270 #else |
| 271 typedef enum { |
| 272 THR_ZEROMV, |
| 273 THR_DC, |
| 274 |
| 275 THR_NEARESTMV, |
| 276 THR_NEARMV, |
| 277 |
| 278 THR_ZEROG, |
| 279 THR_NEARESTG, |
| 280 |
| 281 THR_ZEROA, |
| 282 THR_NEARESTA, |
| 283 |
| 284 THR_NEARG, |
| 285 THR_NEARA, |
| 286 |
| 287 THR_V_PRED, |
| 288 THR_H_PRED, |
| 289 THR_D45_PRED, |
| 290 THR_D135_PRED, |
| 291 THR_D117_PRED, |
| 292 THR_D153_PRED, |
| 293 THR_D27_PRED, |
| 294 THR_D63_PRED, |
| 295 THR_TM, |
| 296 |
| 297 THR_NEWMV, |
| 298 THR_NEWG, |
| 299 THR_NEWA, |
| 300 |
| 301 THR_SPLITMV, |
| 302 THR_SPLITG, |
| 303 THR_SPLITA, |
| 304 |
| 305 THR_B_PRED, |
| 306 THR_I8X8_PRED, |
| 307 |
| 308 THR_COMP_ZEROLG, |
| 309 THR_COMP_NEARESTLG, |
| 310 THR_COMP_NEARLG, |
| 311 |
| 312 THR_COMP_ZEROLA, |
| 313 THR_COMP_NEARESTLA, |
| 314 THR_COMP_NEARLA, |
| 315 |
| 316 THR_COMP_ZEROGA, |
| 317 THR_COMP_NEARESTGA, |
| 318 THR_COMP_NEARGA, |
| 319 |
| 320 THR_COMP_NEWLG, |
| 321 THR_COMP_NEWLA, |
| 322 THR_COMP_NEWGA, |
| 323 |
| 324 THR_COMP_SPLITLG, |
| 325 THR_COMP_SPLITLA, |
| 326 THR_COMP_SPLITGA, |
| 327 #if CONFIG_COMP_INTERINTRA_PRED |
| 328 THR_COMP_INTERINTRA_ZEROL, |
| 329 THR_COMP_INTERINTRA_NEARESTL, |
| 330 THR_COMP_INTERINTRA_NEARL, |
| 331 THR_COMP_INTERINTRA_NEWL, |
| 332 |
| 333 THR_COMP_INTERINTRA_ZEROG, |
| 334 THR_COMP_INTERINTRA_NEARESTG, |
| 335 THR_COMP_INTERINTRA_NEARG, |
| 336 THR_COMP_INTERINTRA_NEWG, |
| 337 |
| 338 THR_COMP_INTERINTRA_ZEROA, |
| 339 THR_COMP_INTERINTRA_NEARESTA, |
| 340 THR_COMP_INTERINTRA_NEARA, |
| 341 THR_COMP_INTERINTRA_NEWA, |
| 342 #endif |
| 343 } |
| 344 THR_MODES; |
| 345 #endif |
| 346 |
| 347 typedef enum { |
| 348 DIAMOND = 0, |
| 349 NSTEP = 1, |
| 350 HEX = 2 |
| 351 } SEARCH_METHODS; |
| 352 |
| 353 typedef struct { |
| 354 int RD; |
| 355 SEARCH_METHODS search_method; |
| 356 int improved_dct; |
| 357 int auto_filter; |
| 358 int recode_loop; |
| 359 int iterative_sub_pixel; |
| 360 int half_pixel_search; |
| 361 int quarter_pixel_search; |
| 362 int thresh_mult[MAX_MODES]; |
| 363 int max_step_search_steps; |
| 364 int first_step; |
| 365 int optimize_coefficients; |
| 366 int no_skip_block4x4_search; |
| 367 int improved_mv_pred; |
| 368 int search_best_filter; |
| 369 |
| 370 } SPEED_FEATURES; |
| 371 |
| 372 typedef struct { |
| 373 MACROBLOCK mb; |
| 374 int totalrate; |
| 375 } MB_ROW_COMP; |
| 376 |
| 377 typedef struct { |
| 378 TOKENEXTRA *start; |
| 379 TOKENEXTRA *stop; |
| 380 } TOKENLIST; |
| 381 |
| 382 typedef struct { |
| 383 int ithread; |
| 384 void *ptr1; |
| 385 void *ptr2; |
| 386 } ENCODETHREAD_DATA; |
| 387 typedef struct { |
| 388 int ithread; |
| 389 void *ptr1; |
| 390 } LPFTHREAD_DATA; |
| 391 |
| 392 enum BlockSize { |
| 393 BLOCK_16X8 = PARTITIONING_16X8, |
| 394 BLOCK_8X16 = PARTITIONING_8X16, |
| 395 BLOCK_8X8 = PARTITIONING_8X8, |
| 396 BLOCK_4X4 = PARTITIONING_4X4, |
| 397 BLOCK_16X16, |
| 398 BLOCK_MAX_SEGMENTS, |
| 399 BLOCK_32X32 = BLOCK_MAX_SEGMENTS, |
| 400 BLOCK_MAX_SB_SEGMENTS, |
| 401 }; |
| 402 |
| 403 typedef struct VP9_COMP { |
| 404 |
| 405 DECLARE_ALIGNED(16, short, Y1quant[QINDEX_RANGE][16]); |
| 406 DECLARE_ALIGNED(16, unsigned char, Y1quant_shift[QINDEX_RANGE][16]); |
| 407 DECLARE_ALIGNED(16, short, Y1zbin[QINDEX_RANGE][16]); |
| 408 DECLARE_ALIGNED(16, short, Y1round[QINDEX_RANGE][16]); |
| 409 |
| 410 DECLARE_ALIGNED(16, short, Y2quant[QINDEX_RANGE][16]); |
| 411 DECLARE_ALIGNED(16, unsigned char, Y2quant_shift[QINDEX_RANGE][16]); |
| 412 DECLARE_ALIGNED(16, short, Y2zbin[QINDEX_RANGE][16]); |
| 413 DECLARE_ALIGNED(16, short, Y2round[QINDEX_RANGE][16]); |
| 414 |
| 415 DECLARE_ALIGNED(16, short, UVquant[QINDEX_RANGE][16]); |
| 416 DECLARE_ALIGNED(16, unsigned char, UVquant_shift[QINDEX_RANGE][16]); |
| 417 DECLARE_ALIGNED(16, short, UVzbin[QINDEX_RANGE][16]); |
| 418 DECLARE_ALIGNED(16, short, UVround[QINDEX_RANGE][16]); |
| 419 |
| 420 DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1[QINDEX_RANGE][16]); |
| 421 DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2[QINDEX_RANGE][16]); |
| 422 DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv[QINDEX_RANGE][16]); |
| 423 |
| 424 DECLARE_ALIGNED(64, short, Y1zbin_8x8[QINDEX_RANGE][64]); |
| 425 DECLARE_ALIGNED(64, short, Y2zbin_8x8[QINDEX_RANGE][64]); |
| 426 DECLARE_ALIGNED(64, short, UVzbin_8x8[QINDEX_RANGE][64]); |
| 427 DECLARE_ALIGNED(64, short, zrun_zbin_boost_y1_8x8[QINDEX_RANGE][64]); |
| 428 DECLARE_ALIGNED(64, short, zrun_zbin_boost_y2_8x8[QINDEX_RANGE][64]); |
| 429 DECLARE_ALIGNED(64, short, zrun_zbin_boost_uv_8x8[QINDEX_RANGE][64]); |
| 430 |
| 431 DECLARE_ALIGNED(16, short, Y1zbin_16x16[QINDEX_RANGE][256]); |
| 432 DECLARE_ALIGNED(16, short, Y2zbin_16x16[QINDEX_RANGE][256]); |
| 433 DECLARE_ALIGNED(16, short, UVzbin_16x16[QINDEX_RANGE][256]); |
| 434 DECLARE_ALIGNED(16, short, zrun_zbin_boost_y1_16x16[QINDEX_RANGE][256]); |
| 435 DECLARE_ALIGNED(16, short, zrun_zbin_boost_y2_16x16[QINDEX_RANGE][256]); |
| 436 DECLARE_ALIGNED(16, short, zrun_zbin_boost_uv_16x16[QINDEX_RANGE][256]); |
| 437 |
| 438 MACROBLOCK mb; |
| 439 VP9_COMMON common; |
| 440 VP9_CONFIG oxcf; |
| 441 |
| 442 struct lookahead_ctx *lookahead; |
| 443 struct lookahead_entry *source; |
| 444 struct lookahead_entry *alt_ref_source; |
| 445 |
| 446 YV12_BUFFER_CONFIG *Source; |
| 447 YV12_BUFFER_CONFIG *un_scaled_source; |
| 448 YV12_BUFFER_CONFIG scaled_source; |
| 449 |
| 450 int source_alt_ref_pending; // frame in src_buffers has been identified to be
encoded as an alt ref |
| 451 int source_alt_ref_active; // an alt ref frame has been encoded and is usable |
| 452 |
| 453 int is_src_frame_alt_ref; // source of frame to encode is an exact copy of a
n alt ref frame |
| 454 |
| 455 int gold_is_last; // golden frame same as last frame ( short circuit gold sear
ches) |
| 456 int alt_is_last; // Alt reference frame same as last ( short circuit altref s
earch) |
| 457 int gold_is_alt; // don't do both alt and gold search ( just do gold). |
| 458 |
| 459 // int refresh_alt_ref_frame; |
| 460 YV12_BUFFER_CONFIG last_frame_uf; |
| 461 |
| 462 TOKENEXTRA *tok; |
| 463 unsigned int tok_count; |
| 464 |
| 465 |
| 466 unsigned int frames_since_key; |
| 467 unsigned int key_frame_frequency; |
| 468 unsigned int this_key_frame_forced; |
| 469 unsigned int next_key_frame_forced; |
| 470 |
| 471 // Ambient reconstruction err target for force key frames |
| 472 int ambient_err; |
| 473 |
| 474 unsigned int mode_check_freq[MAX_MODES]; |
| 475 unsigned int mode_test_hit_counts[MAX_MODES]; |
| 476 unsigned int mode_chosen_counts[MAX_MODES]; |
| 477 |
| 478 int rd_thresh_mult[MAX_MODES]; |
| 479 int rd_baseline_thresh[MAX_MODES]; |
| 480 int rd_threshes[MAX_MODES]; |
| 481 int64_t rd_comp_pred_diff[NB_PREDICTION_TYPES]; |
| 482 int rd_prediction_type_threshes[4][NB_PREDICTION_TYPES]; |
| 483 int comp_pred_count[COMP_PRED_CONTEXTS]; |
| 484 int single_pred_count[COMP_PRED_CONTEXTS]; |
| 485 // FIXME contextualize |
| 486 int txfm_count[TX_SIZE_MAX]; |
| 487 int txfm_count_8x8p[TX_SIZE_MAX - 1]; |
| 488 int64_t rd_tx_select_diff[NB_TXFM_MODES]; |
| 489 int rd_tx_select_threshes[4][NB_TXFM_MODES]; |
| 490 |
| 491 int RDMULT; |
| 492 int RDDIV; |
| 493 |
| 494 CODING_CONTEXT coding_context; |
| 495 |
| 496 // Rate targetting variables |
| 497 int64_t prediction_error; |
| 498 int64_t last_prediction_error; |
| 499 int64_t intra_error; |
| 500 int64_t last_intra_error; |
| 501 |
| 502 int this_frame_target; |
| 503 int projected_frame_size; |
| 504 int last_q[2]; // Separate values for Intra/Inter |
| 505 int last_boosted_qindex; // Last boosted GF/KF/ARF q |
| 506 |
| 507 double rate_correction_factor; |
| 508 double key_frame_rate_correction_factor; |
| 509 double gf_rate_correction_factor; |
| 510 |
| 511 int frames_till_gf_update_due; // Count down till next GF |
| 512 int current_gf_interval; // GF interval chosen when we coded the last
GF |
| 513 |
| 514 int gf_overspend_bits; // Total bits overspent becasue of GF boost
(cumulative) |
| 515 |
| 516 int non_gf_bitrate_adjustment; // Used in the few frames following a GF to
recover the extra bits spent in that GF |
| 517 |
| 518 int kf_overspend_bits; // Extra bits spent on key frames that need
to be recovered on inter frames |
| 519 int kf_bitrate_adjustment; // Current number of bit s to try and recove
r on each inter frame. |
| 520 int max_gf_interval; |
| 521 int baseline_gf_interval; |
| 522 int active_arnr_frames; // <= cpi->oxcf.arnr_max_frames |
| 523 |
| 524 int64_t key_frame_count; |
| 525 int prior_key_frame_distance[KEY_FRAME_CONTEXT]; |
| 526 int per_frame_bandwidth; // Current section per frame bandwidth targe
t |
| 527 int av_per_frame_bandwidth; // Average frame size target for clip |
| 528 int min_frame_bandwidth; // Minimum allocation that should be used fo
r any frame |
| 529 int inter_frame_target; |
| 530 double output_frame_rate; |
| 531 int64_t last_time_stamp_seen; |
| 532 int64_t last_end_time_stamp_seen; |
| 533 int64_t first_time_stamp_ever; |
| 534 |
| 535 int ni_av_qi; |
| 536 int ni_tot_qi; |
| 537 int ni_frames; |
| 538 int avg_frame_qindex; |
| 539 double tot_q; |
| 540 double avg_q; |
| 541 |
| 542 int zbin_over_quant; |
| 543 int zbin_mode_boost; |
| 544 int zbin_mode_boost_enabled; |
| 545 |
| 546 int64_t total_byte_count; |
| 547 |
| 548 int buffered_mode; |
| 549 |
| 550 int buffer_level; |
| 551 int bits_off_target; |
| 552 |
| 553 int rolling_target_bits; |
| 554 int rolling_actual_bits; |
| 555 |
| 556 int long_rolling_target_bits; |
| 557 int long_rolling_actual_bits; |
| 558 |
| 559 int64_t total_actual_bits; |
| 560 int total_target_vs_actual; // debug stats |
| 561 |
| 562 int worst_quality; |
| 563 int active_worst_quality; |
| 564 int best_quality; |
| 565 int active_best_quality; |
| 566 |
| 567 int cq_target_quality; |
| 568 |
| 569 #if CONFIG_SUPERBLOCKS |
| 570 int sb_count; |
| 571 int sb_ymode_count [VP9_I32X32_MODES]; |
| 572 #endif |
| 573 int ymode_count[VP9_YMODES]; /* intra MB type cts this frame */ |
| 574 int bmode_count[VP9_NKF_BINTRAMODES]; |
| 575 int i8x8_mode_count[VP9_I8X8_MODES]; |
| 576 int sub_mv_ref_count[SUBMVREF_COUNT][VP9_SUBMVREFS]; |
| 577 int mbsplit_count[VP9_NUMMBSPLITS]; |
| 578 int y_uv_mode_count[VP9_YMODES][VP9_UV_MODES]; |
| 579 #if CONFIG_COMP_INTERINTRA_PRED |
| 580 unsigned int interintra_count[2]; |
| 581 unsigned int interintra_select_count[2]; |
| 582 #endif |
| 583 |
| 584 nmv_context_counts NMVcount; |
| 585 |
| 586 unsigned int coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_
ENTROPY_TOKENS]; /* for this frame */ |
| 587 vp9_prob frame_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENT
ROPY_NODES]; |
| 588 unsigned int frame_branch_ct [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [
ENTROPY_NODES][2]; |
| 589 unsigned int hybrid_coef_counts [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS
] [MAX_ENTROPY_TOKENS]; /* for this frame */ |
| 590 vp9_prob frame_hybrid_coef_probs [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXT
S] [ENTROPY_NODES]; |
| 591 unsigned int frame_hybrid_branch_ct [BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONT
EXTS] [ENTROPY_NODES][2]; |
| 592 |
| 593 unsigned int coef_counts_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTEXT
S] [MAX_ENTROPY_TOKENS]; /* for this frame */ |
| 594 vp9_prob frame_coef_probs_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTEX
TS] [ENTROPY_NODES]; |
| 595 unsigned int frame_branch_ct_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CON
TEXTS] [ENTROPY_NODES][2]; |
| 596 unsigned int hybrid_coef_counts_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_
CONTEXTS] [MAX_ENTROPY_TOKENS]; /* for this frame */ |
| 597 vp9_prob frame_hybrid_coef_probs_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF
_CONTEXTS] [ENTROPY_NODES]; |
| 598 unsigned int frame_hybrid_branch_ct_8x8 [BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_C
OEF_CONTEXTS] [ENTROPY_NODES][2]; |
| 599 |
| 600 unsigned int coef_counts_16x16 [BLOCK_TYPES_16X16] [COEF_BANDS] [PREV_COEF_CON
TEXTS] [MAX_ENTROPY_TOKENS]; /* for this frame */ |
| 601 vp9_prob frame_coef_probs_16x16 [BLOCK_TYPES_16X16] [COEF_BANDS] [PREV_COEF_CO
NTEXTS] [ENTROPY_NODES]; |
| 602 unsigned int frame_branch_ct_16x16 [BLOCK_TYPES_16X16] [COEF_BANDS] [PREV_COEF
_CONTEXTS] [ENTROPY_NODES][2]; |
| 603 unsigned int hybrid_coef_counts_16x16 [BLOCK_TYPES_16X16] [COEF_BANDS] [PREV_C
OEF_CONTEXTS] [MAX_ENTROPY_TOKENS]; /* for this frame */ |
| 604 vp9_prob frame_hybrid_coef_probs_16x16 [BLOCK_TYPES_16X16] [COEF_BANDS] [PREV_
COEF_CONTEXTS] [ENTROPY_NODES]; |
| 605 unsigned int frame_hybrid_branch_ct_16x16 [BLOCK_TYPES_16X16] [COEF_BANDS] [PR
EV_COEF_CONTEXTS] [ENTROPY_NODES][2]; |
| 606 |
| 607 int gfu_boost; |
| 608 int last_boost; |
| 609 int kf_boost; |
| 610 int kf_zeromotion_pct; |
| 611 |
| 612 int target_bandwidth; |
| 613 struct vpx_codec_pkt_list *output_pkt_list; |
| 614 |
| 615 #if 0 |
| 616 // Experimental code for lagged and one pass |
| 617 ONEPASS_FRAMESTATS one_pass_frame_stats[MAX_LAG_BUFFERS]; |
| 618 int one_pass_frame_index; |
| 619 #endif |
| 620 MBGRAPH_FRAME_STATS mbgraph_stats[MAX_LAG_BUFFERS]; |
| 621 int mbgraph_n_frames; // number of frames filled in the above |
| 622 int static_mb_pct; // % forced skip mbs by segmentation |
| 623 int seg0_progress, seg0_idx, seg0_cnt; |
| 624 int ref_pred_count[3][2]; |
| 625 |
| 626 int decimation_factor; |
| 627 int decimation_count; |
| 628 |
| 629 // for real time encoding |
| 630 int avg_encode_time; // microsecond |
| 631 int avg_pick_mode_time; // microsecond |
| 632 int Speed; |
| 633 unsigned int cpu_freq; // Mhz |
| 634 int compressor_speed; |
| 635 |
| 636 int interquantizer; |
| 637 int goldfreq; |
| 638 int auto_worst_q; |
| 639 int cpu_used; |
| 640 int horiz_scale; |
| 641 int vert_scale; |
| 642 int pass; |
| 643 |
| 644 vp9_prob last_skip_false_probs[3][MBSKIP_CONTEXTS]; |
| 645 int last_skip_probs_q[3]; |
| 646 |
| 647 int recent_ref_frame_usage[MAX_REF_FRAMES]; |
| 648 int count_mb_ref_frame_usage[MAX_REF_FRAMES]; |
| 649 int ref_frame_flags; |
| 650 |
| 651 unsigned char ref_pred_probs_update[PREDICTION_PROBS]; |
| 652 |
| 653 SPEED_FEATURES sf; |
| 654 int error_bins[1024]; |
| 655 |
| 656 // Data used for real time conferencing mode to help determine if it would be
good to update the gf |
| 657 int inter_zz_count; |
| 658 int gf_bad_count; |
| 659 int gf_update_recommended; |
| 660 int skip_true_count[3]; |
| 661 int skip_false_count[3]; |
| 662 |
| 663 unsigned char *segmentation_map; |
| 664 |
| 665 // segment threashold for encode breakout |
| 666 int segment_encode_breakout[MAX_MB_SEGMENTS]; |
| 667 |
| 668 unsigned char *active_map; |
| 669 unsigned int active_map_enabled; |
| 670 |
| 671 TOKENLIST *tplist; |
| 672 |
| 673 fractional_mv_step_fp *find_fractional_mv_step; |
| 674 vp9_full_search_fn_t full_search_sad; |
| 675 vp9_refining_search_fn_t refining_search_sad; |
| 676 vp9_diamond_search_fn_t diamond_search_sad; |
| 677 vp9_variance_fn_ptr_t fn_ptr[BLOCK_MAX_SB_SEGMENTS]; |
| 678 uint64_t time_receive_data; |
| 679 uint64_t time_compress_data; |
| 680 uint64_t time_pick_lpf; |
| 681 uint64_t time_encode_mb_row; |
| 682 |
| 683 int base_skip_false_prob[QINDEX_RANGE][3]; |
| 684 |
| 685 struct twopass_rc { |
| 686 unsigned int section_intra_rating; |
| 687 unsigned int next_iiratio; |
| 688 unsigned int this_iiratio; |
| 689 FIRSTPASS_STATS *total_stats; |
| 690 FIRSTPASS_STATS *this_frame_stats; |
| 691 FIRSTPASS_STATS *stats_in, *stats_in_end, *stats_in_start; |
| 692 FIRSTPASS_STATS *total_left_stats; |
| 693 int first_pass_done; |
| 694 int64_t bits_left; |
| 695 int64_t clip_bits_total; |
| 696 double avg_iiratio; |
| 697 double modified_error_total; |
| 698 double modified_error_used; |
| 699 double modified_error_left; |
| 700 double kf_intra_err_min; |
| 701 double gf_intra_err_min; |
| 702 int frames_to_key; |
| 703 int maxq_max_limit; |
| 704 int maxq_min_limit; |
| 705 int static_scene_max_gf_interval; |
| 706 int kf_bits; |
| 707 // Remaining error from uncoded frames in a gf group. Two pass use only |
| 708 int64_t gf_group_error_left; |
| 709 |
| 710 // Projected total bits available for a key frame group of frames |
| 711 int64_t kf_group_bits; |
| 712 |
| 713 // Error score of frames still to be coded in kf group |
| 714 int64_t kf_group_error_left; |
| 715 |
| 716 // Projected Bits available for a group of frames including 1 GF or ARF |
| 717 int64_t gf_group_bits; |
| 718 // Bits for the golden frame or ARF - 2 pass only |
| 719 int gf_bits; |
| 720 int alt_extra_bits; |
| 721 |
| 722 int sr_update_lag; |
| 723 double est_max_qcorrection_factor; |
| 724 } twopass; |
| 725 |
| 726 #if VP9_TEMPORAL_ALT_REF |
| 727 YV12_BUFFER_CONFIG alt_ref_buffer; |
| 728 YV12_BUFFER_CONFIG *frames[MAX_LAG_BUFFERS]; |
| 729 int fixed_divide[512]; |
| 730 #endif |
| 731 |
| 732 #if CONFIG_INTERNAL_STATS |
| 733 int count; |
| 734 double total_y; |
| 735 double total_u; |
| 736 double total_v; |
| 737 double total; |
| 738 double total_sq_error; |
| 739 double totalp_y; |
| 740 double totalp_u; |
| 741 double totalp_v; |
| 742 double totalp; |
| 743 double total_sq_error2; |
| 744 int bytes; |
| 745 double summed_quality; |
| 746 double summed_weights; |
| 747 unsigned int tot_recode_hits; |
| 748 |
| 749 |
| 750 double total_ssimg_y; |
| 751 double total_ssimg_u; |
| 752 double total_ssimg_v; |
| 753 double total_ssimg_all; |
| 754 |
| 755 int b_calculate_ssimg; |
| 756 #endif |
| 757 int b_calculate_psnr; |
| 758 |
| 759 // Per MB activity measurement |
| 760 unsigned int activity_avg; |
| 761 unsigned int *mb_activity_map; |
| 762 int *mb_norm_activity_map; |
| 763 |
| 764 // Record of which MBs still refer to last golden frame either |
| 765 // directly or through 0,0 |
| 766 unsigned char *gf_active_flags; |
| 767 int gf_active_count; |
| 768 |
| 769 int output_partition; |
| 770 |
| 771 // Store last frame's MV info for next frame MV prediction |
| 772 int_mv *lfmv; |
| 773 int *lf_ref_frame_sign_bias; |
| 774 int *lf_ref_frame; |
| 775 |
| 776 /* force next frame to intra when kf_auto says so */ |
| 777 int force_next_frame_intra; |
| 778 |
| 779 int droppable; |
| 780 |
| 781 // TODO Do we still need this?? |
| 782 int update_context; |
| 783 |
| 784 int dummy_packing; /* flag to indicate if packing is dummy */ |
| 785 |
| 786 #if CONFIG_PRED_FILTER |
| 787 int pred_filter_on_count; |
| 788 int pred_filter_off_count; |
| 789 #endif |
| 790 unsigned int switchable_interp_count[VP9_SWITCHABLE_FILTERS + 1] |
| 791 [VP9_SWITCHABLE_FILTERS]; |
| 792 #if CONFIG_NEW_MVREF |
| 793 unsigned int best_ref_index_counts[MAX_REF_FRAMES][MAX_MV_REFS]; |
| 794 #endif |
| 795 |
| 796 } VP9_COMP; |
| 797 |
| 798 void vp9_encode_frame(VP9_COMP *cpi); |
| 799 |
| 800 void vp9_pack_bitstream(VP9_COMP *cpi, unsigned char *dest, |
| 801 unsigned long *size); |
| 802 |
| 803 void vp9_activity_masking(VP9_COMP *cpi, MACROBLOCK *x); |
| 804 |
| 805 void vp9_set_speed_features(VP9_COMP *cpi); |
| 806 |
| 807 extern int vp9_calc_ss_err(YV12_BUFFER_CONFIG *source, |
| 808 YV12_BUFFER_CONFIG *dest); |
| 809 |
| 810 extern void vp9_alloc_compressor_data(VP9_COMP *cpi); |
| 811 |
| 812 #if CONFIG_DEBUG |
| 813 #define CHECK_MEM_ERROR(lval,expr) do {\ |
| 814 lval = (expr); \ |
| 815 if(!lval) \ |
| 816 vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\ |
| 817 "Failed to allocate "#lval" at %s:%d", \ |
| 818 __FILE__,__LINE__);\ |
| 819 } while(0) |
| 820 #else |
| 821 #define CHECK_MEM_ERROR(lval,expr) do {\ |
| 822 lval = (expr); \ |
| 823 if(!lval) \ |
| 824 vpx_internal_error(&cpi->common.error, VPX_CODEC_MEM_ERROR,\ |
| 825 "Failed to allocate "#lval);\ |
| 826 } while(0) |
| 827 #endif |
| 828 #endif // __INC_ONYX_INT_H |
OLD | NEW |