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

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Jun 17 01:05:49 PDT 2008


Author: xiphmont
Date: 2008-06-17 01:05:49 -0700 (Tue, 17 Jun 2008)
New Revision: 15044

Modified:
   branches/theora-thusnelda/lib/enc/codec_internal.h
   branches/theora-thusnelda/lib/enc/frarray.c
   branches/theora-thusnelda/lib/enc/frinit.c
   branches/theora-thusnelda/lib/enc/mode.c
Log:
Code rearrangement for SB frarray encoding.



Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2008-06-16 23:34:26 UTC (rev 15043)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2008-06-17 08:05:49 UTC (rev 15044)
@@ -120,7 +120,10 @@
   /* the blocks comprising this macroblock */
   int Ryuv[3][4]; /* [Y,U,V][raster order] */
   int Hyuv[3][4]; /* [Y,U,V][hilbert order] */
-
+  int ysb;
+  int usb;
+  int vsb;
+    
   int cneighbors[4];      
   int ncneighbors;
   int pneighbors[4];
@@ -151,6 +154,9 @@
 typedef struct superblock {
   int f[16]; // hilbert order
   int m[16]; // hilbert order; 4 for Y, 4 for UZ in 4:4:4, 8 for UV in 4:2:2, 16 for UV in 4:2:0
+
+  int partial;
+  int coded;
 } superblock_t;
 
 typedef ogg_int16_t    quant_table[64]; 

Modified: branches/theora-thusnelda/lib/enc/frarray.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frarray.c	2008-06-16 23:34:26 UTC (rev 15043)
+++ branches/theora-thusnelda/lib/enc/frarray.c	2008-06-17 08:05:49 UTC (rev 15044)
@@ -112,42 +112,25 @@
   int run_last = -1;
   int run_count = 0;
   int run_break = 0;
-  int partial=0;
-  int fully = 1;
   int invalid_fi = cpi->frag_total;
   unsigned char *cp = cpi->frag_coded;
 
   /* code the partially coded SB flags */
   for( SB = 0; SB < cpi->super_total; SB++ ) {
-    superblock_t *sp = &cpi->super[0][SB];
-    int coded = 0;
-    fully = 1;
+    superblock_t *sb = &cpi->super[0][SB];
+    int partial = (sb->partial & sb->coded); 
 
-    for ( B=0; B<16; B++ ) {
-      int fi = sp->f[B];
-
-      if ( fi != invalid_fi ){
-	if ( cp[fi] ) {
-	  coded = 1; /* SB at least partly coded */
-	}else{
-	  fully = 0;
-	}
-      }
-    }
-    
-    partial = (!fully && coded);
-    
     if(run_last == -1){
       oggpackB_write( cpi->oggbuffer, partial, 1);      
       run_last = partial;
     }
-
+    
     if(run_last == partial && run_count < 4129){
       run_count++;
     }else{
       if(run_break)
 	oggpackB_write( cpi->oggbuffer, partial, 1);
-  
+      
       run_break=0;
       FrArrayCodeSBRun( cpi, run_count );      
       if(run_count >= 4129) run_break = 1;
@@ -156,7 +139,7 @@
     run_last=partial;
   }
   if(run_break)
-    oggpackB_write( cpi->oggbuffer, partial, 1);
+    oggpackB_write( cpi->oggbuffer, run_last, 1);
   if(run_count)
     FrArrayCodeSBRun(cpi, run_count);      
 
@@ -165,42 +148,29 @@
   run_count = 0;
   run_break = 0;
   for( SB = 0; SB < cpi->super_total; SB++ ) {
-    superblock_t *sp = &cpi->super[0][SB];
-    int coded = 0;
-    fully = 1;
+    superblock_t *sb = &cpi->super[0][SB];
     
-    for ( B=0; B<16; B++ ) {
-      int fi = sp->f[B];
-      if ( fi != invalid_fi ) {
-	if ( cp[fi] ) {
-	  coded = 1;
-	}else{
-	  fully = 0;
-	}
-      }
-    }
+    if(sb->partial && sb->coded) continue;
     
-    if(!fully && coded) continue;
-    
     if(run_last == -1){
-      oggpackB_write( cpi->oggbuffer, fully, 1);      
-      run_last = fully;
+      oggpackB_write( cpi->oggbuffer, sb->coded, 1);      
+      run_last = sb->coded;
     }
     
-    if(run_last == fully && run_count < 4129){
+    if(run_last == sb->coded && run_count < 4129){
       run_count++;
     }else{
       if(run_break)
-	oggpackB_write( cpi->oggbuffer, fully, 1);
+	oggpackB_write( cpi->oggbuffer, sb->coded, 1);
       run_break=0;
       FrArrayCodeSBRun( cpi, run_count );      
       if(run_count >= 4129) run_break = 1;
       run_count=1;
     }
-    run_last=fully;
+    run_last=sb->coded;
   }
   if(run_break)
-    oggpackB_write( cpi->oggbuffer, fully, 1);
+    oggpackB_write( cpi->oggbuffer, run_last, 1);
 
   if(run_count)
     FrArrayCodeSBRun(cpi, run_count);      
@@ -209,25 +179,12 @@
   run_last = -1;
   run_count = 0;
   for( SB = 0; SB < cpi->super_total; SB++ ) {
-    superblock_t *sp = &cpi->super[0][SB];
-    int coded = 0;
-    fully = 1;
+    superblock_t *sb = &cpi->super[0][SB];
 
-    for ( B=0; B<16; B++ ) {
-      int fi = sp->f[B];      
-      if ( fi != invalid_fi ) {
-	if ( cp[fi] ) {
-	  coded = 1;
-	}else{
-	  fully = 0; /* SB not fully coded */
-	}
-      }
-    }
+    if(!sb->coded || !sb->partial) continue;
 
-    if(fully || !coded) continue;
-
     for ( B=0; B<16; B++ ) {
-      int fi = sp->f[B];      
+      int fi = sb->f[B];      
       if(fi != invalid_fi){
 	if(run_last == -1){
 	  oggpackB_write( cpi->oggbuffer, cp[fi], 1);      

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2008-06-16 23:34:26 UTC (rev 15043)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2008-06-17 08:05:49 UTC (rev 15044)
@@ -131,8 +131,8 @@
   cpi->dct_eob_fi_storage = _ogg_malloc(cpi->frag_total*BLOCK_SIZE*sizeof(*cpi->dct_eob_fi_storage));
 #endif
   
-
   /* fill in superblock fragment pointers; hilbert order */
+  /* fill in macroblock superblock backpointers */
   {
     int row,col,frag,mb;
     int fhilbertx[16] = {0,1,1,0,0,0,1,1,2,2,3,3,3,2,2,3};
@@ -173,9 +173,9 @@
 	  if(mrow<cpi->macro_v && mcol<cpi->macro_h){
 	    int macroindex = mrow*cpi->macro_h + mcol;
 	    cpi->super[0][superindex].m[mb] = macroindex;
+	    cpi->macro[macroindex].ysb = superindex;
 	  }else
 	    cpi->super[0][superindex].m[mb] = cpi->macro_total;
-
 	}
       }
     }
@@ -191,6 +191,7 @@
 	  if(mrow<cpi->macro_v && mcol<cpi->macro_h){
 	    int macroindex = mrow*cpi->macro_h + mcol;
 	    cpi->super[1][superindex].m[mb] = macroindex;
+	    cpi->macro[macroindex].usb = superindex + cpi->super_n[0];
 	  }else
 	    cpi->super[1][superindex].m[mb] = cpi->macro_total;
 	}
@@ -208,6 +209,7 @@
 	  if(mrow<cpi->macro_v && mcol<cpi->macro_h){
 	    int macroindex = mrow*cpi->macro_h + mcol;
 	    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] = cpi->macro_total;
 	}

Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c	2008-06-16 23:34:26 UTC (rev 15043)
+++ branches/theora-thusnelda/lib/enc/mode.c	2008-06-17 08:05:49 UTC (rev 15044)
@@ -667,20 +667,26 @@
   return 1;
 }
 
-static int TQMB ( CP_INSTANCE *cpi, macroblock_t *mb, int qi, ogg_int16_t req[2][3][64], 
-		  long *rc, int keyframe){
+static int TQMB ( CP_INSTANCE *cpi, macroblock_t *mb, 
+		  int qi, ogg_int16_t req[2][3][64], long *rc, int keyframe){
   int pf = cpi->info.pixelformat;
   int mode = mb->mode;
   int i;
   int coded=0;
-  
-  for(i=0;i<4;i++)
-    if(TQB(cpi,mode,mb->Ryuv[0][i],mb->mv[i],0,req,rc,keyframe))
+  superblock_t *ysb = &cpi->super[0][mb->ysb];
+  superblock_t *usb = &cpi->super[0][mb->usb];
+  superblock_t *vsb = &cpi->super[0][mb->vsb];
+
+  for(i=0;i<4;i++){
+    if(TQB(cpi,mode,mb->Ryuv[0][i],mb->mv[i],0,req,rc,keyframe)){
+      ysb->coded=1;
       coded++;
-    else{
+    }else{
+      ysb->partial=1;
       if(mode == CODE_INTER_FOURMV) 
 	mb->mv[i]=(mv_t){0,0};
     }
+  }
 
   if(coded==0){
     mode = mb->mode = CODE_INTER_NO_MV; /* No luma blocks coded, mode is forced */
@@ -690,66 +696,94 @@
 
   switch(pf){
   case OC_PF_420:
-    if(mode == CODE_INTER_FOURMV){
+    {
       mv_t mv;
-	  
-      mv.x = mb->mv[0].x + mb->mv[1].x + mb->mv[2].x + mb->mv[3].x;
-      mv.y = mb->mv[0].y + mb->mv[1].y + mb->mv[2].y + mb->mv[3].y;
-      
-      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);
-      
-      coded+=TQB(cpi,mode,mb->Ryuv[1][0],mv,1,req,rc,keyframe);
-      coded+=TQB(cpi,mode,mb->Ryuv[2][0],mv,2,req,rc,keyframe);
-    }else{ 
-      coded+=TQB(cpi,mode,mb->Ryuv[1][0],mb->mv[0],1,req,rc,keyframe);
-      coded+=TQB(cpi,mode,mb->Ryuv[2][0],mb->mv[0],2,req,rc,keyframe);
+      if(mode == CODE_INTER_FOURMV){
+	
+	mv.x = mb->mv[0].x + mb->mv[1].x + mb->mv[2].x + mb->mv[3].x;
+	mv.y = mb->mv[0].y + mb->mv[1].y + mb->mv[2].y + mb->mv[3].y;
+	
+	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);
+      }else{
+	mv = mb->mv[0];
+      }
+      if(TQB(cpi,mode,mb->Ryuv[1][0],mv,1,req,rc,keyframe)){
+	usb->coded=1;
+	coded++;
+      }else{
+	usb->partial=1;
+      }
+      if(TQB(cpi,mode,mb->Ryuv[2][0],mv,2,req,rc,keyframe)){
+	vsb->coded=1;
+	coded++;
+      }else{
+	vsb->partial=1;
+      }
     }
     break;
-
   case OC_PF_422:
-    if(mode == CODE_INTER_FOURMV){
-      mv_t mvA;
-      mv_t mvB;
-	  
-      mvA.x = mb->mv[0].x + mb->mv[1].x;
-      mvA.y = mb->mv[0].y + mb->mv[1].y;
-      mvA.x = ( mvA.x >= 0 ? (mvA.x + 1) / 2 : (mvA.x - 1) / 2);
-      mvA.y = ( mvA.y >= 0 ? (mvA.y + 1) / 2 : (mvA.y - 1) / 2);
-      mvB.x = mb->mv[0].x + mb->mv[1].x;
-      mvB.y = mb->mv[0].y + mb->mv[1].y;
-      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);
+    {
+      mv_t mv[2];
       
-      coded+=TQB(cpi,mode,mb->Ryuv[1][0],mvA,1,req,rc,keyframe);
-      coded+=TQB(cpi,mode,mb->Ryuv[1][1],mvB,1,req,rc,keyframe);
-      coded+=TQB(cpi,mode,mb->Ryuv[2][0],mvA,2,req,rc,keyframe);
-      coded+=TQB(cpi,mode,mb->Ryuv[2][1],mvB,2,req,rc,keyframe);
+      if(mode == CODE_INTER_FOURMV){
+	
+	for(i=0;i<2;i++){
+	  mv[i].x = mb->mv[0].x + mb->mv[1].x;
+	  mv[i].y = mb->mv[0].y + mb->mv[1].y;
+	  mv[i].x = ( mv[i].x >= 0 ? (mv[i].x + 1) / 2 : (mv[i].x - 1) / 2);
+	  mv[i].y = ( mv[i].y >= 0 ? (mv[i].y + 1) / 2 : (mv[i].y - 1) / 2);
+	}
+      }else{
+	mv[0] = mv[1] =  mb->mv[0];
+      }
 
-    }else{ 
-      coded+=TQB(cpi,mode,mb->Ryuv[1][0],mb->mv[0],1,req,rc,keyframe);
-      coded+=TQB(cpi,mode,mb->Ryuv[1][1],mb->mv[0],1,req,rc,keyframe);
-      coded+=TQB(cpi,mode,mb->Ryuv[2][0],mb->mv[0],2,req,rc,keyframe);
-      coded+=TQB(cpi,mode,mb->Ryuv[2][1],mb->mv[0],2,req,rc,keyframe);
+      for(i=0;i<2;i++)
+	if(TQB(cpi,mode,mb->Ryuv[1][i],mv[i],1,req,rc,keyframe)){
+	  usb->coded=1;
+	  coded++;
+	}else{
+	  usb->partial=1;
+	}
+
+      for(i=0;i<2;i++)
+	if(TQB(cpi,mode,mb->Ryuv[2][i],mv[i],2,req,rc,keyframe)){
+	  vsb->coded=1;
+	  coded++;
+	}else{
+	  vsb->partial=1;
+	}
     }
     break;
     
   case OC_PF_444:
     for(i=0;i<4;i++)
-      coded+=TQB(cpi,mode,mb->Ryuv[1][i],mb->mv[i],1,req,rc,keyframe);
+      if(TQB(cpi,mode,mb->Ryuv[1][i],mb->mv[i],1,req,rc,keyframe)){
+	usb->coded=1;
+	coded++;
+      }else{
+	usb->partial=1;
+      }
+
     for(i=0;i<4;i++)
-      coded+=TQB(cpi,mode,mb->Ryuv[2][i],mb->mv[i],2,req,rc,keyframe);
+      if(TQB(cpi,mode,mb->Ryuv[2][i],mb->mv[i],2,req,rc,keyframe)){
+	vsb->coded=1;
+	coded++;
+      }else{
+	vsb->partial=1;
+      }
+    
     break;
   }
-
+  
   return coded;
-
+  
 }
 
 int PickModes(CP_INSTANCE *cpi, int recode){
   unsigned char qi = cpi->BaseQ; // temporary
   superblock_t *sb = cpi->super[0];
-  superblock_t *sb_end = sb + cpi->super_n[0];
+  superblock_t *sb_end;
   int i,j,k;
   ogg_uint32_t interbits = 0;
   ogg_uint32_t intrabits = 0;
@@ -775,9 +809,19 @@
  
   if(!recode)
     oc_mcenc_start(cpi, &mcenc); 
-  
+
+  /* clear flags to initial state */
+  sb_end = sb + cpi->super_total;
+  for(; sb<sb_end; sb++){
+    sb->partial = 0;
+    sb->coded = 0;
+  }
+   
   /* Choose mvs, modes; must be done in Hilbert order */
+  sb = cpi->super[0];
+  sb_end = sb + cpi->super_n[0];
   for(; sb<sb_end; sb++){
+    
     for(j = 0; j<4; j++){ /* mode addressing is through Y plane, always 4 MB per SB */
       int mbi = sb->m[j];
 
@@ -804,16 +848,6 @@
 	/* basic 1MV search always done for all macroblocks, coded or not, keyframe or not */
 	oc_mcenc_search(cpi, &mcenc, mbi, 0, mb->mv, &aerror, block_err);
 	
-	/* replace the block MVs for not-coded blocks with (0,0).*/   
-	/*mb->coded = 0;
-	for ( bi=0; bi<4; bi++ ){
-	  int fi = mb->Ryuv[0][bi];
-	  if(!cp[fi]) 
-	    mb->mv[bi]=(mv_t){0,0};
-	  else
-	    mb->coded |= (1<<bi);
-	    }*/
-	
 	/* search golden frame */
 	oc_mcenc_search(cpi, &mcenc, mbi, 1, NULL, &gerror, NULL);
 	



More information about the commits mailing list