summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-05-12 11:55:48 (UTC)
committer llornkcor <llornkcor>2002-05-12 11:55:48 (UTC)
commitb0be5b91c09e3a85de1042c973f17ba3d6897084 (patch) (unidiff)
treec495d1041295d1487feb40db211781ffc3852e75
parent6f19bc4691ec2c0ebbe36fc1aff09e879564fe7d (diff)
downloadopie-b0be5b91c09e3a85de1042c973f17ba3d6897084.zip
opie-b0be5b91c09e3a85de1042c973f17ba3d6897084.tar.gz
opie-b0be5b91c09e3a85de1042c973f17ba3d6897084.tar.bz2
don't show blank entries in tags
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/multimedia/opieplayer/libmad/libmadplugin.cpp7
1 files changed, 4 insertions, 3 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
index b06cdaa..0adb503 100644
--- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp
+++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp
@@ -1,839 +1,840 @@
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// largly modified by Maximilian Reiss <max.reiss@gmx.de> 20// largly modified by Maximilian Reiss <max.reiss@gmx.de>
21 21
22#include <stdio.h> 22#include <stdio.h>
23#include <stdarg.h> 23#include <stdarg.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <sys/types.h> 25#include <sys/types.h>
26#include <sys/stat.h> 26#include <sys/stat.h>
27#include <fcntl.h> 27#include <fcntl.h>
28#include <unistd.h> 28#include <unistd.h>
29#include <string.h> 29#include <string.h>
30#include <ctype.h> 30#include <ctype.h>
31#include <errno.h> 31#include <errno.h>
32#include <time.h> 32#include <time.h>
33#include <locale.h> 33#include <locale.h>
34#include <math.h> 34#include <math.h>
35#include <assert.h> 35#include <assert.h>
36 36
37#include <qapplication.h> 37#include <qapplication.h>
38#include <qmessagebox.h> 38#include <qmessagebox.h>
39#include <qregexp.h>
40 39
41#include <qpe/config.h> 40#include <qpe/config.h>
42 41
43// for network handling 42// for network handling
44#include <netinet/in.h> 43#include <netinet/in.h>
45#include <netdb.h> 44#include <netdb.h>
46#include <sys/socket.h> 45#include <sys/socket.h>
47#include <arpa/inet.h> 46#include <arpa/inet.h>
48#include <unistd.h> 47#include <unistd.h>
49 48
50 49
51//#define HAVE_MMAP 50//#define HAVE_MMAP
52 51
53#if defined(HAVE_MMAP) 52#if defined(HAVE_MMAP)
54# include <sys/mman.h> 53# include <sys/mman.h>
55#endif 54#endif
56#include "libmadplugin.h" 55#include "libmadplugin.h"
57 56
58 57
59extern "C" { 58extern "C" {
60#include "mad.h" 59#include "mad.h"
61} 60}
62 61
63 62
64#define MPEG_BUFFER_SIZE 65536 63#define MPEG_BUFFER_SIZE 65536
65//#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 64//#define MPEG_BUFFER_SIZE 32768 //16384 // 8192
66//#define debugMsg(a) qDebug(a) 65//#define debugMsg(a) qDebug(a)
67#define debugMsg(a) 66#define debugMsg(a)
68 67
69 68
70class Input { 69class Input {
71public: 70public:
72 char const *path; 71 char const *path;
73 int fd; 72 int fd;
74#if defined(HAVE_MMAP) 73#if defined(HAVE_MMAP)
75 void *fdm; 74 void *fdm;
76#endif 75#endif
77 unsigned char *data; 76 unsigned char *data;
78 unsigned long length; 77 unsigned long length;
79 int eof; 78 int eof;
80}; 79};
81 80
82 81
83class Output { 82class Output {
84public: 83public:
85 mad_fixed_t attenuate; 84 mad_fixed_t attenuate;
86 struct filter *filters; 85 struct filter *filters;
87 unsigned int channels_in; 86 unsigned int channels_in;
88 unsigned int channels_out; 87 unsigned int channels_out;
89 unsigned int speed_in; 88 unsigned int speed_in;
90 unsigned int speed_out; 89 unsigned int speed_out;
91 const char *path; 90 const char *path;
92}; 91};
93 92
94 93
95# if defined(HAVE_MMAP) 94# if defined(HAVE_MMAP)
96static void *map_file(int fd, unsigned long *length) 95static void *map_file(int fd, unsigned long *length)
97{ 96{
98 void *fdm; 97 void *fdm;
99 98
100 *length += MAD_BUFFER_GUARD; 99 *length += MAD_BUFFER_GUARD;
101 100
102 fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0); 101 fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0);
103 if (fdm == MAP_FAILED) 102 if (fdm == MAP_FAILED)
104 return 0; 103 return 0;
105 104
106# if defined(HAVE_MADVISE) 105# if defined(HAVE_MADVISE)
107 madvise(fdm, *length, MADV_SEQUENTIAL); 106 madvise(fdm, *length, MADV_SEQUENTIAL);
108# endif 107# endif
109 108
110 return fdm; 109 return fdm;
111} 110}
112 111
113 112
114static int unmap_file(void *fdm, unsigned long length) 113static int unmap_file(void *fdm, unsigned long length)
115{ 114{
116 if (munmap(fdm, length) == -1) 115 if (munmap(fdm, length) == -1)
117 return -1; 116 return -1;
118 117
119 return 0; 118 return 0;
120} 119}
121# endif 120# endif
122 121
123 122
124static inline QString tr( const char *str ) { 123static inline QString tr( const char *str ) {
125 // Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin 124 // Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin
126 return qApp->translate( "OpiePlayer", str, "libmad strings for mp3 file info" ); 125 return qApp->translate( "OpiePlayer", str, "libmad strings for mp3 file info" );
127} 126}
128 127
129 128
130class LibMadPluginData { 129class LibMadPluginData {
131public: 130public:
132 Input input; 131 Input input;
133 Output output; 132 Output output;
134 int bad_last_frame; 133 int bad_last_frame;
135 struct mad_stream stream; 134 struct mad_stream stream;
136 struct mad_frame frame; 135 struct mad_frame frame;
137 struct mad_synth synth; 136 struct mad_synth synth;
138 bool flush; 137 bool flush;
139}; 138};
140 139
141 140
142LibMadPlugin::LibMadPlugin() { 141LibMadPlugin::LibMadPlugin() {
143 d = new LibMadPluginData; 142 d = new LibMadPluginData;
144 d->input.fd = 0; 143 d->input.fd = 0;
145#if defined(HAVE_MMAP) 144#if defined(HAVE_MMAP)
146 d->input.fdm = 0; 145 d->input.fdm = 0;
147#endif 146#endif
148 d->input.data = 0; 147 d->input.data = 0;
149 d->flush = TRUE; 148 d->flush = TRUE;
150 info = tr( "No Song Open" ); 149 info = tr( "No Song Open" );
151} 150}
152 151
153 152
154LibMadPlugin::~LibMadPlugin() { 153LibMadPlugin::~LibMadPlugin() {
155 close(); 154 close();
156 delete d; 155 delete d;
157} 156}
158 157
159 158
160bool LibMadPlugin::isFileSupported( const QString& path ) { 159bool LibMadPlugin::isFileSupported( const QString& path ) {
161 debugMsg( "LibMadPlugin::isFileSupported" ); 160 debugMsg( "LibMadPlugin::isFileSupported" );
162 161
163 // Mpeg file extensions 162 // Mpeg file extensions
164 // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" 163 // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3"
165 // Other media extensions 164 // Other media extensions
166 // "wav","mid","mod","s3m","ogg","avi","mov","sid" 165 // "wav","mid","mod","s3m","ogg","avi","mov","sid"
167 166
168 char *ext = strrchr( path.latin1(), '.' ); 167 char *ext = strrchr( path.latin1(), '.' );
169 168
170 // Test file extension 169 // Test file extension
171 if ( ext ) { 170 if ( ext ) {
172 if ( strncasecmp(ext, ".mp2", 4) == 0 ) 171 if ( strncasecmp(ext, ".mp2", 4) == 0 )
173 return TRUE; 172 return TRUE;
174 if ( strncasecmp(ext, ".mp3", 4) == 0 ) 173 if ( strncasecmp(ext, ".mp3", 4) == 0 )
175 return TRUE; 174 return TRUE;
176 } 175 }
177 176
178 // UGLY - just for fast testing 177 // UGLY - just for fast testing
179 if ( path.left(4) == "http") { 178 if ( path.left(4) == "http") {
180 return TRUE; 179 return TRUE;
181 } 180 }
182 181
183 return FALSE; 182 return FALSE;
184} 183}
185 184
186 185
187 186
188int LibMadPlugin::is_address_multicast(unsigned long address) { 187int LibMadPlugin::is_address_multicast(unsigned long address) {
189 if ((address & 255) >= 224 && (address & 255) <= 239) 188 if ((address & 255) >= 224 && (address & 255) <= 239)
190 return (1); 189 return (1);
191 return (0); 190 return (0);
192} 191}
193 192
194 193
195int LibMadPlugin::udp_open(char *address, int port) { 194int LibMadPlugin::udp_open(char *address, int port) {
196 195
197 int enable = 1L; 196 int enable = 1L;
198 struct sockaddr_in stAddr; 197 struct sockaddr_in stAddr;
199 struct sockaddr_in stLclAddr; 198 struct sockaddr_in stLclAddr;
200 struct ip_mreq stMreq; 199 struct ip_mreq stMreq;
201 struct hostent *host; 200 struct hostent *host;
202 int sock; 201 int sock;
203 202
204 stAddr.sin_family = AF_INET; 203 stAddr.sin_family = AF_INET;
205 stAddr.sin_port = htons(port); 204 stAddr.sin_port = htons(port);
206 205
207 if ((host = gethostbyname(address)) == NULL) { 206 if ((host = gethostbyname(address)) == NULL) {
208 return (0); 207 return (0);
209 } 208 }
210 209
211 stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); 210 stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]);
212 211
213 /* Create a UDP socket */ 212 /* Create a UDP socket */
214 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { 213 if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
215 return (0); 214 return (0);
216 } 215 }
217 216
218 /* Allow multiple instance of the client to share the same address and port */ 217 /* Allow multiple instance of the client to share the same address and port */
219 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&enable, sizeof(unsigned long int)) < 0) { 218 if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&enable, sizeof(unsigned long int)) < 0) {
220 return (0); 219 return (0);
221 } 220 }
222 221
223 /* If the address is multicast, register to the multicast group */ 222 /* If the address is multicast, register to the multicast group */
224 if (is_address_multicast(stAddr.sin_addr.s_addr)) { 223 if (is_address_multicast(stAddr.sin_addr.s_addr)) {
225 /* Bind the socket to port */ 224 /* Bind the socket to port */
226 stLclAddr.sin_family = AF_INET; 225 stLclAddr.sin_family = AF_INET;
227 stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); 226 stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY);
228 stLclAddr.sin_port = stAddr.sin_port; 227 stLclAddr.sin_port = stAddr.sin_port;
229 if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) { 228 if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) {
230 return (0); 229 return (0);
231 } 230 }
232 231
233 /* Register to a multicast address */ 232 /* Register to a multicast address */
234 stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr; 233 stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr;
235 stMreq.imr_interface.s_addr = INADDR_ANY; 234 stMreq.imr_interface.s_addr = INADDR_ANY;
236 if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq, sizeof(stMreq)) < 0) { 235 if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq, sizeof(stMreq)) < 0) {
237 return (0); 236 return (0);
238 } 237 }
239 } else { 238 } else {
240 /* Bind the socket to port */ 239 /* Bind the socket to port */
241 stLclAddr.sin_family = AF_INET; 240 stLclAddr.sin_family = AF_INET;
242 stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); 241 stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY);
243 stLclAddr.sin_port = htons(0); 242 stLclAddr.sin_port = htons(0);
244 if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) { 243 if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) {
245 return (0); 244 return (0);
246 } 245 }
247 } 246 }
248 return (sock); 247 return (sock);
249} 248}
250 249
251int LibMadPlugin::tcp_open(char *address, int port) { 250int LibMadPlugin::tcp_open(char *address, int port) {
252 struct sockaddr_in stAddr; 251 struct sockaddr_in stAddr;
253 struct hostent *host; 252 struct hostent *host;
254 int sock; 253 int sock;
255 struct linger l; 254 struct linger l;
256 255
257 memset(&stAddr, 0, sizeof(stAddr)); 256 memset(&stAddr, 0, sizeof(stAddr));
258 stAddr.sin_family = AF_INET; 257 stAddr.sin_family = AF_INET;
259 stAddr.sin_port = htons(port); 258 stAddr.sin_port = htons(port);
260 259
261 if ((host = gethostbyname(address)) == NULL) { 260 if ((host = gethostbyname(address)) == NULL) {
262 return (0); 261 return (0);
263 } 262 }
264 263
265 stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); 264 stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]);
266 265
267 if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { 266 if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
268 return (0); 267 return (0);
269 } 268 }
270 269
271 l.l_onoff = 1; 270 l.l_onoff = 1;
272 l.l_linger = 5; 271 l.l_linger = 5;
273 if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) { 272 if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) {
274 return (0); 273 return (0);
275 } 274 }
276 275
277 if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) { 276 if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) {
278 return (0); 277 return (0);
279 } 278 }
280 279
281 return (sock); 280 return (sock);
282} 281}
283 282
284 283
285/** 284/**
286 * Read a http line header. 285 * Read a http line header.
287 * This function read character by character. 286 * This function read character by character.
288 * @param tcp_sock the socket use to read the stream 287 * @param tcp_sock the socket use to read the stream
289 * @param buf a buffer to receive the data 288 * @param buf a buffer to receive the data
290 * @param size size of the buffer 289 * @param size size of the buffer
291 * @return the size of the stream read or -1 if an error occured 290 * @return the size of the stream read or -1 if an error occured
292 */ 291 */
293int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { 292int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) {
294 int offset = 0; 293 int offset = 0;
295 294
296 do { 295 do {
297 if (::read(tcp_sock, buf + offset, 1) < 0) 296 if (::read(tcp_sock, buf + offset, 1) < 0)
298 return -1; 297 return -1;
299 if (buf[offset] != '\r') /* Strip \r from answer */ 298 if (buf[offset] != '\r') /* Strip \r from answer */
300 offset++; 299 offset++;
301 } while (offset < size - 1 && buf[offset - 1] != '\n'); 300 } while (offset < size - 1 && buf[offset - 1] != '\n');
302 301
303 buf[offset] = 0; 302 buf[offset] = 0;
304 return offset; 303 return offset;
305} 304}
306 305
307int LibMadPlugin::http_open(const QString& path ) { 306int LibMadPlugin::http_open(const QString& path ) {
308 char *host; 307 char *host;
309 int port; 308 int port;
310 char *request; 309 char *request;
311 int tcp_sock; 310 int tcp_sock;
312 char http_request[PATH_MAX]; 311 char http_request[PATH_MAX];
313 char filename[PATH_MAX]; 312 char filename[PATH_MAX];
314 //char c; 313 //char c;
315 char *arg =strdup(path.latin1()); 314 char *arg =strdup(path.latin1());
316 315
317 /* Check for URL syntax */ 316 /* Check for URL syntax */
318 if (strncmp(arg, "http://", strlen("http://"))) { 317 if (strncmp(arg, "http://", strlen("http://"))) {
319 return (0); 318 return (0);
320 } 319 }
321 320
322 /* Parse URL */ 321 /* Parse URL */
323 port = 80; 322 port = 80;
324 host = arg + strlen("http://"); 323 host = arg + strlen("http://");
325 if ((request = strchr(host, '/')) == NULL) { 324 if ((request = strchr(host, '/')) == NULL) {
326 return (0); 325 return (0);
327 } 326 }
328 327
329 *request++ = 0; 328 *request++ = 0;
330 329
331 if (strchr(host, ':') != NULL) { /* port is specified */ 330 if (strchr(host, ':') != NULL) { /* port is specified */
332 port = atoi(strchr(host, ':') + 1); 331 port = atoi(strchr(host, ':') + 1);
333 *strchr(host, ':') = 0; 332 *strchr(host, ':') = 0;
334 } 333 }
335 334
336 /* Open a TCP socket */ 335 /* Open a TCP socket */
337 if (!(tcp_sock = tcp_open(host, port))) { 336 if (!(tcp_sock = tcp_open(host, port))) {
338 perror("http_open"); 337 perror("http_open");
339 return (0); 338 return (0);
340 } 339 }
341 340
342 snprintf(filename, sizeof(filename) - strlen(host) - 75, "%s", request); 341 snprintf(filename, sizeof(filename) - strlen(host) - 75, "%s", request);
343 342
344 /* Send HTTP GET request */ 343 /* Send HTTP GET request */
345 /* Please don't use a Agent know by shoutcast (Lynx, Mozilla) seems to be reconized and print 344 /* Please don't use a Agent know by shoutcast (Lynx, Mozilla) seems to be reconized and print
346 * a html page and not the stream */ 345 * a html page and not the stream */
347 snprintf(http_request, sizeof(http_request), "GET /%s HTTP/1.0\r\n" 346 snprintf(http_request, sizeof(http_request), "GET /%s HTTP/1.0\r\n"
348 /* "User-Agent: Mozilla/2.0 (Win95; I)\r\n" */ 347 /* "User-Agent: Mozilla/2.0 (Win95; I)\r\n" */
349 "Pragma: no-cache\r\n" "Host: %s\r\n" "Accept: */*\r\n" "\r\n", filename, host); 348 "Pragma: no-cache\r\n" "Host: %s\r\n" "Accept: */*\r\n" "\r\n", filename, host);
350 349
351 send(tcp_sock, http_request, strlen(http_request), 0); 350 send(tcp_sock, http_request, strlen(http_request), 0);
352 351
353 /* Parse server reply */ 352 /* Parse server reply */
354#if 0 353#if 0
355 do 354 do
356 read(tcp_sock, &c, sizeof(char)); 355 read(tcp_sock, &c, sizeof(char));
357 while (c != ' '); 356 while (c != ' ');
358 read(tcp_sock, http_request, 4 * sizeof(char)); 357 read(tcp_sock, http_request, 4 * sizeof(char));
359 http_request[4] = 0; 358 http_request[4] = 0;
360 if (strcmp(http_request, "200 ")) { 359 if (strcmp(http_request, "200 ")) {
361 fprintf(stderr, "http_open: "); 360 fprintf(stderr, "http_open: ");
362 do { 361 do {
363 read(tcp_sock, &c, sizeof(char)); 362 read(tcp_sock, &c, sizeof(char));
364 fprintf(stderr, "%c", c); 363 fprintf(stderr, "%c", c);
365 } while (c != '\r'); 364 } while (c != '\r');
366 fprintf(stderr, "\n"); 365 fprintf(stderr, "\n");
367 return (0); 366 return (0);
368 } 367 }
369#endif 368#endif
370 369
371 QString name; 370 QString name;
372 QString genre; 371 QString genre;
373 QString bitrate; 372 QString bitrate;
374 QString url; 373 QString url;
375 QString message = tr("Info: "); 374 QString message = tr("Info: ");
376 do { 375 do {
377 376
378 int len; 377 int len;
379 378
380 len = http_read_line(tcp_sock, http_request, sizeof(http_request)); 379 len = http_read_line(tcp_sock, http_request, sizeof(http_request));
381 380
382 if (len == -1) { 381 if (len == -1) {
383 qDebug( "http_open: "+ QString(strerror(errno)) +"\n"); 382 qDebug( "http_open: "+ QString(strerror(errno)) +"\n");
384 return 0; 383 return 0;
385 } 384 }
386 385
387 if (QString(http_request).left(9) == "Location:") { 386 if (QString(http_request).left(9) == "Location:") {
388 /* redirect */ 387 /* redirect */
389 ::close(tcp_sock); 388 ::close(tcp_sock);
390 http_request[strlen(http_request) - 1] = '\0'; 389 http_request[strlen(http_request) - 1] = '\0';
391 return http_open(&http_request[10]); 390 return http_open(&http_request[10]);
392 } 391 }
393 392
394 if (QString(http_request).left(4) == "ICY ") { 393 if (QString(http_request).left(4) == "ICY ") {
395 /* This is shoutcast/icecast streaming */ 394 /* This is shoutcast/icecast streaming */
396 if (strncmp(http_request + 4, "200 ", 4)) { 395 if (strncmp(http_request + 4, "200 ", 4)) {
397 qDebug("http_open: " + QString(http_request) + "\n"); 396 qDebug("http_open: " + QString(http_request) + "\n");
398 return 0; 397 return 0;
399 } 398 }
400 } else if (QString(http_request).left(4) == "icy-") { 399 } else if (QString(http_request).left(4) == "icy-") {
401 /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */ 400 /* we can have: icy-noticeX, icy-name, icy-genre, icy-url, icy-pub, icy-metaint, icy-br */
402 if ( QString( http_request ).left( 8 ) == "icy-name" ) { 401 if ( QString( http_request ).left( 8 ) == "icy-name" ) {
403 name = tr("Name: ") + QString(http_request).mid(9, (QString(http_request).length())- 9 ); 402 name = tr("Name: ") + QString(http_request).mid(9, (QString(http_request).length())- 9 );
404 } else if ( QString( http_request ).left( 9 ) == "icy-genre" ) { 403 } else if ( QString( http_request ).left( 9 ) == "icy-genre" ) {
405 genre = tr("Genre: ") + QString(http_request).mid(10, (QString(http_request).length())-10 ); 404 genre = tr("Genre: ") + QString(http_request).mid(10, (QString(http_request).length())-10 );
406 } else if ( QString( http_request ).left( 6 ) == "icy-br" ) { 405 } else if ( QString( http_request ).left( 6 ) == "icy-br" ) {
407 bitrate = tr("Bitrate: ") + QString(http_request).mid(7, (QString(http_request).length())- 7 ); 406 bitrate = tr("Bitrate: ") + QString(http_request).mid(7, (QString(http_request).length())- 7 );
408 } else if ( QString( http_request ).left( 7 ) == "icy-url" ) { 407 } else if ( QString( http_request ).left( 7 ) == "icy-url" ) {
409 url = tr("URL: ") + QString(http_request).mid(8, (QString(http_request).length())- 8 ); 408 url = tr("URL: ") + QString(http_request).mid(8, (QString(http_request).length())- 8 );
410 } else if ( QString( http_request ).left( 10 ) == "icy-notice" ) { 409 } else if ( QString( http_request ).left( 10 ) == "icy-notice" ) {
411 message += QString(http_request).mid(11, QString(http_request).length()-11 ) ; 410 message += QString(http_request).mid(11, QString(http_request).length()-11 ) ;
412 } 411 }
413 } 412 }
414 } while (strcmp(http_request, "\n") != 0); 413 } while (strcmp(http_request, "\n") != 0);
415 414
416 info = QString(name + genre + url + bitrate + message).replace( QRegExp("\n"), " : " ); 415 info = QString(name + genre + url + bitrate + message).replace( QRegExp("\n"), " : " );
417 416
418 qDebug("Stream info: " + info); 417 qDebug("Stream info: " + info);
419 418
420 return (tcp_sock); 419 return (tcp_sock);
421} 420}
422 421
423 422
424 423
425bool LibMadPlugin::open( const QString& path ) { 424bool LibMadPlugin::open( const QString& path ) {
426 debugMsg( "LibMadPlugin::open" ); 425 debugMsg( "LibMadPlugin::open" );
427 Config cfg("OpiePlayer"); 426 Config cfg("OpiePlayer");
428 cfg.setGroup("Options"); 427 cfg.setGroup("Options");
429 bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE); 428 bufferSize = cfg.readNumEntry("MPeg_BufferSize",MPEG_BUFFER_SIZE);
430 qDebug("buffer size is %d", bufferSize); 429 qDebug("buffer size is %d", bufferSize);
431 d->bad_last_frame = 0; 430 d->bad_last_frame = 0;
432 d->flush = TRUE; 431 d->flush = TRUE;
433 info = QString( "" ); 432 info = QString( "" );
434 433
435 //qDebug( "Opening %s", path.latin1() ); 434 //qDebug( "Opening %s", path.latin1() );
436 435
437 436
438 if (path.left( 4 ) == "http" ) { 437 if (path.left( 4 ) == "http" ) {
439 qDebug("Test2"); 438 qDebug("Test2");
440 // in case of any error we get 0 here 439 // in case of any error we get 0 here
441 if ( !(http_open(path) == 0) ) { 440 if ( !(http_open(path) == 0) ) {
442 qDebug("Test3"); 441 qDebug("Test3");
443 d->input.fd = http_open(path); 442 d->input.fd = http_open(path);
444 } else { 443 } else {
445 qDebug("Test5"); 444 qDebug("Test5");
446 return FALSE; 445 return FALSE;
447 } 446 }
448 } else { 447 } else {
449 qDebug("Test4"); 448 qDebug("Test4");
450 d->input.path = path.latin1(); 449 d->input.path = path.latin1();
451 d->input.fd = ::open( d->input.path, O_RDONLY ); 450 d->input.fd = ::open( d->input.path, O_RDONLY );
452 // thats a better place, since it should only seek for ID3 tags on mp3 files, not streams 451 // thats a better place, since it should only seek for ID3 tags on mp3 files, not streams
453 printID3Tags(); 452 printID3Tags();
454 } 453 }
455 if (d->input.fd == -1) { 454 if (d->input.fd == -1) {
456 qDebug("error opening %s", d->input.path ); 455 qDebug("error opening %s", d->input.path );
457 return FALSE; 456 return FALSE;
458 } 457 }
459 458
460// printID3Tags(); 459// printID3Tags();
461 460
462#if defined(HAVE_MMAP) 461#if defined(HAVE_MMAP)
463 struct stat stat; 462 struct stat stat;
464 if (fstat(d->input.fd, &stat) == -1) { 463 if (fstat(d->input.fd, &stat) == -1) {
465 //qDebug("error calling fstat"); return FALSE; 464 //qDebug("error calling fstat"); return FALSE;
466 } 465 }
467 if (S_ISREG(stat.st_mode) && stat.st_size > 0) { 466 if (S_ISREG(stat.st_mode) && stat.st_size > 0) {
468 d->input.length = stat.st_size; 467 d->input.length = stat.st_size;
469 d->input.fdm = map_file(d->input.fd, &d->input.length); 468 d->input.fdm = map_file(d->input.fd, &d->input.length);
470 if (d->input.fdm == 0) { 469 if (d->input.fdm == 0) {
471 qDebug("error mmapping file"); return FALSE; 470 qDebug("error mmapping file"); return FALSE;
472 } 471 }
473 d->input.data = (unsigned char *)d->input.fdm; 472 d->input.data = (unsigned char *)d->input.fdm;
474 } 473 }
475#endif 474#endif
476 475
477 if (d->input.data == 0) { 476 if (d->input.data == 0) {
478 d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/); 477 d->input.data = (unsigned char *)malloc( bufferSize /*MPEG_BUFFER_SIZE*/);
479 if (d->input.data == 0) { 478 if (d->input.data == 0) {
480 qDebug("error allocating input buffer"); 479 qDebug("error allocating input buffer");
481 return FALSE; 480 return FALSE;
482 } 481 }
483 d->input.length = 0; 482 d->input.length = 0;
484 } 483 }
485 484
486 d->input.eof = 0; 485 d->input.eof = 0;
487 486
488 mad_stream_init(&d->stream); 487 mad_stream_init(&d->stream);
489 mad_frame_init(&d->frame); 488 mad_frame_init(&d->frame);
490 mad_synth_init(&d->synth); 489 mad_synth_init(&d->synth);
491 490
492 return TRUE; 491 return TRUE;
493} 492}
494 493
495 494
496bool LibMadPlugin::close() { 495bool LibMadPlugin::close() {
497 debugMsg( "LibMadPlugin::close" ); 496 debugMsg( "LibMadPlugin::close" );
498 497
499 int result = TRUE; 498 int result = TRUE;
500 499
501 mad_synth_finish(&d->synth); 500 mad_synth_finish(&d->synth);
502 mad_frame_finish(&d->frame); 501 mad_frame_finish(&d->frame);
503 mad_stream_finish(&d->stream); 502 mad_stream_finish(&d->stream);
504 503
505#if defined(HAVE_MMAP) 504#if defined(HAVE_MMAP)
506 if (d->input.fdm) { 505 if (d->input.fdm) {
507 if (unmap_file(d->input.fdm, d->input.length) == -1) { 506 if (unmap_file(d->input.fdm, d->input.length) == -1) {
508 qDebug("error munmapping file"); 507 qDebug("error munmapping file");
509 result = FALSE; 508 result = FALSE;
510 } 509 }
511 d->input.fdm = 0; 510 d->input.fdm = 0;
512 d->input.data = 0; 511 d->input.data = 0;
513 } 512 }
514#endif 513#endif
515 514
516 if (d->input.data) { 515 if (d->input.data) {
517 free(d->input.data); 516 free(d->input.data);
518 d->input.data = 0; 517 d->input.data = 0;
519 } 518 }
520 519
521 if (::close(d->input.fd) == -1) { 520 if (::close(d->input.fd) == -1) {
522 qDebug("error closing file %s", d->input.path); 521 qDebug("error closing file %s", d->input.path);
523 result = FALSE; 522 result = FALSE;
524 } 523 }
525 524
526 d->input.fd = 0; 525 d->input.fd = 0;
527 526
528 return result; 527 return result;
529} 528}
530 529
531 530
532bool LibMadPlugin::isOpen() { 531bool LibMadPlugin::isOpen() {
533 debugMsg( "LibMadPlugin::isOpen" ); 532 debugMsg( "LibMadPlugin::isOpen" );
534 return ( d->input.fd != 0 ); 533 return ( d->input.fd != 0 );
535} 534}
536 535
537 536
538int LibMadPlugin::audioStreams() { 537int LibMadPlugin::audioStreams() {
539 debugMsg( "LibMadPlugin::audioStreams" ); 538 debugMsg( "LibMadPlugin::audioStreams" );
540 return 1; 539 return 1;
541} 540}
542 541
543 542
544int LibMadPlugin::audioChannels( int ) { 543int LibMadPlugin::audioChannels( int ) {
545 debugMsg( "LibMadPlugin::audioChannels" ); 544 debugMsg( "LibMadPlugin::audioChannels" );
546/* 545/*
547 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); 546 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
548 qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 ); 547 qDebug( "LibMadPlugin::audioChannels: %i", d->frame.header.mode > 0 ? 2 : 1 );
549 return d->frame.header.mode > 0 ? 2 : 1; 548 return d->frame.header.mode > 0 ? 2 : 1;
550*/ 549*/
551 return 2; 550 return 2;
552} 551}
553 552
554 553
555int LibMadPlugin::audioFrequency( int ) { 554int LibMadPlugin::audioFrequency( int ) {
556 debugMsg( "LibMadPlugin::audioFrequency" ); 555 debugMsg( "LibMadPlugin::audioFrequency" );
557 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); 556 long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
558 qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate ); 557 qDebug( "LibMadPlugin::audioFrequency: %i", d->frame.header.samplerate );
559 return d->frame.header.samplerate; 558 return d->frame.header.samplerate;
560} 559}
561 560
562 561
563int LibMadPlugin::audioSamples( int ) { 562int LibMadPlugin::audioSamples( int ) {
564 debugMsg( "LibMadPlugin::audioSamples" ); 563 debugMsg( "LibMadPlugin::audioSamples" );
565 564
566 // long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 ); 565 // long t; short t1[5]; audioReadSamples( t1, 2, 1, t, 0 );
567// mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream ); 566// mad_header_decode( (struct mad_header *)&d->frame.header, &d->stream );
568// qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate ); 567// qDebug( "LibMadPlugin::audioSamples: %i*%i", d->frame.header.duration.seconds, d->frame.header.samplerate );
569// return d->frame.header.duration.seconds * d->frame.header.samplerate; 568// return d->frame.header.duration.seconds * d->frame.header.samplerate;
570 569
571 return 10000000; 570 return 10000000;
572} 571}
573 572
574 573
575bool LibMadPlugin::audioSetSample( long, int ) { 574bool LibMadPlugin::audioSetSample( long, int ) {
576 debugMsg( "LibMadPlugin::audioSetSample" ); 575 debugMsg( "LibMadPlugin::audioSetSample" );
577 return FALSE; 576 return FALSE;
578} 577}
579 578
580 579
581long LibMadPlugin::audioGetSample( int ) { 580long LibMadPlugin::audioGetSample( int ) {
582 debugMsg( "LibMadPlugin::audioGetSample" ); 581 debugMsg( "LibMadPlugin::audioGetSample" );
583 return 0; 582 return 0;
584} 583}
585 584
586/* 585/*
587bool LibMadPlugin::audioReadSamples( short *, int, long, int ) { 586bool LibMadPlugin::audioReadSamples( short *, int, long, int ) {
588debugMsg( "LibMadPlugin::audioReadSamples" ); 587debugMsg( "LibMadPlugin::audioReadSamples" );
589return FALSE; 588return FALSE;
590} 589}
591 590
592 591
593bool LibMadPlugin::audioReReadSamples( short *, int, long, int ) { 592bool LibMadPlugin::audioReReadSamples( short *, int, long, int ) {
594debugMsg( "LibMadPlugin::audioReReadSamples" ); 593debugMsg( "LibMadPlugin::audioReReadSamples" );
595 return FALSE; 594 return FALSE;
596 } 595 }
597*/ 596*/
598 597
599bool LibMadPlugin::read() { 598bool LibMadPlugin::read() {
600 debugMsg( "LibMadPlugin::read" ); 599 debugMsg( "LibMadPlugin::read" );
601 int len; 600 int len;
602 601
603 if (d->input.eof) 602 if (d->input.eof)
604 return FALSE; 603 return FALSE;
605 604
606#if defined(HAVE_MMAP) 605#if defined(HAVE_MMAP)
607 if (d->input.fdm) { 606 if (d->input.fdm) {
608 unsigned long skip = 0; 607 unsigned long skip = 0;
609 608
610 if (d->stream.next_frame) { 609 if (d->stream.next_frame) {
611 struct stat stat; 610 struct stat stat;
612 611
613 if (fstat(d->input.fd, &stat) == -1) 612 if (fstat(d->input.fd, &stat) == -1)
614 return FALSE; 613 return FALSE;
615 614
616 if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length) 615 if (stat.st_size + MAD_BUFFER_GUARD <= (signed)d->input.length)
617 return FALSE; 616 return FALSE;
618 617
619 // file size changed; update memory map 618 // file size changed; update memory map
620 skip = d->stream.next_frame - d->input.data; 619 skip = d->stream.next_frame - d->input.data;
621 620
622 if (unmap_file(d->input.fdm, d->input.length) == -1) { 621 if (unmap_file(d->input.fdm, d->input.length) == -1) {
623 d->input.fdm = 0; 622 d->input.fdm = 0;
624 d->input.data = 0; 623 d->input.data = 0;
625 return FALSE; 624 return FALSE;
626 } 625 }
627 626
628 d->input.length = stat.st_size; 627 d->input.length = stat.st_size;
629 628
630 d->input.fdm = map_file(d->input.fd, &d->input.length); 629 d->input.fdm = map_file(d->input.fd, &d->input.length);
631 if (d->input.fdm == 0) { 630 if (d->input.fdm == 0) {
632 d->input.data = 0; 631 d->input.data = 0;
633 return FALSE; 632 return FALSE;
634 } 633 }
635 634
636 d->input.data = (unsigned char *)d->input.fdm; 635 d->input.data = (unsigned char *)d->input.fdm;
637 } 636 }
638 637
639 mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip); 638 mad_stream_buffer(&d->stream, d->input.data + skip, d->input.length - skip);
640 639
641 } else 640 } else
642#endif 641#endif
643 { 642 {
644 if (d->stream.next_frame) { 643 if (d->stream.next_frame) {
645 memmove(d->input.data, d->stream.next_frame, 644 memmove(d->input.data, d->stream.next_frame,
646 d->input.length = &d->input.data[d->input.length] - d->stream.next_frame); 645 d->input.length = &d->input.data[d->input.length] - d->stream.next_frame);
647 } 646 }
648 647
649 do { 648 do {
650 len = ::read(d->input.fd, d->input.data + d->input.length, bufferSize /* MPEG_BUFFER_SIZE*/ - d->input.length); 649 len = ::read(d->input.fd, d->input.data + d->input.length, bufferSize /* MPEG_BUFFER_SIZE*/ - d->input.length);
651 } 650 }
652 while (len == -1 && errno == EINTR); 651 while (len == -1 && errno == EINTR);
653 652
654 if (len == -1) { 653 if (len == -1) {
655 qDebug("error reading audio"); 654 qDebug("error reading audio");
656 return FALSE; 655 return FALSE;
657 } 656 }
658 else if (len == 0) { 657 else if (len == 0) {
659 d->input.eof = 1; 658 d->input.eof = 1;
660 659
661 assert(bufferSize /*MPEG_BUFFER_SIZE*/ - d->input.length >= MAD_BUFFER_GUARD); 660 assert(bufferSize /*MPEG_BUFFER_SIZE*/ - d->input.length >= MAD_BUFFER_GUARD);
662 661
663 while (len < MAD_BUFFER_GUARD) 662 while (len < MAD_BUFFER_GUARD)
664 d->input.data[d->input.length + len++] = 0; 663 d->input.data[d->input.length + len++] = 0;
665 } 664 }
666 665
667 mad_stream_buffer(&d->stream, d->input.data, d->input.length += len); 666 mad_stream_buffer(&d->stream, d->input.data, d->input.length += len);
668 } 667 }
669 668
670 return TRUE; 669 return TRUE;
671} 670}
672 671
673 672
674static mad_fixed_t left_err, right_err; 673static mad_fixed_t left_err, right_err;
675static const int bits = 16; 674static const int bits = 16;
676static const int shift = MAD_F_FRACBITS + 1 - bits; 675static const int shift = MAD_F_FRACBITS + 1 - bits;
677 676
678 677
679inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) { 678inline long audio_linear_dither( mad_fixed_t sample, mad_fixed_t& error ) {
680 sample += error; 679 sample += error;
681 mad_fixed_t quantized = (sample >= MAD_F_ONE) ? MAD_F_ONE - 1 : ( (sample < -MAD_F_ONE) ? -MAD_F_ONE : sample ); 680 mad_fixed_t quantized = (sample >= MAD_F_ONE) ? MAD_F_ONE - 1 : ( (sample < -MAD_F_ONE) ? -MAD_F_ONE : sample );
682 quantized &= ~((1L << shift) - 1); 681 quantized &= ~((1L << shift) - 1);
683 error = sample - quantized; 682 error = sample - quantized;
684 return quantized >> shift; 683 return quantized >> shift;
685} 684}
686 685
687 686
688inline void audio_pcm( short *data, unsigned int nsamples, mad_fixed_t *left, mad_fixed_t *right ) { 687inline void audio_pcm( short *data, unsigned int nsamples, mad_fixed_t *left, mad_fixed_t *right ) {
689 if ( right ) { 688 if ( right ) {
690 while (nsamples--) { 689 while (nsamples--) {
691 data[0] = audio_linear_dither( *left++, left_err ); 690 data[0] = audio_linear_dither( *left++, left_err );
692 data[1] = audio_linear_dither( *right++, right_err ); 691 data[1] = audio_linear_dither( *right++, right_err );
693 data += 2; 692 data += 2;
694 } 693 }
695 } else { 694 } else {
696 while (nsamples--) { 695 while (nsamples--) {
697 data[0] = data[1] = audio_linear_dither( *left++, left_err ); 696 data[0] = data[1] = audio_linear_dither( *left++, left_err );
698 data += 2; 697 data += 2;
699 } 698 }
700 } 699 }
701} 700}
702 701
703 702
704bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) { 703bool LibMadPlugin::decode( short *output, long samples, long& samplesMade ) {
705 debugMsg( "LibMadPlugin::decode" ); 704 debugMsg( "LibMadPlugin::decode" );
706 705
707 static int buffered = 0; 706 static int buffered = 0;
708 static mad_fixed_t buffer[2][65536 * 2]; 707 static mad_fixed_t buffer[2][65536 * 2];
709 int offset = buffered; 708 int offset = buffered;
710 samplesMade = 0; 709 samplesMade = 0;
711 710
712 static int maxBuffered = 8000; // 65536; 711 static int maxBuffered = 8000; // 65536;
713 712
714 if ( samples > maxBuffered ) { 713 if ( samples > maxBuffered ) {
715 samples = maxBuffered; 714 samples = maxBuffered;
716 } 715 }
717 716
718 if ( d->flush ) { 717 if ( d->flush ) {
719 buffered = 0; 718 buffered = 0;
720 offset = 0; 719 offset = 0;
721 d->flush = FALSE; 720 d->flush = FALSE;
722 } 721 }
723 722
724 while ( buffered < maxBuffered ) { 723 while ( buffered < maxBuffered ) {
725 724
726 while (mad_frame_decode(&d->frame, &d->stream) == -1) { 725 while (mad_frame_decode(&d->frame, &d->stream) == -1) {
727 if (!MAD_RECOVERABLE(d->stream.error)) { 726 if (!MAD_RECOVERABLE(d->stream.error)) {
728 debugMsg( "feed me" ); 727 debugMsg( "feed me" );
729 return FALSE; // Feed me 728 return FALSE; // Feed me
730 } 729 }
731 if ( d->stream.error == MAD_ERROR_BADCRC ) { 730 if ( d->stream.error == MAD_ERROR_BADCRC ) {
732 mad_frame_mute(&d->frame); 731 mad_frame_mute(&d->frame);
733 qDebug( "error decoding, bad crc" ); 732 qDebug( "error decoding, bad crc" );
734 } 733 }
735 } 734 }
736 735
737 mad_synth_frame(&d->synth, &d->frame); 736 mad_synth_frame(&d->synth, &d->frame);
738 int decodedSamples = d->synth.pcm.length; 737 int decodedSamples = d->synth.pcm.length;
739 memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) ); 738 memcpy( &(buffer[0][offset]), d->synth.pcm.samples[0], decodedSamples * sizeof(mad_fixed_t) );
740 if ( d->synth.pcm.channels == 2 ) 739 if ( d->synth.pcm.channels == 2 )
741 memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) ); 740 memcpy( &(buffer[1][offset]), d->synth.pcm.samples[1], decodedSamples * sizeof(mad_fixed_t) );
742 offset += decodedSamples; 741 offset += decodedSamples;
743 buffered += decodedSamples; 742 buffered += decodedSamples;
744 } 743 }
745 744
746//qApp->processEvents(); 745//qApp->processEvents();
747 audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 ); 746 audio_pcm( output, samples, buffer[0], (d->synth.pcm.channels == 2) ? buffer[1] : 0 );
748// audio_pcm( output, samples, buffer[1], buffer[0] ); 747// audio_pcm( output, samples, buffer[1], buffer[0] );
749// audio_pcm( output, samples, buffer[0], buffer[1] ); 748// audio_pcm( output, samples, buffer[0], buffer[1] );
750 samplesMade = samples; 749 samplesMade = samples;
751 memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); 750 memmove( buffer[0], &(buffer[0][samples]), (buffered - samples) * sizeof(mad_fixed_t) );
752 if ( d->synth.pcm.channels == 2 ) { 751 if ( d->synth.pcm.channels == 2 ) {
753 memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) ); 752 memmove( buffer[1], &(buffer[1][samples]), (buffered - samples) * sizeof(mad_fixed_t) );
754 } 753 }
755 buffered -= samples; 754 buffered -= samples;
756 755
757 return TRUE; 756 return TRUE;
758} 757}
759 758
760/*bool LibMadPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) { 759/*bool LibMadPlugin::audioReadStereoSamples( short *output, long samples, long& samplesMade, int ) {
761*/ 760*/
762bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long samples, long& samplesMade, int ) { 761bool LibMadPlugin::audioReadSamples( short *output, int /*channels*/, long samples, long& samplesMade, int ) {
763 debugMsg( "LibMadPlugin::audioReadStereoSamples" ); 762 debugMsg( "LibMadPlugin::audioReadStereoSamples" );
764 763
765 static bool needInput = TRUE; 764 static bool needInput = TRUE;
766 765
767 if ( samples == 0 ) 766 if ( samples == 0 )
768 return FALSE; 767 return FALSE;
769 768
770 do { 769 do {
771 if ( needInput ) 770 if ( needInput )
772 if ( !read() ) { 771 if ( !read() ) {
773 return FALSE; 772 return FALSE;
774 } 773 }
775 774
776 needInput = FALSE; 775 needInput = FALSE;
777 776
778 if ( decode( output, samples, samplesMade ) ) 777 if ( decode( output, samples, samplesMade ) )
779 return TRUE; 778 return TRUE;
780 else 779 else
781 needInput = TRUE; 780 needInput = TRUE;
782 } 781 }
783 while ( ( samplesMade < samples ) && ( !d->input.eof ) ); 782 while ( ( samplesMade < samples ) && ( !d->input.eof ) );
784 783
785 return FALSE; 784 return FALSE;
786} 785}
787 786
788 787
789double LibMadPlugin::getTime() { 788double LibMadPlugin::getTime() {
790 debugMsg( "LibMadPlugin::getTime" ); 789 debugMsg( "LibMadPlugin::getTime" );
791 return 0.0; 790 return 0.0;
792} 791}
793 792
794 793
795void LibMadPlugin::printID3Tags() { 794void LibMadPlugin::printID3Tags() {
796 qDebug( "LibMadPlugin::printID3Tags" ); 795 qDebug( "LibMadPlugin::printID3Tags" );
797 796
798 char id3v1[128 + 1]; 797 char id3v1[128 + 1];
799 798
800 if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) { 799 if ( ::lseek( d->input.fd, -128, SEEK_END ) == -1 ) {
801 qDebug( "error seeking to id3 tags" ); 800 qDebug( "error seeking to id3 tags" );
802 return; 801 return;
803 } 802 }
804 803
805 if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) { 804 if ( ::read( d->input.fd, id3v1, 128 ) != 128 ) {
806 qDebug( "error reading in id3 tags" ); 805 qDebug( "error reading in id3 tags" );
807 return; 806 return;
808 } 807 }
809 808
810 if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) { 809 if ( ::strncmp( (const char *)id3v1, "TAG", 3 ) != 0 ) {
811 debugMsg( "sorry, no id3 tags" ); 810 debugMsg( "sorry, no id3 tags" );
812 } else { 811 } else {
813 int len[5] = { 30, 30, 30, 4, 30 }; 812 int len[5] = { 30, 30, 30, 4, 30 };
814 QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) }; 813 QString label[5] = { tr( "Title" ), tr( "Artist" ), tr( "Album" ), tr( "Year" ), tr( "Comment" ) };
815 char *ptr = id3v1 + 3, *ptr2 = ptr + len[0]; 814 char *ptr = id3v1 + 3, *ptr2 = ptr + len[0];
816 qDebug( "ID3 tags in file:" ); 815 qDebug( "ID3 tags in file:" );
817 info = ""; 816 info = "";
818 for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) { 817 for ( int i = 0; i < 5; ptr += len[i], i++, ptr2 += len[i] ) {
819 char push = *ptr2; 818 char push = *ptr2;
820 *ptr2 = '\0'; 819 *ptr2 = '\0';
821 char *ptr3 = ptr2; 820 char *ptr3 = ptr2;
822 while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--; 821 while ( ptr3-1 >= ptr && isspace(ptr3[-1]) ) ptr3--;
823 char push2 = *ptr3; *ptr3 = '\0'; 822 char push2 = *ptr3; *ptr3 = '\0';
824 if ( strcmp( ptr, "" ) ) 823 if ( strcmp( ptr, "" ) ) {
824 if( ((QString)ptr).find(" ") == -1) // don't add anything that has blanks
825 info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr; 825 info += ( i != 0 ? ", " : "" ) + label[i] + ": " + ptr;
826 //qDebug( info.latin1() ); 826 }
827// qDebug( info.latin1() );
827 *ptr3 = push2; 828 *ptr3 = push2;
828 *ptr2 = push; 829 *ptr2 = push;
829 } 830 }
830 if (id3v1[126] == 0 && id3v1[127] != 0) 831 if (id3v1[126] == 0 && id3v1[127] != 0)
831 info += tr( ", Track: " ) + id3v1[127]; 832 info += tr( ", Track: " ) + id3v1[127];
832 } 833 }
833 834
834 if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) { 835 if ( ::lseek(d->input.fd, 0, SEEK_SET) == -1 ) {
835 qDebug( "error seeking back to beginning" ); 836 qDebug( "error seeking back to beginning" );
836 return; 837 return;
837 } 838 }
838} 839}
839 840