From 70f9e249d573705db65f50d5634f1445fdafbc7c Mon Sep 17 00:00:00 2001 From: Lahiru Ginnaliya Gamathige Date: Wed, 27 Jan 2021 23:32:46 -0800 Subject: [PATCH] Remove DtlsHandShakeError and replace it with a Function Pointer. - Remove the last sigslot from JsepTransportController. - Tested the potential test failure on chromium blink test by importing this CL to chromium source. Bug: webrtc:11943 Change-Id: I107d05606350aff655ca73a5cb640dff1a7036ee Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/202741 Reviewed-by: Harald Alvestrand Reviewed-by: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#33085} --- pc/jsep_transport_controller.cc | 3 ++- pc/jsep_transport_controller.h | 3 +-- pc/jsep_transport_controller_unittest.cc | 1 + pc/peer_connection.cc | 15 ++++++++++----- pc/peer_connection.h | 2 ++ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc index d2a00017fa..9ab8fb9962 100644 --- a/pc/jsep_transport_controller.cc +++ b/pc/jsep_transport_controller.cc @@ -87,6 +87,7 @@ JsepTransportController::JsepTransportController( RTC_DCHECK(config_.transport_observer); RTC_DCHECK(config_.rtcp_handler); RTC_DCHECK(config_.ice_transport_factory); + RTC_DCHECK(config_.on_dtls_handshake_error_); } JsepTransportController::~JsepTransportController() { @@ -1411,7 +1412,7 @@ void JsepTransportController::OnRtcpPacketReceived_n( void JsepTransportController::OnDtlsHandshakeError( rtc::SSLHandshakeError error) { - SignalDtlsHandshakeError(error); + config_.on_dtls_handshake_error_(error); } } // namespace webrtc diff --git a/pc/jsep_transport_controller.h b/pc/jsep_transport_controller.h index f123997ae1..2f9d8a0a93 100644 --- a/pc/jsep_transport_controller.h +++ b/pc/jsep_transport_controller.h @@ -103,6 +103,7 @@ class JsepTransportController : public sigslot::has_slots<> { // Factory for SCTP transports. SctpTransportFactoryInterface* sctp_factory = nullptr; + std::function on_dtls_handshake_error_; }; // The ICE related events are signaled on the |signaling_thread|. @@ -192,8 +193,6 @@ class JsepTransportController : public sigslot::has_slots<> { // and deletes unused transports, but doesn't consider anything more complex. void RollbackTransports(); - sigslot::signal1 SignalDtlsHandshakeError; - // F: void(const std::string&, const std::vector&) template void SubscribeIceCandidateGathered(F&& callback) { diff --git a/pc/jsep_transport_controller_unittest.cc b/pc/jsep_transport_controller_unittest.cc index 06ac36119a..5361f904aa 100644 --- a/pc/jsep_transport_controller_unittest.cc +++ b/pc/jsep_transport_controller_unittest.cc @@ -82,6 +82,7 @@ class JsepTransportControllerTest : public JsepTransportController::Observer, int64_t packet_time_us) { RTC_NOTREACHED(); }; config.ice_transport_factory = fake_ice_transport_factory_.get(); config.dtls_transport_factory = fake_dtls_transport_factory_.get(); + config.on_dtls_handshake_error_ = [](rtc::SSLHandshakeError s) {}; transport_controller_ = std::make_unique( signaling_thread, network_thread, port_allocator, nullptr /* async_resolver_factory */, config); diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 308c5fb76a..23be9b9112 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -453,7 +453,8 @@ PeerConnection::PeerConnection( call_(std::move(call)), call_ptr_(call_.get()), data_channel_controller_(this), - message_handler_(signaling_thread()) {} + message_handler_(signaling_thread()), + weak_factory_(this) {} PeerConnection::~PeerConnection() { TRACE_EVENT0("webrtc", "PeerConnection::~PeerConnection"); @@ -602,18 +603,22 @@ RTCError PeerConnection::Initialize( } config.ice_transport_factory = ice_transport_factory_.get(); + config.on_dtls_handshake_error_ = + [weak_ptr = weak_factory_.GetWeakPtr()](rtc::SSLHandshakeError s) { + if (weak_ptr) { + weak_ptr->OnTransportControllerDtlsHandshakeError(s); + } + }; transport_controller_.reset(new JsepTransportController( signaling_thread(), network_thread(), port_allocator_.get(), async_resolver_factory_.get(), config)); - transport_controller_->SignalDtlsHandshakeError.connect( - this, &PeerConnection::OnTransportControllerDtlsHandshakeError); - - // Following RTC_DCHECKs are added by looking at the caller thread. + // The following RTC_DCHECKs are added by looking at the caller thread. // If this is incorrect there might not be test failures // due to lack of unit tests which trigger these scenarios. // TODO(bugs.webrtc.org/12160): Remove above comments. + // callbacks for signaling_thread. transport_controller_->SubscribeIceConnectionState( [this](cricket::IceConnectionState s) { RTC_DCHECK_RUN_ON(signaling_thread()); diff --git a/pc/peer_connection.h b/pc/peer_connection.h index 65d893e59e..f3aa9b3422 100644 --- a/pc/peer_connection.h +++ b/pc/peer_connection.h @@ -692,6 +692,8 @@ class PeerConnection : public PeerConnectionInternal, // Administration of senders, receivers and transceivers // Accessed on both signaling and network thread. Const after Initialize(). std::unique_ptr rtp_manager_; + + rtc::WeakPtrFactory weak_factory_; }; } // namespace webrtc