Bug 1387454 - Set sample rate in AudioContext constructor. r=padenot

MozReview-Commit-ID: 9uQLotrF86k

--HG--
extra : rebase_source : df35ed5401e24addb2374e3dd2921963e8fe7aa7
This commit is contained in:
Alex Chronopoulos 2018-04-03 20:02:15 +03:00
Родитель ee0b8e9fc2
Коммит 5c2b9f6591
2 изменённых файлов: 15 добавлений и 3 удалений

Просмотреть файл

@ -120,7 +120,7 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
static float GetSampleRateForAudioContext(bool aIsOffline, float aSampleRate)
{
if (aIsOffline) {
if (aIsOffline || aSampleRate != 0.0) {
return aSampleRate;
} else {
return static_cast<float>(CubebUtils::PreferredSampleRate());
@ -197,6 +197,7 @@ AudioContext::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
/* static */ already_AddRefed<AudioContext>
AudioContext::Constructor(const GlobalObject& aGlobal,
const AudioContextOptions& aOptions,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
@ -205,10 +206,18 @@ AudioContext::Constructor(const GlobalObject& aGlobal,
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;
}
uint32_t maxChannelCount = std::min<uint32_t>(WebAudioUtils::MaxChannelCount,
CubebUtils::MaxNumberOfChannels());
RefPtr<AudioContext> object =
new AudioContext(window, false,maxChannelCount);
new AudioContext(window, false, maxChannelCount,
0, aOptions.mSampleRate);
aRv = object->Init();
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;

Просмотреть файл

@ -116,6 +116,7 @@ private:
};
enum class AudioContextOperation { Suspend, Resume, Close };
struct AudioContextOptions;
class AudioContext final : public DOMEventTargetHelper,
public nsIMemoryReporter,
@ -153,7 +154,9 @@ public:
// Constructor for regular AudioContext
static already_AddRefed<AudioContext>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
Constructor(const GlobalObject& aGlobal,
const AudioContextOptions& aOptions,
ErrorResult& aRv);
// Constructor for offline AudioContext with options object
static already_AddRefed<AudioContext>