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 #ifndef AudioWorkletNode_h_ 8 #define AudioWorkletNode_h_ 9 10 #include "AudioNode.h" 11 12 namespace mozilla { 13 namespace dom { 14 15 class AudioParamMap; 16 struct AudioWorkletNodeOptions; 17 class MessagePort; 18 struct NamedAudioParamTimeline; 19 struct ProcessorErrorDetails; 20 template <typename KeyType, typename ValueType> 21 class Record; 22 23 class AudioWorkletNode : public AudioNode { 24 public: 25 NS_DECL_ISUPPORTS_INHERITED 26 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioWorkletNode, AudioNode) 27 28 IMPL_EVENT_HANDLER(processorerror) 29 30 static already_AddRefed<AudioWorkletNode> Constructor( 31 const GlobalObject& aGlobal, AudioContext& aAudioContext, 32 const nsAString& aName, const AudioWorkletNodeOptions& aOptions, 33 ErrorResult& aRv); 34 35 AudioParamMap* GetParameters(ErrorResult& aRv); 36 Port()37 MessagePort* Port() const { return mPort; }; 38 39 JSObject* WrapObject(JSContext* aCx, 40 JS::Handle<JSObject*> aGivenProto) override; 41 42 // AudioNode methods NumberOfInputs()43 uint16_t NumberOfInputs() const override { return mInputCount; } NumberOfOutputs()44 uint16_t NumberOfOutputs() const override { return mOutputCount; } NodeType()45 const char* NodeType() const override { return "AudioWorkletNode"; } 46 void DispatchProcessorErrorEvent(const ProcessorErrorDetails& aDetails); 47 48 size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override; 49 size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; 50 51 private: 52 AudioWorkletNode(AudioContext* aAudioContext, const nsAString& aName, 53 const AudioWorkletNodeOptions& aOptions); 54 ~AudioWorkletNode() = default; 55 void InitializeParameters(nsTArray<NamedAudioParamTimeline>* aParamTimelines, 56 ErrorResult& aRv); 57 void SendParameterData( 58 const Optional<Record<nsString, double>>& aParameterData); 59 60 nsString mNodeName; 61 RefPtr<MessagePort> mPort; 62 RefPtr<AudioParamMap> mParameters; 63 uint16_t mInputCount; 64 uint16_t mOutputCount; 65 }; 66 67 } // namespace dom 68 } // namespace mozilla 69 70 #endif // AudioWorkletNode_h_ 71