Skip to content

Commit

Permalink
WebRTC: Support config, listener and SDP for TCP transport.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Sep 4, 2022
1 parent 424713a commit 770d959
Show file tree
Hide file tree
Showing 14 changed files with 767 additions and 386 deletions.
21 changes: 21 additions & 0 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,27 @@ rtc_server {
# The udp listen port, we will reuse it for connections.
# default: 8000
listen 8000;
# For WebRTC over TCP directly, not TURN, see https://github.com/ossrs/srs/issues/2852
# Some network does not support UDP, or not very well, so we use TCP like HTTP/80 port for firewall traversing.
tcp {
# Whether enable WebRTC over TCP.
# Overwrite by env SRS_RTC_SERVER_TCP_ENABLED
# Default: off
enabled off;
# The TCP listen port for WebRTC. Highly recommend is some normally used ports, such as TCP/80, TCP/443,
# TCP/8000, TCP/8080 etc. However SRS default to TCP/8000 corresponding to UDP/8000.
# Overwrite by env SRS_RTC_SERVER_TCP_LISTEN
# Default: 8000
listen 8000;
}
# The protocol for candidate to use, it can be:
# udp Generate UDP candidates. Note that UDP server is always enabled for WebRTC.
# tcp Generate TCP candidates. Fail if rtc_server.tcp(WebRTC over TCP) is disabled.
# all Generate UDP+TCP candidates. Ignore if rtc_server.tcp(WebRTC over TCP) is disabled.
# Note that if both are connected, we will use the first connected(DTLS done) one.
# Overwrite by env SRS_RTC_SERVER_PROTOCOL
# Default: udp
protocol udp;
# The exposed candidate IPs, response in SDP candidate line. It can be:
# * Retrieve server IP automatically, from all network interfaces.
# $CANDIDATE Read the IP from ENV variable, use * if not set.
Expand Down
2 changes: 1 addition & 1 deletion trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_sourc
"srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_edge"
"srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_http_static"
"srs_app_recv_thread" "srs_app_security" "srs_app_statistic" "srs_app_hds"
"srs_app_mpegts_udp" "srs_app_listener" "srs_app_async_call"
"srs_app_mpegts_udp" "srs_app_listener" "srs_app_async_call" "srs_app_rtc_network"
"srs_app_caster_flv" "srs_app_latest_version" "srs_app_uuid" "srs_app_process" "srs_app_ng_exec"
"srs_app_hourglass" "srs_app_dash" "srs_app_fragment" "srs_app_dvr"
"srs_app_coworkers" "srs_app_hybrid" "srs_app_threads")
Expand Down
71 changes: 69 additions & 2 deletions trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2289,8 +2289,8 @@ srs_error_t SrsConfig::check_normal_config()
SrsConfDirective* conf = root->get("rtc_server");
for (int i = 0; conf && i < (int)conf->directives.size(); i++) {
string n = conf->at(i)->name;
if (n != "enabled" && n != "listen" && n != "dir" && n != "candidate" && n != "ecdsa"
&& n != "encrypt" && n != "reuseport" && n != "merge_nalus" && n != "black_hole"
if (n != "enabled" && n != "listen" && n != "dir" && n != "candidate" && n != "ecdsa" && n != "tcp"
&& n != "encrypt" && n != "reuseport" && n != "merge_nalus" && n != "black_hole" && n != "protocol"
&& n != "ip_family" && n != "api_as_candidates" && n != "resolve_api_domain"
&& n != "keep_api_domain" && n != "use_auto_detect_network_ip") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal rtc_server.%s", n.c_str());
Expand Down Expand Up @@ -3701,6 +3701,73 @@ bool SrsConfig::get_use_auto_detect_network_ip()
return SRS_CONF_PERFER_TRUE(conf->arg0());
}

bool SrsConfig::get_rtc_server_tcp_enabled()
{
SRS_OVERWRITE_BY_ENV_BOOL("SRS_RTC_SERVER_TCP_ENABLED");

static bool DEFAULT = false;

SrsConfDirective* conf = root->get("rtc_server");
if (!conf) {
return DEFAULT;
}

conf = conf->get("tcp");
if (!conf) {
return DEFAULT;
}

conf = conf->get("enabled");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}

return SRS_CONF_PERFER_FALSE(conf->arg0());
}

int SrsConfig::get_rtc_server_tcp_listen()
{
SRS_OVERWRITE_BY_ENV_INT("SRS_RTC_SERVER_TCP_LISTEN");

static int DEFAULT = 8000;

SrsConfDirective* conf = root->get("rtc_server");
if (!conf) {
return DEFAULT;
}

conf = conf->get("tcp");
if (!conf) {
return DEFAULT;
}

conf = conf->get("listen");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}

return ::atoi(conf->arg0().c_str());
}

std::string SrsConfig::get_rtc_server_protocol()
{
SRS_OVERWRITE_BY_ENV_STRING("SRS_RTC_SERVER_PROTOCOL");

static string DEFAULT = "udp";

SrsConfDirective* conf = root->get("rtc_server");
if (!conf) {
return DEFAULT;
}

conf = conf->get("protocol");
if (!conf || conf->arg0().empty()) {
return DEFAULT;
}

return conf->arg0();
}

std::string SrsConfig::get_rtc_server_ip_family()
{
static string DEFAULT = "ipv4";
Expand Down
3 changes: 3 additions & 0 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ class SrsConfig
virtual bool get_resolve_api_domain();
virtual bool get_keep_api_domain();
virtual bool get_use_auto_detect_network_ip();
virtual bool get_rtc_server_tcp_enabled();
virtual int get_rtc_server_tcp_listen();
virtual std::string get_rtc_server_protocol();
virtual std::string get_rtc_server_ip_family();
virtual bool get_rtc_server_ecdsa();
virtual bool get_rtc_server_encrypt();
Expand Down
Loading

1 comment on commit 770d959

@winlinvip
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For #2852

Please sign in to comment.