content/media/webaudio/AudioListener.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.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef AudioListener_h_
michael@0 8 #define AudioListener_h_
michael@0 9
michael@0 10 #include "nsWrapperCache.h"
michael@0 11 #include "nsCycleCollectionParticipant.h"
michael@0 12 #include "mozilla/Attributes.h"
michael@0 13 #include "nsAutoPtr.h"
michael@0 14 #include "ThreeDPoint.h"
michael@0 15 #include "AudioContext.h"
michael@0 16 #include "PannerNode.h"
michael@0 17 #include "WebAudioUtils.h"
michael@0 18 #include "js/TypeDecls.h"
michael@0 19 #include "mozilla/MemoryReporting.h"
michael@0 20
michael@0 21 namespace mozilla {
michael@0 22
michael@0 23 namespace dom {
michael@0 24
michael@0 25 class AudioListener MOZ_FINAL : public nsWrapperCache
michael@0 26 {
michael@0 27 public:
michael@0 28 explicit AudioListener(AudioContext* aContext);
michael@0 29
michael@0 30 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioListener)
michael@0 31 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioListener)
michael@0 32
michael@0 33 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
michael@0 34
michael@0 35 AudioContext* GetParentObject() const
michael@0 36 {
michael@0 37 return mContext;
michael@0 38 }
michael@0 39
michael@0 40 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
michael@0 41
michael@0 42 double DopplerFactor() const
michael@0 43 {
michael@0 44 return mDopplerFactor;
michael@0 45 }
michael@0 46 void SetDopplerFactor(double aDopplerFactor)
michael@0 47 {
michael@0 48 if (WebAudioUtils::FuzzyEqual(mDopplerFactor, aDopplerFactor)) {
michael@0 49 return;
michael@0 50 }
michael@0 51 mDopplerFactor = aDopplerFactor;
michael@0 52 SendDoubleParameterToStream(PannerNode::LISTENER_DOPPLER_FACTOR, mDopplerFactor);
michael@0 53 }
michael@0 54
michael@0 55 double SpeedOfSound() const
michael@0 56 {
michael@0 57 return mSpeedOfSound;
michael@0 58 }
michael@0 59 void SetSpeedOfSound(double aSpeedOfSound)
michael@0 60 {
michael@0 61 if (WebAudioUtils::FuzzyEqual(mSpeedOfSound, aSpeedOfSound)) {
michael@0 62 return;
michael@0 63 }
michael@0 64 mSpeedOfSound = aSpeedOfSound;
michael@0 65 SendDoubleParameterToStream(PannerNode::LISTENER_SPEED_OF_SOUND, mSpeedOfSound);
michael@0 66 }
michael@0 67
michael@0 68 void SetPosition(double aX, double aY, double aZ)
michael@0 69 {
michael@0 70 if (WebAudioUtils::FuzzyEqual(mPosition.x, aX) &&
michael@0 71 WebAudioUtils::FuzzyEqual(mPosition.y, aY) &&
michael@0 72 WebAudioUtils::FuzzyEqual(mPosition.z, aZ)) {
michael@0 73 return;
michael@0 74 }
michael@0 75 mPosition.x = aX;
michael@0 76 mPosition.y = aY;
michael@0 77 mPosition.z = aZ;
michael@0 78 SendThreeDPointParameterToStream(PannerNode::LISTENER_POSITION, mPosition);
michael@0 79 }
michael@0 80
michael@0 81 const ThreeDPoint& Position() const
michael@0 82 {
michael@0 83 return mPosition;
michael@0 84 }
michael@0 85
michael@0 86 void SetOrientation(double aX, double aY, double aZ,
michael@0 87 double aXUp, double aYUp, double aZUp);
michael@0 88
michael@0 89 const ThreeDPoint& Velocity() const
michael@0 90 {
michael@0 91 return mVelocity;
michael@0 92 }
michael@0 93
michael@0 94 void SetVelocity(double aX, double aY, double aZ)
michael@0 95 {
michael@0 96 if (WebAudioUtils::FuzzyEqual(mVelocity.x, aX) &&
michael@0 97 WebAudioUtils::FuzzyEqual(mVelocity.y, aY) &&
michael@0 98 WebAudioUtils::FuzzyEqual(mVelocity.z, aZ)) {
michael@0 99 return;
michael@0 100 }
michael@0 101 mVelocity.x = aX;
michael@0 102 mVelocity.y = aY;
michael@0 103 mVelocity.z = aZ;
michael@0 104 SendThreeDPointParameterToStream(PannerNode::LISTENER_VELOCITY, mVelocity);
michael@0 105 UpdatePannersVelocity();
michael@0 106 }
michael@0 107
michael@0 108 void RegisterPannerNode(PannerNode* aPannerNode);
michael@0 109 void UnregisterPannerNode(PannerNode* aPannerNode);
michael@0 110
michael@0 111 private:
michael@0 112 void SendDoubleParameterToStream(uint32_t aIndex, double aValue);
michael@0 113 void SendThreeDPointParameterToStream(uint32_t aIndex, const ThreeDPoint& aValue);
michael@0 114 void UpdatePannersVelocity();
michael@0 115
michael@0 116 private:
michael@0 117 friend class PannerNode;
michael@0 118 nsRefPtr<AudioContext> mContext;
michael@0 119 ThreeDPoint mPosition;
michael@0 120 ThreeDPoint mFrontVector;
michael@0 121 ThreeDPoint mRightVector;
michael@0 122 ThreeDPoint mVelocity;
michael@0 123 double mDopplerFactor;
michael@0 124 double mSpeedOfSound;
michael@0 125 nsTArray<WeakPtr<PannerNode> > mPanners;
michael@0 126 };
michael@0 127
michael@0 128 }
michael@0 129 }
michael@0 130
michael@0 131 #endif
michael@0 132

mercurial