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

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Sat Jun 28 18:36:16 PDT 2008


Author: xiphmont
Date: 2008-06-28 18:36:13 -0700 (Sat, 28 Jun 2008)
New Revision: 15083

Modified:
   branches/theora-thusnelda/lib/enc/codec_internal.h
   branches/theora-thusnelda/lib/enc/dct_encode.c
   branches/theora-thusnelda/lib/enc/encode.c
   branches/theora-thusnelda/lib/enc/frinit.c
   branches/theora-thusnelda/lib/enc/mode.c
Log:
Refactoring of tokenization process to allow coding DC last, such that 
AC can be tokenized at quantization time and DC tokenization can be 
delayed until after DC predict.



Modified: branches/theora-thusnelda/lib/enc/codec_internal.h
===================================================================
--- branches/theora-thusnelda/lib/enc/codec_internal.h	2008-06-29 00:25:13 UTC (rev 15082)
+++ branches/theora-thusnelda/lib/enc/codec_internal.h	2008-06-29 01:36:13 UTC (rev 15083)
@@ -248,16 +248,18 @@
   ogg_int16_t     *fr_block;
   unsigned char   *fr_block_bits;
 
+  int              stack_offset;
   unsigned char   *dct_token_storage;
   ogg_uint16_t    *dct_token_eb_storage;
   unsigned char   *dct_token[64];
   ogg_uint16_t    *dct_token_eb[64];
 
-  ogg_uint32_t     dct_token_count[64];
-  ogg_uint32_t     dct_token_ycount[64];
+  ogg_int32_t      dct_token_count[64];
+  ogg_int32_t      dct_token_ycount[64];
 
   ogg_uint32_t     dc_bits[2][DC_HUFF_CHOICES];
-  ogg_uint32_t     ac_bits[2][AC_HUFF_CHOICES];
+  ogg_uint32_t     ac1_bits[2][AC_HUFF_CHOICES];
+  ogg_uint32_t     acN_bits[2][AC_HUFF_CHOICES];
 
   oc_mode_scheme_chooser chooser;
 

Modified: branches/theora-thusnelda/lib/enc/dct_encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/dct_encode.c	2008-06-29 00:25:13 UTC (rev 15082)
+++ branches/theora-thusnelda/lib/enc/dct_encode.c	2008-06-29 01:36:13 UTC (rev 15083)
@@ -31,39 +31,6 @@
   64,64,64,64,64,64,64,64,
   64,64,64,64,64,64,64,64};
 
-/* used for the DC encoding after AC encoding has finished; need to be
-   able to undo AC tokens when zero runs cause things to be moved into
-   the DC token stack from the AC coefficient 1 token stack */
-static void replace_AC1_token(CP_INSTANCE *cpi, int oldchroma, int newchroma,
-			      int pos, int token, int eb, int fi){
-  int oldtoken = cpi->dct_token[1][pos];
-  int i,offset = acoffset[1];
-  
-  /* update huffman tree choice metrics */
-  for ( i = 0; i < AC_HUFF_CHOICES; i++)
-    cpi->ac_bits[oldchroma][i] -= cpi->HuffCodeLengthArray_VP3x[offset+i][oldtoken];
-  if(token < DCT_NOOP)
-    for ( i = 0; i < AC_HUFF_CHOICES; i++)
-      cpi->ac_bits[newchroma][i] -= cpi->HuffCodeLengthArray_VP3x[offset+i][token];
-  
-  /* replace the token itself */
-  cpi->dct_token[1][pos] = token;
-  cpi->dct_token_eb[1][pos] = eb;
-#ifdef COLLECT_METRICS
-  cpi->dct_token_frag[1][pos] = fi;
-#endif
-
-  /* although we have the same token count after as before, the
-     preceeding token may have been in the Y plane where the new one
-     is in a chroma plane. This could happen, eg, when an EOB run
-     begins on the last fragment of the Y plane and continues into
-     chroma, but subsequent DC encoding moves the EOB start for that
-     last fragment into the DC stack. The new coeff 1 EOB token would
-     go into chroma. */
-  if(!oldchroma && newchroma) cpi->dct_token_ycount[1]--;
-  
-}
-
 static void add_token(CP_INSTANCE *cpi, int chroma, int coeff, 
 		      unsigned char token, ogg_uint16_t eb, int fi){
   
@@ -80,11 +47,16 @@
     int i;
     for ( i = 0; i < DC_HUFF_CHOICES; i++)
       cpi->dc_bits[chroma][i] += cpi->HuffCodeLengthArray_VP3x[i][token];
+  }else if (coeff == 1){
+    /* AC == 1*/
+    int i,offset = acoffset[1];
+    for ( i = 0; i < AC_HUFF_CHOICES; i++)
+      cpi->ac1_bits[chroma][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
   }else{
-    /* AC */
+    /* AC > 1*/
     int i,offset = acoffset[coeff];
     for ( i = 0; i < AC_HUFF_CHOICES; i++)
-      cpi->ac_bits[chroma][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
+      cpi->acN_bits[chroma][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
   }
 }
 
@@ -107,11 +79,16 @@
     int i;
     for ( i = 0; i < DC_HUFF_CHOICES; i++)
       cpi->dc_bits[chroma][i] += cpi->HuffCodeLengthArray_VP3x[i][token];
+  }else if (coeff == 1){
+    /* AC == 1*/
+    int i,offset = acoffset[1];
+    for ( i = 0; i < AC_HUFF_CHOICES; i++)
+      cpi->ac1_bits[chroma][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
   }else{
-    /* AC */
+    /* AC > 1*/
     int i,offset = acoffset[coeff];
     for ( i = 0; i < AC_HUFF_CHOICES; i++)
-      cpi->ac_bits[chroma][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
+      cpi->acN_bits[chroma][i] += cpi->HuffCodeLengthArray_VP3x[offset+i][token];
   }
 }
 
@@ -262,24 +239,10 @@
 	
 	/* if there are no other tokens in this group yet, set up to be
 	   prepended later.  */
-	if(cpi->dct_token_count[coeff] == 0){
-	  /* prepending requires space to do so-- save some at front of token stack */
-	  if(eob_pre[coeff]==0 || !(eob_pre[coeff]&0x8ff)){ /* 0xfff is a safe overallocation, 
-							       saves a mod 4095 */
-	    cpi->dct_token[coeff]++;
-	    cpi->dct_token_eb[coeff]++;
-#ifdef COLLECT_METRICS
-	    cpi->dct_token_frag[coeff]++;
-#endif
-	  }
-	  
-	  /* finally, track pre-run */
+	if(cpi->dct_token_count[coeff] == 0 && coeff>1){
+	  /* track pre-run */
 	  eob_pre[coeff]++;
 	  if(!chroma)eob_ypre[coeff]++;
-	  
-#ifdef COLLECT_METRICS
-	  cpi->dct_eob_fi_stack[coeff][cpi->dct_eob_fi_count[coeff]++]=fi;
-#endif
 	}else{
 	  if(eob_run[coeff] == 4095){
 	    emit_eob_run(cpi,(eob_yrun[coeff]==0),coeff,4095);
@@ -289,11 +252,10 @@
 	  
 	  eob_run[coeff]++;
 	  if(!chroma)eob_yrun[coeff]++;
-	  
+	}	  
 #ifdef COLLECT_METRICS
-	  cpi->dct_eob_fi_stack[coeff][cpi->dct_eob_fi_count[coeff]++]=fi;
+	cpi->dct_eob_fi_stack[coeff][cpi->dct_eob_fi_count[coeff]++]=fi;
 #endif
-	}
 	coeff = BLOCK_SIZE;
       }else{
 	
@@ -423,99 +385,99 @@
 /* called after AC tokenization is complete, because DC coding has to
    happen after DC predict, which has to happen after the
    Hilbert-ordered TQT loop */
+/* Convention: All EOB runs in the coeff1 stack are regenerated as the
+   runs are tracked.  Other tokens are adjusted in-place (potentially
+   replaced with NOOP tokens.  The size of the coeff 1 stack is not
+   altered */
 static void tokenize_DC(CP_INSTANCE *cpi, int fi, int chroma,
-			int *eob_yrun, int *eob_run,
-			int *coeff1_idx, int *coeff1_run){
+			int *eob_ypre, int *eob_pre, 
+			int *eob_yrun, int *eob_run, 
+			int *idx1, int *run1){
   
   unsigned char *cp=cpi->frag_coded;
+
   if ( cp[fi] ) {
     dct_t *dct = &cpi->frag_dct[fi];
     int val = dct->data[0];
+    int token1 = cpi->dct_token[1][*idx1];
+    int eb1 = cpi->dct_token_eb[1][*idx1];
 
-    /* track the coeff 1 token stack: do we need to start a new EOB run? */
-    if (*coeff1_run==0){
-      int token1 = cpi->dct_token[1][*coeff1_idx];
-      int eb1 = cpi->dct_token_eb[1][*coeff1_idx];
+    if(!*run1) *run1 = decode_eob_token(token1, eb1);
 
-      *coeff1_run = decode_eob_token(token1, eb1);
-    }
+    if(val){
+      /* nonzero DC val, no coeff 1 stack 'fixup'. */
 
-    if(val){
-      /* nonzero val, we're not going to need any fixup */
-      /* Emit DC EOB run if any in pending */
+      /* Emit pending DC EOB run if any */
       if(eob_run[0]){
 	emit_eob_run(cpi,(eob_yrun[0]==0),0,eob_run[0]);
 	eob_run[0]=0;
 	eob_yrun[0]=0;
       }
+      /* Emit DC value token */
+      TokenizeDctValue(cpi, chroma, 0, val, fi);
+
+      /* there was a nonzero DC value, so there's no alteration to the
+	 track1 stack for this fragment; track/regenerate stack 1
+	 state unchanged */
+      if(*run1){
+	/* in the midst of an EOB run in stack 1 */
+	if(cpi->dct_token_count[1]==0){
+	  /* track pre-run */
+	  eob_pre[1]++;
+	  if(!chroma)eob_ypre[1]++;
+	}else{
+	  if(eob_run[1] == 4095){
+	    emit_eob_run(cpi,(eob_yrun[1]==0),1,4095);
+	    eob_run[1] = 0;
+	    eob_yrun[1] = 0;
+	  }
+	  eob_run[1]++;
+	  if(!chroma)eob_yrun[1]++;
+	}	  	  
+	(*run1)--;
+#ifdef COLLECT_METRICS
+	cpi->dct_eob_fi_stack[1][cpi->dct_eob_fi_count[1]++]=fi;
+#endif
+      }else{
+	/* non-EOB run token to emit for stack 1 */
+
+	/* emit stack 1 eobrun if any */
+	if(eob_run[1]){
+	  emit_eob_run(cpi,(eob_yrun[1]==0),1,eob_run[1]);
+	  eob_run[1]=eob_yrun[1]=0;
+	}
 	
-      /* Emit value token */
-      TokenizeDctValue(cpi, chroma, 0, val, fi);
-      
+	/* emit stack 1 token */
+	add_token(cpi, chroma, 1, token1, eb1, fi);
+      }
+
     }else{
 
       /* zero DC value; that means the entry in coeff position 1
-	 should have been a zero-run or eob token located in the DC coeff
-	 position */
+	 should have been coded from the DC coeff position. This
+	 requires a stack 1 fixup. */
       
-      if(*coeff1_run > 0){
-	/* this is complicated by the pre and post runs not yet being
-	   coded to tokens.  Handle all three cases seperately */
-	if(*coeff1_idx<0){
-	  /* pre-run */
+      if(*run1){
+	/* current stack 1 token an EOB run; conceptually move this fragment's EOBness to stack 0 */
 
-	    add_token(cpi, chroma, 0, DCT_SHORT_ZRL_TOKEN, 0, fi);
-
-
-	}else if (*coeff1_idx>=cpi->dct_token_count[1]){
-	  /* post-run */
-
-
-	    add_token(cpi, chroma, 0, DCT_SHORT_ZRL_TOKEN, 0, fi);
-
-	}else{
-
-	  add_token(cpi, chroma, 0, DCT_SHORT_ZRL_TOKEN, 0, fi);
-#if 0
-	  /* normal tokenized run */
-	  int token1 = cpi->dct_token[1][*coeff1_idx];
-	  int eb1 = cpi->dct_token_eb[1][*coeff1_idx];
-	  int run = decode_eob_token(token1, eb1);
-
-	  if(run==1){
-	    /* the EOB 'run' was only one EOB and started this fragemnt; the token gets nopped */
-	    replace_AC1_token(cpi, chroma, chroma, *coeff1_idx, DCT_NOOP, 0, 0);
-	  }else{
-	    /* if the coeff 1 EOB run started at this fragment, we're
-	       not just reducing the length of the EOB, we're also
-	       'bumping' the new start to the next fragment. It's important
-	       to know that if the token is bumped out of luma into
-	       chroma */
-	    int bump = (run == *coeff1_run);
-	    int newtoken=0,neweb=0;
-	    tokenize_eob_run(run-1, &newtoken, &neweb);XXXXXX
-	    replace_AC1_token(cpi, bump, *coeff1_idx, newtoken, neweb, 0);
-	  }
-#endif
+	if(eob_run[0] == 4095){
+	  emit_eob_run(cpi,(eob_yrun[0]==0),0,4095);
+	  eob_run[0] = 0;
+	  eob_yrun[0] = 0;
 	}
-	
-#if 0
 	eob_run[0]++;
-	if(!chroma)eob_yrun[0]++;
-	
+	if(!chroma)eob_yrun[0]++;	      
 #ifdef COLLECT_METRICS
 	cpi->dct_eob_fi_stack[0][cpi->dct_eob_fi_count[0]++]=fi;
 #endif
-#endif
-	
+	      
+	/* decrement current EOB run for coeff 1 without adding to coded run */
+	(*run1)--;
 
       }else{
 
-	int token1 = cpi->dct_token[1][*coeff1_idx];
-	int eb1 = cpi->dct_token_eb[1][*coeff1_idx];
-
-	/* coeff 1 is one of: zerorun, dctrun or dctval */
-	/* A zero-run token is expanded and moved to token stack 0 (stack 1 entry noopped) */
+	/* stack 1 token is one of: zerorun, dctrun or dctval */
+	/* A zero-run token is expanded and moved to token stack 0 (stack 1 entry dropped) */
 	/* A dctval may be transformed into a single dctrun that is moved to stack 0,
 	   or if it does not fit in a dctrun, we leave the stack 1 entry alone and emit 
 	   a single length-1 zerorun token for stack 0 */
@@ -524,7 +486,7 @@
 	   so we know there's no chance of overrunning the
 	   representable range */
 
-	/* Emit DC EOB run if any in pending */
+	/* Emit DC EOB run if any pending */
 	if(eob_run[0]){
 	  emit_eob_run(cpi,(eob_yrun[0]==0),0,eob_run[0]);
 	  eob_run[0]=0;
@@ -533,45 +495,52 @@
 	  
 	if(token1 <= DCT_ZRL_TOKEN){
 	  /* zero-run.  Extend and move it */
-
 	  int run = decode_zrl_token(token1,eb1);
-	  replace_AC1_token(cpi, 0, *coeff1_idx, DCT_NOOP, 0, 0);
 	  
 	  /* Emit zerorun token */
-	    if ( run+1 <= 8 )
-	      add_token(cpi, chroma, 0, DCT_SHORT_ZRL_TOKEN, run, fi);
-	    else
-	      add_token(cpi, chroma, 0, DCT_ZRL_TOKEN, run, fi);
+	  if ( run < 8 )
+	    add_token(cpi, chroma, 0, DCT_SHORT_ZRL_TOKEN, run, fi);
+	  else
+	    add_token(cpi, chroma, 0, DCT_ZRL_TOKEN, run, fi);
+
+	  /* do not recode stack 1 token */
+
 	} else if(token1 <= DCT_VAL_CATEGORY8){
 
 	  /* DCT value token; will it fit into a dctrun? */
 	  int val = decode_dct_token(token1,eb1);
 
 	  if(abs(val)<=3){
-	    /* emit a dctrun in stack 0, replace the dct token in stack 1*/
+	    /* emit a dctrun in stack 0, do not recode stack 1 token */
 	    TokenizeDctRunValue( cpi, chroma, 0, 1, val, fi);
-	    replace_AC1_token(cpi, 0, *coeff1_idx, DCT_NOOP, 0, 0);
 	  }else{
-	    /* leave dct value token alone, emit a short zerorun */
+	    /* Code stack 0 short zero run */
 	    add_token(cpi, chroma, 0, DCT_SHORT_ZRL_TOKEN, 0, fi);
+	    
+	    /* emit stack 1 eobrun if any */
+	    if(eob_run[1]){
+	      emit_eob_run(cpi,(eob_yrun[1]==0),1,eob_run[1]);
+	      eob_run[1]=eob_yrun[1]=0;
+	    }
+	
+	    /* emit stack 1 token */
+	    add_token(cpi, chroma, 1, token1, eb1, fi);
+
 	  }
 	} else {
 	  /* dctrun token; extend the run by one and move it to stack 0 */
 	  int val;
 	  int run = decode_dctrun_token(token1,eb1,&val)+1;
 	  TokenizeDctRunValue( cpi, chroma, 0, run, val, fi);
-	  replace_AC1_token(cpi, 0, *coeff1_idx, DCT_NOOP, 0, 0);
+	  /* do not recode stack 1 token */
 	}
       }
     }
     
-    /* update stack 1 counters */
-    if (*coeff1_run > 0) (*coeff1_run)--;
-    if (*coeff1_run == 0){
-      (*coeff1_idx)++;
-      if (*coeff1_idx >= cpi->dct_token_count[1])
-	*coeff1_run = eob_run[1];
-    }
+    /* update token counter if not in a run */
+    if (!*run1) (*idx1)++;
+    
+
   }
 }
 
@@ -582,14 +551,15 @@
   int eob_ypre[64];
   
   int i,sbi;
-  int idx1,run1;
+  int idx1=0,run1=0;
 
   memset(eob_run, 0, sizeof(eob_run));
   memset(eob_pre, 0, sizeof(eob_pre));
   memset(eob_yrun, 0, sizeof(eob_yrun));
   memset(eob_ypre, 0, sizeof(eob_ypre));
   memset(cpi->dc_bits, 0, sizeof(cpi->dc_bits));
-  memset(cpi->ac_bits, 0, sizeof(cpi->ac_bits));
+  memset(cpi->ac1_bits, 0, sizeof(cpi->ac1_bits));
+  memset(cpi->acN_bits, 0, sizeof(cpi->acN_bits));
   memset(cpi->dct_token_count, 0, sizeof(cpi->dct_token_count));
   memset(cpi->dct_token_ycount, 0, sizeof(cpi->dct_token_ycount));
 #ifdef COLLECT_METRICS
@@ -597,12 +567,12 @@
 #endif
 
   for(i=0;i<BLOCK_SIZE;i++){
-    cpi->dct_token[i] = cpi->dct_token_storage+cpi->frag_total*i;
-    cpi->dct_token_eb[i] = cpi->dct_token_eb_storage+cpi->frag_total*i;
+    cpi->dct_token[i] = cpi->dct_token_storage + cpi->stack_offset*i;
+    cpi->dct_token_eb[i] = cpi->dct_token_eb_storage + cpi->stack_offset*i;
 
 #ifdef COLLECT_METRICS
-    cpi->dct_eob_fi_stack[i] = cpi->dct_eob_fi_storage+cpi->frag_total*i;
-    cpi->dct_token_frag[i] = cpi->dct_token_frag_storage+cpi->frag_total*i;
+    cpi->dct_eob_fi_stack[i] = cpi->dct_eob_fi_storage + cpi->frag_total*i;
+    cpi->dct_token_frag[i] = cpi->dct_token_frag_storage + cpi->stack_offset*i;
 #endif
   }
 
@@ -623,27 +593,57 @@
     }
   }
 
+  fprintf(stderr,"\n%d (pre): 1count=%d/%d (%d/%d, %d/%d)\n",
+	  (int)cpi->CurrentFrame, 
+	  cpi->dct_token_ycount[1], cpi->dct_token_count[1],
+	  eob_ypre[1],eob_pre[1],
+	  eob_yrun[1],eob_run[1]);
+
   /* for testing; post-facto tokenization of DC with coeff 1 fixups */
-  run1=eob_pre[1];
-  idx1=(run1?-1:0);
+
+  /* we parse the token stack for coeff1 to stay in sync, and re-use
+     the token stack counters to track */
+  /* emit an eob run for the end run of stack 1; this is used to
+     reparse the stack in the DC code loop.  The current state will be
+     recreated by the end of DC encode */
+  if(eob_run[1]) emit_eob_run(cpi,(eob_yrun[1]==0),1,eob_run[1]);
+  memset(cpi->ac1_bits, 0, sizeof(cpi->ac1_bits));
+  cpi->dct_token_count[1]=0;
+  cpi->dct_token_ycount[1]=0;
+  eob_ypre[1]=eob_pre[1]=eob_yrun[1]=eob_run[1]=0;
+#ifdef COLLECT_METRICS
+  /* reset and reuse as a counter */
+  cpi->dct_eob_fi_count[1]=0;
+#endif
+  
   for (sbi=0; sbi < cpi->super_n[0]; sbi++ ){
     superblock_t *sb = &cpi->super[0][sbi];
     int bi;
-    for (bi=0; bi<16; bi++ ) {
+    for (bi=0; bi<16; bi++, i++ ) {
       int fi = sb->f[bi];
-      tokenize_DC(cpi, fi, 0, eob_yrun, eob_run, &idx1, &run1);
+      tokenize_DC(cpi, fi, 0, eob_ypre, eob_pre, eob_yrun, eob_run, &idx1, &run1);
     }
   }
 
   for (; sbi < cpi->super_total; sbi++ ){
     superblock_t *sb = &cpi->super[0][sbi];
     int bi;
-    for (bi=0; bi<16; bi++ ) {
+    for (bi=0; bi<16; bi++,i++ ) {
       int fi = sb->f[bi];
-      tokenize_DC(cpi, fi, 1, eob_yrun, eob_run, &idx1, &run1);
+      tokenize_DC(cpi, fi, 1, eob_ypre, eob_pre, eob_yrun, eob_run, &idx1, &run1);
     }
   }
 
+  /* DC coded, AC coeff 1 state fixed up/regenerated */
+
+  fprintf(stderr,"\n%d: 0count=%d/%d (%d/%d) 1count=%d/%d (%d/%d, %d/%d)\n",
+	  (int)cpi->CurrentFrame, 
+	  cpi->dct_token_ycount[0], cpi->dct_token_count[0],
+	  eob_yrun[0],eob_run[0],
+	  cpi->dct_token_ycount[1], cpi->dct_token_count[1],
+	  eob_ypre[1],eob_pre[1],
+	  eob_yrun[1],eob_run[1]);
+
   /* tie together eob runs at the beginnings/ends of coeff groups */
   {
     int coeff = 0;
@@ -715,7 +715,7 @@
 	}
       }else{
 	/* no eob run to begin group */
-	if(cpi->dct_token_count[i]){
+	if(i==0 || cpi->dct_token_count[i]){
 	  if(run)
 	    emit_eob_run(cpi,chroma,coeff,run);
 	  

Modified: branches/theora-thusnelda/lib/enc/encode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/encode.c	2008-06-29 00:25:13 UTC (rev 15082)
+++ branches/theora-thusnelda/lib/enc/encode.c	2008-06-29 01:36:13 UTC (rev 15083)
@@ -170,11 +170,12 @@
     }
   
     /* Work out which table options are best for AC */
-    best = cpi->ac_bits[plane][0];
+    best = cpi->ac1_bits[plane][0]+cpi->acN_bits[plane][0];
     huff[plane+2] = AC_HUFF_OFFSET;
     for ( i = 1; i < AC_HUFF_CHOICES; i++ ) {
-      if ( cpi->ac_bits[plane][i] < best ){
-	best = cpi->ac_bits[plane][i];
+      int test = cpi->ac1_bits[plane][i] + cpi->acN_bits[plane][i];
+      if ( test < best ){
+	best = test;
 	huff[plane+2] = i + AC_HUFF_OFFSET;
       }
     }

Modified: branches/theora-thusnelda/lib/enc/frinit.c
===================================================================
--- branches/theora-thusnelda/lib/enc/frinit.c	2008-06-29 00:25:13 UTC (rev 15082)
+++ branches/theora-thusnelda/lib/enc/frinit.c	2008-06-29 01:36:13 UTC (rev 15083)
@@ -130,8 +130,9 @@
   cpi->super[1] = cpi->super[0] + cpi->super_n[0];
   cpi->super[2] = cpi->super[1] + cpi->super_n[1];
 
-  cpi->dct_token_storage = _ogg_malloc(cpi->frag_total*BLOCK_SIZE*sizeof(*cpi->dct_token_storage));
-  cpi->dct_token_eb_storage = _ogg_malloc(cpi->frag_total*BLOCK_SIZE*sizeof(*cpi->dct_token_eb_storage));
+  cpi->stack_offset = (cpi->frag_total + (cpi->frag_total+4094)/4095 + 1);
+  cpi->dct_token_storage = _ogg_malloc( cpi->stack_offset*BLOCK_SIZE*sizeof(*cpi->dct_token_storage));
+  cpi->dct_token_eb_storage = _ogg_malloc(cpi->stack_offset*BLOCK_SIZE*sizeof(*cpi->dct_token_eb_storage));
 
   cpi->fr_partial = _ogg_calloc(cpi->super_total+1, sizeof(*cpi->fr_partial));
   cpi->fr_partial_bits = _ogg_calloc(cpi->super_total+1, sizeof(*cpi->fr_partial_bits));
@@ -144,7 +145,7 @@
   cpi->frag_mbi = _ogg_calloc(cpi->frag_total+1, sizeof(*cpi->frag_mbi));
   for(i=0;i<8;i++)
     cpi->frag_sad[i] = _ogg_calloc(cpi->frag_total+1, sizeof(**cpi->frag_sad));
-  cpi->dct_token_frag_storage = _ogg_malloc(cpi->frag_total*BLOCK_SIZE*sizeof(*cpi->dct_token_frag_storage));
+  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));
 #endif
   

Modified: branches/theora-thusnelda/lib/enc/mode.c
===================================================================
--- branches/theora-thusnelda/lib/enc/mode.c	2008-06-29 00:25:13 UTC (rev 15082)
+++ branches/theora-thusnelda/lib/enc/mode.c	2008-06-29 01:36:13 UTC (rev 15083)
@@ -1042,11 +1042,11 @@
 	    prior_mv = last_mv;
 
 	    for(i=0;i<4;i++)
-	      if(mb->coded & (1<<i){
+	      if(mb->coded & (1<<i)){
 		cpi->MVBits_0 += 
 		  MvBits[mb->mv[i].x + MAX_MV_EXTENT] + 
 		  MvBits[mb->mv[i].y + MAX_MV_EXTENT];
-		cpi->MV_Bits_1 += 12;
+		cpi->MVBits_1 += 12;
 		last_mv = mb->mv[i];
 	      }
 	    break;



More information about the commits mailing list