[xiph-commits] r7351 - in trunk/oggdsf/src: lib/core/ogg/libOOOgg

illiminable at dactyl.lonelymoon.com illiminable
Mon Jul 26 09:34:32 PDT 2004


tests/testCircleBuffer
Message-ID: <20040726163432.3BB749AAAB at dactyl.lonelymoon.com>

Author: illiminable
Date: Mon Jul 26 09:34:32 2004
New Revision: 7351

Modified:
trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.h
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPaginator.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.h
trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.vcproj
trunk/oggdsf/src/tests/testCircleBuffer/testCircleBuffer.cpp
Log:
* More demux changes

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp	2004-07-26 16:34:30 UTC (rev 7351)
@@ -8,7 +8,7 @@
,	mWritePtr(0)

{
-	mBuffer = new unsigned char[inBufferSize];
+	mBuffer = new unsigned char[inBufferSize + 1];
}

CircularBuffer::~CircularBuffer(void)
@@ -18,22 +18,27 @@

unsigned long CircularBuffer::read(unsigned char* outData, unsigned long inBytesToRead) {

-	//If requested less or equal to what we have, read that amount, otherwise read as much as we've got.
-	unsigned long locBytesToRead =			(inBytesToRead <= numBytesAvail())	?	inBytesToRead
-																				:	numBytesAvail();
+	if (inBytesToRead >  spaceLeft()) {
+		return 0;
+	}
+
+	unsigned long locBytesToRead =	inBytesToRead;
+
+		//	(inBytesToRead <= numBytesAvail())	?	inBytesToRead
+		//											:	numBytesAvail();
//locBytesToRead = the lower of numBytesAvail() and inBytesToRead
bufASSERT(locBytesToRead <= inBytesToRead);
bufASSERT(locBytesToRead <= numBytesAvail());

-	unsigned long locEndDistance = mBufferSize - mReadPtr;
+	unsigned long locEndDistance = (mBufferSize + 1 - mWritePtr);
bufASSERT(locEndDistance <= mBufferSize);

//Where we will be if in relation to the end of the raw buffer if we wrote the bufferout from here.
//Negative values indicate bytes past the end ofthe buffer.
//Positive values indicate bytes before the end of buffer.
-	signed long locEndOffset = locEndDistance - locBytesToRead;

-	if (locEndOffset >= 0) {
+
+	if (locEndDistance >= locBytesToRead) {
//Within the buffer
bufASSERT(mReadPtr < mBufferSize);

@@ -45,48 +50,35 @@
//Copy from the start of the raw buffer whatever is left
memcpy((void*)(outData + locEndDistance), (const void*)(mBuffer), locBytesToRead - locEndDistance);
}
-	mReadPtr = (mReadPtr + locBytesToRead) % mBufferSize;
+	mReadPtr = (mReadPtr + locBytesToRead) % (mBufferSize + 1);

return locBytesToRead;
}

-unsigned long CircularBuffer::spaceLeft() {
-	//The write pointer is always treated as being equal to or in front of the read pointer.
-	return mBufferSize - numBytesAvail();
-}
-unsigned long CircularBuffer::numBytesAvail() {
-	if (mReadPtr > mWritePtr) {
-		//Read pointer is to the right of the Write pointer
-		// Since the write pointer is always in front, this means all the data from the read ptr
-		// to the end of the buffer, plus everything from the start up to the write pointer is
-		// available
-		//
-		////
+unsigned long CircularBuffer::write(const unsigned char* inData, unsigned long inBytesToWrite) {
+	if (inBytesToWrite >  spaceLeft()) {
+		return 0;
+	}

+	unsigned long locBytesToWrite =	inBytesToWrite;

-		return  (mBufferSize + mWritePtr - mReadPtr);
-	} else {
-		//if (mReadPtr <= mWritePtr)
-		return mWritePtr - mReadPtr;
-	}
-}
+		//		(inBytesToWrite >  spaceLeft())		?	spaceLeft()
+		//										:	inBytesToWrite;

-void CircularBuffer::reset() {
-	mWritePtr = 0;
-	mReadPtr = 0;
-}
+	bufASSERT(locBytesToWrite <= spaceLeft());
+	bufASSERT(locBytesToWrite <= inBytesToWrite);
+	bufASSERT(locBytesToWrite <= mBufferSize);
+	bufASSERT(mWritePtr <= mBufferSize);

-unsigned long CircularBuffer::write(const unsigned char* inData, unsigned long inBytesToWrite) {
-	unsigned long locBytesToWrite =			(inBytesToWrite >  spaceLeft())		?	spaceLeft()
-																				:	inBytesToWrite;
+	unsigned long locEndDistance = (mBufferSize + 1 - mWritePtr);

-	unsigned long locEndDistance = mBufferSize - mWritePtr;
+	bufASSERT(locEndDistance <= mBufferSize + 1);
//Where we will be, in relation to the end of the raw buffer if we wrote the buffer out from here.
//Negative values indicate bytes past the end ofthe buffer.
-	signed long locEndOffset = locEndDistance - locBytesToWrite;
+	//signed long locEndOffset = locEndDistance - locBytesToWrite;


-	if (locEndOffset >= 0) {
+	if (locEndDistance >= locBytesToWrite) {
//Within the buffer
memcpy((void*)(mBuffer + mWritePtr), ((const void*)inData), locBytesToWrite);

@@ -102,10 +94,51 @@
//Advance the write pointer wrapping voer the end.

}
-	mWritePtr = (mWritePtr + locBytesToWrite) % mBufferSize;
+	mWritePtr = (mWritePtr + locBytesToWrite) % (mBufferSize + 1);

return locBytesToWrite;



}
+
+unsigned long CircularBuffer::spaceLeft() {
+	//The write pointer is always treated as being equal to or in front of the read pointer.
+	return mBufferSize - numBytesAvail() - 1;
+	if (mReadPtr > mWritePtr) {
+		//Read pointer is to the right of the Write pointer
+		// Since the write pointer is always in front, this means all the data from the read ptr
+		// to the end of the buffer, plus everything from the start up to the write pointer is
+		// available
+		//
+		////
+
+
+		return  (mReadPtr - mWritePtr - 1);
+	} else {
+
+		return mBufferSize + mReadPtr - mWritePtr ;
+	}
+}
+unsigned long CircularBuffer::numBytesAvail() {
+	if (mReadPtr > mWritePtr) {
+		//Read pointer is to the right of the Write pointer
+		// Since the write pointer is always in front, this means all the data from the read ptr
+		// to the end of the buffer, plus everything from the start up to the write pointer is
+		// available
+		//
+		////
+
+
+		return  (mBufferSize - 1 - mWritePtr - mReadPtr);
+	} else {
+		//if (mReadPtr <= mWritePtr)
+		return mWritePtr - mReadPtr;
+	}
+}
+
+void CircularBuffer::reset() {
+	mWritePtr = 0;
+	mReadPtr = 0;
+}
+

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h	2004-07-26 16:34:30 UTC (rev 7351)
@@ -1,6 +1,98 @@
#pragma once
#include "dllstuff.h"
#include "IFIFOBuffer.h"
+
+
+//Empty Buffer
+//==============
+//
+//		<--------------- Buffer Size -------------------->
+//
+//		0123456789 123456789 123456789 123456789 123456789*
+//      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+//      R
+//		W
+//
+//
+//		0123456789 123456789 123456789 123456789 123456789*
+//      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+//									R
+//									W
+//
+//When R = W Buffer is empty
+//
+//		when R = W:	available bytes = 0
+//		when R = W: space left = buffer size
+////
+
+//Full Buffer
+//===========
+//
+//
+//
+//		<--------------- Buffer Size -------------------->
+//
+//		0123456789 123456789 123456789 123456789 123456789*
+//      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+//                               R
+//								W
+//
+//
+//		<--------------- Buffer Size -------------------->
+//
+//		0123456789 123456789 123456789 123456789 123456789*
+//      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+//      R
+//								                          W
+//
+//Buffer is full when R = (W + 1) MOD (bufferSize + 1)
+//
+//		when	R = (W + 1) MOD (bufferSize + 1):		available bytes = buffer size
+//		when	R = (W + 1) MOD (bufferSize + 1):		space left  = 0
+//
+//
+//
+//
+//////
+
+//Partial Buffers
+//===============
+//
+//Case 1
+//======
+//
+//
+//		<--------------- Buffer Size -------------------->
+//
+//		0123456789 123456789 123456789 123456789 123456789*
+//      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+//    								           R
+//											    W
+//
+//
+//		when W > R:		available bytes								=	W - R
+//		when W > R:		space left = buffer size - available bytes	=	buffer size + R - W
+//
+//
+//Case 2
+//======
+//
+//
+//		<--------------- Buffer Size -------------------->
+//				  1			2		  3			4
+//		0123456789 123456789 123456789 123456789 123456789*
+//      XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+//                                                      R
+//		W
+//
+//		when R > W:			available bytes									=	buffer size + 1 - R + W
+//		when R > W:			space left = buffer size - available bytes		=	R - W - 1
+//
+//
+//
+//
+//
+
class LIBOOOGG_API CircularBuffer
:	public IFIFOBuffer
{

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-07-26 16:34:30 UTC (rev 7351)
@@ -144,18 +144,16 @@

debugLog<<"********** Fed "<<inNumBytes<<" bytes..."<<endl;

-			///STREAM ACCESS::: WRite
-			//Write the data into the stream buffer
-
-			//mStream.write(inData, inNumBytes);
-			mBuffer->write(inData, inNumBytes);
+			unsigned long locNumWritten = mBuffer->write(inData, inNumBytes);

+			if (locNumWritten < inNumBytes) {
+				//Handle this case... you lose data.
+				//Buffer is full
+				debugLog<<"Feed : Could count feed in " <<inNumBytes<<" bytes"<<endl
+						<<"Feed : ** "<<mBuffer->numBytesAvail()<<" avail, "<<mBuffer->spaceLeft()<<" space left."<<endl;
+				locNumWritten = locNumWritten;
+			}

-			//if(mStream.fail()) {
-			//	debugLog<<"ProcessBaseHeader : Buffer write Write FAILED"<<endl;
-			//	return FEED_BUFFER_WRITE_ERROR;
-			//}
-
return (eFeedResult)processBuffer();

} else {
@@ -178,8 +176,6 @@
delete pendingPage;

//make a fresh one
-
-		//TODAY::: verify OggPage initialises properly.
pendingPage = new OggPage;

//Make a local buffer for the header
@@ -188,25 +184,19 @@
debugLog<<"ProcessBaseHeader : Reading from stream..."<<endl;

//STREAM ACCESS::: Read
-		//Read from the stream buffer to it
-		//mStream.read((char*)locBuff, OggPageHeader::OGG_BASE_HEADER_SIZE);
-		mBuffer->read(locBuff, OggPageHeader::OGG_BASE_HEADER_SIZE);
+		unsigned long locNumRead = mBuffer->read(locBuff, OggPageHeader::OGG_BASE_HEADER_SIZE);
+
+		if (locNumRead < OggPageHeader::OGG_BASE_HEADER_SIZE) {
+			debugLog<<"ProcessBaseHeader : ###### Read was short."<<endl;
+			debugLog<<"ProcessBaseHeader : ** "<<mBuffer->numBytesAvail()<<" avail, "<<mBuffer->spaceLeft()<<" space left."<<endl;
+			locNumRead = locNumRead;
+		}

-		//if(mStream.fail()) {
-		//	debugLog<<"ProcessBaseHeader : File Read FAILED"<<endl;
-		//	delete locBuff;
-		//	return PROCESS_STREAM_READ_ERROR;
-		//}
-
-		//Set the base header into the pending page
-
bool locRetVal = pendingPage->header()->setBaseHeader((unsigned char*)locBuff);
if (locRetVal == false) {
return PROCESS_FAILED_TO_SET_HEADER;
}
-
-		//NOTE ::: The page will delete the buffer when it's done. Don't delete it here
-
+
//Set the number of bytes we want for next time
mNumBytesNeeded = pendingPage->header()->NumPageSegments();

@@ -239,29 +229,28 @@

//Read the segment table from the buffer to locBuff
//mStream.read((char*)locBuff, (std::streamsize)locNumSegs);
-	mBuffer->read(locBuff, (std::streamsize)locNumSegs);
-	//if(mStream.fail()) {
-	//	debugLog<<"ProcessSegTable : Read FAILED"<<endl;
-	//	delete locBuff;
-	//	return PROCESS_STREAM_READ_ERROR;
-	//}
+	unsigned long locNumRead = mBuffer->read(locBuff, (unsigned long)locNumSegs);
+
+	if (locNumRead < locNumSegs) {
+		debugLog<<"ProcessSegTable : ##### Short read"<<endl;
+		debugLog<<"ProcessSegTable : ** "<<mBuffer->numBytesAvail()<<" avail, "<<mBuffer->spaceLeft()<<" space left."<<endl;
+		locNumRead = locNumRead;
+	}

-	//TODAY::: Check out the page header class.

//Make a new segment table from the bufferd data.
-	OggSegmentTable* locSegTable = new OggSegmentTable();
-	unsigned long locDataSize = locSegTable->setSegmentTable(locBuff, locNumSegs);
+	pendingPage->header()->setSegmentTable(locBuff);
+	locBuff = NULL;

-	//Set the data into the pending pages segtable... giving  the pointer away, don't use any more.
-	//NOTE ::: The seg table will delete the buffer itself. Don't delete here.
-	pendingPage->header()->setSegmentTable(locSegTable);
-	locSegTable = NULL;
-
+
//Set the number of bytes we want for next time - which is the size of the page data.
-	mNumBytesNeeded = locDataSize;
+
+	mNumBytesNeeded = pendingPage->header()->calculateDataSize();
+
debugLog<<"ProcessSegTable : Num bytes needed for data = "<< mNumBytesNeeded<<endl;

debugLog<<"ProcessSegTable : Transition to AWAITING_DATA"<<endl;
+
mState = AWAITING_DATA;
return PROCESS_OK;

@@ -279,8 +268,8 @@
//unsigned long locPacketOffset = 0;

//THis is a raw pointer into the segment table, don't delete it.
-	unsigned char* locSegTable = pendingPage->header()->SegmentTable()->segmentTable();
-	unsigned int locNumSegs = pendingPage->header()->SegmentTable()->numSegments();
+	unsigned char* locSegTable = pendingPage->header()->SegmentTable();
+	unsigned int locNumSegs = pendingPage->header()->NumPageSegments();

debugLog<<"ProcessDataSegment : Num segs = "<<locNumSegs<<endl;

@@ -317,7 +306,13 @@
//STREAM ACCESS:::
//Read data from the stream into the local buffer.
//mStream.read((char*)(locBuff), locCurrPackSize);
-			mBuffer->read(locBuff, locCurrPackSize);
+			unsigned long locNumRead = mBuffer->read(locBuff, locCurrPackSize);
+
+			if (locNumRead < locCurrPackSize) {
+				debugLog<<"ProcessDataSegment : ###### Short read"<<endl;
+				debugLog<<"ProcessDataSegment : ** "<<mBuffer->numBytesAvail()<<" avail, "<<mBuffer->spaceLeft()<<" space left."<<endl;
+				locNumRead = locNumRead;
+			}


//FIX::: check for stream failure.
@@ -340,7 +335,9 @@

debugLog<<"ProcessDataSegment : num bytes needed = "<<mNumBytesNeeded<<endl;

+	//Dispatch the finished pagbve
bool locRet = dispatch(pendingPage);
+
if (locRet == true) {
debugLog<<"ProcessDataSegment : Transition to AWAITING_BASE_HEADER"<<endl;
mState = AWAITING_BASE_HEADER;
@@ -353,10 +350,6 @@
}
void OggDataBuffer::clearData() {
mBuffer->reset();
-	//mStream.clear();
-	//mStream.flush();
-	//mStream.seekg(0, ios_base::beg);
-	//mStream.seekp(0, ios_base::beg);

debugLog<<"ClearData : Transition back to AWAITING_BASE_HEADER"<<endl;

@@ -368,8 +361,7 @@
}

OggDataBuffer::eProcessResult OggDataBuffer::processBuffer() {
-	debugLog<<"ProcessBuffer :"<<endl;
-
+
while (numBytesAvail() >= mNumBytesNeeded) {
debugLog<<"ProcessBuffer : Bytes Needed = "<<mNumBytesNeeded<<" --- "<<"Bytes avail = "<<numBytesAvail()<<endl;
switch (mState) {
@@ -416,7 +408,14 @@
debugLog<<"ProcessBuffer : Enough to process..."<<endl;

//FIX::: Need error check.
-					return processDataSegment();
+					eProcessResult locResult = processDataSegment();
+
+					if (locResult != PROCESS_OK) {
+						mState = LOST_PAGE_SYNC;
+						//segment table process failed
+						return locResult;
+					}
+
}
break;
case eState::LOST_PAGE_SYNC:

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.h	2004-07-26 16:34:30 UTC (rev 7351)
@@ -72,8 +72,8 @@
};

static const int MAX_OGG_PAGE_SIZE =	OggPageHeader::OGG_BASE_HEADER_SIZE +											//Header
-											(OggSegmentTable::MAX_NUM_SEGMENTS * OggSegmentTable::MAX_SEGMENT_SIZE) +		//Page Data
-											(OggSegmentTable::SEGMENT_WIDTH * OggSegmentTable::MAX_NUM_SEGMENTS);			//Segment table
+											(OggPageHeader::MAX_NUM_SEGMENTS * OggPageHeader::MAX_SEGMENT_SIZE) +		//Page Data
+											(OggPageHeader::SEGMENT_WIDTH * OggPageHeader::MAX_NUM_SEGMENTS);			//Segment table


OggDataBuffer(void);

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.cpp	2004-07-26 16:34:30 UTC (rev 7351)
@@ -33,20 +33,6 @@
#include "oggpageheader.h"


-	//unsigned long mPageSize;
-	//unsigned long mHeaderSize;
-	//unsigned long mDataSize;
-
-	//unsigned char mStructureVersion;
-	//unsigned char mHeaderFlags;
-	//__int64 mGranulePos;
-	//unsigned long mStreamSerialNo;
-	//unsigned long mPageSequenceNo;
-	//unsigned long mCRCChecksum;
-	//unsigned char mNumPageSegments;
-	//OggSegmentTable* mSegmentTable;
-
-	//ePageState mPageState;
OggPageHeader::OggPageHeader(void)
:	mPageSize(0)
,	mHeaderSize(0)
@@ -66,29 +52,11 @@

OggPageHeader::~OggPageHeader(void)
{
-
delete mSegmentTable;
-
}

OggPageHeader* OggPageHeader::clone() {
-	/*
-		unsigned long mPageSize;
-	unsigned long mHeaderSize;
-	unsigned long mDataSize;

-	unsigned char mStructureVersion;
-	unsigned char mHeaderFlags;
-	OggInt64* mGranulePos;
-	unsigned long mStreamSerialNo;
-	unsigned long mPageSequenceNo;
-	unsigned long mCRCChecksum;
-	unsigned char mNumPageSegments;
-	OggSegmentTable* mSegmentTable;
-
-	ePageState mPageState;
-	*/
-
OggPageHeader* retClone = new OggPageHeader();
retClone->mCRCChecksum = mCRCChecksum;
retClone->mDataSize = mDataSize;
@@ -99,82 +67,88 @@
retClone->mPageSequenceNo = mPageSequenceNo;
retClone->mPageSize = mPageSize;
retClone->mPageState = mPageState;
-	retClone->mSegmentTable = mSegmentTable->clone();
+
+	//Copy the segment table.
+	unsigned char* locBuff = new unsigned char[mNumPageSegments];
+	memcpy((void*)locBuff, (const void*)mSegmentTable, mNumPageSegments);
+	retClone->mSegmentTable = locBuff;
+	locBuff = NULL;
+	//
+
retClone->mStreamSerialNo = mStreamSerialNo;
retClone->mStructureVersion = mStructureVersion;

return retClone;
}

-bool OggPageHeader::rawData(unsigned char* outData, unsigned long inBuffSize) {
-
-	//0-3			CapPattern						"Oggs"
-	//4				Struct Ver
-	//5				Head Flags
-	//6-13			Granule Pos
-	//14-17			Stream Serial No
-	//18-21			Page Seq No
-	//22-25			CheckSum
-	//26			Num Segments
-	//27...			SegmentTable
-	if (mHeaderSize > inBuffSize) {
-		//EXIT POINT
-		return false;
+
+unsigned long OggPageHeader::calculateDataSize() {
+	//Sums the bytes in the segment table to calculate the size of data.
+	//FIX::: ??? No checks on pointers.
+
+	unsigned long retDataSize = 0;
+	for (int i = 0; i < mNumPageSegments; i++) {
+		retDataSize += mSegmentTable[i];
}
-	outData[0] = 'O';
-	outData[1] = 'g';
-	outData[2] = 'g';
-	outData[3] = 'S';
-	outData[4] = mStructureVersion;
-	outData[5] = mHeaderFlags;
-	OggMath::Int64ToCharArr(mGranulePos, &outData[6]);
-	OggMath::ULongToCharArr(mStreamSerialNo, &outData[14]);
-	OggMath::ULongToCharArr(mPageSequenceNo, &outData[18]);
-	OggMath::ULongToCharArr(mCRCChecksum, &outData[22]);
-	outData[26] = mSegmentTable->numSegments();;
-	mSegmentTable->rawData(&outData[27]);

-	//EXIT POINT
-	return true;
+	setDataSize(retDataSize);
+	return retDataSize;
+}
+
+bool OggPageHeader::setBaseHeader(const unsigned char* inBaseHeader) {
+	//This now does not delete the buffer

+	unsigned long locOffset = 0;

-}
+	//Check if the page has the correct capture pattern
+	if (strncmp((const char*)inBaseHeader, "OggS", OGG_CAPTURE_PATTERN_SIZE) == 0) {
+
+		locOffset += OGG_CAPTURE_PATTERN_SIZE;

-//ACESSORS
-bool OggPageHeader::isBOS() {
-	if ( (mHeaderFlags & eHeadFlags::BOS) != 0 ) {
+		//Assign the structure version
+		setStructureVersion(inBaseHeader[locOffset]);
+		locOffset++;
+
+		//Assign the header flags
+		setHeaderFlags(inBaseHeader[locOffset]);
+		locOffset++;
+
+		//Assign the granule pos
+		setGranulePos((const unsigned char*)(inBaseHeader + locOffset));
+		locOffset += 8;
+
+		//Assign Serial No
+		setStreamSerialNo((const unsigned char*)(inBaseHeader + locOffset));
+		locOffset += 4;
+
+		//Assign Page Seq No
+		setPageSequenceNo(inBaseHeader + locOffset);
+		locOffset += 4;
+
+		//Assign CheckSum
+		setCRCChecksum(inBaseHeader + locOffset);
+		locOffset += 4;
+
+		//Assign Num Page Segments
+		setNumPageSegments(inBaseHeader[locOffset]);
+		locOffset++;
+
+		//Set the size of the header
+		setHeaderSize(OGG_BASE_HEADER_SIZE + mNumPageSegments);
+
+		mPageState = BASE_HEAD_SET;
+
+		//We are passed our own copy of this so we can delete it now.
+		//delete inBaseHeader;
+
return true;
} else {
return false;
}
-}
-bool OggPageHeader::isEOS() {
-	if ( (mHeaderFlags & eHeadFlags::EOS) != 0 ) {
-		return true;
-	} else {
-		return false;
-	}
-}

-
-string OggPageHeader::toString() {
-
-	string retStr =	"Ver No      : " + StringHelper::numToString((unsigned int)mStructureVersion) + "\n";
-	retStr +=		"Head Flags  : " + StringHelper::numToString((unsigned int)mHeaderFlags) +"\n";
-	retStr +=		"Granule Pos : " + StringHelper::numToString(mGranulePos) + "\n";
-	retStr +=		"Serial No   : " + StringHelper::numToString(mStreamSerialNo) + "\n";
-	retStr +=		"Seq No      : " + StringHelper::numToString(mPageSequenceNo) + "\n";
-	retStr +=		"Checksum    : " + StringHelper::numToString(mCRCChecksum) + "\n";
-	retStr +=		"Num Segs    : " + StringHelper::numToString((unsigned int)mSegmentTable->numSegments()) + "\n";
-	retStr +=		"------------------------\n";
-	retStr +=		"Head Size   : " + StringHelper::numToString(mHeaderSize) + "\n";
-	retStr +=		"Data Size   : " + StringHelper::numToString(mDataSize) + "\n";
-	retStr +=		"Page Size   : " + StringHelper::numToString(mPageSize) +"\n";
-
-	return retStr;
-
}

+
void OggPageHeader::setPageState(ePageState inPageState) {
mPageState = inPageState;
}
@@ -208,114 +182,15 @@

unsigned char OggPageHeader::NumPageSegments()
{
-	if (mSegmentTable == NULL) {
-		return mNumPageSegments;
-	} else {
-		return mSegmentTable->numSegments();
-	}
+	return mNumPageSegments;
}
-OggSegmentTable* OggPageHeader::SegmentTable()
+unsigned char* OggPageHeader::SegmentTable()
{
return mSegmentTable;
}



-bool OggPageHeader::setBaseHeader(const unsigned char* inBaseHeader) {
-	//This now does not delete the buffer
-	bool locIsValidPage = true;
-	unsigned long locOffset = 0;
-
-	//Check if the page has the correct capture pattern
-	if (strncmp((const char*)inBaseHeader, "OggS", OGG_CAPTURE_PATTERN_SIZE) == 0) {
-		locIsValidPage = true;
-
-		if (mPageState == BLANK) {
-			locOffset += OGG_CAPTURE_PATTERN_SIZE;
-
-			//Assign the structure version
-			setStructureVersion(inBaseHeader[locOffset]);
-			locOffset++;
-
-			//Assign the header flags
-			setHeaderFlags(inBaseHeader[locOffset]);
-			locOffset++;
-
-			//Assign the granule pos
-			setGranulePos((const unsigned char*)(inBaseHeader + locOffset));
-			locOffset += 8;
-
-			//Assign Serial No
-			setStreamSerialNo((const unsigned char*)(inBaseHeader + locOffset));
-			locOffset += 4;
-
-			//Assign Page Seq No
-			setPageSequenceNo(inBaseHeader + locOffset);
-			locOffset += 4;
-
-			//Assign CheckSum
-			setCRCChecksum(inBaseHeader + locOffset);
-			locOffset += 4;
-
-			//Assign Num Page Segments
-			setNumPageSegments(inBaseHeader[locOffset]);
-			locOffset++;
-
-			//Set the size of the header
-			setHeaderSize(OGG_BASE_HEADER_SIZE + mNumPageSegments);
-
-			mPageState = BASE_HEAD_SET;
-
-			//We are passed our own copy of this so we can delete it now.
-			//delete inBaseHeader;
-
-			//EXIT POINT
-			return true;
-
-		} else {
-			//The page wasn't blank... so you can't set it's header or the data and header won't
-			// match
-
-			//EXIT POINT
-			return false;
-
-		}
-
-	} else {
-		locIsValidPage = false;
-		return false;
-	}
-
-
-
-}
-
-bool OggPageHeader::setSegmentTable(const unsigned char* inSegTable, unsigned char inNumSegs) {
-
-	//This assumes that mNumPageSegments is set.
-	//ISSUE ::: What happens when numPageSegments is zero ?
-	if ( /*(mPageState == BASE_HEAD_SET) && */ (mSegmentTable == NULL)) {
-		//Make a new segtable object
-		OggSegmentTable* locSegTable = new OggSegmentTable;
-
-		//Put the data in it and set the pagedata size
-		unsigned long locDataSize = locSegTable->setSegmentTable(inSegTable, inNumSegs);
-		setDataSize( locDataSize );
-
-		//Assign the segtable into the page, the page header will look after deleing the memory.
-		setSegmentTable(locSegTable);
-		mPageState = FULL_HEAD_SET;
-		return true;
-
-
-	} else {
-		//The page isn't being built right.
-		return false;
-	}
-}
-
-
-
void OggPageHeader::setStructureVersion(unsigned char inVal)
{
mStructureVersion = inVal;
@@ -367,12 +242,16 @@
mNumPageSegments = inVal;
}
}
-void OggPageHeader::setSegmentTable(OggSegmentTable* inPtr)
-{
-	//Keeps your pointer !
+
+void OggPageHeader::setSegmentTable(const unsigned char* inPtr, unsigned char inNumSegs) {
+	unsigned char* locSegTable = new unsigned char[inNumSegs];
+	memcpy((void*)locSegTable, (const void*)inPtr, inNumSegs);
+	mNumPageSegments = inNumSegs;
+}
+void OggPageHeader::setSegmentTable(unsigned char* inPtr) {
delete mSegmentTable;
mSegmentTable = inPtr;
-
+
}

OggPageHeader::ePageState OggPageHeader::pageState() {
@@ -390,11 +269,75 @@
{
return mDataSize;
}
+bool OggPageHeader::rawData(unsigned char* outData, unsigned long inBuffSize) {
+
+	//0-3			CapPattern						"Oggs"
+	//4				Struct Ver
+	//5				Head Flags
+	//6-13			Granule Pos
+	//14-17			Stream Serial No
+	//18-21			Page Seq No
+	//22-25			CheckSum
+	//26			Num Segments
+	//27...			SegmentTable
+	if (mHeaderSize > inBuffSize) {
+		//EXIT POINT
+		return false;
+	}
+	outData[0] = 'O';
+	outData[1] = 'g';
+	outData[2] = 'g';
+	outData[3] = 'S';
+	outData[4] = mStructureVersion;
+	outData[5] = mHeaderFlags;
+	OggMath::Int64ToCharArr(mGranulePos, &outData[6]);
+	OggMath::ULongToCharArr(mStreamSerialNo, &outData[14]);
+	OggMath::ULongToCharArr(mPageSequenceNo, &outData[18]);
+	OggMath::ULongToCharArr(mCRCChecksum, &outData[22]);
+	outData[26] = mNumPageSegments;

-//unsigned long PageSize()
-//{
-//	return mPageSize;
-//}
+	//TODO::: Validate the length of all this.
+	memcpy((void*)(outData + 27), (const void*)mSegmentTable, mNumPageSegments);
+
+	return true;
+}
+
+
+bool OggPageHeader::isBOS() {
+	if ( (mHeaderFlags & eHeadFlags::BOS) != 0 ) {
+		return true;
+	} else {
+		return false;
+	}
+}
+bool OggPageHeader::isEOS() {
+	if ( (mHeaderFlags & eHeadFlags::EOS) != 0 ) {
+		return true;
+	} else {
+		return false;
+	}
+}
+
+
+string OggPageHeader::toString() {
+
+	string retStr =	"Ver No      : " + StringHelper::numToString((unsigned int)mStructureVersion) + "\n";
+	retStr +=		"Head Flags  : " + StringHelper::numToString((unsigned int)mHeaderFlags) +"\n";
+	retStr +=		"Granule Pos : " + StringHelper::numToString(mGranulePos) + "\n";
+	retStr +=		"Serial No   : " + StringHelper::numToString(mStreamSerialNo) + "\n";
+	retStr +=		"Seq No      : " + StringHelper::numToString(mPageSequenceNo) + "\n";
+	retStr +=		"Checksum    : " + StringHelper::numToString(mCRCChecksum) + "\n";
+	retStr +=		"Num Segs    : " + StringHelper::numToString((unsigned int)mNumPageSegments) + "\n";
+	retStr +=		"------------------------\n";
+	retStr +=		"Head Size   : " + StringHelper::numToString(mHeaderSize) + "\n";
+	retStr +=		"Data Size   : " + StringHelper::numToString(mDataSize) + "\n";
+	retStr +=		"Page Size   : " + StringHelper::numToString(mPageSize) +"\n";
+
+	return retStr;
+}
+
+
+
void OggPageHeader::setHeaderSize(unsigned long inVal)
{
mHeaderSize = inVal;

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.h	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPageHeader.h	2004-07-26 16:34:30 UTC (rev 7351)
@@ -32,7 +32,7 @@
#pragma once

#include "StringHelper.h"
-#include "OggSegmentTable.h"
+//#include "OggSegmentTable.h"
#include "OggInt64.h"
#include "OggMath.h"

@@ -56,6 +56,10 @@
//26			Num Segments
//27...			SegmentTable

+	static const int MAX_NUM_SEGMENTS = 255;
+	static const int MAX_SEGMENT_SIZE = 255;
+	static const int SEGMENT_WIDTH = 1;
+
static const unsigned char OGG_CAPTURE_PATTERN_SIZE = 4;
static const unsigned char OGG_BASE_HEADER_SIZE = 27;
enum ePageState {
@@ -87,9 +91,10 @@
unsigned long headerSize();
unsigned long dataSize();

+	unsigned long calculateDataSize();
//Bulk Mutators
bool setBaseHeader(const unsigned char* inBaseHeader);
-	bool setSegmentTable(const unsigned char* inSegTable, unsigned char inNumSegs);
+	//bool setSegmentTable(const unsigned char* inSegTable, unsigned char inNumSegs);


unsigned char StructureVersion();
@@ -99,7 +104,7 @@
unsigned long PageSequenceNo();
unsigned long CRCChecksum();
unsigned char NumPageSegments();
-	OggSegmentTable* SegmentTable();
+	unsigned char* SegmentTable();



@@ -114,7 +119,8 @@
void setCRCChecksum(unsigned long inVal);
void setCRCChecksum(const unsigned char* inPtr);
void setNumPageSegments(unsigned char inVal);
-	void setSegmentTable(OggSegmentTable* inPtr);
+	void setSegmentTable(unsigned char* inPtr);
+	void setSegmentTable(const unsigned char* inPtr, unsigned char inNumSegs);

void setHeaderSize(unsigned long inVal);
void setDataSize(unsigned long inVal);
@@ -137,7 +143,7 @@
unsigned long mCRCChecksum;
unsigned char mNumPageSegments;

-	unsigned char[255] mSegmentTable;
+	unsigned char* mSegmentTable;
//OggSegmentTable* mSegmentTable;

ePageState mPageState;

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPaginator.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPaginator.cpp	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggPaginator.cpp	2004-07-26 16:34:30 UTC (rev 7351)
@@ -356,7 +356,7 @@
//If it's not the last of the packet, it will be a multiple of 255, hence we don't put a terminating 0 on.
//If it is the last of the packet this last segment will be between 0 and 254 inclusive.
if (locIsLastOfPacket) {
-		mSegmentTable[mSegmentTableSize] = inLength % 255;
+		mSegmentTable[mSegmentTableSize] = (unsigned char)(inLength % 255);
mSegmentTableSize++;
}
mCurrentPageSize += (locNumSegsNeeded + inLength);

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.h	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.h	2004-07-26 16:34:30 UTC (rev 7351)
@@ -37,7 +37,7 @@
#include "OggDataBuffer.h"
#include "OggInt64.h"
#include "OggPage.h"
-#include "OggSegmentTable.h"
+//#include "OggSegmentTable.h"
#include "OggTypeDefs.h"
#include "IOggCallback.h"
#include "OggBOSPage.h"

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.vcproj
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.vcproj	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.vcproj	2004-07-26 16:34:30 UTC (rev 7351)
@@ -176,9 +176,6 @@
RelativePath="OggPaginatorSettings.cpp">
</File>
<File
-				RelativePath="OggSegmentTable.cpp">
-			</File>
-			<File
RelativePath="SerialNoRego.cpp">
</File>
<File
@@ -276,9 +273,6 @@
RelativePath="OggPaginatorSettings.h">
</File>
<File
-				RelativePath="OggSegmentTable.h">
-			</File>
-			<File
RelativePath="OggTypeDefs.h">
</File>
<File

Modified: trunk/oggdsf/src/tests/testCircleBuffer/testCircleBuffer.cpp
===================================================================
--- trunk/oggdsf/src/tests/testCircleBuffer/testCircleBuffer.cpp	2004-07-26 16:26:58 UTC (rev 7350)
+++ trunk/oggdsf/src/tests/testCircleBuffer/testCircleBuffer.cpp	2004-07-26 16:34:30 UTC (rev 7351)
@@ -25,7 +25,7 @@

cout<<"* Testing fill to limit"<<endl;
unsigned long locNumWritten = 0;
-	for (int i = 0; i < 12; i++) {
+	for (int i = 0; i < (CIRC_BUFF_SIZE/LOC_BUFF_SIZE) + 2; i++) {
locNumWritten = locCircBuf->write(locBuf, LOC_BUFF_SIZE);
if (locNumWritten == 0) {
cout<<"Buffer full... Wrote 0"<<endl;



More information about the commits mailing list