mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2026-04-18 18:00:31 +00:00
The segments are parsed for the SourceBufferProcessor by the WebMByteStreamParser. It parses the initialization segment to update its internal set of tracks, then SourceBufferProcessor/SourceBuffer set them up for playback. When a media segment is received, it also parses as much of it as is available, returning all the coded frames found so far. SourceBufferProcessor then tells TrackBufferDemuxer to remove any overlapping frames and insert the new ones. TrackBufferDemuxer implements the Demuxer interface in terms of the coded frame store maintained by the SourceBufferProcessor. It returns the frames in decode order when requested by a data provider. When a is needed, it finds the keyframe prior to the target timestamp, and checks that there are no gaps in data up to the target timestamp. If there are any gaps, it blocks until the gaps are gone.
116 lines
3.7 KiB
C++
116 lines
3.7 KiB
C++
/*
|
|
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibJS/Runtime/Realm.h>
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
#include <LibWeb/Bindings/TextTrackListPrototype.h>
|
|
#include <LibWeb/HTML/EventNames.h>
|
|
#include <LibWeb/HTML/TextTrackList.h>
|
|
|
|
namespace Web::HTML {
|
|
|
|
GC_DEFINE_ALLOCATOR(TextTrackList);
|
|
|
|
TextTrackList::TextTrackList(JS::Realm& realm)
|
|
: DOM::EventTarget(realm, MayInterfereWithIndexedPropertyAccess::Yes)
|
|
{
|
|
}
|
|
|
|
TextTrackList::~TextTrackList() = default;
|
|
|
|
void TextTrackList::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(TextTrackList);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
void TextTrackList::visit_edges(JS::Cell::Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
visitor.visit(m_text_tracks);
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#dom-texttracklist-item
|
|
JS::ThrowCompletionOr<Optional<JS::PropertyDescriptor>> TextTrackList::internal_get_own_property(JS::PropertyKey const& property_name) const
|
|
{
|
|
// To determine the value of an indexed property of a TextTrackList object for a given index index, the user
|
|
// agent must return the indexth text track in the list represented by the TextTrackList object.
|
|
if (property_name.is_number()) {
|
|
if (auto index = property_name.as_number(); index < m_text_tracks.size()) {
|
|
JS::PropertyDescriptor descriptor;
|
|
descriptor.value = m_text_tracks.at(index);
|
|
|
|
return descriptor;
|
|
}
|
|
}
|
|
|
|
return Base::internal_get_own_property(property_name);
|
|
}
|
|
|
|
void TextTrackList::add_track(GC::Ref<TextTrack> text_track)
|
|
{
|
|
m_text_tracks.append(text_track);
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#dom-texttracklist-length
|
|
size_t TextTrackList::length() const
|
|
{
|
|
return m_text_tracks.size();
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#dom-texttracklist-gettrackbyid
|
|
GC::Ptr<TextTrack> TextTrackList::get_track_by_id(StringView id) const
|
|
{
|
|
// The getTrackById(id) method must return the first TextTrack in the TextTrackList object whose id
|
|
// IDL attribute would return a value equal to the value of the id argument.
|
|
auto it = m_text_tracks.find_if([&](auto const& text_track) {
|
|
return text_track->id() == id;
|
|
});
|
|
|
|
// When no tracks match the given argument, the method must return null.
|
|
if (it == m_text_tracks.end())
|
|
return nullptr;
|
|
|
|
return *it;
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#handler-texttracklist-onchange
|
|
void TextTrackList::set_onchange(WebIDL::CallbackType* event_handler)
|
|
{
|
|
set_event_handler_attribute(HTML::EventNames::change, event_handler);
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#handler-texttracklist-onchange
|
|
WebIDL::CallbackType* TextTrackList::onchange()
|
|
{
|
|
return event_handler_attribute(HTML::EventNames::change);
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#handler-texttracklist-onaddtrack
|
|
void TextTrackList::set_onaddtrack(WebIDL::CallbackType* event_handler)
|
|
{
|
|
set_event_handler_attribute(HTML::EventNames::addtrack, event_handler);
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#handler-texttracklist-onaddtrack
|
|
WebIDL::CallbackType* TextTrackList::onaddtrack()
|
|
{
|
|
return event_handler_attribute(HTML::EventNames::addtrack);
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#handler-texttracklist-onremovetrack
|
|
void TextTrackList::set_onremovetrack(WebIDL::CallbackType* event_handler)
|
|
{
|
|
set_event_handler_attribute(HTML::EventNames::removetrack, event_handler);
|
|
}
|
|
|
|
// https://html.spec.whatwg.org/multipage/media.html#handler-texttracklist-onremovetrack
|
|
WebIDL::CallbackType* TextTrackList::onremovetrack()
|
|
{
|
|
return event_handler_attribute(HTML::EventNames::removetrack);
|
|
}
|
|
|
|
}
|