Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/PannerNode.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef PannerNode_h_
8
#define PannerNode_h_
9
10
#include "AudioNode.h"
11
#include "AudioParam.h"
12
#include "mozilla/dom/PannerNodeBinding.h"
13
#include "ThreeDPoint.h"
14
#include "mozilla/WeakPtr.h"
15
#include <limits>
16
#include <set>
17
18
namespace mozilla {
19
namespace dom {
20
21
class AudioContext;
22
class AudioBufferSourceNode;
23
struct PannerOptions;
24
25
class PannerNode final : public AudioNode,
26
                         public SupportsWeakPtr<PannerNode>
27
{
28
public:
29
  static already_AddRefed<PannerNode>
30
  Create(AudioContext& aAudioContext, const PannerOptions& aOptions,
31
         ErrorResult& aRv);
32
33
  MOZ_DECLARE_WEAKREFERENCE_TYPENAME(PannerNode)
34
35
  static already_AddRefed<PannerNode>
36
  Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
37
              const PannerOptions& aOptions, ErrorResult& aRv)
38
0
  {
39
0
    return Create(aAudioContext, aOptions, aRv);
40
0
  }
41
42
  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
43
44
  void SetChannelCount(uint32_t aChannelCount, ErrorResult& aRv) override
45
  {
46
    if (aChannelCount > 2) {
47
      aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
48
      return;
49
    }
50
    AudioNode::SetChannelCount(aChannelCount, aRv);
51
  }
52
  void SetChannelCountModeValue(ChannelCountMode aMode, ErrorResult& aRv) override
53
  {
54
    if (aMode == ChannelCountMode::Max) {
55
      aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
56
      return;
57
    }
58
    AudioNode::SetChannelCountModeValue(aMode, aRv);
59
  }
60
61
  NS_DECL_ISUPPORTS_INHERITED
62
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PannerNode, AudioNode)
63
64
  PanningModelType PanningModel() const
65
0
  {
66
0
    return mPanningModel;
67
0
  }
68
  void SetPanningModel(PanningModelType aPanningModel);
69
70
  DistanceModelType DistanceModel() const
71
0
  {
72
0
    return mDistanceModel;
73
0
  }
74
  void SetDistanceModel(DistanceModelType aDistanceModel)
75
0
  {
76
0
    mDistanceModel = aDistanceModel;
77
0
    SendInt32ParameterToStream(DISTANCE_MODEL, int32_t(mDistanceModel));
78
0
  }
79
80
  void SetPosition(double aX, double aY, double aZ)
81
0
  {
82
0
    if (fabs(aX) > std::numeric_limits<float>::max() ||
83
0
        fabs(aY) > std::numeric_limits<float>::max() ||
84
0
        fabs(aZ) > std::numeric_limits<float>::max()) {
85
0
      return;
86
0
    }
87
0
    mPositionX->SetValue(aX);
88
0
    mPositionY->SetValue(aY);
89
0
    mPositionZ->SetValue(aZ);
90
0
    SendThreeDPointParameterToStream(POSITION, ConvertAudioParamTo3DP(mPositionX, mPositionY, mPositionZ));
91
0
  }
92
93
  void SetOrientation(double aX, double aY, double aZ)
94
0
  {
95
0
    if (fabs(aX) > std::numeric_limits<float>::max() ||
96
0
        fabs(aY) > std::numeric_limits<float>::max() ||
97
0
        fabs(aZ) > std::numeric_limits<float>::max()) {
98
0
      return;
99
0
    }
100
0
    mOrientationX->SetValue(aX);
101
0
    mOrientationY->SetValue(aY);
102
0
    mOrientationZ->SetValue(aZ);
103
0
    SendThreeDPointParameterToStream(ORIENTATION, ConvertAudioParamTo3DP(mOrientationX, mOrientationY, mOrientationZ));
104
0
  }
105
106
  double RefDistance() const
107
0
  {
108
0
    return mRefDistance;
109
0
  }
110
  void SetRefDistance(double aRefDistance, ErrorResult& aRv)
111
0
  {
112
0
    if (WebAudioUtils::FuzzyEqual(mRefDistance, aRefDistance)) {
113
0
      return;
114
0
    }
115
0
116
0
    if (aRefDistance < 0) {
117
0
       aRv.template ThrowRangeError<
118
0
        MSG_INVALID_PANNERNODE_REFDISTANCE_ERROR>();
119
0
      return;
120
0
    }
121
0
122
0
    mRefDistance = aRefDistance;
123
0
    SendDoubleParameterToStream(REF_DISTANCE, mRefDistance);
124
0
  }
125
126
  double MaxDistance() const
127
0
  {
128
0
    return mMaxDistance;
129
0
  }
130
  void SetMaxDistance(double aMaxDistance, ErrorResult& aRv)
131
0
  {
132
0
    if (WebAudioUtils::FuzzyEqual(mMaxDistance, aMaxDistance)) {
133
0
      return;
134
0
    }
135
0
136
0
    if (aMaxDistance <= 0) {
137
0
       aRv.template ThrowRangeError<
138
0
        MSG_INVALID_PANNERNODE_MAXDISTANCE_ERROR>();
139
0
      return;
140
0
    }
141
0
142
0
    mMaxDistance = aMaxDistance;
143
0
    SendDoubleParameterToStream(MAX_DISTANCE, mMaxDistance);
144
0
  }
145
146
  double RolloffFactor() const
147
0
  {
148
0
    return mRolloffFactor;
149
0
  }
150
  void SetRolloffFactor(double aRolloffFactor, ErrorResult& aRv)
151
0
  {
152
0
    if (WebAudioUtils::FuzzyEqual(mRolloffFactor, aRolloffFactor)) {
153
0
      return;
154
0
    }
155
0
156
0
157
0
    if (aRolloffFactor < 0) {
158
0
       aRv.template ThrowRangeError<
159
0
        MSG_INVALID_PANNERNODE_ROLLOFF_ERROR>();
160
0
    }
161
0
162
0
    mRolloffFactor = aRolloffFactor;
163
0
    SendDoubleParameterToStream(ROLLOFF_FACTOR, mRolloffFactor);
164
0
  }
165
166
  double ConeInnerAngle() const
167
0
  {
168
0
    return mConeInnerAngle;
169
0
  }
170
  void SetConeInnerAngle(double aConeInnerAngle)
171
0
  {
172
0
    if (WebAudioUtils::FuzzyEqual(mConeInnerAngle, aConeInnerAngle)) {
173
0
      return;
174
0
    }
175
0
    mConeInnerAngle = aConeInnerAngle;
176
0
    SendDoubleParameterToStream(CONE_INNER_ANGLE, mConeInnerAngle);
177
0
  }
178
179
  double ConeOuterAngle() const
180
0
  {
181
0
    return mConeOuterAngle;
182
0
  }
183
  void SetConeOuterAngle(double aConeOuterAngle)
184
0
  {
185
0
    if (WebAudioUtils::FuzzyEqual(mConeOuterAngle, aConeOuterAngle)) {
186
0
      return;
187
0
    }
188
0
    mConeOuterAngle = aConeOuterAngle;
189
0
    SendDoubleParameterToStream(CONE_OUTER_ANGLE, mConeOuterAngle);
190
0
  }
191
192
  double ConeOuterGain() const
193
0
  {
194
0
    return mConeOuterGain;
195
0
  }
196
  void SetConeOuterGain(double aConeOuterGain, ErrorResult& aRv)
197
0
  {
198
0
    if (WebAudioUtils::FuzzyEqual(mConeOuterGain, aConeOuterGain)) {
199
0
      return;
200
0
    }
201
0
202
0
    if (aConeOuterGain < 0 || aConeOuterGain > 1) {
203
0
      aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
204
0
      return;
205
0
    }
206
0
207
0
    mConeOuterGain = aConeOuterGain;
208
0
    SendDoubleParameterToStream(CONE_OUTER_GAIN, mConeOuterGain);
209
0
  }
210
211
  AudioParam* PositionX()
212
0
  {
213
0
    return mPositionX;
214
0
  }
215
216
  AudioParam* PositionY()
217
0
  {
218
0
    return mPositionY;
219
0
  }
220
221
  AudioParam* PositionZ()
222
0
  {
223
0
    return mPositionZ;
224
0
  }
225
226
  AudioParam* OrientationX()
227
0
  {
228
0
    return mOrientationX;
229
0
  }
230
231
  AudioParam* OrientationY()
232
0
  {
233
0
    return mOrientationY;
234
0
  }
235
236
  AudioParam* OrientationZ()
237
0
  {
238
0
    return mOrientationZ;
239
0
  }
240
241
  const char* NodeType() const override
242
  {
243
    return "PannerNode";
244
  }
245
246
  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
247
  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
248
249
private:
250
  explicit PannerNode(AudioContext* aContext);
251
  ~PannerNode() = default;
252
253
  friend class AudioListener;
254
  friend class PannerNodeEngine;
255
  enum EngineParameters {
256
    PANNING_MODEL,
257
    DISTANCE_MODEL,
258
    POSITION,
259
    POSITIONX,
260
    POSITIONY,
261
    POSITIONZ,
262
    ORIENTATION, // unit length or zero
263
    ORIENTATIONX,
264
    ORIENTATIONY,
265
    ORIENTATIONZ,
266
    REF_DISTANCE,
267
    MAX_DISTANCE,
268
    ROLLOFF_FACTOR,
269
    CONE_INNER_ANGLE,
270
    CONE_OUTER_ANGLE,
271
    CONE_OUTER_GAIN
272
  };
273
274
  ThreeDPoint ConvertAudioParamTo3DP(RefPtr <AudioParam> aX, RefPtr <AudioParam> aY, RefPtr <AudioParam> aZ)
275
0
  {
276
0
    return ThreeDPoint(aX->GetValue(), aY->GetValue(), aZ->GetValue());
277
0
  }
278
279
  PanningModelType mPanningModel;
280
  DistanceModelType mDistanceModel;
281
  RefPtr<AudioParam> mPositionX;
282
  RefPtr<AudioParam> mPositionY;
283
  RefPtr<AudioParam> mPositionZ;
284
  RefPtr<AudioParam> mOrientationX;
285
  RefPtr<AudioParam> mOrientationY;
286
  RefPtr<AudioParam> mOrientationZ;
287
288
  double mRefDistance;
289
  double mMaxDistance;
290
  double mRolloffFactor;
291
  double mConeInnerAngle;
292
  double mConeOuterAngle;
293
  double mConeOuterGain;
294
};
295
296
} // namespace dom
297
} // namespace mozilla
298
299
#endif