content/media/webaudio/AudioProcessingEvent.h

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:79710ce804d6
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 : public Event
18 {
19 public:
20 AudioProcessingEvent(ScriptProcessorNode* aOwner,
21 nsPresContext* aPresContext,
22 WidgetEvent* aEvent);
23
24 NS_DECL_ISUPPORTS_INHERITED
25 NS_FORWARD_TO_EVENT
26 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioProcessingEvent, Event)
27
28 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
29
30 void InitEvent(AudioBuffer* aInputBuffer,
31 uint32_t aNumberOfInputChannels,
32 double aPlaybackTime)
33 {
34 InitEvent(NS_LITERAL_STRING("audioprocess"), false, false);
35 mInputBuffer = aInputBuffer;
36 mNumberOfInputChannels = aNumberOfInputChannels;
37 mPlaybackTime = aPlaybackTime;
38 }
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 {
63 return !!mOutputBuffer;
64 }
65
66 private:
67 already_AddRefed<AudioBuffer>
68 LazilyCreateBuffer(uint32_t aNumberOfChannels, ErrorResult& rv);
69
70 private:
71 double mPlaybackTime;
72 nsRefPtr<AudioBuffer> mInputBuffer;
73 nsRefPtr<AudioBuffer> mOutputBuffer;
74 nsRefPtr<ScriptProcessorNode> mNode;
75 uint32_t mNumberOfInputChannels;
76 };
77
78 }
79 }
80
81 #endif
82

mercurial