From 76cdfe2d732188847002d4bcbde3ed0964d77bb0 Mon Sep 17 00:00:00 2001 From: angiebird Date: Sat, 2 Nov 2019 15:22:13 -0700 Subject: [PATCH] Pack psnr pkt outside of vp9_get_compressed_data Change-Id: I5549c3dbcbe1550824deaebf03178e38c1b07d54 --- vp9/encoder/vp9_encoder.c | 32 +++++++++++--------------------- vp9/encoder/vp9_encoder.h | 3 +++ vp9/vp9_cx_iface.c | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index 2d0c08412..d5a58d9c8 100644 --- a/vp9/encoder/vp9_encoder.c +++ b/vp9/encoder/vp9_encoder.c @@ -460,8 +460,8 @@ static int compute_context_model_diff(const VP9_COMMON *const cm) { #endif // !CONFIG_REALTIME_ONLY // Test for whether to calculate metrics for the frame. -static int is_psnr_calc_enabled(VP9_COMP *cpi) { - VP9_COMMON *const cm = &cpi->common; +static int is_psnr_calc_enabled(const VP9_COMP *cpi) { + const VP9_COMMON *const cm = &cpi->common; const VP9EncoderConfig *const oxcf = &cpi->oxcf; return cpi->b_calculate_psnr && (oxcf->pass != 1) && cm->show_frame; @@ -2761,25 +2761,18 @@ void vp9_remove_compressor(VP9_COMP *cpi) { #endif } -static void generate_psnr_packet(VP9_COMP *cpi) { - struct vpx_codec_cx_pkt pkt; - int i; - PSNR_STATS psnr; +int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr) { + if (is_psnr_calc_enabled(cpi)) { #if CONFIG_VP9_HIGHBITDEPTH - vpx_calc_highbd_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, &psnr, - cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); + vpx_calc_highbd_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, psnr, + cpi->td.mb.e_mbd.bd, cpi->oxcf.input_bit_depth); #else - vpx_calc_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, &psnr); + vpx_calc_psnr(cpi->raw_source_frame, cpi->common.frame_to_show, psnr); #endif - - for (i = 0; i < 4; ++i) { - pkt.data.psnr.samples[i] = psnr.samples[i]; - pkt.data.psnr.sse[i] = psnr.sse[i]; - pkt.data.psnr.psnr[i] = psnr.psnr[i]; - } - pkt.kind = VPX_CODEC_PSNR_PKT; - if (!cpi->use_svc) { - vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt); + return 1; + } else { + vp9_zero(*psnr); + return 0; } } @@ -7358,9 +7351,6 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, vpx_usec_timer_mark(&cmptimer); cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer); - // Should we calculate metrics for the frame. - if (is_psnr_calc_enabled(cpi)) generate_psnr_packet(cpi); - if (cpi->keep_level_stats && oxcf->pass != 1) update_level_info(cpi, size, arf_src_index); diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index 78225f1ea..d603ce62a 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -20,6 +20,7 @@ #include "vpx_dsp/ssim.h" #endif #include "vpx_dsp/variance.h" +#include "vpx_dsp/psnr.h" #include "vpx_ports/system_state.h" #include "vpx_util/vpx_thread.h" #include "vpx_util/vpx_timestamp.h" @@ -1063,6 +1064,8 @@ void vp9_new_framerate(VP9_COMP *cpi, double framerate); void vp9_set_row_mt(VP9_COMP *cpi); +int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr); + #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl)) #ifdef __cplusplus diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index d5aa09b5f..ae5dee47b 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -13,6 +13,7 @@ #include "./vpx_config.h" #include "vpx/vpx_encoder.h" +#include "vpx_dsp/psnr.h" #include "vpx_ports/vpx_once.h" #include "vpx_ports/system_state.h" #include "vpx_util/vpx_timestamp.h" @@ -1117,6 +1118,13 @@ static vpx_codec_frame_flags_t get_frame_pkt_flags(const VP9_COMP *cpi, return flags; } +static INLINE vpx_codec_cx_pkt_t get_psnr_pkt(const PSNR_STATS *psnr) { + vpx_codec_cx_pkt_t pkt; + pkt.kind = VPX_CODEC_PSNR_PKT; + pkt.data.psnr = *psnr; + return pkt; +} + const size_t kMinCompressedSize = 8192; static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, const vpx_image_t *img, @@ -1240,6 +1248,17 @@ static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx, -1 != vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data, &dst_time_stamp, &dst_end_time_stamp, !img)) { + // Pack psnr pkt + if (size > 0 && !cpi->use_svc) { + // TODO(angiebird): Figure out why we don't need psnr pkt when use_svc + // is on + PSNR_STATS psnr; + if (vp9_get_psnr(cpi, &psnr)) { + vpx_codec_cx_pkt_t psnr_pkt = get_psnr_pkt(&psnr); + vpx_codec_pkt_list_add(&ctx->pkt_list.head, &psnr_pkt); + } + } + if (size || (cpi->use_svc && cpi->svc.skip_enhancement_layer)) { // Pack invisible frames with the next visible frame if (!cpi->common.show_frame || -- 2.40.0