修复startSendRtp成功后udp套接字被关闭的问题 (#2468 #2924)

对端端口未打开,udp得到connection refused的错误而关闭。
This commit is contained in:
leibnewton 2023-10-25 15:14:08 +08:00 committed by GitHub
parent a871fc1882
commit 0a19627d86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -140,7 +140,7 @@ void RtpSender::startSend(const MediaSourceEvent::SendRtpArgs &args, const funct
cb(0, SockException(Err_other, ex.what())); cb(0, SockException(Err_other, ex.what()));
return; return;
} }
strong_self->_socket_rtp->bindPeerAddr((struct sockaddr *)&addr); strong_self->_socket_rtp->bindPeerAddr((struct sockaddr *)&addr, 0, true);
strong_self->onConnect(); strong_self->onConnect();
cb(strong_self->_socket_rtp->get_local_port(), SockException()); cb(strong_self->_socket_rtp->get_local_port(), SockException());
}); });
@ -182,7 +182,7 @@ void RtpSender::createRtcpSocket() {
case AF_INET6: ((sockaddr_in6 *)&addr)->sin6_port = htons(ntohs(((sockaddr_in6 *)&addr)->sin6_port) + 1); break; case AF_INET6: ((sockaddr_in6 *)&addr)->sin6_port = htons(ntohs(((sockaddr_in6 *)&addr)->sin6_port) + 1); break;
default: assert(0); break; default: assert(0); break;
} }
_socket_rtcp->bindPeerAddr((struct sockaddr *)&addr); _socket_rtcp->bindPeerAddr((struct sockaddr *)&addr, 0, true);
_rtcp_context = std::make_shared<RtcpContextForSend>(); _rtcp_context = std::make_shared<RtcpContextForSend>();
weak_ptr<RtpSender> weak_self = shared_from_this(); weak_ptr<RtpSender> weak_self = shared_from_this();
@ -349,4 +349,4 @@ void RtpSender::setOnClose(std::function<void(const toolkit::SockException &ex)>
} }
}//namespace mediakit }//namespace mediakit
#endif// defined(ENABLE_RTPPROXY) #endif// defined(ENABLE_RTPPROXY)