| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 #ifdef OUTPUT_YUV_REC | 86 #ifdef OUTPUT_YUV_REC |
| 87 FILE *yuv_rec_file; | 87 FILE *yuv_rec_file; |
| 88 #endif | 88 #endif |
| 89 | 89 |
| 90 #if 0 | 90 #if 0 |
| 91 FILE *framepsnr; | 91 FILE *framepsnr; |
| 92 FILE *kf_list; | 92 FILE *kf_list; |
| 93 FILE *keyfile; | 93 FILE *keyfile; |
| 94 #endif | 94 #endif |
| 95 | 95 |
| 96 #ifdef SPEEDSTATS | 96 void vp9_init_quantizer(VP9_COMP *cpi); |
| 97 unsigned int frames_at_speed[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 98 0, 0, 0}; | |
| 99 #endif | |
| 100 | |
| 101 #if defined(SECTIONBITS_OUTPUT) | |
| 102 extern unsigned __int64 Sectionbits[500]; | |
| 103 #endif | |
| 104 | |
| 105 extern void vp9_init_quantizer(VP9_COMP *cpi); | |
| 106 | 97 |
| 107 static const double in_frame_q_adj_ratio[MAX_SEGMENTS] = | 98 static const double in_frame_q_adj_ratio[MAX_SEGMENTS] = |
| 108 {1.0, 1.5, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0}; | 99 {1.0, 2.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; |
| 109 | 100 |
| 110 static INLINE void Scale2Ratio(int mode, int *hr, int *hs) { | 101 static INLINE void Scale2Ratio(int mode, int *hr, int *hs) { |
| 111 switch (mode) { | 102 switch (mode) { |
| 112 case NORMAL: | 103 case NORMAL: |
| 113 *hr = 1; | 104 *hr = 1; |
| 114 *hs = 1; | 105 *hs = 1; |
| 115 break; | 106 break; |
| 116 case FOURFIVE: | 107 case FOURFIVE: |
| 117 *hr = 4; | 108 *hr = 4; |
| 118 *hs = 5; | 109 *hs = 5; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 260 |
| 270 if (cm->frame_type == KEY_FRAME || | 261 if (cm->frame_type == KEY_FRAME || |
| 271 cpi->refresh_alt_ref_frame || | 262 cpi->refresh_alt_ref_frame || |
| 272 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { | 263 (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref)) { |
| 273 // Clear down the segment map | 264 // Clear down the segment map |
| 274 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); | 265 vpx_memset(cpi->segmentation_map, 0, cm->mi_rows * cm->mi_cols); |
| 275 | 266 |
| 276 // Clear down the complexity map used for rd | 267 // Clear down the complexity map used for rd |
| 277 vpx_memset(cpi->complexity_map, 0, cm->mi_rows * cm->mi_cols); | 268 vpx_memset(cpi->complexity_map, 0, cm->mi_rows * cm->mi_cols); |
| 278 | 269 |
| 279 // Enable segmentation | |
| 280 vp9_enable_segmentation((VP9_PTR)cpi); | 270 vp9_enable_segmentation((VP9_PTR)cpi); |
| 281 vp9_clearall_segfeatures(seg); | 271 vp9_clearall_segfeatures(seg); |
| 282 | 272 |
| 283 // Select delta coding method | 273 // Select delta coding method |
| 284 seg->abs_delta = SEGMENT_DELTADATA; | 274 seg->abs_delta = SEGMENT_DELTADATA; |
| 285 | 275 |
| 286 // Segment 0 "Q" feature is disabled so it defaults to the baseline Q | 276 // Segment 0 "Q" feature is disabled so it defaults to the baseline Q |
| 287 vp9_disable_segfeature(seg, 0, SEG_LVL_ALT_Q); | 277 vp9_disable_segfeature(seg, 0, SEG_LVL_ALT_Q); |
| 288 | 278 |
| 289 // Use some of the segments for in frame Q adjustment | 279 // Use some of the segments for in frame Q adjustment |
| 290 for (segment = 1; segment < 3; segment++) { | 280 for (segment = 1; segment < 2; segment++) { |
| 291 qindex_delta = | 281 qindex_delta = |
| 292 vp9_compute_qdelta_by_rate(cpi, cm->base_qindex, | 282 vp9_compute_qdelta_by_rate(cpi, cm->base_qindex, |
| 293 in_frame_q_adj_ratio[segment]); | 283 in_frame_q_adj_ratio[segment]); |
| 294 vp9_enable_segfeature(seg, segment, SEG_LVL_ALT_Q); | 284 vp9_enable_segfeature(seg, segment, SEG_LVL_ALT_Q); |
| 295 vp9_set_segdata(seg, segment, SEG_LVL_ALT_Q, qindex_delta); | 285 vp9_set_segdata(seg, segment, SEG_LVL_ALT_Q, qindex_delta); |
| 296 } | 286 } |
| 297 } | 287 } |
| 298 } | 288 } |
| 299 static void configure_static_seg_features(VP9_COMP *cpi) { | 289 static void configure_static_seg_features(VP9_COMP *cpi) { |
| 300 VP9_COMMON *cm = &cpi->common; | 290 VP9_COMMON *cm = &cpi->common; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 | 438 |
| 449 for (row = 0; row < cm->mi_rows; row++) { | 439 for (row = 0; row < cm->mi_rows; row++) { |
| 450 mi_8x8 = mi_8x8_ptr; | 440 mi_8x8 = mi_8x8_ptr; |
| 451 cache = cache_ptr; | 441 cache = cache_ptr; |
| 452 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) | 442 for (col = 0; col < cm->mi_cols; col++, mi_8x8++, cache++) |
| 453 cache[0] = mi_8x8[0]->mbmi.segment_id; | 443 cache[0] = mi_8x8[0]->mbmi.segment_id; |
| 454 mi_8x8_ptr += cm->mode_info_stride; | 444 mi_8x8_ptr += cm->mode_info_stride; |
| 455 cache_ptr += cm->mi_cols; | 445 cache_ptr += cm->mi_cols; |
| 456 } | 446 } |
| 457 } | 447 } |
| 448 static int is_slowest_mode(int mode) { |
| 449 return (mode == MODE_SECONDPASS_BEST || mode == MODE_BESTQUALITY); |
| 450 } |
| 458 | 451 |
| 459 static void set_rd_speed_thresholds(VP9_COMP *cpi, int mode) { | 452 static void set_rd_speed_thresholds(VP9_COMP *cpi) { |
| 460 SPEED_FEATURES *sf = &cpi->sf; | 453 SPEED_FEATURES *sf = &cpi->sf; |
| 461 int i; | 454 int i; |
| 462 | 455 |
| 463 // Set baseline threshold values | 456 // Set baseline threshold values |
| 464 for (i = 0; i < MAX_MODES; ++i) | 457 for (i = 0; i < MAX_MODES; ++i) |
| 465 sf->thresh_mult[i] = mode == 0 ? -500 : 0; | 458 sf->thresh_mult[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; |
| 466 | 459 |
| 467 sf->thresh_mult[THR_NEARESTMV] = 0; | 460 sf->thresh_mult[THR_NEARESTMV] = 0; |
| 468 sf->thresh_mult[THR_NEARESTG] = 0; | 461 sf->thresh_mult[THR_NEARESTG] = 0; |
| 469 sf->thresh_mult[THR_NEARESTA] = 0; | 462 sf->thresh_mult[THR_NEARESTA] = 0; |
| 470 | 463 |
| 471 sf->thresh_mult[THR_DC] += 1000; | 464 sf->thresh_mult[THR_DC] += 1000; |
| 472 | 465 |
| 473 sf->thresh_mult[THR_NEWMV] += 1000; | 466 sf->thresh_mult[THR_NEWMV] += 1000; |
| 474 sf->thresh_mult[THR_NEWA] += 1000; | 467 sf->thresh_mult[THR_NEWA] += 1000; |
| 475 sf->thresh_mult[THR_NEWG] += 1000; | 468 sf->thresh_mult[THR_NEWG] += 1000; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 } | 524 } |
| 532 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != | 525 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != |
| 533 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) { | 526 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) { |
| 534 sf->thresh_mult[THR_COMP_ZEROGA ] = INT_MAX; | 527 sf->thresh_mult[THR_COMP_ZEROGA ] = INT_MAX; |
| 535 sf->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX; | 528 sf->thresh_mult[THR_COMP_NEARESTGA] = INT_MAX; |
| 536 sf->thresh_mult[THR_COMP_NEARGA ] = INT_MAX; | 529 sf->thresh_mult[THR_COMP_NEARGA ] = INT_MAX; |
| 537 sf->thresh_mult[THR_COMP_NEWGA ] = INT_MAX; | 530 sf->thresh_mult[THR_COMP_NEWGA ] = INT_MAX; |
| 538 } | 531 } |
| 539 } | 532 } |
| 540 | 533 |
| 541 static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi, int mode) { | 534 static void set_rd_speed_thresholds_sub8x8(VP9_COMP *cpi) { |
| 542 SPEED_FEATURES *sf = &cpi->sf; | 535 SPEED_FEATURES *sf = &cpi->sf; |
| 543 int i; | 536 int i; |
| 544 | 537 |
| 545 for (i = 0; i < MAX_REFS; ++i) | 538 for (i = 0; i < MAX_REFS; ++i) |
| 546 sf->thresh_mult_sub8x8[i] = mode == 0 ? -500 : 0; | 539 sf->thresh_mult_sub8x8[i] = is_slowest_mode(cpi->oxcf.mode) ? -500 : 0; |
| 547 | 540 |
| 548 sf->thresh_mult_sub8x8[THR_LAST] += 2500; | 541 sf->thresh_mult_sub8x8[THR_LAST] += 2500; |
| 549 sf->thresh_mult_sub8x8[THR_GOLD] += 2500; | 542 sf->thresh_mult_sub8x8[THR_GOLD] += 2500; |
| 550 sf->thresh_mult_sub8x8[THR_ALTR] += 2500; | 543 sf->thresh_mult_sub8x8[THR_ALTR] += 2500; |
| 551 sf->thresh_mult_sub8x8[THR_INTRA] += 2500; | 544 sf->thresh_mult_sub8x8[THR_INTRA] += 2500; |
| 552 sf->thresh_mult_sub8x8[THR_COMP_LA] += 4500; | 545 sf->thresh_mult_sub8x8[THR_COMP_LA] += 4500; |
| 553 sf->thresh_mult_sub8x8[THR_COMP_GA] += 4500; | 546 sf->thresh_mult_sub8x8[THR_COMP_GA] += 4500; |
| 554 | 547 |
| 555 // Check for masked out split cases. | 548 // Check for masked out split cases. |
| 556 for (i = 0; i < MAX_REFS; i++) { | 549 for (i = 0; i < MAX_REFS; i++) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 571 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != | 564 if ((cpi->ref_frame_flags & (VP9_GOLD_FLAG | VP9_ALT_FLAG)) != |
| 572 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) | 565 (VP9_GOLD_FLAG | VP9_ALT_FLAG)) |
| 573 sf->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX; | 566 sf->thresh_mult_sub8x8[THR_COMP_GA] = INT_MAX; |
| 574 } | 567 } |
| 575 | 568 |
| 576 static void set_good_speed_feature(VP9_COMMON *cm, | 569 static void set_good_speed_feature(VP9_COMMON *cm, |
| 577 SPEED_FEATURES *sf, | 570 SPEED_FEATURES *sf, |
| 578 int speed) { | 571 int speed) { |
| 579 int i; | 572 int i; |
| 580 sf->adaptive_rd_thresh = 1; | 573 sf->adaptive_rd_thresh = 1; |
| 581 sf->recode_loop = (speed < 1); | 574 sf->recode_loop = ((speed < 1) ? ALLOW_RECODE : ALLOW_RECODE_KFMAXBW); |
| 582 if (speed == 1) { | 575 if (speed == 1) { |
| 583 sf->use_square_partition_only = !frame_is_intra_only(cm); | 576 sf->use_square_partition_only = !frame_is_intra_only(cm); |
| 584 sf->less_rectangular_check = 1; | 577 sf->less_rectangular_check = 1; |
| 585 sf->tx_size_search_method = frame_is_intra_only(cm) | 578 sf->tx_size_search_method = frame_is_intra_only(cm) |
| 586 ? USE_FULL_RD : USE_LARGESTALL; | 579 ? USE_FULL_RD : USE_LARGESTALL; |
| 587 | 580 |
| 588 if (MIN(cm->width, cm->height) >= 720) | 581 if (MIN(cm->width, cm->height) >= 720) |
| 589 sf->disable_split_mask = cm->show_frame ? | 582 sf->disable_split_mask = cm->show_frame ? |
| 590 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; | 583 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; |
| 591 else | 584 else |
| 592 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT; | 585 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT; |
| 593 | 586 |
| 594 sf->use_rd_breakout = 1; | 587 sf->use_rd_breakout = 1; |
| 595 sf->adaptive_motion_search = 1; | 588 sf->adaptive_motion_search = 1; |
| 596 sf->adaptive_pred_interp_filter = 1; | 589 sf->adaptive_pred_interp_filter = 1; |
| 597 sf->auto_mv_step_size = 1; | 590 sf->auto_mv_step_size = 1; |
| 598 sf->adaptive_rd_thresh = 2; | 591 sf->adaptive_rd_thresh = 2; |
| 599 sf->recode_loop = 2; | 592 sf->recode_loop = ALLOW_RECODE_KFARFGF; |
| 600 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; | 593 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 601 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; | 594 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 602 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; | 595 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 603 } | 596 } |
| 604 if (speed == 2) { | 597 if (speed == 2) { |
| 605 sf->use_square_partition_only = !frame_is_intra_only(cm); | 598 sf->use_square_partition_only = !frame_is_intra_only(cm); |
| 606 sf->less_rectangular_check = 1; | 599 sf->less_rectangular_check = 1; |
| 607 sf->tx_size_search_method = frame_is_intra_only(cm) | 600 sf->tx_size_search_method = frame_is_intra_only(cm) |
| 608 ? USE_FULL_RD : USE_LARGESTALL; | 601 ? USE_FULL_RD : USE_LARGESTALL; |
| 609 | 602 |
| 610 if (MIN(cm->width, cm->height) >= 720) | 603 if (MIN(cm->width, cm->height) >= 720) |
| 611 sf->disable_split_mask = cm->show_frame ? | 604 sf->disable_split_mask = cm->show_frame ? |
| 612 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; | 605 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; |
| 613 else | 606 else |
| 614 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY; | 607 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY; |
| 615 | 608 |
| 616 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | | 609 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | |
| 617 FLAG_SKIP_INTRA_BESTINTER | | 610 FLAG_SKIP_INTRA_BESTINTER | |
| 618 FLAG_SKIP_COMP_BESTINTRA | | 611 FLAG_SKIP_COMP_BESTINTRA | |
| 619 FLAG_SKIP_INTRA_LOWVAR; | 612 FLAG_SKIP_INTRA_LOWVAR; |
| 620 sf->use_rd_breakout = 1; | 613 sf->use_rd_breakout = 1; |
| 621 sf->adaptive_motion_search = 1; | 614 sf->adaptive_motion_search = 1; |
| 622 sf->adaptive_pred_interp_filter = 2; | 615 sf->adaptive_pred_interp_filter = 2; |
| 623 sf->reference_masking = 1; | 616 sf->reference_masking = 1; |
| 624 sf->auto_mv_step_size = 1; | 617 sf->auto_mv_step_size = 1; |
| 625 | 618 |
| 626 sf->disable_filter_search_var_thresh = 50; | 619 sf->disable_filter_search_var_thresh = 50; |
| 627 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | 620 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; |
| 628 | 621 |
| 629 sf->auto_min_max_partition_size = 1; | 622 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; |
| 630 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION; | 623 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION; |
| 631 sf->adjust_partitioning_from_last_frame = 1; | 624 sf->adjust_partitioning_from_last_frame = 1; |
| 632 sf->last_partitioning_redo_frequency = 3; | 625 sf->last_partitioning_redo_frequency = 3; |
| 633 | 626 |
| 634 sf->adaptive_rd_thresh = 2; | 627 sf->adaptive_rd_thresh = 2; |
| 635 sf->recode_loop = 2; | 628 sf->recode_loop = ALLOW_RECODE_KFARFGF; |
| 636 sf->use_lp32x32fdct = 1; | 629 sf->use_lp32x32fdct = 1; |
| 637 sf->mode_skip_start = 11; | 630 sf->mode_skip_start = 11; |
| 638 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; | 631 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 639 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; | 632 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 640 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; | 633 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 641 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; | 634 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 642 } | 635 } |
| 643 if (speed == 3) { | 636 if (speed == 3) { |
| 644 sf->use_square_partition_only = 1; | 637 sf->use_square_partition_only = 1; |
| 645 sf->tx_size_search_method = USE_LARGESTALL; | 638 sf->tx_size_search_method = USE_LARGESTALL; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 656 | 649 |
| 657 sf->use_rd_breakout = 1; | 650 sf->use_rd_breakout = 1; |
| 658 sf->adaptive_motion_search = 1; | 651 sf->adaptive_motion_search = 1; |
| 659 sf->adaptive_pred_interp_filter = 2; | 652 sf->adaptive_pred_interp_filter = 2; |
| 660 sf->reference_masking = 1; | 653 sf->reference_masking = 1; |
| 661 sf->auto_mv_step_size = 1; | 654 sf->auto_mv_step_size = 1; |
| 662 | 655 |
| 663 sf->disable_filter_search_var_thresh = 100; | 656 sf->disable_filter_search_var_thresh = 100; |
| 664 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | 657 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; |
| 665 | 658 |
| 666 sf->auto_min_max_partition_size = 1; | 659 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; |
| 667 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; | 660 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; |
| 668 sf->adjust_partitioning_from_last_frame = 1; | 661 sf->adjust_partitioning_from_last_frame = 1; |
| 669 sf->last_partitioning_redo_frequency = 3; | 662 sf->last_partitioning_redo_frequency = 3; |
| 670 | 663 |
| 671 sf->use_uv_intra_rd_estimate = 1; | 664 sf->use_uv_intra_rd_estimate = 1; |
| 672 sf->skip_encode_sb = 1; | 665 sf->skip_encode_sb = 1; |
| 673 sf->use_lp32x32fdct = 1; | 666 sf->use_lp32x32fdct = 1; |
| 674 sf->subpel_iters_per_step = 1; | 667 sf->subpel_iters_per_step = 1; |
| 675 sf->use_fast_coef_updates = 2; | 668 sf->use_fast_coef_updates = 2; |
| 676 | 669 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 691 | 684 |
| 692 sf->use_rd_breakout = 1; | 685 sf->use_rd_breakout = 1; |
| 693 sf->adaptive_motion_search = 1; | 686 sf->adaptive_motion_search = 1; |
| 694 sf->adaptive_pred_interp_filter = 2; | 687 sf->adaptive_pred_interp_filter = 2; |
| 695 sf->reference_masking = 1; | 688 sf->reference_masking = 1; |
| 696 sf->auto_mv_step_size = 1; | 689 sf->auto_mv_step_size = 1; |
| 697 | 690 |
| 698 sf->disable_filter_search_var_thresh = 200; | 691 sf->disable_filter_search_var_thresh = 200; |
| 699 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | 692 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; |
| 700 | 693 |
| 701 sf->auto_min_max_partition_size = 1; | 694 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; |
| 702 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; | 695 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; |
| 703 sf->adjust_partitioning_from_last_frame = 1; | 696 sf->adjust_partitioning_from_last_frame = 1; |
| 704 sf->last_partitioning_redo_frequency = 3; | 697 sf->last_partitioning_redo_frequency = 3; |
| 705 | 698 |
| 706 sf->use_uv_intra_rd_estimate = 1; | 699 sf->use_uv_intra_rd_estimate = 1; |
| 707 sf->skip_encode_sb = 1; | 700 sf->skip_encode_sb = 1; |
| 708 sf->use_lp32x32fdct = 1; | 701 sf->use_lp32x32fdct = 1; |
| 709 sf->subpel_iters_per_step = 1; | 702 sf->subpel_iters_per_step = 1; |
| 710 sf->use_fast_coef_updates = 2; | 703 sf->use_fast_coef_updates = 2; |
| 711 | 704 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 742 sf->use_fast_coef_updates = 2; | 735 sf->use_fast_coef_updates = 2; |
| 743 sf->adaptive_rd_thresh = 4; | 736 sf->adaptive_rd_thresh = 4; |
| 744 sf->mode_skip_start = 6; | 737 sf->mode_skip_start = 6; |
| 745 } | 738 } |
| 746 } | 739 } |
| 747 static void set_rt_speed_feature(VP9_COMMON *cm, | 740 static void set_rt_speed_feature(VP9_COMMON *cm, |
| 748 SPEED_FEATURES *sf, | 741 SPEED_FEATURES *sf, |
| 749 int speed) { | 742 int speed) { |
| 750 sf->static_segmentation = 0; | 743 sf->static_segmentation = 0; |
| 751 sf->adaptive_rd_thresh = 1; | 744 sf->adaptive_rd_thresh = 1; |
| 752 sf->recode_loop = (speed < 1); | 745 sf->recode_loop = ((speed < 1) ? ALLOW_RECODE : ALLOW_RECODE_KFMAXBW); |
| 746 sf->encode_breakout_thresh = 1; |
| 747 |
| 753 if (speed == 1) { | 748 if (speed == 1) { |
| 754 sf->use_square_partition_only = !frame_is_intra_only(cm); | 749 sf->use_square_partition_only = !frame_is_intra_only(cm); |
| 755 sf->less_rectangular_check = 1; | 750 sf->less_rectangular_check = 1; |
| 756 sf->tx_size_search_method = | 751 sf->tx_size_search_method = |
| 757 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL; | 752 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL; |
| 758 | 753 |
| 759 if (MIN(cm->width, cm->height) >= 720) | 754 if (MIN(cm->width, cm->height) >= 720) |
| 760 sf->disable_split_mask = cm->show_frame ? | 755 sf->disable_split_mask = cm->show_frame ? |
| 761 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; | 756 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; |
| 762 else | 757 else |
| 763 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT; | 758 sf->disable_split_mask = DISABLE_COMPOUND_SPLIT; |
| 764 | 759 |
| 765 sf->use_rd_breakout = 1; | 760 sf->use_rd_breakout = 1; |
| 766 sf->adaptive_motion_search = 1; | 761 sf->adaptive_motion_search = 1; |
| 767 sf->adaptive_pred_interp_filter = 1; | 762 sf->adaptive_pred_interp_filter = 1; |
| 768 sf->auto_mv_step_size = 1; | 763 sf->auto_mv_step_size = 1; |
| 769 sf->adaptive_rd_thresh = 2; | 764 sf->adaptive_rd_thresh = 2; |
| 770 sf->recode_loop = 2; | 765 sf->recode_loop = ALLOW_RECODE_KFARFGF; |
| 771 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; | 766 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 772 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; | 767 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 773 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; | 768 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 769 sf->encode_breakout_thresh = 8; |
| 774 } | 770 } |
| 775 if (speed >= 2) { | 771 if (speed >= 2) { |
| 776 sf->use_square_partition_only = !frame_is_intra_only(cm); | 772 sf->use_square_partition_only = !frame_is_intra_only(cm); |
| 777 sf->less_rectangular_check = 1; | 773 sf->less_rectangular_check = 1; |
| 778 sf->tx_size_search_method = | 774 sf->tx_size_search_method = |
| 779 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL; | 775 frame_is_intra_only(cm) ? USE_FULL_RD : USE_LARGESTALL; |
| 780 | 776 |
| 781 if (MIN(cm->width, cm->height) >= 720) | 777 if (MIN(cm->width, cm->height) >= 720) |
| 782 sf->disable_split_mask = cm->show_frame ? | 778 sf->disable_split_mask = cm->show_frame ? |
| 783 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; | 779 DISABLE_ALL_SPLIT : DISABLE_ALL_INTER_SPLIT; |
| 784 else | 780 else |
| 785 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY; | 781 sf->disable_split_mask = LAST_AND_INTRA_SPLIT_ONLY; |
| 786 | 782 |
| 787 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | 783 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH |
| 788 | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA | 784 | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA |
| 789 | FLAG_SKIP_INTRA_LOWVAR; | 785 | FLAG_SKIP_INTRA_LOWVAR; |
| 790 | 786 |
| 791 sf->use_rd_breakout = 1; | 787 sf->use_rd_breakout = 1; |
| 792 sf->adaptive_motion_search = 1; | 788 sf->adaptive_motion_search = 1; |
| 793 sf->adaptive_pred_interp_filter = 2; | 789 sf->adaptive_pred_interp_filter = 2; |
| 794 sf->auto_mv_step_size = 1; | 790 sf->auto_mv_step_size = 1; |
| 795 sf->reference_masking = 1; | 791 sf->reference_masking = 1; |
| 796 | 792 |
| 797 sf->disable_filter_search_var_thresh = 50; | 793 sf->disable_filter_search_var_thresh = 50; |
| 798 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; | 794 sf->comp_inter_joint_search_thresh = BLOCK_SIZES; |
| 799 | 795 |
| 800 sf->auto_min_max_partition_size = 1; | 796 sf->auto_min_max_partition_size = RELAXED_NEIGHBORING_MIN_MAX; |
| 801 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION; | 797 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_LOW_MOTION; |
| 802 sf->adjust_partitioning_from_last_frame = 1; | 798 sf->adjust_partitioning_from_last_frame = 1; |
| 803 sf->last_partitioning_redo_frequency = 3; | 799 sf->last_partitioning_redo_frequency = 3; |
| 804 | 800 |
| 805 sf->adaptive_rd_thresh = 2; | 801 sf->adaptive_rd_thresh = 2; |
| 806 sf->recode_loop = 2; | 802 sf->recode_loop = ALLOW_RECODE_KFARFGF; |
| 807 sf->use_lp32x32fdct = 1; | 803 sf->use_lp32x32fdct = 1; |
| 808 sf->mode_skip_start = 11; | 804 sf->mode_skip_start = 11; |
| 809 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; | 805 sf->intra_y_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 810 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; | 806 sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 811 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; | 807 sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V; |
| 812 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; | 808 sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V; |
| 809 sf->encode_breakout_thresh = 200; |
| 813 } | 810 } |
| 814 if (speed >= 3) { | 811 if (speed >= 3) { |
| 815 sf->use_square_partition_only = 1; | 812 sf->use_square_partition_only = 1; |
| 816 sf->tx_size_search_method = USE_LARGESTALL; | 813 sf->tx_size_search_method = USE_LARGESTALL; |
| 817 | 814 |
| 818 if (MIN(cm->width, cm->height) >= 720) | 815 if (MIN(cm->width, cm->height) >= 720) |
| 819 sf->disable_split_mask = DISABLE_ALL_SPLIT; | 816 sf->disable_split_mask = DISABLE_ALL_SPLIT; |
| 820 else | 817 else |
| 821 sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT; | 818 sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT; |
| 822 | 819 |
| 823 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH | 820 sf->mode_search_skip_flags = FLAG_SKIP_INTRA_DIRMISMATCH |
| 824 | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA | 821 | FLAG_SKIP_INTRA_BESTINTER | FLAG_SKIP_COMP_BESTINTRA |
| 825 | FLAG_SKIP_INTRA_LOWVAR; | 822 | FLAG_SKIP_INTRA_LOWVAR; |
| 826 | 823 |
| 827 sf->disable_filter_search_var_thresh = 100; | 824 sf->disable_filter_search_var_thresh = 100; |
| 828 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; | 825 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_ALL; |
| 829 sf->use_uv_intra_rd_estimate = 1; | 826 sf->use_uv_intra_rd_estimate = 1; |
| 830 sf->skip_encode_sb = 1; | 827 sf->skip_encode_sb = 1; |
| 831 sf->subpel_iters_per_step = 1; | 828 sf->subpel_iters_per_step = 1; |
| 832 sf->use_fast_coef_updates = 2; | 829 sf->use_fast_coef_updates = 2; |
| 833 sf->adaptive_rd_thresh = 4; | 830 sf->adaptive_rd_thresh = 4; |
| 834 sf->mode_skip_start = 6; | 831 sf->mode_skip_start = 6; |
| 832 sf->encode_breakout_thresh = 400; |
| 835 } | 833 } |
| 836 if (speed >= 4) { | 834 if (speed >= 4) { |
| 837 sf->optimize_coefficients = 0; | 835 sf->optimize_coefficients = 0; |
| 836 sf->disable_split_mask = DISABLE_ALL_SPLIT; |
| 837 sf->use_fast_lpf_pick = 2; |
| 838 sf->encode_breakout_thresh = 700; |
| 838 } | 839 } |
| 839 if (speed >= 5) { | 840 if (speed >= 5) { |
| 840 int i; | 841 int i; |
| 841 sf->disable_split_mask = DISABLE_ALL_SPLIT; | 842 sf->adaptive_rd_thresh = 5; |
| 843 sf->auto_min_max_partition_size = frame_is_intra_only(cm) ? |
| 844 RELAXED_NEIGHBORING_MIN_MAX : STRICT_NEIGHBORING_MIN_MAX; |
| 842 sf->subpel_force_stop = 1; | 845 sf->subpel_force_stop = 1; |
| 843 for (i = 0; i < TX_SIZES; i++) { | 846 for (i = 0; i < TX_SIZES; i++) { |
| 844 sf->intra_y_mode_mask[i] = INTRA_DC_H_V; | 847 sf->intra_y_mode_mask[i] = INTRA_DC_H_V; |
| 845 sf->intra_uv_mode_mask[i] = INTRA_DC_ONLY; | 848 sf->intra_uv_mode_mask[i] = INTRA_DC_ONLY; |
| 846 } | 849 } |
| 847 sf->use_fast_lpf_pick = 2; | 850 sf->frame_parameter_update = 0; |
| 851 sf->encode_breakout_thresh = 1000; |
| 852 } |
| 853 if (speed >= 6) { |
| 854 sf->always_this_block_size = BLOCK_16X16; |
| 855 sf->use_pick_mode = 1; |
| 856 sf->encode_breakout_thresh = 1000; |
| 848 } | 857 } |
| 849 } | 858 } |
| 850 | 859 |
| 851 void vp9_set_speed_features(VP9_COMP *cpi) { | 860 void vp9_set_speed_features(VP9_COMP *cpi) { |
| 852 SPEED_FEATURES *sf = &cpi->sf; | 861 SPEED_FEATURES *sf = &cpi->sf; |
| 853 VP9_COMMON *cm = &cpi->common; | 862 VP9_COMMON *cm = &cpi->common; |
| 854 int mode = cpi->compressor_speed; | |
| 855 int speed = cpi->speed; | 863 int speed = cpi->speed; |
| 856 int i; | 864 int i; |
| 857 | 865 |
| 858 // Convert negative speed to positive | 866 // Convert negative speed to positive |
| 859 if (speed < 0) | 867 if (speed < 0) |
| 860 speed = -speed; | 868 speed = -speed; |
| 861 | 869 |
| 862 for (i = 0; i < MAX_MODES; ++i) | 870 for (i = 0; i < MAX_MODES; ++i) |
| 863 cpi->mode_chosen_counts[i] = 0; | 871 cpi->mode_chosen_counts[i] = 0; |
| 864 | 872 |
| 865 // best quality defaults | 873 // best quality defaults |
| 866 sf->RD = 1; | 874 sf->frame_parameter_update = 1; |
| 867 sf->search_method = NSTEP; | 875 sf->search_method = NSTEP; |
| 868 sf->recode_loop = 1; | 876 sf->recode_loop = ALLOW_RECODE; |
| 869 sf->subpel_search_method = SUBPEL_TREE; | 877 sf->subpel_search_method = SUBPEL_TREE; |
| 870 sf->subpel_iters_per_step = 2; | 878 sf->subpel_iters_per_step = 2; |
| 871 sf->subpel_force_stop = 0; | 879 sf->subpel_force_stop = 0; |
| 872 sf->optimize_coefficients = !cpi->oxcf.lossless; | 880 sf->optimize_coefficients = !cpi->oxcf.lossless; |
| 873 sf->reduce_first_step_size = 0; | 881 sf->reduce_first_step_size = 0; |
| 874 sf->auto_mv_step_size = 0; | 882 sf->auto_mv_step_size = 0; |
| 875 sf->max_step_search_steps = MAX_MVSEARCH_STEPS; | 883 sf->max_step_search_steps = MAX_MVSEARCH_STEPS; |
| 876 sf->comp_inter_joint_search_thresh = BLOCK_4X4; | 884 sf->comp_inter_joint_search_thresh = BLOCK_4X4; |
| 877 sf->adaptive_rd_thresh = 0; | 885 sf->adaptive_rd_thresh = 0; |
| 878 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_OFF; | 886 sf->use_lastframe_partitioning = LAST_FRAME_PARTITION_OFF; |
| 879 sf->tx_size_search_method = USE_FULL_RD; | 887 sf->tx_size_search_method = USE_FULL_RD; |
| 880 sf->use_lp32x32fdct = 0; | 888 sf->use_lp32x32fdct = 0; |
| 881 sf->adaptive_motion_search = 0; | 889 sf->adaptive_motion_search = 0; |
| 882 sf->adaptive_pred_interp_filter = 0; | 890 sf->adaptive_pred_interp_filter = 0; |
| 883 sf->reference_masking = 0; | 891 sf->reference_masking = 0; |
| 884 sf->use_one_partition_size_always = 0; | 892 sf->use_one_partition_size_always = 0; |
| 885 sf->less_rectangular_check = 0; | 893 sf->less_rectangular_check = 0; |
| 886 sf->use_square_partition_only = 0; | 894 sf->use_square_partition_only = 0; |
| 887 sf->auto_min_max_partition_size = 0; | 895 sf->auto_min_max_partition_size = NOT_IN_USE; |
| 888 sf->max_partition_size = BLOCK_64X64; | 896 sf->max_partition_size = BLOCK_64X64; |
| 889 sf->min_partition_size = BLOCK_4X4; | 897 sf->min_partition_size = BLOCK_4X4; |
| 890 sf->adjust_partitioning_from_last_frame = 0; | 898 sf->adjust_partitioning_from_last_frame = 0; |
| 891 sf->last_partitioning_redo_frequency = 4; | 899 sf->last_partitioning_redo_frequency = 4; |
| 892 sf->disable_split_mask = 0; | 900 sf->disable_split_mask = 0; |
| 893 sf->mode_search_skip_flags = 0; | 901 sf->mode_search_skip_flags = 0; |
| 894 sf->disable_split_var_thresh = 0; | 902 sf->disable_split_var_thresh = 0; |
| 895 sf->disable_filter_search_var_thresh = 0; | 903 sf->disable_filter_search_var_thresh = 0; |
| 896 for (i = 0; i < TX_SIZES; i++) { | 904 for (i = 0; i < TX_SIZES; i++) { |
| 897 sf->intra_y_mode_mask[i] = ALL_INTRA_MODES; | 905 sf->intra_y_mode_mask[i] = ALL_INTRA_MODES; |
| 898 sf->intra_uv_mode_mask[i] = ALL_INTRA_MODES; | 906 sf->intra_uv_mode_mask[i] = ALL_INTRA_MODES; |
| 899 } | 907 } |
| 900 sf->use_rd_breakout = 0; | 908 sf->use_rd_breakout = 0; |
| 901 sf->skip_encode_sb = 0; | 909 sf->skip_encode_sb = 0; |
| 902 sf->use_uv_intra_rd_estimate = 0; | 910 sf->use_uv_intra_rd_estimate = 0; |
| 903 sf->use_fast_lpf_pick = 0; | 911 sf->use_fast_lpf_pick = 0; |
| 904 sf->use_fast_coef_updates = 0; | 912 sf->use_fast_coef_updates = 0; |
| 905 sf->using_small_partition_info = 0; | |
| 906 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set | 913 sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set |
| 914 sf->use_pick_mode = 0; |
| 915 sf->encode_breakout_thresh = 0; |
| 907 | 916 |
| 908 switch (mode) { | 917 switch (cpi->oxcf.mode) { |
| 909 case 0: // This is the best quality mode. | 918 case MODE_BESTQUALITY: |
| 919 case MODE_SECONDPASS_BEST: // This is the best quality mode. |
| 910 cpi->diamond_search_sad = vp9_full_range_search; | 920 cpi->diamond_search_sad = vp9_full_range_search; |
| 911 break; | 921 break; |
| 912 case 1: | 922 case MODE_FIRSTPASS: |
| 923 case MODE_GOODQUALITY: |
| 924 case MODE_SECONDPASS: |
| 913 set_good_speed_feature(cm, sf, speed); | 925 set_good_speed_feature(cm, sf, speed); |
| 914 break; | 926 break; |
| 915 break; | 927 case MODE_REALTIME: |
| 916 case 2: | |
| 917 set_rt_speed_feature(cm, sf, speed); | 928 set_rt_speed_feature(cm, sf, speed); |
| 918 break; | 929 break; |
| 919 }; /* switch */ | 930 }; /* switch */ |
| 920 | 931 |
| 921 // Set rd thresholds based on mode and speed setting | 932 // Set rd thresholds based on mode and speed setting |
| 922 set_rd_speed_thresholds(cpi, mode); | 933 set_rd_speed_thresholds(cpi); |
| 923 set_rd_speed_thresholds_sub8x8(cpi, mode); | 934 set_rd_speed_thresholds_sub8x8(cpi); |
| 924 | 935 |
| 925 // Slow quant, dct and trellis not worthwhile for first pass | 936 // Slow quant, dct and trellis not worthwhile for first pass |
| 926 // so make sure they are always turned off. | 937 // so make sure they are always turned off. |
| 927 if (cpi->pass == 1) { | 938 if (cpi->pass == 1) { |
| 928 sf->optimize_coefficients = 0; | 939 sf->optimize_coefficients = 0; |
| 929 } | 940 } |
| 930 | 941 |
| 931 // No recode for 1 pass. | 942 // No recode for 1 pass. |
| 932 if (cpi->pass == 0) { | 943 if (cpi->pass == 0) { |
| 933 sf->recode_loop = 0; | 944 sf->recode_loop = DISALLOW_RECODE; |
| 934 sf->optimize_coefficients = 0; | 945 sf->optimize_coefficients = 0; |
| 935 } | 946 } |
| 936 | 947 |
| 937 cpi->mb.fwd_txm4x4 = vp9_fdct4x4; | 948 cpi->mb.fwd_txm4x4 = vp9_fdct4x4; |
| 938 if (cpi->oxcf.lossless || cpi->mb.e_mbd.lossless) { | 949 if (cpi->oxcf.lossless || cpi->mb.e_mbd.lossless) { |
| 939 cpi->mb.fwd_txm4x4 = vp9_fwht4x4; | 950 cpi->mb.fwd_txm4x4 = vp9_fwht4x4; |
| 940 } | 951 } |
| 941 | 952 |
| 942 if (cpi->sf.subpel_search_method == SUBPEL_TREE) { | 953 if (cpi->sf.subpel_search_method == SUBPEL_TREE) { |
| 943 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree; | 954 cpi->find_fractional_mv_step = vp9_find_best_sub_pixel_tree; |
| 944 cpi->find_fractional_mv_step_comp = vp9_find_best_sub_pixel_comp_tree; | 955 cpi->find_fractional_mv_step_comp = vp9_find_best_sub_pixel_comp_tree; |
| 945 } | 956 } |
| 946 | 957 |
| 947 cpi->mb.optimize = cpi->sf.optimize_coefficients == 1 && cpi->pass != 1; | 958 cpi->mb.optimize = cpi->sf.optimize_coefficients == 1 && cpi->pass != 1; |
| 948 | 959 |
| 949 #ifdef SPEEDSTATS | 960 if (cpi->encode_breakout && cpi->oxcf.mode == MODE_REALTIME && |
| 950 frames_at_speed[cpi->speed]++; | 961 sf->encode_breakout_thresh > cpi->encode_breakout) |
| 951 #endif | 962 cpi->encode_breakout = sf->encode_breakout_thresh; |
| 952 } | 963 } |
| 953 | 964 |
| 954 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { | 965 static void alloc_raw_frame_buffers(VP9_COMP *cpi) { |
| 955 VP9_COMMON *cm = &cpi->common; | 966 VP9_COMMON *cm = &cpi->common; |
| 956 | 967 |
| 957 cpi->lookahead = vp9_lookahead_init(cpi->oxcf.width, cpi->oxcf.height, | 968 cpi->lookahead = vp9_lookahead_init(cpi->oxcf.width, cpi->oxcf.height, |
| 958 cm->subsampling_x, cm->subsampling_y, | 969 cm->subsampling_x, cm->subsampling_y, |
| 959 cpi->oxcf.lag_in_frames); | 970 cpi->oxcf.lag_in_frames); |
| 960 if (!cpi->lookahead) | 971 if (!cpi->lookahead) |
| 961 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 972 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 962 "Failed to allocate lag buffers"); | 973 "Failed to allocate lag buffers"); |
| 963 | 974 |
| 964 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, | 975 if (vp9_realloc_frame_buffer(&cpi->alt_ref_buffer, |
| 965 cpi->oxcf.width, cpi->oxcf.height, | 976 cpi->oxcf.width, cpi->oxcf.height, |
| 966 cm->subsampling_x, cm->subsampling_y, | 977 cm->subsampling_x, cm->subsampling_y, |
| 967 VP9_ENC_BORDER_IN_PIXELS)) | 978 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
| 968 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 979 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 969 "Failed to allocate altref buffer"); | 980 "Failed to allocate altref buffer"); |
| 970 } | 981 } |
| 971 | 982 |
| 972 void vp9_alloc_compressor_data(VP9_COMP *cpi) { | 983 void vp9_alloc_compressor_data(VP9_COMP *cpi) { |
| 973 VP9_COMMON *cm = &cpi->common; | 984 VP9_COMMON *cm = &cpi->common; |
| 974 | 985 |
| 975 if (vp9_alloc_frame_buffers(cm, cm->width, cm->height)) | 986 if (vp9_alloc_frame_buffers(cm, cm->width, cm->height)) |
| 976 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 987 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 977 "Failed to allocate frame buffers"); | 988 "Failed to allocate frame buffers"); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1025 | 1036 |
| 1026 static void update_frame_size(VP9_COMP *cpi) { | 1037 static void update_frame_size(VP9_COMP *cpi) { |
| 1027 VP9_COMMON *cm = &cpi->common; | 1038 VP9_COMMON *cm = &cpi->common; |
| 1028 | 1039 |
| 1029 vp9_update_frame_size(cm); | 1040 vp9_update_frame_size(cm); |
| 1030 | 1041 |
| 1031 // Update size of buffers local to this frame | 1042 // Update size of buffers local to this frame |
| 1032 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, | 1043 if (vp9_realloc_frame_buffer(&cpi->last_frame_uf, |
| 1033 cm->width, cm->height, | 1044 cm->width, cm->height, |
| 1034 cm->subsampling_x, cm->subsampling_y, | 1045 cm->subsampling_x, cm->subsampling_y, |
| 1035 VP9_ENC_BORDER_IN_PIXELS)) | 1046 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
| 1036 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 1047 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 1037 "Failed to reallocate last frame buffer"); | 1048 "Failed to reallocate last frame buffer"); |
| 1038 | 1049 |
| 1039 if (vp9_realloc_frame_buffer(&cpi->scaled_source, | 1050 if (vp9_realloc_frame_buffer(&cpi->scaled_source, |
| 1040 cm->width, cm->height, | 1051 cm->width, cm->height, |
| 1041 cm->subsampling_x, cm->subsampling_y, | 1052 cm->subsampling_x, cm->subsampling_y, |
| 1042 VP9_ENC_BORDER_IN_PIXELS)) | 1053 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL)) |
| 1043 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 1054 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
| 1044 "Failed to reallocate scaled source buffer"); | 1055 "Failed to reallocate scaled source buffer"); |
| 1045 | 1056 |
| 1046 { | 1057 { |
| 1047 int y_stride = cpi->scaled_source.y_stride; | 1058 int y_stride = cpi->scaled_source.y_stride; |
| 1048 | 1059 |
| 1049 if (cpi->sf.search_method == NSTEP) { | 1060 if (cpi->sf.search_method == NSTEP) { |
| 1050 vp9_init3smotion_compensation(&cpi->mb, y_stride); | 1061 vp9_init3smotion_compensation(&cpi->mb, y_stride); |
| 1051 } else if (cpi->sf.search_method == DIAMOND) { | 1062 } else if (cpi->sf.search_method == DIAMOND) { |
| 1052 vp9_init_dsmotion_compensation(&cpi->mb, y_stride); | 1063 vp9_init_dsmotion_compensation(&cpi->mb, y_stride); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1089 | 1100 |
| 1090 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { | 1101 void vp9_new_framerate(VP9_COMP *cpi, double framerate) { |
| 1091 VP9_COMMON *const cm = &cpi->common; | 1102 VP9_COMMON *const cm = &cpi->common; |
| 1092 int64_t vbr_max_bits; | 1103 int64_t vbr_max_bits; |
| 1093 | 1104 |
| 1094 if (framerate < 0.1) | 1105 if (framerate < 0.1) |
| 1095 framerate = 30; | 1106 framerate = 30; |
| 1096 | 1107 |
| 1097 cpi->oxcf.framerate = framerate; | 1108 cpi->oxcf.framerate = framerate; |
| 1098 cpi->output_framerate = cpi->oxcf.framerate; | 1109 cpi->output_framerate = cpi->oxcf.framerate; |
| 1099 cpi->rc.per_frame_bandwidth = (int)(cpi->oxcf.target_bandwidth | |
| 1100 / cpi->output_framerate); | |
| 1101 cpi->rc.av_per_frame_bandwidth = (int)(cpi->oxcf.target_bandwidth | 1110 cpi->rc.av_per_frame_bandwidth = (int)(cpi->oxcf.target_bandwidth |
| 1102 / cpi->output_framerate); | 1111 / cpi->output_framerate); |
| 1103 cpi->rc.min_frame_bandwidth = (int)(cpi->rc.av_per_frame_bandwidth * | 1112 cpi->rc.min_frame_bandwidth = (int)(cpi->rc.av_per_frame_bandwidth * |
| 1104 cpi->oxcf.two_pass_vbrmin_section / 100); | 1113 cpi->oxcf.two_pass_vbrmin_section / 100); |
| 1105 | 1114 |
| 1106 | 1115 |
| 1107 cpi->rc.min_frame_bandwidth = MAX(cpi->rc.min_frame_bandwidth, | 1116 cpi->rc.min_frame_bandwidth = MAX(cpi->rc.min_frame_bandwidth, |
| 1108 FRAME_OVERHEAD_BITS); | 1117 FRAME_OVERHEAD_BITS); |
| 1109 | 1118 |
| 1110 // A maximum bitrate for a frame is defined. | 1119 // A maximum bitrate for a frame is defined. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1140 } | 1149 } |
| 1141 | 1150 |
| 1142 static int64_t rescale(int val, int64_t num, int denom) { | 1151 static int64_t rescale(int val, int64_t num, int denom) { |
| 1143 int64_t llnum = num; | 1152 int64_t llnum = num; |
| 1144 int64_t llden = denom; | 1153 int64_t llden = denom; |
| 1145 int64_t llval = val; | 1154 int64_t llval = val; |
| 1146 | 1155 |
| 1147 return (llval * llnum / llden); | 1156 return (llval * llnum / llden); |
| 1148 } | 1157 } |
| 1149 | 1158 |
| 1159 // Initialize layer context data from init_config(). |
| 1160 static void init_layer_context(VP9_COMP *const cpi) { |
| 1161 const VP9_CONFIG *const oxcf = &cpi->oxcf; |
| 1162 int temporal_layer = 0; |
| 1163 cpi->svc.spatial_layer_id = 0; |
| 1164 cpi->svc.temporal_layer_id = 0; |
| 1165 for (temporal_layer = 0; temporal_layer < cpi->svc.number_temporal_layers; |
| 1166 ++temporal_layer) { |
| 1167 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[temporal_layer]; |
| 1168 RATE_CONTROL *const lrc = &lc->rc; |
| 1169 lrc->avg_frame_qindex[INTER_FRAME] = q_trans[oxcf->worst_allowed_q]; |
| 1170 lrc->last_q[INTER_FRAME] = q_trans[oxcf->worst_allowed_q]; |
| 1171 lrc->ni_av_qi = q_trans[oxcf->worst_allowed_q]; |
| 1172 lrc->total_actual_bits = 0; |
| 1173 lrc->total_target_vs_actual = 0; |
| 1174 lrc->ni_tot_qi = 0; |
| 1175 lrc->tot_q = 0.0; |
| 1176 lrc->avg_q = 0.0; |
| 1177 lrc->ni_frames = 0; |
| 1178 lrc->decimation_count = 0; |
| 1179 lrc->decimation_factor = 0; |
| 1180 lrc->rate_correction_factor = 1.0; |
| 1181 lrc->key_frame_rate_correction_factor = 1.0; |
| 1182 lc->target_bandwidth = oxcf->ts_target_bitrate[temporal_layer] * |
| 1183 1000; |
| 1184 lrc->buffer_level = rescale((int)(oxcf->starting_buffer_level), |
| 1185 lc->target_bandwidth, 1000); |
| 1186 lrc->bits_off_target = lrc->buffer_level; |
| 1187 } |
| 1188 } |
| 1189 |
| 1190 // Update the layer context from a change_config() call. |
| 1191 static void update_layer_context_change_config(VP9_COMP *const cpi, |
| 1192 const int target_bandwidth) { |
| 1193 const VP9_CONFIG *const oxcf = &cpi->oxcf; |
| 1194 const RATE_CONTROL *const rc = &cpi->rc; |
| 1195 int temporal_layer = 0; |
| 1196 float bitrate_alloc = 1.0; |
| 1197 for (temporal_layer = 0; temporal_layer < cpi->svc.number_temporal_layers; |
| 1198 ++temporal_layer) { |
| 1199 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[temporal_layer]; |
| 1200 RATE_CONTROL *const lrc = &lc->rc; |
| 1201 lc->target_bandwidth = oxcf->ts_target_bitrate[temporal_layer] * 1000; |
| 1202 bitrate_alloc = (float)lc->target_bandwidth / (float)target_bandwidth; |
| 1203 // Update buffer-related quantities. |
| 1204 lc->starting_buffer_level = oxcf->starting_buffer_level * bitrate_alloc; |
| 1205 lc->optimal_buffer_level = oxcf->optimal_buffer_level * bitrate_alloc; |
| 1206 lc->maximum_buffer_size = oxcf->maximum_buffer_size * bitrate_alloc; |
| 1207 lrc->bits_off_target = MIN(lrc->bits_off_target, lc->maximum_buffer_size); |
| 1208 lrc->buffer_level = MIN(lrc->buffer_level, lc->maximum_buffer_size); |
| 1209 // Update framerate-related quantities. |
| 1210 lc->framerate = oxcf->framerate / oxcf->ts_rate_decimator[temporal_layer]; |
| 1211 lrc->av_per_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); |
| 1212 lrc->max_frame_bandwidth = rc->max_frame_bandwidth; |
| 1213 // Update qp-related quantities. |
| 1214 lrc->worst_quality = rc->worst_quality; |
| 1215 lrc->best_quality = rc->best_quality; |
| 1216 } |
| 1217 } |
| 1218 |
| 1219 // Prior to encoding the frame, update framerate-related quantities |
| 1220 // for the current layer. |
| 1221 static void update_layer_framerate(VP9_COMP *const cpi) { |
| 1222 int temporal_layer = cpi->svc.temporal_layer_id; |
| 1223 const VP9_CONFIG *const oxcf = &cpi->oxcf; |
| 1224 LAYER_CONTEXT *const lc = &cpi->svc.layer_context[temporal_layer]; |
| 1225 RATE_CONTROL *const lrc = &lc->rc; |
| 1226 lc->framerate = oxcf->framerate / oxcf->ts_rate_decimator[temporal_layer]; |
| 1227 lrc->av_per_frame_bandwidth = (int)(lc->target_bandwidth / lc->framerate); |
| 1228 lrc->max_frame_bandwidth = cpi->rc.max_frame_bandwidth; |
| 1229 // Update the average layer frame size (non-cumulative per-frame-bw). |
| 1230 if (temporal_layer == 0) { |
| 1231 lc->avg_frame_size = lrc->av_per_frame_bandwidth; |
| 1232 } else { |
| 1233 double prev_layer_framerate = oxcf->framerate / |
| 1234 oxcf->ts_rate_decimator[temporal_layer - 1]; |
| 1235 int prev_layer_target_bandwidth = |
| 1236 oxcf->ts_target_bitrate[temporal_layer - 1] * 1000; |
| 1237 lc->avg_frame_size = |
| 1238 (int)(lc->target_bandwidth - prev_layer_target_bandwidth) / |
| 1239 (lc->framerate - prev_layer_framerate); |
| 1240 } |
| 1241 } |
| 1242 |
| 1243 // Prior to encoding the frame, set the layer context, for the current layer |
| 1244 // to be encoded, to the cpi struct. |
| 1245 static void restore_layer_context(VP9_COMP *const cpi) { |
| 1246 int temporal_layer = cpi->svc.temporal_layer_id; |
| 1247 LAYER_CONTEXT *lc = &cpi->svc.layer_context[temporal_layer]; |
| 1248 int frame_since_key = cpi->rc.frames_since_key; |
| 1249 int frame_to_key = cpi->rc.frames_to_key; |
| 1250 cpi->rc = lc->rc; |
| 1251 cpi->oxcf.target_bandwidth = lc->target_bandwidth; |
| 1252 cpi->oxcf.starting_buffer_level = lc->starting_buffer_level; |
| 1253 cpi->oxcf.optimal_buffer_level = lc->optimal_buffer_level; |
| 1254 cpi->oxcf.maximum_buffer_size = lc->maximum_buffer_size; |
| 1255 cpi->output_framerate = lc->framerate; |
| 1256 // Reset the frames_since_key and frames_to_key counters to their values |
| 1257 // before the layer restore. Keep these defined for the stream (not layer). |
| 1258 cpi->rc.frames_since_key = frame_since_key; |
| 1259 cpi->rc.frames_to_key = frame_to_key; |
| 1260 } |
| 1261 |
| 1262 // Save the layer context after encoding the frame. |
| 1263 static void save_layer_context(VP9_COMP *const cpi) { |
| 1264 int temporal_layer = cpi->svc.temporal_layer_id; |
| 1265 LAYER_CONTEXT *lc = &cpi->svc.layer_context[temporal_layer]; |
| 1266 lc->rc = cpi->rc; |
| 1267 lc->target_bandwidth = cpi->oxcf.target_bandwidth; |
| 1268 lc->starting_buffer_level = cpi->oxcf.starting_buffer_level; |
| 1269 lc->optimal_buffer_level = cpi->oxcf.optimal_buffer_level; |
| 1270 lc->maximum_buffer_size = cpi->oxcf.maximum_buffer_size; |
| 1271 lc->framerate = cpi->output_framerate; |
| 1272 } |
| 1273 |
| 1150 static void set_tile_limits(VP9_COMP *cpi) { | 1274 static void set_tile_limits(VP9_COMP *cpi) { |
| 1151 VP9_COMMON *const cm = &cpi->common; | 1275 VP9_COMMON *const cm = &cpi->common; |
| 1152 | 1276 |
| 1153 int min_log2_tile_cols, max_log2_tile_cols; | 1277 int min_log2_tile_cols, max_log2_tile_cols; |
| 1154 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); | 1278 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); |
| 1155 | 1279 |
| 1156 cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns, | 1280 cm->log2_tile_cols = clamp(cpi->oxcf.tile_columns, |
| 1157 min_log2_tile_cols, max_log2_tile_cols); | 1281 min_log2_tile_cols, max_log2_tile_cols); |
| 1158 cm->log2_tile_rows = cpi->oxcf.tile_rows; | 1282 cm->log2_tile_rows = cpi->oxcf.tile_rows; |
| 1159 } | 1283 } |
| 1160 | 1284 |
| 1161 static void init_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { | 1285 static void init_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { |
| 1162 VP9_COMP *cpi = (VP9_COMP *)(ptr); | 1286 VP9_COMP *cpi = (VP9_COMP *)(ptr); |
| 1163 VP9_COMMON *const cm = &cpi->common; | 1287 VP9_COMMON *const cm = &cpi->common; |
| 1164 int i; | 1288 int i; |
| 1165 | 1289 |
| 1166 cpi->oxcf = *oxcf; | 1290 cpi->oxcf = *oxcf; |
| 1167 | 1291 |
| 1168 cm->version = oxcf->version; | 1292 cm->version = oxcf->version; |
| 1169 | 1293 |
| 1170 cm->width = oxcf->width; | 1294 cm->width = oxcf->width; |
| 1171 cm->height = oxcf->height; | 1295 cm->height = oxcf->height; |
| 1172 cm->subsampling_x = 0; | 1296 cm->subsampling_x = 0; |
| 1173 cm->subsampling_y = 0; | 1297 cm->subsampling_y = 0; |
| 1174 vp9_alloc_compressor_data(cpi); | 1298 vp9_alloc_compressor_data(cpi); |
| 1175 | 1299 |
| 1300 // Spatial scalability. |
| 1301 cpi->svc.number_spatial_layers = oxcf->ss_number_layers; |
| 1302 // Temporal scalability. |
| 1303 cpi->svc.number_temporal_layers = oxcf->ts_number_layers; |
| 1304 |
| 1305 if (cpi->svc.number_temporal_layers > 1 && |
| 1306 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { |
| 1307 init_layer_context(cpi); |
| 1308 } |
| 1309 |
| 1176 // change includes all joint functionality | 1310 // change includes all joint functionality |
| 1177 vp9_change_config(ptr, oxcf); | 1311 vp9_change_config(ptr, oxcf); |
| 1178 | 1312 |
| 1179 // Initialize active best and worst q and average q values. | 1313 // Initialize active best and worst q and average q values. |
| 1180 cpi->rc.active_worst_quality = cpi->oxcf.worst_allowed_q; | |
| 1181 | |
| 1182 if (cpi->pass == 0 && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { | 1314 if (cpi->pass == 0 && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { |
| 1183 cpi->rc.avg_frame_qindex[0] = cpi->oxcf.worst_allowed_q; | 1315 cpi->rc.avg_frame_qindex[0] = cpi->oxcf.worst_allowed_q; |
| 1184 cpi->rc.avg_frame_qindex[1] = cpi->oxcf.worst_allowed_q; | 1316 cpi->rc.avg_frame_qindex[1] = cpi->oxcf.worst_allowed_q; |
| 1185 cpi->rc.avg_frame_qindex[2] = cpi->oxcf.worst_allowed_q; | 1317 cpi->rc.avg_frame_qindex[2] = cpi->oxcf.worst_allowed_q; |
| 1186 } else { | 1318 } else { |
| 1187 cpi->rc.avg_frame_qindex[0] = (cpi->oxcf.worst_allowed_q + | 1319 cpi->rc.avg_frame_qindex[0] = (cpi->oxcf.worst_allowed_q + |
| 1188 cpi->oxcf.best_allowed_q) / 2; | 1320 cpi->oxcf.best_allowed_q) / 2; |
| 1189 cpi->rc.avg_frame_qindex[1] = (cpi->oxcf.worst_allowed_q + | 1321 cpi->rc.avg_frame_qindex[1] = (cpi->oxcf.worst_allowed_q + |
| 1190 cpi->oxcf.best_allowed_q) / 2; | 1322 cpi->oxcf.best_allowed_q) / 2; |
| 1191 cpi->rc.avg_frame_qindex[2] = (cpi->oxcf.worst_allowed_q + | 1323 cpi->rc.avg_frame_qindex[2] = (cpi->oxcf.worst_allowed_q + |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1206 | 1338 |
| 1207 cpi->rc.total_actual_bits = 0; | 1339 cpi->rc.total_actual_bits = 0; |
| 1208 cpi->rc.total_target_vs_actual = 0; | 1340 cpi->rc.total_target_vs_actual = 0; |
| 1209 | 1341 |
| 1210 cpi->static_mb_pct = 0; | 1342 cpi->static_mb_pct = 0; |
| 1211 | 1343 |
| 1212 cpi->lst_fb_idx = 0; | 1344 cpi->lst_fb_idx = 0; |
| 1213 cpi->gld_fb_idx = 1; | 1345 cpi->gld_fb_idx = 1; |
| 1214 cpi->alt_fb_idx = 2; | 1346 cpi->alt_fb_idx = 2; |
| 1215 | 1347 |
| 1216 cpi->current_layer = 0; | |
| 1217 cpi->use_svc = 0; | |
| 1218 | |
| 1219 set_tile_limits(cpi); | 1348 set_tile_limits(cpi); |
| 1220 | 1349 |
| 1221 cpi->fixed_divide[0] = 0; | 1350 cpi->fixed_divide[0] = 0; |
| 1222 for (i = 1; i < 512; i++) | 1351 for (i = 1; i < 512; i++) |
| 1223 cpi->fixed_divide[i] = 0x80000 / i; | 1352 cpi->fixed_divide[i] = 0x80000 / i; |
| 1224 } | 1353 } |
| 1225 | 1354 |
| 1226 | |
| 1227 void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { | 1355 void vp9_change_config(VP9_PTR ptr, VP9_CONFIG *oxcf) { |
| 1228 VP9_COMP *cpi = (VP9_COMP *)(ptr); | 1356 VP9_COMP *cpi = (VP9_COMP *)(ptr); |
| 1229 VP9_COMMON *const cm = &cpi->common; | 1357 VP9_COMMON *const cm = &cpi->common; |
| 1230 | 1358 |
| 1231 if (!cpi || !oxcf) | 1359 if (!cpi || !oxcf) |
| 1232 return; | 1360 return; |
| 1233 | 1361 |
| 1234 if (cm->version != oxcf->version) { | 1362 if (cm->version != oxcf->version) { |
| 1235 cm->version = oxcf->version; | 1363 cm->version = oxcf->version; |
| 1236 } | 1364 } |
| 1237 | 1365 |
| 1238 cpi->oxcf = *oxcf; | 1366 cpi->oxcf = *oxcf; |
| 1239 | 1367 |
| 1240 switch (cpi->oxcf.mode) { | 1368 switch (cpi->oxcf.mode) { |
| 1241 // Real time and one pass deprecated in test code base | 1369 // Real time and one pass deprecated in test code base |
| 1242 case MODE_GOODQUALITY: | 1370 case MODE_GOODQUALITY: |
| 1243 cpi->pass = 0; | 1371 cpi->pass = 0; |
| 1244 cpi->compressor_speed = 2; | |
| 1245 cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5); | 1372 cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5); |
| 1246 break; | 1373 break; |
| 1247 | 1374 |
| 1248 case MODE_FIRSTPASS: | 1375 case MODE_FIRSTPASS: |
| 1249 cpi->pass = 1; | 1376 cpi->pass = 1; |
| 1250 cpi->compressor_speed = 1; | |
| 1251 break; | 1377 break; |
| 1252 | 1378 |
| 1253 case MODE_SECONDPASS: | 1379 case MODE_SECONDPASS: |
| 1254 cpi->pass = 2; | 1380 cpi->pass = 2; |
| 1255 cpi->compressor_speed = 1; | |
| 1256 cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5); | 1381 cpi->oxcf.cpu_used = clamp(cpi->oxcf.cpu_used, -5, 5); |
| 1257 break; | 1382 break; |
| 1258 | 1383 |
| 1259 case MODE_SECONDPASS_BEST: | 1384 case MODE_SECONDPASS_BEST: |
| 1260 cpi->pass = 2; | 1385 cpi->pass = 2; |
| 1261 cpi->compressor_speed = 0; | 1386 break; |
| 1387 |
| 1388 case MODE_REALTIME: |
| 1389 cpi->pass = 0; |
| 1262 break; | 1390 break; |
| 1263 } | 1391 } |
| 1264 | 1392 |
| 1265 cpi->oxcf.worst_allowed_q = q_trans[oxcf->worst_allowed_q]; | 1393 cpi->oxcf.worst_allowed_q = q_trans[oxcf->worst_allowed_q]; |
| 1266 cpi->oxcf.best_allowed_q = q_trans[oxcf->best_allowed_q]; | 1394 cpi->oxcf.best_allowed_q = q_trans[oxcf->best_allowed_q]; |
| 1267 cpi->oxcf.cq_level = q_trans[cpi->oxcf.cq_level]; | 1395 cpi->oxcf.cq_level = q_trans[cpi->oxcf.cq_level]; |
| 1268 | 1396 |
| 1269 cpi->oxcf.lossless = oxcf->lossless; | 1397 cpi->oxcf.lossless = oxcf->lossless; |
| 1270 cpi->mb.e_mbd.itxm_add = cpi->oxcf.lossless ? vp9_iwht4x4_add | 1398 cpi->mb.e_mbd.itxm_add = cpi->oxcf.lossless ? vp9_iwht4x4_add |
| 1271 : vp9_idct4x4_add; | 1399 : vp9_idct4x4_add; |
| 1272 cpi->rc.baseline_gf_interval = DEFAULT_GF_INTERVAL; | 1400 cpi->rc.baseline_gf_interval = DEFAULT_GF_INTERVAL; |
| 1273 | 1401 |
| 1274 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; | 1402 cpi->ref_frame_flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
| 1275 | 1403 |
| 1276 cpi->refresh_golden_frame = 0; | 1404 cpi->refresh_golden_frame = 0; |
| 1277 cpi->refresh_last_frame = 1; | 1405 cpi->refresh_last_frame = 1; |
| 1278 cm->refresh_frame_context = 1; | 1406 cm->refresh_frame_context = 1; |
| 1279 cm->reset_frame_context = 0; | 1407 cm->reset_frame_context = 0; |
| 1280 | 1408 |
| 1281 vp9_reset_segment_features(&cm->seg); | 1409 vp9_reset_segment_features(&cm->seg); |
| 1282 set_high_precision_mv(cpi, 0); | 1410 set_high_precision_mv(cpi, 0); |
| 1283 | 1411 |
| 1284 { | 1412 { |
| 1285 int i; | 1413 int i; |
| 1286 | 1414 |
| 1287 for (i = 0; i < MAX_SEGMENTS; i++) | 1415 for (i = 0; i < MAX_SEGMENTS; i++) |
| 1288 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout; | 1416 cpi->segment_encode_breakout[i] = cpi->oxcf.encode_breakout; |
| 1289 } | 1417 } |
| 1418 cpi->encode_breakout = cpi->oxcf.encode_breakout; |
| 1290 | 1419 |
| 1291 // local file playback mode == really big buffer | 1420 // local file playback mode == really big buffer |
| 1292 if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK) { | 1421 if (cpi->oxcf.end_usage == USAGE_LOCAL_FILE_PLAYBACK) { |
| 1293 cpi->oxcf.starting_buffer_level = 60000; | 1422 cpi->oxcf.starting_buffer_level = 60000; |
| 1294 cpi->oxcf.optimal_buffer_level = 60000; | 1423 cpi->oxcf.optimal_buffer_level = 60000; |
| 1295 cpi->oxcf.maximum_buffer_size = 240000; | 1424 cpi->oxcf.maximum_buffer_size = 240000; |
| 1296 } | 1425 } |
| 1297 | 1426 |
| 1298 // Convert target bandwidth from Kbit/s to Bit/s | 1427 // Convert target bandwidth from Kbit/s to Bit/s |
| 1299 cpi->oxcf.target_bandwidth *= 1000; | 1428 cpi->oxcf.target_bandwidth *= 1000; |
| 1300 | 1429 |
| 1301 cpi->oxcf.starting_buffer_level = rescale(cpi->oxcf.starting_buffer_level, | 1430 cpi->oxcf.starting_buffer_level = rescale(cpi->oxcf.starting_buffer_level, |
| 1302 cpi->oxcf.target_bandwidth, 1000); | 1431 cpi->oxcf.target_bandwidth, 1000); |
| 1303 | 1432 |
| 1304 // Set or reset optimal and maximum buffer levels. | 1433 // Set or reset optimal and maximum buffer levels. |
| 1305 if (cpi->oxcf.optimal_buffer_level == 0) | 1434 if (cpi->oxcf.optimal_buffer_level == 0) |
| 1306 cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; | 1435 cpi->oxcf.optimal_buffer_level = cpi->oxcf.target_bandwidth / 8; |
| 1307 else | 1436 else |
| 1308 cpi->oxcf.optimal_buffer_level = rescale(cpi->oxcf.optimal_buffer_level, | 1437 cpi->oxcf.optimal_buffer_level = rescale(cpi->oxcf.optimal_buffer_level, |
| 1309 cpi->oxcf.target_bandwidth, 1000); | 1438 cpi->oxcf.target_bandwidth, 1000); |
| 1310 | 1439 |
| 1311 if (cpi->oxcf.maximum_buffer_size == 0) | 1440 if (cpi->oxcf.maximum_buffer_size == 0) |
| 1312 cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; | 1441 cpi->oxcf.maximum_buffer_size = cpi->oxcf.target_bandwidth / 8; |
| 1313 else | 1442 else |
| 1314 cpi->oxcf.maximum_buffer_size = rescale(cpi->oxcf.maximum_buffer_size, | 1443 cpi->oxcf.maximum_buffer_size = rescale(cpi->oxcf.maximum_buffer_size, |
| 1315 cpi->oxcf.target_bandwidth, 1000); | 1444 cpi->oxcf.target_bandwidth, 1000); |
| 1316 // Under a configuration change, where maximum_buffer_size may change, | 1445 // Under a configuration change, where maximum_buffer_size may change, |
| 1317 // keep buffer level clipped to the maximum allowed buffer size. | 1446 // keep buffer level clipped to the maximum allowed buffer size. |
| 1318 if (cpi->rc.bits_off_target > cpi->oxcf.maximum_buffer_size) { | 1447 cpi->rc.bits_off_target = MIN(cpi->rc.bits_off_target, |
| 1319 cpi->rc.bits_off_target = cpi->oxcf.maximum_buffer_size; | 1448 cpi->oxcf.maximum_buffer_size); |
| 1320 cpi->rc.buffer_level = cpi->rc.bits_off_target; | 1449 cpi->rc.buffer_level = MIN(cpi->rc.buffer_level, |
| 1321 } | 1450 cpi->oxcf.maximum_buffer_size); |
| 1322 | 1451 |
| 1323 // Set up frame rate and related parameters rate control values. | 1452 // Set up frame rate and related parameters rate control values. |
| 1324 vp9_new_framerate(cpi, cpi->oxcf.framerate); | 1453 vp9_new_framerate(cpi, cpi->oxcf.framerate); |
| 1325 | 1454 |
| 1326 // Set absolute upper and lower quality limits | 1455 // Set absolute upper and lower quality limits |
| 1327 cpi->rc.worst_quality = cpi->oxcf.worst_allowed_q; | 1456 cpi->rc.worst_quality = cpi->oxcf.worst_allowed_q; |
| 1328 cpi->rc.best_quality = cpi->oxcf.best_allowed_q; | 1457 cpi->rc.best_quality = cpi->oxcf.best_allowed_q; |
| 1329 | 1458 |
| 1330 // active values should only be modified if out of new range | 1459 // active values should only be modified if out of new range |
| 1331 cpi->rc.active_worst_quality = clamp(cpi->rc.active_worst_quality, | |
| 1332 cpi->rc.best_quality, | |
| 1333 cpi->rc.worst_quality); | |
| 1334 | 1460 |
| 1335 cpi->cq_target_quality = cpi->oxcf.cq_level; | 1461 cpi->cq_target_quality = cpi->oxcf.cq_level; |
| 1336 | 1462 |
| 1337 cm->interp_filter = DEFAULT_INTERP_FILTER; | 1463 cm->interp_filter = DEFAULT_INTERP_FILTER; |
| 1338 | 1464 |
| 1339 cpi->target_bandwidth = cpi->oxcf.target_bandwidth; | |
| 1340 | |
| 1341 cm->display_width = cpi->oxcf.width; | 1465 cm->display_width = cpi->oxcf.width; |
| 1342 cm->display_height = cpi->oxcf.height; | 1466 cm->display_height = cpi->oxcf.height; |
| 1343 | 1467 |
| 1344 // VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs) | 1468 // VP8 sharpness level mapping 0-7 (vs 0-10 in general VPx dialogs) |
| 1345 cpi->oxcf.sharpness = MIN(7, cpi->oxcf.sharpness); | 1469 cpi->oxcf.sharpness = MIN(7, cpi->oxcf.sharpness); |
| 1346 | 1470 |
| 1347 cpi->common.lf.sharpness_level = cpi->oxcf.sharpness; | 1471 cpi->common.lf.sharpness_level = cpi->oxcf.sharpness; |
| 1348 | 1472 |
| 1349 if (cpi->initial_width) { | 1473 if (cpi->initial_width) { |
| 1350 // Increasing the size of the frame beyond the first seen frame, or some | 1474 // Increasing the size of the frame beyond the first seen frame, or some |
| 1351 // otherwise signalled maximum size, is not supported. | 1475 // otherwise signaled maximum size, is not supported. |
| 1352 // TODO(jkoleszar): exit gracefully. | 1476 // TODO(jkoleszar): exit gracefully. |
| 1353 assert(cm->width <= cpi->initial_width); | 1477 assert(cm->width <= cpi->initial_width); |
| 1354 assert(cm->height <= cpi->initial_height); | 1478 assert(cm->height <= cpi->initial_height); |
| 1355 } | 1479 } |
| 1356 update_frame_size(cpi); | 1480 update_frame_size(cpi); |
| 1357 | 1481 |
| 1482 if (cpi->svc.number_temporal_layers > 1 && |
| 1483 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { |
| 1484 update_layer_context_change_config(cpi, cpi->oxcf.target_bandwidth); |
| 1485 } |
| 1486 |
| 1358 cpi->speed = cpi->oxcf.cpu_used; | 1487 cpi->speed = cpi->oxcf.cpu_used; |
| 1359 | 1488 |
| 1360 if (cpi->oxcf.lag_in_frames == 0) { | 1489 if (cpi->oxcf.lag_in_frames == 0) { |
| 1361 // force to allowlag to 0 if lag_in_frames is 0; | 1490 // Force allow_lag to 0 if lag_in_frames is 0. |
| 1362 cpi->oxcf.allow_lag = 0; | 1491 cpi->oxcf.allow_lag = 0; |
| 1363 } else if (cpi->oxcf.lag_in_frames > MAX_LAG_BUFFERS) { | 1492 } else if (cpi->oxcf.lag_in_frames > MAX_LAG_BUFFERS) { |
| 1364 // Limit on lag buffers as these are not currently dynamically allocated | 1493 // Limit on lag buffers as these are not currently dynamically allocated. |
| 1365 cpi->oxcf.lag_in_frames = MAX_LAG_BUFFERS; | 1494 cpi->oxcf.lag_in_frames = MAX_LAG_BUFFERS; |
| 1366 } | 1495 } |
| 1367 | 1496 |
| 1368 // YX Temp | |
| 1369 #if CONFIG_MULTIPLE_ARF | 1497 #if CONFIG_MULTIPLE_ARF |
| 1370 vp9_zero(cpi->alt_ref_source); | 1498 vp9_zero(cpi->alt_ref_source); |
| 1371 #else | 1499 #else |
| 1372 cpi->alt_ref_source = NULL; | 1500 cpi->alt_ref_source = NULL; |
| 1373 #endif | 1501 #endif |
| 1374 cpi->rc.is_src_frame_alt_ref = 0; | 1502 cpi->rc.is_src_frame_alt_ref = 0; |
| 1375 | 1503 |
| 1376 #if 0 | 1504 #if 0 |
| 1377 // Experimental RD Code | 1505 // Experimental RD Code |
| 1378 cpi->frame_distortion = 0; | 1506 cpi->frame_distortion = 0; |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1571 return 0; | 1699 return 0; |
| 1572 } | 1700 } |
| 1573 | 1701 |
| 1574 cm->error.setjmp = 1; | 1702 cm->error.setjmp = 1; |
| 1575 | 1703 |
| 1576 CHECK_MEM_ERROR(cm, cpi->mb.ss, vpx_calloc(sizeof(search_site), | 1704 CHECK_MEM_ERROR(cm, cpi->mb.ss, vpx_calloc(sizeof(search_site), |
| 1577 (MAX_MVSEARCH_STEPS * 8) + 1)); | 1705 (MAX_MVSEARCH_STEPS * 8) + 1)); |
| 1578 | 1706 |
| 1579 vp9_create_common(cm); | 1707 vp9_create_common(cm); |
| 1580 | 1708 |
| 1709 cpi->use_svc = 0; |
| 1710 |
| 1581 init_config((VP9_PTR)cpi, oxcf); | 1711 init_config((VP9_PTR)cpi, oxcf); |
| 1582 | 1712 |
| 1583 init_pick_mode_context(cpi); | 1713 init_pick_mode_context(cpi); |
| 1584 | 1714 |
| 1585 cm->current_video_frame = 0; | 1715 cm->current_video_frame = 0; |
| 1586 | 1716 |
| 1587 // Set reference frame sign bias for ALTREF frame to 1 (for now) | 1717 // Set reference frame sign bias for ALTREF frame to 1 (for now) |
| 1588 cm->ref_frame_sign_bias[ALTREF_FRAME] = 1; | 1718 cm->ref_frame_sign_bias[ALTREF_FRAME] = 1; |
| 1589 | 1719 |
| 1590 cpi->rc.baseline_gf_interval = DEFAULT_GF_INTERVAL; | 1720 cpi->rc.baseline_gf_interval = DEFAULT_GF_INTERVAL; |
| 1591 | 1721 |
| 1592 cpi->gold_is_last = 0; | 1722 cpi->gold_is_last = 0; |
| 1593 cpi->alt_is_last = 0; | 1723 cpi->alt_is_last = 0; |
| 1594 cpi->gold_is_alt = 0; | 1724 cpi->gold_is_alt = 0; |
| 1595 | 1725 |
| 1596 // Spatial scalability | |
| 1597 cpi->number_spatial_layers = oxcf->ss_number_layers; | |
| 1598 | |
| 1599 // Create the encoder segmentation map and set all entries to 0 | 1726 // Create the encoder segmentation map and set all entries to 0 |
| 1600 CHECK_MEM_ERROR(cm, cpi->segmentation_map, | 1727 CHECK_MEM_ERROR(cm, cpi->segmentation_map, |
| 1601 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1728 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
| 1602 | 1729 |
| 1603 // Create a complexity map used for rd adjustment | 1730 // Create a complexity map used for rd adjustment |
| 1604 CHECK_MEM_ERROR(cm, cpi->complexity_map, | 1731 CHECK_MEM_ERROR(cm, cpi->complexity_map, |
| 1605 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1732 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
| 1606 | 1733 |
| 1607 | 1734 |
| 1608 // And a place holder structure is the coding context | 1735 // And a place holder structure is the coding context |
| 1609 // for use if we want to save and restore it | 1736 // for use if we want to save and restore it |
| 1610 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, | 1737 CHECK_MEM_ERROR(cm, cpi->coding_context.last_frame_seg_map_copy, |
| 1611 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); | 1738 vpx_calloc(cm->mi_rows * cm->mi_cols, 1)); |
| 1612 | 1739 |
| 1613 CHECK_MEM_ERROR(cm, cpi->active_map, vpx_calloc(cm->MBs, 1)); | 1740 CHECK_MEM_ERROR(cm, cpi->active_map, vpx_calloc(cm->MBs, 1)); |
| 1614 vpx_memset(cpi->active_map, 1, cm->MBs); | 1741 vpx_memset(cpi->active_map, 1, cm->MBs); |
| 1615 cpi->active_map_enabled = 0; | 1742 cpi->active_map_enabled = 0; |
| 1616 | 1743 |
| 1617 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / | 1744 for (i = 0; i < (sizeof(cpi->mbgraph_stats) / |
| 1618 sizeof(cpi->mbgraph_stats[0])); i++) { | 1745 sizeof(cpi->mbgraph_stats[0])); i++) { |
| 1619 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats, | 1746 CHECK_MEM_ERROR(cm, cpi->mbgraph_stats[i].mb_stats, |
| 1620 vpx_calloc(cm->MBs * | 1747 vpx_calloc(cm->MBs * |
| 1621 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); | 1748 sizeof(*cpi->mbgraph_stats[i].mb_stats), 1)); |
| 1622 } | 1749 } |
| 1623 | 1750 |
| 1624 #ifdef ENTROPY_STATS | |
| 1625 if (cpi->pass != 1) | |
| 1626 init_context_counters(); | |
| 1627 #endif | |
| 1628 | |
| 1629 /*Initialize the feed-forward activity masking.*/ | 1751 /*Initialize the feed-forward activity masking.*/ |
| 1630 cpi->activity_avg = 90 << 12; | 1752 cpi->activity_avg = 90 << 12; |
| 1631 cpi->key_frame_frequency = cpi->oxcf.key_freq; | 1753 cpi->key_frame_frequency = cpi->oxcf.key_freq; |
| 1632 | 1754 |
| 1633 cpi->rc.frames_since_key = 8; // Sensible default for first frame. | 1755 cpi->rc.frames_since_key = 8; // Sensible default for first frame. |
| 1634 cpi->rc.this_key_frame_forced = 0; | 1756 cpi->rc.this_key_frame_forced = 0; |
| 1635 cpi->rc.next_key_frame_forced = 0; | 1757 cpi->rc.next_key_frame_forced = 0; |
| 1636 | 1758 |
| 1637 cpi->rc.source_alt_ref_pending = 0; | 1759 cpi->rc.source_alt_ref_pending = 0; |
| 1638 cpi->rc.source_alt_ref_active = 0; | 1760 cpi->rc.source_alt_ref_active = 0; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 yuv_rec_file = fopen("rec.yuv", "wb"); | 1845 yuv_rec_file = fopen("rec.yuv", "wb"); |
| 1724 #endif | 1846 #endif |
| 1725 | 1847 |
| 1726 #if 0 | 1848 #if 0 |
| 1727 framepsnr = fopen("framepsnr.stt", "a"); | 1849 framepsnr = fopen("framepsnr.stt", "a"); |
| 1728 kf_list = fopen("kf_list.stt", "w"); | 1850 kf_list = fopen("kf_list.stt", "w"); |
| 1729 #endif | 1851 #endif |
| 1730 | 1852 |
| 1731 cpi->output_pkt_list = oxcf->output_pkt_list; | 1853 cpi->output_pkt_list = oxcf->output_pkt_list; |
| 1732 | 1854 |
| 1733 cpi->enable_encode_breakout = 1; | 1855 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; |
| 1734 | 1856 |
| 1735 if (cpi->pass == 1) { | 1857 if (cpi->pass == 1) { |
| 1736 vp9_init_first_pass(cpi); | 1858 vp9_init_first_pass(cpi); |
| 1737 } else if (cpi->pass == 2) { | 1859 } else if (cpi->pass == 2) { |
| 1738 size_t packet_sz = sizeof(FIRSTPASS_STATS); | 1860 size_t packet_sz = sizeof(FIRSTPASS_STATS); |
| 1739 int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); | 1861 int packets = (int)(oxcf->two_pass_stats_in.sz / packet_sz); |
| 1740 | 1862 |
| 1741 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; | 1863 cpi->twopass.stats_in_start = oxcf->two_pass_stats_in.buf; |
| 1742 cpi->twopass.stats_in = cpi->twopass.stats_in_start; | 1864 cpi->twopass.stats_in = cpi->twopass.stats_in_start; |
| 1743 cpi->twopass.stats_in_end = (void *)((char *)cpi->twopass.stats_in | 1865 cpi->twopass.stats_in_end = (void *)((char *)cpi->twopass.stats_in |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1949 ((cpi->common.width + 63) / 64); | 2071 ((cpi->common.width + 63) / 64); |
| 1950 norm_per_pixel_mode_tests = | 2072 norm_per_pixel_mode_tests = |
| 1951 norm_per_pixel_mode_tests / | 2073 norm_per_pixel_mode_tests / |
| 1952 (double)(cpi->common.current_video_frame * sb64_per_frame); | 2074 (double)(cpi->common.current_video_frame * sb64_per_frame); |
| 1953 | 2075 |
| 1954 fprintf(f, "%6.4f\n", norm_per_pixel_mode_tests); | 2076 fprintf(f, "%6.4f\n", norm_per_pixel_mode_tests); |
| 1955 fclose(f); | 2077 fclose(f); |
| 1956 } | 2078 } |
| 1957 #endif | 2079 #endif |
| 1958 | 2080 |
| 1959 #if defined(SECTIONBITS_OUTPUT) | |
| 1960 | |
| 1961 if (0) { | |
| 1962 int i; | |
| 1963 FILE *f = fopen("tokenbits.stt", "a"); | |
| 1964 | |
| 1965 for (i = 0; i < 28; i++) | |
| 1966 fprintf(f, "%8d", (int)(Sectionbits[i] / 256)); | |
| 1967 | |
| 1968 fprintf(f, "\n"); | |
| 1969 fclose(f); | |
| 1970 } | |
| 1971 | |
| 1972 #endif | |
| 1973 | |
| 1974 #if 0 | 2081 #if 0 |
| 1975 { | 2082 { |
| 1976 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); | 2083 printf("\n_pick_loop_filter_level:%d\n", cpi->time_pick_lpf / 1000); |
| 1977 printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); | 2084 printf("\n_frames recive_data encod_mb_row compress_frame Total\n"); |
| 1978 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, | 2085 printf("%6d %10ld %10ld %10ld %10ld\n", cpi->common.current_video_frame, |
| 1979 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, | 2086 cpi->time_receive_data / 1000, cpi->time_encode_sb_row / 1000, |
| 1980 cpi->time_compress_data / 1000, | 2087 cpi->time_compress_data / 1000, |
| 1981 (cpi->time_receive_data + cpi->time_compress_data) / 1000); | 2088 (cpi->time_receive_data + cpi->time_compress_data) / 1000); |
| 1982 } | 2089 } |
| 1983 #endif | 2090 #endif |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2179 } | 2286 } |
| 2180 } | 2287 } |
| 2181 | 2288 |
| 2182 int vp9_get_reference_enc(VP9_PTR ptr, int index, YV12_BUFFER_CONFIG **fb) { | 2289 int vp9_get_reference_enc(VP9_PTR ptr, int index, YV12_BUFFER_CONFIG **fb) { |
| 2183 VP9_COMP *cpi = (VP9_COMP *)ptr; | 2290 VP9_COMP *cpi = (VP9_COMP *)ptr; |
| 2184 VP9_COMMON *cm = &cpi->common; | 2291 VP9_COMMON *cm = &cpi->common; |
| 2185 | 2292 |
| 2186 if (index < 0 || index >= REF_FRAMES) | 2293 if (index < 0 || index >= REF_FRAMES) |
| 2187 return -1; | 2294 return -1; |
| 2188 | 2295 |
| 2189 *fb = &cm->yv12_fb[cm->ref_frame_map[index]]; | 2296 *fb = &cm->frame_bufs[cm->ref_frame_map[index]].buf; |
| 2190 return 0; | 2297 return 0; |
| 2191 } | 2298 } |
| 2192 | 2299 |
| 2193 int vp9_set_reference_enc(VP9_PTR ptr, VP9_REFFRAME ref_frame_flag, | 2300 int vp9_set_reference_enc(VP9_PTR ptr, VP9_REFFRAME ref_frame_flag, |
| 2194 YV12_BUFFER_CONFIG *sd) { | 2301 YV12_BUFFER_CONFIG *sd) { |
| 2195 VP9_COMP *cpi = (VP9_COMP *)ptr; | 2302 VP9_COMP *cpi = (VP9_COMP *)ptr; |
| 2196 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); | 2303 YV12_BUFFER_CONFIG *cfg = get_vp9_ref_frame_buffer(cpi, ref_frame_flag); |
| 2197 if (cfg) { | 2304 if (cfg) { |
| 2198 vp8_yv12_copy_frame(sd, cfg); | 2305 vp8_yv12_copy_frame(sd, cfg); |
| 2199 return 0; | 2306 return 0; |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 } | 2537 } |
| 2431 curr += frame->y_stride - frame->y_width + 2; | 2538 curr += frame->y_stride - frame->y_width + 2; |
| 2432 prev += frame->y_stride - frame->y_width + 2; | 2539 prev += frame->y_stride - frame->y_width + 2; |
| 2433 next += frame->y_stride - frame->y_width + 2; | 2540 next += frame->y_stride - frame->y_width + 2; |
| 2434 } | 2541 } |
| 2435 return (double)num_edge_pels / num_pels; | 2542 return (double)num_edge_pels / num_pels; |
| 2436 } | 2543 } |
| 2437 | 2544 |
| 2438 // Function to test for conditions that indicate we should loop | 2545 // Function to test for conditions that indicate we should loop |
| 2439 // back and recode a frame. | 2546 // back and recode a frame. |
| 2440 static int recode_loop_test(VP9_COMP *cpi, | 2547 static int recode_loop_test(const VP9_COMP *cpi, |
| 2441 int high_limit, int low_limit, | 2548 int high_limit, int low_limit, |
| 2442 int q, int maxq, int minq) { | 2549 int q, int maxq, int minq) { |
| 2550 const VP9_COMMON *const cm = &cpi->common; |
| 2551 const RATE_CONTROL *const rc = &cpi->rc; |
| 2443 int force_recode = 0; | 2552 int force_recode = 0; |
| 2444 VP9_COMMON *cm = &cpi->common; | |
| 2445 | 2553 |
| 2446 // Special case trap if maximum allowed frame size exceeded. | 2554 // Special case trap if maximum allowed frame size exceeded. |
| 2447 if (cpi->rc.projected_frame_size > cpi->rc.max_frame_bandwidth) { | 2555 if (rc->projected_frame_size > rc->max_frame_bandwidth) { |
| 2448 force_recode = 1; | 2556 force_recode = 1; |
| 2449 | 2557 |
| 2450 // Is frame recode allowed. | 2558 // Is frame recode allowed. |
| 2451 // Yes if either recode mode 1 is selected or mode 2 is selected | 2559 // Yes if either recode mode 1 is selected or mode 2 is selected |
| 2452 // and the frame is a key frame, golden frame or alt_ref_frame | 2560 // and the frame is a key frame, golden frame or alt_ref_frame |
| 2453 } else if ((cpi->sf.recode_loop == 1) || | 2561 } else if ((cpi->sf.recode_loop == ALLOW_RECODE) || |
| 2454 ((cpi->sf.recode_loop == 2) && | 2562 ((cpi->sf.recode_loop == ALLOW_RECODE_KFARFGF) && |
| 2455 ((cm->frame_type == KEY_FRAME) || | 2563 (cm->frame_type == KEY_FRAME || |
| 2456 cpi->refresh_golden_frame || | 2564 cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) { |
| 2457 cpi->refresh_alt_ref_frame))) { | |
| 2458 // General over and under shoot tests | 2565 // General over and under shoot tests |
| 2459 if (((cpi->rc.projected_frame_size > high_limit) && (q < maxq)) || | 2566 if ((rc->projected_frame_size > high_limit && q < maxq) || |
| 2460 ((cpi->rc.projected_frame_size < low_limit) && (q > minq))) { | 2567 (rc->projected_frame_size < low_limit && q > minq)) { |
| 2461 force_recode = 1; | 2568 force_recode = 1; |
| 2462 } else if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) { | 2569 } else if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) { |
| 2463 // Deal with frame undershoot and whether or not we are | 2570 // Deal with frame undershoot and whether or not we are |
| 2464 // below the automatically set cq level. | 2571 // below the automatically set cq level. |
| 2465 if (q > cpi->cq_target_quality && | 2572 if (q > cpi->cq_target_quality && |
| 2466 cpi->rc.projected_frame_size < | 2573 rc->projected_frame_size < ((rc->this_frame_target * 7) >> 3)) { |
| 2467 ((cpi->rc.this_frame_target * 7) >> 3)) { | |
| 2468 force_recode = 1; | 2574 force_recode = 1; |
| 2469 } | 2575 } |
| 2470 } | 2576 } |
| 2471 } | 2577 } |
| 2472 return force_recode; | 2578 return force_recode; |
| 2473 } | 2579 } |
| 2474 | 2580 |
| 2475 static void update_reference_frames(VP9_COMP * const cpi) { | 2581 static void update_reference_frames(VP9_COMP * const cpi) { |
| 2476 VP9_COMMON * const cm = &cpi->common; | 2582 VP9_COMMON * const cm = &cpi->common; |
| 2477 | 2583 |
| 2478 // At this point the new frame has been encoded. | 2584 // At this point the new frame has been encoded. |
| 2479 // If any buffer copy / swapping is signaled it should be done here. | 2585 // If any buffer copy / swapping is signaled it should be done here. |
| 2480 if (cm->frame_type == KEY_FRAME) { | 2586 if (cm->frame_type == KEY_FRAME) { |
| 2481 ref_cnt_fb(cm->fb_idx_ref_cnt, | 2587 ref_cnt_fb(cm->frame_bufs, |
| 2482 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); | 2588 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); |
| 2483 ref_cnt_fb(cm->fb_idx_ref_cnt, | 2589 ref_cnt_fb(cm->frame_bufs, |
| 2484 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); | 2590 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); |
| 2485 } | 2591 } |
| 2486 #if CONFIG_MULTIPLE_ARF | 2592 #if CONFIG_MULTIPLE_ARF |
| 2487 else if (!cpi->multi_arf_enabled && cpi->refresh_golden_frame && | 2593 else if (!cpi->multi_arf_enabled && cpi->refresh_golden_frame && |
| 2488 !cpi->refresh_alt_ref_frame) { | 2594 !cpi->refresh_alt_ref_frame) { |
| 2489 #else | 2595 #else |
| 2490 else if (cpi->refresh_golden_frame && !cpi->refresh_alt_ref_frame && | 2596 else if (cpi->refresh_golden_frame && !cpi->refresh_alt_ref_frame && |
| 2491 !cpi->use_svc) { | 2597 !cpi->use_svc) { |
| 2492 #endif | 2598 #endif |
| 2493 /* Preserve the previously existing golden frame and update the frame in | 2599 /* Preserve the previously existing golden frame and update the frame in |
| 2494 * the alt ref slot instead. This is highly specific to the current use of | 2600 * the alt ref slot instead. This is highly specific to the current use of |
| 2495 * alt-ref as a forward reference, and this needs to be generalized as | 2601 * alt-ref as a forward reference, and this needs to be generalized as |
| 2496 * other uses are implemented (like RTC/temporal scaling) | 2602 * other uses are implemented (like RTC/temporal scaling) |
| 2497 * | 2603 * |
| 2498 * The update to the buffer in the alt ref slot was signaled in | 2604 * The update to the buffer in the alt ref slot was signaled in |
| 2499 * vp9_pack_bitstream(), now swap the buffer pointers so that it's treated | 2605 * vp9_pack_bitstream(), now swap the buffer pointers so that it's treated |
| 2500 * as the golden frame next time. | 2606 * as the golden frame next time. |
| 2501 */ | 2607 */ |
| 2502 int tmp; | 2608 int tmp; |
| 2503 | 2609 |
| 2504 ref_cnt_fb(cm->fb_idx_ref_cnt, | 2610 ref_cnt_fb(cm->frame_bufs, |
| 2505 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); | 2611 &cm->ref_frame_map[cpi->alt_fb_idx], cm->new_fb_idx); |
| 2506 | 2612 |
| 2507 tmp = cpi->alt_fb_idx; | 2613 tmp = cpi->alt_fb_idx; |
| 2508 cpi->alt_fb_idx = cpi->gld_fb_idx; | 2614 cpi->alt_fb_idx = cpi->gld_fb_idx; |
| 2509 cpi->gld_fb_idx = tmp; | 2615 cpi->gld_fb_idx = tmp; |
| 2510 } else { /* For non key/golden frames */ | 2616 } else { /* For non key/golden frames */ |
| 2511 if (cpi->refresh_alt_ref_frame) { | 2617 if (cpi->refresh_alt_ref_frame) { |
| 2512 int arf_idx = cpi->alt_fb_idx; | 2618 int arf_idx = cpi->alt_fb_idx; |
| 2513 #if CONFIG_MULTIPLE_ARF | 2619 #if CONFIG_MULTIPLE_ARF |
| 2514 if (cpi->multi_arf_enabled) { | 2620 if (cpi->multi_arf_enabled) { |
| 2515 arf_idx = cpi->arf_buffer_idx[cpi->sequence_number + 1]; | 2621 arf_idx = cpi->arf_buffer_idx[cpi->sequence_number + 1]; |
| 2516 } | 2622 } |
| 2517 #endif | 2623 #endif |
| 2518 ref_cnt_fb(cm->fb_idx_ref_cnt, | 2624 ref_cnt_fb(cm->frame_bufs, |
| 2519 &cm->ref_frame_map[arf_idx], cm->new_fb_idx); | 2625 &cm->ref_frame_map[arf_idx], cm->new_fb_idx); |
| 2520 } | 2626 } |
| 2521 | 2627 |
| 2522 if (cpi->refresh_golden_frame) { | 2628 if (cpi->refresh_golden_frame) { |
| 2523 ref_cnt_fb(cm->fb_idx_ref_cnt, | 2629 ref_cnt_fb(cm->frame_bufs, |
| 2524 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); | 2630 &cm->ref_frame_map[cpi->gld_fb_idx], cm->new_fb_idx); |
| 2525 } | 2631 } |
| 2526 } | 2632 } |
| 2527 | 2633 |
| 2528 if (cpi->refresh_last_frame) { | 2634 if (cpi->refresh_last_frame) { |
| 2529 ref_cnt_fb(cm->fb_idx_ref_cnt, | 2635 ref_cnt_fb(cm->frame_bufs, |
| 2530 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); | 2636 &cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx); |
| 2531 } | 2637 } |
| 2532 } | 2638 } |
| 2533 | 2639 |
| 2534 static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { | 2640 static void loopfilter_frame(VP9_COMP *cpi, VP9_COMMON *cm) { |
| 2535 MACROBLOCKD *xd = &cpi->mb.e_mbd; | 2641 MACROBLOCKD *xd = &cpi->mb.e_mbd; |
| 2536 struct loopfilter *lf = &cm->lf; | 2642 struct loopfilter *lf = &cm->lf; |
| 2537 if (xd->lossless) { | 2643 if (xd->lossless) { |
| 2538 lf->filter_level = 0; | 2644 lf->filter_level = 0; |
| 2539 } else { | 2645 } else { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2557 vp9_extend_frame_inner_borders(cm->frame_to_show, | 2663 vp9_extend_frame_inner_borders(cm->frame_to_show, |
| 2558 cm->subsampling_x, cm->subsampling_y); | 2664 cm->subsampling_x, cm->subsampling_y); |
| 2559 } | 2665 } |
| 2560 | 2666 |
| 2561 static void scale_references(VP9_COMP *cpi) { | 2667 static void scale_references(VP9_COMP *cpi) { |
| 2562 VP9_COMMON *cm = &cpi->common; | 2668 VP9_COMMON *cm = &cpi->common; |
| 2563 MV_REFERENCE_FRAME ref_frame; | 2669 MV_REFERENCE_FRAME ref_frame; |
| 2564 | 2670 |
| 2565 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 2671 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 2566 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | 2672 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
| 2567 YV12_BUFFER_CONFIG *ref = &cm->yv12_fb[idx]; | 2673 YV12_BUFFER_CONFIG *const ref = &cm->frame_bufs[idx].buf; |
| 2568 | 2674 |
| 2569 if (ref->y_crop_width != cm->width || | 2675 if (ref->y_crop_width != cm->width || |
| 2570 ref->y_crop_height != cm->height) { | 2676 ref->y_crop_height != cm->height) { |
| 2571 const int new_fb = get_free_fb(cm); | 2677 const int new_fb = get_free_fb(cm); |
| 2572 vp9_realloc_frame_buffer(&cm->yv12_fb[new_fb], | 2678 vp9_realloc_frame_buffer(&cm->frame_bufs[new_fb].buf, |
| 2573 cm->width, cm->height, | 2679 cm->width, cm->height, |
| 2574 cm->subsampling_x, cm->subsampling_y, | 2680 cm->subsampling_x, cm->subsampling_y, |
| 2575 VP9_ENC_BORDER_IN_PIXELS); | 2681 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); |
| 2576 scale_and_extend_frame(ref, &cm->yv12_fb[new_fb]); | 2682 scale_and_extend_frame(ref, &cm->frame_bufs[new_fb].buf); |
| 2577 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; | 2683 cpi->scaled_ref_idx[ref_frame - 1] = new_fb; |
| 2578 } else { | 2684 } else { |
| 2579 cpi->scaled_ref_idx[ref_frame - 1] = idx; | 2685 cpi->scaled_ref_idx[ref_frame - 1] = idx; |
| 2580 cm->fb_idx_ref_cnt[idx]++; | 2686 cm->frame_bufs[idx].ref_count++; |
| 2581 } | 2687 } |
| 2582 } | 2688 } |
| 2583 } | 2689 } |
| 2584 | 2690 |
| 2585 static void release_scaled_references(VP9_COMP *cpi) { | 2691 static void release_scaled_references(VP9_COMP *cpi) { |
| 2586 VP9_COMMON *cm = &cpi->common; | 2692 VP9_COMMON *cm = &cpi->common; |
| 2587 int i; | 2693 int i; |
| 2588 | 2694 |
| 2589 for (i = 0; i < 3; i++) | 2695 for (i = 0; i < 3; i++) |
| 2590 cm->fb_idx_ref_cnt[cpi->scaled_ref_idx[i]]--; | 2696 cm->frame_bufs[cpi->scaled_ref_idx[i]].ref_count--; |
| 2591 } | 2697 } |
| 2592 | 2698 |
| 2593 static void full_to_model_count(unsigned int *model_count, | 2699 static void full_to_model_count(unsigned int *model_count, |
| 2594 unsigned int *full_count) { | 2700 unsigned int *full_count) { |
| 2595 int n; | 2701 int n; |
| 2596 model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN]; | 2702 model_count[ZERO_TOKEN] = full_count[ZERO_TOKEN]; |
| 2597 model_count[ONE_TOKEN] = full_count[ONE_TOKEN]; | 2703 model_count[ONE_TOKEN] = full_count[ONE_TOKEN]; |
| 2598 model_count[TWO_TOKEN] = full_count[TWO_TOKEN]; | 2704 model_count[TWO_TOKEN] = full_count[TWO_TOKEN]; |
| 2599 for (n = THREE_TOKEN; n < EOB_TOKEN; ++n) | 2705 for (n = THREE_TOKEN; n < EOB_TOKEN; ++n) |
| 2600 model_count[TWO_TOKEN] += full_count[n]; | 2706 model_count[TWO_TOKEN] += full_count[n]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2618 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); | 2724 FILE *const f = fopen("tmp.stt", cm->current_video_frame ? "a" : "w"); |
| 2619 int recon_err; | 2725 int recon_err; |
| 2620 | 2726 |
| 2621 vp9_clear_system_state(); // __asm emms; | 2727 vp9_clear_system_state(); // __asm emms; |
| 2622 | 2728 |
| 2623 recon_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); | 2729 recon_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); |
| 2624 | 2730 |
| 2625 if (cpi->twopass.total_left_stats.coded_error != 0.0) | 2731 if (cpi->twopass.total_left_stats.coded_error != 0.0) |
| 2626 fprintf(f, "%10u %10d %10d %10d %10d %10d " | 2732 fprintf(f, "%10u %10d %10d %10d %10d %10d " |
| 2627 "%10"PRId64" %10"PRId64" %10d " | 2733 "%10"PRId64" %10"PRId64" %10d " |
| 2628 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" | 2734 "%7.2lf %7.2lf %7.2lf %7.2lf %7.2lf" |
| 2629 "%6d %6d %5d %5d %5d " | 2735 "%6d %6d %5d %5d %5d " |
| 2630 "%10"PRId64" %10.3lf" | 2736 "%10"PRId64" %10.3lf" |
| 2631 "%10lf %8u %10d %10d %10d\n", | 2737 "%10lf %8u %10d %10d %10d\n", |
| 2632 cpi->common.current_video_frame, cpi->rc.this_frame_target, | 2738 cpi->common.current_video_frame, cpi->rc.this_frame_target, |
| 2633 cpi->rc.projected_frame_size, | 2739 cpi->rc.projected_frame_size, |
| 2634 cpi->rc.projected_frame_size / cpi->common.MBs, | 2740 cpi->rc.projected_frame_size / cpi->common.MBs, |
| 2635 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), | 2741 (cpi->rc.projected_frame_size - cpi->rc.this_frame_target), |
| 2636 cpi->rc.total_target_vs_actual, | 2742 cpi->rc.total_target_vs_actual, |
| 2637 (cpi->oxcf.starting_buffer_level - cpi->rc.bits_off_target), | 2743 (cpi->oxcf.starting_buffer_level - cpi->rc.bits_off_target), |
| 2638 cpi->rc.total_actual_bits, cm->base_qindex, | 2744 cpi->rc.total_actual_bits, cm->base_qindex, |
| 2639 vp9_convert_qindex_to_q(cm->base_qindex), | 2745 vp9_convert_qindex_to_q(cm->base_qindex), |
| 2640 (double)vp9_dc_quant(cm->base_qindex, 0) / 4.0, | 2746 (double)vp9_dc_quant(cm->base_qindex, 0) / 4.0, |
| 2641 vp9_convert_qindex_to_q(cpi->rc.active_worst_quality), cpi->rc.avg_q, | 2747 cpi->rc.avg_q, |
| 2642 vp9_convert_qindex_to_q(cpi->rc.ni_av_qi), | 2748 vp9_convert_qindex_to_q(cpi->rc.ni_av_qi), |
| 2643 vp9_convert_qindex_to_q(cpi->cq_target_quality), | 2749 vp9_convert_qindex_to_q(cpi->cq_target_quality), |
| 2644 cpi->refresh_last_frame, cpi->refresh_golden_frame, | 2750 cpi->refresh_last_frame, cpi->refresh_golden_frame, |
| 2645 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, | 2751 cpi->refresh_alt_ref_frame, cm->frame_type, cpi->rc.gfu_boost, |
| 2646 cpi->twopass.bits_left, | 2752 cpi->twopass.bits_left, |
| 2647 cpi->twopass.total_left_stats.coded_error, | 2753 cpi->twopass.total_left_stats.coded_error, |
| 2648 cpi->twopass.bits_left / | 2754 cpi->twopass.bits_left / |
| 2649 (1 + cpi->twopass.total_left_stats.coded_error), | 2755 (1 + cpi->twopass.total_left_stats.coded_error), |
| 2650 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, | 2756 cpi->tot_recode_hits, recon_err, cpi->rc.kf_boost, |
| 2651 cpi->twopass.kf_zeromotion_pct); | 2757 cpi->twopass.kf_zeromotion_pct); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2665 for (i = 0; i < MAX_REFS; ++i) | 2771 for (i = 0; i < MAX_REFS; ++i) |
| 2666 fprintf(fmodes, "%5d ", cpi->sub8x8_mode_chosen_counts[i]); | 2772 fprintf(fmodes, "%5d ", cpi->sub8x8_mode_chosen_counts[i]); |
| 2667 | 2773 |
| 2668 fprintf(fmodes, "\n"); | 2774 fprintf(fmodes, "\n"); |
| 2669 | 2775 |
| 2670 fclose(fmodes); | 2776 fclose(fmodes); |
| 2671 } | 2777 } |
| 2672 } | 2778 } |
| 2673 #endif | 2779 #endif |
| 2674 | 2780 |
| 2781 static void encode_without_recode_loop(VP9_COMP *cpi, |
| 2782 size_t *size, |
| 2783 uint8_t *dest, |
| 2784 int q) { |
| 2785 VP9_COMMON *const cm = &cpi->common; |
| 2786 vp9_clear_system_state(); // __asm emms; |
| 2787 vp9_set_quantizer(cpi, q); |
| 2788 |
| 2789 // Set up entropy context depending on frame type. The decoder mandates |
| 2790 // the use of the default context, index 0, for keyframes and inter |
| 2791 // frames where the error_resilient_mode or intra_only flag is set. For |
| 2792 // other inter-frames the encoder currently uses only two contexts; |
| 2793 // context 1 for ALTREF frames and context 0 for the others. |
| 2794 if (cm->frame_type == KEY_FRAME) { |
| 2795 vp9_setup_key_frame(cpi); |
| 2796 } else { |
| 2797 if (!cm->intra_only && !cm->error_resilient_mode) { |
| 2798 cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame; |
| 2799 } |
| 2800 vp9_setup_inter_frame(cpi); |
| 2801 } |
| 2802 // Variance adaptive and in frame q adjustment experiments are mutually |
| 2803 // exclusive. |
| 2804 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
| 2805 vp9_vaq_frame_setup(cpi); |
| 2806 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| 2807 setup_in_frame_q_adj(cpi); |
| 2808 } |
| 2809 // transform / motion compensation build reconstruction frame |
| 2810 vp9_encode_frame(cpi); |
| 2811 |
| 2812 // Update the skip mb flag probabilities based on the distribution |
| 2813 // seen in the last encoder iteration. |
| 2814 // update_base_skip_probs(cpi); |
| 2815 vp9_clear_system_state(); // __asm emms; |
| 2816 } |
| 2817 |
| 2675 static void encode_with_recode_loop(VP9_COMP *cpi, | 2818 static void encode_with_recode_loop(VP9_COMP *cpi, |
| 2676 size_t *size, | 2819 size_t *size, |
| 2677 uint8_t *dest, | 2820 uint8_t *dest, |
| 2678 int *q, | 2821 int q, |
| 2679 int bottom_index, | 2822 int bottom_index, |
| 2680 int top_index, | 2823 int top_index) { |
| 2681 int frame_over_shoot_limit, | |
| 2682 int frame_under_shoot_limit) { | |
| 2683 VP9_COMMON *const cm = &cpi->common; | 2824 VP9_COMMON *const cm = &cpi->common; |
| 2684 int loop_count = 0; | 2825 int loop_count = 0; |
| 2685 int loop = 0; | 2826 int loop = 0; |
| 2686 int overshoot_seen = 0; | 2827 int overshoot_seen = 0; |
| 2687 int undershoot_seen = 0; | 2828 int undershoot_seen = 0; |
| 2688 int q_low = bottom_index, q_high = top_index; | 2829 int q_low = bottom_index, q_high = top_index; |
| 2830 int frame_over_shoot_limit; |
| 2831 int frame_under_shoot_limit; |
| 2832 |
| 2833 // Decide frame size bounds |
| 2834 vp9_rc_compute_frame_size_bounds(cpi, cpi->rc.this_frame_target, |
| 2835 &frame_under_shoot_limit, |
| 2836 &frame_over_shoot_limit); |
| 2689 | 2837 |
| 2690 do { | 2838 do { |
| 2691 vp9_clear_system_state(); // __asm emms; | 2839 vp9_clear_system_state(); // __asm emms; |
| 2692 | 2840 |
| 2693 vp9_set_quantizer(cpi, *q); | 2841 vp9_set_quantizer(cpi, q); |
| 2694 | 2842 |
| 2695 if (loop_count == 0) { | 2843 if (loop_count == 0) { |
| 2696 // Set up entropy context depending on frame type. The decoder mandates | 2844 // Set up entropy context depending on frame type. The decoder mandates |
| 2697 // the use of the default context, index 0, for keyframes and inter | 2845 // the use of the default context, index 0, for keyframes and inter |
| 2698 // frames where the error_resilient_mode or intra_only flag is set. For | 2846 // frames where the error_resilient_mode or intra_only flag is set. For |
| 2699 // other inter-frames the encoder currently uses only two contexts; | 2847 // other inter-frames the encoder currently uses only two contexts; |
| 2700 // context 1 for ALTREF frames and context 0 for the others. | 2848 // context 1 for ALTREF frames and context 0 for the others. |
| 2701 if (cm->frame_type == KEY_FRAME) { | 2849 if (cm->frame_type == KEY_FRAME) { |
| 2702 vp9_setup_key_frame(cpi); | 2850 vp9_setup_key_frame(cpi); |
| 2703 } else { | 2851 } else { |
| 2704 if (!cm->intra_only && !cm->error_resilient_mode) { | 2852 if (!cm->intra_only && !cm->error_resilient_mode) { |
| 2705 cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame; | 2853 cpi->common.frame_context_idx = cpi->refresh_alt_ref_frame; |
| 2706 } | 2854 } |
| 2707 vp9_setup_inter_frame(cpi); | 2855 vp9_setup_inter_frame(cpi); |
| 2708 } | 2856 } |
| 2709 } | 2857 } |
| 2710 | 2858 |
| 2711 // Variance adaptive and in frame q adjustment experiments are mutually | 2859 // Variance adaptive and in frame q adjustment experiments are mutually |
| 2712 // exclusive. | 2860 // exclusive. |
| 2713 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 2861 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
| 2714 vp9_vaq_frame_setup(cpi); | 2862 vp9_vaq_frame_setup(cpi); |
| 2715 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 2863 } else if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| 2716 setup_in_frame_q_adj(cpi); | 2864 setup_in_frame_q_adj(cpi); |
| 2717 } | 2865 } |
| 2718 | 2866 |
| 2719 // transform / motion compensation build reconstruction frame | 2867 // transform / motion compensation build reconstruction frame |
| 2720 | |
| 2721 vp9_encode_frame(cpi); | 2868 vp9_encode_frame(cpi); |
| 2722 | 2869 |
| 2723 // Update the skip mb flag probabilities based on the distribution | 2870 // Update the skip mb flag probabilities based on the distribution |
| 2724 // seen in the last encoder iteration. | 2871 // seen in the last encoder iteration. |
| 2725 // update_base_skip_probs(cpi); | 2872 // update_base_skip_probs(cpi); |
| 2726 | 2873 |
| 2727 vp9_clear_system_state(); // __asm emms; | 2874 vp9_clear_system_state(); // __asm emms; |
| 2728 | 2875 |
| 2729 // Dummy pack of the bitstream using up to date stats to get an | 2876 // Dummy pack of the bitstream using up to date stats to get an |
| 2730 // accurate estimate of output frame size to determine if we need | 2877 // accurate estimate of output frame size to determine if we need |
| 2731 // to recode. | 2878 // to recode. |
| 2732 if (cpi->sf.recode_loop != 0) { | 2879 if (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) { |
| 2733 vp9_save_coding_context(cpi); | 2880 vp9_save_coding_context(cpi); |
| 2734 cpi->dummy_packing = 1; | 2881 cpi->dummy_packing = 1; |
| 2735 vp9_pack_bitstream(cpi, dest, size); | 2882 if (!cpi->sf.use_pick_mode) |
| 2883 vp9_pack_bitstream(cpi, dest, size); |
| 2884 |
| 2736 cpi->rc.projected_frame_size = (*size) << 3; | 2885 cpi->rc.projected_frame_size = (*size) << 3; |
| 2737 vp9_restore_coding_context(cpi); | 2886 vp9_restore_coding_context(cpi); |
| 2738 | 2887 |
| 2739 if (frame_over_shoot_limit == 0) | 2888 if (frame_over_shoot_limit == 0) |
| 2740 frame_over_shoot_limit = 1; | 2889 frame_over_shoot_limit = 1; |
| 2741 } | 2890 } |
| 2742 | 2891 |
| 2743 if (cpi->oxcf.end_usage == USAGE_CONSTANT_QUALITY) { | 2892 if (cpi->oxcf.end_usage == USAGE_CONSTANT_QUALITY) { |
| 2744 loop = 0; | 2893 loop = 0; |
| 2745 } else { | 2894 } else { |
| 2746 if ((cm->frame_type == KEY_FRAME) && | 2895 if ((cm->frame_type == KEY_FRAME) && |
| 2747 cpi->rc.this_key_frame_forced && | 2896 cpi->rc.this_key_frame_forced && |
| 2748 (cpi->rc.projected_frame_size < cpi->rc.max_frame_bandwidth)) { | 2897 (cpi->rc.projected_frame_size < cpi->rc.max_frame_bandwidth)) { |
| 2749 int last_q = *q; | 2898 int last_q = q; |
| 2750 int kf_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); | 2899 int kf_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); |
| 2751 | 2900 |
| 2752 int high_err_target = cpi->ambient_err; | 2901 int high_err_target = cpi->ambient_err; |
| 2753 int low_err_target = cpi->ambient_err >> 1; | 2902 int low_err_target = cpi->ambient_err >> 1; |
| 2754 | 2903 |
| 2755 // Prevent possible divide by zero error below for perfect KF | 2904 // Prevent possible divide by zero error below for perfect KF |
| 2756 kf_err += !kf_err; | 2905 kf_err += !kf_err; |
| 2757 | 2906 |
| 2758 // The key frame is not good enough or we can afford | 2907 // The key frame is not good enough or we can afford |
| 2759 // to make it better without undue risk of popping. | 2908 // to make it better without undue risk of popping. |
| 2760 if ((kf_err > high_err_target && | 2909 if ((kf_err > high_err_target && |
| 2761 cpi->rc.projected_frame_size <= frame_over_shoot_limit) || | 2910 cpi->rc.projected_frame_size <= frame_over_shoot_limit) || |
| 2762 (kf_err > low_err_target && | 2911 (kf_err > low_err_target && |
| 2763 cpi->rc.projected_frame_size <= frame_under_shoot_limit)) { | 2912 cpi->rc.projected_frame_size <= frame_under_shoot_limit)) { |
| 2764 // Lower q_high | 2913 // Lower q_high |
| 2765 q_high = *q > q_low ? *q - 1 : q_low; | 2914 q_high = q > q_low ? q - 1 : q_low; |
| 2766 | 2915 |
| 2767 // Adjust Q | 2916 // Adjust Q |
| 2768 *q = ((*q) * high_err_target) / kf_err; | 2917 q = (q * high_err_target) / kf_err; |
| 2769 *q = MIN((*q), (q_high + q_low) >> 1); | 2918 q = MIN(q, (q_high + q_low) >> 1); |
| 2770 } else if (kf_err < low_err_target && | 2919 } else if (kf_err < low_err_target && |
| 2771 cpi->rc.projected_frame_size >= frame_under_shoot_limit) { | 2920 cpi->rc.projected_frame_size >= frame_under_shoot_limit) { |
| 2772 // The key frame is much better than the previous frame | 2921 // The key frame is much better than the previous frame |
| 2773 // Raise q_low | 2922 // Raise q_low |
| 2774 q_low = *q < q_high ? *q + 1 : q_high; | 2923 q_low = q < q_high ? q + 1 : q_high; |
| 2775 | 2924 |
| 2776 // Adjust Q | 2925 // Adjust Q |
| 2777 *q = ((*q) * low_err_target) / kf_err; | 2926 q = (q * low_err_target) / kf_err; |
| 2778 *q = MIN((*q), (q_high + q_low + 1) >> 1); | 2927 q = MIN(q, (q_high + q_low + 1) >> 1); |
| 2779 } | 2928 } |
| 2780 | 2929 |
| 2781 // Clamp Q to upper and lower limits: | 2930 // Clamp Q to upper and lower limits: |
| 2782 *q = clamp(*q, q_low, q_high); | 2931 q = clamp(q, q_low, q_high); |
| 2783 | 2932 |
| 2784 loop = *q != last_q; | 2933 loop = q != last_q; |
| 2785 } else if (recode_loop_test( | 2934 } else if (recode_loop_test( |
| 2786 cpi, frame_over_shoot_limit, frame_under_shoot_limit, | 2935 cpi, frame_over_shoot_limit, frame_under_shoot_limit, |
| 2787 *q, MAX(q_high, top_index), bottom_index)) { | 2936 q, MAX(q_high, top_index), bottom_index)) { |
| 2788 // Is the projected frame size out of range and are we allowed | 2937 // Is the projected frame size out of range and are we allowed |
| 2789 // to attempt to recode. | 2938 // to attempt to recode. |
| 2790 int last_q = *q; | 2939 int last_q = q; |
| 2791 int retries = 0; | 2940 int retries = 0; |
| 2792 | 2941 |
| 2793 // Frame size out of permitted range: | 2942 // Frame size out of permitted range: |
| 2794 // Update correction factor & compute new Q to try... | 2943 // Update correction factor & compute new Q to try... |
| 2795 | 2944 |
| 2796 // Frame is too large | 2945 // Frame is too large |
| 2797 if (cpi->rc.projected_frame_size > cpi->rc.this_frame_target) { | 2946 if (cpi->rc.projected_frame_size > cpi->rc.this_frame_target) { |
| 2798 // Special case if the projected size is > the max allowed. | 2947 // Special case if the projected size is > the max allowed. |
| 2799 if (cpi->rc.projected_frame_size >= cpi->rc.max_frame_bandwidth) | 2948 if (cpi->rc.projected_frame_size >= cpi->rc.max_frame_bandwidth) |
| 2800 q_high = cpi->rc.worst_quality; | 2949 q_high = cpi->rc.worst_quality; |
| 2801 | 2950 |
| 2802 // Raise Qlow as to at least the current value | 2951 // Raise Qlow as to at least the current value |
| 2803 q_low = *q < q_high ? *q + 1 : q_high; | 2952 q_low = q < q_high ? q + 1 : q_high; |
| 2804 | 2953 |
| 2805 if (undershoot_seen || loop_count > 1) { | 2954 if (undershoot_seen || loop_count > 1) { |
| 2806 // Update rate_correction_factor unless | 2955 // Update rate_correction_factor unless |
| 2807 vp9_rc_update_rate_correction_factors(cpi, 1); | 2956 vp9_rc_update_rate_correction_factors(cpi, 1); |
| 2808 | 2957 |
| 2809 *q = (q_high + q_low + 1) / 2; | 2958 q = (q_high + q_low + 1) / 2; |
| 2810 } else { | 2959 } else { |
| 2811 // Update rate_correction_factor unless | 2960 // Update rate_correction_factor unless |
| 2812 vp9_rc_update_rate_correction_factors(cpi, 0); | 2961 vp9_rc_update_rate_correction_factors(cpi, 0); |
| 2813 | 2962 |
| 2814 *q = vp9_rc_regulate_q(cpi, cpi->rc.this_frame_target, | 2963 q = vp9_rc_regulate_q(cpi, cpi->rc.this_frame_target, |
| 2815 bottom_index, MAX(q_high, top_index)); | 2964 bottom_index, MAX(q_high, top_index)); |
| 2816 | 2965 |
| 2817 while (*q < q_low && retries < 10) { | 2966 while (q < q_low && retries < 10) { |
| 2818 vp9_rc_update_rate_correction_factors(cpi, 0); | 2967 vp9_rc_update_rate_correction_factors(cpi, 0); |
| 2819 *q = vp9_rc_regulate_q(cpi, cpi->rc.this_frame_target, | 2968 q = vp9_rc_regulate_q(cpi, cpi->rc.this_frame_target, |
| 2820 bottom_index, MAX(q_high, top_index)); | 2969 bottom_index, MAX(q_high, top_index)); |
| 2821 retries++; | 2970 retries++; |
| 2822 } | 2971 } |
| 2823 } | 2972 } |
| 2824 | 2973 |
| 2825 overshoot_seen = 1; | 2974 overshoot_seen = 1; |
| 2826 } else { | 2975 } else { |
| 2827 // Frame is too small | 2976 // Frame is too small |
| 2828 q_high = *q > q_low ? *q - 1 : q_low; | 2977 q_high = q > q_low ? q - 1 : q_low; |
| 2829 | 2978 |
| 2830 if (overshoot_seen || loop_count > 1) { | 2979 if (overshoot_seen || loop_count > 1) { |
| 2831 vp9_rc_update_rate_correction_factors(cpi, 1); | 2980 vp9_rc_update_rate_correction_factors(cpi, 1); |
| 2832 *q = (q_high + q_low) / 2; | 2981 q = (q_high + q_low) / 2; |
| 2833 } else { | 2982 } else { |
| 2834 vp9_rc_update_rate_correction_factors(cpi, 0); | 2983 vp9_rc_update_rate_correction_factors(cpi, 0); |
| 2835 *q = vp9_rc_regulate_q(cpi, cpi->rc.this_frame_target, | 2984 q = vp9_rc_regulate_q(cpi, cpi->rc.this_frame_target, |
| 2836 bottom_index, top_index); | 2985 bottom_index, top_index); |
| 2837 // Special case reset for qlow for constrained quality. | 2986 // Special case reset for qlow for constrained quality. |
| 2838 // This should only trigger where there is very substantial | 2987 // This should only trigger where there is very substantial |
| 2839 // undershoot on a frame and the auto cq level is above | 2988 // undershoot on a frame and the auto cq level is above |
| 2840 // the user passsed in value. | 2989 // the user passsed in value. |
| 2841 if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY && | 2990 if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY && |
| 2842 *q < q_low) { | 2991 q < q_low) { |
| 2843 q_low = *q; | 2992 q_low = q; |
| 2844 } | 2993 } |
| 2845 | 2994 |
| 2846 while (*q > q_high && retries < 10) { | 2995 while (q > q_high && retries < 10) { |
| 2847 vp9_rc_update_rate_correction_factors(cpi, 0); | 2996 vp9_rc_update_rate_correction_factors(cpi, 0); |
| 2848 *q = vp9_rc_regulate_q(cpi, cpi->rc.this_frame_target, | 2997 q = vp9_rc_regulate_q(cpi, cpi->rc.this_frame_target, |
| 2849 bottom_index, top_index); | 2998 bottom_index, top_index); |
| 2850 retries++; | 2999 retries++; |
| 2851 } | 3000 } |
| 2852 } | 3001 } |
| 2853 | 3002 |
| 2854 undershoot_seen = 1; | 3003 undershoot_seen = 1; |
| 2855 } | 3004 } |
| 2856 | 3005 |
| 2857 // Clamp Q to upper and lower limits: | 3006 // Clamp Q to upper and lower limits: |
| 2858 *q = clamp(*q, q_low, q_high); | 3007 q = clamp(q, q_low, q_high); |
| 2859 | 3008 |
| 2860 loop = *q != last_q; | 3009 loop = q != last_q; |
| 2861 } else { | 3010 } else { |
| 2862 loop = 0; | 3011 loop = 0; |
| 2863 } | 3012 } |
| 2864 } | 3013 } |
| 2865 | 3014 |
| 2866 // Special case for overlay frame. | 3015 // Special case for overlay frame. |
| 2867 if (cpi->rc.is_src_frame_alt_ref && | 3016 if (cpi->rc.is_src_frame_alt_ref && |
| 2868 (cpi->rc.projected_frame_size < cpi->rc.max_frame_bandwidth)) | 3017 (cpi->rc.projected_frame_size < cpi->rc.max_frame_bandwidth)) |
| 2869 loop = 0; | 3018 loop = 0; |
| 2870 | 3019 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2923 } | 3072 } |
| 2924 } | 3073 } |
| 2925 | 3074 |
| 2926 static void encode_frame_to_data_rate(VP9_COMP *cpi, | 3075 static void encode_frame_to_data_rate(VP9_COMP *cpi, |
| 2927 size_t *size, | 3076 size_t *size, |
| 2928 uint8_t *dest, | 3077 uint8_t *dest, |
| 2929 unsigned int *frame_flags) { | 3078 unsigned int *frame_flags) { |
| 2930 VP9_COMMON *const cm = &cpi->common; | 3079 VP9_COMMON *const cm = &cpi->common; |
| 2931 TX_SIZE t; | 3080 TX_SIZE t; |
| 2932 int q; | 3081 int q; |
| 2933 int frame_over_shoot_limit; | |
| 2934 int frame_under_shoot_limit; | |
| 2935 int top_index; | 3082 int top_index; |
| 2936 int bottom_index; | 3083 int bottom_index; |
| 2937 | 3084 |
| 2938 SPEED_FEATURES *const sf = &cpi->sf; | 3085 SPEED_FEATURES *const sf = &cpi->sf; |
| 2939 unsigned int max_mv_def = MIN(cpi->common.width, cpi->common.height); | 3086 unsigned int max_mv_def = MIN(cm->width, cm->height); |
| 2940 struct segmentation *const seg = &cm->seg; | 3087 struct segmentation *const seg = &cm->seg; |
| 2941 | 3088 |
| 2942 set_ext_overrides(cpi); | 3089 set_ext_overrides(cpi); |
| 2943 | 3090 |
| 2944 /* Scale the source buffer, if required. */ | 3091 /* Scale the source buffer, if required. */ |
| 2945 if (cm->mi_cols * 8 != cpi->un_scaled_source->y_width || | 3092 if (cm->mi_cols * MI_SIZE != cpi->un_scaled_source->y_width || |
| 2946 cm->mi_rows * 8 != cpi->un_scaled_source->y_height) { | 3093 cm->mi_rows * MI_SIZE != cpi->un_scaled_source->y_height) { |
| 2947 scale_and_extend_frame_nonnormative(cpi->un_scaled_source, | 3094 scale_and_extend_frame_nonnormative(cpi->un_scaled_source, |
| 2948 &cpi->scaled_source); | 3095 &cpi->scaled_source); |
| 2949 cpi->Source = &cpi->scaled_source; | 3096 cpi->Source = &cpi->scaled_source; |
| 2950 } else { | 3097 } else { |
| 2951 cpi->Source = cpi->un_scaled_source; | 3098 cpi->Source = cpi->un_scaled_source; |
| 2952 } | 3099 } |
| 2953 scale_references(cpi); | 3100 scale_references(cpi); |
| 2954 | 3101 |
| 2955 // Clear down mmx registers to allow floating point in what follows. | |
| 2956 vp9_clear_system_state(); | 3102 vp9_clear_system_state(); |
| 2957 | 3103 |
| 2958 // For an alt ref frame in 2 pass we skip the call to the second | |
| 2959 // pass function that sets the target bandwidth so we must set it here. | |
| 2960 if (cpi->refresh_alt_ref_frame) { | |
| 2961 // Set a per frame bit target for the alt ref frame. | |
| 2962 cpi->rc.per_frame_bandwidth = cpi->twopass.gf_bits; | |
| 2963 // Set a per second target bitrate. | |
| 2964 cpi->target_bandwidth = (int)(cpi->twopass.gf_bits * cpi->output_framerate); | |
| 2965 } | |
| 2966 | |
| 2967 // Clear zbin over-quant value and mode boost values. | |
| 2968 cpi->zbin_mode_boost = 0; | |
| 2969 | |
| 2970 // Enable or disable mode based tweaking of the zbin. | 3104 // Enable or disable mode based tweaking of the zbin. |
| 2971 // For 2 pass only used where GF/ARF prediction quality | 3105 // For 2 pass only used where GF/ARF prediction quality |
| 2972 // is above a threshold. | 3106 // is above a threshold. |
| 2973 cpi->zbin_mode_boost = 0; | 3107 cpi->zbin_mode_boost = 0; |
| 2974 cpi->zbin_mode_boost_enabled = 0; | 3108 cpi->zbin_mode_boost_enabled = 0; |
| 2975 | 3109 |
| 2976 // Current default encoder behavior for the altref sign bias. | 3110 // Current default encoder behavior for the altref sign bias. |
| 2977 cpi->common.ref_frame_sign_bias[ALTREF_FRAME] = cpi->rc.source_alt_ref_active; | 3111 cm->ref_frame_sign_bias[ALTREF_FRAME] = cpi->rc.source_alt_ref_active; |
| 2978 | 3112 |
| 2979 // Set default state for segment based loop filter update flags. | 3113 // Set default state for segment based loop filter update flags. |
| 2980 cm->lf.mode_ref_delta_update = 0; | 3114 cm->lf.mode_ref_delta_update = 0; |
| 2981 | 3115 |
| 2982 // Initialize cpi->mv_step_param to default based on max resolution. | 3116 // Initialize cpi->mv_step_param to default based on max resolution. |
| 2983 cpi->mv_step_param = vp9_init_search_range(cpi, max_mv_def); | 3117 cpi->mv_step_param = vp9_init_search_range(cpi, max_mv_def); |
| 2984 // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate. | 3118 // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate. |
| 2985 if (sf->auto_mv_step_size) { | 3119 if (sf->auto_mv_step_size) { |
| 2986 if (frame_is_intra_only(&cpi->common)) { | 3120 if (frame_is_intra_only(cm)) { |
| 2987 // Initialize max_mv_magnitude for use in the first INTER frame | 3121 // Initialize max_mv_magnitude for use in the first INTER frame |
| 2988 // after a key/intra-only frame. | 3122 // after a key/intra-only frame. |
| 2989 cpi->max_mv_magnitude = max_mv_def; | 3123 cpi->max_mv_magnitude = max_mv_def; |
| 2990 } else { | 3124 } else { |
| 2991 if (cm->show_frame) | 3125 if (cm->show_frame) |
| 2992 // Allow mv_steps to correspond to twice the max mv magnitude found | 3126 // Allow mv_steps to correspond to twice the max mv magnitude found |
| 2993 // in the previous frame, capped by the default max_mv_magnitude based | 3127 // in the previous frame, capped by the default max_mv_magnitude based |
| 2994 // on resolution. | 3128 // on resolution. |
| 2995 cpi->mv_step_param = vp9_init_search_range( | 3129 cpi->mv_step_param = vp9_init_search_range(cpi, MIN(max_mv_def, 2 * |
| 2996 cpi, MIN(max_mv_def, 2 * cpi->max_mv_magnitude)); | 3130 cpi->max_mv_magnitude)); |
| 2997 cpi->max_mv_magnitude = 0; | 3131 cpi->max_mv_magnitude = 0; |
| 2998 } | 3132 } |
| 2999 } | 3133 } |
| 3000 | 3134 |
| 3001 // Set various flags etc to special state if it is a key frame. | 3135 // Set various flags etc to special state if it is a key frame. |
| 3002 if (frame_is_intra_only(cm)) { | 3136 if (frame_is_intra_only(cm)) { |
| 3003 vp9_setup_key_frame(cpi); | 3137 vp9_setup_key_frame(cpi); |
| 3004 // Reset the loop filter deltas and segmentation map. | 3138 // Reset the loop filter deltas and segmentation map. |
| 3005 vp9_reset_segment_features(&cm->seg); | 3139 vp9_reset_segment_features(&cm->seg); |
| 3006 | 3140 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3023 } else if (cm->intra_only) { | 3157 } else if (cm->intra_only) { |
| 3024 // Only reset the current context. | 3158 // Only reset the current context. |
| 3025 cm->reset_frame_context = 2; | 3159 cm->reset_frame_context = 2; |
| 3026 } | 3160 } |
| 3027 } | 3161 } |
| 3028 | 3162 |
| 3029 // Configure experimental use of segmentation for enhanced coding of | 3163 // Configure experimental use of segmentation for enhanced coding of |
| 3030 // static regions if indicated. | 3164 // static regions if indicated. |
| 3031 // Only allowed in second pass of two pass (as requires lagged coding) | 3165 // Only allowed in second pass of two pass (as requires lagged coding) |
| 3032 // and if the relevant speed feature flag is set. | 3166 // and if the relevant speed feature flag is set. |
| 3033 if ((cpi->pass == 2) && (cpi->sf.static_segmentation)) { | 3167 if (cpi->pass == 2 && cpi->sf.static_segmentation) |
| 3034 configure_static_seg_features(cpi); | 3168 configure_static_seg_features(cpi); |
| 3035 } | |
| 3036 | 3169 |
| 3037 // For 1 pass CBR, check if we are dropping this frame. | 3170 // For 1 pass CBR, check if we are dropping this frame. |
| 3038 // Never drop on key frame. | 3171 // Never drop on key frame. |
| 3039 if (cpi->pass == 0 && | 3172 if (cpi->pass == 0 && |
| 3040 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER && | 3173 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER && |
| 3041 cm->frame_type != KEY_FRAME) { | 3174 cm->frame_type != KEY_FRAME) { |
| 3042 if (vp9_drop_frame(cpi)) { | 3175 if (vp9_rc_drop_frame(cpi)) { |
| 3043 // Update buffer level with zero size, update frame counters, and return. | |
| 3044 vp9_update_buffer_level(cpi, 0); | |
| 3045 cm->last_frame_type = cm->frame_type; | |
| 3046 vp9_rc_postencode_update_drop_frame(cpi); | 3176 vp9_rc_postencode_update_drop_frame(cpi); |
| 3047 cm->current_video_frame++; | 3177 ++cm->current_video_frame; |
| 3048 return; | 3178 return; |
| 3049 } | 3179 } |
| 3050 } | 3180 } |
| 3051 | 3181 |
| 3052 vp9_clear_system_state(); | 3182 vp9_clear_system_state(); |
| 3053 | 3183 |
| 3054 vp9_zero(cpi->rd_tx_select_threshes); | 3184 vp9_zero(cpi->rd_tx_select_threshes); |
| 3055 | 3185 |
| 3056 #if CONFIG_VP9_POSTPROC | 3186 #if CONFIG_VP9_POSTPROC |
| 3057 if (cpi->oxcf.noise_sensitivity > 0) { | 3187 if (cpi->oxcf.noise_sensitivity > 0) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 3075 break; | 3205 break; |
| 3076 } | 3206 } |
| 3077 vp9_denoise(cpi->Source, cpi->Source, l); | 3207 vp9_denoise(cpi->Source, cpi->Source, l); |
| 3078 } | 3208 } |
| 3079 #endif | 3209 #endif |
| 3080 | 3210 |
| 3081 #ifdef OUTPUT_YUV_SRC | 3211 #ifdef OUTPUT_YUV_SRC |
| 3082 vp9_write_yuv_frame(cpi->Source); | 3212 vp9_write_yuv_frame(cpi->Source); |
| 3083 #endif | 3213 #endif |
| 3084 | 3214 |
| 3085 // Decide how big to make the frame. | 3215 // Decide q and q bounds. |
| 3086 vp9_rc_pick_frame_size_target(cpi); | 3216 q = vp9_rc_pick_q_and_bounds(cpi, &bottom_index, &top_index); |
| 3087 | |
| 3088 // Decide frame size bounds | |
| 3089 vp9_rc_compute_frame_size_bounds(cpi, cpi->rc.this_frame_target, | |
| 3090 &frame_under_shoot_limit, | |
| 3091 &frame_over_shoot_limit); | |
| 3092 | |
| 3093 // Decide q and q bounds | |
| 3094 q = vp9_rc_pick_q_and_adjust_q_bounds(cpi, | |
| 3095 &bottom_index, | |
| 3096 &top_index); | |
| 3097 | 3217 |
| 3098 if (!frame_is_intra_only(cm)) { | 3218 if (!frame_is_intra_only(cm)) { |
| 3099 cm->interp_filter = DEFAULT_INTERP_FILTER; | 3219 cm->interp_filter = DEFAULT_INTERP_FILTER; |
| 3100 /* TODO: Decide this more intelligently */ | 3220 /* TODO: Decide this more intelligently */ |
| 3101 set_high_precision_mv(cpi, (q < HIGH_PRECISION_MV_QTHRESH)); | 3221 set_high_precision_mv(cpi, (q < HIGH_PRECISION_MV_QTHRESH)); |
| 3102 } | 3222 } |
| 3103 | 3223 |
| 3104 encode_with_recode_loop(cpi, | 3224 if (cpi->sf.recode_loop == DISALLOW_RECODE) { |
| 3105 size, | 3225 encode_without_recode_loop(cpi, size, dest, q); |
| 3106 dest, | 3226 } else { |
| 3107 &q, | 3227 encode_with_recode_loop(cpi, size, dest, q, bottom_index, top_index); |
| 3108 bottom_index, | 3228 } |
| 3109 top_index, | |
| 3110 frame_over_shoot_limit, | |
| 3111 frame_under_shoot_limit); | |
| 3112 | 3229 |
| 3113 // Special case code to reduce pulsing when key frames are forced at a | 3230 // Special case code to reduce pulsing when key frames are forced at a |
| 3114 // fixed interval. Note the reconstruction error if it is the frame before | 3231 // fixed interval. Note the reconstruction error if it is the frame before |
| 3115 // the force key frame | 3232 // the force key frame |
| 3116 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { | 3233 if (cpi->rc.next_key_frame_forced && cpi->rc.frames_to_key == 1) { |
| 3117 cpi->ambient_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); | 3234 cpi->ambient_err = vp9_calc_ss_err(cpi->Source, get_frame_new_buffer(cm)); |
| 3118 } | 3235 } |
| 3119 | 3236 |
| 3120 // If the encoder forced a KEY_FRAME decision | 3237 // If the encoder forced a KEY_FRAME decision |
| 3121 if (cm->frame_type == KEY_FRAME) | 3238 if (cm->frame_type == KEY_FRAME) |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3148 cpi->dummy_packing = 0; | 3265 cpi->dummy_packing = 0; |
| 3149 vp9_pack_bitstream(cpi, dest, size); | 3266 vp9_pack_bitstream(cpi, dest, size); |
| 3150 | 3267 |
| 3151 if (cm->seg.update_map) | 3268 if (cm->seg.update_map) |
| 3152 update_reference_segmentation_map(cpi); | 3269 update_reference_segmentation_map(cpi); |
| 3153 | 3270 |
| 3154 release_scaled_references(cpi); | 3271 release_scaled_references(cpi); |
| 3155 update_reference_frames(cpi); | 3272 update_reference_frames(cpi); |
| 3156 | 3273 |
| 3157 for (t = TX_4X4; t <= TX_32X32; t++) | 3274 for (t = TX_4X4; t <= TX_32X32; t++) |
| 3158 full_to_model_counts(cpi->common.counts.coef[t], | 3275 full_to_model_counts(cm->counts.coef[t], cpi->coef_counts[t]); |
| 3159 cpi->coef_counts[t]); | |
| 3160 if (!cpi->common.error_resilient_mode && | |
| 3161 !cpi->common.frame_parallel_decoding_mode) { | |
| 3162 vp9_adapt_coef_probs(&cpi->common); | |
| 3163 } | |
| 3164 | 3276 |
| 3165 if (!frame_is_intra_only(&cpi->common)) { | 3277 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) |
| 3166 if (!cpi->common.error_resilient_mode && | 3278 vp9_adapt_coef_probs(cm); |
| 3167 !cpi->common.frame_parallel_decoding_mode) { | 3279 |
| 3168 vp9_adapt_mode_probs(&cpi->common); | 3280 if (!frame_is_intra_only(cm)) { |
| 3169 vp9_adapt_mv_probs(&cpi->common, cpi->common.allow_high_precision_mv); | 3281 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { |
| 3282 vp9_adapt_mode_probs(cm); |
| 3283 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
| 3170 } | 3284 } |
| 3171 } | 3285 } |
| 3172 | 3286 |
| 3173 #ifdef ENTROPY_STATS | |
| 3174 vp9_update_mode_context_stats(cpi); | |
| 3175 #endif | |
| 3176 | |
| 3177 /* Move storing frame_type out of the above loop since it is also | |
| 3178 * needed in motion search besides loopfilter */ | |
| 3179 cm->last_frame_type = cm->frame_type; | |
| 3180 | |
| 3181 #if 0 | 3287 #if 0 |
| 3182 output_frame_level_debug_stats(cpi); | 3288 output_frame_level_debug_stats(cpi); |
| 3183 #endif | 3289 #endif |
| 3184 if (cpi->refresh_golden_frame == 1) | 3290 if (cpi->refresh_golden_frame == 1) |
| 3185 cm->frame_flags = cm->frame_flags | FRAMEFLAGS_GOLDEN; | 3291 cm->frame_flags |= FRAMEFLAGS_GOLDEN; |
| 3186 else | 3292 else |
| 3187 cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_GOLDEN; | 3293 cm->frame_flags &= ~FRAMEFLAGS_GOLDEN; |
| 3188 | 3294 |
| 3189 if (cpi->refresh_alt_ref_frame == 1) | 3295 if (cpi->refresh_alt_ref_frame == 1) |
| 3190 cm->frame_flags = cm->frame_flags | FRAMEFLAGS_ALTREF; | 3296 cm->frame_flags |= FRAMEFLAGS_ALTREF; |
| 3191 else | 3297 else |
| 3192 cm->frame_flags = cm->frame_flags&~FRAMEFLAGS_ALTREF; | 3298 cm->frame_flags &= ~FRAMEFLAGS_ALTREF; |
| 3193 | 3299 |
| 3194 get_ref_frame_flags(cpi); | 3300 get_ref_frame_flags(cpi); |
| 3195 | 3301 |
| 3196 vp9_rc_postencode_update(cpi, *size); | 3302 vp9_rc_postencode_update(cpi, *size); |
| 3197 | 3303 |
| 3198 if (cm->frame_type == KEY_FRAME) { | 3304 if (cm->frame_type == KEY_FRAME) { |
| 3199 // Tell the caller that the frame was coded as a key frame | 3305 // Tell the caller that the frame was coded as a key frame |
| 3200 *frame_flags = cm->frame_flags | FRAMEFLAGS_KEY; | 3306 *frame_flags = cm->frame_flags | FRAMEFLAGS_KEY; |
| 3201 | 3307 |
| 3202 #if CONFIG_MULTIPLE_ARF | 3308 #if CONFIG_MULTIPLE_ARF |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3229 // filter deltas. | 3335 // filter deltas. |
| 3230 cm->seg.update_map = 0; | 3336 cm->seg.update_map = 0; |
| 3231 cm->seg.update_data = 0; | 3337 cm->seg.update_data = 0; |
| 3232 cm->lf.mode_ref_delta_update = 0; | 3338 cm->lf.mode_ref_delta_update = 0; |
| 3233 | 3339 |
| 3234 // keep track of the last coded dimensions | 3340 // keep track of the last coded dimensions |
| 3235 cm->last_width = cm->width; | 3341 cm->last_width = cm->width; |
| 3236 cm->last_height = cm->height; | 3342 cm->last_height = cm->height; |
| 3237 | 3343 |
| 3238 // reset to normal state now that we are done. | 3344 // reset to normal state now that we are done. |
| 3239 cm->last_show_frame = cm->show_frame; | 3345 if (!cm->show_existing_frame) |
| 3346 cm->last_show_frame = cm->show_frame; |
| 3347 |
| 3240 if (cm->show_frame) { | 3348 if (cm->show_frame) { |
| 3241 // current mip will be the prev_mip for the next frame | 3349 // current mip will be the prev_mip for the next frame |
| 3242 MODE_INFO *temp = cm->prev_mip; | 3350 MODE_INFO *temp = cm->prev_mip; |
| 3243 MODE_INFO **temp2 = cm->prev_mi_grid_base; | 3351 MODE_INFO **temp2 = cm->prev_mi_grid_base; |
| 3244 cm->prev_mip = cm->mip; | 3352 cm->prev_mip = cm->mip; |
| 3245 cm->mip = temp; | 3353 cm->mip = temp; |
| 3246 cm->prev_mi_grid_base = cm->mi_grid_base; | 3354 cm->prev_mi_grid_base = cm->mi_grid_base; |
| 3247 cm->mi_grid_base = temp2; | 3355 cm->mi_grid_base = temp2; |
| 3248 | 3356 |
| 3249 // update the upper left visible macroblock ptrs | 3357 // update the upper left visible macroblock ptrs |
| 3250 cm->mi = cm->mip + cm->mode_info_stride + 1; | 3358 cm->mi = cm->mip + cm->mode_info_stride + 1; |
| 3251 cm->mi_grid_visible = cm->mi_grid_base + cm->mode_info_stride + 1; | 3359 cm->mi_grid_visible = cm->mi_grid_base + cm->mode_info_stride + 1; |
| 3252 | 3360 |
| 3253 cpi->mb.e_mbd.mi_8x8 = cm->mi_grid_visible; | 3361 cpi->mb.e_mbd.mi_8x8 = cm->mi_grid_visible; |
| 3254 cpi->mb.e_mbd.mi_8x8[0] = cm->mi; | 3362 cpi->mb.e_mbd.mi_8x8[0] = cm->mi; |
| 3255 | 3363 |
| 3256 // Don't increment frame counters if this was an altref buffer | 3364 // Don't increment frame counters if this was an altref buffer |
| 3257 // update not a real frame | 3365 // update not a real frame |
| 3258 ++cm->current_video_frame; | 3366 ++cm->current_video_frame; |
| 3259 } | 3367 } |
| 3368 |
| 3260 // restore prev_mi | 3369 // restore prev_mi |
| 3261 cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1; | 3370 cm->prev_mi = cm->prev_mip + cm->mode_info_stride + 1; |
| 3262 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1; | 3371 cm->prev_mi_grid_visible = cm->prev_mi_grid_base + cm->mode_info_stride + 1; |
| 3263 } | 3372 } |
| 3264 | 3373 |
| 3265 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 3374 static void SvcEncode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
| 3266 unsigned int *frame_flags) { | 3375 unsigned int *frame_flags) { |
| 3267 vp9_get_svc_params(cpi); | 3376 vp9_rc_get_svc_params(cpi); |
| 3268 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 3377 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
| 3269 } | 3378 } |
| 3270 | 3379 |
| 3271 static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 3380 static void Pass0Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
| 3272 unsigned int *frame_flags) { | 3381 unsigned int *frame_flags) { |
| 3273 if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { | 3382 if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { |
| 3274 vp9_get_one_pass_cbr_params(cpi); | 3383 vp9_rc_get_one_pass_cbr_params(cpi); |
| 3275 } else { | 3384 } else { |
| 3276 vp9_get_one_pass_params(cpi); | 3385 vp9_rc_get_one_pass_vbr_params(cpi); |
| 3277 } | 3386 } |
| 3278 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 3387 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
| 3279 } | 3388 } |
| 3280 | 3389 |
| 3281 static void Pass1Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, | 3390 static void Pass1Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, |
| 3282 unsigned int *frame_flags) { | 3391 unsigned int *frame_flags) { |
| 3283 (void) size; | 3392 (void) size; |
| 3284 (void) dest; | 3393 (void) dest; |
| 3285 (void) frame_flags; | 3394 (void) frame_flags; |
| 3286 | 3395 |
| 3287 vp9_get_first_pass_params(cpi); | 3396 vp9_rc_get_first_pass_params(cpi); |
| 3288 vp9_set_quantizer(cpi, find_fp_qindex()); | 3397 vp9_set_quantizer(cpi, find_fp_qindex()); |
| 3289 vp9_first_pass(cpi); | 3398 vp9_first_pass(cpi); |
| 3290 } | 3399 } |
| 3291 | 3400 |
| 3292 static void Pass2Encode(VP9_COMP *cpi, size_t *size, | 3401 static void Pass2Encode(VP9_COMP *cpi, size_t *size, |
| 3293 uint8_t *dest, unsigned int *frame_flags) { | 3402 uint8_t *dest, unsigned int *frame_flags) { |
| 3294 cpi->enable_encode_breakout = 1; | 3403 cpi->allow_encode_breakout = ENCODE_BREAKOUT_ENABLED; |
| 3295 | 3404 |
| 3296 vp9_get_second_pass_params(cpi); | 3405 vp9_rc_get_second_pass_params(cpi); |
| 3297 encode_frame_to_data_rate(cpi, size, dest, frame_flags); | 3406 encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
| 3298 // vp9_print_modes_and_motion_vectors(&cpi->common, "encode.stt"); | |
| 3299 | 3407 |
| 3300 vp9_twopass_postencode_update(cpi, *size); | 3408 vp9_twopass_postencode_update(cpi, *size); |
| 3301 } | 3409 } |
| 3302 | 3410 |
| 3303 static void check_initial_width(VP9_COMP *cpi, int subsampling_x, | 3411 static void check_initial_width(VP9_COMP *cpi, int subsampling_x, |
| 3304 int subsampling_y) { | 3412 int subsampling_y) { |
| 3305 VP9_COMMON *const cm = &cpi->common; | 3413 VP9_COMMON *const cm = &cpi->common; |
| 3306 if (!cpi->initial_width) { | 3414 if (!cpi->initial_width) { |
| 3307 cm->subsampling_x = subsampling_x; | 3415 cm->subsampling_x = subsampling_x; |
| 3308 cm->subsampling_y = subsampling_y; | 3416 cm->subsampling_y = subsampling_y; |
| 3309 alloc_raw_frame_buffers(cpi); | 3417 alloc_raw_frame_buffers(cpi); |
| 3310 cpi->initial_width = cm->width; | 3418 cpi->initial_width = cm->width; |
| 3311 cpi->initial_height = cm->height; | 3419 cpi->initial_height = cm->height; |
| 3312 } | 3420 } |
| 3313 } | 3421 } |
| 3314 | 3422 |
| 3315 | 3423 |
| 3316 int vp9_receive_raw_frame(VP9_PTR ptr, unsigned int frame_flags, | 3424 int vp9_receive_raw_frame(VP9_PTR ptr, unsigned int frame_flags, |
| 3317 YV12_BUFFER_CONFIG *sd, int64_t time_stamp, | 3425 YV12_BUFFER_CONFIG *sd, int64_t time_stamp, |
| 3318 int64_t end_time) { | 3426 int64_t end_time) { |
| 3319 VP9_COMP *cpi = (VP9_COMP *) ptr; | 3427 VP9_COMP *cpi = (VP9_COMP *) ptr; |
| 3428 VP9_COMMON *cm = &cpi->common; |
| 3320 struct vpx_usec_timer timer; | 3429 struct vpx_usec_timer timer; |
| 3321 int res = 0; | 3430 int res = 0; |
| 3322 const int subsampling_x = sd->uv_width < sd->y_width; | 3431 const int subsampling_x = sd->uv_width < sd->y_width; |
| 3323 const int subsampling_y = sd->uv_height < sd->y_height; | 3432 const int subsampling_y = sd->uv_height < sd->y_height; |
| 3324 | 3433 |
| 3325 check_initial_width(cpi, subsampling_x, subsampling_y); | 3434 check_initial_width(cpi, subsampling_x, subsampling_y); |
| 3326 vpx_usec_timer_start(&timer); | 3435 vpx_usec_timer_start(&timer); |
| 3327 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags, | 3436 if (vp9_lookahead_push(cpi->lookahead, sd, time_stamp, end_time, frame_flags, |
| 3328 cpi->active_map_enabled ? cpi->active_map : NULL)) | 3437 cpi->active_map_enabled ? cpi->active_map : NULL)) |
| 3329 res = -1; | 3438 res = -1; |
| 3330 vpx_usec_timer_mark(&timer); | 3439 vpx_usec_timer_mark(&timer); |
| 3331 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); | 3440 cpi->time_receive_data += vpx_usec_timer_elapsed(&timer); |
| 3332 | 3441 |
| 3442 if (cm->version == 0 && (subsampling_x != 1 || subsampling_y != 1)) { |
| 3443 vpx_internal_error(&cm->error, VPX_CODEC_INVALID_PARAM, |
| 3444 "Non-4:2:0 color space requires profile >= 1"); |
| 3445 res = -1; |
| 3446 } |
| 3447 |
| 3333 return res; | 3448 return res; |
| 3334 } | 3449 } |
| 3335 | 3450 |
| 3336 | 3451 |
| 3337 static int frame_is_reference(const VP9_COMP *cpi) { | 3452 static int frame_is_reference(const VP9_COMP *cpi) { |
| 3338 const VP9_COMMON *cm = &cpi->common; | 3453 const VP9_COMMON *cm = &cpi->common; |
| 3339 | 3454 |
| 3340 return cm->frame_type == KEY_FRAME || | 3455 return cm->frame_type == KEY_FRAME || |
| 3341 cpi->refresh_last_frame || | 3456 cpi->refresh_last_frame || |
| 3342 cpi->refresh_golden_frame || | 3457 cpi->refresh_golden_frame || |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3438 if ((cpi->source = vp9_lookahead_peek(cpi->lookahead, frames_to_arf))) { | 3553 if ((cpi->source = vp9_lookahead_peek(cpi->lookahead, frames_to_arf))) { |
| 3439 #if CONFIG_MULTIPLE_ARF | 3554 #if CONFIG_MULTIPLE_ARF |
| 3440 cpi->alt_ref_source[cpi->arf_buffered] = cpi->source; | 3555 cpi->alt_ref_source[cpi->arf_buffered] = cpi->source; |
| 3441 #else | 3556 #else |
| 3442 cpi->alt_ref_source = cpi->source; | 3557 cpi->alt_ref_source = cpi->source; |
| 3443 #endif | 3558 #endif |
| 3444 | 3559 |
| 3445 if (cpi->oxcf.arnr_max_frames > 0) { | 3560 if (cpi->oxcf.arnr_max_frames > 0) { |
| 3446 // Produce the filtered ARF frame. | 3561 // Produce the filtered ARF frame. |
| 3447 // TODO(agrange) merge these two functions. | 3562 // TODO(agrange) merge these two functions. |
| 3448 configure_arnr_filter(cpi, cm->current_video_frame + frames_to_arf, | 3563 vp9_configure_arnr_filter(cpi, frames_to_arf, cpi->rc.gfu_boost); |
| 3449 cpi->rc.gfu_boost); | |
| 3450 vp9_temporal_filter_prepare(cpi, frames_to_arf); | 3564 vp9_temporal_filter_prepare(cpi, frames_to_arf); |
| 3451 vp9_extend_frame_borders(&cpi->alt_ref_buffer, | 3565 vp9_extend_frame_borders(&cpi->alt_ref_buffer, |
| 3452 cm->subsampling_x, cm->subsampling_y); | 3566 cm->subsampling_x, cm->subsampling_y); |
| 3453 force_src_buffer = &cpi->alt_ref_buffer; | 3567 force_src_buffer = &cpi->alt_ref_buffer; |
| 3454 } | 3568 } |
| 3455 | 3569 |
| 3456 cm->show_frame = 0; | 3570 cm->show_frame = 0; |
| 3457 cpi->refresh_alt_ref_frame = 1; | 3571 cpi->refresh_alt_ref_frame = 1; |
| 3458 cpi->refresh_golden_frame = 0; | 3572 cpi->refresh_golden_frame = 0; |
| 3459 cpi->refresh_last_frame = 0; | 3573 cpi->refresh_last_frame = 0; |
| 3460 cpi->rc.is_src_frame_alt_ref = 0; | 3574 cpi->rc.is_src_frame_alt_ref = 0; |
| 3461 | 3575 |
| 3462 #if CONFIG_MULTIPLE_ARF | 3576 #if CONFIG_MULTIPLE_ARF |
| 3463 if (!cpi->multi_arf_enabled) | 3577 if (!cpi->multi_arf_enabled) |
| 3464 #endif | 3578 #endif |
| 3465 cpi->rc.source_alt_ref_pending = 0; // Clear Pending altf Ref flag. | 3579 cpi->rc.source_alt_ref_pending = 0; |
| 3580 } else { |
| 3581 cpi->rc.source_alt_ref_pending = 0; |
| 3466 } | 3582 } |
| 3467 } | 3583 } |
| 3468 | 3584 |
| 3469 if (!cpi->source) { | 3585 if (!cpi->source) { |
| 3470 #if CONFIG_MULTIPLE_ARF | 3586 #if CONFIG_MULTIPLE_ARF |
| 3471 int i; | 3587 int i; |
| 3472 #endif | 3588 #endif |
| 3473 if ((cpi->source = vp9_lookahead_pop(cpi->lookahead, flush))) { | 3589 if ((cpi->source = vp9_lookahead_pop(cpi->lookahead, flush))) { |
| 3474 cm->show_frame = 1; | 3590 cm->show_frame = 1; |
| 3475 cm->intra_only = 0; | 3591 cm->intra_only = 0; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3528 if (cpi->source->ts_start < cpi->first_time_stamp_ever) { | 3644 if (cpi->source->ts_start < cpi->first_time_stamp_ever) { |
| 3529 cpi->first_time_stamp_ever = cpi->source->ts_start; | 3645 cpi->first_time_stamp_ever = cpi->source->ts_start; |
| 3530 cpi->last_end_time_stamp_seen = cpi->source->ts_start; | 3646 cpi->last_end_time_stamp_seen = cpi->source->ts_start; |
| 3531 } | 3647 } |
| 3532 | 3648 |
| 3533 // adjust frame rates based on timestamps given | 3649 // adjust frame rates based on timestamps given |
| 3534 if (cm->show_frame) { | 3650 if (cm->show_frame) { |
| 3535 adjust_frame_rate(cpi); | 3651 adjust_frame_rate(cpi); |
| 3536 } | 3652 } |
| 3537 | 3653 |
| 3654 if (cpi->svc.number_temporal_layers > 1 && |
| 3655 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { |
| 3656 update_layer_framerate(cpi); |
| 3657 restore_layer_context(cpi); |
| 3658 } |
| 3659 |
| 3538 // start with a 0 size frame | 3660 // start with a 0 size frame |
| 3539 *size = 0; | 3661 *size = 0; |
| 3540 | 3662 |
| 3541 // Clear down mmx registers | 3663 // Clear down mmx registers |
| 3542 vp9_clear_system_state(); // __asm emms; | 3664 vp9_clear_system_state(); // __asm emms; |
| 3543 | 3665 |
| 3544 /* find a free buffer for the new frame, releasing the reference previously | 3666 /* find a free buffer for the new frame, releasing the reference previously |
| 3545 * held. | 3667 * held. |
| 3546 */ | 3668 */ |
| 3547 cm->fb_idx_ref_cnt[cm->new_fb_idx]--; | 3669 cm->frame_bufs[cm->new_fb_idx].ref_count--; |
| 3548 cm->new_fb_idx = get_free_fb(cm); | 3670 cm->new_fb_idx = get_free_fb(cm); |
| 3549 | 3671 |
| 3550 #if CONFIG_MULTIPLE_ARF | 3672 #if CONFIG_MULTIPLE_ARF |
| 3551 /* Set up the correct ARF frame. */ | 3673 /* Set up the correct ARF frame. */ |
| 3552 if (cpi->refresh_alt_ref_frame) { | 3674 if (cpi->refresh_alt_ref_frame) { |
| 3553 ++cpi->arf_buffered; | 3675 ++cpi->arf_buffered; |
| 3554 } | 3676 } |
| 3555 if (cpi->multi_arf_enabled && (cm->frame_type != KEY_FRAME) && | 3677 if (cpi->multi_arf_enabled && (cm->frame_type != KEY_FRAME) && |
| 3556 (cpi->pass == 2)) { | 3678 (cpi->pass == 2)) { |
| 3557 cpi->alt_fb_idx = cpi->arf_buffer_idx[cpi->sequence_number]; | 3679 cpi->alt_fb_idx = cpi->arf_buffer_idx[cpi->sequence_number]; |
| 3558 } | 3680 } |
| 3559 #endif | 3681 #endif |
| 3560 | 3682 |
| 3561 cm->frame_flags = *frame_flags; | 3683 cm->frame_flags = *frame_flags; |
| 3562 | 3684 |
| 3563 // Reset the frame pointers to the current frame size | 3685 // Reset the frame pointers to the current frame size |
| 3564 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), | 3686 vp9_realloc_frame_buffer(get_frame_new_buffer(cm), |
| 3565 cm->width, cm->height, | 3687 cm->width, cm->height, |
| 3566 cm->subsampling_x, cm->subsampling_y, | 3688 cm->subsampling_x, cm->subsampling_y, |
| 3567 VP9_ENC_BORDER_IN_PIXELS); | 3689 VP9_ENC_BORDER_IN_PIXELS, NULL, NULL, NULL); |
| 3568 | 3690 |
| 3569 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { | 3691 for (ref_frame = LAST_FRAME; ref_frame <= ALTREF_FRAME; ++ref_frame) { |
| 3570 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; | 3692 const int idx = cm->ref_frame_map[get_ref_frame_idx(cpi, ref_frame)]; |
| 3571 YV12_BUFFER_CONFIG *const buf = &cm->yv12_fb[idx]; | 3693 YV12_BUFFER_CONFIG *const buf = &cm->frame_bufs[idx].buf; |
| 3572 | |
| 3573 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; | 3694 RefBuffer *const ref_buf = &cm->frame_refs[ref_frame - 1]; |
| 3574 ref_buf->buf = buf; | 3695 ref_buf->buf = buf; |
| 3575 ref_buf->idx = idx; | 3696 ref_buf->idx = idx; |
| 3576 vp9_setup_scale_factors_for_frame(&ref_buf->sf, | 3697 vp9_setup_scale_factors_for_frame(&ref_buf->sf, |
| 3577 buf->y_crop_width, buf->y_crop_height, | 3698 buf->y_crop_width, buf->y_crop_height, |
| 3578 cm->width, cm->height); | 3699 cm->width, cm->height); |
| 3579 | 3700 |
| 3580 if (vp9_is_scaled(&ref_buf->sf)) | 3701 if (vp9_is_scaled(&ref_buf->sf)) |
| 3581 vp9_extend_frame_borders(buf, cm->subsampling_x, cm->subsampling_y); | 3702 vp9_extend_frame_borders(buf, cm->subsampling_x, cm->subsampling_y); |
| 3582 } | 3703 } |
| 3583 | 3704 |
| 3584 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); | 3705 set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); |
| 3585 vp9_setup_interp_filters(xd, DEFAULT_INTERP_FILTER, cm); | 3706 xd->interp_kernel = vp9_get_interp_kernel( |
| 3707 DEFAULT_INTERP_FILTER == SWITCHABLE ? EIGHTTAP : DEFAULT_INTERP_FILTER); |
| 3586 | 3708 |
| 3587 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { | 3709 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { |
| 3588 vp9_vaq_init(); | 3710 vp9_vaq_init(); |
| 3589 } | 3711 } |
| 3590 | 3712 |
| 3591 if (cpi->use_svc) { | 3713 if (cpi->use_svc) { |
| 3592 SvcEncode(cpi, size, dest, frame_flags); | 3714 SvcEncode(cpi, size, dest, frame_flags); |
| 3593 } else if (cpi->pass == 1) { | 3715 } else if (cpi->pass == 1) { |
| 3594 Pass1Encode(cpi, size, dest, frame_flags); | 3716 Pass1Encode(cpi, size, dest, frame_flags); |
| 3595 } else if (cpi->pass == 2) { | 3717 } else if (cpi->pass == 2) { |
| 3596 Pass2Encode(cpi, size, dest, frame_flags); | 3718 Pass2Encode(cpi, size, dest, frame_flags); |
| 3597 } else { | 3719 } else { |
| 3598 // One pass encode | 3720 // One pass encode |
| 3599 Pass0Encode(cpi, size, dest, frame_flags); | 3721 Pass0Encode(cpi, size, dest, frame_flags); |
| 3600 } | 3722 } |
| 3601 | 3723 |
| 3602 if (cm->refresh_frame_context) | 3724 if (cm->refresh_frame_context) |
| 3603 cm->frame_contexts[cm->frame_context_idx] = cm->fc; | 3725 cm->frame_contexts[cm->frame_context_idx] = cm->fc; |
| 3604 | 3726 |
| 3605 // Frame was dropped, release scaled references. | 3727 // Frame was dropped, release scaled references. |
| 3606 if (*size == 0) { | 3728 if (*size == 0) { |
| 3607 release_scaled_references(cpi); | 3729 release_scaled_references(cpi); |
| 3608 } | 3730 } |
| 3609 | 3731 |
| 3610 if (*size > 0) { | 3732 if (*size > 0) { |
| 3611 cpi->droppable = !frame_is_reference(cpi); | 3733 cpi->droppable = !frame_is_reference(cpi); |
| 3612 } | 3734 } |
| 3613 | 3735 |
| 3736 // Save layer specific state. |
| 3737 if (cpi->svc.number_temporal_layers > 1 && |
| 3738 cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { |
| 3739 save_layer_context(cpi); |
| 3740 } |
| 3741 |
| 3614 vpx_usec_timer_mark(&cmptimer); | 3742 vpx_usec_timer_mark(&cmptimer); |
| 3615 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); | 3743 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); |
| 3616 | 3744 |
| 3617 if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) | 3745 if (cpi->b_calculate_psnr && cpi->pass != 1 && cm->show_frame) |
| 3618 generate_psnr_packet(cpi); | 3746 generate_psnr_packet(cpi); |
| 3619 | 3747 |
| 3620 #if CONFIG_INTERNAL_STATS | 3748 #if CONFIG_INTERNAL_STATS |
| 3621 | 3749 |
| 3622 if (cpi->pass != 1) { | 3750 if (cpi->pass != 1) { |
| 3623 cpi->bytes += *size; | 3751 cpi->bytes += *size; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3817 unsigned int height) { | 3945 unsigned int height) { |
| 3818 VP9_COMP *cpi = (VP9_COMP *)comp; | 3946 VP9_COMP *cpi = (VP9_COMP *)comp; |
| 3819 VP9_COMMON *cm = &cpi->common; | 3947 VP9_COMMON *cm = &cpi->common; |
| 3820 | 3948 |
| 3821 check_initial_width(cpi, 1, 1); | 3949 check_initial_width(cpi, 1, 1); |
| 3822 | 3950 |
| 3823 if (width) { | 3951 if (width) { |
| 3824 cm->width = width; | 3952 cm->width = width; |
| 3825 if (cm->width * 5 < cpi->initial_width) { | 3953 if (cm->width * 5 < cpi->initial_width) { |
| 3826 cm->width = cpi->initial_width / 5 + 1; | 3954 cm->width = cpi->initial_width / 5 + 1; |
| 3827 printf("Warning: Desired width too small, changed to %d \n", cm->width); | 3955 printf("Warning: Desired width too small, changed to %d\n", cm->width); |
| 3828 } | 3956 } |
| 3829 if (cm->width > cpi->initial_width) { | 3957 if (cm->width > cpi->initial_width) { |
| 3830 cm->width = cpi->initial_width; | 3958 cm->width = cpi->initial_width; |
| 3831 printf("Warning: Desired width too large, changed to %d \n", cm->width); | 3959 printf("Warning: Desired width too large, changed to %d\n", cm->width); |
| 3832 } | 3960 } |
| 3833 } | 3961 } |
| 3834 | 3962 |
| 3835 if (height) { | 3963 if (height) { |
| 3836 cm->height = height; | 3964 cm->height = height; |
| 3837 if (cm->height * 5 < cpi->initial_height) { | 3965 if (cm->height * 5 < cpi->initial_height) { |
| 3838 cm->height = cpi->initial_height / 5 + 1; | 3966 cm->height = cpi->initial_height / 5 + 1; |
| 3839 printf("Warning: Desired height too small, changed to %d \n", cm->height); | 3967 printf("Warning: Desired height too small, changed to %d\n", cm->height); |
| 3840 } | 3968 } |
| 3841 if (cm->height > cpi->initial_height) { | 3969 if (cm->height > cpi->initial_height) { |
| 3842 cm->height = cpi->initial_height; | 3970 cm->height = cpi->initial_height; |
| 3843 printf("Warning: Desired height too large, changed to %d \n", cm->height); | 3971 printf("Warning: Desired height too large, changed to %d\n", cm->height); |
| 3844 } | 3972 } |
| 3845 } | 3973 } |
| 3846 | 3974 |
| 3847 assert(cm->width <= cpi->initial_width); | 3975 assert(cm->width <= cpi->initial_width); |
| 3848 assert(cm->height <= cpi->initial_height); | 3976 assert(cm->height <= cpi->initial_height); |
| 3849 update_frame_size(cpi); | 3977 update_frame_size(cpi); |
| 3850 return 0; | 3978 return 0; |
| 3851 } | 3979 } |
| 3852 | 3980 |
| 3853 void vp9_set_svc(VP9_PTR comp, int use_svc) { | 3981 void vp9_set_svc(VP9_PTR comp, int use_svc) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3877 ref += 16 * reference->y_stride; | 4005 ref += 16 * reference->y_stride; |
| 3878 } | 4006 } |
| 3879 | 4007 |
| 3880 return total; | 4008 return total; |
| 3881 } | 4009 } |
| 3882 | 4010 |
| 3883 | 4011 |
| 3884 int vp9_get_quantizer(VP9_PTR c) { | 4012 int vp9_get_quantizer(VP9_PTR c) { |
| 3885 return ((VP9_COMP *)c)->common.base_qindex; | 4013 return ((VP9_COMP *)c)->common.base_qindex; |
| 3886 } | 4014 } |
| OLD | NEW |