Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/webaudio/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
0
  {
31
0
    return 0;
32
0
  }
33
  AudioBufferSourceNode* AsAudioBufferSourceNode() override
34
0
  {
35
0
    return this;
36
0
  }
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
  {
45
    return Create(aGlobal.Context(), aAudioContext, aOptions, aRv);
46
  }
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
  {
58
    return mBuffer;
59
  }
60
  void SetBuffer(JSContext* aCx, AudioBuffer* aBuffer)
61
  {
62
    mBuffer = aBuffer;
63
    SendBufferParameterToStream(aCx);
64
    SendLoopParametersToStream();
65
  }
66
  AudioParam* PlaybackRate() const
67
  {
68
    return mPlaybackRate;
69
  }
70
  AudioParam* Detune() const
71
  {
72
    return mDetune;
73
  }
74
  bool Loop() const
75
  {
76
    return mLoop;
77
  }
78
  void SetLoop(bool aLoop)
79
  {
80
    mLoop = aLoop;
81
    SendLoopParametersToStream();
82
  }
83
  double LoopStart() const
84
  {
85
    return mLoopStart;
86
  }
87
  void SetLoopStart(double aStart)
88
  {
89
    mLoopStart = aStart;
90
    SendLoopParametersToStream();
91
  }
92
  double LoopEnd() const
93
  {
94
    return mLoopEnd;
95
  }
96
  void SetLoopEnd(double aEnd)
97
  {
98
    mLoopEnd = aEnd;
99
    SendLoopParametersToStream();
100
  }
101
  void SendDopplerShiftToStream(double aDopplerShift);
102
103
  void NotifyMainThreadStreamFinished() override;
104
105
  const char* NodeType() const override
106
0
  {
107
0
    return "AudioBufferSourceNode";
108
0
  }
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
0
  ~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