From 82e0fd2095632e19ef377a89721bd0d99d90e17e Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Fri, 1 Dec 2017 16:09:40 -0800 Subject: [PATCH] Default multicast interface address to "0.0.0.0" if absent It aligns with what a lot of other apps are doing, e.g. tsplay. Also added notes in docker to adjust network setting if wants to use multicast in docker container. Change-Id: I666a8979cc041c904f7ff8e3e022f800c0830d5d --- docs/source/docker_instructions.md | 8 ++++++++ docs/source/options/udp_file_options.rst | 2 +- packager/file/udp_file.cc | 6 ------ packager/file/udp_options.h | 4 ++-- packager/file/udp_options_unittest.cc | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docs/source/docker_instructions.md b/docs/source/docker_instructions.md index c1f73b6ced..13a350e0e3 100644 --- a/docs/source/docker_instructions.md +++ b/docs/source/docker_instructions.md @@ -32,6 +32,14 @@ This runs the container and maps `host_media_path` to `media` in the container: $ docker run -v /host_media_path/:/media -it --rm google/shaka-packager ``` +Note that the networking in the container is containerized by default, so if +you want to access UDP multicast in the host network, you will need to configure +the network explicitly. You may do this with `--net=host` option, i.e. + +```shell +$ docker run -v /host_media_path/:/media -it --net=host --rm google/shaka-packager +``` + Then in the container, run the packager command, e.g.: ```shell diff --git a/docs/source/options/udp_file_options.rst b/docs/source/options/udp_file_options.rst index 05de7102dd..025c524d16 100644 --- a/docs/source/options/udp_file_options.rst +++ b/docs/source/options/udp_file_options.rst @@ -11,7 +11,7 @@ options: :interface=, source=: Multicast group interface address. Only the packets sent to this address is - received. + received. Default to "0.0.0.0" if not specified. :timeout=: diff --git a/packager/file/udp_file.cc b/packager/file/udp_file.cc index 6bb9445cd6..256947e958 100644 --- a/packager/file/udp_file.cc +++ b/packager/file/udp_file.cc @@ -207,12 +207,6 @@ bool UdpFile::Open() { struct ip_mreq multicast_group; multicast_group.imr_multiaddr = local_in_addr; - if (options->interface_address().empty()) { - LOG(ERROR) << "Interface address is required for multicast, which can be " - "specified in udp url, e.g. " - "udp://ip:port?interface=interface_ip."; - return false; - } if (inet_pton(AF_INET, options->interface_address().c_str(), &multicast_group.imr_interface) != 1) { LOG(ERROR) << "Malformed IPv4 interface address " diff --git a/packager/file/udp_options.h b/packager/file/udp_options.h index eb016ac6b0..23981fea40 100644 --- a/packager/file/udp_options.h +++ b/packager/file/udp_options.h @@ -31,12 +31,12 @@ class UdpOptions { UdpOptions() = default; /// IP Address. - std::string address_; + std::string address_ = "0.0.0.0"; uint16_t port_ = 0; /// Allow or disallow reusing UDP sockets. bool reuse_ = false; // Address of the interface over which to receive UDP multicast streams. - std::string interface_address_; + std::string interface_address_ = "0.0.0.0"; /// Timeout in microseconds. 0 to indicate unlimited timeout. unsigned timeout_us_ = 0; }; diff --git a/packager/file/udp_options_unittest.cc b/packager/file/udp_options_unittest.cc index c422c51b62..f690db414f 100644 --- a/packager/file/udp_options_unittest.cc +++ b/packager/file/udp_options_unittest.cc @@ -25,7 +25,7 @@ TEST_F(UdpOptionsTest, AddressAndPort) { EXPECT_EQ(88u, options->port()); // The below fields are not set. EXPECT_FALSE(options->reuse()); - EXPECT_EQ("", options->interface_address()); + EXPECT_EQ("0.0.0.0", options->interface_address()); EXPECT_EQ(0u, options->timeout_us()); } @@ -62,7 +62,7 @@ TEST_F(UdpOptionsTest, Reuse) { EXPECT_EQ("224.1.2.30", options->address()); EXPECT_EQ(88u, options->port()); EXPECT_TRUE(options->reuse()); - EXPECT_EQ("", options->interface_address()); + EXPECT_EQ("0.0.0.0", options->interface_address()); EXPECT_EQ(0u, options->timeout_us()); }