1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Update RtcSession peer address when changed.

This commit is contained in:
xiaozhihong 2020-03-22 16:54:31 +08:00
parent 0cd67a997e
commit 734e848741
4 changed files with 41 additions and 21 deletions

View file

@ -237,23 +237,21 @@ SrsUdpMuxSocket::~SrsUdpMuxSocket()
srs_freepa(buf);
}
SrsUdpMuxSocket::SrsUdpMuxSocket(const SrsUdpMuxSocket& rhs)
SrsUdpMuxSocket* SrsUdpMuxSocket::copy_sendonly()
{
operator=(rhs);
}
SrsUdpMuxSocket* sendonly = new SrsUdpMuxSocket(lfd);
SrsUdpMuxSocket& SrsUdpMuxSocket::operator=(const SrsUdpMuxSocket& rhs)
{
buf = NULL;
nb_buf = 0;
nread = 0;
lfd = rhs.lfd;
from = rhs.from;
fromlen = rhs.fromlen;
peer_ip = rhs.peer_ip;
peer_port = rhs.peer_port;
// Don't copy buffer
srs_freepa(sendonly->buf);
sendonly->nb_buf = 0;
sendonly->nread = 0;
sendonly->lfd = lfd;
sendonly->from = from;
sendonly->fromlen = fromlen;
sendonly->peer_ip = peer_ip;
sendonly->peer_port = peer_port;
return *this;
return sendonly;
}
int SrsUdpMuxSocket::recvfrom(srs_utime_t timeout)

View file

@ -143,9 +143,6 @@ public:
SrsUdpMuxSocket(srs_netfd_t fd);
virtual ~SrsUdpMuxSocket();
SrsUdpMuxSocket(const SrsUdpMuxSocket& rhs);
SrsUdpMuxSocket& operator=(const SrsUdpMuxSocket& rhs);
int recvfrom(srs_utime_t timeout);
srs_error_t sendto(void* data, int size, srs_utime_t timeout);
@ -154,6 +151,12 @@ public:
std::string get_peer_ip() const { return peer_ip; }
int get_peer_port() const { return peer_port; }
std::string get_peer_id();
public:
SrsUdpMuxSocket* copy_sendonly();
private:
// Don't allow copy, user copy_sendonly instead
SrsUdpMuxSocket(const SrsUdpMuxSocket& rhs);
SrsUdpMuxSocket& operator=(const SrsUdpMuxSocket& rhs);
};
class SrsUdpMuxListener : public ISrsCoroutineHandler

View file

@ -605,18 +605,19 @@ srs_error_t SrsDtlsSession::unprotect_rtcp(char* out_buf, const char* in_buf, in
}
SrsRtcSenderThread::SrsRtcSenderThread(SrsRtcSession* s, SrsUdpMuxSocket* u, int parent_cid)
: ukt(NULL)
: sendonly_ukt(NULL)
{
_parent_cid = parent_cid;
trd = new SrsDummyCoroutine();
rtc_session = s;
ukt = *u;
sendonly_ukt = u->copy_sendonly();
}
SrsRtcSenderThread::~SrsRtcSenderThread()
{
srs_freep(trd);
srs_freep(sendonly_ukt);
}
int SrsRtcSenderThread::cid()
@ -695,10 +696,19 @@ srs_error_t SrsRtcSenderThread::cycle()
continue;
}
send_and_free_messages(msgs.msgs, msg_count, &ukt);
send_and_free_messages(msgs.msgs, msg_count, sendonly_ukt);
}
}
void SrsRtcSenderThread::update_sendonly_socket(SrsUdpMuxSocket* ukt)
{
srs_trace("session %s address changed, update %s -> %s",
rtc_session->id().c_str(), sendonly_ukt->get_peer_id().c_str(), ukt->get_peer_id().c_str());
srs_freep(sendonly_ukt);
sendonly_ukt = ukt->copy_sendonly();
}
void SrsRtcSenderThread::send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, SrsUdpMuxSocket* udp_mux_skt)
{
srs_error_t err = srs_success;
@ -776,6 +786,12 @@ srs_error_t SrsRtcSession::on_stun(SrsUdpMuxSocket* udp_mux_skt, SrsStunPacket*
last_stun_time = srs_get_system_time();
if (strd && strd->sendonly_ukt) {
if (strd->sendonly_ukt->get_peer_id() != udp_mux_skt->get_peer_id()) {
strd->update_sendonly_socket(udp_mux_skt);
}
}
return err;
}

View file

@ -165,7 +165,8 @@ protected:
int _parent_cid;
private:
SrsRtcSession* rtc_session;
SrsUdpMuxSocket ukt;
public:
SrsUdpMuxSocket* sendonly_ukt;
public:
SrsRtcSenderThread(SrsRtcSession* s, SrsUdpMuxSocket* u, int parent_cid);
virtual ~SrsRtcSenderThread();
@ -177,6 +178,8 @@ public:
virtual void stop_loop();
public:
virtual srs_error_t cycle();
public:
void update_sendonly_socket(SrsUdpMuxSocket* ukt);
private:
void send_and_free_messages(SrsSharedPtrMessage** msgs, int nb_msgs, SrsUdpMuxSocket* udp_mux_skt);
};