Backed out changeset d9bcbec33260 for bustage.
authorJason Duell <jduell.mcbugs@gmail.com>
Mon, 03 Dec 2012 22:13:21 -0800
changeset 120465 f88a7f4b3792c8f1ab5bfd6badfa970ceaff0bce
parent 120463 773c8d166ae861f708b7e3aab3c2f1ac06694e37 (current diff)
parent 120464 643dbbbe0f21338461f5fca380ce942936357662 (diff)
child 120466 857e8fdd2d5d1136f5030af1a5a1c639f6a39346
push idunknown
push userunknown
push dateunknown
milestone20.0a1
backs outd9bcbec33260fe36730a387daded40a4e11a93a7
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.
  */