[xiph-commits] r14785 - branches/theora-thusnelda/lib/enc

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Apr 22 15:51:36 PDT 2008


Author: xiphmont
Date: 2008-04-22 15:51:35 -0700 (Tue, 22 Apr 2008)
New Revision: 14785

Modified:
   branches/theora-thusnelda/lib/enc/codec_internal.h
   branches/theora-thusnelda/lib/enc/encode.c
   branches/theora-thusnelda/lib/enc/mode.c
Log:
More rho domain analysis work in progress 


Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2008-04-22 18:09:00 UTC (rev 14784)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2008-04-22 22:51:35 UTC (rev 14785)
@@ -255,7 +255,8 @@
 
   /********************************************************************/
   /* Fragment SAD->bitrate estimation tracking metrics */
-  ogg_uint32_t     rho_count[65]; 
+  long             rho_count[65]; 
+  long             mrho_count[65]; 
 
 #ifdef COLLECT_METRICS
   int             *frag_mbi;

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2008-04-22 18:09:00 UTC (rev 14784)
+++ branches/theora-thusnelda/lib/enc/encode.c	2008-04-22 22:51:35 UTC (rev 14785)
@@ -218,20 +218,24 @@
   }
 }
 
-static void EncodeTokenList (CP_INSTANCE *cpi, int huff[4]) {
+static long EncodeTokenList (CP_INSTANCE *cpi, int huff[4]) {
   int i;
   oggpack_buffer *opb=cpi->oggbuffer;
+  long bits0,bits1;
 
   /* DC tokens aren't special, they just come first */
   oggpackB_write( opb, huff[0] - DC_HUFF_OFFSET, DC_HUFF_CHOICE_BITS );
   oggpackB_write( opb, huff[1] - DC_HUFF_OFFSET, DC_HUFF_CHOICE_BITS );
 
+  bits0 = oggpackB_bits(opb);
   EncodeTokenGroup(cpi, 0,  huff[0], huff[1]);
+  bits0 = oggpackB_bits(opb)-bits0;
 
   /* AC tokens */
   oggpackB_write( opb, huff[2] - AC_HUFF_OFFSET, AC_HUFF_CHOICE_BITS );
   oggpackB_write( opb, huff[3] - AC_HUFF_OFFSET, AC_HUFF_CHOICE_BITS );
 
+  bits1 = oggpackB_bits(opb);
   for(i=1;i<=AC_TABLE_2_THRESH;i++)
     EncodeTokenGroup(cpi, i,  huff[2], huff[3]);
 
@@ -243,7 +247,9 @@
 
   for(;i<BLOCK_SIZE;i++)
     EncodeTokenGroup(cpi, i,  huff[2]+AC_HUFF_CHOICES*3, huff[3]+AC_HUFF_CHOICES*3);
+  bits1 = oggpackB_bits(opb)-bits1;
 
+  return bits1;
 }
 
 static const unsigned char NoOpModeWords[8] = {0,1,2,3,4,5,6,7};
@@ -367,7 +373,7 @@
 #ifdef COLLECT_METRICS
   ModeMetrics(cpi,tokenhuff);
 #endif
-  EncodeTokenList(cpi, tokenhuff);
+  long bitsDCT = EncodeTokenList(cpi, tokenhuff);
   bits = oggpackB_bits(cpi->oggbuffer);
   
   ReconRefFrames(cpi);

Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c	2008-04-22 18:09:00 UTC (rev 14784)
+++ branches/theora-thusnelda/lib/enc/mode.c	2008-04-22 22:51:35 UTC (rev 14785)
@@ -496,7 +496,8 @@
   return i+1;
 }
 
-static void TQB (CP_INSTANCE *cpi, int mode, int fi, mv_t mv, int plane, ogg_int16_t re_q[2][3][64], int *rho_count){
+static void TQB (CP_INSTANCE *cpi, int mode, int fi, mv_t mv, int plane, ogg_int16_t re_q[2][3][64], 
+		 long *rho_count, long *mrho_count){
   if ( cpi->frag_coded[fi] ) {
     int qi = cpi->BaseQ; /* temporary */;
     int inter = (mode != CODE_INTRA);
@@ -557,17 +558,30 @@
     
     /* collect rho metrics, quantize */
     {
+      /* modified rho-domain (track zero-runs as well) */
+	/* ZXZ; splits one zero run into two zero runs and a nonzero; +2
+	   ZXN; adds one nonzero token; +1
+	   NXZ; adds one nonzero token; +1
+	   NXN; replaces a zero run with a nonzero; +0  */
       int i;
+      int lastpos = 0;
+      
       for(i=0;i<64;i++){
-	int ii = zigzag_index[i];
-	int pos = find_nonzero_transition(cpi->quant_tables[inter][plane][ii],buffer[i]);
+	int ii = dezigzag_index[i];
+	int pos = find_nonzero_transition(cpi->quant_tables[inter][plane][i],buffer[ii]);
+	
+	/* basic rho-domain tracking */
 	rho_count[pos]++;
-	
+	/* modified rho count */
+	//mrho_count[pos]++;
+	if(pos<lastpos)mrho_count[pos]++;
+	lastpos = pos;
+
 	if(qi<pos){
-	  data[ii] = 0;
+	  data[i] = 0;
 	}else{
-	  int val = (((iq[i]>>15)*buffer[i]) + (1<<15) + (((iq[i]&0x7fff)*buffer[i])>>15)) >>16;
-	  data[ii] = (val>511?511:(val<-511?-511:val));
+	  int val = (((iq[ii]>>15)*buffer[ii]) + (1<<15) + (((iq[ii]&0x7fff)*buffer[ii])>>15)) >>16;
+	  data[i] = (val>511?511:(val<-511?-511:val));
 	}
       }
     }
@@ -595,13 +609,13 @@
   }
 }
 
-static void TQMB ( CP_INSTANCE *cpi, macroblock_t *mb, int qi, ogg_int16_t req[2][3][64], int *rc){
+static void TQMB ( CP_INSTANCE *cpi, macroblock_t *mb, int qi, ogg_int16_t req[2][3][64], long *rc, long *mc){
   int pf = cpi->info.pixelformat;
   int mode = mb->mode;
   int i;
 
   for(i=0;i<4;i++)
-    TQB(cpi,mode,mb->Ryuv[0][i],mb->mv[i],0,req,rc);
+    TQB(cpi,mode,mb->Ryuv[0][i],mb->mv[i],0,req,rc,mc);
 
   switch(pf){
   case OC_PF_420:
@@ -614,11 +628,11 @@
       mv.x = ( mv.x >= 0 ? (mv.x + 2) / 4 : (mv.x - 2) / 4);
       mv.y = ( mv.y >= 0 ? (mv.y + 2) / 4 : (mv.y - 2) / 4);
       
-      TQB(cpi,mode,mb->Ryuv[1][0],mv,1,req,rc);
-      TQB(cpi,mode,mb->Ryuv[2][0],mv,2,req,rc);
+      TQB(cpi,mode,mb->Ryuv[1][0],mv,1,req,rc,mc);
+      TQB(cpi,mode,mb->Ryuv[2][0],mv,2,req,rc,mc);
     }else{ 
-      TQB(cpi,mode,mb->Ryuv[1][0],mb->mv[0],1,req,rc);
-      TQB(cpi,mode,mb->Ryuv[2][0],mb->mv[0],2,req,rc);
+      TQB(cpi,mode,mb->Ryuv[1][0],mb->mv[0],1,req,rc,mc);
+      TQB(cpi,mode,mb->Ryuv[2][0],mb->mv[0],2,req,rc,mc);
     }
     break;
 
@@ -636,24 +650,24 @@
       mvB.x = ( mvB.x >= 0 ? (mvB.x + 1) / 2 : (mvB.x - 1) / 2);
       mvB.y = ( mvB.y >= 0 ? (mvB.y + 1) / 2 : (mvB.y - 1) / 2);
       
-      TQB(cpi,mode,mb->Ryuv[1][0],mvA,1,req,rc);
-      TQB(cpi,mode,mb->Ryuv[1][1],mvB,1,req,rc);
-      TQB(cpi,mode,mb->Ryuv[2][0],mvA,2,req,rc);
-      TQB(cpi,mode,mb->Ryuv[2][1],mvB,2,req,rc);
+      TQB(cpi,mode,mb->Ryuv[1][0],mvA,1,req,rc,mc);
+      TQB(cpi,mode,mb->Ryuv[1][1],mvB,1,req,rc,mc);
+      TQB(cpi,mode,mb->Ryuv[2][0],mvA,2,req,rc,mc);
+      TQB(cpi,mode,mb->Ryuv[2][1],mvB,2,req,rc,mc);
 
     }else{ 
-      TQB(cpi,mode,mb->Ryuv[1][0],mb->mv[0],1,req,rc);
-      TQB(cpi,mode,mb->Ryuv[1][1],mb->mv[0],1,req,rc);
-      TQB(cpi,mode,mb->Ryuv[2][0],mb->mv[0],2,req,rc);
-      TQB(cpi,mode,mb->Ryuv[2][1],mb->mv[0],2,req,rc);
+      TQB(cpi,mode,mb->Ryuv[1][0],mb->mv[0],1,req,rc,mc);
+      TQB(cpi,mode,mb->Ryuv[1][1],mb->mv[0],1,req,rc,mc);
+      TQB(cpi,mode,mb->Ryuv[2][0],mb->mv[0],2,req,rc,mc);
+      TQB(cpi,mode,mb->Ryuv[2][1],mb->mv[0],2,req,rc,mc);
     }
     break;
     
   case OC_PF_444:
     for(i=0;i<4;i++)
-      TQB(cpi,mode,mb->Ryuv[1][i],mb->mv[i],1,req,rc);
+      TQB(cpi,mode,mb->Ryuv[1][i],mb->mv[i],1,req,rc,mc);
     for(i=0;i<4;i++)
-      TQB(cpi,mode,mb->Ryuv[2][i],mb->mv[i],2,req,rc);
+      TQB(cpi,mode,mb->Ryuv[2][i],mb->mv[i],2,req,rc,mc);
     break;
   }
 }
@@ -670,12 +684,14 @@
   mv_t prior_mv = {0,0};
   unsigned char *cp = cpi->frag_coded;
   ogg_int16_t req[2][3][64];
-  int rho_count[65];
+  long rho_count[65];
+  long mrho_count[65];
 #ifdef COLLECT_METRICS
   int sad[8][3][4];
 #endif
   oc_mode_scheme_chooser_init(cpi);
   memset(rho_count,0,sizeof(rho_count));
+  memset(mrho_count,0,sizeof(mrho_count));
 
   for(i=0;i<2;i++)
     for(j=0;j<3;j++)
@@ -832,11 +848,20 @@
 #endif
 
       /* Transform, quantize, collect rho metrics */
-      TQMB(cpi, mb, qi, req, rho_count);
+      TQMB(cpi, mb, qi, req, rho_count, mrho_count);
 
     }
   }
 
+  for(i=1;i<65;i++){
+    rho_count[i]+=rho_count[i-1];
+    mrho_count[i]+=mrho_count[i-1];
+  }
+
+
+  memcpy(cpi->rho_count,rho_count,sizeof(rho_count));
+  memcpy(cpi->mrho_count,mrho_count,sizeof(mrho_count));
+
   if(cpi->FrameType != KEY_FRAME){
     
     if(interbits>intrabits) return 1; /* short circuit */



More information about the commits mailing list