nathan@0: /* nathan@0: * MP3/MPlayer plugin to VDR (C++) nathan@0: * nathan@0: * (C) 2001-2006 Stefan Huelswitt nathan@0: * nathan@0: * This code is free software; you can redistribute it and/or nathan@0: * modify it under the terms of the GNU General Public License nathan@0: * as published by the Free Software Foundation; either version 2 nathan@0: * of the License, or (at your option) any later version. nathan@0: * nathan@0: * This code is distributed in the hope that it will be useful, nathan@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of nathan@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the nathan@0: * GNU General Public License for more details. nathan@0: * nathan@0: * You should have received a copy of the GNU General Public License nathan@0: * along with this program; if not, write to the Free Software nathan@0: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. nathan@0: * Or, point your browser to http://www.gnu.org/copyleft/gpl.html nathan@0: */ nathan@0: nathan@0: #ifndef ___STREAM_H nathan@0: #define ___STREAM_H nathan@0: nathan@0: #include "decoder.h" nathan@0: nathan@0: class cNet; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: #if 0 nathan@0: class cIO : public cFileInfo { nathan@0: protected: nathan@0: bool log; nathan@0: unsigned long long readpos; nathan@0: public: nathan@0: cIO(const char *Filename, bool Log); nathan@0: virtual ~cIO(); nathan@0: virtual bool Open(void)=0; nathan@0: virtual void Close(void)=0; nathan@0: virtual int Read(unsigned char *Data, int Size)=0; nathan@0: virtual unsigned char *StreamInit(int Size) { return 0; } nathan@0: virtual int Stream(const unsigned char *rest) { return -1; } nathan@0: virtual bool Seek(unsigned long long pos, int whence) { return -1; } nathan@0: virtual unsigned long long Tell(void) { return readpos; } nathan@0: }; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cStreamIO { nathan@0: private: nathan@0: int size, fill; nathan@0: unsigned char *data; nathan@0: protected: nathan@0: void StreamClear(bool all); nathan@0: public: nathan@0: cStreamIO(void); nathan@0: virtual ~cStreamIO(); nathan@0: virtual unsigned char *StreamInit(int Size); nathan@0: virtual int Stream(const unsigned char *rest); nathan@0: virtual int Read(unsigned char *Data, int Size)=0; nathan@0: }; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cFileIO : public cIO, public cStreamIO { nathan@0: protected: nathan@0: int fd; nathan@0: public: nathan@0: cFileIO(const char *Filename, bool Log); nathan@0: virtual ~cFileIO(); nathan@0: virtual bool Open(void); nathan@0: virtual void Close(void); nathan@0: virtual int Read(unsigned char *Data, int Size); nathan@0: virtual bool Seek(unsigned long long pos, int whence); nathan@0: }; nathan@0: #endif nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cStream : public cFileInfo { nathan@0: private: nathan@0: int fd; nathan@0: bool ismmap; nathan@0: protected: nathan@0: unsigned char *buffer; nathan@0: unsigned long long readpos, buffpos; nathan@0: unsigned long fill; nathan@0: public: nathan@0: cStream(const char *Filename); nathan@0: virtual ~cStream(); nathan@0: virtual bool Open(bool log=true); nathan@0: virtual void Close(void); nathan@0: virtual bool Stream(unsigned char *&data, unsigned long &len, const unsigned char *rest=NULL); nathan@0: virtual bool Seek(unsigned long long pos=0); nathan@0: virtual unsigned long long BufferPos(void) { return buffpos; } nathan@0: }; nathan@0: nathan@0: // ---------------------------------------------------------------- nathan@0: nathan@0: class cNetStream : public cStream { nathan@0: private: nathan@0: cNet *net; nathan@0: char *host, *path, *auth; nathan@0: int port, cc; nathan@0: // nathan@0: char *icyName, *icyUrl, *icyTitle; nathan@0: int metaInt, metaCnt; nathan@0: bool icyChanged; nathan@0: // nathan@0: bool ParseURL(const char *line, bool log); nathan@0: bool ParseURLFile(const char *name, bool log); nathan@0: bool SendRequest(void); nathan@0: bool GetHTTPResponse(void); nathan@0: bool ParseHeader(const char *buff, const char *name, char **value); nathan@0: bool ParseMetaData(void); nathan@0: char *ParseMetaString(const char *buff, const char *name, char **value); nathan@0: public: nathan@0: cNetStream(const char *Filename); nathan@0: virtual ~cNetStream(); nathan@0: virtual bool Open(bool log=true); nathan@0: virtual void Close(void); nathan@0: virtual bool Stream(unsigned char *&data, unsigned long &len, const unsigned char *rest=NULL); nathan@0: virtual bool Seek(unsigned long long pos=0); nathan@0: bool Valid(void) { return ParseURLFile(Filename,false); } nathan@0: const char *IcyName(void) const { return icyName; } nathan@0: const char *IcyUrl(void) const { return icyUrl; } nathan@0: const char *IcyTitle(void) const { return icyTitle; } nathan@0: bool IcyChanged(void); nathan@0: }; nathan@0: nathan@0: #endif //___STREAM_H