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 AudioListener_h_ 8 #define AudioListener_h_ 9 10 #include "nsWrapperCache.h" 11 #include "nsCycleCollectionParticipant.h" 12 #include "mozilla/Attributes.h" 13 #include "ThreeDPoint.h" 14 #include "AudioContext.h" 15 #include "PannerNode.h" 16 #include "WebAudioUtils.h" 17 #include "js/TypeDecls.h" 18 #include "mozilla/MemoryReporting.h" 19 20 namespace mozilla { 21 22 namespace dom { 23 24 class AudioListenerEngine final { 25 public: 26 NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AudioListenerEngine) 27 28 AudioListenerEngine(); 29 30 enum class AudioListenerParameter { 31 POSITION, 32 FRONT, // unit length 33 RIGHT // unit length, orthogonal to FRONT 34 }; 35 void RecvListenerEngineEvent( 36 AudioListenerEngine::AudioListenerParameter aParameter, 37 const ThreeDPoint& aValue); 38 const ThreeDPoint& Position() const; 39 const ThreeDPoint& FrontVector() const; 40 const ThreeDPoint& RightVector() const; 41 42 private: 43 ~AudioListenerEngine() = default; 44 45 ThreeDPoint mPosition; 46 ThreeDPoint mFrontVector; 47 ThreeDPoint mRightVector; 48 }; 49 50 class AudioListener final : public nsWrapperCache { 51 public: 52 explicit AudioListener(AudioContext* aContext); 53 54 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioListener) 55 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioListener) 56 57 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 58 GetParentObject()59 AudioContext* GetParentObject() const { return mContext; } 60 61 JSObject* WrapObject(JSContext* aCx, 62 JS::Handle<JSObject*> aGivenProto) override; 63 64 void SetPosition(double aX, double aY, double aZ); 65 void SetOrientation(double aX, double aY, double aZ, double aXUp, double aYUp, 66 double aZUp); 67 Engine()68 AudioListenerEngine* Engine() { return mEngine.get(); } 69 70 private: 71 void SendListenerEngineEvent( 72 AudioListenerEngine::AudioListenerParameter aParameter, 73 const ThreeDPoint& aValue); 74 75 ~AudioListener() = default; 76 77 private: 78 RefPtr<AudioContext> mContext; 79 RefPtr<AudioListenerEngine> mEngine; 80 ThreeDPoint mPosition; 81 ThreeDPoint mFrontVector; 82 ThreeDPoint mRightVector; 83 }; 84 85 } // namespace dom 86 } // namespace mozilla 87 88 #endif 89