[xiph-commits] r14369 - in trunk/theora/lib: . dec

tterribe at svn.xiph.org tterribe at svn.xiph.org
Sat Jan 5 15:15:39 PST 2008


Author: tterribe
Date: 2008-01-05 15:15:32 -0800 (Sat, 05 Jan 2008)
New Revision: 14369

Added:
   trunk/theora/lib/dec/bitwise.c
   trunk/theora/lib/dec/bitwise.h
Modified:
   trunk/theora/lib/Makefile.am
   trunk/theora/lib/dec/decinfo.c
   trunk/theora/lib/dec/decint.h
   trunk/theora/lib/dec/decode.c
   trunk/theora/lib/dec/dequant.c
   trunk/theora/lib/dec/huffdec.c
Log:
Copy the libogg bitpacker directly into libtheoradec.
Due to the vagaries of -fPIC and dynamic linking, we wasting a _huge_ amount of
 time on function call overhead.
We also take the opportunity to get rid of our wrapper around the old libogg
 API and implement the API we want directly.
This gives more than an 18% decoding speed-up for an 82-byte net increase in
 code size.



Modified: trunk/theora/lib/Makefile.am
===================================================================
--- trunk/theora/lib/Makefile.am	2008-01-05 23:01:51 UTC (rev 14368)
+++ trunk/theora/lib/Makefile.am	2008-01-05 23:15:32 UTC (rev 14369)
@@ -74,6 +74,7 @@
 
 decoder_sources = \
 	dec/apiwrapper.c \
+	dec/bitwise.c \
 	dec/decapiwrapper.c \
 	dec/decinfo.c \
 	dec/decode.c \
@@ -114,6 +115,7 @@
 	enc/toplevel_lookup.h \
 	enc/dsp.h \
 	dec/apiwrapper.h \
+	dec/bitwise.h \
 	dec/dct.h \
 	dec/decint.h \
 	dec/dequant.h \

Copied: trunk/theora/lib/dec/bitwise.c (from rev 14367, trunk/ogg/src/bitwise.c)
===================================================================
--- trunk/theora/lib/dec/bitwise.c	                        (rev 0)
+++ trunk/theora/lib/dec/bitwise.c	2008-01-05 23:15:32 UTC (rev 14369)
@@ -0,0 +1,120 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+  function: packing variable sized words into an octet stream
+  last mod: $Id$
+
+ ********************************************************************/
+
+/* We're 'MSb' endian; if we write a word but read individual bits,
+   then we'll read the msb first */
+
+#include <string.h>
+#include <stdlib.h>
+#include "bitwise.h"
+
+void theorapackB_reset(oggpack_buffer *b){
+  b->ptr=b->buffer;
+  b->buffer[0]=0;
+  b->endbit=b->endbyte=0;
+}
+
+void theorapackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
+  memset(b,0,sizeof(*b));
+  b->buffer=b->ptr=buf;
+  b->storage=bytes;
+}
+
+int theorapackB_look1(oggpack_buffer *b,long *_ret){
+  if(b->endbyte>=b->storage){
+    *_ret=0L;
+    return -1;
+  }
+  *_ret=((b->ptr[0]>>(7-b->endbit))&1);
+  return 0;
+}
+
+void theorapackB_adv1(oggpack_buffer *b){
+  if(++(b->endbit)>7){
+    b->endbit=0;
+    b->ptr++;
+    b->endbyte++;
+  }
+}
+
+/* bits <= 32 */
+int theorapackB_read(oggpack_buffer *b,int bits,long *_ret){
+  long ret;
+  long m;
+  int fail;
+  m=32-bits;
+  bits+=b->endbit;
+  if(b->endbyte+4>=b->storage){
+    /* not the main path */
+    if(b->endbyte*8+bits>b->storage*8){
+      *_ret=0L;
+      fail=-1;
+      goto overflow;
+    }
+  }
+  ret=b->ptr[0]<<(24+b->endbit);
+  if(bits>8){
+    ret|=b->ptr[1]<<(16+b->endbit);
+    if(bits>16){
+      ret|=b->ptr[2]<<(8+b->endbit);
+      if(bits>24){
+        ret|=b->ptr[3]<<(b->endbit);
+        if(bits>32 && b->endbit)
+          ret|=b->ptr[4]>>(8-b->endbit);
+      }
+    }
+  }
+  *_ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
+  fail=0;
+overflow:
+  b->ptr+=bits/8;
+  b->endbyte+=bits/8;
+  b->endbit=bits&7;
+  return fail;
+}
+
+int theorapackB_read1(oggpack_buffer *b,long *_ret){
+  int fail;
+  if(b->endbyte>=b->storage){
+    /* not the main path */
+    *_ret=0L;
+    fail=-1;
+    goto overflow;
+  }
+  *_ret=(b->ptr[0]>>(7-b->endbit))&1;
+  fail=0;
+overflow:
+  b->endbit++;
+  if(b->endbit>7){
+    b->endbit=0;
+    b->ptr++;
+    b->endbyte++;
+  }
+  return fail;
+}
+
+long theorapackB_bytes(oggpack_buffer *b){
+  return(b->endbyte+(b->endbit+7)/8);
+}
+
+long theorapackB_bits(oggpack_buffer *b){
+  return(b->endbyte*8+b->endbit);
+}
+
+unsigned char *theorapackB_get_buffer(oggpack_buffer *b){
+  return(b->buffer);
+}

Added: trunk/theora/lib/dec/bitwise.h
===================================================================
--- trunk/theora/lib/dec/bitwise.h	                        (rev 0)
+++ trunk/theora/lib/dec/bitwise.h	2008-01-05 23:15:32 UTC (rev 14369)
@@ -0,0 +1,82 @@
+/********************************************************************
+ *                                                                  *
+ * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
+ * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
+ * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
+ * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
+ *                                                                  *
+ * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
+ * by the Xiph.Org Foundation http://www.xiph.org/                  *
+ *                                                                  *
+ ********************************************************************
+
+  function: packing variable sized words into an octet stream
+  last mod: $Id: bitwise.c 7675 2004-09-01 00:34:39Z xiphmont $
+
+ ********************************************************************/
+#if !defined(_bitwise_H)
+# define _bitwise_H (1)
+# include <ogg/ogg.h>
+
+void theorapackB_reset(oggpack_buffer *b);
+void theorapackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
+/* Read in bits without advancing the bitptr; bits <= 32 */
+static int theorapackB_look(oggpack_buffer *b,int bits,long *_ret);
+int theorapackB_look1(oggpack_buffer *b,long *_ret);
+static void theorapackB_adv(oggpack_buffer *b,int bits);
+void theorapackB_adv1(oggpack_buffer *b);
+/* bits <= 32 */
+int theorapackB_read(oggpack_buffer *b,int bits,long *_ret);
+int theorapackB_read1(oggpack_buffer *b,long *_ret);
+long theorapackB_bytes(oggpack_buffer *b);
+long theorapackB_bits(oggpack_buffer *b);
+unsigned char *theorapackB_get_buffer(oggpack_buffer *b);
+
+/*These two functions are only used in one place, and declaring them static so
+   they can be inlined saves considerable function call overhead.*/
+
+/* Read in bits without advancing the bitptr; bits <= 32 */
+static int theorapackB_look(oggpack_buffer *b,int bits,long *_ret){
+  long ret;
+  long m;
+  m=32-bits;
+  bits+=b->endbit;
+  if(b->endbyte+4>=b->storage){
+    /* not the main path */
+    if(b->endbyte>=b->storage){
+      *_ret=0L;
+      return -1;
+    }
+    /*If we have some bits left, but not enough, return the ones we have.*/
+    if(b->endbyte*8+bits>b->storage*8){
+      int rem_bits;
+      rem_bits=b->storage*8-(b->endbyte*8+b->endbit);
+      theorapackB_look(b,rem_bits,_ret);
+      *_ret<<=bits-b->endbit-rem_bits;
+      return 0;
+    }
+  }
+  ret=b->ptr[0]<<(24+b->endbit);
+  if(bits>8){
+    ret|=b->ptr[1]<<(16+b->endbit);
+    if(bits>16){
+      ret|=b->ptr[2]<<(8+b->endbit);
+      if(bits>24){
+        ret|=b->ptr[3]<<(b->endbit);
+        if(bits>32 && b->endbit)
+          ret|=b->ptr[4]>>(8-b->endbit);
+      }
+    }
+  }
+  *_ret=((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
+  return 0;
+}
+
+static void theorapackB_adv(oggpack_buffer *b,int bits){
+  bits+=b->endbit;
+  b->ptr+=bits/8;
+  b->endbyte+=bits/8;
+  b->endbit=bits&7;
+}
+
+#endif

Modified: trunk/theora/lib/dec/decinfo.c
===================================================================
--- trunk/theora/lib/dec/decinfo.c	2008-01-05 23:01:51 UTC (rev 14368)
+++ trunk/theora/lib/dec/decinfo.c	2008-01-05 23:15:32 UTC (rev 14369)
@@ -29,7 +29,7 @@
 static void oc_unpack_octets(oggpack_buffer *_opb,char *_buf,size_t _len){
   while(_len-->0){
     long val;
-    theora_read(_opb,8,&val);
+    theorapackB_read(_opb,8,&val);
     *_buf++=(char)val;
   }
 }
@@ -38,18 +38,18 @@
 static long oc_unpack_length(oggpack_buffer *_opb){
   long ret[4];
   int  i;
-  for(i=0;i<4;i++)theora_read(_opb,8,ret+i);
+  for(i=0;i<4;i++)theorapackB_read(_opb,8,ret+i);
   return ret[0]|ret[1]<<8|ret[2]<<16|ret[3]<<24;
 }
 
 static int oc_info_unpack(oggpack_buffer *_opb,th_info *_info){
   long val;
   /*Check the codec bitstream version.*/
-  theora_read(_opb,8,&val);
+  theorapackB_read(_opb,8,&val);
   _info->version_major=(unsigned char)val;
-  theora_read(_opb,8,&val);
+  theorapackB_read(_opb,8,&val);
   _info->version_minor=(unsigned char)val;
-  theora_read(_opb,8,&val);
+  theorapackB_read(_opb,8,&val);
   _info->version_subminor=(unsigned char)val;
   /*verify we can parse this bitstream version.
      We accept earlier minors and all subminors, by spec*/
@@ -59,25 +59,25 @@
     return TH_EVERSION;
   }
   /*Read the encoded frame description.*/
-  theora_read(_opb,16,&val);
+  theorapackB_read(_opb,16,&val);
   _info->frame_width=(ogg_uint32_t)val<<4;
-  theora_read(_opb,16,&val);
+  theorapackB_read(_opb,16,&val);
   _info->frame_height=(ogg_uint32_t)val<<4;
-  theora_read(_opb,24,&val);
+  theorapackB_read(_opb,24,&val);
   _info->pic_width=(ogg_uint32_t)val;
-  theora_read(_opb,24,&val);
+  theorapackB_read(_opb,24,&val);
   _info->pic_height=(ogg_uint32_t)val;
-  theora_read(_opb,8,&val);
+  theorapackB_read(_opb,8,&val);
   _info->pic_x=(ogg_uint32_t)val;
   /*Note: The sense of pic_y is inverted in what we pass back to the
      application compared to how it is stored in the bitstream.
     This is because the bitstream uses a right-handed coordinate system, while
      applications expect a left-handed one.*/
-  theora_read(_opb,8,&val);
+  theorapackB_read(_opb,8,&val);
   _info->pic_y=_info->frame_height-_info->pic_height-(ogg_uint32_t)val;
-  theora_read32(_opb,&val);
+  theorapackB_read(_opb,32,&val);
   _info->fps_numerator=(ogg_uint32_t)val;
-  theora_read32(_opb,&val);
+  theorapackB_read(_opb,32,&val);
   _info->fps_denominator=(ogg_uint32_t)val;
   if(_info->frame_width<=0||_info->frame_height<=0||
    _info->pic_width+_info->pic_x>_info->frame_width||
@@ -85,22 +85,22 @@
    _info->fps_numerator<=0||_info->fps_denominator<=0){
     return TH_EBADHEADER;
   }
-  theora_read(_opb,24,&val);
+  theorapackB_read(_opb,24,&val);
   _info->aspect_numerator=(ogg_uint32_t)val;
-  theora_read(_opb,24,&val);
+  theorapackB_read(_opb,24,&val);
   _info->aspect_denominator=(ogg_uint32_t)val;
-  theora_read(_opb,8,&val);
+  theorapackB_read(_opb,8,&val);
   _info->colorspace=(th_colorspace)val;
-  theora_read(_opb,24,&val);
+  theorapackB_read(_opb,24,&val);
   _info->target_bitrate=(int)val;
-  theora_read(_opb,6,&val);
+  theorapackB_read(_opb,6,&val);
   _info->quality=(int)val;
-  theora_read(_opb,5,&val);
+  theorapackB_read(_opb,5,&val);
   _info->keyframe_granule_shift=(int)val;
-  theora_read(_opb,2,&val);
+  theorapackB_read(_opb,2,&val);
   _info->pixel_fmt=(th_pixel_fmt)val;
   if(_info->pixel_fmt==TH_PF_RSVD)return TH_EBADHEADER;
-  if(theora_read(_opb,3,&val)<0||val!=0)return TH_EBADHEADER;
+  if(theorapackB_read(_opb,3,&val)<0||val!=0)return TH_EBADHEADER;
   return 0;
 }
 
@@ -129,7 +129,7 @@
       _tc->user_comments[i][len]='\0';
     }
   }
-  return theora_read(_opb,0,&len)<0?TH_EBADHEADER:0;
+  return theorapackB_read(_opb,0,&len)<0?TH_EBADHEADER:0;
 }
 
 static int oc_setup_unpack(oggpack_buffer *_opb,th_setup_info *_setup){
@@ -152,7 +152,7 @@
   long val;
   int  packtype;
   int  ret;
-  theora_read(_opb,8,&val);
+  theorapackB_read(_opb,8,&val);
   packtype=(int)val;
   /*If we're at a data packet and we have received all three headers, we're
      done.*/
@@ -220,7 +220,7 @@
   int            ret;
   if(_op==NULL)return TH_EBADHEADER;
   if(_info==NULL)return TH_EFAULT;
-  oggpackB_readinit(&opb,_op->packet,_op->bytes);
+  theorapackB_readinit(&opb,_op->packet,_op->bytes);
   ret=oc_dec_headerin(&opb,_info,_tc,_setup,_op);
   /*TODO: Clear opb in libogg2.*/
   return ret;

Modified: trunk/theora/lib/dec/decint.h
===================================================================
--- trunk/theora/lib/dec/decint.h	2008-01-05 23:01:51 UTC (rev 14368)
+++ trunk/theora/lib/dec/decint.h	2008-01-05 23:15:32 UTC (rev 14369)
@@ -20,6 +20,7 @@
 # define _decint_H (1)
 # include "theora/theoradec.h"
 # include "../internal.h"
+# include "bitwise.h"
 
 typedef struct th_setup_info oc_setup_info;
 typedef struct th_dec_ctx    oc_dec_ctx;
@@ -91,48 +92,4 @@
   th_stripe_callback   stripe_cb;
 };
 
-/*Fix-ups for the libogg1 API, which returns -1 when there are insufficient
-   bits left in the packet as the value read.
-  This has two problems:
-  a) Cannot distinguish between reading 32 1 bits and failing to have
-   sufficient bits left in the packet.
-  b) Returns values that are outside the range [0..(1<<nbits)-1], which can
-   crash code that uses such values as indexes into arrays, etc.
-
-  We solve the first problem by doing two reads and combining the results.
-  We solve the second problem by masking out the result based on the sign bit
-   of the return value.
-  It's a little more work, but branchless, so it should not slow us down much.
-
-  The libogg2 API does not have these problems, and the definitions of the
-   functions below can be replaced by direct libogg2 calls.
-
-  One issue remaining is that in libogg2, the return value and the number of
-   bits parameters are swapped between the read and write functions.
-  This can cause some confusion.
-  We could fix that in our wrapper here, but then we would be swapped from the
-   normal libogg2 calls, which could also cause confusion.
-  For the moment we keep the libogg2 parameter ordering.*/
-
-/*Read 32 bits.
-  *_ret is set to 0 on failure.
-  Return: 0 on success, or a negative value on failure.*/
-extern int theora_read32(oggpack_buffer *_opb,long *_ret);
-/*Read n bits, where n <= 31 for libogg1.
-  *_ret is set to 0 on failure.
-  Return: 0 on success, or a negative value on failure.*/
-extern int theora_read(oggpack_buffer *_opb,int _nbits,long *_ret);
-/*Read 1 bit,
-  *_ret is set to 0 on failure.
-  Return: 0 on success, or a negative value on failure.*/
-extern int theora_read1(oggpack_buffer *_opb,long *_ret);
-/*Look ahead n bits, where n <= 31 for libogg1.
-  In the event that there are some bits remaining, but fewer than n, then the
-   remaining bits are returned, with the missing bits set to 0, and the
-   function succeeds.
-  The stream can be advanced afterwards with oggpackB_adv().
-  *_ret is set to 0 on failure.
-  Return: 0 on success, or a negative value on failure.*/
-extern int theora_look(oggpack_buffer *_opb,int _nbits,long *_ret);
-
 #endif

Modified: trunk/theora/lib/dec/decode.c
===================================================================
--- trunk/theora/lib/dec/decode.c	2008-01-05 23:01:51 UTC (rev 14368)
+++ trunk/theora/lib/dec/decode.c	2008-01-05 23:15:32 UTC (rev 14369)
@@ -43,72 +43,8 @@
 /*Maximum valid post-processing level.*/
 #define OC_PP_LEVEL_MAX       (7)
 
-/*Read 32 bits.
-  *_ret is set to 0 on failure.
-  Return: 0 on success, or a negative value on failure.*/
-int theora_read32(oggpack_buffer *_opb,long *_ret){
-  long ret1;
-  long ret2;
-  long mask;
-  ret1=oggpackB_read(_opb,16);
-  ret2=oggpackB_read(_opb,16);
-  mask=ret2>>31;
-  *_ret=((ret1<<16)|ret2)&~mask;
-  return (int)mask;
-}
 
-/*Read n bits, where n <= 31 for libogg1.
-  *_ret is set to 0 on failure.
-  Return: 0 on success, or a negative value on failure.*/
-int theora_read(oggpack_buffer *_opb,int _nbits,long *_ret){
-  long mask;
-  *_ret=oggpackB_read(_opb,_nbits);
-  mask=*_ret>>31;
-  *_ret&=~mask;
-  return (int)mask;
-}
 
-/*Read 1 bit,
-  *_ret is set to 0 on failure.
-  Return: 0 on success, or a negative value on failure.*/
-int theora_read1(oggpack_buffer *_opb,long *_ret){
-  int mask;
-  *_ret=oggpackB_read1(_opb);
-  mask=(int)*_ret>>31;
-  *_ret&=~mask;
-  return mask;
-}
-
-/*Look ahead n bits, where n <= 31 for libogg1.
-  In the event that there are some bits remaining, but fewer than n, then the
-   remaining bits are returned, with the missing bits set to 0, and the
-   function succeeds.
-  The stream can be advanced afterwards with oggpackB_adv().
-  *_ret is set to 0 on failure.
-  Return: 0 on success, or a negative value on failure.*/
-int theora_look(oggpack_buffer *_opb,int _nbits,long *_ret){
-  int nbits;
-  *_ret=oggpackB_look(_opb,_nbits);
-  if(*_ret>=0)return 0;
-  /*libogg1 fails if we try to look past the end of the stream.
-    We might be looking ahead more bits than we actually need, however, and so
-     we must return the ones that are actually there.*/
-  /*There's no accessor for the storage field, which we need to figure out
-     how many bits _are_ left in the buffer (without resorting to trial and
-     error, which would be silly).*/
-  nbits=(_opb->storage<<3)-oggpackB_bits(_opb);
-  if(nbits>0){
-    /*If there are some bits left, return them.*/
-    *_ret=oggpackB_look(_opb,nbits)<<_nbits-nbits;
-    /*Success should be guaranteed.*/
-    return 0;
-  }
-  /*If there are no bits left, then we truly should fail.*/
-  *_ret=0;
-  return -1;
-}
-
-
 /*The mode alphabets for the various mode coding schemes.
   Scheme 0 uses a custom alphabet, which is not stored in this table.*/
 static const int OC_MODE_ALPHABETS[7][OC_NMODES]={
@@ -165,26 +101,26 @@
      11110xxx                10-17
      111110xxxx              18-33
      111111xxxxxxxxxxxx      34-4129*/
-  theora_read1(_opb,&bits);
+  theorapackB_read1(_opb,&bits);
   if(bits==0)return 1;
-  theora_read(_opb,2,&bits);
+  theorapackB_read(_opb,2,&bits);
   if((bits&2)==0)return 2+(int)bits;
   else if((bits&1)==0){
-    theora_read1(_opb,&bits);
+    theorapackB_read1(_opb,&bits);
     return 4+(int)bits;
   }
-  theora_read(_opb,3,&bits);
+  theorapackB_read(_opb,3,&bits);
   if((bits&4)==0)return 6+(int)bits;
   else if((bits&2)==0){
     ret=10+((bits&1)<<2);
-    theora_read(_opb,2,&bits);
+    theorapackB_read(_opb,2,&bits);
     return ret+(int)bits;
   }
   else if((bits&1)==0){
-    theora_read(_opb,4,&bits);
+    theorapackB_read(_opb,4,&bits);
     return 18+(int)bits;
   }
-  theora_read(_opb,12,&bits);
+  theorapackB_read(_opb,12,&bits);
   return 34+(int)bits;
 }
 
@@ -199,21 +135,21 @@
      1110xx                  7-10
      11110xx                 11-14
      11111xxxx               15-30*/
-  theora_read(_opb,2,&bits);
+  theorapackB_read(_opb,2,&bits);
   if((bits&2)==0)return 1+(int)bits;
   else if((bits&1)==0){
-    theora_read1(_opb,&bits);
+    theorapackB_read1(_opb,&bits);
     return 3+(int)bits;
   }
-  theora_read(_opb,2,&bits);
+  theorapackB_read(_opb,2,&bits);
   if((bits&2)==0)return 5+(int)bits;
   else if((bits&1)==0){
-    theora_read(_opb,2,&bits);
+    theorapackB_read(_opb,2,&bits);
     return 7+(int)bits;
   }
-  theora_read(_opb,3,&bits);
+  theorapackB_read(_opb,3,&bits);
   if((bits&4)==0)return 11+bits;
-  theora_read(_opb,2,&bits2);
+  theorapackB_read(_opb,2,&bits2);
   return 15+((bits&3)<<2)+bits2;
 }
 
@@ -277,27 +213,27 @@
   TH_DEBUG("\n>>>> beginning frame %ld\n\n",dframe);
 
   /*Check to make sure this is a data packet.*/
-  theora_read1(&_dec->opb,&val);
+  theorapackB_read1(&_dec->opb,&val);
   TH_DEBUG("frame type = %s, ",val==0?"video":"unknown");
   if(val!=0)return TH_EBADPACKET;
   /*Read in the frame type (I or P).*/
-  theora_read1(&_dec->opb,&val);
+  theorapackB_read1(&_dec->opb,&val);
   _dec->state.frame_type=(int)val;
   TH_DEBUG("%s\n",val?"predicted":"key");
   /*Read in the current qi.*/
-  theora_read(&_dec->opb,6,&val);
+  theorapackB_read(&_dec->opb,6,&val);
   _dec->state.qis[0]=(int)val;
   TH_DEBUG("frame quality = { %ld ",val);
-  theora_read1(&_dec->opb,&val);
+  theorapackB_read1(&_dec->opb,&val);
   if(!val)_dec->state.nqis=1;
   else{
-    theora_read(&_dec->opb,6,&val);
+    theorapackB_read(&_dec->opb,6,&val);
     _dec->state.qis[1]=(int)val;
     TH_DEBUG("%ld ",val);
-    theora_read1(&_dec->opb,&val);
+    theorapackB_read1(&_dec->opb,&val);
     if(!val)_dec->state.nqis=2;
     else{
-      theora_read(&_dec->opb,6,&val);
+      theorapackB_read(&_dec->opb,6,&val);
       TH_DEBUG("%ld ",val);
       _dec->state.qis[2]=(int)val;
       _dec->state.nqis=3;
@@ -310,7 +246,7 @@
       Most of the other unused bits in the VP3 headers were eliminated.
       I don't know why these remain.*/
     /* I wanted to eliminate wasted bits, but not all config wiggle room --Monty */
-    theora_read(&_dec->opb,3,&val);
+    theorapackB_read(&_dec->opb,3,&val);
     if(val!=0)return TH_EIMPL;
   }
   return 0;
@@ -366,7 +302,7 @@
   int    flag;
   int    npartial;
   int    run_count;
-  theora_read1(&_dec->opb,&val);
+  theorapackB_read1(&_dec->opb,&val);
   flag=(int)val;
 
   sb=_dec->state.sbs;
@@ -385,7 +321,7 @@
 
     while(--run_count>0&&sb<sb_end);
     if(full_run&&sb<sb_end){
-      theora_read1(&_dec->opb,&val);
+      theorapackB_read1(&_dec->opb,&val);
       flag=(int)val;
     }
     else flag=!flag;
@@ -410,7 +346,7 @@
   sb_end=sb+_dec->state.nsbs;
   /*Skip partially coded super blocks.*/
   for(;sb->coded_partially;sb++);
-  theora_read1(&_dec->opb,&val);
+  theorapackB_read1(&_dec->opb,&val);
   flag=(int)val;
 
   while(sb<sb_end){
@@ -423,7 +359,7 @@
       sb->coded_fully=flag;
     }
     if(full_run&&sb<sb_end){
-      theora_read1(&_dec->opb,&val);
+      theorapackB_read1(&_dec->opb,&val);
       flag=(int)val;
     }
     else flag=!flag;
@@ -447,7 +383,7 @@
   npartial=oc_dec_partial_sb_flags_unpack(_dec);
   if(npartial<_dec->state.nsbs)oc_dec_coded_sb_flags_unpack(_dec);
   if(npartial>0){
-    theora_read1(&_dec->opb,&val);
+    theorapackB_read1(&_dec->opb,&val);
     flag=!(int)val;
   }
   else flag=0;
@@ -566,7 +502,7 @@
   long val;
   int  i;
   for(i=0;i<7;i++){
-    theora_read1(_opb,&val);
+    theorapackB_read1(_opb,&val);
     if(!val)break;
   }
   return i;
@@ -574,7 +510,7 @@
 
 static int oc_clc_mode_unpack(oggpack_buffer *_opb){
   long val;
-  theora_read(_opb,3,&val);
+  theorapackB_read(_opb,3,&val);
   return (int)val;
 }
 
@@ -587,7 +523,7 @@
   long                 val,j;
   int                  scheme0_alphabet[8];
   int                  mode_scheme;
-  theora_read(&_dec->opb,3,&val);
+  theorapackB_read(&_dec->opb,3,&val);
   mode_scheme=(int)val;
   TH_DEBUG("mode encode scheme = %d\n",(int)val);
 
@@ -601,7 +537,7 @@
     /*LOOP VECTORIZES.*/
     for(mi=0;mi<OC_NMODES;mi++)scheme0_alphabet[mi]=OC_MODE_INTER_NOMV;
     for(mi=0;mi<OC_NMODES;mi++){
-      theora_read(&_dec->opb,3,&val);
+      theorapackB_read(&_dec->opb,3,&val);
       scheme0_alphabet[val]=OC_MODE_ALPHABETS[6][mi];
       TH_DEBUG("%d ",(int)val);
     }
@@ -649,7 +585,7 @@
 static int oc_vlc_mv_comp_unpack(oggpack_buffer *_opb){
   long bits;
   int  mvsigned[2];
-  theora_read(_opb,3,&bits);
+  theorapackB_read(_opb,3,&bits);
   switch(bits){
     case  0:return 0;
     case  1:return 1;
@@ -657,14 +593,14 @@
     case  3:
     case  4:{
       mvsigned[0]=(int)(bits-1);
-      theora_read1(_opb,&bits);
+      theorapackB_read1(_opb,&bits);
     }break;
     /*case  5:
     case  6:
     case  7:*/
     default:{
       mvsigned[0]=1<<bits-3;
-      theora_read(_opb,bits-2,&bits);
+      theorapackB_read(_opb,bits-2,&bits);
       mvsigned[0]+=(int)(bits>>1);
       bits&=1;
     }break;
@@ -676,7 +612,7 @@
 static int oc_clc_mv_comp_unpack(oggpack_buffer *_opb){
   long bits;
   int  mvsigned[2];
-  theora_read(_opb,6,&bits);
+  theorapackB_read(_opb,6,&bits);
   mvsigned[0]=bits>>1;
   mvsigned[1]=-mvsigned[0];
   return mvsigned[bits&1];
@@ -698,7 +634,7 @@
   oc_mv                   last_mv[2];
   oc_mv                   cbmvs[4];
   set_chroma_mvs=OC_SET_CHROMA_MVS_TABLE[_dec->state.info.pixel_fmt];
-  theora_read1(&_dec->opb,&val);
+  theorapackB_read1(&_dec->opb,&val);
   TH_DEBUG("motion vector table = %d\n",(int)val);
   mv_comp_unpack=val?oc_clc_mv_comp_unpack:oc_vlc_mv_comp_unpack;
   map_idxs=OC_MB_MAP_IDXS[_dec->state.info.pixel_fmt];
@@ -871,7 +807,7 @@
      At first we just store the qii in the fragment.
      After all the qii's are decoded, we make a final pass to replace them
       with the corresponding qi's for this frame.*/
-    theora_read1(&_dec->opb,&val);
+    theorapackB_read1(&_dec->opb,&val);
     flag=(int)val;
     run_count=nqi0=0;
     while(coded_fragi<coded_fragi_end){
@@ -884,7 +820,7 @@
       }
       while(--run_count>0&&coded_fragi<coded_fragi_end);
       if(full_run&&coded_fragi<coded_fragi_end){
-        theora_read1(&_dec->opb,&val);
+        theorapackB_read1(&_dec->opb,&val);
         flag=(int)val;
       }
       else flag=!flag;
@@ -897,7 +833,7 @@
       /*Skip qii==0 fragments.*/
       for(coded_fragi=_dec->state.coded_fragis;
        _dec->state.frags[*coded_fragi].qi==0;coded_fragi++);
-      theora_read1(&_dec->opb,&val);
+      theorapackB_read1(&_dec->opb,&val);
       flag=(int)val;
       while(coded_fragi<coded_fragi_end){
         int full_run;
@@ -911,7 +847,7 @@
           frag->qi+=flag;
         }
         if(full_run&&coded_fragi<coded_fragi_end){
-          theora_read1(&_dec->opb,&val);
+          theorapackB_read1(&_dec->opb,&val);
           flag=(int)val;
         }
         else flag=!flag;
@@ -1064,7 +1000,7 @@
       _dec->dct_tokens[0][ti++]=(unsigned char)token;
       neb=OC_DCT_TOKEN_EXTRA_BITS[token];
       if(neb){
-        theora_read(&_dec->opb,neb,&val);
+        theorapackB_read(&_dec->opb,neb,&val);
         eb=(int)val;
         _dec->extra_bits[0][ebi++]=(ogg_uint16_t)eb;
       }
@@ -1136,7 +1072,7 @@
       _dec->dct_tokens[_zzi][ti++]=(unsigned char)token;
       neb=OC_DCT_TOKEN_EXTRA_BITS[token];
       if(neb){
-        theora_read(&_dec->opb,neb,&val);
+        theorapackB_read(&_dec->opb,neb,&val);
         eb=(int)val;
         _dec->extra_bits[_zzi][ebi++]=(ogg_uint16_t)eb;
       }
@@ -1204,17 +1140,17 @@
   for(pli=0;pli<3;pli++)for(zzi=0;zzi<64;zzi++){
     ntoks_left[pli][zzi]=_dec->state.ncoded_fragis[pli];
   }
-  theora_read(&_dec->opb,4,&val);
+  theorapackB_read(&_dec->opb,4,&val);
   huffi_y=(int)val;
-  theora_read(&_dec->opb,4,&val);
+  theorapackB_read(&_dec->opb,4,&val);
   huffi_c=(int)val;
   huff_idxs[0]=huffi_y;
   huff_idxs[1]=huff_idxs[2]=huffi_c;
   _dec->eob_runs[0][0]=0;
   eobs=oc_dec_dc_coeff_unpack(_dec,huff_idxs,ntoks_left);
-  theora_read(&_dec->opb,4,&val);
+  theorapackB_read(&_dec->opb,4,&val);
   huffi_y=(int)val;
-  theora_read(&_dec->opb,4,&val);
+  theorapackB_read(&_dec->opb,4,&val);
   huffi_c=(int)val;
   zzi=1;
   for(hgi=1;hgi<5;hgi++){
@@ -2111,7 +2047,7 @@
     int                   pli;
     int                   notstart;
     int                   notdone;
-    oggpackB_readinit(&_dec->opb,_op->packet,_op->bytes);
+    theorapackB_readinit(&_dec->opb,_op->packet,_op->bytes);
     ret=oc_dec_frame_header_unpack(_dec);
     if(ret<0)return ret;
     /*Select a free buffer to use for the reconstructed version of this

Modified: trunk/theora/lib/dec/dequant.c
===================================================================
--- trunk/theora/lib/dec/dequant.c	2008-01-05 23:01:51 UTC (rev 14368)
+++ trunk/theora/lib/dec/dequant.c	2008-01-05 23:15:32 UTC (rev 14369)
@@ -36,30 +36,30 @@
   int            qri;
   int            qi;
   int            i;
-  theora_read(_opb,3,&val);
+  theorapackB_read(_opb,3,&val);
   nbits=(int)val;
   for(qi=0;qi<64;qi++){
-    theora_read(_opb,nbits,&val);
+    theorapackB_read(_opb,nbits,&val);
     _qinfo->loop_filter_limits[qi]=(unsigned char)val;
   }
-  theora_read(_opb,4,&val);
+  theorapackB_read(_opb,4,&val);
   nbits=(int)val+1;
   for(qi=0;qi<64;qi++){
-    theora_read(_opb,nbits,&val);
+    theorapackB_read(_opb,nbits,&val);
     _qinfo->ac_scale[qi]=(ogg_uint16_t)val;
   }
-  theora_read(_opb,4,&val);
+  theorapackB_read(_opb,4,&val);
   nbits=(int)val+1;
   for(qi=0;qi<64;qi++){
-    theora_read(_opb,nbits,&val);
+    theorapackB_read(_opb,nbits,&val);
     _qinfo->dc_scale[qi]=(ogg_uint16_t)val;
   }
-  theora_read(_opb,9,&val);
+  theorapackB_read(_opb,9,&val);
   nbase_mats=(int)val+1;
   base_mats=_ogg_malloc(nbase_mats*sizeof(base_mats[0]));
   for(bmi=0;bmi<nbase_mats;bmi++){
     for(ci=0;ci<64;ci++){
-      theora_read(_opb,8,&val);
+      theorapackB_read(_opb,8,&val);
       base_mats[bmi][ci]=(unsigned char)val;
     }
   }
@@ -72,12 +72,12 @@
     pli=i%3;
     qranges=_qinfo->qi_ranges[qti]+pli;
     if(i>0){
-      theora_read1(_opb,&val);
+      theorapackB_read1(_opb,&val);
       if(!val){
         int qtj;
         int plj;
         if(qti>0){
-          theora_read1(_opb,&val);
+          theorapackB_read1(_opb,&val);
           if(val){
             qtj=qti-1;
             plj=pli;
@@ -95,13 +95,13 @@
         continue;
       }
     }
-    theora_read(_opb,nbits,&val);
+    theorapackB_read(_opb,nbits,&val);
     indices[0]=(int)val;
     for(qi=qri=0;qi<63;){
-      theora_read(_opb,oc_ilog(62-qi),&val);
+      theorapackB_read(_opb,oc_ilog(62-qi),&val);
       sizes[qri]=(int)val+1;
       qi+=(int)val+1;
-      theora_read(_opb,nbits,&val);
+      theorapackB_read(_opb,nbits,&val);
       indices[++qri]=(int)val;
     }
     /*Note: The caller is responsible for cleaning up any partially

Modified: trunk/theora/lib/dec/huffdec.c
===================================================================
--- trunk/theora/lib/dec/huffdec.c	2008-01-05 23:01:51 UTC (rev 14368)
+++ trunk/theora/lib/dec/huffdec.c	2008-01-05 23:15:32 UTC (rev 14369)
@@ -96,7 +96,7 @@
   long          bits;
   /*Prevent infinite recursion.*/
   if(++_depth>32)return TH_EBADHEADER;
-  if(theora_read1(_opb,&bits)<0)return TH_EBADHEADER;
+  if(theorapackB_read1(_opb,&bits)<0)return TH_EBADHEADER;
   /*Read an internal node:*/
   if(!bits){
     int ret;
@@ -111,7 +111,7 @@
   }
   /*Read a leaf node:*/
   else{
-    if(theora_read(_opb,OC_NDCT_TOKEN_BITS,&bits)<0)return TH_EBADHEADER;
+    if(theorapackB_read(_opb,OC_NDCT_TOKEN_BITS,&bits)<0)return TH_EBADHEADER;
     binode=oc_huff_node_alloc(0);
     binode->depth=(unsigned char)(_depth>1);
     binode->token=(unsigned char)bits;
@@ -270,9 +270,9 @@
 int oc_huff_token_decode(oggpack_buffer *_opb,const oc_huff_node *_node){
   long bits;
   while(_node->nbits!=0){
-    theora_look(_opb,_node->nbits,&bits);
+    theorapackB_look(_opb,_node->nbits,&bits);
     _node=_node->nodes[bits];
-    oggpackB_adv(_opb,_node->depth);
+    theorapackB_adv(_opb,_node->depth);
   }
   return _node->token;
 }



More information about the commits mailing list