See bug 980506 for an extensive discussion about this. This patch adds
three APIs to AudioNode in order for us to be able to build awesome
devtools on top of it.
* Weak reference API.
This patch allows one to hold a weak reference to all AudioNode's
using Components.utils.getWeakReference(). That way, the devtool's
inspection code would not change the lifetime of AudioNodes.
* AudioNode.id
This is a chrome-only unique and monotonically incrementing ID for
AudioNode objects. It is supposed to be used in order for the
devtools to be able to identify a node without having to keep it
alive.
* webaudio-node-demise
This is an observer notification that is called every time an
AudioNode gets destroyed inside Gecko. The ID of the corresponding
node is passed to this notification.
--HG--
extra : rebase_source : 83246a990489daf44ddc97dd4ea372a8cebe8e00
See bug 980506 for an extensive discussion about this. This patch adds
three APIs to AudioNode in order for us to be able to build awesome
devtools on top of it.
* Weak reference API.
This patch allows one to hold a weak reference to all AudioNode's
using Components.utils.getWeakReference(). That way, the devtool's
inspection code would not change the lifetime of AudioNodes.
* AudioNode.id
This is a chrome-only unique and monotonically incrementing ID for
AudioNode objects. It is supposed to be used in order for the
devtools to be able to identify a node without having to keep it
alive.
* webaudio-node-demise
This is an observer notification that is called every time an
AudioNode gets destroyed inside Gecko. The ID of the corresponding
node is passed to this notification.
This patch was mostly generated with the following command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e '/WrapObject(JSContext/ {; N; s/\(WrapObject(JSContext *\* *a\{0,1\}[Cc]x\),\n\{0,1\} *JS::Handle<JSObject\*> a\{0,1\}[sS]cope/\1/ ; }' -i ""
and then reverting the changes that made to
dom/bindings/BindingUtils.h, since those WrapObject methods are not
the ones we're trying to change here, plus a bunch of manual fixups
for cases that this command did not catch (including all the callsites
of WrapObject()).
This means that the graph will be shutdown properly, even if the
AudioDestinationNode is unlinked before AudioContext::Shutdown() is called.
Making MediaStreamGraph::DestroyNonRealtimeInstance() idempotent also makes
AudioContext::Shutdown() idempotent.
--HG--
extra : transplant_source : jZ%86%C5%C2n%17%EF%C2%C0y%ED%14%0E%17_dt%0C%07
Here we make the non-realtime graphs to go to sleep until they're shut down
from the main thread. This allows us to use the common forced shutdown code
path in MediaStreamGraphImpl::RunThread. We also need to delete the graph
object when the last message is dispatched to it.
In addition, we need to make sure that the AudioNodes also get released when
they're no longer needed. To do this, we need for force the SelfReference of
AudioBufferSourceNodes to be released when the context is shut down, and also
trigger the destruction of the graph there.
We offload most of the logic for OfflineAudioContext to the destination node,
since that's where the sample recording needs to happen, so doing this will
make the code simpler.
The ObtainInputBlock API is also changed to create an input block for one input
block at a time. An array of these input blocks is then sent to
ProduceAudioBlock for processing, which generates an array of AudioChunks as
output.
Backwards compatibilty with existing engines is achieved by keeping the
existing ProduceAudioBlock API for use with engines with only a maximum of one
input and output port.
Here is what this patch does:
* Got rid of the JSBindingFinalized stuff
* Made all nodes wrappercached
* Started to hold a self reference while the AudioBufferSourceNode is playing back
* Converted the input references to weak references
* Got rid of all of the SetProduceOwnOutput and UpdateOutputEnded logic
The nodes are now collected by the cycle collector which calls into
DisconnectFromGraph which drops the references to other nodes and destroys the
media stream. Note that most of the cycles that are now inherent in the
ownership model are between nodes and their AudioParams (that is, the cycles
not created by content.)
This is a mega-patch that was too hard to disentangle. Here's what it does:
-- Create infrastructure around AudioNode::UpdateOutputEnded to detect
when a node can no longer produce any output. When that becomes true,
disconnect it from the AudioNode graph.
-- Have AudioNode implement JSBindingFinalized to use as input in
UpdateOutputEnded.
-- Give every AudioNode a MediaStream, and give every connection
a MediaInputPort.
-- Actually play the audio that reaches the AudioContext's destination node.
-- Force AudioContext to use the audio sample rate defined by MediaStreamGraph.
-- Fix AudioBufferSourceNode's start and stop methods to possibly throw and
take default 'when' parameters.
-- Create an AudioNodeStream for AudioBufferSourceNode and give it a
AudioBufferSourceNodeEngine that does what's needed. Set parameters for
this engine in the start() and stop() methods.
-- Create AudioBuffer::GetThreadSharedChannelsForRate, which is responsible
for stealing the contents of any JS array buffers, and bundling them up
into a thread-shared read-only buffer object which can be used as
part of an AudioChunk. This method will also be responsible for
resampling and caching as necessary.
--HG--
rename : content/media/MediaStreamGraph.cpp => content/media/MediaStreamGraphImpl.h
extra : rebase_source : 9fa0ec0efa304acd6513e427103d6339c78efa53
This is a mega-patch that was too hard to disentangle. Here's what it does:
-- Create infrastructure around AudioNode::UpdateOutputEnded to detect
when a node can no longer produce any output. When that becomes true,
disconnect it from the AudioNode graph.
-- Have AudioNode implement JSBindingFinalized to use as input in
UpdateOutputEnded.
-- Give every AudioNode a MediaStream, and give every connection
a MediaInputPort.
-- Actually play the audio that reaches the AudioContext's destination node.
-- Force AudioContext to use the audio sample rate defined by MediaStreamGraph.
-- Fix AudioBufferSourceNode's start and stop methods to possibly throw and
take default 'when' parameters.
-- Create an AudioNodeStream for AudioBufferSourceNode and give it a
AudioBufferSourceNodeEngine that does what's needed. Set parameters for
this engine in the start() and stop() methods.
-- Create AudioBuffer::GetThreadSharedChannelsForRate, which is responsible
for stealing the contents of any JS array buffers, and bundling them up
into a thread-shared read-only buffer object which can be used as
part of an AudioChunk. This method will also be responsible for
resampling and caching as necessary.
Here's what this patch does:
-- Makes AudioNodes mostly not use nsWrapperCache. AudioDestinationNode
still does.
-- Rename MaxNumberOfInputs/Outputs to NumberOfInputs/Outputs, and have them
default to 1 in AudioNode.
-- Allow any number of nodes to be connected to any given input/output port.