diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index c31f67175b..a8d1d70362 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -566,10 +566,8 @@ PeerConnection::~PeerConnection() { if (sdp_handler_) { // Don't destroy BaseChannels until after stats has been cleaned up so that // the last stats request can still read from the channels. - sdp_handler_->DestroyAllChannels(); - + sdp_handler_->DestroyMediaChannels(); RTC_LOG(LS_INFO) << "Session: " << session_id() << " is destroyed."; - sdp_handler_->ResetSessionDescFactory(); } @@ -584,6 +582,8 @@ PeerConnection::~PeerConnection() { if (network_thread_safety_) network_thread_safety_->SetNotAlive(); }); + sctp_mid_s_.reset(); + SetSctpTransportName(""); // call_ and event_log_ must be destroyed on the worker thread. worker_thread()->BlockingCall([this] { @@ -1899,7 +1899,12 @@ void PeerConnection::Close() { // Don't destroy BaseChannels until after stats has been cleaned up so that // the last stats request can still read from the channels. - sdp_handler_->DestroyAllChannels(); + // TODO(tommi): The voice/video channels will be partially uninitialized on + // the network thread (see `RtpTransceiver::ClearChannel`), partially on the + // worker thread (see `PushNewMediaChannelAndDeleteChannel`) and then + // eventually freed on the signaling thread. + // It would be good to combine those steps with the teardown steps here. + sdp_handler_->DestroyMediaChannels(); // The event log is used in the transport controller, which must be outlived // by the former. CreateOffer by the peer connection is implemented @@ -1912,12 +1917,8 @@ void PeerConnection::Close() { } network_thread()->BlockingCall([this] { - // Data channels will already have been unset via the DestroyAllChannels() - // call above, which triggers a call to TeardownDataChannelTransport_n(). - // TODO(tommi): ^^ That's not exactly optimal since this is yet another - // blocking hop to the network thread during Close(). Further still, the - // voice/video/data channels will be cleared on the worker thread. RTC_DCHECK_RUN_ON(network_thread()); + TeardownDataChannelTransport_n({}); transport_controller_.reset(); port_allocator_->DiscardCandidatePool(); if (network_thread_safety_) { @@ -1925,6 +1926,9 @@ void PeerConnection::Close() { } }); + sctp_mid_s_.reset(); + SetSctpTransportName(""); + worker_thread()->BlockingCall([this] { RTC_DCHECK_RUN_ON(worker_thread()); worker_thread_safety_->SetNotAlive(); diff --git a/pc/sdp_offer_answer.cc b/pc/sdp_offer_answer.cc index c795ccff6c..0261195bb0 100644 --- a/pc/sdp_offer_answer.cc +++ b/pc/sdp_offer_answer.cc @@ -5204,7 +5204,7 @@ RTCError SdpOfferAnswerHandler::CreateChannels(const SessionDescription& desc) { return RTCError::OK(); } -void SdpOfferAnswerHandler::DestroyAllChannels() { +void SdpOfferAnswerHandler::DestroyMediaChannels() { RTC_DCHECK_RUN_ON(signaling_thread()); if (!transceivers()) { return; @@ -5227,8 +5227,6 @@ void SdpOfferAnswerHandler::DestroyAllChannels() { transceiver->internal()->ClearChannel(); } } - - pc_->DestroyDataChannelTransport({}); } void SdpOfferAnswerHandler::GenerateMediaDescriptionOptions( diff --git a/pc/sdp_offer_answer.h b/pc/sdp_offer_answer.h index eb7c705461..8aa7040b16 100644 --- a/pc/sdp_offer_answer.h +++ b/pc/sdp_offer_answer.h @@ -166,8 +166,8 @@ class SdpOfferAnswerHandler : public SdpStateProvider { // See also `InternalDataChannelInit::fallback_ssl_role`. absl::optional GuessSslRole() const; - // Destroys all BaseChannels and destroys the SCTP data channel, if present. - void DestroyAllChannels(); + // Destroys all media BaseChannels. + void DestroyMediaChannels(); rtc::scoped_refptr local_streams(); rtc::scoped_refptr remote_streams();