Refactor RtpTransceiver::SetChannel and remove PushNewMediaChannel Remove the PushNewMediaChannel method and the set_media_channels parameter from RtpTransceiver::SetChannel. This removes test-only legacy (PlanB) behavior from the production code when channels are injected to a transceiver. Bug: webrtc:42222804 Change-Id: Ia9abca1e7657de68557a8280d5c148c8aeac698f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/462900 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Cr-Commit-Position: refs/heads/main@{#47387}
diff --git a/pc/rtp_transceiver.cc b/pc/rtp_transceiver.cc index 54e27bd..9c21128 100644 --- a/pc/rtp_transceiver.cc +++ b/pc/rtp_transceiver.cc
@@ -535,15 +535,13 @@ srtp_required, crypto_options, std::move(callbacks)); } }); - return SetChannel(std::move(new_channel), std::move(transport_lookup), - /*set_media_channels=*/false); + return SetChannel(std::move(new_channel), std::move(transport_lookup)); } RTCError RtpTransceiver::SetChannel( std::unique_ptr<ChannelInterface> channel, absl::AnyInvocable<RtpTransportInternal*(const std::string&) &&> - transport_lookup, - bool set_media_channels) { + transport_lookup) { RTC_DCHECK_RUN_ON(thread_); RTC_DCHECK(channel); RTC_DCHECK(transport_lookup); @@ -586,9 +584,6 @@ if (err.ok()) { transport_name_ = std::move(transport_name); - if (set_media_channels) { - PushNewMediaChannel(); - } } RTC_DCHECK_BLOCK_COUNT_NO_MORE_THAN(2); @@ -670,19 +665,6 @@ } } -void RtpTransceiver::PushNewMediaChannel() { - RTC_DCHECK_RUN_ON(thread_); - RTC_DCHECK(channel_); - if (senders_.empty() && receivers_.empty()) { - return; - } - context()->worker_thread()->BlockingCall([&, channel = channel_.get()]() { - RTC_DCHECK_RUN_ON(context()->worker_thread()); - SetMediaChannels(channel->media_send_channel(), - channel->media_receive_channel()); - }); -} - // RTC_RUN_ON(context()->worker_thread()); void RtpTransceiver::SetMediaChannels(MediaSendChannelInterface* send, MediaReceiveChannelInterface* receive) {
diff --git a/pc/rtp_transceiver.h b/pc/rtp_transceiver.h index 66aa443..16ae3e9 100644 --- a/pc/rtp_transceiver.h +++ b/pc/rtp_transceiver.h
@@ -190,8 +190,7 @@ RTCError SetChannel( std::unique_ptr<ChannelInterface> channel, absl::AnyInvocable<RtpTransportInternal*(const std::string&) &&> - transport_lookup, - bool set_media_channels = true); + transport_lookup); // Clear the association between the transceiver and the channel. void ClearChannel(); @@ -419,13 +418,11 @@ scoped_refptr<PendingTaskSafetyFlag> safety) RTC_RUN_ON(context()->network_thread()); void OnFirstPacketSent(); + // Stops the receivers synchronously and returns a task that stops the // senders. The returned task must be executed on the worker thread. [[nodiscard]] absl_nonnull absl::AnyInvocable<void() &&> GetStopSendingAndReceiving(); - // Tell the senders and receivers about possibly-new media channels - // in a newly created `channel_`. - void PushNewMediaChannel(); void SetMediaChannels(MediaSendChannelInterface* send, MediaReceiveChannelInterface* receive)
diff --git a/pc/test/fake_peer_connection_for_stats.h b/pc/test/fake_peer_connection_for_stats.h index bee4444..5c4ef44 100644 --- a/pc/test/fake_peer_connection_for_stats.h +++ b/pc/test/fake_peer_connection_for_stats.h
@@ -50,6 +50,7 @@ #include "p2p/base/transport_info.h" #include "p2p/test/fake_ice_transport.h" #include "pc/channel.h" +#include "pc/channel_interface.h" #include "pc/connection_context.h" #include "pc/data_channel_utils.h" #include "pc/dtls_transport.h" @@ -456,10 +457,9 @@ RTC_DCHECK(!transceiver->HasChannel()); RTC_DCHECK(transceiver->mid()); UpdateJsepTransportController(mid, transport_name); - transceiver->SetChannel( - std::move(voice_channel), [this](const std::string& mid) { - return transport_controller_->GetRtpTransport(mid); - }); + SetChannelAndPushMediaChannels(transceiver, std::move(voice_channel), + voice_media_send_channel_ptr, + voice_media_receive_channel_ptr); auto dtls_transport = transport_controller_->LookupDtlsTransportByMid(mid); transceiver->SetTransport(dtls_transport, transport_name); voice_media_send_channel_ptr->SetStats(initial_stats); @@ -495,10 +495,9 @@ RTC_DCHECK(!transceiver->HasChannel()); RTC_DCHECK(transceiver->mid()); UpdateJsepTransportController(mid, transport_name); - transceiver->SetChannel( - std::move(video_channel), [this](const std::string& mid) { - return transport_controller_->GetRtpTransport(mid); - }); + SetChannelAndPushMediaChannels(transceiver, std::move(video_channel), + video_media_send_channel_ptr, + video_media_receive_channel_ptr); auto dtls_transport = transport_controller_->LookupDtlsTransportByMid(mid); transceiver->SetTransport(dtls_transport, transport_name); video_media_send_channel_ptr->SetStats(initial_stats); @@ -662,6 +661,23 @@ } private: + void SetChannelAndPushMediaChannels( + RtpTransceiver* transceiver, + std::unique_ptr<ChannelInterface> channel, + MediaSendChannelInterface* send_channel, + MediaReceiveChannelInterface* receive_channel) { + transceiver->SetChannel(std::move(channel), [this](const std::string& mid) { + return transport_controller_->GetRtpTransport(mid); + }); + RTC_ALLOW_PLAN_B_DEPRECATION_BEGIN() + for (const auto& sender : transceiver->senders()) { + sender->internal()->SetMediaChannel(send_channel); + } + for (const auto& receiver : transceiver->receivers()) { + receiver->internal()->SetMediaChannel(receive_channel); + } + RTC_ALLOW_PLAN_B_DEPRECATION_END() + } TransportStats GetTransportStatsByName(const std::string& transport_name) { auto it = transport_stats_by_name_.find(transport_name); if (it != transport_stats_by_name_.end()) {