[xiph-commits] r10773 - branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2

illiminable at svn.xiph.org illiminable at svn.xiph.org
Mon Jan 30 05:05:56 PST 2006


Author: illiminable
Date: 2006-01-30 05:05:50 -0800 (Mon, 30 Jan 2006)
New Revision: 10773

Modified:
   branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPStreamingFileSource.cpp
   branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPStreamingFileSource.h
Log:
* Add another buffer to the stream to try and hold onto the headers. Since processing the headers requires at least one data page to be forced out of the buffer, a seek back is required, but our buffer is forward only. So now, on the first pass it copies the start of the file into another buffer. On seeks that are from within that buffer, a fake read pointer is changed, and requests up to where the network cache starts are served from the header cache. Stops a double http request to setup a file, and solves the problem of subsequent requests on an anndoex server return a file with different serial no's.

Modified: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPStreamingFileSource.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPStreamingFileSource.cpp	2006-01-30 11:41:24 UTC (rev 10772)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPStreamingFileSource.cpp	2006-01-30 13:05:50 UTC (rev 10773)
@@ -42,6 +42,10 @@
 	,	mMemoryBuffer(NULL)
 	,	mContentLength(-1)
 	,	mIsBufferFilling(false)
+	,	mFirstPass(true)
+	,	mStreamStartBuffer(NULL)
+	,	mStreamStartBufferLength(0)
+	,	mApparentReadPosition(0)
 {
 	mBufferLock = new CCritSec;
 #ifdef OGGCODECS_LOGGING
@@ -52,6 +56,7 @@
 	
 	mInterBuff = new unsigned char[RECV_BUFF_SIZE* 2];
 	mMemoryBuffer = new CircularBuffer(MEMORY_BUFFER_SIZE);
+	mStreamStartBuffer = new unsigned char[STREAM_START_BUFFER_SIZE];
 
 }
 
@@ -69,6 +74,7 @@
 	delete mInterBuff;
 
 	delete mMemoryBuffer;
+	delete mStreamStartBuffer;
 }
 
 void HTTPStreamingFileSource::unChunk(unsigned char* inBuff, unsigned long inNumBytes) 
@@ -402,17 +408,31 @@
 	//debugLog<<"Seeking to "<<inPos<<endl;
 
 	//Keep track of the absolute position we are looking at in the file.
-	mCurrentAbsoluteReadPosition = inPos;
 	
-	if ((mContentLength != -1) || (inPos == 0)) {
-		close();
-		closeSocket();
-		clear();
+	mFirstPass = false;
+	if (mCurrentAbsoluteReadPosition <= mStreamStartBufferLength) {
+		//The network stream is still within the start buffer
+		mApparentReadPosition = inPos;
+		return inPos;
+	} else {
+	
+		mCurrentAbsoluteReadPosition = inPos;
+	
+	
+	
+	
+	
+		if ((mContentLength != -1) || (inPos == 0)) {
+			close();
+			closeSocket();
+			clear();
 
-		open(mSourceLocation, inPos);
+			open(mSourceLocation, inPos);
+			return inPos;
 
-	} else {
-		return (unsigned long) -1;
+		} else {
+			return (unsigned long) -1;
+		}
 	}
 	//if (mFileCache.readSeek(inPos)) {
 	//	return inPos;
@@ -506,7 +526,12 @@
 	mIsFirstChunk = true;
 	mChunkRemains = 0;
 	mNumLeftovers = 0;
+	
+	//TODO::: Check if this should really be here
+	mFirstPass = true;
+
 	mCurrentAbsoluteReadPosition = 0;
+	mApparentReadPosition = 0;
 	//mSourceLocation = "";
 	//mContentLength = -1;
 }
@@ -538,28 +563,56 @@
 	{ //CRITICAL SECTION - PROTECTING STREAM BUFFER
 		CAutoLock locLock(mBufferLock);
 		
-		//debugLog<<"Read:"<<endl;
-		if((mMemoryBuffer->numBytesAvail() == 0) || mWasError) {
-			//debugLog<<"read : Can't read is error or eof"<<endl;
-			//return 0;
+		if (!mFirstPass && (mApparentReadPosition < mStreamStartBufferLength)) {
+			//In this case we have done a seekback and need to serve the request from the start buffer
+			unsigned long locBytesStillBuffered = mStreamStartBufferLength - mApparentReadPosition;
+
+			unsigned long locBytesToRead = (inNumBytes <= locBytesStillBuffered)	?	inNumBytes
+																					:	locBytesStillBuffered;
+
+			memcpy((void*)outBuffer, (const void*)(mStreamStartBuffer + mApparentReadPosition), locBytesToRead);
+			mApparentReadPosition += locBytesToRead;
+			locNumRead = locBytesToRead;
+
 		} else {
-			//debugLog<<"Reading from buffer"<<endl;
-			
-			//if (mMemoryBuffer->numBytesAvail() < inNumBytes) {
-			//	locNumRead = 0;
-			//} else {
+			//debugLog<<"Read:"<<endl;
+			if((mMemoryBuffer->numBytesAvail() == 0) || mWasError) {
+				//debugLog<<"read : Can't read is error or eof"<<endl;
+				//return 0;
+			} else {
+				//debugLog<<"Reading from buffer"<<endl;
+				
 				//Allow short reads from buffer
 				locNumRead = mMemoryBuffer->read((unsigned char*)outBuffer, inNumBytes, true);
-			//}
 
-			if (locNumRead > 0) {
-				debugLog<<locNumRead<<" bytes read from buffer at "<<mCurrentAbsoluteReadPosition<< endl;
+				//Handle the special start of stream buffer
+				if (mFirstPass && (locNumRead > 0) && (mStreamStartBufferLength < STREAM_START_BUFFER_SIZE)) {
+					//If we are still on the first pass (which means we are still parsing header info)
+					//	then we copy this into the start buffer
+
+					unsigned long locSpaceLeftInStartBuffer = STREAM_START_BUFFER_SIZE - mStreamStartBufferLength;
+
+					//There is at least 1 byte of space left
+					unsigned long locBytesToCopy = (locNumRead <= locSpaceLeftInStartBuffer)	?	locNumRead
+																								:	locSpaceLeftInStartBuffer;
+
+					memcpy((void*)(mStreamStartBuffer + mStreamStartBufferLength), (const void*)outBuffer, locBytesToCopy);
+					mStreamStartBufferLength += locBytesToCopy;
+				}
+
+
+				if (locNumRead > 0) {
+					debugLog<<locNumRead<<" bytes read from buffer at "<<mCurrentAbsoluteReadPosition<< endl;
+				}
+
+				mCurrentAbsoluteReadPosition += locNumRead;
+
+				//if (mMemoryBuffer->numBytesAvail() <= MEMORY_BUFFER_LOW_TIDE) {
+				//	CallWorker(THREAD_RUN);
+				//}
+				//return locNumRead;
+
 			}
-
-			//if (mMemoryBuffer->numBytesAvail() <= MEMORY_BUFFER_LOW_TIDE) {
-			//	CallWorker(THREAD_RUN);
-			//}
-			//return locNumRead;
 		}
 	} //END CRITICAL SECTION
 
@@ -567,6 +620,6 @@
 		CallWorker(THREAD_RUN);
 	}
 
-	mCurrentAbsoluteReadPosition += locNumRead;
+	
 	return locNumRead;
 }

Modified: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPStreamingFileSource.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPStreamingFileSource.h	2006-01-30 11:41:24 UTC (rev 10772)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPStreamingFileSource.h	2006-01-30 13:05:50 UTC (rev 10773)
@@ -96,6 +96,7 @@
 	unsigned char* mInterBuff;
 	unsigned long mNumLeftovers;
 	static	const unsigned long RECV_BUFF_SIZE = 1024;
+	static const unsigned long STREAM_START_BUFFER_SIZE = 32 * 1024;
 
 	//Fix for seekback on headers - since we only maintain a forward buffer. The seek back to start which occurs
 	//	right after the headers are processed, will generally trigger a stream reset. But an annodex server,
@@ -109,6 +110,12 @@
 	//If it is, then we can set a flag, and respond to read requests from this new buffer, up until the point
 	//	where the stream was before the seek, then switch back to serving out live streaming data.
 	unsigned long mCurrentAbsoluteReadPosition;
+	bool mFirstPass;
+
+	unsigned char* mStreamStartBuffer;
+	unsigned long mStreamStartBufferLength;
+
+	unsigned long mApparentReadPosition;
 	
 	//
 



More information about the commits mailing list