| @@ -5374,8 +5374,6 @@ static void Pass2Encode(VP9_COMP *cpi, size_t *size, uint8_t *dest, · 5373 unmodified lines |
| 5374 | 5374 | mismatch_move_frame_idx_w(); |
| 5375 | 5375 | #endif |
| 5376 | 5376 | encode_frame_to_data_rate(cpi, size, dest, frame_flags); |
| 5377 | | − |
| 5378 | | − vp9_twopass_postencode_update(cpi); |
| 5379 | 5377 | } |
| 5380 | 5378 | #endif // !CONFIG_REALTIME_ONLY |
| 5381 | 5379 | |
| @@ -7091,12 +7089,29 @@ static void init_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result) { · 1709 unmodified lines |
| 7091 | 7089 | encode_frame_result->show_idx = -1; // Actual encoding deosn't happen. |
| 7092 | 7090 | } |
| 7093 | 7091 | |
| 7092 | +#if !CONFIG_REALTIME_ONLY |
| 7094 | 7093 | static void update_encode_frame_result(ENCODE_FRAME_RESULT *encode_frame_result, |
| 7095 | 7094 | int show_idx, |
| 7096 | | − FRAME_UPDATE_TYPE update_type) { |
| 7095 | + FRAME_UPDATE_TYPE update_type, |
| 7096 | + const YV12_BUFFER_CONFIG *source_frame, |
| 7097 | + const YV12_BUFFER_CONFIG *coded_frame, |
| 7098 | + uint32_t bit_depth, |
| 7099 | + uint32_t input_bit_depth) { |
| 7100 | + PSNR_STATS psnr; |
| 7101 | +#if CONFIG_VP9_HIGHBITDEPTH |
| 7102 | + vpx_calc_highbd_psnr(source_frame, coded_frame, &psnr, bit_depth, |
| 7103 | + input_bit_depth); |
| 7104 | +#else |
| 7105 | + (void)bit_depth; |
| 7106 | + (void)input_bit_depth; |
| 7107 | + vpx_calc_psnr(source_frame, coded_frame, &psnr); |
| 7108 | +#endif |
| 7109 | + encode_frame_result->psnr = psnr.psnr[0]; |
| 7110 | + encode_frame_result->sse = psnr.sse[0]; |
| 7097 | 7111 | encode_frame_result->show_idx = show_idx; |
| 7098 | 7112 | encode_frame_result->update_type = update_type; |
| 7099 | 7113 | } |
| 7114 | +#endif // !CONFIG_REALTIME_ONLY |
| 7100 | 7115 | |
| 7101 | 7116 | int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, |
| 7102 | 7117 | size_t *size, uint8_t *dest, int64_t *time_stamp, |
| @@ -7349,12 +7364,6 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, · 246 unmodified lines |
| 7349 | 7364 | bitstream_queue_set_frame_write(cm->current_video_frame * 2 + cm->show_frame); |
| 7350 | 7365 | #endif |
| 7351 | 7366 | |
| 7352 | | − if (oxcf->pass != 1) { |
| 7353 | | − update_encode_frame_result( |
| 7354 | | − encode_frame_result, source->show_idx, |
| 7355 | | − cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index]); |
| 7356 | | − } |
| 7357 | | − |
| 7358 | 7367 | cpi->td.mb.fp_src_pred = 0; |
| 7359 | 7368 | #if CONFIG_REALTIME_ONLY |
| 7360 | 7369 | if (cpi->use_svc) { |
| @@ -7381,6 +7390,25 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, · 20 unmodified lines |
| 7381 | 7390 | vp9_first_pass(cpi, source); |
| 7382 | 7391 | } else if (oxcf->pass == 2 && !cpi->use_svc) { |
| 7383 | 7392 | Pass2Encode(cpi, size, dest, frame_flags); |
| 7393 | + // update_encode_frame_result() depends on twopass.gf_group.index and |
| 7394 | + // cm->new_fb_idx and cpi->Source are updated for current properly and have |
| 7395 | + // not been updated for the next frame yet. |
| 7396 | + // The update locations are as follows. |
| 7397 | + // 1) twopass.gf_group.index is initialized at define_gf_group by vp9_zero() |
| 7398 | + // for the first frame in the gf_group and is updated for the next frame at |
| 7399 | + // vp9_twopass_postencode_update(). |
| 7400 | + // 2) cpi->Source is updated at the beginging of this function, i.e. |
| 7401 | + // vp9_get_compressed_data() |
| 7402 | + // 3) cm->new_fb_idx is updated at the beginging of this function by |
| 7403 | + // get_free_fb(cm) |
| 7404 | + // TODO(angiebird): Improve the codebase to make the update of frame |
| 7405 | + // dependent variables more robust. |
| 7406 | + update_encode_frame_result( |
| 7407 | + encode_frame_result, source->show_idx, |
| 7408 | + cpi->twopass.gf_group.update_type[cpi->twopass.gf_group.index], |
| 7409 | + cpi->Source, get_frame_new_buffer(cm), cpi->oxcf.input_bit_depth, |
| 7410 | + cm->bit_depth); |
| 7411 | + vp9_twopass_postencode_update(cpi); |
| 7384 | 7412 | } else if (cpi->use_svc) { |
| 7385 | 7413 | SvcEncode(cpi, size, dest, frame_flags); |
| 7386 | 7414 | } else { |