Commit 1034fe3b authored by Raymond Toy's avatar Raymond Toy Committed by Commit Bot

AudioNodeInput::Bus returns scoped_refptr<AudioBus>

Make sure all users of an input bus increment the ref count by using
scoped_refptr instead of a raw pointer to the bus so that lifetime
is managed correctly.  We only handle the input bus in this CL.

Bug: 1040246
Change-Id: Ib93299da51e6eafbf9a7d0e433e1beea8fe9c266
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1958616
Commit-Queue: Raymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarHongchan Choi <hongchan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738021}
parent b5275ba3
...@@ -58,12 +58,12 @@ void AnalyserHandler::Process(uint32_t frames_to_process) { ...@@ -58,12 +58,12 @@ void AnalyserHandler::Process(uint32_t frames_to_process) {
return; return;
} }
AudioBus* input_bus = Input(0).Bus(); scoped_refptr<AudioBus> input_bus = Input(0).Bus();
// Give the analyser the audio which is passing through this // Give the analyser the audio which is passing through this
// AudioNode. This must always be done so that the state of the // AudioNode. This must always be done so that the state of the
// Analyser reflects the current input. // Analyser reflects the current input.
analyser_.WriteInput(input_bus, frames_to_process); analyser_.WriteInput(input_bus.get(), frames_to_process);
if (!Input(0).IsConnected()) { if (!Input(0).IsConnected()) {
// No inputs, so clear the output, and propagate the silence hint. // No inputs, so clear the output, and propagate the silence hint.
......
...@@ -75,14 +75,14 @@ void AudioBasicProcessorHandler::Process(uint32_t frames_to_process) { ...@@ -75,14 +75,14 @@ void AudioBasicProcessorHandler::Process(uint32_t frames_to_process) {
Processor()->NumberOfChannels() != NumberOfChannels()) { Processor()->NumberOfChannels() != NumberOfChannels()) {
destination_bus->Zero(); destination_bus->Zero();
} else { } else {
AudioBus* source_bus = Input(0).Bus(); scoped_refptr<AudioBus> source_bus = Input(0).Bus();
// FIXME: if we take "tail time" into account, then we can avoid calling // FIXME: if we take "tail time" into account, then we can avoid calling
// processor()->process() once the tail dies down. // processor()->process() once the tail dies down.
if (!Input(0).IsConnected()) if (!Input(0).IsConnected())
source_bus->Zero(); source_bus->Zero();
Processor()->Process(source_bus, destination_bus, frames_to_process); Processor()->Process(source_bus.get(), destination_bus, frames_to_process);
} }
} }
......
...@@ -565,7 +565,7 @@ void AudioContext::ContextDestroyed(ExecutionContext*) { ...@@ -565,7 +565,7 @@ void AudioContext::ContextDestroyed(ExecutionContext*) {
bool AudioContext::HasPendingActivity() const { bool AudioContext::HasPendingActivity() const {
// There's activity if the context is is not closed. Suspended contexts count // There's activity if the context is is not closed. Suspended contexts count
// as having activity even though they are basically idle with nothing going // as having activity even though they are basically idle with nothing going
// on. However, the can be resumed at any time, so we don't want contexts // on. However, they can be resumed at any time, so we don't want contexts
// going away prematurely. // going away prematurely.
return (ContextState() != kClosed) && BaseAudioContext::HasPendingActivity(); return (ContextState() != kClosed) && BaseAudioContext::HasPendingActivity();
} }
......
...@@ -86,7 +86,7 @@ unsigned AudioNodeInput::NumberOfChannels() const { ...@@ -86,7 +86,7 @@ unsigned AudioNodeInput::NumberOfChannels() const {
return max_channels; return max_channels;
} }
AudioBus* AudioNodeInput::Bus() { scoped_refptr<AudioBus> AudioNodeInput::Bus() {
DCHECK(GetDeferredTaskHandler().IsAudioThread()); DCHECK(GetDeferredTaskHandler().IsAudioThread());
// Handle single connection specially to allow for in-place processing. // Handle single connection specially to allow for in-place processing.
...@@ -98,13 +98,13 @@ AudioBus* AudioNodeInput::Bus() { ...@@ -98,13 +98,13 @@ AudioBus* AudioNodeInput::Bus() {
return InternalSummingBus(); return InternalSummingBus();
} }
AudioBus* AudioNodeInput::InternalSummingBus() { scoped_refptr<AudioBus> AudioNodeInput::InternalSummingBus() {
DCHECK(GetDeferredTaskHandler().IsAudioThread()); DCHECK(GetDeferredTaskHandler().IsAudioThread());
return internal_summing_bus_.get(); return internal_summing_bus_;
} }
void AudioNodeInput::SumAllConnections(AudioBus* summing_bus, void AudioNodeInput::SumAllConnections(scoped_refptr<AudioBus> summing_bus,
uint32_t frames_to_process) { uint32_t frames_to_process) {
DCHECK(GetDeferredTaskHandler().IsAudioThread()); DCHECK(GetDeferredTaskHandler().IsAudioThread());
...@@ -132,8 +132,8 @@ void AudioNodeInput::SumAllConnections(AudioBus* summing_bus, ...@@ -132,8 +132,8 @@ void AudioNodeInput::SumAllConnections(AudioBus* summing_bus,
} }
} }
AudioBus* AudioNodeInput::Pull(AudioBus* in_place_bus, scoped_refptr<AudioBus> AudioNodeInput::Pull(AudioBus* in_place_bus,
uint32_t frames_to_process) { uint32_t frames_to_process) {
DCHECK(GetDeferredTaskHandler().IsAudioThread()); DCHECK(GetDeferredTaskHandler().IsAudioThread());
// Handle single connection case. // Handle single connection case.
...@@ -144,7 +144,7 @@ AudioBus* AudioNodeInput::Pull(AudioBus* in_place_bus, ...@@ -144,7 +144,7 @@ AudioBus* AudioNodeInput::Pull(AudioBus* in_place_bus,
return output->Pull(in_place_bus, frames_to_process); return output->Pull(in_place_bus, frames_to_process);
} }
AudioBus* internal_summing_bus = this->InternalSummingBus(); scoped_refptr<AudioBus> internal_summing_bus = this->InternalSummingBus();
if (!NumberOfRenderingConnections()) { if (!NumberOfRenderingConnections()) {
// At least, generate silence if we're not connected to anything. // At least, generate silence if we're not connected to anything.
......
...@@ -65,12 +65,13 @@ class MODULES_EXPORT AudioNodeInput final : public AudioSummingJunction { ...@@ -65,12 +65,13 @@ class MODULES_EXPORT AudioNodeInput final : public AudioSummingJunction {
// where possible using inPlaceBus. It returns the bus which it rendered // where possible using inPlaceBus. It returns the bus which it rendered
// into, returning inPlaceBus if in-place processing was performed. // into, returning inPlaceBus if in-place processing was performed.
// Called from context's audio thread. // Called from context's audio thread.
AudioBus* Pull(AudioBus* in_place_bus, uint32_t frames_to_process); scoped_refptr<AudioBus> Pull(AudioBus* in_place_bus,
uint32_t frames_to_process);
// bus() contains the rendered audio after pull() has been called for each // bus() contains the rendered audio after pull() has been called for each
// time quantum. // time quantum.
// Called from context's audio thread. // Called from context's audio thread.
AudioBus* Bus(); scoped_refptr<AudioBus> Bus();
// updateInternalBus() updates m_internalSummingBus appropriately for the // updateInternalBus() updates m_internalSummingBus appropriately for the
// number of channels. This must be called when we own the context's graph // number of channels. This must be called when we own the context's graph
...@@ -97,8 +98,9 @@ class MODULES_EXPORT AudioNodeInput final : public AudioSummingJunction { ...@@ -97,8 +98,9 @@ class MODULES_EXPORT AudioNodeInput final : public AudioSummingJunction {
HashSet<AudioNodeOutput*> disabled_outputs_; HashSet<AudioNodeOutput*> disabled_outputs_;
// Called from context's audio thread. // Called from context's audio thread.
AudioBus* InternalSummingBus(); scoped_refptr<AudioBus> InternalSummingBus();
void SumAllConnections(AudioBus* summing_bus, uint32_t frames_to_process); void SumAllConnections(scoped_refptr<AudioBus> summing_bus,
uint32_t frames_to_process);
scoped_refptr<AudioBus> internal_summing_bus_; scoped_refptr<AudioBus> internal_summing_bus_;
......
...@@ -179,7 +179,7 @@ AudioWorkletProcessor* AudioWorkletGlobalScope::CreateProcessor( ...@@ -179,7 +179,7 @@ AudioWorkletProcessor* AudioWorkletGlobalScope::CreateProcessor(
bool AudioWorkletGlobalScope::Process( bool AudioWorkletGlobalScope::Process(
AudioWorkletProcessor* processor, AudioWorkletProcessor* processor,
Vector<AudioBus*>* input_buses, Vector<scoped_refptr<AudioBus>>* input_buses,
Vector<AudioBus*>* output_buses, Vector<AudioBus*>* output_buses,
HashMap<String, std::unique_ptr<AudioFloatArray>>* param_value_map) { HashMap<String, std::unique_ptr<AudioFloatArray>>* param_value_map) {
CHECK_GE(input_buses->size(), 0u); CHECK_GE(input_buses->size(), 0u);
...@@ -205,7 +205,7 @@ bool AudioWorkletGlobalScope::Process( ...@@ -205,7 +205,7 @@ bool AudioWorkletGlobalScope::Process(
// 1st arg of JS callback: inputs // 1st arg of JS callback: inputs
v8::Local<v8::Array> inputs = v8::Array::New(isolate, input_buses->size()); v8::Local<v8::Array> inputs = v8::Array::New(isolate, input_buses->size());
uint32_t input_bus_index = 0; uint32_t input_bus_index = 0;
for (auto* const input_bus : *input_buses) { for (auto input_bus : *input_buses) {
// If |input_bus| is null, then the input is not connected, and // If |input_bus| is null, then the input is not connected, and
// the array for that input should have one channel and a length // the array for that input should have one channel and a length
// of 0. // of 0.
......
...@@ -81,7 +81,7 @@ class MODULES_EXPORT AudioWorkletGlobalScope final : public WorkletGlobalScope { ...@@ -81,7 +81,7 @@ class MODULES_EXPORT AudioWorkletGlobalScope final : public WorkletGlobalScope {
// AudioWorkletProcessor, along with given AudioBuffer from the audio graph. // AudioWorkletProcessor, along with given AudioBuffer from the audio graph.
bool Process( bool Process(
AudioWorkletProcessor*, AudioWorkletProcessor*,
Vector<AudioBus*>* input_buses, Vector<scoped_refptr<AudioBus>>* input_buses,
Vector<AudioBus*>* output_buses, Vector<AudioBus*>* output_buses,
HashMap<String, std::unique_ptr<AudioFloatArray>>* param_value_map); HashMap<String, std::unique_ptr<AudioFloatArray>>* param_value_map);
......
...@@ -291,7 +291,7 @@ class AudioWorkletGlobalScopeTest : public PageTestBase { ...@@ -291,7 +291,7 @@ class AudioWorkletGlobalScopeTest : public PageTestBase {
SerializedScriptValue::NullValue()); SerializedScriptValue::NullValue());
EXPECT_TRUE(processor); EXPECT_TRUE(processor);
Vector<AudioBus*> input_buses; Vector<scoped_refptr<AudioBus>> input_buses;
Vector<AudioBus*> output_buses; Vector<AudioBus*> output_buses;
HashMap<String, std::unique_ptr<AudioFloatArray>> param_data_map; HashMap<String, std::unique_ptr<AudioFloatArray>> param_data_map;
scoped_refptr<AudioBus> input_bus = scoped_refptr<AudioBus> input_bus =
......
...@@ -89,12 +89,13 @@ void AudioWorkletHandler::Process(uint32_t frames_to_process) { ...@@ -89,12 +89,13 @@ void AudioWorkletHandler::Process(uint32_t frames_to_process) {
// We also need to check if the global scope is valid before we request // We also need to check if the global scope is valid before we request
// the rendering in the AudioWorkletGlobalScope. // the rendering in the AudioWorkletGlobalScope.
if (processor_ && !processor_->hasErrorOccured()) { if (processor_ && !processor_->hasErrorOccured()) {
Vector<AudioBus*> input_buses; Vector<scoped_refptr<AudioBus>> input_buses;
Vector<AudioBus*> output_buses; Vector<AudioBus*> output_buses;
for (unsigned i = 0; i < NumberOfInputs(); ++i) { for (unsigned i = 0; i < NumberOfInputs(); ++i) {
// If the input is not connected, inform the processor of that // If the input is not connected, inform the processor of that
// fact by setting the bus to null. // fact by setting the bus to null.
AudioBus* bus = Input(i).IsConnected() ? Input(i).Bus() : nullptr; scoped_refptr<AudioBus> bus =
Input(i).IsConnected() ? Input(i).Bus() : nullptr;
input_buses.push_back(bus); input_buses.push_back(bus);
} }
for (unsigned i = 0; i < NumberOfOutputs(); ++i) for (unsigned i = 0; i < NumberOfOutputs(); ++i)
......
...@@ -34,7 +34,7 @@ AudioWorkletProcessor::AudioWorkletProcessor( ...@@ -34,7 +34,7 @@ AudioWorkletProcessor::AudioWorkletProcessor(
: global_scope_(global_scope), processor_port_(port), name_(name) {} : global_scope_(global_scope), processor_port_(port), name_(name) {}
bool AudioWorkletProcessor::Process( bool AudioWorkletProcessor::Process(
Vector<AudioBus*>* input_buses, Vector<scoped_refptr<AudioBus>>* input_buses,
Vector<AudioBus*>* output_buses, Vector<AudioBus*>* output_buses,
HashMap<String, std::unique_ptr<AudioFloatArray>>* param_value_map) { HashMap<String, std::unique_ptr<AudioFloatArray>>* param_value_map) {
DCHECK(global_scope_->IsContextThread()); DCHECK(global_scope_->IsContextThread());
......
...@@ -45,7 +45,7 @@ class MODULES_EXPORT AudioWorkletProcessor : public ScriptWrappable { ...@@ -45,7 +45,7 @@ class MODULES_EXPORT AudioWorkletProcessor : public ScriptWrappable {
// |AudioWorkletHandler| invokes this method to process audio. // |AudioWorkletHandler| invokes this method to process audio.
bool Process( bool Process(
Vector<AudioBus*>* input_buses, Vector<scoped_refptr<AudioBus>>* input_buses,
Vector<AudioBus*>* output_buses, Vector<AudioBus*>* output_buses,
HashMap<String, std::unique_ptr<AudioFloatArray>>* param_value_map); HashMap<String, std::unique_ptr<AudioFloatArray>>* param_value_map);
......
...@@ -61,7 +61,7 @@ scoped_refptr<ChannelSplitterHandler> ChannelSplitterHandler::Create( ...@@ -61,7 +61,7 @@ scoped_refptr<ChannelSplitterHandler> ChannelSplitterHandler::Create(
} }
void ChannelSplitterHandler::Process(uint32_t frames_to_process) { void ChannelSplitterHandler::Process(uint32_t frames_to_process) {
AudioBus* source = Input(0).Bus(); scoped_refptr<AudioBus> source = Input(0).Bus();
DCHECK(source); DCHECK(source);
DCHECK_EQ(frames_to_process, source->length()); DCHECK_EQ(frames_to_process, source->length());
......
...@@ -90,7 +90,8 @@ void ConvolverHandler::Process(uint32_t frames_to_process) { ...@@ -90,7 +90,8 @@ void ConvolverHandler::Process(uint32_t frames_to_process) {
// FIXME: If we wanted to get fancy we could try to factor in the 'tail // FIXME: If we wanted to get fancy we could try to factor in the 'tail
// time' and stop processing once the tail dies down if // time' and stop processing once the tail dies down if
// we keep getting fed silence. // we keep getting fed silence.
reverb_->Process(Input(0).Bus(), output_bus, frames_to_process); scoped_refptr<AudioBus> input_bus = Input(0).Bus();
reverb_->Process(input_bus.get(), output_bus, frames_to_process);
} }
} else { } else {
// Too bad - the tryLock() failed. We must be in the middle of setting a // Too bad - the tryLock() failed. We must be in the middle of setting a
......
...@@ -97,7 +97,8 @@ void DynamicsCompressorHandler::Process(uint32_t frames_to_process) { ...@@ -97,7 +97,8 @@ void DynamicsCompressorHandler::Process(uint32_t frames_to_process) {
dynamics_compressor_->SetParameterValue(DynamicsCompressor::kParamRelease, dynamics_compressor_->SetParameterValue(DynamicsCompressor::kParamRelease,
release); release);
dynamics_compressor_->Process(Input(0).Bus(), output_bus, frames_to_process); scoped_refptr<AudioBus> input_bus = Input(0).Bus();
dynamics_compressor_->Process(input_bus.get(), output_bus, frames_to_process);
float reduction = float reduction =
dynamics_compressor_->ParameterValue(DynamicsCompressor::kParamReduction); dynamics_compressor_->ParameterValue(DynamicsCompressor::kParamReduction);
......
...@@ -65,7 +65,7 @@ void GainHandler::Process(uint32_t frames_to_process) { ...@@ -65,7 +65,7 @@ void GainHandler::Process(uint32_t frames_to_process) {
if (!IsInitialized() || !Input(0).IsConnected()) { if (!IsInitialized() || !Input(0).IsConnected()) {
output_bus->Zero(); output_bus->Zero();
} else { } else {
AudioBus* input_bus = Input(0).Bus(); scoped_refptr<AudioBus> input_bus = Input(0).Bus();
if (gain_->HasSampleAccurateValues()) { if (gain_->HasSampleAccurateValues()) {
// Apply sample-accurate gain scaling for precise envelopes, grain // Apply sample-accurate gain scaling for precise envelopes, grain
......
...@@ -301,7 +301,8 @@ bool OfflineAudioDestinationHandler::RenderIfNotSuspended( ...@@ -301,7 +301,8 @@ bool OfflineAudioDestinationHandler::RenderIfNotSuspended(
// This will cause the node(s) connected to us to process, which in turn // 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 // will pull on their input(s), all the way backwards through the
// rendering graph. // rendering graph.
AudioBus* rendered_bus = Input(0).Pull(destination_bus, number_of_frames); scoped_refptr<AudioBus> rendered_bus =
Input(0).Pull(destination_bus, number_of_frames);
if (!rendered_bus) { if (!rendered_bus) {
destination_bus->Zero(); destination_bus->Zero();
......
...@@ -170,7 +170,7 @@ void PannerHandler::Process(uint32_t frames_to_process) { ...@@ -170,7 +170,7 @@ void PannerHandler::Process(uint32_t frames_to_process) {
return; return;
} }
AudioBus* source = Input(0).Bus(); scoped_refptr<AudioBus> source = Input(0).Bus();
if (!source) { if (!source) {
destination->Zero(); destination->Zero();
return; return;
...@@ -194,7 +194,7 @@ void PannerHandler::Process(uint32_t frames_to_process) { ...@@ -194,7 +194,7 @@ void PannerHandler::Process(uint32_t frames_to_process) {
// But in general we can't because something may scheduled to start in the // But in general we can't because something may scheduled to start in the
// middle of the rendering quantum. On the other hand, the audible effect // middle of the rendering quantum. On the other hand, the audible effect
// may be small enough that we can afford to do this optimization. // may be small enough that we can afford to do this optimization.
ProcessSampleAccurateValues(destination, source, frames_to_process); ProcessSampleAccurateValues(destination, source.get(), frames_to_process);
} else { } else {
// Apply the panning effect. // Apply the panning effect.
double azimuth; double azimuth;
...@@ -206,8 +206,8 @@ void PannerHandler::Process(uint32_t frames_to_process) { ...@@ -206,8 +206,8 @@ void PannerHandler::Process(uint32_t frames_to_process) {
AzimuthElevation(&azimuth, &elevation); AzimuthElevation(&azimuth, &elevation);
panner_->Pan(azimuth, elevation, source, destination, frames_to_process, panner_->Pan(azimuth, elevation, source.get(), destination,
InternalChannelInterpretation()); frames_to_process, InternalChannelInterpretation());
// Get the distance and cone gain. // Get the distance and cone gain.
float total_gain = DistanceConeGain(); float total_gain = DistanceConeGain();
......
...@@ -203,7 +203,8 @@ void RealtimeAudioDestinationHandler::Render( ...@@ -203,7 +203,8 @@ void RealtimeAudioDestinationHandler::Render(
if (try_locker.Locked() && IsPullingAudioGraphAllowed()) { if (try_locker.Locked() && IsPullingAudioGraphAllowed()) {
// Renders the graph by pulling all the inputs to this node. This will // Renders the graph by pulling all the inputs to this node. This will
// in turn pull on their inputs, all the way backwards through the graph. // in turn pull on their inputs, all the way backwards through the graph.
AudioBus* rendered_bus = Input(0).Pull(destination_bus, number_of_frames); scoped_refptr<AudioBus> rendered_bus =
Input(0).Pull(destination_bus, number_of_frames);
DCHECK(rendered_bus); DCHECK(rendered_bus);
if (!rendered_bus) { if (!rendered_bus) {
......
...@@ -119,7 +119,7 @@ void ScriptProcessorHandler::Process(uint32_t frames_to_process) { ...@@ -119,7 +119,7 @@ void ScriptProcessorHandler::Process(uint32_t frames_to_process) {
// code is the consumer of inputBuffer and the producer for outputBuffer. // code is the consumer of inputBuffer and the producer for outputBuffer.
// Get input and output busses. // Get input and output busses.
AudioBus* input_bus = Input(0).Bus(); scoped_refptr<AudioBus> input_bus = Input(0).Bus();
AudioBus* output_bus = Output(0).Bus(); AudioBus* output_bus = Output(0).Bus();
// Get input and output buffers. We double-buffer both the input and output // Get input and output buffers. We double-buffer both the input and output
......
...@@ -53,7 +53,7 @@ void StereoPannerHandler::Process(uint32_t frames_to_process) { ...@@ -53,7 +53,7 @@ void StereoPannerHandler::Process(uint32_t frames_to_process) {
return; return;
} }
AudioBus* input_bus = Input(0).Bus(); scoped_refptr<AudioBus> input_bus = Input(0).Bus();
if (!input_bus) { if (!input_bus) {
output_bus->Zero(); output_bus->Zero();
return; return;
...@@ -64,10 +64,10 @@ void StereoPannerHandler::Process(uint32_t frames_to_process) { ...@@ -64,10 +64,10 @@ void StereoPannerHandler::Process(uint32_t frames_to_process) {
DCHECK_LE(frames_to_process, sample_accurate_pan_values_.size()); DCHECK_LE(frames_to_process, sample_accurate_pan_values_.size());
float* pan_values = sample_accurate_pan_values_.Data(); float* pan_values = sample_accurate_pan_values_.Data();
pan_->CalculateSampleAccurateValues(pan_values, frames_to_process); pan_->CalculateSampleAccurateValues(pan_values, frames_to_process);
stereo_panner_->PanWithSampleAccurateValues(input_bus, output_bus, stereo_panner_->PanWithSampleAccurateValues(input_bus.get(), output_bus,
pan_values, frames_to_process); pan_values, frames_to_process);
} else { } else {
stereo_panner_->PanToTargetValue(input_bus, output_bus, pan_->Value(), stereo_panner_->PanToTargetValue(input_bus.get(), output_bus, pan_->Value(),
frames_to_process); frames_to_process);
} }
} }
......
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