shithub: libvpx

Download patch

ref: bb25083d65c4892c0f2fb585588b0c52c1c11b11
parent: 36fe9735a96855095a8dc1a298b6eaeb579783a2
author: Yaowu Xu <yaowu@google.com>
date: Tue May 8 08:38:39 EDT 2012

Added the ability to accumulate coef stats across encodings

This commit added the ability to accumulate the coef stats across
different encodings using an intermediate binary stats files. The
accumulation happens only the binary stats file exists in current
directory. The encoder needs to be built with "ENTROPY_STATS" to
allow the output. The commit also fixed a few formating issues in
output stats file.

Change-Id: Ib1a41180aa554845cf51e4421a230b128a3a82b4

--- a/vp8/encoder/bitstream.c
+++ b/vp8/encoder/bitstream.c
@@ -35,14 +35,14 @@
 int intra_mode_stats[VP8_BINTRAMODES]
                     [VP8_BINTRAMODES]
                     [VP8_BINTRAMODES];
-static unsigned int tree_update_hist [BLOCK_TYPES]
-                                     [COEF_BANDS]
-                                     [PREV_COEF_CONTEXTS]
-                                     [ENTROPY_NODES] [2]={0};
-static unsigned int tree_update_hist_8x8 [BLOCK_TYPES_8X8]
-                                         [COEF_BANDS]
-                                         [PREV_COEF_CONTEXTS]
-                                         [ENTROPY_NODES] [2]={0};
+unsigned int tree_update_hist [BLOCK_TYPES]
+                              [COEF_BANDS]
+                              [PREV_COEF_CONTEXTS]
+                              [ENTROPY_NODES][2];
+unsigned int tree_update_hist_8x8 [BLOCK_TYPES_8X8]
+                                  [COEF_BANDS]
+                                  [PREV_COEF_CONTEXTS]
+                                  [ENTROPY_NODES] [2];
 
 extern unsigned int active_section;
 #endif
@@ -2686,7 +2686,11 @@
     FILE *f = fopen("coefupdprob.h", "w");
     int Sum;
     fprintf(f, "\n/* Update probabilities for token entropy tree. */\n\n");
-    fprintf(f, "const vp8_prob tree_update_probs[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] = {\n");
+    fprintf(f, "const vp8_prob\n"
+               "vp8_coef_update_probs[BLOCK_TYPES]\n"
+               "                     [COEF_BANDS]\n"
+               "                     [PREV_COEF_CONTEXTS]\n"
+               "                     [ENTROPY_NODES] = {\n");
 
     for (i = 0; i < BLOCK_TYPES; i++)
     {
@@ -2726,8 +2730,13 @@
 
     fprintf(f, "};\n");
 
-    fprintf(f, "const vp8_prob tree_update_probs_8x8[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [ENTROPY_NODES] = {\n");
+    fprintf(f, "const vp8_prob\n"
+               "vp8_coef_update_probs_8x8[BLOCK_TYPES_8X8]\n"
+               "                         [COEF_BANDS]\n"
+               "                         [PREV_COEF_CONTEXTS]\n"
+               "                         [ENTROPY_NODES] = {\n");
 
+
     for (i = 0; i < BLOCK_TYPES_8X8; i++)
     {
         fprintf(f, "  { \n");
@@ -2764,5 +2773,10 @@
         fprintf(f, "  },\n");
     }
     fclose(f);
+    f = fopen("treeupdate.bin", "wb");
+    fwrite(tree_update_hist, sizeof(tree_update_hist), 1, f);
+    fwrite(tree_update_hist_8x8, sizeof(tree_update_hist_8x8), 1, f);
+    fclose(f);
+
 }
 #endif
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -1742,7 +1742,8 @@
     }
 
 #ifdef ENTROPY_STATS
-    init_context_counters();
+    if(cpi->pass != 1)
+        init_context_counters();
 #endif
 #ifdef MODE_STATS
     vp8_zero(y_modes);
@@ -1978,9 +1979,12 @@
         }
 
 #ifdef ENTROPY_STATS
+    if(cpi->pass != 1)
+    {
         print_context_counters();
         print_tree_update_probs();
         print_mode_context();
+    }
 #endif
 
 #if CONFIG_INTERNAL_STATS
--- a/vp8/encoder/tokenize.c
+++ b/vp8/encoder/tokenize.c
@@ -26,6 +26,14 @@
 #ifdef ENTROPY_STATS
 INT64 context_counters[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
 INT64 context_counters_8x8[BLOCK_TYPES_8X8] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS];
+extern unsigned int tree_update_hist [BLOCK_TYPES]
+                                     [COEF_BANDS]
+                                     [PREV_COEF_CONTEXTS]
+                                     [ENTROPY_NODES][2];
+extern unsigned int tree_update_hist_8x8 [BLOCK_TYPES_8X8]
+                                         [COEF_BANDS]
+                                         [PREV_COEF_CONTEXTS]
+                                         [ENTROPY_NODES] [2];
 #endif
 void vp8_stuff_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) ;
 void vp8_stuff_mb_8x8(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t) ;
@@ -614,8 +622,31 @@
 
 void init_context_counters(void)
 {
-    vpx_memset(context_counters, 0, sizeof(context_counters));
-    vpx_memset(context_counters_8x8, 0, sizeof(context_counters_8x8));
+    FILE *f = fopen("context.bin", "rb");
+    if(!f)
+    {
+        vpx_memset(context_counters, 0, sizeof(context_counters));
+        vpx_memset(context_counters_8x8, 0, sizeof(context_counters_8x8));
+    }
+    else
+    {
+        fread(context_counters, sizeof(context_counters), 1, f);
+        fread(context_counters_8x8, sizeof(context_counters_8x8), 1, f);
+        fclose(f);
+    }
+
+    f = fopen("treeupdate.bin", "rb");
+    if(!f)
+    {
+        vpx_memset(tree_update_hist, 0, sizeof(tree_update_hist));
+        vpx_memset(tree_update_hist_8x8, 0, sizeof(tree_update_hist_8x8));
+    }
+    else
+    {
+        fread(tree_update_hist, sizeof(tree_update_hist), 1, f);
+        fread(tree_update_hist_8x8, sizeof(tree_update_hist_8x8), 1, f);
+        fclose(f);
+    }
 }
 
 void print_context_counters()
@@ -622,17 +653,17 @@
 {
 
     int type, band, pt, t;
+    FILE *f = fopen("context.c", "w");
 
-    FILE *const f = fopen("context.c", "w");
-
     fprintf(f, "#include \"entropy.h\"\n");
-
     fprintf(f, "\n/* *** GENERATED FILE: DO NOT EDIT *** */\n\n");
+    fprintf(f, "static const unsigned int\n"
+               "vp8_default_coef_counts[BLOCK_TYPES]\n"
+               "                      [COEF_BANDS]\n"
+               "                      [PREV_COEF_CONTEXTS]\n"
+               "                      [MAX_ENTROPY_TOKENS]={\n");
 
-    fprintf(f, "static const unsigned int\nvp8_default_coef_counts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {");
-
 # define Comma( X) (X? ",":"")
-
     type = 0;
     do
     {
@@ -641,7 +672,6 @@
         do
         {
             fprintf(f, "%s\n    { /* Coeff Band %d */", Comma(band), band);
-
             pt = 0;
             do
             {
@@ -816,6 +846,11 @@
     while (++type < BLOCK_TYPES_8X8);
     fprintf(f, "\n};\n");
 
+    fclose(f);
+
+    f = fopen("context.bin", "wb");
+    fwrite(context_counters, sizeof(context_counters), 1, f);
+    fwrite(context_counters_8x8, sizeof(context_counters_8x8), 1, f);
     fclose(f);
 }
 
--