content/media/webaudio/AudioDestinationNode.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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 AudioDestinationNode_h_
     8 #define AudioDestinationNode_h_
    10 #include "mozilla/dom/AudioChannelBinding.h"
    11 #include "AudioNode.h"
    12 #include "nsIDOMEventListener.h"
    13 #include "nsIAudioChannelAgent.h"
    14 #include "AudioChannelCommon.h"
    15 #include "nsWeakReference.h"
    17 namespace mozilla {
    18 namespace dom {
    20 class AudioContext;
    22 class AudioDestinationNode : public AudioNode
    23                            , public nsIDOMEventListener
    24                            , public nsIAudioChannelAgentCallback
    25                            , public nsSupportsWeakReference
    26                            , public MainThreadMediaStreamListener
    27 {
    28 public:
    29   // This node type knows what MediaStreamGraph to use based on
    30   // whether it's in offline mode.
    31   AudioDestinationNode(AudioContext* aContext,
    32                        bool aIsOffline,
    33                        AudioChannel aChannel = AudioChannel::Normal,
    34                        uint32_t aNumberOfChannels = 0,
    35                        uint32_t aLength = 0,
    36                        float aSampleRate = 0.0f);
    38   virtual void DestroyMediaStream() MOZ_OVERRIDE;
    40   NS_DECL_ISUPPORTS_INHERITED
    41   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioDestinationNode, AudioNode)
    42   NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
    44   virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    46   virtual uint16_t NumberOfOutputs() const MOZ_FINAL MOZ_OVERRIDE
    47   {
    48     return 0;
    49   }
    51   uint32_t MaxChannelCount() const;
    52   virtual void SetChannelCount(uint32_t aChannelCount,
    53                                ErrorResult& aRv) MOZ_OVERRIDE;
    55   void Mute();
    56   void Unmute();
    58   void StartRendering();
    60   void OfflineShutdown();
    62   // nsIDOMEventListener
    63   NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
    65   AudioChannel MozAudioChannelType() const;
    66   void SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv);
    68   virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE;
    69   void FireOfflineCompletionEvent();
    71   // An amount that should be added to the MediaStream's current time to
    72   // get the AudioContext.currentTime.
    73   double ExtraCurrentTime();
    75   // When aIsOnlyNode is true, this is the only node for the AudioContext.
    76   void SetIsOnlyNodeForContext(bool aIsOnlyNode);
    78   virtual const char* NodeType() const
    79   {
    80     return "AudioDestinationNode";
    81   }
    83   virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
    84   virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
    86 private:
    87   bool CheckAudioChannelPermissions(AudioChannel aValue);
    88   void CreateAudioChannelAgent();
    90   void SetCanPlay(bool aCanPlay);
    92   void NotifyStableState();
    93   void ScheduleStableStateNotification();
    95   SelfReference<AudioDestinationNode> mOfflineRenderingRef;
    96   uint32_t mFramesToProduce;
    98   nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
   100   // Audio Channel Type.
   101   AudioChannel mAudioChannel;
   102   bool mIsOffline;
   103   bool mHasFinished;
   105   TimeStamp mStartedBlockingDueToBeingOnlyNode;
   106   double mExtraCurrentTime;
   107   double mExtraCurrentTimeSinceLastStartedBlocking;
   108   bool mExtraCurrentTimeUpdatedSinceLastStableState;
   109 };
   111 }
   112 }
   114 #endif

mercurial