Fixes to support building in -std=c++20 mode.

* Structs with user-declared constructors are no longer considered
  aggregates, so remove the declarations when possible
* Types of both arguments to "==" must match to avoid "ambiguous
  function call" warning
* Various types of math involving enums are deprecated, so replace with
  constexprs where necessary
* ABSL_CONST_INIT must be used on definition as well as declaration
* volatile memory may no longer be read from and written to by the same
  operator, so replace e.g. "n++" with "n = n + 1"
* Replace an outdated check for no_unique_address support with
  __has_cpp_attribute
* std::result_of(f(x)) has been removed, replace with
  std::invoke_result(f, x)

Bug: chromium:1284275
Change-Id: I77b366ab1da7eb2c1e4c825b2714417c31ee5903
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261221
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Tomas Gunnarsson <tommi@google.com>
Reviewed-by: Tomas Gunnarsson <tommi@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#36786}
This commit is contained in:
Peter Kasting 2022-05-04 12:57:00 -07:00 committed by WebRTC LUCI CQ
parent 95897aea2f
commit 662d7f11d5
14 changed files with 48 additions and 52 deletions

View file

@ -80,8 +80,6 @@ const uint32_t kFmtIeeeFloatSubchunkSize =
// read audio samples. // read audio samples.
#pragma pack(2) #pragma pack(2)
struct WavHeaderPcm { struct WavHeaderPcm {
WavHeaderPcm(const WavHeaderPcm&) = default;
WavHeaderPcm& operator=(const WavHeaderPcm&) = default;
RiffHeader riff; RiffHeader riff;
FmtPcmSubchunk fmt; FmtPcmSubchunk fmt;
struct { struct {
@ -95,8 +93,6 @@ static_assert(sizeof(WavHeaderPcm) == kPcmWavHeaderSize,
// WAV implementation. // WAV implementation.
#pragma pack(2) #pragma pack(2)
struct WavHeaderIeeeFloat { struct WavHeaderIeeeFloat {
WavHeaderIeeeFloat(const WavHeaderIeeeFloat&) = default;
WavHeaderIeeeFloat& operator=(const WavHeaderIeeeFloat&) = default;
RiffHeader riff; RiffHeader riff;
FmtIeeeFloatSubchunk fmt; FmtIeeeFloatSubchunk fmt;
struct { struct {

View file

@ -17,7 +17,7 @@ InternalAPMConfig::InternalAPMConfig(InternalAPMConfig&&) = default;
InternalAPMConfig& InternalAPMConfig::operator=(const InternalAPMConfig&) = InternalAPMConfig& InternalAPMConfig::operator=(const InternalAPMConfig&) =
default; default;
bool InternalAPMConfig::operator==(const InternalAPMConfig& other) { bool InternalAPMConfig::operator==(const InternalAPMConfig& other) const {
return aec_enabled == other.aec_enabled && return aec_enabled == other.aec_enabled &&
aec_delay_agnostic_enabled == other.aec_delay_agnostic_enabled && aec_delay_agnostic_enabled == other.aec_delay_agnostic_enabled &&
aec_drift_compensation_enabled == aec_drift_compensation_enabled ==

View file

@ -31,7 +31,7 @@ struct InternalAPMConfig {
InternalAPMConfig& operator=(const InternalAPMConfig&); InternalAPMConfig& operator=(const InternalAPMConfig&);
InternalAPMConfig& operator=(InternalAPMConfig&&) = delete; InternalAPMConfig& operator=(InternalAPMConfig&&) = delete;
bool operator==(const InternalAPMConfig& other); bool operator==(const InternalAPMConfig& other) const;
bool aec_enabled = false; bool aec_enabled = false;
bool aec_delay_agnostic_enabled = false; bool aec_delay_agnostic_enabled = false;

View file

@ -21,8 +21,8 @@ namespace webrtc {
// Only bit `kBandFirst` through bit `kBandLast` are processed and // Only bit `kBandFirst` through bit `kBandLast` are processed and
// `kBandFirst` - `kBandLast` must be < 32. // `kBandFirst` - `kBandLast` must be < 32.
enum { kBandFirst = 12 }; constexpr int kBandFirst = 12;
enum { kBandLast = 43 }; constexpr int kBandLast = 43;
static __inline uint32_t SetBit(uint32_t in, int pos) { static __inline uint32_t SetBit(uint32_t in, int pos) {
uint32_t mask = (1 << pos); uint32_t mask = (1 << pos);

View file

@ -35,7 +35,7 @@ class VadAudioProc {
size_t length, size_t length,
AudioFeatures* audio_features); AudioFeatures* audio_features);
static const size_t kDftSize = 512; static constexpr size_t kDftSize = 512;
private: private:
void PitchAnalysis(double* pitch_gains, double* pitch_lags_hz, size_t length); void PitchAnalysis(double* pitch_gains, double* pitch_lags_hz, size_t length);
@ -51,28 +51,24 @@ class VadAudioProc {
// For every 30 ms we compute 3 spectral peak there for 3 LPC analysis. // For every 30 ms we compute 3 spectral peak there for 3 LPC analysis.
// LPC is computed over 15 ms of windowed audio. For every 10 ms sub-frame // LPC is computed over 15 ms of windowed audio. For every 10 ms sub-frame
// we need 5 ms of past signal to create the input of LPC analysis. // we need 5 ms of past signal to create the input of LPC analysis.
enum : size_t { static constexpr size_t kNumPastSignalSamples =
kNumPastSignalSamples = static_cast<size_t>(kSampleRateHz / 200) static_cast<size_t>(kSampleRateHz / 200);
};
// TODO(turajs): maybe defining this at a higher level (maybe enum) so that // TODO(turajs): maybe defining this at a higher level (maybe enum) so that
// all the code recognize it as "no-error." // all the code recognize it as "no-error."
enum : int { kNoError = 0 }; static constexpr int kNoError = 0;
enum : size_t { kNum10msSubframes = 3 }; static constexpr size_t kNum10msSubframes = 3;
enum : size_t { static constexpr size_t kNumSubframeSamples =
kNumSubframeSamples = static_cast<size_t>(kSampleRateHz / 100) static_cast<size_t>(kSampleRateHz / 100);
};
enum : size_t {
// Samples in 30 ms @ given sampling rate. // Samples in 30 ms @ given sampling rate.
kNumSamplesToProcess = kNum10msSubframes * kNumSubframeSamples static constexpr size_t kNumSamplesToProcess =
}; size_t{kNum10msSubframes} * kNumSubframeSamples;
enum : size_t { static constexpr size_t kBufferLength =
kBufferLength = kNumPastSignalSamples + kNumSamplesToProcess size_t{kNumPastSignalSamples} + kNumSamplesToProcess;
}; static constexpr size_t kIpLength = kDftSize >> 1;
enum : size_t { kIpLength = kDftSize >> 1 }; static constexpr size_t kWLength = kDftSize >> 1;
enum : size_t { kWLength = kDftSize >> 1 }; static constexpr size_t kLpcOrder = 16;
enum : size_t { kLpcOrder = 16 };
size_t ip_[kIpLength]; size_t ip_[kIpLength];
float w_fft_[kWLength]; float w_fft_[kWLength];

View file

@ -191,7 +191,7 @@ const char* LibaomAv1Decoder::ImplementationName() const {
} // namespace } // namespace
const bool kIsLibaomAv1DecoderSupported = true; ABSL_CONST_INIT const bool kIsLibaomAv1DecoderSupported = true;
std::unique_ptr<VideoDecoder> CreateLibaomAv1Decoder() { std::unique_ptr<VideoDecoder> CreateLibaomAv1Decoder() {
return std::make_unique<LibaomAv1Decoder>(); return std::make_unique<LibaomAv1Decoder>();

View file

@ -18,7 +18,7 @@
namespace webrtc { namespace webrtc {
#if defined(RTC_USE_LIBAOM_AV1_ENCODER) #if defined(RTC_USE_LIBAOM_AV1_ENCODER)
const bool kIsLibaomAv1EncoderSupported = true; ABSL_CONST_INIT const bool kIsLibaomAv1EncoderSupported = true;
std::unique_ptr<VideoEncoder> CreateLibaomAv1EncoderIfSupported() { std::unique_ptr<VideoEncoder> CreateLibaomAv1EncoderIfSupported() {
return CreateLibaomAv1Encoder(); return CreateLibaomAv1Encoder();
} }

View file

@ -26,10 +26,10 @@ namespace media_optimization {
// Number of time periods used for (max) window filter for packet loss // Number of time periods used for (max) window filter for packet loss
// TODO(marpan): set reasonable window size for filtered packet loss, // TODO(marpan): set reasonable window size for filtered packet loss,
// adjustment should be based on logged/real data of loss stats/correlation. // adjustment should be based on logged/real data of loss stats/correlation.
enum { kLossPrHistorySize = 10 }; constexpr int kLossPrHistorySize = 10;
// 1000 ms, total filter length is (kLossPrHistorySize * 1000) ms // 1000 ms, total filter length is (kLossPrHistorySize * 1000) ms
enum { kLossPrShortFilterWinMs = 1000 }; constexpr int kLossPrShortFilterWinMs = 1000;
// The type of filter used on the received packet loss reports. // The type of filter used on the received packet loss reports.
enum FilterPacketLossMode { enum FilterPacketLossMode {
@ -41,11 +41,11 @@ enum FilterPacketLossMode {
// Thresholds for hybrid NACK/FEC // Thresholds for hybrid NACK/FEC
// common to media optimization and the jitter buffer. // common to media optimization and the jitter buffer.
const int64_t kLowRttNackMs = 20; constexpr int64_t kLowRttNackMs = 20;
// If the RTT is higher than this an extra RTT wont be added to to the jitter // If the RTT is higher than this an extra RTT wont be added to to the jitter
// buffer delay. // buffer delay.
const int kMaxRttDelayThreshold = 500; constexpr int kMaxRttDelayThreshold = 500;
struct VCMProtectionParameters { struct VCMProtectionParameters {
VCMProtectionParameters(); VCMProtectionParameters();
@ -175,15 +175,15 @@ class VCMFecMethod : public VCMProtectionMethod {
int BitsPerFrame(const VCMProtectionParameters* parameters); int BitsPerFrame(const VCMProtectionParameters* parameters);
protected: protected:
enum { kUpperLimitFramesFec = 6 }; static constexpr int kUpperLimitFramesFec = 6;
// Thresholds values for the bytes/frame and round trip time, below which we // Thresholds values for the bytes/frame and round trip time, below which we
// may turn off FEC, depending on `_numLayers` and `_maxFramesFec`. // may turn off FEC, depending on `_numLayers` and `_maxFramesFec`.
// Max bytes/frame for VGA, corresponds to ~140k at 25fps. // Max bytes/frame for VGA, corresponds to ~140k at 25fps.
enum { kMaxBytesPerFrameForFec = 700 }; static constexpr int kMaxBytesPerFrameForFec = 700;
// Max bytes/frame for CIF and lower: corresponds to ~80k at 25fps. // Max bytes/frame for CIF and lower: corresponds to ~80k at 25fps.
enum { kMaxBytesPerFrameForFecLow = 400 }; static constexpr int kMaxBytesPerFrameForFecLow = 400;
// Max bytes/frame for frame size larger than VGA, ~200k at 25fps. // Max bytes/frame for frame size larger than VGA, ~200k at 25fps.
enum { kMaxBytesPerFrameForFecHigh = 1000 }; static constexpr int kMaxBytesPerFrameForFecHigh = 1000;
const RateControlSettings rate_control_settings_; const RateControlSettings rate_control_settings_;
}; };

View file

@ -25,7 +25,9 @@ RaceChecker::RaceChecker() {}
bool RaceChecker::Acquire() const { bool RaceChecker::Acquire() const {
const PlatformThreadRef current_thread = CurrentThreadRef(); const PlatformThreadRef current_thread = CurrentThreadRef();
// Set new accessing thread if this is a new use. // Set new accessing thread if this is a new use.
if (access_count_++ == 0) const int current_access_count = access_count_;
access_count_ = access_count_ + 1;
if (current_access_count == 0)
accessing_thread_ = current_thread; accessing_thread_ = current_thread;
// If this is being used concurrently this check will fail for the second // If this is being used concurrently this check will fail for the second
// thread entering since it won't set the thread. Recursive use of checked // thread entering since it won't set the thread. Recursive use of checked
@ -35,7 +37,7 @@ bool RaceChecker::Acquire() const {
} }
void RaceChecker::Release() const { void RaceChecker::Release() const {
--access_count_; access_count_ = access_count_ - 1;
} }
namespace internal { namespace internal {

View file

@ -24,8 +24,10 @@
// should add support for it starting from C++20. Among clang compilers, // should add support for it starting from C++20. Among clang compilers,
// clang-cl doesn't support it yet and support is unclear also when the target // clang-cl doesn't support it yet and support is unclear also when the target
// platform is iOS. // platform is iOS.
#if ((defined(__clang__) && !defined(_MSC_VER) && !defined(WEBRTC_IOS)) || \ #ifndef __has_cpp_attribute
__cplusplus > 201703L) #define __has_cpp_attribute(__x) 0
#endif
#if __has_cpp_attribute(no_unique_address)
// NOLINTNEXTLINE(whitespace/braces) // NOLINTNEXTLINE(whitespace/braces)
#define RTC_NO_UNIQUE_ADDRESS [[no_unique_address]] #define RTC_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else #else

View file

@ -75,8 +75,8 @@ class RepeatingTaskImpl final : public RepeatingTaskBase {
closure_(std::forward<Closure>(closure)) { closure_(std::forward<Closure>(closure)) {
static_assert( static_assert(
std::is_same<TimeDelta, std::is_same<TimeDelta,
typename std::result_of<decltype (&Closure::operator())( typename std::invoke_result<decltype(&Closure::operator()),
Closure)>::type>::value, Closure>::type>::value,
""); "");
} }

View file

@ -50,22 +50,22 @@ class UnitBase {
return value_ == MinusInfinityVal(); return value_ == MinusInfinityVal();
} }
constexpr bool operator==(const Unit_T& other) const { constexpr bool operator==(const UnitBase<Unit_T>& other) const {
return value_ == other.value_; return value_ == other.value_;
} }
constexpr bool operator!=(const Unit_T& other) const { constexpr bool operator!=(const UnitBase<Unit_T>& other) const {
return value_ != other.value_; return value_ != other.value_;
} }
constexpr bool operator<=(const Unit_T& other) const { constexpr bool operator<=(const UnitBase<Unit_T>& other) const {
return value_ <= other.value_; return value_ <= other.value_;
} }
constexpr bool operator>=(const Unit_T& other) const { constexpr bool operator>=(const UnitBase<Unit_T>& other) const {
return value_ >= other.value_; return value_ >= other.value_;
} }
constexpr bool operator>(const Unit_T& other) const { constexpr bool operator>(const UnitBase<Unit_T>& other) const {
return value_ > other.value_; return value_ > other.value_;
} }
constexpr bool operator<(const Unit_T& other) const { constexpr bool operator<(const UnitBase<Unit_T>& other) const {
return value_ < other.value_; return value_ < other.value_;
} }
constexpr Unit_T RoundTo(const Unit_T& resolution) const { constexpr Unit_T RoundTo(const Unit_T& resolution) const {

View file

@ -363,7 +363,7 @@ namespace webrtc {
namespace metrics { namespace metrics {
// Time that should have elapsed for stats that are gathered once per call. // Time that should have elapsed for stats that are gathered once per call.
enum { kMinRunTimeInSeconds = 10 }; constexpr int kMinRunTimeInSeconds = 10;
class Histogram; class Histogram;

View file

@ -63,9 +63,9 @@ namespace webrtc {
namespace test { namespace test {
#if defined(WEBRTC_WIN) #if defined(WEBRTC_WIN)
const absl::string_view kPathDelimiter = "\\"; ABSL_CONST_INIT const absl::string_view kPathDelimiter = "\\";
#else #else
const absl::string_view kPathDelimiter = "/"; ABSL_CONST_INIT const absl::string_view kPathDelimiter = "/";
#endif #endif
std::string DirName(absl::string_view path) { std::string DirName(absl::string_view path) {