]> granicus.if.org Git - libvpx/commitdiff
Add moving-average bit rate stats
authorhui su <huisu@google.com>
Thu, 12 Nov 2015 02:39:23 +0000 (18:39 -0800)
committerhui su <huisu@google.com>
Wed, 18 Nov 2015 01:58:42 +0000 (17:58 -0800)
Change-Id: Id764e573776d4d0ee2c400a4eca0832268e1e2b1

vp9/decoder/vp9_decodeframe.c
vp9/decoder/vp9_decoder.h

index 38cd9529a5c4eda395ebd17034b7562f0a4c2643..d4b4b31c8d3926ce5a62818fa3536c9b69edde50 100644 (file)
@@ -2004,6 +2004,9 @@ void vp9_decode_frame(VP9Decoder *pbi,
       init_read_bit_buffer(pbi, &rb, data, data_end, clear_data));
   const int tile_rows = 1 << cm->log2_tile_rows;
   const int tile_cols = 1 << cm->log2_tile_cols;
+#if CONFIG_INTERNAL_STATS
+  const int64_t data_size = data_end - data;
+#endif
   YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm);
   xd->cur_buf = new_fb;
 
@@ -2036,6 +2039,11 @@ void vp9_decode_frame(VP9Decoder *pbi,
 #if CONFIG_INTERNAL_STATS
   // Reset internal stats
   if (cm->current_video_frame == 0) {
+    int i;
+    for (i = 0; i < BR_MOVING_AVERAGE_SIZE; ++i)
+      pbi->br_data.bit_rate[i] = 0;
+    pbi->br_data.index = 0;
+    pbi->peak_average_br = 0;
     pbi->total_block_in_8x8 = 0;
     pbi->subpel_mc_block_in_4x4_h = 0;
     pbi->subpel_mc_block_in_4x4_v = 0;
@@ -2119,6 +2127,7 @@ void vp9_decode_frame(VP9Decoder *pbi,
   vp9_clear_system_state();
   {
     FILE *pf = fopen("frame_level_stats.stt", "a");
+    int i;
     double subpel_mc_h = (double)pbi->subpel_mc_block_in_4x4_h /
         (double)pbi->total_block_in_8x8;
     double subpel_mc_v = (double)pbi->subpel_mc_block_in_4x4_v /
@@ -2131,11 +2140,24 @@ void vp9_decode_frame(VP9Decoder *pbi,
         (double)pbi->total_block_in_8x8;
     double sub8x8_intra = (double)pbi->sub8x8_intra /
         (double)pbi->total_block_in_8x8;
+    double average_bit_rate = 0;
+
+    pbi->br_data.bit_rate[pbi->br_data.index] = data_size;
+    ++pbi->br_data.index;
+    if (pbi->br_data.index >= BR_MOVING_AVERAGE_SIZE)
+      pbi->br_data.index = 0;
+    for (i = 0; i < BR_MOVING_AVERAGE_SIZE; ++i) {
+      average_bit_rate += (double)pbi->br_data.bit_rate[i];
+    }
+    average_bit_rate /= BR_MOVING_AVERAGE_SIZE;
+    if ((int64_t)average_bit_rate > pbi->peak_average_br)
+      pbi->peak_average_br = (int64_t)average_bit_rate;
 
     fprintf(pf, "frame index %d, sub-pel mc (%7.3f, %7.3f)\tintra mode%7.3f\tcompound inter block%7.3f\t",
             cm->current_video_frame, 25 * subpel_mc_h, 25 * subpel_mc_v, 100 * intra_mode,
             100 * compound_block);
-    fprintf(pf, "sub8x8 inter %7.3f intra %7.3f\n", 100 * sub8x8_inter, 100 * sub8x8_intra);
+    fprintf(pf, "sub8x8 inter %7.3f intra %7.3f average-br %7.3f peak-average-br %7.3f\n",
+            100 * sub8x8_inter, 100 * sub8x8_intra, average_bit_rate, (double)pbi->peak_average_br / 1000);
     fclose(pf);
   }
 #endif
index 4b3ced6bf35a9fedcd6b37d160f5179ad9cef76e..2f4da431c1a01c348a641a9c56057d8559174a2f 100644 (file)
 extern "C" {
 #endif
 
+#if CONFIG_INTERNAL_STATS
+#define BR_MOVING_AVERAGE_SIZE 4
+typedef struct BR_DATA {
+  int64_t bit_rate[BR_MOVING_AVERAGE_SIZE];
+  int index;
+} BR_DATA;
+#endif
+
 // TODO(hkuang): combine this with TileWorkerData.
 typedef struct TileData {
   VP9_COMMON *cm;
@@ -95,6 +103,10 @@ typedef struct VP9Decoder {
 
   // number of blocks using compound prediction mode.
   int64_t compound_inter_block_in_8x8;
+
+  // peak N-frame-average bit rate
+  int64_t peak_average_br;
+  BR_DATA br_data;
 #endif
 } VP9Decoder;