mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
RTC: Rename SrsRtcSession to SrsRtcConnection
This commit is contained in:
parent
f551ff5ae8
commit
0cdfd062f2
5 changed files with 88 additions and 87 deletions
|
@ -183,7 +183,7 @@ srs_error_t SrsGoApiRtcPlay::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: When server enabled, but vhost disabled, should report error.
|
// TODO: FIXME: When server enabled, but vhost disabled, should report error.
|
||||||
SrsRtcSession* session = NULL;
|
SrsRtcConnection* session = NULL;
|
||||||
if ((err = server_->create_session(&request, remote_sdp, local_sdp, eip, false, &session)) != srs_success) {
|
if ((err = server_->create_session(&request, remote_sdp, local_sdp, eip, false, &session)) != srs_success) {
|
||||||
return srs_error_wrap(err, "create session");
|
return srs_error_wrap(err, "create session");
|
||||||
}
|
}
|
||||||
|
@ -541,7 +541,7 @@ srs_error_t SrsGoApiRtcPublish::do_serve_http(ISrsHttpResponseWriter* w, ISrsHtt
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: When server enabled, but vhost disabled, should report error.
|
// TODO: FIXME: When server enabled, but vhost disabled, should report error.
|
||||||
SrsRtcSession* session = NULL;
|
SrsRtcConnection* session = NULL;
|
||||||
if ((err = server_->create_session(&request, remote_sdp, local_sdp, eip, true, &session)) != srs_success) {
|
if ((err = server_->create_session(&request, remote_sdp, local_sdp, eip, true, &session)) != srs_success) {
|
||||||
return srs_error_wrap(err, "create session");
|
return srs_error_wrap(err, "create session");
|
||||||
}
|
}
|
||||||
|
@ -808,7 +808,7 @@ srs_error_t SrsGoApiRtcNACK::do_serve_http(ISrsHttpResponseWriter* w, ISrsHttpMe
|
||||||
return srs_error_new(ERROR_RTC_INVALID_PARAMS, "invalid drop=%s/%d", dropv.c_str(), drop);
|
return srs_error_new(ERROR_RTC_INVALID_PARAMS, "invalid drop=%s/%d", dropv.c_str(), drop);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSession* session = server_->find_session_by_username(username);
|
SrsRtcConnection* session = server_->find_session_by_username(username);
|
||||||
if (!session) {
|
if (!session) {
|
||||||
return srs_error_new(ERROR_RTC_NO_SESSION, "no session username=%s", username.c_str());
|
return srs_error_new(ERROR_RTC_NO_SESSION, "no session username=%s", username.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ SrsNtp SrsNtp::to_time_ms(uint64_t ntp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SrsSecurityTransport::SrsSecurityTransport(SrsRtcSession* s)
|
SrsSecurityTransport::SrsSecurityTransport(SrsRtcConnection* s)
|
||||||
{
|
{
|
||||||
session_ = s;
|
session_ = s;
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ srs_error_t SrsSecurityTransport::write_dtls_data(void* data, int size)
|
||||||
|
|
||||||
if (session_->blackhole && session_->blackhole_addr && session_->blackhole_stfd) {
|
if (session_->blackhole && session_->blackhole_addr && session_->blackhole_stfd) {
|
||||||
// Ignore any error for black-hole.
|
// Ignore any error for black-hole.
|
||||||
void* p = data; int len = size; SrsRtcSession* s = session_;
|
void* p = data; int len = size; SrsRtcConnection* s = session_;
|
||||||
srs_sendto(s->blackhole_stfd, p, len, (sockaddr*)s->blackhole_addr, sizeof(sockaddr_in), SRS_UTIME_NO_TIMEOUT);
|
srs_sendto(s->blackhole_stfd, p, len, (sockaddr*)s->blackhole_addr, sizeof(sockaddr_in), SRS_UTIME_NO_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ SrsRtcOutgoingInfo::~SrsRtcOutgoingInfo()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcPlayer::SrsRtcPlayer(SrsRtcSession* s, SrsContextId parent_cid)
|
SrsRtcPlayer::SrsRtcPlayer(SrsRtcConnection* s, SrsContextId parent_cid)
|
||||||
{
|
{
|
||||||
_parent_cid = parent_cid;
|
_parent_cid = parent_cid;
|
||||||
trd = new SrsDummyCoroutine();
|
trd = new SrsDummyCoroutine();
|
||||||
|
@ -847,7 +847,7 @@ srs_error_t SrsRtcPlayer::on_rtcp_rr(char* data, int nb_data)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcPublisher::SrsRtcPublisher(SrsRtcSession* session)
|
SrsRtcPublisher::SrsRtcPublisher(SrsRtcConnection* session)
|
||||||
{
|
{
|
||||||
report_timer = new SrsHourGlass(this, 200 * SRS_UTIME_MILLISECONDS);
|
report_timer = new SrsHourGlass(this, 200 * SRS_UTIME_MILLISECONDS);
|
||||||
|
|
||||||
|
@ -967,7 +967,7 @@ void SrsRtcPublisher::check_send_nacks(SrsRtpNackForReceiver* nack, uint32_t ssr
|
||||||
|
|
||||||
if (session_->blackhole && session_->blackhole_addr && session_->blackhole_stfd) {
|
if (session_->blackhole && session_->blackhole_addr && session_->blackhole_stfd) {
|
||||||
// Ignore any error for black-hole.
|
// Ignore any error for black-hole.
|
||||||
void* p = stream.data(); int len = stream.pos(); SrsRtcSession* s = session_;
|
void* p = stream.data(); int len = stream.pos(); SrsRtcConnection* s = session_;
|
||||||
srs_sendto(s->blackhole_stfd, p, len, (sockaddr*)s->blackhole_addr, sizeof(sockaddr_in), SRS_UTIME_NO_TIMEOUT);
|
srs_sendto(s->blackhole_stfd, p, len, (sockaddr*)s->blackhole_addr, sizeof(sockaddr_in), SRS_UTIME_NO_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1124,7 +1124,7 @@ srs_error_t SrsRtcPublisher::send_rtcp_fb_pli(uint32_t ssrc)
|
||||||
|
|
||||||
if (session_->blackhole && session_->blackhole_addr && session_->blackhole_stfd) {
|
if (session_->blackhole && session_->blackhole_addr && session_->blackhole_stfd) {
|
||||||
// Ignore any error for black-hole.
|
// Ignore any error for black-hole.
|
||||||
void* p = stream.data(); int len = stream.pos(); SrsRtcSession* s = session_;
|
void* p = stream.data(); int len = stream.pos(); SrsRtcConnection* s = session_;
|
||||||
srs_sendto(s->blackhole_stfd, p, len, (sockaddr*)s->blackhole_addr, sizeof(sockaddr_in), SRS_UTIME_NO_TIMEOUT);
|
srs_sendto(s->blackhole_stfd, p, len, (sockaddr*)s->blackhole_addr, sizeof(sockaddr_in), SRS_UTIME_NO_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1201,7 +1201,7 @@ srs_error_t SrsRtcPublisher::on_rtp(char* data, int nb_data)
|
||||||
|
|
||||||
if (session_->blackhole && session_->blackhole_addr && session_->blackhole_stfd) {
|
if (session_->blackhole && session_->blackhole_addr && session_->blackhole_stfd) {
|
||||||
// Ignore any error for black-hole.
|
// Ignore any error for black-hole.
|
||||||
void* p = unprotected_buf; int len = nb_unprotected_buf; SrsRtcSession* s = session_;
|
void* p = unprotected_buf; int len = nb_unprotected_buf; SrsRtcConnection* s = session_;
|
||||||
srs_sendto(s->blackhole_stfd, p, len, (sockaddr*)s->blackhole_addr, sizeof(sockaddr_in), SRS_UTIME_NO_TIMEOUT);
|
srs_sendto(s->blackhole_stfd, p, len, (sockaddr*)s->blackhole_addr, sizeof(sockaddr_in), SRS_UTIME_NO_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1764,7 +1764,7 @@ void SrsRtcPublisher::simulate_drop_packet(SrsRtpHeader* h, int nn_bytes)
|
||||||
nn_simulate_nack_drop--;
|
nn_simulate_nack_drop--;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSession::SrsRtcSession(SrsRtcServer* s)
|
SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s)
|
||||||
{
|
{
|
||||||
req = NULL;
|
req = NULL;
|
||||||
is_publisher_ = false;
|
is_publisher_ = false;
|
||||||
|
@ -1787,7 +1787,7 @@ SrsRtcSession::SrsRtcSession(SrsRtcServer* s)
|
||||||
blackhole_stfd = NULL;
|
blackhole_stfd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSession::~SrsRtcSession()
|
SrsRtcConnection::~SrsRtcConnection()
|
||||||
{
|
{
|
||||||
srs_freep(player_);
|
srs_freep(player_);
|
||||||
srs_freep(publisher_);
|
srs_freep(publisher_);
|
||||||
|
@ -1798,73 +1798,73 @@ SrsRtcSession::~SrsRtcSession()
|
||||||
srs_freep(sendonly_skt);
|
srs_freep(sendonly_skt);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSdp* SrsRtcSession::get_local_sdp()
|
SrsSdp* SrsRtcConnection::get_local_sdp()
|
||||||
{
|
{
|
||||||
return &local_sdp;
|
return &local_sdp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSession::set_local_sdp(const SrsSdp& sdp)
|
void SrsRtcConnection::set_local_sdp(const SrsSdp& sdp)
|
||||||
{
|
{
|
||||||
local_sdp = sdp;
|
local_sdp = sdp;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsSdp* SrsRtcSession::get_remote_sdp()
|
SrsSdp* SrsRtcConnection::get_remote_sdp()
|
||||||
{
|
{
|
||||||
return &remote_sdp;
|
return &remote_sdp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSession::set_remote_sdp(const SrsSdp& sdp)
|
void SrsRtcConnection::set_remote_sdp(const SrsSdp& sdp)
|
||||||
{
|
{
|
||||||
remote_sdp = sdp;
|
remote_sdp = sdp;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSessionStateType SrsRtcSession::state()
|
SrsRtcConnectionStateType SrsRtcConnection::state()
|
||||||
{
|
{
|
||||||
return state_;
|
return state_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSession::set_state(SrsRtcSessionStateType state)
|
void SrsRtcConnection::set_state(SrsRtcConnectionStateType state)
|
||||||
{
|
{
|
||||||
state_ = state;
|
state_ = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
string SrsRtcSession::id()
|
string SrsRtcConnection::id()
|
||||||
{
|
{
|
||||||
return peer_id_ + "/" + username_;
|
return peer_id_ + "/" + username_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string SrsRtcSession::peer_id()
|
string SrsRtcConnection::peer_id()
|
||||||
{
|
{
|
||||||
return peer_id_;
|
return peer_id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSession::set_peer_id(string v)
|
void SrsRtcConnection::set_peer_id(string v)
|
||||||
{
|
{
|
||||||
peer_id_ = v;
|
peer_id_ = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
string SrsRtcSession::username()
|
string SrsRtcConnection::username()
|
||||||
{
|
{
|
||||||
return username_;
|
return username_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSession::set_encrypt(bool v)
|
void SrsRtcConnection::set_encrypt(bool v)
|
||||||
{
|
{
|
||||||
encrypt = v;
|
encrypt = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSession::switch_to_context()
|
void SrsRtcConnection::switch_to_context()
|
||||||
{
|
{
|
||||||
_srs_context->set_id(cid);
|
_srs_context->set_id(cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsContextId SrsRtcSession::context_id()
|
SrsContextId SrsRtcConnection::context_id()
|
||||||
{
|
{
|
||||||
return cid;
|
return cid;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::initialize(SrsRtcSource* source, SrsRequest* r, bool is_publisher, string username, SrsContextId context_id)
|
srs_error_t SrsRtcConnection::initialize(SrsRtcSource* source, SrsRequest* r, bool is_publisher, string username, SrsContextId context_id)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -1911,7 +1911,7 @@ srs_error_t SrsRtcSession::initialize(SrsRtcSource* source, SrsRequest* r, bool
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* r)
|
srs_error_t SrsRtcConnection::on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* r)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -1941,12 +1941,12 @@ srs_error_t SrsRtcSession::on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* r)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::on_dtls(char* data, int nb_data)
|
srs_error_t SrsRtcConnection::on_dtls(char* data, int nb_data)
|
||||||
{
|
{
|
||||||
return transport_->on_dtls(data, nb_data);
|
return transport_->on_dtls(data, nb_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::on_rtcp(char* data, int nb_data)
|
srs_error_t SrsRtcConnection::on_rtcp(char* data, int nb_data)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -1977,7 +1977,7 @@ srs_error_t SrsRtcSession::on_rtcp(char* data, int nb_data)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::on_rtp(char* data, int nb_data)
|
srs_error_t SrsRtcConnection::on_rtp(char* data, int nb_data)
|
||||||
{
|
{
|
||||||
if (publisher_ == NULL) {
|
if (publisher_ == NULL) {
|
||||||
return srs_error_new(ERROR_RTC_RTCP, "rtc publisher null");
|
return srs_error_new(ERROR_RTC_RTCP, "rtc publisher null");
|
||||||
|
@ -1990,7 +1990,7 @@ srs_error_t SrsRtcSession::on_rtp(char* data, int nb_data)
|
||||||
return publisher_->on_rtp(data, nb_data);
|
return publisher_->on_rtp(data, nb_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::on_connection_established()
|
srs_error_t SrsRtcConnection::on_connection_established()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -2010,7 +2010,7 @@ srs_error_t SrsRtcSession::on_connection_established()
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::start_play()
|
srs_error_t SrsRtcConnection::start_play()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -2047,7 +2047,7 @@ srs_error_t SrsRtcSession::start_play()
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::start_publish()
|
srs_error_t SrsRtcConnection::start_publish()
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -2099,12 +2099,12 @@ srs_error_t SrsRtcSession::start_publish()
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsRtcSession::is_stun_timeout()
|
bool SrsRtcConnection::is_stun_timeout()
|
||||||
{
|
{
|
||||||
return last_stun_time + sessionStunTimeout < srs_get_system_time();
|
return last_stun_time + sessionStunTimeout < srs_get_system_time();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSession::update_sendonly_socket(SrsUdpMuxSocket* skt)
|
void SrsRtcConnection::update_sendonly_socket(SrsUdpMuxSocket* skt)
|
||||||
{
|
{
|
||||||
if (sendonly_skt) {
|
if (sendonly_skt) {
|
||||||
srs_trace("session %s address changed, update %s -> %s",
|
srs_trace("session %s address changed, update %s -> %s",
|
||||||
|
@ -2115,7 +2115,7 @@ void SrsRtcSession::update_sendonly_socket(SrsUdpMuxSocket* skt)
|
||||||
sendonly_skt = skt->copy_sendonly();
|
sendonly_skt = skt->copy_sendonly();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcSession::simulate_nack_drop(int nn)
|
void SrsRtcConnection::simulate_nack_drop(int nn)
|
||||||
{
|
{
|
||||||
if (player_) {
|
if (player_) {
|
||||||
player_->simulate_nack_drop(nn);
|
player_->simulate_nack_drop(nn);
|
||||||
|
@ -2133,7 +2133,7 @@ void SrsRtcSession::simulate_nack_drop(int nn)
|
||||||
#define be32toh ntohl
|
#define be32toh ntohl
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
srs_error_t SrsRtcSession::on_binding_request(SrsStunPacket* r)
|
srs_error_t SrsRtcConnection::on_binding_request(SrsStunPacket* r)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ class SrsUdpMuxSocket;
|
||||||
class SrsConsumer;
|
class SrsConsumer;
|
||||||
class SrsStunPacket;
|
class SrsStunPacket;
|
||||||
class SrsRtcServer;
|
class SrsRtcServer;
|
||||||
class SrsRtcSession;
|
class SrsRtcConnection;
|
||||||
class SrsSharedPtrMessage;
|
class SrsSharedPtrMessage;
|
||||||
class SrsRtcSource;
|
class SrsRtcSource;
|
||||||
class SrsRtpPacket2;
|
class SrsRtpPacket2;
|
||||||
|
@ -95,7 +95,7 @@ public:
|
||||||
static uint64_t kMagicNtpFractionalUnit;
|
static uint64_t kMagicNtpFractionalUnit;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum SrsRtcSessionStateType
|
enum SrsRtcConnectionStateType
|
||||||
{
|
{
|
||||||
// TODO: FIXME: Should prefixed by enum name.
|
// TODO: FIXME: Should prefixed by enum name.
|
||||||
INIT = -1,
|
INIT = -1,
|
||||||
|
@ -109,12 +109,12 @@ enum SrsRtcSessionStateType
|
||||||
class SrsSecurityTransport : public ISrsDtlsCallback
|
class SrsSecurityTransport : public ISrsDtlsCallback
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SrsRtcSession* session_;
|
SrsRtcConnection* session_;
|
||||||
SrsDtls* dtls_;
|
SrsDtls* dtls_;
|
||||||
SrsSRTP* srtp_;
|
SrsSRTP* srtp_;
|
||||||
bool handshake_done;
|
bool handshake_done;
|
||||||
public:
|
public:
|
||||||
SrsSecurityTransport(SrsRtcSession* s);
|
SrsSecurityTransport(SrsRtcConnection* s);
|
||||||
virtual ~SrsSecurityTransport();
|
virtual ~SrsSecurityTransport();
|
||||||
|
|
||||||
srs_error_t initialize(SrsSessionConfig* cfg);
|
srs_error_t initialize(SrsSessionConfig* cfg);
|
||||||
|
@ -187,7 +187,7 @@ class SrsRtcPlayer : virtual public ISrsCoroutineHandler, virtual public ISrsRel
|
||||||
protected:
|
protected:
|
||||||
SrsContextId _parent_cid;
|
SrsContextId _parent_cid;
|
||||||
SrsCoroutine* trd;
|
SrsCoroutine* trd;
|
||||||
SrsRtcSession* session_;
|
SrsRtcConnection* session_;
|
||||||
private:
|
private:
|
||||||
// TODO: FIXME: How to handle timestamp overflow?
|
// TODO: FIXME: How to handle timestamp overflow?
|
||||||
// Information for audio.
|
// Information for audio.
|
||||||
|
@ -208,7 +208,7 @@ private:
|
||||||
// Whether enabled nack.
|
// Whether enabled nack.
|
||||||
bool nack_enabled_;
|
bool nack_enabled_;
|
||||||
public:
|
public:
|
||||||
SrsRtcPlayer(SrsRtcSession* s, SrsContextId parent_cid);
|
SrsRtcPlayer(SrsRtcConnection* s, SrsContextId parent_cid);
|
||||||
virtual ~SrsRtcPlayer();
|
virtual ~SrsRtcPlayer();
|
||||||
public:
|
public:
|
||||||
srs_error_t initialize(uint32_t vssrc, uint32_t assrc, uint16_t v_pt, uint16_t a_pt);
|
srs_error_t initialize(uint32_t vssrc, uint32_t assrc, uint16_t v_pt, uint16_t a_pt);
|
||||||
|
@ -248,7 +248,7 @@ private:
|
||||||
SrsHourGlass* report_timer;
|
SrsHourGlass* report_timer;
|
||||||
uint64_t nn_audio_frames;
|
uint64_t nn_audio_frames;
|
||||||
private:
|
private:
|
||||||
SrsRtcSession* session_;
|
SrsRtcConnection* session_;
|
||||||
uint32_t video_ssrc;
|
uint32_t video_ssrc;
|
||||||
uint32_t audio_ssrc;
|
uint32_t audio_ssrc;
|
||||||
uint16_t pt_to_drop_;
|
uint16_t pt_to_drop_;
|
||||||
|
@ -275,7 +275,7 @@ private:
|
||||||
SrsRtcpTWCC rtcp_twcc_;
|
SrsRtcpTWCC rtcp_twcc_;
|
||||||
SrsRtpExtensionTypes extension_types_;
|
SrsRtpExtensionTypes extension_types_;
|
||||||
public:
|
public:
|
||||||
SrsRtcPublisher(SrsRtcSession* session);
|
SrsRtcPublisher(SrsRtcConnection* session);
|
||||||
virtual ~SrsRtcPublisher();
|
virtual ~SrsRtcPublisher();
|
||||||
public:
|
public:
|
||||||
srs_error_t initialize(uint32_t vssrc, uint32_t assrc, int twcc_id, SrsRequest* req);
|
srs_error_t initialize(uint32_t vssrc, uint32_t assrc, int twcc_id, SrsRequest* req);
|
||||||
|
@ -313,7 +313,8 @@ private:
|
||||||
srs_error_t on_twcc(uint16_t sn);
|
srs_error_t on_twcc(uint16_t sn);
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsRtcSession
|
// A RTC Peer Connection, SDP level object.
|
||||||
|
class SrsRtcConnection
|
||||||
{
|
{
|
||||||
friend class SrsSecurityTransport;
|
friend class SrsSecurityTransport;
|
||||||
friend class SrsRtcPlayer;
|
friend class SrsRtcPlayer;
|
||||||
|
@ -322,7 +323,7 @@ public:
|
||||||
bool disposing_;
|
bool disposing_;
|
||||||
private:
|
private:
|
||||||
SrsRtcServer* server_;
|
SrsRtcServer* server_;
|
||||||
SrsRtcSessionStateType state_;
|
SrsRtcConnectionStateType state_;
|
||||||
SrsSecurityTransport* transport_;
|
SrsSecurityTransport* transport_;
|
||||||
SrsRtcPlayer* player_;
|
SrsRtcPlayer* player_;
|
||||||
SrsRtcPublisher* publisher_;
|
SrsRtcPublisher* publisher_;
|
||||||
|
@ -357,15 +358,15 @@ private:
|
||||||
sockaddr_in* blackhole_addr;
|
sockaddr_in* blackhole_addr;
|
||||||
srs_netfd_t blackhole_stfd;
|
srs_netfd_t blackhole_stfd;
|
||||||
public:
|
public:
|
||||||
SrsRtcSession(SrsRtcServer* s);
|
SrsRtcConnection(SrsRtcServer* s);
|
||||||
virtual ~SrsRtcSession();
|
virtual ~SrsRtcConnection();
|
||||||
public:
|
public:
|
||||||
SrsSdp* get_local_sdp();
|
SrsSdp* get_local_sdp();
|
||||||
void set_local_sdp(const SrsSdp& sdp);
|
void set_local_sdp(const SrsSdp& sdp);
|
||||||
SrsSdp* get_remote_sdp();
|
SrsSdp* get_remote_sdp();
|
||||||
void set_remote_sdp(const SrsSdp& sdp);
|
void set_remote_sdp(const SrsSdp& sdp);
|
||||||
SrsRtcSessionStateType state();
|
SrsRtcConnectionStateType state();
|
||||||
void set_state(SrsRtcSessionStateType state);
|
void set_state(SrsRtcConnectionStateType state);
|
||||||
std::string id();
|
std::string id();
|
||||||
std::string peer_id();
|
std::string peer_id();
|
||||||
void set_peer_id(std::string v);
|
void set_peer_id(std::string v);
|
||||||
|
@ -401,13 +402,13 @@ public:
|
||||||
virtual ~ISrsRtcHijacker();
|
virtual ~ISrsRtcHijacker();
|
||||||
public:
|
public:
|
||||||
// When start publisher by RTC.
|
// When start publisher by RTC.
|
||||||
virtual srs_error_t on_start_publish(SrsRtcSession* session, SrsRtcPublisher* publisher, SrsRequest* req) = 0;
|
virtual srs_error_t on_start_publish(SrsRtcConnection* session, SrsRtcPublisher* publisher, SrsRequest* req) = 0;
|
||||||
// When got RTP plaintext packet.
|
// When got RTP plaintext packet.
|
||||||
virtual srs_error_t on_rtp_packet(SrsRtcSession* session, SrsRtcPublisher* publisher, SrsRequest* req, SrsRtpPacket2* pkt) = 0;
|
virtual srs_error_t on_rtp_packet(SrsRtcConnection* session, SrsRtcPublisher* publisher, SrsRequest* req, SrsRtpPacket2* pkt) = 0;
|
||||||
// When start player by RTC.
|
// When start player by RTC.
|
||||||
virtual srs_error_t on_start_play(SrsRtcSession* session, SrsRtcPlayer* player, SrsRequest* req) = 0;
|
virtual srs_error_t on_start_play(SrsRtcConnection* session, SrsRtcPlayer* player, SrsRequest* req) = 0;
|
||||||
// When start consuming for player for RTC.
|
// When start consuming for player for RTC.
|
||||||
virtual srs_error_t on_start_consume(SrsRtcSession* session, SrsRtcPlayer* player, SrsRequest* req, SrsRtcConsumer* consumer) = 0;
|
virtual srs_error_t on_start_consume(SrsRtcConnection* session, SrsRtcPlayer* player, SrsRequest* req, SrsRtcConsumer* consumer) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ISrsRtcHijacker* _srs_rtc_hijacker;
|
extern ISrsRtcHijacker* _srs_rtc_hijacker;
|
||||||
|
|
|
@ -154,9 +154,9 @@ SrsRtcServer::~SrsRtcServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
std::vector<SrsRtcSession*>::iterator it;
|
std::vector<SrsRtcConnection*>::iterator it;
|
||||||
for (it = zombies_.begin(); it != zombies_.end(); ++it) {
|
for (it = zombies_.begin(); it != zombies_.end(); ++it) {
|
||||||
SrsRtcSession* session = *it;
|
SrsRtcConnection* session = *it;
|
||||||
srs_freep(session);
|
srs_freep(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ srs_error_t SrsRtcServer::on_udp_packet(SrsUdpMuxSocket* skt)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
char* data = skt->data(); int size = skt->size();
|
char* data = skt->data(); int size = skt->size();
|
||||||
SrsRtcSession* session = find_session_by_peer_id(skt->peer_id());
|
SrsRtcConnection* session = find_session_by_peer_id(skt->peer_id());
|
||||||
|
|
||||||
if (session) {
|
if (session) {
|
||||||
// Now, we got the RTC session to handle the packet, switch to its context
|
// Now, we got the RTC session to handle the packet, switch to its context
|
||||||
|
@ -296,7 +296,7 @@ srs_error_t SrsRtcServer::listen_api()
|
||||||
|
|
||||||
srs_error_t SrsRtcServer::create_session(
|
srs_error_t SrsRtcServer::create_session(
|
||||||
SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp, const std::string& mock_eip, bool publish,
|
SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp, const std::string& mock_eip, bool publish,
|
||||||
SrsRtcSession** psession
|
SrsRtcConnection** psession
|
||||||
) {
|
) {
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ srs_error_t SrsRtcServer::create_session(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSession* session = new SrsRtcSession(this);
|
SrsRtcConnection* session = new SrsRtcConnection(this);
|
||||||
session->set_remote_sdp(remote_sdp);
|
session->set_remote_sdp(remote_sdp);
|
||||||
// We must setup the local SDP, then initialize the session object.
|
// We must setup the local SDP, then initialize the session object.
|
||||||
session->set_local_sdp(local_sdp);
|
session->set_local_sdp(local_sdp);
|
||||||
|
@ -357,7 +357,7 @@ srs_error_t SrsRtcServer::create_session(
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcServer::create_session2(SrsSdp& local_sdp, SrsRtcSession** psession)
|
srs_error_t SrsRtcServer::create_session2(SrsSdp& local_sdp, SrsRtcConnection** psession)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ srs_error_t SrsRtcServer::create_session2(SrsSdp& local_sdp, SrsRtcSession** pse
|
||||||
// TODO: FIXME: Collision detect.
|
// TODO: FIXME: Collision detect.
|
||||||
std::string local_ufrag = gen_random_str(8);
|
std::string local_ufrag = gen_random_str(8);
|
||||||
|
|
||||||
SrsRtcSession* session = new SrsRtcSession(this);
|
SrsRtcConnection* session = new SrsRtcConnection(this);
|
||||||
*psession = session;
|
*psession = session;
|
||||||
|
|
||||||
local_sdp.set_ice_ufrag(local_ufrag);
|
local_sdp.set_ice_ufrag(local_ufrag);
|
||||||
|
@ -385,7 +385,7 @@ srs_error_t SrsRtcServer::create_session2(SrsSdp& local_sdp, SrsRtcSession** pse
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcServer::setup_session2(SrsRtcSession* session, SrsRequest* req, const SrsSdp& remote_sdp)
|
srs_error_t SrsRtcServer::setup_session2(SrsRtcConnection* session, SrsRequest* req, const SrsSdp& remote_sdp)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
@ -414,14 +414,14 @@ srs_error_t SrsRtcServer::setup_session2(SrsRtcSession* session, SrsRequest* req
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcServer::destroy(SrsRtcSession* session)
|
void SrsRtcServer::destroy(SrsRtcConnection* session)
|
||||||
{
|
{
|
||||||
if (session->disposing_) {
|
if (session->disposing_) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
session->disposing_ = true;
|
session->disposing_ = true;
|
||||||
|
|
||||||
std::map<std::string, SrsRtcSession*>::iterator it;
|
std::map<std::string, SrsRtcConnection*>::iterator it;
|
||||||
|
|
||||||
if ((it = map_username_session.find(session->username())) != map_username_session.end()) {
|
if ((it = map_username_session.find(session->username())) != map_username_session.end()) {
|
||||||
map_username_session.erase(it);
|
map_username_session.erase(it);
|
||||||
|
@ -434,16 +434,16 @@ void SrsRtcServer::destroy(SrsRtcSession* session)
|
||||||
zombies_.push_back(session);
|
zombies_.push_back(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsRtcServer::insert_into_id_sessions(const string& peer_id, SrsRtcSession* session)
|
bool SrsRtcServer::insert_into_id_sessions(const string& peer_id, SrsRtcConnection* session)
|
||||||
{
|
{
|
||||||
return map_id_session.insert(make_pair(peer_id, session)).second;
|
return map_id_session.insert(make_pair(peer_id, session)).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsRtcServer::check_and_clean_timeout_session()
|
void SrsRtcServer::check_and_clean_timeout_session()
|
||||||
{
|
{
|
||||||
map<string, SrsRtcSession*>::iterator iter = map_username_session.begin();
|
map<string, SrsRtcConnection*>::iterator iter = map_username_session.begin();
|
||||||
while (iter != map_username_session.end()) {
|
while (iter != map_username_session.end()) {
|
||||||
SrsRtcSession* session = iter->second;
|
SrsRtcConnection* session = iter->second;
|
||||||
srs_assert(session);
|
srs_assert(session);
|
||||||
|
|
||||||
if (!session->is_stun_timeout()) {
|
if (!session->is_stun_timeout()) {
|
||||||
|
@ -474,9 +474,9 @@ int SrsRtcServer::nn_sessions()
|
||||||
return (int)map_username_session.size();
|
return (int)map_username_session.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSession* SrsRtcServer::find_session_by_peer_id(const string& peer_id)
|
SrsRtcConnection* SrsRtcServer::find_session_by_peer_id(const string& peer_id)
|
||||||
{
|
{
|
||||||
map<string, SrsRtcSession*>::iterator iter = map_id_session.find(peer_id);
|
map<string, SrsRtcConnection*>::iterator iter = map_id_session.find(peer_id);
|
||||||
if (iter == map_id_session.end()) {
|
if (iter == map_id_session.end()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -484,9 +484,9 @@ SrsRtcSession* SrsRtcServer::find_session_by_peer_id(const string& peer_id)
|
||||||
return iter->second;
|
return iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcSession* SrsRtcServer::find_session_by_username(const std::string& username)
|
SrsRtcConnection* SrsRtcServer::find_session_by_username(const std::string& username)
|
||||||
{
|
{
|
||||||
map<string, SrsRtcSession*>::iterator iter = map_username_session.find(username);
|
map<string, SrsRtcConnection*>::iterator iter = map_username_session.find(username);
|
||||||
if (iter == map_username_session.end()) {
|
if (iter == map_username_session.end()) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -506,12 +506,12 @@ srs_error_t SrsRtcServer::notify(int type, srs_utime_t interval, srs_utime_t tic
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<SrsRtcSession*> zombies;
|
std::vector<SrsRtcConnection*> zombies;
|
||||||
zombies.swap(zombies_);
|
zombies.swap(zombies_);
|
||||||
|
|
||||||
std::vector<SrsRtcSession*>::iterator it;
|
std::vector<SrsRtcConnection*>::iterator it;
|
||||||
for (it = zombies.begin(); it != zombies.end(); ++it) {
|
for (it = zombies.begin(); it != zombies.end(); ++it) {
|
||||||
SrsRtcSession* session = *it;
|
SrsRtcConnection* session = *it;
|
||||||
srs_freep(session);
|
srs_freep(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
class SrsRtcServer;
|
class SrsRtcServer;
|
||||||
class SrsHourGlass;
|
class SrsHourGlass;
|
||||||
class SrsRtcSession;
|
class SrsRtcConnection;
|
||||||
class SrsRequest;
|
class SrsRequest;
|
||||||
class SrsSdp;
|
class SrsSdp;
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public:
|
||||||
virtual ~ISrsRtcServerHandler();
|
virtual ~ISrsRtcServerHandler();
|
||||||
public:
|
public:
|
||||||
// When server detect the timeout for session object.
|
// When server detect the timeout for session object.
|
||||||
virtual void on_timeout(SrsRtcSession* session) = 0;
|
virtual void on_timeout(SrsRtcConnection* session) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SrsRtcServer : virtual public ISrsUdpMuxHandler, virtual public ISrsHourGlass
|
class SrsRtcServer : virtual public ISrsUdpMuxHandler, virtual public ISrsHourGlass
|
||||||
|
@ -57,10 +57,10 @@ private:
|
||||||
std::vector<SrsUdpMuxListener*> listeners;
|
std::vector<SrsUdpMuxListener*> listeners;
|
||||||
ISrsRtcServerHandler* handler;
|
ISrsRtcServerHandler* handler;
|
||||||
private:
|
private:
|
||||||
std::map<std::string, SrsRtcSession*> map_username_session; // key: username(local_ufrag + ":" + remote_ufrag)
|
std::map<std::string, SrsRtcConnection*> map_username_session; // key: username(local_ufrag + ":" + remote_ufrag)
|
||||||
std::map<std::string, SrsRtcSession*> map_id_session; // key: peerip(ip + ":" + port)
|
std::map<std::string, SrsRtcConnection*> map_id_session; // key: peerip(ip + ":" + port)
|
||||||
// The zombie sessions, we will free them.
|
// The zombie sessions, we will free them.
|
||||||
std::vector<SrsRtcSession*> zombies_;
|
std::vector<SrsRtcConnection*> zombies_;
|
||||||
public:
|
public:
|
||||||
SrsRtcServer();
|
SrsRtcServer();
|
||||||
virtual ~SrsRtcServer();
|
virtual ~SrsRtcServer();
|
||||||
|
@ -78,20 +78,20 @@ public:
|
||||||
// Peer start offering, we answer it.
|
// Peer start offering, we answer it.
|
||||||
srs_error_t create_session(
|
srs_error_t create_session(
|
||||||
SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp, const std::string& mock_eip, bool publish,
|
SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp, const std::string& mock_eip, bool publish,
|
||||||
SrsRtcSession** psession
|
SrsRtcConnection** psession
|
||||||
);
|
);
|
||||||
// We start offering, create_session2 to generate offer, setup_session2 to handle answer.
|
// We start offering, create_session2 to generate offer, setup_session2 to handle answer.
|
||||||
srs_error_t create_session2(SrsSdp& local_sdp, SrsRtcSession** psession);
|
srs_error_t create_session2(SrsSdp& local_sdp, SrsRtcConnection** psession);
|
||||||
srs_error_t setup_session2(SrsRtcSession* session, SrsRequest* req, const SrsSdp& remote_sdp);
|
srs_error_t setup_session2(SrsRtcConnection* session, SrsRequest* req, const SrsSdp& remote_sdp);
|
||||||
// Destroy the session from server.
|
// Destroy the session from server.
|
||||||
void destroy(SrsRtcSession* session);
|
void destroy(SrsRtcConnection* session);
|
||||||
public:
|
public:
|
||||||
bool insert_into_id_sessions(const std::string& peer_id, SrsRtcSession* session);
|
bool insert_into_id_sessions(const std::string& peer_id, SrsRtcConnection* session);
|
||||||
void check_and_clean_timeout_session();
|
void check_and_clean_timeout_session();
|
||||||
int nn_sessions();
|
int nn_sessions();
|
||||||
SrsRtcSession* find_session_by_username(const std::string& ufrag);
|
SrsRtcConnection* find_session_by_username(const std::string& ufrag);
|
||||||
private:
|
private:
|
||||||
SrsRtcSession* find_session_by_peer_id(const std::string& peer_id);
|
SrsRtcConnection* find_session_by_peer_id(const std::string& peer_id);
|
||||||
// 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);
|
||||||
|
|
Loading…
Reference in a new issue