Line data Source code
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 0 : NS_FORWARD_TO_EVENT
26 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioProcessingEvent, Event)
27 :
28 : JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
29 :
30 0 : void InitEvent(AudioBuffer* aInputBuffer,
31 : uint32_t aNumberOfInputChannels,
32 : double aPlaybackTime)
33 : {
34 0 : InitEvent(NS_LITERAL_STRING("audioprocess"), false, false);
35 0 : mInputBuffer = aInputBuffer;
36 0 : mNumberOfInputChannels = aNumberOfInputChannels;
37 0 : mPlaybackTime = aPlaybackTime;
38 0 : }
39 :
40 0 : double PlaybackTime() const
41 : {
42 0 : return mPlaybackTime;
43 : }
44 :
45 0 : AudioBuffer* GetInputBuffer(ErrorResult& aRv)
46 : {
47 0 : if (!mInputBuffer) {
48 0 : mInputBuffer = LazilyCreateBuffer(mNumberOfInputChannels, aRv);
49 : }
50 0 : return mInputBuffer;
51 : }
52 :
53 0 : AudioBuffer* GetOutputBuffer(ErrorResult& aRv)
54 : {
55 0 : if (!mOutputBuffer) {
56 0 : mOutputBuffer = LazilyCreateBuffer(mNode->NumberOfOutputChannels(), aRv);
57 : }
58 0 : return mOutputBuffer;
59 : }
60 :
61 0 : bool HasOutputBuffer() const
62 : {
63 0 : return !!mOutputBuffer;
64 : }
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 :
|