Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Unified Diff: third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp

Issue 2793593002: AudioWorklet prototype
Patch Set: Merge changes, AudioParam bug fix Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
diff --git a/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp b/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
index 75fd1c8c35927d38d68d4a878a14dea3f0fe509e..51ed4572ec1167539f2595f2e877d5f41a3842a2 100644
--- a/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
+++ b/third_party/WebKit/Source/modules/webaudio/AudioWorkletGlobalScope.cpp
@@ -8,13 +8,16 @@
#include "bindings/core/v8/NativeValueTraitsImpl.h"
#include "bindings/core/v8/ToV8ForCore.h"
#include "bindings/core/v8/V8BindingForCore.h"
+#include "bindings/core/v8/V8ObjectBuilder.h"
#include "bindings/core/v8/WorkerOrWorkletScriptController.h"
#include "bindings/modules/v8/V8AudioParamDescriptor.h"
+#include "core/dom/DOMTypedArray.h"
#include "core/dom/ExceptionCode.h"
#include "modules/webaudio/AudioBuffer.h"
#include "modules/webaudio/AudioParamDescriptor.h"
#include "modules/webaudio/AudioWorkletProcessor.h"
#include "modules/webaudio/AudioWorkletProcessorDefinition.h"
+#include "platform/audio/AudioUtilities.h"
#include "platform/bindings/V8BindingMacros.h"
#include "platform/bindings/V8ObjectConstructor.h"
#include "platform/weborigin/SecurityOrigin.h"
@@ -28,6 +31,8 @@ AudioWorkletGlobalScope* AudioWorkletGlobalScope::Create(
v8::Isolate* isolate,
WorkerThread* thread,
WorkerClients* worker_clients) {
+ LOG(INFO) << "AudioWorkletGlobalScope::RegisterProcessor thread = "
+ << thread;
return new AudioWorkletGlobalScope(url, user_agent,
std::move(security_origin), isolate,
thread, worker_clients);
@@ -72,6 +77,7 @@ void AudioWorkletGlobalScope::registerProcessor(
v8::Isolate* isolate = ScriptController()->GetScriptState()->GetIsolate();
v8::Local<v8::Context> context = ScriptController()->GetContext();
+ // Get a handle for the class definition (i.e. constructor)
if (!class_definition.V8Value()->IsFunction()) {
exception_state.ThrowTypeError(
"The processor definition is neither 'class' nor 'function'.");
@@ -81,6 +87,7 @@ void AudioWorkletGlobalScope::registerProcessor(
v8::Local<v8::Function> class_definition_local =
v8::Local<v8::Function>::Cast(class_definition.V8Value());
+ // Get a handle for |prototype| object out of class definition.
v8::Local<v8::Value> prototype_value_local;
bool prototype_extracted =
class_definition_local->Get(context, V8String(isolate, "prototype"))
@@ -90,6 +97,7 @@ void AudioWorkletGlobalScope::registerProcessor(
v8::Local<v8::Object> prototype_object_local =
v8::Local<v8::Object>::Cast(prototype_value_local);
+ // Extract |process| function.
v8::Local<v8::Value> process_value_local;
bool process_extracted =
prototype_object_local->Get(context, V8String(isolate, "process"))
@@ -158,11 +166,12 @@ AudioWorkletProcessor* AudioWorkletGlobalScope::CreateInstance(
v8::Local<v8::Object> instance_local;
if (!V8ObjectConstructor::NewInstance(isolate,
definition->ConstructorLocal(isolate))
- .ToLocal(&instance_local)) {
+ .ToLocal(&instance_local)) {
return nullptr;
}
- AudioWorkletProcessor* processor = AudioWorkletProcessor::Create(this, name);
+ AudioWorkletProcessor* processor =
+ AudioWorkletProcessor::Create(this, definition);
DCHECK(processor);
processor->SetInstance(isolate, instance_local);
@@ -172,23 +181,43 @@ AudioWorkletProcessor* AudioWorkletGlobalScope::CreateInstance(
return processor;
}
-bool AudioWorkletGlobalScope::Process(AudioWorkletProcessor* processor,
- AudioBuffer* input_buffer,
- AudioBuffer* output_buffer) {
+bool AudioWorkletGlobalScope::Process(
+ AudioWorkletProcessor* processor,
+ AudioBuffer* input_buffer,
+ AudioBuffer* output_buffer,
+ HashMap<String, AudioFloatArray*> audio_param_data_map) {
CHECK(input_buffer);
CHECK(output_buffer);
ScriptState* script_state = ScriptController()->GetScriptState();
+ v8::Isolate* isolate = script_state->GetIsolate();
+
ScriptState::Scope scope(script_state);
- v8::Isolate* isolate = script_state->GetIsolate();
AudioWorkletProcessorDefinition* definition =
FindDefinition(processor->GetName());
DCHECK(definition);
+ V8ObjectBuilder parameters_object(script_state);
+
+ for (const auto& param_name : audio_param_data_map.Keys()) {
+ DOMFloat32Array* param_data_array =
+ DOMFloat32Array::CreateOrNull(AudioUtilities::kRenderQuantumFrames);
+ const float* source = audio_param_data_map.at(param_name)->Data();
+ float* destination = param_data_array->Data();
+
+ memcpy(destination, source,
+ AudioUtilities::kRenderQuantumFrames * sizeof(float));
+
+ parameters_object.Add(
+ StringView(param_name),
+ ToV8(param_data_array, script_state->GetContext()->Global(), isolate));
+ }
+
v8::Local<v8::Value> argv[] = {
ToV8(input_buffer, script_state->GetContext()->Global(), isolate),
- ToV8(output_buffer, script_state->GetContext()->Global(), isolate)};
+ ToV8(output_buffer, script_state->GetContext()->Global(), isolate),
+ parameters_object.V8Value()};
// TODO(hongchan): Catch exceptions thrown in the process method. The verbose
// options forces the TryCatch object to save the exception location. The

Powered by Google App Engine
This is Rietveld 408576698