roc-streaming / roc-toolkit

Real-time audio streaming over the network.
https://roc-streaming.org
Mozilla Public License 2.0
1.06k stars 213 forks source link

Broadcast support #308

Closed gavv closed 4 years ago

gavv commented 4 years ago

(This was initially reported via mailing list: https://www.freelists.org/post/roc/ROC-over-BROADCAST-IP)

Sending datagrams to broadcast address is permitted only when SO_BROADCAST socket option is enabled. Without it, sendto() returns EACCESS if the address is broadcast.

The reason for this is the common convention to disable broadcast messages unless explicitly enabled by user to prevent accidental flood.

We can't determine if the address is broadcast by just looking at it, and we should follow the common convention of not permitting it by default. Thus, we should add a way to explicitly enable it.

We should add bool broadcast flag to SocketAddr, and --broadcast command-line option to roc-send, which sets the flag on sender's bind address. If the flag is set, UDPSenderPort should call uv_udp_set_broadcast() to enable broadcast on the socket.

Later we will also add corresponding flag to roc_endpoint API.

gavv commented 4 years ago

Fixed with d159cdf3bedcf0bf09e7048568fa43c38db91c19 and 328f330cafed835e7348c46076c13f949b994187.

However note that broadcast may work extremely bad on Wi-Fi. See these SO threads:

The reasons are:

In result, the packet loss ratio is very high for me when using broadcast on WiFi, and there are a lot of glitches. Unicast works pretty good at the same time.

This can be worked around by increasing latency on receiver (e.g. --sess-latency=500ms) and redundancy level (repair to source packet ratio) on sender (e.g. --nbsrc 20 --nbrpr 80).