[xiph-commits] r17645 - in trunk/theora: lib tools

giles at svn.xiph.org giles at svn.xiph.org
Wed Nov 24 12:51:36 PST 2010


Author: giles
Date: 2010-11-24 12:51:36 -0800 (Wed, 24 Nov 2010)
New Revision: 17645

Modified:
   trunk/theora/lib/analyze.c
   trunk/theora/lib/collect.c
   trunk/theora/lib/collect.h
   trunk/theora/lib/encint.h
   trunk/theora/lib/modedec.h
   trunk/theora/tools/process_modedec_stats.c
Log:
Rename OC_SAD_SHIFT to OC_SATD_SHIFT.

The SAD and SADT metrics have different ranges, so it is
necessary to use different scale factors when comparing
them.

Originally we used SAD, and when SATD was added, the
scale factor was updated without changing the name.
This commit finally does so. However, it is intended
that the code switch back to the SAD metric at higher
speed levels, we also keep OC_SAD_SHIFT with its
appropriate value, 6 according to Tim.

Likewise, OC_SAD_BINS is renamed OC_COMP_BINS in
expectation of supporting mode tables for both
metrics.

Modified: trunk/theora/lib/analyze.c
===================================================================
--- trunk/theora/lib/analyze.c	2010-11-24 20:46:15 UTC (rev 17644)
+++ trunk/theora/lib/analyze.c	2010-11-24 20:51:36 UTC (rev 17645)
@@ -1082,7 +1082,7 @@
         dx=OC_MODE_LOGQ[modeline][pli][qti]-log_plq;
         dq=OC_MODE_LOGQ[modeline][pli][qti]-OC_MODE_LOGQ[modeline+1][pli][qti];
         if(dq==0)dq=1;
-        for(bin=0;bin<OC_SAD_BINS;bin++){
+        for(bin=0;bin<OC_COMP_BINS;bin++){
           int y0;
           int z0;
           int dy;
@@ -1115,15 +1115,15 @@
   /*SATD metrics for chroma planes vary much less than luma, so we scale them
      by 4 to distribute them into the mode decision bins more evenly.*/
   _satd<<=_pli+1&2;
-  bin=OC_MINI(_satd>>OC_SAD_SHIFT,OC_SAD_BINS-2);
-  dx=_satd-(bin<<OC_SAD_SHIFT);
+  bin=OC_MINI(_satd>>OC_SATD_SHIFT,OC_COMP_BINS-2);
+  dx=_satd-(bin<<OC_SATD_SHIFT);
   y0=_enc->mode_rd[_qii][_pli][_qti][bin].rate;
   z0=_enc->mode_rd[_qii][_pli][_qti][bin].rmse;
   dy=_enc->mode_rd[_qii][_pli][_qti][bin+1].rate-y0;
   dz=_enc->mode_rd[_qii][_pli][_qti][bin+1].rmse-z0;
-  rmse=OC_MAXI(z0+(dz*dx>>OC_SAD_SHIFT),0);
+  rmse=OC_MAXI(z0+(dz*dx>>OC_SATD_SHIFT),0);
   *_ssd=rmse*rmse>>2*OC_RMSE_SCALE-OC_BIT_SCALE;
-  return OC_MAXI(y0+(dy*dx>>OC_SAD_SHIFT),0);
+  return OC_MAXI(y0+(dy*dx>>OC_SATD_SHIFT),0);
 }
 
 /*activity_avg must be positive, or flat regions could get a zero weight, which

Modified: trunk/theora/lib/collect.c
===================================================================
--- trunk/theora/lib/collect.c	2010-11-24 20:46:15 UTC (rev 17644)
+++ trunk/theora/lib/collect.c	2010-11-24 20:51:36 UTC (rev 17645)
@@ -23,8 +23,8 @@
 #if defined(OC_COLLECT_METRICS)
 
 int              OC_HAS_MODE_METRICS;
-double           OC_MODE_RD_WEIGHT[OC_LOGQ_BINS][3][2][OC_SAD_BINS];
-oc_mode_metrics  OC_MODE_METRICS[OC_LOGQ_BINS-1][3][2][OC_SAD_BINS];
+double           OC_MODE_RD_WEIGHT[OC_LOGQ_BINS][3][2][OC_COMP_BINS];
+oc_mode_metrics  OC_MODE_METRICS[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];
 const char      *OC_MODE_METRICS_FILENAME="modedec.stats";
 
 void oc_mode_metrics_add(oc_mode_metrics *_metrics,
@@ -424,7 +424,7 @@
   dd=dr=INT_MAX;
   niters=0;
   /*The encoder interpolates rate and RMSE terms bilinearly from an
-     OC_LOGQ_BINS by OC_SAD_BINS grid of sample points in OC_MODE_RD.
+     OC_LOGQ_BINS by OC_COMP_BINS grid of sample points in OC_MODE_RD.
     To find the sample values at the grid points that minimize the total
      squared prediction error actually requires solving a relatively sparse
      linear system with a number of variables equal to the number of grid
@@ -439,7 +439,7 @@
     for(pli=0;pli<3;pli++){
       for(qti=0;qti<2;qti++){
         for(qi=0;qi<OC_LOGQ_BINS;qi++){
-          for(si=0;si<OC_SAD_BINS;si++){
+          for(si=0;si<OC_COMP_BINS;si++){
             oc_mode_metrics m[4];
             int             s0[4];
             int             s1[4];
@@ -463,8 +463,8 @@
             if(qi>0&&si>0){
               q0[n]=OC_MODE_LOGQ[qi-1][pli][qti];
               q1[n]=OC_MODE_LOGQ[qi][pli][qti];
-              s0[n]=si-1<<OC_SAD_SHIFT;
-              s1[n]=si<<OC_SAD_SHIFT;
+              s0[n]=si-1<<OC_SATD_SHIFT;
+              s1[n]=si<<OC_SATD_SHIFT;
               ra[n]=ldexp(OC_MODE_RD[qi-1][pli][qti][si-1].rate,-OC_BIT_SCALE);
               da[n]=ldexp(OC_MODE_RD[qi-1][pli][qti][si-1].rmse,-OC_RMSE_SCALE);
               rb[n]=ldexp(OC_MODE_RD[qi-1][pli][qti][si].rate,-OC_BIT_SCALE);
@@ -474,11 +474,11 @@
               *(m+n++)=*(OC_MODE_METRICS[qi-1][pli][qti]+si-1);
             }
             if(qi>0){
-              ds=si+1<OC_SAD_BINS?1:-1;
+              ds=si+1<OC_COMP_BINS?1:-1;
               q0[n]=OC_MODE_LOGQ[qi-1][pli][qti];
               q1[n]=OC_MODE_LOGQ[qi][pli][qti];
-              s0[n]=si+ds<<OC_SAD_SHIFT;
-              s1[n]=si<<OC_SAD_SHIFT;
+              s0[n]=si+ds<<OC_SATD_SHIFT;
+              s1[n]=si<<OC_SATD_SHIFT;
               ra[n]=ldexp(OC_MODE_RD[qi-1][pli][qti][si+ds].rate,-OC_BIT_SCALE);
               da[n]=
                ldexp(OC_MODE_RD[qi-1][pli][qti][si+ds].rmse,-OC_RMSE_SCALE);
@@ -491,8 +491,8 @@
             if(qi+1<OC_LOGQ_BINS&&si>0){
               q0[n]=OC_MODE_LOGQ[qi+1][pli][qti];
               q1[n]=OC_MODE_LOGQ[qi][pli][qti];
-              s0[n]=si-1<<OC_SAD_SHIFT;
-              s1[n]=si<<OC_SAD_SHIFT;
+              s0[n]=si-1<<OC_SATD_SHIFT;
+              s1[n]=si<<OC_SATD_SHIFT;
               ra[n]=ldexp(OC_MODE_RD[qi+1][pli][qti][si-1].rate,-OC_BIT_SCALE);
               da[n]=ldexp(OC_MODE_RD[qi+1][pli][qti][si-1].rmse,-OC_RMSE_SCALE);
               rb[n]=ldexp(OC_MODE_RD[qi+1][pli][qti][si].rate,-OC_BIT_SCALE);
@@ -502,11 +502,11 @@
               *(m+n++)=*(OC_MODE_METRICS[qi][pli][qti]+si-1);
             }
             if(qi+1<OC_LOGQ_BINS){
-              ds=si+1<OC_SAD_BINS?1:-1;
+              ds=si+1<OC_COMP_BINS?1:-1;
               q0[n]=OC_MODE_LOGQ[qi+1][pli][qti];
               q1[n]=OC_MODE_LOGQ[qi][pli][qti];
-              s0[n]=si+ds<<OC_SAD_SHIFT;
-              s1[n]=si<<OC_SAD_SHIFT;
+              s0[n]=si+ds<<OC_SATD_SHIFT;
+              s1[n]=si<<OC_SATD_SHIFT;
               ra[n]=ldexp(OC_MODE_RD[qi+1][pli][qti][si+ds].rate,-OC_BIT_SCALE);
               da[n]=
                ldexp(OC_MODE_RD[qi+1][pli][qti][si+ds].rmse,-OC_RMSE_SCALE);
@@ -559,7 +559,7 @@
     for(pli=0;pli<3;pli++){
       for(qti=0;qti<2;qti++){
         for(qi=0;qi<OC_LOGQ_BINS;qi++){
-          for(si=0;si<OC_SAD_BINS;si++){
+          for(si=0;si<OC_COMP_BINS;si++){
             double wt;
             wt=OC_MODE_RD_WEIGHT[qi][pli][qti][si];
             wt/=OC_ZWEIGHT+wt;
@@ -615,7 +615,7 @@
    "# if !defined(OC_COLLECT_METRICS)\n"
    "static const\n"
    "# endif\n"
-   "oc_mode_rd OC_MODE_RD[OC_LOGQ_BINS][3][2][OC_SAD_BINS]={\n");
+   "oc_mode_rd OC_MODE_RD[OC_LOGQ_BINS][3][2][OC_COMP_BINS]={\n");
   for(qii=0;qii<OC_LOGQ_BINS;qii++){
     int pli;
     fprintf(_fout,"  {\n");
@@ -632,12 +632,12 @@
          pl_names[pli],qi,qti_names[qti]);
         fprintf(_fout,"      {\n");
         fprintf(_fout,"        ");
-        for(bin=0;bin<OC_SAD_BINS;bin++){
+        for(bin=0;bin<OC_COMP_BINS;bin++){
           if(bin&&!(bin&0x3))fprintf(_fout,"\n        ");
           fprintf(_fout,"{%5i,%5i}",
            OC_MODE_RD[qii][pli][qti][bin].rate,
            OC_MODE_RD[qii][pli][qti][bin].rmse);
-          if(bin+1<OC_SAD_BINS)fprintf(_fout,",");
+          if(bin+1<OC_COMP_BINS)fprintf(_fout,",");
         }
         fprintf(_fout,"\n      }");
         if(qti<1)fprintf(_fout,",");
@@ -915,7 +915,7 @@
       qii=frags[fragi].qii;
       qi=_enc->state.qis[qii];
       satd=frag_satd[fragi]<<(pli+1&2);
-      bin=OC_MINI(satd>>OC_SAD_SHIFT,OC_SAD_BINS-1);
+      bin=OC_MINI(satd>>OC_SATD_SHIFT,OC_COMP_BINS-1);
       qtj=mb_mode!=OC_MODE_INTRA;
       /*Accumulate statistics.
         The rate (frag_bits) and RMSE (sqrt(frag_ssd)) are not scaled by

Modified: trunk/theora/lib/collect.h
===================================================================
--- trunk/theora/lib/collect.h	2010-11-24 20:46:15 UTC (rev 17644)
+++ trunk/theora/lib/collect.h	2010-11-24 20:51:36 UTC (rev 17645)
@@ -79,10 +79,10 @@
    out the contributions from AC and DC into separate tables.*/
 
 extern ogg_int16_t OC_MODE_LOGQ[OC_LOGQ_BINS][3][2];
-extern oc_mode_rd  OC_MODE_RD[OC_LOGQ_BINS][3][2][OC_SAD_BINS];
+extern oc_mode_rd  OC_MODE_RD[OC_LOGQ_BINS][3][2][OC_COMP_BINS];
 
 extern int              OC_HAS_MODE_METRICS;
-extern oc_mode_metrics  OC_MODE_METRICS[OC_LOGQ_BINS-1][3][2][OC_SAD_BINS];
+extern oc_mode_metrics  OC_MODE_METRICS[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];
 extern const char      *OC_MODE_METRICS_FILENAME;
 
 void oc_mode_metrics_dump();

Modified: trunk/theora/lib/encint.h
===================================================================
--- trunk/theora/lib/encint.h	2010-11-24 20:46:15 UTC (rev 17644)
+++ trunk/theora/lib/encint.h	2010-11-24 20:51:36 UTC (rev 17645)
@@ -222,13 +222,13 @@
 # define OC_RMSE_SCALE (5)
 /*The number of quantizer bins to partition statistics into.*/
 # define OC_LOGQ_BINS  (8)
-/*The number of SATD bins to partition statistics into.*/
-# define OC_SAD_BINS   (24)
-/*The number of bits of precision to drop from SAD scores to assign them to a
-   bin.*/
-# define OC_SAD_SHIFT  (9)
+/*The number of SAD/SATD bins to partition statistics into.*/
+# define OC_COMP_BINS   (24)
+/*The number of bits of precision to drop from SAD and SATD scores
+   to assign them to a bin.*/
+# define OC_SAD_SHIFT  (6)
+# define OC_SATD_SHIFT (9)
 
-
 /*Masking is applied by scaling the D used in R-D optimization (via rd_scale)
    or the lambda parameter (via rd_iscale).
   These are only equivalent within a single block; when more than one block is
@@ -721,7 +721,7 @@
   ogg_uint16_t             chroma_rd_scale[2][64][2];
   /*The interpolated mode decision R-D lookup tables for the current
      quantizers, color plane, and quantization type.*/
-  oc_mode_rd               mode_rd[3][3][2][OC_SAD_BINS];
+  oc_mode_rd               mode_rd[3][3][2][OC_COMP_BINS];
   /*The buffer state used to drive rate control.*/
   oc_rc_state              rc;
 # if defined(OC_ENC_USE_VTABLE)

Modified: trunk/theora/lib/modedec.h
===================================================================
--- trunk/theora/lib/modedec.h	2010-11-24 20:46:15 UTC (rev 17644)
+++ trunk/theora/lib/modedec.h	2010-11-24 20:51:36 UTC (rev 17645)
@@ -26,7 +26,7 @@
 # if !defined(OC_COLLECT_METRICS)
 static const
 # endif
-oc_mode_rd OC_MODE_RD[OC_LOGQ_BINS][3][2][OC_SAD_BINS]={
+oc_mode_rd OC_MODE_RD[OC_LOGQ_BINS][3][2][OC_COMP_BINS]={
   {
     {
       /*Y'  qi=0  INTRA*/

Modified: trunk/theora/tools/process_modedec_stats.c
===================================================================
--- trunk/theora/tools/process_modedec_stats.c	2010-11-24 20:46:15 UTC (rev 17644)
+++ trunk/theora/tools/process_modedec_stats.c	2010-11-24 20:51:36 UTC (rev 17645)
@@ -12,10 +12,10 @@
 
 
 ogg_int16_t     OC_MODE_LOGQ_TMP[OC_LOGQ_BINS][3][2];
-oc_mode_metrics OC_MODE_METRICS_TMP[OC_LOGQ_BINS-1][3][2][OC_SAD_BINS];
+oc_mode_metrics OC_MODE_METRICS_TMP[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];
 
 ogg_int16_t     OC_MODE_LOGQ_BASE[OC_LOGQ_BINS][3][2];
-oc_mode_metrics OC_MODE_METRICS_BASE[OC_LOGQ_BINS-1][3][2][OC_SAD_BINS];
+oc_mode_metrics OC_MODE_METRICS_BASE[OC_LOGQ_BINS-1][3][2][OC_COMP_BINS];
 
 
 
@@ -129,7 +129,7 @@
                _argv[i]);
               return EXIT_FAILURE;
             }
-            for(si=0;si<OC_SAD_BINS;si++){
+            for(si=0;si<OC_COMP_BINS;si++){
               oc_mode_metrics m[3];
               *(m+0)=*(OC_MODE_METRICS[qi][pli][qti]+si);
               *(m+1)=*(OC_MODE_METRICS_TMP[qi][pli][qti]+si);



More information about the commits mailing list