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

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Wed Dec 10 00:14:03 PST 2008


Author: xiphmont
Date: 2008-12-10 00:14:03 -0800 (Wed, 10 Dec 2008)
New Revision: 15571

Modified:
   branches/theora-thusnelda/lib/enc/codec_internal.h
   branches/theora-thusnelda/lib/enc/dct_encode.c
   branches/theora-thusnelda/lib/enc/frinit.c
   branches/theora-thusnelda/lib/enc/mcenc.c
   branches/theora-thusnelda/lib/enc/mode.c
Log:
Back otu the frag_total => -1 convention change



Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2008-12-10 01:05:33 UTC (rev 15570)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2008-12-10 08:14:03 UTC (rev 15571)
@@ -22,7 +22,7 @@
 # include "config.h"
 #endif
 
-#define COLLECT_METRICS 
+//#define COLLECT_METRICS 
 
 #include "theora/theora.h"
 #include "encoder_huffman.h"

Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c	2008-12-10 01:05:33 UTC (rev 15570)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c	2008-12-10 08:14:03 UTC (rev 15571)
@@ -673,7 +673,7 @@
     int bi;
     for (bi=0; bi<16; bi++, i++ ) {
       int fi = sb->f[bi];
-      if(fi>=0 && cp[fi]) 
+      if(cp[fi]) 
         tokenize_DC(cpi, fi, 0, &idx1, &run1);
     }
   }
@@ -690,7 +690,7 @@
     int bi;
     for (bi=0; bi<16; bi++,i++ ) {
       int fi = sb->f[bi];
-      if(fi>=0 && cp[fi]) 
+      if(cp[fi]) 
 	tokenize_DC(cpi, fi, 1, &idx1, &run1);
     }
   }

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2008-12-10 01:05:33 UTC (rev 15570)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2008-12-10 08:14:03 UTC (rev 15571)
@@ -112,11 +112,13 @@
   cpi->super_n[2] = cpi->super_h[2] * cpi->super_v[2];
   cpi->super_total = cpi->super_n[0] + cpi->super_n[1] + cpi->super_n[2];
 
-  cpi->frag_coded = calloc(cpi->frag_total, sizeof(*cpi->frag_coded)); 
+  /* +1; the last entry is the 'invalid' frag, which is always set to not coded as it doesn't really exist */
+  cpi->frag_coded = calloc(cpi->frag_total+1, sizeof(*cpi->frag_coded)); 
   cpi->frag_buffer_index = calloc(cpi->frag_total, sizeof(*cpi->frag_buffer_index));
   cpi->frag_dc = calloc(cpi->frag_total, sizeof(*cpi->frag_dc));
 
-  cpi->macro = calloc(cpi->macro_total, sizeof(*cpi->macro));
+  /* +1; the last entry is the 'invalid' mb, which contains only 'invalid' frags */
+  cpi->macro = calloc(cpi->macro_total+1, sizeof(*cpi->macro));
 
   cpi->super[0] = calloc(cpi->super_total, sizeof(**cpi->super));
   cpi->super[1] = cpi->super[0] + cpi->super_n[0];
@@ -136,8 +138,8 @@
 #ifdef COLLECT_METRICS
  {
    int i;
-   cpi->frag_mbi = _ogg_calloc(cpi->frag_total, sizeof(*cpi->frag_mbi));
-   cpi->frag_sad = _ogg_calloc(cpi->frag_total, sizeof(*cpi->frag_sad));
+   cpi->frag_mbi = _ogg_calloc(cpi->frag_total+1, sizeof(*cpi->frag_mbi));
+   cpi->frag_sad = _ogg_calloc(cpi->frag_total+1, sizeof(*cpi->frag_sad));
    cpi->dct_token_frag_storage = _ogg_malloc(cpi->stack_offset*BLOCK_SIZE*sizeof(*cpi->dct_token_frag_storage));
    cpi->dct_eob_fi_storage = _ogg_malloc(cpi->frag_total*BLOCK_SIZE*sizeof(*cpi->dct_eob_fi_storage));
  }
@@ -167,7 +169,7 @@
 	      int fragindex = frow*cpi->frag_h[plane] + fcol + offset;
 	      cpi->super[plane][superindex].f[frag] = fragindex;
 	    }else
-	      cpi->super[plane][superindex].f[frag] = -1; /* 'invalid' */
+	      cpi->super[plane][superindex].f[frag] = cpi->frag_total; /* 'invalid' */
 	  }
 	}
       }
@@ -187,7 +189,7 @@
 	    cpi->super[0][superindex].m[mb] = macroindex;
 	    cpi->macro[macroindex].ysb = superindex;
 	  }else
-	    cpi->super[0][superindex].m[mb] = -1;
+	    cpi->super[0][superindex].m[mb] = cpi->macro_total;
 	}
       }
     }
@@ -205,7 +207,7 @@
 	    cpi->super[1][superindex].m[mb] = macroindex;
 	    cpi->macro[macroindex].usb = superindex + cpi->super_n[0];
 	  }else
-	    cpi->super[1][superindex].m[mb] = -1;
+	    cpi->super[1][superindex].m[mb] = cpi->macro_total;
 	}
       }
     }
@@ -223,7 +225,7 @@
 	    cpi->super[2][superindex].m[mb] = macroindex;
 	    cpi->macro[macroindex].vsb = superindex + cpi->super_n[0] + cpi->super_n[1];
 	  }else
-	    cpi->super[2][superindex].m[mb] = -1;
+	    cpi->super[2][superindex].m[mb] = cpi->macro_total;
 	}
       }
     }
@@ -251,8 +253,8 @@
 	  int Rrow = baserow + ((frag>>1)&1);
 	  int Rcol = basecol + (frag&1);
 
-	  cpi->macro[macroindex].Hyuv[0][frag] = -1;
-	  cpi->macro[macroindex].Ryuv[0][frag] = -1;
+	  cpi->macro[macroindex].Hyuv[0][frag] = cpi->frag_total; // default
+	  cpi->macro[macroindex].Ryuv[0][frag] = cpi->frag_total; //default
 	  if(Hrow<cpi->frag_v[0] && Hcol<cpi->frag_h[0]){
 	    cpi->macro[macroindex].Hyuv[0][frag] = Hrow*cpi->frag_h[0] + Hcol;	    
 #ifdef COLLECT_METRICS
@@ -264,14 +266,14 @@
 	}
 
 	/* U */
-	cpi->macro[macroindex].Ryuv[1][0] = -1;
-	cpi->macro[macroindex].Ryuv[1][1] = -1;
-	cpi->macro[macroindex].Ryuv[1][2] = -1;
-	cpi->macro[macroindex].Ryuv[1][3] = -1;
-	cpi->macro[macroindex].Hyuv[1][0] = -1;
-	cpi->macro[macroindex].Hyuv[1][1] = -1;
-	cpi->macro[macroindex].Hyuv[1][2] = -1;
-	cpi->macro[macroindex].Hyuv[1][3] = -1;
+	cpi->macro[macroindex].Ryuv[1][0] = cpi->frag_total;
+	cpi->macro[macroindex].Ryuv[1][1] = cpi->frag_total;
+	cpi->macro[macroindex].Ryuv[1][2] = cpi->frag_total;
+	cpi->macro[macroindex].Ryuv[1][3] = cpi->frag_total;
+	cpi->macro[macroindex].Hyuv[1][0] = cpi->frag_total;
+	cpi->macro[macroindex].Hyuv[1][1] = cpi->frag_total;
+	cpi->macro[macroindex].Hyuv[1][2] = cpi->frag_total;
+	cpi->macro[macroindex].Hyuv[1][3] = cpi->frag_total;
 	if(row<cpi->frag_v[1] && col<cpi->frag_h[1]){
 	  cpi->macro[macroindex].Hyuv[1][0] = cpi->frag_n[0] + macroindex;
 	  cpi->macro[macroindex].Ryuv[1][0] = cpi->frag_n[0] + macroindex;
@@ -281,14 +283,14 @@
 	}
 	
 	/* V */
-	cpi->macro[macroindex].Ryuv[2][0] = -1;
-	cpi->macro[macroindex].Ryuv[2][1] = -1;
-	cpi->macro[macroindex].Ryuv[2][2] = -1;
-	cpi->macro[macroindex].Ryuv[2][3] = -1;
-	cpi->macro[macroindex].Hyuv[2][0] = -1;
-	cpi->macro[macroindex].Hyuv[2][1] = -1;
-	cpi->macro[macroindex].Hyuv[2][2] = -1;
-	cpi->macro[macroindex].Hyuv[2][3] = -1;
+	cpi->macro[macroindex].Ryuv[2][0] = cpi->frag_total;
+	cpi->macro[macroindex].Ryuv[2][1] = cpi->frag_total;
+	cpi->macro[macroindex].Ryuv[2][2] = cpi->frag_total;
+	cpi->macro[macroindex].Ryuv[2][3] = cpi->frag_total;
+	cpi->macro[macroindex].Hyuv[2][0] = cpi->frag_total;
+	cpi->macro[macroindex].Hyuv[2][1] = cpi->frag_total;
+	cpi->macro[macroindex].Hyuv[2][2] = cpi->frag_total;
+	cpi->macro[macroindex].Hyuv[2][3] = cpi->frag_total;
 	if(row<cpi->frag_v[2] && col<cpi->frag_h[2]){
 	  cpi->macro[macroindex].Hyuv[2][0] = cpi->frag_n[0] + cpi->frag_n[1] + macroindex;
 	  cpi->macro[macroindex].Ryuv[2][0] = cpi->frag_n[0] + cpi->frag_n[1] + macroindex;
@@ -372,6 +374,21 @@
     }
   }
 
+  /* fill in 'invalid' macroblock */
+  {
+    int p,f;
+    for(p=0;p<3;p++)
+      for(f=0;f<4;f++){
+	cpi->macro[cpi->macro_total].Ryuv[p][f] = cpi->frag_total;
+	cpi->macro[cpi->macro_total].Hyuv[p][f] = cpi->frag_total;
+      }
+    cpi->macro[cpi->macro_total].ncneighbors=0;
+    cpi->macro[cpi->macro_total].npneighbors=0;
+#ifdef COLLECT_METRICS
+    cpi->frag_mbi[cpi->frag_total] = cpi->macro_total;
+#endif
+  }
+
   /* allocate frames */
   cpi->frame = _ogg_calloc(cpi->frame_size,sizeof(*cpi->frame));
   cpi->lastrecon = _ogg_calloc(cpi->frame_size,sizeof(*cpi->lastrecon));

Modified: branches/theora-thusnelda/lib/enc/mcenc.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mcenc.c	2008-12-10 01:05:33 UTC (rev 15570)
+++ branches/theora-thusnelda/lib/enc/mcenc.c	2008-12-10 08:14:03 UTC (rev 15571)
@@ -230,7 +230,7 @@
   err=0;
   for(bi=0;bi<4;bi++){
     int fi = mb->Ryuv[0][bi];
-    if(fi >= 0){ /* last fragment is the 'invalid fragment' */
+    if(fi < cpi->frag_total){ /* last fragment is the 'invalid fragment' */
       ogg_uint32_t base_offset = cpi->frag_buffer_index[fi];
       const unsigned char *cur = cpi->frame + base_offset;
       const unsigned char *ref = (_goldenp ? cpi->golden : cpi->lastrecon) + base_offset;
@@ -308,7 +308,7 @@
   int err;
   int fi = mb->Ryuv[0][_bi];
 
-  if(fi < 0) return _best_err;
+  if(fi >= cpi->frag_total) return _best_err;
 
   mvoffset_base=_vec->x+_vec->y*stride;
   offset_y[0]=offset_y[1]=offset_y[2]=-stride;

Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c	2008-12-10 01:05:33 UTC (rev 15570)
+++ branches/theora-thusnelda/lib/enc/mode.c	2008-12-10 08:14:03 UTC (rev 15571)
@@ -309,7 +309,7 @@
   for(i=0;i<3;i++){
     for(j=0;j<4;j++){
       int fi=mb->Ryuv[i][j];
-      if(fi>=0){
+      if(fi<cpi->frag_total){
 	int sad = BIntraSAD(cpi,fi,i);
 	cost += BINMAP(mode_rate[qi][i][1],sad);
       }
@@ -328,7 +328,7 @@
   for(i=0;i<3;i++){
     for(j=0;j<4;j++){
       int fi=mb->Ryuv[i][j];
-      if(fi>=0){
+      if(fi<cpi->frag_total){
 	int sad = BInterSAD(cpi,fi,i,mode==CODE_USING_GOLDEN,mv);
 	cost += BINMAP(mode_rate[qi][i][0],sad);
       }
@@ -345,7 +345,7 @@
   for(i=0;i<3;i++){
     for(j=0;j<4;j++){
       int fi=mb->Ryuv[i][j];
-      if(fi>=0){
+      if(fi<cpi->frag_total){
 	int bi = cpi->frag_buffer_index[fi];
 	int stride = cpi->stride[i];  
 	int sad =  dsp_sad8x8 (cpi->dsp, cpi->frame+bi, cpi->lastrecon+bi, stride);
@@ -367,7 +367,7 @@
   for(i=0;i<3;i++){
     for(j=0;j<4;j++){
       int fi=mb->Ryuv[i][j];
-      if(fi>=0){
+      if(fi<cpi->frag_total){
 	int sad = BInterSAD(cpi,fi,i,golden,mb->analysis_mv[0][golden]);
 	cost += BINMAP(mode_rate[qi][i][0],sad);
       }
@@ -395,7 +395,7 @@
 
   for(j=0;j<4;j++){
     int fi=mb->Ryuv[0][j];
-    if(fi>=0){
+    if(fi<cpi->frag_total){
       int sad = BInterSAD(cpi,fi,0,0,mb->mv[j]);
       cost += BINMAP(mode_rate[qi][0][0],sad);
       
@@ -419,7 +419,7 @@
       
       for(i=1;i<3;i++){
 	int fi=mb->Ryuv[i][0];
-	if(fi>=0){
+	if(fi<cpi->frag_total){
 	  int sad = BInterSAD(cpi,fi,i,0,ch);
 	  cost += BINMAP(mode_rate[qi][i][0],sad);
 	}
@@ -444,7 +444,7 @@
       for(i=1;i<3;i++){
 	for(j=0;j<2;j++){
 	  int fi=mb->Ryuv[i][j];
-	  if(fi>=0){
+	  if(fi<cpi->frag_total){
 	    int sad = BInterSAD(cpi,fi,i,0,mv[j]);
 	    cost += BINMAP(mode_rate[qi][i][0],sad);
 	  }
@@ -457,7 +457,7 @@
     for(i=1;i<3;i++){
       for(j=0;j<4;j++){
 	int fi=mb->Ryuv[i][j];
-	if(fi>=0){
+	if(fi<cpi->frag_total){
 	  int sad = BInterSAD(cpi,fi,i,0,mb->mv[j]);
 	  cost += BINMAP(mode_rate[qi][i][0],sad);
 	}
@@ -532,7 +532,6 @@
 		token_checkpoint_t **stack){
   
   const int keyframe = (cpi->FrameType == KEY_FRAME);
-  const int qi = ps->qi;
   const ogg_int32_t *iq = ps->iq[mode != CODE_INTRA];
   ogg_int16_t buffer[64];
   ogg_int16_t data[64];
@@ -605,10 +604,10 @@
   int sad=0;
   if(mode==CODE_INTRA){
     int acc=0;
-    for(i=0;i<64;i++){
+    for(i=0;i<64;i++)
       acc += data[i];
+    for(i=0;i<64;i++)
       sad += abs((data[i]<<6)-acc);
-    }
     sad >>=6;
   }else{
     for(i=0;i<64;i++)
@@ -864,7 +863,7 @@
     int fi = sb->f[i];
     int mb_phase;
 
-    if(fi>=0){
+    if(fi<cpi->frag_total){
       token_checkpoint_t *stackptr = stack;
       macroblock_t *mb = &cpi->macro[sb->m[i]];
       mv_t mv;
@@ -953,7 +952,7 @@
     for(j = 0; j<4; j++){ /* mode addressing is through Y plane, always 4 MB per SB */
       int mbi = sb->m[j];
 
-      if(mbi < 0) continue;
+      if(mbi >= cpi->macro_total) continue;
 
       int cost[8] = {0,0,0,0, 0,0,0,0};
       int overhead[8] = {0,0,0,0, 0,0,0,0};
@@ -1273,6 +1272,7 @@
       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 fracbits = ((bits<<OC_BIT_SCALE) + (run>>1))/run;
       
@@ -1344,30 +1344,33 @@
   /* accumulate */
   for(fi=0;fi<v;fi++)
     if(cp[fi]){
-      macroblock_t *mb = &cpi->macro[mp[fi]];
-      int mode = mb->mode;
-      int plane = (fi<y ? 0 : (fi<u ? 1 : 2));
-      int bin = BIN(sp[fi]);
-      mode_metric[qi][plane][mode==CODE_INTRA].frag[bin]++;
-      mode_metric[qi][plane][mode==CODE_INTRA].sad[bin] += sp[fi];
-      mode_metric[qi][plane][mode==CODE_INTRA].bits[bin] += actual_bits[fi];
-
-      {
-	int bi = cpi->frag_buffer_index[fi];
-	unsigned char *frame = cpi->frame+bi;
-	unsigned char *recon = cpi->lastrecon+bi;
-	int stride = cpi->stride[plane];
-	int lssd=0;
-	int xi,yi;
-      
-	for(yi=0;yi<8;yi++){
-	  for(xi=0;xi<8;xi++)
-	    lssd += (frame[xi]-recon[xi])*(frame[xi]-recon[xi]);
-	  frame+=stride;
-	  recon+=stride;
+      int mbi = mp[fi];
+      if(mbi>=0){
+	macroblock_t *mb = &cpi->macro[mbi];
+	int mode = mb->mode;
+	int plane = (fi<y ? 0 : (fi<u ? 1 : 2));
+	int bin = BIN(sp[fi]);
+	mode_metric[qi][plane][mode==CODE_INTRA].frag[bin]++;
+	mode_metric[qi][plane][mode==CODE_INTRA].sad[bin] += sp[fi];
+	mode_metric[qi][plane][mode==CODE_INTRA].bits[bin] += actual_bits[fi];
+	
+	if(0){
+	  int bi = cpi->frag_buffer_index[fi];
+	  unsigned char *frame = cpi->frame+bi;
+	  unsigned char *recon = cpi->lastrecon+bi;
+	  int stride = cpi->stride[plane];
+	  int lssd=0;
+	  int xi,yi;
+	  
+	  for(yi=0;yi<8;yi++){
+	    for(xi=0;xi<8;xi++)
+	      lssd += (frame[xi]-recon[xi])*(frame[xi]-recon[xi]);
+	    frame+=stride;
+	    recon+=stride;
+	  }
+	  cpi->dist_dist[plane][mode] += lssd;
+	  cpi->dist_bits[plane][mode] += actual_bits[fi];
 	}
-	cpi->dist_dist[plane][mode] += lssd;
-	cpi->dist_bits[plane][mode] += actual_bits[fi];
       }
     }
 



More information about the commits mailing list