1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 20:01:56 +00:00

RTC: Remove dead code. Merge tiny functions.

This commit is contained in:
winlin 2020-07-25 09:59:36 +08:00
parent 21835c38b7
commit 6545370b7f
4 changed files with 23 additions and 44 deletions

View file

@ -337,11 +337,6 @@ void SrsRtcPlayStream::stop()
trd->stop(); trd->stop();
} }
void SrsRtcPlayStream::stop_loop()
{
trd->interrupt();
}
srs_error_t SrsRtcPlayStream::cycle() srs_error_t SrsRtcPlayStream::cycle()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;

View file

@ -200,8 +200,6 @@ public:
public: public:
virtual srs_error_t start(); virtual srs_error_t start();
virtual void stop(); virtual void stop();
// TODO: FIXME: Remove dead code.
virtual void stop_loop();
public: public:
virtual srs_error_t cycle(); virtual srs_error_t cycle();
private: private:
@ -345,12 +343,6 @@ private:
SrsRtcStream* source_; SrsRtcStream* source_;
SrsSdp remote_sdp; SrsSdp remote_sdp;
SrsSdp local_sdp; SrsSdp local_sdp;
public:
// TODO: FIXME: Remove dead code.
// User debugging parameters, overwrite config.
std::string sequence_startup;
std::string sequence_delta;
std::string sequence_keep;
private: private:
// twcc handler // twcc handler
int twcc_id_; int twcc_id_;

View file

@ -284,13 +284,20 @@ srs_error_t SrsRtcServer::on_udp_packet(SrsUdpMuxSocket* skt)
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
string peer_id = skt->peer_id();
char* data = skt->data(); int size = skt->size(); char* data = skt->data(); int size = skt->size();
SrsRtcConnection* session = find_session_by_peer_id(skt->peer_id());
if (session) { SrsRtcConnection* session = NULL;
// Now, we got the RTC session to handle the packet, switch to its context if (true) {
// to make all logs write to the "correct" pid+cid. map<string, SrsRtcConnection*>::iterator it = map_id_session.find(peer_id);
session->switch_to_context(); if (it != map_id_session.end()) {
session = it->second;
// Switch to the session to write logs to the context.
if (session) {
session->switch_to_context();
}
}
} }
// For STUN, the peer address may change. // For STUN, the peer address may change.
@ -299,27 +306,29 @@ srs_error_t SrsRtcServer::on_udp_packet(SrsUdpMuxSocket* skt)
if ((err = ping.decode(data, size)) != srs_success) { if ((err = ping.decode(data, size)) != srs_success) {
return srs_error_wrap(err, "decode stun packet failed"); return srs_error_wrap(err, "decode stun packet failed");
} }
srs_verbose("recv stun packet from %s, use-candidate=%d, ice-controlled=%d, ice-controlling=%d", srs_info("recv stun packet from %s, use-candidate=%d, ice-controlled=%d, ice-controlling=%d",
skt->peer_id().c_str(), ping.get_use_candidate(), ping.get_ice_controlled(), ping.get_ice_controlling()); peer_id.c_str(), ping.get_use_candidate(), ping.get_ice_controlled(), ping.get_ice_controlling());
// TODO: FIXME: For ICE trickle, we may get STUN packets before SDP answer, so maybe should response it. // TODO: FIXME: For ICE trickle, we may get STUN packets before SDP answer, so maybe should response it.
if (!session) { if (!session) {
session = find_session_by_username(ping.get_username()); session = find_session_by_username(ping.get_username());
// Switch to the session to write logs to the context.
if (session) { if (session) {
session->switch_to_context(); session->switch_to_context();
} }
} }
if (session == NULL) { if (!session) {
return srs_error_new(ERROR_RTC_STUN, "can not find session, stun username=%s, peer_id=%s", return srs_error_new(ERROR_RTC_STUN, "can not find session, stun username=%s, peer_id=%s",
ping.get_username().c_str(), skt->peer_id().c_str()); ping.get_username().c_str(), peer_id.c_str());
} }
return session->on_stun(skt, &ping); return session->on_stun(skt, &ping);
} }
// For DTLS, RTCP or RTP, which does not support peer address changing. // For DTLS, RTCP or RTP, which does not support peer address changing.
if (session == NULL) { if (!session) {
return srs_error_new(ERROR_RTC_STUN, "can not find session, peer_id=%s", skt->peer_id().c_str()); return srs_error_new(ERROR_RTC_STUN, "can not find session, peer_id=%s", peer_id.c_str());
} }
if (is_dtls((uint8_t*)data, size)) { if (is_dtls((uint8_t*)data, size)) {
@ -600,21 +609,6 @@ void SrsRtcServer::check_and_clean_timeout_session()
} }
} }
int SrsRtcServer::nn_sessions()
{
return (int)map_username_session.size();
}
SrsRtcConnection* SrsRtcServer::find_session_by_peer_id(const string& peer_id)
{
map<string, SrsRtcConnection*>::iterator iter = map_id_session.find(peer_id);
if (iter == map_id_session.end()) {
return NULL;
}
return iter->second;
}
SrsRtcConnection* SrsRtcServer::find_session_by_username(const std::string& username) SrsRtcConnection* SrsRtcServer::find_session_by_username(const std::string& username)
{ {
map<string, SrsRtcConnection*>::iterator iter = map_username_session.find(username); map<string, SrsRtcConnection*>::iterator iter = map_username_session.find(username);

View file

@ -118,12 +118,10 @@ 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);
// TODO: FIXME: Change to private.
void check_and_clean_timeout_session();
int nn_sessions();
SrsRtcConnection* find_session_by_username(const std::string& ufrag);
private: private:
SrsRtcConnection* find_session_by_peer_id(const std::string& peer_id); void check_and_clean_timeout_session();
public:
SrsRtcConnection* find_session_by_username(const std::string& ufrag);
// interface ISrsHourGlass // interface ISrsHourGlass
public: public:
virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick); virtual srs_error_t notify(int type, srs_utime_t interval, srs_utime_t tick);