Commit 383b95ed authored by Hongchan Choi's avatar Hongchan Choi Committed by Commit Bot

Implement AudioParamMap

AudioParamMap is a map-like container owned by AudioWorkletNode object.
It associates the name of a parameter to the actual AudioParam object.

Spec: https://webaudio.github.io/web-audio-api/#idl-def-AudioParamMap

Bug: 736781
Change-Id: I063add4281954036b90442dc5c4a6e9c50145e41
Reviewed-on: https://chromium-review.googlesource.com/548239
Commit-Queue: Hongchan Choi <hongchan@chromium.org>
Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarTakashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486007}
parent 6d14d6a8
......@@ -346,6 +346,17 @@ interface AudioParam
method setValueAtTime
method setValueCurveAtTime
setter value
interface AudioParamMap
attribute @@toStringTag
getter size
method @@iterator
method constructor
method entries
method forEach
method get
method has
method keys
method values
interface AudioProcessingEvent : Event
attribute @@toStringTag
getter inputBuffer
......
......@@ -346,6 +346,17 @@ interface AudioParam
method setValueAtTime
method setValueCurveAtTime
setter value
interface AudioParamMap
attribute @@toStringTag
getter size
method @@iterator
method constructor
method entries
method forEach
method get
method has
method keys
method values
interface AudioProcessingEvent : Event
attribute @@toStringTag
getter inputBuffer
......
......@@ -290,6 +290,7 @@ modules_idl_files =
"webaudio/AudioListener.idl",
"webaudio/AudioNode.idl",
"webaudio/AudioParam.idl",
"webaudio/AudioParamMap.idl",
"webaudio/AudioProcessingEvent.idl",
"webaudio/AudioScheduledSourceNode.idl",
"webaudio/AudioWorkletGlobalScope.idl",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "modules/webaudio/AudioParamMap.h"
namespace blink {
class AudioParamMapIterationSource final
: public PairIterable<String, AudioParam*>::IterationSource {
public:
AudioParamMapIterationSource(
const HeapHashMap<String, Member<AudioParam>>& map) {
for (const auto name : map.Keys()) {
parameter_names_.push_back(name);
parameter_objects_.push_back(map.at(name));
}
}
bool Next(ScriptState* scrip_state,
String& key,
AudioParam*& audio_param,
ExceptionState&) override {
if (current_index_ == parameter_names_.size())
return false;
key = parameter_names_[current_index_];
audio_param = parameter_objects_[current_index_];
++current_index_;
return true;
}
DEFINE_INLINE_VIRTUAL_TRACE() {
visitor->Trace(parameter_objects_);
PairIterable<String, AudioParam*>::IterationSource::Trace(visitor);
}
private:
// For sequential iteration (e.g. Next()).
Vector<String> parameter_names_;
HeapVector<Member<AudioParam>> parameter_objects_;
unsigned current_index_;
};
AudioParamMap::AudioParamMap(
const HeapHashMap<String, Member<AudioParam>>& parameter_map)
: parameter_map_(parameter_map) {}
PairIterable<String, AudioParam*>::IterationSource*
AudioParamMap::StartIteration(ScriptState*, ExceptionState&) {
return new AudioParamMapIterationSource(parameter_map_);
}
bool AudioParamMap::GetMapEntry(ScriptState*,
const String& key,
AudioParam*& audio_param,
ExceptionState&) {
if (parameter_map_.Contains(key)) {
audio_param = parameter_map_.at(key);
return true;
}
return false;
}
} // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef AudioParamMap_h
#define AudioParamMap_h
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/Maplike.h"
#include "bindings/core/v8/V8BindingForCore.h"
#include "modules/webaudio/AudioParam.h"
#include "platform/bindings/ScriptWrappable.h"
#include "platform/heap/Handle.h"
#include "platform/wtf/text/WTFString.h"
namespace blink {
class AudioParam;
class AudioParamMap final : public GarbageCollectedFinalized<AudioParamMap>,
public ScriptWrappable,
public Maplike<String, AudioParam*> {
DEFINE_WRAPPERTYPEINFO();
public:
explicit AudioParamMap(
const HeapHashMap<String, Member<AudioParam>>& parameter_map);
// IDL attributes / methods
size_t size() const { return parameter_map_.size(); }
AudioParam* At(String name) { return parameter_map_.at(name); }
bool Contains(String name) { return parameter_map_.Contains(name); }
DEFINE_INLINE_VIRTUAL_TRACE() { visitor->Trace(parameter_map_); }
private:
PairIterable<String, AudioParam*>::IterationSource* StartIteration(
ScriptState*,
ExceptionState&) override;
bool GetMapEntry(ScriptState*,
const String& key,
AudioParam*&,
ExceptionState&) override;
const HeapHashMap<String, Member<AudioParam>> parameter_map_;
};
} // namespace blink
#endif
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// https://webaudio.github.io/web-audio-api/#idl-def-AudioParamMap
[
RuntimeEnabled=AudioWorklet
] interface AudioParamMap {
readonly maplike<DOMString, AudioParam>;
};
......@@ -32,6 +32,8 @@ blink_modules_sources("webaudio") {
"AudioNodeOutput.h",
"AudioParam.cpp",
"AudioParam.h",
"AudioParamMap.cpp",
"AudioParamMap.h",
"AudioParamTimeline.cpp",
"AudioParamTimeline.h",
"AudioProcessingEvent.cpp",
......
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