From 82b78f45445c3043221db664434b0bb86f9c6f7a Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Fri, 15 Oct 2021 17:12:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84webrtc=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E8=BF=BD=E8=B8=AA=E7=9B=B8=E5=85=B3=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcPlayer.cpp | 1 - webrtc/WebRtcPusher.cpp | 1 - webrtc/WebRtcSession.cpp | 11 +++++++++-- webrtc/WebRtcSession.h | 2 ++ webrtc/WebRtcTransport.cpp | 16 ++++++++-------- webrtc/WebRtcTransport.h | 4 ++-- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/webrtc/WebRtcPlayer.cpp b/webrtc/WebRtcPlayer.cpp index 85dcf869..d24bb923 100644 --- a/webrtc/WebRtcPlayer.cpp +++ b/webrtc/WebRtcPlayer.cpp @@ -24,7 +24,6 @@ WebRtcPlayer::Ptr WebRtcPlayer::create(const EventPoller::Ptr &poller, WebRtcPlayer::WebRtcPlayer(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info) : WebRtcTransportImp(poller) { - InfoL << this; _media_info = info; _play_src = src; CHECK(_play_src); diff --git a/webrtc/WebRtcPusher.cpp b/webrtc/WebRtcPusher.cpp index b0d5e6d5..3791678e 100644 --- a/webrtc/WebRtcPusher.cpp +++ b/webrtc/WebRtcPusher.cpp @@ -24,7 +24,6 @@ WebRtcPusher::Ptr WebRtcPusher::create(const EventPoller::Ptr &poller, WebRtcPusher::WebRtcPusher(const EventPoller::Ptr &poller, const RtspMediaSource::Ptr &src, const MediaInfo &info) : WebRtcTransportImp(poller) { - InfoL << this; _media_info = info; _push_src = src; CHECK(_push_src); diff --git a/webrtc/WebRtcSession.cpp b/webrtc/WebRtcSession.cpp index e2295c9e..6dd508e9 100644 --- a/webrtc/WebRtcSession.cpp +++ b/webrtc/WebRtcSession.cpp @@ -14,7 +14,6 @@ WebRtcSession::WebRtcSession(const Socket::Ptr &sock) : UdpSession(sock) { socklen_t addr_len = sizeof(_peer_addr); getpeername(sock->rawFD(), &_peer_addr, &addr_len); - InfoP(this); } WebRtcSession::~WebRtcSession() { @@ -61,9 +60,12 @@ void WebRtcSession::onRecv_l(const Buffer::Ptr &buffer) { if (_find_transport) { //只允许寻找一次transport _find_transport = false; - _transport = WebRtcTransportImp::move(getUserName(buffer)); + auto user_name = getUserName(buffer); + _identifier = user_name + '-' + to_string(reinterpret_cast(this)); + _transport = WebRtcTransportImp::move(user_name); CHECK(_transport && _transport->getPoller()->isCurrentThread()); _transport->setSession(shared_from_this()); + InfoP(this); } _ticker.resetTime(); CHECK(_transport); @@ -96,3 +98,8 @@ void WebRtcSession::onManager() { return; } } + +std::string WebRtcSession::getIdentifier() const { + return _identifier; +} + diff --git a/webrtc/WebRtcSession.h b/webrtc/WebRtcSession.h index 3dce62b1..20ac1600 100644 --- a/webrtc/WebRtcSession.h +++ b/webrtc/WebRtcSession.h @@ -28,11 +28,13 @@ public: void onRecv(const Buffer::Ptr &) override; void onError(const SockException &err) override; void onManager() override; + std::string getIdentifier() const override; private: void onRecv_l(const Buffer::Ptr &); private: + std::string _identifier; bool _find_transport = true; Ticker _ticker; struct sockaddr _peer_addr; diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index fbbbe0b5..2b982094 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -45,12 +45,12 @@ static onceToken token([]() { WebRtcTransport::WebRtcTransport(const EventPoller::Ptr &poller) { _poller = poller; + _identifier = to_string(reinterpret_cast(this)); } void WebRtcTransport::onCreate(){ - _key = to_string(reinterpret_cast(this)); _dtls_transport = std::make_shared(_poller, this); - _ice_server = std::make_shared(this, _key, makeRandStr(24)); + _ice_server = std::make_shared(this, _identifier, makeRandStr(24)); } void WebRtcTransport::onDestory(){ @@ -62,8 +62,8 @@ const EventPoller::Ptr& WebRtcTransport::getPoller() const{ return _poller; } -const string &WebRtcTransport::getKey() const { - return _key; +const string &WebRtcTransport::getIdentifier() const { + return _identifier; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -310,11 +310,11 @@ void WebRtcTransportImp::onCreate(){ } WebRtcTransportImp::WebRtcTransportImp(const EventPoller::Ptr &poller) : WebRtcTransport(poller) { - InfoL << this; + InfoL << getIdentifier(); } WebRtcTransportImp::~WebRtcTransportImp() { - InfoL << this; + InfoL << getIdentifier(); } void WebRtcTransportImp::onDestory() { @@ -889,7 +889,7 @@ public: void WebRtcTransportImp::registerSelf() { _self = static_pointer_cast(shared_from_this()); - WebRtcTransportManager::instance().addItem(getKey(), _self); + WebRtcTransportManager::instance().addItem(getIdentifier(), _self); } void WebRtcTransportImp::unrefSelf() { @@ -898,7 +898,7 @@ void WebRtcTransportImp::unrefSelf() { void WebRtcTransportImp::unregisterSelf() { unrefSelf(); - WebRtcTransportManager::instance().removeItem(getKey()); + WebRtcTransportManager::instance().removeItem(getIdentifier()); } WebRtcTransportImp::Ptr WebRtcTransportImp::get(const string &key) { diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index 38109083..7e58b947 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -77,7 +77,7 @@ public: void sendRtcpPacket(const char *buf, int len, bool flush, void *ctx = nullptr); const EventPoller::Ptr& getPoller() const; - const string& getKey() const; + const string& getIdentifier() const; protected: //// dtls相关的回调 //// @@ -130,7 +130,7 @@ protected: private: uint8_t _srtp_buf[2000]; - string _key; + string _identifier; EventPoller::Ptr _poller; std::shared_ptr _ice_server; std::shared_ptr _dtls_transport;