Call this function before coding a new group of picture to get information about it.
Unified · Split
| @@ -3627,56 +3627,65 @@ void vp9_twopass_postencode_update(VP9_COMP *cpi) { · 3626 unmodified lines | ||
| 3627 | 3627 | } |
| 3628 | 3628 | |
| 3629 | 3629 | #if CONFIG_RATE_CTRL |
| 3630 | +int vp9_get_gop_coding_frame_count( | |
| 3631 | + int *use_alt_ref, const VP9EncoderConfig *oxcf, | |
| 3632 | + const FRAME_INFO *frame_info, const FIRST_PASS_INFO *first_pass_info, | |
| 3633 | + const RATE_CONTROL *rc, int show_idx, int multi_layer_arf, | |
| 3634 | + int allow_alt_ref, int first_is_key_frame, int last_gop_use_alt_ref) { | |
| 3635 | + int frame_count; | |
| 3636 | + double gop_intra_factor; | |
| 3637 | + const int arf_active_or_kf = last_gop_use_alt_ref || first_is_key_frame; | |
| 3638 | + RANGE active_gf_interval = get_active_gf_inverval_range( | |
| 3639 | + frame_info, rc, arf_active_or_kf, show_idx, /*active_worst_quality=*/0, | |
| 3640 | + /*last_boosted_qindex=*/0); | |
| 3641 | + | |
| 3642 | + const int arf_layers = get_arf_layers(multi_layer_arf, oxcf->enable_auto_arf, | |
| 3643 | + active_gf_interval.max); | |
| 3644 | + if (multi_layer_arf) { | |
| 3645 | + gop_intra_factor = 1.0 + 0.25 * arf_layers; | |
| 3646 | + } else { | |
| 3647 | + gop_intra_factor = 1.0; | |
| 3648 | + } | |
| 3649 | + | |
| 3650 | + frame_count = get_gop_coding_frame_num( | |
| 3651 | + use_alt_ref, frame_info, first_pass_info, rc, show_idx, | |
| 3652 | + &active_gf_interval, gop_intra_factor, oxcf->lag_in_frames); | |
| 3653 | + *use_alt_ref &= allow_alt_ref; | |
| 3654 | + return frame_count; | |
| 3655 | +} | |
| 3656 | + | |
| 3630 | 3657 | // Under CONFIG_RATE_CTRL, once the first_pass_info is ready, the number of |
| 3631 | 3658 | // coding frames (including show frame and alt ref) can be determined. |
| 3632 | −int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf, | |
| 3659 | +int vp9_get_coding_frame_num(const VP9EncoderConfig *oxcf, | |
| 3633 | 3660 | const FRAME_INFO *frame_info, |
| 3634 | 3661 | const FIRST_PASS_INFO *first_pass_info, |
| 3635 | 3662 | int multi_layer_arf, int allow_alt_ref) { |
| 3636 | 3663 | int coding_frame_num = 0; |
| 3637 | 3664 | RATE_CONTROL rc; |
| 3638 | − RANGE active_gf_interval; | |
| 3639 | − int arf_layers; | |
| 3640 | − double gop_intra_factor; | |
| 3641 | − int use_alt_ref; | |
| 3642 | − int gop_coding_frames; | |
| 3665 | + int gop_coding_frame_count; | |
| 3643 | 3666 | int gop_show_frames; |
| 3644 | 3667 | int show_idx = 0; |
| 3645 | − int arf_active_or_kf = 1; | |
| 3668 | + int last_gop_use_alt_ref = 0; | |
| 3646 | 3669 | rc.static_scene_max_gf_interval = 250; |
| 3647 | 3670 | vp9_rc_init(oxcf, 1, &rc); |
| 3648 | 3671 | |
| 3649 | 3672 | while (show_idx < first_pass_info->num_frames) { |
| 3673 | + int use_alt_ref; | |
| 3674 | + int first_is_key_frame = 0; | |
| 3650 | 3675 | if (rc.frames_to_key == 0) { |
| 3651 | 3676 | rc.frames_to_key = vp9_get_frames_to_next_key( |
| 3652 | 3677 | oxcf, frame_info, first_pass_info, show_idx, rc.min_gf_interval); |
| 3653 | − arf_active_or_kf = 1; | |
| 3654 | − } else { | |
| 3655 | − } | |
| 3656 | − | |
| 3657 | − { | |
| 3658 | − int dummy = 0; | |
| 3659 | − active_gf_interval = get_active_gf_inverval_range( | |
| 3660 | − frame_info, &rc, arf_active_or_kf, show_idx, dummy, dummy); | |
| 3678 | + first_is_key_frame = 1; | |
| 3661 | 3679 | } |
| 3662 | 3680 | |
| 3663 | − arf_layers = get_arf_layers(multi_layer_arf, oxcf->enable_auto_arf, | |
| 3664 | − active_gf_interval.max); | |
| 3665 | − if (multi_layer_arf) { | |
| 3666 | − gop_intra_factor = 1.0 + 0.25 * arf_layers; | |
| 3667 | − } else { | |
| 3668 | − gop_intra_factor = 1.0; | |
| 3669 | − } | |
| 3670 | − | |
| 3671 | − gop_coding_frames = get_gop_coding_frame_num( | |
| 3672 | − &use_alt_ref, frame_info, first_pass_info, &rc, show_idx, | |
| 3673 | − &active_gf_interval, gop_intra_factor, oxcf->lag_in_frames); | |
| 3674 | − | |
| 3675 | − use_alt_ref &= allow_alt_ref; | |
| 3681 | + gop_coding_frame_count = vp9_get_gop_coding_frame_count( | |
| 3682 | + &use_alt_ref, oxcf, frame_info, first_pass_info, &rc, show_idx, | |
| 3683 | + multi_layer_arf, allow_alt_ref, first_is_key_frame, | |
| 3684 | + last_gop_use_alt_ref); | |
| 3676 | 3685 | |
| 3677 | 3686 | rc.source_alt_ref_active = use_alt_ref; |
| 3678 | − arf_active_or_kf = use_alt_ref; | |
| 3679 | − gop_show_frames = gop_coding_frames - use_alt_ref; | |
| 3687 | + last_gop_use_alt_ref = use_alt_ref; | |
| 3688 | + gop_show_frames = gop_coding_frame_count - use_alt_ref; | |
| 3680 | 3689 | rc.frames_to_key -= gop_show_frames; |
| 3681 | 3690 | rc.frames_since_key += gop_show_frames; |
| 3682 | 3691 | show_idx += gop_show_frames; |
| @@ -252,6 +252,28 @@ int vp9_get_frames_to_next_key(const struct VP9EncoderConfig *oxcf, · 251 unmodified lines | ||
| 252 | 252 | const FIRST_PASS_INFO *first_pass_info, |
| 253 | 253 | int kf_show_idx, int min_gf_interval); |
| 254 | 254 | #if CONFIG_RATE_CTRL |
| 255 | +/*!\brief Call this function before coding a new group of pictures to get | |
| 256 | + * information about it. | |
| 257 | + * \param[in] oxcf Encoder config | |
| 258 | + * \param[in] frame_info Frame info | |
| 259 | + * \param[in] first_pass_info First pass stats | |
| 260 | + * \param[in] rc Rate control state | |
| 261 | + * \param[in] show_idx Show index of the first frame in the group | |
| 262 | + * \param[in] multi_layer_arf Is multi-layer alternate reference used | |
| 263 | + * \param[in] allow_alt_ref Is alternate reference allowed | |
| 264 | + * \param[in] first_is_key_frame Is the first frame in the group a key frame | |
| 265 | + * \param[in] last_gop_use_alt_ref Does the last group use alternate reference | |
| 266 | + * | |
| 267 | + * \param[out] use_alt_ref Does this group use alternate reference | |
| 268 | + * | |
| 269 | + * \return Returns coding frame count | |
| 270 | + */ | |
| 271 | +int vp9_get_gop_coding_frame_count( | |
| 272 | + int *use_alt_ref, const struct VP9EncoderConfig *oxcf, | |
| 273 | + const FRAME_INFO *frame_info, const FIRST_PASS_INFO *first_pass_info, | |
| 274 | + const RATE_CONTROL *rc, int show_idx, int multi_layer_arf, | |
| 275 | + int allow_alt_ref, int first_is_key_frame, int last_gop_use_alt_ref); | |
| 276 | + | |
| 255 | 277 | int vp9_get_coding_frame_num(const struct VP9EncoderConfig *oxcf, |
| 256 | 278 | const FRAME_INFO *frame_info, |
| 257 | 279 | const FIRST_PASS_INFO *first_pass_info, |