diff --git a/trunk/conf/rtc.conf b/trunk/conf/rtc.conf
index 5af4172b0..fe8d545ec 100644
--- a/trunk/conf/rtc.conf
+++ b/trunk/conf/rtc.conf
@@ -23,6 +23,8 @@ http_server {
rtc {
enabled on;
listen 9527;
+ # candidate device ip: *(all interface), 192.168.1.1 ...
+ candidate *;
}
stats {
network 0;
diff --git a/trunk/research/players/rtc_upload.html b/trunk/research/players/rtc_upload.html
new file mode 100644
index 000000000..68c515d8e
--- /dev/null
+++ b/trunk/research/players/rtc_upload.html
@@ -0,0 +1,97 @@
+
+
+
+
+
+
+
+
+
local_media_player:
+
+
rtc_media_player:
+
+
+
+
+
+
+
diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp
index 315ec58f7..babb870cf 100644
--- a/trunk/src/app/srs_app_config.cpp
+++ b/trunk/src/app/srs_app_config.cpp
@@ -4255,6 +4255,23 @@ int SrsConfig::get_rtc_listen()
return ::atoi(conf->arg0().c_str());
}
+std::string SrsConfig::get_rtc_candidates()
+{
+ static string DEFAULT = "*";
+
+ SrsConfDirective* conf = root->get("rtc");
+ if (!conf) {
+ return DEFAULT;
+ }
+
+ conf = conf->get("candidate");
+ if (!conf || conf->arg0().empty()) {
+ return DEFAULT;
+ }
+
+ return (conf->arg0().c_str());
+}
+
SrsConfDirective* SrsConfig::get_vhost(string vhost, bool try_default_vhost)
{
srs_assert(root);
diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp
index 1f85550f7..97d8f4851 100644
--- a/trunk/src/app/srs_app_config.hpp
+++ b/trunk/src/app/srs_app_config.hpp
@@ -496,6 +496,7 @@ public:
virtual int get_rtc_enabled();
virtual bool get_rtc_enabled(SrsConfDirective* conf);
virtual int get_rtc_listen();
+ virtual std::string get_rtc_candidates();
// vhost specified section
public:
diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp
index fb33382d2..5e1486093 100644
--- a/trunk/src/app/srs_app_http_api.cpp
+++ b/trunk/src/app/srs_app_http_api.cpp
@@ -850,19 +850,20 @@ srs_error_t SrsGoApiSdp::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage*
obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS));
obj->set("server", SrsJsonAny::integer(stat->server_id()));
- string candidate_str = "candidate:1 1 udp 2115783679 192.168.170.129:9527 typ host generation 0 ufrag "
- + local_sdp.get_ice_ufrag() + "netwrok-cost 50";
+ // XXX: ice candidate
+ //string candidate_str = "candidate:1 1 udp 2115783679 192.168.170.129:9527 typ host generation 0 ufrag "
+ // + local_sdp.get_ice_ufrag() + "netwrok-cost 50";
- SrsJsonObject* candidate_obj = SrsJsonAny::object();
+ //SrsJsonObject* candidate_obj = SrsJsonAny::object();
//SrsAutoFree(SrsJsonObject, candidate_obj);
- candidate_obj->set("candidate", SrsJsonAny::str(candidate_str.c_str()));
- candidate_obj->set("sdpMid", SrsJsonAny::str("0"));
- candidate_obj->set("sdpMLineIndex", SrsJsonAny::str("0"));
+ //candidate_obj->set("candidate", SrsJsonAny::str(candidate_str.c_str()));
+ //candidate_obj->set("sdpMid", SrsJsonAny::str("0"));
+ //candidate_obj->set("sdpMLineIndex", SrsJsonAny::str("0"));
if (r->is_http_post()) {
obj->set("sdp", SrsJsonAny::str(local_sdp_str.c_str()));
- obj->set("candidate", candidate_obj);
+ // obj->set("candidate", candidate_obj);
} else {
return srs_go_http_error(w, SRS_CONSTS_HTTP_MethodNotAllowed);
}
diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp
index 2a570b4a9..65cd4fe10 100644
--- a/trunk/src/app/srs_app_rtc_conn.cpp
+++ b/trunk/src/app/srs_app_rtc_conn.cpp
@@ -39,6 +39,8 @@ using namespace std;
#include
#include
#include
+#include
+#include
static bool is_stun(const char* data, const int size)
{
@@ -71,6 +73,33 @@ static string gen_random_str(int len)
const int SRTP_MASTER_KEY_KEY_LEN = 16;
const int SRTP_MASTER_KEY_SALT_LEN = 14;
+SrsCandidate::SrsCandidate()
+{
+}
+
+SrsCandidate::~SrsCandidate()
+{
+}
+
+std::vector SrsCandidate::get_candidate_ips()
+{
+ std::vector candidate_ips;
+
+ string candidate = _srs_config->get_rtc_candidates();
+ if (candidate == "*" || candidate == "0.0.0.0") {
+ std::vector tmp = srs_get_local_ips();
+ for (int i = 0; i < tmp.size(); ++i) {
+ if (tmp[i] != "127.0.0.1") {
+ candidate_ips.push_back(tmp[i]);
+ }
+ }
+ } else {
+ candidate_ips.push_back(candidate);
+ }
+
+ return candidate_ips;
+}
+
SrsSdpMediaInfo::SrsSdpMediaInfo()
{
}
@@ -139,6 +168,15 @@ srs_error_t SrsSdp::encode(string& sdp_str)
{
srs_error_t err = srs_success;
+ string candidate_lines = "";
+
+ std::vector candidate_ips = SrsCandidate::get_candidate_ips();
+ for (int i = 0; i < candidate_ips.size(); ++i) {
+ ostringstream os;
+ os << "a=candidate:10 1 udp 2115783679 " << candidate_ips[i] << " " << _srs_config->get_rtc_listen() <<" typ host generation 0\\r\\n";
+ candidate_lines += os.str();
+ }
+
// FIXME:
sdp_str =
"v=0\\r\\n"
@@ -150,7 +188,7 @@ srs_error_t SrsSdp::encode(string& sdp_str)
"a=msid-semantic: WMS 6VrfBKXrwK\\r\\n"
"m=audio 9 UDP/TLS/RTP/SAVPF 111\\r\\n"
"c=IN IP4 0.0.0.0\\r\\n"
- "a=candidate:10 1 udp 2115783679 192.168.170.129 9527 typ host generation 0\\r\\n"
+ + candidate_lines +
"a=rtcp:9 IN IP4 0.0.0.0\\r\\n"
"a=ice-ufrag:" + ice_ufrag + "\\r\\n"
"a=ice-pwd:" + ice_pwd + "\\r\\n"
@@ -170,7 +208,7 @@ srs_error_t SrsSdp::encode(string& sdp_str)
"a=ssrc:3233846890 label:6VrfBKXrwKa0\\r\\n"
"m=video 9 UDP/TLS/RTP/SAVPF 96 98 102\\r\\n"
"c=IN IP4 0.0.0.0\\r\\n"
- "a=candidate:10 1 udp 2115783679 192.168.170.129 9527 typ host generation 0\\r\\n"
+ + candidate_lines +
"a=rtcp:9 IN IP4 0.0.0.0\\r\\n"
"b=as:2000000\\r\\n"
"a=ice-ufrag:" + ice_ufrag + "\\r\\n"
diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp
index c40076686..b9d60d07e 100644
--- a/trunk/src/app/srs_app_rtc_conn.hpp
+++ b/trunk/src/app/srs_app_rtc_conn.hpp
@@ -37,6 +37,16 @@
class SrsServer;
class SrsStunPacket;
+class SrsCandidate
+{
+private:
+public:
+ SrsCandidate();
+ virtual ~SrsCandidate();
+
+ static std::vector get_candidate_ips();
+};
+
class SrsSdpMediaInfo
{
private:
@@ -151,6 +161,7 @@ public:
virtual ~SrsRtcServer();
public:
virtual srs_error_t initialize();
+
virtual srs_error_t on_udp_packet(srs_netfd_t fd, const std::string& peer_ip, const int peer_port,
const sockaddr* from, const int fromlen, const char* data, const int size);