[xiph-commits] r14609 - in branches/theora-thusnelda/lib: . enc

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Mar 19 12:40:48 PDT 2008


Author: xiphmont
Date: 2008-03-19 12:40:47 -0700 (Wed, 19 Mar 2008)
New Revision: 14609

Modified:
   branches/theora-thusnelda/lib/cpu.c
   branches/theora-thusnelda/lib/enc/dct_encode.c
   branches/theora-thusnelda/lib/enc/encode.c
   branches/theora-thusnelda/lib/enc/mcenc.c
   branches/theora-thusnelda/lib/enc/mode.c
Log:
Ongoing work, correct a bounds bug introduce recently in tokenization reflow.



Modified: branches/theora-thusnelda/lib/cpu.c
===================================================================
--- branches/theora-thusnelda/lib/cpu.c	2008-03-19 11:40:05 UTC (rev 14608)
+++ branches/theora-thusnelda/lib/cpu.c	2008-03-19 19:40:47 UTC (rev 14609)
@@ -103,19 +103,7 @@
     flags=0;
   }
   
-#ifdef DEBUG
-  if (flags) {
-    TH_DEBUG("vectorized instruction sets supported:");
-    if (flags & OC_CPU_X86_MMX)      TH_DEBUG(" mmx");
-    if (flags & OC_CPU_X86_MMXEXT)   TH_DEBUG(" mmxext");
-    if (flags & OC_CPU_X86_SSE)      TH_DEBUG(" sse");
-    if (flags & OC_CPU_X86_SSE2)     TH_DEBUG(" sse2");
-    if (flags & OC_CPU_X86_3DNOW)    TH_DEBUG(" 3dnow");
-    if (flags & OC_CPU_X86_3DNOWEXT) TH_DEBUG(" 3dnowext");
-    TH_DEBUG("\n");
-  }
 #endif
-#endif
   
   return flags;
 }

Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c	2008-03-19 11:40:05 UTC (rev 14608)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c	2008-03-19 19:40:47 UTC (rev 14609)
@@ -45,12 +45,12 @@
     /* DC */
     int i;
     for ( i = 0; i < DC_HUFF_CHOICES; i++)
-      cpi->dc_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[i][token];
+      cpi->dc_bits[plane>0][i] += cpi->HuffCodeLengthArray_VP3x[i][token];
   }else{
     /* AC */
     int i,offset = acoffset[coeff];
     for ( i = 0; i < AC_HUFF_CHOICES; i++)
-      cpi->ac_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
+      cpi->ac_bits[plane>0][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
   }
 }
 
@@ -71,12 +71,12 @@
     /* DC */
     int i;
     for ( i = 0; i < DC_HUFF_CHOICES; i++)
-      cpi->dc_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[i][token];
+      cpi->dc_bits[plane>0][i] += cpi->HuffCodeLengthArray_VP3x[i][token];
   }else{
     /* AC */
     int i,offset = acoffset[coeff];
     for ( i = 0; i < AC_HUFF_CHOICES; i++)
-      cpi->ac_bits[plane][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
+      cpi->ac_bits[plane>0][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
   }
 }
 

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2008-03-19 11:40:05 UTC (rev 14608)
+++ branches/theora-thusnelda/lib/enc/encode.c	2008-03-19 19:40:47 UTC (rev 14609)
@@ -348,7 +348,7 @@
     }
   }
 }
-
+//#include <stdio.h>
 static void PackMotionVectors (CP_INSTANCE *cpi) {
   const ogg_uint32_t * MvPatternPtr;
   const ogg_uint32_t * MvBitsPtr;
@@ -393,8 +393,10 @@
   }
 }
 
+//#include <stdio.h>
 void EncodeData(CP_INSTANCE *cpi){
   int tokenhuff[4];
+  //long bits;
 
   dsp_save_fpu (cpi->dsp);
 
@@ -407,10 +409,17 @@
   PredictDC(cpi);
   DPCMTokenize(cpi);
 
+  //bits = oggpackB_bits(cpi->oggbuffer);
+  //fprintf(stderr,"\nFrame %ld: coded=%ld ", cpi->CurrentFrame, bits);
+
   /* Mode and MV data not needed for key frames. */
   if ( cpi->FrameType != KEY_FRAME ){
     PackModes(cpi);
+    //fprintf(stderr," modes=%ld ",oggpackB_bits(cpi->oggbuffer)-bits);
+    //bits = oggpackB_bits(cpi->oggbuffer);
     PackMotionVectors (cpi);
+    //fprintf(stderr," mvs=%ld ",oggpackB_bits(cpi->oggbuffer)-bits);
+    //bits = oggpackB_bits(cpi->oggbuffer);
   }
 
   ChooseTokenTables(cpi, tokenhuff);
@@ -418,7 +427,9 @@
   ModeMetrics(cpi,tokenhuff);
 #endif
   EncodeTokenList(cpi, tokenhuff);
-
+  //fprintf(stderr," DCT=%ld\n",oggpackB_bits(cpi->oggbuffer)-bits);
+  //bits = oggpackB_bits(cpi->oggbuffer);
+  
   ReconRefFrames(cpi);
 
   dsp_restore_fpu (cpi->dsp);

Modified: branches/theora-thusnelda/lib/enc/mcenc.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcenc.c	2008-03-19 11:40:05 UTC (rev 14608)
+++ branches/theora-thusnelda/lib/enc/mcenc.c	2008-03-19 19:40:47 UTC (rev 14609)
@@ -207,6 +207,7 @@
     const unsigned char *ref = (_goldenp ? cpi->golden : cpi->recon) + base_offset;
     
     err+=  dsp_sad8x8_xy2_thres (cpi->dsp, cur, ref+_mvoffset0, ref+_mvoffset1, cpi->stride[0], _best_err-err);
+    //err+=  dsp_inter8x8_err_xy2 (cpi->dsp, cur, ref+_mvoffset0, ref+_mvoffset1, cpi->stride[0]);
 
   }
   
@@ -236,6 +237,8 @@
       const unsigned char *ref = (_goldenp ? cpi->golden : cpi->recon) + base_offset;
       
       _block_err[bi] = dsp_sad8x8_thres (cpi->dsp, cur, ref+mvoffset,stride,9999999); 
+      //_block_err[bi] = dsp_inter8x8_err (cpi->dsp, cur, ref+mvoffset,stride); 
+
       err += _block_err[bi];
     }
   }
@@ -349,6 +352,7 @@
     mvoffset1=mvoffset_base+(dx&~xmask)+(offset_y[site]&~ymask);
 
     err=dsp_sad8x8_xy2_thres (cpi->dsp, cur, ref+mvoffset0, ref+mvoffset1, stride, _best_err);
+    //err=dsp_inter8x8_err_xy2 (cpi->dsp, cur, ref+mvoffset0, ref+mvoffset1, stride);
 
     if(err<_best_err){
       _best_err=err;

Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c	2008-03-19 11:40:05 UTC (rev 14608)
+++ branches/theora-thusnelda/lib/enc/mode.c	2008-03-19 19:40:47 UTC (rev 14609)
@@ -487,6 +487,7 @@
   mv_t prior_mv = {0,0};
 
   oc_mode_scheme_chooser_init(cpi);
+
   cpi->MVBits_0 = 0;
   cpi->MVBits_1 = 0;
  
@@ -547,9 +548,10 @@
 	/* Add the motion vector bits for each mode that requires them.*/
 	mb_mv_bits_0  = MvBits[mb->analysis_mv[0][0].x + MAX_MV_EXTENT] + 
 	  MvBits[mb->analysis_mv[0][0].y + MAX_MV_EXTENT];
-	mb_gmv_bits_0 = MvBits[mb->analysis_mv[0][1].x+MAX_MV_EXTENT] + 
-	  MvBits[mb->analysis_mv[0][1].y+MAX_MV_EXTENT];
+	mb_gmv_bits_0 = MvBits[mb->analysis_mv[0][1].x + MAX_MV_EXTENT] + 
+	  MvBits[mb->analysis_mv[0][1].y + MAX_MV_EXTENT];
 	mb_4mv_bits_0 = mb_4mv_bits_1 = 0;
+
 	if(mb->coded & 1){
 	  mb_4mv_bits_0 += MvBits[mb->mv[0].x + MAX_MV_EXTENT] + 
 	    MvBits[mb->mv[0].y+MAX_MV_EXTENT];
@@ -590,7 +592,6 @@
 	   considered in the context of LAST_MV and PRIOR_LAST. */
 	cost[CODE_INTER_PLUS_MV] -= 384;
 	
-	
 	/* Finally, pick the mode with the cheapest estimated bit cost.*/
 	mode=0;
 	for(i=1;i<8;i++)
@@ -748,45 +749,48 @@
   }
 }
 
-static void ModeMetricsGroup(CP_INSTANCE *cpi, int group, int huffY, int huffC, int *eobcounts, int *actual_bits){
+static void ModeMetricsGroup(CP_INSTANCE *cpi, int plane, int group, int huff, int *eobcounts, int *actual_bits){
   int ti;
-  int *stack = cpi->dct_eob_fi_stack[group];
-  int ty = cpi->dct_token_ycount[group];
-  int *tfi = cpi->dct_token_frag[group];
-  int tn = cpi->dct_token_count[group];
-
+  int *stack = cpi->dct_eob_fi_stack[plane][group];
+  int *tfi = cpi->dct_token_frag[plane][group];
+  int tn = cpi->dct_token_count[plane][group];
+  
   for(ti=0;ti<tn;ti++){
-    int huff = (ti<ty?huffY:huffC);
-    int token = cpi->dct_token[group][ti];
+    int token = cpi->dct_token[plane][group][ti];
     int bits = cpi->HuffCodeLengthArray_VP3x[huff][token] + cpi->ExtraBitLengths_VP3x[token];
-    
+      
     if(token>DCT_REPEAT_RUN4_TOKEN){
       /* not an EOB run; this token belongs to a single fragment */
       int fi = tfi[ti];
       actual_bits[fi] += (bits<<OC_BIT_SCALE);
     }else{
       /* EOB run; its bits should be split up between all the fragments in the run */
-      int run = parse_eob_run(token, cpi->dct_token_eb[group][ti]);
+      int run = parse_eob_run(token, cpi->dct_token_eb[plane][group][ti]);
       int fracbits = ((bits<<OC_BIT_SCALE) + (run>>1))/run;
-
+      
       if(ti+1<tn){
-	/* tokens follow EOB so it must be entirely ensconced within this group */
+	/* tokens follow EOB so it must be entirely ensconced within this plane/group */
 	while(run--){
 	  int fi = stack[eobcounts[group]++];
 	  actual_bits[fi]+=fracbits;
 	}
       }else{
-	/* EOB is the last token in this group, so it may span into the next group (or groups) */
-	int n = cpi->dct_eob_fi_count[group];
+	/* EOB is the last token in this plane/group, so it may span into the next plane/group */
+	int n = cpi->dct_eob_fi_count[plane][group];
 	while(run){
 	  while(eobcounts[group] < n && run){
 	    int fi = stack[eobcounts[group]++];
 	    actual_bits[fi]+=fracbits;
 	    run--;
 	  }
-	  group++;
-	  n = cpi->dct_eob_fi_count[group];
-	  stack = cpi->dct_eob_fi_stack[group];
+	  plane++;
+	  if(plane>=3){
+	    group++;
+	    plane=0;
+	  }
+	  n = cpi->dct_eob_fi_count[plane][group];
+	  stack = cpi->dct_eob_fi_stack[plane][group];
+	 
 	}
       }
     }
@@ -801,7 +805,7 @@
   unsigned char *cp = cpi->frag_coded;
   int *sp = cpi->frag_sad;
   int *mp = cpi->frag_mbi;
-  int eobcounts[64];
+  int eobcounts[3][64];
   int qi = cpi->BaseQ; /* temporary */
   int actual_bits[cpi->frag_total];
   memset(actual_bits,0,sizeof(actual_bits));
@@ -813,15 +817,29 @@
   }
 
   /* count bits for tokens */
-  ModeMetricsGroup(cpi, 0, huff[0], huff[1], eobcounts, actual_bits);
-  for(gi=1;gi<=AC_TABLE_2_THRESH;gi++)
-    ModeMetricsGroup(cpi, gi,  huff[2], huff[3], eobcounts, actual_bits);
-  for(;gi<=AC_TABLE_3_THRESH;gi++)
-    ModeMetricsGroup(cpi, gi, huff[2]+AC_HUFF_CHOICES, huff[3]+AC_HUFF_CHOICES, eobcounts, actual_bits);
-  for(;gi<=AC_TABLE_4_THRESH;gi++)
-    ModeMetricsGroup(cpi, gi, huff[2]+AC_HUFF_CHOICES*2, huff[3]+AC_HUFF_CHOICES*2, eobcounts, actual_bits);
-  for(;gi<BLOCK_SIZE;gi++)
-    ModeMetricsGroup(cpi, gi, huff[2]+AC_HUFF_CHOICES*3, huff[3]+AC_HUFF_CHOICES*3, eobcounts, actual_bits);
+  ModeMetricsGroup(cpi, 0, 0, huff[0], eobcounts[0], actual_bits);
+  ModeMetricsGroup(cpi, 1, 0, huff[1], eobcounts[1], actual_bits);
+  ModeMetricsGroup(cpi, 2, 0, huff[1], eobcounts[2], actual_bits);
+  for(gi=1;gi<=AC_TABLE_2_THRESH;gi++){
+    ModeMetricsGroup(cpi, 0, gi,  huff[2], eobcounts[0], actual_bits);
+    ModeMetricsGroup(cpi, 1, gi,  huff[3], eobcounts[1], actual_bits);
+    ModeMetricsGroup(cpi, 2, gi,  huff[3], eobcounts[2], actual_bits);
+  }
+  for(;gi<=AC_TABLE_3_THRESH;gi++){
+    ModeMetricsGroup(cpi, 0, gi, huff[2]+AC_HUFF_CHOICES, eobcounts[0], actual_bits);
+    ModeMetricsGroup(cpi, 1, gi, huff[3]+AC_HUFF_CHOICES, eobcounts[1], actual_bits);
+    ModeMetricsGroup(cpi, 2, gi, huff[3]+AC_HUFF_CHOICES, eobcounts[2], actual_bits);
+  }
+  for(;gi<=AC_TABLE_4_THRESH;gi++){
+    ModeMetricsGroup(cpi, 0, gi, huff[2]+AC_HUFF_CHOICES*2, eobcounts[0], actual_bits);
+    ModeMetricsGroup(cpi, 1, gi, huff[3]+AC_HUFF_CHOICES*2, eobcounts[1], actual_bits);
+    ModeMetricsGroup(cpi, 2, gi, huff[3]+AC_HUFF_CHOICES*2, eobcounts[2], actual_bits);
+  }
+  for(;gi<BLOCK_SIZE;gi++){
+    ModeMetricsGroup(cpi, 0, gi, huff[2]+AC_HUFF_CHOICES*3, eobcounts[0], actual_bits);
+    ModeMetricsGroup(cpi, 1, gi, huff[3]+AC_HUFF_CHOICES*3, eobcounts[1], actual_bits);
+    ModeMetricsGroup(cpi, 2, gi, huff[3]+AC_HUFF_CHOICES*3, eobcounts[2], actual_bits);
+  }
 
   /* accumulate */
   for(fi=0;fi<v;fi++)
@@ -872,19 +890,19 @@
 	fprintf(stdout,"        { ");
 	for(bin=0;bin<OC_SAD_BINS;bin++){
 	  if(bin && !(bin&0x3))fprintf(stdout,"\n          ");
-	  fprintf(stdout,"%12lldLL,",mode_metric[qi][plane][mode].bits[bin]);
+	  fprintf(stdout,"%12ldLL,",mode_metric[qi][plane][mode].bits[bin]);
 	}
 	fprintf(stdout," },\n");
 	fprintf(stdout,"        { ");
 	for(bin=0;bin<OC_SAD_BINS;bin++){
 	  if(bin && !(bin&0x3))fprintf(stdout,"\n          ");
-	  fprintf(stdout,"%12lldLL,",mode_metric[qi][plane][mode].frag[bin]);
+	  fprintf(stdout,"%12ldLL,",mode_metric[qi][plane][mode].frag[bin]);
 	}
 	fprintf(stdout," },\n");
 	fprintf(stdout,"        { ");
 	for(bin=0;bin<OC_SAD_BINS;bin++){
 	  if(bin && !(bin&0x3))fprintf(stdout,"\n          ");
-	  fprintf(stdout,"%12lldLL,",mode_metric[qi][plane][mode].sad[bin]);
+	  fprintf(stdout,"%12ldLL,",mode_metric[qi][plane][mode].sad[bin]);
 	}
 	fprintf(stdout," },\n");
 	fprintf(stdout,"      },\n");



More information about the commits mailing list