/* * Copyright (c) 2024, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include namespace Web::MediaSourceExtensions { // https://w3c.github.io/media-source/#dom-mediasource class MediaSource : public DOM::EventTarget { WEB_PLATFORM_OBJECT(MediaSource, DOM::EventTarget); GC_DECLARE_ALLOCATOR(MediaSource); public: [[nodiscard]] static WebIDL::ExceptionOr> construct_impl(JS::Realm&); void queue_a_media_source_task(GC::Ref>); Bindings::ReadyState ready_state() const; bool ready_state_is_closed() const; void set_has_ever_been_attached(); void set_ready_state_to_open_and_fire_sourceopen_event(); GC::Ref source_buffers(); GC::Ref active_source_buffers(); Utf16String next_track_id(); // https://w3c.github.io/media-source/#dom-mediasource-canconstructindedicatedworker static bool can_construct_in_dedicated_worker(JS::VM&) { return false; } void set_assigned_to_media_element(Badge, HTML::HTMLMediaElement&); void unassign_from_media_element(Badge); GC::Ptr media_element_assigned_to() { return m_media_element_assigned_to; } void set_onsourceopen(GC::Ptr); GC::Ptr onsourceopen(); void set_onsourceended(GC::Ptr); GC::Ptr onsourceended(); void set_onsourceclose(GC::Ptr); GC::Ptr onsourceclose(); WebIDL::ExceptionOr> add_source_buffer(String const& type); WebIDL::ExceptionOr end_of_stream(Optional const& error = {}); void run_end_of_stream_algorithm(Badge, Optional const& error) { run_end_of_stream_algorithm(error); } // https://w3c.github.io/media-source/#dom-mediasource-duration double duration() const; WebIDL::ExceptionOr set_duration(double); // https://w3c.github.io/media-source/#duration-change-algorithm void run_duration_change_algorithm(double new_duration); static bool is_type_supported(String const&); static bool is_type_supported(JS::VM&, String const& type) { return is_type_supported(type); } protected: MediaSource(JS::Realm&); virtual ~MediaSource() override; virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; private: // https://w3c.github.io/media-source/#end-of-stream-algorithm void run_end_of_stream_algorithm(Optional const&); Bindings::ReadyState m_ready_state { Bindings::ReadyState::Closed }; bool m_has_ever_been_attached { false }; GC::Ptr m_media_element_assigned_to; GC::Ref m_source_buffers; GC::Ref m_active_source_buffers; double m_duration { NAN }; u64 m_next_track_id = 1; }; }