Bug 792646 - Implement the skeleton of Web Audio source and destination nodes; r=bzbarsky

This is the bare minimum that one needs in order to get those interfaces
implemented.  The work to make the simplest of Web Audio test cases
actually pass will be done in bug 792649.
This commit is contained in:
Ehsan Akhgari 2012-09-18 19:07:33 -04:00
Родитель eec0719f79
Коммит c461ff018e
20 изменённых файлов: 425 добавлений и 4 удалений

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

@ -0,0 +1,29 @@
/* -*- 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 "AudioBufferSourceNode.h"
#include "mozilla/dom/AudioBufferSourceNodeBinding.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS_INHERITED0(AudioBufferSourceNode, AudioSourceNode)
AudioBufferSourceNode::AudioBufferSourceNode(AudioContext* aContext)
: AudioSourceNode(aContext)
{
}
JSObject*
AudioBufferSourceNode::WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap)
{
return AudioBufferSourceNodeBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
}
}

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

@ -0,0 +1,31 @@
/* -*- 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/. */
#pragma once
#include "AudioSourceNode.h"
namespace mozilla {
namespace dom {
class AudioBufferSourceNode : public AudioSourceNode
{
public:
explicit AudioBufferSourceNode(AudioContext* aContext);
NS_DECL_ISUPPORTS_INHERITED
void NoteOn(double) { /* no-op for now */ }
void NoteOff(double) { /* no-op for now */ }
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap);
};
}
}

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

@ -9,11 +9,13 @@
#include "nsIDOMWindow.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/AudioContextBinding.h"
#include "AudioDestinationNode.h"
#include "AudioBufferSourceNode.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(AudioContext, mWindow)
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(AudioContext, mWindow, mDestination)
NS_IMPL_CYCLE_COLLECTING_ADDREF(AudioContext)
NS_IMPL_CYCLE_COLLECTING_RELEASE(AudioContext)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioContext)
@ -23,6 +25,7 @@ NS_INTERFACE_MAP_END
AudioContext::AudioContext(nsIDOMWindow* aWindow)
: mWindow(aWindow)
, mDestination(new AudioDestinationNode(this))
{
SetIsDOMBinding();
}
@ -52,6 +55,14 @@ AudioContext::Constructor(nsISupports* aGlobal, ErrorResult& aRv)
return object;
}
already_AddRefed<AudioBufferSourceNode>
AudioContext::CreateBufferSource()
{
nsRefPtr<AudioBufferSourceNode> bufferNode =
new AudioBufferSourceNode(this);
return bufferNode.forget();
}
}
}

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

@ -4,11 +4,14 @@
* 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/. */
#pragma once
#include "nsWrapperCache.h"
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Attributes.h"
#include "nsCOMPtr.h"
#include "EnableWebAudioCheck.h"
#include "nsAutoPtr.h"
class JSContext;
class nsIDOMWindow;
@ -19,6 +22,9 @@ class ErrorResult;
namespace dom {
class AudioDestinationNode;
class AudioBufferSourceNode;
class AudioContext MOZ_FINAL : public nsISupports,
public nsWrapperCache,
public EnableWebAudioCheck
@ -42,8 +48,16 @@ public:
static already_AddRefed<AudioContext>
Constructor(nsISupports* aGlobal, ErrorResult& aRv);
AudioDestinationNode* Destination() const
{
return mDestination;
}
already_AddRefed<AudioBufferSourceNode> CreateBufferSource();
private:
nsCOMPtr<nsIDOMWindow> mWindow;
nsRefPtr<AudioDestinationNode> mDestination;
};
}

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

@ -0,0 +1,29 @@
/* -*- 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 "AudioDestinationNode.h"
#include "mozilla/dom/AudioDestinationNodeBinding.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS_INHERITED0(AudioDestinationNode, AudioNode)
AudioDestinationNode::AudioDestinationNode(AudioContext* aContext)
: AudioNode(aContext)
{
}
JSObject*
AudioDestinationNode::WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap)
{
return AudioDestinationNodeBinding::Wrap(aCx, aScope, this, aTriedToWrap);
}
}
}

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

@ -0,0 +1,30 @@
/* -*- 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/. */
#pragma once
#include "AudioNode.h"
namespace mozilla {
namespace dom {
class AudioContext;
class AudioDestinationNode : public AudioNode
{
public:
explicit AudioDestinationNode(AudioContext* aContext);
NS_DECL_ISUPPORTS_INHERITED
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
bool* aTriedToWrap);
};
}
}

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

@ -0,0 +1,31 @@
/* -*- 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 "AudioNode.h"
#include "AudioContext.h"
#include "nsContentUtils.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(AudioNode, mContext)
NS_IMPL_CYCLE_COLLECTING_ADDREF(AudioNode)
NS_IMPL_CYCLE_COLLECTING_RELEASE(AudioNode)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioNode)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
AudioNode::AudioNode(AudioContext* aContext)
: mContext(aContext)
{
MOZ_ASSERT(aContext);
SetIsDOMBinding();
}
}
}

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

@ -0,0 +1,55 @@
/* -*- 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/. */
#pragma once
#include "nsWrapperCache.h"
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Attributes.h"
#include "EnableWebAudioCheck.h"
#include "nsAutoPtr.h"
#include "AudioContext.h"
struct JSContext;
namespace mozilla {
namespace dom {
class AudioNode : public nsISupports,
public nsWrapperCache,
public EnableWebAudioCheck
{
public:
explicit AudioNode(AudioContext* aContext);
virtual ~AudioNode() {}
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(AudioNode)
AudioContext* GetParentObject() const
{
return mContext;
}
AudioContext* Context() const
{
return mContext;
}
void Connect(AudioNode& aDestination, uint32_t aOutput,
uint32_t aInput)
{ /* no-op for now */ }
void Disconnect(uint32_t aOutput)
{ /* no-op for now */ }
private:
nsRefPtr<AudioContext> mContext;
};
}
}

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

@ -0,0 +1,21 @@
/* -*- 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 "AudioSourceNode.h"
namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS_INHERITED0(AudioSourceNode, AudioNode)
AudioSourceNode::AudioSourceNode(AudioContext* aContext)
: AudioNode(aContext)
{
}
}
}

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

@ -0,0 +1,25 @@
/* -*- 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/. */
#pragma once
#include "AudioNode.h"
namespace mozilla {
namespace dom {
class AudioSourceNode : public AudioNode
{
public:
explicit AudioSourceNode(AudioContext* aContext);
NS_DECL_ISUPPORTS_INHERITED
};
}
}

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

@ -4,6 +4,8 @@
* 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/. */
#pragma once
namespace mozilla {
namespace dom {

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

@ -15,10 +15,22 @@ LIBRARY_NAME := gkconwebaudio_s
LIBXUL_LIBRARY := 1
CPPSRCS := \
AudioBufferSourceNode.cpp \
AudioContext.cpp \
AudioDestinationNode.cpp \
AudioNode.cpp \
AudioSourceNode.cpp \
EnableWebAudioCheck.cpp \
$(NULL)
EXPORTS_NAMESPACES := mozilla/dom
EXPORTS_mozilla/dom := \
AudioBufferSourceNode.h \
AudioDestinationNode.h \
AudioNode.h \
AudioSourceNode.h \
$(NULL)
PARALLEL_DIRS := test
FORCE_STATIC_LIB := 1

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

@ -27,8 +27,13 @@
# at all).
# * concrete - Indicates whether there exist objects with this interface as
# their primary interface (defaults to True).
# * prefable - Indicates whether this binding is subject to the about:config
# pref, or whether it's always enabled (defaults to False).
# * prefable - Indicates whether this bindings should be disabled if the
# global pref for Web IDL bindings is set to false. This is a
# risk mitigation strategy and it will cause all of the Web IDL
# bindings marked as prefable to fall back to the xpconnect
# bindings in case something goes wrong. This defaults to False.
# Setting this on objects which only have Web IDL bindings does
# not make any sense.
# Cannot be set on external interfaces.
# * workers - Indicates whether the descriptor is intended to be used for
# worker threads (defaults to false).
@ -63,7 +68,20 @@ DOMInterfaces = {
'mozAudioContext': {
'nativeType': 'AudioContext',
'prefable': True,
},
'AudioNode' : {
'concrete': False,
},
'AudioSourceNode': {
'concrete': False,
},
'AudioBufferSourceNode': {
},
'AudioDestinationNode': {
},
'Blob': [

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

@ -4,6 +4,8 @@
* 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/. */
#pragma once
#include "nsWrapperCache.h"
#include "nsCycleCollectionParticipant.h"
#include "mozilla/Attributes.h"

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

@ -0,0 +1,35 @@
/* -*- 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 AudioBufferSourceNode : AudioSourceNode {
const unsigned short UNSCHEDULED_STATE = 0;
const unsigned short SCHEDULED_STATE = 1;
const unsigned short PLAYING_STATE = 2;
const unsigned short FINISHED_STATE = 3;
//readonly attribute unsigned short playbackState;
// Playback this in-memory audio asset
// Many sources can share the same buffer
//attribute AudioBuffer buffer;
//attribute AudioParam playbackRate;
//attribute boolean loop;
void noteOn(double when);
//void noteGrainOn(double when, double grainOffset, double grainDuration);
void noteOff(double when);
};

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

@ -12,5 +12,13 @@
[Constructor, PrefControlled]
interface mozAudioContext {
readonly attribute AudioDestinationNode destination;
// AudioNode creation
AudioBufferSourceNode createBufferSource();
};
typedef mozAudioContext AudioContext;

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

@ -0,0 +1,20 @@
/* -*- 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 AudioDestinationNode : AudioNode {
//readonly attribute unsigned long maxNumberOfChannels;
//attribute unsigned long numberOfChannels;
};

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

@ -0,0 +1,27 @@
/* -*- 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 AudioNode {
void connect(AudioNode destination, optional unsigned long output = 0, optional unsigned long input = 0);
//void connect(AudioParam destination, optional unsigned long output = 0);
void disconnect(optional unsigned long output = 0);
readonly attribute AudioContext context;
//readonly attribute unsigned long numberOfInputs;
//readonly attribute unsigned long numberOfOutputs;
};

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

@ -0,0 +1,17 @@
/* -*- 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 AudioSourceNode : AudioNode {
};

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

@ -9,7 +9,11 @@ generated_webidl_files = \
$(NULL)
webidl_files = \
AudioBufferSourceNode.webidl \
AudioContext.webidl \
AudioDestinationNode.webidl \
AudioNode.webidl \
AudioSourceNode.webidl \
Blob.webidl \
CanvasRenderingContext2D.webidl \
ClientRectList.webidl \