[xiph-commits] r7625 - trunk/oggdsf/src/lib/core/directshow/dsfOggDemux

illiminable at motherfish-iii.xiph.org illiminable at motherfish-iii.xiph.org
Tue Aug 24 08:35:23 PDT 2004


Author: illiminable
Date: 2004-08-24 08:35:23 -0700 (Tue, 24 Aug 2004)
New Revision: 7625

Modified:
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/IFilterDataSource.h
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/SingleMediaFileCache.cpp
   trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/SingleMediaFileCache.h
Log:
* Fleshed out cache system. Ready for testing...

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp	2004-08-24 15:08:42 UTC (rev 7624)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.cpp	2004-08-24 15:35:23 UTC (rev 7625)
@@ -80,8 +80,12 @@
 			debugLog <<"Num Read = "<<locNumRead<<endl;
 			if (mSeenResponse) {
 				//Add to buffer
-				mStreamBuffer.write(locBuff, locNumRead);
-				debugLog<<"Added to buffer "<<locNumRead<<" bytes."<<endl;
+				bool locWriteOK = mFileCache.write((const unsigned char*)locBuff, locNumRead);
+				if (locWriteOK) {
+					debugLog<<"Added to cache "<<locNumRead<<" bytes."<<endl;
+				} else {
+					debugLog<<"Write to cache failed.."<<endl;
+				}
 				//Dump to file
 				//fileDump.write(locBuff, locNumRead);
 			} else {
@@ -96,21 +100,25 @@
 					char* locBuff2 = locBuff + locPos + 4;  //View only - don't delete.
 					locTemp = locBuff2;
 					//debugLog<<"Start of data follows"<<endl<<locTemp<<endl;
-					mStreamBuffer.write(locBuff2, (std::streamsize)(locNumRead - (locPos + 4)));
+					bool locWriteOK = mFileCache.write((const unsigned char*)locBuff2, (locNumRead - (locPos + 4)));
+
 					//Dump to file
 					//fileDump.write(locBuff2, locNumRead - (locPos + 4));
 					
 
-					if(mStreamBuffer.fail()) {
+					if(locWriteOK) {
+						debugLog<<"Added to Buffer "<<locNumRead - (locPos+4)<<" bytes... first after response."<<endl;
+						
+					} else {
 						debugLog<<"Buffering failure..."<<endl;
 					}
 
-					size_t locG, locP;
-					locG = mStreamBuffer.tellg();
-					locP = mStreamBuffer.tellp();
+					//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;
+					//debugLog << "Get : "<<locG<<" ---- Put : "<<locP<<endl;
+					
 				}
 			}
 		} //END CRITICAL SECTION
@@ -150,8 +158,13 @@
 	//Close the socket down
 	//Open up a new one to the same place.
 	//Make the partial content request.
-	debugLog<<"Seek ::::: EOROR NOT IMPL"<<endl;
-	return 0;
+	debugLog<<"Seeking to "<<inPos<<endl;
+	if (mFileCache.readSeek(inPos)) {
+		return inPos;
+	} else {
+		return (unsigned long) -1;
+	}
+	
 }
 
 
@@ -172,15 +185,18 @@
 	//
 	mSeenResponse = false;
 	mLastResponse = "";
-	debugLog<<"Open:"<<endl;
+	debugLog<<"Open: "<<inSourceLocation<<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;
+		//mStreamBuffer.flush();
+		//mStreamBuffer.clear();
+		//mStreamBuffer.seekg(0, ios_base::beg);
+		//mStreamBuffer.seekp(0, ios_base::beg);
+
+		//TODO::: Get rid of this path.
+		if(mFileCache.open("g:\\logs\\filecache.dat")) {
+			debugLog<<"OPEN : Can't open file cache"<<endl;
 		}
 	} //END CRITICAL SECTION
 
@@ -193,6 +209,8 @@
 	}
 
 	debugLog<<"Sending request..."<<endl;
+
+	//How is filename already set ??
 	httpRequest(assembleRequest(mFileName));
 	debugLog<<"Socket ok... starting thread"<<endl;
 	locIsOK = startThread();
@@ -208,10 +226,10 @@
 bool HTTPFileSource::isEOF() {
 	{ //CRITICAL SECTION - PROTECTING STREAM BUFFER
 		CAutoLock locLock(mBufferLock);
-		unsigned long locSizeBuffed = mStreamBuffer.tellp() - mStreamBuffer.tellg();
+		unsigned long locSizeBuffed = mFileCache.bytesAvail();;
 	
 
-		debugLog<<"isEOF : Amount Buffered = "<<locSizeBuffed<<endl;
+		debugLog<<"isEOF : Amount Buffered avail = "<<locSizeBuffed<<endl;
 		if ((locSizeBuffed == 0) && mIsEOF) {
 			debugLog<<"isEOF : It is EOF"<<endl;
 			return true;
@@ -230,16 +248,16 @@
 		CAutoLock locLock(mBufferLock);
 		
 		debugLog<<"Read:"<<endl;
-		if(isEOF() || mWasError) {
+		if(mIsEOF || mWasError) {
 			debugLog<<"read : 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) {
+			
+			unsigned long locNumRead = mFileCache.read((unsigned char*)outBuffer, inNumBytes);
+	/*		if (locNumRead == 0) {
 				mStreamBuffer.clear();
-			}
+			}*/
 
 			debugLog<<locNumRead<<" bytes read from buffer"<<endl;
 			return locNumRead;

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h	2004-08-24 15:08:42 UTC (rev 7624)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/HTTPFileSource.h	2004-08-24 15:35:23 UTC (rev 7625)
@@ -33,6 +33,7 @@
 #include <winsock.h>
 //#include <stdlib.h>
 #include "HTTPSocket.h"
+#include "SingleMediaFileCache.h"
 #include <string>
 #include <sstream>
 #include <fstream>
@@ -70,7 +71,8 @@
 	bool HTTPFileSource::startThread();
 	void DataProcessLoop();
 
-	stringstream mStreamBuffer;
+	//stringstream mStreamBuffer;
+	SingleMediaFileCache mFileCache;
 
 	fstream debugLog;
 	//fstream fileDump;

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/IFilterDataSource.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/IFilterDataSource.h	2004-08-24 15:08:42 UTC (rev 7624)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/IFilterDataSource.h	2004-08-24 15:35:23 UTC (rev 7625)
@@ -40,4 +40,5 @@
 	virtual void clear() = 0;
 	virtual bool isEOF() = 0;
 	virtual unsigned long read(char* outBuffer, unsigned long inNumBytes) = 0;
+	
 };

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/SingleMediaFileCache.cpp
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/SingleMediaFileCache.cpp	2004-08-24 15:08:42 UTC (rev 7624)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/SingleMediaFileCache.cpp	2004-08-24 15:35:23 UTC (rev 7625)
@@ -2,6 +2,8 @@
 #include ".\singlemediafilecache.h"
 
 SingleMediaFileCache::SingleMediaFileCache(void)
+	:	mBytesWritten(0)
+	,	mIsComplete(false)
 {
 }
 
@@ -36,4 +38,15 @@
 	} else {
 		return false;
 	}
-}
\ No newline at end of file
+}
+
+unsigned long SingleMediaFileCache::totalBytes() {
+	return mBytesWritten;
+}
+unsigned long SingleMediaFileCache::bytesAvail() {
+	if (!mLocalFile.fail() && mBytesWritten > 0) {
+		return mBytesWritten - mLocalFile.tellg();
+	} else {
+		return 0;
+	}
+}

Modified: trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/SingleMediaFileCache.h
===================================================================
--- trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/SingleMediaFileCache.h	2004-08-24 15:08:42 UTC (rev 7624)
+++ trunk/oggdsf/src/lib/core/directshow/dsfOggDemux/SingleMediaFileCache.h	2004-08-24 15:35:23 UTC (rev 7625)
@@ -23,6 +23,9 @@
 	bool write(const unsigned char* inBuff, unsigned long inBuffSize);
 	unsigned long read(unsigned char* outBuff, unsigned long inBuffSize);
 	bool readSeek(unsigned long inSeekPos);
+	unsigned long totalBytes();
+	unsigned long bytesAvail();
+
 protected:
 	fstream mLocalFile;
 



More information about the commits mailing list