Move the logics of computing gf_group_err, gf_group_raw_error, gf_group_noise, gf_group_skip_pct, gf_group_inactive_zone_rowsa, gf_group_inter, gf_group_motion into one for loop The behavior stays the same.
Unified · Split
| @@ -2450,15 +2450,18 @@ static void adjust_group_arnr_filter(VP9_COMP *cpi, double section_noise, · 2449 unmodified lines | |||
| 2450 | #define ARF_ABS_ZOOM_THRESH 4.0 | 2450 | #define ARF_ABS_ZOOM_THRESH 4.0 |
| 2451 | 2451 | ||
| 2452 | #define MAX_GF_BOOST 5400 | 2452 | #define MAX_GF_BOOST 5400 |
| 2453 | static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { | 2453 | static void define_gf_group(VP9_COMP *cpi) { |
| 2454 | VP9_COMMON *const cm = &cpi->common; | 2454 | VP9_COMMON *const cm = &cpi->common; |
| 2455 | RATE_CONTROL *const rc = &cpi->rc; | 2455 | RATE_CONTROL *const rc = &cpi->rc; |
| 2456 | VP9EncoderConfig *const oxcf = &cpi->oxcf; | 2456 | VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 2457 | TWO_PASS *const twopass = &cpi->twopass; | 2457 | TWO_PASS *const twopass = &cpi->twopass; |
| 2458 | const FRAME_INFO *frame_info = &cpi->frame_info; | 2458 | const FRAME_INFO *frame_info = &cpi->frame_info; |
| 2459 | const FIRST_PASS_INFO *first_pass_info = &twopass->first_pass_info; | ||
| 2459 | FIRSTPASS_STATS next_frame; | 2460 | FIRSTPASS_STATS next_frame; |
| 2460 | const FIRSTPASS_STATS *const start_pos = twopass->stats_in; | 2461 | const FIRSTPASS_STATS *const start_pos = twopass->stats_in; |
| 2462 | const int gf_start_show_idx = cm->current_video_frame; | ||
| 2461 | int i; | 2463 | int i; |
| 2464 | int j; | ||
| 2462 | 2465 | ||
| 2463 | double gf_group_err = 0.0; | 2466 | double gf_group_err = 0.0; |
| 2464 | double gf_group_raw_error = 0.0; | 2467 | double gf_group_raw_error = 0.0; |
| @@ -2489,6 +2492,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 24 unmodified lines | |||
| 2489 | int64_t gf_group_bits; | 2492 | int64_t gf_group_bits; |
| 2490 | int gf_arf_bits; | 2493 | int gf_arf_bits; |
| 2491 | const int is_key_frame = frame_is_intra_only(cm); | 2494 | const int is_key_frame = frame_is_intra_only(cm); |
| 2495 | // If this is a key frame or the overlay from a previous arf then | ||
| 2496 | // the error score / cost of this frame has already been accounted for. | ||
| 2492 | const int arf_active_or_kf = is_key_frame || rc->source_alt_ref_active; | 2497 | const int arf_active_or_kf = is_key_frame || rc->source_alt_ref_active; |
| 2493 | int is_alt_ref_flash = 0; | 2498 | int is_alt_ref_flash = 0; |
| 2494 | 2499 | ||
| @@ -2504,20 +2509,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 9 unmodified lines | |||
| 2504 | vpx_clear_system_state(); | 2509 | vpx_clear_system_state(); |
| 2505 | vp9_zero(next_frame); | 2510 | vp9_zero(next_frame); |
| 2506 | 2511 | ||
| 2507 | // If this is a key frame or the overlay from a previous arf then | ||
| 2508 | // the error score / cost of this frame has already been accounted for. | ||
| 2509 | if (arf_active_or_kf) { | ||
| 2510 | double gf_first_frame_err = calc_norm_frame_score( | ||
| 2511 | oxcf, frame_info, this_frame, mean_mod_score, av_err); | ||
| 2512 | gf_group_err -= gf_first_frame_err; | ||
| 2513 | gf_group_raw_error -= this_frame->coded_error; | ||
| 2514 | gf_group_noise -= this_frame->frame_noise_energy; | ||
| 2515 | gf_group_skip_pct -= this_frame->intra_skip_pct; | ||
| 2516 | gf_group_inactive_zone_rows -= this_frame->inactive_zone_rows; | ||
| 2517 | gf_group_inter -= this_frame->pcnt_inter; | ||
| 2518 | gf_group_motion -= this_frame->pcnt_motion; | ||
| 2519 | } | ||
| 2520 | |||
| 2521 | // Motion breakout threshold for loop below depends on image size. | 2512 | // Motion breakout threshold for loop below depends on image size. |
| 2522 | mv_ratio_accumulator_thresh = | 2513 | mv_ratio_accumulator_thresh = |
| 2523 | (cpi->initial_height + cpi->initial_width) / 4.0; | 2514 | (cpi->initial_height + cpi->initial_width) / 4.0; |
| @@ -2580,16 +2571,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 56 unmodified lines | |||
| 2580 | const FIRSTPASS_STATS *next_next_frame; | 2571 | const FIRSTPASS_STATS *next_next_frame; |
| 2581 | ++i; | 2572 | ++i; |
| 2582 | 2573 | ||
| 2583 | // Accumulate error score of frames in this gf group. | ||
| 2584 | gf_group_err += calc_norm_frame_score(oxcf, frame_info, this_frame, | ||
| 2585 | mean_mod_score, av_err); | ||
| 2586 | gf_group_raw_error += this_frame->coded_error; | ||
| 2587 | gf_group_noise += this_frame->frame_noise_energy; | ||
| 2588 | gf_group_skip_pct += this_frame->intra_skip_pct; | ||
| 2589 | gf_group_inactive_zone_rows += this_frame->inactive_zone_rows; | ||
| 2590 | gf_group_inter += this_frame->pcnt_inter; | ||
| 2591 | gf_group_motion += this_frame->pcnt_motion; | ||
| 2592 | |||
| 2593 | if (EOF == input_stats(twopass, &next_frame)) break; | 2574 | if (EOF == input_stats(twopass, &next_frame)) break; |
| 2594 | 2575 | ||
| 2595 | // Test for the case where there is a brief flash but the prediction | 2576 | // Test for the case where there is a brief flash but the prediction |
| @@ -2658,8 +2639,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 62 unmodified lines | |||
| 2658 | (sr_accumulator > gop_intra_factor * next_frame.intra_error))) { | 2639 | (sr_accumulator > gop_intra_factor * next_frame.intra_error))) { |
| 2659 | break; | 2640 | break; |
| 2660 | } | 2641 | } |
| 2661 | |||
| 2662 | *this_frame = next_frame; | ||
| 2663 | } | 2642 | } |
| 2664 | 2643 | ||
| 2665 | // Was the group length constrained by the requirement for a new KF? | 2644 | // Was the group length constrained by the requirement for a new KF? |
| @@ -2729,6 +2708,27 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { · 63 unmodified lines | |||
| 2729 | if (rc->source_alt_ref_pending) | 2708 | if (rc->source_alt_ref_pending) |
| 2730 | is_alt_ref_flash = detect_flash(twopass, rc->baseline_gf_interval); | 2709 | is_alt_ref_flash = detect_flash(twopass, rc->baseline_gf_interval); |
| 2731 | 2710 | ||
| 2711 | { | ||
| 2712 | // If the first frame is a key frame or the overlay from a previous arf then | ||
| 2713 | // the error score / cost of this frame has already been accounted for. | ||
| 2714 | int start_idx = arf_active_or_kf ? 1 : 0; | ||
| 2715 | int num_show_frames = i; | ||
| 2716 | for (j = start_idx; j < num_show_frames; ++j) { | ||
| 2717 | int show_idx = gf_start_show_idx + j; | ||
| 2718 | const FIRSTPASS_STATS *frame_stats = | ||
| 2719 | fps_get_frame_stats(first_pass_info, show_idx); | ||
| 2720 | // Accumulate error score of frames in this gf group. | ||
| 2721 | gf_group_err += calc_norm_frame_score(oxcf, frame_info, frame_stats, | ||
| 2722 | mean_mod_score, av_err); | ||
| 2723 | gf_group_raw_error += frame_stats->coded_error; | ||
| 2724 | gf_group_noise += frame_stats->frame_noise_energy; | ||
| 2725 | gf_group_skip_pct += frame_stats->intra_skip_pct; | ||
| 2726 | gf_group_inactive_zone_rows += frame_stats->inactive_zone_rows; | ||
| 2727 | gf_group_inter += frame_stats->pcnt_inter; | ||
| 2728 | gf_group_motion += frame_stats->pcnt_motion; | ||
| 2729 | } | ||
| 2730 | } | ||
| 2731 | |||
| 2732 | // Calculate the bits to be allocated to the gf/arf group as a whole | 2732 | // Calculate the bits to be allocated to the gf/arf group as a whole |
| 2733 | gf_group_bits = calculate_total_gf_group_bits(cpi, gf_group_err); | 2733 | gf_group_bits = calculate_total_gf_group_bits(cpi, gf_group_err); |
| 2734 | 2734 | ||
| @@ -3396,7 +3396,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { · 661 unmodified lines | |||
| 3396 | 3396 | ||
| 3397 | // Define a new GF/ARF group. (Should always enter here for key frames). | 3397 | // Define a new GF/ARF group. (Should always enter here for key frames). |
| 3398 | if (rc->frames_till_gf_update_due == 0) { | 3398 | if (rc->frames_till_gf_update_due == 0) { |
| 3399 | define_gf_group(cpi, &this_frame); | 3399 | define_gf_group(cpi); |
| 3400 | 3400 | ||
| 3401 | rc->frames_till_gf_update_due = rc->baseline_gf_interval; | 3401 | rc->frames_till_gf_update_due = rc->baseline_gf_interval; |
| 3402 | 3402 | ||
| @@ -158,6 +158,14 @@ static INLINE void fps_init_first_pass_info(FIRST_PASS_INFO *first_pass_info, · 157 unmodified lines | |||
| 158 | first_pass_info->num_frames = num_frames; | 158 | first_pass_info->num_frames = num_frames; |
| 159 | } | 159 | } |
| 160 | 160 | ||
| 161 | static INLINE const FIRSTPASS_STATS *fps_get_frame_stats( | ||
| 162 | const FIRST_PASS_INFO *first_pass_info, int show_idx) { | ||
| 163 | if (show_idx >= first_pass_info->num_frames) { | ||
| 164 | return NULL; | ||
| 165 | } | ||
| 166 | return &first_pass_info->stats[show_idx]; | ||
| 167 | } | ||
| 168 | |||
| 161 | typedef struct { | 169 | typedef struct { |
| 162 | unsigned int section_intra_rating; | 170 | unsigned int section_intra_rating; |
| 163 | unsigned int key_frame_section_intra_rating; | 171 | unsigned int key_frame_section_intra_rating; |