[xiph-commits] r10251 - in branches/oggdsf_new_demux:
sln/oggdsf_all src/lib/core/directshow/dsfOggDemux2
illiminable at svn.xiph.org
illiminable at svn.xiph.org
Sat Oct 22 09:30:54 PDT 2005
Author: illiminable
Date: 2005-10-22 09:30:36 -0700 (Sat, 22 Oct 2005)
New Revision: 10251
Added:
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/DataSourceFactory.cpp
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/DataSourceFactory.h
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/FilterFileSource.cpp
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/FilterFileSource.h
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPFileSource.cpp
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPFileSource.h
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPSocket.cpp
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPSocket.h
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/IFilterDataSource.h
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/SingleMediaFileCache.cpp
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/SingleMediaFileCache.h
Modified:
branches/oggdsf_new_demux/sln/oggdsf_all/oggdsf_all.sln
branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/dsfOggDemux2.vcproj
Log:
* Copy over the DataSourceFactory, File and HTTP sources, and HTTP cache, that code was all ok.
Modified: branches/oggdsf_new_demux/sln/oggdsf_all/oggdsf_all.sln
===================================================================
--- branches/oggdsf_new_demux/sln/oggdsf_all/oggdsf_all.sln 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/sln/oggdsf_all/oggdsf_all.sln 2005-10-22 16:30:36 UTC (rev 10251)
@@ -1201,6 +1201,7 @@
ProjectSection(ProjectDependencies) = postProject
{223ACC19-608E-4E1B-A054-067F0CACB272} = {223ACC19-608E-4E1B-A054-067F0CACB272}
{EA7091BB-9906-41DF-9738-F4858A136086} = {EA7091BB-9906-41DF-9738-F4858A136086}
+ {2DA569EC-3E22-4BC9-A242-C7A56EB9C6F4} = {2DA569EC-3E22-4BC9-A242-C7A56EB9C6F4}
EndProjectSection
EndProject
Global
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/DataSourceFactory.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/DataSourceFactory.cpp 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/DataSourceFactory.cpp 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,84 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#include "stdafx.h"
+#include "datasourcefactory.h"
+
+DataSourceFactory::DataSourceFactory(void)
+{
+}
+
+DataSourceFactory::~DataSourceFactory(void)
+{
+}
+
+IFilterDataSource* DataSourceFactory::createDataSource(string inSourceLocation) {
+ string locType = identifySourceType(inSourceLocation);
+
+ if(locType.length() == 1) {
+ //File...
+ return new FilterFileSource;
+ } else if (locType == "\\\\") {
+ //Network share...
+ return new FilterFileSource;
+ } else if (locType == "http") {
+ //Http stream
+ return new HTTPFileSource;
+ } else {
+ //Something else
+ return NULL;
+ }
+}
+
+string DataSourceFactory::identifySourceType(string inSourceLocation) {
+ size_t locPos = inSourceLocation.find(':');
+ if (locPos == string::npos) {
+ //No colon... not a normal file. See if it's a network share...
+
+ //Make sure it's long enough...
+ if (inSourceLocation.length() > 2) {
+ string retStr = inSourceLocation.substr(0,2);
+ if (retStr == "\\\\") {
+ //A "\\" is a network share
+ return retStr;
+ } else {
+ //Not a network share.
+ return "";
+ }
+ } else {
+ //Too short
+ return "";
+ }
+ } else {
+ string retStr = inSourceLocation.substr(0,locPos);
+ return retStr;
+ }
+
+}
\ No newline at end of file
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/DataSourceFactory.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/DataSourceFactory.h 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/DataSourceFactory.h 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,43 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#pragma once
+#include "IFilterDataSource.h"
+#include "FilterFileSource.h"
+#include "HTTPFileSource.h"
+class OGG_DEMUX2_API DataSourceFactory
+{
+public:
+ DataSourceFactory(void);
+ ~DataSourceFactory(void);
+
+ static IFilterDataSource* createDataSource(string inSourceLocation);
+ static string identifySourceType(string inSourceLocation);
+};
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/FilterFileSource.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/FilterFileSource.cpp 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/FilterFileSource.cpp 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,63 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#include "stdafx.h"
+#include "filterfilesource.h"
+
+FilterFileSource::FilterFileSource(void)
+{
+}
+
+FilterFileSource::~FilterFileSource(void)
+{
+ mSourceFile.close();
+}
+
+unsigned long FilterFileSource::seek(unsigned long inPos) {
+ mSourceFile.seekg(inPos, ios_base::beg);
+ return mSourceFile.tellg();
+}
+void FilterFileSource::close() {
+ mSourceFile.close();
+}
+bool FilterFileSource::open(string inSourceLocation) {
+ mSourceFile.open(inSourceLocation.c_str(), ios_base::in|ios_base::binary);
+ return mSourceFile.is_open();
+}
+void FilterFileSource::clear() {
+ mSourceFile.clear();
+}
+bool FilterFileSource::isEOF() {
+ return mSourceFile.eof();
+}
+unsigned long FilterFileSource::read(char* outBuffer, unsigned long inNumBytes) {
+ mSourceFile.read(outBuffer, inNumBytes);
+ return mSourceFile.gcount();
+}
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/FilterFileSource.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/FilterFileSource.h 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/FilterFileSource.h 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,58 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#pragma once
+
+#include <fstream>
+#include <string>
+
+using namespace std;
+#include "IFilterDataSource.h"
+class OGG_DEMUX2_API FilterFileSource
+ : public IFilterDataSource
+{
+public:
+ FilterFileSource(void);
+ virtual ~FilterFileSource(void);
+
+ //IFilterDataSource Interface
+ virtual unsigned long seek(unsigned long inPos);
+ virtual void close();
+ virtual bool open(string inSourceLocation);
+ virtual void clear();
+ virtual bool isEOF();
+ virtual bool isError() { return false; }
+ virtual unsigned long read(char* outBuffer, unsigned long inNumBytes);
+ virtual string shouldRetryAt() { return ""; }
+ //
+
+protected:
+ fstream mSourceFile;
+};
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPFileSource.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPFileSource.cpp 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPFileSource.cpp 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,463 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#include "stdafx.h"
+#include "httpfilesource.h"
+
+//#define OGGCODECS_LOGGING
+HTTPFileSource::HTTPFileSource(void)
+ : mBufferLock(NULL)
+ , mIsChunked(false)
+ , mIsFirstChunk(true)
+ , mChunkRemains(0)
+ , mNumLeftovers(0)
+{
+ mBufferLock = new CCritSec;
+#ifdef OGGCODECS_LOGGING
+ debugLog.open("d:\\zen\\logs\\htttp.log", ios_base::out | ios_base::app);
+ fileDump.open("d:\\zen\\logs\\filedump.ogg", ios_base::out|ios_base::binary);
+ rawDump.open("D:\\zen\\logs\\rawdump.out", ios_base::out|ios_base::binary);
+#endif
+ mInterBuff = new unsigned char[RECV_BUFF_SIZE* 2];
+
+}
+
+HTTPFileSource::~HTTPFileSource(void)
+{
+ //debugLog<<"About to close socket"<<endl;
+ close();
+ //debugLog<<"Winsock ended"<<endl;
+#ifdef OGGCODECS_LOGGING
+ debugLog.close();
+ fileDump.close();
+ rawDump.close();
+#endif
+ delete mBufferLock;
+ delete mInterBuff;
+}
+
+void HTTPFileSource::unChunk(unsigned char* inBuff, unsigned long inNumBytes)
+{
+
+ //This method is a bit rough and ready !!
+ ASSERT(inNumBytes > 2);
+ rawDump.write((char*)inBuff, inNumBytes);
+ debugLog<<"UnChunk"<<endl;
+ unsigned long locNumBytesLeft = inNumBytes;
+
+ memcpy((void*)(mInterBuff + mNumLeftovers), (const void*)inBuff, inNumBytes);
+ locNumBytesLeft += mNumLeftovers;
+ mNumLeftovers = 0;
+ unsigned char* locWorkingBuffPtr = mInterBuff;
+
+ //debugLog<<"inNumBytes = "<<inNumBytes<<endl;
+
+ while (locNumBytesLeft > 8) {
+ //debugLog<<"---"<<endl;
+ //debugLog<<"Bytes left = "<<locNumBytesLeft<<endl;
+ //debugLog<<"ChunkRemaining = "<<mChunkRemains<<endl;
+
+ if (mChunkRemains == 0) {
+ //debugLog<<"Zero bytes of chunk remains"<<endl;
+
+ //Assign to a string for easy manipulation of the hex size
+ string locTemp;
+
+ if (mIsFirstChunk) {
+ //debugLog<<"It's the first chunk"<<endl;
+ mIsFirstChunk = false;
+ locTemp = (char*)locWorkingBuffPtr;
+ } else {
+ //debugLog<<"Not the first chunk"<<endl;
+ //debugLog<<"Skip bytes = "<<(int)locWorkingBuffPtr[0]<<(int)locWorkingBuffPtr[1]<<endl;
+ locTemp = (char*)(locWorkingBuffPtr + 2);
+ locWorkingBuffPtr+=2;
+ locNumBytesLeft -= 2;
+ }
+
+ /* if (mLeftOver != "") {
+ debugLog<<"Sticking the leftovers back together..."<<endl;
+ locTemp = mLeftOver + locTemp;
+ mLeftOver = "";
+ }*/
+
+ size_t locChunkSizePos = locTemp.find("\r\n");
+
+
+ if (locChunkSizePos != string::npos) {
+ //debugLog<<"Found the size bytes "<<endl;
+ //Get a string representation of the hex string that tells us the size of the chunk
+ string locChunkSizeStr = locTemp.substr(0, locChunkSizePos);
+ //debugLog<<"Sizingbuytes " << locChunkSizeStr<<endl;
+ char* locDummyPtr = NULL;
+
+ //Convert it to a number
+ mChunkRemains = strtol(locChunkSizeStr.c_str(), &locDummyPtr, 16);
+
+ //debugLog<<"Chunk reamining "<<mChunkRemains<<endl;
+ //The size of the crlf 's and the chunk size value
+ unsigned long locGuffSize = (unsigned long)(locChunkSizeStr.size() + 2);
+ locWorkingBuffPtr += locGuffSize;
+ locNumBytesLeft -= locGuffSize;
+ } else {
+ //debugLog<<"************************************** "<<endl;
+
+
+ }
+ }
+
+ //This is the end of file
+ if (mChunkRemains == 0) {
+ //debugLog<<"EOF"<<endl;
+ return;
+ }
+
+ //If theres less bytes than the remainder of the chunk
+ if (locNumBytesLeft < mChunkRemains) {
+ //debugLog<<"less bytes remain than the chunk needs"<<endl;
+
+ mFileCache.write((const unsigned char*)locWorkingBuffPtr, locNumBytesLeft );
+ fileDump.write((char*)locWorkingBuffPtr, locNumBytesLeft);
+ locWorkingBuffPtr += locNumBytesLeft;
+ mChunkRemains -= locNumBytesLeft;
+ locNumBytesLeft = 0;
+ } else {
+ //debugLog<<"more bytes remain than the chunk needs"<<endl;
+ mFileCache.write((const unsigned char*)locWorkingBuffPtr, mChunkRemains );
+ fileDump.write((char*)locWorkingBuffPtr, mChunkRemains);
+ locWorkingBuffPtr += mChunkRemains;
+ locNumBytesLeft -= mChunkRemains;
+ mChunkRemains = 0;
+ }
+
+ }
+
+ if (locNumBytesLeft != 0) {
+ //debugLog<<"There is a non- zero amount of bytes leftover... buffer them up for next time..."<<endl;
+ memcpy((void*)mInterBuff, (const void*)locWorkingBuffPtr, locNumBytesLeft);
+ mNumLeftovers = locNumBytesLeft;
+ }
+}
+void HTTPFileSource::DataProcessLoop() {
+ //debugLog<<"DataProcessLoop: "<<endl;
+ int locNumRead = 0;
+ char* locBuff = NULL;
+ DWORD locCommand = 0;
+ bool locSeenAny = false;
+ debugLog<<"Starting dataprocessloop"<<endl;
+
+ locBuff = new char[RECV_BUFF_SIZE];
+
+ while(true) {
+ if(CheckRequest(&locCommand) == TRUE) {
+ debugLog<<"Thread Data Process loop received breakout signal..."<<endl;
+ delete[] locBuff;
+ return;
+ }
+ //debugLog<<"About to call recv"<<endl;
+ locNumRead = recv(mSocket, locBuff, RECV_BUFF_SIZE, 0);
+ //debugLog<<"recv complete"<<endl;
+ if (locNumRead == SOCKET_ERROR) {
+ int locErr = WSAGetLastError();
+ debugLog<<"Socket error receiving - Err No = "<<locErr<<endl;
+ mWasError = true;
+ break;
+ }
+
+ if (locNumRead == 0) {
+ debugLog<<"Read last bytes..."<<endl;
+ mIsEOF = true;
+ delete[] locBuff;
+ return;
+ }
+
+ {//CRITICAL SECTION - PROTECTING BUFFER STATE
+ CAutoLock locLock(mBufferLock);
+ //debugLog <<"Num Read = "<<locNumRead<<endl;
+ if (mSeenResponse) {
+ //Add to buffer
+
+ if (mIsChunked) {
+ unChunk((unsigned char*)locBuff, locNumRead);
+ } else {
+ mFileCache.write((const unsigned char*)locBuff, locNumRead);
+ }
+
+ //Dump to file
+ //fileDump.write(locBuff, locNumRead);
+ } else {
+ //if (!locSeenAny) {
+ // locSeenAny = true;
+ // //Start of response
+ // if (locBuff[0] != '2') {
+ // mWasError = true;
+ // delete[] locBuff;
+ // return;
+ // }
+ //}
+ 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);
+ debugLog<<"HTTP Response:"<<endl;
+ debugLog<<mLastResponse<<endl;
+
+ unsigned short locResponseCode = getHTTPResponseCode(mLastResponse);
+
+ mRetryAt = "";
+ if (locResponseCode == 301) {
+ size_t locLocPos = mLastResponse.find("Location: ");
+ if (locLocPos != string::npos) {
+ locLocPos += 10;
+ size_t locEndPos = mLastResponse.find("\r", locLocPos);
+ if (locEndPos != string::npos) {
+ if (locEndPos > locLocPos) {
+ mRetryAt = mLastResponse.substr(locLocPos, locEndPos - locLocPos);
+ debugLog<<"Retry URL = "<<mRetryAt<<endl;
+ }
+ }
+ }
+
+ debugLog<<"Setting error to true"<<endl;
+ mIsEOF = true;
+ mWasError = true;
+ //close();
+ } else if (locResponseCode >= 300) {
+ debugLog<<"Setting error to true"<<endl;
+ mIsEOF = true;
+ mWasError = true;
+ //close();
+ }
+
+ if (locTemp.find("Transfer-Encoding: chunked") != string::npos) {
+ mIsChunked = true;
+ }
+
+ char* locBuff2 = locBuff + locPos + 4; //View only - don't delete.
+ locTemp = locBuff2;
+
+ if (mIsChunked) {
+ if (locNumRead - locPos - 4 > 0) {
+ unChunk((unsigned char*)locBuff2, locNumRead - locPos - 4);
+ }
+ } else {
+ //debugLog<<"Start of data follows"<<endl<<locTemp<<endl;
+ if (locNumRead - locPos - 4 > 0) {
+ mFileCache.write((const unsigned char*)locBuff2, (locNumRead - (locPos + 4)));
+ }
+ }
+ }
+ }
+ } //END CRITICAL SECTION
+ }
+
+ delete[] locBuff;
+}
+
+unsigned short HTTPFileSource::getHTTPResponseCode(string inHTTPResponse)
+{
+ size_t locPos = inHTTPResponse.find(" ");
+ if (locPos != string::npos) {
+ string locCodeString = inHTTPResponse.substr(locPos + 1, 3);
+ try {
+ unsigned short locCode = (unsigned short)StringHelper::stringToNum(locCodeString);
+ return locCode;
+ } catch(...) {
+ return 0;
+ }
+ } else {
+ return 0;
+ }
+}
+string HTTPFileSource::shouldRetryAt()
+{
+ return mRetryAt;
+}
+
+DWORD HTTPFileSource::ThreadProc(void) {
+ //debugLog<<"ThreadProc:"<<endl;
+ while(true) {
+ DWORD locThreadCommand = GetRequest();
+
+ switch(locThreadCommand) {
+ case THREAD_EXIT:
+
+ Reply(S_OK);
+ return S_OK;
+
+ case THREAD_RUN:
+
+ Reply(S_OK);
+ DataProcessLoop();
+ break;
+ }
+
+
+ }
+ return S_OK;
+}
+unsigned long HTTPFileSource::seek(unsigned long inPos) {
+ //Close the socket down
+ //Open up a new one to the same place.
+ //Make the partial content request.
+ //debugLog<<"Seeking to "<<inPos<<endl;
+ if (mFileCache.readSeek(inPos)) {
+ return inPos;
+ } else {
+ return (unsigned long) -1;
+ }
+
+}
+
+
+void HTTPFileSource::close() {
+ //Killing thread
+ //debugLog<<"HTTPFileSource::close()"<<endl;
+ if (ThreadExists() == TRUE) {
+ //debugLog<<"Calling Thread to EXIT"<<endl;
+ CallWorker(THREAD_EXIT);
+ //debugLog<<"Killing thread..."<<endl;
+ Close();
+ //debugLog<<"After Close called on CAMThread"<<endl;
+ }
+
+
+
+ //debugLog<<"Closing socket..."<<endl;
+ //Close the socket down.
+ closeSocket();
+}
+
+bool HTTPFileSource::startThread() {
+ if (ThreadExists() == FALSE) {
+ Create();
+ }
+ CallWorker(THREAD_RUN);
+ return true;
+}
+bool HTTPFileSource::open(string inSourceLocation) {
+ //Open network connection and start feeding data into a buffer
+ //
+ mSeenResponse = false;
+ mLastResponse = "";
+ //debugLog<<"Open: "<<inSourceLocation<<endl;
+
+ { //CRITICAL SECTION - PROTECTING STREAM BUFFER
+ CAutoLock locLock(mBufferLock);
+
+ //Init rand number generator
+ LARGE_INTEGER locTicks;
+ QueryPerformanceCounter(&locTicks);
+ srand((unsigned int)locTicks.LowPart);
+
+ int locRand = rand();
+
+ string locCacheFileName = getenv("TEMP");
+ //debugLog<<"Temp = "<<locCacheFileName<<endl;
+ locCacheFileName += "\\filecache";
+
+ locCacheFileName += StringHelper::numToString(locRand);
+ locCacheFileName += ".ogg";
+ //debugLog<<"Cache file = "<<locCacheFileName<<endl;
+ if(mFileCache.open(locCacheFileName)) {
+ //debugLog<<"OPEN : Cach file opened"<<endl;
+ }
+ } //END CRITICAL SECTION
+
+ bool locIsOK = setupSocket(inSourceLocation);
+
+ if (!locIsOK) {
+ //debugLog<<"Setup socket FAILED"<<endl;
+ closeSocket();
+ return false;
+ }
+
+ //debugLog<<"Sending request..."<<endl;
+
+ //How is filename already set ??
+ httpRequest(assembleRequest(mFileName));
+ //debugLog<<"Socket ok... starting thread"<<endl;
+ locIsOK = startThread();
+
+
+ return locIsOK;
+}
+void HTTPFileSource::clear() {
+ //Reset flags.
+ debugLog<<"Setting error to false";
+ mIsEOF = false;
+ mWasError = false;
+ mRetryAt = "";
+}
+bool HTTPFileSource::isError()
+{
+ return mWasError;
+}
+bool HTTPFileSource::isEOF() {
+ { //CRITICAL SECTION - PROTECTING STREAM BUFFER
+ CAutoLock locLock(mBufferLock);
+ unsigned long locSizeBuffed = mFileCache.bytesAvail();;
+
+ //debugLog<<"isEOF : Amount Buffered avail = "<<locSizeBuffed<<endl;
+ if ((locSizeBuffed == 0) && mIsEOF) {
+ //debugLog<<"isEOF : It is EOF"<<endl;
+ return true;
+ } else {
+ //debugLog<<"isEOF : 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.
+
+ { //CRITICAL SECTION - PROTECTING STREAM BUFFER
+ CAutoLock locLock(mBufferLock);
+
+ //debugLog<<"Read:"<<endl;
+ if((mFileCache.bytesAvail() == 0) || mWasError) {
+ //debugLog<<"read : Can't read is error or eof"<<endl;
+ return 0;
+ } else {
+ debugLog<<"Reading from buffer"<<endl;
+
+ unsigned long locNumRead = mFileCache.read((unsigned char*)outBuffer, inNumBytes);
+
+ //debugLog<<locNumRead<<" bytes read from buffer"<<endl;
+ return locNumRead;
+ }
+ } //END CRITICAL SECTION
+}
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPFileSource.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPFileSource.h 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPFileSource.h 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,92 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#pragma once
+#include "oggdllstuff.h"
+
+#include "HTTPSocket.h"
+#include "SingleMediaFileCache.h"
+#include "IFilterDataSource.h"
+#include <string>
+#include <sstream>
+#include <fstream>
+
+using namespace std;
+
+class OGG_DEMUX2_API HTTPFileSource
+ : public IFilterDataSource
+ , public CAMThread
+ , protected HTTPSocket
+{
+public:
+ HTTPFileSource(void);
+ virtual ~HTTPFileSource(void);
+
+ //Thread commands
+ static const int THREAD_RUN = 0;
+ static const int THREAD_EXIT = 1;
+
+ //IFilterDataSource Interface
+ virtual unsigned long seek(unsigned long inPos);
+ virtual void close() ;
+ virtual bool open(string inSourceLocation);
+ virtual void clear();
+ virtual bool isEOF();
+ virtual bool isError();
+ virtual unsigned long read(char* outBuffer, unsigned long inNumBytes);
+ virtual string shouldRetryAt();
+
+ //CAMThread pure virtuals
+ DWORD HTTPFileSource::ThreadProc();
+
+protected:
+ void unChunk(unsigned char* inBuff, unsigned long inNumBytes);
+ unsigned short getHTTPResponseCode(string inHTTPResponse);
+ bool startThread();
+ void DataProcessLoop();
+
+ SingleMediaFileCache mFileCache;
+
+ bool mIsChunked;
+ unsigned long mChunkRemains;
+
+ bool mIsFirstChunk;
+ string mRetryAt;
+
+ fstream debugLog;
+ fstream fileDump;
+ fstream rawDump;
+
+ unsigned char* mInterBuff;
+ unsigned long mNumLeftovers;
+ static const unsigned long RECV_BUFF_SIZE = 1024;
+
+ CCritSec* mBufferLock;
+};
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPSocket.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPSocket.cpp 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPSocket.cpp 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,208 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#include "stdafx.h"
+#include ".\httpsocket.h"
+
+HTTPSocket::HTTPSocket(void)
+ : mWasError(false)
+ , mIsEOF(false)
+ , mIsOpen(false)
+ , mSeenResponse(false)
+{
+ //debugLog2.open("G:\\logs\\httpsocket.log", ios_base::out);
+
+ //Setup the socket API
+ WORD locWinsockVersion = MAKEWORD(1,1);
+ WSADATA locWinsockData;
+ int locRet= 0;
+
+ locRet = WSAStartup(locWinsockVersion, &locWinsockData);
+ if ((locRet != 0) || (locWinsockData.wVersion != locWinsockVersion)) {
+ //Failed to setup.
+ //debugLog2<<"Failed to start winsock V "<<locWinsockData.wVersion<<endl;
+ WSACleanup();
+ throw 0;
+ }
+
+ //debugLog2<<"Winsock started"<<endl;
+}
+
+HTTPSocket::~HTTPSocket(void)
+{
+ //debugLog2<<"Winsock ended"<<endl;
+ //debugLog2.close();
+
+ WSACleanup();
+}
+
+
+bool HTTPSocket::setupSocket(string inSourceLocation) {
+
+ //debugLog2<<"Setup Socket:"<<endl;
+ IN_ADDR locAddress; //iaHost
+ LPHOSTENT locHostData;; //lpHost
+
+ bool locValidURL = splitURL(inSourceLocation);
+
+ locAddress.S_un.S_addr = inet_addr(mServerName.c_str());
+
+
+ if (locAddress.S_un.S_addr == INADDR_NONE) {
+ locHostData = gethostbyname(mServerName.c_str());
+ } else {
+ locHostData = gethostbyaddr((const char*)&locAddress, sizeof(struct in_addr), AF_INET);
+ }
+
+
+
+ if (locHostData == NULL) {
+ //debugLog2<<"LocHostData is NULL"<<endl;
+ //Failed
+ return false;
+ }
+
+ mSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (mSocket == INVALID_SOCKET) {
+ //debugLog2<<"Socket Invalid"<<endl;
+ //Failed
+ return false;
+ }
+
+
+ LPSERVENT locServiceData; //lpServEnt
+ SOCKADDR_IN locServiceSocketAddr; //saServer
+
+ if (mPort == 0) {
+ locServiceData = getservbyname("http", "tcp");
+ if (locServiceData == NULL) {
+ locServiceSocketAddr.sin_port = htons(80);
+ } else {
+ locServiceSocketAddr.sin_port = locServiceData->s_port;
+ }
+ } else {
+ //Explicit port
+ locServiceSocketAddr.sin_port = htons(mPort);
+ }
+
+
+
+ locServiceSocketAddr.sin_family = AF_INET;
+ locServiceSocketAddr.sin_addr = *((LPIN_ADDR)*locHostData->h_addr_list);
+
+
+ int locRetVal = 0;
+ locRetVal = connect(mSocket, (LPSOCKADDR)&locServiceSocketAddr, sizeof(SOCKADDR_IN));
+ if (locRetVal == SOCKET_ERROR) {
+ //debugLog2<<"Failed to connect..."<<endl;
+ closesocket(mSocket);
+ return false;
+ }
+
+ return true;
+
+
+}
+
+string HTTPSocket::assembleRequest(string inFilePath) {
+ string retRequest;
+ retRequest = "GET " + inFilePath+ " HTTP/1.1\r\n" + "Host: " + mServerName+ "\r\n" + "Connection: close" + "\r\n\r\n";
+ //debugLog2<<"Assembled Req : "<<endl<<retRequest<<endl;
+ return retRequest;
+}
+
+bool HTTPSocket::httpRequest(string inRequest) {
+ //debugLog2<<"Http Request:"<<endl;
+ int locRetVal = send(mSocket, inRequest.c_str(), (int)inRequest.length(), 0);
+
+ if (locRetVal == SOCKET_ERROR) {
+ //debugLog2<<"Socket error on send"<<endl;
+ closesocket(mSocket);
+ return false;
+ }
+ return true;
+}
+
+bool HTTPSocket::splitURL(string inURL) {
+ //debugLog2<<"Split url:"<<endl;
+ string locProtocol;
+ string locServerName;
+ string locPath;
+ string locPort;
+ string locTemp;
+ size_t locPos2;
+ size_t locPos = inURL.find(':');
+ if (locPos == string::npos) {
+ //No colon... not a url or file... failure.
+ return false;
+ } else {
+ locProtocol = inURL.substr(0, locPos);
+ locTemp = inURL.substr(locPos+1);
+ locPos = locTemp.find("//");
+ if ((locPos == string::npos) || (locPos != 0)) {
+ return false;
+ } else {
+ locTemp = locTemp.substr(locPos+2);
+ locPos = locTemp.find('/');
+ if (locPos == string::npos) {
+ return false;
+ } else {
+ locPos2 = locTemp.find(':');
+ if (locPos2 == string::npos) {
+ locServerName = locTemp.substr(0, locPos);
+ locPath = locTemp.substr(locPos);
+ } else if (locPos2 < locPos) {
+ //Explicit port specification
+ locPort = locTemp.substr(locPos2 + 1, locPos - locPos2 - 1);
+ locServerName = locTemp.substr(0, locPos2);
+ locPath = locTemp.substr(locPos);
+ }
+
+ }
+ }
+
+ }
+
+ mServerName = locServerName;
+ mFileName = locPath;
+ if (locPort != "") {
+ //TODO::: Error checking needed
+ mPort = atoi(locPort.c_str());
+ } else {
+ mPort = 0;
+ }
+ //debugLog2<<"Proto : "<<locProtocol<<endl<<"Server : "<<locServerName<<endl<<" Path : "<<mFileName<<" Port : "<<mPort<<endl;
+ return true;
+
+}
+void HTTPSocket::closeSocket() {
+ //debugLog2<<"Close Socket:"<<endl;
+ closesocket(mSocket);
+}
\ No newline at end of file
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPSocket.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPSocket.h 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/HTTPSocket.h 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,62 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#pragma once
+#include <fstream>
+#include <string>
+#include <winsock.h>
+using namespace std;
+
+class OGG_DEMUX2_API HTTPSocket
+{
+public:
+ HTTPSocket(void);
+ virtual ~HTTPSocket(void);
+
+ virtual bool setupSocket(string inSourceLocation);
+ virtual void closeSocket();
+ virtual bool splitURL(string inURL);
+ virtual string assembleRequest(string inFilePath);
+ bool httpRequest(string inRequest);
+protected:
+ string mServerName;
+ string mFileName;
+ unsigned short mPort;
+ string mLastResponse;
+ SOCKET mSocket;
+
+ bool mIsEOF;
+ bool mWasError;
+ bool mIsOpen;
+ bool mSeenResponse;
+
+ //fstream debugLog2;
+
+};
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/IFilterDataSource.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/IFilterDataSource.h 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/IFilterDataSource.h 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,50 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#pragma once
+#include <string>
+using namespace std;
+class OGG_DEMUX2_API IFilterDataSource
+{
+public:
+ //Empty Constructor and destructor to ensure proper deletion
+ IFilterDataSource(void) {}
+ virtual ~IFilterDataSource(void) {}
+
+ virtual unsigned long seek(unsigned long inPos) = 0;
+ virtual void close() = 0;
+ virtual bool open(string inSourceLocation) = 0;
+ virtual void clear() = 0;
+ virtual bool isEOF() = 0;
+ virtual bool isError() = 0;
+ virtual unsigned long read(char* outBuffer, unsigned long inNumBytes) = 0;
+ virtual string shouldRetryAt() = 0;
+
+};
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/SingleMediaFileCache.cpp
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/SingleMediaFileCache.cpp 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/SingleMediaFileCache.cpp 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,125 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#include "stdafx.h"
+#include ".\singlemediafilecache.h"
+
+SingleMediaFileCache::SingleMediaFileCache(void)
+ : mBytesWritten(0)
+ , mIsComplete(false)
+ , mReadPtr(0)
+{
+ //debugLog.open("G:\\logs\\mediacache.log", ios_base::out);
+}
+
+SingleMediaFileCache::~SingleMediaFileCache(void)
+{
+ //debugLog.close();
+}
+
+bool SingleMediaFileCache::open(string inFileName) {
+ mBytesWritten = 0;
+ //debugLog<<"Opening "<<inFileName<<endl;
+ mLocalFile.open(inFileName.c_str(), ios_base::in|ios_base::out|ios_base::binary|ios_base::trunc);
+
+ if (mLocalFile.is_open()) {
+ //debugLog<<"File open...."<<endl;
+ } else {
+ //debugLog<<"File open FAILED"<<endl;
+ }
+ return mLocalFile.is_open();
+}
+void SingleMediaFileCache::close() {
+ mLocalFile.close();
+
+}
+bool SingleMediaFileCache::write(const unsigned char* inBuff, unsigned long inBuffSize) {
+ //debugLog<<"Writeing "<<inBuffSize<<endl;
+ //debugLog<<"Read Ptr = "<<mLocalFile.tellg();
+ //debugLog<<"Write Ptr = "<<mLocalFile.tellp();
+ mLocalFile.seekp(0, ios_base::end);
+ if (inBuffSize != 0) {
+ mLocalFile.write((const char*)inBuff, inBuffSize);
+ mBytesWritten += inBuffSize;
+ }
+
+ if (mLocalFile.fail()) {
+ //debugLog<<"*** Write put into FAIL"<<endl;
+ }
+ return !(mLocalFile.fail());
+}
+unsigned long SingleMediaFileCache::read(unsigned char* outBuff, unsigned long inBuffSize) {
+ //debugLog<<"Read request for "<<inBuffSize<<" got ";
+ //debugLog<<"Read Ptr = "<<mLocalFile.tellg();
+ //debugLog<<"Write Ptr = "<<mLocalFile.tellp();
+ mLocalFile.seekg(mReadPtr);
+ unsigned long locBytesAvail = bytesAvail();
+ if (locBytesAvail >= inBuffSize) {
+ mLocalFile.read((char*)outBuff, inBuffSize);
+ //debugLog<<mLocalFile.gcount()<<endl;
+ mReadPtr+=mLocalFile.gcount();
+ return mLocalFile.gcount();
+ } else if (locBytesAvail > 0) {
+ mLocalFile.read((char*)outBuff, locBytesAvail);
+ //debugLog<<locBytesAvail<<endl;
+ mReadPtr += locBytesAvail;
+ return locBytesAvail;
+ } else {
+ //debugLog << "NOTHING"<<endl;
+ return 0;
+ }
+
+}
+bool SingleMediaFileCache::readSeek(unsigned long inSeekPos) {
+ if (inSeekPos < mBytesWritten) {
+ //debugLog<<"Seeking to "<<inSeekPos<<endl;
+ mReadPtr = inSeekPos;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+unsigned long SingleMediaFileCache::totalBytes() {
+ return mBytesWritten;
+}
+unsigned long SingleMediaFileCache::bytesAvail() {
+ if (mLocalFile.fail()) {
+ //debugLog<<"bytesAvail : File is in fail state"<<endl;
+ }
+ //debugLog<<"bytesAvail : Byteswritten = "<<mBytesWritten<<endl;
+ //if ((!mLocalFile.fail()) && (mBytesWritten > 0)) {
+ if (mBytesWritten > 0) {
+ //debugLog<<"bytes Avail = "<<mBytesWritten - mReadPtr<<endl;
+ return mBytesWritten - mReadPtr;
+ } else {
+ return 0;
+ }
+}
Added: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/SingleMediaFileCache.h
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/SingleMediaFileCache.h 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/SingleMediaFileCache.h 2005-10-22 16:30:36 UTC (rev 10251)
@@ -0,0 +1,67 @@
+//===========================================================================
+//Copyright (C) 2003, 2004 Zentaro Kavanagh
+//
+//Redistribution and use in source and binary forms, with or without
+//modification, are permitted provided that the following conditions
+//are met:
+//
+//- Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+//- Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+//
+//- Neither the name of Zentaro Kavanagh nor the names of contributors
+// may be used to endorse or promote products derived from this software
+// without specific prior written permission.
+//
+//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+//``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+//LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+//PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ORGANISATION OR
+//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+//EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+//PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+//PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+//LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+//SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//===========================================================================
+#pragma once
+
+//This class will be a cache of a single media file.
+//It will only allow a single chunk of data to be cached...
+// ie you can't cache bytes 0-1000 and 2000-3000...
+// only consecutive blocks for now.
+//
+//Data can be read randomly... but only written sequentially.
+//Will act as a buffer so that data read off the network can be put straight
+// into the file and then read as needed.
+
+#include <string>
+#include <fstream>
+using namespace std;
+class OGG_DEMUX2_API SingleMediaFileCache
+{
+public:
+ SingleMediaFileCache(void);
+ ~SingleMediaFileCache(void);
+
+ bool open(string inFileName);
+ void close();
+ 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;
+
+ unsigned long mBytesWritten;
+ unsigned long mReadPtr;
+
+ //fstream debugLog;
+ bool mIsComplete;
+};
Modified: branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/dsfOggDemux2.vcproj
===================================================================
--- branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/dsfOggDemux2.vcproj 2005-10-22 16:13:49 UTC (rev 10250)
+++ branches/oggdsf_new_demux/src/lib/core/directshow/dsfOggDemux2/dsfOggDemux2.vcproj 2005-10-22 16:30:36 UTC (rev 10251)
@@ -123,9 +123,21 @@
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
+ RelativePath=".\DataSourceFactory.cpp">
+ </File>
+ <File
RelativePath=".\dsfOggDemux2.def">
</File>
<File
+ RelativePath=".\FilterFileSource.cpp">
+ </File>
+ <File
+ RelativePath=".\HTTPFileSource.cpp">
+ </File>
+ <File
+ RelativePath=".\HTTPSocket.cpp">
+ </File>
+ <File
RelativePath=".\OggDemuxPageSourceFilter.cpp">
</File>
<File
@@ -141,6 +153,9 @@
RelativePath=".\RegWrap.cpp">
</File>
<File
+ RelativePath=".\SingleMediaFileCache.cpp">
+ </File>
+ <File
RelativePath=".\stdafx.cpp">
<FileConfiguration
Name="Debug|Win32">
@@ -161,9 +176,24 @@
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
+ RelativePath=".\DataSourceFactory.h">
+ </File>
+ <File
RelativePath=".\ds_guids.h">
</File>
<File
+ RelativePath=".\FilterFileSource.h">
+ </File>
+ <File
+ RelativePath=".\HTTPFileSource.h">
+ </File>
+ <File
+ RelativePath=".\HTTPSocket.h">
+ </File>
+ <File
+ RelativePath=".\IFilterDataSource.h">
+ </File>
+ <File
RelativePath=".\IOggDecoder.h">
</File>
<File
@@ -182,6 +212,9 @@
RelativePath=".\RegWrap.h">
</File>
<File
+ RelativePath=".\SingleMediaFileCache.h">
+ </File>
+ <File
RelativePath=".\stdafx.h">
</File>
</Filter>
More information about the commits
mailing list