diff options
-rw-r--r-- | doc/example.mux | 2 | ||||
-rw-r--r-- | src/input/Edi.cpp | 23 |
2 files changed, 23 insertions, 2 deletions
diff --git a/doc/example.mux b/doc/example.mux index 383a2ab..d53b789 100644 --- a/doc/example.mux +++ b/doc/example.mux @@ -215,6 +215,8 @@ subchannels { ;inputuri "udp://:9001" ; Multicast UDP input: ;inputuri "udp://@239.10.0.1:9001" + ; Multicast UDP input with local interface (192.168.0.10) specification + ;inputuri "udp://192.168.0.10@239.10.0.1:9001" ; Two buffer-management types are available: prebuffering and timestamped. ; prebuffering will accumulate a few frames before it starts streaming, and each diff --git a/src/input/Edi.cpp b/src/input/Edi.cpp index 3838541..fc380d8 100644 --- a/src/input/Edi.cpp +++ b/src/input/Edi.cpp @@ -81,6 +81,7 @@ void Edi::open(const std::string& name) { const std::regex re_udp("udp://:([0-9]+)"); const std::regex re_udp_multicast("udp://@([0-9.]+):([0-9]+)"); + const std::regex re_udp_multicast_bindto("udp://([0-9.])+@([0-9.]+):([0-9]+)"); const std::regex re_tcp("tcp://(.*):([0-9]+)"); lock_guard<mutex> lock(m_mutex); @@ -97,13 +98,31 @@ void Edi::open(const std::string& name) m_udp_sock.reinit(udp_port); m_udp_sock.setBlocking(false); } + else if (std::regex_match(name, m, re_udp_multicast_bindto)) { + const string bind_to = m[1].str(); + const string multicast_address = m[2].str(); + const int udp_port = std::stoi(m[3].str()); + + m_input_used = InputUsed::UDP; + if (IN_MULTICAST(ntohl(inet_addr(multicast_address.c_str())))) { + m_udp_sock.init_receive_multicast(udp_port, bind_to, multicast_address); + } + else { + throw runtime_error(string("Address ") + multicast_address + " is not a multicast address"); + } + m_udp_sock.setBlocking(false); + } else if (std::regex_match(name, m, re_udp_multicast)) { const string multicast_address = m[1].str(); const int udp_port = std::stoi(m[2].str()); m_input_used = InputUsed::UDP; - m_udp_sock.reinit(udp_port); + if (IN_MULTICAST(ntohl(inet_addr(multicast_address.c_str())))) { + m_udp_sock.init_receive_multicast(udp_port, "0.0.0.0", multicast_address); + } + else { + throw runtime_error(string("Address ") + multicast_address + " is not a multicast address"); + } m_udp_sock.setBlocking(false); - m_udp_sock.joinGroup(multicast_address.c_str()); } else if (std::regex_match(name, m, re_tcp)) { m_input_used = InputUsed::TCP; |