mirror of
				https://github.com/ossrs/srs.git
				synced 2025-03-09 15:49:59 +00:00 
			
		
		
		
	RTC: Support address switch
This commit is contained in:
		
							parent
							
								
									38f935ead8
								
							
						
					
					
						commit
						5f88dc357e
					
				
					 3 changed files with 21 additions and 0 deletions
				
			
		| 
						 | 
					@ -1938,15 +1938,27 @@ bool SrsRtcConnection::is_stun_timeout()
 | 
				
			||||||
    return last_stun_time + sessionStunTimeout < srs_get_system_time();
 | 
					    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)
 | 
					void SrsRtcConnection::update_sendonly_socket(SrsUdpMuxSocket* skt)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    std::string old_peer_id;
 | 
				
			||||||
    if (sendonly_skt) {
 | 
					    if (sendonly_skt) {
 | 
				
			||||||
        srs_trace("session %s address changed, update %s -> %s",
 | 
					        srs_trace("session %s address changed, update %s -> %s",
 | 
				
			||||||
            id().c_str(), sendonly_skt->peer_id().c_str(), skt->peer_id().c_str());
 | 
					            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);
 | 
					    srs_freep(sendonly_skt);
 | 
				
			||||||
    sendonly_skt = skt->copy_sendonly();
 | 
					    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)
 | 
					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;
 | 
					    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()
 | 
					void SrsRtcServer::check_and_clean_timeout_session()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    map<string, SrsRtcConnection*>::iterator iter = map_username_session.begin();
 | 
					    map<string, SrsRtcConnection*>::iterator iter = map_username_session.begin();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,6 +94,7 @@ public:
 | 
				
			||||||
    void destroy(SrsRtcConnection* session);
 | 
					    void destroy(SrsRtcConnection* session);
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    bool insert_into_id_sessions(const std::string& peer_id, SrsRtcConnection* session);
 | 
					    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();
 | 
					    void check_and_clean_timeout_session();
 | 
				
			||||||
    int nn_sessions();
 | 
					    int nn_sessions();
 | 
				
			||||||
    SrsRtcConnection* find_session_by_username(const std::string& ufrag);
 | 
					    SrsRtcConnection* find_session_by_username(const std::string& ufrag);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue