Bug 1542931 add a mechanism to notify engine on graph thread of forced shutdown r=padenot

This will be used to release the AudioWorkletProcessor on the correct thread.

Depends on D34480

Differential Revision: https://phabricator.services.mozilla.com/D34481

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Karl Tomlinson 2019-06-14 15:04:48 +00:00
parent 64d6bd309f
commit ff940f743d
6 changed files with 22 additions and 1 deletions

View File

@ -1347,6 +1347,12 @@ void MediaStreamGraphImpl::Process() {
bool MediaStreamGraphImpl::UpdateMainThreadState() {
MOZ_ASSERT(OnGraphThread());
if (mForceShutDown) {
for (MediaStream* stream : AllStreams()) {
stream->NotifyForcedShutdown();
}
}
MonitorAutoLock lock(mMonitor);
bool finalUpdate =
mForceShutDown || (IsEmpty() && mBackMessageQueue.IsEmpty());

View File

@ -511,6 +511,10 @@ class MediaStream : public mozilla::LinkedListElement<MediaStream> {
void DecrementSuspendCount();
protected:
// Called on graph thread before handing control to the main thread to
// release streams.
virtual void NotifyForcedShutdown() {}
// |AdvanceTimeVaryingValuesToCurrentTime| will be override in
// SourceMediaStream.
virtual void AdvanceTimeVaryingValuesToCurrentTime(GraphTime aCurrentTime,

View File

@ -333,6 +333,10 @@ class AudioNodeEngine {
// returning false, then the stream can be suspended.
virtual bool IsActive() const { return false; }
// Called on forced shutdown of the MediaStreamGraph before handing ownership
// from graph thread to main thread.
virtual void NotifyForcedShutdown() {}
bool HasNode() const {
MOZ_ASSERT(NS_IsMainThread());
return !!mNode;

View File

@ -52,6 +52,10 @@ AudioNodeStream::~AudioNodeStream() {
MOZ_COUNT_DTOR(AudioNodeStream);
}
void AudioNodeStream::NotifyForcedShutdown() {
mEngine->NotifyForcedShutdown();
}
void AudioNodeStream::DestroyImpl() {
// These are graph thread objects, so clean up on graph thread.
mInputChunks.Clear();

View File

@ -175,6 +175,7 @@ class AudioNodeStream : public ProcessedMediaStream {
class AdvanceAndResumeMessage;
class CheckForInactiveMessage;
void NotifyForcedShutdown() override;
void DestroyImpl() override;
/*
@ -201,7 +202,7 @@ class AudioNodeStream : public ProcessedMediaStream {
void DecrementActiveInputCount();
// The engine that will generate output for this node.
nsAutoPtr<AudioNodeEngine> mEngine;
const nsAutoPtr<AudioNodeEngine> mEngine;
// The mixed input blocks are kept from iteration to iteration to avoid
// reallocating channel data arrays and any buffers for mixing.
OutputChunks mInputChunks;

View File

@ -23,6 +23,8 @@ class WorkletNodeEngine final : public AudioNodeEngine {
void ConstructProcessor(AudioWorkletImpl* aWorkletImpl,
const nsAString& aName,
StructuredCloneHolder* aOptionsSerialization);
void NotifyForcedShutdown() override {}
};
void WorkletNodeEngine::ConstructProcessor(