add rtc tcp port config and ignore candidate when port is 0

This commit is contained in:
xiongguangjie 2022-11-19 01:51:53 +08:00
parent 89959ef02f
commit 0d6fa1281a
5 changed files with 19 additions and 4 deletions

View File

@ -313,6 +313,10 @@ externIP=
#该端口是多线程的,同时支持客户端网络切换导致的连接迁移 #该端口是多线程的,同时支持客户端网络切换导致的连接迁移
#需要注意的是如果服务器在nat内需要做端口映射时必须确保外网映射端口跟该端口一致 #需要注意的是如果服务器在nat内需要做端口映射时必须确保外网映射端口跟该端口一致
port=8000 port=8000
#rtc tcp服务器监听端口号在udp 不通的情况下会使用tcp传输数据
#该端口是多线程的,同时支持客户端网络切换导致的连接迁移
#需要注意的是如果服务器在nat内需要做端口映射时必须确保外网映射端口跟该端口一致
tcpPort = 8000
#设置remb比特率非0时关闭twcc并开启remb。该设置在rtc推流时有效可以控制推流画质 #设置remb比特率非0时关闭twcc并开启remb。该设置在rtc推流时有效可以控制推流画质
#目前已经实现twcc自动调整码率关闭remb根据真实网络状况调整码率 #目前已经实现twcc自动调整码率关闭remb根据真实网络状况调整码率
rembBitRate=0 rembBitRate=0

View File

@ -292,6 +292,7 @@ int start_main(int argc,char *argv[]) {
return Socket::createSocket(new_poller, false); return Socket::createSocket(new_poller, false);
}); });
uint16_t rtcPort = mINI::Instance()[Rtc::kPort]; uint16_t rtcPort = mINI::Instance()[Rtc::kPort];
uint16_t rtcTcpPort = mINI::Instance()[Rtc::kTcpPort];
#endif//defined(ENABLE_WEBRTC) #endif//defined(ENABLE_WEBRTC)
@ -338,7 +339,10 @@ int start_main(int argc,char *argv[]) {
#if defined(ENABLE_WEBRTC) #if defined(ENABLE_WEBRTC)
//webrtc udp服务器 //webrtc udp服务器
if (rtcPort) { rtcSrv_udp->start<WebRtcSession>(rtcPort); rtcSrv_tcp->start<WebRtcSession>(rtcPort); } if (rtcPort) { rtcSrv_udp->start<WebRtcSession>(rtcPort);}
if (rtcTcpPort) { rtcSrv_tcp->start<WebRtcSession>(rtcTcpPort);}
#endif//defined(ENABLE_WEBRTC) #endif//defined(ENABLE_WEBRTC)
#if defined(ENABLE_SRT) #if defined(ENABLE_SRT)

View File

@ -1204,7 +1204,9 @@ RtcSessionSdp::Ptr RtcSession::toRtcSessionSdp() const{
} }
for (auto &cand : m.candidate) { for (auto &cand : m.candidate) {
sdp_media.addAttr(std::make_shared<SdpAttrCandidate>(cand)); if(cand.port){
sdp_media.addAttr(std::make_shared<SdpAttrCandidate>(cand));
}
} }
} }
return ret; return ret;

View File

@ -44,11 +44,14 @@ const string kRembBitRate = RTC_FIELD "rembBitRate";
// webrtc单端口udp服务器 // webrtc单端口udp服务器
const string kPort = RTC_FIELD "port"; const string kPort = RTC_FIELD "port";
const string kTcpPort = RTC_FIELD "tcpPort";
static onceToken token([]() { static onceToken token([]() {
mINI::Instance()[kTimeOutSec] = 15; mINI::Instance()[kTimeOutSec] = 15;
mINI::Instance()[kExternIP] = ""; mINI::Instance()[kExternIP] = "";
mINI::Instance()[kRembBitRate] = 0; mINI::Instance()[kRembBitRate] = 0;
mINI::Instance()[kPort] = 8000; mINI::Instance()[kPort] = 8000;
mINI::Instance()[kTcpPort] = 8000;
}); });
} // namespace RTC } // namespace RTC
@ -612,6 +615,7 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
WebRtcTransport::onRtcConfigure(configure); WebRtcTransport::onRtcConfigure(configure);
GET_CONFIG(uint16_t, local_port, Rtc::kPort); GET_CONFIG(uint16_t, local_port, Rtc::kPort);
GET_CONFIG(uint16_t, local_tcp_port, Rtc::kTcpPort);
// 添加接收端口candidate信息 // 添加接收端口candidate信息
GET_CONFIG_FUNC(std::vector<std::string>, extern_ips, Rtc::kExternIP, [](string str) { GET_CONFIG_FUNC(std::vector<std::string>, extern_ips, Rtc::kExternIP, [](string str) {
std::vector<std::string> ret; std::vector<std::string> ret;
@ -624,13 +628,13 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const {
if (extern_ips.empty()) { if (extern_ips.empty()) {
std::string localIp = SockUtil::get_local_ip(); std::string localIp = SockUtil::get_local_ip();
configure.addCandidate(*makeIceCandidate(localIp, local_port, 120, "udp")); 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 { } else {
const uint32_t delta = 10; const uint32_t delta = 10;
uint32_t priority = 100 + delta * extern_ips.size(); uint32_t priority = 100 + delta * extern_ips.size();
for (auto ip : extern_ips) { for (auto ip : extern_ips) {
configure.addCandidate(*makeIceCandidate(ip, local_port, priority + 5, "udp")); 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; priority -= delta;
} }
} }

View File

@ -32,6 +32,7 @@ namespace mediakit {
//RTC配置项目 //RTC配置项目
namespace Rtc { namespace Rtc {
extern const std::string kPort; extern const std::string kPort;
extern const std::string kTcpPort;
extern const std::string kTimeOutSec; extern const std::string kTimeOutSec;
}//namespace RTC }//namespace RTC