-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index 0fcc230..7bb6541 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp | |||
@@ -1,248 +1,248 @@ | |||
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 | 37 | // for network handling |
38 | #include <netinet/in.h> | 38 | #include <netinet/in.h> |
39 | #include <netdb.h> | 39 | #include <netdb.h> |
40 | #include <sys/socket.h> | 40 | #include <sys/socket.h> |
41 | #include <arpa/inet.h> | 41 | #include <arpa/inet.h> |
42 | #include <unistd.h> | 42 | #include <unistd.h> |
43 | 43 | ||
44 | 44 | ||
45 | //#define HAVE_MMAP | 45 | //#define HAVE_MMAP |
46 | 46 | ||
47 | #if defined(HAVE_MMAP) | 47 | #if defined(HAVE_MMAP) |
48 | # include <sys/mman.h> | 48 | # include <sys/mman.h> |
49 | #endif | 49 | #endif |
50 | #include "libmadplugin.h" | 50 | #include "libmadplugin.h" |
51 | 51 | ||
52 | 52 | ||
53 | extern "C" { | 53 | extern "C" { |
54 | #include "mad.h" | 54 | #include "mad.h" |
55 | } | 55 | } |
56 | 56 | ||
57 | 57 | ||
58 | #define MPEG_BUFFER_SIZE 65536 | 58 | #define MPEG_BUFFER_SIZE 65536 |
59 | //#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 | 59 | //#define MPEG_BUFFER_SIZE 32768 //16384 // 8192 |
60 | //#define debugMsg(a) qDebug(a) | 60 | //#define debugMsg(a) qDebug(a) |
61 | #define debugMsg(a) | 61 | #define debugMsg(a) |
62 | 62 | ||
63 | 63 | ||
64 | class Input { | 64 | class Input { |
65 | public: | 65 | public: |
66 | char const *path; | 66 | char const *path; |
67 | int fd; | 67 | int fd; |
68 | #if defined(HAVE_MMAP) | 68 | #if defined(HAVE_MMAP) |
69 | void *fdm; | 69 | void *fdm; |
70 | #endif | 70 | #endif |
71 | unsigned char *data; | 71 | unsigned char *data; |
72 | unsigned long length; | 72 | unsigned long length; |
73 | int eof; | 73 | int eof; |
74 | }; | 74 | }; |
75 | 75 | ||
76 | 76 | ||
77 | class Output { | 77 | class Output { |
78 | public: | 78 | public: |
79 | mad_fixed_t attenuate; | 79 | mad_fixed_t attenuate; |
80 | struct filter *filters; | 80 | struct filter *filters; |
81 | unsigned int channels_in; | 81 | unsigned int channels_in; |
82 | unsigned int channels_out; | 82 | unsigned int channels_out; |
83 | unsigned int speed_in; | 83 | unsigned int speed_in; |
84 | unsigned int speed_out; | 84 | unsigned int speed_out; |
85 | const char *path; | 85 | const char *path; |
86 | }; | 86 | }; |
87 | 87 | ||
88 | 88 | ||
89 | # if defined(HAVE_MMAP) | 89 | # if defined(HAVE_MMAP) |
90 | static void *map_file(int fd, unsigned long *length) | 90 | static void *map_file(int fd, unsigned long *length) |
91 | { | 91 | { |
92 | void *fdm; | 92 | void *fdm; |
93 | 93 | ||
94 | *length += MAD_BUFFER_GUARD; | 94 | *length += MAD_BUFFER_GUARD; |
95 | 95 | ||
96 | fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0); | 96 | fdm = mmap(0, *length, PROT_READ, MAP_SHARED, fd, 0); |
97 | if (fdm == MAP_FAILED) | 97 | if (fdm == MAP_FAILED) |
98 | return 0; | 98 | return 0; |
99 | 99 | ||
100 | # if defined(HAVE_MADVISE) | 100 | # if defined(HAVE_MADVISE) |
101 | madvise(fdm, *length, MADV_SEQUENTIAL); | 101 | madvise(fdm, *length, MADV_SEQUENTIAL); |
102 | # endif | 102 | # endif |
103 | 103 | ||
104 | return fdm; | 104 | return fdm; |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | static int unmap_file(void *fdm, unsigned long length) | 108 | static int unmap_file(void *fdm, unsigned long length) |
109 | { | 109 | { |
110 | if (munmap(fdm, length) == -1) | 110 | if (munmap(fdm, length) == -1) |
111 | return -1; | 111 | return -1; |
112 | 112 | ||
113 | return 0; | 113 | return 0; |
114 | } | 114 | } |
115 | # endif | 115 | # endif |
116 | 116 | ||
117 | 117 | ||
118 | static inline QString tr( const char *str ) { | 118 | static inline QString tr( const char *str ) { |
119 | // 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 |
120 | return qApp->translate( "MediaPlayer", str, "libmad strings for mp3 file info" ); | 120 | return qApp->translate( "OpiePlayer", str, "libmad strings for mp3 file info" ); |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | class LibMadPluginData { | 124 | class LibMadPluginData { |
125 | public: | 125 | public: |
126 | Input input; | 126 | Input input; |
127 | Output output; | 127 | Output output; |
128 | int bad_last_frame; | 128 | int bad_last_frame; |
129 | struct mad_stream stream; | 129 | struct mad_stream stream; |
130 | struct mad_frame frame; | 130 | struct mad_frame frame; |
131 | struct mad_synth synth; | 131 | struct mad_synth synth; |
132 | bool flush; | 132 | bool flush; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | 135 | ||
136 | LibMadPlugin::LibMadPlugin() { | 136 | LibMadPlugin::LibMadPlugin() { |
137 | d = new LibMadPluginData; | 137 | d = new LibMadPluginData; |
138 | d->input.fd = 0; | 138 | d->input.fd = 0; |
139 | #if defined(HAVE_MMAP) | 139 | #if defined(HAVE_MMAP) |
140 | d->input.fdm = 0; | 140 | d->input.fdm = 0; |
141 | #endif | 141 | #endif |
142 | d->input.data = 0; | 142 | d->input.data = 0; |
143 | d->flush = TRUE; | 143 | d->flush = TRUE; |
144 | info = tr( "No Song Open" ); | 144 | info = tr( "No Song Open" ); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | LibMadPlugin::~LibMadPlugin() { | 148 | LibMadPlugin::~LibMadPlugin() { |
149 | close(); | 149 | close(); |
150 | delete d; | 150 | delete d; |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | bool LibMadPlugin::isFileSupported( const QString& path ) { | 154 | bool LibMadPlugin::isFileSupported( const QString& path ) { |
155 | debugMsg( "LibMadPlugin::isFileSupported" ); | 155 | debugMsg( "LibMadPlugin::isFileSupported" ); |
156 | 156 | ||
157 | // Mpeg file extensions | 157 | // Mpeg file extensions |
158 | // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" | 158 | // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" |
159 | // Other media extensions | 159 | // Other media extensions |
160 | // "wav","mid","mod","s3m","ogg","avi","mov","sid" | 160 | // "wav","mid","mod","s3m","ogg","avi","mov","sid" |
161 | 161 | ||
162 | char *ext = strrchr( path.latin1(), '.' ); | 162 | char *ext = strrchr( path.latin1(), '.' ); |
163 | 163 | ||
164 | // Test file extension | 164 | // Test file extension |
165 | if ( ext ) { | 165 | if ( ext ) { |
166 | if ( strncasecmp(ext, ".mp2", 4) == 0 ) | 166 | if ( strncasecmp(ext, ".mp2", 4) == 0 ) |
167 | return TRUE; | 167 | return TRUE; |
168 | if ( strncasecmp(ext, ".mp3", 4) == 0 ) | 168 | if ( strncasecmp(ext, ".mp3", 4) == 0 ) |
169 | return TRUE; | 169 | return TRUE; |
170 | } | 170 | } |
171 | // UGLY - just for fast testing | 171 | // UGLY - just for fast testing |
172 | if ( path.left(4) == "http") { | 172 | if ( path.left(4) == "http") { |
173 | return TRUE; | 173 | return TRUE; |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
177 | return FALSE; | 177 | return FALSE; |
178 | } | 178 | } |
179 | 179 | ||
180 | 180 | ||
181 | int LibMadPlugin::tcp_open(char *address, int port) { | 181 | int LibMadPlugin::tcp_open(char *address, int port) { |
182 | struct sockaddr_in stAddr; | 182 | struct sockaddr_in stAddr; |
183 | struct hostent *host; | 183 | struct hostent *host; |
184 | int sock; | 184 | int sock; |
185 | struct linger l; | 185 | struct linger l; |
186 | 186 | ||
187 | memset(&stAddr, 0, sizeof(stAddr)); | 187 | memset(&stAddr, 0, sizeof(stAddr)); |
188 | stAddr.sin_family = AF_INET; | 188 | stAddr.sin_family = AF_INET; |
189 | stAddr.sin_port = htons(port); | 189 | stAddr.sin_port = htons(port); |
190 | 190 | ||
191 | if ((host = gethostbyname(address)) == NULL) | 191 | if ((host = gethostbyname(address)) == NULL) |
192 | return (0); | 192 | return (0); |
193 | 193 | ||
194 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); | 194 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); |
195 | 195 | ||
196 | if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) | 196 | if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) |
197 | return (0); | 197 | return (0); |
198 | 198 | ||
199 | l.l_onoff = 1; | 199 | l.l_onoff = 1; |
200 | l.l_linger = 5; | 200 | l.l_linger = 5; |
201 | if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) | 201 | if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) |
202 | return (0); | 202 | return (0); |
203 | 203 | ||
204 | if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) | 204 | if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) |
205 | return (0); | 205 | return (0); |
206 | 206 | ||
207 | return (sock); | 207 | return (sock); |
208 | } | 208 | } |
209 | 209 | ||
210 | 210 | ||
211 | /** | 211 | /** |
212 | * Read a http line header. | 212 | * Read a http line header. |
213 | * This function read character by character. | 213 | * This function read character by character. |
214 | * @param tcp_sock the socket use to read the stream | 214 | * @param tcp_sock the socket use to read the stream |
215 | * @param buf a buffer to receive the data | 215 | * @param buf a buffer to receive the data |
216 | * @param size size of the buffer | 216 | * @param size size of the buffer |
217 | * @return the size of the stream read or -1 if an error occured | 217 | * @return the size of the stream read or -1 if an error occured |
218 | */ | 218 | */ |
219 | int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { | 219 | int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { |
220 | int offset = 0; | 220 | int offset = 0; |
221 | 221 | ||
222 | do | 222 | do |
223 | { | 223 | { |
224 | if (std::read(tcp_sock, buf + offset, 1) < 0) | 224 | if (std::read(tcp_sock, buf + offset, 1) < 0) |
225 | return -1; | 225 | return -1; |
226 | if (buf[offset] != '\r') /* Strip \r from answer */ | 226 | if (buf[offset] != '\r') /* Strip \r from answer */ |
227 | offset++; | 227 | offset++; |
228 | } | 228 | } |
229 | while (offset < size - 1 && buf[offset - 1] != '\n'); | 229 | while (offset < size - 1 && buf[offset - 1] != '\n'); |
230 | 230 | ||
231 | buf[offset] = 0; | 231 | buf[offset] = 0; |
232 | return offset; | 232 | return offset; |
233 | } | 233 | } |
234 | 234 | ||
235 | int LibMadPlugin::http_open(const QString& path ) { | 235 | int LibMadPlugin::http_open(const QString& path ) { |
236 | char *host; | 236 | char *host; |
237 | int port; | 237 | int port; |
238 | char *request; | 238 | char *request; |
239 | int tcp_sock; | 239 | int tcp_sock; |
240 | char http_request[PATH_MAX]; | 240 | char http_request[PATH_MAX]; |
241 | char filename[PATH_MAX]; | 241 | char filename[PATH_MAX]; |
242 | char c; | 242 | char c; |
243 | char *arg =strdup(path.latin1()); | 243 | char *arg =strdup(path.latin1()); |
244 | 244 | ||
245 | /* Check for URL syntax */ | 245 | /* Check for URL syntax */ |
246 | if (strncmp(arg, "http://", strlen("http://"))) | 246 | if (strncmp(arg, "http://", strlen("http://"))) |
247 | return (0); | 247 | return (0); |
248 | 248 | ||