script/dom/audio/
audiodestinationnode.rs1use dom_struct::dom_struct;
6use js::context::JSContext;
7use script_bindings::reflector::reflect_dom_object_with_cx;
8
9use crate::dom::audio::audionode::{AudioNode, AudioNodeOptionsHelper, MAX_CHANNEL_COUNT};
10use crate::dom::audio::baseaudiocontext::BaseAudioContext;
11use crate::dom::bindings::codegen::Bindings::AudioDestinationNodeBinding::AudioDestinationNodeMethods;
12use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
13 AudioNodeOptions, ChannelCountMode, ChannelInterpretation,
14};
15use crate::dom::bindings::root::DomRoot;
16use crate::dom::globalscope::GlobalScope;
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 Some(context.destination_node()),
33 context,
34 node_options,
35 1,
36 1,
37 ),
38 }
39 }
40
41 #[cfg_attr(crown, expect(crown::unrooted_must_root))]
42 pub(crate) fn new(
43 cx: &mut JSContext,
44 global: &GlobalScope,
45 context: &BaseAudioContext,
46 options: &AudioNodeOptions,
47 ) -> DomRoot<AudioDestinationNode> {
48 let node = AudioDestinationNode::new_inherited(context, options);
49 reflect_dom_object_with_cx(Box::new(node), global, cx)
50 }
51}
52
53impl AudioDestinationNodeMethods<crate::DomTypeHolder> for AudioDestinationNode {
54 fn MaxChannelCount(&self) -> u32 {
56 MAX_CHANNEL_COUNT
57 }
58}