From 418a8c2c83f7aeec139cd368f53c8962f184fdb6 Mon Sep 17 00:00:00 2001 From: Evan Shrubsole Date: Tue, 18 Feb 2025 13:10:10 +0000 Subject: [PATCH] Move string_format.h to webrtc namespace Bug: webrtc:42232595 Change-Id: I208257358150eeb97304946929649414af5eb2ca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/377542 Commit-Queue: Evan Shrubsole Reviewed-by: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#43915} --- call/video_send_stream.cc | 2 +- media/engine/webrtc_voice_engine.cc | 8 ++-- net/dcsctp/packet/chunk/init_ack_chunk.cc | 4 +- net/dcsctp/packet/chunk/init_chunk.cc | 4 +- net/dcsctp/packet/sctp_packet.cc | 2 +- net/dcsctp/socket/dcsctp_socket.cc | 10 ++-- .../socket/dcsctp_socket_network_test.cc | 3 +- pc/channel.cc | 48 +++++++++---------- pc/remote_audio_source.cc | 3 +- rtc_base/string_encode_unittest.cc | 2 +- rtc_base/strings/string_format.cc | 4 +- rtc_base/strings/string_format.h | 8 +++- rtc_base/strings/string_format_unittest.cc | 4 +- 13 files changed, 54 insertions(+), 48 deletions(-) diff --git a/call/video_send_stream.cc b/call/video_send_stream.cc index 20f6cefc3e..5f8694cfd1 100644 --- a/call/video_send_stream.cc +++ b/call/video_send_stream.cc @@ -74,7 +74,7 @@ std::string VideoSendStream::Stats::ToString(int64_t time_ms) const { char buf[2048]; rtc::SimpleStringBuilder ss(buf); ss << "VideoSendStream stats: " << time_ms << ", {"; - ss << "input_fps: " << rtc::StringFormat("%.1f", input_frame_rate) << ", "; + ss << "input_fps: " << StringFormat("%.1f", input_frame_rate) << ", "; ss << "encode_fps: " << encode_frame_rate << ", "; ss << "encode_ms: " << avg_encode_time_ms << ", "; ss << "encode_usage_perc: " << encode_usage_percent << ", "; diff --git a/media/engine/webrtc_voice_engine.cc b/media/engine/webrtc_voice_engine.cc index 82d38f8a1c..d9f138263e 100644 --- a/media/engine/webrtc_voice_engine.cc +++ b/media/engine/webrtc_voice_engine.cc @@ -2452,17 +2452,17 @@ void WebRtcVoiceReceiveChannel::OnDemuxerCriteriaUpdateComplete() {} bool WebRtcVoiceReceiveChannel::SetOutputVolume(uint32_t ssrc, double volume) { RTC_DCHECK_RUN_ON(worker_thread_); - RTC_LOG(LS_INFO) << rtc::StringFormat("WRVMC::%s({ssrc=%u}, {volume=%.2f})", - __func__, ssrc, volume); + RTC_LOG(LS_INFO) << webrtc::StringFormat( + "WRVMC::%s({ssrc=%u}, {volume=%.2f})", __func__, ssrc, volume); const auto it = recv_streams_.find(ssrc); if (it == recv_streams_.end()) { - RTC_LOG(LS_WARNING) << rtc::StringFormat( + RTC_LOG(LS_WARNING) << webrtc::StringFormat( "WRVMC::%s => (WARNING: no receive stream for SSRC %u)", __func__, ssrc); return false; } it->second->SetOutputVolume(volume); - RTC_LOG(LS_INFO) << rtc::StringFormat( + RTC_LOG(LS_INFO) << webrtc::StringFormat( "WRVMC::%s => (stream with SSRC %u now uses volume %.2f)", __func__, ssrc, volume); return true; diff --git a/net/dcsctp/packet/chunk/init_ack_chunk.cc b/net/dcsctp/packet/chunk/init_ack_chunk.cc index 7977faa326..cd7c59fb12 100644 --- a/net/dcsctp/packet/chunk/init_ack_chunk.cc +++ b/net/dcsctp/packet/chunk/init_ack_chunk.cc @@ -80,7 +80,7 @@ void InitAckChunk::SerializeTo(std::vector& out) const { } std::string InitAckChunk::ToString() const { - return rtc::StringFormat("INIT_ACK, initiate_tag=0x%0x, initial_tsn=%u", - *initiate_tag(), *initial_tsn()); + return webrtc::StringFormat("INIT_ACK, initiate_tag=0x%0x, initial_tsn=%u", + *initiate_tag(), *initial_tsn()); } } // namespace dcsctp diff --git a/net/dcsctp/packet/chunk/init_chunk.cc b/net/dcsctp/packet/chunk/init_chunk.cc index dbb3382cbf..c1662e07a5 100644 --- a/net/dcsctp/packet/chunk/init_chunk.cc +++ b/net/dcsctp/packet/chunk/init_chunk.cc @@ -81,8 +81,8 @@ void InitChunk::SerializeTo(std::vector& out) const { } std::string InitChunk::ToString() const { - return rtc::StringFormat("INIT, initiate_tag=0x%0x, initial_tsn=%u", - *initiate_tag(), *initial_tsn()); + return webrtc::StringFormat("INIT, initiate_tag=0x%0x, initial_tsn=%u", + *initiate_tag(), *initial_tsn()); } } // namespace dcsctp diff --git a/net/dcsctp/packet/sctp_packet.cc b/net/dcsctp/packet/sctp_packet.cc index f9c881242b..bf7377cb9a 100644 --- a/net/dcsctp/packet/sctp_packet.cc +++ b/net/dcsctp/packet/sctp_packet.cc @@ -139,7 +139,7 @@ std::optional SctpPacket::Parse(rtc::ArrayView data, BoundedByteWriter(data_copy).Store32<8>(0); uint32_t calculated_checksum = GenerateCrc32C(data_copy); if (calculated_checksum != common_header.checksum) { - RTC_DLOG(LS_WARNING) << rtc::StringFormat( + RTC_DLOG(LS_WARNING) << webrtc::StringFormat( "Invalid packet checksum, packet_checksum=0x%08x, " "calculated_checksum=0x%08x", common_header.checksum, calculated_checksum); diff --git a/net/dcsctp/socket/dcsctp_socket.cc b/net/dcsctp/socket/dcsctp_socket.cc index dcc68871d8..6580b7e414 100644 --- a/net/dcsctp/socket/dcsctp_socket.cc +++ b/net/dcsctp/socket/dcsctp_socket.cc @@ -316,7 +316,7 @@ void DcSctpSocket::Connect() { callbacks_.GetRandomInt(kMinVerificationTag, kMaxVerificationTag)); RTC_DLOG(LS_INFO) << log_prefix() - << rtc::StringFormat( + << webrtc::StringFormat( "Connecting. my_verification_tag=%08x, my_initial_tsn=%u", *connect_params_.verification_tag, *connect_params_.initial_tsn); SendInit(); @@ -715,7 +715,7 @@ bool DcSctpSocket::ValidatePacket(const SctpPacket& packet) { } callbacks_.OnError( ErrorKind::kParseFailed, - rtc::StringFormat( + webrtc::StringFormat( "Packet has invalid verification tag: %08x, expected %08x", *header.verification_tag, *connect_params_.verification_tag)); return false; @@ -760,7 +760,7 @@ bool DcSctpSocket::ValidatePacket(const SctpPacket& packet) { callbacks_.OnError( ErrorKind::kParseFailed, - rtc::StringFormat( + webrtc::StringFormat( "Packet has invalid verification tag: %08x, expected %08x", *header.verification_tag, *my_verification_tag)); return false; @@ -1215,7 +1215,7 @@ void DcSctpSocket::HandleInit(const CommonHeader& /* header */, RTC_DLOG(LS_VERBOSE) << log_prefix() - << rtc::StringFormat( + << webrtc::StringFormat( "Proceeding with connection. my_verification_tag=%08x, " "my_initial_tsn=%u, peer_verification_tag=%08x, " "peer_initial_tsn=%u", @@ -1327,7 +1327,7 @@ void DcSctpSocket::HandleCookieEcho( if (header.verification_tag != cookie->my_tag()) { callbacks_.OnError( ErrorKind::kParseFailed, - rtc::StringFormat( + webrtc::StringFormat( "Received CookieEcho with invalid verification tag: %08x, " "expected %08x", *header.verification_tag, *cookie->my_tag())); diff --git a/net/dcsctp/socket/dcsctp_socket_network_test.cc b/net/dcsctp/socket/dcsctp_socket_network_test.cc index c6e06f9b8e..0ac8282c96 100644 --- a/net/dcsctp/socket/dcsctp_socket_network_test.cc +++ b/net/dcsctp/socket/dcsctp_socket_network_test.cc @@ -167,7 +167,8 @@ class SctpActor : public DcSctpSocketCallbacks { double bitrate_mbps = static_cast(received_bytes_ * 8) / duration.ms() / 1000; RTC_LOG(LS_INFO) << log_prefix() - << rtc::StringFormat("Received %0.2f Mbps", bitrate_mbps); + << webrtc::StringFormat("Received %0.2f Mbps", + bitrate_mbps); received_bitrate_mbps_.push_back(bitrate_mbps); received_bytes_ = 0; diff --git a/pc/channel.cc b/pc/channel.cc index e533d863f4..e98eb83ff5 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -170,7 +170,7 @@ BaseChannel::~BaseChannel() { } std::string BaseChannel::ToString() const { - return StringFormat( + return webrtc::StringFormat( "{mid: %s, media_type: %s}", mid().c_str(), MediaTypeToString(media_send_channel_->media_type()).c_str()); } @@ -508,9 +508,9 @@ bool BaseChannel::MaybeUpdateDemuxerAndRtpExtensions_w( return true; if (!rtp_transport_->RegisterRtpDemuxerSink(demuxer_criteria_, this)) { - error_desc = - StringFormat("Failed to apply demuxer criteria for '%s': '%s'.", - mid().c_str(), demuxer_criteria_.ToString().c_str()); + error_desc = webrtc::StringFormat( + "Failed to apply demuxer criteria for '%s': '%s'.", mid().c_str(), + demuxer_criteria_.ToString().c_str()); return false; } return true; @@ -666,7 +666,7 @@ bool BaseChannel::UpdateLocalStreams_w(const std::vector& streams, continue; } if (!media_send_channel()->RemoveSendStream(old_stream.first_ssrc())) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to remove send stream with ssrc %u from m-section with " "mid='%s'.", old_stream.first_ssrc(), mid().c_str()); @@ -692,7 +692,7 @@ bool BaseChannel::UpdateLocalStreams_w(const std::vector& streams, RTC_DCHECK(new_stream.has_ssrcs() || new_stream.has_rids()); if (new_stream.has_ssrcs() && new_stream.has_rids()) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to add send stream: %u into m-section with mid='%s'. Stream " "has both SSRCs and RIDs.", new_stream.first_ssrc(), mid().c_str()); @@ -712,7 +712,7 @@ bool BaseChannel::UpdateLocalStreams_w(const std::vector& streams, RTC_LOG(LS_INFO) << "Add send stream ssrc: " << new_stream.ssrcs[0] << " into " << ToString(); } else { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to add send stream ssrc: %u into m-section with mid='%s'", new_stream.first_ssrc(), mid().c_str()); ret = false; @@ -754,7 +754,7 @@ bool BaseChannel::UpdateRemoteStreams_w(const MediaContentDescription* content, RTC_LOG(LS_INFO) << "Remove remote ssrc: " << old_stream.first_ssrc() << " from " << ToString() << "."; } else { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to remove remote stream with ssrc %u from m-section with " "mid='%s'.", old_stream.first_ssrc(), mid().c_str()); @@ -778,12 +778,12 @@ bool BaseChannel::UpdateRemoteStreams_w(const MediaContentDescription* content, : "unsignaled") << " to " << ToString(); } else { - error_desc = - StringFormat("Failed to add remote stream ssrc: %s to %s", - new_stream.has_ssrcs() - ? std::to_string(new_stream.first_ssrc()).c_str() - : "unsignaled", - ToString().c_str()); + error_desc = webrtc::StringFormat( + "Failed to add remote stream ssrc: %s to %s", + new_stream.has_ssrcs() + ? std::to_string(new_stream.first_ssrc()).c_str() + : "unsignaled", + ToString().c_str()); return false; } } @@ -800,8 +800,8 @@ bool BaseChannel::UpdateRemoteStreams_w(const MediaContentDescription* content, // Re-register the sink to update after changing the demuxer criteria. if (needs_re_registration && !RegisterRtpDemuxerSink_w()) { - error_desc = StringFormat("Failed to set up audio demuxing for mid='%s'.", - mid().c_str()); + error_desc = webrtc::StringFormat( + "Failed to set up audio demuxing for mid='%s'.", mid().c_str()); return false; } @@ -910,7 +910,7 @@ bool VoiceChannel::SetLocalContent_w(const MediaContentDescription* content, recv_params.mid = mid(); if (!media_receive_channel()->SetReceiverParameters(recv_params)) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to set local audio description recv parameters for m-section " "with mid='%s'.", mid().c_str()); @@ -966,7 +966,7 @@ bool VoiceChannel::SetRemoteContent_w(const MediaContentDescription* content, bool parameters_applied = media_send_channel()->SetSenderParameters(send_params); if (!parameters_applied) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to set remote audio description send parameters for m-section " "with mid='%s'.", mid().c_str()); @@ -1097,7 +1097,7 @@ bool VideoChannel::SetLocalContent_w(const MediaContentDescription* content, send_codec.packetization = std::nullopt; needs_send_params_update = true; } else if (!has_matching_packetization) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to set local answer due to incompatible codec " "packetization for pt='%d' specified in m-section with mid='%s'.", send_codec.id, mid().c_str()); @@ -1111,7 +1111,7 @@ bool VideoChannel::SetLocalContent_w(const MediaContentDescription* content, } if (!media_receive_channel()->SetReceiverParameters(recv_params)) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to set local video description recv parameters for m-section " "with mid='%s'.", mid().c_str()); @@ -1130,7 +1130,7 @@ bool VideoChannel::SetLocalContent_w(const MediaContentDescription* content, if (needs_send_params_update) { if (!media_send_channel()->SetSenderParameters(send_params)) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to set send parameters for m-section with mid='%s'.", mid().c_str()); return false; @@ -1211,7 +1211,7 @@ bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, recv_codec.packetization = std::nullopt; needs_recv_params_update = true; } else if (!has_matching_packetization) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to set remote answer due to incompatible codec " "packetization for pt='%d' specified in m-section with mid='%s'.", recv_codec.id, mid().c_str()); @@ -1225,7 +1225,7 @@ bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, } if (!media_send_channel()->SetSenderParameters(send_params)) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to set remote video description send parameters for m-section " "with mid='%s'.", mid().c_str()); @@ -1241,7 +1241,7 @@ bool VideoChannel::SetRemoteContent_w(const MediaContentDescription* content, if (needs_recv_params_update) { if (!media_receive_channel()->SetReceiverParameters(recv_params)) { - error_desc = StringFormat( + error_desc = webrtc::StringFormat( "Failed to set recv parameters for m-section with mid='%s'.", mid().c_str()); return false; diff --git a/pc/remote_audio_source.cc b/pc/remote_audio_source.cc index 87095c172d..e1c4d54791 100644 --- a/pc/remote_audio_source.cc +++ b/pc/remote_audio_source.cc @@ -115,8 +115,7 @@ bool RemoteAudioSource::remote() const { void RemoteAudioSource::SetVolume(double volume) { RTC_DCHECK_GE(volume, 0); RTC_DCHECK_LE(volume, 10); - RTC_LOG(LS_INFO) << rtc::StringFormat("RAS::%s({volume=%.2f})", __func__, - volume); + RTC_LOG(LS_INFO) << StringFormat("RAS::%s({volume=%.2f})", __func__, volume); for (auto* observer : audio_observers_) { observer->OnSetVolume(volume); } diff --git a/rtc_base/string_encode_unittest.cc b/rtc_base/string_encode_unittest.cc index 93453c3285..cd2e17e1a2 100644 --- a/rtc_base/string_encode_unittest.cc +++ b/rtc_base/string_encode_unittest.cc @@ -277,7 +277,7 @@ TEST(ToString, SanityCheck) { EXPECT_EQ(ToString((unsigned long long int)123), "123"); EXPECT_EQ(ToString(0.5), "0.5"); int i = 10; - EXPECT_EQ(StringFormat("%p", &i), ToString(&i)); + EXPECT_EQ(webrtc::StringFormat("%p", &i), ToString(&i)); } template diff --git a/rtc_base/strings/string_format.cc b/rtc_base/strings/string_format.cc index e69fb6193d..35661531ec 100644 --- a/rtc_base/strings/string_format.cc +++ b/rtc_base/strings/string_format.cc @@ -14,7 +14,7 @@ #include "rtc_base/checks.h" -namespace rtc { +namespace webrtc { namespace { @@ -38,4 +38,4 @@ std::string StringFormat(const char* fmt, ...) { return std::string(buffer); } -} // namespace rtc +} // namespace webrtc diff --git a/rtc_base/strings/string_format.h b/rtc_base/strings/string_format.h index 13124d2925..924968ac79 100644 --- a/rtc_base/strings/string_format.h +++ b/rtc_base/strings/string_format.h @@ -13,7 +13,7 @@ #include -namespace rtc { +namespace webrtc { #if defined(__GNUC__) #define RTC_PRINTF_FORMAT(format_param, dots_param) \ @@ -26,6 +26,12 @@ namespace rtc { // Based on base::StringPrintf() in Chrome but without its fancy dynamic memory // allocation for any size of the input buffer. std::string StringFormat(const char* fmt, ...) RTC_PRINTF_FORMAT(1, 2); +} // namespace webrtc + +// Re-export symbols from the webrtc namespace for backwards compatibility. +// TODO(bugs.webrtc.org/4222596): Remove once all references are updated. +namespace rtc { +using ::webrtc::StringFormat; } // namespace rtc #endif // RTC_BASE_STRINGS_STRING_FORMAT_H_ diff --git a/rtc_base/strings/string_format_unittest.cc b/rtc_base/strings/string_format_unittest.cc index 5531001979..3710de7708 100644 --- a/rtc_base/strings/string_format_unittest.cc +++ b/rtc_base/strings/string_format_unittest.cc @@ -17,7 +17,7 @@ #include "rtc_base/string_encode.h" #include "test/gtest.h" -namespace rtc { +namespace webrtc { TEST(StringFormatTest, Empty) { EXPECT_EQ("", StringFormat("%s", "")); @@ -49,4 +49,4 @@ TEST(StringFormatTest, FormatStringView) { EXPECT_EQ(formatted.compare("We have a substring."), 0); } -} // namespace rtc +} // namespace webrtc