[xiph-commits] r6911 - in trunk/oggdsf/src/lib/core:

illiminable at dactyl.lonelymoon.com illiminable
Mon Jun 28 04:30:34 PDT 2004


directshow/dsfOggDemux ogg/libOOOgg
Message-ID: <20040628113034.7F7C79AAAB at dactyl.lonelymoon.com>

Author: illiminable
Date: Mon Jun 28 04:30:34 2004
New Revision: 6911

Modified:
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp
trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h
trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
Log:
* Untested build. Buggy.
* Fixed some threading problems with http streams
* Fixed a problem where the read interface can now return 0 bytes but not be eof or fail state. Needed to tweak some code so zero length buffers weren't written onto the buffer causing a fail state.


Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp	2004-06-28 09:52:07 UTC (rev 6910)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp	2004-06-28 11:30:32 UTC (rev 6911)
@@ -36,8 +36,11 @@
,	mIsEOF(false)
,	mIsOpen(false)
,	mSeenResponse(false)
+	,	mBufferLock(NULL)
{
+	mBufferLock = new CCritSec;
debugLog.open("G:\\httpdebug.log", ios_base::out);
+	fileDump.open("G:\\filedump.ogg", ios_base::out|ios_base::binary);
WORD locWinsockVersion = MAKEWORD(1,1);
WSADATA locWinsockData;
int locRet= 0;
@@ -59,6 +62,9 @@
HTTPFileSource::~HTTPFileSource(void)
{
debugLog<<"Winsock ended"<<endl;
+	debugLog.close();
+	fileDump.close();
+	delete mBufferLock;
WSACleanup();
}

@@ -84,21 +90,45 @@
break;
}

-		if (mSeenResponse) {
-			//Add to buffer
-			mStreamBuffer.write(locBuff, locNumRead);
-			debugLog<<"Added to buffer "<<locNumRead<<" bytes."<<endl;
-		} else {
-			string locTemp = locBuff;
-			size_t locPos = locTemp.find("\n\n");
-			if (locPos != string::npos) {
-				//Found the break
-				mSeenResponse = true;
-				mLastResponse = locTemp.substr(0, locPos);
-				mStreamBuffer.write(locBuff + locPos + 2, locNumRead - (locPos + 2));
-				debugLog<<"Added to Buffer "<<locNumRead - (locPos+2)<<" bytes... first after response."<<endl;
+		{//CRITICAL SECTION - PROTECTING BUFFER STATE
+			CAutoLock locLock(mBufferLock);
+			debugLog <<"Num Read = "<<locNumRead<<endl;
+			if (mSeenResponse) {
+				//Add to buffer
+				mStreamBuffer.write(locBuff, locNumRead);
+				debugLog<<"Added to buffer "<<locNumRead<<" bytes."<<endl;
+				//Dump to file
+				fileDump.write(locBuff, locNumRead);
+			} else {
+				string locTemp = locBuff;
+				debugLog<<"Binary follows... "<<endl<<locTemp<<endl;
+				size_t locPos = locTemp.find("\r\n\r\n");
+				if (locPos != string::npos) {
+					//Found the break
+					debugLog<<"locPos = "<<locPos<<endl;
+					mSeenResponse = true;
+					mLastResponse = locTemp.substr(0, locPos);
+					char* locBuff2 = locBuff + locPos + 4;  //View only - don't delete.
+					locTemp = locBuff2;
+					debugLog<<"Start of data follows"<<endl<<locTemp<<endl;
+					mStreamBuffer.write(locBuff2, locNumRead - (locPos + 4));
+					//Dump to file
+					fileDump.write(locBuff2, locNumRead - (locPos + 4));
+
+
+					if(mStreamBuffer.fail()) {
+						debugLog<<"Buffering failure..."<<endl;
+					}
+
+					size_t locG, locP;
+					locG = mStreamBuffer.tellg();
+					locP = mStreamBuffer.tellp();
+
+					debugLog << "Get : "<<locG<<" ---- Put : "<<locP<<endl;
+					debugLog<<"Added to Buffer "<<locNumRead - (locPos+4)<<" bytes... first after response."<<endl;
+				}
}
-		}
+		} //END CRITICAL SECTION
}

delete locBuff;
@@ -276,6 +306,17 @@
mSeenResponse = false;
mLastResponse = "";
debugLog<<"Open:"<<endl;
+	{ //CRITICAL SECTION - PROTECTING STREAM BUFFER
+		CAutoLock locLock(mBufferLock);
+		mStreamBuffer.flush();
+		mStreamBuffer.clear();
+		mStreamBuffer.seekg(0, ios_base::beg);
+		mStreamBuffer.seekp(0, ios_base::beg);
+		if(mStreamBuffer.fail()) {
+			debugLog<<"OPEN : Stream buffer already fucked"<<endl;
+		}
+	} //END CRITICAL SECTION
+
bool locIsOK = setupSocket(inSourceLocation);

if (!locIsOK) {
@@ -298,28 +339,43 @@
mWasError = false;
}
bool HTTPFileSource::isEOF() {
+	{ //CRITICAL SECTION - PROTECTING STREAM BUFFER
+		CAutoLock locLock(mBufferLock);
+		unsigned long locSizeBuffed = mStreamBuffer.tellp() - mStreamBuffer.tellg();

-	if ((mStreamBuffer.tellp() - mStreamBuffer.tellg() == 0) && mIsEOF) {
-		debugLog<<"It is EOF"<<endl;
-		return true;
-	} else {
-		debugLog<<"It's not EOF"<<endl;
-		return false;
-	}
+
+		debugLog<<"Amount Buffered = "<<locSizeBuffed<<endl;
+		if ((locSizeBuffed == 0) && mIsEOF) {
+			debugLog<<"It is EOF"<<endl;
+			return true;
+		} else {
+			debugLog<<"It's not EOF"<<endl;
+			return false;
+		}
+	} //END CRITICAL SECTION
+
}
unsigned long HTTPFileSource::read(char* outBuffer, unsigned long inNumBytes) {
//Reads from the buffer, will return 0 if nothing in buffer.
// If it returns 0 check the isEOF flag to see if it was the end of file or the network is just slow.
-	debugLog<<"Read:"<<endl;
-	if(isEOF() || mWasError) {
-		debugLog<<"Can't read is error or eof"<<endl;
-		return 0;
-	} else {
-		debugLog<<"Reading from buffer"<<endl;
-		mStreamBuffer.read(outBuffer, inNumBytes);
-		unsigned long locNumRead = mStreamBuffer.gcount();
-		debugLog<<locNumRead<<" bytes read from buffer"<<endl;
-		return locNumRead;
-	}

+	{ //CRITICAL SECTION - PROTECTING STREAM BUFFER
+		CAutoLock locLock(mBufferLock);
+
+		debugLog<<"Read:"<<endl;
+		if(isEOF() || mWasError) {
+			debugLog<<"Can't read is error or eof"<<endl;
+			return 0;
+		} else {
+			debugLog<<"Reading from buffer"<<endl;
+			mStreamBuffer.read(outBuffer, inNumBytes);
+			unsigned long locNumRead = mStreamBuffer.gcount();
+			if (locNumRead == 0) {
+				mStreamBuffer.clear();
+			}
+
+			debugLog<<locNumRead<<" bytes read from buffer"<<endl;
+			return locNumRead;
+		}
+	} //END CRITICAL SECTION
}

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h	2004-06-28 09:52:07 UTC (rev 6910)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h	2004-06-28 11:30:32 UTC (rev 6911)
@@ -78,8 +78,11 @@
stringstream mStreamBuffer;

fstream debugLog;
+	fstream fileDump;
bool mIsEOF;
bool mWasError;
bool mIsOpen;
bool mSeenResponse;
+
+	CCritSec* mBufferLock;
};

Modified: trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-06-28 09:52:07 UTC (rev 6910)
+++ trunk/oggdsf/src/lib/core/ogg/libOOOgg/OggDataBuffer.cpp	2004-06-28 11:30:32 UTC (rev 6911)
@@ -114,11 +114,14 @@
}

bool OggDataBuffer::feed(const char* inData, unsigned long inNumBytes) {
-
-	mStream.write(inData, inNumBytes);
-	//FIX ::: Need error checking.
+	if (inNumBytes != 0) {
+		mStream.write(inData, inNumBytes);
+		//FIX ::: Need error checking.

-	return processBuffer();
+		return processBuffer();
+	} else {
+		return true;
+	}


}
@@ -178,9 +181,12 @@
locIsLastSeg = (locNumSegs - 1 == i);
if ( (locSegTable[i] != 255) || locIsLastSeg ) {

+			//MEMORY LEAK
locBuff = new unsigned char[locCurrPackSize];
mStream.read((char*)(locBuff), locCurrPackSize);
+
pendingPage->addPacket( new StampedOggPacket(locBuff, locCurrPackSize, (locSegTable[i] != 255), 0, pendingPage->header()->GranulePos()->value(), StampedOggPacket::OGG_END_ONLY ) );
+
//locPacketOffset += locCurrPackSize;
locCurrPackSize = 0;
}



More information about the commits mailing list