Commit 81cf93a2 by ziyue

openRtpServer接口强制关闭reuse_port属性,防止端口冲突

parent 8937d9ea
...@@ -1025,10 +1025,6 @@ void installWebApi() { ...@@ -1025,10 +1025,6 @@ void installWebApi() {
api_regist("/index/api/openRtpServer",[](API_ARGS_MAP){ api_regist("/index/api/openRtpServer",[](API_ARGS_MAP){
CHECK_SECRET(); CHECK_SECRET();
CHECK_ARGS("port", "enable_tcp", "stream_id"); CHECK_ARGS("port", "enable_tcp", "stream_id");
bool enable_reuse = true;
if (!allArgs["enable_reuse"].empty()) {
enable_reuse = allArgs["enable_reuse"].as<bool>();
}
auto stream_id = allArgs["stream_id"]; auto stream_id = allArgs["stream_id"];
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx); lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
...@@ -1038,7 +1034,7 @@ void installWebApi() { ...@@ -1038,7 +1034,7 @@ void installWebApi() {
} }
RtpServer::Ptr server = std::make_shared<RtpServer>(); RtpServer::Ptr server = std::make_shared<RtpServer>();
server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as<bool>(), "0.0.0.0", enable_reuse); server->start(allArgs["port"], stream_id, allArgs["enable_tcp"].as<bool>(), "0.0.0.0", false);
server->setOnDetach([stream_id]() { server->setOnDetach([stream_id]() {
//设置rtp超时移除事件 //设置rtp超时移除事件
lock_guard<recursive_mutex> lck(s_rtpServerMapMtx); lock_guard<recursive_mutex> lck(s_rtpServerMapMtx);
......
...@@ -84,7 +84,7 @@ private: ...@@ -84,7 +84,7 @@ private:
std::shared_ptr<struct sockaddr> _rtcp_addr; std::shared_ptr<struct sockaddr> _rtcp_addr;
}; };
void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_tcp, const char *local_ip,bool enable_reuse) { void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_tcp, const char *local_ip, bool enable_reuse) {
//创建udp服务器 //创建udp服务器
Socket::Ptr rtp_socket = Socket::createSocket(nullptr, true); Socket::Ptr rtp_socket = Socket::createSocket(nullptr, true);
Socket::Ptr rtcp_socket = Socket::createSocket(nullptr, true); Socket::Ptr rtcp_socket = Socket::createSocket(nullptr, true);
...@@ -95,10 +95,10 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable ...@@ -95,10 +95,10 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable
//取偶数端口 //取偶数端口
rtp_socket = pair.first; rtp_socket = pair.first;
rtcp_socket = pair.second; rtcp_socket = pair.second;
} else if (!rtp_socket->bindUdpSock(local_port, local_ip,enable_reuse)) { } else if (!rtp_socket->bindUdpSock(local_port, local_ip, enable_reuse)) {
//用户指定端口 //用户指定端口
throw std::runtime_error(StrPrinter << "创建rtp端口 " << local_ip << ":" << local_port << " 失败:" << get_uv_errmsg(true)); throw std::runtime_error(StrPrinter << "创建rtp端口 " << local_ip << ":" << local_port << " 失败:" << get_uv_errmsg(true));
} else if(!rtcp_socket->bindUdpSock(rtp_socket->get_local_port() + 1, local_ip,enable_reuse)) { } else if(!rtcp_socket->bindUdpSock(rtp_socket->get_local_port() + 1, local_ip, enable_reuse)) {
// rtcp端口 // rtcp端口
throw std::runtime_error(StrPrinter << "创建rtcp端口 " << local_ip << ":" << local_port << " 失败:" << get_uv_errmsg(true)); throw std::runtime_error(StrPrinter << "创建rtcp端口 " << local_ip << ":" << local_port << " 失败:" << get_uv_errmsg(true));
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论