| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/webaudio/AudioWorkletProcessor.h" | 5 #include "modules/webaudio/AudioWorkletProcessor.h" |
| 6 | 6 |
| 7 #include "modules/webaudio/AudioWorkletGlobalScope.h" | 7 #include "modules/webaudio/AudioWorkletGlobalScope.h" |
| 8 #include "modules/webaudio/AudioWorkletProcessorDefinition.h" |
| 8 | 9 |
| 9 namespace blink { | 10 namespace blink { |
| 10 | 11 |
| 11 // This static factory should be called after an instance of |AudioWorkletNode| | 12 // This static factory should be called after an instance of |AudioWorkletNode| |
| 12 // gets created by user-supplied JS code in the main thread. This factory must | 13 // gets created by user-supplied JS code in the main thread. This factory must |
| 13 // not be called by user in |AudioWorkletGlobalScope|. | 14 // not be called by user in |AudioWorkletGlobalScope|. |
| 14 AudioWorkletProcessor* AudioWorkletProcessor::Create( | 15 AudioWorkletProcessor* AudioWorkletProcessor::Create( |
| 15 AudioWorkletGlobalScope* global_scope, | 16 AudioWorkletGlobalScope* global_scope, |
| 16 const String& name) { | 17 AudioWorkletProcessorDefinition* definition) { |
| 17 DCHECK(!IsMainThread()); | 18 DCHECK(!IsMainThread()); |
| 18 DCHECK(global_scope); | 19 DCHECK(global_scope); |
| 19 return new AudioWorkletProcessor(global_scope, name); | 20 return new AudioWorkletProcessor(global_scope, definition); |
| 20 } | 21 } |
| 21 | 22 |
| 22 AudioWorkletProcessor::AudioWorkletProcessor( | 23 AudioWorkletProcessor::AudioWorkletProcessor( |
| 23 AudioWorkletGlobalScope* global_scope, | 24 AudioWorkletGlobalScope* global_scope, |
| 24 const String& name) | 25 AudioWorkletProcessorDefinition* definition) |
| 25 : global_scope_(global_scope), name_(name), instance_(this) {} | 26 : global_scope_(global_scope), definition_(definition), instance_(this) {} |
| 26 | 27 |
| 27 AudioWorkletProcessor::~AudioWorkletProcessor() {} | 28 AudioWorkletProcessor::~AudioWorkletProcessor() {} |
| 28 | 29 |
| 29 void AudioWorkletProcessor::SetInstance(v8::Isolate* isolate, | 30 void AudioWorkletProcessor::SetInstance(v8::Isolate* isolate, |
| 30 v8::Local<v8::Object> instance) { | 31 v8::Local<v8::Object> instance) { |
| 31 DCHECK(global_scope_->IsContextThread()); | 32 DCHECK(global_scope_->IsContextThread()); |
| 32 instance_.Set(isolate, instance); | 33 instance_.Set(isolate, instance); |
| 33 } | 34 } |
| 34 | 35 |
| 35 v8::Local<v8::Object> AudioWorkletProcessor::InstanceLocal( | 36 v8::Local<v8::Object> AudioWorkletProcessor::InstanceLocal( |
| 36 v8::Isolate* isolate) { | 37 v8::Isolate* isolate) { |
| 37 DCHECK(global_scope_->IsContextThread()); | 38 DCHECK(global_scope_->IsContextThread()); |
| 38 return instance_.NewLocal(isolate); | 39 return instance_.NewLocal(isolate); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void AudioWorkletProcessor::Process(AudioBuffer* input_buffer, | 42 void AudioWorkletProcessor::Process( |
| 42 AudioBuffer* output_buffer) { | 43 AudioBuffer* input_buffer, |
| 44 AudioBuffer* output_buffer, |
| 45 HashMap<String, AudioFloatArray*> audio_param_data_map) { |
| 43 DCHECK(global_scope_->IsContextThread()); | 46 DCHECK(global_scope_->IsContextThread()); |
| 44 global_scope_->Process(this, input_buffer, output_buffer); | 47 if (!input_buffer || !output_buffer) |
| 48 return; |
| 49 |
| 50 global_scope_->Process(this, |
| 51 input_buffer, output_buffer, audio_param_data_map); |
| 52 } |
| 53 |
| 54 const String& AudioWorkletProcessor::GetName() const { |
| 55 return definition_->GetName(); |
| 56 } |
| 57 |
| 58 const AudioWorkletProcessorDefinition* |
| 59 AudioWorkletProcessor::GetDefinition() const { |
| 60 return definition_; |
| 61 } |
| 62 |
| 63 void AudioWorkletProcessor::Dispose() { |
| 64 is_disposed_ = true; |
| 45 } | 65 } |
| 46 | 66 |
| 47 DEFINE_TRACE(AudioWorkletProcessor) { | 67 DEFINE_TRACE(AudioWorkletProcessor) { |
| 48 visitor->Trace(global_scope_); | 68 visitor->Trace(global_scope_); |
| 69 visitor->Trace(definition_); |
| 49 } | 70 } |
| 50 | 71 |
| 51 DEFINE_TRACE_WRAPPERS(AudioWorkletProcessor) { | 72 DEFINE_TRACE_WRAPPERS(AudioWorkletProcessor) { |
| 52 visitor->TraceWrappers(instance_.Cast<v8::Value>()); | 73 visitor->TraceWrappers(instance_.Cast<v8::Value>()); |
| 53 } | 74 } |
| 54 | 75 |
| 55 } // namespace blink | 76 } // namespace blink |
| OLD | NEW |