diff --git a/pc/rtp_transceiver.cc b/pc/rtp_transceiver.cc index 807cf26880..d696c6494b 100644 --- a/pc/rtp_transceiver.cc +++ b/pc/rtp_transceiver.cc @@ -311,8 +311,7 @@ void RtpTransceiver::SetChannel( RTC_DCHECK_EQ(media_type(), channel->media_type()); signaling_thread_safety_ = PendingTaskSafetyFlag::Create(); - - std::unique_ptr channel_to_delete; + channel_ = std::move(channel); // An alternative to this, could be to require SetChannel to be called // on the network thread. The channel object operates for the most part @@ -324,17 +323,6 @@ void RtpTransceiver::SetChannel( // helps with keeping the channel implementation requirements being met and // avoids synchronization for accessing the pointer or network related state. context()->network_thread()->BlockingCall([&]() { - // TODO(tommi): Isn't `channel_` guaranteed to be nullptr here? (i.e. - // remove this block). - if (channel_) { - channel_->SetFirstPacketReceivedCallback(nullptr); - channel_->SetFirstPacketSentCallback(nullptr); - channel_->SetRtpTransport(nullptr); - channel_to_delete = std::move(channel_); - } - - channel_ = std::move(channel); - channel_->SetRtpTransport(transport_lookup(channel_->mid())); channel_->SetFirstPacketReceivedCallback( [thread = thread_, flag = signaling_thread_safety_, this]() mutable { @@ -361,23 +349,17 @@ void RtpTransceiver::ClearChannel() { RTC_LOG_THREAD_BLOCK_COUNT(); - if (channel_) { - signaling_thread_safety_->SetNotAlive(); - signaling_thread_safety_ = nullptr; - } - std::unique_ptr channel_to_delete; + signaling_thread_safety_->SetNotAlive(); + signaling_thread_safety_ = nullptr; context()->network_thread()->BlockingCall([&]() { - if (channel_) { - channel_->SetFirstPacketReceivedCallback(nullptr); - channel_->SetFirstPacketSentCallback(nullptr); - channel_->SetRtpTransport(nullptr); - channel_to_delete = std::move(channel_); - } + channel_->SetFirstPacketReceivedCallback(nullptr); + channel_->SetFirstPacketSentCallback(nullptr); + channel_->SetRtpTransport(nullptr); }); RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(1); - PushNewMediaChannelAndDeleteChannel(std::move(channel_to_delete)); + PushNewMediaChannelAndDeleteChannel(std::move(channel_)); RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(2); } @@ -405,9 +387,7 @@ void RtpTransceiver::PushNewMediaChannelAndDeleteChannel( // Destroy the channel, if we had one, now _after_ updating the receivers // who might have had references to the previous channel. - if (channel_to_delete) { - channel_to_delete.reset(nullptr); - } + channel_to_delete = nullptr; }); }