diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index 42980655bdd..286c1cec436 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -68,6 +68,7 @@ class GetUserMediaNotificationEvent: public nsRunnable typedef enum { MEDIA_START, MEDIA_STOP, + MEDIA_RELEASE } MediaOperation; // Generic class for running long media operations off the main thread, and @@ -100,21 +101,12 @@ public: , mSourceStream(aStream) {} - ~MediaOperationRunnable() - { - // nsDOMMediaStreams are cycle-collected and thus main-thread-only for - // refcounting and releasing - if (mStream) { - nsCOMPtr 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(); } @@ -143,7 +135,6 @@ public: nsRefPtr event = new GetUserMediaNotificationEvent(GetUserMediaNotificationEvent::STARTING); - NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL); } break; @@ -168,15 +159,23 @@ public: 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 mAudioSource; // threadsafe - nsRefPtr mVideoSource; // threadsafe - nsRefPtr mStream; // not threadsafe + nsRefPtr mAudioSource; + nsRefPtr mVideoSource; + nsRefPtr mStream; SourceMediaStream *mSourceStream; };