From 74b57d4f28c645e6199e9b57c0b6a3afa3f0f57c Mon Sep 17 00:00:00 2001 From: Eric Rahm Date: Mon, 2 Sep 2019 12:40:00 +0000 Subject: [PATCH] Bug 1577932 - Remove using namespace std from dom/media r=padenot Differential Revision: https://phabricator.services.mozilla.com/D44289 --HG-- extra : moz-landing-system : lando --- dom/media/webaudio/PannerNode.cpp | 6 ++---- dom/media/webaudio/StereoPannerNode.cpp | 2 -- dom/media/webaudio/WebAudioUtils.h | 13 +++---------- .../webaudio/blink/DynamicsCompressorKernel.cpp | 16 +++++++--------- dom/media/webaudio/blink/HRTFDatabase.cpp | 2 -- dom/media/webaudio/blink/HRTFElevation.cpp | 5 ++--- dom/media/webaudio/blink/HRTFPanner.cpp | 5 ++--- 7 files changed, 16 insertions(+), 33 deletions(-) diff --git a/dom/media/webaudio/PannerNode.cpp b/dom/media/webaudio/PannerNode.cpp index 1c3150a17a44..15e6d9fef210 100644 --- a/dom/media/webaudio/PannerNode.cpp +++ b/dom/media/webaudio/PannerNode.cpp @@ -23,8 +23,6 @@ using WebCore::HRTFPanner; namespace mozilla { namespace dom { -using namespace std; - NS_IMPL_CYCLE_COLLECTION_CLASS(PannerNode) NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PannerNode, AudioNode) NS_IMPL_CYCLE_COLLECTION_UNLINK(mPositionX, mPositionY, mPositionZ, @@ -448,7 +446,7 @@ void PannerNodeEngine::EqualPowerPanningFunction(const AudioBlock& aInput, // The following algorithm is described in the spec. // Clamp azimuth in the [-90, 90] range. - azimuth = min(180.f, max(-180.f, azimuth)); + azimuth = std::min(180.f, std::max(-180.f, azimuth)); // Wrap around if (azimuth < -90.f) { @@ -548,7 +546,7 @@ void PannerNodeEngine::EqualPowerPanningFunction(const AudioBlock& aInput, // The following algorithm is described in the spec. // Clamp azimuth in the [-90, 90] range. - azimuth = min(180.f, max(-180.f, azimuth)); + azimuth = std::min(180.f, std::max(-180.f, azimuth)); // Wrap around if (azimuth < -90.f) { diff --git a/dom/media/webaudio/StereoPannerNode.cpp b/dom/media/webaudio/StereoPannerNode.cpp index 6f25cda3ae15..d92c0bb356f9 100644 --- a/dom/media/webaudio/StereoPannerNode.cpp +++ b/dom/media/webaudio/StereoPannerNode.cpp @@ -18,8 +18,6 @@ namespace mozilla { namespace dom { -using namespace std; - NS_IMPL_CYCLE_COLLECTION_INHERITED(StereoPannerNode, AudioNode, mPan) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StereoPannerNode) diff --git a/dom/media/webaudio/WebAudioUtils.h b/dom/media/webaudio/WebAudioUtils.h index cc0c65888534..8d55e008619b 100644 --- a/dom/media/webaudio/WebAudioUtils.h +++ b/dom/media/webaudio/WebAudioUtils.h @@ -38,14 +38,8 @@ const size_t MaxChannelCount = 32; const uint32_t MinSampleRate = 8000; const uint32_t MaxSampleRate = 192000; -inline bool FuzzyEqual(float v1, float v2) { - using namespace std; - return fabsf(v1 - v2) < 1e-7f; -} -inline bool FuzzyEqual(double v1, double v2) { - using namespace std; - return fabs(v1 - v2) < 1e-7; -} +inline bool FuzzyEqual(float v1, float v2) { return fabsf(v1 - v2) < 1e-7f; } +inline bool FuzzyEqual(double v1, double v2) { return fabs(v1 - v2) < 1e-7; } /** * Converts an AudioTimelineEvent's floating point time values to tick values @@ -160,8 +154,7 @@ inline bool IsTimeValid(double aTime) { */ template IntType TruncateFloatToInt(FloatType f) { - using namespace std; - + using std::numeric_limits; static_assert(mozilla::IsIntegral::value == true, "IntType must be an integral type"); static_assert(mozilla::IsFloatingPoint::value == true, diff --git a/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp b/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp index 00f20f7d14bc..9dae91136ec5 100644 --- a/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp +++ b/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp @@ -35,8 +35,6 @@ #include "mozilla/FloatingPoint.h" #include "WebAudioUtils.h" -using namespace std; - using namespace mozilla::dom; // for WebAudioUtils using mozilla::IsInfinite; using mozilla::IsNaN; @@ -242,7 +240,7 @@ void DynamicsCompressorKernel::process( WebAudioUtils::ConvertDecibelsToLinear(dbPostGain) * fullRangeMakeupGain; // Attack parameters. - attackTime = max(0.001f, attackTime); + attackTime = std::max(0.001f, attackTime); float attackFrames = attackTime * sampleRate; // Release parameters. @@ -337,8 +335,8 @@ void DynamicsCompressorKernel::process( // Contain within range: -12 -> 0 then scale to go from 0 -> 3 float x = compressionDiffDb; - x = max(-12.0f, x); - x = min(0.0f, x); + x = std::max(-12.0f, x); + x = std::min(0.0f, x); x = 0.25f * (x + 12); // Compute adaptive release curve using 4th order polynomial. @@ -366,7 +364,7 @@ void DynamicsCompressorKernel::process( m_maxAttackCompressionDiffDb < compressionDiffDb) m_maxAttackCompressionDiffDb = compressionDiffDb; - float effAttenDiffDb = max(0.5f, m_maxAttackCompressionDiffDb); + float effAttenDiffDb = std::max(0.5f, m_maxAttackCompressionDiffDb); float x = 0.25f / effAttenDiffDb; envelopeRate = 1 - powf(x, 1 / attackFrames); @@ -415,7 +413,7 @@ void DynamicsCompressorKernel::process( float attenuationDb = -WebAudioUtils::ConvertLinearToDecibels(attenuation, -1000.0f); - attenuationDb = max(2.0f, attenuationDb); + attenuationDb = std::max(2.0f, attenuationDb); float dbPerFrame = attenuationDb / satReleaseFrames; @@ -426,7 +424,7 @@ void DynamicsCompressorKernel::process( float rate = isRelease ? satReleaseRate : 1; detectorAverage += (attenuation - detectorAverage) * rate; - detectorAverage = min(1.0f, detectorAverage); + detectorAverage = std::min(1.0f, detectorAverage); // Fix gremlins. if (IsNaN(detectorAverage)) detectorAverage = 1; @@ -439,7 +437,7 @@ void DynamicsCompressorKernel::process( } else { // Release - exponentially increase gain to 1.0 compressorGain *= envelopeRate; - compressorGain = min(1.0f, compressorGain); + compressorGain = std::min(1.0f, compressorGain); } // Warp pre-compression gain to smooth out sharp exponential transition diff --git a/dom/media/webaudio/blink/HRTFDatabase.cpp b/dom/media/webaudio/blink/HRTFDatabase.cpp index 7c61afec1574..54be5ea9584e 100644 --- a/dom/media/webaudio/blink/HRTFDatabase.cpp +++ b/dom/media/webaudio/blink/HRTFDatabase.cpp @@ -30,8 +30,6 @@ #include "HRTFElevation.h" -using namespace std; - namespace WebCore { const int HRTFDatabase::MinElevation = -45; diff --git a/dom/media/webaudio/blink/HRTFElevation.cpp b/dom/media/webaudio/blink/HRTFElevation.cpp index 8da19507f134..94830407684c 100644 --- a/dom/media/webaudio/blink/HRTFElevation.cpp +++ b/dom/media/webaudio/blink/HRTFElevation.cpp @@ -34,7 +34,6 @@ #include "IRC_Composite_C_R0195-incl.cpp" -using namespace std; using namespace mozilla; namespace WebCore { @@ -76,7 +75,7 @@ size_t HRTFElevation::fftSizeForSampleRate(float sampleRate) { unsigned resampledLength = floorf(ResponseFrameSize * sampleRate / rawSampleRate); // Keep things semi-sane, with max FFT size of 1024. - unsigned size = min(resampledLength, 1023U); + unsigned size = std::min(resampledLength, 1023U); // Ensure a minimum of 2 * WEBAUDIO_BLOCK_SIZE (with the size++ below) for // FFTConvolver and set the 8 least significant bits for rounding up to // the next power of 2 below. @@ -242,7 +241,7 @@ nsReturnRef HRTFElevation::createBuiltin(int elevation, for (unsigned rawIndex = 0; rawIndex < NumberOfRawAzimuths; ++rawIndex) { // Don't let elevation exceed maximum for this azimuth. int maxElevation = maxElevations[rawIndex]; - int actualElevation = min(elevation, maxElevation); + int actualElevation = std::min(elevation, maxElevation); kernelListL[interpolatedIndex] = calculateKernelForAzimuthElevation( rawIndex * AzimuthSpacing, actualElevation, resampler, sampleRate); diff --git a/dom/media/webaudio/blink/HRTFPanner.cpp b/dom/media/webaudio/blink/HRTFPanner.cpp index c8730dddceaa..d9a4d4e38e5b 100644 --- a/dom/media/webaudio/blink/HRTFPanner.cpp +++ b/dom/media/webaudio/blink/HRTFPanner.cpp @@ -29,7 +29,6 @@ #include "HRTFDatabase.h" #include "AudioBlock.h" -using namespace std; using namespace mozilla; using dom::ChannelInterpretation; @@ -111,8 +110,8 @@ int HRTFPanner::calculateDesiredAzimuthIndexAndBlend(double azimuth, // We don't immediately start using this azimuth index, but instead approach // this index from the last index we rendered at. This minimizes the clicks // and graininess for moving sources which occur otherwise. - desiredAzimuthIndex = max(0, desiredAzimuthIndex); - desiredAzimuthIndex = min(numberOfAzimuths - 1, desiredAzimuthIndex); + desiredAzimuthIndex = std::max(0, desiredAzimuthIndex); + desiredAzimuthIndex = std::min(numberOfAzimuths - 1, desiredAzimuthIndex); return desiredAzimuthIndex; }