diff --git a/dom/media/AudioStream.h b/dom/media/AudioStream.h index e105e6b1b954..3143a87cab00 100644 --- a/dom/media/AudioStream.h +++ b/dom/media/AudioStream.h @@ -286,6 +286,11 @@ public: // Returns true when the audio stream is paused. bool IsPaused(); + static uint32_t GetPreferredRate() + { + CubebUtils::InitPreferredSampleRate(); + return CubebUtils::PreferredSampleRate(); + } uint32_t GetRate() { return mOutRate; } uint32_t GetChannels() { return mChannels; } uint32_t GetOutChannels() { return mOutChannels; } diff --git a/dom/media/mediasink/DecodedAudioDataSink.cpp b/dom/media/mediasink/DecodedAudioDataSink.cpp index cedc35cdcb29..7128c7fe6335 100644 --- a/dom/media/mediasink/DecodedAudioDataSink.cpp +++ b/dom/media/mediasink/DecodedAudioDataSink.cpp @@ -49,8 +49,20 @@ DecodedAudioDataSink::DecodedAudioDataSink(AbstractThread* aThread, , mLastEndTime(0) { bool resampling = gfxPrefs::AudioSinkResampling(); - uint32_t resamplingRate = gfxPrefs::AudioSinkResampleRate(); - mOutputRate = resampling ? resamplingRate : mInfo.mRate; + + if (resampling) { + mOutputRate = gfxPrefs::AudioSinkResampleRate(); + } else if (mInfo.mRate == 44100 || mInfo.mRate == 48000) { + // The original rate is of good quality and we want to minimize unecessary + // resampling. The common scenario being that the sampling rate is one or + // the other, this allows to minimize audio quality regression and hoping + // content provider want change from those rates mid-stream. + mOutputRate = mInfo.mRate; + } else { + // We will resample all data to match cubeb's preferred sampling rate. + mOutputRate = AudioStream::GetPreferredRate(); + } + mOutputChannels = mInfo.mChannels > 2 && gfxPrefs::AudioSinkForceStereo() ? 2 : mInfo.mChannels;