author | llornkcor <llornkcor> | 2002-04-21 02:16:03 (UTC) |
---|---|---|
committer | llornkcor <llornkcor> | 2002-04-21 02:16:03 (UTC) |
commit | 1c459273c0e9e387fd5fe2e2c05bef4db5bce115 (patch) (unidiff) | |
tree | cba3a1247a06ec54508c154b0232b7d33d581413 | |
parent | 0e028a1857c7648bc329cbbf5cb35435be909ea6 (diff) | |
download | opie-1c459273c0e9e387fd5fe2e2c05bef4db5bce115.zip opie-1c459273c0e9e387fd5fe2e2c05bef4db5bce115.tar.gz opie-1c459273c0e9e387fd5fe2e2c05bef4db5bce115.tar.bz2 |
I really dont understand..
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmad.pro | 4 | ||||
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 68 |
2 files changed, 23 insertions, 49 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmad.pro b/core/multimedia/opieplayer/libmad/libmad.pro index 679242b..8278bf0 100644 --- a/core/multimedia/opieplayer/libmad/libmad.pro +++ b/core/multimedia/opieplayer/libmad/libmad.pro | |||
@@ -1,25 +1,25 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on release |
3 | HEADERS = libmad_version.h fixed.h bit.h timer.h stream.h frame.h synth.h decoder.h \ | 3 | HEADERS = libmad_version.h fixed.h bit.h timer.h stream.h frame.h synth.h decoder.h \ |
4 | layer12.h layer3.h huffman.h libmad_global.h mad.h libmadplugin.h libmadpluginimpl.h | 4 | layer12.h layer3.h huffman.h libmad_global.h mad.h libmadplugin.h libmadpluginimpl.h |
5 | SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c synth.c decoder.c \ | 5 | SOURCES = version.c fixed.c bit.c timer.c stream.c frame.c synth.c decoder.c \ |
6 | layer12.c layer3.c huffman.c libmadplugin.cpp libmadpluginimpl.cpp | 6 | network.c layer12.c layer3.c huffman.c libmadplugin.cpp libmadpluginimpl.cpp |
7 | TARGET = madplugin | 7 | TARGET = madplugin |
8 | DESTDIR = ../../../plugins/codecs | 8 | DESTDIR = $(OPIEDIR)/plugins/codecs |
9 | INCLUDEPATH += $(OPIEDIR)/include .. | 9 | INCLUDEPATH += $(OPIEDIR)/include .. |
10 | DEPENDPATH += ../$(OPIEDIR)/include .. | 10 | DEPENDPATH += ../$(OPIEDIR)/include .. |
11 | LIBS += -lqpe -lm | 11 | LIBS += -lqpe -lm |
12 | VERSION = 1.0.0 | 12 | VERSION = 1.0.0 |
13 | 13 | ||
14 | TRANSLATIONS = ../../i18n/pt_BR/libmadplugin.ts | 14 | TRANSLATIONS = ../../i18n/pt_BR/libmadplugin.ts |
15 | TRANSLATIONS += ../../i18n/de/libmadplugin.ts | 15 | TRANSLATIONS += ../../i18n/de/libmadplugin.ts |
16 | TRANSLATIONS += ../../i18n/en/libmadplugin.ts | 16 | TRANSLATIONS += ../../i18n/en/libmadplugin.ts |
17 | TRANSLATIONS += ../../i18n/hu/libmadplugin.ts | 17 | TRANSLATIONS += ../../i18n/hu/libmadplugin.ts |
18 | TRANSLATIONS += ../../i18n/sl/libmadplugin.ts | 18 | TRANSLATIONS += ../../i18n/sl/libmadplugin.ts |
19 | TRANSLATIONS += ../../i18n/ja/libmadplugin.ts | 19 | TRANSLATIONS += ../../i18n/ja/libmadplugin.ts |
20 | TRANSLATIONS += ../../i18n/pl/libmadplugin.ts | 20 | TRANSLATIONS += ../../i18n/pl/libmadplugin.ts |
21 | TRANSLATIONS += ../../i18n/ko/libmadplugin.ts | 21 | TRANSLATIONS += ../../i18n/ko/libmadplugin.ts |
22 | TRANSLATIONS += ../../i18n/no/libmadplugin.ts | 22 | TRANSLATIONS += ../../i18n/no/libmadplugin.ts |
23 | TRANSLATIONS += ../../i18n/zh_CN/libmadplugin.ts | 23 | TRANSLATIONS += ../../i18n/zh_CN/libmadplugin.ts |
24 | TRANSLATIONS += ../../i18n/zh_TW/libmadplugin.ts | 24 | TRANSLATIONS += ../../i18n/zh_TW/libmadplugin.ts |
25 | TRANSLATIONS += ../../i18n/fr/libmadplugin.ts | 25 | TRANSLATIONS += ../../i18n/fr/libmadplugin.ts |
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index 7978805..7bb6541 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp | |||
@@ -1,135 +1,131 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Qtopia Environment. | 4 | ** This file is part of Qtopia Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | 14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #include <qapplication.h> | ||
21 | #include <qpe/config.h> | ||
22 | #include <qmessagebox.h> | ||
23 | #include <qstring.h> | ||
24 | |||
25 | #include <stdio.h> | 20 | #include <stdio.h> |
26 | #include <stdarg.h> | 21 | #include <stdarg.h> |
27 | #include <stdlib.h> | 22 | #include <stdlib.h> |
28 | #include <sys/types.h> | 23 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 24 | #include <sys/stat.h> |
30 | #include <fcntl.h> | 25 | #include <fcntl.h> |
31 | #include <unistd.h> | 26 | #include <unistd.h> |
32 | #include <string.h> | 27 | #include <string.h> |
33 | #include <ctype.h> | 28 | #include <ctype.h> |
34 | #include <errno.h> | 29 | #include <errno.h> |
35 | #include <time.h> | 30 | #include <time.h> |
36 | #include <locale.h> | 31 | #include <locale.h> |
37 | #include <math.h> | 32 | #include <math.h> |
38 | #include <assert.h> | 33 | #include <assert.h> |
39 | 34 | #include <qapplication.h> | |
35 | #include <qpe/config.h> | ||
40 | 36 | ||
41 | // for network handling | 37 | // for network handling |
42 | #include <netinet/in.h> | 38 | #include <netinet/in.h> |
43 | #include <netdb.h> | 39 | #include <netdb.h> |
44 | #include <sys/socket.h> | 40 | #include <sys/socket.h> |
45 | #include <arpa/inet.h> | 41 | #include <arpa/inet.h> |
46 | #include <unistd.h> | 42 | #include <unistd.h> |
47 | 43 | ||
48 | 44 | ||
49 | //#define HAVE_MMAP | 45 | //#define HAVE_MMAP |
50 | 46 | ||
51 | #if defined(HAVE_MMAP) | 47 | #if defined(HAVE_MMAP) |
52 | # include <sys/mman.h> | 48 | # include <sys/mman.h> |
53 | #endif | 49 | #endif |
54 | #include "libmadplugin.h" | 50 | #include "libmadplugin.h" |
55 | 51 | ||
56 | 52 | ||
57 | extern "C" { | 53 | extern "C" { |
58 | #include "mad.h" | 54 | #include "mad.h" |
59 | } | 55 | } |
60 | 56 | ||
61 | 57 | ||
62 | #define MPEG_BUFFER_SIZE 65536 | 58 | #define MPEG_BUFFER_SIZE 65536 |
63 | //#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 | 59 | //#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 |
64 | //#define debugMsg(a) qDebug(a) | 60 | //#define debugMsg(a) qDebug(a) |
65 | #define debugMsg(a) | 61 | #define debugMsg(a) |
66 | 62 | ||
67 | 63 | ||
68 | class Input { | 64 | class Input { |
69 | public: | 65 | public: |
70 | char const *path; | 66 | char const *path; |
71 | int fd; | 67 | int fd; |
72 | #if defined(HAVE_MMAP) | 68 | #if defined(HAVE_MMAP) |
73 | void *fdm; | 69 | void *fdm; |
74 | #endif | 70 | #endif |
75 | unsigned char *data; | 71 | unsigned char *data; |
76 | unsigned long length; | 72 | unsigned long length; |
77 | int eof; | 73 | int eof; |
78 | }; | 74 | }; |
79 | 75 | ||
80 | 76 | ||
81 | class Output { | 77 | class Output { |
82 | public: | 78 | public: |
83 | mad_fixed_t attenuate; | 79 | mad_fixed_t attenuate; |
84 | struct filter *filters; | 80 | struct filter *filters; |
85 | unsigned int channels_in; | 81 | unsigned int channels_in; |
86 | unsigned int channels_out; | 82 | unsigned int channels_out; |
87 | unsigned int speed_in; | 83 | unsigned int speed_in; |
88 | unsigned int speed_out; | 84 | unsigned int speed_out; |
89 | const char *path; | 85 | const char *path; |
90 | }; | 86 | }; |
91 | 87 | ||
92 | 88 | ||
93 | # if defined(HAVE_MMAP) | 89 | # if defined(HAVE_MMAP) |
94 | static void *map_file(int fd, unsigned long *length) | 90 | static void *map_file(int fd, unsigned long *length) |
95 | { | 91 | { |
96 | void *fdm; | 92 | void *fdm; |
97 | 93 | ||
98 | *length += MAD_BUFFER_GUARD; | 94 | *length += MAD_BUFFER_GUARD; |
99 | 95 | ||
100 | fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0); | 96 | fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0); |
101 | if (fdm == MAP_FAILED) | 97 | if (fdm == MAP_FAILED) |
102 | return 0; | 98 | return 0; |
103 | 99 | ||
104 | # if defined(HAVE_MADVISE) | 100 | # if defined(HAVE_MADVISE) |
105 | madvise(fdm, *length, MADV_SEQUENTIAL); | 101 | madvise(fdm, *length, MADV_SEQUENTIAL); |
106 | # endif | 102 | # endif |
107 | 103 | ||
108 | return fdm; | 104 | return fdm; |
109 | } | 105 | } |
110 | 106 | ||
111 | 107 | ||
112 | static int unmap_file(void *fdm, unsigned long length) | 108 | static int unmap_file(void *fdm, unsigned long length) |
113 | { | 109 | { |
114 | if (munmap(fdm, length) == -1) | 110 | if (munmap(fdm, length) == -1) |
115 | return -1; | 111 | return -1; |
116 | 112 | ||
117 | return 0; | 113 | return 0; |
118 | } | 114 | } |
119 | # endif | 115 | # endif |
120 | 116 | ||
121 | 117 | ||
122 | static inline QString tr( const char *str ) { | 118 | static inline QString tr( const char *str ) { |
123 | // Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin | 119 | // Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin |
124 | return qApp->translate( "OpiePlayer", str, "libmad strings for mp3 file info" ); | 120 | return qApp->translate( "OpiePlayer", str, "libmad strings for mp3 file info" ); |
125 | } | 121 | } |
126 | 122 | ||
127 | 123 | ||
128 | class LibMadPluginData { | 124 | class LibMadPluginData { |
129 | public: | 125 | public: |
130 | Input input; | 126 | Input input; |
131 | Output output; | 127 | Output output; |
132 | int bad_last_frame; | 128 | int bad_last_frame; |
133 | struct mad_stream stream; | 129 | struct mad_stream stream; |
134 | struct mad_frame frame; | 130 | struct mad_frame frame; |
135 | struct mad_synth synth; | 131 | struct mad_synth synth; |
@@ -144,378 +140,356 @@ LibMadPlugin::LibMadPlugin() { | |||
144 | d->input.fdm = 0; | 140 | d->input.fdm = 0; |
145 | #endif | 141 | #endif |
146 | d->input.data = 0; | 142 | d->input.data = 0; |
147 | d->flush = TRUE; | 143 | d->flush = TRUE; |
148 | info = tr( "No Song Open" ); | 144 | info = tr( "No Song Open" ); |
149 | } | 145 | } |
150 | 146 | ||
151 | 147 | ||
152 | LibMadPlugin::~LibMadPlugin() { | 148 | LibMadPlugin::~LibMadPlugin() { |
153 | close(); | 149 | close(); |
154 | delete d; | 150 | delete d; |
155 | } | 151 | } |
156 | 152 | ||
157 | 153 | ||
158 | bool LibMadPlugin::isFileSupported( const QString& path ) { | 154 | bool LibMadPlugin::isFileSupported( const QString& path ) { |
159 | debugMsg( "LibMadPlugin::isFileSupported" ); | 155 | debugMsg( "LibMadPlugin::isFileSupported" ); |
160 | 156 | ||
161 | // Mpeg file extensions | 157 | // Mpeg file extensions |
162 | // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" | 158 | // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" |
163 | // Other media extensions | 159 | // Other media extensions |
164 | // "wav","mid","mod","s3m","ogg","avi","mov","sid" | 160 | // "wav","mid","mod","s3m","ogg","avi","mov","sid" |
165 | 161 | ||
166 | char *ext = strrchr( path.latin1(), '.' ); | 162 | char *ext = strrchr( path.latin1(), '.' ); |
167 | 163 | ||
168 | // Test file extension | 164 | // Test file extension |
169 | if ( ext ) { | 165 | if ( ext ) { |
170 | if ( strncasecmp(ext, ".mp2", 4) == 0 ) | 166 | if ( strncasecmp(ext, ".mp2", 4) == 0 ) |
171 | return TRUE; | 167 | return TRUE; |
172 | if ( strncasecmp(ext, ".mp3", 4) == 0 ) | 168 | if ( strncasecmp(ext, ".mp3", 4) == 0 ) |
173 | return TRUE; | 169 | return TRUE; |
174 | } | 170 | } |
175 | // UGLY - just for fast testing | 171 | // UGLY - just for fast testing |
176 | if ( path.left(4) == "http") { | 172 | if ( path.left(4) == "http") { |
177 | return TRUE; | 173 | return TRUE; |
178 | } | 174 | } |
179 | 175 | ||
180 | 176 | ||
181 | return FALSE; | 177 | return FALSE; |
182 | } | 178 | } |
183 | 179 | ||
184 | 180 | ||
185 | int LibMadPlugin::tcp_open(char *address, int port) { | 181 | int LibMadPlugin::tcp_open(char *address, int port) { |
186 | struct sockaddr_in stAddr; | 182 | struct sockaddr_in stAddr; |
187 | struct hostent *host; | 183 | struct hostent *host; |
188 | int sock; | 184 | int sock; |
189 | struct linger l; | 185 | struct linger l; |
190 | 186 | ||
191 | memset(&stAddr, 0, sizeof(stAddr)); | 187 | memset(&stAddr, 0, sizeof(stAddr)); |
192 | stAddr.sin_family = AF_INET; | 188 | stAddr.sin_family = AF_INET; |
193 | stAddr.sin_port = htons(port); | 189 | stAddr.sin_port = htons(port); |
194 | 190 | ||
195 | if ((host = gethostbyname(address)) == NULL) | 191 | if ((host = gethostbyname(address)) == NULL) |
196 | return (0); | 192 | return (0); |
197 | 193 | ||
198 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); | 194 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); |
199 | 195 | ||
200 | if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) | 196 | if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) |
201 | return (0); | 197 | return (0); |
202 | 198 | ||
203 | l.l_onoff = 1; | 199 | l.l_onoff = 1; |
204 | l.l_linger = 5; | 200 | l.l_linger = 5; |
205 | if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) | 201 | if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) |
206 | return (0); | 202 | return (0); |
207 | 203 | ||
208 | if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) | 204 | if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) |
209 | return (0); | 205 | return (0); |
210 | 206 | ||
211 | return (sock); | 207 | return (sock); |
212 | } | 208 | } |
213 | 209 | ||
214 | 210 | ||
215 | /** | 211 | /** |
216 | * Read a http line header. | 212 | * Read a http line header. |
217 | * This function read character by character. | 213 | * This function read character by character. |
218 | * @param tcp_sock the socket use to read the stream | 214 | * @param tcp_sock the socket use to read the stream |
219 | * @param buf a buffer to receive the data | 215 | * @param buf a buffer to receive the data |
220 | * @param size size of the buffer | 216 | * @param size size of the buffer |
221 | * @return the size of the stream read or -1 if an error occured | 217 | * @return the size of the stream read or -1 if an error occured |
222 | */ | 218 | */ |
223 | int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { | 219 | int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { |
224 | int offset = 0; | 220 | int offset = 0; |
225 | 221 | ||
226 | do | 222 | do |
227 | { | 223 | { |
228 | if (std::read(tcp_sock, buf + offset, 1) < 0) | 224 | if (std::read(tcp_sock, buf + offset, 1) < 0) |
229 | return -1; | 225 | return -1; |
230 | if (buf[offset] != '\r') /* Strip \r from answer */ | 226 | if (buf[offset] != '\r') /* Strip \r from answer */ |
231 | offset++; | 227 | offset++; |
232 | } | 228 | } |
233 | while (offset < size - 1 && buf[offset - 1] != '\n'); | 229 | while (offset < size - 1 && buf[offset - 1] != '\n'); |
234 | 230 | ||
235 | buf[offset] = 0; | 231 | buf[offset] = 0; |
236 | return offset; | 232 | return offset; |
237 | } | 233 | } |
238 | 234 | ||
239 | int LibMadPlugin::http_open(const QString& path ) { | 235 | int LibMadPlugin::http_open(const QString& path ) { |
240 | qDebug("Open http"); | ||
241 | char *host; | 236 | char *host; |
242 | int port; | 237 | int port; |
243 | char *request; | 238 | char *request; |
244 | int tcp_sock; | 239 | int tcp_sock; |
245 | char http_request[PATH_MAX]; | 240 | char http_request[PATH_MAX]; |
246 | char filename[PATH_MAX]; | 241 | char filename[PATH_MAX]; |
247 | // char c; | 242 | char c; |
248 | char *arg =strdup(path.latin1()); | 243 | char *arg =strdup(path.latin1()); |
249 | 244 | ||
250 | QString errorMsg; | ||
251 | |||
252 | /* Check for URL syntax */ | 245 | /* Check for URL syntax */ |
253 | // if (strncmp(arg, "http://", strlen("http://"))) { | 246 | if (strncmp(arg, "http://", strlen("http://"))) |
254 | // qDebug("Url syntax error"); | 247 | return (0); |
255 | // return (0); | ||
256 | // } | ||
257 | 248 | ||
258 | qDebug("Parse URL"); | 249 | /* Parse URL */ |
259 | port = 80; | 250 | port = 80; |
260 | host = arg + strlen("http://"); | 251 | host = arg + strlen("http://"); |
261 | 252 | if ((request = strchr(host, '/')) == NULL) | |
262 | // we need to think of something better than that | 253 | return (0); |
263 | //if ((request = strchr(host, '/')) == NULL) { | ||
264 | // qDebug("Url syntax 2error %s", host); | ||
265 | // return (0); | ||
266 | // } | ||
267 | |||
268 | *request++ = 0; | 254 | *request++ = 0; |
269 | 255 | ||
270 | if (strchr(host, ':') != NULL) /* port is specified */ | 256 | if (strchr(host, ':') != NULL) /* port is specified */ |
271 | { | 257 | { |
272 | port = atoi(strchr(host, ':') + 1); | 258 | port = atoi(strchr(host, ':') + 1); |
273 | *strchr(host, ':') = 0; | 259 | *strchr(host, ':') = 0; |
274 | } | 260 | } |
275 | 261 | ||
276 | qDebug("Open a TCP socket"); | 262 | /* Open a TCP socket */ |
277 | if (!(tcp_sock = tcp_open(host, port))) { | 263 | if (!(tcp_sock = tcp_open(host, port))) |
278 | perror("http_open"); | 264 | { |
279 | errorMsg="http_open "+(QString)strerror(errno); | 265 | perror("http_open"); |
280 | QMessageBox::message("OPiePlayer",errorMsg); | ||
281 | return (0); | 266 | return (0); |
282 | } | 267 | } |
283 | 268 | ||
284 | snprintf(filename, sizeof(filename) - strlen(host) - 75, "%s", request); | 269 | snprintf(filename, sizeof(filename) - strlen(host) - 75, "%s", request); |
285 | 270 | ||
286 | /* Send HTTP GET request */ | 271 | /* Send HTTP GET request */ |
287 | /* Please don't use a Agent know by shoutcast (Lynx, Mozilla) seems to be reconized and print | 272 | /* Please don't use a Agent know by shoutcast (Lynx, Mozilla) seems to be reconized and print |
288 | * a html page and not the stream */ | 273 | * a html page and not the stream */ |
289 | snprintf(http_request, sizeof(http_request), "GET /%s HTTP/1.0\r\n" | 274 | snprintf(http_request, sizeof(http_request), "GET /%s HTTP/1.0\r\n" |
290 | /* "User-Agent: Mozilla/2.0 (Win95; I)\r\n" */ | 275 | /* "User-Agent: Mozilla/2.0 (Win95; I)\r\n" */ |
291 | "Pragma: no-cache\r\n" "Host: %s\r\n" "Accept: */*\r\n" "\r\n", filename, host); | 276 | "Pragma: no-cache\r\n" "Host: %s\r\n" "Accept: */*\r\n" "\r\n", filename, host); |
292 | qDebug("send"); | 277 | |
293 | send(tcp_sock, http_request, strlen(http_request), 0); | 278 | send(tcp_sock, http_request, strlen(http_request), 0); |
294 | 279 | ||
295 | qDebug("Parse server reply"); | 280 | /* Parse server reply */ |
296 | #if 0 | 281 | #if 0 |
297 | qDebug("do 0"); | ||
298 | do | 282 | do |
299 | read(tcp_sock, &c, sizeof(char)); | 283 | read(tcp_sock, &c, sizeof(char)); |
300 | while (c != ' '); | 284 | while (c != ' '); |
301 | read(tcp_sock, http_request, 4 * sizeof(char)); | 285 | read(tcp_sock, http_request, 4 * sizeof(char)); |
302 | http_request[4] = 0; | 286 | http_request[4] = 0; |
303 | if (strcmp(http_request, "200 ")) | 287 | if (strcmp(http_request, "200 ")) |
304 | { | 288 | { |
305 | fprintf(stderr, "http_open: "); | 289 | fprintf(stderr, "http_open: "); |
306 | do | 290 | do |
307 | { | 291 | { |
308 | read(tcp_sock, &c, sizeof(char)); | 292 | read(tcp_sock, &c, sizeof(char)); |
309 | fprintf(stderr, "%c", c); | 293 | fprintf(stderr, "%c", c); |
310 | } | 294 | } |
311 | while (c != '\r'); | 295 | while (c != '\r'); |
312 | fprintf(stderr, "\n"); | 296 | fprintf(stderr, "\n"); |
313 | return (0); | 297 | return (0); |
314 | } | 298 | } |
315 | #endif | 299 | #endif |
316 | 300 | ||
317 | do | 301 | do |
318 | { | 302 | { |
319 | int len; | 303 | int len; |
320 | 304 | ||
321 | len = http_read_line(tcp_sock, http_request, sizeof(http_request)); | 305 | len = http_read_line(tcp_sock, http_request, sizeof(http_request)); |
322 | 306 | ||
323 | if (len == -1) | 307 | if (len == -1) |
324 | { | 308 | { |
325 | fprintf(stderr, "http_open: %s\n", strerror(errno)); | 309 | fprintf(stderr, "http_open: %s\n", strerror(errno)); |
326 | return 0; | 310 | return 0; |
327 | } | 311 | } |
328 | 312 | ||
329 | if (strncmp(http_request, "Location:", 9) == 0) | 313 | if (strncmp(http_request, "Location:", 9) == 0) |
330 | { | 314 | { |
331 | qDebug("redirect"); | 315 | /* redirect */ |
332 | std::close(tcp_sock); | 316 | std::close(tcp_sock); |
333 | 317 | ||
334 | http_request[strlen(http_request) - 1] = '\0'; | 318 | http_request[strlen(http_request) - 1] = '\0'; |
335 | 319 | ||
336 | return http_open(&http_request[10]); | 320 | return http_open(&http_request[10]); |
337 | } | 321 | } |
338 | 322 | ||
339 | if (strncmp(http_request, "ICY ", 4) == 0) | 323 | if (strncmp(http_request, "ICY ", 4) == 0) |
340 | { | 324 | { |
341 | qDebug(" This is icecast streaming"); | 325 | /* This is icecast streaming */ |
342 | if (strncmp(http_request + 4, "200 ", 4)) | 326 | if (strncmp(http_request + 4, "200 ", 4)) |
343 | { | 327 | { |
344 | fprintf(stderr, "http_open: %s\n", http_request); | 328 | fprintf(stderr, "http_open: %s\n", http_request); |
345 | return 0; | 329 | return 0; |
346 | } | 330 | } |
347 | } | 331 | } |
348 | else if (strncmp(http_request, "icy-", 4) == 0) | 332 | else if (strncmp(http_request, "icy-", 4) == 0) |
349 | { | 333 | { |
350 | /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */ | 334 | /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */ |
351 | /* Don't print these - mpg123 doesn't */ | 335 | /* Don't print these - mpg123 doesn't */ |
352 | /* fprintf(stderr,"%s\n",http_request); */ | 336 | /* fprintf(stderr,"%s\n",http_request); */ |
353 | } | 337 | } |
354 | } | 338 | } |
355 | while (strcmp(http_request, "\n") != 0); | 339 | while (strcmp(http_request, "\n") != 0); |
356 | 340 | ||
357 | return (tcp_sock); | 341 | return (tcp_sock); |
358 | } | 342 | } |
359 | 343 | ||
360 | 344 | ||
361 | bool LibMadPlugin::open( const QString& path ) { | 345 | bool LibMadPlugin::open( const QString& path ) { |
362 | debugMsg( "LibMadPlugin::open" ); | 346 | debugMsg( "LibMadPlugin::open" ); |
363 | Config cfg("OpiePlayer"); | 347 | Config cfg("MediaPlayer"); |
364 | cfg.setGroup("Options"); | 348 | cfg.setGroup("Options"); |
365 | bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE); | 349 | bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE); |
366 | qDebug("buffer size is %d", bufferSize); | 350 | qDebug("buffer size is %d", bufferSize); |
367 | d->bad_last_frame = 0; | 351 | d->bad_last_frame = 0; |
368 | d->flush = TRUE; | 352 | d->flush = TRUE; |
369 | info = QString( "" ); | 353 | info = QString( "" ); |
370 | 354 | ||
371 | qDebug( "Opening %s", path.latin1() ); | 355 | //qDebug( "Opening %s", path.latin1() ); |
356 | |||
372 | 357 | ||
373 | bool isStream=FALSE; | ||
374 | if (path.left( 4 ) == "http" ) { | 358 | if (path.left( 4 ) == "http" ) { |
375 | d->input.fd = http_open(path); | 359 | d->input.fd = http_open(path); |
376 | if(d->input.fd == 0) { | ||
377 | qDebug("http_open error"); | ||
378 | } | ||
379 | isStream=TRUE; | ||
380 | qDebug("Opened ok"); | ||
381 | 360 | ||
382 | } else { | 361 | } else { |
383 | d->input.path = path.latin1(); | 362 | d->input.path = path.latin1(); |
384 | d->input.fd = ::open( d->input.path, O_RDONLY ); | 363 | d->input.fd = ::open( d->input.path, O_RDONLY ); |
385 | } | 364 | } |
386 | if (d->input.fd == -1) { | 365 | if (d->input.fd == -1) { |
387 | qDebug("error opening %s", d->input.path ); | 366 | qDebug("error opening %s", d->input.path ); |
388 | return FALSE; | 367 | return FALSE; |
389 | } | 368 | } |
390 | if(!isStream) { | 369 | |
391 | qDebug("Print ID#tags"); | 370 | printID3Tags(); |
392 | printID3Tags(); | ||
393 | } | ||
394 | 371 | ||
395 | #if defined(HAVE_MMAP) | 372 | #if defined(HAVE_MMAP) |
396 | struct stat stat; | 373 | struct stat stat; |
397 | if (fstat(d->input.fd, &stat) == -1) { | 374 | if (fstat(d->input.fd, &stat) == -1) { |
398 | qDebug("error calling fstat"); return FALSE; | 375 | qDebug("error calling fstat"); return FALSE; |
399 | } | 376 | } |
400 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) { | 377 | if (S_ISREG(stat.st_mode) && stat.st_size > 0) { |
401 | d->input.length = stat.st_size; | 378 | d->input.length = stat.st_size; |
402 | d->input.fdm = map_file(d->input.fd, &d->input.length); | 379 | d->input.fdm = map_file(d->input.fd, &d->input.length); |
403 | if (d->input.fdm == 0) { | 380 | if (d->input.fdm == 0) { |
404 | qDebug("error mmapping file"); return FALSE; | 381 | qDebug("error mmapping file"); return FALSE; |
405 | } | 382 | } |
406 | d->input.data = (unsigned char *)d->input.fdm; | 383 | d->input.data = (unsigned char *)d->input.fdm; |
407 | } | 384 | } |
408 | #endif | 385 | #endif |
409 | 386 | ||
410 | if (d->input.data == 0) { | 387 | if (d->input.data == 0) { |
411 | d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); | 388 | d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); |
412 | if (d->input.data == 0) { | 389 | if (d->input.data == 0) { |
413 | qDebug("error allocating input buffer"); | 390 | qDebug("error allocating input buffer"); |
414 | return FALSE; | 391 | return FALSE; |
415 | } | 392 | } |
416 | d->input.length = 0; | 393 | d->input.length = 0; |
417 | } | 394 | } |
418 | 395 | ||
419 | d->input.eof = 0; | 396 | d->input.eof = 0; |
420 | 397 | ||
421 | qDebug("about to mad_stream"); | ||
422 | mad_stream_init(&d->stream); | 398 | mad_stream_init(&d->stream); |
423 | qDebug("mad_frame"); | ||
424 | mad_frame_init(&d->frame); | 399 | mad_frame_init(&d->frame); |
425 | qDebug("mad_synth"); | ||
426 | mad_synth_init(&d->synth); | 400 | mad_synth_init(&d->synth); |
427 | 401 | ||
428 | return TRUE; | 402 | return TRUE; |
429 | } | 403 | } |
430 | 404 | ||
431 | 405 | ||
432 | bool LibMadPlugin::close() { | 406 | bool LibMadPlugin::close() { |
433 | debugMsg( "LibMadPlugin::close" ); | 407 | debugMsg( "LibMadPlugin::close" ); |
434 | 408 | ||
435 | int result = TRUE; | 409 | int result = TRUE; |
436 | 410 | ||
437 | mad_synth_finish(&d->synth); | 411 | mad_synth_finish(&d->synth); |
438 | mad_frame_finish(&d->frame); | 412 | mad_frame_finish(&d->frame); |
439 | mad_stream_finish(&d->stream); | 413 | mad_stream_finish(&d->stream); |
440 | 414 | ||
441 | #if defined(HAVE_MMAP) | 415 | #if defined(HAVE_MMAP) |
442 | if (d->input.fdm) { | 416 | if (d->input.fdm) { |
443 | if (unmap_file(d->input.fdm, d->input.length) == -1) { | 417 | if (unmap_file(d->input.fdm, d->input.length) == -1) { |
444 | qDebug("error munmapping file"); | 418 | qDebug("error munmapping file"); |
445 | result = FALSE; | 419 | result = FALSE; |
446 | } | 420 | } |
447 | d->input.fdm = 0; | 421 | d->input.fdm = 0; |
448 | d->input.data = 0; | 422 | d->input.data = 0; |
449 | } | 423 | } |
450 | #endif | 424 | #endif |
451 | 425 | ||
452 | if (d->input.data) { | 426 | if (d->input.data) { |
453 | free(d->input.data); | 427 | free(d->input.data); |
454 | d->input.data = 0; | 428 | d->input.data = 0; |
455 | } | 429 | } |
456 | 430 | ||
457 | if (::close(d->input.fd) == -1) { | 431 | if (::close(d->input.fd) == -1) { |
458 | qDebug("error closing file %s", d->input.path); | 432 | qDebug("error closing file %s", d->input.path); |
459 | result = FALSE; | 433 | result = FALSE; |
460 | } | 434 | } |
461 | 435 | ||
462 | d->input.fd = 0; | 436 | d->input.fd = 0; |
463 | 437 | ||
464 | return result; | 438 | return result; |
465 | } | 439 | } |
466 | 440 | ||
467 | 441 | ||
468 | bool LibMadPlugin::isOpen() { | 442 | bool LibMadPlugin::isOpen() { |
469 | debugMsg( "LibMadPlugin::isOpen" ); | 443 | debugMsg( "LibMadPlugin::isOpen" ); |
470 | return ( d->input.fd != 0 ); | 444 | return ( d->input.fd != 0 ); |
471 | } | 445 | } |
472 | 446 | ||
473 | 447 | ||
474 | int LibMadPlugin::audioStreams() { | 448 | int LibMadPlugin::audioStreams() { |
475 | debugMsg( "LibMadPlugin::audioStreams" ); | 449 | debugMsg( "LibMadPlugin::audioStreams" ); |
476 | return 1; | 450 | return 1; |
477 | } | 451 | } |
478 | 452 | ||
479 | 453 | ||
480 | int LibMadPlugin::audioChannels( int ) { | 454 | int LibMadPlugin::audioChannels( int ) { |
481 | debugMsg( "LibMadPlugin::audioChannels" ); | 455 | debugMsg( "LibMadPlugin::audioChannels" ); |
482 | /* | 456 | /* |
483 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 457 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
484 | qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 ); | 458 | qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 ); |
485 | return d->frame.header.mode > 0 ? 2 : 1; | 459 | return d->frame.header.mode > 0 ? 2 : 1; |
486 | */ | 460 | */ |
487 | return 2; | 461 | return 2; |
488 | } | 462 | } |
489 | 463 | ||
490 | 464 | ||
491 | int LibMadPlugin::audioFrequency( int ) { | 465 | int LibMadPlugin::audioFrequency( int ) { |
492 | debugMsg( "LibMadPlugin::audioFrequency" ); | 466 | debugMsg( "LibMadPlugin::audioFrequency" ); |
493 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 467 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
494 | qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); | 468 | qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); |
495 | return d->frame.header.samplerate; | 469 | return d->frame.header.samplerate; |
496 | } | 470 | } |
497 | 471 | ||
498 | 472 | ||
499 | int LibMadPlugin::audioSamples( int ) { | 473 | int LibMadPlugin::audioSamples( int ) { |
500 | debugMsg( "LibMadPlugin::audioSamples" ); | 474 | debugMsg( "LibMadPlugin::audioSamples" ); |
501 | /* | 475 | /* |
502 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); | 476 | long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); |
503 | mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); | 477 | mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); |
504 | qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate ); | 478 | qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate ); |
505 | return d->frame.header.duration.seconds * d->frame.header.samplerate; | 479 | return d->frame.header.duration.seconds * d->frame.header.samplerate; |
506 | */ | 480 | */ |
507 | return 10000000; | 481 | return 10000000; |
508 | } | 482 | } |
509 | 483 | ||
510 | 484 | ||
511 | bool LibMadPlugin::audioSetSample( long, int ) { | 485 | bool LibMadPlugin::audioSetSample( long, int ) { |
512 | debugMsg( "LibMadPlugin::audioSetSample" ); | 486 | debugMsg( "LibMadPlugin::audioSetSample" ); |
513 | return FALSE; | 487 | return FALSE; |
514 | } | 488 | } |
515 | 489 | ||
516 | 490 | ||
517 | long LibMadPlugin::audioGetSample( int ) { | 491 | long LibMadPlugin::audioGetSample( int ) { |
518 | debugMsg( "LibMadPlugin::audioGetSample" ); | 492 | debugMsg( "LibMadPlugin::audioGetSample" ); |
519 | return 0; | 493 | return 0; |
520 | } | 494 | } |
521 | 495 | ||