提交 cbc7c0ba authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Room.cpp: unify code

上级 71b8cccf
...@@ -51,6 +51,7 @@ namespace RTC ...@@ -51,6 +51,7 @@ namespace RTC
private: private:
RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr) const; RTC::Peer* GetPeerFromRequest(Channel::Request* request, uint32_t* peerId = nullptr) const;
void SetCapabilities(std::vector<RTC::RtpCodecParameters>& mediaCodecs); void SetCapabilities(std::vector<RTC::RtpCodecParameters>& mediaCodecs);
void AddRtpSenderForRtpReceiver(RTC::Peer* senderPeer, const RTC::RtpReceiver* rtpReceiver);
/* Pure virtual methods inherited from RTC::Peer::Listener. */ /* Pure virtual methods inherited from RTC::Peer::Listener. */
public: public:
......
...@@ -442,6 +442,28 @@ namespace RTC ...@@ -442,6 +442,28 @@ namespace RTC
this->capabilities.fecMechanisms = Room::supportedRtpCapabilities.fecMechanisms; this->capabilities.fecMechanisms = Room::supportedRtpCapabilities.fecMechanisms;
} }
inline void Room::AddRtpSenderForRtpReceiver(RTC::Peer* senderPeer, const RTC::RtpReceiver* rtpReceiver)
{
MS_TRACE();
MS_ASSERT(senderPeer->HasCapabilities(), "sender peer has no capabilities");
MS_ASSERT(rtpReceiver->GetParameters(), "rtpReceiver has no parameters");
uint32_t rtpSenderId = Utils::Crypto::GetRandomUInt(10000000, 99999999);
RTC::RtpSender* rtpSender =
new RTC::RtpSender(senderPeer, this->notifier, rtpSenderId, rtpReceiver->kind);
// Store into the maps.
this->mapRtpReceiverRtpSenders[rtpReceiver].insert(rtpSender);
this->mapRtpSenderRtpReceiver[rtpSender] = rtpReceiver;
auto rtpParameters = rtpReceiver->GetParameters();
auto associatedRtpReceiverId = rtpReceiver->rtpReceiverId;
// Attach the RtpSender to the peer.
senderPeer->AddRtpSender(rtpSender, rtpParameters, associatedRtpReceiverId);
}
void Room::onPeerClosed(const RTC::Peer* peer) void Room::onPeerClosed(const RTC::Peer* peer)
{ {
MS_TRACE(); MS_TRACE();
...@@ -502,19 +524,7 @@ namespace RTC ...@@ -502,19 +524,7 @@ namespace RTC
if (!rtpReceiver->GetParameters()) if (!rtpReceiver->GetParameters())
continue; continue;
uint32_t rtpSenderId = Utils::Crypto::GetRandomUInt(10000000, 99999999); AddRtpSenderForRtpReceiver(peer, rtpReceiver);
RTC::RtpSender* rtpSender =
new RTC::RtpSender(peer, this->notifier, rtpSenderId, rtpReceiver->kind);
// Store into the maps.
this->mapRtpReceiverRtpSenders[rtpReceiver].insert(rtpSender);
this->mapRtpSenderRtpReceiver[rtpSender] = rtpReceiver;
auto rtpParameters = rtpReceiver->GetParameters();
auto associatedRtpReceiverId = rtpReceiver->rtpReceiverId;
// Attach the RtpSender to the peer.
peer->AddRtpSender(rtpSender, rtpParameters, associatedRtpReceiverId);
} }
} }
} }
...@@ -544,20 +554,7 @@ namespace RTC ...@@ -544,20 +554,7 @@ namespace RTC
if (!senderPeer->HasCapabilities()) if (!senderPeer->HasCapabilities())
continue; continue;
// Create a RtpSender for the other Peer. AddRtpSenderForRtpReceiver(senderPeer, rtpReceiver);
uint32_t rtpSenderId = Utils::Crypto::GetRandomUInt(10000000, 99999999);
RTC::RtpSender* rtpSender =
new RTC::RtpSender(senderPeer, this->notifier, rtpSenderId, rtpReceiver->kind);
// Store into the maps.
this->mapRtpReceiverRtpSenders[rtpReceiver].insert(rtpSender);
this->mapRtpSenderRtpReceiver[rtpSender] = rtpReceiver;
auto rtpParameters = rtpReceiver->GetParameters();
auto associatedRtpReceiverId = rtpReceiver->rtpReceiverId;
// Attach the RtpSender to the senderPeer.
senderPeer->AddRtpSender(rtpSender, rtpParameters, associatedRtpReceiverId);
} }
} }
// If this is not a new RtpReceiver let's retrieve its updated parameters // If this is not a new RtpReceiver let's retrieve its updated parameters
......
...@@ -758,7 +758,7 @@ namespace RTC ...@@ -758,7 +758,7 @@ namespace RTC
// Ensure DTLS is connected. // Ensure DTLS is connected.
if (this->dtlsTransport->GetState() != RTC::DtlsTransport::DtlsState::CONNECTED) if (this->dtlsTransport->GetState() != RTC::DtlsTransport::DtlsState::CONNECTED)
{ {
MS_WARN_2TAGS(dtls, rtp, "ignoring RTP packet while DTLS not connected"); MS_DEBUG_2TAGS(dtls, rtp, "ignoring RTP packet while DTLS not connected");
return; return;
} }
...@@ -766,7 +766,7 @@ namespace RTC ...@@ -766,7 +766,7 @@ namespace RTC
// Ensure there is receiving SRTP session. // Ensure there is receiving SRTP session.
if (!this->srtpRecvSession) if (!this->srtpRecvSession)
{ {
MS_WARN_TAG(srtp, "ignoring RTP packet due to non receiving SRTP session"); MS_DEBUG_TAG(srtp, "ignoring RTP packet due to non receiving SRTP session");
return; return;
} }
...@@ -868,7 +868,7 @@ namespace RTC ...@@ -868,7 +868,7 @@ namespace RTC
// Ensure DTLS is connected. // Ensure DTLS is connected.
if (this->dtlsTransport->GetState() != RTC::DtlsTransport::DtlsState::CONNECTED) if (this->dtlsTransport->GetState() != RTC::DtlsTransport::DtlsState::CONNECTED)
{ {
MS_WARN_2TAGS(dtls, rtcp, "ignoring RTCP packet while DTLS not connected"); MS_DEBUG_2TAGS(dtls, rtcp, "ignoring RTCP packet while DTLS not connected");
return; return;
} }
...@@ -876,7 +876,7 @@ namespace RTC ...@@ -876,7 +876,7 @@ namespace RTC
// Ensure there is receiving SRTP session. // Ensure there is receiving SRTP session.
if (!this->srtpRecvSession) if (!this->srtpRecvSession)
{ {
MS_WARN_TAG(srtp, "ignoring RTCP packet due to non receiving SRTP session"); MS_DEBUG_TAG(srtp, "ignoring RTCP packet due to non receiving SRTP session");
return; return;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论