Commit e4c27b50 authored by Hongchan Choi's avatar Hongchan Choi Committed by Commit Bot

Remove tear_down_mutex_ from BaseAudioContext

In favor of the self-referencing patch, this mutex can be safely
removed.

Test: Ran the patch on a repro case from crbug.com/1029462 and saw no crash after 20 min.
Bug: 1058555
Change-Id: I0335fa6c878f4ca7e52a03ed7eb6fc0891dfa3ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088491Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Hongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748376}
parent cf24a7aa
...@@ -150,8 +150,6 @@ void BaseAudioContext::Clear() { ...@@ -150,8 +150,6 @@ void BaseAudioContext::Clear() {
void BaseAudioContext::Uninitialize() { void BaseAudioContext::Uninitialize() {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
MutexLocker locker(GetTearDownMutex());
if (!IsDestinationInitialized()) if (!IsDestinationInitialized())
return; return;
......
...@@ -328,8 +328,6 @@ class MODULES_EXPORT BaseAudioContext ...@@ -328,8 +328,6 @@ class MODULES_EXPORT BaseAudioContext
void ReportDidCreate() final; void ReportDidCreate() final;
void ReportWillBeDestroyed() final; void ReportWillBeDestroyed() final;
Mutex& GetTearDownMutex() const { return tear_down_mutex_; }
protected: protected:
enum ContextType { kRealtimeContext, kOfflineContext }; enum ContextType { kRealtimeContext, kOfflineContext };
...@@ -431,12 +429,6 @@ class MODULES_EXPORT BaseAudioContext ...@@ -431,12 +429,6 @@ class MODULES_EXPORT BaseAudioContext
// This cannot be nullptr once it is assigned from AudioWorkletThread until // This cannot be nullptr once it is assigned from AudioWorkletThread until
// the BaseAudioContext goes away. // the BaseAudioContext goes away.
WorkerThread* audio_worklet_thread_ = nullptr; WorkerThread* audio_worklet_thread_ = nullptr;
// Due to the multi-threading architecture of WebAudio, it is possible that
// object allocated by the main thread still can be accessed by the audio
// rendering thread while this context is torn down (GCed) by
// |Uninitialize()|.
mutable Mutex tear_down_mutex_;
}; };
} // namespace blink } // namespace blink
......
...@@ -293,33 +293,25 @@ bool OfflineAudioDestinationHandler::RenderIfNotSuspended( ...@@ -293,33 +293,25 @@ bool OfflineAudioDestinationHandler::RenderIfNotSuspended(
return true; return true;
} }
{ DCHECK_GE(NumberOfInputs(), 1u);
MutexTryLocker try_locker(Context()->GetTearDownMutex());
if (try_locker.Locked()) {
DCHECK_GE(NumberOfInputs(), 1u);
// This will cause the node(s) connected to us to process, which in turn
// will pull on their input(s), all the way backwards through the
// rendering graph.
scoped_refptr<AudioBus> rendered_bus =
Input(0).Pull(destination_bus, number_of_frames);
if (!rendered_bus) {
destination_bus->Zero();
} else if (rendered_bus != destination_bus) {
// in-place processing was not possible - so copy
destination_bus->CopyFrom(*rendered_bus);
}
} else {
destination_bus->Zero();
}
// Process nodes which need a little extra help because they are not // This will cause the node(s) connected to us to process, which in turn will
// connected to anything, but still need to process. // pull on their input(s), all the way backwards through the rendering graph.
Context()->GetDeferredTaskHandler().ProcessAutomaticPullNodes( scoped_refptr<AudioBus> rendered_bus =
number_of_frames); Input(0).Pull(destination_bus, number_of_frames);
if (!rendered_bus) {
destination_bus->Zero();
} else if (rendered_bus != destination_bus) {
// in-place processing was not possible - so copy
destination_bus->CopyFrom(*rendered_bus);
} }
// Process nodes which need a little extra help because they are not connected
// to anything, but still need to process.
Context()->GetDeferredTaskHandler().ProcessAutomaticPullNodes(
number_of_frames);
// Let the context take care of any business at the end of each render // Let the context take care of any business at the end of each render
// quantum. // quantum.
Context()->HandlePostRenderTasks(); Context()->HandlePostRenderTasks();
......
...@@ -198,35 +198,30 @@ void RealtimeAudioDestinationHandler::Render( ...@@ -198,35 +198,30 @@ void RealtimeAudioDestinationHandler::Render(
// Only pull on the audio graph if we have not stopped the destination. It // Only pull on the audio graph if we have not stopped the destination. It
// takes time for the destination to stop, but we want to stop pulling before // takes time for the destination to stop, but we want to stop pulling before
// the destination has actually stopped. // the destination has actually stopped.
{ if (IsPullingAudioGraphAllowed()) {
MutexTryLocker try_locker(context->GetTearDownMutex()); // Renders the graph by pulling all the inputs to this node. This will in
if (try_locker.Locked() && IsPullingAudioGraphAllowed()) { // turn pull on their inputs, all the way backwards through the graph.
// Renders the graph by pulling all the inputs to this node. This will scoped_refptr<AudioBus> rendered_bus =
// in turn pull on their inputs, all the way backwards through the graph. Input(0).Pull(destination_bus, number_of_frames);
scoped_refptr<AudioBus> rendered_bus =
Input(0).Pull(destination_bus, number_of_frames); DCHECK(rendered_bus);
if (!rendered_bus) {
DCHECK(rendered_bus); // AudioNodeInput might be in the middle of destruction. Then the internal
if (!rendered_bus) { // summing bus will return as nullptr. Then zero out the output.
// AudioNodeInput might be in the middle of destruction. Then the
// internal summing bus will return as nullptr. Then zero out the
// output.
destination_bus->Zero();
} else if (rendered_bus != destination_bus) {
// In-place processing was not possible. Copy the rendererd result to
// the given |destination_bus| buffer.
destination_bus->CopyFrom(*rendered_bus);
}
} else {
destination_bus->Zero(); destination_bus->Zero();
} else if (rendered_bus != destination_bus) {
// In-place processing was not possible. Copy the rendered result to the
// given |destination_bus| buffer.
destination_bus->CopyFrom(*rendered_bus);
} }
} else {
// Processes "automatic" nodes that are not connected to anything. This can destination_bus->Zero();
// be done after copying because it does not affect the rendered result.
context->GetDeferredTaskHandler().ProcessAutomaticPullNodes(
number_of_frames);
} }
// Processes "automatic" nodes that are not connected to anything. This can
// be done after copying because it does not affect the rendered result.
context->GetDeferredTaskHandler().ProcessAutomaticPullNodes(number_of_frames);
context->HandlePostRenderTasks(); context->HandlePostRenderTasks();
context->HandleAudibility(destination_bus); context->HandleAudibility(destination_bus);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment