diff --git a/media/base/fake_media_engine.h b/media/base/fake_media_engine.h index e4f7b6659f..bf8a0592a5 100644 --- a/media/base/fake_media_engine.h +++ b/media/base/fake_media_engine.h @@ -275,7 +275,7 @@ class RtpHelper : public Base { } void OnPacketSent(const rtc::SentPacket& sent_packet) override {} void OnReadyToSend(bool ready) override { ready_to_send_ = ready; } - void OnNetworkRouteChanged(const std::string& transport_name, + void OnNetworkRouteChanged(absl::string_view transport_name, const rtc::NetworkRoute& network_route) override { last_network_route_ = network_route; ++num_network_route_changes_; diff --git a/media/base/media_channel.h b/media/base/media_channel.h index e7684913e9..8f20616ebb 100644 --- a/media/base/media_channel.h +++ b/media/base/media_channel.h @@ -187,7 +187,7 @@ class MediaChannel { virtual void OnReadyToSend(bool ready) = 0; // Called when the network route used for sending packets changed. virtual void OnNetworkRouteChanged( - const std::string& transport_name, + absl::string_view transport_name, const rtc::NetworkRoute& network_route) = 0; // Creates a new outgoing media stream with SSRCs and CNAME as described // by sp. diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index 7f3cf92f83..cccb9fb397 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -1864,11 +1864,12 @@ void WebRtcVideoChannel::OnReadyToSend(bool ready) { } void WebRtcVideoChannel::OnNetworkRouteChanged( - const std::string& transport_name, + absl::string_view transport_name, const rtc::NetworkRoute& network_route) { RTC_DCHECK_RUN_ON(&network_thread_checker_); worker_thread_->PostTask(ToQueuedTask( - task_safety_, [this, name = transport_name, route = network_route] { + task_safety_, + [this, name = std::string(transport_name), route = network_route] { RTC_DCHECK_RUN_ON(&thread_checker_); webrtc::RtpTransportControllerSendInterface* transport = call_->GetTransportControllerSend(); diff --git a/media/engine/webrtc_video_engine.h b/media/engine/webrtc_video_engine.h index 90d824a55b..72ed7bf0b3 100644 --- a/media/engine/webrtc_video_engine.h +++ b/media/engine/webrtc_video_engine.h @@ -167,7 +167,7 @@ class WebRtcVideoChannel : public VideoMediaChannel, int64_t packet_time_us) override; void OnPacketSent(const rtc::SentPacket& sent_packet) override; void OnReadyToSend(bool ready) override; - void OnNetworkRouteChanged(const std::string& transport_name, + void OnNetworkRouteChanged(absl::string_view transport_name, const rtc::NetworkRoute& network_route) override; void SetInterface(NetworkInterface* iface) override; diff --git a/media/engine/webrtc_voice_engine.cc b/media/engine/webrtc_voice_engine.cc index 18399c3c6a..0a8d3da8c2 100644 --- a/media/engine/webrtc_voice_engine.cc +++ b/media/engine/webrtc_voice_engine.cc @@ -2284,14 +2284,15 @@ void WebRtcVoiceMediaChannel::OnPacketSent(const rtc::SentPacket& sent_packet) { } void WebRtcVoiceMediaChannel::OnNetworkRouteChanged( - const std::string& transport_name, + absl::string_view transport_name, const rtc::NetworkRoute& network_route) { RTC_DCHECK_RUN_ON(&network_thread_checker_); call_->OnAudioTransportOverheadChanged(network_route.packet_overhead); worker_thread_->PostTask(ToQueuedTask( - task_safety_, [this, name = transport_name, route = network_route] { + task_safety_, + [this, name = std::string(transport_name), route = network_route] { RTC_DCHECK_RUN_ON(worker_thread_); call_->GetTransportControllerSend()->OnNetworkRouteChanged(name, route); })); diff --git a/media/engine/webrtc_voice_engine.h b/media/engine/webrtc_voice_engine.h index a8eb61d318..846d59d7f5 100644 --- a/media/engine/webrtc_voice_engine.h +++ b/media/engine/webrtc_voice_engine.h @@ -209,7 +209,7 @@ class WebRtcVoiceMediaChannel final : public VoiceMediaChannel, void OnPacketReceived(rtc::CopyOnWriteBuffer packet, int64_t packet_time_us) override; void OnPacketSent(const rtc::SentPacket& sent_packet) override; - void OnNetworkRouteChanged(const std::string& transport_name, + void OnNetworkRouteChanged(absl::string_view transport_name, const rtc::NetworkRoute& network_route) override; void OnReadyToSend(bool ready) override; bool GetStats(VoiceMediaInfo* info, bool get_and_clear_legacy_stats) override; diff --git a/pc/channel.cc b/pc/channel.cc index ce61414fa9..745a380051 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -232,8 +232,6 @@ bool BaseChannel::SetRtpTransport(webrtc::RtpTransportInternal* rtp_transport) { rtp_transport_ = rtp_transport; if (rtp_transport_) { - transport_name_ = rtp_transport_->transport_name(); - if (!ConnectToRtpTransport()) { RTC_LOG(LS_ERROR) << "Failed to connect to the new RtpTransport for " << ToString() << "."; @@ -369,7 +367,7 @@ void BaseChannel::OnNetworkRouteChanged( // use the same transport name and MediaChannel::OnNetworkRouteChanged cannot // work correctly. Intentionally leave it broken to simplify the code and // encourage the users to stop using non-muxing RTCP. - media_channel_->OnNetworkRouteChanged(transport_name_, new_route); + media_channel_->OnNetworkRouteChanged(transport_name(), new_route); } void BaseChannel::SetFirstPacketReceivedCallback( diff --git a/pc/channel.h b/pc/channel.h index 701ac965f4..fa4a26e96f 100644 --- a/pc/channel.h +++ b/pc/channel.h @@ -124,12 +124,11 @@ class BaseChannel : public ChannelInterface, rtc::Thread* network_thread() const { return network_thread_; } const std::string& content_name() const override { return content_name_; } // TODO(deadbeef): This is redundant; remove this. - const std::string& transport_name() const override { + absl::string_view transport_name() const override { RTC_DCHECK_RUN_ON(network_thread()); if (rtp_transport_) return rtp_transport_->transport_name(); - // TODO(tommi): Delete this variable. - return transport_name_; + return ""; } // This function returns true if using SRTP (DTLS-based keying or SDES). @@ -304,14 +303,6 @@ class BaseChannel : public ChannelInterface, std::function on_first_packet_received_ RTC_GUARDED_BY(network_thread()); - // Won't be set when using raw packet transports. SDP-specific thing. - // TODO(bugs.webrtc.org/12230): Written on network thread, read on - // worker thread (at least). - // TODO(tommi): Remove this variable and instead use rtp_transport_ to - // return the transport name. This variable is currently required for - // "for_test" methods. - std::string transport_name_; - webrtc::RtpTransportInternal* rtp_transport_ RTC_GUARDED_BY(network_thread()) = nullptr; diff --git a/pc/channel_interface.h b/pc/channel_interface.h index 3b71f0f8b5..08cbff33ff 100644 --- a/pc/channel_interface.h +++ b/pc/channel_interface.h @@ -14,6 +14,7 @@ #include #include +#include "absl/strings/string_view.h" #include "api/jsep.h" #include "api/media_types.h" #include "media/base/media_channel.h" @@ -32,8 +33,11 @@ class ChannelInterface { virtual MediaChannel* media_channel() const = 0; + // Returns a string view for the transport name. Fetching the transport name + // must be done on the network thread only and note that the lifetime of + // the returned object should be assumed to only be the calling scope. // TODO(deadbeef): This is redundant; remove this. - virtual const std::string& transport_name() const = 0; + virtual absl::string_view transport_name() const = 0; virtual const std::string& content_name() const = 0; diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 94a00d2327..350233df5e 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -2666,8 +2666,8 @@ void PeerConnection::ReportTransportStats() { media_types_by_transport_name; for (const auto& transceiver : rtp_manager()->transceivers()->UnsafeList()) { if (transceiver->internal()->channel()) { - const std::string& transport_name = - transceiver->internal()->channel()->transport_name(); + std::string transport_name( + transceiver->internal()->channel()->transport_name()); media_types_by_transport_name[transport_name].insert( transceiver->media_type()); } @@ -2827,7 +2827,8 @@ bool PeerConnection::OnTransportChanged( if (dtls_transport) { signaling_thread()->PostTask(ToQueuedTask( signaling_thread_safety_.flag(), - [this, name = dtls_transport->internal()->transport_name()] { + [this, + name = std::string(dtls_transport->internal()->transport_name())] { RTC_DCHECK_RUN_ON(signaling_thread()); sctp_transport_name_s_ = std::move(name); })); diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index 025feb9298..0539559946 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -2148,7 +2148,7 @@ void RTCStatsCollector::PrepareTransceiverStatsInfosAndCallStats_s_w_n() { } stats.mid = channel->content_name(); - stats.transport_name = channel->transport_name(); + stats.transport_name = std::string(channel->transport_name()); if (media_type == cricket::MEDIA_TYPE_AUDIO) { auto* voice_channel = static_cast(channel); diff --git a/pc/stats_collector.cc b/pc/stats_collector.cc index dc172599da..81c5434bfd 100644 --- a/pc/stats_collector.cc +++ b/pc/stats_collector.cc @@ -887,7 +887,7 @@ StatsCollector::SessionStats StatsCollector::ExtractSessionInfo_n( cricket::ChannelInterface* channel = transceiver->internal()->channel(); if (channel) { stats.transport_names_by_mid[channel->content_name()] = - channel->transport_name(); + std::string(channel->transport_name()); } } diff --git a/pc/test/fake_peer_connection_for_stats.h b/pc/test/fake_peer_connection_for_stats.h index 4cdbd82162..5a9bc5d7c0 100644 --- a/pc/test/fake_peer_connection_for_stats.h +++ b/pc/test/fake_peer_connection_for_stats.h @@ -101,7 +101,7 @@ class VoiceChannelForTesting : public cricket::VoiceChannel { test_transport_name_(std::move(transport_name)) {} private: - const std::string& transport_name() const override { + absl::string_view transport_name() const override { return test_transport_name_; } @@ -130,7 +130,7 @@ class VideoChannelForTesting : public cricket::VideoChannel { test_transport_name_(std::move(transport_name)) {} private: - const std::string& transport_name() const override { + absl::string_view transport_name() const override { return test_transport_name_; } diff --git a/pc/test/mock_channel_interface.h b/pc/test/mock_channel_interface.h index 6faba5c8fc..c964b6ca71 100644 --- a/pc/test/mock_channel_interface.h +++ b/pc/test/mock_channel_interface.h @@ -26,7 +26,7 @@ class MockChannelInterface : public cricket::ChannelInterface { public: MOCK_METHOD(cricket::MediaType, media_type, (), (const, override)); MOCK_METHOD(MediaChannel*, media_channel, (), (const, override)); - MOCK_METHOD(const std::string&, transport_name, (), (const, override)); + MOCK_METHOD(absl::string_view, transport_name, (), (const, override)); MOCK_METHOD(const std::string&, content_name, (), (const, override)); MOCK_METHOD(void, Enable, (bool), (override)); MOCK_METHOD(void, diff --git a/pc/test/mock_voice_media_channel.h b/pc/test/mock_voice_media_channel.h index d6756b154e..8e694a16f7 100644 --- a/pc/test/mock_voice_media_channel.h +++ b/pc/test/mock_voice_media_channel.h @@ -40,7 +40,7 @@ class MockVoiceMediaChannel : public VoiceMediaChannel { MOCK_METHOD(void, OnReadyToSend, (bool ready), (override)); MOCK_METHOD(void, OnNetworkRouteChanged, - (const std::string& transport_name, + (absl::string_view transport_name, const rtc::NetworkRoute& network_route), (override)); MOCK_METHOD(bool, AddSendStream, (const StreamParams& sp), (override));