Backed out changeset d9bcbec33260 for bustage.
authorJason Duell <jduell.mcbugs@gmail.com>
Mon, 03 Dec 2012 22:13:21 -0800
changeset 114894 f88a7f4b3792
parent 114892 773c8d166ae8 (current diff)
parent 114893 643dbbbe0f21 (diff)
child 114895 857e8fdd2d5d
push id23947
push useremorley@mozilla.com
push dateTue, 04 Dec 2012 14:54:11 +0000
treeherdermozilla-central@0035f77045bc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
milestone20.0a1
backs outd9bcbec33260
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset d9bcbec33260 for bustage.
--- a/dom/media/MediaManager.h
+++ b/dom/media/MediaManager.h
@@ -63,16 +63,17 @@ class GetUserMediaNotificationEvent: pub
 
   protected:
     GetUserMediaStatus mStatus;
 };
 
 typedef enum {
   MEDIA_START,
   MEDIA_STOP,
+  MEDIA_RELEASE
 } MediaOperation;
 
 // Generic class for running long media operations off the main thread, and
 // then (because nsDOMMediaStreams aren't threadsafe), re-sends itseld to
 // MainThread to release mStream.  This is part of the reason we use an
 // operation type - we can change it to repost the runnable to MainThread
 // to do operations with the nsDOMMediaStreams, while we can't assign or
 // copy a nsRefPtr to a nsDOMMediaStream
@@ -95,31 +96,22 @@ public:
     MediaEngineSource* aVideoSource)
     : mType(aType)
     , mAudioSource(aAudioSource)
     , mVideoSource(aVideoSource)
     , mStream(nullptr)
     , mSourceStream(aStream)
     {}
 
-  ~MediaOperationRunnable()
-  {
-    // nsDOMMediaStreams are cycle-collected and thus main-thread-only for
-    // refcounting and releasing
-    if (mStream) {
-      nsCOMPtr<nsIThread> mainThread = do_GetMainThread();
-      NS_ProxyRelease(mainThread,mStream,false);
-    }
-  }
-
   NS_IMETHOD
   Run()
   {
-    // No locking between these is required as all the callbacks for the
-    // same MediaStream will occur on the same thread.
+    // No locking between these is required as all the callbacks (other
+    // than MEDIA_RELEASE) for the same MediaStream will occur on the same
+    // thread.
     if (mStream) {
       mSourceStream = mStream->GetStream()->AsSourceStream();
     }
     switch (mType) {
       case MEDIA_START:
         {
           NS_ASSERTION(!NS_IsMainThread(), "Never call on main thread");
           nsresult rv;
@@ -138,17 +130,16 @@ public:
               MM_LOG(("Starting video failed, rv=%d",rv));
             }
           }
 
           MM_LOG(("started all sources"));
           nsRefPtr<GetUserMediaNotificationEvent> event =
             new GetUserMediaNotificationEvent(GetUserMediaNotificationEvent::STARTING);
 
-
           NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
         }
         break;
 
       case MEDIA_STOP:
         {
           NS_ASSERTION(!NS_IsMainThread(), "Never call on main thread");
           if (mAudioSource) {
@@ -163,25 +154,33 @@ public:
           mSourceStream->Finish();
 
           nsRefPtr<GetUserMediaNotificationEvent> event =
             new GetUserMediaNotificationEvent(GetUserMediaNotificationEvent::STOPPING);
 
           NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
         }
         break;
+      case MEDIA_RELEASE:
+        // We go to MainThread to die
+        break;
+    }
+    if (mType != MEDIA_RELEASE) {
+      // nsDOMMediaStreams aren't thread-safe... sigh.
+      mType = MEDIA_RELEASE;
+      NS_DispatchToMainThread(this);
     }
     return NS_OK;
   }
 
 private:
   MediaOperation mType;
-  nsRefPtr<MediaEngineSource> mAudioSource; // threadsafe
-  nsRefPtr<MediaEngineSource> mVideoSource; // threadsafe
-  nsRefPtr<nsDOMMediaStream> mStream;       // not threadsafe
+  nsRefPtr<MediaEngineSource> mAudioSource;
+  nsRefPtr<MediaEngineSource> mVideoSource;
+  nsRefPtr<nsDOMMediaStream> mStream;
   SourceMediaStream *mSourceStream;
 };
 
 /**
  * This class is an implementation of MediaStreamListener. This is used
  * to Start() and Stop() the underlying MediaEngineSource when MediaStreams
  * are assigned and deassigned in content.
  */