[xiph-commits] r7336 - trunk/oggdsf/src/lib/core/ogg/libOOOgg

illiminable at dactyl.lonelymoon.com illiminable
Sun Jul 25 13:28:54 PDT 2004


Author: illiminable
Date: Sun Jul 25 13:28:54 2004
New Revision: 7336

Added:
trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h
Modified:
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.vcproj
Log:
* Changing the buffer on the demux.
* Added a circular buffer

Added: trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp	2004-07-25 19:13:43 UTC (rev 7335)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.cpp	2004-07-25 20:28:53 UTC (rev 7336)
@@ -0,0 +1,102 @@
+#include "StdAfx.h"
+#include ".\circularbuffer.h"
+
+CircularBuffer::CircularBuffer(unsigned long inBufferSize)
+	:	mBufferSize(inBufferSize)
+	,	mBuffer(NULL)
+	,	mReadPtr(0)
+	,	mWritePtr(0)
+
+{
+	mBuffer = new unsigned char[inBufferSize];
+}
+
+CircularBuffer::~CircularBuffer(void)
+{
+	delete mBuffer;
+}
+
+unsigned long CircularBuffer::read(unsigned char* outData, unsigned long inBytesToRead) {
+
+	unsigned long locBytesToRead =			(inBytesToRead > numBytesAvail())	?	numBytesAvail()
+																				:	inBytesToRead;
+
+	unsigned long locEndDistance = mBufferSize - mReadPtr;
+	//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.
+	signed long locEndOffset = locEndDistance - locBytesToRead;
+
+	if (locEndOffset >= 0) {
+		//Within the buffer
+		memcpy((void*)outData, (const void*)(mBuffer + mReadPtr), locBytesToRead);
+		mReadPtr += locBytesToRead;
+	} else {
+		//Copy from the end of the raw buffer as much as we can into outdtata
+		memcpy((void*)outData, (const void*)(mBuffer + mReadPtr), locEndDistance);
+
+		//Copy from the start of the raw buffer whatever is left
+		memcpy((void*)(outData + locEndDistance), (const void*)(mBuffer + mReadPtr + locEndDistance), locBytesToRead - locEndDistance);
+		mReadPtr = (mReadPtr + locBytesToRead) % mBufferSize;
+	}
+
+	mReadPtr = (mReadPtr + locBytesToRead) % mBufferSize;
+
+	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
+		//
+		////
+
+
+		return (mBufferSize + mWritePtr - mReadPtr);
+
+
+
+	} else {
+		//if (mReadPtr <= mWritePtr)
+		return mWritePtr - mReadPtr;
+	}
+}
+
+unsigned long CircularBuffer::write(const unsigned char* inData, unsigned long inBytesToWrite) {
+	unsigned long locBytesToWrite =			(inBytesToWrite >  spaceLeft())		?	spaceLeft()
+																				:	inBytesToWrite;
+
+	unsigned long locEndDistance = mBufferSize - mWritePtr;
+	//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;
+
+
+	if (locEndOffset >= 0) {
+		//Within the buffer
+		memcpy((void*)(mBuffer + mWritePtr), ((const void*)inData), locBytesToWrite);
+
+		mWritePtr += locBytesToWrite;
+	} else {
+
+		//Copy from the end of the raw buffer as much as we can into outdtata
+		memcpy((void*)(mBuffer + mWritePtr), (const void*)inData, locEndDistance);
+
+		//Copy from the start of the raw buffer whatever is left
+		memcpy((void*)(mBuffer + mWritePtr + locEndDistance), (const void*)(inData + locEndDistance), locBytesToWrite - locEndDistance);
+
+		//Advance the write pointer wrapping voer the end.
+		mWritePtr = (mWritePtr + locBytesToWrite) % mBufferSize;
+	}
+
+	return locBytesToWrite;
+
+
+
+}

Added: trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h	2004-07-25 19:13:43 UTC (rev 7335)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/CircularBuffer.h	2004-07-25 20:28:53 UTC (rev 7336)
@@ -0,0 +1,21 @@
+#pragma once
+
+class CircularBuffer
+{
+public:
+	CircularBuffer(unsigned long inBufferSize);
+	~CircularBuffer(void);
+
+	unsigned long read(unsigned char* outData, unsigned long inBytesToRead);
+	unsigned long write(const unsigned char* inData, unsigned long inBytesToWrite);
+
+	unsigned long numBytesAvail();
+	unsigned long spaceLeft();
+
+protected:
+	unsigned long mBufferSize;
+	unsigned long mReadPtr;
+	unsigned long mWritePtr;
+
+	unsigned char* mBuffer;
+};

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-07-25 19:13:43 UTC (rev 7335)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-07-25 20:28:53 UTC (rev 7336)
@@ -176,6 +176,7 @@

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);


Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.vcproj
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.vcproj	2004-07-25 19:13:43 UTC (rev 7335)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/libOOOgg.vcproj	2004-07-25 20:28:53 UTC (rev 7336)
@@ -131,6 +131,9 @@
RelativePath="CallbackRego.cpp">
</File>
<File
+				RelativePath=".\CircularBuffer.cpp">
+			</File>
+			<File
RelativePath="FLACMath.cpp">
</File>
<File
@@ -222,6 +225,9 @@
RelativePath="CallbackRego.h">
</File>
<File
+				RelativePath=".\CircularBuffer.h">
+			</File>
+			<File
RelativePath="dllstuff.h">
</File>
<File



More information about the commits mailing list