Bug 1267600 - Ask the main thread to shut down the SystemClockDriver if needed. r?jesup
This also factors in the OfflineAudioDriver case that was correct, but similar,
in the ThreadedDriver dtor, and implements the suggestion that was in the
comment (use .forget()).
MozReview-Commit-ID: 7kdb60mFAnb
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -164,20 +164,45 @@ void GraphDriver::SetPreviousDriver(Grap
GraphImpl()->GetMonitor().AssertCurrentThreadOwns();
mPreviousDriver = aPreviousDriver;
}
ThreadedDriver::ThreadedDriver(MediaStreamGraphImpl* aGraphImpl)
: GraphDriver(aGraphImpl)
{ }
+class MediaStreamGraphShutdownThreadRunnable : public nsRunnable {
+public:
+ explicit MediaStreamGraphShutdownThreadRunnable(already_AddRefed<nsIThread> aThread)
+ : mThread(aThread)
+ {
+ }
+ NS_IMETHOD Run()
+ {
+ MOZ_ASSERT(NS_IsMainThread());
+ MOZ_ASSERT(mThread);
+
+ mThread->Shutdown();
+ mThread = nullptr;
+ return NS_OK;
+ }
+private:
+ nsCOMPtr<nsIThread> mThread;
+};
+
ThreadedDriver::~ThreadedDriver()
{
if (mThread) {
- mThread->Shutdown();
+ if (NS_IsMainThread()) {
+ mThread->Shutdown();
+ } else {
+ nsCOMPtr<nsIRunnable> event =
+ new MediaStreamGraphShutdownThreadRunnable(mThread.forget());
+ NS_DispatchToMainThread(event);
+ }
}
}
class MediaStreamGraphInitThreadRunnable : public nsRunnable {
public:
explicit MediaStreamGraphInitThreadRunnable(ThreadedDriver* aDriver)
: mDriver(aDriver)
{
}
@@ -416,44 +441,18 @@ void SystemClockDriver::WakeUp()
OfflineClockDriver::OfflineClockDriver(MediaStreamGraphImpl* aGraphImpl, GraphTime aSlice)
: ThreadedDriver(aGraphImpl),
mSlice(aSlice)
{
}
-class MediaStreamGraphShutdownThreadRunnable : public nsRunnable {
-public:
- explicit MediaStreamGraphShutdownThreadRunnable(nsIThread* aThread)
- : mThread(aThread)
- {
- }
- NS_IMETHOD Run()
- {
- MOZ_ASSERT(NS_IsMainThread());
- MOZ_ASSERT(mThread);
-
- mThread->Shutdown();
- mThread = nullptr;
- return NS_OK;
- }
-private:
- nsCOMPtr<nsIThread> mThread;
-};
-
OfflineClockDriver::~OfflineClockDriver()
{
- // transfer the ownership of mThread to the event
- // XXX should use .forget()/etc
- if (mThread) {
- nsCOMPtr<nsIRunnable> event = new MediaStreamGraphShutdownThreadRunnable(mThread);
- mThread = nullptr;
- NS_DispatchToMainThread(event);
- }
}
MediaTime
OfflineClockDriver::GetIntervalForIteration()
{
return mGraphImpl->MillisecondsToMediaTime(mSlice);
}