[xiph-commits] r9612 - trunk/theora/lib

giles at svn.xiph.org giles at svn.xiph.org
Sat Jul 23 23:32:36 PDT 2005


Author: giles
Date: 2005-07-23 23:32:34 -0700 (Sat, 23 Jul 2005)
New Revision: 9612

Modified:
   trunk/theora/lib/codec_internal.h
   trunk/theora/lib/decode.c
   trunk/theora/lib/quant.c
Log:
Slight code rearrangement. One the decode side, store the Q Index
value from the frame header directly in the playback state instead
of inverting it in UpdateQ(). Also move UpdateQ() into the frame
header parse from LoadAndDecode().

This actually removed the LastFrameQualityValue != ThisFrameQualityValue
check before recalculating the Q matricies. This should either be replaced
with a check against the previous Q Index (or single QI frames) or 
LastFrameQualityValue should go away entirely; but this involves
disentangling the encoder's use of the field.


Modified: trunk/theora/lib/codec_internal.h
===================================================================
--- trunk/theora/lib/codec_internal.h	2005-07-24 05:38:58 UTC (rev 9611)
+++ trunk/theora/lib/codec_internal.h	2005-07-24 06:32:34 UTC (rev 9612)
@@ -734,7 +734,7 @@
 extern void quantize( PB_INSTANCE *pbi,
                       ogg_int16_t * DCT_block,
                       Q_LIST_ENTRY * quantized_list);
-extern void UpdateQ( PB_INSTANCE *pbi, ogg_uint32_t NewQ );
+extern void UpdateQ( PB_INSTANCE *pbi, int NewQIndex );
 extern void UpdateQC( CP_INSTANCE *cpi, ogg_uint32_t NewQ );
 extern void fdct_short ( ogg_int16_t * InputData, ogg_int16_t * OutputData );
 extern ogg_uint32_t DPCMTokenizeBlock (CP_INSTANCE *cpi,

Modified: trunk/theora/lib/decode.c
===================================================================
--- trunk/theora/lib/decode.c	2005-07-24 05:38:58 UTC (rev 9611)
+++ trunk/theora/lib/decode.c	2005-07-24 06:32:34 UTC (rev 9612)
@@ -61,7 +61,7 @@
 
 static int LoadFrameHeader(PB_INSTANCE *pbi){
   long ret;
-  unsigned char  DctQMask;
+  unsigned char  DctQIndex;
   unsigned char  SpareBits;       /* Spare cfg bits */
 
   /* Is the frame and inter frame or a key frame */
@@ -70,11 +70,13 @@
 
   /* Quality (Q) index */
   theora_read(pbi->opb,6,&ret);
-  DctQMask = (unsigned char)ret;
+  DctQIndex = (unsigned char)ret;
 
   /* spare bit for possible additional Q indicies - should be 0 */
   theora_read(pbi->opb,1,&ret);
   SpareBits = (unsigned char)ret;
+  /* todo: properly handle additional Q indicies */
+  if (SpareBits != 0) return OC_IMPL;
 
   if ( (pbi->FrameType == KEY_FRAME) ){
     /* Read the type / coding method for the key frame. */
@@ -84,10 +86,11 @@
     theora_read(pbi->opb,2,&ret);
     SpareBits = (unsigned char)ret;
 
+    if (pbi->KeyFrameType || SpareBits) return OC_BADPACKET;
   }
 
-  /* Set this frame quality value from Q Index */
-  pbi->ThisFrameQualityValue = pbi->QThreshTable[DctQMask];
+  /* Set this frame quality value and tables from the coded Q Index */
+  UpdateQ(pbi, DctQIndex);
 
   return 1;
 }
@@ -822,13 +825,8 @@
   LoadFrameOK = LoadFrame(pbi);
 
   if ( LoadFrameOK ){
-    if ( (pbi->ThisFrameQualityValue != pbi->LastFrameQualityValue) ){
-      /* Initialise DCT tables. */
-      UpdateQ( pbi, pbi->ThisFrameQualityValue );
-      pbi->LastFrameQualityValue = pbi->ThisFrameQualityValue;
-    }
+    pbi->LastFrameQualityValue = pbi->ThisFrameQualityValue;
 
-
     /* Decode the data into the fragment buffer. */
     DecodeData(pbi);
     return(0);

Modified: trunk/theora/lib/quant.c
===================================================================
--- trunk/theora/lib/quant.c	2005-07-24 05:38:58 UTC (rev 9611)
+++ trunk/theora/lib/quant.c	2005-07-24 06:32:34 UTC (rev 9612)
@@ -783,26 +783,18 @@
   pbi->dequant_coeffs = pbi->dequant_Y_coeffs;
 }
 
-void UpdateQ( PB_INSTANCE *pbi, ogg_uint32_t NewQ ){
+void UpdateQ( PB_INSTANCE *pbi, int NewQIndex ){
   ogg_uint32_t qscale;
 
-  /* Do bounds checking and convert to a float. */
-  qscale = NewQ;
-  if ( qscale < pbi->QThreshTable[Q_TABLE_SIZE-1] )
-    qscale = pbi->QThreshTable[Q_TABLE_SIZE-1];
-  else if ( qscale > pbi->QThreshTable[0] )
-    qscale = pbi->QThreshTable[0];
+  /* clamp to legal bounds */
+  if (NewQIndex >= Q_TABLE_SIZE) NewQIndex = Q_TABLE_SIZE - 1;
+  else if (NewQIndex < 0) NewQIndex = 0;
 
-  /* Set the inter/intra descision control variables. */
-  pbi->FrameQIndex = Q_TABLE_SIZE - 1;
-  while ( (ogg_int32_t) pbi->FrameQIndex >= 0 ) {
-    if ( (pbi->FrameQIndex == 0) ||
-         ( pbi->QThreshTable[pbi->FrameQIndex] >= NewQ) )
-      break;
-    pbi->FrameQIndex --;
-  }
+  pbi->FrameQIndex = NewQIndex;
+  qscale = pbi->QThreshTable[NewQIndex];
+  pbi->ThisFrameQualityValue = qscale;
 
-  /* Re-initialise the q tables for forward and reverse transforms. */
+  /* Re-initialise the Q tables for forward and reverse transforms. */
   init_dequantizer ( pbi, qscale, (unsigned char) pbi->FrameQIndex );
 }
 



More information about the commits mailing list