2012-09-18 16:07:33 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#ifndef AudioNode_h_
|
|
|
|
#define AudioNode_h_
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2013-04-12 08:28:33 -07:00
|
|
|
#include "nsDOMEventTargetHelper.h"
|
2013-04-27 15:44:50 -07:00
|
|
|
#include "mozilla/dom/AudioNodeBinding.h"
|
2012-09-18 16:07:33 -07:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "EnableWebAudioCheck.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2012-09-24 20:31:58 -07:00
|
|
|
#include "nsTArray.h"
|
2012-09-18 16:07:33 -07:00
|
|
|
#include "AudioContext.h"
|
2013-03-29 18:46:03 -07:00
|
|
|
#include "AudioParamTimeline.h"
|
2013-02-04 15:07:25 -08:00
|
|
|
#include "MediaStreamGraph.h"
|
2012-09-18 16:07:33 -07:00
|
|
|
|
|
|
|
struct JSContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2012-09-24 20:31:58 -07:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
namespace dom {
|
|
|
|
|
2013-03-12 08:28:14 -07:00
|
|
|
struct ThreeDPoint;
|
|
|
|
|
2013-04-14 18:52:55 -07:00
|
|
|
template<class T>
|
|
|
|
class SelfReference {
|
|
|
|
public:
|
|
|
|
SelfReference() : mHeld(false) {}
|
|
|
|
~SelfReference()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mHeld, "Forgot to drop the self reference?");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Take(T* t)
|
|
|
|
{
|
|
|
|
if (!mHeld) {
|
|
|
|
mHeld = true;
|
|
|
|
t->AddRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void Drop(T* t)
|
|
|
|
{
|
|
|
|
if (mHeld) {
|
|
|
|
mHeld = false;
|
|
|
|
t->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
operator bool() const { return mHeld; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mHeld;
|
|
|
|
};
|
|
|
|
|
2013-02-04 15:07:25 -08:00
|
|
|
/**
|
|
|
|
* The DOM object representing a Web Audio AudioNode.
|
|
|
|
*
|
|
|
|
* Each AudioNode has a MediaStream representing the actual
|
|
|
|
* real-time processing and output of this AudioNode.
|
|
|
|
*
|
|
|
|
* We track the incoming and outgoing connections to other AudioNodes.
|
|
|
|
* All connections are strong and thus rely on cycle collection to break them.
|
|
|
|
* However, we also track whether an AudioNode is capable of producing output
|
|
|
|
* in the future. If it isn't, then we break its connections to its inputs
|
|
|
|
* and outputs, allowing nodes to be immediately disconnected. This
|
|
|
|
* disconnection is done internally, invisible to DOM users.
|
|
|
|
*/
|
2013-04-12 08:28:33 -07:00
|
|
|
class AudioNode : public nsDOMEventTargetHelper,
|
2012-09-18 16:07:33 -07:00
|
|
|
public EnableWebAudioCheck
|
|
|
|
{
|
2013-04-24 13:57:07 -07:00
|
|
|
protected:
|
|
|
|
// You can only use refcounting to delete this object
|
|
|
|
virtual ~AudioNode();
|
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
public:
|
2013-04-27 15:44:50 -07:00
|
|
|
AudioNode(AudioContext* aContext,
|
|
|
|
uint32_t aChannelCount,
|
|
|
|
ChannelCountMode aChannelCountMode,
|
|
|
|
ChannelInterpretation aChannelInterpretation);
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2013-02-04 15:07:25 -08:00
|
|
|
// This should be idempotent (safe to call multiple times).
|
2013-04-22 19:45:37 -07:00
|
|
|
virtual void DestroyMediaStream();
|
2013-02-04 15:07:25 -08:00
|
|
|
|
2013-04-24 13:57:07 -07:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2013-04-12 08:28:33 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioNode,
|
|
|
|
nsDOMEventTargetHelper)
|
2013-02-04 15:07:25 -08:00
|
|
|
|
2013-04-11 05:47:57 -07:00
|
|
|
virtual AudioBufferSourceNode* AsAudioBufferSourceNode() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
AudioContext* GetParentObject() const
|
|
|
|
{
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioContext* Context() const
|
|
|
|
{
|
|
|
|
return mContext;
|
|
|
|
}
|
|
|
|
|
2013-04-22 18:23:54 -07:00
|
|
|
virtual void Connect(AudioNode& aDestination, uint32_t aOutput,
|
|
|
|
uint32_t aInput, ErrorResult& aRv);
|
2012-09-24 20:31:58 -07:00
|
|
|
|
2013-04-22 18:23:54 -07:00
|
|
|
virtual void Disconnect(uint32_t aOutput, ErrorResult& aRv);
|
2012-09-24 20:31:58 -07:00
|
|
|
|
|
|
|
// The following two virtual methods must be implemented by each node type
|
2013-01-23 16:50:18 -08:00
|
|
|
// to provide their number of input and output ports. These numbers are
|
|
|
|
// constant for the lifetime of the node. Both default to 1.
|
|
|
|
virtual uint32_t NumberOfInputs() const { return 1; }
|
|
|
|
virtual uint32_t NumberOfOutputs() const { return 1; }
|
|
|
|
|
2013-04-27 15:44:50 -07:00
|
|
|
uint32_t ChannelCount() const { return mChannelCount; }
|
|
|
|
void SetChannelCount(uint32_t aChannelCount)
|
|
|
|
{
|
|
|
|
mChannelCount = aChannelCount;
|
2013-04-27 16:25:23 -07:00
|
|
|
SendChannelMixingParametersToStream();
|
2013-04-27 15:44:50 -07:00
|
|
|
}
|
|
|
|
ChannelCountMode ChannelCountModeValue() const
|
|
|
|
{
|
|
|
|
return mChannelCountMode;
|
|
|
|
}
|
|
|
|
void SetChannelCountModeValue(ChannelCountMode aMode)
|
|
|
|
{
|
|
|
|
mChannelCountMode = aMode;
|
2013-04-27 16:25:23 -07:00
|
|
|
SendChannelMixingParametersToStream();
|
2013-04-27 15:44:50 -07:00
|
|
|
}
|
|
|
|
ChannelInterpretation ChannelInterpretationValue() const
|
|
|
|
{
|
|
|
|
return mChannelInterpretation;
|
|
|
|
}
|
|
|
|
void SetChannelInterpretationValue(ChannelInterpretation aMode)
|
|
|
|
{
|
|
|
|
mChannelInterpretation = aMode;
|
2013-04-27 16:25:23 -07:00
|
|
|
SendChannelMixingParametersToStream();
|
2013-04-27 15:44:50 -07:00
|
|
|
}
|
|
|
|
|
2013-01-23 16:50:18 -08:00
|
|
|
struct InputNode {
|
2013-02-04 15:07:25 -08:00
|
|
|
~InputNode()
|
|
|
|
{
|
|
|
|
if (mStreamPort) {
|
|
|
|
mStreamPort->Destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-14 18:52:55 -07:00
|
|
|
// Weak reference.
|
|
|
|
AudioNode* mInputNode;
|
2013-02-04 15:07:25 -08:00
|
|
|
nsRefPtr<MediaInputPort> mStreamPort;
|
2013-01-23 16:50:18 -08:00
|
|
|
// The index of the input port this node feeds into.
|
|
|
|
uint32_t mInputPort;
|
|
|
|
// The index of the output port this node comes out of.
|
|
|
|
uint32_t mOutputPort;
|
2012-09-24 20:31:58 -07:00
|
|
|
};
|
2012-09-18 16:07:33 -07:00
|
|
|
|
2013-02-04 15:07:25 -08:00
|
|
|
MediaStream* Stream() { return mStream; }
|
|
|
|
|
2013-04-11 05:47:57 -07:00
|
|
|
const nsTArray<InputNode>& InputNodes() const
|
|
|
|
{
|
|
|
|
return mInputNodes;
|
|
|
|
}
|
|
|
|
|
2013-04-14 18:52:55 -07:00
|
|
|
private:
|
|
|
|
// This could possibly delete 'this'.
|
|
|
|
void DisconnectFromGraph();
|
|
|
|
|
2013-01-28 15:59:29 -08:00
|
|
|
protected:
|
|
|
|
static void Callback(AudioNode* aNode) { /* not implemented */ }
|
|
|
|
|
2013-03-12 08:28:14 -07:00
|
|
|
// Helpers for sending different value types to streams
|
|
|
|
void SendDoubleParameterToStream(uint32_t aIndex, double aValue);
|
|
|
|
void SendInt32ParameterToStream(uint32_t aIndex, int32_t aValue);
|
|
|
|
void SendThreeDPointParameterToStream(uint32_t aIndex, const ThreeDPoint& aValue);
|
2013-04-27 16:25:23 -07:00
|
|
|
void SendChannelMixingParametersToStream();
|
2013-03-29 18:46:03 -07:00
|
|
|
static void SendTimelineParameterToStream(AudioNode* aNode, uint32_t aIndex,
|
|
|
|
const AudioParamTimeline& aValue);
|
2013-03-12 08:28:14 -07:00
|
|
|
|
2012-09-18 16:07:33 -07:00
|
|
|
private:
|
|
|
|
nsRefPtr<AudioContext> mContext;
|
2013-01-23 16:50:18 -08:00
|
|
|
|
2013-02-04 15:07:25 -08:00
|
|
|
protected:
|
|
|
|
// Must be set in the constructor. Must not be null.
|
|
|
|
// If MaxNumberOfInputs() is > 0, then mStream must be a ProcessedMediaStream.
|
|
|
|
nsRefPtr<MediaStream> mStream;
|
|
|
|
|
|
|
|
private:
|
2013-01-23 16:50:18 -08:00
|
|
|
// For every InputNode, there is a corresponding entry in mOutputNodes of the
|
|
|
|
// InputNode's mInputNode.
|
|
|
|
nsTArray<InputNode> mInputNodes;
|
|
|
|
// For every mOutputNode entry, there is a corresponding entry in mInputNodes
|
|
|
|
// of the mOutputNode entry. We won't necessarily be able to identify the
|
|
|
|
// exact matching entry, since mOutputNodes doesn't include the port
|
|
|
|
// identifiers and the same node could be connected on multiple ports.
|
|
|
|
nsTArray<nsRefPtr<AudioNode> > mOutputNodes;
|
2013-04-27 15:44:50 -07:00
|
|
|
uint32_t mChannelCount;
|
|
|
|
ChannelCountMode mChannelCountMode;
|
|
|
|
ChannelInterpretation mChannelInterpretation;
|
2012-09-18 16:07:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#endif
|