forked from jsantell/firefox-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1068270-connect-disconnect-audionodeactors.patch
217 lines (203 loc) · 7.21 KB
/
1068270-connect-disconnect-audionodeactors.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
From 5814b498a13401454a02fd555ba6ab8b0f554738 Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Tue, 14 Oct 2014 14:25:26 -0700
Subject: Bug 1068270 - Add connectNode and disconnect methods to AudioNodeActor, r=vp
---
browser/devtools/webaudioeditor/test/browser.ini | 1 +
...owser_audionode-actor-connectnode-disconnect.js | 44 +++++++++++++++++
toolkit/devtools/server/actors/webaudio.js | 57 +++++++++++++++++++++-
3 files changed, 101 insertions(+), 1 deletion(-)
create mode 100644 browser/devtools/webaudioeditor/test/browser_audionode-actor-connectnode-disconnect.js
diff --git a/browser/devtools/webaudioeditor/test/browser.ini b/browser/devtools/webaudioeditor/test/browser.ini
index b2ec41b..438accd 100644
--- a/browser/devtools/webaudioeditor/test/browser.ini
+++ b/browser/devtools/webaudioeditor/test/browser.ini
@@ -17,16 +17,17 @@ support-files =
[browser_audionode-actor-get-param-flags.js]
[browser_audionode-actor-get-params-01.js]
[browser_audionode-actor-get-params-02.js]
[browser_audionode-actor-get-set-param.js]
[browser_audionode-actor-get-type.js]
[browser_audionode-actor-is-source.js]
[browser_audionode-actor-bypass.js]
+[browser_audionode-actor-connectnode-disconnect.js]
[browser_webaudio-actor-simple.js]
[browser_webaudio-actor-destroy-node.js]
[browser_webaudio-actor-connect-param.js]
[browser_wa_destroy-node-01.js]
[browser_wa_first-run.js]
[browser_wa_reset-01.js]
diff --git a/browser/devtools/webaudioeditor/test/browser_audionode-actor-connectnode-disconnect.js b/browser/devtools/webaudioeditor/test/browser_audionode-actor-connectnode-disconnect.js
new file mode 100644
index 0000000..b3da4e9
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/browser_audionode-actor-connectnode-disconnect.js
@@ -0,0 +1,44 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests that AudioNodeActor#connectNode() and AudioNodeActor#disconnect() work.
+ * Uses the editor front as the actors do not retain connect state.
+ */
+
+function spawnTest() {
+ let { target, panel } = yield initWebAudioEditor(SIMPLE_CONTEXT_URL);
+ let { panelWin } = panel;
+ let { gFront, $, $$, EVENTS, gAudioNodes } = panelWin;
+
+ reload(target);
+
+ let [actors] = yield Promise.all([
+ get3(gFront, "create-node"),
+ waitForGraphRendered(panelWin, 3, 2)
+ ]);
+
+ let [dest, osc, gain] = actors;
+
+ info("Disconnecting oscillator...");
+ osc.disconnect();
+ yield Promise.all([
+ waitForGraphRendered(panelWin, 3, 1),
+ once(gAudioNodes, "disconnect")
+ ]);
+ ok(true, "Oscillator disconnected, event emitted.");
+
+
+ info("Reconnecting oscillator...");
+ osc.connectNode(gain);
+ yield Promise.all([
+ waitForGraphRendered(panelWin, 3, 2),
+ once(gAudioNodes, "connect")
+ ]);
+ ok(true, "Oscillator reconnected.");
+
+
+ yield teardown(panel);
+ finish();
+}
+
diff --git a/toolkit/devtools/server/actors/webaudio.js b/toolkit/devtools/server/actors/webaudio.js
index f30fd41..b276d91 100644
--- a/toolkit/devtools/server/actors/webaudio.js
+++ b/toolkit/devtools/server/actors/webaudio.js
@@ -10,17 +10,17 @@ const Services = require("Services");
const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
const events = require("sdk/event/core");
const { on: systemOn, off: systemOff } = require("sdk/system/events");
const protocol = require("devtools/server/protocol");
const { CallWatcherActor, CallWatcherFront } = require("devtools/server/actors/call-watcher");
const { ThreadActor } = require("devtools/server/actors/script");
const { on, once, off, emit } = events;
-const { method, Arg, Option, RetVal } = protocol;
+const { types, method, Arg, Option, RetVal } = protocol;
const AUDIO_GLOBALS = [
"AudioContext", "AudioNode"
];
const NODE_CREATION_METHODS = [
"createBufferSource", "createMediaElementSource", "createMediaStreamSource",
"createMediaStreamDestination", "createScriptProcessor", "createAnalyser",
@@ -104,16 +104,17 @@ const NODE_PROPERTIES = {
"stream": { "MediaStream": true }
}
};
/**
* An Audio Node actor allowing communication to a specific audio node in the
* Audio Context graph.
*/
+types.addActorType("audionode");
let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
typeName: "audionode",
/**
* Create the Audio Node actor.
*
* @param DebuggerServerConnection conn
* The server connection.
@@ -284,17 +285,70 @@ let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
* corresponding to a property name and current value of the audio node.
*/
getParams: method(function (param) {
let props = Object.keys(NODE_PROPERTIES[this.type]);
return props.map(prop =>
({ param: prop, value: this.getParam(prop), flags: this.getParamFlags(prop) }));
}, {
response: { params: RetVal("json") }
+ }),
+
+ /**
+ * Connects this audionode to another via `node.connect(dest)`.
+ */
+ connectNode: method(function (destActor, output, input) {
+ let srcNode = this.node.get();
+ let destNode = destActor.node.get();
+
+ if (srcNode === null || destNode === null) {
+ return CollectedAudioNodeError();
+ }
+
+ try {
+ // Connect via the unwrapped node, so we can call the
+ // patched method that fires the webaudio actor's `connect-node` event.
+ // Connect directly to the wrapped `destNode`, otherwise
+ // the patched method thinks this is a new node and won't be
+ // able to find it in `_nativeToActorID`.
+ XPCNativeWrapper.unwrap(srcNode).connect(destNode, output, input);
+ } catch (e) {
+ return constructError(e);
+ }
+ }, {
+ request: {
+ destActor: Arg(0, "audionode"),
+ output: Arg(1, "nullable:number"),
+ input: Arg(2, "nullable:number")
+ },
+ response: { error: RetVal("nullable:json") }
+ }),
+
+ /**
+ * Disconnects this audionode from all connections via `node.disconnect()`.
+ */
+ disconnect: method(function (destActor, output) {
+ let node = this.node.get();
+
+ if (node === null) {
+ return CollectedAudioNodeError();
+ }
+
+ try {
+ // Disconnect via the unwrapped node, so we can call the
+ // patched method that fires the webaudio actor's `disconnect` event.
+ XPCNativeWrapper.unwrap(node).disconnect(output);
+ } catch (e) {
+ return constructError(e);
+ }
+ }, {
+ request: { output: Arg(0, "nullable:number") },
+ response: { error: RetVal("nullable:json") }
})
+
});
/**
* The corresponding Front object for the AudioNodeActor.
*/
let AudioNodeFront = protocol.FrontClass(AudioNodeActor, {
initialize: function (client, form) {
protocol.Front.prototype.initialize.call(this, client, form);
@@ -548,16 +602,17 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
},
/**
* Called when one audio node is connected to another.
*/
_onConnectNode: function (source, dest) {
let sourceActor = this._getActorByNativeID(source.id);
let destActor = this._getActorByNativeID(dest.id);
+
emit(this, "connect-node", {
source: sourceActor,
dest: destActor
});
},
/**
* Called when an audio node is connected to an audio param.
--
1.8.4.2