content/media/webaudio/AudioProcessingEvent.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 #ifndef AudioProcessingEvent_h_
     8 #define AudioProcessingEvent_h_
    10 #include "AudioBuffer.h"
    11 #include "ScriptProcessorNode.h"
    12 #include "mozilla/dom/Event.h"
    14 namespace mozilla {
    15 namespace dom {
    17 class AudioProcessingEvent : public Event
    18 {
    19 public:
    20   AudioProcessingEvent(ScriptProcessorNode* aOwner,
    21                        nsPresContext* aPresContext,
    22                        WidgetEvent* aEvent);
    24   NS_DECL_ISUPPORTS_INHERITED
    25   NS_FORWARD_TO_EVENT
    26   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioProcessingEvent, Event)
    28   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    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   }
    40   double PlaybackTime() const
    41   {
    42     return mPlaybackTime;
    43   }
    45   AudioBuffer* GetInputBuffer(ErrorResult& aRv)
    46   {
    47     if (!mInputBuffer) {
    48       mInputBuffer = LazilyCreateBuffer(mNumberOfInputChannels, aRv);
    49     }
    50     return mInputBuffer;
    51   }
    53   AudioBuffer* GetOutputBuffer(ErrorResult& aRv)
    54   {
    55     if (!mOutputBuffer) {
    56       mOutputBuffer = LazilyCreateBuffer(mNode->NumberOfOutputChannels(), aRv);
    57     }
    58     return mOutputBuffer;
    59   }
    61   bool HasOutputBuffer() const
    62   {
    63     return !!mOutputBuffer;
    64   }
    66 private:
    67   already_AddRefed<AudioBuffer>
    68   LazilyCreateBuffer(uint32_t aNumberOfChannels, ErrorResult& rv);
    70 private:
    71   double mPlaybackTime;
    72   nsRefPtr<AudioBuffer> mInputBuffer;
    73   nsRefPtr<AudioBuffer> mOutputBuffer;
    74   nsRefPtr<ScriptProcessorNode> mNode;
    75   uint32_t mNumberOfInputChannels;
    76 };
    78 }
    79 }
    81 #endif

mercurial