Remove internal media/base/ stringstream usages
The %f -> %g changes are there to make the SimpleStringBuilder behave like stringstream/cout and friends. With %f it prints e.g. 2.2 as 2.200000. This change also makes it use scientific notation for numbers > 1000000, like the other streams. Bug: webrtc:8982 Change-Id: Id174b02c5776460607f48efc196a08673b67eeb0 Reviewed-on: https://webrtc-review.googlesource.com/67080 Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Fredrik Solenberg <solenberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23094}
This commit is contained in:
@ -11,12 +11,12 @@
|
||||
#include "media/base/codec.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
#include "media/base/h264_profile_level_id.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/stringencode.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
#include "rtc_base/stringutils.h"
|
||||
|
||||
namespace cricket {
|
||||
@ -183,10 +183,11 @@ bool AudioCodec::Matches(const AudioCodec& codec) const {
|
||||
}
|
||||
|
||||
std::string AudioCodec::ToString() const {
|
||||
std::ostringstream os;
|
||||
os << "AudioCodec[" << id << ":" << name << ":" << clockrate << ":" << bitrate
|
||||
char buf[256];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "AudioCodec[" << id << ":" << name << ":" << clockrate << ":" << bitrate
|
||||
<< ":" << channels << "]";
|
||||
return os.str();
|
||||
return sb.str();
|
||||
}
|
||||
|
||||
webrtc::RtpCodecParameters AudioCodec::ToCodecParameters() const {
|
||||
@ -197,9 +198,10 @@ webrtc::RtpCodecParameters AudioCodec::ToCodecParameters() const {
|
||||
}
|
||||
|
||||
std::string VideoCodec::ToString() const {
|
||||
std::ostringstream os;
|
||||
os << "VideoCodec[" << id << ":" << name << "]";
|
||||
return os.str();
|
||||
char buf[256];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "VideoCodec[" << id << ":" << name << "]";
|
||||
return sb.str();
|
||||
}
|
||||
|
||||
webrtc::RtpCodecParameters VideoCodec::ToCodecParameters() const {
|
||||
@ -331,9 +333,10 @@ DataCodec& DataCodec::operator=(const DataCodec& c) = default;
|
||||
DataCodec& DataCodec::operator=(DataCodec&& c) = default;
|
||||
|
||||
std::string DataCodec::ToString() const {
|
||||
std::ostringstream os;
|
||||
os << "DataCodec[" << id << ":" << name << "]";
|
||||
return os.str();
|
||||
char buf[256];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "DataCodec[" << id << ":" << name << "]";
|
||||
return sb.str();
|
||||
}
|
||||
|
||||
bool HasNack(const Codec& codec) {
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include "media/base/streamparams.h"
|
||||
|
||||
#include <list>
|
||||
#include <sstream>
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace cricket {
|
||||
namespace {
|
||||
@ -90,17 +90,18 @@ bool MediaStreams::RemoveDataStream(
|
||||
}
|
||||
|
||||
static std::string SsrcsToString(const std::vector<uint32_t>& ssrcs) {
|
||||
std::ostringstream ost;
|
||||
ost << "ssrcs:[";
|
||||
char buf[1024];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "ssrcs:[";
|
||||
for (std::vector<uint32_t>::const_iterator it = ssrcs.begin();
|
||||
it != ssrcs.end(); ++it) {
|
||||
if (it != ssrcs.begin()) {
|
||||
ost << ",";
|
||||
sb << ",";
|
||||
}
|
||||
ost << *it;
|
||||
sb << *it;
|
||||
}
|
||||
ost << "]";
|
||||
return ost.str();
|
||||
sb << "]";
|
||||
return sb.str();
|
||||
}
|
||||
|
||||
SsrcGroup::SsrcGroup(const std::string& usage,
|
||||
@ -118,12 +119,13 @@ bool SsrcGroup::has_semantics(const std::string& semantics_in) const {
|
||||
}
|
||||
|
||||
std::string SsrcGroup::ToString() const {
|
||||
std::ostringstream ost;
|
||||
ost << "{";
|
||||
ost << "semantics:" << semantics << ";";
|
||||
ost << SsrcsToString(ssrcs);
|
||||
ost << "}";
|
||||
return ost.str();
|
||||
char buf[1024];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "{";
|
||||
sb << "semantics:" << semantics << ";";
|
||||
sb << SsrcsToString(ssrcs);
|
||||
sb << "}";
|
||||
return sb.str();
|
||||
}
|
||||
|
||||
StreamParams::StreamParams() = default;
|
||||
@ -134,38 +136,39 @@ StreamParams& StreamParams::operator=(const StreamParams&) = default;
|
||||
StreamParams& StreamParams::operator=(StreamParams&&) = default;
|
||||
|
||||
std::string StreamParams::ToString() const {
|
||||
std::ostringstream ost;
|
||||
ost << "{";
|
||||
char buf[2 * 1024];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << "{";
|
||||
if (!groupid.empty()) {
|
||||
ost << "groupid:" << groupid << ";";
|
||||
sb << "groupid:" << groupid << ";";
|
||||
}
|
||||
if (!id.empty()) {
|
||||
ost << "id:" << id << ";";
|
||||
sb << "id:" << id << ";";
|
||||
}
|
||||
ost << SsrcsToString(ssrcs) << ";";
|
||||
ost << "ssrc_groups:";
|
||||
sb << SsrcsToString(ssrcs) << ";";
|
||||
sb << "ssrc_groups:";
|
||||
for (std::vector<SsrcGroup>::const_iterator it = ssrc_groups.begin();
|
||||
it != ssrc_groups.end(); ++it) {
|
||||
if (it != ssrc_groups.begin()) {
|
||||
ost << ",";
|
||||
sb << ",";
|
||||
}
|
||||
ost << it->ToString();
|
||||
sb << it->ToString();
|
||||
}
|
||||
ost << ";";
|
||||
sb << ";";
|
||||
if (!cname.empty()) {
|
||||
ost << "cname:" << cname << ";";
|
||||
sb << "cname:" << cname << ";";
|
||||
}
|
||||
ost << "stream_ids:";
|
||||
sb << "stream_ids:";
|
||||
for (std::vector<std::string>::const_iterator it = stream_ids_.begin();
|
||||
it != stream_ids_.end(); ++it) {
|
||||
if (it != stream_ids_.begin()) {
|
||||
ost << ",";
|
||||
sb << ",";
|
||||
}
|
||||
ost << *it;
|
||||
sb << *it;
|
||||
}
|
||||
ost << ";";
|
||||
ost << "}";
|
||||
return ost.str();
|
||||
sb << ";";
|
||||
sb << "}";
|
||||
return sb.str();
|
||||
}
|
||||
void StreamParams::GetPrimarySsrcs(std::vector<uint32_t>* ssrcs) const {
|
||||
const SsrcGroup* sim_group = get_ssrc_group(kSimSsrcGroupSemantics);
|
||||
|
@ -12,9 +12,9 @@
|
||||
|
||||
#include <limits.h> // For INT_MAX
|
||||
#include <math.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "rtc_base/arraysize.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
|
||||
namespace cricket {
|
||||
|
||||
@ -70,10 +70,11 @@ std::string VideoFormat::ToString() const {
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << fourcc_name << width << "x" << height << "x"
|
||||
char buf[256];
|
||||
rtc::SimpleStringBuilder sb(buf);
|
||||
sb << fourcc_name << width << "x" << height << "x"
|
||||
<< IntervalToFpsFloat(interval);
|
||||
return ss.str();
|
||||
return sb.str();
|
||||
}
|
||||
|
||||
} // namespace cricket
|
||||
|
@ -67,15 +67,15 @@ SimpleStringBuilder& SimpleStringBuilder::operator<<(
|
||||
}
|
||||
|
||||
SimpleStringBuilder& SimpleStringBuilder::operator<<(float f) {
|
||||
return AppendFormat("%f", f);
|
||||
return AppendFormat("%g", f);
|
||||
}
|
||||
|
||||
SimpleStringBuilder& SimpleStringBuilder::operator<<(double f) {
|
||||
return AppendFormat("%f", f);
|
||||
return AppendFormat("%g", f);
|
||||
}
|
||||
|
||||
SimpleStringBuilder& SimpleStringBuilder::operator<<(long double f) {
|
||||
return AppendFormat("%Lf", f);
|
||||
return AppendFormat("%Lg", f);
|
||||
}
|
||||
|
||||
SimpleStringBuilder& SimpleStringBuilder::AppendFormat(const char* fmt, ...) {
|
||||
|
@ -33,7 +33,7 @@ TEST(SimpleStringBuilder, NumbersAndChars) {
|
||||
SimpleStringBuilder sb(sb_buf);
|
||||
sb << 1 << ':' << 2.1 << ":" << 2.2f << ':' << 78187493520ll << ':'
|
||||
<< 78187493520ul;
|
||||
EXPECT_EQ(0, strcmp(sb.str(), "1:2.100000:2.200000:78187493520:78187493520"));
|
||||
EXPECT_EQ(0, strcmp(sb.str(), "1:2.1:2.2:78187493520:78187493520"));
|
||||
}
|
||||
|
||||
TEST(SimpleStringBuilder, Format) {
|
||||
|
Reference in New Issue
Block a user