2012-10-17 05:19:06 +04: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-31 01:39:38 +04:00
|
|
|
#ifndef AudioParam_h_
|
|
|
|
#define AudioParam_h_
|
2012-10-17 05:19:06 +04:00
|
|
|
|
2013-03-22 08:01:28 +04:00
|
|
|
#include "AudioParamTimeline.h"
|
2012-10-17 05:19:06 +04:00
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-01-29 03:59:29 +04:00
|
|
|
#include "AudioNode.h"
|
2012-10-17 05:19:06 +04:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
2013-03-21 04:12:07 +04:00
|
|
|
#include "WebAudioUtils.h"
|
2013-08-28 06:59:14 +04:00
|
|
|
#include "js/TypeDecls.h"
|
2012-10-17 05:19:06 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class AudioParam final : public nsWrapperCache,
|
2015-03-27 21:52:19 +03:00
|
|
|
public AudioParamTimeline
|
2012-10-17 05:19:06 +04:00
|
|
|
{
|
2014-06-24 20:36:43 +04:00
|
|
|
virtual ~AudioParam();
|
|
|
|
|
2012-10-17 05:19:06 +04:00
|
|
|
public:
|
2013-01-29 03:59:29 +04:00
|
|
|
AudioParam(AudioNode* aNode,
|
2015-10-01 05:48:20 +03:00
|
|
|
uint32_t aIndex,
|
2016-12-21 12:53:38 +03:00
|
|
|
const char* aName,
|
2015-04-14 18:03:52 +03:00
|
|
|
float aDefaultValue,
|
2016-12-21 12:53:38 +03:00
|
|
|
float aMinValue = -std::numeric_limits<float>::infinity(),
|
|
|
|
float aMaxValue = std::numeric_limits<float>::infinity());
|
2012-10-17 05:19:06 +04:00
|
|
|
|
2014-03-28 00:38:33 +04:00
|
|
|
NS_IMETHOD_(MozExternalRefCountType) AddRef(void);
|
|
|
|
NS_IMETHOD_(MozExternalRefCountType) Release(void);
|
2012-10-17 05:19:06 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioParam)
|
|
|
|
|
|
|
|
AudioContext* GetParentObject() const
|
|
|
|
{
|
2013-01-29 03:59:29 +04:00
|
|
|
return mNode->Context();
|
2012-10-17 05:19:06 +04:00
|
|
|
}
|
|
|
|
|
2016-01-18 06:22:51 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2012-10-17 05:19:06 +04:00
|
|
|
|
|
|
|
// We override SetValueCurveAtTime to convert the Float32Array to the wrapper
|
|
|
|
// object.
|
2016-04-19 15:52:27 +03:00
|
|
|
AudioParam* SetValueCurveAtTime(const Float32Array& aValues,
|
|
|
|
double aStartTime,
|
|
|
|
double aDuration,
|
|
|
|
ErrorResult& aRv)
|
2012-10-17 05:19:06 +04:00
|
|
|
{
|
2013-06-02 17:26:06 +04:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aStartTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-06-02 17:26:06 +04:00
|
|
|
}
|
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-28 01:32:41 +04:00
|
|
|
aValues.ComputeLengthAndData();
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2016-11-08 17:29:35 +03:00
|
|
|
aStartTime = std::max(aStartTime, GetParentObject()->CurrentTime());
|
2015-09-25 16:57:55 +03:00
|
|
|
EventInsertionHelper(aRv, AudioTimelineEvent::SetValueCurve,
|
|
|
|
aStartTime, 0.0f, 0.0f, aDuration, aValues.Data(),
|
|
|
|
aValues.Length());
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-01-29 03:59:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetValue(float aValue)
|
|
|
|
{
|
2015-09-25 16:57:55 +03:00
|
|
|
AudioTimelineEvent event(AudioTimelineEvent::SetValue, 0.0f, aValue);
|
|
|
|
|
|
|
|
ErrorResult rv;
|
|
|
|
if (!ValidateEvent(event, rv)) {
|
|
|
|
MOZ_ASSERT(false, "This should not happen, "
|
|
|
|
"setting the value should always work");
|
2013-03-17 23:57:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2013-01-29 03:59:29 +04:00
|
|
|
AudioParamTimeline::SetValue(aValue);
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2015-10-01 05:48:20 +03:00
|
|
|
SendEventToEngine(event);
|
2013-01-29 03:59:29 +04:00
|
|
|
}
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2016-04-19 15:52:27 +03:00
|
|
|
AudioParam* SetValueAtTime(float aValue, double aStartTime, ErrorResult& aRv)
|
2013-01-29 03:59:29 +04:00
|
|
|
{
|
2013-05-31 04:53:15 +04:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aStartTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-05-31 04:53:15 +04:00
|
|
|
}
|
2016-11-08 17:29:35 +03:00
|
|
|
aStartTime = std::max(aStartTime, GetParentObject()->CurrentTime());
|
2015-09-25 16:57:55 +03:00
|
|
|
EventInsertionHelper(aRv, AudioTimelineEvent::SetValueAtTime,
|
|
|
|
aStartTime, aValue);
|
2016-04-19 15:52:27 +03:00
|
|
|
|
|
|
|
return this;
|
2013-01-29 03:59:29 +04:00
|
|
|
}
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2016-04-19 15:52:27 +03:00
|
|
|
AudioParam* LinearRampToValueAtTime(float aValue, double aEndTime,
|
|
|
|
ErrorResult& aRv)
|
2013-01-29 03:59:29 +04:00
|
|
|
{
|
2013-05-31 04:53:15 +04:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aEndTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-05-31 04:53:15 +04:00
|
|
|
}
|
2016-11-08 17:29:35 +03:00
|
|
|
aEndTime = std::max(aEndTime, GetParentObject()->CurrentTime());
|
2015-09-25 16:57:55 +03:00
|
|
|
EventInsertionHelper(aRv, AudioTimelineEvent::LinearRamp, aEndTime, aValue);
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-01-29 03:59:29 +04:00
|
|
|
}
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2016-04-19 15:52:27 +03:00
|
|
|
AudioParam* ExponentialRampToValueAtTime(float aValue, double aEndTime,
|
|
|
|
ErrorResult& aRv)
|
2013-01-29 03:59:29 +04:00
|
|
|
{
|
2013-05-31 04:53:15 +04:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aEndTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-05-31 04:53:15 +04:00
|
|
|
}
|
2016-11-08 17:29:35 +03:00
|
|
|
aEndTime = std::max(aEndTime, GetParentObject()->CurrentTime());
|
2015-09-25 16:57:55 +03:00
|
|
|
EventInsertionHelper(aRv, AudioTimelineEvent::ExponentialRamp,
|
|
|
|
aEndTime, aValue);
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-01-29 03:59:29 +04:00
|
|
|
}
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2016-04-19 15:52:27 +03:00
|
|
|
AudioParam* SetTargetAtTime(float aTarget, double aStartTime,
|
|
|
|
double aTimeConstant, ErrorResult& aRv)
|
2013-01-29 03:59:29 +04:00
|
|
|
{
|
2013-05-31 04:53:15 +04:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aStartTime) ||
|
|
|
|
!WebAudioUtils::IsTimeValid(aTimeConstant)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-05-31 04:53:15 +04:00
|
|
|
}
|
2016-11-08 17:29:35 +03:00
|
|
|
aStartTime = std::max(aStartTime, GetParentObject()->CurrentTime());
|
2015-09-25 16:57:55 +03:00
|
|
|
EventInsertionHelper(aRv, AudioTimelineEvent::SetTarget,
|
|
|
|
aStartTime, aTarget,
|
|
|
|
aTimeConstant);
|
2016-04-19 15:52:27 +03:00
|
|
|
|
|
|
|
return this;
|
2013-01-29 03:59:29 +04:00
|
|
|
}
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2016-04-19 15:52:27 +03:00
|
|
|
AudioParam* CancelScheduledValues(double aStartTime, ErrorResult& aRv)
|
2013-01-29 03:59:29 +04:00
|
|
|
{
|
2013-05-31 04:53:15 +04:00
|
|
|
if (!WebAudioUtils::IsTimeValid(aStartTime)) {
|
|
|
|
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
|
2016-04-19 15:52:27 +03:00
|
|
|
return this;
|
2013-05-31 04:53:15 +04:00
|
|
|
}
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2016-11-08 17:29:35 +03:00
|
|
|
aStartTime = std::max(aStartTime, GetParentObject()->CurrentTime());
|
|
|
|
|
2015-09-25 16:57:55 +03:00
|
|
|
// Remove some events on the main thread copy.
|
2015-09-29 00:46:43 +03:00
|
|
|
AudioEventTimeline::CancelScheduledValues(aStartTime);
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2015-09-29 00:46:43 +03:00
|
|
|
AudioTimelineEvent event(AudioTimelineEvent::Cancel, aStartTime, 0.0f);
|
2015-09-25 16:57:55 +03:00
|
|
|
|
2015-10-01 05:48:20 +03:00
|
|
|
SendEventToEngine(event);
|
2016-04-19 15:52:27 +03:00
|
|
|
|
|
|
|
return this;
|
2012-10-17 05:19:06 +04:00
|
|
|
}
|
|
|
|
|
2015-04-14 18:03:52 +03:00
|
|
|
uint32_t ParentNodeId()
|
|
|
|
{
|
|
|
|
return mNode->Id();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName.AssignASCII(mName);
|
|
|
|
}
|
|
|
|
|
2013-01-25 23:26:31 +04:00
|
|
|
float DefaultValue() const
|
|
|
|
{
|
|
|
|
return mDefaultValue;
|
|
|
|
}
|
|
|
|
|
2016-12-21 12:53:38 +03:00
|
|
|
float MinValue() const
|
|
|
|
{
|
|
|
|
return mMinValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float MaxValue() const
|
|
|
|
{
|
|
|
|
return mMaxValue;
|
|
|
|
}
|
|
|
|
|
2013-05-02 02:59:02 +04: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-02 05:02:31 +04:00
|
|
|
// May create the stream if it doesn't exist
|
|
|
|
MediaStream* Stream();
|
2013-05-02 02:59:02 +04:00
|
|
|
|
2016-01-18 06:22:51 +03:00
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override
|
2014-04-13 22:08:10 +04:00
|
|
|
{
|
|
|
|
size_t amount = AudioParamTimeline::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
// Not owned:
|
|
|
|
// - mNode
|
|
|
|
|
|
|
|
// Just count the array, actual nodes are counted in mNode.
|
2015-07-29 09:24:24 +03:00
|
|
|
amount += mInputNodes.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
2014-04-13 22:08:10 +04:00
|
|
|
|
|
|
|
if (mNodeStreamPort) {
|
|
|
|
amount += mNodeStreamPort->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:22:51 +03:00
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override
|
2014-04-13 22:08:10 +04:00
|
|
|
{
|
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2012-10-17 05:19:06 +04:00
|
|
|
private:
|
2015-09-25 16:57:55 +03:00
|
|
|
void EventInsertionHelper(ErrorResult& aRv,
|
|
|
|
AudioTimelineEvent::Type aType,
|
|
|
|
double aTime, float aValue,
|
|
|
|
double aTimeConstant = 0.0,
|
|
|
|
float aDuration = 0.0,
|
|
|
|
const float* aCurve = nullptr,
|
|
|
|
uint32_t aCurveLength = 0)
|
|
|
|
{
|
2015-09-29 00:46:43 +03:00
|
|
|
AudioTimelineEvent event(aType, aTime, aValue,
|
2015-09-25 16:57:55 +03:00
|
|
|
aTimeConstant, aDuration, aCurve, aCurveLength);
|
|
|
|
|
|
|
|
if (!ValidateEvent(event, aRv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioEventTimeline::InsertEvent<double>(event);
|
|
|
|
|
2015-10-01 05:48:20 +03:00
|
|
|
SendEventToEngine(event);
|
2016-06-29 11:25:58 +03:00
|
|
|
|
|
|
|
CleanupOldEvents();
|
2015-09-25 16:57:55 +03:00
|
|
|
}
|
|
|
|
|
2016-06-29 11:25:58 +03:00
|
|
|
void CleanupOldEvents();
|
|
|
|
|
2015-10-01 05:48:20 +03:00
|
|
|
void SendEventToEngine(const AudioTimelineEvent& aEvent);
|
|
|
|
|
2015-10-02 04:24:51 +03:00
|
|
|
void DisconnectFromGraphAndDestroyStream();
|
|
|
|
|
2015-10-01 05:48:20 +03:00
|
|
|
nsCycleCollectingAutoRefCnt mRefCnt;
|
|
|
|
NS_DECL_OWNINGTHREAD
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AudioNode> mNode;
|
2013-05-02 02:59:02 +04:00
|
|
|
// For every InputNode, there is a corresponding entry in mOutputParams of the
|
|
|
|
// InputNode's mInputNode.
|
|
|
|
nsTArray<AudioNode::InputNode> mInputNodes;
|
2015-04-14 18:03:52 +03:00
|
|
|
const char* mName;
|
2013-05-02 05:02:31 +04:00
|
|
|
// The input port used to connect the AudioParam's stream to its node's stream
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaInputPort> mNodeStreamPort;
|
2015-10-01 05:48:20 +03:00
|
|
|
const uint32_t mIndex;
|
|
|
|
const float mDefaultValue;
|
2016-12-21 12:53:38 +03:00
|
|
|
const float mMinValue;
|
|
|
|
const float mMaxValue;
|
2012-10-17 05:19:06 +04:00
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2012-10-17 05:19:06 +04:00
|
|
|
|
2012-10-31 01:39:38 +04:00
|
|
|
#endif
|
|
|
|
|