summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/blink/renderer/modules/webaudio/cross_thread_audio_worklet_processor_info.h
blob: e8b55fe9062abad726a133fbf6ee4433d3cfcc9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 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 THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_CROSS_THREAD_AUDIO_WORKLET_PROCESSOR_INFO_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_CROSS_THREAD_AUDIO_WORKLET_PROCESSOR_INFO_H_

#include "third_party/blink/renderer/bindings/modules/v8/v8_audio_param_descriptor.h"
#include "third_party/blink/renderer/modules/webaudio/audio_worklet_processor_definition.h"
#include "third_party/blink/renderer/platform/bindings/enumeration_base.h"

namespace blink {

// A class for shallow repackage of |AudioParamDescriptor|. This is created only
// when requested when the synchronization between AudioWorkletMessagingProxy
// and AudioWorkletGlobalScope.
class CrossThreadAudioParamInfo {
  DISALLOW_NEW();

 public:
  explicit CrossThreadAudioParamInfo(const AudioParamDescriptor* descriptor)
      : automation_rate_(
            IDLEnumAsString(descriptor->automationRate()).IsolatedCopy()),
        default_value_(descriptor->defaultValue()),
        max_value_(descriptor->maxValue()),
        min_value_(descriptor->minValue()),
        name_(descriptor->name().IsolatedCopy()) {}

  const String& AutomationRate() const { return automation_rate_; }
  float DefaultValue() const { return default_value_; }
  float MaxValue() const { return max_value_; }
  float MinValue() const { return min_value_; }
  const String& Name() const { return name_; }

 private:
  const String automation_rate_;
  const float default_value_;
  const float max_value_;
  const float min_value_;
  const String name_;
};

// A class for shallow repackage of |AudioWorkletProcessorDefinition|. This is
// created only when requested when the synchronization between
// AudioWorkletMessagingProxy and AudioWorkletGlobalScope.
class CrossThreadAudioWorkletProcessorInfo {
  DISALLOW_NEW();

 public:
  explicit CrossThreadAudioWorkletProcessorInfo(
      const AudioWorkletProcessorDefinition& definition)
      : name_(definition.GetName().IsolatedCopy()) {
    // To avoid unnecessary reallocations of the vector.
    param_info_list_.ReserveInitialCapacity(
        definition.GetAudioParamDescriptorNames().size());

    for (const String& name : definition.GetAudioParamDescriptorNames()) {
      param_info_list_.emplace_back(
          definition.GetAudioParamDescriptor(name));
    }
  }

  const String& Name() const { return name_; }
  Vector<CrossThreadAudioParamInfo> ParamInfoList() { return param_info_list_; }

 private:
  const String name_;
  Vector<CrossThreadAudioParamInfo> param_info_list_;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_CROSS_THREAD_AUDIO_WORKLET_PROCESSOR_INFO_H_