Backing out 24aed997dbcd
authorDoug Turner <dougt@dougt.org>
Sat, 27 Nov 2010 21:40:43 -0800
changeset 58308 9537e23f97081f3df45d0e4356035e8662b2dc2a
parent 58307 24aed997dbcd9b157252b4bb1ec0ce77005c3a2b
child 58309 bb43b6a9b62114137cfc6461baff7f619e378708
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs614160
milestone2.0b8pre
Backing out 24aed997dbcd Matthew Gregan – Bug 614160 - Fix remote audio ownership and avoid sending IPCs when actor is being destroyed. r=dougt a=blocking=fennec It caused windows builds to go red. qq. a=me
content/media/nsAudioStream.cpp
dom/ipc/AudioChild.cpp
dom/ipc/AudioChild.h
dom/ipc/AudioParent.cpp
dom/ipc/AudioParent.h
dom/ipc/ContentChild.cpp
dom/ipc/ContentParent.cpp
--- a/content/media/nsAudioStream.cpp
+++ b/content/media/nsAudioStream.cpp
@@ -133,27 +133,33 @@ class nsAudioStreamRemote : public nsAud
   void SetVolume(float aVolume);
   void Drain();
   void Pause();
   void Resume();
   PRInt64 GetPosition();
   PRInt64 GetSampleOffset();
   PRBool IsPaused();
 
-  nsRefPtr<AudioChild> mAudioChild;
+  AudioChild* mAudioChild;
 
   SampleFormat mFormat;
   int mRate;
   int mChannels;
   // PR_TRUE if this audio stream is paused.
   PRPackedBool mPaused;
 
   PRInt32 mBytesPerSample;
 
   friend class AudioInitEvent;
+  friend class AudioShutdownEvent;
+  friend class AudioWriteEvent;
+  friend class AudioSetVolumeEvent;
+  friend class AudioPauseEvent;
+  friend class AudioDrainEvent;
+  friend class AudioGetSampleEvent;
 };
 
 class AudioInitEvent : public nsRunnable
 {
  public:
   AudioInitEvent(nsAudioStreamRemote* owner)
   {
     mOwner = owner;
@@ -170,128 +176,111 @@ class AudioInitEvent : public nsRunnable
   }
   
   nsRefPtr<nsAudioStreamRemote> mOwner;
 };
 
 class AudioWriteEvent : public nsRunnable
 {
  public:
-  AudioWriteEvent(AudioChild* aChild,
+  AudioWriteEvent(nsAudioStreamRemote* owner,
                   const void* aBuf,
                   PRUint32 aNumberOfSamples,
                   PRUint32 aBytesPerSample)
   {    
-    mAudioChild = aChild;
+    mOwner = owner;
     mBytesPerSample = aBytesPerSample;
     mBuffer.Assign((const char*)aBuf, aNumberOfSamples*aBytesPerSample);
   }
 
   NS_IMETHOD Run()
   {
-    if (!mAudioChild->IsIPCOpen())
+    if (!mOwner->mAudioChild)
       return NS_OK;
 
-    mAudioChild->SendWrite(mBuffer,
-                           mBuffer.Length() / mBytesPerSample);
+    mOwner->mAudioChild->SendWrite(mBuffer,
+                                   mBuffer.Length() / mBytesPerSample);
     return NS_OK;
   }
 
-  nsRefPtr<AudioChild> mAudioChild;
+  nsRefPtr<nsAudioStreamRemote> mOwner;
   nsCString mBuffer;
   PRUint32 mBytesPerSample;
 };
 
 class AudioSetVolumeEvent : public nsRunnable
 {
  public:
-  AudioSetVolumeEvent(AudioChild* aChild, float volume)
+  AudioSetVolumeEvent(nsAudioStreamRemote* owner, float volume)
   {
-    mAudioChild = aChild;
+    mOwner = owner;
     mVolume = volume;
   }
 
   NS_IMETHOD Run()
   {
-    if (!mAudioChild->IsIPCOpen())
+    if (!mOwner->mAudioChild)
       return NS_OK;
 
-    mAudioChild->SendSetVolume(mVolume);
+    mOwner->mAudioChild->SendSetVolume(mVolume);
     return NS_OK;
   }
   
-  nsRefPtr<AudioChild> mAudioChild;
+  nsRefPtr<nsAudioStreamRemote> mOwner;
   float mVolume;
 };
 
 class AudioDrainEvent : public nsRunnable
 {
  public:
-  AudioDrainEvent(AudioChild* aChild)
+  AudioDrainEvent(nsAudioStreamRemote* owner)
   {
-    mAudioChild = aChild;
+    mOwner = owner;
   }
 
   NS_IMETHOD Run()
   {
-    if (!mAudioChild->IsIPCOpen())
+    if (!mOwner->mAudioChild)
       return NS_OK;
 
-    mAudioChild->SendDrain();
+    mOwner->mAudioChild->SendDrain();
     return NS_OK;
   }
   
-  nsRefPtr<AudioChild> mAudioChild;
+  nsRefPtr<nsAudioStreamRemote> mOwner;
 };
 
 
 class AudioPauseEvent : public nsRunnable
 {
  public:
-  AudioPauseEvent(AudioChild* aChild, PRBool pause)
+  AudioPauseEvent(nsAudioStreamRemote* owner, PRBool pause)
   {
-    mAudioChild = aChild;
+    mOwner = owner;
     mPause = pause;
   }
 
   NS_IMETHOD Run()
   {
-    if (!mAudioChild->IsIPCOpen())
+    if (!mOwner->mAudioChild)
       return NS_OK;
 
     if (mPause)
-      mAudioChild->SendPause();
+      mOwner->mAudioChild->SendPause();
     else
-      mAudioChild->SendResume();
+      mOwner->mAudioChild->SendResume();
 
     return NS_OK;
   }
   
-  nsRefPtr<AudioChild> mAudioChild;
+  nsRefPtr<nsAudioStreamRemote> mOwner;
   PRBool mPause;
 };
 
 
-class AudioShutdownEvent : public nsRunnable
-{
- public:
-  AudioShutdownEvent(AudioChild* aChild)
-  {
-    mAudioChild = aChild;
-  }
-
-  NS_IMETHOD Run()
-  {
-    if (mAudioChild->IsIPCOpen())
-      PAudioChild::Send__delete__(mAudioChild);
-    return NS_OK;
-  }
-  
-  nsRefPtr<AudioChild> mAudioChild;
-};
 #endif // MOZ_IPC
 
 
 void nsAudioStream::InitLibrary()
 {
 #ifdef PR_LOGGING
   gAudioStreamLog = PR_NewLogModule("nsAudioStream");
 #endif
@@ -608,86 +597,73 @@ nsAudioStreamRemote::Init(PRInt32 aNumCh
       break;
     }
     case FORMAT_FLOAT32: {
       mBytesPerSample = sizeof(float);
     }
   }
 
   nsCOMPtr<nsIRunnable> event = new AudioInitEvent(this);
-  NS_DispatchToMainThread(event, NS_DISPATCH_SYNC);
+  NS_DispatchToMainThread(event);
   return NS_OK;
 }
 
 void
 nsAudioStreamRemote::Shutdown()
 {
-  if (!mAudioChild)
-    return;
-  nsCOMPtr<nsIRunnable> event = new AudioShutdownEvent(mAudioChild);
-  NS_DispatchToMainThread(event);
+  PAudioChild::Send__delete__(mAudioChild);
   mAudioChild = nsnull;
 }
 
 nsresult
 nsAudioStreamRemote::Write(const void* aBuf,
                            PRUint32 aCount,
                            PRBool aBlocking)
 {
-  if (!mAudioChild)
-    return NS_ERROR_FAILURE;
-  nsCOMPtr<nsIRunnable> event = new AudioWriteEvent(mAudioChild,
+  nsCOMPtr<nsIRunnable> event = new AudioWriteEvent(this,
                                                     aBuf,
                                                     aCount,
                                                     mBytesPerSample);
   NS_DispatchToMainThread(event);
   return NS_OK;
 }
 
 PRUint32
 nsAudioStreamRemote::Available()
 {
   return FAKE_BUFFER_SIZE;
 }
 
 void
 nsAudioStreamRemote::SetVolume(float aVolume)
 {
-  if (!mAudioChild)
-    return;
-  nsCOMPtr<nsIRunnable> event = new AudioSetVolumeEvent(mAudioChild, aVolume);
+  nsCOMPtr<nsIRunnable> event = new AudioSetVolumeEvent(this, aVolume);
   NS_DispatchToMainThread(event);
 }
 
 void
 nsAudioStreamRemote::Drain()
 {
-  if (!mAudioChild)
-    return;
-  nsCOMPtr<nsIRunnable> event = new AudioDrainEvent(mAudioChild);
+  nsCOMPtr<nsIRunnable> event = new AudioDrainEvent(this);
   NS_DispatchToMainThread(event, NS_DISPATCH_SYNC);
 }
  
 void
 nsAudioStreamRemote::Pause()
 {
   mPaused = PR_TRUE;
-  if (!mAudioChild)
-    return;
-  nsCOMPtr<nsIRunnable> event = new AudioPauseEvent(mAudioChild, PR_TRUE);
+  nsCOMPtr<nsIRunnable> event = new AudioPauseEvent(this, PR_TRUE);
   NS_DispatchToMainThread(event);
 }
 
 void
 nsAudioStreamRemote::Resume()
 {
   mPaused = PR_FALSE;
-  if (!mAudioChild)
-    return;
-  nsCOMPtr<nsIRunnable> event = new AudioPauseEvent(mAudioChild, PR_FALSE);
+  nsCOMPtr<nsIRunnable> event = new AudioPauseEvent(this, PR_FALSE);
   NS_DispatchToMainThread(event);
 }
 
 PRInt64 nsAudioStreamRemote::GetPosition()
 {
   PRInt64 sampleOffset = GetSampleOffset();
   if (sampleOffset >= 0) {
     return ((MILLISECONDS_PER_SECOND * sampleOffset) / mRate / mChannels);
--- a/dom/ipc/AudioChild.cpp
+++ b/dom/ipc/AudioChild.cpp
@@ -37,38 +37,28 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/dom/AudioChild.h"
 
 namespace mozilla {
 namespace dom {
 
-NS_IMPL_THREADSAFE_ADDREF(AudioChild);
-NS_IMPL_THREADSAFE_RELEASE(AudioChild);
-
 AudioChild::AudioChild()
   : mLastSampleOffset(-1),
-    mLastSampleOffsetTime(0),
-    mIPCOpen(PR_TRUE)
+    mLastSampleOffsetTime(0)
 {
   MOZ_COUNT_CTOR(AudioChild);
 }
 
 AudioChild::~AudioChild()
 {
   MOZ_COUNT_DTOR(AudioChild);
 }
 
-void
-AudioChild::ActorDestroy(ActorDestroyReason aWhy)
-{
-  mIPCOpen = PR_FALSE;
-}
-
 bool
 AudioChild::RecvSampleOffsetUpdate(const PRInt64& offset,
                                    const PRInt64& time)
 {
   mLastSampleOffset = offset;
   mLastSampleOffsetTime = time;
   return true;
 }
--- a/dom/ipc/AudioChild.h
+++ b/dom/ipc/AudioChild.h
@@ -43,31 +43,22 @@
 #include "mozilla/dom/PAudioChild.h"
 
 namespace mozilla {
 namespace dom {
 
 class AudioChild : public PAudioChild
 {
  public:
-    nsrefcnt AddRef();
-    nsrefcnt Release();
-
     AudioChild();
     virtual ~AudioChild();
     virtual bool RecvSampleOffsetUpdate(const PRInt64&, const PRInt64&);
-    virtual void ActorDestroy(ActorDestroyReason);
     
     PRInt64 GetLastKnownSampleOffset();
     PRInt64 GetLastKnownSampleOffsetTime();
-
-    PRBool IsIPCOpen() { return mIPCOpen; };
  private:
-    nsAutoRefCnt mRefCnt;
-    NS_DECL_OWNINGTHREAD
     PRInt64 mLastSampleOffset, mLastSampleOffsetTime;
-    PRPackedBool mIPCOpen;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif
--- a/dom/ipc/AudioParent.cpp
+++ b/dom/ipc/AudioParent.cpp
@@ -61,45 +61,22 @@ class AudioWriteEvent : public nsRunnabl
   }
 
  private:
     nsRefPtr<nsAudioStream> mOwner;
     nsCString mData;
     PRUint32  mCount;
 };
 
-class AudioPauseEvent : public nsRunnable
-{
- public:
-  AudioPauseEvent(nsAudioStream* owner, PRBool aPause)
-  {
-    mOwner = owner;
-    mPause = aPause;
-  }
-
-  NS_IMETHOD Run()
-  {
-    if (mPause)
-        mOwner->Pause();
-    else
-        mOwner->Resume();
-    return NS_OK;
-  }
-
- private:
-    nsRefPtr<nsAudioStream> mOwner;
-    PRBool mPause;
-};
-
 NS_IMPL_THREADSAFE_ISUPPORTS1(AudioParent, nsITimerCallback)
 
 nsresult
 AudioParent::Notify(nsITimer* timer)
 {
-  if (!mIPCOpen || !mStream) {
+  if (!mStream) {
     timer->Cancel();
     return NS_ERROR_FAILURE;
   }
 
   PRInt64 offset = mStream->GetSampleOffset();
   SendSampleOffsetUpdate(offset, PR_IntervalNow());
   return NS_OK;
 }
@@ -128,28 +105,26 @@ AudioParent::RecvDrain()
   if (mStream)
     mStream->Drain();
   return true;
 }
 
 bool
 AudioParent::RecvPause()
 {
-  nsCOMPtr<nsIRunnable> event = new AudioPauseEvent(mStream, PR_TRUE);
-  nsCOMPtr<nsIThread> thread = nsAudioStream::GetGlobalThread();
-  thread->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
+  if (mStream)
+    mStream->Pause();
   return true;
 }
 
 bool
 AudioParent::RecvResume()
 {
-  nsCOMPtr<nsIRunnable> event = new AudioPauseEvent(mStream, PR_FALSE);
-  nsCOMPtr<nsIThread> thread = nsAudioStream::GetGlobalThread();
-  thread->Dispatch(event, nsIEventTarget::DISPATCH_NORMAL);
+  if (mStream)
+    mStream->Resume();
   return true;
 }
 
 bool
 AudioParent::Recv__delete__()
 {
   if (mStream) {
     mStream->Shutdown();
@@ -159,17 +134,16 @@ AudioParent::Recv__delete__()
   if (mTimer) {
     mTimer->Cancel();
     mTimer = nsnull;
   }
   return true;
 }
 
 AudioParent::AudioParent(PRInt32 aNumChannels, PRInt32 aRate, PRInt32 aFormat)
-  : mIPCOpen(PR_TRUE)
 {
   mStream = nsAudioStream::AllocateStream();
   if (mStream)
     mStream->Init(aNumChannels,
                   aRate,
                   (nsAudioStream::SampleFormat) aFormat);
   if (!mStream)
     return; 
@@ -177,16 +151,10 @@ AudioParent::AudioParent(PRInt32 aNumCha
   mTimer = do_CreateInstance("@mozilla.org/timer;1");
   mTimer->InitWithCallback(this, 1000, nsITimer::TYPE_REPEATING_SLACK);
 }
 
 AudioParent::~AudioParent()
 {
 }
 
-void
-AudioParent::ActorDestroy(ActorDestroyReason aWhy)
-{
-  mIPCOpen = PR_FALSE;
-}
-
 } // namespace dom
 } // namespace mozilla
--- a/dom/ipc/AudioParent.h
+++ b/dom/ipc/AudioParent.h
@@ -70,20 +70,17 @@ class AudioParent : public PAudioParent,
     virtual bool
     RecvResume();
 
     virtual bool
     Recv__delete__();
 
     AudioParent(PRInt32 aNumChannels, PRInt32 aRate, PRInt32 aFormat);
     virtual ~AudioParent();
-    virtual void ActorDestroy(ActorDestroyReason);
 
     nsRefPtr<nsAudioStream> mStream;
     nsCOMPtr<nsITimer> mTimer;
 
-private:
-    PRPackedBool mIPCOpen;
 };
 } // namespace dom
 } // namespace mozilla
 
 #endif
--- a/dom/ipc/ContentChild.cpp
+++ b/dom/ipc/ContentChild.cpp
@@ -328,26 +328,24 @@ ContentChild::RecvPTestShellConstructor(
     return true;
 }
 
 PAudioChild*
 ContentChild::AllocPAudio(const PRInt32& numChannels,
                           const PRInt32& rate,
                           const PRInt32& format)
 {
-    AudioChild *child = new AudioChild();
-    NS_ADDREF(child);
+    PAudioChild *child = new AudioChild();
     return child;
 }
 
 bool
 ContentChild::DeallocPAudio(PAudioChild* doomed)
 {
-    AudioChild *child = static_cast<AudioChild*>(doomed);
-    NS_RELEASE(child);
+    delete doomed;
     return true;
 }
 
 PNeckoChild* 
 ContentChild::AllocPNecko()
 {
     return new NeckoChild();
 }
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -422,17 +422,17 @@ ContentParent::DeallocPTestShell(PTestSh
 }
  
 PAudioParent*
 ContentParent::AllocPAudio(const PRInt32& numChannels,
                            const PRInt32& rate,
                            const PRInt32& format)
 {
     AudioParent *parent = new AudioParent(numChannels, rate, format);
-    NS_ADDREF(parent);
+    parent->AddRef();
     return parent;
 }
 
 bool
 ContentParent::DeallocPAudio(PAudioParent* doomed)
 {
     AudioParent *parent = static_cast<AudioParent*>(doomed);
     NS_RELEASE(parent);