AudioProcessingEvent.cpp (1843B)
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 #include "AudioProcessingEvent.h" 8 9 #include "AudioContext.h" 10 #include "mozilla/dom/AudioProcessingEventBinding.h" 11 #include "mozilla/dom/ScriptSettings.h" 12 #include "nsGlobalWindowInner.h" 13 14 namespace mozilla::dom { 15 16 NS_IMPL_CYCLE_COLLECTION_INHERITED(AudioProcessingEvent, Event, mInputBuffer, 17 mOutputBuffer, mNode) 18 19 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(AudioProcessingEvent) 20 NS_INTERFACE_MAP_END_INHERITING(Event) 21 22 NS_IMPL_ADDREF_INHERITED(AudioProcessingEvent, Event) 23 NS_IMPL_RELEASE_INHERITED(AudioProcessingEvent, Event) 24 25 AudioProcessingEvent::AudioProcessingEvent(ScriptProcessorNode* aOwner, 26 nsPresContext* aPresContext, 27 WidgetEvent* aEvent) 28 : Event(aOwner, aPresContext, aEvent), mPlaybackTime(0.0), mNode(aOwner) {} 29 30 AudioProcessingEvent::~AudioProcessingEvent() = default; 31 32 JSObject* AudioProcessingEvent::WrapObjectInternal( 33 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 34 return AudioProcessingEvent_Binding::Wrap(aCx, this, aGivenProto); 35 } 36 37 already_AddRefed<AudioBuffer> AudioProcessingEvent::LazilyCreateBuffer( 38 uint32_t aNumberOfChannels, ErrorResult& aRv) { 39 RefPtr<AudioBuffer> buffer = AudioBuffer::Create( 40 mNode->Context()->GetOwnerWindow(), aNumberOfChannels, 41 mNode->BufferSize(), mNode->Context()->SampleRate(), aRv); 42 MOZ_ASSERT(buffer || aRv.ErrorCodeIs(NS_ERROR_OUT_OF_MEMORY)); 43 return buffer.forget(); 44 } 45 46 } // namespace mozilla::dom