Skip to content

Truly independent web browser

LibMedia+LibWeb+Compositor: Implement VideoPlaybackQuality

Zaggy1024e1b836a74f05
diff --git a/Libraries/LibCompositing/Video/VideoFramePresentationPage.h b/Libraries/LibCompositing/Video/VideoFramePresentationPage.h
index d45a261a4be..3353a95a8b9 100644
--- a/Libraries/LibCompositing/Video/VideoFramePresentationPage.h
+++ b/Libraries/LibCompositing/Video/VideoFramePresentationPage.h
@@ -51,6 +51,7 @@ public:
struct PresentedFrame {
u64 generation { 0 };
u64 presented_frame_count { 0 };
+ u64 dropped_frame_count { 0 };
AK::Duration media_time { AK::Duration::zero() };
MonotonicTime presentation_time;
u32 width { 0 };
diff --git a/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp b/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
index 9c993e006f6..05a9beff046 100644
--- a/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
+++ b/Libraries/LibMedia/Sinks/DisplayingVideoSink.cpp
@@ -131,6 +131,11 @@ DisplayingVideoSinkUpdateResult DisplayingVideoSink::update(MonotonicTime now)
auto time_state = m_time_reader.time_state(now);
auto current_time = time_state.time;
auto new_frame_available = false;
+ u64 passed_frame_count = 0;
+ auto last_passed_frame_was_late = false;
+ Optional<AK::Duration> last_passed_timestamp;
+ if (m_current_frame)
+ last_passed_timestamp = m_current_frame->timestamp();
auto last_status = PipelineStatus::Pending;
auto seek_resolved_during_this_update = false;
@@ -150,6 +155,7 @@ DisplayingVideoSinkUpdateResult DisplayingVideoSink::update(MonotonicTime now)
}
if (m_seek_status != SeekStatus::None && resolves_seek(last_status)) {
m_current_frame.clear();
+ last_passed_timestamp.clear();
m_seek_status = SeekStatus::None;
seek_resolved_during_this_update = true;
new_frame_available = true;
@@ -159,7 +165,7 @@ DisplayingVideoSinkUpdateResult DisplayingVideoSink::update(MonotonicTime now)
if (m_next_frame->timestamp() > current_time)
break;
- if (m_current_frame && m_current_frame->timestamp() > m_next_frame->timestamp()) {
+ if (last_passed_timestamp.has_value() && last_passed_timestamp.value() > m_next_frame->timestamp()) {
m_next_frame.clear();
continue;
}
@@ -177,6 +183,11 @@ DisplayingVideoSinkUpdateResult DisplayingVideoSink::update(MonotonicTime now)
last_status = next.status;
if (!is_terminal(last_status)) {
if (last_status == PipelineStatus::HaveData) {
+ if (!m_seek_resolution_is_pending_frame_at_target) {
+ passed_frame_count++;
+ last_passed_frame_was_late = true;
+ }
+ last_passed_timestamp = m_next_frame->timestamp();
m_next_frame = move(next.frame);
m_input->consume();
m_cached_frames_are_discontinuous = true;
@@ -188,8 +199,19 @@ DisplayingVideoSinkUpdateResult DisplayingVideoSink::update(MonotonicTime now)
m_current_frame = m_next_frame.release_nonnull();
m_cached_frames_are_discontinuous = false;
new_frame_available = true;
+ last_passed_timestamp = m_current_frame->timestamp();
+ if (m_seek_resolution_is_pending_frame_at_target)
+ passed_frame_count = 1;
+ else
+ passed_frame_count++;
+ last_passed_frame_was_late = false;
}
+ if (last_passed_frame_was_late)
+ m_frame_counts.dropped += passed_frame_count;
+ else
+ m_frame_counts.presented += passed_frame_count;
+
auto status_to_dispatch = last_status;
if (m_current_frame != nullptr && m_seek_status == SeekStatus::None) {
diff --git a/Libraries/LibMedia/Sinks/DisplayingVideoSink.h b/Libraries/LibMedia/Sinks/DisplayingVideoSink.h
index 1931746ceb0..ea1ce934706 100644
--- a/Libraries/LibMedia/Sinks/DisplayingVideoSink.h
+++ b/Libraries/LibMedia/Sinks/DisplayingVideoSink.h
@@ -26,6 +26,13 @@ struct DisplayingVideoSinkUpdateResult {
bool may_require_updates { false };
};
+struct DisplayingVideoSinkFrameCounts {
+ u64 presented { 0 };
+ u64 dropped { 0 };
+
+ bool is_zero() const { return presented == 0 && dropped == 0; }
+};
+
class MEDIA_API DisplayingVideoSink final : public VideoSink
, public ThreadSafeWeakable<DisplayingVideoSink> {
public:
@@ -46,6 +53,7 @@ public:
DisplayingVideoSinkUpdateResult update(MonotonicTime now);
RefPtr<VideoFrame> current_frame() const;
+ DisplayingVideoSinkFrameCounts take_frame_counts() { return exchange(m_frame_counts, {}); }
void set_on_present_needed(Function<void()> handler) { m_on_present_needed = move(handler); }
@@ -59,6 +67,7 @@ private:
RefPtr<VideoFrame> m_current_frame;
bool m_cached_frames_are_discontinuous { false };
bool m_seek_resolution_is_pending_frame_at_target { false };
+ DisplayingVideoSinkFrameCounts m_frame_counts;
enum class SeekStatus : u8 {
None,
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 57faa9606fe..dcc73e647d5 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -682,6 +682,7 @@ set(SOURCES
HTML/UserNavigationInvolvement.cpp
HTML/UniversalGlobalScope.cpp
HTML/ValidityState.cpp
+ HTML/VideoPlaybackQuality.cpp
HTML/VideoTrack.cpp
HTML/VideoTrackList.cpp
HTML/WebViewHints.cpp
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 755a388fc6d..4c7f0ee1418 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -837,6 +837,7 @@ class TransferDataDecoder;
class UserActivation;
class UserScrollGestureHold;
class ValidityState;
+class VideoPlaybackQuality;
class VideoTrack;
class VideoTrackList;
class Window;
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
index 4b15f7c8a45..2a960d5c406 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp
@@ -97,8 +97,7 @@ public:
return;
unregister();
m_compositor_host = &compositor_host;
- m_frames_presented_on_earlier_pages += m_frames_presented_on_this_page;
- m_frames_presented_on_this_page = 0;
+ m_frame_counts_of_earlier_pages += exchange(m_frame_counts_of_this_page, {});
m_presentation_page = MUST(Compositing::VideoFramePresentationPage::create());
m_compositor_host->add_video_sink(m_handle, *m_presentation_page);
}
@@ -139,7 +138,7 @@ public:
auto presented_frame = m_presentation_page->presented_frame();
if (!presented_frame.has_value())
return {};
- m_frames_presented_on_this_page = presented_frame->presented_frame_count;
+ note_frame_counts(*presented_frame);
if (presented_frame->presented_frame_count == 0)
return {};
auto hold = Compositing::VideoFrameHold::hold_frame_of_generation(*m_presentation_page, m_handle, presented_frame->generation, m_compositor_host->video_frame_hold_releaser_for_current_connection());
@@ -147,7 +146,7 @@ public:
continue;
m_hold_for_video_frame_callbacks = move(hold);
return PresentedVideoFrame {
- .presented_frames = total_presented_frames(),
+ .presented_frames = frame_counts().presented,
.media_time = presented_frame->media_time,
.presentation_time = presented_frame->presentation_time,
.width = presented_frame->width,
@@ -159,13 +158,13 @@ public:
void release_frame_held_for_video_frame_callbacks() { m_hold_for_video_frame_callbacks = nullptr; }
- u64 total_presented_frames()
+ VideoFrameCounts frame_counts()
{
if (m_presentation_page) {
if (auto presented_frame = m_presentation_page->presented_frame(); presented_frame.has_value())
- m_frames_presented_on_this_page = presented_frame->presented_frame_count;
+ note_frame_counts(*presented_frame);
}
- return m_frames_presented_on_earlier_pages + m_frames_presented_on_this_page;
+ return m_frame_counts_of_earlier_pages + m_frame_counts_of_this_page;
}
private:
@@ -175,8 +174,13 @@ private:
RefPtr<Compositing::VideoFramePresentationPage> m_presentation_page;
WeakPtr<Compositing::VideoFrameHold> m_latest_hold;
RefPtr<Compositing::VideoFrameHold> m_hold_for_video_frame_callbacks;
- u64 m_frames_presented_on_earlier_pages { 0 };
- u64 m_frames_presented_on_this_page { 0 };
+ void note_frame_counts(Compositing::VideoFramePresentationPage::PresentedFrame const& presented_frame)
+ {
+ m_frame_counts_of_this_page = { .presented = presented_frame.presented_frame_count, .dropped = presented_frame.dropped_frame_count };
+ }
+
+ VideoFrameCounts m_frame_counts_of_earlier_pages;
+ VideoFrameCounts m_frame_counts_of_this_page;
};
static u64 s_next_remote_fetch_data_id = 0;
@@ -877,6 +881,10 @@ WebIDL::ExceptionOr<void> HTMLMediaElement::load_element()
{
m_has_fired_loadeddata = false;
+ // https://w3c.github.io/media-playback-quality/#concepts
+ // NB: The total and dropped video frame counts are "reset to 0 when the media element load algorithm is invoked".
+ m_video_frame_counts_at_last_load = video_frame_counts();
+
// FIXME: 1. Set this element's is currently stalled to false.
// 2. Abort any already-running instance of the resource selection algorithm for this element.
@@ -2011,12 +2019,12 @@ Optional<Compositing::CapturedVideoFrame> HTMLMediaElement::capture_current_vide
return m_active_video_sink->capture_current_frame();
}
-u64 HTMLMediaElement::presented_video_frame_count() const
+HTMLMediaElement::VideoFrameCounts HTMLMediaElement::video_frame_counts() const
{
- auto presented_frames = m_frames_presented_by_released_video_sinks;
+ auto frame_counts = m_frame_counts_of_released_video_sinks;
if (m_active_video_sink)
- presented_frames += m_active_video_sink->total_presented_frames();
- return presented_frames;
+ frame_counts += m_active_video_sink->frame_counts();
+ return frame_counts;
}
Optional<HTMLMediaElement::PresentedVideoFrame> HTMLMediaElement::hold_presented_video_frame_for_callbacks()
@@ -2025,7 +2033,7 @@ Optional<HTMLMediaElement::PresentedVideoFrame> HTMLMediaElement::hold_presented
return {};
auto presented_frame = m_active_video_sink->hold_presented_frame_for_video_frame_callbacks();
if (presented_frame.has_value())
- presented_frame->presented_frames += m_frames_presented_by_released_video_sinks;
+ presented_frame->presented_frames += m_frame_counts_of_released_video_sinks.presented;
return presented_frame;
}
@@ -2077,7 +2085,7 @@ void HTMLMediaElement::release_active_video_sink()
{
auto handle = video_sink_handle();
if (m_active_video_sink)
- m_frames_presented_by_released_video_sinks += m_active_video_sink->total_presented_frames();
+ m_frame_counts_of_released_video_sinks += m_active_video_sink->frame_counts();
m_active_video_sink.clear();
if (m_playback_manager && handle.has_value())
m_playback_manager->disable_video_sink_by_handle(*handle);
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.h b/Libraries/LibWeb/HTML/HTMLMediaElement.h
index 5564e9656f8..ef5491f0aa4 100644
--- a/Libraries/LibWeb/HTML/HTMLMediaElement.h
+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.h
@@ -202,6 +202,17 @@ public:
Optional<Media::VideoSinkHandle> video_sink_handle() const;
Optional<Compositing::CapturedVideoFrame> capture_current_video_frame() const;
+ struct VideoFrameCounts {
+ u64 presented { 0 };
+ u64 dropped { 0 };
+
+ VideoFrameCounts operator+(VideoFrameCounts const& other) const { return { presented + other.presented, dropped + other.dropped }; }
+ VideoFrameCounts operator-(VideoFrameCounts const& other) const { return { presented - other.presented, dropped - other.dropped }; }
+ VideoFrameCounts& operator+=(VideoFrameCounts const& other) { return *this = *this + other; }
+ };
+ VideoFrameCounts video_frame_counts() const;
+ VideoFrameCounts video_frame_counts_since_last_load() const { return video_frame_counts() - m_video_frame_counts_at_last_load; }
+
struct PresentedVideoFrame {
u64 presented_frames { 0 };
AK::Duration media_time;
@@ -209,7 +220,6 @@ public:
u32 width { 0 };
u32 height { 0 };
};
- u64 presented_video_frame_count() const;
Optional<PresentedVideoFrame> hold_presented_video_frame_for_callbacks();
void release_presented_video_frame_held_for_callbacks();
virtual void request_rendering_update_for_video_frame_callbacks() { }
@@ -475,7 +485,8 @@ private:
RefPtr<Core::Timer> m_playback_position_update_timer;
GC::Ptr<VideoTrack> m_selected_video_track;
OwnPtr<ActiveVideoSink> m_active_video_sink;
- u64 m_frames_presented_by_released_video_sinks { 0 };
+ VideoFrameCounts m_frame_counts_of_released_video_sinks;
+ VideoFrameCounts m_video_frame_counts_at_last_load;
mutable bool m_video_frame_was_recently_captured { false };
mutable RefPtr<Core::Timer> m_video_frame_capture_keepalive_timer;
Optional<ScreenWakeLockHandle> m_screen_wake_lock;
diff --git a/Libraries/LibWeb/HTML/HTMLVideoElement.cpp b/Libraries/LibWeb/HTML/HTMLVideoElement.cpp
index 107ed690bf0..a80a006a87a 100644
--- a/Libraries/LibWeb/HTML/HTMLVideoElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLVideoElement.cpp
@@ -29,6 +29,7 @@
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Scripting/ExceptionReporter.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
+#include <LibWeb/HTML/VideoPlaybackQuality.h>
#include <LibWeb/HTML/VideoTrack.h>
#include <LibWeb/HTML/VideoTrackList.h>
#include <LibWeb/HTML/Window.h>
@@ -539,7 +540,7 @@ WebIDL::UnsignedLong HTMLVideoElement::request_video_frame_callback(GC::Ref<WebI
// AD-HOC: Callbacks are "fired the next time a frame is presented to the compositor", so to ensure we don't invoke
// the callback on a frame that was presented before the request, update the identifier here.
if (m_list_of_video_frame_request_callbacks.is_empty())
- m_last_presented_frame_identifier = presented_video_frame_count();
+ m_last_presented_frame_identifier = video_frame_counts().presented;
// 4. Append callback to video's list of video frame request callbacks, associated with callbackId.
m_list_of_video_frame_request_callbacks.append({ .handle = callback_id, .callback = callback });
@@ -645,4 +646,22 @@ void HTMLVideoElement::request_rendering_update_for_video_frame_callbacks()
document().page().client().request_frame();
}
+// https://w3c.github.io/media-playback-quality/#dom-htmlvideoelement-getvideoplaybackquality
+GC::Ref<VideoPlaybackQuality> HTMLVideoElement::get_video_playback_quality()
+{
+ auto frame_counts = video_frame_counts_since_last_load();
+ auto clamp_count = [](u64 count) { return static_cast<WebIDL::UnsignedLong>(min(count, NumericLimits<WebIDL::UnsignedLong>::max())); };
+
+ // 1. Let playbackQuality be a new instance of VideoPlaybackQuality.
+ // 2. Set playbackQuality.creationTime to the current high resolution time.
+ // 3. Set playbackQuality.totalVideoFrames to the current value of the total video frame count.
+ // 4. Set playbackQuality.droppedVideoFrames to the current value of the dropped video frame count.
+ // 5. [DEPRECATED] Set playbackQuality.corruptedVideoFrames to the current value of the corrupted video frame count.
+ // 6. Return playbackQuality.
+ return VideoPlaybackQuality::create(
+ HighResolutionTime::current_high_resolution_time(relevant_global_object(*this)),
+ clamp_count(frame_counts.dropped),
+ clamp_count(frame_counts.presented + frame_counts.dropped));
+}
+
}
diff --git a/Libraries/LibWeb/HTML/HTMLVideoElement.h b/Libraries/LibWeb/HTML/HTMLVideoElement.h
index 9f5e1c616dd..abd8532f632 100644
--- a/Libraries/LibWeb/HTML/HTMLVideoElement.h
+++ b/Libraries/LibWeb/HTML/HTMLVideoElement.h
@@ -70,6 +70,8 @@ public:
void for_each_visual_clone(Function<void(HTMLVideoElement&)> const&) const;
void clear_visual_clones();
+ GC::Ref<VideoPlaybackQuality> get_video_playback_quality();
+
WebIDL::UnsignedLong request_video_frame_callback(GC::Ref<WebIDL::CallbackType>);
void cancel_video_frame_callback(WebIDL::UnsignedLong handle);
bool has_video_frame_request_callbacks() const { return !m_list_of_video_frame_request_callbacks.is_empty(); }
diff --git a/Libraries/LibWeb/HTML/VideoPlaybackQuality.cpp b/Libraries/LibWeb/HTML/VideoPlaybackQuality.cpp
new file mode 100644
index 00000000000..1fe94a9e7fa
--- /dev/null
+++ b/Libraries/LibWeb/HTML/VideoPlaybackQuality.cpp
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibGC/Heap.h>
+#include <LibWeb/HTML/VideoPlaybackQuality.h>
+
+namespace Web::HTML {
+
+GC_DEFINE_ALLOCATOR(VideoPlaybackQuality);
+
+GC::Ref<VideoPlaybackQuality> VideoPlaybackQuality::create(HighResolutionTime::DOMHighResTimeStamp creation_time, WebIDL::UnsignedLong dropped_video_frames, WebIDL::UnsignedLong total_video_frames)
+{
+ return GC::Heap::the().allocate<VideoPlaybackQuality>(creation_time, dropped_video_frames, total_video_frames);
+}
+
+VideoPlaybackQuality::VideoPlaybackQuality(HighResolutionTime::DOMHighResTimeStamp creation_time, WebIDL::UnsignedLong dropped_video_frames, WebIDL::UnsignedLong total_video_frames)
+ : m_creation_time(creation_time)
+ , m_dropped_video_frames(dropped_video_frames)
+ , m_total_video_frames(total_video_frames)
+{
+}
+
+}
diff --git a/Libraries/LibWeb/HTML/VideoPlaybackQuality.h b/Libraries/LibWeb/HTML/VideoPlaybackQuality.h
new file mode 100644
index 00000000000..ece58c4088c
--- /dev/null
+++ b/Libraries/LibWeb/HTML/VideoPlaybackQuality.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/Bindings/Wrappable.h>
+#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>
+#include <LibWebCommon/WebIDL/Types.h>
+
+namespace Web::HTML {
+
+// https://w3c.github.io/media-playback-quality/#videoplaybackquality-interface
+class VideoPlaybackQuality final : public Bindings::GCAllocatedWrappable {
+ WEB_WRAPPABLE(VideoPlaybackQuality, Bindings::GCAllocatedWrappable);
+ GC_DECLARE_ALLOCATOR(VideoPlaybackQuality);
+
+public:
+ [[nodiscard]] static GC::Ref<VideoPlaybackQuality> create(HighResolutionTime::DOMHighResTimeStamp creation_time, WebIDL::UnsignedLong dropped_video_frames, WebIDL::UnsignedLong total_video_frames);
+
+ HighResolutionTime::DOMHighResTimeStamp creation_time() const { return m_creation_time; }
+ WebIDL::UnsignedLong dropped_video_frames() const { return m_dropped_video_frames; }
+ WebIDL::UnsignedLong total_video_frames() const { return m_total_video_frames; }
+ WebIDL::UnsignedLong corrupted_video_frames() const { return 0; }
+
+private:
+ VideoPlaybackQuality(HighResolutionTime::DOMHighResTimeStamp creation_time, WebIDL::UnsignedLong dropped_video_frames, WebIDL::UnsignedLong total_video_frames);
+
+ HighResolutionTime::DOMHighResTimeStamp m_creation_time { 0 };
+ WebIDL::UnsignedLong m_dropped_video_frames { 0 };
+ WebIDL::UnsignedLong m_total_video_frames { 0 };
+};
+
+}
diff --git a/Libraries/LibWeb/HTML/VideoPlaybackQuality.idl b/Libraries/LibWeb/HTML/VideoPlaybackQuality.idl
new file mode 100644
index 00000000000..d086c3c56c6
--- /dev/null
+++ b/Libraries/LibWeb/HTML/VideoPlaybackQuality.idl
@@ -0,0 +1,15 @@
+// https://w3c.github.io/media-playback-quality/#idl-def-videoplaybackquality
+[Exposed=Window]
+interface VideoPlaybackQuality {
+ readonly attribute DOMHighResTimeStamp creationTime;
+ readonly attribute unsigned long droppedVideoFrames;
+ readonly attribute unsigned long totalVideoFrames;
+
+ // Deprecated!
+ readonly attribute unsigned long corruptedVideoFrames;
+};
+
+// https://w3c.github.io/media-playback-quality/#htmlvideoelement
+partial interface HTMLVideoElement {
+ VideoPlaybackQuality getVideoPlaybackQuality();
+};
diff --git a/Libraries/LibWeb/idl_files.cmake b/Libraries/LibWeb/idl_files.cmake
index c2f76ca7beb..05be954340f 100644
--- a/Libraries/LibWeb/idl_files.cmake
+++ b/Libraries/LibWeb/idl_files.cmake
@@ -372,6 +372,7 @@ libweb_js_bindings(HTML/TrackEvent)
libweb_js_bindings(HTML/UserActivation)
libweb_js_bindings(HTML/ValidityState)
libweb_js_bindings(HTML/VideoFrameRequestCallback)
+libweb_js_bindings(HTML/VideoPlaybackQuality)
libweb_js_bindings(HTML/VideoTrack)
libweb_js_bindings(HTML/VideoTrackList)
libweb_js_bindings(HTML/Window)
diff --git a/Services/Compositor/CompositorState.cpp b/Services/Compositor/CompositorState.cpp
index 07a1949e2dc..b8b72b1d5c8 100644
--- a/Services/Compositor/CompositorState.cpp
+++ b/Services/Compositor/CompositorState.cpp
@@ -314,7 +314,7 @@ void CompositorState::on_video_sink_ready(CompositorStateWebContentClient& clien
sink_state->sink = sink;
sink->set_on_present_needed([this, &client, handle] {
if (auto* sink_state = video_sink_state(client, handle); sink_state && sink_state->sink)
- client.video_sink_presented_frame(handle, sink_state->sink->current_frame());
+ client.video_sink_presented_frame(handle, sink_state->sink->current_frame(), sink_state->sink->take_frame_counts());
present_contexts_drawing_video_sink(client, handle);
update_unpainted_video_update_scheduling();
});
@@ -430,6 +430,11 @@ CompositorState::VideoSinkUpdateResult CompositorState::update_all_video_sinks()
auto is_painted = video_sink_is_painted_by_any_context(client_entry.key, sink_entry.key);
sink_state.requires_updates = video_sink_updates_are_needed(sink_state)
&& sink_state.sink->update(now).may_require_updates;
+ Media::DisplayingVideoSinkFrameCounts frame_counts;
+ if (sink_state.sink)
+ frame_counts = sink_state.sink->take_frame_counts();
+ if (!frame_counts.is_zero())
+ client_entry.key->video_sink_counted_frames(sink_entry.key, frame_counts);
if (!is_painted && sink_state.requires_updates)
result = VideoSinkUpdateResult::UnpaintedSinkRequiresUpdates;
}
diff --git a/Services/Compositor/CompositorState.h b/Services/Compositor/CompositorState.h
index 4186d0e44dd..ec60e63606c 100644
--- a/Services/Compositor/CompositorState.h
+++ b/Services/Compositor/CompositorState.h
@@ -30,6 +30,7 @@
#include <LibGfx/Size.h>
#include <LibGfx/SkiaBackendContext.h>
#include <LibMedia/Forward.h>
+#include <LibMedia/Sinks/DisplayingVideoSink.h>
#include <LibMedia/VideoSinkHandle.h>
#include <LibMediaCodecs/VideoFramePool.h>
@@ -64,7 +65,8 @@ public:
virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) = 0;
virtual void create_video_edge(Media::VideoSinkHandle) = 0;
virtual void release_video_edge(Media::VideoSinkHandle) = 0;
- virtual void video_sink_presented_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>) { }
+ virtual void video_sink_presented_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>, Media::DisplayingVideoSinkFrameCounts) { }
+ virtual void video_sink_counted_frames(Media::VideoSinkHandle, Media::DisplayingVideoSinkFrameCounts) { }
virtual void placeholder_canvas_committed(Compositing::CanvasId, Gfx::IntSize, bool origin_clean) = 0;
// The owner of this client's canvases, which are the only ones its contexts may draw.
virtual Compositing::CanvasSurfaceOwnerId canvas_surface_owner_id() const = 0;
diff --git a/Services/Compositor/ConnectionFromWebContent.cpp b/Services/Compositor/ConnectionFromWebContent.cpp
index 28c2181ea04..33526f65a03 100644
--- a/Services/Compositor/ConnectionFromWebContent.cpp
+++ b/Services/Compositor/ConnectionFromWebContent.cpp
@@ -101,9 +101,14 @@ void ConnectionFromWebContent::release_video_frame_hold(Media::VideoSinkHandle v
did_misbehave("WebContent released a video frame hold that it did not take");
}
-void ConnectionFromWebContent::video_sink_presented_frame(Media::VideoSinkHandle video_sink_handle, RefPtr<Media::VideoFrame> frame)
+void ConnectionFromWebContent::video_sink_presented_frame(Media::VideoSinkHandle video_sink_handle, RefPtr<Media::VideoFrame> frame, Media::DisplayingVideoSinkFrameCounts new_frame_counts)
{
- m_video_frame_holds.present_frame(video_sink_handle, move(frame));
+ m_video_frame_holds.present_frame(video_sink_handle, move(frame), new_frame_counts);
+}
+
+void ConnectionFromWebContent::video_sink_counted_frames(Media::VideoSinkHandle video_sink_handle, Media::DisplayingVideoSinkFrameCounts new_frame_counts)
+{
+ m_video_frame_holds.add_frame_counts(video_sink_handle, new_frame_counts);
}
void ConnectionFromWebContent::set_video_sink_ticking(Media::VideoSinkHandle video_sink_handle, bool should_tick)
diff --git a/Services/Compositor/ConnectionFromWebContent.h b/Services/Compositor/ConnectionFromWebContent.h
index 06264812cb4..f0df8d81f38 100644
--- a/Services/Compositor/ConnectionFromWebContent.h
+++ b/Services/Compositor/ConnectionFromWebContent.h
@@ -102,7 +102,8 @@ private:
virtual void async_scroll_updates(Web::CompositorContextId, Compositing::PendingAsyncScrollUpdates const&) override;
virtual void create_video_edge(Media::VideoSinkHandle) override;
virtual void release_video_edge(Media::VideoSinkHandle) override;
- virtual void video_sink_presented_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>) override;
+ virtual void video_sink_presented_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>, Media::DisplayingVideoSinkFrameCounts) override;
+ virtual void video_sink_counted_frames(Media::VideoSinkHandle, Media::DisplayingVideoSinkFrameCounts) override;
virtual void placeholder_canvas_committed(Compositing::CanvasId, Gfx::IntSize, bool origin_clean) override;
virtual Compositing::CanvasSurfaceOwnerId canvas_surface_owner_id() const override { return m_canvas_host.canvas_surface_owner_id(); }
bool context_is_owned_by_this_connection(Web::CompositorContextId);
diff --git a/Services/Compositor/VideoFrameHolds.cpp b/Services/Compositor/VideoFrameHolds.cpp
index 6f66a976a25..7392db5a476 100644
--- a/Services/Compositor/VideoFrameHolds.cpp
+++ b/Services/Compositor/VideoFrameHolds.cpp
@@ -17,7 +17,7 @@ void VideoFrameHolds::add_sink(Media::VideoSinkHandle handle, NonnullRefPtr<Vide
// WebContent may already hold generation 0.
if (auto sink = m_sinks.get(handle); sink.has_value())
retire_current_generation(handle, *sink, VideoFramePresentationPage::retired_generation);
- m_sinks.set(handle, Sink { .page = move(page), .generation = 0, .frame = nullptr });
+ m_sinks.set(handle, Sink { .page = move(page), .generation = 0, .frame = nullptr, .presented_frame = {} });
}
void VideoFrameHolds::remove_sink(Media::VideoSinkHandle handle)
@@ -29,27 +29,48 @@ void VideoFrameHolds::remove_sink(Media::VideoSinkHandle handle)
m_sinks.remove(handle);
}
-void VideoFrameHolds::present_frame(Media::VideoSinkHandle handle, RefPtr<Media::VideoFrame> frame)
+void VideoFrameHolds::present_frame(Media::VideoSinkHandle handle, RefPtr<Media::VideoFrame> frame, Media::DisplayingVideoSinkFrameCounts new_frame_counts)
{
auto sink = m_sinks.get(handle);
- if (!sink.has_value() || sink->frame == frame)
+ if (!sink.has_value())
+ return;
+ if (sink->frame == frame) {
+ add_frame_counts(handle, new_frame_counts);
return;
+ }
auto next_generation = sink->generation + 1;
retire_current_generation(handle, *sink, next_generation);
sink->generation = next_generation;
sink->frame = move(frame);
- Compositing::VideoFramePresentationPage::PresentedFrame presented_frame { .generation = next_generation, .presentation_time = MonotonicTime::now() };
+ auto& presented_frame = sink->presented_frame;
+ presented_frame.generation = next_generation;
+ presented_frame.presentation_time = MonotonicTime::now();
+ presented_frame.media_time = AK::Duration::zero();
+ presented_frame.width = 0;
+ presented_frame.height = 0;
+ presented_frame.presented_frame_count += new_frame_counts.presented;
+ presented_frame.dropped_frame_count += new_frame_counts.dropped;
if (sink->frame) {
- sink->presented_frame_count++;
presented_frame.media_time = sink->frame->timestamp();
presented_frame.width = sink->frame->width();
presented_frame.height = sink->frame->height();
}
- presented_frame.presented_frame_count = sink->presented_frame_count;
sink->page->publish_presented_frame(presented_frame);
}
+void VideoFrameHolds::add_frame_counts(Media::VideoSinkHandle handle, Media::DisplayingVideoSinkFrameCounts new_frame_counts)
+{
+ auto sink = m_sinks.get(handle);
+ if (!sink.has_value())
+ return;
+ if (new_frame_counts.is_zero())
+ return;
+ sink->presented_frame.presented_frame_count += new_frame_counts.presented;
+ sink->presented_frame.dropped_frame_count += new_frame_counts.dropped;
+ sink->page->publish_presented_frame(sink->presented_frame);
+}
+
void VideoFrameHolds::retire_current_generation(Media::VideoSinkHandle handle, Sink& sink, u64 next_generation)
{
auto replaced = sink.page->replace_generation(next_generation);
diff --git a/Services/Compositor/VideoFrameHolds.h b/Services/Compositor/VideoFrameHolds.h
index 43a3d67c2f8..6753fc408e8 100644
--- a/Services/Compositor/VideoFrameHolds.h
+++ b/Services/Compositor/VideoFrameHolds.h
@@ -11,6 +11,7 @@
#include <AK/NonnullRefPtr.h>
#include <AK/RefPtr.h>
#include <LibCompositing/Video/VideoFramePresentationPage.h>
+#include <LibMedia/Sinks/DisplayingVideoSink.h>
#include <LibMedia/VideoSinkHandle.h>
#include <LibMediaCodecs/Forward.h>
@@ -21,7 +22,8 @@ public:
void add_sink(Media::VideoSinkHandle, NonnullRefPtr<Compositing::VideoFramePresentationPage>);
void remove_sink(Media::VideoSinkHandle);
- void present_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>);
+ void present_frame(Media::VideoSinkHandle, RefPtr<Media::VideoFrame>, Media::DisplayingVideoSinkFrameCounts new_frame_counts);
+ void add_frame_counts(Media::VideoSinkHandle, Media::DisplayingVideoSinkFrameCounts new_frame_counts);
ErrorOr<void> release_hold(Media::VideoSinkHandle, u64 generation);
RefPtr<Media::VideoFrame> held_frame(Media::VideoSinkHandle, u64 generation) const;
@@ -31,7 +33,7 @@ private:
NonnullRefPtr<Compositing::VideoFramePresentationPage> page;
u64 generation { 0 };
RefPtr<Media::VideoFrame> frame;
- u64 presented_frame_count { 0 };
+ Compositing::VideoFramePresentationPage::PresentedFrame presented_frame;
};
struct RetainedFrame {
RefPtr<Media::VideoFrame> frame;
diff --git a/Tests/LibMedia/TestDisplayingVideoSink.cpp b/Tests/LibMedia/TestDisplayingVideoSink.cpp
index 74dbdf98fd0..cea00f986d4 100644
--- a/Tests/LibMedia/TestDisplayingVideoSink.cpp
+++ b/Tests/LibMedia/TestDisplayingVideoSink.cpp
@@ -260,6 +260,174 @@ TEST_CASE(seek_past_the_cached_frames_waits_for_the_frame_at_the_target)
EXPECT_EQ(dispatched_statuses, (Vector { Media::PipelineStatus::HaveData }));
}
+TEST_CASE(frames_passed_while_waiting_on_a_late_frame_are_counted_as_dropped)
+{
+ never_destroyed_event_loop();
+
+ auto pool = MUST(Media::VideoFramePool::create());
+ auto clock = MUST(Media::MonotonicMediaClock::try_create());
+ clock->seek(AK::Duration::from_milliseconds(1000));
+
+ auto sink = MUST(Media::DisplayingVideoSink::try_create(clock->time_reader()));
+ auto producer = ScriptedVideoProducer::create();
+ MUST(sink->connect_input(producer));
+
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1000), AK::Duration::from_milliseconds(40)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->take_frame_counts().presented, 1u);
+
+ // Both frames are late, and the second waits for a frame after it to replace it.
+ clock->seek(AK::Duration::from_milliseconds(1200));
+ for (auto timestamp : { 1040, 1080 })
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(timestamp), AK::Duration::from_milliseconds(40)));
+ EXPECT(!sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->current_frame()->timestamp(), AK::Duration::from_milliseconds(1000));
+ auto frame_counts = sink->take_frame_counts();
+ EXPECT_EQ(frame_counts.presented, 0u);
+ EXPECT_EQ(frame_counts.dropped, 1u);
+ EXPECT(sink->take_frame_counts().is_zero());
+}
+
+TEST_CASE(frames_passed_by_an_update_landing_on_time_are_counted_as_presented)
+{
+ never_destroyed_event_loop();
+
+ auto pool = MUST(Media::VideoFramePool::create());
+ auto clock = MUST(Media::MonotonicMediaClock::try_create());
+ clock->seek(AK::Duration::from_milliseconds(1000));
+
+ auto sink = MUST(Media::DisplayingVideoSink::try_create(clock->time_reader()));
+ auto producer = ScriptedVideoProducer::create();
+ MUST(sink->connect_input(producer));
+
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1000), AK::Duration::from_milliseconds(4)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->take_frame_counts().presented, 1u);
+
+ // Updates spaced further apart than the frames make the oldest ones late, but the frame landed on is on time.
+ clock->seek(AK::Duration::from_milliseconds(1016));
+ for (auto timestamp : { 1004, 1008, 1012, 1016 })
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(timestamp), AK::Duration::from_milliseconds(4)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->current_frame()->timestamp(), AK::Duration::from_milliseconds(1016));
+ auto frame_counts = sink->take_frame_counts();
+ EXPECT_EQ(frame_counts.presented, 4u);
+ EXPECT_EQ(frame_counts.dropped, 0u);
+}
+
+TEST_CASE(frames_passed_by_a_seek_within_the_cached_frames_are_not_counted)
+{
+ auto& loop = never_destroyed_event_loop();
+
+ auto pool = MUST(Media::VideoFramePool::create());
+ auto clock = MUST(Media::MonotonicMediaClock::try_create());
+ clock->seek(AK::Duration::from_milliseconds(1000));
+
+ auto sink = MUST(Media::DisplayingVideoSink::try_create(clock->time_reader()));
+ auto producer = ScriptedVideoProducer::create();
+ MUST(sink->connect_input(producer));
+
+ // A long frame followed by a short one, so that a seek within the long one's conservative end lands after the
+ // short one's.
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1000), AK::Duration::from_milliseconds(100)));
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1100), AK::Duration::from_milliseconds(10)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ loop.pump(Core::EventLoop::WaitMode::PollForEvents);
+ EXPECT_EQ(sink->take_frame_counts().presented, 1u);
+
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1110), AK::Duration::from_milliseconds(40)));
+ clock->seek(AK::Duration::from_milliseconds(1120));
+ sink->seek(AK::Duration::from_milliseconds(1120));
+ loop.pump(Core::EventLoop::WaitMode::PollForEvents);
+ EXPECT_EQ(sink->current_frame()->timestamp(), AK::Duration::from_milliseconds(1110));
+ auto frame_counts = sink->take_frame_counts();
+ EXPECT_EQ(frame_counts.presented, 1u);
+ EXPECT_EQ(frame_counts.dropped, 0u);
+}
+
+TEST_CASE(frames_replaced_within_an_update_are_presented_when_the_last_one_is_on_time)
+{
+ never_destroyed_event_loop();
+
+ auto pool = MUST(Media::VideoFramePool::create());
+ auto clock = MUST(Media::MonotonicMediaClock::try_create());
+ clock->seek(AK::Duration::from_milliseconds(1000));
+
+ auto sink = MUST(Media::DisplayingVideoSink::try_create(clock->time_reader()));
+ auto producer = ScriptedVideoProducer::create();
+ MUST(sink->connect_input(producer));
+
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1000), AK::Duration::from_milliseconds(40)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->take_frame_counts().presented, 1u);
+
+ // Both frames are due and neither is late, so the update passes over the first.
+ clock->seek(AK::Duration::from_milliseconds(1090));
+ for (auto timestamp : { 1040, 1080 })
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(timestamp), AK::Duration::from_milliseconds(40)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->current_frame()->timestamp(), AK::Duration::from_milliseconds(1080));
+ auto frame_counts = sink->take_frame_counts();
+ EXPECT_EQ(frame_counts.presented, 2u);
+ EXPECT_EQ(frame_counts.dropped, 0u);
+}
+
+TEST_CASE(frames_passed_for_a_late_frame_ending_the_stream_are_counted_as_presented)
+{
+ never_destroyed_event_loop();
+
+ auto pool = MUST(Media::VideoFramePool::create());
+ auto clock = MUST(Media::MonotonicMediaClock::try_create());
+ clock->seek(AK::Duration::from_milliseconds(1000));
+
+ auto sink = MUST(Media::DisplayingVideoSink::try_create(clock->time_reader()));
+ auto producer = ScriptedVideoProducer::create();
+ MUST(sink->connect_input(producer));
+
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1000), AK::Duration::from_milliseconds(40)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->take_frame_counts().presented, 1u);
+
+ // A long frame that is still on time is replaced by a short one that is already late, but is presented because
+ // the stream ends after it.
+ clock->seek(AK::Duration::from_milliseconds(1150));
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1040), AK::Duration::from_milliseconds(100)));
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1100), AK::Duration::from_milliseconds(10)));
+ producer->append_output(nullptr, Media::PipelineStatus::EndOfStream);
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->current_frame()->timestamp(), AK::Duration::from_milliseconds(1100));
+ auto frame_counts = sink->take_frame_counts();
+ EXPECT_EQ(frame_counts.presented, 2u);
+ EXPECT_EQ(frame_counts.dropped, 0u);
+}
+
+TEST_CASE(frames_out_of_order_with_a_passed_frame_are_not_counted)
+{
+ never_destroyed_event_loop();
+
+ auto pool = MUST(Media::VideoFramePool::create());
+ auto clock = MUST(Media::MonotonicMediaClock::try_create());
+ clock->seek(AK::Duration::from_milliseconds(1000));
+
+ auto sink = MUST(Media::DisplayingVideoSink::try_create(clock->time_reader()));
+ auto producer = ScriptedVideoProducer::create();
+ MUST(sink->connect_input(producer));
+
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(1000), AK::Duration::from_milliseconds(40)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->take_frame_counts().presented, 1u);
+
+ // The frame at 1020 follows the current frame, but precedes the late frame skipped before it.
+ clock->seek(AK::Duration::from_milliseconds(1200));
+ for (auto timestamp : { 1040, 1020, 1180 })
+ producer->append_frame(create_test_frame(*pool, AK::Duration::from_milliseconds(timestamp), AK::Duration::from_milliseconds(40)));
+ EXPECT(sink->update(MonotonicTime::now()).new_frame_available);
+ EXPECT_EQ(sink->current_frame()->timestamp(), AK::Duration::from_milliseconds(1180));
+ auto frame_counts = sink->take_frame_counts();
+ EXPECT_EQ(frame_counts.presented, 2u);
+ EXPECT_EQ(frame_counts.dropped, 0u);
+}
+
// The input reaching its end leaves the last frame on screen until its interval ends, and only an update after that
// can report the end of the stream.
TEST_CASE(updates_are_required_until_the_last_frame_finishes_presenting)
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index b4c8738a058..eab0d9f3ed2 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -95,6 +95,7 @@ Text/input/HTML/HTMLMediaElement-load-overrides-preload-none.html
Text/input/HTML/HTMLMediaElement-preload-none-does-not-fetch.html
Text/input/css/FontFace-arraybuffer-matching.html
Text/input/wpt-import/mediacapture-streams/idlharness.https.window.html
+Text/input/wpt-import/media-playback-quality/idlharness.window.html
Text/input/css/font-face-load-dedups-same-url.html
Text/input/css/font-load-delays-document-load-event.html
Text/input/css/font-face-unused-face-not-fetched.html
diff --git a/Tests/LibWeb/Text/expected/HTML/HTMLVideoElement-getVideoPlaybackQuality.txt b/Tests/LibWeb/Text/expected/HTML/HTMLVideoElement-getVideoPlaybackQuality.txt
new file mode 100644
index 00000000000..2abadb65088
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/HTMLVideoElement-getVideoPlaybackQuality.txt
@@ -0,0 +1,4 @@
+Before loading: VideoPlaybackQuality, total 0, dropped 0, corrupted 0
+After playing: total at least 5: true, dropped within total: true, corrupted 0
+creationTime does not go backwards: true
+After loading again: total 0, dropped 0
diff --git a/Tests/LibWeb/Text/expected/all-window-properties.txt b/Tests/LibWeb/Text/expected/all-window-properties.txt
index c49b83798b2..5aeac8af90a 100644
--- a/Tests/LibWeb/Text/expected/all-window-properties.txt
+++ b/Tests/LibWeb/Text/expected/all-window-properties.txt
@@ -557,6 +557,7 @@ UserActivation
VTTCue
VTTRegion
ValidityState
+VideoPlaybackQuality
VideoTrack
VideoTrackList
ViewTransition
diff --git a/Tests/LibWeb/Text/expected/wpt-import/media-playback-quality/idlharness.window.txt b/Tests/LibWeb/Text/expected/wpt-import/media-playback-quality/idlharness.window.txt
new file mode 100644
index 00000000000..ee5771baf2c
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/media-playback-quality/idlharness.window.txt
@@ -0,0 +1,35 @@
+Harness status: OK
+
+Found 30 tests
+
+30 Pass
+Pass idl_test setup
+Pass idl_test validation
+Pass Partial interface HTMLVideoElement: original interface defined
+Pass Partial interface HTMLVideoElement: member names are unique
+Pass Partial interface Element: member names are unique
+Pass HTMLElement includes GlobalEventHandlers: member names are unique
+Pass HTMLElement includes ElementContentEditable: member names are unique
+Pass HTMLElement includes HTMLOrSVGElement: member names are unique
+Pass Element includes ParentNode: member names are unique
+Pass Element includes NonDocumentTypeChildNode: member names are unique
+Pass Element includes ChildNode: member names are unique
+Pass Element includes Slottable: member names are unique
+Pass VideoPlaybackQuality interface: existence and properties of interface object
+Pass VideoPlaybackQuality interface object length
+Pass VideoPlaybackQuality interface object name
+Pass VideoPlaybackQuality interface: existence and properties of interface prototype object
+Pass VideoPlaybackQuality interface: existence and properties of interface prototype object's "constructor" property
+Pass VideoPlaybackQuality interface: existence and properties of interface prototype object's @@unscopables property
+Pass VideoPlaybackQuality interface: attribute creationTime
+Pass VideoPlaybackQuality interface: attribute droppedVideoFrames
+Pass VideoPlaybackQuality interface: attribute totalVideoFrames
+Pass VideoPlaybackQuality interface: attribute corruptedVideoFrames
+Pass VideoPlaybackQuality must be primary interface of videoPlaybackQuality
+Pass Stringification of videoPlaybackQuality
+Pass VideoPlaybackQuality interface: videoPlaybackQuality must inherit property "creationTime" with the proper type
+Pass VideoPlaybackQuality interface: videoPlaybackQuality must inherit property "droppedVideoFrames" with the proper type
+Pass VideoPlaybackQuality interface: videoPlaybackQuality must inherit property "totalVideoFrames" with the proper type
+Pass VideoPlaybackQuality interface: videoPlaybackQuality must inherit property "corruptedVideoFrames" with the proper type
+Pass HTMLVideoElement interface: operation getVideoPlaybackQuality()
+Pass HTMLVideoElement interface: video must inherit property "getVideoPlaybackQuality()" with the proper type
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/HTML/HTMLVideoElement-getVideoPlaybackQuality.html b/Tests/LibWeb/Text/input/HTML/HTMLVideoElement-getVideoPlaybackQuality.html
new file mode 100644
index 00000000000..4ad0716e93c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/HTMLVideoElement-getVideoPlaybackQuality.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ promiseTest(async () => {
+ internals.setAutoplayPolicy("allow-audio-and-video");
+ const video = document.createElement("video");
+ video.muted = true;
+ document.body.append(video);
+
+ const initial = video.getVideoPlaybackQuality();
+ println(`Before loading: ${initial.constructor.name}, total ${initial.totalVideoFrames}, dropped ${initial.droppedVideoFrames}, corrupted ${initial.corruptedVideoFrames}`);
+
+ video.src = "../../../Assets/red-with-second-in-gray-64x36.webm";
+ if (video.readyState < HTMLMediaElement.HAVE_CURRENT_DATA)
+ await new Promise(resolve => video.addEventListener("loadeddata", resolve, { once: true }));
+ await video.play();
+ await new Promise(resolve => {
+ const waitForFrames = () => {
+ if (video.getVideoPlaybackQuality().totalVideoFrames >= 5)
+ resolve();
+ else
+ video.requestVideoFrameCallback(waitForFrames);
+ };
+ waitForFrames();
+ });
+ video.pause();
+
+ const played = video.getVideoPlaybackQuality();
+ println(`After playing: total at least 5: ${played.totalVideoFrames >= 5}, dropped within total: ${played.droppedVideoFrames <= played.totalVideoFrames}, corrupted ${played.corruptedVideoFrames}`);
+ println(`creationTime does not go backwards: ${played.creationTime >= initial.creationTime}`);
+
+ // Setting src runs the media element load algorithm, which resets the counts.
+ video.src = "../../../Assets/blue-with-second-in-gray-64x36.webm";
+ const reloaded = video.getVideoPlaybackQuality();
+ println(`After loading again: total ${reloaded.totalVideoFrames}, dropped ${reloaded.droppedVideoFrames}`);
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/interfaces/media-playback-quality.idl b/Tests/LibWeb/Text/input/wpt-import/interfaces/media-playback-quality.idl
new file mode 100644
index 00000000000..f73d8dbd598
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/interfaces/media-playback-quality.idl
@@ -0,0 +1,18 @@
+// GENERATED CONTENT - DO NOT EDIT
+// Content was automatically extracted by Reffy into webref
+// (https://github.com/w3c/webref)
+// Source: Media Playback Quality (https://w3c.github.io/media-playback-quality/)
+
+partial interface HTMLVideoElement {
+ VideoPlaybackQuality getVideoPlaybackQuality();
+};
+
+[Exposed=Window]
+interface VideoPlaybackQuality {
+ readonly attribute DOMHighResTimeStamp creationTime;
+ readonly attribute unsigned long droppedVideoFrames;
+ readonly attribute unsigned long totalVideoFrames;
+
+ // Deprecated!
+ readonly attribute unsigned long corruptedVideoFrames;
+};
diff --git a/Tests/LibWeb/Text/input/wpt-import/media-playback-quality/idlharness.window.html b/Tests/LibWeb/Text/input/wpt-import/media-playback-quality/idlharness.window.html
new file mode 100644
index 00000000000..e44c18d439d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/media-playback-quality/idlharness.window.html
@@ -0,0 +1,9 @@
+<!doctype html>
+<meta charset=utf-8>
+
+<script src="../resources/testharness.js"></script>
+<script src="../resources/testharnessreport.js"></script>
+<script src="../resources/WebIDLParser.js"></script>
+<script src="../resources/idlharness.js"></script>
+<div id=log></div>
+<script src="../media-playback-quality/idlharness.window.js"></script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/media-playback-quality/idlharness.window.js b/Tests/LibWeb/Text/input/wpt-import/media-playback-quality/idlharness.window.js
new file mode 100644
index 00000000000..2444e30c704
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/media-playback-quality/idlharness.window.js
@@ -0,0 +1,20 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+
+// https://w3c.github.io/media-playback-quality/
+
+'use strict';
+
+idl_test(
+ ['media-playback-quality'],
+ ['html', 'dom'],
+ idl_array => {
+ idl_array.add_objects({
+ HTMLVideoElement: ['video'],
+ VideoPlaybackQuality: ['videoPlaybackQuality']
+ });
+
+ self.video = document.createElement('video');
+ self.videoPlaybackQuality = video.getVideoPlaybackQuality();
+ }
+);