Unified · Split
| @@ -460,8 +460,8 @@ static int compute_context_model_diff(const VP9_COMMON *const cm) { · 459 unmodified lines | ||
| 460 | 460 | #endif // !CONFIG_REALTIME_ONLY |
| 461 | 461 | |
| 462 | 462 | // Test for whether to calculate metrics for the frame. |
| 463 | −static int is_psnr_calc_enabled(VP9_COMP *cpi) { | |
| 464 | − VP9_COMMON *const cm = &cpi->common; | |
| 463 | +static int is_psnr_calc_enabled(const VP9_COMP *cpi) { | |
| 464 | + const VP9_COMMON *const cm = &cpi->common; | |
| 465 | 465 | const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 466 | 466 | |
| 467 | 467 | return cpi->b_calculate_psnr && (oxcf->pass != 1) && cm->show_frame; |
| @@ -2761,25 +2761,18 @@ void vp9_remove_compressor(VP9_COMP *cpi) { · 2293 unmodified lines | ||
| 2761 | 2761 | #endif |
| 2762 | 2762 | } |
| 2763 | 2763 | |
| 2764 | −static void generate_psnr_packet(VP9_COMP *cpi) { | |
| 2765 | − struct vpx_codec_cx_pkt pkt; | |
| 2766 | − int i; | |
| 2767 | − PSNR_STATS psnr; | |
| 2764 | +int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr) { | |
| 2765 | + if (is_psnr_calc_enabled(cpi)) { | |
| 2768 | 2766 | #if CONFIG_VP9_HIGHBITDEPTH |
| 2769 | − vpx_calc_highbd_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, &psnr, | |
| 2770 | − cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); | |
| 2767 | + vpx_calc_highbd_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, psnr, | |
| 2768 | + cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); | |
| 2771 | 2769 | #else |
| 2772 | − vpx_calc_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, &psnr); | |
| 2770 | + vpx_calc_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, psnr); | |
| 2773 | 2771 | #endif |
| 2774 | − | |
| 2775 | − for (i = 0; i < 4; ++i) { | |
| 2776 | − pkt.data.psnr.samples[i] = psnr.samples[i]; | |
| 2777 | − pkt.data.psnr.sse[i] = psnr.sse[i]; | |
| 2778 | − pkt.data.psnr.psnr[i] = psnr.psnr[i]; | |
| 2779 | − } | |
| 2780 | − pkt.kind = VPX_CODEC_PSNR_PKT; | |
| 2781 | − if (!cpi->use_svc) { | |
| 2782 | − vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt); | |
| 2772 | + return 1; | |
| 2773 | + } else { | |
| 2774 | + vp9_zero(*psnr); | |
| 2775 | + return 0; | |
| 2783 | 2776 | } |
| 2784 | 2777 | } |
| 2785 | 2778 | |
| @@ -7358,9 +7351,6 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, · 4572 unmodified lines | ||
| 7358 | 7351 | vpx_usec_timer_mark(&cmptimer); |
| 7359 | 7352 | cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); |
| 7360 | 7353 | |
| 7361 | − // Should we calculate metrics for the frame. | |
| 7362 | − if (is_psnr_calc_enabled(cpi)) generate_psnr_packet(cpi); | |
| 7363 | − | |
| 7364 | 7354 | if (cpi->keep_level_stats && oxcf->pass != 1) |
| 7365 | 7355 | update_level_info(cpi, size, arf_src_index); |
| 7366 | 7356 | |
| @@ -20,6 +20,7 @@ · 19 unmodified lines | ||
| 20 | 20 | #include "vpx_dsp/ssim.h" |
| 21 | 21 | #endif |
| 22 | 22 | #include "vpx_dsp/variance.h" |
| 23 | +#include "vpx_dsp/psnr.h" | |
| 23 | 24 | #include "vpx_ports/system_state.h" |
| 24 | 25 | #include "vpx_util/vpx_thread.h" |
| 25 | 26 | #include "vpx_util/vpx_timestamp.h" |
| @@ -1063,6 +1064,8 @@ void vp9_new_framerate(VP9_COMP *cpi, double framerate); · 1037 unmodified lines | ||
| 1063 | 1064 | |
| 1064 | 1065 | void vp9_set_row_mt(VP9_COMP *cpi); |
| 1065 | 1066 | |
| 1067 | +int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr); | |
| 1068 | + | |
| 1066 | 1069 | #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl)) |
| 1067 | 1070 | |
| 1068 | 1071 | #ifdef __cplusplus |
| @@ -13,6 +13,7 @@ · 12 unmodified lines | ||
| 13 | 13 | |
| 14 | 14 | #include "./vpx_config.h" |
| 15 | 15 | #include "vpx/vpx_encoder.h" |
| 16 | +#include "vpx_dsp/psnr.h" | |
| 16 | 17 | #include "vpx_ports/vpx_once.h" |
| 17 | 18 | #include "vpx_ports/system_state.h" |
| 18 | 19 | #include "vpx_util/vpx_timestamp.h" |
| @@ -1117,6 +1118,13 @@ static vpx_codec_frame_flags_t get_frame_pkt_flags(const VP9_COMP *cpi, · 1098 unmodified lines | ||
| 1117 | 1118 | return flags; |
| 1118 | 1119 | } |
| 1119 | 1120 | |
| 1121 | +static INLINE vpx_codec_cx_pkt_t get_psnr_pkt(const PSNR_STATS *psnr) { | |
| 1122 | + vpx_codec_cx_pkt_t pkt; | |
| 1123 | + pkt.kind = VPX_CODEC_PSNR_PKT; | |
| 1124 | + pkt.data.psnr = *psnr; | |
| 1125 | + return pkt; | |
| 1126 | +} | |
| 1127 | + | |
| 1120 | 1128 | const size_t kMinCompressedSize = 8192; |
| 1121 | 1129 | static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, |
| 1122 | 1130 | const vpx_image_t *img, |
| @@ -1240,6 +1248,17 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, · 117 unmodified lines | ||
| 1240 | 1248 | -1 != vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data, |
| 1241 | 1249 | &dst_time_stamp, &dst_end_time_stamp, |
| 1242 | 1250 | !img)) { |
| 1251 | + // Pack psnr pkt | |
| 1252 | + if (size > 0 && !cpi->use_svc) { | |
| 1253 | + // TODO(angiebird): Figure out why we don't need psnr pkt when use_svc | |
| 1254 | + // is on | |
| 1255 | + PSNR_STATS psnr; | |
| 1256 | + if (vp9_get_psnr(cpi, &psnr)) { | |
| 1257 | + vpx_codec_cx_pkt_t psnr_pkt = get_psnr_pkt(&psnr); | |
| 1258 | + vpx_codec_pkt_list_add(&ctx->pkt_list.head, &psnr_pkt); | |
| 1259 | + } | |
| 1260 | + } | |
| 1261 | + | |
| 1243 | 1262 | if (size || (cpi->use_svc && cpi->svc.skip_enhancement_layer)) { |
| 1244 | 1263 | // Pack invisible frames with the next visible frame |
| 1245 | 1264 | if (!cpi->common.show_frame || |