[Live-devel] Read 2 video streams from 2 different multicast address on the same port

Aeschbacher, Fabrice Fabrice.Aeschbacher at siemens.com
Thu Nov 8 01:34:34 PST 2007


Hi,

We have a multithreaded application (using live555 / linux) acquiring
many video streams (RTP/multicast) and displaying them on differents
video outputs (monitors).

Under circumstances, some of our customers want to use for their video
sources two different multicast addresses (let's say 239.61.87.46 and
239.61.87.46), but the same port (say 8000)

Unfortunately, when reading the two RTP streams, live555 seems to mix
the two streams into one.

I wrote a small test program to try to reproduce this error: one
multicast_reader(ip,port), one multicast_writer(ip, port,text). I
started the following test:
  $ multicast_reader 239.61.87.46 8000
  $ multicast_reader 239.61.87.47 8000
  $ multicast_writer 239.61.87.46 8000 "hello, world!"

and effectively, the two multicast readers become the same datagram.

The raison for this is the following lines in the reader's code:

    saddr.sin_family = PF_INET;
    saddr.sin_port = htons(port);
   
    // Following DOES NOT work as expected: the socket will become
datagrams from
    // ALL multicast addresses on the same port
    saddr.sin_addr.s_addr = htonl(INADDR_ANY); // bind socket to any
interface
    status = bind(sock, (struct sockaddr *)&saddr, sizeof(struct
sockaddr_in));

The solution is not to bind with INADDR_ANY, but with the desired
multicast address:

    // Whereas following works: socket will only see datagrams from
'multicast_addr'
    saddr.sin_addr.s_addr = inet_addr(multicast_addr);
    status = bind(sock, (struct sockaddr *)&saddr, sizeof(struct
sockaddr_in));

With this small modification in the reader's code, the test runs as
expected: every reader becomes only the datagrams for its multicast
address.


Now, the problem is to try to do the same with live555 library.
The socket for the reader is created in setupDatagramSocket():

    MAKE_SOCKADDR_IN(name, ReceivingInterfaceAddr, port.num());
    if (bind(newSocket, (struct sockaddr*)&name, sizeof name) != 0) {
    ...

By default, ReceivingInterfaceAddr is INADDR_ANY: that's why we get the
two video streams mixed on the video output.
The problem is that ReceivingInterfaceAddr is a global variable. We
would need here one different value (i.e. multicast address) for each
reader.

Could you give me some advise here to help me with this issue?

Best regards,
Fabrice Aeschbacher


More information about the live-devel mailing list