script/dom/audio/
audiodestinationnode.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6
7use crate::dom::audio::audionode::{AudioNode, AudioNodeOptionsHelper, MAX_CHANNEL_COUNT};
8use crate::dom::audio::baseaudiocontext::BaseAudioContext;
9use crate::dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::AudioDestinationNodeMethods;
10use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
11    AudioNodeOptions, ChannelCountMode, ChannelInterpretation,
12};
13use crate::dom::bindings::reflector::reflect_dom_object;
14use crate::dom::bindings::root::DomRoot;
15use crate::dom::globalscope::GlobalScope;
16use crate::script_runtime::CanGc;
17
18#[dom_struct]
19pub(crate) struct AudioDestinationNode {
20    node: AudioNode,
21}
22
23impl AudioDestinationNode {
24    fn new_inherited(
25        context: &BaseAudioContext,
26        options: &AudioNodeOptions,
27    ) -> AudioDestinationNode {
28        let node_options =
29            options.unwrap_or(2, ChannelCountMode::Max, ChannelInterpretation::Speakers);
30        AudioDestinationNode {
31            node: AudioNode::new_inherited_for_id(
32                context.destination_node(),
33                context,
34                node_options,
35                1,
36                1,
37            ),
38        }
39    }
40
41    #[cfg_attr(crown, allow(crown::unrooted_must_root))]
42    pub(crate) fn new(
43        global: &GlobalScope,
44        context: &BaseAudioContext,
45        options: &AudioNodeOptions,
46        can_gc: CanGc,
47    ) -> DomRoot<AudioDestinationNode> {
48        let node = AudioDestinationNode::new_inherited(context, options);
49        reflect_dom_object(Box::new(node), global, can_gc)
50    }
51}
52
53impl AudioDestinationNodeMethods<crate::DomTypeHolder> for AudioDestinationNode {
54    // https://webaudio.github.io/web-audio-api/#dom-audiodestinationnode-maxchannelcount
55    fn MaxChannelCount(&self) -> u32 {
56        MAX_CHANNEL_COUNT
57    }
58}