Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dist/include/mozilla/dom/AudioBufferSourceNode.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 AudioBufferSourceNode_h_
8
#define AudioBufferSourceNode_h_
9
10
#include "AudioScheduledSourceNode.h"
11
#include "AudioBuffer.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
struct AudioBufferSourceOptions;
17
class AudioParam;
18
19
class AudioBufferSourceNode final : public AudioScheduledSourceNode
20
                                  , public MainThreadMediaStreamListener
21
{
22
public:
23
  static already_AddRefed<AudioBufferSourceNode>
24
  Create(JSContext* aCx, AudioContext& aAudioContext,
25
         const AudioBufferSourceOptions& aOptions, ErrorResult& aRv);
26
27
  void DestroyMediaStream() override;
28
29
  uint16_t NumberOfInputs() const final
30
  {
31
    return 0;
32
  }
33
  AudioBufferSourceNode* AsAudioBufferSourceNode() override
34
  {
35
    return this;
36
  }
37
  NS_DECL_ISUPPORTS_INHERITED
38
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioBufferSourceNode,
39
                                           AudioScheduledSourceNode)
40
41
  static already_AddRefed<AudioBufferSourceNode>
42
  Constructor(const GlobalObject& aGlobal, AudioContext& aAudioContext,
43
              const AudioBufferSourceOptions& aOptions, ErrorResult& aRv)
44
0
  {
45
0
    return Create(aGlobal.Context(), aAudioContext, aOptions, aRv);
46
0
  }
47
48
  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
49
50
  void Start(double aWhen, double aOffset,
51
             const Optional<double>& aDuration, ErrorResult& aRv);
52
53
  void Start(double aWhen, ErrorResult& aRv) override;
54
  void Stop(double aWhen, ErrorResult& aRv) override;
55
56
  AudioBuffer* GetBuffer(JSContext* aCx) const
57
0
  {
58
0
    return mBuffer;
59
0
  }
60
  void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer)
61
0
  {
62
0
    mBuffer = aBuffer;
63
0
    SendBufferParameterToStream(aCx);
64
0
    SendLoopParametersToStream();
65
0
  }
66
  AudioParam* PlaybackRate() const
67
0
  {
68
0
    return mPlaybackRate;
69
0
  }
70
  AudioParam* Detune() const
71
0
  {
72
0
    return mDetune;
73
0
  }
74
  bool Loop() const
75
0
  {
76
0
    return mLoop;
77
0
  }
78
  void SetLoop(bool aLoop)
79
0
  {
80
0
    mLoop = aLoop;
81
0
    SendLoopParametersToStream();
82
0
  }
83
  double LoopStart() const
84
0
  {
85
0
    return mLoopStart;
86
0
  }
87
  void SetLoopStart(double aStart)
88
0
  {
89
0
    mLoopStart = aStart;
90
0
    SendLoopParametersToStream();
91
0
  }
92
  double LoopEnd() const
93
0
  {
94
0
    return mLoopEnd;
95
0
  }
96
  void SetLoopEnd(double aEnd)
97
0
  {
98
0
    mLoopEnd = aEnd;
99
0
    SendLoopParametersToStream();
100
0
  }
101
  void SendDopplerShiftToStream(double aDopplerShift);
102
103
  void NotifyMainThreadStreamFinished() override;
104
105
  const char* NodeType() const override
106
  {
107
    return "AudioBufferSourceNode";
108
  }
109
110
  size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override;
111
  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
112
113
private:
114
  explicit AudioBufferSourceNode(AudioContext* aContext);
115
  ~AudioBufferSourceNode() = default;
116
117
  friend class AudioBufferSourceNodeEngine;
118
  // START is sent during Start().
119
  // STOP is sent during Stop().
120
  // BUFFERSTART and BUFFEREND are sent when SetBuffer() and Start() have
121
  // been called (along with sending the buffer).
122
  enum EngineParameters {
123
    SAMPLE_RATE,
124
    START,
125
    STOP,
126
    // BUFFERSTART is the "offset" passed to start(), multiplied by
127
    // buffer.sampleRate.
128
    BUFFERSTART,
129
    // BUFFEREND is the sum of "offset" and "duration" passed to start(),
130
    // multiplied by buffer.sampleRate, or the size of the buffer, if smaller.
131
    BUFFEREND,
132
    LOOP,
133
    LOOPSTART,
134
    LOOPEND,
135
    PLAYBACKRATE,
136
    DETUNE,
137
    DOPPLERSHIFT
138
  };
139
140
  void SendLoopParametersToStream();
141
  void SendBufferParameterToStream(JSContext* aCx);
142
  void SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream);
143
144
  double mLoopStart;
145
  double mLoopEnd;
146
  double mOffset;
147
  double mDuration;
148
  RefPtr<AudioBuffer> mBuffer;
149
  RefPtr<AudioParam> mPlaybackRate;
150
  RefPtr<AudioParam> mDetune;
151
  bool mLoop;
152
  bool mStartCalled;
153
};
154
155
} // namespace dom
156
} // namespace mozilla
157
158
#endif