Skip to content

Commit

Permalink
[apps] Added 'bind' parameter handling for applications (#2672).
Browse files Browse the repository at this point in the history
  • Loading branch information
ethouris committed Feb 17, 2023
1 parent 806f474 commit 46d55c6
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions apps/transmitmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,24 @@ void SrtCommon::InitParameters(string host, map<string,string> par)
}
}

if (par.count("bind"))
{
string bindspec = par.at("bind");
UriParser u (bindspec, UriParser::EXPECT_HOST);
if ( u.scheme() != ""
|| u.path() != ""
|| !u.parameters().empty()
|| u.portno() == 0)
{
Error("Invalid syntax in 'bind' option");
}

if (u.host() != "")
par["adapter"] = u.host();
par["port"] = u.port();
par.erase("bind");
}

string adapter;
if (par.count("adapter"))
{
Expand Down
1 change: 1 addition & 0 deletions docs/apps/srt-live-transmit.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ srt://:5001?adapter=10.10.10.100
- *port* part: remote port to connect to (mandatory)
- **port** parameter: the local port to bind (default: 0 - "system autoselection")
- **adapter** parameter: the local IP address to bind (default: 0.0.0.0 - "system selected device")
- **bind** parameter: a shortcut to set adapter or port by specifying ADAPTER:PORT

```yaml
srt://remote.host.com:5001
Expand Down
19 changes: 19 additions & 0 deletions testing/testmedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,24 @@ void SrtCommon::InitParameters(string host, string path, map<string,string> par)
#endif
}

if (par.count("bind"))
{
string bindspec = par.at("bind");
UriParser u (bindspec, UriParser::EXPECT_HOST);
if ( u.scheme() != ""
|| u.path() != ""
|| !u.parameters().empty()
|| u.portno() == 0)
{
Error("Invalid syntax in 'bind' option");
}

if (u.host() != "")
par["adapter"] = u.host();
par["port"] = u.port();
par.erase("bind");
}

string adapter;
if (par.count("adapter"))
{
Expand Down Expand Up @@ -864,6 +882,7 @@ int SrtCommon::ConfigurePre(SRTSOCKET sock)

void SrtCommon::SetupAdapter(const string& host, int port)
{
Verb() << "Binding the caller socket to " << host << ":" << port << " ...";
auto lsa = CreateAddr(host, port);
int stat = srt_bind(m_sock, lsa.get(), sizeof lsa);
if (stat == SRT_ERROR)
Expand Down

0 comments on commit 46d55c6

Please sign in to comment.