turingmachine / omxplayer-sync

OMXPlayer-Sync facilitates synchronization of multiple OMXPlayer instances over the network in a master/slave fashion.
194 stars 70 forks source link

Multiple groups of synced videos sharing same network #115

Open demmaone opened 2 years ago

demmaone commented 2 years ago

Hello, I've been using omxplayer-sync for a while with great results. Now I have to make 6 o 7 groups of players but they have to be in the same network sharing the same switch. Should I play with the port (currently 1666) or should I try to force the slaves to look for an specific master IP? (I don't know what the bind do here: https://github.com/turingmachine/omxplayer-sync/commit/ccb139daf190bdf05bf4e192558caefbfb32bb97). Any help would be great, meanwhile I'll keep trying. Thanks in advance.

barlaensdoonn commented 2 years ago

This is an interesting question, and i'm curious what others have to say about it - i'm no networking expert, and i don't know if this can be solved with the call to bind that you linked to.

In an ideal world you would have each group on its own isolated network, any troubleshooting would benefit from this setup... but you seem to be limited to a single network, so let's proceed under that constraint.

The OMXPlayerSync class uses UDP sockets to broadcast messages to all hosts on the network. This configuration can be seen in the init_socket (socket.SOCK_DGRAM is UDP) and the master-specific socket_enable_broadcast methods.

A simple approach I've successfully used in the past to single out a specific server on the network from a pool of servers listening for UDP broadcast messages is to prepend the message with a string - like a hostname - that the servers parse and then decide if they should act on it or not. This would work the same for groups of servers too. For example in send_position_local, you would change the message being sent to include a string that specifies a group, let's say 'groupA':

self.sock.send(("{}%{}%{}".format('groupA', str(self.position_local), self.filename)).encode('utf-8'))

Then in read_position_master you'd add some logic to determine if the message is meant for the particular server that is parsing the message. This means both the sender and receiver would need to know which group they are in... you'd probably want to add an option to the OptionParser to declare this group value as a command line argument when calling omxplayer-sync. More code changes are likely needed to get this working properly, but that's a theoretical starting point.


The thing that most interested me about your question is if it's possible to have multiple clients sending UDP broadcast messages to all available hosts on the same port on the same network. I have never tried this, but it seems like it may be possible by using the SO_REUSEPORT socket option, which you can most likely set in the call to setsockopt.

Reference for how that socket option works: https://stackoverflow.com/questions/14388706/how-do-so-reuseaddr-and-so-reuseport-differ

magdesign commented 2 years ago

Does the socket method work?