diff --git a/dom/media/AudioDriftCorrection.h b/dom/media/AudioDriftCorrection.h index eead81beaea3..a7df8beb1f40 100644 --- a/dom/media/AudioDriftCorrection.h +++ b/dom/media/AudioDriftCorrection.h @@ -38,8 +38,8 @@ class ClockDrift final { /** * Provide the nominal source and the target sample rate. */ - ClockDrift(int32_t aSourceRate, int32_t aTargetRate, - int32_t aDesiredBuffering) + ClockDrift(uint32_t aSourceRate, uint32_t aTargetRate, + uint32_t aDesiredBuffering) : mSourceRate(aSourceRate), mTargetRate(aTargetRate), mDesiredBuffering(aDesiredBuffering) {} @@ -60,8 +60,8 @@ class ClockDrift final { * In addition to that, the correction is clamped to 10% to avoid sound * distortion so the result will be in [0.9, 1.1]. */ - void UpdateClock(int aSourceFrames, int aTargetFrames, int aBufferedFrames, - int aRemainingFrames) { + void UpdateClock(uint32_t aSourceFrames, uint32_t aTargetFrames, + uint32_t aBufferedFrames, uint32_t aRemainingFrames) { if (mSourceClock >= mSourceRate / 10 || mTargetClock >= mTargetRate / 10) { // Only update the correction if 100ms has passed since last update. if (aBufferedFrames < mDesiredBuffering * 4 / 10 /*40%*/ || @@ -86,19 +86,19 @@ class ClockDrift final { * 1 - aCalculationWeight. This gives some inertia to the speed at which the * correction changes, for smoother changes. */ - void CalculateCorrection(float aCalculationWeight, int aBufferedFrames, - int aRemainingFrames) { + void CalculateCorrection(float aCalculationWeight, uint32_t aBufferedFrames, + uint32_t aRemainingFrames) { // We want to maintain the desired buffer - int32_t bufferedFramesDiff = aBufferedFrames - mDesiredBuffering; - int32_t resampledSourceClock = - std::max(1, mSourceClock + bufferedFramesDiff); + uint32_t bufferedFramesDiff = aBufferedFrames - mDesiredBuffering; + uint32_t resampledSourceClock = + std::max(1u, mSourceClock + bufferedFramesDiff); if (mTargetRate != mSourceRate) { resampledSourceClock *= static_cast(mTargetRate) / mSourceRate; } MOZ_LOG(gMediaTrackGraphLog, LogLevel::Verbose, ("ClockDrift %p Calculated correction %.3f (with weight: %.1f -> " - "%.3f) (buffer: %d, desired: %d, remaining: %d)", + "%.3f) (buffer: %u, desired: %u, remaining: %u)", this, static_cast(mTargetClock) / resampledSourceClock, aCalculationWeight, (1 - aCalculationWeight) * mCorrection + @@ -117,16 +117,16 @@ class ClockDrift final { } public: - const int32_t mSourceRate; - const int32_t mTargetRate; - const int32_t mAdjustmentIntervalMs = 1000; - const int32_t mDesiredBuffering; + const uint32_t mSourceRate; + const uint32_t mTargetRate; + const uint32_t mAdjustmentIntervalMs = 1000; + const uint32_t mDesiredBuffering; private: float mCorrection = 1.0; - int32_t mSourceClock = 0; - int32_t mTargetClock = 0; + uint32_t mSourceClock = 0; + uint32_t mTargetClock = 0; }; /** @@ -150,7 +150,7 @@ class ClockDrift final { */ class AudioDriftCorrection final { public: - AudioDriftCorrection(int32_t aSourceRate, int32_t aTargetRate) + AudioDriftCorrection(uint32_t aSourceRate, uint32_t aTargetRate) : mDesiredBuffering( std::max(5, Preferences::GetInt("media.clockdrift.buffering", 50)) * aSourceRate / 1000), @@ -168,7 +168,7 @@ class AudioDriftCorrection final { * AudioSegment will be returned. Not thread-safe. */ AudioSegment RequestFrames(const AudioSegment& aInput, - int32_t aOutputFrames) { + uint32_t aOutputFrames) { // Very important to go first since the Dynamic will get the sample format // from the chunk. if (aInput.GetDuration()) { @@ -193,8 +193,8 @@ class AudioDriftCorrection final { // Only accessible from the same thread that is driving RequestFrames(). uint32_t CurrentBuffering() const { return mResampler.InputDuration(); } - const int32_t mDesiredBuffering; - const int32_t mTargetRate; + const uint32_t mDesiredBuffering; + const uint32_t mTargetRate; private: ClockDrift mClockDrift; diff --git a/dom/media/AudioRingBuffer.cpp b/dom/media/AudioRingBuffer.cpp index ff99966c1884..917d4880a135 100644 --- a/dom/media/AudioRingBuffer.cpp +++ b/dom/media/AudioRingBuffer.cpp @@ -35,7 +35,7 @@ class RingBuffer final { /** * Write `aSamples` number of zeros in the buffer. */ - int WriteSilence(int aSamples) { + uint32_t WriteSilence(uint32_t aSamples) { MOZ_ASSERT(aSamples); return Write(Span(), aSamples); } @@ -43,7 +43,7 @@ class RingBuffer final { /** * Copy `aBuffer` to the RingBuffer. */ - int Write(const Span& aBuffer) { + uint32_t Write(const Span& aBuffer) { MOZ_ASSERT(!aBuffer.IsEmpty()); return Write(aBuffer, aBuffer.Length()); } @@ -53,7 +53,7 @@ class RingBuffer final { * Copy `aSamples` number of elements from `aBuffer` to the RingBuffer. If * `aBuffer` is empty append `aSamples` of zeros. */ - int Write(const Span& aBuffer, int aSamples) { + uint32_t Write(const Span& aBuffer, uint32_t aSamples) { MOZ_ASSERT(aSamples > 0 && aBuffer.Length() <= static_cast(aSamples)); @@ -61,9 +61,9 @@ class RingBuffer final { return 0; } - int toWrite = std::min(AvailableWrite(), aSamples); - int part1 = std::min(Capacity() - mWriteIndex, toWrite); - int part2 = toWrite - part1; + uint32_t toWrite = std::min(AvailableWrite(), aSamples); + uint32_t part1 = std::min(Capacity() - mWriteIndex, toWrite); + uint32_t part2 = toWrite - part1; Span part1Buffer = mStorage.Subspan(mWriteIndex, part1); Span part2Buffer = mStorage.To(part2); @@ -90,20 +90,21 @@ class RingBuffer final { * Copy `aSamples` number of elements from `aBuffer` to the RingBuffer. The * `aBuffer` does not change. */ - int Write(const RingBuffer& aBuffer, int aSamples) { + uint32_t Write(const RingBuffer& aBuffer, uint32_t aSamples) { MOZ_ASSERT(aSamples); if (IsFull()) { return 0; } - int toWriteThis = std::min(AvailableWrite(), aSamples); - int toReadThat = std::min(aBuffer.AvailableRead(), toWriteThis); - int part1 = std::min(aBuffer.Capacity() - aBuffer.mReadIndex, toReadThat); - int part2 = toReadThat - part1; + uint32_t toWriteThis = std::min(AvailableWrite(), aSamples); + uint32_t toReadThat = std::min(aBuffer.AvailableRead(), toWriteThis); + uint32_t part1 = + std::min(aBuffer.Capacity() - aBuffer.mReadIndex, toReadThat); + uint32_t part2 = toReadThat - part1; Span part1Buffer = aBuffer.mStorage.Subspan(aBuffer.mReadIndex, part1); - DebugOnly ret = Write(part1Buffer); + DebugOnly ret = Write(part1Buffer); MOZ_ASSERT(ret == part1); if (part2) { Span part2Buffer = aBuffer.mStorage.To(part2); @@ -117,17 +118,17 @@ class RingBuffer final { /** * Copy `aBuffer.Length()` number of elements from RingBuffer to `aBuffer`. */ - int Read(const Span& aBuffer) { + uint32_t Read(const Span& aBuffer) { MOZ_ASSERT(!aBuffer.IsEmpty()); - MOZ_ASSERT(aBuffer.size() <= std::numeric_limits::max()); + MOZ_ASSERT(aBuffer.size() <= std::numeric_limits::max()); if (IsEmpty()) { return 0; } - int toRead = std::min(AvailableRead(), static_cast(aBuffer.Length())); - int part1 = std::min(Capacity() - mReadIndex, toRead); - int part2 = toRead - part1; + uint32_t toRead = std::min(AvailableRead(), aBuffer.Length()); + uint32_t part1 = std::min(Capacity() - mReadIndex, toRead); + uint32_t part2 = toRead - part1; Span part1Buffer = mStorage.Subspan(mReadIndex, part1); Span part2Buffer = mStorage.To(part2); @@ -164,16 +165,17 @@ class RingBuffer final { * the `aCallable`. In the body of the `aCallable` those buffers can be used * directly without any copy or intermediate steps. */ - int ReadNoCopy(std::function&)>&& aCallable) { + uint32_t ReadNoCopy( + std::function&)>&& aCallable) { if (IsEmpty()) { return 0; } - int part1 = std::min(Capacity() - mReadIndex, AvailableRead()); - int part2 = AvailableRead() - part1; + uint32_t part1 = std::min(Capacity() - mReadIndex, AvailableRead()); + uint32_t part2 = AvailableRead() - part1; Span part1Buffer = mStorage.Subspan(mReadIndex, part1); - int toRead = aCallable(part1Buffer); + uint32_t toRead = aCallable(part1Buffer); MOZ_ASSERT(toRead <= part1); if (toRead == part1 && part2) { @@ -190,14 +192,14 @@ class RingBuffer final { /** * Remove the next `aSamples` number of samples from the ring buffer. */ - int Discard(int aSamples) { + uint32_t Discard(uint32_t aSamples) { MOZ_ASSERT(aSamples); if (IsEmpty()) { return 0; } - int toDiscard = std::min(AvailableRead(), aSamples); + uint32_t toDiscard = std::min(AvailableRead(), aSamples); mReadIndex = NextIndex(mReadIndex, toDiscard); return toDiscard; @@ -206,12 +208,12 @@ class RingBuffer final { /** * Empty the ring buffer. */ - int Clear() { + uint32_t Clear() { if (IsEmpty()) { return 0; } - int toDiscard = AvailableRead(); + uint32_t toDiscard = AvailableRead(); mReadIndex = NextIndex(mReadIndex, toDiscard); return toDiscard; @@ -232,10 +234,10 @@ class RingBuffer final { /** * The number of samples available for writing. */ - int AvailableWrite() const { + uint32_t AvailableWrite() const { /* We subtract one element here to always keep at least one sample * free in the buffer, to distinguish between full and empty array. */ - int rv = mReadIndex - mWriteIndex - 1; + uint32_t rv = mReadIndex - mWriteIndex - 1; if (mWriteIndex >= mReadIndex) { rv += Capacity(); } @@ -245,7 +247,7 @@ class RingBuffer final { /** * The number of samples available for reading. */ - int AvailableRead() const { + uint32_t AvailableRead() const { if (mWriteIndex >= mReadIndex) { return mWriteIndex - mReadIndex; } @@ -253,14 +255,13 @@ class RingBuffer final { } private: - int NextIndex(int aIndex, int aStep) const { - MOZ_ASSERT(aStep >= 0); + uint32_t NextIndex(uint32_t aIndex, uint32_t aStep) const { MOZ_ASSERT(aStep < Capacity()); MOZ_ASSERT(aIndex < Capacity()); return (aIndex + aStep) % Capacity(); } - int32_t Capacity() const { return mStorage.Length(); } + uint32_t Capacity() const { return mStorage.Length(); } Span ConvertToSpan(const AlignedByteBuffer& aOther) const { MOZ_ASSERT(aOther.Length() >= sizeof(T)); @@ -274,8 +275,8 @@ class RingBuffer final { } private: - int mReadIndex = 0; - int mWriteIndex = 0; + uint32_t mReadIndex = 0; + uint32_t mWriteIndex = 0; /* Points to the mMemoryBuffer. */ const Span mStorage; /* The actual allocated memory set from outside. It is set in the ctor and it @@ -296,10 +297,9 @@ class AudioRingBuffer::AudioRingBufferPrivate { Maybe mBackingBuffer; }; -AudioRingBuffer::AudioRingBuffer(int aSizeInBytes) +AudioRingBuffer::AudioRingBuffer(uint32_t aSizeInBytes) : mPtr(MakeUnique()) { MOZ_ASSERT(aSizeInBytes > 0); - MOZ_ASSERT(aSizeInBytes < std::numeric_limits::max()); mPtr->mBackingBuffer.emplace(aSizeInBytes); MOZ_ASSERT(mPtr->mBackingBuffer); } @@ -323,21 +323,22 @@ void AudioRingBuffer::SetSampleFormat(AudioSampleFormat aFormat) { MOZ_ASSERT(!mPtr->mBackingBuffer); } -int AudioRingBuffer::Write(const Span& aBuffer) { +uint32_t AudioRingBuffer::Write(const Span& aBuffer) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mIntRingBuffer); MOZ_ASSERT(!mPtr->mBackingBuffer); return mPtr->mFloatRingBuffer->Write(aBuffer); } -int AudioRingBuffer::Write(const Span& aBuffer) { +uint32_t AudioRingBuffer::Write(const Span& aBuffer) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16); MOZ_ASSERT(!mPtr->mFloatRingBuffer); MOZ_ASSERT(!mPtr->mBackingBuffer); return mPtr->mIntRingBuffer->Write(aBuffer); } -int AudioRingBuffer::Write(const AudioRingBuffer& aBuffer, int aSamples) { +uint32_t AudioRingBuffer::Write(const AudioRingBuffer& aBuffer, + uint32_t aSamples) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16 || mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mBackingBuffer); @@ -351,7 +352,7 @@ int AudioRingBuffer::Write(const AudioRingBuffer& aBuffer, int aSamples) { aSamples); } -int AudioRingBuffer::WriteSilence(int aSamples) { +uint32_t AudioRingBuffer::WriteSilence(uint32_t aSamples) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16 || mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mBackingBuffer); @@ -363,37 +364,37 @@ int AudioRingBuffer::WriteSilence(int aSamples) { return mPtr->mFloatRingBuffer->WriteSilence(aSamples); } -int AudioRingBuffer::Read(const Span& aBuffer) { +uint32_t AudioRingBuffer::Read(const Span& aBuffer) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mIntRingBuffer); MOZ_ASSERT(!mPtr->mBackingBuffer); return mPtr->mFloatRingBuffer->Read(aBuffer); } -int AudioRingBuffer::Read(const Span& aBuffer) { +uint32_t AudioRingBuffer::Read(const Span& aBuffer) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16); MOZ_ASSERT(!mPtr->mFloatRingBuffer); MOZ_ASSERT(!mPtr->mBackingBuffer); return mPtr->mIntRingBuffer->Read(aBuffer); } -int AudioRingBuffer::ReadNoCopy( - std::function&)>&& aCallable) { +uint32_t AudioRingBuffer::ReadNoCopy( + std::function&)>&& aCallable) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mIntRingBuffer); MOZ_ASSERT(!mPtr->mBackingBuffer); return mPtr->mFloatRingBuffer->ReadNoCopy(std::move(aCallable)); } -int AudioRingBuffer::ReadNoCopy( - std::function&)>&& aCallable) { +uint32_t AudioRingBuffer::ReadNoCopy( + std::function&)>&& aCallable) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16); MOZ_ASSERT(!mPtr->mFloatRingBuffer); MOZ_ASSERT(!mPtr->mBackingBuffer); return mPtr->mIntRingBuffer->ReadNoCopy(std::move(aCallable)); } -int AudioRingBuffer::Discard(int aSamples) { +uint32_t AudioRingBuffer::Discard(uint32_t aSamples) { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16 || mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mBackingBuffer); @@ -405,7 +406,7 @@ int AudioRingBuffer::Discard(int aSamples) { return mPtr->mFloatRingBuffer->Discard(aSamples); } -int AudioRingBuffer::Clear() { +uint32_t AudioRingBuffer::Clear() { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16 || mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mBackingBuffer); @@ -443,7 +444,7 @@ bool AudioRingBuffer::IsEmpty() const { return mPtr->mFloatRingBuffer->IsEmpty(); } -int AudioRingBuffer::AvailableWrite() const { +uint32_t AudioRingBuffer::AvailableWrite() const { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16 || mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mBackingBuffer); @@ -455,7 +456,7 @@ int AudioRingBuffer::AvailableWrite() const { return mPtr->mFloatRingBuffer->AvailableWrite(); } -int AudioRingBuffer::AvailableRead() const { +uint32_t AudioRingBuffer::AvailableRead() const { MOZ_ASSERT(mPtr->mSampleFormat == AUDIO_FORMAT_S16 || mPtr->mSampleFormat == AUDIO_FORMAT_FLOAT32); MOZ_ASSERT(!mPtr->mBackingBuffer); diff --git a/dom/media/AudioRingBuffer.h b/dom/media/AudioRingBuffer.h index a8f1851d24e5..305e414bb82e 100644 --- a/dom/media/AudioRingBuffer.h +++ b/dom/media/AudioRingBuffer.h @@ -22,7 +22,7 @@ namespace mozilla { */ class AudioRingBuffer final { public: - explicit AudioRingBuffer(int aSizeInBytes); + explicit AudioRingBuffer(uint32_t aSizeInBytes); ~AudioRingBuffer(); /** @@ -34,55 +34,57 @@ class AudioRingBuffer final { /** * Write `aBuffer.Length()` number of samples when the format is float. */ - int Write(const Span& aBuffer); + uint32_t Write(const Span& aBuffer); /** * Write `aBuffer.Length()` number of samples when the format is short. */ - int Write(const Span& aBuffer); + uint32_t Write(const Span& aBuffer); /** * Write `aSamples` number of samples from `aBuffer`. Note the `aBuffer` does * not change. */ - int Write(const AudioRingBuffer& aBuffer, int aSamples); + uint32_t Write(const AudioRingBuffer& aBuffer, uint32_t aSamples); /** * Write `aSamples` number of zeros. */ - int WriteSilence(int aSamples); + uint32_t WriteSilence(uint32_t aSamples); /** * Read `aBuffer.Length()` number of samples when the format is float. */ - int Read(const Span& aBuffer); + uint32_t Read(const Span& aBuffer); /** * Read `aBuffer.Length()` number of samples when the format is short. */ - int Read(const Span& aBuffer); + uint32_t Read(const Span& aBuffer); /** * Read the internal buffer without extra copies when sample format is float. * Check also the RingBuffer::ReadNoCopy() for more details. */ - int ReadNoCopy(std::function&)>&& aCallable); + uint32_t ReadNoCopy( + std::function&)>&& aCallable); /** * Read the internal buffer without extra copies when sample format is short. * Check also the RingBuffer::ReadNoCopy() for more details. */ - int ReadNoCopy(std::function&)>&& aCallable); + uint32_t ReadNoCopy( + std::function&)>&& aCallable); /** * Remove `aSamples` number of samples. */ - int Discard(int aSamples); + uint32_t Discard(uint32_t aSamples); /** * Remove all available samples. */ - int Clear(); + uint32_t Clear(); /** * Return true if the buffer is full. @@ -97,12 +99,12 @@ class AudioRingBuffer final { /** * Return the number of samples available for writing. */ - int AvailableWrite() const; + uint32_t AvailableWrite() const; /** * Return the number of samples available for reading. */ - int AvailableRead() const; + uint32_t AvailableRead() const; private: class AudioRingBufferPrivate; diff --git a/dom/media/DynamicResampler.cpp b/dom/media/DynamicResampler.cpp index 6039eefef935..28e2e0132416 100644 --- a/dom/media/DynamicResampler.cpp +++ b/dom/media/DynamicResampler.cpp @@ -7,7 +7,7 @@ namespace mozilla { -DynamicResampler::DynamicResampler(int aInRate, int aOutRate, +DynamicResampler::DynamicResampler(uint32_t aInRate, uint32_t aOutRate, uint32_t aPreBufferFrames) : mInRate(aInRate), mPreBufferFrames(aPreBufferFrames), mOutRate(aOutRate) { MOZ_ASSERT(aInRate); @@ -35,13 +35,13 @@ void DynamicResampler::SetSampleFormat(AudioSampleFormat aFormat) { } bool DynamicResampler::Resample(float* aOutBuffer, uint32_t* aOutFrames, - int aChannelIndex) { + uint32_t aChannelIndex) { MOZ_ASSERT(mSampleFormat == AUDIO_FORMAT_FLOAT32); return ResampleInternal(aOutBuffer, aOutFrames, aChannelIndex); } bool DynamicResampler::Resample(int16_t* aOutBuffer, uint32_t* aOutFrames, - int aChannelIndex) { + uint32_t aChannelIndex) { MOZ_ASSERT(mSampleFormat == AUDIO_FORMAT_S16); return ResampleInternal(aOutBuffer, aOutFrames, aChannelIndex); } @@ -49,7 +49,7 @@ bool DynamicResampler::Resample(int16_t* aOutBuffer, uint32_t* aOutFrames, void DynamicResampler::ResampleInternal(const float* aInBuffer, uint32_t* aInFrames, float* aOutBuffer, uint32_t* aOutFrames, - int aChannelIndex) { + uint32_t aChannelIndex) { MOZ_ASSERT(mResampler); MOZ_ASSERT(mChannels); MOZ_ASSERT(mInRate); @@ -62,7 +62,6 @@ void DynamicResampler::ResampleInternal(const float* aInBuffer, MOZ_ASSERT(aOutFrames); MOZ_ASSERT(*aOutFrames > 0); - MOZ_ASSERT(aChannelIndex >= 0); MOZ_ASSERT(aChannelIndex <= mChannels); #ifdef DEBUG @@ -77,7 +76,7 @@ void DynamicResampler::ResampleInternal(const int16_t* aInBuffer, uint32_t* aInFrames, int16_t* aOutBuffer, uint32_t* aOutFrames, - int aChannelIndex) { + uint32_t aChannelIndex) { MOZ_ASSERT(mResampler); MOZ_ASSERT(mChannels); MOZ_ASSERT(mInRate); @@ -90,7 +89,6 @@ void DynamicResampler::ResampleInternal(const int16_t* aInBuffer, MOZ_ASSERT(aOutFrames); MOZ_ASSERT(*aOutFrames > 0); - MOZ_ASSERT(aChannelIndex >= 0); MOZ_ASSERT(aChannelIndex <= mChannels); #ifdef DEBUG @@ -101,7 +99,7 @@ void DynamicResampler::ResampleInternal(const int16_t* aInBuffer, MOZ_ASSERT(rv == RESAMPLER_ERR_SUCCESS); } -void DynamicResampler::UpdateResampler(int aOutRate, int aChannels) { +void DynamicResampler::UpdateResampler(uint32_t aOutRate, uint32_t aChannels) { MOZ_ASSERT(aOutRate); MOZ_ASSERT(aChannels); @@ -121,7 +119,7 @@ void DynamicResampler::UpdateResampler(int aOutRate, int aChannels) { mChannels == STEREO) { // The mono channel is always up to date. When we are going from mono // to stereo upmix the mono to stereo channel - int bufferedDuration = mInternalInBuffer[0].AvailableRead(); + uint32_t bufferedDuration = mInternalInBuffer[0].AvailableRead(); mInternalInBuffer[1].Clear(); if (bufferedDuration) { mInternalInBuffer[1].Write(mInternalInBuffer[0], bufferedDuration); @@ -135,7 +133,7 @@ void DynamicResampler::UpdateResampler(int aOutRate, int aChannels) { // upmix or downmix, for now just clear but it has to be updated // because allocates and this is executed in audio thread. mInternalInBuffer.Clear(); - for (int i = 0; i < mChannels; ++i) { + for (uint32_t i = 0; i < mChannels; ++i) { // Pre-allocate something big, twice the pre-buffer, or at least 100ms. AudioRingBuffer* b = mInternalInBuffer.AppendElement( sizeof(float) * std::max(2 * mPreBufferFrames, mInRate / 10)); @@ -165,7 +163,7 @@ void DynamicResampler::UpdateResampler(int aOutRate, int aChannels) { void DynamicResampler::WarmUpResampler(bool aSkipLatency) { MOZ_ASSERT(mInputTail.Length()); - for (int i = 0; i < mChannels; ++i) { + for (uint32_t i = 0; i < mChannels; ++i) { if (!mInputTail[i].Length()) { continue; } @@ -206,7 +204,7 @@ void DynamicResampler::AppendInput(const nsTArray& aInBuffer, } bool DynamicResampler::EnoughInFrames(uint32_t aOutFrames, - int aChannelIndex) const { + uint32_t aChannelIndex) const { if (mInRate == mOutRate) { return InFramesBuffered(aChannelIndex) >= aOutFrames; } @@ -220,7 +218,7 @@ bool DynamicResampler::EnoughInFrames(uint32_t aOutFrames, } bool DynamicResampler::CanResample(uint32_t aOutFrames) const { - for (int i = 0; i < mChannels; ++i) { + for (uint32_t i = 0; i < mChannels; ++i) { if (!EnoughInFrames(aOutFrames, i)) { return false; } @@ -232,36 +230,34 @@ void DynamicResampler::AppendInputSilence(const uint32_t aInFrames) { MOZ_ASSERT(aInFrames); MOZ_ASSERT(mChannels); MOZ_ASSERT(mInternalInBuffer.Length() >= (uint32_t)mChannels); - for (int i = 0; i < mChannels; ++i) { + for (uint32_t i = 0; i < mChannels; ++i) { mInternalInBuffer[i].WriteSilence(aInFrames); } } -uint32_t DynamicResampler::InFramesBuffered(int aChannelIndex) const { +uint32_t DynamicResampler::InFramesBuffered(uint32_t aChannelIndex) const { MOZ_ASSERT(mChannels); - MOZ_ASSERT(aChannelIndex >= 0); MOZ_ASSERT(aChannelIndex <= mChannels); - MOZ_ASSERT((uint32_t)aChannelIndex <= mInternalInBuffer.Length()); + MOZ_ASSERT(aChannelIndex <= mInternalInBuffer.Length()); return mInternalInBuffer[aChannelIndex].AvailableRead(); } -uint32_t DynamicResampler::InFramesLeftToBuffer(int aChannelIndex) const { +uint32_t DynamicResampler::InFramesLeftToBuffer(uint32_t aChannelIndex) const { MOZ_ASSERT(mChannels); - MOZ_ASSERT(aChannelIndex >= 0); MOZ_ASSERT(aChannelIndex <= mChannels); - MOZ_ASSERT((uint32_t)aChannelIndex <= mInternalInBuffer.Length()); + MOZ_ASSERT(aChannelIndex <= mInternalInBuffer.Length()); return mInternalInBuffer[aChannelIndex].AvailableWrite(); } -AudioChunkList::AudioChunkList(int aTotalDuration, int aChannels) { - int numOfChunks = aTotalDuration / mChunkCapacity; +AudioChunkList::AudioChunkList(uint32_t aTotalDuration, uint32_t aChannels) { + uint32_t numOfChunks = aTotalDuration / mChunkCapacity; if (aTotalDuration % mChunkCapacity) { ++numOfChunks; } CreateChunks(numOfChunks, aChannels); } -void AudioChunkList::CreateChunks(int aNumOfChunks, int aChannels) { +void AudioChunkList::CreateChunks(uint32_t aNumOfChunks, uint32_t aChannels) { MOZ_ASSERT(!mChunks.Length()); MOZ_ASSERT(aNumOfChunks); MOZ_ASSERT(aChannels); @@ -274,20 +270,20 @@ void AudioChunkList::CreateChunks(int aNumOfChunks, int aChannels) { AutoTArray bufferPtrs; bufferPtrs.AppendElements(aChannels); - for (int i = 0; i < aChannels; ++i) { + for (uint32_t i = 0; i < aChannels; ++i) { float* ptr = buffer[i].AppendElements(mChunkCapacity); bufferPtrs[i] = ptr; } chunk.mBuffer = new mozilla::SharedChannelArrayBuffer(std::move(buffer)); chunk.mChannelData.AppendElements(aChannels); - for (int i = 0; i < aChannels; ++i) { + for (uint32_t i = 0; i < aChannels; ++i) { chunk.mChannelData[i] = bufferPtrs[i]; } } } -void AudioChunkList::UpdateToMonoOrStereo(int aChannels) { +void AudioChunkList::UpdateToMonoOrStereo(uint32_t aChannels) { MOZ_ASSERT(mChunks.Length()); MOZ_ASSERT(mSampleFormat == AUDIO_FORMAT_S16 || mSampleFormat == AUDIO_FORMAT_FLOAT32); @@ -343,9 +339,9 @@ AudioChunk& AudioChunkList::GetNext() { return chunk; } -void AudioChunkList::Update(int aChannels) { +void AudioChunkList::Update(uint32_t aChannels) { MOZ_ASSERT(mChunks.Length()); - if (mChunks[0].ChannelCount() == (uint32_t)aChannels) { + if (mChunks[0].ChannelCount() == aChannels) { return; } @@ -355,12 +351,12 @@ void AudioChunkList::Update(int aChannels) { return; } - int numOfChunks = static_cast(mChunks.Length()); + uint32_t numOfChunks = mChunks.Length(); mChunks.ClearAndRetainStorage(); CreateChunks(numOfChunks, aChannels); } -AudioResampler::AudioResampler(int aInRate, int aOutRate, +AudioResampler::AudioResampler(uint32_t aInRate, uint32_t aOutRate, uint32_t aPreBufferFrames) : mResampler(aInRate, aOutRate, aPreBufferFrames), mOutputChunks(aOutRate / 10, STEREO) {} @@ -419,11 +415,11 @@ AudioSegment AudioResampler::Resample(uint32_t aOutFrames) { return segment; } - int totalFrames = aOutFrames; + uint32_t totalFrames = aOutFrames; while (totalFrames) { MOZ_ASSERT(totalFrames > 0); AudioChunk& chunk = mOutputChunks.GetNext(); - int outFrames = std::min(totalFrames, mOutputChunks.ChunkCapacity()); + uint32_t outFrames = std::min(totalFrames, mOutputChunks.ChunkCapacity()); totalFrames -= outFrames; for (uint32_t i = 0; i < chunk.ChannelCount(); ++i) { @@ -443,7 +439,7 @@ AudioSegment AudioResampler::Resample(uint32_t aOutFrames) { &outFramesUsed, i); MOZ_ASSERT(rv); } - MOZ_ASSERT(outFramesUsed == (uint32_t)outFrames); + MOZ_ASSERT(outFramesUsed == outFrames); chunk.mDuration = outFrames; } @@ -456,25 +452,25 @@ AudioSegment AudioResampler::Resample(uint32_t aOutFrames) { return segment; } -void AudioResampler::Update(int aOutRate, int aChannels) { +void AudioResampler::Update(uint32_t aOutRate, uint32_t aChannels) { mResampler.UpdateResampler(aOutRate, aChannels); mOutputChunks.Update(aChannels); } -int AudioResampler::InputDuration() const { +uint32_t AudioResampler::InputDuration() const { if (!mIsSampleFormatSet) { - return (int)mResampler.mPreBufferFrames; + return mResampler.mPreBufferFrames; } - MOZ_ASSERT((int)mResampler.InFramesBuffered(0) >= 0); - return (int)mResampler.InFramesBuffered(0); + MOZ_ASSERT(mResampler.InFramesBuffered(0) >= 0); + return mResampler.InFramesBuffered(0); } -int AudioResampler::InputRemainingDuration() const { +uint32_t AudioResampler::InputRemainingDuration() const { if (!mIsSampleFormatSet) { - return (int)mResampler.mPreBufferFrames; + return mResampler.mPreBufferFrames; } - MOZ_ASSERT((int)mResampler.InFramesLeftToBuffer(0) >= 0); - return (int)mResampler.InFramesLeftToBuffer(0); + MOZ_ASSERT(mResampler.InFramesLeftToBuffer(0) >= 0); + return mResampler.InFramesLeftToBuffer(0); } } // namespace mozilla diff --git a/dom/media/DynamicResampler.h b/dom/media/DynamicResampler.h index 88c370bafdcd..3105f97ddb92 100644 --- a/dom/media/DynamicResampler.h +++ b/dom/media/DynamicResampler.h @@ -13,7 +13,7 @@ namespace mozilla { -const int STEREO = 2; +const uint32_t STEREO = 2; /** * DynamicResampler allows updating on the fly the output sample rate and the @@ -43,15 +43,16 @@ class DynamicResampler final { * The channel count will be set to stereo. Memory allocation will take * place. The input buffer is non-interleaved. */ - DynamicResampler(int aInRate, int aOutRate, uint32_t aPreBufferFrames = 0); + DynamicResampler(uint32_t aInRate, uint32_t aOutRate, + uint32_t aPreBufferFrames = 0); ~DynamicResampler(); /** * Set the sample format type to float or short. */ void SetSampleFormat(AudioSampleFormat aFormat); - int GetOutRate() const { return mOutRate; } - int GetChannels() const { return mChannels; } + uint32_t GetOutRate() const { return mOutRate; } + uint32_t GetChannels() const { return mChannels; } /** * Append `aInFrames` number of frames from `aInBuffer` to the internal input @@ -68,11 +69,11 @@ class DynamicResampler final { /** * Return the number of frames stored in the internal input buffer. */ - uint32_t InFramesBuffered(int aChannelIndex) const; + uint32_t InFramesBuffered(uint32_t aChannelIndex) const; /** * Return the number of frames left to store in the internal input buffer. */ - uint32_t InFramesLeftToBuffer(int aChannelIndex) const; + uint32_t InFramesLeftToBuffer(uint32_t aChannelIndex) const; /* * Resampler as much frame is needed from the internal input buffer to the @@ -80,8 +81,10 @@ class DynamicResampler final { * not enough input frames to provide the requested output frames no * resampling is attempted and false is returned. */ - bool Resample(float* aOutBuffer, uint32_t* aOutFrames, int aChannelIndex); - bool Resample(int16_t* aOutBuffer, uint32_t* aOutFrames, int aChannelIndex); + bool Resample(float* aOutBuffer, uint32_t* aOutFrames, + uint32_t aChannelIndex); + bool Resample(int16_t* aOutBuffer, uint32_t* aOutFrames, + uint32_t aChannelIndex); /** * Update the output rate or/and the channel count. If a value is not updated @@ -92,7 +95,7 @@ class DynamicResampler final { * place. A stereo internal input buffer is always maintained even if the * sound is mono. */ - void UpdateResampler(int aOutRate, int aChannels); + void UpdateResampler(uint32_t aOutRate, uint32_t aChannels); /** * Returns true if the resampler has enough input data to provide to the @@ -107,27 +110,26 @@ class DynamicResampler final { void AppendInputInternal(const nsTArray& aInBuffer, uint32_t aInFrames) { MOZ_ASSERT(aInBuffer.Length() == (uint32_t)mChannels); - for (int i = 0; i < mChannels; ++i) { + for (uint32_t i = 0; i < mChannels; ++i) { PushInFrames(aInBuffer[i], aInFrames, i); } } void ResampleInternal(const float* aInBuffer, uint32_t* aInFrames, float* aOutBuffer, uint32_t* aOutFrames, - int aChannelIndex); + uint32_t aChannelIndex); void ResampleInternal(const int16_t* aInBuffer, uint32_t* aInFrames, int16_t* aOutBuffer, uint32_t* aOutFrames, - int aChannelIndex); + uint32_t aChannelIndex); template bool ResampleInternal(T* aOutBuffer, uint32_t* aOutFrames, - int aChannelIndex) { + uint32_t aChannelIndex) { MOZ_ASSERT(mInRate); MOZ_ASSERT(mOutRate); MOZ_ASSERT(mChannels); - MOZ_ASSERT(aChannelIndex >= 0); MOZ_ASSERT(aChannelIndex <= mChannels); - MOZ_ASSERT((uint32_t)aChannelIndex <= mInternalInBuffer.Length()); + MOZ_ASSERT(aChannelIndex <= mInternalInBuffer.Length()); MOZ_ASSERT(aOutFrames); MOZ_ASSERT(*aOutFrames); @@ -151,7 +153,7 @@ class DynamicResampler final { mInternalInBuffer[aChannelIndex].ReadNoCopy( [this, &aOutBuffer, &totalOutFramesNeeded, - aChannelIndex](const Span& aInBuffer) -> int { + aChannelIndex](const Span& aInBuffer) -> uint32_t { if (!totalOutFramesNeeded) { return 0; } @@ -169,29 +171,28 @@ class DynamicResampler final { return true; } - bool EnoughInFrames(uint32_t aOutFrames, int aChannelIndex) const; + bool EnoughInFrames(uint32_t aOutFrames, uint32_t aChannelIndex) const; template void PushInFrames(const T* aInBuffer, const uint32_t aInFrames, - int aChannelIndex) { + uint32_t aChannelIndex) { MOZ_ASSERT(aInBuffer); MOZ_ASSERT(aInFrames); MOZ_ASSERT(mChannels); - MOZ_ASSERT(aChannelIndex >= 0); MOZ_ASSERT(aChannelIndex <= mChannels); - MOZ_ASSERT((uint32_t)aChannelIndex <= mInternalInBuffer.Length()); + MOZ_ASSERT(aChannelIndex <= mInternalInBuffer.Length()); mInternalInBuffer[aChannelIndex].Write(Span(aInBuffer, aInFrames)); } void WarmUpResampler(bool aSkipLatency); public: - const int mInRate; + const uint32_t mInRate; const uint32_t mPreBufferFrames; private: - int mChannels = 0; - int mOutRate; + uint32_t mChannels = 0; + uint32_t mOutRate; AutoTArray mInternalInBuffer; @@ -216,15 +217,15 @@ class DynamicResampler final { mSize = MAXSIZE; } else { PodCopy(Buffer(), aInBuffer, aInFrames); - mSize = static_cast(aInFrames); + mSize = aInFrames; } } - int Length() { return mSize; } - static const int MAXSIZE = 20; + uint32_t Length() { return mSize; } + static const uint32_t MAXSIZE = 20; private: float mBuffer[MAXSIZE] = {}; - int mSize = 0; + uint32_t mSize = 0; }; AutoTArray mInputTail; }; @@ -272,7 +273,7 @@ class AudioChunkList { * Constructor, the final total duration might be different from the requested * `aTotalDuration`. Memory allocation takes place. */ - AudioChunkList(int aTotalDuration, int aChannels); + AudioChunkList(uint32_t aTotalDuration, uint32_t aChannels); AudioChunkList(const AudioChunkList&) = delete; AudioChunkList(AudioChunkList&&) = delete; ~AudioChunkList() = default; @@ -300,7 +301,7 @@ class AudioChunkList { /** * Get the capacity of each individual AudioChunk in the list. */ - int ChunkCapacity() const { + uint32_t ChunkCapacity() const { MOZ_ASSERT(mSampleFormat == AUDIO_FORMAT_S16 || mSampleFormat == AUDIO_FORMAT_FLOAT32); return mChunkCapacity; @@ -308,30 +309,30 @@ class AudioChunkList { /** * Get the total capacity of AudioChunkList. */ - int TotalCapacity() const { + uint32_t TotalCapacity() const { MOZ_ASSERT(mSampleFormat == AUDIO_FORMAT_S16 || mSampleFormat == AUDIO_FORMAT_FLOAT32); - return CheckedInt(mChunkCapacity * mChunks.Length()).value(); + return CheckedInt(mChunkCapacity * mChunks.Length()).value(); } /** * Update the channel count of the AudioChunkList. Memory allocation is * taking place. */ - void Update(int aChannels); + void Update(uint32_t aChannels); private: void IncrementIndex() { ++mIndex; - mIndex = CheckedInt(mIndex % mChunks.Length()).value(); + mIndex = CheckedInt(mIndex % mChunks.Length()).value(); } - void CreateChunks(int aNumOfChunks, int aChannels); - void UpdateToMonoOrStereo(int aChannels); + void CreateChunks(uint32_t aNumOfChunks, uint32_t aChannels); + void UpdateToMonoOrStereo(uint32_t aChannels); private: nsTArray mChunks; - int mIndex = 0; - int mChunkCapacity = 128; + uint32_t mIndex = 0; + uint32_t mChunkCapacity = 128; AudioSampleFormat mSampleFormat = AUDIO_FORMAT_SILENCE; }; @@ -355,7 +356,8 @@ class AudioChunkList { */ class AudioResampler final { public: - AudioResampler(int aInRate, int aOutRate, uint32_t aPreBufferFrames = 0); + AudioResampler(uint32_t aInRate, uint32_t aOutRate, + uint32_t aPreBufferFrames = 0); /** * Append input data into the resampler internal buffer. Copy/move of the @@ -366,12 +368,12 @@ class AudioResampler final { /** * Get the duration of the internal input buffer in frames. */ - int InputDuration() const; + uint32_t InputDuration() const; /** * Get the duration of the remaining space in the internal input buffer in * frames. */ - int InputRemainingDuration() const; + uint32_t InputRemainingDuration() const; /* * Reguest `aOutFrames` of audio in the output sample rate. The internal @@ -383,15 +385,15 @@ class AudioResampler final { /* * Updates the output rate that will be used by the resampler. */ - void UpdateOutRate(int aOutRate) { + void UpdateOutRate(uint32_t aOutRate) { Update(aOutRate, mResampler.GetChannels()); } private: - void UpdateChannels(int aChannels) { + void UpdateChannels(uint32_t aChannels) { Update(mResampler.GetOutRate(), aChannels); } - void Update(int aOutRate, int aChannels); + void Update(uint32_t aOutRate, uint32_t aChannels); private: DynamicResampler mResampler; diff --git a/dom/media/gtest/TestAudioDriftCorrection.cpp b/dom/media/gtest/TestAudioDriftCorrection.cpp index 71814fb8742f..6eb733456dc6 100644 --- a/dom/media/gtest/TestAudioDriftCorrection.cpp +++ b/dom/media/gtest/TestAudioDriftCorrection.cpp @@ -14,12 +14,13 @@ // Runs UpdateClock() and checks that the reported correction level doesn't // change for enough time to trigger a correction update on the first // following UpdateClock(). Returns the first reported correction level. -static float RunUntilCorrectionUpdate(ClockDrift& aC, int aSource, int aTarget, - int aBuffering, int aSaturation, - int aSourceOffset = 0, - int aTargetOffset = 0) { +static float RunUntilCorrectionUpdate(ClockDrift& aC, uint32_t aSource, + uint32_t aTarget, uint32_t aBuffering, + uint32_t aSaturation, + uint32_t aSourceOffset = 0, + uint32_t aTargetOffset = 0) { Maybe correction; - for (int s = aSourceOffset, t = aTargetOffset; + for (uint32_t s = aSourceOffset, t = aTargetOffset; s < aC.mSourceRate && t < aC.mTargetRate; s += aSource, t += aTarget) { aC.UpdateClock(aSource, aTarget, aBuffering, aSaturation); if (correction) { @@ -35,7 +36,7 @@ static float RunUntilCorrectionUpdate(ClockDrift& aC, int aSource, int aTarget, TEST(TestClockDrift, Basic) { // Keep buffered frames to the wanted level in order to not affect that test. - const int buffered = 5 * 480; + const uint32_t buffered = 5 * 480; ClockDrift c(48000, 48000, buffered); EXPECT_EQ(c.GetCorrection(), 1.0); @@ -56,7 +57,7 @@ TEST(TestClockDrift, Basic) TEST(TestClockDrift, BasicResampler) { // Keep buffered frames to the wanted level in order to not affect that test. - const int buffered = 5 * 240; + const uint32_t buffered = 5 * 240; ClockDrift c(24000, 48000, buffered); @@ -147,7 +148,7 @@ TEST(TestClockDrift, BufferedInputWithResampling) TEST(TestClockDrift, Clamp) { // Keep buffered frames to the wanted level in order to not affect that test. - const int buffered = 5 * 480; + const uint32_t buffered = 5 * 480; ClockDrift c(48000, 48000, buffered); @@ -166,7 +167,7 @@ TEST(TestClockDrift, Clamp) TEST(TestClockDrift, SmallDiff) { // Keep buffered frames to the wanted level in order to not affect that test. - const int buffered = 5 * 480; + const uint32_t buffered = 5 * 480; ClockDrift c(48000, 48000, buffered); @@ -187,7 +188,7 @@ TEST(TestClockDrift, SmallBufferedFrames) ClockDrift c(48000, 48000, 5 * 480); EXPECT_FLOAT_EQ(c.GetCorrection(), 1.0); - for (int i = 0; i < 10; ++i) { + for (uint32_t i = 0; i < 10; ++i) { c.UpdateClock(480, 480, 5 * 480, 5 * 480); } EXPECT_FLOAT_EQ(c.GetCorrection(), 1.0); @@ -206,7 +207,7 @@ void printAudioSegment(const AudioSegment& segment) { for (AudioSegment::ConstChunkIterator iter(segment); !iter.IsEnded(); iter.Next()) { const AudioChunk& c = *iter; - for (int i = 0; i < c.GetDuration(); ++i) { + for (uint32_t i = 0; i < c.GetDuration(); ++i) { if (c.mBufferFormat == AUDIO_FORMAT_FLOAT32) { printf("%f\n", c.ChannelData()[0][i]); } else { @@ -217,7 +218,7 @@ void printAudioSegment(const AudioSegment& segment) { } template -AudioChunk CreateAudioChunk(uint32_t aFrames, int aChannels, +AudioChunk CreateAudioChunk(uint32_t aFrames, uint32_t aChannels, AudioSampleFormat aSampleFormat); void testAudioCorrection(int32_t aSourceRate, int32_t aTargetRate) { @@ -237,7 +238,7 @@ void testAudioCorrection(int32_t aSourceRate, int32_t aTargetRate) { const uint32_t targetFrames = sampleRateReceiver / 100; // Run for some time: 3 * 1050 = 3150 iterations - for (int j = 0; j < 3; ++j) { + for (uint32_t j = 0; j < 3; ++j) { // apply some drift if (j % 2 == 0) { sourceFrames = @@ -249,7 +250,7 @@ void testAudioCorrection(int32_t aSourceRate, int32_t aTargetRate) { // 10.5 seconds, allows for at least 10 correction changes, to stabilize // around the desired buffer. - for (int n = 0; n < 1050; ++n) { + for (uint32_t n = 0; n < 1050; ++n) { // Create the input (sine tone) AudioSegment inSegment; tone.Generate(inSegment, sourceFrames); @@ -291,7 +292,7 @@ TEST(TestAudioDriftCorrection, Basic) testAudioCorrection(23458, 25113); } -void testMonoToStereoInput(int aSourceRate, int aTargetRate) { +void testMonoToStereoInput(uint32_t aSourceRate, uint32_t aTargetRate) { const uint32_t frequency = 100; const uint32_t sampleRateTransmitter = aSourceRate; const uint32_t sampleRateReceiver = aTargetRate; @@ -307,7 +308,7 @@ void testMonoToStereoInput(int aSourceRate, int aTargetRate) { const uint32_t targetFrames = sampleRateReceiver / 100; // Run for some time: 6 * 250 = 1500 iterations - for (int j = 0; j < 6; ++j) { + for (uint32_t j = 0; j < 6; ++j) { // apply some drift if (j % 2 == 0) { sourceFrames = sampleRateTransmitter / 100 + 10; @@ -315,7 +316,7 @@ void testMonoToStereoInput(int aSourceRate, int aTargetRate) { sourceFrames = sampleRateTransmitter / 100 - 10; } - for (int n = 0; n < 250; ++n) { + for (uint32_t n = 0; n < 250; ++n) { // Create the input (sine tone) of two chunks. AudioSegment inSegment; monoTone.Generate(inSegment, sourceFrames / 2); @@ -362,7 +363,7 @@ TEST(TestAudioDriftCorrection, NotEnoughFrames) AudioDriftCorrection ad(sampleRateTransmitter, sampleRateReceiver); const uint32_t targetFrames = sampleRateReceiver / 100; - for (int i = 0; i < 7; ++i) { + for (uint32_t i = 0; i < 7; ++i) { // Input is something small, 10 frames here, in order to dry out fast, // after 4 iterations AudioChunk chunk = CreateAudioChunk(10, 1, AUDIO_FORMAT_FLOAT32); @@ -388,7 +389,7 @@ TEST(TestAudioDriftCorrection, CrashInAudioResampler) AudioDriftCorrection ad(sampleRateTransmitter, sampleRateReceiver); const uint32_t targetFrames = sampleRateReceiver / 100; - for (int i = 0; i < 100; ++i) { + for (uint32_t i = 0; i < 100; ++i) { AudioChunk chunk = CreateAudioChunk(sampleRateTransmitter / 1000, 1, AUDIO_FORMAT_FLOAT32); AudioSegment inSegment; diff --git a/dom/media/gtest/TestAudioRingBuffer.cpp b/dom/media/gtest/TestAudioRingBuffer.cpp index 4773515de587..ec6c35c23539 100644 --- a/dom/media/gtest/TestAudioRingBuffer.cpp +++ b/dom/media/gtest/TestAudioRingBuffer.cpp @@ -14,75 +14,75 @@ TEST(TestAudioRingBuffer, BasicFloat) EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); - int rv = ringBuffer.WriteSilence(4); - EXPECT_EQ(rv, 4); + uint32_t rv = ringBuffer.WriteSilence(4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); float in[4] = {.1, .2, .3, .4}; rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 2); - EXPECT_EQ(ringBuffer.AvailableRead(), 8); + EXPECT_EQ(ringBuffer.AvailableWrite(), 2u); + EXPECT_EQ(ringBuffer.AvailableRead(), 8u); rv = ringBuffer.WriteSilence(4); - EXPECT_EQ(rv, 2); + EXPECT_EQ(rv, 2u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 0); - EXPECT_EQ(ringBuffer.AvailableRead(), 10); + EXPECT_EQ(ringBuffer.AvailableWrite(), 0u); + EXPECT_EQ(ringBuffer.AvailableRead(), 10u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 0); + EXPECT_EQ(rv, 0u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 0); - EXPECT_EQ(ringBuffer.AvailableRead(), 10); + EXPECT_EQ(ringBuffer.AvailableWrite(), 0u); + EXPECT_EQ(ringBuffer.AvailableRead(), 10u); float out[4] = {}; rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 4); - EXPECT_EQ(ringBuffer.AvailableRead(), 6); + EXPECT_EQ(ringBuffer.AvailableWrite(), 4u); + EXPECT_EQ(ringBuffer.AvailableRead(), 6u); for (float f : out) { EXPECT_FLOAT_EQ(f, 0.0); } rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 8); - EXPECT_EQ(ringBuffer.AvailableRead(), 2); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 8u); + EXPECT_EQ(ringBuffer.AvailableRead(), 2u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_FLOAT_EQ(in[i], out[i]); } rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 2); + EXPECT_EQ(rv, 2u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < 2; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < 2; ++i) { EXPECT_FLOAT_EQ(out[i], 0.0); } rv = ringBuffer.Clear(); - EXPECT_EQ(rv, 0); + EXPECT_EQ(rv, 0u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); } TEST(TestAudioRingBuffer, BasicShort) @@ -92,75 +92,75 @@ TEST(TestAudioRingBuffer, BasicShort) EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); - int rv = ringBuffer.WriteSilence(4); - EXPECT_EQ(rv, 4); + uint32_t rv = ringBuffer.WriteSilence(4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); short in[4] = {1, 2, 3, 4}; rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 2); - EXPECT_EQ(ringBuffer.AvailableRead(), 8); + EXPECT_EQ(ringBuffer.AvailableWrite(), 2u); + EXPECT_EQ(ringBuffer.AvailableRead(), 8u); rv = ringBuffer.WriteSilence(4); - EXPECT_EQ(rv, 2); + EXPECT_EQ(rv, 2u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 0); - EXPECT_EQ(ringBuffer.AvailableRead(), 10); + EXPECT_EQ(ringBuffer.AvailableWrite(), 0u); + EXPECT_EQ(ringBuffer.AvailableRead(), 10u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 0); + EXPECT_EQ(rv, 0u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 0); - EXPECT_EQ(ringBuffer.AvailableRead(), 10); + EXPECT_EQ(ringBuffer.AvailableWrite(), 0u); + EXPECT_EQ(ringBuffer.AvailableRead(), 10u); short out[4] = {}; rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 4); - EXPECT_EQ(ringBuffer.AvailableRead(), 6); + EXPECT_EQ(ringBuffer.AvailableWrite(), 4u); + EXPECT_EQ(ringBuffer.AvailableRead(), 6u); for (float f : out) { EXPECT_EQ(f, 0); } rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 8); - EXPECT_EQ(ringBuffer.AvailableRead(), 2); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 8u); + EXPECT_EQ(ringBuffer.AvailableRead(), 2u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_EQ(in[i], out[i]); } rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 2); + EXPECT_EQ(rv, 2u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < 2; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < 2; ++i) { EXPECT_EQ(out[i], 0); } rv = ringBuffer.Clear(); - EXPECT_EQ(rv, 0); + EXPECT_EQ(rv, 0u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); } TEST(TestAudioRingBuffer, BasicFloat2) @@ -170,101 +170,101 @@ TEST(TestAudioRingBuffer, BasicFloat2) EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); float in[4] = {.1, .2, .3, .4}; - int rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + uint32_t rv = ringBuffer.Write(Span(in, 4)); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 2); - EXPECT_EQ(ringBuffer.AvailableRead(), 8); + EXPECT_EQ(ringBuffer.AvailableWrite(), 2u); + EXPECT_EQ(ringBuffer.AvailableRead(), 8u); float out[4] = {}; rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_FLOAT_EQ(in[i], out[i]); } // WriteIndex = 12 rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 2); - EXPECT_EQ(ringBuffer.AvailableRead(), 8); + EXPECT_EQ(ringBuffer.AvailableWrite(), 2u); + EXPECT_EQ(ringBuffer.AvailableRead(), 8u); rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_FLOAT_EQ(in[i], out[i]); } rv = ringBuffer.Read(Span(out, 8)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_FLOAT_EQ(in[i], out[i]); } rv = ringBuffer.Read(Span(out, 8)); - EXPECT_EQ(rv, 0); + EXPECT_EQ(rv, 0u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_FLOAT_EQ(in[i], out[i]); } // WriteIndex = 16 rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 2); - EXPECT_EQ(ringBuffer.AvailableRead(), 8); + EXPECT_EQ(ringBuffer.AvailableWrite(), 2u); + EXPECT_EQ(ringBuffer.AvailableRead(), 8u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 2); + EXPECT_EQ(rv, 2u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 0); - EXPECT_EQ(ringBuffer.AvailableRead(), 10); + EXPECT_EQ(ringBuffer.AvailableWrite(), 0u); + EXPECT_EQ(ringBuffer.AvailableRead(), 10u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 0); + EXPECT_EQ(rv, 0u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 0); - EXPECT_EQ(ringBuffer.AvailableRead(), 10); + EXPECT_EQ(ringBuffer.AvailableWrite(), 0u); + EXPECT_EQ(ringBuffer.AvailableRead(), 10u); } TEST(TestAudioRingBuffer, BasicShort2) @@ -274,101 +274,101 @@ TEST(TestAudioRingBuffer, BasicShort2) EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); int16_t in[4] = {1, 2, 3, 4}; - int rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + uint32_t rv = ringBuffer.Write(Span(in, 4)); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 2); - EXPECT_EQ(ringBuffer.AvailableRead(), 8); + EXPECT_EQ(ringBuffer.AvailableWrite(), 2u); + EXPECT_EQ(ringBuffer.AvailableRead(), 8u); int16_t out[4] = {}; rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_EQ(in[i], out[i]); } // WriteIndex = 12 rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 2); - EXPECT_EQ(ringBuffer.AvailableRead(), 8); + EXPECT_EQ(ringBuffer.AvailableWrite(), 2u); + EXPECT_EQ(ringBuffer.AvailableRead(), 8u); rv = ringBuffer.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_EQ(in[i], out[i]); } rv = ringBuffer.Read(Span(out, 8)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_EQ(in[i], out[i]); } rv = ringBuffer.Read(Span(out, 8)); - EXPECT_EQ(rv, 0); + EXPECT_EQ(rv, 0u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_EQ(in[i], out[i]); } // WriteIndex = 16 rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 6); - EXPECT_EQ(ringBuffer.AvailableRead(), 4); + EXPECT_EQ(ringBuffer.AvailableWrite(), 6u); + EXPECT_EQ(ringBuffer.AvailableRead(), 4u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 2); - EXPECT_EQ(ringBuffer.AvailableRead(), 8); + EXPECT_EQ(ringBuffer.AvailableWrite(), 2u); + EXPECT_EQ(ringBuffer.AvailableRead(), 8u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 2); + EXPECT_EQ(rv, 2u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 0); - EXPECT_EQ(ringBuffer.AvailableRead(), 10); + EXPECT_EQ(ringBuffer.AvailableWrite(), 0u); + EXPECT_EQ(ringBuffer.AvailableRead(), 10u); rv = ringBuffer.Write(Span(in, 4)); - EXPECT_EQ(rv, 0); + EXPECT_EQ(rv, 0u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 0); - EXPECT_EQ(ringBuffer.AvailableRead(), 10); + EXPECT_EQ(ringBuffer.AvailableWrite(), 0u); + EXPECT_EQ(ringBuffer.AvailableRead(), 10u); } TEST(TestAudioRingBuffer, NoCopyFloat) @@ -385,17 +385,18 @@ TEST(TestAudioRingBuffer, NoCopyFloat) float out[10] = {}; float* out_ptr = out; - int rv = ringBuffer.ReadNoCopy([&out_ptr](const Span aInBuffer) { - PodMove(out_ptr, aInBuffer.data(), aInBuffer.Length()); - out_ptr += aInBuffer.Length(); - return aInBuffer.Length(); - }); - EXPECT_EQ(rv, 6); + uint32_t rv = + ringBuffer.ReadNoCopy([&out_ptr](const Span aInBuffer) { + PodMove(out_ptr, aInBuffer.data(), aInBuffer.Length()); + out_ptr += aInBuffer.Length(); + return aInBuffer.Length(); + }); + EXPECT_EQ(rv, 6u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i], in[i]); } @@ -410,12 +411,12 @@ TEST(TestAudioRingBuffer, NoCopyFloat) out_ptr += aInBuffer.Length(); return aInBuffer.Length(); }); - EXPECT_EQ(rv, 8); + EXPECT_EQ(rv, 8u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i], in[i]); } } @@ -434,17 +435,18 @@ TEST(TestAudioRingBuffer, NoCopyShort) short out[10] = {}; short* out_ptr = out; - int rv = ringBuffer.ReadNoCopy([&out_ptr](const Span aInBuffer) { - PodMove(out_ptr, aInBuffer.data(), aInBuffer.Length()); - out_ptr += aInBuffer.Length(); - return aInBuffer.Length(); - }); - EXPECT_EQ(rv, 6); + uint32_t rv = + ringBuffer.ReadNoCopy([&out_ptr](const Span aInBuffer) { + PodMove(out_ptr, aInBuffer.data(), aInBuffer.Length()); + out_ptr += aInBuffer.Length(); + return aInBuffer.Length(); + }); + EXPECT_EQ(rv, 6u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i], in[i]); } @@ -459,12 +461,12 @@ TEST(TestAudioRingBuffer, NoCopyShort) out_ptr += aInBuffer.Length(); return aInBuffer.Length(); }); - EXPECT_EQ(rv, 8); + EXPECT_EQ(rv, 8u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i], in[i]); } } @@ -482,11 +484,12 @@ TEST(TestAudioRingBuffer, NoCopyFloat2) float out[10] = {}; float* out_ptr = out; - int total_frames = 3; + uint32_t total_frames = 3; - int rv = ringBuffer.ReadNoCopy( + uint32_t rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -495,19 +498,20 @@ TEST(TestAudioRingBuffer, NoCopyFloat2) // v ReadIndex // [x0: .0, x1: .1, x2: .2, x3: .3, x4: .4, // x5: .5, x6: .0, x7: .0, x8: .0, x9: .0, x10: .0] - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 7); - EXPECT_EQ(ringBuffer.AvailableRead(), 3); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 7u); + EXPECT_EQ(ringBuffer.AvailableRead(), 3u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i], in[i]); } total_frames = 3; rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -516,12 +520,12 @@ TEST(TestAudioRingBuffer, NoCopyFloat2) // [x0: .0, x1: .1, x2: .2, x3: .3, x4: .4, // x5: .5, x6: .0, x7: .0, x8: .0, x9: .0, x10: .0] // ^ ReadIndex - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i + 3], in[i + 3]); } @@ -536,7 +540,8 @@ TEST(TestAudioRingBuffer, NoCopyFloat2) total_frames = 3; rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -546,19 +551,20 @@ TEST(TestAudioRingBuffer, NoCopyFloat2) // [x0: .5, x1: .6, x2: .2, x3: .3, x4: .4, // x5: .5, x6: .0, x7: .1, x8: .2, x9: .3, x10: .4 // ^ ReadIndex - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 5); - EXPECT_EQ(ringBuffer.AvailableRead(), 5); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 5u); + EXPECT_EQ(ringBuffer.AvailableRead(), 5u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i], in[i]); } total_frames = 3; rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -568,19 +574,20 @@ TEST(TestAudioRingBuffer, NoCopyFloat2) // v ReadIndex // [x0: .5, x1: .6, x2: .7, x3: .3, x4: .4, // x5: .5, x6: .0, x7: .1, x8: .2, x9: .3, x10: .4 - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 8); - EXPECT_EQ(ringBuffer.AvailableRead(), 2); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 8u); + EXPECT_EQ(ringBuffer.AvailableRead(), 2u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i + 3], in[i + 3]); } total_frames = 3; rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -590,13 +597,13 @@ TEST(TestAudioRingBuffer, NoCopyFloat2) // v ReadIndex // [x0: .5, x1: .6, x2: .7, x3: .3, x4: .4, // x5: .5, x6: .0, x7: .1, x8: .2, x9: .3, x10: .4 - EXPECT_EQ(rv, 2); - EXPECT_EQ(total_frames, 1); + EXPECT_EQ(rv, 2u); + EXPECT_EQ(total_frames, 1u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i + 6], in[i + 6]); } } @@ -614,11 +621,12 @@ TEST(TestAudioRingBuffer, NoCopyShort2) short out[10] = {}; short* out_ptr = out; - int total_frames = 3; + uint32_t total_frames = 3; - int rv = ringBuffer.ReadNoCopy( + uint32_t rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -627,19 +635,20 @@ TEST(TestAudioRingBuffer, NoCopyShort2) // v ReadIndex // [x0: 0, x1: 1, x2: 2, x3: 3, x4: 4, // x5: 5, x6: 0, x7: 0, x8: 0, x9: 0, x10: 0] - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 7); - EXPECT_EQ(ringBuffer.AvailableRead(), 3); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 7u); + EXPECT_EQ(ringBuffer.AvailableRead(), 3u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i], in[i]); } total_frames = 3; rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -648,12 +657,12 @@ TEST(TestAudioRingBuffer, NoCopyShort2) // [x0: 0, x1: 1, x2: 2, x3: 3, x4: 4, // x5: 5, x6: 0, x7: 0, x8: 0, x9: 0, x10: .0] // ^ ReadIndex - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i + 3], in[i + 3]); } @@ -668,7 +677,8 @@ TEST(TestAudioRingBuffer, NoCopyShort2) total_frames = 3; rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -678,19 +688,20 @@ TEST(TestAudioRingBuffer, NoCopyShort2) // [x0: 5, x1: 6, x2: 2, x3: 3, x4: 4, // x5: 5, x6: 0, x7: 1, x8: 2, x9: 3, x10: 4 // ^ ReadIndex - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 5); - EXPECT_EQ(ringBuffer.AvailableRead(), 5); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 5u); + EXPECT_EQ(ringBuffer.AvailableRead(), 5u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i], in[i]); } total_frames = 3; rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -700,19 +711,20 @@ TEST(TestAudioRingBuffer, NoCopyShort2) // v ReadIndex // [x0: 5, x1: 6, x2: 7, x3: 3, x4: 4, // x5: 5, x6: 0, x7: 1, x8: 2, x9: 3, x10: 4 - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 8); - EXPECT_EQ(ringBuffer.AvailableRead(), 2); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 8u); + EXPECT_EQ(ringBuffer.AvailableRead(), 2u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i + 3], in[i + 3]); } total_frames = 3; rv = ringBuffer.ReadNoCopy( [&out_ptr, &total_frames](const Span& aInBuffer) { - int inFramesUsed = std::min(total_frames, aInBuffer.Length()); + uint32_t inFramesUsed = + std::min(total_frames, aInBuffer.Length()); PodMove(out_ptr, aInBuffer.data(), inFramesUsed); out_ptr += inFramesUsed; total_frames -= inFramesUsed; @@ -722,13 +734,13 @@ TEST(TestAudioRingBuffer, NoCopyShort2) // v ReadIndex // [x0: 5, x1: 6, x2: 7, x3: 3, x4: 4, // x5: 5, x6: 0, x7: 1, x8: 2, x9: 3, x10: 4 - EXPECT_EQ(rv, 2); - EXPECT_EQ(total_frames, 1); + EXPECT_EQ(rv, 2u); + EXPECT_EQ(total_frames, 1u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i + 6], in[i + 6]); } } @@ -741,38 +753,38 @@ TEST(TestAudioRingBuffer, DiscardFloat) float in[8] = {.0, .1, .2, .3, .4, .5, .6, .7}; ringBuffer.Write(Span(in, 8)); - int rv = ringBuffer.Discard(3); - EXPECT_EQ(rv, 3); + uint32_t rv = ringBuffer.Discard(3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 5); - EXPECT_EQ(ringBuffer.AvailableRead(), 5); + EXPECT_EQ(ringBuffer.AvailableWrite(), 5u); + EXPECT_EQ(ringBuffer.AvailableRead(), 5u); float out[8] = {}; rv = ringBuffer.Read(Span(out, 3)); - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 8); - EXPECT_EQ(ringBuffer.AvailableRead(), 2); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 8u); + EXPECT_EQ(ringBuffer.AvailableRead(), 2u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i], in[i + 3]); } rv = ringBuffer.Discard(3); - EXPECT_EQ(rv, 2); + EXPECT_EQ(rv, 2u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); ringBuffer.WriteSilence(4); rv = ringBuffer.Discard(6); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); } TEST(TestAudioRingBuffer, DiscardShort) @@ -783,38 +795,38 @@ TEST(TestAudioRingBuffer, DiscardShort) short in[8] = {0, 1, 2, 3, 4, 5, 6, 7}; ringBuffer.Write(Span(in, 8)); - int rv = ringBuffer.Discard(3); - EXPECT_EQ(rv, 3); + uint32_t rv = ringBuffer.Discard(3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 5); - EXPECT_EQ(ringBuffer.AvailableRead(), 5); + EXPECT_EQ(ringBuffer.AvailableWrite(), 5u); + EXPECT_EQ(ringBuffer.AvailableRead(), 5u); short out[8] = {}; rv = ringBuffer.Read(Span(out, 3)); - EXPECT_EQ(rv, 3); + EXPECT_EQ(rv, 3u); EXPECT_TRUE(!ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 8); - EXPECT_EQ(ringBuffer.AvailableRead(), 2); - for (int i = 0; i < rv; ++i) { + EXPECT_EQ(ringBuffer.AvailableWrite(), 8u); + EXPECT_EQ(ringBuffer.AvailableRead(), 2u); + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i], in[i + 3]); } rv = ringBuffer.Discard(3); - EXPECT_EQ(rv, 2); + EXPECT_EQ(rv, 2u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); ringBuffer.WriteSilence(4); rv = ringBuffer.Discard(6); - EXPECT_EQ(rv, 4); + EXPECT_EQ(rv, 4u); EXPECT_TRUE(ringBuffer.IsEmpty()); EXPECT_TRUE(!ringBuffer.IsFull()); - EXPECT_EQ(ringBuffer.AvailableWrite(), 10); - EXPECT_EQ(ringBuffer.AvailableRead(), 0); + EXPECT_EQ(ringBuffer.AvailableWrite(), 10u); + EXPECT_EQ(ringBuffer.AvailableRead(), 0u); } TEST(TestRingBuffer, WriteFromRing1) @@ -825,18 +837,18 @@ TEST(TestRingBuffer, WriteFromRing1) ringBuffer2.SetSampleFormat(AUDIO_FORMAT_FLOAT32); float in[4] = {.1, .2, .3, .4}; - int rv = ringBuffer1.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + uint32_t rv = ringBuffer1.Write(Span(in, 4)); + EXPECT_EQ(rv, 4u); - EXPECT_EQ(ringBuffer2.AvailableRead(), 0); + EXPECT_EQ(ringBuffer2.AvailableRead(), 0u); rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 4); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 4u); float out[4] = {}; rv = ringBuffer2.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(rv, 4u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_FLOAT_EQ(in[i], out[i]); } } @@ -853,16 +865,16 @@ TEST(TestRingBuffer, WriteFromRing2) ringBuffer2.Clear(); float in[4] = {.1, .2, .3, .4}; - int rv = ringBuffer1.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + uint32_t rv = ringBuffer1.Write(Span(in, 4)); + EXPECT_EQ(rv, 4u); rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 4); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 4u); float out[4] = {}; rv = ringBuffer2.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(rv, 4u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_FLOAT_EQ(in[i], out[i]); } } @@ -881,16 +893,16 @@ TEST(TestRingBuffer, WriteFromRing3) ringBuffer2.Clear(); float in[4] = {.1, .2, .3, .4}; - int rv = ringBuffer1.Write(Span(in, 4)); - EXPECT_EQ(rv, 4); + uint32_t rv = ringBuffer1.Write(Span(in, 4)); + EXPECT_EQ(rv, 4u); rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 4); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 4u); float out[4] = {}; rv = ringBuffer2.Read(Span(out, 4)); - EXPECT_EQ(rv, 4); - for (int i = 0; i < 4; ++i) { + EXPECT_EQ(rv, 4u); + for (uint32_t i = 0; i < 4; ++i) { EXPECT_FLOAT_EQ(in[i], out[i]); } } @@ -901,37 +913,37 @@ TEST(TestAudioRingBuffer, WriteFromRingShort) ringBuffer1.SetSampleFormat(AUDIO_FORMAT_S16); short in[8] = {0, 1, 2, 3, 4, 5, 6, 7}; - int rv = ringBuffer1.Write(Span(in, 8)); - EXPECT_EQ(rv, 8); + uint32_t rv = ringBuffer1.Write(Span(in, 8)); + EXPECT_EQ(rv, 8u); AudioRingBuffer ringBuffer2(11 * sizeof(short)); ringBuffer2.SetSampleFormat(AUDIO_FORMAT_S16); rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 4); - EXPECT_EQ(ringBuffer1.AvailableRead(), 8); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 4u); + EXPECT_EQ(ringBuffer1.AvailableRead(), 8u); short out[4] = {}; rv = ringBuffer2.Read(Span(out, 4)); - for (int i = 0; i < rv; ++i) { + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out[i], in[i]); } rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 4); - EXPECT_EQ(ringBuffer1.AvailableRead(), 8); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 4u); + EXPECT_EQ(ringBuffer1.AvailableRead(), 8u); ringBuffer1.Discard(4); rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 8); - EXPECT_EQ(ringBuffer1.AvailableRead(), 4); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 8u); + EXPECT_EQ(ringBuffer1.AvailableRead(), 4u); short out2[8] = {}; rv = ringBuffer2.Read(Span(out2, 8)); - for (int i = 0; i < rv; ++i) { + for (uint32_t i = 0; i < rv; ++i) { EXPECT_EQ(out2[i], in[i]); } } @@ -942,37 +954,37 @@ TEST(TestAudioRingBuffer, WriteFromRingFloat) ringBuffer1.SetSampleFormat(AUDIO_FORMAT_FLOAT32); float in[8] = {.0, .1, .2, .3, .4, .5, .6, .7}; - int rv = ringBuffer1.Write(Span(in, 8)); - EXPECT_EQ(rv, 8); + uint32_t rv = ringBuffer1.Write(Span(in, 8)); + EXPECT_EQ(rv, 8u); AudioRingBuffer ringBuffer2(11 * sizeof(float)); ringBuffer2.SetSampleFormat(AUDIO_FORMAT_FLOAT32); rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 4); - EXPECT_EQ(ringBuffer1.AvailableRead(), 8); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 4u); + EXPECT_EQ(ringBuffer1.AvailableRead(), 8u); float out[4] = {}; rv = ringBuffer2.Read(Span(out, 4)); - for (int i = 0; i < rv; ++i) { + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out[i], in[i]); } rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 4); - EXPECT_EQ(ringBuffer1.AvailableRead(), 8); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 4u); + EXPECT_EQ(ringBuffer1.AvailableRead(), 8u); ringBuffer1.Discard(4); rv = ringBuffer2.Write(ringBuffer1, 4); - EXPECT_EQ(rv, 4); - EXPECT_EQ(ringBuffer2.AvailableRead(), 8); - EXPECT_EQ(ringBuffer1.AvailableRead(), 4); + EXPECT_EQ(rv, 4u); + EXPECT_EQ(ringBuffer2.AvailableRead(), 8u); + EXPECT_EQ(ringBuffer1.AvailableRead(), 4u); float out2[8] = {}; rv = ringBuffer2.Read(Span(out2, 8)); - for (int i = 0; i < rv; ++i) { + for (uint32_t i = 0; i < rv; ++i) { EXPECT_FLOAT_EQ(out2[i], in[i]); } } diff --git a/dom/media/gtest/TestDynamicResampler.cpp b/dom/media/gtest/TestDynamicResampler.cpp index ff6f3d866253..a84b0be3eee0 100644 --- a/dom/media/gtest/TestDynamicResampler.cpp +++ b/dom/media/gtest/TestDynamicResampler.cpp @@ -15,9 +15,9 @@ TEST(TestDynamicResampler, SameRates_Float1) { const uint32_t in_frames = 100; const uint32_t out_frames = 100; - int channels = 2; - int in_rate = 44100; - int out_rate = 44100; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 44100; DynamicResampler dr(in_rate, out_rate); dr.SetSampleFormat(AUDIO_FORMAT_FLOAT32); @@ -81,9 +81,9 @@ TEST(TestDynamicResampler, SameRates_Short1) { uint32_t in_frames = 2; uint32_t out_frames = 2; - int channels = 2; - int in_rate = 44100; - int out_rate = 44100; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 44100; DynamicResampler dr(in_rate, out_rate); dr.SetSampleFormat(AUDIO_FORMAT_S16); @@ -126,9 +126,9 @@ TEST(TestDynamicResampler, SameRates_Float2) { uint32_t in_frames = 3; uint32_t out_frames = 2; - int channels = 2; - int in_rate = 44100; - int out_rate = 44100; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 44100; DynamicResampler dr(in_rate, out_rate); dr.SetSampleFormat(AUDIO_FORMAT_FLOAT32); @@ -181,9 +181,9 @@ TEST(TestDynamicResampler, SameRates_Short2) { uint32_t in_frames = 3; uint32_t out_frames = 2; - int channels = 2; - int in_rate = 44100; - int out_rate = 44100; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 44100; DynamicResampler dr(in_rate, out_rate); dr.SetSampleFormat(AUDIO_FORMAT_S16); @@ -236,9 +236,9 @@ TEST(TestDynamicResampler, SameRates_Float3) { uint32_t in_frames = 2; uint32_t out_frames = 3; - int channels = 2; - int in_rate = 44100; - int out_rate = 44100; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 44100; DynamicResampler dr(in_rate, out_rate); dr.SetSampleFormat(AUDIO_FORMAT_FLOAT32); @@ -284,9 +284,9 @@ TEST(TestDynamicResampler, SameRates_Short3) { uint32_t in_frames = 2; uint32_t out_frames = 3; - int channels = 2; - int in_rate = 44100; - int out_rate = 44100; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 44100; DynamicResampler dr(in_rate, out_rate); dr.SetSampleFormat(AUDIO_FORMAT_S16); @@ -332,9 +332,9 @@ TEST(TestDynamicResampler, UpdateOutRate_Float) { uint32_t in_frames = 10; uint32_t out_frames = 40; - int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 20; @@ -390,9 +390,9 @@ TEST(TestDynamicResampler, UpdateOutRate_Short) { uint32_t in_frames = 10; uint32_t out_frames = 40; - int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 20; @@ -448,15 +448,15 @@ TEST(TestDynamicResampler, BigRangeOutRates_Float) { uint32_t in_frames = 10; uint32_t out_frames = 10; - int channels = 2; - int in_rate = 44100; - int out_rate = 44100; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 44100; uint32_t pre_buffer = 20; DynamicResampler dr(in_rate, out_rate, pre_buffer); dr.SetSampleFormat(AUDIO_FORMAT_FLOAT32); - const int in_capacity = 40; + const uint32_t in_capacity = 40; float in_ch1[in_capacity] = {}; float in_ch2[in_capacity] = {}; for (uint32_t i = 0; i < in_capacity; ++i) { @@ -467,11 +467,11 @@ TEST(TestDynamicResampler, BigRangeOutRates_Float) in_buffer[0] = in_ch1; in_buffer[1] = in_ch2; - const int out_capacity = 1000; + const uint32_t out_capacity = 1000; float out_ch1[out_capacity] = {}; float out_ch2[out_capacity] = {}; - for (int rate = 10000; rate < 90000; ++rate) { + for (uint32_t rate = 10000; rate < 90000; ++rate) { out_rate = rate; dr.UpdateResampler(out_rate, channels); EXPECT_EQ(dr.GetOutRate(), out_rate); @@ -479,7 +479,7 @@ TEST(TestDynamicResampler, BigRangeOutRates_Float) in_frames = 20; // more than we need out_frames = in_frames * out_rate / in_rate; uint32_t expected_out_frames = out_frames; - for (int y = 0; y < 2; ++y) { + for (uint32_t y = 0; y < 2; ++y) { dr.AppendInput(in_buffer, in_frames); bool rv = dr.Resample(out_ch1, &out_frames, 0); EXPECT_TRUE(rv); @@ -495,15 +495,15 @@ TEST(TestDynamicResampler, BigRangeOutRates_Short) { uint32_t in_frames = 10; uint32_t out_frames = 10; - int channels = 2; - int in_rate = 44100; - int out_rate = 44100; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 44100; uint32_t pre_buffer = 20; DynamicResampler dr(in_rate, out_rate, pre_buffer); dr.SetSampleFormat(AUDIO_FORMAT_S16); - const int in_capacity = 40; + const uint32_t in_capacity = 40; short in_ch1[in_capacity] = {}; short in_ch2[in_capacity] = {}; for (uint32_t i = 0; i < in_capacity; ++i) { @@ -514,17 +514,17 @@ TEST(TestDynamicResampler, BigRangeOutRates_Short) in_buffer[0] = in_ch1; in_buffer[1] = in_ch2; - const int out_capacity = 1000; + const uint32_t out_capacity = 1000; short out_ch1[out_capacity] = {}; short out_ch2[out_capacity] = {}; - for (int rate = 10000; rate < 90000; ++rate) { + for (uint32_t rate = 10000; rate < 90000; ++rate) { out_rate = rate; dr.UpdateResampler(out_rate, channels); in_frames = 20; // more than we need out_frames = in_frames * out_rate / in_rate; uint32_t expected_out_frames = out_frames; - for (int y = 0; y < 2; ++y) { + for (uint32_t y = 0; y < 2; ++y) { dr.AppendInput(in_buffer, in_frames); bool rv = dr.Resample(out_ch1, &out_frames, 0); EXPECT_TRUE(rv); @@ -540,9 +540,9 @@ TEST(TestDynamicResampler, UpdateChannels_Float) { uint32_t in_frames = 10; uint32_t out_frames = 10; - int channels = 2; - int in_rate = 44100; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 48000; DynamicResampler dr(in_rate, out_rate); dr.SetSampleFormat(AUDIO_FORMAT_FLOAT32); @@ -571,7 +571,7 @@ TEST(TestDynamicResampler, UpdateChannels_Float) // Add 3rd channel dr.UpdateResampler(out_rate, 3); EXPECT_EQ(dr.GetOutRate(), out_rate); - EXPECT_EQ(dr.GetChannels(), 3); + EXPECT_EQ(dr.GetChannels(), 3u); float in_ch3[10] = {}; for (uint32_t i = 0; i < in_frames; ++i) { @@ -603,7 +603,7 @@ TEST(TestDynamicResampler, UpdateChannels_Float) dr.UpdateResampler(out_rate, 4); EXPECT_EQ(dr.GetOutRate(), out_rate); - EXPECT_EQ(dr.GetChannels(), 4); + EXPECT_EQ(dr.GetChannels(), 4u); dr.AppendInput(in_buffer, in_frames); rv = dr.Resample(out_ch1, &out_frames, 0); @@ -624,9 +624,9 @@ TEST(TestDynamicResampler, UpdateChannels_Short) { uint32_t in_frames = 10; uint32_t out_frames = 10; - int channels = 2; - int in_rate = 44100; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 44100; + uint32_t out_rate = 48000; DynamicResampler dr(in_rate, out_rate); dr.SetSampleFormat(AUDIO_FORMAT_S16); @@ -655,7 +655,7 @@ TEST(TestDynamicResampler, UpdateChannels_Short) // Add 3rd channel dr.UpdateResampler(out_rate, 3); EXPECT_EQ(dr.GetOutRate(), out_rate); - EXPECT_EQ(dr.GetChannels(), 3); + EXPECT_EQ(dr.GetChannels(), 3u); short in_ch3[10] = {}; for (uint32_t i = 0; i < in_frames; ++i) { @@ -688,7 +688,7 @@ TEST(TestDynamicResampler, UpdateChannels_Short) dr.UpdateResampler(out_rate, 4); EXPECT_EQ(dr.GetOutRate(), out_rate); - EXPECT_EQ(dr.GetChannels(), 4); + EXPECT_EQ(dr.GetChannels(), 4u); dr.AppendInput(in_buffer, in_frames); rv = dr.Resample(out_ch1, &out_frames, 0); @@ -709,14 +709,14 @@ TEST(TestAudioChunkList, Basic1) { AudioChunkList list(256, 2); list.SetSampleFormat(AUDIO_FORMAT_FLOAT32); - EXPECT_EQ(list.ChunkCapacity(), 128); - EXPECT_EQ(list.TotalCapacity(), 256); + EXPECT_EQ(list.ChunkCapacity(), 128u); + EXPECT_EQ(list.TotalCapacity(), 256u); AudioChunk& c1 = list.GetNext(); float* c1_ch1 = c1.ChannelDataForWrite(0); float* c1_ch2 = c1.ChannelDataForWrite(1); EXPECT_EQ(c1.mBufferFormat, AUDIO_FORMAT_FLOAT32); - for (int i = 0; i < list.ChunkCapacity(); ++i) { + for (uint32_t i = 0; i < list.ChunkCapacity(); ++i) { c1_ch1[i] = c1_ch2[i] = 0.01f * static_cast(i); } AudioChunk& c2 = list.GetNext(); @@ -728,7 +728,7 @@ TEST(TestAudioChunkList, Basic1) EXPECT_EQ(c1.mBuffer.get(), c3.mBuffer.get()); float* c3_ch1 = c3.ChannelDataForWrite(0); float* c3_ch2 = c3.ChannelDataForWrite(1); - for (int i = 0; i < list.ChunkCapacity(); ++i) { + for (uint32_t i = 0; i < list.ChunkCapacity(); ++i) { EXPECT_FLOAT_EQ(c1_ch1[i], c3_ch1[i]); EXPECT_FLOAT_EQ(c1_ch2[i], c3_ch2[i]); } @@ -738,14 +738,14 @@ TEST(TestAudioChunkList, Basic2) { AudioChunkList list(256, 2); list.SetSampleFormat(AUDIO_FORMAT_S16); - EXPECT_EQ(list.ChunkCapacity(), 256); - EXPECT_EQ(list.TotalCapacity(), 512); + EXPECT_EQ(list.ChunkCapacity(), 256u); + EXPECT_EQ(list.TotalCapacity(), 512u); AudioChunk& c1 = list.GetNext(); EXPECT_EQ(c1.mBufferFormat, AUDIO_FORMAT_S16); short* c1_ch1 = c1.ChannelDataForWrite(0); short* c1_ch2 = c1.ChannelDataForWrite(1); - for (int i = 0; i < list.ChunkCapacity(); ++i) { + for (uint32_t i = 0; i < list.ChunkCapacity(); ++i) { c1_ch1[i] = c1_ch2[i] = static_cast(i); } AudioChunk& c2 = list.GetNext(); @@ -761,7 +761,7 @@ TEST(TestAudioChunkList, Basic2) EXPECT_EQ(c1.mBuffer.get(), c5.mBuffer.get()); short* c5_ch1 = c5.ChannelDataForWrite(0); short* c5_ch2 = c5.ChannelDataForWrite(1); - for (int i = 0; i < list.ChunkCapacity(); ++i) { + for (uint32_t i = 0; i < list.ChunkCapacity(); ++i) { EXPECT_EQ(c1_ch1[i], c5_ch1[i]); EXPECT_EQ(c1_ch2[i], c5_ch2[i]); } @@ -771,8 +771,8 @@ TEST(TestAudioChunkList, Basic3) { AudioChunkList list(260, 2); list.SetSampleFormat(AUDIO_FORMAT_FLOAT32); - EXPECT_EQ(list.ChunkCapacity(), 128); - EXPECT_EQ(list.TotalCapacity(), 256 + 128); + EXPECT_EQ(list.ChunkCapacity(), 128u); + EXPECT_EQ(list.TotalCapacity(), 256u + 128u); AudioChunk& c1 = list.GetNext(); AudioChunk& c2 = list.GetNext(); @@ -787,8 +787,8 @@ TEST(TestAudioChunkList, Basic4) { AudioChunkList list(260, 2); list.SetSampleFormat(AUDIO_FORMAT_S16); - EXPECT_EQ(list.ChunkCapacity(), 256); - EXPECT_EQ(list.TotalCapacity(), 512 + 256); + EXPECT_EQ(list.ChunkCapacity(), 256u); + EXPECT_EQ(list.TotalCapacity(), 512u + 256u); AudioChunk& c1 = list.GetNext(); AudioChunk& c2 = list.GetNext(); @@ -826,7 +826,7 @@ TEST(TestAudioChunkList, UpdateBetweenMonoAndStereo) AudioChunk& c1 = list.GetNext(); float* c1_ch1 = c1.ChannelDataForWrite(0); float* c1_ch2 = c1.ChannelDataForWrite(1); - for (int i = 0; i < list.ChunkCapacity(); ++i) { + for (uint32_t i = 0; i < list.ChunkCapacity(); ++i) { c1_ch1[i] = c1_ch2[i] = 0.01f * static_cast(i); } @@ -839,7 +839,7 @@ TEST(TestAudioChunkList, UpdateBetweenMonoAndStereo) AudioChunk& c3 = list.GetNext(); float* c3_ch1 = c3.ChannelDataForWrite(0); - for (int i = 0; i < list.ChunkCapacity(); ++i) { + for (uint32_t i = 0; i < list.ChunkCapacity(); ++i) { EXPECT_FLOAT_EQ(c3_ch1[i], c1_ch1[i]); } @@ -849,7 +849,7 @@ TEST(TestAudioChunkList, UpdateBetweenMonoAndStereo) EXPECT_EQ(static_cast*>(c3.mBuffer.get()) ->mBuffers[0] .Length(), - (uint32_t)list.ChunkCapacity()); + list.ChunkCapacity()); // Upmix to stereo list.Update(2); @@ -861,18 +861,18 @@ TEST(TestAudioChunkList, UpdateBetweenMonoAndStereo) EXPECT_EQ(static_cast*>(c5.mBuffer.get()) ->mBuffers[0] .Length(), - (uint32_t)list.ChunkCapacity()); + list.ChunkCapacity()); EXPECT_EQ(static_cast*>(c5.mBuffer.get()) ->mBuffers[1] .Length(), - (uint32_t)list.ChunkCapacity()); + list.ChunkCapacity()); // Downmix to mono list.Update(1); AudioChunk& c7 = list.GetNext(); float* c7_ch1 = c7.ChannelDataForWrite(0); - for (int i = 0; i < list.ChunkCapacity(); ++i) { + for (uint32_t i = 0; i < list.ChunkCapacity(); ++i) { EXPECT_FLOAT_EQ(c7_ch1[i], c1_ch1[i]); } @@ -882,7 +882,7 @@ TEST(TestAudioChunkList, UpdateBetweenMonoAndStereo) EXPECT_EQ(static_cast*>(c7.mBuffer.get()) ->mBuffers[0] .Length(), - (uint32_t)list.ChunkCapacity()); + list.ChunkCapacity()); } TEST(TestAudioChunkList, ConsumeAndForget) @@ -909,7 +909,7 @@ TEST(TestAudioChunkList, ConsumeAndForget) } template -AudioChunk CreateAudioChunk(uint32_t aFrames, int aChannels, +AudioChunk CreateAudioChunk(uint32_t aFrames, uint32_t aChannels, AudioSampleFormat aSampleFormat) { AudioChunk chunk; nsTArray> buffer; @@ -918,7 +918,7 @@ AudioChunk CreateAudioChunk(uint32_t aFrames, int aChannels, nsTArray bufferPtrs; bufferPtrs.AppendElements(aChannels); - for (int i = 0; i < aChannels; ++i) { + for (uint32_t i = 0; i < aChannels; ++i) { T* ptr = buffer[i].AppendElements(aFrames); bufferPtrs[i] = ptr; for (uint32_t j = 0; j < aFrames; ++j) { @@ -933,7 +933,7 @@ AudioChunk CreateAudioChunk(uint32_t aFrames, int aChannels, chunk.mBuffer = new mozilla::SharedChannelArrayBuffer(std::move(buffer)); chunk.mBufferFormat = aSampleFormat; chunk.mChannelData.AppendElements(aChannels); - for (int i = 0; i < aChannels; ++i) { + for (uint32_t i = 0; i < aChannels; ++i) { chunk.mChannelData[i] = bufferPtrs[i]; } chunk.mDuration = aFrames; @@ -941,7 +941,7 @@ AudioChunk CreateAudioChunk(uint32_t aFrames, int aChannels, } template -AudioSegment CreateAudioSegment(uint32_t aFrames, int aChannels, +AudioSegment CreateAudioSegment(uint32_t aFrames, uint32_t aChannels, AudioSampleFormat aSampleFormat) { AudioSegment segment; AudioChunk chunk = CreateAudioChunk(aFrames, aChannels, aSampleFormat); @@ -953,9 +953,9 @@ TEST(TestAudioResampler, OutAudioSegment_Float) { uint32_t in_frames = 10; uint32_t out_frames = 40; - int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 21; @@ -999,9 +999,9 @@ TEST(TestAudioResampler, OutAudioSegment_Short) { uint32_t in_frames = 10; uint32_t out_frames = 40; - int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 21; @@ -1045,9 +1045,9 @@ TEST(TestAudioResampler, OutAudioSegmentFail_Float) { const uint32_t in_frames = 130; const uint32_t out_frames = 300; - int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 5; @@ -1067,9 +1067,9 @@ TEST(TestAudioResampler, InAudioSegment_Float) { uint32_t in_frames = 10; uint32_t out_frames = 40; - int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 10; AudioResampler dr(in_rate, out_rate, pre_buffer); @@ -1087,7 +1087,7 @@ TEST(TestAudioResampler, InAudioSegment_Float) nsTArray bufferPtrs; bufferPtrs.AppendElements(channels); - for (int i = 0; i < channels; ++i) { + for (uint32_t i = 0; i < channels; ++i) { float* ptr = buffer[i].AppendElements(5); bufferPtrs[i] = ptr; for (uint32_t j = 0; j < 5; ++j) { @@ -1098,7 +1098,7 @@ TEST(TestAudioResampler, InAudioSegment_Float) chunk2.mBuffer = new mozilla::SharedChannelArrayBuffer(std::move(buffer)); chunk2.mBufferFormat = AUDIO_FORMAT_FLOAT32; chunk2.mChannelData.AppendElements(channels); - for (int i = 0; i < channels; ++i) { + for (uint32_t i = 0; i < channels; ++i) { chunk2.mChannelData[i] = bufferPtrs[i]; } chunk2.mDuration = in_frames / 2; @@ -1121,9 +1121,9 @@ TEST(TestAudioResampler, InAudioSegment_Short) { uint32_t in_frames = 10; uint32_t out_frames = 40; - int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 10; AudioResampler dr(in_rate, out_rate, pre_buffer); @@ -1142,7 +1142,7 @@ TEST(TestAudioResampler, InAudioSegment_Short) nsTArray bufferPtrs; bufferPtrs.AppendElements(channels); - for (int i = 0; i < channels; ++i) { + for (uint32_t i = 0; i < channels; ++i) { short* ptr = buffer[i].AppendElements(5); bufferPtrs[i] = ptr; for (uint32_t j = 0; j < 5; ++j) { @@ -1153,7 +1153,7 @@ TEST(TestAudioResampler, InAudioSegment_Short) chunk2.mBuffer = new mozilla::SharedChannelArrayBuffer(std::move(buffer)); chunk2.mBufferFormat = AUDIO_FORMAT_S16; chunk2.mChannelData.AppendElements(channels); - for (int i = 0; i < channels; ++i) { + for (uint32_t i = 0; i < channels; ++i) { chunk2.mChannelData[i] = bufferPtrs[i]; } chunk2.mDuration = in_frames / 2; @@ -1175,9 +1175,9 @@ TEST(TestAudioResampler, ChannelChange_MonoToStereo) { uint32_t in_frames = 10; uint32_t out_frames = 40; - // int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + // uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 0; @@ -1205,9 +1205,9 @@ TEST(TestAudioResampler, ChannelChange_StereoToMono) { uint32_t in_frames = 10; uint32_t out_frames = 40; - // int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + // uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 0; @@ -1235,9 +1235,9 @@ TEST(TestAudioResampler, ChannelChange_StereoToQuad) { uint32_t in_frames = 10; uint32_t out_frames = 40; - // int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + // uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; uint32_t pre_buffer = 0; @@ -1270,9 +1270,9 @@ TEST(TestAudioResampler, ChannelChange_QuadToStereo) { uint32_t in_frames = 10; uint32_t out_frames = 40; - // int channels = 2; - int in_rate = 24000; - int out_rate = 48000; + // uint32_t channels = 2; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; AudioResampler dr(in_rate, out_rate); @@ -1303,8 +1303,8 @@ void printAudioSegment(const AudioSegment& segment); TEST(TestAudioResampler, ChannelChange_Discontinuity) { - int in_rate = 24000; - int out_rate = 48000; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; const float amplitude = 0.5; const float frequency = 200; @@ -1312,20 +1312,20 @@ TEST(TestAudioResampler, ChannelChange_Discontinuity) float time = 0.0; const float deltaTime = 1.0f / static_cast(in_rate); - int in_frames = in_rate / 100; - int out_frames = out_rate / 100; + uint32_t in_frames = in_rate / 100; + uint32_t out_frames = out_rate / 100; AudioResampler dr(in_rate, out_rate); AudioChunk monoChunk = CreateAudioChunk(in_frames, 1, AUDIO_FORMAT_FLOAT32); - for (int i = 0; i < monoChunk.GetDuration(); ++i) { + for (uint32_t i = 0; i < monoChunk.GetDuration(); ++i) { double value = amplitude * sin(2 * M_PI * frequency * time + phase); monoChunk.ChannelDataForWrite(0)[i] = static_cast(value); time += deltaTime; } AudioChunk stereoChunk = CreateAudioChunk(in_frames, 2, AUDIO_FORMAT_FLOAT32); - for (int i = 0; i < stereoChunk.GetDuration(); ++i) { + for (uint32_t i = 0; i < stereoChunk.GetDuration(); ++i) { double value = amplitude * sin(2 * M_PI * frequency * time + phase); stereoChunk.ChannelDataForWrite(0)[i] = static_cast(value); if (stereoChunk.ChannelCount() == 2) { @@ -1359,8 +1359,8 @@ TEST(TestAudioResampler, ChannelChange_Discontinuity) TEST(TestAudioResampler, ChannelChange_Discontinuity2) { - int in_rate = 24000; - int out_rate = 48000; + uint32_t in_rate = 24000; + uint32_t out_rate = 48000; const float amplitude = 0.5; const float frequency = 200; @@ -1368,20 +1368,20 @@ TEST(TestAudioResampler, ChannelChange_Discontinuity2) float time = 0.0; const float deltaTime = 1.0f / static_cast(in_rate); - int in_frames = in_rate / 100; - int out_frames = out_rate / 100; + uint32_t in_frames = in_rate / 100; + uint32_t out_frames = out_rate / 100; AudioResampler dr(in_rate, out_rate, 10); AudioChunk monoChunk = CreateAudioChunk(in_frames / 2, 1, AUDIO_FORMAT_FLOAT32); - for (int i = 0; i < monoChunk.GetDuration(); ++i) { + for (uint32_t i = 0; i < monoChunk.GetDuration(); ++i) { double value = amplitude * sin(2 * M_PI * frequency * time + phase); monoChunk.ChannelDataForWrite(0)[i] = static_cast(value); time += deltaTime; } AudioChunk stereoChunk = CreateAudioChunk(in_frames / 2, 2, AUDIO_FORMAT_FLOAT32); - for (int i = 0; i < stereoChunk.GetDuration(); ++i) { + for (uint32_t i = 0; i < stereoChunk.GetDuration(); ++i) { double value = amplitude * sin(2 * M_PI * frequency * time + phase); stereoChunk.ChannelDataForWrite(0)[i] = static_cast(value); if (stereoChunk.ChannelCount() == 2) { @@ -1420,8 +1420,8 @@ TEST(TestAudioResampler, ChannelChange_Discontinuity2) TEST(TestAudioResampler, ChannelChange_Discontinuity3) { - int in_rate = 48000; - int out_rate = 48000; + uint32_t in_rate = 48000; + uint32_t out_rate = 48000; const float amplitude = 0.5; const float frequency = 200; @@ -1429,13 +1429,13 @@ TEST(TestAudioResampler, ChannelChange_Discontinuity3) float time = 0.0; const float deltaTime = 1.0f / static_cast(in_rate); - int in_frames = in_rate / 100; - int out_frames = out_rate / 100; + uint32_t in_frames = in_rate / 100; + uint32_t out_frames = out_rate / 100; AudioResampler dr(in_rate, out_rate, 10); AudioChunk stereoChunk = CreateAudioChunk(in_frames, 2, AUDIO_FORMAT_FLOAT32); - for (int i = 0; i < stereoChunk.GetDuration(); ++i) { + for (uint32_t i = 0; i < stereoChunk.GetDuration(); ++i) { double value = amplitude * sin(2 * M_PI * frequency * time + phase); stereoChunk.ChannelDataForWrite(0)[i] = static_cast(value); if (stereoChunk.ChannelCount() == 2) {