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 | |||
@@ -163,21 +163,83 @@ bool LibMadPlugin::isFileSupported( const QString& path ) { | |||
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; |
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 | |||
@@ -102,6 +102,8 @@ public: | |||
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 ); |