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