mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Refine cid for session
This commit is contained in:
parent
c9c34b54a7
commit
d2984ea49c
3 changed files with 13 additions and 13 deletions
|
@ -1462,11 +1462,12 @@ void SrsRtcPublishStream::update_send_report_time(uint32_t ssrc, const SrsNtp& n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s)
|
SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s, SrsContextId context_id)
|
||||||
{
|
{
|
||||||
req = NULL;
|
req = NULL;
|
||||||
is_publisher_ = false;
|
is_publisher_ = false;
|
||||||
encrypt = true;
|
encrypt = true;
|
||||||
|
cid = context_id;
|
||||||
|
|
||||||
source_ = NULL;
|
source_ = NULL;
|
||||||
publisher_ = NULL;
|
publisher_ = NULL;
|
||||||
|
@ -1672,13 +1673,12 @@ srs_error_t SrsRtcConnection::add_player2(SrsRequest* req, SrsSdp& local_sdp)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsRtcConnection::initialize(SrsRtcStream* source, SrsRequest* r, bool is_publisher, string username, SrsContextId context_id)
|
srs_error_t SrsRtcConnection::initialize(SrsRtcStream* source, SrsRequest* r, bool is_publisher, string username)
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
username_ = username;
|
username_ = username;
|
||||||
req = r->copy();
|
req = r->copy();
|
||||||
cid = context_id;
|
|
||||||
is_publisher_ = is_publisher;
|
is_publisher_ = is_publisher;
|
||||||
source_ = source;
|
source_ = source;
|
||||||
|
|
||||||
|
|
|
@ -337,7 +337,7 @@ private:
|
||||||
// Simulators.
|
// Simulators.
|
||||||
int nn_simulate_player_nack_drop;
|
int nn_simulate_player_nack_drop;
|
||||||
public:
|
public:
|
||||||
SrsRtcConnection(SrsRtcServer* s);
|
SrsRtcConnection(SrsRtcServer* s, SrsContextId context_id);
|
||||||
virtual ~SrsRtcConnection();
|
virtual ~SrsRtcConnection();
|
||||||
public:
|
public:
|
||||||
// TODO: FIXME: save only connection info.
|
// TODO: FIXME: save only connection info.
|
||||||
|
@ -360,7 +360,7 @@ public:
|
||||||
srs_error_t add_player2(SrsRequest* request, SrsSdp& local_sdp);
|
srs_error_t add_player2(SrsRequest* request, SrsSdp& local_sdp);
|
||||||
public:
|
public:
|
||||||
// Before initialize, user must set the local SDP, which is used to inititlize DTLS.
|
// Before initialize, user must set the local SDP, which is used to inititlize DTLS.
|
||||||
srs_error_t initialize(SrsRtcStream* source, SrsRequest* r, bool is_publisher, std::string username, SrsContextId context_id);
|
srs_error_t initialize(SrsRtcStream* source, SrsRequest* r, bool is_publisher, std::string username);
|
||||||
// The peer address may change, we can identify that by STUN messages.
|
// The peer address may change, we can identify that by STUN messages.
|
||||||
srs_error_t on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* r);
|
srs_error_t on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* r);
|
||||||
srs_error_t on_dtls(char* data, int nb_data);
|
srs_error_t on_dtls(char* data, int nb_data);
|
||||||
|
|
|
@ -302,6 +302,8 @@ srs_error_t SrsRtcServer::create_session(
|
||||||
) {
|
) {
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
SrsRtcStream* source = NULL;
|
SrsRtcStream* source = NULL;
|
||||||
if ((err = _srs_rtc_sources->fetch_or_create(req, &source)) != srs_success) {
|
if ((err = _srs_rtc_sources->fetch_or_create(req, &source)) != srs_success) {
|
||||||
return srs_error_wrap(err, "create source");
|
return srs_error_wrap(err, "create source");
|
||||||
|
@ -313,7 +315,7 @@ srs_error_t SrsRtcServer::create_session(
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: FIXME: add do_create_session to error process.
|
// TODO: FIXME: add do_create_session to error process.
|
||||||
SrsRtcConnection* session = new SrsRtcConnection(this);
|
SrsRtcConnection* session = new SrsRtcConnection(this, cid);
|
||||||
if ((err = do_create_session(session, req, remote_sdp, local_sdp, mock_eip, publish, source)) != srs_success) {
|
if ((err = do_create_session(session, req, remote_sdp, local_sdp, mock_eip, publish, source)) != srs_success) {
|
||||||
srs_freep(session);
|
srs_freep(session);
|
||||||
return srs_error_wrap(err, "create session");
|
return srs_error_wrap(err, "create session");
|
||||||
|
@ -331,8 +333,6 @@ srs_error_t SrsRtcServer::do_create_session(
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsContextId cid = _srs_context->get_id();
|
|
||||||
|
|
||||||
// first add publisher/player for negotiate sdp media info
|
// first add publisher/player for negotiate sdp media info
|
||||||
if (publish) {
|
if (publish) {
|
||||||
if ((err = session->add_publisher(req, remote_sdp, local_sdp)) != srs_success) {
|
if ((err = session->add_publisher(req, remote_sdp, local_sdp)) != srs_success) {
|
||||||
|
@ -393,7 +393,7 @@ srs_error_t SrsRtcServer::do_create_session(
|
||||||
session->set_state(WAITING_STUN);
|
session->set_state(WAITING_STUN);
|
||||||
|
|
||||||
// Before session initialize, we must setup the local SDP.
|
// Before session initialize, we must setup the local SDP.
|
||||||
if ((err = session->initialize(source, req, publish, username, cid)) != srs_success) {
|
if ((err = session->initialize(source, req, publish, username)) != srs_success) {
|
||||||
return srs_error_wrap(err, "init");
|
return srs_error_wrap(err, "init");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -405,11 +405,13 @@ srs_error_t SrsRtcServer::create_session2(SrsRequest* req, SrsSdp& local_sdp, co
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
|
SrsContextId cid = _srs_context->get_id();
|
||||||
|
|
||||||
std::string local_pwd = srs_random_str(32);
|
std::string local_pwd = srs_random_str(32);
|
||||||
// TODO: FIXME: Collision detect.
|
// TODO: FIXME: Collision detect.
|
||||||
std::string local_ufrag = srs_random_str(8);
|
std::string local_ufrag = srs_random_str(8);
|
||||||
|
|
||||||
SrsRtcConnection* session = new SrsRtcConnection(this);
|
SrsRtcConnection* session = new SrsRtcConnection(this, cid);
|
||||||
// first add player for negotiate local sdp media info
|
// first add player for negotiate local sdp media info
|
||||||
if ((err = session->add_player2(req, local_sdp)) != srs_success) {
|
if ((err = session->add_player2(req, local_sdp)) != srs_success) {
|
||||||
srs_freep(session);
|
srs_freep(session);
|
||||||
|
@ -445,8 +447,6 @@ srs_error_t SrsRtcServer::setup_session2(SrsRtcConnection* session, SrsRequest*
|
||||||
{
|
{
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
SrsContextId cid = _srs_context->get_id();
|
|
||||||
|
|
||||||
if (session->state() != WAITING_ANSWER) {
|
if (session->state() != WAITING_ANSWER) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,7 @@ srs_error_t SrsRtcServer::setup_session2(SrsRtcConnection* session, SrsRequest*
|
||||||
// TODO: FIXME: Collision detect.
|
// TODO: FIXME: Collision detect.
|
||||||
string username = session->get_local_sdp()->get_ice_ufrag() + ":" + remote_sdp.get_ice_ufrag();
|
string username = session->get_local_sdp()->get_ice_ufrag() + ":" + remote_sdp.get_ice_ufrag();
|
||||||
|
|
||||||
if ((err = session->initialize(source, req, false, username, cid)) != srs_success) {
|
if ((err = session->initialize(source, req, false, username)) != srs_success) {
|
||||||
return srs_error_wrap(err, "init");
|
return srs_error_wrap(err, "init");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue