author | harlekin <harlekin> | 2002-04-21 12:00:04 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-04-21 12:00:04 (UTC) |
commit | c7a23ea04b627db855934fac5061d7e291cdf230 (patch) (side-by-side diff) | |
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 @@ -150,47 +150,109 @@ LibMadPlugin::~LibMadPlugin() { delete d; } bool LibMadPlugin::isFileSupported( const QString& path ) { debugMsg( "LibMadPlugin::isFileSupported" ); // Mpeg file extensions // "mp2","mp3","m1v","m2v","m2s","mpg","vob","mpeg","ac3" // Other media extensions // "wav","mid","mod","s3m","ogg","avi","mov","sid" char *ext = strrchr( path.latin1(), '.' ); // Test file extension if ( ext ) { - if ( strncasecmp(ext, ".mp2", 4) == 0 ) - return TRUE; - if ( strncasecmp(ext, ".mp3", 4) == 0 ) - return TRUE; + if ( strncasecmp(ext, ".mp2", 4) == 0 ) + return TRUE; + if ( strncasecmp(ext, ".mp3", 4) == 0 ) + return TRUE; } + // UGLY - just for fast testing if ( path.left(4) == "http") { return TRUE; } + return FALSE; +} + - return FALSE; + +int LibMadPlugin::is_address_multicast(unsigned long address) { + if ((address & 255) >= 224 && (address & 255) <= 239) + return (1); + return (0); } +int LibMadPlugin::udp_open(char *address, int port) { + + int enable = 1L; + struct sockaddr_in stAddr; + struct sockaddr_in stLclAddr; + struct ip_mreq stMreq; + struct hostent *host; + int sock; + + stAddr.sin_family = AF_INET; + stAddr.sin_port = htons(port); + + if ((host = gethostbyname(address)) == NULL) + return (0); + + stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); + + /* Create a UDP socket */ + if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) < 0) + return (0); + + /* Allow multiple instance of the client to share the same address and port */ + if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&enable, sizeof(unsigned long int)) < 0) + return (0); + + /* If the address is multicast, register to the multicast group */ + if (is_address_multicast(stAddr.sin_addr.s_addr)) + { + /* Bind the socket to port */ + stLclAddr.sin_family = AF_INET; + stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); + stLclAddr.sin_port = stAddr.sin_port; + if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) + return (0); + + /* Register to a multicast address */ + stMreq.imr_multiaddr.s_addr = stAddr.sin_addr.s_addr; + stMreq.imr_interface.s_addr = INADDR_ANY; + if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&stMreq, sizeof(stMreq)) < 0) + return (0); + } + else + { + /* Bind the socket to port */ + stLclAddr.sin_family = AF_INET; + stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY); + stLclAddr.sin_port = htons(0); + if (bind(sock, (struct sockaddr *)&stLclAddr, sizeof(stLclAddr)) < 0) + return (0); + } + + return (sock); +} + int LibMadPlugin::tcp_open(char *address, int port) { struct sockaddr_in stAddr; struct hostent *host; int sock; struct linger l; memset(&stAddr, 0, sizeof(stAddr)); stAddr.sin_family = AF_INET; stAddr.sin_port = htons(port); if ((host = gethostbyname(address)) == NULL) return (0); stAddr.sin_addr = *((struct in_addr *)host->h_addr_list[0]); if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) 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 @@ -89,27 +89,29 @@ public: // Ignore if these aren't supported bool setSMP( int ) { return FALSE; } bool setMMX( bool ) { return FALSE; } // Capabilities bool supportsAudio() { return TRUE; } bool supportsVideo() { return FALSE; } bool supportsYUV() { return FALSE; } bool supportsMMX() { return TRUE; } bool supportsSMP() { return FALSE; } bool supportsStereo() { return TRUE; } bool supportsScaling() { return FALSE; } long getPlayTime() { return -1; } private: + int is_address_multicast(unsigned long address); + int udp_open(char *address, int port); int tcp_open(char *address, int port); int http_read_line(int tcp_sock, char *buf, int size) ; int http_open(const QString& path ); LibMadPluginData *d; QString info; int bufferSize; }; #endif |