HTTPStreamingFileSource.h

Go to the documentation of this file.
00001 
00002 //===========================================================================
00003 //Copyright (C) 2003-2006 Zentaro Kavanagh
00004 //
00005 //Redistribution and use in source and binary forms, with or without
00006 //modification, are permitted provided that the following conditions
00007 //are met:
00008 //
00009 //- Redistributions of source code must retain the above copyright
00010 //  notice, this list of conditions and the following disclaimer.
00011 //
00012 //- Redistributions in binary form must reproduce the above copyright
00013 //  notice, this list of conditions and the following disclaimer in the
00014 //  documentation and/or other materials provided with the distribution.
00015 //
00016 //- Neither the name of Zentaro Kavanagh nor the names of contributors 
00017 //  may be used to endorse or promote products derived from this software 
00018 //  without specific prior written permission.
00019 //
00020 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 //``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 //LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
00023 //PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE ORGANISATION OR
00024 //CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025 //EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00026 //PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 //PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 //LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 //NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //===========================================================================
00032 #pragma once
00033 #include "oggdllstuff.h"
00034 
00035 #include "HTTPSocket.h"
00036 #include "IFilterDataSource.h"
00037 #include <string>
00038 #include <sstream>
00039 #include <fstream>
00040 
00041 using namespace std;
00042 
00043 class OGG_DEMUX2_API HTTPStreamingFileSource
00044         :       public IFilterDataSource
00045         ,       public CAMThread
00046         ,       protected HTTPSocket    
00047 {
00048 public:
00049         HTTPStreamingFileSource(void);
00050         virtual ~HTTPStreamingFileSource(void);
00051 
00052         //Consts
00053         static const unsigned long MEMORY_BUFFER_SIZE = 1024 * 1024 * 2;        //2 megs
00054         static const unsigned long MEMORY_BUFFER_LOW_TIDE = 1024 * 512 * 3; //1.5 megs
00055         //Thread commands
00056         static const int THREAD_RUN = 0;
00057         static const int THREAD_EXIT = 1;
00058 
00059         //IFilterDataSource Interface
00060         virtual unsigned long seek(unsigned long inPos);
00061         virtual void close() ;
00062         virtual bool open(string inSourceLocation, unsigned long inStartByte = 0);
00063         virtual void clear();
00064         virtual bool isEOF();
00065         virtual bool isError();
00066         virtual unsigned long read(char* outBuffer, unsigned long inNumBytes);
00067         virtual string shouldRetryAt();
00068 
00069         
00070         //CAMThread pure virtuals
00071         DWORD ThreadProc();
00072 
00073 
00074 
00075 protected:
00076         void unChunk(unsigned char* inBuff, unsigned long inNumBytes);
00077         unsigned short getHTTPResponseCode(string inHTTPResponse);
00078         bool startThread();
00079         void DataProcessLoop();
00080 
00081         //SingleMediaFileCache mFileCache;
00082         CircularBuffer* mMemoryBuffer;
00083 
00084         bool mIsChunked;
00085         unsigned long mChunkRemains;
00086 
00087         bool mIsBufferFilling;
00088 
00089         bool mIsFirstChunk;
00090         string mRetryAt;
00091 
00092         fstream debugLog;
00093         fstream fileDump;
00094         fstream rawDump;
00095 
00096         unsigned char* mInterBuff;
00097         unsigned long mNumLeftovers;
00098         static  const unsigned long RECV_BUFF_SIZE = 1024;
00099         static const unsigned long STREAM_START_BUFFER_SIZE = 32 * 1024;
00100 
00101         //Fix for seekback on headers - since we only maintain a forward buffer. The seek back to start which occurs
00102         //      right after the headers are processed, will generally trigger a stream reset. But an annodex server,
00103         //      will serve out a file with completely different serial numbers, making it impossible to map the streams
00104         //      using the originally gathered information.
00105         //
00106         //Now we are going to buffer up the first part of the file into yet another buffer. Also keep track
00107         //      of what the absolute byte position is we have read up to so far from the stream. When we receive a seek request,
00108         //      we check if the current read position is within this new buffer.
00109         //
00110         //If it is, then we can set a flag, and respond to read requests from this new buffer, up until the point
00111         //      where the stream was before the seek, then switch back to serving out live streaming data.
00112         unsigned long mCurrentAbsoluteReadPosition;
00113         bool mFirstPass;
00114 
00115         unsigned char* mStreamStartBuffer;
00116         unsigned long mStreamStartBufferLength;
00117 
00118         unsigned long mApparentReadPosition;
00119         
00120         //
00121 
00122         __int64 mContentLength;
00123 
00124         CCritSec* mBufferLock;
00125 };

Generated on Thu Feb 16 23:48:14 2006 for oggdsf by  doxygen 1.3.9