2 * MP3/MPlayer plugin to VDR (C++)
4 * (C) 2001-2006 Stefan Huelswitt <s.huelswitt@gmx.de>
6 * This code is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This code is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
29 // ----------------------------------------------------------------
32 class cIO : public cFileInfo {
35 unsigned long long readpos;
37 cIO(const char *Filename, bool Log);
39 virtual bool Open(void)=0;
40 virtual void Close(void)=0;
41 virtual int Read(unsigned char *Data, int Size)=0;
42 virtual unsigned char *StreamInit(int Size) { return 0; }
43 virtual int Stream(const unsigned char *rest) { return -1; }
44 virtual bool Seek(unsigned long long pos, int whence) { return -1; }
45 virtual unsigned long long Tell(void) { return readpos; }
48 // ----------------------------------------------------------------
55 void StreamClear(bool all);
59 virtual unsigned char *StreamInit(int Size);
60 virtual int Stream(const unsigned char *rest);
61 virtual int Read(unsigned char *Data, int Size)=0;
64 // ----------------------------------------------------------------
66 class cFileIO : public cIO, public cStreamIO {
70 cFileIO(const char *Filename, bool Log);
72 virtual bool Open(void);
73 virtual void Close(void);
74 virtual int Read(unsigned char *Data, int Size);
75 virtual bool Seek(unsigned long long pos, int whence);
79 // ----------------------------------------------------------------
81 class cStream : public cFileInfo {
86 unsigned char *buffer;
87 unsigned long long readpos, buffpos;
90 cStream(const char *Filename);
92 virtual bool Open(bool log=true);
93 virtual void Close(void);
94 virtual bool Stream(unsigned char *&data, unsigned long &len, const unsigned char *rest=NULL);
95 virtual bool Seek(unsigned long long pos=0);
96 virtual unsigned long long BufferPos(void) { return buffpos; }
99 // ----------------------------------------------------------------
101 class cNetStream : public cStream {
104 char *host, *path, *auth;
107 char *icyName, *icyUrl, *icyTitle;
108 int metaInt, metaCnt;
111 bool ParseURL(const char *line, bool log);
112 bool ParseURLFile(const char *name, bool log);
113 bool SendRequest(void);
114 bool GetHTTPResponse(void);
115 bool ParseHeader(const char *buff, const char *name, char **value);
116 bool ParseMetaData(void);
117 char *ParseMetaString(const char *buff, const char *name, char **value);
119 cNetStream(const char *Filename);
120 virtual ~cNetStream();
121 virtual bool Open(bool log=true);
122 virtual void Close(void);
123 virtual bool Stream(unsigned char *&data, unsigned long &len, const unsigned char *rest=NULL);
124 virtual bool Seek(unsigned long long pos=0);
125 bool Valid(void) { return ParseURLFile(Filename,false); }
126 const char *IcyName(void) const { return icyName; }
127 const char *IcyUrl(void) const { return icyUrl; }
128 const char *IcyTitle(void) const { return icyTitle; }
129 bool IcyChanged(void);