Add vp9_extrc_update_encodeframe_result()
authorangiebird <angiebird@google.com>
Tue, 13 Oct 2020 00:58:16 +0000 (17:58 -0700)
committerAngie Chiang <angiebird@google.com>
Fri, 16 Oct 2020 01:52:05 +0000 (18:52 -0700)
Bug: webm:1707

Change-Id: I962ffa23f03b953f7c0dfd81f49dc79d1975bbba

vp9/encoder/vp9_encoder.c
vp9/encoder/vp9_ext_ratectrl.c
vp9/encoder/vp9_ext_ratectrl.h
vpx/vpx_ext_ratectrl.h

index bf338ee..3838a9d 100644 (file)
@@ -5479,6 +5479,13 @@ static void encode_frame_to_data_rate(
   // 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 @@ static void update_encode_frame_result(
 #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;
index 59b5c09..64414cd 100644 (file)
@@ -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); }
 
@@ -112,3 +113,28 @@ void vp9_extrc_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);
+  }
+}
index 990735e..82f300c 100644 (file)
@@ -36,4 +36,10 @@ void vp9_extrc_get_encodeframe_decision(
     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_
index 940227a..c994344 100644 (file)
@@ -133,7 +133,7 @@ typedef int (*vpx_rc_get_encodeframe_decision_cb_fn_t)(
  */
 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
  *