From 026206633a5773436c84db75f45000d5fb505708 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Fri, 3 May 2013 10:59:41 -0400 Subject: [PATCH] Bug 868409 - ScriptProcessorNode's playing ref should remain active as long as there are outstanding connections; r=roc --- content/media/webaudio/AudioNode.h | 38 ++++++++++++++++++++ content/media/webaudio/ScriptProcessorNode.h | 4 +-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/content/media/webaudio/AudioNode.h b/content/media/webaudio/AudioNode.h index 3f387241c545..a201d48da063 100644 --- a/content/media/webaudio/AudioNode.h +++ b/content/media/webaudio/AudioNode.h @@ -59,6 +59,44 @@ private: bool mHeld; }; +template +class SelfCountedReference { +public: + SelfCountedReference() : mRefCnt(0) {} + ~SelfCountedReference() + { + NS_ASSERTION(mRefCnt == 0, "Forgot to drop the self reference?"); + } + + void Take(T* t) + { + if (mRefCnt++ == 0) { + t->AddRef(); + } + } + void Drop(T* t) + { + if (mRefCnt > 0) { + --mRefCnt; + if (mRefCnt == 0) { + t->Release(); + } + } + } + void ForceDrop(T* t) + { + if (mRefCnt > 0) { + mRefCnt = 0; + t->Release(); + } + } + + operator bool() const { return mRefCnt > 0; } + +private: + nsrefcnt mRefCnt; +}; + /** * The DOM object representing a Web Audio AudioNode. * diff --git a/content/media/webaudio/ScriptProcessorNode.h b/content/media/webaudio/ScriptProcessorNode.h index af78c2f462a4..05e6cd258882 100644 --- a/content/media/webaudio/ScriptProcessorNode.h +++ b/content/media/webaudio/ScriptProcessorNode.h @@ -82,14 +82,14 @@ public: void Stop() { - mPlayingRef.Drop(this); + mPlayingRef.ForceDrop(this); } private: nsAutoPtr mSharedBuffers; const uint32_t mBufferSize; const uint32_t mNumberOfOutputChannels; - SelfReference mPlayingRef; // a reference to self while planing + SelfCountedReference mPlayingRef; // a reference to self while planing }; }