S027: isTypeSupported registry check, endOfStream error reaches the media element, WPT runner fixes, tools rows, hand-over

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-12 16:44:13 -06:00
commit ec251a8209
8 changed files with 206 additions and 8 deletions

View file

@ -72,8 +72,9 @@ Never modify: `~/Documents/Apps/Nacre` (the original Python Nacre, reference onl
| `tools/smoke.sh tests/smoke/settings.txt` (+ `SMOKE_SIZE=1280x1100`) | every settings section and sub-page dark and light, search results (`nacre://settings/?search=…`), narrow width; `settings-write.txt` (hidden, `SMOKE_SIZE=1280x1100`, fresh outdir) taps controls with selftest `tap x y`, then check `home/.config/nacre-servo/Default/settings.json` (expected values in its header) | now (S019) |
| `SMOKE_SIZE=1280x1600 tools/smoke.sh tests/smoke/sliders.txt` | controls hold still (R1-21): Interface size drag (value label while held, applied on release), Contrast live, Style chip pick; `SMOKE_VISIBLE=1 tools/smoke.sh tests/smoke/sliders-visible.txt` the same plus scrolling for the user's window (~772 px). Selftest `press`/`drag`/`release`, `scroll x y dy`; read the PNGs | now (R1-21) |
| `python3 tests/smoke/net/server.py &` + `tools/smoke.sh tests/smoke/net-{privacy,adblock,downloads}.txt` | network pass, offline: secure DNS through a local DoH stub (`*.nacre.test` → 127.0.0.1), HTTPS-only + certificate warning, tracking params, ad blocker with a local list, downloads + download manager stubs; the server's `/log` has requests, DNS names, Range headers, manager calls. `cache-restart.txt` with `SMOKE_HOME=<cache.txt outdir>/home`: disk cache. `net-real.txt` needs internet. `@HOME@` in scripts = the throwaway home | now (S007) |
| `tools/smoke.sh tests/smoke/mse.txt` | MSE: MediaSource + one SourceBuffer plays chunk-appended fMP4 and WebM (offline); passes only on a build with the MSE patches (branch `s022-mse-proto`, see docs/engine/mse-spike.md) | S022 prototype |
| `SMOKE_TIMEOUT=400 tools/smoke.sh tests/smoke/mse.txt` + `tests/smoke/mse-leak-check.sh <outdir>` | MSE: chunk-appended fMP4, WebM and split A/V play; `mse-spec.html` spec cases (attach/detach, duration, buffered/seekable, remove, removeSourceBuffer, changeType, abort, reopen, sequence, leak); the leak check reads nacre.log (offline). `NACRE_DOM_MEDIA_SOURCE_ENABLED=0 tools/smoke.sh tests/smoke/mse-off.txt`: the switch. Branch `s022-mse-proto` only (docs/engine/mse-spike.md) | S022, S027 |
| `tools/gst-mse.sh [test]` | builds Nacre's patched gst_mse library and `mse` plugin (vendor/gst-mse) into `target/gst-mse/` (needed before running a build that uses MSE); `test` also runs the C tests in `tests/gst-mse/` | now (S026, branch s022-mse-proto) |
| `tools/wpt-mse.sh [outdir] [file ...]` | WPT media-source subset (60 files) in a hidden run; first run sparse-clones WPT at a pinned commit into `target/wpt` (needs internet once); prints subtest pass counts, results in `<outdir>/wpt/results.json`; ~45 min | S027 |
| `python tools/icons.py` | rebuilds the icon font subset and `src/ui/icons.rs` from `tools/icons.txt` (needs fontTools and Arch's ttf-material-symbols-variable) | now (S015) |
| appimagetool, wine + Inno Setup, VM "Windows 10" | packaging and Windows checks | see the user's global CLAUDE.md "Building" |

40
docs/S027-handoff.md Normal file
View file

@ -0,0 +1,40 @@
# S027 hand-over (MSE DOM to spec) — 2026-11-12
Branch `s022-mse-proto`, worktree ~/Projects/Nacre-s022 (own target/). Plan: Plans/05 Engine/S027-mse-dom-spec.md (on main).
## Done (committed on the branch)
- DOM rewrite: vendor/servo-script/dom/media/{mediasource,sourcebuffer,sourcebufferlist}.rs. DOM owns spec state; all events
queued as media element tasks; attach/detach (htmlmediaelement.rs step 7.3, resource_fetch_algorithm), duration change
(element duration from the MediaSource), HTMLMediaElement.buffered/seekable from MediaSource (pure fns + 5 tests in
vendor/servo-media-player/mse.rs), activeSourceBuffers from gst active list, removeSourceBuffer, abort, changeType (same
container only), sequence mode, live seekable range, endOfStream(error) -> element error steps.
- Object URLs: per-global map GlobalScope::media_source_urls, revoke removes one task later, cleared on unload.
- Weak event sink: thread-local id -> WeakRef<MediaSource> (MediaSource weakReferenceable). Debug counter: nacre.log
"MSE: MediaSource <id> created/freed".
- Pref: [Func="MediaSource::enabled"] reads NACRE_DOM_MEDIA_SOURCE_ENABLED (D-017 on main explains why not servo-config).
- isTypeSupported: servo_media_player::mse::is_type_well_formed (registry rules) before gst + decoder check.
- gst_mse patches 5-9 (vendor/gst-mse, nacre.patch regenerated, docs/engine/gst-mse-patches.md): remove() real, abort()
resets parser, reset drops old appsinks (crash), track_feeds keyed by id, appendWindowStart check inverted.
C tests tests/gst-mse/mse-fixes.c 5/5 (tools/gst-mse.sh test).
- Smoke: tests/smoke/mse.txt (+ pages/mse-spec.html, 11 cases) green; tests/smoke/mse-leak-check.sh ok (MS freed in run);
tests/smoke/mse-off.txt green with NACRE_DOM_MEDIA_SOURCE_ENABLED=0. Run mse.txt with SMOKE_TIMEOUT=400.
- WPT runner: tools/wpt-mse.sh (+ tests/wpt-mse/), pinned WPT in target/wpt.
## WPT
- Run 1 (before validator/endOfStream error): 246/407 subtests in 60 files.
- Run 2 (current build) was running at hand-over; output: /tmp/claude-1000/-home-astar76-Projects-Nacre/9e6752f4-4824-467b-b5b7-80b90b1ca98b/scratchpad/wpt4.out, results /tmp/claude-1000/-home-astar76-Projects-Nacre/9e6752f4-4824-467b-b5b7-80b90b1ca98b/scratchpad/wpt4/wpt/results.json.
If gone, rerun: tools/wpt-mse.sh (~45 min). Target in plan: >= 293.
## Not done / next steps
1. Get run-2 count; record in PROGRESS (main). Tick plan box 7 (smoke) and 8 (PROGRESS, INDEX, push) + tracker S027.
2. Biggest remaining WPT gaps are player integration (S028): loadedmetadata/HAVE_METADATA after init segment only
(duration-boundaryconditions 0/13 time out, play/seek tests 0/1), changetype across containers (gst can't, 1/19 x3),
errors before init segment, buffered after removeSourceBuffer should throw ([Throws] attr), same TimeRanges object.
3. Opus/fLaC in mp4 unsupported (gst/decoder), 4 WPT subtests.
## Gotchas
- weakReferenceable structs can't impl Drop (codegen does); counter lives in a LiveCount field.
- Servo runs no FinalizationRegistry callbacks / WeakRef clearing: leak check must use the log.
- WPT tests call alert() on 404s: tests/wpt-mse/testharnessreport.js stubs it; WPT media/ dir needed.
- After abort/changeType the next append must start with an init segment (gst reset forgets it).
- Negative timestampOffset clamps to 0 (GstClockTime).

View file

@ -1,6 +1,7 @@
// Nacre's WPT report hook (tools/wpt-mse.sh): replaces resources/testharnessreport.js and keeps the results on
// window.__wpt for the driver page (tests/wpt-mse/driver.html), which runs each test in an iframe.
setup({ explicit_timeout: true });
// A test's alert() would block the driver; log it instead.
window.alert = function (message) { console.log('alert: ' + message); };
add_completion_callback(function (tests, status) {
window.__wpt = {
done: true,

View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash
# Runs a subset of WPT media-source/ in Nacre and prints pass counts (S027). Offline after the first run.
# - fetches web-platform-tests at $WPT_REV (sparse: media-source, resources, common) into target/wpt once
# - fetches web-platform-tests at $WPT_REV (sparse: media-source, media, resources, common) into target/wpt once
# - serves it on 127.0.0.1:$WPT_PORT (tests/wpt-mse/server.py) with our testharnessreport.js
# - runs tests/wpt-mse/driver.html in a hidden smoke run (tools/smoke.sh): every test in an iframe, $WPT_TIMEOUT s each
# - writes <outdir>/wpt/results.json and prints per-file and total subtest pass counts
@ -17,9 +17,9 @@ out=${1:-$root/target/smoke/wpt-mse-$(date +%H%M%S)}
shift || true
mkdir -p "$out/wpt"
if [ ! -d "$wpt/media-source" ]; then
git clone --filter=blob:none --no-checkout https://github.com/web-platform-tests/wpt.git "$wpt"
git -C "$wpt" sparse-checkout set media-source resources common
if [ ! -d "$wpt/media" ]; then
[ -d "$wpt/.git" ] || git clone --filter=blob:none --no-checkout https://github.com/web-platform-tests/wpt.git "$wpt"
git -C "$wpt" sparse-checkout set media-source media resources common
git -C "$wpt" fetch --depth 1 origin "$rev"
git -C "$wpt" checkout -q "$rev"
fi
@ -37,7 +37,7 @@ server=$!
trap 'kill $server 2>/dev/null' EXIT
rm -f "$out/wpt/results.json"
timeout_each=${WPT_TIMEOUT:-40}
timeout_each=${WPT_TIMEOUT:-75}
cat >"$out/wpt/wpt.txt" <<SCRIPT
# Generated by tools/wpt-mse.sh
wait 2

View file

@ -294,7 +294,8 @@ impl Backend for GStreamerBackend {
fn is_media_source_type_supported(&self, mime: &str) -> bool {
// gst_mse only checks that it can parse the type; a decoder must exist too, or a page
// picks a codec (YouTube: AV1 without dav1d) that never shows a picture.
mse::GStreamerMediaSource::is_type_supported(mime) &&
servo_media_player::mse::is_type_well_formed(mime) &&
mse::GStreamerMediaSource::is_type_supported(mime) &&
self.can_play_type(mime) != SupportsMediaType::No
}

View file

@ -166,6 +166,96 @@ pub fn media_source_seekable(
}
}
/// Whether `mime` is a well-formed MSE type that names its codecs the way the byte stream format
/// registry wants (<https://www.w3.org/TR/mse-byte-stream-format-registry/>): WebM and MP4 need a
/// `codecs` parameter whose codecs fit the container (no video codec in an `audio/` type), MPEG
/// audio and ADTS take none, and unknown parameters are refused (players' capability hints such
/// as `width` or `framerate` are allowed). Whether the backend can decode them is checked apart.
pub fn is_type_well_formed(mime: &str) -> bool {
let mut parts = mime.split(';');
let essence = parts.next().unwrap_or("").trim().to_ascii_lowercase();
let mut codecs = None;
for param in parts {
let Some((name, value)) = param.split_once('=') else {
return false;
};
let name = name.trim().to_ascii_lowercase();
let value = value.trim().trim_matches('"').trim();
if value.is_empty() {
return false;
}
match name.as_str() {
"codecs" => codecs = Some(value.to_owned()),
"width" | "height" | "framerate" | "bitrate" | "channels" | "samplerate" | "eotf" |
"features" | "decode-to-texture" | "experimental" => {},
_ => return false,
}
}
let Some((kind, container)) = essence.split_once('/') else {
return false;
};
let audio_only = match kind {
"audio" => true,
"video" => false,
_ => return false,
};
match container {
"mpeg" | "aac" if audio_only => return codecs.is_none(),
"webm" | "mp4" => {},
_ => return false,
}
let Some(codecs) = codecs else {
return false;
};
codecs.split(',').map(str::trim).all(|codec| {
match codec_kind(container, codec) {
Some(CodecKind::Audio) => true,
Some(CodecKind::Video) => !audio_only,
None => false,
}
})
}
enum CodecKind {
Audio,
Video,
}
fn codec_kind(container: &str, codec: &str) -> Option<CodecKind> {
let lower = codec.to_ascii_lowercase();
let dotted = |prefix: &str| lower.strip_prefix(prefix).is_some_and(|rest| rest.len() > 1);
let audio = matches!(lower.as_str(), "opus" | "vorbis" | "flac" | "ac-3" | "ec-3");
if container == "webm" {
return if matches!(lower.as_str(), "opus" | "vorbis") {
Some(CodecKind::Audio)
} else if matches!(lower.as_str(), "vp8" | "vp9") || dotted("vp09.") || dotted("av01.") {
Some(CodecKind::Video)
} else {
None
};
}
if audio && lower != "vorbis" {
return Some(CodecKind::Audio);
}
if let Some(rest) = lower.strip_prefix("mp4a.") {
// mp4a.40.<audio object type>, or an MPEG object type alone (mp4a.69, mp4a.6b, mp4a.67).
let valid = match rest.split_once('.') {
Some(("40", object_type)) => {
!object_type.is_empty() && object_type.bytes().all(|b| b.is_ascii_digit())
},
Some(_) => false,
None => matches!(rest, "69" | "6b" | "67" | "66" | "68"),
};
return valid.then_some(CodecKind::Audio);
}
if dotted("avc1.") || dotted("avc3.") || dotted("hev1.") || dotted("hvc1.") ||
dotted("av01.") || dotted("vp09.")
{
return Some(CodecKind::Video);
}
None
}
#[cfg(test)]
mod tests {
use super::*;
@ -207,4 +297,41 @@ mod tests {
vec![1.0..8.0]
);
}
#[test]
fn well_formed_types() {
for good in [
r#"video/webm; codecs="vp9""#,
r#"video/webm; codecs="vp09.00.10.08, opus""#,
r#"audio/webm;codecs="vorbis""#,
r#"video/mp4; codecs="avc1.4d401f, mp4a.40.2""#,
r#"audio/mp4; codecs="mp4a.40.2""#,
r#"video/mp4;codecs="Opus""#,
r#"audio/mp4;codecs="fLaC""#,
r#"video/mp4; codecs="av01.0.05M.08"; width=1920; height=1080; framerate=30"#,
"audio/mpeg",
"audio/aac",
] {
assert!(is_type_well_formed(good), "{good}");
}
for bad in [
"video/webm",
"video/webm;",
"video/webm;codecs",
"video/webm;codecs=",
r#"audio/webm;aaacodecsbbb=opus"#,
r#"audio/webm;codecs="vp8""#,
r#"audio/mp4;codecs="avc1.4d001e""#,
r#"video/webm;codecs="mp4a.40.2""#,
r#"video/mp4;codecs="vp8""#,
r#"audio/mpeg;codecs="mp3""#,
r#"audio/mp4;codecs="mp4a""#,
r#"audio/mp4;codecs="mp4a.40""#,
r#"audio/mp4;codecs="mp4a.40.""#,
r#"audio/mp4;codecs="mp4a.67.3""#,
"text/plain",
] {
assert!(!is_type_well_formed(bad), "{bad}");
}
}
}

View file

@ -3049,6 +3049,18 @@ impl HTMLMediaElement {
self.set_duration_and_notify(duration);
}
/// <https://w3c.github.io/media-source/#end-of-stream-algorithm> with an error: before any
/// metadata the dedicated media source failure steps, after it the network error or
/// "media data is corrupted" steps.
pub(crate) fn media_source_ended_with_error(&self, cx: &mut JSContext, decode: bool) {
if self.ready_state.get() == ReadyState::HaveNothing {
self.queue_dedicated_media_source_failure_steps();
} else {
let error = if decode { MEDIA_ERR_DECODE } else { MEDIA_ERR_NETWORK };
self.media_data_processing_fatal_steps(error, cx);
}
}
/// <https://w3c.github.io/media-source/#duration-change-algorithm>, the media element's part.
pub(crate) fn media_source_duration_changed(&self, duration: f64) {
self.set_duration_and_notify(duration);

View file

@ -32,6 +32,7 @@ use crate::dom::bindings::codegen::Bindings::MediaSourceBinding::{
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
use crate::dom::bindings::refcounted::Trusted;
use crate::dom::bindings::reflector::DomGlobal;
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
use crate::dom::bindings::str::DOMString;
@ -342,6 +343,21 @@ impl MediaSource {
warn!("MediaSource duration at end of stream: {error:?}");
}
}
// With an error, the media element runs its error steps (in a task: this may run inside a
// DOM method without a JSContext).
if let Some(error) = error &&
error != BackendEndOfStreamError::None &&
let Some(element) = self.media_element.get()
{
let element = Trusted::new(&*element);
let decode = error == BackendEndOfStreamError::Decode;
self.global()
.task_manager()
.media_element_task_source()
.queue(task!(media_source_error: move |cx| {
element.root().media_source_ended_with_error(cx, decode);
}));
}
// gst_mse may still be ended itself (reopened only in our state, by a removal); then
// there is nothing to tell it.
if self.backend.ready_state() == BackendReadyState::Open &&