VLC does _not_ work with multicast, but VLS surely does (Even more info)

Roy Sigurd Karlsbakk roy at karlsbakk.net
Tue Jul 16 21:30:13 CEST 2002


> hi all
>
> After hours, I've come to the conclusion that VLC doesn't work with
> multicast. I've tested playing from localhost, from other computers and -
> at last - from a Windows machine connected to a damn hub together with
> the server.
>
> nothing
>
> If I do the same over Unicast, it works fine

Trying to check for VLS failure...

The error is _not_ VLS. I wrote a small program (below) to join the given 
multicast group, reposition to the next TS packet and dump it all from there 
to STDOUT, and it works fine. Somehow VLC doesn't understand it, but that's 
probably because it wants some nice start of files.

So - what the hell is VLC doing wrong?

roy
--
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define MC_GROUP			"239.1.1.3"
#define MC_PORT				1234
#define BUFFERSIZE			(1024 * 32)

#endif

int main() {
	int s,addrlen,br;
	struct sockaddr_in addr;
	struct ip_mreq mreq;
	char buf[BUFFERSIZE];
	int firstblock = 1;
	int fbcounter;

	s = socket(AF_INET, SOCK_DGRAM, 0);
	if (s == -1) {
		perror("socket");
		exit(1);
	}

	addr.sin_family=AF_INET;
	addr.sin_addr.s_addr=htonl(INADDR_ANY); /* N.B.: differs from sender */
	addr.sin_port=htons(MC_PORT);

	if (bind(s,(struct sockaddr *) &addr,sizeof(addr)) < 0) {
		perror("bind");
		exit(1);
	}
    
	mreq.imr_multiaddr.s_addr=inet_addr(MC_GROUP);
	mreq.imr_interface.s_addr=htonl(INADDR_ANY);

	if (setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
		perror("setsockopt");
		exit(1);
	}

	while (1) {
		addrlen=sizeof(addr);
		if ((br = recvfrom(s, buf, BUFFERSIZE, 0, (struct sockaddr *) &addr, 
&addrlen)) < 0) {
			perror("recvfrom");
			exit(1);
		}
		if (firstblock) {
			fbcounter = 0;
			while (1) {
				while (buf[fbcounter] != 0x47)
					fbcounter++;
				if (buf[fbcounter+188] == 0x47 && 
					buf[fbcounter+376] == 0x47 && 
					buf[fbcounter+564] == 0x47 && 
					buf[fbcounter+752] == 0x47)
					break;
				if (fbcounter > 188) {
					fprintf(stderr, "unknown stream format\n");
					exit(1);
				}
			}
			br-=fbcounter;
			write(1, &buf[fbcounter], br);
			firstblock++;
		} else {
			write(1, buf, br);
		}
	}

	return 0;
}


-- 
Roy Sigurd Karlsbakk, Datavaktmester

Computers are like air conditioners.
They stop working when you open Windows.


-- 
This is the vlc-devel mailing-list, see http://www.videolan.org/vlc/
To unsubscribe, please read http://www.videolan.org/lists.html
If you are in trouble, please contact <postmaster at videolan.org>



More information about the vlc-devel mailing list