void
AudioBufferSourceNode::NotifyMainThreadStateChanged()
{
  if (mStream->IsFinished()) {
    class EndedEventDispatcher : public nsRunnable
    {
    public:
      explicit EndedEventDispatcher(AudioBufferSourceNode* aNode)
        : mNode(aNode) {}
      NS_IMETHODIMP Run()
      {
        // If it's not safe to run scripts right now, schedule this to run later
        if (!nsContentUtils::IsSafeToRunScript()) {
          nsContentUtils::AddScriptRunner(this);
          return NS_OK;
        }

        mNode->DispatchTrustedEvent(NS_LITERAL_STRING("ended"));
        return NS_OK;
      }
    private:
      nsRefPtr<AudioBufferSourceNode> mNode;
    };
    if (!mStopped) {
      // Only dispatch the ended event once
      NS_DispatchToMainThread(new EndedEventDispatcher(this));
      mStopped = true;
    }

    // Drop the playing reference
    // Warning: The below line might delete this.
    MarkInactive();
  }
}
Exemplo n.º 2
0
void
OscillatorNode::NotifyMainThreadStreamFinished()
{
  MOZ_ASSERT(mStream->IsFinished());

  class EndedEventDispatcher final : public nsRunnable
  {
  public:
    explicit EndedEventDispatcher(OscillatorNode* aNode)
      : mNode(aNode) {}
    NS_IMETHOD Run() override
    {
      // If it's not safe to run scripts right now, schedule this to run later
      if (!nsContentUtils::IsSafeToRunScript()) {
        nsContentUtils::AddScriptRunner(this);
        return NS_OK;
      }

      mNode->DispatchTrustedEvent(NS_LITERAL_STRING("ended"));
      // Release stream resources.
      mNode->DestroyMediaStream();
      return NS_OK;
    }
  private:
    nsRefPtr<OscillatorNode> mNode;
  };

  NS_DispatchToMainThread(new EndedEventDispatcher(this));

  // Drop the playing reference
  // Warning: The below line might delete this.
  MarkInactive();
}
Exemplo n.º 3
0
void
ScriptProcessorNode::UpdateConnectedStatus()
{
  bool isConnected = mHasPhantomInput ||
    !(OutputNodes().IsEmpty() && OutputParams().IsEmpty()
      && InputNodes().IsEmpty());

  // Events are queued even when there is no listener because a listener
  // may be added while events are in the queue.
  SendInt32ParameterToStream(ScriptProcessorNodeEngine::IS_CONNECTED,
                             isConnected);

  if (isConnected && HasListenersFor(nsGkAtoms::onaudioprocess)) {
    MarkActive();
  } else {
    MarkInactive();
  }
}
Exemplo n.º 4
0
void FlashEffect::OnUpdate(float delta)
{
	if (m_flashingIn)
	{
		m_alpha += (delta * m_flashInSpeed);
		if (m_alpha >= m_maximumIntensity)
		{
			m_alpha = m_maximumIntensity;
			m_flashingIn = false;
		}
	}
	else
	{
		m_alpha -= (delta * m_flashOutSpeed);
		if (m_alpha < 0.0f)
			m_alpha = 0.0f;
	}

	if (m_alpha == 0.0f && m_flashingIn == false)
		MarkInactive();
}
void
AudioBufferSourceNode::SendBufferParameterToStream(JSContext* aCx)
{
    AudioNodeStream* ns = mStream;
    if (!ns) {
        return;
    }

    if (mBuffer) {
        RefPtr<ThreadSharedFloatArrayBufferList> data =
            mBuffer->GetThreadSharedChannelsForRate(aCx);
        ns->SetBuffer(data.forget());

        if (mStartCalled) {
            SendOffsetAndDurationParametersToStream(ns);
        }
    } else {
        ns->SetInt32Parameter(BUFFEREND, 0);
        ns->SetBuffer(nullptr);

        MarkInactive();
    }
}