shithub: libvpx

Download patch

ref: e6208a95073f12f035fb554c1bd3e6a32a92f877
parent: 20bca1350a16af4c3346cfbf7f8f6c181e21a9ca
author: angiebird <angiebird@google.com>
date: Thu Oct 8 14:40:34 EDT 2020

Add vp9_extrc_send_firstpass_stats()

Change-Id: Ia2457b416200a2b2d1558600bff90ac2746cf396

--- a/vp9/encoder/vp9_ext_ratectrl.c
+++ b/vp9/encoder/vp9_ext_ratectrl.c
@@ -15,6 +15,7 @@
 
 void vp9_extrc_create(vpx_rc_funcs_t funcs, vpx_rc_config_t ratectrl_config,
                       EXT_RATECTRL *ext_ratectrl) {
+  vpx_rc_firstpass_stats_t *rc_firstpass_stats;
   vp9_extrc_delete(ext_ratectrl);
   ext_ratectrl->funcs = funcs;
   ext_ratectrl->ratectrl_config = ratectrl_config;
@@ -21,6 +22,11 @@
   ext_ratectrl->funcs.create_model(ext_ratectrl->funcs.priv,
                                    &ext_ratectrl->ratectrl_config,
                                    ext_ratectrl->model);
+  rc_firstpass_stats = &ext_ratectrl->rc_firstpass_stats;
+  rc_firstpass_stats->num_frames = ratectrl_config.show_frame_count;
+  rc_firstpass_stats->frame_stats =
+      vpx_malloc(sizeof(*rc_firstpass_stats->frame_stats) *
+                 rc_firstpass_stats->num_frames);
   ext_ratectrl->ready = 1;
 }
 
@@ -29,4 +35,49 @@
     ext_ratectrl->funcs.delete_model(ext_ratectrl->model);
   }
   vp9_extrc_init(ext_ratectrl);
+}
+
+static void gen_rc_firstpass_stats(const FIRSTPASS_STATS *stats,
+                                   double *rc_frame_stats) {
+  rc_frame_stats[0] = stats->frame;
+  rc_frame_stats[1] = stats->weight;
+  rc_frame_stats[2] = stats->intra_error;
+  rc_frame_stats[3] = stats->coded_error;
+  rc_frame_stats[4] = stats->sr_coded_error;
+  rc_frame_stats[5] = stats->frame_noise_energy;
+  rc_frame_stats[6] = stats->pcnt_inter;
+  rc_frame_stats[7] = stats->pcnt_motion;
+  rc_frame_stats[8] = stats->pcnt_second_ref;
+  rc_frame_stats[9] = stats->pcnt_neutral;
+  rc_frame_stats[10] = stats->pcnt_intra_low;
+  rc_frame_stats[11] = stats->pcnt_intra_high;
+  rc_frame_stats[12] = stats->intra_skip_pct;
+  rc_frame_stats[13] = stats->intra_smooth_pct;
+  rc_frame_stats[14] = stats->inactive_zone_rows;
+  rc_frame_stats[15] = stats->inactive_zone_cols;
+  rc_frame_stats[16] = stats->MVr;
+  rc_frame_stats[17] = stats->mvr_abs;
+  rc_frame_stats[18] = stats->MVc;
+  rc_frame_stats[19] = stats->mvc_abs;
+  rc_frame_stats[20] = stats->MVrv;
+  rc_frame_stats[21] = stats->MVcv;
+  rc_frame_stats[22] = stats->mv_in_out_count;
+  rc_frame_stats[23] = stats->duration;
+  rc_frame_stats[24] = stats->count;
+}
+
+void vp9_extrc_send_firstpass_stats(const FIRST_PASS_INFO *first_pass_info,
+                                    EXT_RATECTRL *ext_ratectrl) {
+  if (ext_ratectrl->ready) {
+    vpx_rc_firstpass_stats_t *rc_firstpass_stats =
+        &ext_ratectrl->rc_firstpass_stats;
+    int i;
+    assert(rc_firstpass_stats->num_frames == first_pass_info->num_frames);
+    for (i = 0; i < rc_firstpass_stats->num_frames; ++i) {
+      gen_rc_firstpass_stats(&first_pass_info->stats[i],
+                             rc_firstpass_stats->frame_stats[i]);
+    }
+    ext_ratectrl->funcs.send_firstpass_stats(ext_ratectrl->model,
+                                             rc_firstpass_stats);
+  }
 }
--- a/vp9/encoder/vp9_ext_ratectrl.h
+++ b/vp9/encoder/vp9_ext_ratectrl.h
@@ -12,6 +12,7 @@
 #define VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_
 
 #include "vpx/vpx_ext_ratectrl.h"
+#include "vp9/encoder/vp9_firstpass.h"
 
 typedef struct EXT_RATECTRL {
   int ready;
@@ -18,6 +19,7 @@
   vpx_rc_model_t model;
   vpx_rc_funcs_t funcs;
   vpx_rc_config_t ratectrl_config;
+  vpx_rc_firstpass_stats_t rc_firstpass_stats;
 } EXT_RATECTRL;
 
 void vp9_extrc_init(EXT_RATECTRL *ext_ratectrl);
@@ -26,5 +28,8 @@
                       EXT_RATECTRL *ext_ratectrl);
 
 void vp9_extrc_delete(EXT_RATECTRL *ext_ratectrl);
+
+void vp9_extrc_send_firstpass_stats(const FIRST_PASS_INFO *first_pass_info,
+                                    EXT_RATECTRL *ext_ratectrl);
 
 #endif  // VPX_VP9_ENCODER_VP9_EXT_RATECTRL_H_
--- a/vpx/vpx_ext_ratectrl.h
+++ b/vpx/vpx_ext_ratectrl.h
@@ -36,7 +36,7 @@
 } vpx_rc_encodeframe_result_t;
 
 typedef struct vpx_rc_firstpass_stats {
-  double (*frame_stats)[26];
+  double (*frame_stats)[25];
   int num_frames;
 } vpx_rc_firstpass_stats_t;