|
1 /* |
|
2 * MP3/MPlayer plugin to VDR (C++) |
|
3 * |
|
4 * (C) 2001-2006 Stefan Huelswitt <s.huelswitt@gmx.de> |
|
5 * |
|
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. |
|
10 * |
|
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. |
|
15 * |
|
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 |
|
20 */ |
|
21 |
|
22 #ifndef ___STREAM_H |
|
23 #define ___STREAM_H |
|
24 |
|
25 #include "decoder.h" |
|
26 |
|
27 class cNet; |
|
28 |
|
29 // ---------------------------------------------------------------- |
|
30 |
|
31 #if 0 |
|
32 class cIO : public cFileInfo { |
|
33 protected: |
|
34 bool log; |
|
35 unsigned long long readpos; |
|
36 public: |
|
37 cIO(const char *Filename, bool Log); |
|
38 virtual ~cIO(); |
|
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; } |
|
46 }; |
|
47 |
|
48 // ---------------------------------------------------------------- |
|
49 |
|
50 class cStreamIO { |
|
51 private: |
|
52 int size, fill; |
|
53 unsigned char *data; |
|
54 protected: |
|
55 void StreamClear(bool all); |
|
56 public: |
|
57 cStreamIO(void); |
|
58 virtual ~cStreamIO(); |
|
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; |
|
62 }; |
|
63 |
|
64 // ---------------------------------------------------------------- |
|
65 |
|
66 class cFileIO : public cIO, public cStreamIO { |
|
67 protected: |
|
68 int fd; |
|
69 public: |
|
70 cFileIO(const char *Filename, bool Log); |
|
71 virtual ~cFileIO(); |
|
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); |
|
76 }; |
|
77 #endif |
|
78 |
|
79 // ---------------------------------------------------------------- |
|
80 |
|
81 class cStream : public cFileInfo { |
|
82 private: |
|
83 int fd; |
|
84 bool ismmap; |
|
85 protected: |
|
86 unsigned char *buffer; |
|
87 unsigned long long readpos, buffpos; |
|
88 unsigned long fill; |
|
89 public: |
|
90 cStream(const char *Filename); |
|
91 virtual ~cStream(); |
|
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; } |
|
97 }; |
|
98 |
|
99 // ---------------------------------------------------------------- |
|
100 |
|
101 class cNetStream : public cStream { |
|
102 private: |
|
103 cNet *net; |
|
104 char *host, *path, *auth; |
|
105 int port, cc; |
|
106 // |
|
107 char *icyName, *icyUrl, *icyTitle; |
|
108 int metaInt, metaCnt; |
|
109 bool icyChanged; |
|
110 // |
|
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); |
|
118 public: |
|
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); |
|
130 }; |
|
131 |
|
132 #endif //___STREAM_H |