shithub: libvpx

Download patch

ref: 8bfc92063138476dee2d719ec45bb95d16a1a38f
parent: f71dd6e23e9d238ab0b03cdf105db733b8486778
author: angiebird <angiebird@google.com>
date: Mon Oct 12 13:58:16 EDT 2020

Add vp9_extrc_update_encodeframe_result()

Bug: webm:1707

Change-Id: I962ffa23f03b953f7c0dfd81f49dc79d1975bbba

--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -5479,6 +5479,13 @@
   // build the bitstream
   vp9_pack_bitstream(cpi, dest, size);
 
+  {
+    const RefCntBuffer *coded_frame_buf =
+        get_ref_cnt_buffer(cm, cm->new_fb_idx);
+    vp9_extrc_update_encodeframe_result(&cpi->ext_ratectrl, (*size) << 3,
+                                        cpi->Source, &coded_frame_buf->buf,
+                                        cpi->oxcf.input_bit_depth);
+  }
 #if CONFIG_REALTIME_ONLY
   (void)encode_frame_result;
   assert(encode_frame_result == NULL);
@@ -7541,7 +7548,7 @@
 #if CONFIG_RATE_CTRL
   PSNR_STATS psnr;
 #if CONFIG_VP9_HIGHBITDEPTH
-  vpx_calc_highbd_psnr(source_frame, coded_frame_buf->buf, &psnr, bit_depth,
+  vpx_calc_highbd_psnr(source_frame, &coded_frame_buf->buf, &psnr, bit_depth,
                        input_bit_depth);
 #else   // CONFIG_VP9_HIGHBITDEPTH
   (void)bit_depth;
--- a/vp9/encoder/vp9_ext_ratectrl.c
+++ b/vp9/encoder/vp9_ext_ratectrl.c
@@ -10,6 +10,7 @@
 
 #include "vp9/encoder/vp9_ext_ratectrl.h"
 #include "vp9/common/vp9_common.h"
+#include "vpx_dsp/psnr.h"
 
 void vp9_extrc_init(EXT_RATECTRL *ext_ratectrl) { vp9_zero(*ext_ratectrl); }
 
@@ -110,5 +111,30 @@
     encode_frame_info.frame_type = extrc_get_frame_type(update_type);
     ext_ratectrl->funcs.get_encodeframe_decision(
         ext_ratectrl->model, &encode_frame_info, encode_frame_decision);
+  }
+}
+
+void vp9_extrc_update_encodeframe_result(EXT_RATECTRL *ext_ratectrl,
+                                         int64_t bit_count,
+                                         const YV12_BUFFER_CONFIG *source_frame,
+                                         const YV12_BUFFER_CONFIG *coded_frame,
+                                         uint32_t input_bit_depth) {
+  if (ext_ratectrl->ready) {
+    PSNR_STATS psnr;
+    vpx_rc_encodeframe_result_t encode_frame_result;
+    encode_frame_result.bit_count = bit_count;
+    encode_frame_result.pixel_count =
+        source_frame->y_width * source_frame->y_height +
+        2 * source_frame->uv_width * source_frame->uv_height;
+#if CONFIG_VP9_HIGHBITDEPTH
+    vpx_calc_highbd_psnr(source_frame, coded_frame, &psnr,
+                         source_frame->bit_depth, input_bit_depth);
+#else
+    (void)input_bit_depth;
+    vpx_calc_psnr(source_frame, coded_frame, &psnr);
+#endif
+    encode_frame_result.sse = psnr.sse[0];
+    ext_ratectrl->funcs.update_encodeframe_result(ext_ratectrl->model,
+                                                  &encode_frame_result);
   }
 }
--- a/vp9/encoder/vp9_ext_ratectrl.h
+++ b/vp9/encoder/vp9_ext_ratectrl.h
@@ -36,4 +36,10 @@
     EXT_RATECTRL *ext_ratectrl, const GF_GROUP *gf_group, int show_index,
     int coding_index, vpx_rc_encodeframe_decision_t *encode_frame_decision);
 
+void vp9_extrc_update_encodeframe_result(EXT_RATECTRL *ext_ratectrl,
+                                         int64_t bit_count,
+                                         const YV12_BUFFER_CONFIG *source_frame,
+                                         const YV12_BUFFER_CONFIG *coded_frame,
+                                         uint32_t input_bit_depth);
+
 #endif  // VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_
--- a/vpx/vpx_ext_ratectrl.h
+++ b/vpx/vpx_ext_ratectrl.h
@@ -133,7 +133,7 @@
  */
 typedef int (*vpx_rc_update_encodeframe_result_cb_fn_t)(
     vpx_rc_model_t rate_ctrl_model,
-    vpx_rc_encodeframe_result_t *encode_frame_result);
+    const vpx_rc_encodeframe_result_t *encode_frame_result);
 
 /*!\brief Delete the external rate control model callback prototype
  *