Skip to content

Commit

Permalink
Bug 11130010 - Backout new AudioNode.disconnect methods; r=mreavy,kar…
Browse files Browse the repository at this point in the history
…lt,smaug

MozReview-Commit-ID: AgHScRbICYU
  • Loading branch information
dminor committed Aug 16, 2016
1 parent 2fcc30f commit 2b5cd10
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 745 deletions.
242 changes: 37 additions & 205 deletions dom/media/webaudio/AudioNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,14 @@ AudioNode::SendChannelMixingParametersToStream()
}
}

bool
AudioNode::DisconnectFromOutputIfConnected(AudioNode& aDestination, uint32_t aOutputIndex, uint32_t aInputIndex)
void
AudioNode::Disconnect(uint32_t aOutput, ErrorResult& aRv)
{
if (aOutput >= NumberOfOutputs()) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}

WEB_AUDIO_API_LOG("%f: %s %u Disconnect()", Context()->CurrentTime(),
NodeType(), Id());

Expand All @@ -317,222 +322,49 @@ AudioNode::DisconnectFromOutputIfConnected(AudioNode& aDestination, uint32_t aOu
RefPtr<AudioNode> mNode;
};

InputNode& input = aDestination.mInputNodes[aInputIndex];
if (input.mInputNode != this) {
return false;
}
// RunAfterPendingUpdates() call below.
aDestination.mInputNodes.RemoveElementAt(aInputIndex);
// Remove one instance of 'dest' from mOutputNodes. There could be
// others, and it's not correct to remove them all since some of them
// could be for different output ports.
RefPtr<AudioNode> output = mOutputNodes[aOutputIndex].forget();
mOutputNodes.RemoveElementAt(aOutputIndex);
if (mStream) {
nsCOMPtr<nsIRunnable> runnable = new RunnableRelease(output.forget());
mStream->RunAfterPendingUpdates(runnable.forget());
}
return true;
}

bool
AudioNode::DisconnectFromParamIfConnected(AudioParam& aDestination, uint32_t aOutputIndex, uint32_t aInputIndex)
{
MOZ_ASSERT(aOutputIndex < mOutputParams.Length());
MOZ_ASSERT(aInputIndex < aDestination.InputNodes().Length());

const InputNode& input = aDestination.InputNodes()[aInputIndex];
if (input.mInputNode != this) {
return false;
}
aDestination.RemoveInputNode(aInputIndex);
// Remove one instance of 'dest' from mOutputParams. There could be
// others, and it's not correct to remove them all since some of them
// could be for different output ports.
mOutputParams.RemoveElementAt(aOutputIndex);
return true;
}

void
AudioNode::Disconnect(ErrorResult& aRv)
{
for (int32_t outputIndex = mOutputNodes.Length() - 1; outputIndex >= 0; --outputIndex) {
AudioNode* dest = mOutputNodes[outputIndex];
for (int32_t inputIndex = dest->mInputNodes.Length() - 1; inputIndex >= 0; --inputIndex) {
DisconnectFromOutputIfConnected(*dest, outputIndex, inputIndex);
}
}

for (int32_t outputIndex = mOutputParams.Length() - 1; outputIndex >= 0; --outputIndex) {
AudioParam* dest = mOutputParams[outputIndex];
for (int32_t inputIndex = dest->InputNodes().Length() - 1; inputIndex >= 0; --inputIndex) {
DisconnectFromParamIfConnected(*dest, outputIndex, inputIndex);
}
}

// This disconnection may have disconnected a panner and a source.
Context()->UpdatePannerSource();
}

void
AudioNode::Disconnect(uint32_t aOutput, ErrorResult& aRv)
{
if (aOutput >= NumberOfOutputs()) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}

for (int32_t outputIndex = mOutputNodes.Length() - 1; outputIndex >= 0; --outputIndex) {
AudioNode* dest = mOutputNodes[outputIndex];
for (int32_t inputIndex = dest->mInputNodes.Length() - 1; inputIndex >= 0; --inputIndex) {
InputNode& input = dest->mInputNodes[inputIndex];
if (input.mOutputPort == aOutput) {
DisconnectFromOutputIfConnected(*dest, outputIndex, inputIndex);
}
}
}

for (int32_t outputIndex = mOutputParams.Length() - 1; outputIndex >= 0; --outputIndex) {
AudioParam* dest = mOutputParams[outputIndex];
for (int32_t inputIndex = dest->InputNodes().Length() - 1; inputIndex >= 0; --inputIndex) {
const InputNode& input = dest->InputNodes()[inputIndex];
if (input.mOutputPort == aOutput) {
DisconnectFromParamIfConnected(*dest, outputIndex, inputIndex);
}
}
}

// This disconnection may have disconnected a panner and a source.
Context()->UpdatePannerSource();
}

void
AudioNode::Disconnect(AudioNode& aDestination, ErrorResult& aRv)
{
bool wasConnected = false;

size_t outputIndex = mOutputNodes.IndexOf(&aDestination);
if (outputIndex == nsTArray<InputNode>::NoIndex) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return;
}
for (int32_t inputIndex = aDestination.mInputNodes.Length() - 1; inputIndex >= 0; --inputIndex) {
wasConnected |= DisconnectFromOutputIfConnected(aDestination, outputIndex, inputIndex);
}

if (!wasConnected) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return;
}

// This disconnection may have disconnected a panner and a source.
Context()->UpdatePannerSource();
}

void
AudioNode::Disconnect(AudioNode& aDestination, uint32_t aOutput, ErrorResult& aRv)
{
if (aOutput >= NumberOfOutputs()) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}

bool wasConnected = false;

for (int32_t outputIndex = mOutputNodes.Length() - 1; outputIndex >= 0; --outputIndex) {
for (int32_t inputIndex = aDestination.mInputNodes.Length() - 1; inputIndex >= 0; --inputIndex) {
InputNode& input = aDestination.mInputNodes[inputIndex];
if (input.mOutputPort == aOutput) {
wasConnected |= DisconnectFromOutputIfConnected(aDestination, outputIndex, inputIndex);
for (int32_t i = mOutputNodes.Length() - 1; i >= 0; --i) {
AudioNode* dest = mOutputNodes[i];
for (int32_t j = dest->mInputNodes.Length() - 1; j >= 0; --j) {
InputNode& input = dest->mInputNodes[j];
if (input.mInputNode == this && input.mOutputPort == aOutput) {
// Destroying the InputNode here sends a message to the graph thread
// to disconnect the streams, which should be sent before the
// RunAfterPendingUpdates() call below.
dest->mInputNodes.RemoveElementAt(j);
// Remove one instance of 'dest' from mOutputNodes. There could be
// others, and it's not correct to remove them all since some of them
// could be for different output ports.
RefPtr<AudioNode> output = mOutputNodes[i].forget();
mOutputNodes.RemoveElementAt(i);
output->NotifyInputsChanged();
if (mStream) {
RefPtr<nsIRunnable> runnable = new RunnableRelease(output.forget());
mStream->RunAfterPendingUpdates(runnable.forget());
}
break;
}
}
}

if (!wasConnected) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return;
}

// This disconnection may have disconnected a panner and a source.
Context()->UpdatePannerSource();
}

void
AudioNode::Disconnect(AudioNode& aDestination, uint32_t aOutput, uint32_t aInput, ErrorResult& aRv)
{
if (aOutput >= NumberOfOutputs()) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}

if (aInput >= aDestination.NumberOfInputs()) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}

bool wasConnected = false;

for (int32_t outputIndex = mOutputNodes.Length() - 1; outputIndex >= 0; --outputIndex) {
for (int32_t inputIndex = aDestination.mInputNodes.Length() - 1; inputIndex >= 0; --inputIndex) {
InputNode& input = aDestination.mInputNodes[inputIndex];
if (input.mOutputPort == aOutput && input.mInputPort == aInput) {
wasConnected |= DisconnectFromOutputIfConnected(aDestination, outputIndex, inputIndex);
for (int32_t i = mOutputParams.Length() - 1; i >= 0; --i) {
AudioParam* dest = mOutputParams[i];
for (int32_t j = dest->InputNodes().Length() - 1; j >= 0; --j) {
const InputNode& input = dest->InputNodes()[j];
if (input.mInputNode == this && input.mOutputPort == aOutput) {
dest->RemoveInputNode(j);
// Remove one instance of 'dest' from mOutputParams. There could be
// others, and it's not correct to remove them all since some of them
// could be for different output ports.
mOutputParams.RemoveElementAt(i);
break;
}
}
}

if (!wasConnected) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return;
}

// This disconnection may have disconnected a panner and a source.
Context()->UpdatePannerSource();
}

void
AudioNode::Disconnect(AudioParam& aDestination, ErrorResult& aRv)
{
bool wasConnected = false;

for (int32_t outputIndex = mOutputParams.Length() - 1; outputIndex >= 0; --outputIndex) {
for (int32_t inputIndex = aDestination.InputNodes().Length() - 1; inputIndex >= 0; --inputIndex) {
wasConnected |= DisconnectFromParamIfConnected(aDestination, outputIndex, inputIndex);
}
}

if (!wasConnected) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return;
}
}

void
AudioNode::Disconnect(AudioParam& aDestination, uint32_t aOutput, ErrorResult& aRv)
{
if (aOutput >= NumberOfOutputs()) {
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
return;
}

bool wasConnected = false;

for (int32_t outputIndex = mOutputParams.Length() - 1; outputIndex >= 0; --outputIndex) {
for (int32_t inputIndex = aDestination.InputNodes().Length() - 1; inputIndex >= 0; --inputIndex) {
const InputNode& input = aDestination.InputNodes()[inputIndex];
if (input.mOutputPort == aOutput) {
wasConnected |= DisconnectFromParamIfConnected(aDestination, outputIndex, inputIndex);
}
}
}

if (!wasConnected) {
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
return;
}
}

void
AudioNode::DestroyMediaStream()
{
Expand Down
12 changes: 0 additions & 12 deletions dom/media/webaudio/AudioNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,7 @@ class AudioNode : public DOMEventTargetHelper,
virtual void Connect(AudioParam& aDestination, uint32_t aOutput,
ErrorResult& aRv);

virtual void Disconnect(ErrorResult& aRv);
virtual void Disconnect(uint32_t aOutput, ErrorResult& aRv);
virtual void Disconnect(AudioNode& aDestination, ErrorResult& aRv);
virtual void Disconnect(AudioNode& aDestination, uint32_t aOutput,
ErrorResult& aRv);
virtual void Disconnect(AudioNode& aDestination,
uint32_t aOutput, uint32_t aInput,
ErrorResult& aRv);
virtual void Disconnect(AudioParam& aDestination, ErrorResult& aRv);
virtual void Disconnect(AudioParam& aDestination, uint32_t aOutput,
ErrorResult& aRv);

// Called after input nodes have been explicitly added or removed through
// the Connect() or Disconnect() methods.
Expand Down Expand Up @@ -230,8 +220,6 @@ class AudioNode : public DOMEventTargetHelper,
}
// Callers must hold a reference to 'this'.
void DisconnectFromGraph();
bool DisconnectFromOutputIfConnected(AudioNode& aDestination, uint32_t aOutputIndex, uint32_t aInputIndex);
bool DisconnectFromParamIfConnected(AudioParam& aDestination, uint32_t aOutputIndex, uint32_t aInputIndex);

protected:
// Helpers for sending different value types to streams
Expand Down
36 changes: 5 additions & 31 deletions dom/media/webaudio/ScriptProcessorNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ class ScriptProcessorNode final : public AudioNode
UpdateConnectedStatus();
}
}
void Disconnect(ErrorResult& aRv) override
{
AudioNode::Disconnect(aRv);
UpdateConnectedStatus();
}

void Disconnect(uint32_t aOutput, ErrorResult& aRv) override
{
AudioNode::Disconnect(aOutput, aRv);
UpdateConnectedStatus();
if (!aRv.Failed()) {
UpdateConnectedStatus();
}
}
void NotifyInputsChanged() override
{
Expand All @@ -70,31 +68,7 @@ class ScriptProcessorNode final : public AudioNode
// No need to UpdateConnectedStatus() because there was previously an
// input in InputNodes().
}
void Disconnect(AudioNode& aDestination, ErrorResult& aRv) override
{
AudioNode::Disconnect(aDestination, aRv);
UpdateConnectedStatus();
}
void Disconnect(AudioNode& aDestination, uint32_t aOutput, ErrorResult& aRv) override
{
AudioNode::Disconnect(aDestination, aOutput, aRv);
UpdateConnectedStatus();
}
void Disconnect(AudioNode& aDestination, uint32_t aOutput, uint32_t aInput, ErrorResult& aRv) override
{
AudioNode::Disconnect(aDestination, aOutput, aInput, aRv);
UpdateConnectedStatus();
}
void Disconnect(AudioParam& aDestination, ErrorResult& aRv) override
{
AudioNode::Disconnect(aDestination, aRv);
UpdateConnectedStatus();
}
void Disconnect(AudioParam& aDestination, uint32_t aOutput, ErrorResult& aRv) override
{
AudioNode::Disconnect(aDestination, aOutput, aRv);
UpdateConnectedStatus();
}

void SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv) override
{
if (aChannelCount != ChannelCount()) {
Expand Down
8 changes: 0 additions & 8 deletions dom/media/webaudio/test/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,6 @@ skip-if = toolkit == 'android' # bug 1056706
[test_delayNodeTailWithGain.html]
[test_delayNodeTailWithReconnect.html]
[test_delayNodeWithGain.html]
[test_disconnectAll.html]
[test_disconnectAudioParam.html]
[test_disconnectAudioParamFromOutput.html]
[test_disconnectExceptions.html]
[test_disconnectFromAudioNode.html]
[test_disconnectFromAudioNodeAndOutput.html]
[test_disconnectFromAudioNodeAndOutputAndInput.html]
[test_disconnectFromOutput.html]
[test_dynamicsCompressorNode.html]
[test_dynamicsCompressorNodePassThrough.html]
[test_dynamicsCompressorNodeWithGain.html]
Expand Down
Loading

0 comments on commit 2b5cd10

Please sign in to comment.