[xiph-cvs] cvs commit: theora/lib decode.c encode.c encoder_internal.h frarray.c huffman.c pb.c toplevel.c
Arc
arc at xiph.org
Sat Dec 6 10:06:20 PST 2003
arc 03/12/06 13:06:20
Modified: include/theora theora.h
lib decode.c encode.c encoder_internal.h frarray.c
huffman.c pb.c toplevel.c
Log:
Continued work to add libogg2 support...
I believe that only the examples need additional work
Revision Changes Path
1.17 +3 -1 theora/include/theora/theora.h
Index: theora.h
===================================================================
RCS file: /usr/local/cvsroot/theora/include/theora/theora.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- theora.h 3 Dec 2003 08:59:47 -0000 1.16
+++ theora.h 6 Dec 2003 18:06:19 -0000 1.17
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: theora.h,v 1.16 2003/12/03 08:59:47 arc Exp $
+ last mod: $Id: theora.h,v 1.17 2003/12/06 18:06:19 arc Exp $
********************************************************************/
@@ -22,6 +22,8 @@
#include <ogg/ogg.h>
#else
#include <ogg2/ogg.h>
+/* This is temporary until libogg2 is more complete */
+ogg_buffer_state *ogg_buffer_create(void);
#endif
typedef struct {
<p><p>1.10 +41 -32 theora/lib/decode.c
Index: decode.c
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/decode.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- decode.c 3 Dec 2003 08:59:39 -0000 1.9
+++ decode.c 6 Dec 2003 18:06:20 -0000 1.10
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: decode.c,v 1.9 2003/12/03 08:59:39 arc Exp $
+ last mod: $Id: decode.c,v 1.10 2003/12/06 18:06:20 arc Exp $
********************************************************************/
@@ -65,23 +65,23 @@
unsigned char SpareBits; /* Spare cfg bits */
/* Is the frame and inter frame or a key frame */
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->FrameType = (unsigned char)ret;
/* Quality (Q) index */
- theora_read(&pbi->opb,6,&ret);
+ theora_read(pbi->opb,6,&ret);
DctQMask = (unsigned char)ret;
/* spare bit for possible additional Q indicies - should be 0 */
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
SpareBits = (unsigned char)ret;
if ( (pbi->FrameType == BASE_FRAME) ){
/* Read the type / coding method for the key frame. */
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->KeyFrameType = (unsigned char)ret;
- theora_read(&pbi->opb,2,&ret);
+ theora_read(pbi->opb,2,&ret);
SpareBits = (unsigned char)ret;
}
@@ -150,14 +150,15 @@
const CODING_MODE *ModeList;
/* Read the coding method */
- theora_read(&pbi->opb, MODE_METHOD_BITS, &CodingScheme);
+ theora_read(pbi->opb, MODE_METHOD_BITS, &ret);
+ CodingScheme=ret;
/* If the coding method is method 0 then we have to read in a
custom coding scheme */
if ( CodingScheme == 0 ){
/* Read the coding scheme. */
for ( i = 0; i < MAX_MODES; i++ ){
- theora_read(&pbi->opb, MODE_BITS, &ret);
+ theora_read(pbi->opb, MODE_BITS, &ret);
CustomModeAlphabet[ret]=i;
}
ModeList=CustomModeAlphabet;
@@ -183,7 +184,7 @@
if ( CodingScheme == (MODE_METHODS-1) ){
/* This is the fall back coding scheme. */
/* Simply MODE_BITS bits per mode entry. */
- theora_read(&pbi->opb, MODE_BITS, &ret);
+ theora_read(pbi->opb, MODE_BITS, &ret);
CodingMethod = (CODING_MODE)ret;
}else{
ModeEntry = FrArrayUnpackMode(pbi);
@@ -226,7 +227,8 @@
ogg_uint32_t ExtraBits = 0;
/* Get group to which coded component belongs */
- theora_read(&pbi->opb, 3, &MVCode);
+ theora_read(pbi->opb, 3, &ret);
+ MVCode=ret;
/* Now extract the appropriate number of bits to identify the component */
switch ( MVCode ){
@@ -240,37 +242,40 @@
MVectComponent = -1;
break;
case 3:
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
if (ret)
MVectComponent = -2;
else
MVectComponent = 2;
break;
case 4:
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
if (ret)
MVectComponent = -3;
else
MVectComponent = 3;
break;
case 5:
- theora_read(&pbi->opb,2,&ExtraBits);
+ theora_read(pbi->opb,2,&ret);
+ ExtraBits=ret;
MVectComponent = 4 + ExtraBits;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
if (ret)
MVectComponent = -MVectComponent;
break;
case 6:
- theora_read(&pbi->opb,3,&ExtraBits);
+ theora_read(pbi->opb,3,&ret);
+ ExtraBits=ret;
MVectComponent = 8 + ExtraBits;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
if (ret)
MVectComponent = -MVectComponent;
break;
case 7:
- theora_read(&pbi->opb,4,&ExtraBits);
+ theora_read(pbi->opb,4,&ret);
+ ExtraBits=ret;
MVectComponent = 16 + ExtraBits;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
if (ret)
MVectComponent = -MVectComponent;
break;
@@ -284,8 +289,9 @@
ogg_int32_t MVectComponent;
/* Get group to which coded component belongs */
- theora_read(&pbi->opb,5,&MVectComponent);
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,5,&ret);
+ MVectComponent=ret;
+ theora_read(pbi->opb,1,&ret);
if (ret)
MVectComponent = -MVectComponent;
@@ -329,7 +335,7 @@
PriorLastInterMV.y = 0;
/* Read the entropy method used and set up the appropriate decode option */
- theora_read(&pbi->opb, 1, &ret);
+ theora_read(pbi->opb, 1, &ret);
if ( ret == 0 )
ExtractMVectorComponent = ExtractMVectorComponentA;
else
@@ -512,10 +518,11 @@
static void UnpackAndExpandDcToken( PB_INSTANCE *pbi,
Q_LIST_ENTRY *ExpandedBlock,
unsigned char * CoeffIndex ){
- ogg_int32_t ExtraBits;
+ long ret;
+ ogg_int32_t ExtraBits = 0;
ogg_uint32_t Token;
- Token = ExtractToken(&pbi->opb, pbi->HuffRoot_VP3x[pbi->DcHuffChoice]);
+ Token = ExtractToken(pbi->opb, pbi->HuffRoot_VP3x[pbi->DcHuffChoice]);
/* Now.. if we are using the DCT optimised coding system, extract any
@@ -523,8 +530,8 @@
*/
if ( pbi->ExtraBitLengths_VP3x[Token] > 0 ){
/* Extract the appropriate number of extra bits. */
- theora_read(&pbi->opb,pbi->ExtraBitLengths_VP3x[Token], &ExtraBits);
-
+ theora_read(pbi->opb,pbi->ExtraBitLengths_VP3x[Token], &ret);
+ ExtraBits = ret;
}
/* Take token dependant action */
@@ -576,17 +583,19 @@
static void UnpackAndExpandAcToken( PB_INSTANCE *pbi,
Q_LIST_ENTRY * ExpandedBlock,
unsigned char * CoeffIndex ) {
- ogg_int32_t ExtraBits;
+ long ret;
+ ogg_int32_t ExtraBits = 0;
ogg_uint32_t Token;
- Token = ExtractToken(&pbi->opb, pbi->HuffRoot_VP3x[pbi->ACHuffChoice]);
+ Token = ExtractToken(pbi->opb, pbi->HuffRoot_VP3x[pbi->ACHuffChoice]);
/* Now.. if we are using the DCT optimised coding system, extract any
* assosciated additional bits token.
*/
if ( pbi->ExtraBitLengths_VP3x[Token] > 0 ){
/* Extract the appropriate number of extra bits. */
- theora_read(&pbi->opb,pbi->ExtraBitLengths_VP3x[Token], &ExtraBits);
+ theora_read(pbi->opb,pbi->ExtraBitLengths_VP3x[Token], &ret);
+ ExtraBits = ret;
}
/* Take token dependant action */
@@ -666,9 +675,9 @@
pbi->BlocksToDecode = pbi->CodedBlockIndex;
/* Get the DC huffman table choice for Y and then UV */
- theora_read(&pbi->opb,DC_HUFF_CHOICE_BITS,&ret);
+ theora_read(pbi->opb,DC_HUFF_CHOICE_BITS,&ret);
DcHuffChoice1 = ret + DC_HUFF_OFFSET;
- theora_read(&pbi->opb,DC_HUFF_CHOICE_BITS,&ret);
+ theora_read(pbi->opb,DC_HUFF_CHOICE_BITS,&ret);
DcHuffChoice2 = ret + DC_HUFF_OFFSET;
/* UnPack DC coefficients / tokens */
@@ -704,9 +713,9 @@
/* Get the AC huffman table choice for Y and then for UV. */
- theora_read(&pbi->opb,AC_HUFF_CHOICE_BITS,&ret);
+ theora_read(pbi->opb,AC_HUFF_CHOICE_BITS,&ret);
AcHuffIndex1 = ret + AC_HUFF_OFFSET;
- theora_read(&pbi->opb,AC_HUFF_CHOICE_BITS,&ret);
+ theora_read(pbi->opb,AC_HUFF_CHOICE_BITS,&ret);
AcHuffIndex2 = ret + AC_HUFF_OFFSET;
/* Unpack Lower AC coefficients. */
<p><p>1.16 +16 -13 theora/lib/encode.c
Index: encode.c
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/encode.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- encode.c 3 Dec 2003 08:59:40 -0000 1.15
+++ encode.c 6 Dec 2003 18:06:20 -0000 1.16
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: encode.c,v 1.15 2003/12/03 08:59:40 arc Exp $
+ last mod: $Id: encode.c,v 1.16 2003/12/06 18:06:20 arc Exp $
********************************************************************/
@@ -112,7 +112,7 @@
ogg_uint32_t DcHuffChoice[2];
ogg_uint32_t EntropyTableBits[2][DC_HUFF_CHOICES];
- oggpack_buffer *opb=&cpi->oggbuffer;
+ oggpack_buffer *opb=cpi->oggbuffer;
/* Clear table data structure */
memset ( EntropyTableBits, 0, sizeof(ogg_uint32_t)*DC_HUFF_CHOICES*2 );
@@ -195,7 +195,7 @@
ogg_uint32_t AcHuffChoice[2];
ogg_uint32_t EntropyTableBits[2][AC_HUFF_CHOICES];
- oggpack_buffer *opb=&cpi->oggbuffer;
+ oggpack_buffer *opb=cpi->oggbuffer;
memset ( EntropyTableBits, 0, sizeof(ogg_uint32_t)*AC_HUFF_CHOICES*2 );
@@ -272,14 +272,14 @@
unsigned char BestModeSchemes[MAX_MODES];
ogg_int32_t ModeCount[MAX_MODES];
- ogg_int32_t TmpFreq;
- ogg_int32_t TmpIndex;
+ ogg_int32_t TmpFreq = -1;
+ ogg_int32_t TmpIndex = -1;
ogg_uint32_t BestScheme;
ogg_uint32_t BestSchemeScore;
ogg_uint32_t SchemeScore;
- oggpack_buffer *opb=&cpi->oggbuffer;
+ oggpack_buffer *opb=cpi->oggbuffer;
/* Build a frequency map for the modes in this frame */
memset( ModeCount, 0, MAX_MODES*sizeof(ogg_int32_t) );
@@ -290,7 +290,6 @@
scheme 0 */
for ( j = 0; j < MAX_MODES; j++ ) {
/* Find the most frequent */
- TmpFreq = -1;
for ( i = 0; i < MAX_MODES; i++ ) {
/* Is this the best scheme so far ??? */
if ( ModeCount[i] > TmpFreq ) {
@@ -298,8 +297,12 @@
TmpIndex = i;
}
}
- ModeCount[TmpIndex] = -1;
- BestModeSchemes[TmpIndex] = (unsigned char)j;
+ /* I don't know if the above loop ever fails to match, but it's
+ better safe than sorry. Plus this takes care of gcc warning */
+ if ( TmpIndex != -1 ) {
+ ModeCount[TmpIndex] = -1;
+ BestModeSchemes[TmpIndex] = (unsigned char)j;
+ }
}
/* Default/ fallback scheme uses MODE_BITS bits per mode entry */
@@ -368,7 +371,7 @@
ogg_uint32_t * MvBitsPtr;
ogg_uint32_t * MvPatternPtr;
- oggpack_buffer *opb=&cpi->oggbuffer;
+ oggpack_buffer *opb=cpi->oggbuffer;
/* Choose the coding method */
MvBitsPtr = &MvBits[MAX_MV_EXTENT];
@@ -594,7 +597,7 @@
}
/* Note the number of bits used to code the tree itself. */
- cpi->FrameBitCount = oggpackB_bytes(&cpi->oggbuffer) << 3;
+ cpi->FrameBitCount = oggpackB_bytes(cpi->oggbuffer) << 3;
/* Mode and MV data not needed for key frames. */
if ( GetFrameType(&cpi->pb) != BASE_FRAME ){
@@ -604,7 +607,7 @@
PackMotionVectors (cpi);
}
- cpi->FrameBitCount = oggpackB_bytes(&cpi->oggbuffer) << 3;
+ cpi->FrameBitCount = oggpackB_bytes(cpi->oggbuffer) << 3;
/* Optimise the DC tokens */
for ( i = 0; i < cpi->pb.CodedBlockIndex; i++ ) {
@@ -1453,7 +1456,7 @@
void WriteFrameHeader( CP_INSTANCE *cpi) {
ogg_uint32_t i;
- oggpack_buffer *opb=&cpi->oggbuffer;
+ oggpack_buffer *opb=cpi->oggbuffer;
/* Output the frame type (base/key frame or inter frame) */
oggpackB_write( opb, cpi->pb.FrameType, 1 );
<p><p>1.17 +8 -5 theora/lib/encoder_internal.h
Index: encoder_internal.h
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/encoder_internal.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- encoder_internal.h 3 Dec 2003 08:59:42 -0000 1.16
+++ encoder_internal.h 6 Dec 2003 18:06:20 -0000 1.17
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: encoder_internal.h,v 1.16 2003/12/03 08:59:42 arc Exp $
+ last mod: $Id: encoder_internal.h,v 1.17 2003/12/06 18:06:20 arc Exp $
********************************************************************/
@@ -257,10 +257,10 @@
} codec_setup_info;
typedef struct PB_INSTANCE {
- oggpack_buffer opb;
- theora_info info;
+ oggpack_buffer *opb;
+ theora_info info;
/* how far do we shift the granulepos to seperate out P frame counts? */
- int keyframe_granule_shift;
+ int keyframe_granule_shift;
/***********************************************************************/
@@ -646,7 +646,10 @@
PB_INSTANCE pb; /* playback */
/* ogg bitpacker for use in packet coding, other API state */
- oggpack_buffer oggbuffer;
+ oggpack_buffer *oggbuffer;
+#ifdef LIBOGG2 /* Remember, this is just until we drop libogg1 */
+ ogg_buffer_state *oggbufferstate;
+#endif
int readyflag;
int packetflag;
int doneflag;
<p><p>1.10 +20 -20 theora/lib/frarray.c
Index: frarray.c
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/frarray.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- frarray.c 4 Dec 2003 05:58:31 -0000 1.9
+++ frarray.c 6 Dec 2003 18:06:20 -0000 1.10
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: frarray.c,v 1.9 2003/12/04 05:58:31 arc Exp $
+ last mod: $Id: frarray.c,v 1.10 2003/12/06 18:06:20 arc Exp $
********************************************************************/
@@ -57,7 +57,7 @@
}
/* Add the bits to the encode holding buffer. */
- oggpackB_write( &cpi->oggbuffer, CodedVal, (ogg_uint32_t)CodedBits );
+ oggpackB_write( cpi->oggbuffer, CodedVal, (ogg_uint32_t)CodedBits );
return CodedBits;
}
@@ -100,7 +100,7 @@
}
/* Add the bits to the encode holding buffer. */
- oggpackB_write( &cpi->oggbuffer, CodedVal, (ogg_uint32_t)CodedBits );
+ oggpackB_write( cpi->oggbuffer, CodedVal, (ogg_uint32_t)CodedBits );
return CodedBits;
}
@@ -160,7 +160,7 @@
/* Code list of partially coded Super-Block. */
val = cpi->PartiallyCodedFlags[0];
- oggpackB_write( &cpi->oggbuffer, (ogg_uint32_t)val, 1);
+ oggpackB_write( cpi->oggbuffer, (ogg_uint32_t)val, 1);
i = 0;
while ( i < cpi->pb.SuperBlocks ) {
run_count = 0;
@@ -183,7 +183,7 @@
if ( i < cpi->pb.SuperBlocks ) {
val = cpi->pb.SBFullyFlags[i];
- oggpackB_write( &cpi->oggbuffer, (ogg_uint32_t)val, 1);
+ oggpackB_write( cpi->oggbuffer, (ogg_uint32_t)val, 1);
while ( i < cpi->pb.SuperBlocks ) {
run_count = 0;
@@ -205,7 +205,7 @@
if ( BListIndex > 0 ) {
/* Code the block flags start value */
val = cpi->BlockCodedFlags[0];
- oggpackB_write( &cpi->oggbuffer, (ogg_uint32_t)val, 1);
+ oggpackB_write( cpi->oggbuffer, (ogg_uint32_t)val, 1);
/* Now code the block flags. */
for ( i = 0; i < BListIndex; ) {
@@ -379,12 +379,12 @@
static void GetNextBInit(PB_INSTANCE *pbi){
long ret;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->NextBit = (unsigned char)ret;
/* Read run length */
FrArrayDeCodeInit(pbi);
- do theora_read(&pbi->opb,1,&ret);
+ do theora_read(pbi->opb,1,&ret);
while (FrArrayDeCodeBlockRun(pbi,ret,&pbi->BitsLeft)==0);
}
@@ -397,7 +397,7 @@
/* Read next run */
FrArrayDeCodeInit(pbi);
- do theora_read(&pbi->opb,1,&ret);
+ do theora_read(pbi->opb,1,&ret);
while (FrArrayDeCodeBlockRun(pbi,ret,&pbi->BitsLeft)==0);
}
@@ -412,12 +412,12 @@
static void GetNextSbInit(PB_INSTANCE *pbi){
long ret;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->NextBit = (unsigned char)ret;
/* Read run length */
FrArrayDeCodeInit(pbi);
- do theora_read(&pbi->opb,1,&ret);
+ do theora_read(pbi->opb,1,&ret);
while (FrArrayDeCodeSBRun(pbi,ret,&pbi->BitsLeft)==0);
}
@@ -431,7 +431,7 @@
/* Read next run */
FrArrayDeCodeInit(pbi);
- do theora_read(&pbi->opb,1,&ret);
+ do theora_read(pbi->opb,1,&ret);
while (FrArrayDeCodeSBRun(pbi,ret,&pbi->BitsLeft)==0);
}
@@ -557,52 +557,52 @@
*/
/* Initialise the decoding. */
- pbi->bit_pattern = 0;
pbi->bits_so_far = 0;
- theora_read(&pbi->opb,1,&pbi->bit_pattern);
+ theora_read(pbi->opb,1,&ret);
+ pbi->bit_pattern = ret;
/* Do we have a match */
if ( pbi->bit_pattern == 0 )
return (CODING_MODE)0;
/* Get the next bit */
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
/* Do we have a match */
if ( pbi->bit_pattern == 0x0002 )
return (CODING_MODE)1;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
/* Do we have a match */
if ( pbi->bit_pattern == 0x0006 )
return (CODING_MODE)2;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
/* Do we have a match */
if ( pbi->bit_pattern == 0x000E )
return (CODING_MODE)3;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
/* Do we have a match */
if ( pbi->bit_pattern == 0x001E )
return (CODING_MODE)4;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
/* Do we have a match */
if ( pbi->bit_pattern == 0x003E )
return (CODING_MODE)5;
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
pbi->bit_pattern = (pbi->bit_pattern << 1) | ret;
/* Do we have a match */
<p><p>1.12 +4 -2 theora/lib/huffman.c
Index: huffman.c
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/huffman.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- huffman.c 3 Dec 2003 08:59:41 -0000 1.11
+++ huffman.c 6 Dec 2003 18:06:20 -0000 1.12
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: huffman.c,v 1.11 2003/12/03 08:59:41 arc Exp $
+ last mod: $Id: huffman.c,v 1.12 2003/12/06 18:06:20 arc Exp $
********************************************************************/
@@ -225,6 +225,7 @@
static int ReadHuffTree(HUFF_ENTRY * HuffRoot, int depth,
oggpack_buffer *opb) {
long bit;
+ long ret;
theora_read(opb,1,&bit);
if(bit < 0) return OC_BADHEADER;
else if(!bit) {
@@ -240,7 +241,8 @@
} else {
HuffRoot->ZeroChild = NULL;
HuffRoot->OneChild = NULL;
- theora_read(opb,5,&HuffRoot->Value);
+ theora_read(opb,5,&ret);
+ HuffRoot->Value=ret;;
if (HuffRoot->Value < 0) return OC_BADHEADER;
}
return 0;
<p><p>1.7 +11 -1 theora/lib/pb.c
Index: pb.c
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/pb.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- pb.c 3 Dec 2003 08:59:41 -0000 1.6
+++ pb.c 6 Dec 2003 18:06:20 -0000 1.7
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: pb.c,v 1.6 2003/12/03 08:59:41 arc Exp $
+ last mod: $Id: pb.c,v 1.7 2003/12/06 18:06:20 arc Exp $
********************************************************************/
@@ -85,6 +85,9 @@
void ClearPBInstance(PB_INSTANCE *pbi){
if(pbi){
ClearTmpBuffers(pbi);
+ if (pbi->opb) {
+ _ogg_free(pbi->opb);
+ }
}
}
@@ -94,6 +97,13 @@
InitTmpBuffers(pbi);
+ /* allocate memory for the oggpack_buffer */
+#ifndef LIBOGG2
+ pbi->opb = _ogg_malloc(sizeof(oggpack_buffer));
+#else
+ pbi->opb = _ogg_malloc(oggpack_buffersize());
+#endif
+
/* variables needing initialization (not being set to 0) */
pbi->ModifierPointer[0] = &pbi->Modifier[0][255];
<p><p>1.35 +171 -102 theora/lib/toplevel.c
Index: toplevel.c
===================================================================
RCS file: /usr/local/cvsroot/theora/lib/toplevel.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- toplevel.c 3 Dec 2003 08:59:42 -0000 1.34
+++ toplevel.c 6 Dec 2003 18:06:20 -0000 1.35
@@ -11,7 +11,7 @@
********************************************************************
function:
- last mod: $Id: toplevel.c,v 1.34 2003/12/03 08:59:42 arc Exp $
+ last mod: $Id: toplevel.c,v 1.35 2003/12/06 18:06:20 arc Exp $
********************************************************************/
@@ -244,7 +244,7 @@
ogg_int32_t MinFrameTargetRate;
/* Update the frame carry over. */
- cpi->TotKeyFrameBytes += oggpackB_bytes(&cpi->oggbuffer);
+ cpi->TotKeyFrameBytes += oggpackB_bytes(cpi->oggbuffer);
/* reset keyframe context and calculate weighted average of last
KEY_FRAME_CONTEXT keyframes */
@@ -254,7 +254,7 @@
cpi->PriorKeyFrameDistance[i] = cpi->PriorKeyFrameDistance[i+1];
} else {
cpi->PriorKeyFrameSize[KEY_FRAME_CONTEXT - 1] =
- oggpackB_bytes(&cpi->oggbuffer);
+ oggpackB_bytes(cpi->oggbuffer);
cpi->PriorKeyFrameDistance[KEY_FRAME_CONTEXT - 1] =
cpi->LastKeyFrame;
}
@@ -293,7 +293,7 @@
}
cpi->LastKeyFrame = 1;
- cpi->LastKeyFrameSize=oggpackB_bytes(&cpi->oggbuffer);
+ cpi->LastKeyFrameSize=oggpackB_bytes(cpi->oggbuffer);
}
@@ -308,10 +308,13 @@
cpi->pb.InvLastInterDC = 0;
/* Initialise bit packing mechanism. */
- oggpackB_reset(&cpi->oggbuffer);
-
+#ifndef LIBOGG2
+ oggpackB_reset(cpi->oggbuffer);
+#else
+ oggpackB_writeinit(cpi->oggbuffer, cpi->oggbufferstate);
+#endif
/* mark as video frame */
- oggpackB_write(&cpi->oggbuffer,0,1);
+ oggpackB_write(cpi->oggbuffer,0,1);
/* Write out the frame header information including size. */
WriteFrameHeader(cpi);
@@ -328,7 +331,7 @@
/* Apply decay factor then add in the last frame size. */
cpi->DropFrameTriggerBytes =
((cpi->DropFrameTriggerBytes * (DF_CANDIDATE_WINDOW-1)) /
- DF_CANDIDATE_WINDOW) + oggpackB_bytes(&cpi->oggbuffer);
+ DF_CANDIDATE_WINDOW) + oggpackB_bytes(cpi->oggbuffer);
}else{
/* Increase cpi->DropFrameTriggerBytes a little. Just after a key
frame may actually be a good time to drop a frame. */
@@ -359,7 +362,7 @@
not we were close enough with our selection of DCT quantiser. */
if ( GetFrameType(&cpi->pb) != BASE_FRAME ) {
/* Work out a size correction factor. */
- CorrectionFactor = (double)oggpackB_bytes(&cpi->oggbuffer) /
+ CorrectionFactor = (double)oggpackB_bytes(cpi->oggbuffer) /
(double)cpi->ThisFrameTargetBytes;
if ( (CorrectionFactor > 1.05) &&
@@ -395,9 +398,9 @@
} else {
/* Update the frame carry over */
cpi->CarryOver += ((ogg_int32_t)cpi->frame_target_rate -
- (ogg_int32_t)oggpackB_bytes(&cpi->oggbuffer));
+ (ogg_int32_t)oggpackB_bytes(cpi->oggbuffer));
}
- cpi->TotalByteCount += oggpackB_bytes(&cpi->oggbuffer);
+ cpi->TotalByteCount += oggpackB_bytes(cpi->oggbuffer);
}
static void CompressFirstFrame(CP_INSTANCE *cpi) {
@@ -849,10 +852,14 @@
/* Set up an encode buffer */
#ifndef LIBOGG2
- oggpackB_writeinit(&cpi->oggbuffer);
+ cpi->oggbuffer = _ogg_malloc(sizeof(oggpack_buffer));
+ oggpackB_writeinit(cpi->oggbuffer);
#else
- oggpackB_writeinit(&cpi->oggbuffer, ogg_buffer_create());
+ cpi->oggbuffer = _ogg_malloc(oggpack_buffersize());
+ cpi->oggbufferstate = ogg_buffer_create();
+ oggpackB_writeinit(cpi->oggbuffer, cpi->oggbufferstate);
#endif
+
/* Set data rate related variables. */
cpi->Configuration.TargetBandwidth = (c->target_bitrate) / 8;
@@ -980,7 +987,7 @@
}
/* Update stats variables. */
- cpi->LastFrameSize = oggpackB_bytes(&cpi->oggbuffer);
+ cpi->LastFrameSize = oggpackB_bytes(cpi->oggbuffer);
cpi->CurrentFrame++;
cpi->packetflag=1;
@@ -993,16 +1000,16 @@
int theora_encode_packetout( theora_state *t, int last_p, ogg_packet *op){
CP_INSTANCE *cpi=(CP_INSTANCE *)(t->internal_encode);
- long bytes=oggpackB_bytes(&cpi->oggbuffer);
+ long bytes=oggpackB_bytes(cpi->oggbuffer);
if(!bytes)return(0);
if(!cpi->packetflag)return(0);
if(cpi->doneflag)return(-1);
#ifndef LIBOGG2
- op->packet=oggpackB_get_buffer(&cpi->oggbuffer);
+ op->packet=oggpackB_get_buffer(cpi->oggbuffer);
#else
- op->packet=oggpackB_writebuffer(&cpi->oggbuffer);
+ op->packet=oggpackB_writebuffer(cpi->oggbuffer);
#endif
op->bytes=bytes;
op->b_o_s=0;
@@ -1020,9 +1027,23 @@
static void _tp_readbuffer(oggpack_buffer *opb, char *buf, const long len)
{
long i;
+ long ret;
- for (i = 0; i < len; i++)
- *buf++=(char)oggpack_read(opb,8);
+ for (i = 0; i < len; i++) {
+ theora_read(opb, 8, &ret);
+ *buf++=(char)ret;
+ }
+}
+
+static void _tp_readlsbint(oggpack_buffer *opb, long *value)
+{
+ int i;
+ long ret[4];
+
+ for (i = 0; i < 4; i++) {
+ theora_read(opb,8,&ret[i]);
+ }
+ *value = ret[0]|ret[1]<<8|ret[2]<<16|ret[3]<<24;
}
static void _tp_writebuffer(oggpack_buffer *opb, const char *buf, const long len)
@@ -1030,47 +1051,59 @@
long i;
for (i = 0; i < len; i++)
- oggpack_write(opb, *buf++, 8);
+ oggpackB_write(opb, *buf++, 8);
+}
+
+static void _tp_writelsbint(oggpack_buffer *opb, long value)
+{
+ oggpackB_write(opb, value&0xFF, 8);
+ oggpackB_write(opb, value>>8&0xFF, 8);
+ oggpackB_write(opb, value>>16&0xFF, 8);
+ oggpackB_write(opb, value>>24&0xFF, 8);
}
/* build the initial short header for stream recognition and format */
int theora_encode_header(theora_state *t, ogg_packet *op){
CP_INSTANCE *cpi=(CP_INSTANCE *)(t->internal_encode);
- oggpackB_reset(&cpi->oggbuffer);
- oggpackB_write(&cpi->oggbuffer,0x80,8);
- _tp_writebuffer(&cpi->oggbuffer, "theora", 6);
-
- oggpackB_write(&cpi->oggbuffer,VERSION_MAJOR,8);
- oggpackB_write(&cpi->oggbuffer,VERSION_MINOR,8);
- oggpackB_write(&cpi->oggbuffer,VERSION_SUB,8);
-
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.width>>4,16);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.height>>4,16);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.frame_width,24);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.frame_height,24);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.offset_x,8);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.offset_y,8);
-
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.fps_numerator,32);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.fps_denominator,32);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.aspect_numerator,24);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.aspect_denominator,24);
-
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.colorspace,8);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.target_bitrate,24);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.info.quality,6);
+#ifndef LIBOGG2
+ oggpackB_reset(cpi->oggbuffer);
+#else
+ oggpackB_writeinit(cpi->oggbuffer, cpi->oggbufferstate);
+#endif
+ oggpackB_write(cpi->oggbuffer,0x80,8);
+ _tp_writebuffer(cpi->oggbuffer, "theora", 6);
+
+ oggpackB_write(cpi->oggbuffer,VERSION_MAJOR,8);
+ oggpackB_write(cpi->oggbuffer,VERSION_MINOR,8);
+ oggpackB_write(cpi->oggbuffer,VERSION_SUB,8);
+
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.width>>4,16);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.height>>4,16);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.frame_width,24);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.frame_height,24);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.offset_x,8);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.offset_y,8);
+
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.fps_numerator,32);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.fps_denominator,32);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.aspect_numerator,24);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.aspect_denominator,24);
+
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.colorspace,8);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.target_bitrate,24);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.info.quality,6);
- oggpackB_write(&cpi->oggbuffer,cpi->pb.keyframe_granule_shift,5);
+ oggpackB_write(cpi->oggbuffer,cpi->pb.keyframe_granule_shift,5);
- oggpackB_write(&cpi->oggbuffer,0,5); /* spare config bits */
+ oggpackB_write(cpi->oggbuffer,0,5); /* spare config bits */
#ifndef LIBOGG2
- op->packet=oggpackB_get_buffer(&cpi->oggbuffer);
+ op->packet=oggpackB_get_buffer(cpi->oggbuffer);
#else
- op->packet=oggpackB_writebuffer(&cpi->oggbuffer);
+ op->packet=oggpackB_writebuffer(cpi->oggbuffer);
#endif
- op->bytes=oggpackB_bytes(&cpi->oggbuffer);
+ op->bytes=oggpackB_bytes(cpi->oggbuffer);
op->b_o_s=1;
op->e_o_s=0;
@@ -1088,39 +1121,47 @@
{
const char *vendor = theora_version_string();
const int vendor_length = strlen(vendor);
- oggpack_buffer opb;
+ oggpack_buffer *opb;
- oggpack_writeinit(&opb);
- oggpack_write(&opb, 0x81, 8);
- _tp_writebuffer(&opb, "theora", 6);
+#ifndef LIBOGG2
+ opb = malloc(sizeof(oggpack_buffer));
+ oggpackB_writeinit(opb);
+#else
+ opb = malloc(oggpack_buffersize());
+ oggpackB_writeinit(opb, ogg_buffer_create());
+#endif
+ oggpackB_write(opb, 0x81, 8);
+ _tp_writebuffer(opb, "theora", 6);
- oggpack_write(&opb, vendor_length, 32);
- _tp_writebuffer(&opb, vendor, vendor_length);
+ _tp_writelsbint(opb, vendor_length);
+ _tp_writebuffer(opb, vendor, vendor_length);
- oggpack_write(&opb, tc->comments, 32);
+ _tp_writelsbint(opb, tc->comments);
if(tc->comments){
int i;
for(i=0;i<tc->comments;i++){
if(tc->user_comments[i]){
- oggpack_write(&opb,tc->comment_lengths[i],32);
- _tp_writebuffer(&opb,tc->user_comments[i],tc->comment_lengths[i]);
+ _tp_writelsbint(opb,tc->comment_lengths[i]);
+ _tp_writebuffer(opb,tc->user_comments[i],tc->comment_lengths[i]);
}else{
- oggpack_write(&opb,0,32);
+ oggpackB_write(opb,0,32);
}
}
}
- {
- int bytes=oggpack_bytes(&opb);
- op->packet=malloc(bytes);
+ op->bytes=oggpack_bytes(opb);
+
#ifndef LIBOGG2
- memcpy(op->packet, oggpack_get_buffer(&opb), bytes);
+ /* So we're expecting the application with free this? */
+ op->packet=malloc(oggpack_bytes(opb));
+ memcpy(op->packet, oggpack_get_buffer(opb), oggpack_bytes(opb));
+ oggpack_writeclear(opb);
#else
- /* I don't know why memcpy is used above, but it wont work here */
- op->packet = oggpack_writebuffer(&opb);
+ op->packet = oggpack_writebuffer(opb);
+ /* When the application puts op->packet into a stream_state object,
+ it becomes the property of libogg2's internal memory management. */
#endif
- op->bytes=bytes;
- }
- oggpack_writeclear(&opb);
+
+ free(opb);
op->b_o_s=0;
op->e_o_s=0;
@@ -1136,15 +1177,23 @@
int theora_encode_tables(theora_state *t, ogg_packet *op){
CP_INSTANCE *cpi=(CP_INSTANCE *)(t->internal_encode);
- oggpackB_reset(&cpi->oggbuffer);
- oggpackB_write(&cpi->oggbuffer,0x82,8);
- _tp_writebuffer(&cpi->oggbuffer,"theora",6);
+#ifndef LIBOGG2
+ oggpackB_reset(cpi->oggbuffer);
+#else
+ oggpackB_writeinit(cpi->oggbuffer, cpi->oggbufferstate);
+#endif
+ oggpackB_write(cpi->oggbuffer,0x82,8);
+ _tp_writebuffer(cpi->oggbuffer,"theora",6);
- WriteQTables(&cpi->pb,&cpi->oggbuffer);
- WriteHuffmanTrees(cpi->pb.HuffRoot_VP3x,&cpi->oggbuffer);
+ WriteQTables(&cpi->pb,cpi->oggbuffer);
+ WriteHuffmanTrees(cpi->pb.HuffRoot_VP3x,cpi->oggbuffer);
- op->packet=oggpackB_get_buffer(&cpi->oggbuffer);
- op->bytes=oggpackB_bytes(&cpi->oggbuffer);
+#ifndef LIBOGG2
+ op->packet=oggpackB_get_buffer(cpi->oggbuffer);
+#else
+ op->packet=oggpackB_writebuffer(cpi->oggbuffer);
+#endif
+ op->bytes=oggpackB_bytes(cpi->oggbuffer);
op->b_o_s=0;
op->e_o_s=0;
@@ -1186,8 +1235,8 @@
ClearTmpBuffers(&cpi->pb);
ClearPPInstance(&cpi->pp);
- _ogg_free(t->internal_encode);
-
+ _ogg_free(cpi->oggbuffer);
+ _ogg_free(t->internal_encode);
}
if(pbi){
@@ -1254,13 +1303,7 @@
ci->keyframe_frequency_force=1<<ret;
/* spare configuration bits */
- /* This has to be #ifdef for now since it needs to know if the packet
- has terminated early, and this is the only place this is needed. */
-#ifndef LIBOGG2
- if ( oggpackB_read(opb,5) < 0 )
-#else
- if ( oggpackB_read(opb,5,&ret) < 5 )
-#endif
+ if ( theora_read(opb,5,&ret) == -1 )
return (OC_BADHEADER);
return(0);
@@ -1268,18 +1311,20 @@
static int _theora_unpack_comment(theora_comment *tc, oggpack_buffer *opb){
int i;
- int len = oggpack_read(opb,32);
+ int len;
+
+ _tp_readlsbint(opb,(long *) &len);
if(len<0)return(OC_BADHEADER);
tc->vendor=_ogg_calloc(1,len+1);
_tp_readbuffer(opb,tc->vendor, len);
tc->vendor[len]='\0';
- tc->comments=oggpack_read(opb,32);
+ _tp_readlsbint(opb,(long *) &tc->comments);
if(tc->comments<0)goto parse_err;
tc->user_comments=_ogg_calloc(tc->comments,sizeof(*tc->user_comments));
tc->comment_lengths=_ogg_calloc(tc->comments,sizeof(*tc->comment_lengths));
for(i=0;i<tc->comments;i++){
- len=oggpack_read(opb,32);
+ _tp_readlsbint(opb,(long *)&len);
if(len<0)goto parse_err;
tc->user_comments[i]=_ogg_calloc(1,len+1);
_tp_readbuffer(opb,tc->user_comments[i],len);
@@ -1305,54 +1350,76 @@
}
int theora_decode_header(theora_info *ci, theora_comment *cc, ogg_packet *op){
- oggpack_buffer opb;
-
+ long ret;
+ oggpack_buffer *opb;
+
if(!op)return OC_BADHEADER;
+
#ifndef LIBOGG2
- oggpackB_readinit(&opb,op->packet,op->bytes);
+ opb = malloc(sizeof(oggpack_buffer));
+ oggpackB_readinit(opb,op->packet,op->bytes);
#else
- oggpackB_readinit(&opb,op->packet);
+ opb = malloc(oggpack_buffersize());
+ oggpackB_readinit(opb,op->packet);
#endif
{
char id[6];
int typeflag;
+
+ theora_read(opb,8,&ret);
+ typeflag = ret;
+ if(!(typeflag&0x80)) {
+ free(opb);
+ return(OC_NOTFORMAT);
+ }
- theora_read(&opb,8,&typeflag);
- if(!(typeflag&0x80))return(OC_NOTFORMAT);
-
- _tp_readbuffer(&opb,id,6);
- if(memcmp(id,"theora",6))return(OC_NOTFORMAT);
+ _tp_readbuffer(opb,id,6);
+ if(memcmp(id,"theora",6)) {
+ free(opb);
+ return(OC_NOTFORMAT);
+ }
switch(typeflag){
case 0x80:
if(!op->b_o_s){
/* Not the initial packet */
+ free(opb);
return(OC_BADHEADER);
}
if(ci->version_major!=0){
/* previously initialized info header */
+ free(opb);
return OC_BADHEADER;
}
- return(_theora_unpack_info(ci,&opb));
+ ret = _theora_unpack_info(ci,opb);
+ free(opb);
+ return(ret);
case 0x81:
if(ci->version_major==0){
/* um... we didn't get the initial header */
+ free(opb);
return(OC_BADHEADER);
}
- return(_theora_unpack_comment(cc,&opb));
+ ret = _theora_unpack_comment(cc,opb);
+ free(opb);
+ return(ret);
case 0x82:
if(ci->version_major==0 || cc->vendor==NULL){
/* um... we didn't get the initial header or comments yet */
+ free(opb);
return(OC_BADHEADER);
}
- return(_theora_unpack_tables(ci,&opb));
+ ret = _theora_unpack_tables(ci,opb);
+ free(opb);
+ return(ret);
default:
+ free(opb);
if(ci->version_major==0 || cc->vendor==NULL ||
((codec_setup_info *)ci->codec_setup)->HuffRoot[0]==NULL){
/* we haven't gotten the three required headers */
@@ -1362,6 +1429,8 @@
return(OC_NEWPACKET);
}
}
+ /* I don't think it's possible to get this far, but better safe.. */
+ free(opb);
return(OC_BADHEADER);
}
@@ -1399,19 +1468,19 @@
}
int theora_decode_packetin(theora_state *th,ogg_packet *op){
- int ret;
+ long ret;
PB_INSTANCE *pbi=(PB_INSTANCE *)(th->internal_decode);
pbi->DecoderErrorCode = 0;
#ifndef LIBOGG2
- oggpackB_readinit(&pbi->opb,op->packet,op->bytes);
+ oggpackB_readinit(pbi->opb,op->packet,op->bytes);
#else
- oggpackB_readinit(&pbi->opb,op->packet);
+ oggpackB_readinit(pbi->opb,op->packet);
#endif
/* verify that this is a video frame */
- theora_read(&pbi->opb,1,&ret);
+ theora_read(pbi->opb,1,&ret);
if (ret==0) {
ret=LoadAndDecode(pbi);
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list