author | harlekin <harlekin> | 2002-04-21 12:00:04 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-04-21 12:00:04 (UTC) |
commit | c7a23ea04b627db855934fac5061d7e291cdf230 (patch) (unidiff) | |
tree | 1c9e8d615e70f53a17f7dfb055a7aee5b4912d12 | |
parent | 6cf7106e761ed81c28f73338f2e431b41d54ed4e (diff) | |
download | opie-c7a23ea04b627db855934fac5061d7e291cdf230.zip opie-c7a23ea04b627db855934fac5061d7e291cdf230.tar.gz opie-c7a23ea04b627db855934fac5061d7e291cdf230.tar.bz2 |
added udp support
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.cpp | 72 | ||||
-rw-r--r-- | core/multimedia/opieplayer/libmad/libmadplugin.h | 2 |
2 files changed, 69 insertions, 5 deletions
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.cpp b/core/multimedia/opieplayer/libmad/libmadplugin.cpp index 7bb6541..6793773 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.cpp +++ b/core/multimedia/opieplayer/libmad/libmadplugin.cpp | |||
@@ -102,143 +102,205 @@ static void *map_file(int fd, unsigned long *length) | |||
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( "OpiePlayer", 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 | |||
171 | // UGLY - just for fast testing | 172 | // UGLY - just for fast testing |
172 | if ( path.left(4) == "http") { | 173 | if ( path.left(4) == "http") { |
173 | return TRUE; | 174 | return TRUE; |
174 | } | 175 | } |
175 | 176 | ||
177 | return FALSE; | ||
178 | } | ||
179 | |||
176 | 180 | ||
177 | return FALSE; | 181 | |
182 | int LibMadPlugin::is_address_multicast(unsigned long address) { | ||
183 | if ((address & 255) >= 224 && (address & 255) <= 239) | ||
184 | return (1); | ||
185 | return (0); | ||
178 | } | 186 | } |
179 | 187 | ||
180 | 188 | ||
189 | int LibMadPlugin::udp_open(char *address, int port) { | ||
190 | |||
191 | int enable = 1L; | ||
192 | struct sockaddr_in stAddr; | ||
193 | struct sockaddr_in stLclAddr; | ||
194 | struct ip_mreq stMreq; | ||
195 | struct hostent *host; | ||
196 | int sock; | ||
197 | |||
198 | stAddr.sin_family = AF_INET; | ||
199 | stAddr.sin_port = htons(port); | ||
200 | |||
201 | if ((host = gethostbyname(address)) == NULL) | ||
202 | return (0); | ||
203 | |||
204 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); | ||
205 | |||
206 | /* Create a UDP socket */ | ||
207 | if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) | ||
208 | return (0); | ||
209 | |||
210 | /* Allow multiple instance of the client to share the same address and port */ | ||
211 | if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&enable, sizeof(unsigned long int)) < 0) | ||
212 | return (0); | ||
213 | |||
214 | /* If the address is multicast, register to the multicast group */ | ||
215 | if (is_address_multicast(stAddr.sin_addr.s_addr)) | ||
216 | { | ||
217 | /* Bind the socket to port */ | ||
218 | stLclAddr.sin_family = AF_INET; | ||
219 | stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
220 | stLclAddr.sin_port = stAddr.sin_port; | ||
221 | if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) | ||
222 | return (0); | ||
223 | |||
224 | /* Register to a multicast address */ | ||
225 | stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr; | ||
226 | stMreq.imr_interface.s_addr = INADDR_ANY; | ||
227 | if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq, sizeof(stMreq)) < 0) | ||
228 | return (0); | ||
229 | } | ||
230 | else | ||
231 | { | ||
232 | /* Bind the socket to port */ | ||
233 | stLclAddr.sin_family = AF_INET; | ||
234 | stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); | ||
235 | stLclAddr.sin_port = htons(0); | ||
236 | if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) | ||
237 | return (0); | ||
238 | } | ||
239 | |||
240 | return (sock); | ||
241 | } | ||
242 | |||
181 | int LibMadPlugin::tcp_open(char *address, int port) { | 243 | int LibMadPlugin::tcp_open(char *address, int port) { |
182 | struct sockaddr_in stAddr; | 244 | struct sockaddr_in stAddr; |
183 | struct hostent *host; | 245 | struct hostent *host; |
184 | int sock; | 246 | int sock; |
185 | struct linger l; | 247 | struct linger l; |
186 | 248 | ||
187 | memset(&stAddr, 0, sizeof(stAddr)); | 249 | memset(&stAddr, 0, sizeof(stAddr)); |
188 | stAddr.sin_family = AF_INET; | 250 | stAddr.sin_family = AF_INET; |
189 | stAddr.sin_port = htons(port); | 251 | stAddr.sin_port = htons(port); |
190 | 252 | ||
191 | if ((host = gethostbyname(address)) == NULL) | 253 | if ((host = gethostbyname(address)) == NULL) |
192 | return (0); | 254 | return (0); |
193 | 255 | ||
194 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); | 256 | stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); |
195 | 257 | ||
196 | if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) | 258 | if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) |
197 | return (0); | 259 | return (0); |
198 | 260 | ||
199 | l.l_onoff = 1; | 261 | l.l_onoff = 1; |
200 | l.l_linger = 5; | 262 | l.l_linger = 5; |
201 | if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) | 263 | if (setsockopt(sock, SOL_SOCKET, SO_LINGER, (char *)&l, sizeof(l)) < 0) |
202 | return (0); | 264 | return (0); |
203 | 265 | ||
204 | if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) | 266 | if (connect(sock, (struct sockaddr *)&stAddr, sizeof(stAddr)) < 0) |
205 | return (0); | 267 | return (0); |
206 | 268 | ||
207 | return (sock); | 269 | return (sock); |
208 | } | 270 | } |
209 | 271 | ||
210 | 272 | ||
211 | /** | 273 | /** |
212 | * Read a http line header. | 274 | * Read a http line header. |
213 | * This function read character by character. | 275 | * This function read character by character. |
214 | * @param tcp_sock the socket use to read the stream | 276 | * @param tcp_sock the socket use to read the stream |
215 | * @param buf a buffer to receive the data | 277 | * @param buf a buffer to receive the data |
216 | * @param size size of the buffer | 278 | * @param size size of the buffer |
217 | * @return the size of the stream read or -1 if an error occured | 279 | * @return the size of the stream read or -1 if an error occured |
218 | */ | 280 | */ |
219 | int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { | 281 | int LibMadPlugin::http_read_line(int tcp_sock, char *buf, int size) { |
220 | int offset = 0; | 282 | int offset = 0; |
221 | 283 | ||
222 | do | 284 | do |
223 | { | 285 | { |
224 | if (std::read(tcp_sock, buf + offset, 1) < 0) | 286 | if (std::read(tcp_sock, buf + offset, 1) < 0) |
225 | return -1; | 287 | return -1; |
226 | if (buf[offset] != '\r') /* Strip \r from answer */ | 288 | if (buf[offset] != '\r') /* Strip \r from answer */ |
227 | offset++; | 289 | offset++; |
228 | } | 290 | } |
229 | while (offset < size - 1 && buf[offset - 1] != '\n'); | 291 | while (offset < size - 1 && buf[offset - 1] != '\n'); |
230 | 292 | ||
231 | buf[offset] = 0; | 293 | buf[offset] = 0; |
232 | return offset; | 294 | return offset; |
233 | } | 295 | } |
234 | 296 | ||
235 | int LibMadPlugin::http_open(const QString& path ) { | 297 | int LibMadPlugin::http_open(const QString& path ) { |
236 | char *host; | 298 | char *host; |
237 | int port; | 299 | int port; |
238 | char *request; | 300 | char *request; |
239 | int tcp_sock; | 301 | int tcp_sock; |
240 | char http_request[PATH_MAX]; | 302 | char http_request[PATH_MAX]; |
241 | char filename[PATH_MAX]; | 303 | char filename[PATH_MAX]; |
242 | char c; | 304 | char c; |
243 | char *arg =strdup(path.latin1()); | 305 | char *arg =strdup(path.latin1()); |
244 | 306 | ||
diff --git a/core/multimedia/opieplayer/libmad/libmadplugin.h b/core/multimedia/opieplayer/libmad/libmadplugin.h index ee1ca9d..6747712 100644 --- a/core/multimedia/opieplayer/libmad/libmadplugin.h +++ b/core/multimedia/opieplayer/libmad/libmadplugin.h | |||
@@ -41,75 +41,77 @@ public: | |||
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 | ||
47 | bool close(); | 47 | bool close(); |
48 | bool isOpen(); | 48 | bool isOpen(); |
49 | const QString &fileInfo() { return info; } | 49 | const QString &fileInfo() { return info; } |
50 | 50 | ||
51 | // If decoder doesn't support audio then return 0 here | 51 | // If decoder doesn't support audio then return 0 here |
52 | int audioStreams(); | 52 | int audioStreams(); |
53 | int audioChannels( int stream ); | 53 | int audioChannels( int stream ); |
54 | int audioFrequency( int stream ); | 54 | int audioFrequency( int stream ); |
55 | int audioSamples( int stream ); | 55 | int audioSamples( int stream ); |
56 | bool audioSetSample( long sample, int stream ); | 56 | bool audioSetSample( long sample, int stream ); |
57 | /* int audioBitsPerSample(int) {return 0;} */ | 57 | /* int audioBitsPerSample(int) {return 0;} */ |
58 | long audioGetSample( int stream ); | 58 | long audioGetSample( int stream ); |
59 | #ifdef OLD_MEDIAPLAYER_API | 59 | #ifdef OLD_MEDIAPLAYER_API |
60 | bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); | 60 | bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); |
61 | bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); | 61 | bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); |
62 | bool audioReadSamples( short *output, int channel, long samples, int stream ); | 62 | bool audioReadSamples( short *output, int channel, long samples, int stream ); |
63 | bool audioReReadSamples( short *output, int channel, long samples, int stream ); | 63 | bool audioReReadSamples( short *output, int channel, long samples, int stream ); |
64 | #else | 64 | #else |
65 | 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 ); |
66 | #endif | 66 | #endif |
67 | 67 | ||
68 | 68 | ||
69 | bool read(); | 69 | bool read(); |
70 | bool decode( short *output, long samples, long& samplesRead ); | 70 | bool decode( short *output, long samples, long& samplesRead ); |
71 | void printID3Tags(); | 71 | void printID3Tags(); |
72 | 72 | ||
73 | 73 | ||
74 | // If decoder doesn't support video then return 0 here | 74 | // If decoder doesn't support video then return 0 here |
75 | int videoStreams() { return 0; } | 75 | int videoStreams() { return 0; } |
76 | int videoWidth( int ) { return 0; } | 76 | int videoWidth( int ) { return 0; } |
77 | int videoHeight( int ) { return 0; } | 77 | int videoHeight( int ) { return 0; } |
78 | double videoFrameRate( int ) { return 0.0; } | 78 | double videoFrameRate( int ) { return 0.0; } |
79 | int videoFrames( int ) { return 0; } | 79 | int videoFrames( int ) { return 0; } |
80 | bool videoSetFrame( long, int ) { return FALSE; } | 80 | bool videoSetFrame( long, int ) { return FALSE; } |
81 | long videoGetFrame( int ) { return 0; } | 81 | long videoGetFrame( int ) { return 0; } |
82 | 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; } |
83 | 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; } |
84 | 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; } |
85 | 85 | ||
86 | // Profiling | 86 | // Profiling |
87 | double getTime(); | 87 | double getTime(); |
88 | 88 | ||
89 | // Ignore if these aren't supported | 89 | // Ignore if these aren't supported |
90 | bool setSMP( int ) { return FALSE; } | 90 | bool setSMP( int ) { return FALSE; } |
91 | bool setMMX( bool ) { return FALSE; } | 91 | bool setMMX( bool ) { return FALSE; } |
92 | 92 | ||
93 | // Capabilities | 93 | // Capabilities |
94 | bool supportsAudio() { return TRUE; } | 94 | bool supportsAudio() { return TRUE; } |
95 | bool supportsVideo() { return FALSE; } | 95 | bool supportsVideo() { return FALSE; } |
96 | bool supportsYUV() { return FALSE; } | 96 | bool supportsYUV() { return FALSE; } |
97 | bool supportsMMX() { return TRUE; } | 97 | bool supportsMMX() { return TRUE; } |
98 | bool supportsSMP() { return FALSE; } | 98 | bool supportsSMP() { return FALSE; } |
99 | bool supportsStereo() { return TRUE; } | 99 | bool supportsStereo() { return TRUE; } |
100 | bool supportsScaling() { return FALSE; } | 100 | bool supportsScaling() { return FALSE; } |
101 | 101 | ||
102 | long getPlayTime() { return -1; } | 102 | long getPlayTime() { return -1; } |
103 | 103 | ||
104 | private: | 104 | private: |
105 | int is_address_multicast(unsigned long address); | ||
106 | int udp_open(char *address, int port); | ||
105 | int tcp_open(char *address, int port); | 107 | int tcp_open(char *address, int port); |
106 | int http_read_line(int tcp_sock, char *buf, int size) ; | 108 | int http_read_line(int tcp_sock, char *buf, int size) ; |
107 | int http_open(const QString& path ); | 109 | int http_open(const QString& path ); |
108 | 110 | ||
109 | LibMadPluginData *d; | 111 | LibMadPluginData *d; |
110 | QString info; | 112 | QString info; |
111 | int bufferSize; | 113 | int bufferSize; |
112 | }; | 114 | }; |
113 | 115 | ||
114 | 116 | ||
115 | #endif | 117 | #endif |