diff --git a/dom/media/webaudio/AudioListener.cpp b/dom/media/webaudio/AudioListener.cpp index ba4073810e31..679b71b476fa 100644 --- a/dom/media/webaudio/AudioListener.cpp +++ b/dom/media/webaudio/AudioListener.cpp @@ -62,7 +62,7 @@ AudioListenerEngine::RightVector() const AudioListener::AudioListener(AudioContext* aContext) : mContext(aContext) - , mEngine(MakeUnique()) + , mEngine(new AudioListenerEngine()) , mPosition() , mFrontVector(0., 0., -1.) , mRightVector(1., 0., 0.) @@ -142,19 +142,18 @@ AudioListener::SendListenerEngineEvent( , mEngine(aEngine) , mParameter(aParameter) , mValue(aValue) - { - } + { } void Run() override { mEngine->RecvListenerEngineEvent(mParameter, mValue); } - AudioListenerEngine* mEngine; + RefPtr mEngine; AudioListenerEngine::AudioListenerParameter mParameter; ThreeDPoint mValue; }; mContext->DestinationStream()->GraphImpl()->AppendMessage( - MakeUnique(mEngine.get(), aParameter, aValue)); + MakeUnique(Engine(), aParameter, aValue)); } size_t diff --git a/dom/media/webaudio/AudioListener.h b/dom/media/webaudio/AudioListener.h index 34c4b376d0c9..531b9e9f6862 100644 --- a/dom/media/webaudio/AudioListener.h +++ b/dom/media/webaudio/AudioListener.h @@ -24,13 +24,16 @@ namespace dom { class AudioListenerEngine final { public: + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AudioListenerEngine) + + AudioListenerEngine(); + enum class AudioListenerParameter { POSITION, FRONT, // unit length RIGHT // unit length, orthogonal to FRONT }; - AudioListenerEngine(); void RecvListenerEngineEvent( AudioListenerEngine::AudioListenerParameter aParameter, const ThreeDPoint& aValue); @@ -39,6 +42,8 @@ public: const ThreeDPoint& RightVector() const; private: + ~AudioListenerEngine() = default; + ThreeDPoint mPosition; ThreeDPoint mFrontVector; ThreeDPoint mRightVector; @@ -65,7 +70,7 @@ public: void SetOrientation(double aX, double aY, double aZ, double aXUp, double aYUp, double aZUp); - const AudioListenerEngine* Engine() { return mEngine.get(); } + AudioListenerEngine* Engine() { return mEngine.get(); } private: void SendListenerEngineEvent( @@ -77,7 +82,7 @@ private: void SendThreeDPointParameterToStream(uint32_t aIndex, const ThreeDPoint& aValue); private: RefPtr mContext; - const UniquePtr mEngine; + RefPtr mEngine; ThreeDPoint mPosition; ThreeDPoint mFrontVector; ThreeDPoint mRightVector; diff --git a/dom/media/webaudio/PannerNode.cpp b/dom/media/webaudio/PannerNode.cpp index 0f09047749ef..b270cda9cdcc 100644 --- a/dom/media/webaudio/PannerNode.cpp +++ b/dom/media/webaudio/PannerNode.cpp @@ -44,7 +44,7 @@ class PannerNodeEngine final : public AudioNodeEngine public: explicit PannerNodeEngine(AudioNode* aNode, AudioDestinationNode* aDestination, - const AudioListenerEngine* aListenerEngine) + AudioListenerEngine* aListenerEngine) : AudioNodeEngine(aNode) , mDestination(aDestination->Stream()) , mListenerEngine(aListenerEngine) @@ -256,9 +256,7 @@ public: // thread untile mPanningModelFunction has changed, and this happens strictly // later, via a MediaStreamGraph ControlMessage. nsAutoPtr mHRTFPanner; - // This is set in the ctor, and guaranteed to live longer than this engine: - // its lifetime is the same as the AudioContext itself. - const AudioListenerEngine* mListenerEngine; + RefPtr mListenerEngine; typedef void (PannerNodeEngine::*PanningModelFunction)(const AudioBlock& aInput, AudioBlock* aOutput, StreamTime tick); PanningModelFunction mPanningModelFunction; typedef float (PannerNodeEngine::*DistanceModelFunction)(double aDistance);