修复某些平台下,udp connect后sendto时指定对端地址发送失败的问题

This commit is contained in:
xiongziliang 2021-04-07 20:33:53 +08:00
parent a22a6bafb7
commit 87e1209d0a
2 changed files with 39 additions and 7 deletions

View File

@ -120,6 +120,10 @@ const RtcSession& WebRtcTransport::getSdp(SdpType type) const{
}
}
RTC::TransportTuple* WebRtcTransport::getSelectedTuple() const{
return _ice_server->GetSelectedTuple();
}
string getFingerprint(const string &algorithm_str, const std::shared_ptr<RTC::DtlsTransport> &transport){
auto algorithm = RTC::DtlsTransport::GetFingerprintAlgorithm(algorithm_str);
for (auto &finger_prints : transport->GetLocalFingerprints()) {
@ -614,10 +618,27 @@ string WebRtcTransportImp::getOriginUrl(MediaSource &sender) const {
}
std::shared_ptr<SockInfo> WebRtcTransportImp::getOriginSock(MediaSource &sender) const {
return const_cast<WebRtcTransportImp *>(this)->_socket;
return const_cast<WebRtcTransportImp *>(this)->shared_from_this();
}
void WebRtcTransportImp::OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) {
WebRtcTransport::OnIceServerSelectedTuple(iceServer, tuple);
_socket->setSendPeerAddr(tuple);
/////////////////////////////////////////////////////////////////////////////////////////////
string WebRtcTransportImp::get_local_ip() {
return getSdp(SdpType::answer).media[0].candidate[0].address;
}
uint16_t WebRtcTransportImp::get_local_port() {
return _socket->get_local_port();
}
string WebRtcTransportImp::get_peer_ip() {
return SockUtil::inet_ntoa(((struct sockaddr_in *) getSelectedTuple())->sin_addr);
}
uint16_t WebRtcTransportImp::get_peer_port() {
return ntohs(((struct sockaddr_in *) getSelectedTuple())->sin_port);
}
string WebRtcTransportImp::getIdentifier() const {
return StrPrinter << this;
}

View File

@ -93,6 +93,7 @@ protected:
protected:
const RtcSession& getSdp(SdpType type) const;
RTC::TransportTuple* getSelectedTuple() const;
private:
void onSendSockData(const char *buf, size_t len, bool flush = true);
@ -110,7 +111,7 @@ private:
class RtpReceiverImp;
class WebRtcTransportImp : public WebRtcTransport, public MediaSourceEvent, public std::enable_shared_from_this<WebRtcTransportImp>{
class WebRtcTransportImp : public WebRtcTransport, public MediaSourceEvent, public SockInfo, public std::enable_shared_from_this<WebRtcTransportImp>{
public:
using Ptr = std::shared_ptr<WebRtcTransportImp>;
~WebRtcTransportImp() override;
@ -139,8 +140,6 @@ protected:
void onRtcp(const char *buf, size_t len) override;
void onShutdown(const SockException &ex) override;
void OnIceServerSelectedTuple(const RTC::IceServer *iceServer, RTC::TransportTuple *tuple) override;
///////MediaSourceEvent override///////
// 关闭
bool close(MediaSource &sender, bool force) override;
@ -153,6 +152,18 @@ protected:
// 获取媒体源客户端相关信息
std::shared_ptr<SockInfo> getOriginSock(MediaSource &sender) const override;
///////SockInfo override///////
//获取本机ip
string get_local_ip() override;
//获取本机端口号
uint16_t get_local_port() override;
//获取对方ip
string get_peer_ip() override;
//获取对方端口号
uint16_t get_peer_port() override;
//获取标识符
string getIdentifier() const override;
private:
WebRtcTransportImp(const EventPoller::Ptr &poller);
void onCreate() override;