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}
This commit is contained in:
parent
e9aa803359
commit
418a8c2c83
@ -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 << ", ";
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -80,7 +80,7 @@ void InitAckChunk::SerializeTo(std::vector<uint8_t>& 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
|
||||
|
||||
@ -81,8 +81,8 @@ void InitChunk::SerializeTo(std::vector<uint8_t>& 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
|
||||
|
||||
@ -139,7 +139,7 @@ std::optional<SctpPacket> SctpPacket::Parse(rtc::ArrayView<const uint8_t> data,
|
||||
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);
|
||||
|
||||
@ -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()));
|
||||
|
||||
@ -167,7 +167,8 @@ class SctpActor : public DcSctpSocketCallbacks {
|
||||
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;
|
||||
|
||||
@ -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<StreamParams>& 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<StreamParams>& 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<StreamParams>& 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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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 <typename T>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 @@ 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_
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user