LibWeb: Add MediaElementAudioSourceNode interface

This commit is contained in:
Tim Ledbetter 2025-01-15 23:07:00 +00:00 committed by Luke Wilde
parent a588756105
commit aa39aa50f7
Notes: github-actions[bot] 2025-01-17 19:05:50 +00:00
7 changed files with 111 additions and 0 deletions

View file

@ -800,6 +800,7 @@ set(SOURCES
WebAudio/DelayNode.cpp
WebAudio/DynamicsCompressorNode.cpp
WebAudio/GainNode.cpp
WebAudio/MediaElementAudioSourceNode.cpp
WebAudio/OfflineAudioContext.cpp
WebAudio/OscillatorNode.cpp
WebAudio/PannerNode.cpp

View file

@ -0,0 +1,47 @@
/*
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/MediaElementAudioSourceNodePrototype.h>
#include <LibWeb/HTML/HTMLMediaElement.h>
#include <LibWeb/WebAudio/AudioContext.h>
#include <LibWeb/WebAudio/MediaElementAudioSourceNode.h>
namespace Web::WebAudio {
GC_DEFINE_ALLOCATOR(MediaElementAudioSourceNode);
MediaElementAudioSourceNode::MediaElementAudioSourceNode(JS::Realm& realm, GC::Ref<AudioContext> context, MediaElementAudioSourceOptions const& options)
: AudioNode(realm, context)
, m_media_element(*options.media_element)
{
}
MediaElementAudioSourceNode::~MediaElementAudioSourceNode() = default;
WebIDL::ExceptionOr<GC::Ref<MediaElementAudioSourceNode>> MediaElementAudioSourceNode::create(JS::Realm& realm, GC::Ref<AudioContext> context, MediaElementAudioSourceOptions const& options)
{
return construct_impl(realm, context, options);
}
WebIDL::ExceptionOr<GC::Ref<MediaElementAudioSourceNode>> MediaElementAudioSourceNode::construct_impl(JS::Realm& realm, GC::Ref<AudioContext> context, MediaElementAudioSourceOptions const& options)
{
return realm.create<MediaElementAudioSourceNode>(realm, context, options);
}
void MediaElementAudioSourceNode::initialize(JS::Realm& realm)
{
Base::initialize(realm);
WEB_SET_PROTOTYPE_FOR_INTERFACE(MediaElementAudioSourceNode);
}
void MediaElementAudioSourceNode::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_media_element);
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2025, Tim Ledbetter <tim.ledbetter@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/WebAudio/AudioNode.h>
namespace Web::WebAudio {
// https://webaudio.github.io/web-audio-api/#MediaElementAudioSourceOptions
struct MediaElementAudioSourceOptions {
GC::Ptr<HTML::HTMLMediaElement> media_element;
};
// https://webaudio.github.io/web-audio-api/#MediaElementAudioSourceNode
class MediaElementAudioSourceNode final : public AudioNode {
WEB_PLATFORM_OBJECT(MediaElementAudioSourceNode, AudioNode);
GC_DECLARE_ALLOCATOR(MediaElementAudioSourceNode);
public:
virtual ~MediaElementAudioSourceNode() override;
static WebIDL::ExceptionOr<GC::Ref<MediaElementAudioSourceNode>> create(JS::Realm&, GC::Ref<AudioContext>, MediaElementAudioSourceOptions const&);
static WebIDL::ExceptionOr<GC::Ref<MediaElementAudioSourceNode>> construct_impl(JS::Realm&, GC::Ref<AudioContext>, MediaElementAudioSourceOptions const&);
virtual WebIDL::UnsignedLong number_of_inputs() override { return 0; }
virtual WebIDL::UnsignedLong number_of_outputs() override { return 1; }
GC::Ref<HTML::HTMLMediaElement> media_element() const { return m_media_element; }
private:
MediaElementAudioSourceNode(JS::Realm&, GC::Ref<AudioContext>, MediaElementAudioSourceOptions const&);
virtual void initialize(JS::Realm&) override;
virtual void visit_edges(Cell::Visitor&) override;
GC::Ref<HTML::HTMLMediaElement> m_media_element;
};
}

View file

@ -0,0 +1,17 @@
#import <HTML/HTMLMediaElement.idl>
#import <WebAudio/AudioContext.idl>
#import <WebAudio/AudioNode.idl>
#import <WebAudio/AudioParam.idl>
#import <WebAudio/AudioParam.idl>
// https://webaudio.github.io/web-audio-api/#MediaElementAudioSourceOptions
dictionary MediaElementAudioSourceOptions {
required HTMLMediaElement mediaElement;
};
// https://webaudio.github.io/web-audio-api/#MediaElementAudioSourceNode
[Exposed=Window]
interface MediaElementAudioSourceNode : AudioNode {
constructor (AudioContext context, MediaElementAudioSourceOptions options);
[SameObject] readonly attribute HTMLMediaElement mediaElement;
};

View file

@ -374,6 +374,7 @@ libweb_js_bindings(WebAudio/ChannelMergerNode)
libweb_js_bindings(WebAudio/ChannelSplitterNode)
libweb_js_bindings(WebAudio/ConstantSourceNode)
libweb_js_bindings(WebAudio/DelayNode)
libweb_js_bindings(WebAudio/MediaElementAudioSourceNode)
libweb_js_bindings(WebAudio/OfflineAudioContext)
libweb_js_bindings(WebAudio/OscillatorNode)
libweb_js_bindings(WebAudio/PannerNode)

View file

@ -35,6 +35,7 @@ static bool is_platform_object(Type const& type)
"AnimationTimeline"sv,
"Attr"sv,
"AudioBuffer"sv,
"AudioContext"sv,
"AudioListener"sv,
"AudioNode"sv,
"AudioParam"sv,

View file

@ -234,6 +234,7 @@ ManagedSourceBuffer
Map
MathMLElement
MediaCapabilities
MediaElementAudioSourceNode
MediaError
MediaList
MediaQueryList