| @@ -4205,6 +4205,27 @@ static int encode_without_recode_loop(VP9_COMP *cpi, size_t *size, · 4204 unmodified lines |
| 4205 | 4205 | return 1; |
| 4206 | 4206 | } |
| 4207 | 4207 | |
| 4208 | +static int get_ref_frame_flags(const VP9_COMP *cpi) { |
| 4209 | + const int *const map = cpi->common.ref_frame_map; |
| 4210 | + const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; |
| 4211 | + const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; |
| 4212 | + const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4213 | + int flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
| 4214 | + |
| 4215 | + if (gold_is_last) flags &= ~VP9_GOLD_FLAG; |
| 4216 | + |
| 4217 | + if (cpi->rc.frames_till_gf_update_due == INT_MAX && |
| 4218 | + (cpi->svc.number_temporal_layers == 1 && |
| 4219 | + cpi->svc.number_spatial_layers == 1)) |
| 4220 | + flags &= ~VP9_GOLD_FLAG; |
| 4221 | + |
| 4222 | + if (alt_is_last) flags &= ~VP9_ALT_FLAG; |
| 4223 | + |
| 4224 | + if (gold_is_alt) flags &= ~VP9_ALT_FLAG; |
| 4225 | + |
| 4226 | + return flags; |
| 4227 | +} |
| 4228 | + |
| 4208 | 4229 | #if !CONFIG_REALTIME_ONLY |
| 4209 | 4230 | #define MAX_QSTEP_ADJ 4 |
| 4210 | 4231 | static int get_qstep_adj(int rate_excess, int rate_limit) { |
| @@ -4481,9 +4502,14 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest · 270 unmodified lines |
| 4481 | 4502 | if (cpi->ext_ratectrl.ready) { |
| 4482 | 4503 | const GF_GROUP *gf_group = &cpi->twopass.gf_group; |
| 4483 | 4504 | vpx_rc_encodeframe_decision_t encode_frame_decision; |
| 4505 | + FRAME_UPDATE_TYPE update_type = gf_group->update_type[gf_group->index]; |
| 4506 | + const int ref_frame_flags = get_ref_frame_flags(cpi); |
| 4507 | + RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES]; |
| 4508 | + get_ref_frame_bufs(cpi, ref_frame_bufs); |
| 4484 | 4509 | vp9_extrc_get_encodeframe_decision( |
| 4485 | | − &cpi->ext_ratectrl, gf_group, cm->current_video_frame, |
| 4486 | | − cm->current_frame_coding_index, &encode_frame_decision); |
| 4510 | + &cpi->ext_ratectrl, cm->current_video_frame, |
| 4511 | + cm->current_frame_coding_index, update_type, ref_frame_bufs, |
| 4512 | + ref_frame_flags, &encode_frame_decision); |
| 4487 | 4513 | q = encode_frame_decision.q_index; |
| 4488 | 4514 | } |
| 4489 | 4515 | |
| @@ -4772,27 +4798,6 @@ static void encode_with_recode_loop(VP9_COMP *cpi, size_t *size, uint8_t *dest · 282 unmodified lines |
| 4772 | 4798 | } |
| 4773 | 4799 | #endif // !CONFIG_REALTIME_ONLY |
| 4774 | 4800 | |
| 4775 | | −static int get_ref_frame_flags(const VP9_COMP *cpi) { |
| 4776 | | − const int *const map = cpi->common.ref_frame_map; |
| 4777 | | − const int gold_is_last = map[cpi->gld_fb_idx] == map[cpi->lst_fb_idx]; |
| 4778 | | − const int alt_is_last = map[cpi->alt_fb_idx] == map[cpi->lst_fb_idx]; |
| 4779 | | − const int gold_is_alt = map[cpi->gld_fb_idx] == map[cpi->alt_fb_idx]; |
| 4780 | | − int flags = VP9_ALT_FLAG | VP9_GOLD_FLAG | VP9_LAST_FLAG; |
| 4781 | | − |
| 4782 | | − if (gold_is_last) flags &= ~VP9_GOLD_FLAG; |
| 4783 | | − |
| 4784 | | − if (cpi->rc.frames_till_gf_update_due == INT_MAX && |
| 4785 | | − (cpi->svc.number_temporal_layers == 1 && |
| 4786 | | − cpi->svc.number_spatial_layers == 1)) |
| 4787 | | − flags &= ~VP9_GOLD_FLAG; |
| 4788 | | − |
| 4789 | | − if (alt_is_last) flags &= ~VP9_ALT_FLAG; |
| 4790 | | − |
| 4791 | | − if (gold_is_alt) flags &= ~VP9_ALT_FLAG; |
| 4792 | | − |
| 4793 | | − return flags; |
| 4794 | | −} |
| 4795 | | − |
| 4796 | 4801 | static void set_ext_overrides(VP9_COMP *cpi) { |
| 4797 | 4802 | // Overrides the defaults with the externally supplied values with |
| 4798 | 4803 | // vp9_update_reference() and vp9_update_entropy() calls |
| @@ -5097,9 +5102,7 @@ static void set_frame_index(VP9_COMP *cpi, VP9_COMMON *cm) { · 298 unmodified lines |
| 5097 | 5102 | const GF_GROUP *const gf_group = &cpi->twopass.gf_group; |
| 5098 | 5103 | ref_buffer->frame_index = |
| 5099 | 5104 | cm->current_video_frame + gf_group->arf_src_offset[gf_group->index]; |
| 5100 | | −#if CONFIG_RATE_CTRL |
| 5101 | 5105 | ref_buffer->frame_coding_index = cm->current_frame_coding_index; |
| 5102 | | −#endif // CONFIG_RATE_CTRL |
| 5103 | 5106 | } |
| 5104 | 5107 | } |
| 5105 | 5108 | |
| @@ -7391,6 +7394,30 @@ static void setup_tpl_stats(VP9_COMP *cpi) { · 2285 unmodified lines |
| 7391 | 7394 | #endif // CONFIG_NON_GREEDY_MV |
| 7392 | 7395 | } |
| 7393 | 7396 | |
| 7397 | +void vp9_get_ref_frame_info(FRAME_UPDATE_TYPE update_type, int ref_frame_flags, |
| 7398 | + RefCntBuffer *ref_frame_bufs[MAX_INTER_REF_FRAMES], |
| 7399 | + int *ref_frame_coding_indexes, |
| 7400 | + int *ref_frame_valid_list) { |
| 7401 | + if (update_type != KF_UPDATE) { |
| 7402 | + const VP9_REFFRAME inter_ref_flags[MAX_INTER_REF_FRAMES] = { VP9_LAST_FLAG, |
| 7403 | + VP9_GOLD_FLAG, |
| 7404 | + VP9_ALT_FLAG }; |
| 7405 | + int i; |
| 7406 | + for (i = 0; i < MAX_INTER_REF_FRAMES; ++i) { |
| 7407 | + assert(ref_frame_bufs[i] != NULL); |
| 7408 | + ref_frame_coding_indexes[i] = ref_frame_bufs[i]->frame_coding_index; |
| 7409 | + ref_frame_valid_list[i] = (ref_frame_flags & inter_ref_flags[i]) != 0; |
| 7410 | + } |
| 7411 | + } else { |
| 7412 | + // No reference frame is available when this is a key frame. |
| 7413 | + int i; |
| 7414 | + for (i = 0; i < MAX_INTER_REF_FRAMES; ++i) { |
| 7415 | + ref_frame_coding_indexes[i] = -1; |
| 7416 | + ref_frame_valid_list[i] = 0; |
| 7417 | + } |
| 7418 | + } |
| 7419 | +} |
| 7420 | + |
| 7394 | 7421 | #if !CONFIG_REALTIME_ONLY |
| 7395 | 7422 | #if CONFIG_RATE_CTRL |
| 7396 | 7423 | static void copy_frame_counts(const FRAME_COUNTS *input_counts, |
| @@ -7538,6 +7565,7 @@ static void yv12_buffer_to_image_buffer(const YV12_BUFFER_CONFIG *yv12_buffer, · 141 unmodified lines |
| 7538 | 7565 | } |
| 7539 | 7566 | } |
| 7540 | 7567 | #endif // CONFIG_RATE_CTRL |
| 7568 | + |
| 7541 | 7569 | static void update_encode_frame_result( |
| 7542 | 7570 | int ref_frame_flags, FRAME_UPDATE_TYPE update_type, |
| 7543 | 7571 | const YV12_BUFFER_CONFIG *source_frame, const RefCntBuffer *coded_frame_buf, |
| @@ -7560,26 +7588,10 @@ static void update_encode_frame_result( · 16 unmodified lines |
| 7560 | 7588 | #endif // CONFIG_VP9_HIGHBITDEPTH |
| 7561 | 7589 | encode_frame_result->frame_coding_index = coded_frame_buf->frame_coding_index; |
| 7562 | 7590 | |
| 7563 | | − if (update_type != KF_UPDATE) { |
| 7564 | | − const VP9_REFFRAME inter_ref_flags[MAX_INTER_REF_FRAMES] = { VP9_LAST_FLAG, |
| 7565 | | − VP9_GOLD_FLAG, |
| 7566 | | − VP9_ALT_FLAG }; |
| 7567 | | − int i; |
| 7568 | | − for (i = 0; i < MAX_INTER_REF_FRAMES; ++i) { |
| 7569 | | − assert(ref_frame_bufs[i] != NULL); |
| 7570 | | − encode_frame_result->ref_frame_coding_indexes[i] = |
| 7571 | | − ref_frame_bufs[i]->frame_coding_index; |
| 7572 | | − encode_frame_result->ref_frame_valid_list[i] = |
| 7573 | | − (ref_frame_flags & inter_ref_flags[i]) != 0; |
| 7574 | | − } |
| 7575 | | − } else { |
| 7576 | | − // No reference frame is available when this is a key frame. |
| 7577 | | − int i; |
| 7578 | | − for (i = 0; i < MAX_INTER_REF_FRAMES; ++i) { |
| 7579 | | − encode_frame_result->ref_frame_coding_indexes[i] = -1; |
| 7580 | | − encode_frame_result->ref_frame_valid_list[i] = 0; |
| 7581 | | − } |
| 7582 | | − } |
| 7591 | + vp9_get_ref_frame_info(update_type, ref_frame_flags, ref_frame_bufs, |
| 7592 | + encode_frame_result->ref_frame_coding_indexes, |
| 7593 | + encode_frame_result->ref_frame_valid_list); |
| 7594 | + |
| 7583 | 7595 | encode_frame_result->psnr = psnr.psnr[0]; |
| 7584 | 7596 | encode_frame_result->sse = psnr.sse[0]; |
| 7585 | 7597 | copy_frame_counts(counts, &encode_frame_result->frame_counts); |