RTC: Support address switch

pull/1908/head
winlin 5 years ago
parent 38f935ead8
commit 5f88dc357e

@ -1938,15 +1938,27 @@ bool SrsRtcConnection::is_stun_timeout()
return last_stun_time + sessionStunTimeout < srs_get_system_time();
}
// TODO: FIXME: We should support multiple addresses, because client may use more than one addresses.
void SrsRtcConnection::update_sendonly_socket(SrsUdpMuxSocket* skt)
{
std::string old_peer_id;
if (sendonly_skt) {
srs_trace("session %s address changed, update %s -> %s",
id().c_str(), sendonly_skt->peer_id().c_str(), skt->peer_id().c_str());
old_peer_id = sendonly_skt->peer_id();
}
// Update the transport.
srs_freep(sendonly_skt);
sendonly_skt = skt->copy_sendonly();
// Update the sessions to handle packets from the new address.
server_->insert_into_id_sessions(sendonly_skt->peer_id().c_str(), this);
// Remove the old address.
if (!old_peer_id.empty()) {
server_->remove_id_sessions(old_peer_id);
}
}
void SrsRtcConnection::check_send_nacks(SrsRtpNackForReceiver* nack, uint32_t ssrc)

@ -494,6 +494,14 @@ bool SrsRtcServer::insert_into_id_sessions(const string& peer_id, SrsRtcConnecti
return map_id_session.insert(make_pair(peer_id, session)).second;
}
void SrsRtcServer::remove_id_sessions(const string& peer_id)
{
std::map<std::string, SrsRtcConnection*>::iterator it;
if ((it = map_id_session.find(peer_id)) != map_id_session.end()) {
map_id_session.erase(it);
}
}
void SrsRtcServer::check_and_clean_timeout_session()
{
map<string, SrsRtcConnection*>::iterator iter = map_username_session.begin();

@ -94,6 +94,7 @@ public:
void destroy(SrsRtcConnection* session);
public:
bool insert_into_id_sessions(const std::string& peer_id, SrsRtcConnection* session);
void remove_id_sessions(const std::string& peer_id);
void check_and_clean_timeout_session();
int nn_sessions();
SrsRtcConnection* find_session_by_username(const std::string& ufrag);

Loading…
Cancel
Save