From 51af2b477992aeb0587cb49629492b5b8b3690fd Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 14 Mar 2020 17:15:46 +0800 Subject: [PATCH] For #1638, #307, rtc conf support ENV. --- trunk/conf/full.conf | 19 +++++ trunk/conf/rtc.conf | 38 ++++----- trunk/research/players/rtc.html | 6 +- trunk/research/players/rtc_upload.html | 97 ---------------------- trunk/research/players/srs_rtc_player.html | 90 -------------------- trunk/src/app/srs_app_config.cpp | 7 +- trunk/src/app/srs_app_http_api.cpp | 2 +- trunk/src/app/srs_app_utility.cpp | 20 +++++ trunk/src/app/srs_app_utility.hpp | 4 + trunk/src/main/srs_main_server.cpp | 12 --- 10 files changed, 68 insertions(+), 227 deletions(-) delete mode 100644 trunk/research/players/rtc_upload.html delete mode 100644 trunk/research/players/srs_rtc_player.html diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 1a23b87c96..3c8abe1c69 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -306,6 +306,25 @@ srt_server { default_app live; } +############################################################################################# +# WebRTC server section +############################################################################################# +rtc { + # Whether enable WebRTC server. + # default: off + enabled on; + # The udp listen port, we will reuse it for connections. + # default: 8080 + listen 8000; + # The exposed candidate IP, response in SDP candidate line. + # It can be: + # * Retrieve server IP automatically, specified by stats.network for multiple networks. + # $CANDIDATE Read the IP from ENV variable $EIP, see https://github.com/ossrs/srs/issues/307#issuecomment-599028124 + # x.x.x.x A specified IP address or DNS name, which can be access by client such as Chrome. + # default: * + candidate *; +} + ############################################################################################# # Kafka sections ############################################################################################# diff --git a/trunk/conf/rtc.conf b/trunk/conf/rtc.conf index fe8d545ec1..03b42c75d1 100644 --- a/trunk/conf/rtc.conf +++ b/trunk/conf/rtc.conf @@ -1,40 +1,32 @@ -# main config for srs. -# @see full.conf for detail config. listen 1935; max_connections 1000; -srs_log_tank file; +srs_log_tank console; srs_log_file ./objs/srs.log; -http_api { - enabled on; - listen 1985; - raw_api { - enabled on; - allow_reload on; - allow_query on; - allow_update on; - } -} + http_server { enabled on; listen 8080; dir ./objs/nginx/html; } -rtc { + +http_api { enabled on; - listen 9527; - # candidate device ip: *(all interface), 192.168.1.1 ... - candidate *; + listen 1985; } stats { network 0; - disk sda sdb xvda xvdb; } -vhost __defaultVhost__ { - http_remux { - enabled on; - mount [vhost]/[app]/[stream].flv; - } +rtc { + enabled on; + # Listen at udp://8000 + listen 8000; + # The * means using IP of network interface stats.network, + # For example, if stats.network=0, then use IP of eth0 as candidate. + # @see https://github.com/ossrs/srs/issues/307#issuecomment-599028124 + candidate *; } +vhost __defaultVhost__ { +} diff --git a/trunk/research/players/rtc.html b/trunk/research/players/rtc.html index 4dd8e44f25..80cd1a2c08 100644 --- a/trunk/research/players/rtc.html +++ b/trunk/research/players/rtc.html @@ -7,7 +7,7 @@ rtc_media_player:
- + @@ -16,7 +16,7 @@ var PeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var SessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription; -var url = "http://hw.com:1985/api/v1/sdp/"; +var url = "http://localhost:1985/api/v1/sdp/"; var method = "POST"; var shouldBeAsync = true; @@ -40,7 +40,7 @@ pc.setLocalDescription(desc); - var sdp_json = {"sdp":desc.sdp, "app":"webrtc", "stream":"test"}; + var sdp_json = {"sdp":desc.sdp, "app":"live", "stream":"livestream"}; request.send(JSON.stringify(sdp_json)); }; diff --git a/trunk/research/players/rtc_upload.html b/trunk/research/players/rtc_upload.html deleted file mode 100644 index 68c515d8eb..0000000000 --- a/trunk/research/players/rtc_upload.html +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - -
local_media_player:
- -
rtc_media_player:
- - - - - - - diff --git a/trunk/research/players/srs_rtc_player.html b/trunk/research/players/srs_rtc_player.html deleted file mode 100644 index bbb605ab51..0000000000 --- a/trunk/research/players/srs_rtc_player.html +++ /dev/null @@ -1,90 +0,0 @@ - - - - - - - - -rtc_media_player:
- - - - - - - diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index a206dc6da1..cb47e12e01 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -4290,7 +4290,7 @@ bool SrsConfig::get_rtc_enabled(SrsConfDirective* conf) int SrsConfig::get_rtc_listen() { - static int DEFAULT = 9527; + static int DEFAULT = 8000; SrsConfDirective* conf = root->get("rtc"); if (!conf) { @@ -4318,6 +4318,11 @@ std::string SrsConfig::get_rtc_candidates() if (!conf || conf->arg0().empty()) { return DEFAULT; } + + string eip = srs_getenv(conf->arg0()); + if (!eip.empty()) { + return eip; + } return (conf->arg0().c_str()); } diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index fd418bf86c..5cf5fe038b 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -851,7 +851,7 @@ srs_error_t SrsGoApiSdp::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* obj->set("server", SrsJsonAny::integer(stat->server_id())); // XXX: ice candidate - //string candidate_str = "candidate:1 1 udp 2115783679 192.168.170.129:9527 typ host generation 0 ufrag " + //string candidate_str = "candidate:1 1 udp 2115783679 192.168.170.129:8000 typ host generation 0 ufrag " // + local_sdp.get_ice_ufrag() + "netwrok-cost 50"; //SrsJsonObject* candidate_obj = SrsJsonAny::object(); diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index 66ae112696..f6da9502fa 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -1227,3 +1227,23 @@ string dump_string_hex(const char* buf, const int nb_buf, const int& max_len) return ret; } + +string srs_getenv(string key) +{ + string ekey = key; + if (srs_string_starts_with(key, "$")) { + ekey = key.substr(1); + } + + if (ekey.empty()) { + return ""; + } + + char* value = ::getenv(ekey.c_str()); + if (value) { + return value; + } + + return ""; +} + diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 77d28f802d..0ae50687de 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -653,5 +653,9 @@ extern void srs_api_dump_summaries(SrsJsonObject* obj); extern std::string dump_string_hex(const std::string& str, const int& max_len = INT_MAX); extern std::string dump_string_hex(const char* buf, const int nb_buf, const int& max_len = INT_MAX); +// Get ENV variable, which may starts with $. +// srs_getenv("EIP") === srs_getenv("$EIP") +extern std::string srs_getenv(std::string key); + #endif diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index 61f4f1d0d3..0778c72f16 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -59,7 +59,6 @@ using namespace std; srs_error_t run_directly_or_daemon(); srs_error_t run_hybrid_server(); void show_macro_features(); -string srs_getenv(const char* name); // @global log and context. ISrsLog* _srs_log = new SrsFastLog(); @@ -344,17 +343,6 @@ void show_macro_features() #endif } -string srs_getenv(const char* name) -{ - char* cv = ::getenv(name); - - if (cv) { - return cv; - } - - return ""; -} - // Detect docker by https://stackoverflow.com/a/41559867 bool _srs_in_docker = false; srs_error_t srs_detect_docker()