]> granicus.if.org Git - libvpx/commitdiff
Added the ability to accumulate coef stats across encodings
authorYaowu Xu <yaowu@google.com>
Tue, 8 May 2012 19:38:39 +0000 (12:38 -0700)
committerYaowu Xu <yaowu@google.com>
Tue, 12 Jun 2012 21:41:51 +0000 (14:41 -0700)
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

vp8/encoder/bitstream.c
vp8/encoder/onyx_if.c
vp8/encoder/tokenize.c

index f44705299fef03349b21d822bf550f74907dd131..27b585302ad3689787bddcc1e4d2f2edf854efd1 100644 (file)
@@ -35,14 +35,14 @@ unsigned __int64 Sectionbits[500];
 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 @@ void print_tree_update_probs()
     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,7 +2730,12 @@ void print_tree_update_probs()
 
     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++)
     {
@@ -2764,5 +2773,10 @@ void print_tree_update_probs()
         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
index 3896d977b094d808cc8bbbc2f93bc06b36d2621e..642ff64ebe8f95b9f762ee8e2146b0725e8211f7 100644 (file)
@@ -1742,7 +1742,8 @@ VP8_PTR vp8_create_compressor(VP8_CONFIG *oxcf)
     }
 
 #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 @@ void vp8_remove_compressor(VP8_PTR *ptr)
         }
 
 #ifdef ENTROPY_STATS
+    if(cpi->pass != 1)
+    {
         print_context_counters();
         print_tree_update_probs();
         print_mode_context();
+    }
 #endif
 
 #if CONFIG_INTERNAL_STATS
index 1d55244140d231ca8547871733d862c813ff372a..4bbe99fd0876e8b4d9f2977e254e7ecba03049fe 100644 (file)
 #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,25 +622,48 @@ void vp8_tokenize_mb(VP8_COMP *cpi, MACROBLOCKD *x, TOKENEXTRA **t)
 
 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()
 {
 
     int type, band, pt, t;
-
-    FILE *const f = fopen("context.c", "w");
+    FILE *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\nvp8_default_coef_counts[BLOCK_TYPES] [COEF_BANDS] [PREV_COEF_CONTEXTS] [MAX_ENTROPY_TOKENS] = {");
+    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");
 
 # define Comma( X) (X? ",":"")
-
     type = 0;
     do
     {
@@ -641,7 +672,6 @@ void print_context_counters()
         do
         {
             fprintf(f, "%s\n    { /* Coeff Band %d */", Comma(band), band);
-
             pt = 0;
             do
             {
@@ -817,6 +847,11 @@ void print_context_counters()
     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);
 }
 
 #endif