From fcb312ad9562a70ab42b571dd74cd5104ff2e8bf Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 6 Jul 2018 14:59:08 -0700 Subject: [PATCH 1/2] Expose disconnect methods as messages --- servo-media/src/audio/graph.rs | 2 +- servo-media/src/audio/render_thread.rs | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/servo-media/src/audio/graph.rs b/servo-media/src/audio/graph.rs index 8ba9aa47..266d38d1 100644 --- a/servo-media/src/audio/graph.rs +++ b/servo-media/src/audio/graph.rs @@ -145,7 +145,7 @@ impl AudioGraph { /// Disconnect all outgoing connections from a node /// /// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect - pub fn disconnect_all(&mut self, node: NodeId) { + pub fn disconnect_all_from(&mut self, node: NodeId) { let edges = self.graph .edges(node.0) .map(|e| e.id()) diff --git a/servo-media/src/audio/render_thread.rs b/servo-media/src/audio/render_thread.rs index 9032e4a9..2f5c6689 100644 --- a/servo-media/src/audio/render_thread.rs +++ b/servo-media/src/audio/render_thread.rs @@ -24,6 +24,12 @@ pub enum AudioRenderThreadMsg { Close(Sender), SinkNeedData, GetCurrentTime(Sender), + + DisconnectAllFrom(NodeId), + DisconnectOutput(PortId), + DisconnectBetween(NodeId, NodeId), + DisconnectOutputBetween(PortId, NodeId), + DisconnectOutputBetweenTo(PortId, PortId), } pub struct AudioRenderThread { @@ -123,6 +129,22 @@ impl AudioRenderThread { // Do nothing. This will simply unblock the thread so we // can restart the non-blocking event loop. } + + AudioRenderThreadMsg::DisconnectAllFrom(id) => { + context.graph.disconnect_all_from(id) + } + AudioRenderThreadMsg::DisconnectOutput(out) => { + context.graph.disconnect_output(out) + } + AudioRenderThreadMsg::DisconnectBetween(from, to) => { + context.graph.disconnect_between(from, to) + } + AudioRenderThreadMsg::DisconnectOutputBetween(from, to) => { + context.graph.disconnect_output_between(from, to) + } + AudioRenderThreadMsg::DisconnectOutputBetweenTo(from, to) => { + context.graph.disconnect_output_between_to(from, to) + } }; break_loop From 4a4fc5859733d8a06bef63034ce07994954736d4 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 6 Jul 2018 15:05:32 -0700 Subject: [PATCH 2/2] Expose on AudioContext --- servo-media/src/audio/context.rs | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/servo-media/src/audio/context.rs b/servo-media/src/audio/context.rs index 67c9ceb9..254ce785 100644 --- a/servo-media/src/audio/context.rs +++ b/servo-media/src/audio/context.rs @@ -179,6 +179,43 @@ impl AudioContext { .send(AudioRenderThreadMsg::ConnectPorts(from, to)); } + pub fn disconnect_all_from(&self, node: NodeId) { + let _ = self.sender + .send(AudioRenderThreadMsg::DisconnectAllFrom(node)); + } + + // /// Disconnect all outgoing connections from a node's output + // /// + // /// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-output + pub fn disconnect_output(&self, out: PortId) { + let _ = self.sender + .send(AudioRenderThreadMsg::DisconnectOutput(out)); + } + + /// Disconnect connections from a node to another node + /// + /// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode + pub fn disconnect_between(&self, from: NodeId, to: NodeId) { + let _ = self.sender + .send(AudioRenderThreadMsg::DisconnectBetween(from, to)); + } + + /// Disconnect all outgoing connections from a node's output to another node + /// + /// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode-output + pub fn disconnect_output_between(&self, out: PortId, to: NodeId) { + let _ = self.sender + .send(AudioRenderThreadMsg::DisconnectOutputBetween(out, to)); + } + + // /// Disconnect all outgoing connections from a node's output to another node's input + // /// + // /// https://webaudio.github.io/web-audio-api/#dom-audionode-disconnect-destinationnode-output-input + pub fn disconnect_output_between_to(&self, out: PortId, inp: PortId) { + let _ = self.sender + .send(AudioRenderThreadMsg::DisconnectOutputBetweenTo(out, inp)); + } + /// Asynchronously decodes the audio file data contained in the given /// buffer. pub fn decode_audio_data(&self, data: Vec, callbacks: AudioDecoderCallbacks) {