oficina / meet Public

Calls: the browser gate caps a downlink and watches the levels go down and back up (spec 15.30)

lowbandwidth caps B's incoming video with a token bucket in an encoded
transform and prints the levels each second; audioonly drives the Video
quality picker. Keyframe requests and time frozen count as trouble too:
on the gate's thin link the picture was mostly stuck between a few
freezes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 8c401babf7533c1470215aa9540734e6942f2576 parent 97be428
4 files changed, +339 −10
  • internal/calls/static/room.js +61 −7
  • internal/callstest/browser_test.go +2 −0
  • test/browser/call.mjs +263 −0
  • test/browser/room-adapt.test.mjs +13 −3
diff --git a/internal/calls/static/room.js b/internal/calls/static/room.js
index 1c58cbe..71552e4 100644
--- a/internal/calls/static/room.js
+++ b/internal/calls/static/room.js
@@ -414,6 +414,8 @@
const ADAPT_DOWN_JITTER_BUFFER = 500; // ms, the audio jitter buffer's mean delay
const ADAPT_DOWN_DROPPED = 0.25; // frames dropped, of decoded and dropped, at least ADAPT_DOWN_DROPPED_MIN
const ADAPT_DOWN_DROPPED_MIN = 10;
+ const ADAPT_DOWN_FREEZE_SECONDS = 2; // seconds frozen in the window: a picture stuck a fifth of the time
+ const ADAPT_DOWN_KEYFRAME_ASKS = 3; // keyframes this side asked the camera for (PLI, FIR) in the window
const ADAPT_SEVERE_FREEZES = 5;
const ADAPT_SEVERE_FREEZE_SECONDS = 4; // seconds frozen in the window
const ADAPT_SEVERE_LOSS = 0.15;
@@ -4639,7 +4641,12 @@
// buffer, and frames decoded and dropped. Null when nothing at all
// arrived and nothing was measured: a connection that is down is
// §15.28's to mend, and says nothing about the link's width.
- function adaptSample(q, cameraWatched) {
+ //
+ // `keyframeAsks` is the PLIs and FIRs this side sent for their camera in
+ // the second: a decoder that keeps losing its picture asks for a new one,
+ // and on a thin link that, not a freeze, can be all there is to see — a
+ // picture at five frames a second, every one a keyframe.
+ function adaptSample(q, cameraWatched, keyframeAsks) {
const inb = (q && q.in) || {};
const a = inb.audio || {};
const v = inb.video || {};
@@ -4651,6 +4658,7 @@
return {
freezes: cameraWatched ? v.freezes || 0 : 0,
freezeSeconds: cameraWatched ? v.freezeSeconds || 0 : 0,
+ keyframeAsks: cameraWatched ? keyframeAsks || 0 : 0,
packets,
lost,
rtt,
@@ -4664,12 +4672,13 @@
// round trip as their median (one spike is not a slow link), the jitter
// buffer as their mean.
function adaptWindow(samples) {
- const w = { freezes: 0, freezeSeconds: 0, packets: 0, lost: 0, decoded: 0, dropped: 0, rtt: null, jitterBuffer: null };
+ const w = { freezes: 0, freezeSeconds: 0, keyframeAsks: 0, packets: 0, lost: 0, decoded: 0, dropped: 0, rtt: null, jitterBuffer: null };
const rtts = [];
const jbs = [];
for (const x of samples) {
w.freezes += x.freezes;
w.freezeSeconds += x.freezeSeconds;
+ w.keyframeAsks += x.keyframeAsks || 0;
w.packets += x.packets;
w.lost += x.lost;
w.decoded += x.decoded;
@@ -4692,7 +4701,8 @@
w.loss > ADAPT_SEVERE_LOSS) {
return 'severe';
}
- if (w.freezes >= ADAPT_DOWN_FREEZES || w.loss > ADAPT_DOWN_LOSS ||
+ if (w.freezes >= ADAPT_DOWN_FREEZES || w.freezeSeconds >= ADAPT_DOWN_FREEZE_SECONDS || w.loss > ADAPT_DOWN_LOSS ||
+ w.keyframeAsks >= ADAPT_DOWN_KEYFRAME_ASKS ||
(w.rtt !== null && w.rtt >= ADAPT_DOWN_RTT && w.freezes >= 1) ||
(w.jitterBuffer !== null && w.jitterBuffer >= ADAPT_DOWN_JITTER_BUFFER) ||
(w.dropped >= ADAPT_DOWN_DROPPED_MIN && w.dropped >= ADAPT_DOWN_DROPPED * (w.decoded + w.dropped))) {
@@ -4704,7 +4714,7 @@
// adaptClean is whether one second was clean, for the slow way up.
function adaptClean(x) {
const n = x.packets + x.lost;
- return x.freezes === 0 && x.freezeSeconds === 0 && (n === 0 || x.lost / n <= ADAPT_CLEAN_LOSS) &&
+ return x.freezes === 0 && x.freezeSeconds === 0 && !x.keyframeAsks && (n === 0 || x.lost / n <= ADAPT_CLEAN_LOSS) &&
(x.rtt === null || x.rtt < ADAPT_CLEAN_RTT) &&
(x.jitterBufferMs === null || x.jitterBufferMs < ADAPT_CLEAN_JITTER_BUFFER);
}
@@ -4871,9 +4881,10 @@
function adaptLook(id, entry, stats, now) {
const reading = qualityReading(stats, (r) => qualityKind(id, entry, r));
const prev = entry.adaptReading;
- entry.adaptReading = { pc: entry.pc, reading, at: now };
+ entry.adaptReading = { pc: entry.pc, reading, at: now, stats };
if (!prev || prev.pc !== entry.pc || now <= prev.at) return;
const q = qualityPeer(prev.reading, reading, (now - prev.at) / 1000);
+ const asks = keyframeAsksFor(id, entry, prev.stats, stats);
const media = remoteMedia.get(id) || null;
const watched = !(media && media.cameraOff) && !(typeof document !== 'undefined' && document.hidden);
let rec = adapt.get(id);
@@ -4882,13 +4893,33 @@
adapt.set(id, rec);
}
const before = rec.level;
- adaptStep(rec, now, adaptSample(q, watched));
+ adaptStep(rec, now, adaptSample(q, watched, asks));
if (rec.level !== before) {
console.info('calls: video from ' + id.slice(0, 6) + ' ' + ADAPT_LEVELS[before] + ' -> ' +
ADAPT_LEVELS[rec.level] + (rec.level < before ? ' (probe)' : ''));
}
}
+ // keyframeAsksFor is the PLIs and FIRs this side sent for one peer's
+ // camera between two stats walks, by report id (a new stream counts from
+ // nothing); the screen is not counted.
+ function keyframeAsksFor(id, entry, before, after) {
+ const count = (stats) => {
+ const out = new Map();
+ if (!stats || typeof stats.forEach !== 'function') return out;
+ stats.forEach((r) => {
+ if (r.type === 'inbound-rtp' && r.kind === 'video' && frameKey(id, entry, r.mid || '') === id) {
+ out.set(r.id, (r.pliCount || 0) + (r.firCount || 0));
+ }
+ });
+ return out;
+ };
+ const was = count(before);
+ let n = 0;
+ for (const [key, x] of count(after)) n += Math.max(0, x - (was.get(key) || 0));
+ return n;
+ }
+
// answerAdapt runs after each stats walk: the asks this tab makes, sent
// when they change; the tiles' badges; and the seconds at each level,
// asked and sent, for the next quality report.
@@ -4952,6 +4983,28 @@
for (const id of pcs.keys()) markAdapt(id);
}
+ // adaptWire is, for the gate, what one connection's last stats walk says
+ // is on the wire: our camera going out to them (its size, rate, bytes and
+ // whether the encoding is active) and their audio arriving here.
+ function adaptWire(id, entry) {
+ const out = { cameraHeight: 0, cameraFps: 0, cameraBytes: 0, audioPackets: 0, videoFreezes: 0 };
+ const stats = entry.statsReport;
+ if (!stats || typeof stats.forEach !== 'function') return out;
+ stats.forEach((r) => {
+ if (r.type === 'outbound-rtp' && r.kind === 'video' && !(entry.shareTx && entry.shareTx.mid && r.mid === entry.shareTx.mid)) {
+ out.cameraHeight = r.frameHeight || 0;
+ out.cameraFps = r.framesPerSecond || 0;
+ out.cameraBytes += r.bytesSent || 0;
+ if (typeof r.active === 'boolean') out.cameraActive = r.active;
+ } else if (r.type === 'inbound-rtp' && r.kind === 'audio') {
+ out.audioPackets += r.packetsReceived || 0;
+ } else if (r.type === 'inbound-rtp' && r.kind === 'video' && qualityKind(id, entry, r) === 'video') {
+ out.videoFreezes += r.freezeCount || 0;
+ }
+ });
+ return out;
+ }
+
// showAdaptNotice puts the sender's notice up for ADAPT_NOTICE_FOR, once
// per change, and says it to a screen reader politely.
function showAdaptNotice(words) {
@@ -9322,7 +9375,8 @@
const e = pcs.get(id);
return [id, { level: r ? ADAPT_LEVELS[r.level] : 'normal', asked: videoAsks[id] || 'normal',
sent: ADAPT_LEVELS[(e && e.sentLevel) || 0], downs: r ? r.downs : 0, ups: r ? r.ups : 0,
- upWait: r ? r.upWait : adaptUpAfter, cameraPaused: !!(e && e.cameraPaused) }];
+ upWait: r ? r.upWait : adaptUpAfter, cameraPaused: !!(e && e.cameraPaused),
+ wire: e ? adaptWire(id, e) : null, last: r && r.samples.length ? r.samples[r.samples.length - 1] : null }];
})),
videoAsks: Object.assign({}, videoAsks),
videoSetting: videoSetting(),
diff --git a/internal/callstest/browser_test.go b/internal/callstest/browser_test.go
index 65293df..93f5b7c 100644
--- a/internal/callstest/browser_test.go
+++ b/internal/callstest/browser_test.go
@@ -130,6 +130,8 @@ var scenarios = []string{
"autoplay",
"connecting",
"quality",
+ "lowbandwidth",
+ "audioonly",
"selfview",
"selfviewwebkit",
"scriptless",
diff --git a/test/browser/call.mjs b/test/browser/call.mjs
index f40e349..0f61ab2 100644
--- a/test/browser/call.mjs
+++ b/test/browser/call.mjs
@@ -340,6 +340,58 @@ const consoleLines = new Map(); // label -> string[]
// `via` is the browser to open the context in, for the one scenario
// (autoplay) that needs a Chromium launched under a different policy.
+// downlinkCap is §15.30's thin link, for the lowbandwidth scenario: every
+// video receiver this page makes gets an encoded transform whose worker
+// passes a frame only while a token bucket of `kbit/s` (1.5 s of burst)
+// has room for it, and drops it otherwise — before the decoder, as a link
+// that cannot carry the picture loses it. window.__capDownlink(kbps) sets
+// the cap (0 lifts it) and answers how many receivers are behind it. The
+// gate's, never the page's: the worker comes from a blob, which the
+// page's own CSP refuses unless the context bypasses it.
+function downlinkCap() {
+ if (typeof RTCRtpScriptTransform === 'undefined') return;
+ const Native = window.RTCPeerConnection;
+ let worker = null;
+ let receivers = 0;
+ const work = () => {
+ if (!worker) {
+ const code = [
+ 'let cap = 0, tokens = 0, last = 0;',
+ 'onmessage = (m) => { cap = m.data.cap || 0; tokens = cap * 125 * 1.5; last = performance.now(); };',
+ 'onrtctransform = (e) => {',
+ ' e.transformer.readable.pipeThrough(new TransformStream({ transform(f, c) {',
+ ' if (!cap) { c.enqueue(f); return; }',
+ ' const now = performance.now();',
+ ' tokens = Math.min(cap * 125 * 1.5, tokens + (now - last) / 1000 * cap * 125);',
+ ' last = now;',
+ ' if (tokens >= f.data.byteLength) { tokens -= f.data.byteLength; c.enqueue(f); }',
+ ' } })).pipeTo(e.transformer.writable);',
+ '};',
+ ].join('\n');
+ worker = new Worker(URL.createObjectURL(new Blob([code], { type: 'text/javascript' })));
+ }
+ return worker;
+ };
+ window.__capDownlink = (kbps) => {
+ work().postMessage({ cap: Number(kbps) || 0 });
+ return receivers;
+ };
+ window.RTCPeerConnection = class extends Native {
+ constructor(...args) {
+ super(...args);
+ this.addEventListener('track', (ev) => {
+ if (!ev.receiver || ev.track.kind !== 'video') return;
+ try {
+ ev.receiver.transform = new RTCRtpScriptTransform(work(), {});
+ receivers += 1;
+ } catch {
+ // A receiver that has started already: not behind the cap.
+ }
+ });
+ }
+ };
+}
+
async function newContext(label, { cookie = null, javaScriptEnabled = true, via = browser, options = {} } = {}) {
const ctx = await via.newContext({ javaScriptEnabled, ...options });
if (cookie) {
@@ -6562,6 +6614,217 @@ const run = {
await ctxB.close();
},
+ // Spec §15.30: adaptive video. B's downlink is capped — every video
+ // frame arriving at B passes a token bucket in an encoded transform, so
+ // what does not fit the cap is dropped before B's decoder, which is what
+ // a thin link does to a picture — and B's watch has to ask A for less,
+ // A has to send less, B's tile has to say so, and audio has to keep
+ // arriving. Then the cap is lifted and B has to climb back: the first
+ // step on the real 45 s, the rest on the gate's shortened wait. The
+ // levels over time are printed, once a second, as the evidence.
+ async lowbandwidth() {
+ // What the gate's fake camera sends: about 100–300 kbit/s at normal and
+ // reduced, 20–60 at minimal (measured 2026-10-28). The cap sits between.
+ const CAP_KBPS = Number(process.env.CALLS_CAP_KBPS) || 60;
+ const state = (page) => page.evaluate(() => window.meet.state());
+ const ctxA = await newContext('member A', { cookie: cookieA });
+ const ctxB = await newContext('member B', { cookie: cookieB, options: { bypassCSP: true } });
+ await ctxB.addInitScript(downlinkCap);
+ const pageA = await openRoom(ctxA);
+ const pageB = await openRoom(ctxB);
+ const pair = await assertPair(pageA, pageB, 'member A', 'member B');
+ if (!pair) return;
+ const a = pair.a.peer;
+ const b = pair.b.peer;
+ const t0 = Date.now();
+ const timeline = [];
+ let lastBytes = null;
+ const look = async (what) => {
+ const sa = await pageA.evaluate(() => window.meet.state());
+ const sb = await pageB.evaluate(() => window.meet.state());
+ const x = sb.adapt[a] || {};
+ const y = sa.adapt[b] || {};
+ const row = {
+ t: Math.round((Date.now() - t0) / 1000), what,
+ bWatch: x.level, bAsks: x.asked, aSends: y.sent,
+ aCamera: y.wire ? y.wire.cameraHeight + 'p@' + Math.round(y.wire.cameraFps || 0) : '-',
+ bAudioIn: x.wire ? x.wire.audioPackets : 0, bFreezes: x.wire ? x.wire.videoFreezes : 0,
+ notice: sa.videoNotice, aAsks: JSON.stringify(sa.videoAsks), bLast: x.last,
+ aKbps: y.wire && lastBytes ? Math.round(((y.wire.cameraBytes - lastBytes.bytes) * 8) / (Date.now() - lastBytes.at)) : 0,
+ };
+ if (y.wire) lastBytes = { bytes: y.wire.cameraBytes, at: Date.now() };
+ timeline.push(row);
+ line('levels ' + JSON.stringify(row));
+ return { sa, sb, row };
+ };
+ // A few seconds for A's camera to ramp up past what the cap carries.
+ for (let i = 0; i < 6; i++) {
+ await look('open');
+ await sleep(1000);
+ }
+ const capped = await pageB.evaluate((k) => window.__capDownlink(k), CAP_KBPS);
+ check(capped, 'B’s video receivers are behind the downlink cap (' + capped + ')');
+ let down = null;
+ for (let i = 0; i < 40 && !down; i++) {
+ const { row } = await look('capped at ' + CAP_KBPS + ' kbit/s');
+ if (row.bAsks === 'minimal' || row.bAsks === 'audio') down = row;
+ else await sleep(1000);
+ }
+ check(down, 'B, capped, asks A for minimal video within 40 s (' + JSON.stringify(timeline[timeline.length - 1]) + ')');
+ const firstDown = timeline.find((r) => r.bAsks !== 'normal' && r.what.startsWith('capped'));
+ check(firstDown && firstDown.t - timeline.find((r) => r.what.startsWith('capped')).t <= 25,
+ 'the first step down came within 25 s of the cap (' + JSON.stringify(firstDown) + ')');
+ // The sender's half, over the wire.
+ const sent = await until(async () => {
+ const { row } = await look('capped, sender');
+ return row.aSends === row.bAsks && row.aSends !== 'normal' ? row : false;
+ }, 5000);
+ check(sent, 'A sends B what B asks for (' + JSON.stringify(timeline[timeline.length - 1]) + ')');
+ const small = await until(async () => {
+ const { sa } = await look('capped, encoder');
+ const w = sa.adapt[b] && sa.adapt[b].wire;
+ return w && w.cameraHeight > 0 && w.cameraHeight <= 180 ? w : false;
+ }, 15000);
+ check(small, 'A’s camera to B is encoded at 180 lines or fewer (' + JSON.stringify(timeline[timeline.length - 1]) + ')');
+ const notice = (await state(pageA)).videoNotice || '';
+ check(/^Sending (reduced video|only audio) to .+ \(their connection is weak\)$/.test(notice),
+ 'A is told it is sending B less (' + notice + ')');
+ const badge = await pageB.evaluate((id) => {
+ const el = document.querySelector('#tiles figure[data-tile="' + id + '"] .calls-tile-low');
+ return el && !el.hidden ? { text: el.textContent.trim(), label: el.getAttribute('aria-label') || '' } : null;
+ }, a);
+ check(badge && badge.text === 'Low bandwidth' && /less video/.test(badge.label),
+ 'B’s tile for A says Low bandwidth, with words for a screen reader (' + JSON.stringify(badge) + ')');
+ const noBadge = await pageA.evaluate((id) => {
+ const el = document.querySelector('#tiles figure[data-tile="' + id + '"] .calls-tile-low');
+ return !el || el.hidden;
+ }, b);
+ check(noBadge, 'A, asking nothing of B, shows no badge on B’s tile');
+ const audioBefore = (await look('capped, audio')).row.bAudioIn;
+ await sleep(3000);
+ const audioAfter = (await look('capped, audio')).row.bAudioIn;
+ check(audioAfter - audioBefore >= 100, 'audio from A keeps arriving at B (' + audioBefore + ' -> ' + audioAfter + ' packets in 3 s)');
+ const hears = await pageB.evaluate((id) => window.meet.state().hearingList.includes(id), a);
+ check(hears, 'B still hears A');
+ // Lift the cap: the first step up on the real wait.
+ await pageB.evaluate(() => window.__capDownlink(0));
+ const lifted = Date.now();
+ const from = (await look('lifted')).row.bAsks;
+ let up = null;
+ while (!up && Date.now() - lifted < 65000) {
+ await sleep(1000);
+ const { row } = await look('lifted');
+ if (row.bAsks !== from) up = row;
+ }
+ const upAfter = (Date.now() - lifted) / 1000;
+ check(up && upAfter >= 44 && upAfter <= 62,
+ 'B steps A’s video up one level 45–60 s after the cap is lifted (' + from + ' -> ' + (up && up.bAsks) + ' after ' + upAfter.toFixed(1) + ' s)');
+ // The rest on a shortened wait, all the way back to normal.
+ await pageB.evaluate(() => window.meet.adaptForTest({ upAfter: 4000 }));
+ const normal = await until(async () => {
+ const { row } = await look('lifted, short wait');
+ return row.bAsks === 'normal' && row.aSends === 'normal' ? row : false;
+ }, 30000);
+ check(normal, 'B climbs back to normal and A sends normal again (' + JSON.stringify(timeline[timeline.length - 1]) + ')');
+ const cleared = await pageB.evaluate((id) => {
+ const el = document.querySelector('#tiles figure[data-tile="' + id + '"] .calls-tile-low');
+ return !el || el.hidden;
+ }, a);
+ check(cleared, 'the badge goes when B asks for normal again');
+ check(!(await state(pageA)).videoNotice, 'A’s notice is gone once B asks for normal');
+ check(errorsFor('member A') === '', 'no console errors in A (' + errorsFor('member A') + ')');
+ check(errorsFor('member B') === '', 'no console errors in B (' + errorsFor('member B') + ')');
+ await leaveRoom(pageA);
+ await leaveRoom(pageB);
+ await ctxA.close();
+ await ctxB.close();
+ },
+
+ // Spec §15.30: the person's own Video quality. Audio only on B: B asks
+ // A for no video and stops sending its own camera; A's camera encoding
+ // to B goes inactive, B's tile for A says the video is paused, A sees B
+ // as camera off, and audio keeps flowing both ways. Low bandwidth asks
+ // for minimal, and Auto goes back. The choice is remembered.
+ async audioonly() {
+ const full = (page) => page.evaluate(() => window.meet.state());
+ const ctxA = await newContext('member A', { cookie: cookieA });
+ const ctxB = await newContext('member B', { cookie: cookieB });
+ const pageA = await openRoom(ctxA);
+ const pageB = await openRoom(ctxB);
+ const pair = await assertPair(pageA, pageB, 'member A', 'member B');
+ if (!pair) return;
+ const a = pair.a.peer;
+ const b = pair.b.peer;
+ await pageB.click('#devices-toggle');
+ const picker = pageB.locator('#pick-video-quality');
+ check(await pageB.getByLabel('Video quality', { exact: true }).count() === 1, 'the Devices panel has a Video quality picker, labelled');
+ const options = await pageB.locator('#pick-video-quality option').allTextContents();
+ check(JSON.stringify(options) === JSON.stringify(['Auto', 'Low bandwidth', 'Audio only']),
+ 'its choices are Auto, Low bandwidth and Audio only (' + options + ')');
+ check(await picker.inputValue() === 'auto', 'Auto is the default');
+
+ await picker.selectOption('audio');
+ const asked = await until(async () => {
+ const sa = await full(pageA);
+ const x = sa.adapt[b] || {};
+ return x.sent === 'audio' && x.cameraPaused ? sa : false;
+ }, 8000);
+ check(asked, 'A pauses its camera to B when B asks for audio only (' + JSON.stringify((await full(pageA)).adapt[b]) + ')');
+ const idle = await until(async () => {
+ const w1 = (await full(pageA)).adapt[b].wire;
+ await sleep(2000);
+ const w2 = (await full(pageA)).adapt[b].wire;
+ return w2.cameraBytes - w1.cameraBytes < 2000 ? [w1.cameraBytes, w2.cameraBytes] : false;
+ }, 12000);
+ check(idle, 'A’s camera to B sends nothing (' + JSON.stringify(idle) + ')');
+ const cover = await pageB.evaluate((id) => {
+ const el = document.querySelector('#tiles figure[data-tile="' + id + '"] .calls-tile-video-paused-cover');
+ return el && !el.hidden ? el.innerText.trim().replace(/\s+/g, ' ') : '';
+ }, a);
+ check(cover === 'Video paused to keep audio clear', 'B’s tile for A says the video is paused, and nothing about an old app (' + cover + ')');
+ const bOff = await until(async () => {
+ const m = (await full(pageA)).remoteMedia[b];
+ return m && m.cameraOff ? m : false;
+ }, 5000);
+ check(bOff, 'A sees B’s camera as off: B sends no camera to anyone');
+ const bSendsNothing = await until(async () => {
+ const sb = await full(pageB);
+ return sb.adapt[a] && sb.adapt[a].cameraPaused ? true : false;
+ }, 5000);
+ check(bSendsNothing, 'B’s own camera to A is paused');
+ const aIn1 = (await full(pageA)).adapt[b].wire.audioPackets;
+ const bIn1 = (await full(pageB)).adapt[a].wire.audioPackets;
+ await sleep(3000);
+ const aIn2 = (await full(pageA)).adapt[b].wire.audioPackets;
+ const bIn2 = (await full(pageB)).adapt[a].wire.audioPackets;
+ check(aIn2 - aIn1 >= 100 && bIn2 - bIn1 >= 100, 'audio flows both ways (' + [aIn1, aIn2, bIn1, bIn2] + ')');
+ check(!(await state(pageA)).terminal && (await state(pageA)).connection[b] === 'connected', 'the connection was not rebuilt for it');
+
+ await picker.selectOption('low');
+ const low = await until(async () => {
+ const x = (await full(pageA)).adapt[b] || {};
+ return x.sent === 'minimal' && !x.cameraPaused ? x : false;
+ }, 8000);
+ check(low, 'Low bandwidth asks A for minimal, and A’s camera to B is on again (' + JSON.stringify((await full(pageA)).adapt[b]) + ')');
+ const back = await until(async () => {
+ const m = (await full(pageA)).remoteMedia[b];
+ return m && !m.cameraOff ? m : false;
+ }, 5000);
+ check(back, 'B’s camera goes to A again once B is no longer on Audio only');
+ check(await pageB.evaluate(() => JSON.parse(localStorage.getItem('meet.devices') || '{}').videoQuality) === 'low',
+ 'the choice is remembered in this browser');
+
+ await picker.selectOption('auto');
+ const auto = await until(async () => ((await full(pageA)).adapt[b] || {}).sent === 'normal', 8000);
+ check(auto, 'Auto asks A for normal again');
+ check(errorsFor('member A') === '', 'no console errors in A (' + errorsFor('member A') + ')');
+ check(errorsFor('member B') === '', 'no console errors in B (' + errorsFor('member B') + ')');
+ await leaveRoom(pageA);
+ await leaveRoom(pageB);
+ await ctxA.close();
+ await ctxB.close();
+ },
+
// The self view, in Chromium and in WebKit (2026-10-21: on an iPhone
// in Safari the floating self view was black for a whole call while
// the camera was being sent perfectly well). Every way the local
diff --git a/test/browser/room-adapt.test.mjs b/test/browser/room-adapt.test.mjs
index 5f8860e..d91a0c3 100644
--- a/test/browser/room-adapt.test.mjs
+++ b/test/browser/room-adapt.test.mjs
@@ -35,7 +35,7 @@ function liftConst(name) {
return 'const ' + name + ' = ' + m[1] + ';';
}
const CONSTS = ['ADAPT_LEVELS', 'ADAPT_WINDOW', 'ADAPT_SEVERE_AFTER', 'ADAPT_DOWN_FREEZES', 'ADAPT_DOWN_LOSS',
- 'ADAPT_DOWN_RTT', 'ADAPT_DOWN_JITTER_BUFFER', 'ADAPT_DOWN_DROPPED', 'ADAPT_DOWN_DROPPED_MIN', 'ADAPT_SEVERE_FREEZES',
+ 'ADAPT_DOWN_RTT', 'ADAPT_DOWN_JITTER_BUFFER', 'ADAPT_DOWN_DROPPED', 'ADAPT_DOWN_DROPPED_MIN', 'ADAPT_DOWN_FREEZE_SECONDS', 'ADAPT_DOWN_KEYFRAME_ASKS', 'ADAPT_SEVERE_FREEZES',
'ADAPT_SEVERE_FREEZE_SECONDS', 'ADAPT_SEVERE_LOSS', 'ADAPT_CLEAN_LOSS', 'ADAPT_CLEAN_RTT', 'ADAPT_CLEAN_JITTER_BUFFER',
'ADAPT_UP_AFTER', 'ADAPT_PROBE_WATCH', 'ADAPT_PROBE_JUDGE', 'ADAPT_UP_MAX', 'ADAPT_CAMERA', 'ADAPT_SCREEN',
'ADAPT_MIN_NATIVE_VERSION', 'QUALITY_MAX_SECONDS'].map(liftConst).join('\n');
@@ -105,6 +105,8 @@ test('loss over five percent, a slow link with freezes, a deep jitter buffer and
['one freeze on a 700 ms round trip', (t) => clean({ rtt: 700, freezes: t === 5 ? 1 : 0 })],
['the jitter buffer', () => clean({ jitterBufferMs: 650 })],
['frames dropped', () => clean({ decoded: 20, dropped: 10 })],
+ ['one long freeze', (t) => clean({ freezes: t === 5 ? 1 : 0, freezeSeconds: t === 5 ? 2.5 : 0 })],
+ ['a keyframe asked for every three seconds', (t) => clean({ keyframeAsks: t % 3 === 0 ? 1 : 0 })],
]) {
const rec = r.adaptRecord();
assert.deepEqual(run(rec, 0, 10, sample), [[10, 1]], what);
@@ -128,9 +130,10 @@ test('a second with nothing measured is no news either way', () => {
test('freezes count only while the camera is watched', () => {
const q = { rtt: 50, in: { audio: { packets: 50, lost: 1, jitterBufferMs: 70 }, video: { packets: 90, freezes: 2, freezeSeconds: 1.5, decoded: 30, dropped: 1 },
screen: { packets: 10, lost: 1, decoded: 1 } } };
- assert.deepEqual(r.adaptSample(q, true), { freezes: 2, freezeSeconds: 1.5, packets: 150, lost: 2, rtt: 50, jitterBufferMs: 70, decoded: 31, dropped: 1 });
- const off = r.adaptSample(q, false);
+ assert.deepEqual(r.adaptSample(q, true, 2), { freezes: 2, freezeSeconds: 1.5, keyframeAsks: 2, packets: 150, lost: 2, rtt: 50, jitterBufferMs: 70, decoded: 31, dropped: 1 });
+ const off = r.adaptSample(q, false, 2);
assert.equal(off.freezes, 0);
+ assert.equal(off.keyframeAsks, 0);
assert.equal(off.freezeSeconds, 0);
assert.equal(off.packets, 150);
});
@@ -146,6 +149,13 @@ test('clean seconds step up one level after forty-five, and again after another
assert.equal(rec.upWait, r.ADAPT_UP_AFTER, 'a probe that holds puts the wait back');
});
+test('a keyframe asked for is not a clean second', () => {
+ const rec = r.adaptRecord();
+ run(rec, 0, 10, freezing);
+ const seen = run(rec, 11, 120, (t) => clean({ keyframeAsks: t === 30 ? 1 : 0 }));
+ assert.deepEqual(seen, [[76, 0]]);
+});
+
test('one bad second resets the clean run', () => {
const rec = r.adaptRecord();
run(rec, 0, 10, freezing);