Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/webaudio/AudioWorkletNode.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 https://mozilla.org/MPL/2.0/. */
6
7
#include "AudioWorkletNode.h"
8
9
#include "AudioParamMap.h"
10
#include "mozilla/dom/AudioWorkletNodeBinding.h"
11
#include "mozilla/dom/MessagePort.h"
12
13
namespace mozilla {
14
namespace dom {
15
16
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(AudioWorkletNode, AudioNode)
17
18
AudioWorkletNode::AudioWorkletNode(AudioContext* aAudioContext,
19
                                   const nsAString& aName)
20
  : AudioNode(aAudioContext,
21
              2,
22
              ChannelCountMode::Max,
23
              ChannelInterpretation::Speakers)
24
  , mNodeName(aName)
25
0
{
26
0
}
27
28
/* static */ already_AddRefed<AudioWorkletNode>
29
AudioWorkletNode::Constructor(const GlobalObject& aGlobal,
30
                              AudioContext& aAudioContext,
31
                              const nsAString& aName,
32
                              const AudioWorkletNodeOptions& aOptions,
33
                              ErrorResult& aRv)
34
0
{
35
0
  if (aAudioContext.CheckClosed(aRv)) {
36
0
    return nullptr;
37
0
  }
38
0
39
0
  if (aOptions.mNumberOfInputs == 0 && aOptions.mNumberOfOutputs == 0) {
40
0
    aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
41
0
    return nullptr;
42
0
  }
43
0
44
0
  if (aOptions.mOutputChannelCount.WasPassed()) {
45
0
    if (aOptions.mOutputChannelCount.Value().Length() !=
46
0
        aOptions.mNumberOfOutputs) {
47
0
      aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
48
0
      return nullptr;
49
0
    }
50
0
51
0
    for (uint32_t channelCount : aOptions.mOutputChannelCount.Value()) {
52
0
      if (channelCount == 0 ||
53
0
          channelCount > WebAudioUtils::MaxChannelCount) {
54
0
        aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
55
0
        return nullptr;
56
0
      }
57
0
    }
58
0
  }
59
0
60
0
  RefPtr<AudioWorkletNode> audioWorkletNode =
61
0
      new AudioWorkletNode(&aAudioContext, aName);
62
0
63
0
  audioWorkletNode->Initialize(aOptions, aRv);
64
0
  if (NS_WARN_IF(aRv.Failed())) {
65
0
    return nullptr;
66
0
  }
67
0
68
0
  return audioWorkletNode.forget();
69
0
}
70
71
AudioParamMap* AudioWorkletNode::GetParameters(ErrorResult& aRv) const
72
0
{
73
0
  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
74
0
  return nullptr;
75
0
}
76
77
MessagePort* AudioWorkletNode::GetPort(ErrorResult& aRv) const
78
0
{
79
0
  aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
80
0
  return nullptr;
81
0
}
82
83
JSObject*
84
AudioWorkletNode::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
85
0
{
86
0
  return AudioWorkletNode_Binding::Wrap(aCx, this, aGivenProto);
87
0
}
88
89
size_t
90
AudioWorkletNode::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
91
0
{
92
0
  size_t amount = AudioNode::SizeOfExcludingThis(aMallocSizeOf);
93
0
  return amount;
94
0
}
95
96
size_t
97
AudioWorkletNode::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
98
0
{
99
0
  return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
100
0
}
101
102
} // namespace dom
103
} // namespace mozilla