diff --git a/conf/config.ini b/conf/config.ini index 46bdb452..ae0ce077 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -313,6 +313,10 @@ externIP= #该端口是多线程的,同时支持客户端网络切换导致的连接迁移 #需要注意的是,如果服务器在nat内,需要做端口映射时,必须确保外网映射端口跟该端口一致 port=8000 +#rtc tcp服务器监听端口号,在udp 不通的情况下,会使用tcp传输数据 +#该端口是多线程的,同时支持客户端网络切换导致的连接迁移 +#需要注意的是,如果服务器在nat内,需要做端口映射时,必须确保外网映射端口跟该端口一致 +tcpPort = 8000 #设置remb比特率,非0时关闭twcc并开启remb。该设置在rtc推流时有效,可以控制推流画质 #目前已经实现twcc自动调整码率,关闭remb根据真实网络状况调整码率 rembBitRate=0 diff --git a/server/main.cpp b/server/main.cpp index f41d1d10..8d3b0353 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -292,6 +292,7 @@ int start_main(int argc,char *argv[]) { return Socket::createSocket(new_poller, false); }); uint16_t rtcPort = mINI::Instance()[Rtc::kPort]; + uint16_t rtcTcpPort = mINI::Instance()[Rtc::kTcpPort]; #endif//defined(ENABLE_WEBRTC) @@ -338,7 +339,10 @@ int start_main(int argc,char *argv[]) { #if defined(ENABLE_WEBRTC) //webrtc udp服务器 - if (rtcPort) { rtcSrv_udp->start(rtcPort); rtcSrv_tcp->start(rtcPort); } + if (rtcPort) { rtcSrv_udp->start(rtcPort);} + + if (rtcTcpPort) { rtcSrv_tcp->start(rtcTcpPort);} + #endif//defined(ENABLE_WEBRTC) #if defined(ENABLE_SRT) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index d3d3d397..2466d9e8 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -1204,7 +1204,9 @@ RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{ } for (auto &cand : m.candidate) { - sdp_media.addAttr(std::make_shared(cand)); + if(cand.port){ + sdp_media.addAttr(std::make_shared(cand)); + } } } return ret; diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index d345fddc..e2be1628 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -44,11 +44,14 @@ const string kRembBitRate = RTC_FIELD "rembBitRate"; // webrtc单端口udp服务器 const string kPort = RTC_FIELD "port"; +const string kTcpPort = RTC_FIELD "tcpPort"; + static onceToken token([]() { mINI::Instance()[kTimeOutSec] = 15; mINI::Instance()[kExternIP] = ""; mINI::Instance()[kRembBitRate] = 0; mINI::Instance()[kPort] = 8000; + mINI::Instance()[kTcpPort] = 8000; }); } // namespace RTC @@ -612,6 +615,7 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const { WebRtcTransport::onRtcConfigure(configure); GET_CONFIG(uint16_t, local_port, Rtc::kPort); + GET_CONFIG(uint16_t, local_tcp_port, Rtc::kTcpPort); // 添加接收端口candidate信息 GET_CONFIG_FUNC(std::vector, extern_ips, Rtc::kExternIP, [](string str) { std::vector ret; @@ -624,13 +628,13 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const { if (extern_ips.empty()) { std::string localIp = SockUtil::get_local_ip(); configure.addCandidate(*makeIceCandidate(localIp, local_port, 120, "udp")); - configure.addCandidate(*makeIceCandidate(localIp, local_port, 110, "tcp")); + configure.addCandidate(*makeIceCandidate(localIp, local_tcp_port, 110, "tcp")); } else { const uint32_t delta = 10; uint32_t priority = 100 + delta * extern_ips.size(); for (auto ip : extern_ips) { configure.addCandidate(*makeIceCandidate(ip, local_port, priority + 5, "udp")); - configure.addCandidate(*makeIceCandidate(ip, local_port, priority, "tcp")); + configure.addCandidate(*makeIceCandidate(ip, local_tcp_port, priority, "tcp")); priority -= delta; } } diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index d3a492cf..14615146 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -32,6 +32,7 @@ namespace mediakit { //RTC配置项目 namespace Rtc { extern const std::string kPort; +extern const std::string kTcpPort; extern const std::string kTimeOutSec; }//namespace RTC