From 1fadb7fa2f6e5e8e5b5905dedf7597dba19dee3b Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Wed, 6 Jul 2022 09:04:40 -0500 Subject: Issue #1956 - Use preprocessor to work around strange template behavior with 32-bit MSVC2022. --- dom/media/webrtc/MediaTrackConstraints.cpp | 50 ++++++++++++++++++++++++++++++ dom/media/webrtc/MediaTrackConstraints.h | 10 ++++++ 2 files changed, 60 insertions(+) (limited to 'dom') diff --git a/dom/media/webrtc/MediaTrackConstraints.cpp b/dom/media/webrtc/MediaTrackConstraints.cpp index 08bb513955..63dab1492f 100644 --- a/dom/media/webrtc/MediaTrackConstraints.cpp +++ b/dom/media/webrtc/MediaTrackConstraints.cpp @@ -34,6 +34,56 @@ NormalizedConstraintSet::Range::SetFrom(const ConstrainRange& aOther) } } +// FIXME(Issue #1956): 32-bit MSVC 2022 does not like these functions being +// defined here. The 64-bit version accepts my workaround for the 32-bit +// version as valid code, but every other compiler dislikes them being defined +// elsewhere. + +#if _MSC_VER <= 1900 || !defined(_MSC_VER) +// The Range code works surprisingly well for bool, except when averaging ideals. +template<> +bool +NormalizedConstraintSet::Range::Merge(const Range& aOther) { + if (!Intersects(aOther)) { + return false; + } + Intersect(aOther); + + // To avoid "unsafe use of type 'bool'", we keep counter in mMergeDenominator + uint32_t counter = mMergeDenominator >> 16; + uint32_t denominator = mMergeDenominator & 0xffff; + + if (aOther.mIdeal.isSome()) { + if (mIdeal.isNothing()) { + mIdeal.emplace(aOther.Get(false)); + counter = aOther.Get(false); + denominator = 1; + } else { + if (!denominator) { + counter = Get(false); + denominator = 1; + } + counter += aOther.Get(false); + denominator++; + } + } + mMergeDenominator = ((counter & 0xffff) << 16) + (denominator & 0xffff); + return true; +} + +template<> +void +NormalizedConstraintSet::Range::FinalizeMerge() +{ + if (mMergeDenominator) { + uint32_t counter = mMergeDenominator >> 16; + uint32_t denominator = mMergeDenominator & 0xffff; + + *mIdeal = !!(counter / denominator); + mMergeDenominator = 0; + } +} +#endif NormalizedConstraintSet::LongRange::LongRange( LongPtrType aMemberPtr, diff --git a/dom/media/webrtc/MediaTrackConstraints.h b/dom/media/webrtc/MediaTrackConstraints.h index 693c905d5f..0746fc245f 100644 --- a/dom/media/webrtc/MediaTrackConstraints.h +++ b/dom/media/webrtc/MediaTrackConstraints.h @@ -261,6 +261,11 @@ public: aOther.mMozAutoGainControl, advanced, aList) {} }; +// FIXME (Issue #1956): 32-bit MSVC 2022 needed this code to be moved here, +// and the 64-bit version seems fine with it as well. But other compilers +// are not. + +#if _MSC_VER > 1900 // The Range code works surprisingly well for bool, except when averaging ideals. template<> bool @@ -304,7 +309,12 @@ NormalizedConstraintSet::Range::FinalizeMerge() mMergeDenominator = 0; } } +#endif +#if _MSC_VER <= 1900 || !defined(_MSC_VER) +template<> bool NormalizedConstraintSet::Range::Merge(const Range& aOther); +template<> void NormalizedConstraintSet::Range::FinalizeMerge(); +#endif // Used instead of MediaTrackConstraints in lower-level code. struct NormalizedConstraints : public NormalizedConstraintSet -- cgit v1.2.3