Bug 1264199: P3. Attempt to minimize audio quality loss and unnecessary processing. r=kinetik

We attempt to avoid unnecessary resampling of 44.1kHz and 48kHz content, for all others we use cubeb's preferred sampling rate as final sampling rate.

MozReview-Commit-ID: 413qnsDFHzY
This commit is contained in:
Jean-Yves Avenard 2016-04-13 17:55:48 +10:00
parent 024b052f14
commit a0ed015dba
2 changed files with 20 additions and 2 deletions

View File

@ -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; }

View File

@ -48,8 +48,21 @@ 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();
}
MOZ_DIAGNOSTIC_ASSERT(mOutputRate, "output rate can't be 0.");
mOutputChannels = mInfo.mChannels > 2 && gfxPrefs::AudioSinkForceStereo()
? 2 : mInfo.mChannels;
}