author | dwmw2 <dwmw2> | 2002-05-09 10:55:29 (UTC) |
---|---|---|
committer | dwmw2 <dwmw2> | 2002-05-09 10:55:29 (UTC) |
commit | d23dbae0bafac32e9f91bf7bf9d0f7721a893ddf (patch) (unidiff) | |
tree | 4a885128bb79823dab6e857e09460dd1de7210f8 | |
parent | 87b3b4dc4e32a7ffbe1ffd2d54b2eb8c23674c66 (diff) | |
download | opie-d23dbae0bafac32e9f91bf7bf9d0f7721a893ddf.zip opie-d23dbae0bafac32e9f91bf7bf9d0f7721a893ddf.tar.gz opie-d23dbae0bafac32e9f91bf7bf9d0f7721a893ddf.tar.bz2 |
include qregexp.h
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index eda5859..b06cdaa 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp | |||
@@ -1,294 +1,295 @@ | |||
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> | ||
39 | 40 | ||
40 | #include <qpe/config.h> | 41 | #include <qpe/config.h> |
41 | 42 | ||
42 | // for network handling | 43 | // for network handling |
43 | #include <netinet/in.h> | 44 | #include <netinet/in.h> |
44 | #include <netdb.h> | 45 | #include <netdb.h> |
45 | #include <sys/socket.h> | 46 | #include <sys/socket.h> |
46 | #include <arpa/inet.h> | 47 | #include <arpa/inet.h> |
47 | #include <unistd.h> | 48 | #include <unistd.h> |
48 | 49 | ||
49 | 50 | ||
50 | //#define HAVE_MMAP | 51 | //#define HAVE_MMAP |
51 | 52 | ||
52 | #if defined(HAVE_MMAP) | 53 | #if defined(HAVE_MMAP) |
53 | # include <sys/mman.h> | 54 | # include <sys/mman.h> |
54 | #endif | 55 | #endif |
55 | #include "libmadplugin.h" | 56 | #include "libmadplugin.h" |
56 | 57 | ||
57 | 58 | ||
58 | extern "C" { | 59 | extern "C" { |
59 | #include "mad.h" | 60 | #include "mad.h" |
60 | } | 61 | } |
61 | 62 | ||
62 | 63 | ||
63 | #define MPEG_BUFFER_SIZE 65536 | 64 | #define MPEG_BUFFER_SIZE 65536 |
64 | //#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 | 65 | //#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 |
65 | //#define debugMsg(a) qDebug(a) | 66 | //#define debugMsg(a) qDebug(a) |
66 | #define debugMsg(a) | 67 | #define debugMsg(a) |
67 | 68 | ||
68 | 69 | ||
69 | class Input { | 70 | class Input { |
70 | public: | 71 | public: |
71 | char const *path; | 72 | char const *path; |
72 | int fd; | 73 | int fd; |
73 | #if defined(HAVE_MMAP) | 74 | #if defined(HAVE_MMAP) |
74 | void *fdm; | 75 | void *fdm; |
75 | #endif | 76 | #endif |
76 | unsigned char *data; | 77 | unsigned char *data; |
77 | unsigned long length; | 78 | unsigned long length; |
78 | int eof; | 79 | int eof; |
79 | }; | 80 | }; |
80 | 81 | ||
81 | 82 | ||
82 | class Output { | 83 | class Output { |
83 | public: | 84 | public: |
84 | mad_fixed_t attenuate; | 85 | mad_fixed_t attenuate; |
85 | struct filter *filters; | 86 | struct filter *filters; |
86 | unsigned int channels_in; | 87 | unsigned int channels_in; |
87 | unsigned int channels_out; | 88 | unsigned int channels_out; |
88 | unsigned int speed_in; | 89 | unsigned int speed_in; |
89 | unsigned int speed_out; | 90 | unsigned int speed_out; |
90 | const char *path; | 91 | const char *path; |
91 | }; | 92 | }; |
92 | 93 | ||
93 | 94 | ||
94 | # if defined(HAVE_MMAP) | 95 | # if defined(HAVE_MMAP) |
95 | static void *map_file(int fd, unsigned long *length) | 96 | static void *map_file(int fd, unsigned long *length) |
96 | { | 97 | { |
97 | void *fdm; | 98 | void *fdm; |
98 | 99 | ||
99 | *length += MAD_BUFFER_GUARD; | 100 | *length += MAD_BUFFER_GUARD; |
100 | 101 | ||
101 | fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0); | 102 | fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0); |
102 | if (fdm == MAP_FAILED) | 103 | if (fdm == MAP_FAILED) |
103 | return 0; | 104 | return 0; |
104 | 105 | ||
105 | # if defined(HAVE_MADVISE) | 106 | # if defined(HAVE_MADVISE) |
106 | madvise(fdm, *length, MADV_SEQUENTIAL); | 107 | madvise(fdm, *length, MADV_SEQUENTIAL); |
107 | # endif | 108 | # endif |
108 | 109 | ||
109 | return fdm; | 110 | return fdm; |
110 | } | 111 | } |
111 | 112 | ||
112 | 113 | ||
113 | static int unmap_file(void *fdm, unsigned long length) | 114 | static int unmap_file(void *fdm, unsigned long length) |
114 | { | 115 | { |
115 | if (munmap(fdm, length) == -1) | 116 | if (munmap(fdm, length) == -1) |
116 | return -1; | 117 | return -1; |
117 | 118 | ||
118 | return 0; | 119 | return 0; |
119 | } | 120 | } |
120 | # endif | 121 | # endif |
121 | 122 | ||
122 | 123 | ||
123 | static inline QString tr( const char *str ) { | 124 | static inline QString tr( const char *str ) { |
124 | // Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin | 125 | // Apparently this is okay from a plugin as it runs in the process space of the owner of the plugin |
125 | return qApp->translate( "OpiePlayer", str, "libmad strings for mp3 file info" ); | 126 | return qApp->translate( "OpiePlayer", str, "libmad strings for mp3 file info" ); |
126 | } | 127 | } |
127 | 128 | ||
128 | 129 | ||
129 | class LibMadPluginData { | 130 | class LibMadPluginData { |
130 | public: | 131 | public: |
131 | Input input; | 132 | Input input; |
132 | Output output; | 133 | Output output; |
133 | int bad_last_frame; | 134 | int bad_last_frame; |
134 | struct mad_stream stream; | 135 | struct mad_stream stream; |
135 | struct mad_frame frame; | 136 | struct mad_frame frame; |
136 | struct mad_synth synth; | 137 | struct mad_synth synth; |
137 | bool flush; | 138 | bool flush; |
138 | }; | 139 | }; |
139 | 140 | ||
140 | 141 | ||
141 | LibMadPlugin::LibMadPlugin() { | 142 | LibMadPlugin::LibMadPlugin() { |
142 | d = new LibMadPluginData; | 143 | d = new LibMadPluginData; |
143 | d->input.fd = 0; | 144 | d->input.fd = 0; |
144 | #if defined(HAVE_MMAP) | 145 | #if defined(HAVE_MMAP) |
145 | d->input.fdm = 0; | 146 | d->input.fdm = 0; |
146 | #endif | 147 | #endif |
147 | d->input.data = 0; | 148 | d->input.data = 0; |
148 | d->flush = TRUE; | 149 | d->flush = TRUE; |
149 | info = tr( "No Song Open" ); | 150 | info = tr( "No Song Open" ); |
150 | } | 151 | } |
151 | 152 | ||
152 | 153 | ||
153 | LibMadPlugin::~LibMadPlugin() { | 154 | LibMadPlugin::~LibMadPlugin() { |
154 | close(); | 155 | close(); |
155 | delete d; | 156 | delete d; |
156 | } | 157 | } |
157 | 158 | ||
158 | 159 | ||
159 | bool LibMadPlugin::isFileSupported( const QString& path ) { | 160 | bool LibMadPlugin::isFileSupported( const QString& path ) { |
160 | debugMsg( "LibMadPlugin::isFileSupported" ); | 161 | debugMsg( "LibMadPlugin::isFileSupported" ); |
161 | 162 | ||
162 | // Mpeg file extensions | 163 | // Mpeg file extensions |
163 | // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" | 164 | // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" |
164 | // Other media extensions | 165 | // Other media extensions |
165 | // "wav","mid","mod","s3m","ogg","avi","mov","sid" | 166 | // "wav","mid","mod","s3m","ogg","avi","mov","sid" |
166 | 167 | ||
167 | char *ext = strrchr( path.latin1(), '.' ); | 168 | char *ext = strrchr( path.latin1(), '.' ); |
168 | 169 | ||
169 | // Test file extension | 170 | // Test file extension |
170 | if ( ext ) { | 171 | if ( ext ) { |
171 | if ( strncasecmp(ext, ".mp2", 4) == 0 ) | 172 | if ( strncasecmp(ext, ".mp2", 4) == 0 ) |
172 | return TRUE; | 173 | return TRUE; |
173 | if ( strncasecmp(ext, ".mp3", 4) == 0 ) | 174 | if ( strncasecmp(ext, ".mp3", 4) == 0 ) |
174 | return TRUE; | 175 | return TRUE; |
175 | } | 176 | } |
176 | 177 | ||
177 | // UGLY - just for fast testing | 178 | // UGLY - just for fast testing |
178 | if ( path.left(4) == "http") { | 179 | if ( path.left(4) == "http") { |
179 | return TRUE; | 180 | return TRUE; |
180 | } | 181 | } |
181 | 182 | ||
182 | return FALSE; | 183 | return FALSE; |
183 | } | 184 | } |
184 | 185 | ||
185 | 186 | ||
186 | 187 | ||
187 | int LibMadPlugin::is_address_multicast(unsigned long address) { | 188 | int LibMadPlugin::is_address_multicast(unsigned long address) { |
188 | if ((address & 255) >= 224 && (address & 255) <= 239) | 189 | if ((address & 255) >= 224 && (address & 255) <= 239) |
189 | return (1); | 190 | return (1); |
190 | return (0); | 191 | return (0); |
191 | } | 192 | } |
192 | 193 | ||
193 | 194 | ||
194 | int LibMadPlugin::udp_open(char *address, int port) { | 195 | int LibMadPlugin::udp_open(char *address, int port) { |
195 | 196 | ||
196 | int enable = 1L; | 197 | int enable = 1L; |
197 | struct sockaddr_in stAddr; | 198 | struct sockaddr_in stAddr; |
198 | struct sockaddr_in stLclAddr; | 199 | struct sockaddr_in stLclAddr; |
199 | struct ip_mreq stMreq; | 200 | struct ip_mreq stMreq; |
200 | struct hostent *host; | 201 | struct hostent *host; |
201 | int sock; | 202 | int sock; |
202 | 203 | ||
203 | stAddr.sin_family = AF_INET; | 204 | stAddr.sin_family = AF_INET; |
204 | stAddr.sin_port = htons(port); | 205 | stAddr.sin_port = htons(port); |
205 | 206 | ||
206 | if ((host = gethostbyname(address)) == NULL) { | 207 | if ((host = gethostbyname(address)) == NULL) { |
207 | return (0); | 208 | return (0); |
208 | } | 209 | } |
209 | 210 | ||
210 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); | 211 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); |
211 | 212 | ||
212 | /* Create a UDP socket */ | 213 | /* Create a UDP socket */ |
213 | if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | 214 | if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
214 | return (0); | 215 | return (0); |
215 | } | 216 | } |
216 | 217 | ||
217 | /* Allow multiple instance of the client to share the same address and port */ | 218 | /* Allow multiple instance of the client to share the same address and port */ |
218 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&enable, sizeof(unsigned long int)) < 0) { | 219 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&enable, sizeof(unsigned long int)) < 0) { |
219 | return (0); | 220 | return (0); |
220 | } | 221 | } |
221 | 222 | ||
222 | /* If the address is multicast, register to the multicast group */ | 223 | /* If the address is multicast, register to the multicast group */ |
223 | if (is_address_multicast(stAddr.sin_addr.s_addr)) { | 224 | if (is_address_multicast(stAddr.sin_addr.s_addr)) { |
224 | /* Bind the socket to port */ | 225 | /* Bind the socket to port */ |
225 | stLclAddr.sin_family = AF_INET; | 226 | stLclAddr.sin_family = AF_INET; |
226 | stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); | 227 | stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); |
227 | stLclAddr.sin_port = stAddr.sin_port; | 228 | stLclAddr.sin_port = stAddr.sin_port; |
228 | if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) { | 229 | if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) { |
229 | return (0); | 230 | return (0); |
230 | } | 231 | } |
231 | 232 | ||
232 | /* Register to a multicast address */ | 233 | /* Register to a multicast address */ |
233 | stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr; | 234 | stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr; |
234 | stMreq.imr_interface.s_addr = INADDR_ANY; | 235 | stMreq.imr_interface.s_addr = INADDR_ANY; |
235 | if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq, sizeof(stMreq)) < 0) { | 236 | if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq, sizeof(stMreq)) < 0) { |
236 | return (0); | 237 | return (0); |
237 | } | 238 | } |
238 | } else { | 239 | } else { |
239 | /* Bind the socket to port */ | 240 | /* Bind the socket to port */ |
240 | stLclAddr.sin_family = AF_INET; | 241 | stLclAddr.sin_family = AF_INET; |
241 | stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); | 242 | stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); |
242 | stLclAddr.sin_port = htons(0); | 243 | stLclAddr.sin_port = htons(0); |
243 | if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) { | 244 | if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) { |
244 | return (0); | 245 | return (0); |
245 | } | 246 | } |
246 | } | 247 | } |
247 | return (sock); | 248 | return (sock); |
248 | } | 249 | } |
249 | 250 | ||
250 | int LibMadPlugin::tcp_open(char *address, int port) { | 251 | int LibMadPlugin::tcp_open(char *address, int port) { |
251 | struct sockaddr_in stAddr; | 252 | struct sockaddr_in stAddr; |
252 | struct hostent *host; | 253 | struct hostent *host; |
253 | int sock; | 254 | int sock; |
254 | struct linger l; | 255 | struct linger l; |
255 | 256 | ||
256 | memset(&stAddr, 0, sizeof(stAddr)); | 257 | memset(&stAddr, 0, sizeof(stAddr)); |
257 | stAddr.sin_family = AF_INET; | 258 | stAddr.sin_family = AF_INET; |
258 | stAddr.sin_port = htons(port); | 259 | stAddr.sin_port = htons(port); |
259 | 260 | ||
260 | if ((host = gethostbyname(address)) == NULL) { | 261 | if ((host = gethostbyname(address)) == NULL) { |
261 | return (0); | 262 | return (0); |
262 | } | 263 | } |
263 | 264 | ||
264 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); | 265 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); |
265 | 266 | ||
266 | if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { | 267 | if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { |
267 | return (0); | 268 | return (0); |
268 | } | 269 | } |
269 | 270 | ||
270 | l.l_onoff = 1; | 271 | l.l_onoff = 1; |
271 | l.l_linger = 5; | 272 | l.l_linger = 5; |
272 | if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) { | 273 | if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) { |
273 | return (0); | 274 | return (0); |
274 | } | 275 | } |
275 | 276 | ||
276 | if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) { | 277 | if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) { |
277 | return (0); | 278 | return (0); |
278 | } | 279 | } |
279 | 280 | ||
280 | return (sock); | 281 | return (sock); |
281 | } | 282 | } |
282 | 283 | ||
283 | 284 | ||
284 | /** | 285 | /** |
285 | * Read a http line header. | 286 | * Read a http line header. |
286 | * This function read character by character. | 287 | * This function read character by character. |
287 | * @param tcp_sock the socket use to read the stream | 288 | * @param tcp_sock the socket use to read the stream |
288 | * @param buf a buffer to receive the data | 289 | * @param buf a buffer to receive the data |
289 | * @param size size of the buffer | 290 | * @param size size of the buffer |
290 | * @return the size of the stream read or -1 if an error occured | 291 | * @return the size of the stream read or -1 if an error occured |
291 | */ | 292 | */ |
292 | int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { | 293 | int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { |
293 | int offset = 0; | 294 | int offset = 0; |
294 | 295 | ||