diff --git a/dom/media/webrtc/MediaEngineTabVideoSource.cpp b/dom/media/webrtc/MediaEngineTabVideoSource.cpp index ec21fa070e47..7508ac839a62 100644 --- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp +++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp @@ -119,6 +119,17 @@ MediaEngineTabVideoSource::InitRunnable::Run() return NS_OK; } +nsresult +MediaEngineTabVideoSource::DestroyRunnable::Run() +{ + MOZ_ASSERT(NS_IsMainThread()); + + mVideoSource->mWindow = nullptr; + mVideoSource->mTabSource = nullptr; + + return NS_OK; +} + void MediaEngineTabVideoSource::GetName(nsAString_internal& aName) const { @@ -193,6 +204,8 @@ nsresult MediaEngineTabVideoSource::Deallocate(AllocationHandle* aHandle) { MOZ_ASSERT(!aHandle); + NS_DispatchToMainThread(do_AddRef(new DestroyRunnable(this))); + { MonitorAutoLock mon(mMonitor); mState = kReleased; diff --git a/dom/media/webrtc/MediaEngineTabVideoSource.h b/dom/media/webrtc/MediaEngineTabVideoSource.h index d4d30a811314..d11bd7765af8 100644 --- a/dom/media/webrtc/MediaEngineTabVideoSource.h +++ b/dom/media/webrtc/MediaEngineTabVideoSource.h @@ -81,6 +81,13 @@ class MediaEngineTabVideoSource : public MediaEngineVideoSource, nsIDOMEventList RefPtr mVideoSource; }; + class DestroyRunnable : public Runnable { + public: + explicit DestroyRunnable(MediaEngineTabVideoSource* videoSource) : mVideoSource(videoSource) {} + NS_IMETHOD Run(); + RefPtr mVideoSource; + }; + protected: ~MediaEngineTabVideoSource() {}