Bug 1387454 - Create preference to enable setting of sample rate in AudioContext. r?padenot
MozReview-Commit-ID: IyFkx8ooLLL
--- a/dom/media/tests/mochitest/head.js
+++ b/dom/media/tests/mochitest/head.js
@@ -415,17 +415,18 @@ function setupEnvironment() {
['media.peerconnection.remoteTrackId.enabled', true],
['media.peerconnection.rtpsourcesapi.enabled', true],
['media.navigator.permission.disabled', true],
// If either fake audio or video is desired we enable fake streams.
// If loopback devices are set they will be chosen instead of fakes in gecko.
['media.navigator.streams.fake', WANT_FAKE_AUDIO || WANT_FAKE_VIDEO],
['media.getusermedia.screensharing.enabled', true],
['media.getusermedia.audiocapture.enabled', true],
- ['media.recorder.audio_node.enabled', true]
+ ['media.recorder.audio_node.enabled', true],
+ ['media.webaudio.audiocontextoptions-samplerate.enabled', true]
]
};
if (!WANT_FAKE_AUDIO) {
defaultMochitestPrefs.set.push(
["media.volume_scale", "1"],
);
}
--- a/dom/media/webaudio/AudioContext.cpp
+++ b/dom/media/webaudio/AudioContext.cpp
@@ -6,16 +6,17 @@
#include "AudioContext.h"
#include "blink/PeriodicWave.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/OwningNonNull.h"
#include "mozilla/RefPtr.h"
+#include "mozilla/Preferences.h"
#include "mozilla/dom/AnalyserNode.h"
#include "mozilla/dom/AnalyserNodeBinding.h"
#include "mozilla/dom/AudioBufferSourceNodeBinding.h"
#include "mozilla/dom/AudioContextBinding.h"
#include "mozilla/dom/BaseAudioContextBinding.h"
#include "mozilla/dom/BiquadFilterNodeBinding.h"
#include "mozilla/dom/ChannelMergerNodeBinding.h"
@@ -201,28 +202,32 @@ AudioContext::Constructor(const GlobalOb
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
if (!window) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
- if (aOptions.mSampleRate > 0 &&
- (aOptions.mSampleRate - WebAudioUtils::MinSampleRate < 0.0 ||
- WebAudioUtils::MaxSampleRate - aOptions.mSampleRate < 0.0)) {
- aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
- return nullptr;
+ float sampleRate = MediaStreamGraph::REQUEST_DEFAULT_SAMPLE_RATE;
+ if (Preferences::GetBool("media.webaudio.audiocontextoptions-samplerate.enabled")) {
+ if (aOptions.mSampleRate > 0 &&
+ (aOptions.mSampleRate - WebAudioUtils::MinSampleRate < 0.0 ||
+ WebAudioUtils::MaxSampleRate - aOptions.mSampleRate < 0.0)) {
+ aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
+ return nullptr;
+ }
+ sampleRate = aOptions.mSampleRate;
}
uint32_t maxChannelCount = std::min<uint32_t>(WebAudioUtils::MaxChannelCount,
CubebUtils::MaxNumberOfChannels());
RefPtr<AudioContext> object =
new AudioContext(window, false, maxChannelCount,
- 0, aOptions.mSampleRate);
+ 0, sampleRate);
aRv = object->Init();
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RegisterWeakMemoryReporter(object);
return object.forget();
--- a/dom/media/webaudio/test/test_audioContextParams_recordNonDefaultSampleRate.html
+++ b/dom/media/webaudio/test/test_audioContextParams_recordNonDefaultSampleRate.html
@@ -35,14 +35,15 @@ function startTest() {
recorder.start(1000);
ok(true, 'recorder started');
is('recording', recorder.state, 'check record state recording');
} catch (e) {
ok(false, 'Can t record audio context');
}
}
+SpecialPowers.setBoolPref("media.webaudio.audiocontextoptions-samplerate.enabled", true);
startTest();
SimpleTest.waitForExplicitFinish();
</script>
</pre>
</body>
</html>
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -661,16 +661,18 @@ pref("media.cubeb.logging_level", "");
pref("media.cubeb.sandbox", true);
pref("media.audioipc.pool_size", 2);
// 64 kB stack per pool thread.
pref("media.audioipc.stack_size", 65536);
#else
pref("media.cubeb.sandbox", false);
#endif
+pref("media.webaudio.audiocontextoptions-samplerate.enabled", true);
+
// Set to true to force demux/decode warnings to be treated as errors.
pref("media.playback.warnings-as-errors", false);
// Weather we allow AMD switchable graphics
pref("layers.amd-switchable-gfx.enabled", true);
// Whether to use async panning and zooming
pref("layers.async-pan-zoom.enabled", true);