Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/webaudio/AudioProcessingEvent.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 AudioProcessingEvent_h_
8
#define AudioProcessingEvent_h_
9
10
#include "AudioBuffer.h"
11
#include "ScriptProcessorNode.h"
12
#include "mozilla/dom/Event.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
class AudioProcessingEvent final : public Event
18
{
19
public:
20
  AudioProcessingEvent(ScriptProcessorNode* aOwner,
21
                       nsPresContext* aPresContext,
22
                       WidgetEvent* aEvent);
23
24
  NS_DECL_ISUPPORTS_INHERITED
25
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioProcessingEvent, Event)
26
27
  JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
28
29
  using Event::InitEvent;
30
  void InitEvent(AudioBuffer* aInputBuffer,
31
                 uint32_t aNumberOfInputChannels,
32
                 double aPlaybackTime)
33
0
  {
34
0
    InitEvent(NS_LITERAL_STRING("audioprocess"), CanBubble::eNo, Cancelable::eNo);
35
0
    mInputBuffer = aInputBuffer;
36
0
    mNumberOfInputChannels = aNumberOfInputChannels;
37
0
    mPlaybackTime = aPlaybackTime;
38
0
  }
39
40
  double PlaybackTime() const
41
  {
42
    return mPlaybackTime;
43
  }
44
45
  AudioBuffer* GetInputBuffer(ErrorResult& aRv)
46
  {
47
    if (!mInputBuffer) {
48
      mInputBuffer = LazilyCreateBuffer(mNumberOfInputChannels, aRv);
49
    }
50
    return mInputBuffer;
51
  }
52
53
  AudioBuffer* GetOutputBuffer(ErrorResult& aRv)
54
  {
55
    if (!mOutputBuffer) {
56
      mOutputBuffer = LazilyCreateBuffer(mNode->NumberOfOutputChannels(), aRv);
57
    }
58
    return mOutputBuffer;
59
  }
60
61
  bool HasOutputBuffer() const
62
0
  {
63
0
    return !!mOutputBuffer;
64
0
  }
65
66
protected:
67
  virtual ~AudioProcessingEvent();
68
69
private:
70
  already_AddRefed<AudioBuffer>
71
  LazilyCreateBuffer(uint32_t aNumberOfChannels, ErrorResult& rv);
72
73
private:
74
  double mPlaybackTime;
75
  RefPtr<AudioBuffer> mInputBuffer;
76
  RefPtr<AudioBuffer> mOutputBuffer;
77
  RefPtr<ScriptProcessorNode> mNode;
78
  uint32_t mNumberOfInputChannels;
79
};
80
81
} // namespace dom
82
} // namespace mozilla
83
84
#endif
85