diff --git a/PRESUBMIT.py b/PRESUBMIT.py index e533507ac0..048689e6ce 100755 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -432,7 +432,7 @@ def CheckNoStreamUsageIsAdded(input_api, output_api, include_re = input_api.re.compile(r'#include <(i|o|s)stream>') usage_re = input_api.re.compile(r'std::(w|i|o|io|wi|wo|wio)(string)*stream') no_presubmit_re = input_api.re.compile( - r' // no-presubmit-check TODO\(webrtc:8982\)') + r'// no-presubmit-check TODO\(webrtc:8982\)') for f in input_api.AffectedSourceFiles(input_api.FilterSourceFile): if f.LocalPath() == 'PRESUBMIT.py': continue diff --git a/api/rtcerror.cc b/api/rtcerror.cc index f9a31d0893..5a8ba033e8 100644 --- a/api/rtcerror.cc +++ b/api/rtcerror.cc @@ -94,8 +94,13 @@ void RTCError::set_message(std::string&& message) { } std::ostream& operator<<(std::ostream& stream, RTCErrorType error) { + return stream << ToString(error); +} + +// TODO(jonasolsson): Change to use absl::string_view when it's available. +std::string ToString(RTCErrorType error) { int index = static_cast(error); - return stream << kRTCErrorTypeNames[index]; + return std::string(kRTCErrorTypeNames[index]); } } // namespace webrtc diff --git a/api/rtcerror.h b/api/rtcerror.h index 962f46dd81..760bad8317 100644 --- a/api/rtcerror.h +++ b/api/rtcerror.h @@ -145,6 +145,8 @@ class RTCError { // Only intended to be used for logging/disagnostics. std::ostream& operator<<(std::ostream& stream, RTCErrorType error); +std::string ToString(RTCErrorType error); + // Helper macro that can be used by implementations to create an error with a // message and log it. |message| should be a string literal or movable // std::string. diff --git a/modules/congestion_controller/network_control/network_units.cc b/modules/congestion_controller/network_control/network_units.cc index 48eb8c48ac..806ad977de 100644 --- a/modules/congestion_controller/network_control/network_units.cc +++ b/modules/congestion_controller/network_control/network_units.cc @@ -50,5 +50,4 @@ DataSize operator*(const TimeDelta& duration, const DataRate& rate) { return rate * duration; } - } // namespace webrtc diff --git a/modules/video_coding/codecs/h264/include/h264_globals.h b/modules/video_coding/codecs/h264/include/h264_globals.h index cae270cc39..365dbca5d2 100644 --- a/modules/video_coding/codecs/h264/include/h264_globals.h +++ b/modules/video_coding/codecs/h264/include/h264_globals.h @@ -14,6 +14,8 @@ #ifndef MODULES_VIDEO_CODING_CODECS_H264_INCLUDE_H264_GLOBALS_H_ #define MODULES_VIDEO_CODING_CODECS_H264_INCLUDE_H264_GLOBALS_H_ +#include + namespace webrtc { // The packetization types that we support: single, aggregated, and fragmented. @@ -40,17 +42,20 @@ enum class H264PacketizationMode { // This function is declared inline because it is not clear which // .cc file it should belong to. // TODO(hta): Refactor. https://bugs.webrtc.org/6842 +// TODO(jonasolsson): Use absl::string_view instead when that's available. +inline std::string ToString(H264PacketizationMode mode) { + if (mode == H264PacketizationMode::NonInterleaved) { + return "NonInterleaved"; + } else if (mode == H264PacketizationMode::SingleNalUnit) { + return "SingleNalUnit"; + } + RTC_NOTREACHED(); + return ""; +} + inline std::ostream& operator<<(std::ostream& stream, H264PacketizationMode mode) { - switch (mode) { - case H264PacketizationMode::NonInterleaved: - stream << "NonInterleaved"; - break; - case H264PacketizationMode::SingleNalUnit: - stream << "SingleNalUnit"; - break; - } - return stream; + return stream << ToString(mode); } struct NaluInfo { diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index 3c1b9f0e44..92088b0cb1 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -334,6 +334,17 @@ rtc_source_set("stringutils") { ] } +rtc_source_set("audio_format_to_string") { + sources = [ + "strings/audio_format_to_string.cc", + "strings/audio_format_to_string.h", + ] + deps = [ + ":stringutils", + "../api/audio_codecs:audio_codecs_api", + ] +} + rtc_source_set("type_traits") { sources = [ "type_traits.h", diff --git a/rtc_base/ipaddress.cc b/rtc_base/ipaddress.cc index d441f075f8..3f7698acb3 100644 --- a/rtc_base/ipaddress.cc +++ b/rtc_base/ipaddress.cc @@ -217,12 +217,16 @@ const InterfaceAddress& InterfaceAddress::operator=( } std::ostream& operator<<(std::ostream& os, const InterfaceAddress& ip) { - os << static_cast(ip); + return os << ip.ToString(); +} - if (ip.family() == AF_INET6) - os << "|flags:0x" << std::hex << ip.ipv6_flags(); +std::string InterfaceAddress::ToString() const { + std::string result = IPAddress::ToString(); - return os; + if (family() == AF_INET6) + result += "|flags:0x" + rtc::ToHex(ipv6_flags()); + + return result; } static bool IPIsPrivateNetworkV4(const IPAddress& ip) { diff --git a/rtc_base/ipaddress.h b/rtc_base/ipaddress.h index 63543ba076..aa8bb1a320 100644 --- a/rtc_base/ipaddress.h +++ b/rtc_base/ipaddress.h @@ -144,6 +144,8 @@ class InterfaceAddress : public IPAddress { friend std::ostream& operator<<(std::ostream& os, const InterfaceAddress& addr); + std::string ToString() const; + private: int ipv6_flags_; }; diff --git a/rtc_base/strings/audio_format_to_string.cc b/rtc_base/strings/audio_format_to_string.cc new file mode 100644 index 0000000000..2d0b53b643 --- /dev/null +++ b/rtc_base/strings/audio_format_to_string.cc @@ -0,0 +1,52 @@ +/* + * Copyright 2018 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "rtc_base/strings/audio_format_to_string.h" + +#include "rtc_base/strings/string_builder.h" + +namespace rtc { + std::string ToString(const webrtc::SdpAudioFormat& saf) { + char sb_buf[1024]; + rtc::SimpleStringBuilder sb(sb_buf); + sb << "{name: " << saf.name; + sb << ", clockrate_hz: " << saf.clockrate_hz; + sb << ", num_channels: " << saf.num_channels; + sb << ", parameters: {"; + const char* sep = ""; + for (const auto& kv : saf.parameters) { + sb << sep << kv.first << ": " << kv.second; + sep = ", "; + } + sb << "}}"; + return sb.str(); + } + std::string ToString(const webrtc::AudioCodecInfo& aci) { + char sb_buf[1024]; + rtc::SimpleStringBuilder sb(sb_buf); + sb << "{sample_rate_hz: " << aci.sample_rate_hz; + sb << ", num_channels: " << aci.num_channels; + sb << ", default_bitrate_bps: " << aci.default_bitrate_bps; + sb << ", min_bitrate_bps: " << aci.min_bitrate_bps; + sb << ", max_bitrate_bps: " << aci.max_bitrate_bps; + sb << ", allow_comfort_noise: " << aci.allow_comfort_noise; + sb << ", supports_network_adaption: " << aci.supports_network_adaption; + sb << "}"; + return sb.str(); + } + std::string ToString(const webrtc::AudioCodecSpec& acs) { + char sb_buf[1024]; + rtc::SimpleStringBuilder sb(sb_buf); + sb << "{format: " << ToString(acs.format); + sb << ", info: " << ToString(acs.info); + sb << "}"; + return sb.str(); + } +} // namespace rtc diff --git a/rtc_base/strings/audio_format_to_string.h b/rtc_base/strings/audio_format_to_string.h new file mode 100644 index 0000000000..de0ce16e66 --- /dev/null +++ b/rtc_base/strings/audio_format_to_string.h @@ -0,0 +1,24 @@ +/* + * Copyright 2018 The WebRTC Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef RTC_BASE_STRINGS_AUDIO_FORMAT_TO_STRING_H_ +#define RTC_BASE_STRINGS_AUDIO_FORMAT_TO_STRING_H_ + +#include + +#include "api/audio_codecs/audio_format.h" + +namespace rtc { + std::string ToString(const webrtc::SdpAudioFormat& saf); + std::string ToString(const webrtc::AudioCodecInfo& saf); + std::string ToString(const webrtc::AudioCodecSpec& acs); +} // namespace rtc + +#endif // RTC_BASE_STRINGS_AUDIO_FORMAT_TO_STRING_H_ diff --git a/rtc_base/stringutils.cc b/rtc_base/stringutils.cc index 8671b52c5d..7664bb8c54 100644 --- a/rtc_base/stringutils.cc +++ b/rtc_base/stringutils.cc @@ -7,6 +7,8 @@ * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ +#include +#include #include "rtc_base/stringutils.h" #include "rtc_base/checks.h" @@ -130,4 +132,11 @@ std::string string_trim(const std::string& s) { return s.substr(first, last - first + 1); } +std::string ToHex(const int i) { + char buffer[50]; + snprintf(buffer, sizeof(buffer), "%x", i); + + return std::string(buffer); +} + } // namespace rtc diff --git a/rtc_base/stringutils.h b/rtc_base/stringutils.h index 686402c1f1..386ca9ede7 100644 --- a/rtc_base/stringutils.h +++ b/rtc_base/stringutils.h @@ -78,7 +78,7 @@ inline int _strnicmp(const char* s1, const char* s2, size_t n) { return strncasecmp(s1, s2, n); } -#endif // WEBRTC_POSIX +#endif // WEBRTC_POSIX /////////////////////////////////////////////////////////////////////////////// // Traits simplifies porting string functions to be CTYPE-agnostic @@ -91,9 +91,9 @@ const size_t SIZE_UNKNOWN = static_cast(-1); template struct Traits { // STL string type - //typedef XXX string; + // typedef XXX string; // Null-terminated string - //inline static const CTYPE* empty_str(); + // inline static const CTYPE* empty_str(); }; /////////////////////////////////////////////////////////////////////////////// @@ -119,7 +119,7 @@ const CTYPE* strchr(const CTYPE* str, const CTYPE* chs) { template const CTYPE* strchrn(const CTYPE* str, size_t slen, CTYPE ch) { - for (size_t i=0; i