[matroska] r1090 - in trunk/libebml: ebml src src/platform/win32

[email protected]
Newsgroups gmane.comp.multimedia.matroska.cvs
Message-ID <[email protected]>
Author: robux4
Date: 2005-03-16 15:47:59 +0300 (Wed, 16 Mar 2005)
New Revision: 1090

Modified:
   trunk/libebml/ebml/StdIOCallback.h
   trunk/libebml/src/StdIOCallback.cpp
   trunk/libebml/src/platform/win32/WinIOCallback.cpp
   trunk/libebml/src/platform/win32/WinIOCallback.h
Log:
libebml: cache the stream position for StdIOCallback and WinIOCallback (not tested)

Modified: trunk/libebml/ebml/StdIOCallback.h
===================================================================
--- trunk/libebml/ebml/StdIOCallback.h	2005-03-16 12:28:14 UTC (rev 1089)
+++ trunk/libebml/ebml/StdIOCallback.h	2005-03-16 12:47:59 UTC (rev 1090)
@@ -66,6 +66,7 @@
 {
     private:
     	FILE*File;
+		uint64 mCurrentPosition;
 
     public:
 //	StdIOCallback(const char*Path,const char*Mode);

Modified: trunk/libebml/src/StdIOCallback.cpp
===================================================================
--- trunk/libebml/src/StdIOCallback.cpp	2005-03-16 12:28:14 UTC (rev 1089)
+++ trunk/libebml/src/StdIOCallback.cpp	2005-03-16 12:47:59 UTC (rev 1090)
@@ -92,6 +92,7 @@
 		throw CRTError(Msg.str());
 #endif // GCC2
 	}
+	mCurrentPosition = 0;
 }
 
 
@@ -107,6 +108,7 @@
 	assert(File!=0);
 	
 	size_t result = fread(Buffer, 1, Size, File);
+	mCurrentPosition += result;
 	return result;
 }
 
@@ -134,19 +136,33 @@
 		throw CRTError(Msg.str());
 #endif // GCC2
 	}
+	switch ( Mode )
+	{
+		case SEEK_CUR:
+			mCurrentPosition += Offset;
+			break;
+		case SEEK_END:
+			mCurrentPosition = ftell(File);
+			break;
+		case SEEK_SET:
+			mCurrentPosition = Offset;
+			break;
+	}
 }
 
 size_t StdIOCallback::write(const void*Buffer,size_t Size)
 {
 	assert(File!=0);
-
-	return fwrite(Buffer,1,Size,File);
+	uint32 Result = fwrite(Buffer,1,Size,File);
+	mCurrentPosition += Result;
+	return result;
 }
 
 uint64 StdIOCallback::getFilePointer()
 {
 	assert(File!=0);
 
+#if 0
 	long Result=ftell(File);
 	if(Result<0)
 	{
@@ -156,8 +172,9 @@
 		throw CRTError(Msg.str());
 #endif // GCC2
 	}
+#endif
 
-	return Result;
+	return mCurrentPosition;
 }
 
 void StdIOCallback::close()

Modified: trunk/libebml/src/platform/win32/WinIOCallback.cpp
===================================================================
--- trunk/libebml/src/platform/win32/WinIOCallback.cpp	2005-03-16 12:28:14 UTC (rev 1089)
+++ trunk/libebml/src/platform/win32/WinIOCallback.cpp	2005-03-16 12:47:59 UTC (rev 1090)
@@ -110,6 +110,7 @@
 			return mOk = false;
 		}
 	}
+	mCurrentPosition = 0;
 
 	EBML_TRACE("Successfully opened file \"%hs\" in mode %d. The handle is %p\n", Path, aMode, mFile);
 
@@ -191,6 +192,7 @@
 			return mOk = false;
 		}		
 	}
+	mCurrentPosition = 0;
 
 	EBML_TRACE("Successfully opened file \"%S\" in mode %d. The handle is %p\n", Path, aMode, mFile);
 	return mOk = true;
@@ -209,11 +211,15 @@
 	if (!mFile) {
 		return 0;
 	}
+	
+	return mCurrentPosition;
+#if 0
 	LONG High = 0;
 	DWORD Low = SetFilePointer(mFile, 0, &High, FILE_CURRENT);
 	if ( (Low==INVALID_SET_FILE_POINTER) && (GetLastError()!=NO_ERROR) )
 		return static_cast<uint64>(-1);
 	return ((uint64(High)<<32) | Low);
+#endif
 }
 
 void WinIOCallback::setFilePointer(int64 Offset, seek_mode Mode)
@@ -236,7 +242,8 @@
 	}
 
 	LONG High = LONG(Offset>>32);
-	SetFilePointer(mFile, LONG(Offset & 0xffffffff), &High, Method);
+	mCurrentPosition = SetFilePointer(mFile, LONG(Offset & 0xffffffff), &High, Method);
+	mCurrentPosition += (High<<32);
 }
 
 uint32 WinIOCallback::read(void*Buffer,size_t Size)
@@ -245,6 +252,7 @@
 	if (!ReadFile(mFile, Buffer, Size, &BytesRead, NULL)) {
 		return 0;
 	}
+	mCurrentPosition += BytesRead;
 	return BytesRead;
 }
 
@@ -254,6 +262,7 @@
 	if (!WriteFile(mFile, Buffer, Size, &BytesWriten, NULL)) {
 		return 0;
 	}
+	mCurrentPosition += BytesWriten;
 	return BytesWriten;
 }
 

Modified: trunk/libebml/src/platform/win32/WinIOCallback.h
===================================================================
--- trunk/libebml/src/platform/win32/WinIOCallback.h	2005-03-16 12:28:14 UTC (rev 1089)
+++ trunk/libebml/src/platform/win32/WinIOCallback.h	2005-03-16 12:47:59 UTC (rev 1090)
@@ -65,6 +65,7 @@
 protected:
 	bool mOk;
 	std::string mLastErrorStr;
+	uint64 mCurrentPosition;
 
 	HANDLE mFile;
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.