void AudioNode::DisconnectFromGraph() { // Addref this temporarily so the refcount bumping below doesn't destroy us // prematurely nsRefPtr<AudioNode> kungFuDeathGrip = this; // The idea here is that we remove connections one by one, and at each step // the graph is in a valid state. // Disconnect inputs. We don't need them anymore. while (!mInputNodes.IsEmpty()) { size_t i = mInputNodes.Length() - 1; nsRefPtr<AudioNode> input = mInputNodes[i].mInputNode; mInputNodes.RemoveElementAt(i); input->mOutputNodes.RemoveElement(this); } while (!mOutputNodes.IsEmpty()) { size_t i = mOutputNodes.Length() - 1; nsRefPtr<AudioNode> output = mOutputNodes[i].forget(); mOutputNodes.RemoveElementAt(i); size_t inputIndex = FindIndexOfNode(output->mInputNodes, this); // It doesn't matter which one we remove, since we're going to remove all // entries for this node anyway. output->mInputNodes.RemoveElementAt(inputIndex); // This effects of this connection will remain. output->NotifyHasPhantomInput(); } while (!mOutputParams.IsEmpty()) { size_t i = mOutputParams.Length() - 1; nsRefPtr<AudioParam> output = mOutputParams[i].forget(); mOutputParams.RemoveElementAt(i); size_t inputIndex = FindIndexOfNode(output->InputNodes(), this); // It doesn't matter which one we remove, since we're going to remove all // entries for this node anyway. output->RemoveInputNode(inputIndex); } DestroyMediaStream(); }
void AudioNode::DisconnectFromGraph() { MOZ_ASSERT(mRefCnt.get() > mInputNodes.Length(), "Caller should be holding a reference"); // The idea here is that we remove connections one by one, and at each step // the graph is in a valid state. // Disconnect inputs. We don't need them anymore. while (!mInputNodes.IsEmpty()) { size_t i = mInputNodes.Length() - 1; RefPtr<AudioNode> input = mInputNodes[i].mInputNode; mInputNodes.RemoveElementAt(i); input->mOutputNodes.RemoveElement(this); } while (!mOutputNodes.IsEmpty()) { size_t i = mOutputNodes.Length() - 1; RefPtr<AudioNode> output = mOutputNodes[i].forget(); mOutputNodes.RemoveElementAt(i); size_t inputIndex = FindIndexOfNode(output->mInputNodes, this); // It doesn't matter which one we remove, since we're going to remove all // entries for this node anyway. output->mInputNodes.RemoveElementAt(inputIndex); // This effects of this connection will remain. output->NotifyHasPhantomInput(); } while (!mOutputParams.IsEmpty()) { size_t i = mOutputParams.Length() - 1; RefPtr<AudioParam> output = mOutputParams[i].forget(); mOutputParams.RemoveElementAt(i); size_t inputIndex = FindIndexOfNode(output->InputNodes(), this); // It doesn't matter which one we remove, since we're going to remove all // entries for this node anyway. output->RemoveInputNode(inputIndex); } DestroyMediaStream(); }