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 <eshr@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43915}
diff --git a/call/video_send_stream.cc b/call/video_send_stream.cc
index 20f6cef..5f8694c 100644
--- a/call/video_send_stream.cc
+++ b/call/video_send_stream.cc
@@ -74,7 +74,7 @@
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 82d38f8..d9f138263 100644
--- a/media/engine/webrtc_voice_engine.cc
+++ b/media/engine/webrtc_voice_engine.cc
@@ -2452,17 +2452,17 @@
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 7977faa..cd7c59f 100644
--- a/net/dcsctp/packet/chunk/init_ack_chunk.cc
+++ b/net/dcsctp/packet/chunk/init_ack_chunk.cc
@@ -80,7 +80,7 @@
}
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 dbb3382..c1662e0 100644
--- a/net/dcsctp/packet/chunk/init_chunk.cc
+++ b/net/dcsctp/packet/chunk/init_chunk.cc
@@ -81,8 +81,8 @@
}
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 f9c8812..bf7377c 100644
--- a/net/dcsctp/packet/sctp_packet.cc
+++ b/net/dcsctp/packet/sctp_packet.cc
@@ -139,7 +139,7 @@
BoundedByteWriter<kHeaderSize>(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 dcc68871..6580b7e 100644
--- a/net/dcsctp/socket/dcsctp_socket.cc
+++ b/net/dcsctp/socket/dcsctp_socket.cc
@@ -316,7 +316,7 @@
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 @@
}
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 @@
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 @@
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 @@
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 c6e06f9..0ac8282 100644
--- a/net/dcsctp/socket/dcsctp_socket_network_test.cc
+++ b/net/dcsctp/socket/dcsctp_socket_network_test.cc
@@ -167,7 +167,8 @@
double bitrate_mbps =
static_cast<double>(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 e533d86..e98eb83 100644
--- a/pc/channel.cc
+++ b/pc/channel.cc
@@ -170,7 +170,7 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
: "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 @@
// 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 @@
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 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 @@
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 @@
}
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 @@
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 @@
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 @@
}
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 @@
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 87095c1..e1c4d54 100644
--- a/pc/remote_audio_source.cc
+++ b/pc/remote_audio_source.cc
@@ -115,8 +115,7 @@
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 93453c3..cd2e17e 100644
--- a/rtc_base/string_encode_unittest.cc
+++ b/rtc_base/string_encode_unittest.cc
@@ -277,7 +277,7 @@
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 <typename T>
diff --git a/rtc_base/strings/string_format.cc b/rtc_base/strings/string_format.cc
index e69fb61..3566153 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 @@
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 13124d2..924968a 100644
--- a/rtc_base/strings/string_format.h
+++ b/rtc_base/strings/string_format.h
@@ -13,7 +13,7 @@
#include <string>
-namespace rtc {
+namespace webrtc {
#if defined(__GNUC__)
#define RTC_PRINTF_FORMAT(format_param, dots_param) \
@@ -26,6 +26,12 @@
// 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 5531001..3710de7 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 @@
EXPECT_EQ(formatted.compare("We have a substring."), 0);
}
-} // namespace rtc
+} // namespace webrtc