/* * Copyright (c) 2024, Jelle Raaijmakers * Copyright (c) 2026, Gregory Bertilson * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace Web::MediaSourceExtensions { class SourceBufferProcessor; struct InitializationSegmentData; // https://w3c.github.io/media-source/#dom-sourcebuffer class SourceBuffer : public DOM::EventTarget { WEB_PLATFORM_OBJECT(SourceBuffer, DOM::EventTarget); GC_DECLARE_ALLOCATOR(SourceBuffer); public: void set_onupdatestart(GC::Ptr); GC::Ptr onupdatestart(); void set_onupdate(GC::Ptr); GC::Ptr onupdate(); void set_onupdateend(GC::Ptr); GC::Ptr onupdateend(); void set_onerror(GC::Ptr); GC::Ptr onerror(); void set_onabort(GC::Ptr); GC::Ptr onabort(); // https://w3c.github.io/media-source/#dom-sourcebuffer-mode Bindings::AppendMode mode() const; WebIDL::ExceptionOr set_mode(Bindings::AppendMode); // https://w3c.github.io/media-source/#dom-sourcebuffer-updating bool updating() const; // https://w3c.github.io/media-source/#dom-sourcebuffer-buffered GC::Ref buffered(); void set_content_type(String const& type); // https://w3c.github.io/media-source/#addsourcebuffer-method WebIDL::ExceptionOr append_buffer(GC::Root const&); // https://w3c.github.io/media-source/#dom-sourcebuffer-abort WebIDL::ExceptionOr abort(); // https://w3c.github.io/media-source/#dom-sourcebuffer-changetype WebIDL::ExceptionOr change_type(String const& type); void set_reached_end_of_stream(Badge); void clear_reached_end_of_stream(Badge); protected: SourceBuffer(JS::Realm&, MediaSource&); virtual ~SourceBuffer() override; virtual void initialize(JS::Realm&) override; virtual void visit_edges(Cell::Visitor&) override; private: WebIDL::ExceptionOr prepare_append(); void run_buffer_append_algorithm(); void run_append_error_algorithm(); void on_first_initialization_segment_processed(InitializationSegmentData const&); void update_ready_state_and_duration_after_coded_frame_processing(); void finish_buffer_append(); GC::Ref m_media_source; NonnullRefPtr m_processor; // https://w3c.github.io/media-source/#dom-sourcebuffer-audiotracks GC::Ref m_audio_tracks; // https://w3c.github.io/media-source/#dom-sourcebuffer-videotracks GC::Ref m_video_tracks; // https://w3c.github.io/media-source/#dom-sourcebuffer-texttracks GC::Ref m_text_tracks; }; }