Bug 848954 - Part 18 - Start the thread after having processed the messages to make sure there are messages in the queue when processing starts. r=roc

This commit is contained in:
Paul Adenot 2014-08-26 17:02:09 +02:00
Родитель c5abb79941
Коммит 86c51354d2
2 изменённых файлов: 21 добавлений и 24 удалений

Просмотреть файл

@ -172,10 +172,6 @@ public:
char aLocal;
STREAM_LOG(PR_LOG_DEBUG, ("Starting system thread"));
profiler_register_thread("MediaStreamGraph", &aLocal);
{
MonitorAutoLock mon(mDriver->mGraphImpl->GetMonitor());
mDriver->mGraphImpl->SwapMessageQueues();
}
if (mDriver->mPreviousDriver) {
MOZ_ASSERT(!mDriver->AsAudioCallbackDriver());
// Stop and release the previous driver off-main-thread.
@ -183,6 +179,10 @@ public:
new AsyncCubebTask(mDriver->mPreviousDriver->AsAudioCallbackDriver(), AsyncCubebTask::SHUTDOWN);
mDriver->mPreviousDriver = nullptr;
releaseEvent->Dispatch();
} else {
MonitorAutoLock mon(mDriver->mGraphImpl->GetMonitor());
MOZ_ASSERT(mDriver->mGraphImpl->MessagesQueued(), "Don't start a graph without messages queued.");
mDriver->mGraphImpl->SwapMessageQueues();
}
mDriver->RunThread();
return NS_OK;

Просмотреть файл

@ -1564,26 +1564,6 @@ MediaStreamGraphImpl::RunInStableState()
}
mStreamUpdates.Clear();
// Don't start the thread for a non-realtime graph until it has been
// explicitly started by StartNonRealtimeProcessing.
if (mLifecycleState == LIFECYCLE_THREAD_NOT_STARTED &&
(mRealtime || mNonRealtimeProcessing)) {
mLifecycleState = LIFECYCLE_RUNNING;
// Start the thread now. We couldn't start it earlier because
// the graph might exit immediately on finding it has no streams. The
// first message for a new graph must create a stream.
{
// We should exit the monitor for now, because starting a stream might
// take locks, and we don't want to deadlock. We probably want this to be
// async on another thread.
MonitorAutoUnlock unlock(mMonitor);
STREAM_LOG(PR_LOG_DEBUG, ("Starting a graph with a %s\n",
CurrentDriver()->AsAudioCallbackDriver() ? "AudioDriver" :
"SystemDriver"));
CurrentDriver()->Start();
}
}
if (mCurrentTaskMessageQueue.IsEmpty()) {
if (mLifecycleState == LIFECYCLE_WAITING_FOR_MAIN_THREAD_CLEANUP && IsEmpty()) {
// Complete shutdown. First, ensure that this graph is no longer used.
@ -1626,6 +1606,23 @@ MediaStreamGraphImpl::RunInStableState()
}
}
// Don't start the thread for a non-realtime graph until it has been
// explicitly started by StartNonRealtimeProcessing.
if (mLifecycleState == LIFECYCLE_THREAD_NOT_STARTED &&
(mRealtime || mNonRealtimeProcessing)) {
mLifecycleState = LIFECYCLE_RUNNING;
// Start the thread now. We couldn't start it earlier because
// the graph might exit immediately on finding it has no streams. The
// first message for a new graph must create a stream.
{
// We should exit the monitor for now, because starting a stream might
// take locks, and we don't want to deadlock.
MonitorAutoUnlock unlock(mMonitor);
STREAM_LOG(PR_LOG_DEBUG, ("Starting a graph ! %s\n", CurrentDriver()->AsAudioCallbackDriver() ? "AudioDriver" : "SystemDriver"));
CurrentDriver()->Start();
}
}
if ((mForceShutDown || !mRealtime) &&
mLifecycleState == LIFECYCLE_WAITING_FOR_MAIN_THREAD_CLEANUP) {
// Defer calls to RunDuringShutdown() to happen while mMonitor is not held.