diff --git a/content/media/webaudio/AudioContext.cpp b/content/media/webaudio/AudioContext.cpp index 68114e569e99..fb590b1fd682 100644 --- a/content/media/webaudio/AudioContext.cpp +++ b/content/media/webaudio/AudioContext.cpp @@ -59,6 +59,7 @@ AudioContext::AudioContext(nsPIDOMWindow* aWindow, aLength, aSampleRate)) , mNumberOfChannels(aNumberOfChannels) , mIsOffline(aIsOffline) + , mIsStarted(!aIsOffline) { // Actually play audio mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey); @@ -595,10 +596,15 @@ AudioContext::GetJSContext() const } void -AudioContext::StartRendering() +AudioContext::StartRendering(ErrorResult& aRv) { MOZ_ASSERT(mIsOffline, "This should only be called on OfflineAudioContext"); + if (mIsStarted) { + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return; + } + mIsStarted = true; mDestination->StartRendering(); } diff --git a/content/media/webaudio/AudioContext.h b/content/media/webaudio/AudioContext.h index 19759604e339..69dd2c1ede9a 100644 --- a/content/media/webaudio/AudioContext.h +++ b/content/media/webaudio/AudioContext.h @@ -205,7 +205,7 @@ public: const Optional >& aFailureCallback); // OfflineAudioContext methods - void StartRendering(); + void StartRendering(ErrorResult& aRv); IMPL_EVENT_HANDLER(complete) bool IsOffline() const { return mIsOffline; } @@ -251,6 +251,7 @@ private: // Number of channels passed in the OfflineAudioContext ctor. uint32_t mNumberOfChannels; bool mIsOffline; + bool mIsStarted; }; } diff --git a/content/media/webaudio/test/test_OfflineAudioContext.html b/content/media/webaudio/test/test_OfflineAudioContext.html index 29c58edd80bc..3e0240f30fca 100644 --- a/content/media/webaudio/test/test_OfflineAudioContext.html +++ b/content/media/webaudio/test/test_OfflineAudioContext.html @@ -54,6 +54,10 @@ addLoadEvent(function() { compareBuffers(e.renderedBuffer.getChannelData(0), buf.getChannelData(0)); compareBuffers(e.renderedBuffer.getChannelData(1), buf.getChannelData(1)); + expectException(function() { + ctx.startRendering(); + }, DOMException.INVALID_STATE_ERR); + SimpleTest.finish(); }, false); }); diff --git a/dom/webidl/OfflineAudioContext.webidl b/dom/webidl/OfflineAudioContext.webidl index ee2ba3019d7e..1fa0d1cf87cd 100644 --- a/dom/webidl/OfflineAudioContext.webidl +++ b/dom/webidl/OfflineAudioContext.webidl @@ -1,4 +1,4 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. @@ -16,6 +16,7 @@ callback OfflineRenderSuccessCallback = void (AudioBuffer renderedData); PrefControlled] interface OfflineAudioContext : AudioContext { + [Throws] void startRendering(); attribute EventHandler oncomplete;