Bug 1726024 - Handle failure to get shutdown barrier in MediaTrackGraph. r=pehrsons

Differential Revision: https://phabricator.services.mozilla.com/D123004
This commit is contained in:
Bryce Seager van Dyk 2021-08-26 18:37:03 +00:00
Родитель dfb5047d9c
Коммит 7ced8e76ab
2 изменённых файлов: 30 добавлений и 13 удалений

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

@ -1769,7 +1769,7 @@ MediaTrackGraphImpl::Notify(nsITimer* aTimer) {
return NS_OK; return NS_OK;
} }
void MediaTrackGraphImpl::AddShutdownBlocker() { bool MediaTrackGraphImpl::AddShutdownBlocker() {
MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(!mShutdownBlocker); MOZ_ASSERT(!mShutdownBlocker);
@ -1787,21 +1787,31 @@ void MediaTrackGraphImpl::AddShutdownBlocker() {
} }
}; };
nsCOMPtr<nsIAsyncShutdownClient> barrier = media::GetShutdownBarrier();
if (!barrier) {
// We're already shutting down, we won't be able to add a blocker, bail.
LOG(LogLevel::Error,
("%p: Couldn't get shutdown barrier, won't add shutdown blocker",
this));
return false;
}
// Blocker names must be distinct. // Blocker names must be distinct.
nsString blockerName; nsString blockerName;
blockerName.AppendPrintf("MediaTrackGraph %p shutdown", this); blockerName.AppendPrintf("MediaTrackGraph %p shutdown", this);
mShutdownBlocker = MakeAndAddRef<Blocker>(this, blockerName); mShutdownBlocker = MakeAndAddRef<Blocker>(this, blockerName);
nsresult rv = media::GetShutdownBarrier()->AddBlocker( nsresult rv = barrier->AddBlocker(mShutdownBlocker,
mShutdownBlocker, NS_LITERAL_STRING_FROM_CSTRING(__FILE__), __LINE__, NS_LITERAL_STRING_FROM_CSTRING(__FILE__),
u"MediaTrackGraph shutdown"_ns); __LINE__, u"MediaTrackGraph shutdown"_ns);
MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv)); MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
return true;
} }
void MediaTrackGraphImpl::RemoveShutdownBlocker() { void MediaTrackGraphImpl::RemoveShutdownBlocker() {
if (!mShutdownBlocker) { if (!mShutdownBlocker) {
return; return;
} }
media::GetShutdownBarrier()->RemoveBlocker(mShutdownBlocker); media::MustGetShutdownBarrier()->RemoveBlocker(mShutdownBlocker);
mShutdownBlocker = nullptr; mShutdownBlocker = nullptr;
} }
@ -3368,9 +3378,19 @@ MediaTrackGraphImpl::MediaTrackGraphImpl(
mMainThreadGraphTime(0, "MediaTrackGraphImpl::mMainThreadGraphTime"), mMainThreadGraphTime(0, "MediaTrackGraphImpl::mMainThreadGraphTime"),
mAudioOutputLatency(0.0), mAudioOutputLatency(0.0),
mMaxOutputChannelCount(std::min(8u, CubebUtils::MaxNumberOfChannels())) { mMaxOutputChannelCount(std::min(8u, CubebUtils::MaxNumberOfChannels())) {
if (aRunTypeRequested == SINGLE_THREAD && !mGraphRunner) { bool failedToGetShutdownBlocker = false;
// Failed to create thread. Jump to the last phase of the lifecycle. if (!IsNonRealtime()) {
failedToGetShutdownBlocker = !AddShutdownBlocker();
}
if ((aRunTypeRequested == SINGLE_THREAD && !mGraphRunner) ||
failedToGetShutdownBlocker) {
// At least one of the following happened
// - Failed to create thread.
// - Failed to install a shutdown blocker when one is needed.
// Because we have a fail state, jump to last phase of the lifecycle.
mLifecycleState = LIFECYCLE_WAITING_FOR_TRACK_DESTRUCTION; mLifecycleState = LIFECYCLE_WAITING_FOR_TRACK_DESTRUCTION;
RemoveShutdownBlocker(); // No-op if blocker wasn't added.
#ifdef DEBUG #ifdef DEBUG
mCanRunMessagesSynchronously = true; mCanRunMessagesSynchronously = true;
#endif #endif
@ -3394,10 +3414,6 @@ MediaTrackGraphImpl::MediaTrackGraphImpl(
mLastMainThreadUpdate = TimeStamp::Now(); mLastMainThreadUpdate = TimeStamp::Now();
RegisterWeakAsyncMemoryReporter(this); RegisterWeakAsyncMemoryReporter(this);
if (!IsNonRealtime()) {
AddShutdownBlocker();
}
} }
#ifdef DEBUG #ifdef DEBUG

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

@ -256,9 +256,10 @@ class MediaTrackGraphImpl : public MediaTrackGraph,
/** /**
* Sets mShutdownBlocker and makes it block shutdown. * Sets mShutdownBlocker and makes it block shutdown.
* Main thread only. Not idempotent. * Main thread only. Not idempotent. Returns true if a blocker was added,
* false if this failed.
*/ */
void AddShutdownBlocker(); bool AddShutdownBlocker();
/** /**
* Removes mShutdownBlocker and unblocks shutdown. * Removes mShutdownBlocker and unblocks shutdown.