Move string_to_number.h to webrtc namespace
Bug: webrtc:42232595 Change-Id: I104cff12bf40509fb4554b98f7af16975263285a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/377520 Commit-Queue: Evan Shrubsole <eshr@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#43911}
This commit is contained in:
parent
a99a3ae72a
commit
f052c432fe
@ -43,7 +43,7 @@ std::optional<AudioEncoderL16::Config> AudioEncoderL16::SdpToConfig(
|
||||
config.num_channels = rtc::dchecked_cast<int>(format.num_channels);
|
||||
auto ptime_iter = format.parameters.find("ptime");
|
||||
if (ptime_iter != format.parameters.end()) {
|
||||
const auto ptime = rtc::StringToNumber<int>(ptime_iter->second);
|
||||
const auto ptime = StringToNumber<int>(ptime_iter->second);
|
||||
if (ptime && *ptime > 0) {
|
||||
config.frame_size_ms = rtc::SafeClamp(10 * (*ptime / 10), 10, 60);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ std::optional<AudioEncoderG711::Config> AudioEncoderG711::SdpToConfig(
|
||||
config.frame_size_ms = 20;
|
||||
auto ptime_iter = format.parameters.find("ptime");
|
||||
if (ptime_iter != format.parameters.end()) {
|
||||
const auto ptime = rtc::StringToNumber<int>(ptime_iter->second);
|
||||
const auto ptime = StringToNumber<int>(ptime_iter->second);
|
||||
if (ptime && *ptime > 0) {
|
||||
config.frame_size_ms = rtc::SafeClamp(10 * (*ptime / 10), 10, 60);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ std::optional<AudioEncoderG722Config> AudioEncoderG722::SdpToConfig(
|
||||
config.num_channels = rtc::checked_cast<int>(format.num_channels);
|
||||
auto ptime_iter = format.parameters.find("ptime");
|
||||
if (ptime_iter != format.parameters.end()) {
|
||||
auto ptime = rtc::StringToNumber<int>(ptime_iter->second);
|
||||
auto ptime = StringToNumber<int>(ptime_iter->second);
|
||||
if (ptime && *ptime > 0) {
|
||||
const int whole_packets = *ptime / 10;
|
||||
config.frame_size_ms = rtc::SafeClamp<int>(whole_packets * 10, 10, 60);
|
||||
|
||||
@ -35,7 +35,7 @@ absl::string_view AV1ProfileToString(AV1Profile profile) {
|
||||
}
|
||||
|
||||
std::optional<AV1Profile> StringToAV1Profile(absl::string_view str) {
|
||||
const std::optional<int> i = rtc::StringToNumber<int>(str);
|
||||
const std::optional<int> i = StringToNumber<int>(str);
|
||||
if (!i.has_value())
|
||||
return std::nullopt;
|
||||
|
||||
|
||||
@ -66,7 +66,7 @@ static constexpr LevelConstraint kLevelConstraints[] = {
|
||||
|
||||
// Annex A of https://www.itu.int/rec/T-REC-H.265 (08/21), section A.3.
|
||||
std::optional<H265Profile> StringToH265Profile(const std::string& profile) {
|
||||
std::optional<int> i = rtc::StringToNumber<int>(profile);
|
||||
std::optional<int> i = StringToNumber<int>(profile);
|
||||
if (!i.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -102,7 +102,7 @@ std::optional<H265Profile> StringToH265Profile(const std::string& profile) {
|
||||
// Annex A of https://www.itu.int/rec/T-REC-H.265 (08/21), section A.4,
|
||||
// tiers and levels.
|
||||
std::optional<H265Tier> StringToH265Tier(const std::string& tier) {
|
||||
std::optional<int> i = rtc::StringToNumber<int>(tier);
|
||||
std::optional<int> i = StringToNumber<int>(tier);
|
||||
if (!i.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
@ -118,7 +118,7 @@ std::optional<H265Tier> StringToH265Tier(const std::string& tier) {
|
||||
}
|
||||
|
||||
std::optional<H265Level> StringToH265Level(const std::string& level) {
|
||||
const std::optional<int> i = rtc::StringToNumber<int>(level);
|
||||
const std::optional<int> i = StringToNumber<int>(level);
|
||||
if (!i.has_value())
|
||||
return std::nullopt;
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ std::string VP9ProfileToString(VP9Profile profile) {
|
||||
}
|
||||
|
||||
std::optional<VP9Profile> StringToVP9Profile(const std::string& str) {
|
||||
const std::optional<int> i = rtc::StringToNumber<int>(str);
|
||||
const std::optional<int> i = StringToNumber<int>(str);
|
||||
if (!i.has_value())
|
||||
return std::nullopt;
|
||||
|
||||
|
||||
@ -64,8 +64,7 @@ std::optional<int> ParsePositiveNumberFromParams(
|
||||
if (max_frame_rate_it == params.end())
|
||||
return std::nullopt;
|
||||
|
||||
const std::optional<int> i =
|
||||
rtc::StringToNumber<int>(max_frame_rate_it->second);
|
||||
const std::optional<int> i = StringToNumber<int>(max_frame_rate_it->second);
|
||||
if (!i.has_value() || i.value() <= 0)
|
||||
return std::nullopt;
|
||||
return i;
|
||||
|
||||
@ -39,7 +39,7 @@ std::optional<std::vector<unsigned char>> GetFormatParameter(
|
||||
: (next_comma - pos);
|
||||
auto substring_with_number =
|
||||
comma_separated_list.substr(pos, distance_to_next_comma);
|
||||
auto conv = rtc::StringToNumber<int>(substring_with_number);
|
||||
auto conv = StringToNumber<int>(substring_with_number);
|
||||
if (!conv.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ std::optional<std::string> GetFormatParameter(const SdpAudioFormat& format,
|
||||
template <typename T>
|
||||
std::optional<T> GetFormatParameter(const SdpAudioFormat& format,
|
||||
absl::string_view param) {
|
||||
return rtc::StringToNumber<T>(GetFormatParameter(format, param).value_or(""));
|
||||
return StringToNumber<T>(GetFormatParameter(format, param).value_or(""));
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
@ -108,7 +108,7 @@ int CalculateBitrate(int max_playback_rate_hz,
|
||||
CalculateDefaultBitrate(max_playback_rate_hz, num_channels);
|
||||
|
||||
if (bitrate_param) {
|
||||
const auto bitrate = rtc::StringToNumber<int>(*bitrate_param);
|
||||
const auto bitrate = StringToNumber<int>(*bitrate_param);
|
||||
if (bitrate) {
|
||||
const int chosen_bitrate =
|
||||
std::max(AudioEncoderOpusConfig::kMinBitrateBps,
|
||||
|
||||
@ -94,7 +94,7 @@ int CalculateBitrate(int max_playback_rate_hz,
|
||||
CalculateDefaultBitrate(max_playback_rate_hz, num_channels);
|
||||
|
||||
if (bitrate_param) {
|
||||
const auto bitrate = rtc::StringToNumber<int>(*bitrate_param);
|
||||
const auto bitrate = StringToNumber<int>(*bitrate_param);
|
||||
if (bitrate) {
|
||||
const int chosen_bitrate =
|
||||
std::max(AudioEncoderOpusConfig::kMinBitrateBps,
|
||||
|
||||
@ -35,10 +35,10 @@ std::vector<Turn> LoadTiming(absl::string_view timing_filepath) {
|
||||
RTC_CHECK_LE(fields.size(), 4);
|
||||
int gain = 0;
|
||||
if (fields.size() == 4) {
|
||||
gain = rtc::StringToNumber<int>(fields[3]).value_or(0);
|
||||
gain = StringToNumber<int>(fields[3]).value_or(0);
|
||||
}
|
||||
return Turn(fields[0], fields[1],
|
||||
rtc::StringToNumber<int>(fields[2]).value_or(0), gain);
|
||||
StringToNumber<int>(fields[2]).value_or(0), gain);
|
||||
};
|
||||
|
||||
// Init.
|
||||
|
||||
@ -96,7 +96,7 @@ std::optional<int> ParsePort(absl::string_view in_str) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return rtc::StringToNumber<int>(in_str);
|
||||
return StringToNumber<int>(in_str);
|
||||
}
|
||||
|
||||
// This method parses IPv6 and IPv4 literal strings, along with hostnames in
|
||||
|
||||
@ -164,7 +164,7 @@ webrtc::RTCError ParseRidPayloadList(const std::string& payload_list,
|
||||
}
|
||||
|
||||
for (const std::string& payload_type : string_payloads) {
|
||||
std::optional<int> value = rtc::StringToNumber<int>(payload_type);
|
||||
std::optional<int> value = StringToNumber<int>(payload_type);
|
||||
if (!value.has_value()) {
|
||||
return ParseError("Invalid payload type: " + payload_type);
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ template <typename T,
|
||||
int>::type = 0>
|
||||
static bool FromString(absl::string_view s, T* t) {
|
||||
RTC_DCHECK(t);
|
||||
std::optional<T> result = StringToNumber<T>(s);
|
||||
std::optional<T> result = webrtc::StringToNumber<T>(s);
|
||||
|
||||
if (result)
|
||||
*t = *result;
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
#include "rtc_base/checks.h"
|
||||
|
||||
namespace rtc {
|
||||
namespace webrtc {
|
||||
namespace string_to_number_internal {
|
||||
|
||||
std::optional<signed_type> ParseSigned(absl::string_view str, int base) {
|
||||
@ -101,4 +101,4 @@ template std::optional<double> ParseFloatingPoint(absl::string_view str);
|
||||
template std::optional<long double> ParseFloatingPoint(absl::string_view str);
|
||||
|
||||
} // namespace string_to_number_internal
|
||||
} // namespace rtc
|
||||
} // namespace webrtc
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
|
||||
namespace rtc {
|
||||
namespace webrtc {
|
||||
|
||||
// This file declares a family of functions to parse integers from strings.
|
||||
// The standard C library functions either fail to indicate errors (atoi, etc.)
|
||||
@ -100,6 +100,12 @@ StringToNumber(absl::string_view str, int /* base */ = 10) {
|
||||
return string_to_number_internal::ParseFloatingPoint<T>(str);
|
||||
}
|
||||
|
||||
} // 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::StringToNumber;
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_STRING_TO_NUMBER_H_
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "test/gtest.h"
|
||||
|
||||
namespace rtc {
|
||||
namespace webrtc {
|
||||
|
||||
namespace {
|
||||
// clang-format off
|
||||
@ -135,4 +135,4 @@ TEST(StringToNumberTest, TestSpecificValues) {
|
||||
EXPECT_EQ(std::nullopt, StringToNumber<int8_t>("-256"));
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
} // namespace webrtc
|
||||
|
||||
@ -60,7 +60,7 @@ bool UniqueStringGenerator::AddKnownId(absl::string_view value) {
|
||||
// TODO(webrtc:13579): remove string copy here once absl::string_view version
|
||||
// of StringToNumber is available.
|
||||
std::optional<uint32_t> int_value =
|
||||
StringToNumber<uint32_t>(std::string(value));
|
||||
webrtc::StringToNumber<uint32_t>(std::string(value));
|
||||
// The underlying generator works for uint32_t values, so if the provided
|
||||
// value is not a uint32_t it will never be generated anyway.
|
||||
if (int_value.has_value()) {
|
||||
|
||||
@ -155,10 +155,10 @@ rtc::scoped_refptr<Video> OpenY4mFile(const std::string& file_name) {
|
||||
const std::string suffix = field.substr(1);
|
||||
switch (prefix) {
|
||||
case 'W':
|
||||
width = rtc::StringToNumber<int>(suffix);
|
||||
width = StringToNumber<int>(suffix);
|
||||
break;
|
||||
case 'H':
|
||||
height = rtc::StringToNumber<int>(suffix);
|
||||
height = StringToNumber<int>(suffix);
|
||||
break;
|
||||
case 'C':
|
||||
if (suffix != "420" && suffix != "420mpeg2") {
|
||||
@ -173,10 +173,9 @@ rtc::scoped_refptr<Video> OpenY4mFile(const std::string& file_name) {
|
||||
std::vector<std::string> fraction;
|
||||
rtc::tokenize(suffix, ':', &fraction);
|
||||
if (fraction.size() == 2) {
|
||||
const std::optional<int> numerator =
|
||||
rtc::StringToNumber<int>(fraction[0]);
|
||||
const std::optional<int> numerator = StringToNumber<int>(fraction[0]);
|
||||
const std::optional<int> denominator =
|
||||
rtc::StringToNumber<int>(fraction[1]);
|
||||
StringToNumber<int>(fraction[1]);
|
||||
if (numerator && denominator && *denominator != 0)
|
||||
fps = *numerator / static_cast<float>(*denominator);
|
||||
break;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user