2012-10-16 18:19:06 -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 AudioParam_h_
|
|
|
|
#define AudioParam_h_
|
2012-10-16 18:19:06 -07:00
|
|
|
|
2013-03-21 21:01:28 -07:00
|
|
|
#include "AudioParamTimeline.h"
|
2012-10-16 18:19:06 -07:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-01-28 15:59:29 -08:00
|
|
|
#include "AudioNode.h"
|
2012-10-16 18:19:06 -07:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2013-03-20 17:12:07 -07:00
|
|
|
#include "WebAudioUtils.h"
|
2013-08-27 19:59:14 -07:00
|
|
|
#include "js/TypeDecls.h"
|
2012-10-16 18:19:06 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class AudioParam MOZ_FINAL : public nsWrapperCache,
|
|
|
|
public AudioParamTimeline
|
|
|
|
{
|
2014-06-24 09:36:43 -07:00
|
|
|
virtual ~AudioParam();
|
|
|
|
|
2012-10-16 18:19:06 -07:00
|
|
|
public:
|
2013-01-28 15:59:29 -08:00
|
|
|
typedef void (*CallbackType)(AudioNode*);
|
|
|
|
|
|
|
|
AudioParam(AudioNode* aNode,
|
|
|
|
CallbackType aCallback,
|
2013-04-08 18:57:54 -07:00
|
|
|
float aDefaultValue);
|
2012-10-16 18:19:06 -07:00
|
|
|
|
2014-03-27 13:38:33 -07:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release(void);
|
2012-10-16 18:19:06 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioParam)
|
|
|
|
|
|
|
|
AudioContext* GetParentObject() const
|
|
|
|
{
|
2013-01-28 15:59:29 -08:00
|
|
|
return mNode->Context();
|
2012-10-16 18:19:06 -07:00
|
|
|
}
|
|
|
|
|
2014-01-15 03:08:20 -08:00
|
|
|
double DOMTimeToStreamTime(double aTime) const
|
|
|
|
{
|
|
|
|
return mNode->Context()->DOMTimeToStreamTime(aTime);
|
|
|
|
}
|
|
|
|
|
2014-04-08 15:27:18 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
|
2012-10-16 18:19:06 -07:00
|
|
|
|
|
|
|
// We override SetValueCurveAtTime to convert the Float32Array to the wrapper
|
|
|
|
// object.
|
2013-05-06 16:50:45 -07:00
|
|
|
void SetValueCurveAtTime(const Float32Array& aValues, double aStartTime, double aDuration, ErrorResult& aRv)
|
2012-10-16 18:19:06 -07:00
|
|
|
{
|
2013-06-02 06:26:06 -07:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aStartTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
Bug 999651, bug 995679, bug 1009952, bug 1011007, bug 991981. r=sfink, r=shu, r=jandem, r=jdm, r=luke, r=bbouvier, r=nmatsakis, r=bz, r=ehsan, r=jgilbert, r=smaug, r=sicking, r=terrence, r=bholley, r=bent, r=efaust, r=jorendorff
2014-05-27 14:32:41 -07:00
|
|
|
aValues.ComputeLengthAndData();
|
2013-01-25 13:46:44 -08:00
|
|
|
AudioParamTimeline::SetValueCurveAtTime(aValues.Data(), aValues.Length(),
|
2014-01-15 03:08:20 -08:00
|
|
|
DOMTimeToStreamTime(aStartTime), aDuration, aRv);
|
2013-01-28 15:59:29 -08:00
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We override the rest of the mutating AudioParamTimeline methods in order to make
|
|
|
|
// sure that the callback is called every time that this object gets mutated.
|
|
|
|
void SetValue(float aValue)
|
|
|
|
{
|
2013-03-17 12:57:15 -07:00
|
|
|
// Optimize away setting the same value on an AudioParam
|
2013-03-20 17:12:07 -07:00
|
|
|
if (HasSimpleValue() &&
|
|
|
|
WebAudioUtils::FuzzyEqual(GetValue(), aValue)) {
|
2013-03-17 12:57:15 -07:00
|
|
|
return;
|
|
|
|
}
|
2013-01-28 15:59:29 -08:00
|
|
|
AudioParamTimeline::SetValue(aValue);
|
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void SetValueAtTime(float aValue, double aStartTime, ErrorResult& aRv)
|
|
|
|
{
|
2013-05-30 17:53:15 -07:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aStartTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-15 03:08:20 -08:00
|
|
|
AudioParamTimeline::SetValueAtTime(aValue, DOMTimeToStreamTime(aStartTime), aRv);
|
2013-01-28 15:59:29 -08:00
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void LinearRampToValueAtTime(float aValue, double aEndTime, ErrorResult& aRv)
|
|
|
|
{
|
2013-05-30 17:53:15 -07:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aEndTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-15 03:08:20 -08:00
|
|
|
AudioParamTimeline::LinearRampToValueAtTime(aValue, DOMTimeToStreamTime(aEndTime), aRv);
|
2013-01-28 15:59:29 -08:00
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void ExponentialRampToValueAtTime(float aValue, double aEndTime, ErrorResult& aRv)
|
|
|
|
{
|
2013-05-30 17:53:15 -07:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aEndTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-15 03:08:20 -08:00
|
|
|
AudioParamTimeline::ExponentialRampToValueAtTime(aValue, DOMTimeToStreamTime(aEndTime), aRv);
|
2013-01-28 15:59:29 -08:00
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void SetTargetAtTime(float aTarget, double aStartTime, double aTimeConstant, ErrorResult& aRv)
|
|
|
|
{
|
2013-05-30 17:53:15 -07:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aStartTime) ||
|
|
|
|
!WebAudioUtils::IsTimeValid(aTimeConstant)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-15 03:08:20 -08:00
|
|
|
AudioParamTimeline::SetTargetAtTime(aTarget, DOMTimeToStreamTime(aStartTime), aTimeConstant, aRv);
|
2013-01-28 15:59:29 -08:00
|
|
|
mCallback(mNode);
|
|
|
|
}
|
2013-05-30 17:53:15 -07:00
|
|
|
void CancelScheduledValues(double aStartTime, ErrorResult& aRv)
|
2013-01-28 15:59:29 -08:00
|
|
|
{
|
2013-05-30 17:53:15 -07:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aStartTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2014-01-15 03:08:20 -08:00
|
|
|
AudioParamTimeline::CancelScheduledValues(DOMTimeToStreamTime(aStartTime));
|
2013-01-28 15:59:29 -08:00
|
|
|
mCallback(mNode);
|
2012-10-16 18:19:06 -07:00
|
|
|
}
|
|
|
|
|
2013-01-25 11:26:31 -08:00
|
|
|
float DefaultValue() const
|
|
|
|
{
|
|
|
|
return mDefaultValue;
|
|
|
|
}
|
|
|
|
|
2013-05-01 18:02:31 -07:00
|
|
|
AudioNode* Node() const
|
|
|
|
{
|
|
|
|
return mNode;
|
|
|
|
}
|
|
|
|
|
2013-05-01 15:59:02 -07:00
|
|
|
const nsTArray<AudioNode::InputNode>& InputNodes() const
|
|
|
|
{
|
|
|
|
return mInputNodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveInputNode(uint32_t aIndex)
|
|
|
|
{
|
|
|
|
mInputNodes.RemoveElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioNode::InputNode* AppendInputNode()
|
|
|
|
{
|
|
|
|
return mInputNodes.AppendElement();
|
|
|
|
}
|
|
|
|
|
2013-05-01 18:02:31 -07:00
|
|
|
void DisconnectFromGraphAndDestroyStream();
|
|
|
|
|
|
|
|
// May create the stream if it doesn't exist
|
|
|
|
MediaStream* Stream();
|
2013-05-01 15:59:02 -07:00
|
|
|
|
2014-04-13 11:08:10 -07:00
|
|
|
virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
size_t amount = AudioParamTimeline::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
// Not owned:
|
|
|
|
// - mNode
|
|
|
|
|
|
|
|
// Just count the array, actual nodes are counted in mNode.
|
|
|
|
amount += mInputNodes.SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
if (mNodeStreamPort) {
|
|
|
|
amount += mNodeStreamPort->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2013-05-01 15:59:02 -07:00
|
|
|
protected:
|
|
|
|
nsCycleCollectingAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
|
2012-10-16 18:19:06 -07:00
|
|
|
private:
|
2013-01-28 15:59:29 -08:00
|
|
|
nsRefPtr<AudioNode> mNode;
|
2013-05-01 15:59:02 -07:00
|
|
|
// For every InputNode, there is a corresponding entry in mOutputParams of the
|
|
|
|
// InputNode's mInputNode.
|
|
|
|
nsTArray<AudioNode::InputNode> mInputNodes;
|
2013-01-28 15:59:29 -08:00
|
|
|
CallbackType mCallback;
|
2013-01-25 11:26:31 -08:00
|
|
|
const float mDefaultValue;
|
2013-05-01 18:02:31 -07:00
|
|
|
// The input port used to connect the AudioParam's stream to its node's stream
|
|
|
|
nsRefPtr<MediaInputPort> mNodeStreamPort;
|
2012-10-16 18:19:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#endif
|
|
|
|
|