Bug 836599 - Part 9: Implement the DOM binding for OfflineAudioContext; r=roc

This commit is contained in:
Ehsan Akhgari 2013-05-16 19:30:41 -04:00
Родитель 8d5f66955c
Коммит ee70633121
12 изменённых файлов: 200 добавлений и 5 удалений

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

@ -853,6 +853,11 @@ NON_IDL_EVENT(audioprocess,
EventNameType_None,
NS_EVENT)
NON_IDL_EVENT(complete,
NS_AUDIO_COMPLETE,
EventNameType_None,
NS_EVENT)
#ifdef DEFINED_FORWARDED_EVENT
#undef DEFINED_FORWARDED_EVENT
#undef FORWARDED_EVENT

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

@ -8,6 +8,8 @@
#include "nsContentUtils.h"
#include "nsPIDOMWindow.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/AudioContextBinding.h"
#include "mozilla/dom/OfflineAudioContextBinding.h"
#include "MediaStreamGraph.h"
#include "mozilla/dom/AnalyserNode.h"
#include "AudioDestinationNode.h"
@ -44,8 +46,9 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
static uint8_t gWebAudioOutputKey;
AudioContext::AudioContext(nsPIDOMWindow* aWindow)
AudioContext::AudioContext(nsPIDOMWindow* aWindow, bool aIsOffline)
: mDestination(new AudioDestinationNode(this, MediaStreamGraph::GetInstance()))
, mIsOffline(aIsOffline)
{
// Actually play audio
mDestination->Stream()->AddAudioOutput(&gWebAudioOutputKey);
@ -64,7 +67,11 @@ AudioContext::~AudioContext()
JSObject*
AudioContext::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return AudioContextBinding::Wrap(aCx, aScope, this);
if (mIsOffline) {
return OfflineAudioContextBinding::Wrap(aCx, aScope, this);
} else {
return AudioContextBinding::Wrap(aCx, aScope, this);
}
}
/* static */ already_AddRefed<AudioContext>
@ -76,7 +83,31 @@ AudioContext::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
return nullptr;
}
nsRefPtr<AudioContext> object = new AudioContext(window);
nsRefPtr<AudioContext> object = new AudioContext(window, false);
window->AddAudioContext(object);
return object.forget();
}
/* static */ already_AddRefed<AudioContext>
AudioContext::Constructor(const GlobalObject& aGlobal,
uint32_t aNumberOfChannels,
uint32_t aLength,
float aSampleRate,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.Get());
if (!window) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
if (aSampleRate != IdealAudioRate()) {
// TODO: Add support for running OfflineAudioContext at other sampling rates
aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
return nullptr;
}
nsRefPtr<AudioContext> object = new AudioContext(window, true);
window->AddAudioContext(object);
return object.forget();
}

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

@ -50,6 +50,7 @@ class DelayNode;
class DynamicsCompressorNode;
class GainNode;
class GlobalObject;
class OfflineRenderSuccessCallback;
class PannerNode;
class ScriptProcessorNode;
class WaveShaperNode;
@ -57,8 +58,8 @@ class WaveShaperNode;
class AudioContext MOZ_FINAL : public nsDOMEventTargetHelper,
public EnableWebAudioCheck
{
explicit AudioContext(nsPIDOMWindow* aParentWindow);
~AudioContext();
explicit AudioContext(nsPIDOMWindow* aParentWindow, bool aIsOffline);
virtual ~AudioContext();
public:
NS_DECL_ISUPPORTS_INHERITED
@ -77,9 +78,20 @@ public:
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
// Constructor for regular AudioContext
static already_AddRefed<AudioContext>
Constructor(const GlobalObject& aGlobal, ErrorResult& aRv);
// Constructor for offline AudioContext
static already_AddRefed<AudioContext>
Constructor(const GlobalObject& aGlobal,
uint32_t aNumberOfChannels,
uint32_t aLength,
float aSampleRate,
ErrorResult& aRv);
// AudioContext methods
AudioDestinationNode* Destination() const
{
return mDestination;
@ -164,6 +176,10 @@ public:
DecodeSuccessCallback& aSuccessCallback,
const Optional<OwningNonNull<DecodeErrorCallback> >& aFailureCallback);
// OfflineAudioContext methods
void StartRendering() {}
IMPL_EVENT_HANDLER(complete)
uint32_t GetRate() const { return IdealAudioRate(); }
MediaStreamGraph* Graph() const;
@ -193,6 +209,7 @@ private:
// Hashset containing all ScriptProcessorNodes in order to stop them.
// These are all weak pointers.
nsTHashtable<nsPtrHashKey<ScriptProcessorNode> > mScriptProcessorNodes;
bool mIsOffline;
};
}

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

@ -33,6 +33,7 @@ CPPSRCS := \
EnableWebAudioCheck.cpp \
GainNode.cpp \
MediaBufferDecoder.cpp \
OfflineAudioCompletionEvent.cpp \
PannerNode.cpp \
ScriptProcessorNode.cpp \
ThreeDPoint.cpp \

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

@ -0,0 +1,38 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#include "OfflineAudioCompletionEvent.h"
#include "mozilla/dom/OfflineAudioCompletionEventBinding.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED_1(OfflineAudioCompletionEvent, nsDOMEvent,
mRenderedBuffer)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(OfflineAudioCompletionEvent)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
NS_IMPL_ADDREF_INHERITED(OfflineAudioCompletionEvent, nsDOMEvent)
NS_IMPL_RELEASE_INHERITED(OfflineAudioCompletionEvent, nsDOMEvent)
OfflineAudioCompletionEvent::OfflineAudioCompletionEvent(AudioContext* aOwner,
nsPresContext* aPresContext,
nsEvent* aEvent)
: nsDOMEvent(aOwner, aPresContext, aEvent)
{
SetIsDOMBinding();
}
JSObject*
OfflineAudioCompletionEvent::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return OfflineAudioCompletionEventBinding::Wrap(aCx, aScope, this);
}
}
}

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

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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/. */
#ifndef OfflineAudioCompletionEvent_h_
#define OfflineAudioCompletionEvent_h_
#include "nsDOMEvent.h"
#include "AudioBuffer.h"
#include "AudioContext.h"
namespace mozilla {
namespace dom {
class OfflineAudioCompletionEvent : public nsDOMEvent,
public EnableWebAudioCheck
{
public:
OfflineAudioCompletionEvent(AudioContext* aOwner,
nsPresContext *aPresContext,
nsEvent *aEvent);
NS_DECL_ISUPPORTS_INHERITED
NS_FORWARD_TO_NSDOMEVENT
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(OfflineAudioCompletionEvent, nsDOMEvent)
virtual JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
AudioBuffer* RenderedBuffer()
{
return mRenderedBuffer;
}
private:
nsRefPtr<AudioBuffer> mRenderedBuffer;
};
}
}
#endif

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

@ -34,6 +34,7 @@ EXPORTS.mozilla.dom += [
'DynamicsCompressorNode.h',
'EnableWebAudioCheck.h',
'GainNode.h',
'OfflineAudioCompletionEvent.h',
'PannerNode.h',
'ScriptProcessorNode.h',
'WaveShaperNode.h',

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

@ -675,6 +675,17 @@ DOMInterfaces = {
'nativeType': 'nsDOMNotifyAudioAvailableEvent',
},
'OfflineAudioCompletionEvent': {
'resultNotAddRefed': [ 'renderedBuffer' ],
},
'OfflineAudioContext': {
'nativeType': 'mozilla::dom::AudioContext',
'implicitJSContext': [ 'createBuffer' ],
'nativeOwnership': 'refcounted',
'resultNotAddRefed': [ 'destination', 'listener' ],
},
'PaintRequest': {
'nativeType': 'nsPaintRequest',
},

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

@ -0,0 +1,19 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
[PrefControlled]
interface OfflineAudioCompletionEvent : Event {
readonly attribute AudioBuffer renderedBuffer;
};

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

@ -0,0 +1,24 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*
* The origin of this IDL file is
* https://dvcs.w3.org/hg/audio/raw-file/tip/webaudio/specification.html
*
* Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
* liability, trademark and document use rules apply.
*/
callback OfflineRenderSuccessCallback = void (AudioBuffer renderedData);
[Constructor(unsigned long numberOfChannels, unsigned long length, float sampleRate),
PrefControlled]
interface OfflineAudioContext : AudioContext {
void startRendering();
[SetterThrows]
attribute EventHandler oncomplete;
};

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

@ -178,6 +178,8 @@ webidl_files = \
Notification.webidl \
NotifyAudioAvailableEvent.webidl \
NotifyPaintEvent.webidl \
OfflineAudioCompletionEvent.webidl \
OfflineAudioContext.webidl \
PaintRequest.webidl \
PaintRequestList.webidl \
PannerNode.webidl \

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

@ -401,6 +401,7 @@ enum nsEventStructType {
#define NS_WEBAUDIO_EVENT_START 4350
#define NS_AUDIO_PROCESS (NS_WEBAUDIO_EVENT_START)
#define NS_AUDIO_COMPLETE (NS_WEBAUDIO_EVENT_START + 1)
// script notification events
#define NS_NOTIFYSCRIPT_START 4500