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
This commit is contained in:
KongQun Yang 2017-12-01 16:09:40 -08:00
parent 0fdb0d02aa
commit 82e0fd2095
5 changed files with 13 additions and 11 deletions

View File

@ -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

View File

@ -11,7 +11,7 @@ options:
:interface=<addr>, source=<addr>:
Multicast group interface address. Only the packets sent to this address is
received.
received. Default to "0.0.0.0" if not specified.
:timeout=<microseconds>:

View File

@ -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 "

View File

@ -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;
};

View File

@ -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());
}