tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

AudioProcessingEvent.h (2179B)


      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::dom {
     15 
     16 class AudioProcessingEvent final : public Event {
     17 public:
     18  AudioProcessingEvent(ScriptProcessorNode* aOwner, nsPresContext* aPresContext,
     19                       WidgetEvent* aEvent);
     20 
     21  NS_DECL_ISUPPORTS_INHERITED
     22  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioProcessingEvent, Event)
     23 
     24  JSObject* WrapObjectInternal(JSContext* aCx,
     25                               JS::Handle<JSObject*> aGivenProto) override;
     26 
     27  using Event::InitEvent;
     28  void InitEvent(AudioBuffer* aInputBuffer, uint32_t aNumberOfInputChannels,
     29                 double aPlaybackTime) {
     30    InitEvent(u"audioprocess"_ns, CanBubble::eNo, Cancelable::eNo);
     31    mInputBuffer = aInputBuffer;
     32    mNumberOfInputChannels = aNumberOfInputChannels;
     33    mPlaybackTime = aPlaybackTime;
     34  }
     35 
     36  double PlaybackTime() const { return mPlaybackTime; }
     37 
     38  AudioBuffer* GetInputBuffer(ErrorResult& aRv) {
     39    if (!mInputBuffer) {
     40      mInputBuffer = LazilyCreateBuffer(mNumberOfInputChannels, aRv);
     41    }
     42    return mInputBuffer;
     43  }
     44 
     45  AudioBuffer* GetOutputBuffer(ErrorResult& aRv) {
     46    if (!mOutputBuffer) {
     47      mOutputBuffer = LazilyCreateBuffer(mNode->NumberOfOutputChannels(), aRv);
     48    }
     49    return mOutputBuffer;
     50  }
     51 
     52  bool HasOutputBuffer() const { return !!mOutputBuffer; }
     53 
     54 protected:
     55  virtual ~AudioProcessingEvent();
     56 
     57 private:
     58  already_AddRefed<AudioBuffer> LazilyCreateBuffer(uint32_t aNumberOfChannels,
     59                                                   ErrorResult& rv);
     60 
     61 private:
     62  double mPlaybackTime;
     63  RefPtr<AudioBuffer> mInputBuffer;
     64  RefPtr<AudioBuffer> mOutputBuffer;
     65  RefPtr<ScriptProcessorNode> mNode;
     66  uint32_t mNumberOfInputChannels;
     67 };
     68 
     69 }  // namespace mozilla::dom
     70 
     71 #endif