Skip to main content

cdp_driver/protocol/
web_audio.rs

1// @generated by `just generate-methods` from protocol/*.json.
2// Do not edit by hand; edit xtask/ and regenerate.
3
4//! This domain allows inspection of Web Audio API.
5//! <https://webaudio.github.io/web-audio-api/>
6//!
7//! Types, command parameters and event payloads for the `WebAudio`
8//! domain. The method-name constants for the same domain are in
9//! [`crate::methods`].
10//!
11//! This domain is experimental and may change without notice.
12
13use serde::{Deserialize, Serialize};
14
15/// An unique ID for a graph object (AudioContext, AudioNode, AudioParam) in
16/// Web Audio API
17pub type GraphObjectId = String;
18
19/// Enum of BaseAudioContext types
20#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
21pub enum ContextType {
22    /// `realtime`
23    #[serde(rename = "realtime")]
24    Realtime,
25    /// `offline`
26    #[serde(rename = "offline")]
27    Offline,
28    /// A value this vendored schema does not list. Chrome adds values ahead of
29    /// the published protocol, so an unrecognised one is kept as it arrived
30    /// rather than failing the payload it came in.
31    #[serde(untagged)]
32    Unrecognized(String),
33}
34
35/// Enum of AudioContextState from the spec
36#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
37pub enum ContextState {
38    /// `suspended`
39    #[serde(rename = "suspended")]
40    Suspended,
41    /// `running`
42    #[serde(rename = "running")]
43    Running,
44    /// `closed`
45    #[serde(rename = "closed")]
46    Closed,
47    /// `interrupted`
48    #[serde(rename = "interrupted")]
49    Interrupted,
50    /// A value this vendored schema does not list. Chrome adds values ahead of
51    /// the published protocol, so an unrecognised one is kept as it arrived
52    /// rather than failing the payload it came in.
53    #[serde(untagged)]
54    Unrecognized(String),
55}
56
57/// Enum of AudioNode types
58pub type NodeType = String;
59
60/// Enum of AudioNode::ChannelCountMode from the spec
61#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
62pub enum ChannelCountMode {
63    /// `clamped-max`
64    #[serde(rename = "clamped-max")]
65    ClampedMax,
66    /// `explicit`
67    #[serde(rename = "explicit")]
68    Explicit,
69    /// `max`
70    #[serde(rename = "max")]
71    Max,
72    /// A value this vendored schema does not list. Chrome adds values ahead of
73    /// the published protocol, so an unrecognised one is kept as it arrived
74    /// rather than failing the payload it came in.
75    #[serde(untagged)]
76    Unrecognized(String),
77}
78
79/// Enum of AudioNode::ChannelInterpretation from the spec
80#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
81pub enum ChannelInterpretation {
82    /// `discrete`
83    #[serde(rename = "discrete")]
84    Discrete,
85    /// `speakers`
86    #[serde(rename = "speakers")]
87    Speakers,
88    /// A value this vendored schema does not list. Chrome adds values ahead of
89    /// the published protocol, so an unrecognised one is kept as it arrived
90    /// rather than failing the payload it came in.
91    #[serde(untagged)]
92    Unrecognized(String),
93}
94
95/// Enum of AudioParam types
96pub type ParamType = String;
97
98/// Enum of AudioParam::AutomationRate from the spec
99#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
100pub enum AutomationRate {
101    /// `a-rate`
102    #[serde(rename = "a-rate")]
103    ARate,
104    /// `k-rate`
105    #[serde(rename = "k-rate")]
106    KRate,
107    /// A value this vendored schema does not list. Chrome adds values ahead of
108    /// the published protocol, so an unrecognised one is kept as it arrived
109    /// rather than failing the payload it came in.
110    #[serde(untagged)]
111    Unrecognized(String),
112}
113
114/// Fields in AudioContext that change in real-time.
115#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
116pub struct ContextRealtimeData {
117    /// The current context time in second in BaseAudioContext.
118    #[serde(rename = "currentTime")]
119    pub current_time: f64,
120    /// The time spent on rendering graph divided by render quantum duration, and
121    /// multiplied by 100. 100 means the audio renderer reached the full capacity
122    /// and glitch may occur.
123    #[serde(rename = "renderCapacity")]
124    pub render_capacity: f64,
125    /// A running mean of callback interval.
126    #[serde(rename = "callbackIntervalMean")]
127    pub callback_interval_mean: f64,
128    /// A running variance of callback interval.
129    #[serde(rename = "callbackIntervalVariance")]
130    pub callback_interval_variance: f64,
131}
132
133/// Protocol object for BaseAudioContext
134#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
135pub struct BaseAudioContext {
136    #[serde(rename = "contextId")]
137    pub context_id: GraphObjectId,
138    #[serde(rename = "contextType")]
139    pub context_type: ContextType,
140    #[serde(rename = "contextState")]
141    pub context_state: ContextState,
142    #[serde(
143        rename = "realtimeData",
144        default,
145        skip_serializing_if = "Option::is_none"
146    )]
147    pub realtime_data: Option<ContextRealtimeData>,
148    /// Platform-dependent callback buffer size.
149    #[serde(rename = "callbackBufferSize")]
150    pub callback_buffer_size: f64,
151    /// Number of output channels supported by audio hardware in use.
152    #[serde(rename = "maxOutputChannelCount")]
153    pub max_output_channel_count: f64,
154    /// Context sample rate.
155    #[serde(rename = "sampleRate")]
156    pub sample_rate: f64,
157    #[serde(rename = "renderQuantumSize")]
158    pub render_quantum_size: f64,
159}
160
161/// Protocol object for AudioListener
162#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
163pub struct AudioListener {
164    #[serde(rename = "listenerId")]
165    pub listener_id: GraphObjectId,
166    #[serde(rename = "contextId")]
167    pub context_id: GraphObjectId,
168}
169
170/// Protocol object for AudioNode
171#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
172pub struct AudioNode {
173    #[serde(rename = "nodeId")]
174    pub node_id: GraphObjectId,
175    #[serde(rename = "contextId")]
176    pub context_id: GraphObjectId,
177    #[serde(rename = "nodeType")]
178    pub node_type: NodeType,
179    #[serde(rename = "numberOfInputs")]
180    pub number_of_inputs: f64,
181    #[serde(rename = "numberOfOutputs")]
182    pub number_of_outputs: f64,
183    #[serde(rename = "channelCount")]
184    pub channel_count: f64,
185    #[serde(rename = "channelCountMode")]
186    pub channel_count_mode: ChannelCountMode,
187    #[serde(rename = "channelInterpretation")]
188    pub channel_interpretation: ChannelInterpretation,
189}
190
191/// Protocol object for AudioParam
192#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
193pub struct AudioParam {
194    #[serde(rename = "paramId")]
195    pub param_id: GraphObjectId,
196    #[serde(rename = "nodeId")]
197    pub node_id: GraphObjectId,
198    #[serde(rename = "contextId")]
199    pub context_id: GraphObjectId,
200    #[serde(rename = "paramType")]
201    pub param_type: ParamType,
202    pub rate: AutomationRate,
203    #[serde(rename = "defaultValue")]
204    pub default_value: f64,
205    #[serde(rename = "minValue")]
206    pub min_value: f64,
207    #[serde(rename = "maxValue")]
208    pub max_value: f64,
209}
210
211/// Enables the WebAudio domain and starts sending context lifetime events.
212///
213/// Parameters of `WebAudio.enable`.
214#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
215pub struct EnableParams {}
216
217impl crate::typed::Command for EnableParams {
218    const METHOD: &'static str = "WebAudio.enable";
219    type Returns = crate::typed::NoReturns;
220}
221
222/// Disables the WebAudio domain.
223///
224/// Parameters of `WebAudio.disable`.
225#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
226pub struct DisableParams {}
227
228impl crate::typed::Command for DisableParams {
229    const METHOD: &'static str = "WebAudio.disable";
230    type Returns = crate::typed::NoReturns;
231}
232
233/// Fetch the realtime data from the registered contexts.
234///
235/// Parameters of `WebAudio.getRealtimeData`.
236#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
237pub struct GetRealtimeDataParams {
238    #[serde(rename = "contextId")]
239    pub context_id: GraphObjectId,
240}
241
242/// What `WebAudio.getRealtimeData` answers with.
243#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
244pub struct GetRealtimeDataReturns {
245    #[serde(rename = "realtimeData")]
246    pub realtime_data: ContextRealtimeData,
247}
248
249impl crate::typed::Command for GetRealtimeDataParams {
250    const METHOD: &'static str = "WebAudio.getRealtimeData";
251    type Returns = GetRealtimeDataReturns;
252}
253
254/// Notifies that a new BaseAudioContext has been created.
255///
256/// Payload of the `WebAudio.contextCreated` event.
257#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
258pub struct ContextCreatedEvent {
259    pub context: BaseAudioContext,
260}
261
262impl crate::typed::Event for ContextCreatedEvent {
263    const METHOD: &'static str = "WebAudio.contextCreated";
264}
265
266/// Notifies that an existing BaseAudioContext will be destroyed.
267///
268/// Payload of the `WebAudio.contextWillBeDestroyed` event.
269#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
270pub struct ContextWillBeDestroyedEvent {
271    #[serde(rename = "contextId")]
272    pub context_id: GraphObjectId,
273}
274
275impl crate::typed::Event for ContextWillBeDestroyedEvent {
276    const METHOD: &'static str = "WebAudio.contextWillBeDestroyed";
277}
278
279/// Notifies that existing BaseAudioContext has changed some properties (id
280/// stays the same)..
281///
282/// Payload of the `WebAudio.contextChanged` event.
283#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
284pub struct ContextChangedEvent {
285    pub context: BaseAudioContext,
286}
287
288impl crate::typed::Event for ContextChangedEvent {
289    const METHOD: &'static str = "WebAudio.contextChanged";
290}
291
292/// Notifies that the construction of an AudioListener has finished.
293///
294/// Payload of the `WebAudio.audioListenerCreated` event.
295#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
296pub struct AudioListenerCreatedEvent {
297    pub listener: AudioListener,
298}
299
300impl crate::typed::Event for AudioListenerCreatedEvent {
301    const METHOD: &'static str = "WebAudio.audioListenerCreated";
302}
303
304/// Notifies that a new AudioListener has been created.
305///
306/// Payload of the `WebAudio.audioListenerWillBeDestroyed` event.
307#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
308pub struct AudioListenerWillBeDestroyedEvent {
309    #[serde(rename = "contextId")]
310    pub context_id: GraphObjectId,
311    #[serde(rename = "listenerId")]
312    pub listener_id: GraphObjectId,
313}
314
315impl crate::typed::Event for AudioListenerWillBeDestroyedEvent {
316    const METHOD: &'static str = "WebAudio.audioListenerWillBeDestroyed";
317}
318
319/// Notifies that a new AudioNode has been created.
320///
321/// Payload of the `WebAudio.audioNodeCreated` event.
322#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
323pub struct AudioNodeCreatedEvent {
324    pub node: AudioNode,
325}
326
327impl crate::typed::Event for AudioNodeCreatedEvent {
328    const METHOD: &'static str = "WebAudio.audioNodeCreated";
329}
330
331/// Notifies that an existing AudioNode has been destroyed.
332///
333/// Payload of the `WebAudio.audioNodeWillBeDestroyed` event.
334#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
335pub struct AudioNodeWillBeDestroyedEvent {
336    #[serde(rename = "contextId")]
337    pub context_id: GraphObjectId,
338    #[serde(rename = "nodeId")]
339    pub node_id: GraphObjectId,
340}
341
342impl crate::typed::Event for AudioNodeWillBeDestroyedEvent {
343    const METHOD: &'static str = "WebAudio.audioNodeWillBeDestroyed";
344}
345
346/// Notifies that a new AudioParam has been created.
347///
348/// Payload of the `WebAudio.audioParamCreated` event.
349#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
350pub struct AudioParamCreatedEvent {
351    pub param: AudioParam,
352}
353
354impl crate::typed::Event for AudioParamCreatedEvent {
355    const METHOD: &'static str = "WebAudio.audioParamCreated";
356}
357
358/// Notifies that an existing AudioParam has been destroyed.
359///
360/// Payload of the `WebAudio.audioParamWillBeDestroyed` event.
361#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
362pub struct AudioParamWillBeDestroyedEvent {
363    #[serde(rename = "contextId")]
364    pub context_id: GraphObjectId,
365    #[serde(rename = "nodeId")]
366    pub node_id: GraphObjectId,
367    #[serde(rename = "paramId")]
368    pub param_id: GraphObjectId,
369}
370
371impl crate::typed::Event for AudioParamWillBeDestroyedEvent {
372    const METHOD: &'static str = "WebAudio.audioParamWillBeDestroyed";
373}
374
375/// Notifies that two AudioNodes are connected.
376///
377/// Payload of the `WebAudio.nodesConnected` event.
378#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
379pub struct NodesConnectedEvent {
380    #[serde(rename = "contextId")]
381    pub context_id: GraphObjectId,
382    #[serde(rename = "sourceId")]
383    pub source_id: GraphObjectId,
384    #[serde(rename = "destinationId")]
385    pub destination_id: GraphObjectId,
386    #[serde(
387        rename = "sourceOutputIndex",
388        default,
389        skip_serializing_if = "Option::is_none"
390    )]
391    pub source_output_index: Option<f64>,
392    #[serde(
393        rename = "destinationInputIndex",
394        default,
395        skip_serializing_if = "Option::is_none"
396    )]
397    pub destination_input_index: Option<f64>,
398}
399
400impl crate::typed::Event for NodesConnectedEvent {
401    const METHOD: &'static str = "WebAudio.nodesConnected";
402}
403
404/// Notifies that AudioNodes are disconnected. The destination can be null,
405/// and it means all the outgoing connections from the source are
406/// disconnected.
407///
408/// Payload of the `WebAudio.nodesDisconnected` event.
409#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
410pub struct NodesDisconnectedEvent {
411    #[serde(rename = "contextId")]
412    pub context_id: GraphObjectId,
413    #[serde(rename = "sourceId")]
414    pub source_id: GraphObjectId,
415    #[serde(rename = "destinationId")]
416    pub destination_id: GraphObjectId,
417    #[serde(
418        rename = "sourceOutputIndex",
419        default,
420        skip_serializing_if = "Option::is_none"
421    )]
422    pub source_output_index: Option<f64>,
423    #[serde(
424        rename = "destinationInputIndex",
425        default,
426        skip_serializing_if = "Option::is_none"
427    )]
428    pub destination_input_index: Option<f64>,
429}
430
431impl crate::typed::Event for NodesDisconnectedEvent {
432    const METHOD: &'static str = "WebAudio.nodesDisconnected";
433}
434
435/// Notifies that an AudioNode is connected to an AudioParam.
436///
437/// Payload of the `WebAudio.nodeParamConnected` event.
438#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
439pub struct NodeParamConnectedEvent {
440    #[serde(rename = "contextId")]
441    pub context_id: GraphObjectId,
442    #[serde(rename = "sourceId")]
443    pub source_id: GraphObjectId,
444    #[serde(rename = "destinationId")]
445    pub destination_id: GraphObjectId,
446    #[serde(
447        rename = "sourceOutputIndex",
448        default,
449        skip_serializing_if = "Option::is_none"
450    )]
451    pub source_output_index: Option<f64>,
452}
453
454impl crate::typed::Event for NodeParamConnectedEvent {
455    const METHOD: &'static str = "WebAudio.nodeParamConnected";
456}
457
458/// Notifies that an AudioNode is disconnected to an AudioParam.
459///
460/// Payload of the `WebAudio.nodeParamDisconnected` event.
461#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
462pub struct NodeParamDisconnectedEvent {
463    #[serde(rename = "contextId")]
464    pub context_id: GraphObjectId,
465    #[serde(rename = "sourceId")]
466    pub source_id: GraphObjectId,
467    #[serde(rename = "destinationId")]
468    pub destination_id: GraphObjectId,
469    #[serde(
470        rename = "sourceOutputIndex",
471        default,
472        skip_serializing_if = "Option::is_none"
473    )]
474    pub source_output_index: Option<f64>,
475}
476
477impl crate::typed::Event for NodeParamDisconnectedEvent {
478    const METHOD: &'static str = "WebAudio.nodeParamDisconnected";
479}