History

Pack psnr pkt outside of vp9_get_compressed_data

angiebird committed 7 years ago

Commit 76cdfe21 parent 8eb69623 files · +33 −21Browse files

Unified · Split

3 files
  1. vp9/encoder/vp9_encoder.c +11 −21
  2. vp9/encoder/vp9_encoder.h +3 −0
  3. vp9/vp9_cx_iface.c +19 −0
vp9/encoder/vp9_encoder.c+11−21
@@ -460,8 +460,8 @@ static int compute_context_model_diff(const VP9_COMMON *const cm) { · 459 unmodified lines
460460 #endif // !CONFIG_REALTIME_ONLY
461461
462462 // 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;
465465 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
466466
467467 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
27612761 #endif
27622762 }
27632763
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)) {
27682766 #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);
27712769 #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);
27732771 #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;
27832776 }
27842777 }
27852778
@@ -7358,9 +7351,6 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, · 4572 unmodified lines
73587351 vpx_usec_timer_mark(&cmptimer);
73597352 cpi->time_compress_data += vpx_usec_timer_elapsed(&cmptimer);
73607353
7361− // Should we calculate metrics for the frame.
7362− if (is_psnr_calc_enabled(cpi)) generate_psnr_packet(cpi);
7363−
73647354 if (cpi->keep_level_stats && oxcf->pass != 1)
73657355 update_level_info(cpi, size, arf_src_index);
73667356
vp9/encoder/vp9_encoder.h+3−0
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 #include "vpx_dsp/ssim.h"
2121 #endif
2222 #include "vpx_dsp/variance.h"
23+#include "vpx_dsp/psnr.h"
2324 #include "vpx_ports/system_state.h"
2425 #include "vpx_util/vpx_thread.h"
2526 #include "vpx_util/vpx_timestamp.h"
@@ -1063,6 +1064,8 @@ void vp9_new_framerate(VP9_COMP *cpi, double framerate); · 1037 unmodified lines
10631064
10641065 void vp9_set_row_mt(VP9_COMP *cpi);
10651066
1067+int vp9_get_psnr(const VP9_COMP *cpi, PSNR_STATS *psnr);
1068+
10661069 #define LAYER_IDS_TO_IDX(sl, tl, num_tl) ((sl) * (num_tl) + (tl))
10671070
10681071 #ifdef __cplusplus
vp9/vp9_cx_iface.c+19−0
@@ -13,6 +13,7 @@ · 12 unmodified lines
1313
1414 #include "./vpx_config.h"
1515 #include "vpx/vpx_encoder.h"
16+#include "vpx_dsp/psnr.h"
1617 #include "vpx_ports/vpx_once.h"
1718 #include "vpx_ports/system_state.h"
1819 #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
11171118 return flags;
11181119 }
11191120
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+
11201128 const size_t kMinCompressedSize = 8192;
11211129 static vpx_codec_err_t encoder_encode(vpx_codec_alg_priv_t *ctx,
11221130 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
12401248 -1 != vp9_get_compressed_data(cpi, &lib_flags, &size, cx_data,
12411249 &dst_time_stamp, &dst_end_time_stamp,
12421250 !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+
12431262 if (size || (cpi->use_svc && cpi->svc.skip_enhancement_layer)) {
12441263 // Pack invisible frames with the next visible frame
12451264 if (!cpi->common.show_frame ||

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t