Minor ClearChannel() and SetChannel() simplifications

Bug: none
Change-Id: I3ee302429b1412143fecf3036766c89a5226f8e7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/324302
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43456}
This commit is contained in:
Tommi 2024-11-26 10:41:39 +01:00 committed by WebRTC LUCI CQ
parent 0a69daf38b
commit d257b4a054

View File

@ -311,8 +311,7 @@ void RtpTransceiver::SetChannel(
RTC_DCHECK_EQ(media_type(), channel->media_type());
signaling_thread_safety_ = PendingTaskSafetyFlag::Create();
std::unique_ptr<cricket::ChannelInterface> 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<cricket::ChannelInterface> 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;
});
}