content/media/webaudio/AudioDestinationNode.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/AudioDestinationNode.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,115 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef AudioDestinationNode_h_
    1.11 +#define AudioDestinationNode_h_
    1.12 +
    1.13 +#include "mozilla/dom/AudioChannelBinding.h"
    1.14 +#include "AudioNode.h"
    1.15 +#include "nsIDOMEventListener.h"
    1.16 +#include "nsIAudioChannelAgent.h"
    1.17 +#include "AudioChannelCommon.h"
    1.18 +#include "nsWeakReference.h"
    1.19 +
    1.20 +namespace mozilla {
    1.21 +namespace dom {
    1.22 +
    1.23 +class AudioContext;
    1.24 +
    1.25 +class AudioDestinationNode : public AudioNode
    1.26 +                           , public nsIDOMEventListener
    1.27 +                           , public nsIAudioChannelAgentCallback
    1.28 +                           , public nsSupportsWeakReference
    1.29 +                           , public MainThreadMediaStreamListener
    1.30 +{
    1.31 +public:
    1.32 +  // This node type knows what MediaStreamGraph to use based on
    1.33 +  // whether it's in offline mode.
    1.34 +  AudioDestinationNode(AudioContext* aContext,
    1.35 +                       bool aIsOffline,
    1.36 +                       AudioChannel aChannel = AudioChannel::Normal,
    1.37 +                       uint32_t aNumberOfChannels = 0,
    1.38 +                       uint32_t aLength = 0,
    1.39 +                       float aSampleRate = 0.0f);
    1.40 +
    1.41 +  virtual void DestroyMediaStream() MOZ_OVERRIDE;
    1.42 +
    1.43 +  NS_DECL_ISUPPORTS_INHERITED
    1.44 +  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(AudioDestinationNode, AudioNode)
    1.45 +  NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
    1.46 +
    1.47 +  virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
    1.48 +
    1.49 +  virtual uint16_t NumberOfOutputs() const MOZ_FINAL MOZ_OVERRIDE
    1.50 +  {
    1.51 +    return 0;
    1.52 +  }
    1.53 +
    1.54 +  uint32_t MaxChannelCount() const;
    1.55 +  virtual void SetChannelCount(uint32_t aChannelCount,
    1.56 +                               ErrorResult& aRv) MOZ_OVERRIDE;
    1.57 +
    1.58 +  void Mute();
    1.59 +  void Unmute();
    1.60 +
    1.61 +  void StartRendering();
    1.62 +
    1.63 +  void OfflineShutdown();
    1.64 +
    1.65 +  // nsIDOMEventListener
    1.66 +  NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent);
    1.67 +
    1.68 +  AudioChannel MozAudioChannelType() const;
    1.69 +  void SetMozAudioChannelType(AudioChannel aValue, ErrorResult& aRv);
    1.70 +
    1.71 +  virtual void NotifyMainThreadStateChanged() MOZ_OVERRIDE;
    1.72 +  void FireOfflineCompletionEvent();
    1.73 +
    1.74 +  // An amount that should be added to the MediaStream's current time to
    1.75 +  // get the AudioContext.currentTime.
    1.76 +  double ExtraCurrentTime();
    1.77 +
    1.78 +  // When aIsOnlyNode is true, this is the only node for the AudioContext.
    1.79 +  void SetIsOnlyNodeForContext(bool aIsOnlyNode);
    1.80 +
    1.81 +  virtual const char* NodeType() const
    1.82 +  {
    1.83 +    return "AudioDestinationNode";
    1.84 +  }
    1.85 +
    1.86 +  virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
    1.87 +  virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE;
    1.88 +
    1.89 +private:
    1.90 +  bool CheckAudioChannelPermissions(AudioChannel aValue);
    1.91 +  void CreateAudioChannelAgent();
    1.92 +
    1.93 +  void SetCanPlay(bool aCanPlay);
    1.94 +
    1.95 +  void NotifyStableState();
    1.96 +  void ScheduleStableStateNotification();
    1.97 +
    1.98 +  SelfReference<AudioDestinationNode> mOfflineRenderingRef;
    1.99 +  uint32_t mFramesToProduce;
   1.100 +
   1.101 +  nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
   1.102 +
   1.103 +  // Audio Channel Type.
   1.104 +  AudioChannel mAudioChannel;
   1.105 +  bool mIsOffline;
   1.106 +  bool mHasFinished;
   1.107 +
   1.108 +  TimeStamp mStartedBlockingDueToBeingOnlyNode;
   1.109 +  double mExtraCurrentTime;
   1.110 +  double mExtraCurrentTimeSinceLastStartedBlocking;
   1.111 +  bool mExtraCurrentTimeUpdatedSinceLastStableState;
   1.112 +};
   1.113 +
   1.114 +}
   1.115 +}
   1.116 +
   1.117 +#endif
   1.118 +

mercurial