## Problem and outcome Stale ICE and transport callbacks, interrupted media ownership, and optional encoder capabilities could break otherwise recoverable sharing sessions. This maintenance phase corrects those owners across Web, Native and embedded SFU, improves current-state diagnostics, and finishes the affected UI and documentation animation paths. Android, QR invitations and App/Server headline presentation stay on their feature branch. This PR contains the accepted maintenance scope only. ## Release notes **Play together. Your turn!** Approved friends can play together with shared keyboard and mouse controls or optional gamepads. **远程同乐,轮到你啦!** 获准的朋友可以共用键鼠,或使用可选手柄,一起玩本地多人游戏。 ### English This maintenance update improves connection recovery, capture compatibility and troubleshooting for existing Piik rooms. - Keep ICE candidates and gathering completion tied to their current connection. Preserve Viewer route preferences through reconnection and retry newly available Peer opportunities after SFU fallback. - Correct picture and voice ownership during restart, source replacement and connection retirement. Report failed picture dependencies while keeping room voice available. - Separate capture and forwarding statistics and isolate pooled sender attachment failures. - Improve Windows H.264 compatibility with optional encoder properties, retain safe capture failure codes, and keep shared sound volume usable without microphone support. - Improve remote input continuity and mouse responsiveness after idle. - Fix fullscreen handling in some mobile browsers, source-picker refresh, delayed chat confirmations, starred-site startup and local App requests. Refine control motion and reduced-motion behavior. - Restore the mascot's face and shared animation lifecycle in the documentation header. - Include current connection and playback state in diagnostic exports, update Zod to 4.6.6 and simplify shared lifecycle code. Existing 2.x protocols, configuration and default quality settings are preserved. ### 中文 本次维护更新改善现有房间的连接恢复、采集兼容性和故障诊断。 - ICE 候选和收集结束事件跟随当前连接;重连保留观众线路偏好,SFU 兜底后出现新的可用 P2P 机会仍可尝试。 - 修正重启、换源和连接结束时的画面与语音生命周期;语音继续时,画面失败会明确反馈。 - 区分采集与转发统计,隔离编码池中单个输出连接的失败。 - 改善 Windows H.264 可选属性兼容性,保留有效的采集失败原因;没有麦克风能力时也能调整共享声音音量。 - 修复部分移动浏览器全屏、选源刷新、迟到聊天确认、收藏站点启动和本机 App 请求问题,打磨控件动效及减少动态效果行为。 - 修复文档导航 mascot 面部一直隐藏的问题,接回共用动画生命周期。 - 诊断导出补取当前连接与播放状态,升级 Zod 至 4.6.6,精简共用生命周期代码。 沿用现有 2.x 协议、配置和画质默认值。Android、二维码邀请及 App/Server 新增的 HEADLINE 展示留待后续版本。 ## Verification - `npm run check`: type-check, 98 test files / 1,765 tests, production Web build passed. - `npm run check:go-core`: Go formatting, tests, vet, Windows/Linux builds passed; Darwin builds require the native CI runners. - `npm run check:native`: current Windows capture compilation, fixtures and capability probe passed. - `npm run build:website`, TypeScript and repository hygiene checks passed after the documentation-brand fix. - Existing controlled media lifecycle and P2P/SFU voice acceptance covered the retained route/transport changes. Final local browser acceptance covered actual sharing and pause/resume, fullscreen, source refresh, voice/keyboard/settings, 320px to desktop layouts, both themes and all presentation modes. Documentation brand was reproduced broken, then verified on load, replay and reduced motion. - Independent scoped reviews found no integration blocker. ## Impact Patch release v2.4.1. Existing 2.x wire, configuration, authority, capacity and default quality contracts remain intact; no data migration. Source volume no longer depends on microphone availability. Zod 4.6.6 fixes GHSA-mrhx-c7xc-m3w5. The device-specific Windows reports #495 and #452 remain under investigation; this PR improves compatibility and diagnostics without claiming those reports fully resolved. Physical macOS acceptance remains with its native runner/device checks.
430 lines
22 KiB
TypeScript
430 lines
22 KiB
TypeScript
import { createOpaqueId } from "../lib/opaque-id";
|
|
import { browserDebugEnabled, debugError, debugEvent } from "../lib/debug";
|
|
import { EMPTY_METRICS, type ConnectionMetrics } from "../types";
|
|
import { captureMetrics, collectConnectionMetricsFromReport, createStatsAccumulator } from "../webrtc/stats";
|
|
import { BrowserEncodingProducer } from "./browser-encoding-producer";
|
|
import { BROWSER_CARRIER_SIZE, type BrowserEncodingOutput } from "./browser-encoding-output";
|
|
import { codecIdentity, fits, nativeVideoBudget, negotiatedCodec, noRegression, observeVideo,
|
|
projectEncodingMetrics, videoOutbound, type Observation } from "./browser-encoding-stats";
|
|
import { videoQualitySettingsEqual, type QualityProfile } from "./quality";
|
|
|
|
export interface BrowserPooledSender {
|
|
updateProfile(profile: QualityProfile): Promise<void>;
|
|
carrierScale(): number | undefined;
|
|
setPaused(paused: boolean): void;
|
|
metrics(transport: ConnectionMetrics): ConnectionMetrics;
|
|
dispose(): void;
|
|
}
|
|
|
|
type Output = ReturnType<BrowserEncodingOutput["snapshot"]>;
|
|
type Group = {
|
|
producer: BrowserEncodingProducer; source: MediaStreamTrack; profile: QualityProfile;
|
|
codecKey: string; budget: number; ready: boolean; failed: boolean;
|
|
report?: RTCStatsReport; previous?: RTCOutboundRtpStreamStats; output?: Observation;
|
|
updating?: Promise<void>;
|
|
};
|
|
type Member = {
|
|
id: string; source: MediaStreamTrack; sender: RTCRtpSender; connection: RTCPeerConnection;
|
|
profile: QualityProfile; encoded: BrowserEncodingOutput;
|
|
configureCarrier: () => Promise<boolean>;
|
|
requestKey: () => Promise<void>; onFatal: () => void;
|
|
paused: boolean; disabled: boolean; disposed: boolean; mixed: boolean; carrier: boolean;
|
|
codec?: RTCRtpCodec; codecKey?: string; budget?: number; raw?: RTCOutboundRtpStreamStats;
|
|
encoderStats: ReturnType<typeof createStatsAccumulator>;
|
|
current?: Group; pending?: { group: Group; selecting?: boolean };
|
|
output?: Output; previousOutput?: Output; replacement?: Promise<void>;
|
|
};
|
|
|
|
// M152 exposes BWE through getStats, not a bandwidth callback. The paired
|
|
// weak-entry probe bounds observation lag at this cadence; it is not a retry.
|
|
const BUDGET_SAMPLE_MS = 500;
|
|
|
|
/** One owner per captured source tree; connections retain their own RTP and transport. */
|
|
export class BrowserEncodingPool {
|
|
private readonly members = new Set<Member>();
|
|
private readonly groups = new Set<Group>();
|
|
private readonly failedSources = new WeakSet<MediaStreamTrack>();
|
|
private timer: ReturnType<typeof setInterval> | undefined;
|
|
private polling = false;
|
|
private disposed = false;
|
|
|
|
create(source: MediaStreamTrack, sender: RTCRtpSender, connection: RTCPeerConnection,
|
|
profile: QualityProfile, encoded: BrowserEncodingOutput, configureCarrier: Member["configureCarrier"], requestKey: Member["requestKey"],
|
|
onFatal: () => void): BrowserPooledSender | null {
|
|
if (this.disposed || this.failedSources.has(source) || source.kind !== "video" || source.readyState !== "live") return null;
|
|
const member: Member = { id: createOpaqueId(), source, sender, connection, profile: { ...profile }, encoded, configureCarrier, requestKey, onFatal,
|
|
paused: !source.enabled, disabled: false, disposed: false, mixed: false, carrier: encoded.snapshot().frames === 0,
|
|
encoderStats: createStatsAccumulator() };
|
|
this.members.add(member);
|
|
// A fresh connection has no useful raw output to preserve. Start its
|
|
// tiny clock immediately, rather than warming two full encoders first.
|
|
if (!member.carrier) encoded.passthrough(requestKey);
|
|
if (!this.timer) this.timer = setInterval(() => void this.poll(), BUDGET_SAMPLE_MS);
|
|
return {
|
|
carrierScale: () => {
|
|
if (!member.carrier) return;
|
|
const width = member.sender.track?.getSettings().width ?? member.profile.resolution.width;
|
|
return Math.max(1, width / BROWSER_CARRIER_SIZE);
|
|
},
|
|
updateProfile: async (next) => {
|
|
if (member.disposed || videoQualitySettingsEqual(member.profile, next)) return;
|
|
member.profile = { ...next };
|
|
member.encoderStats = createStatsAccumulator(); member.previousOutput = undefined;
|
|
// HostPeer awaits this inside its sender queue. Handoffs run outside it.
|
|
},
|
|
setPaused: (paused) => {
|
|
if (member.disposed || member.paused === paused) return;
|
|
member.paused = paused;
|
|
member.previousOutput = undefined;
|
|
this.updatePauses();
|
|
},
|
|
metrics: (transport) => this.metrics(member, transport),
|
|
dispose: () => this.remove(member),
|
|
};
|
|
}
|
|
|
|
dispose(): void {
|
|
this.disposed = true;
|
|
for (const member of [...this.members]) this.remove(member);
|
|
this.prune();
|
|
}
|
|
|
|
private compatible(member: Member, group: Group): boolean {
|
|
return member.source === group.source && member.codecKey === group.codecKey &&
|
|
videoQualitySettingsEqual(member.profile, group.profile) && !group.failed;
|
|
}
|
|
|
|
private references(group: Group): Member[] {
|
|
return [...this.members].filter((member) => member.current === group || member.pending?.group === group);
|
|
}
|
|
|
|
private demand(group: Group, except?: Member): number | undefined {
|
|
const budgets = this.references(group).flatMap((member) => member !== except &&
|
|
this.compatible(member, group) && member.budget !== undefined ? [member.budget] : []);
|
|
return budgets.length ? Math.max(...budgets) : undefined;
|
|
}
|
|
|
|
private hasHigherDemand(member: Member, group: Group): boolean {
|
|
return (this.demand(group) ?? 0) > member.budget!;
|
|
}
|
|
|
|
private canJoin(member: Member, group: Group): boolean {
|
|
// A pending newcomer cannot prove compatibility with its own demand or
|
|
// raise the incumbent owner's allocation merely to reuse its encoder.
|
|
const demand = this.demand(group, member);
|
|
return demand === undefined || demand === member.budget;
|
|
}
|
|
|
|
private canReuse(member: Member, group: Group, current: Group): boolean {
|
|
const output = group.output, previous = current.output;
|
|
// A quiet scene does not make a higher rate owner compatible. Check both
|
|
// allocations before pending membership can raise the candidate's budget.
|
|
return this.compatible(member, group) && this.canJoin(member, group) &&
|
|
group.budget <= member.budget! && group.budget >= current.budget &&
|
|
fits(output, member.budget) && output?.reason === "none" && !!previous &&
|
|
noRegression(output, previous.width, previous.height, previous.fps, member.profile);
|
|
}
|
|
|
|
private acceptsFrame(member: Member, group: Group, metadata: RTCEncodedVideoFrameMetadata): boolean {
|
|
if (member.disabled || member.paused || !this.compatible(member, group) || group.updating ||
|
|
member.budget === undefined || group.budget > member.budget || !this.canJoin(member, group)) return false;
|
|
const current = member.current;
|
|
const optional = current && this.compatible(member, current) &&
|
|
!this.hasHigherDemand(member, current);
|
|
// Initial output and necessary downgrades have no healthy picture to beat.
|
|
if (current ? !optional : member.carrier) return true;
|
|
const actual = member.encoded.snapshot();
|
|
if (actual.lastProducerId !== (current?.producer.id ?? null)) return false;
|
|
if (!metadata.width || !metadata.height || actual.width === null || actual.height === null ||
|
|
metadata.width < actual.width || metadata.height < actual.height) {
|
|
// A real key can disprove the last statistics sample. Do not let another
|
|
// reconciliation reuse that sample before the normal poll replaces it.
|
|
group.output = undefined;
|
|
return false;
|
|
}
|
|
return current ? this.canReuse(member, group, current) : !!group.output &&
|
|
noRegression(group.output, actual.width, actual.height, member.raw?.framesPerSecond ?? null, member.profile);
|
|
}
|
|
|
|
private async poll(): Promise<void> {
|
|
if (this.polling || this.disposed) return;
|
|
this.polling = true;
|
|
try {
|
|
await Promise.allSettled([
|
|
...[...this.members].map(async (member) => {
|
|
if (member.disposed || member.disabled || member.connection.connectionState !== "connected") { member.budget = undefined; return; }
|
|
const report = await member.connection.getStats().catch(() => null);
|
|
if (member.disposed) return;
|
|
if (!report) { member.budget = undefined; return; }
|
|
const codec = negotiatedCodec(report);
|
|
if (!codec) {
|
|
if (member.current || member.pending) this.fallback(member);
|
|
else {
|
|
const outbound = videoOutbound(report);
|
|
if (outbound?.codecId && report.get(outbound.codecId)) this.fallback(member);
|
|
}
|
|
return;
|
|
}
|
|
const key = codecIdentity(codec);
|
|
if (member.codecKey && member.codecKey !== key && (member.current || member.pending)) {
|
|
this.fallback(member); return;
|
|
}
|
|
member.codec = codec; member.codecKey = key;
|
|
member.raw = videoOutbound(report);
|
|
member.budget = nativeVideoBudget(member.raw, member.profile.maxBitrate);
|
|
}),
|
|
...[...this.groups].map(async (group) => {
|
|
if (!group.ready || group.failed) { group.output = undefined; return; }
|
|
const report = await group.producer.report().catch(() => null);
|
|
if (!this.groups.has(group)) return;
|
|
if (!report) { group.output = undefined; return; }
|
|
group.report = report;
|
|
const video = videoOutbound(report);
|
|
group.output = observeVideo(video, group.previous);
|
|
group.previous = video;
|
|
}),
|
|
]);
|
|
if (this.disposed) return;
|
|
this.reconcile();
|
|
for (const member of this.members) {
|
|
member.output = member.encoded.snapshot();
|
|
if (!member.pending && !member.replacement && member.output.frames > 0 &&
|
|
member.output.lastProducerId === (member.current?.producer.id ?? null)) member.mixed = false;
|
|
}
|
|
if (browserDebugEnabled) debugEvent("encoding-pool", "sample", {
|
|
members: [...this.members].map((member) => ({ memberId: member.id, trackId: member.source.id,
|
|
rtpStatsId: member.raw?.id, ssrc: member.raw?.ssrc,
|
|
producerId: member.current?.producer.id, pendingProducerId: member.pending?.group.producer.id,
|
|
budget: member.budget, carrier: member.carrier, paused: member.paused, disabled: member.disabled, output: member.output })),
|
|
groups: [...this.groups].map((group) => ({ producerId: group.producer.id, budget: group.budget,
|
|
ready: group.ready, failed: group.failed, output: group.output })),
|
|
});
|
|
} finally { this.polling = false; }
|
|
}
|
|
|
|
private reconcile(): void {
|
|
// Remove obsolete requests before they can displace a current member in
|
|
// this pass. Applied rates may still belong to the previous stats sample.
|
|
for (const member of this.members) {
|
|
if (member.pending && member.budget !== undefined && !this.canJoin(member, member.pending.group) &&
|
|
member.encoded.cancelSelection(member.pending.group.producer.id)) member.pending = undefined;
|
|
}
|
|
const changing = new Set<Group>();
|
|
for (const group of this.groups) {
|
|
const references = this.references(group);
|
|
const profile = references[0]?.profile;
|
|
if (!profile || group.failed || videoQualitySettingsEqual(profile, group.profile) ||
|
|
!references.every((member) => member.source === group.source && member.codecKey === group.codecKey &&
|
|
videoQualitySettingsEqual(member.profile, profile))) continue;
|
|
changing.add(group);
|
|
if (!group.ready || group.updating) continue;
|
|
for (const member of references) if (member.current === group && member.pending && !member.pending.selecting) member.pending = undefined;
|
|
const next = { ...profile };
|
|
const budget = Math.min(next.maxBitrate, Math.max(...references.map((member) => member.budget ?? group.budget)));
|
|
group.budget = budget;
|
|
group.updating = group.producer.update(next, budget).then(() => {
|
|
if (!this.groups.has(group)) return;
|
|
group.profile = next;
|
|
for (const member of this.members) if (member.current === group || member.pending?.group === group) {
|
|
member.encoderStats = createStatsAccumulator(); member.previousOutput = undefined;
|
|
}
|
|
}).catch(() => {
|
|
if (this.groups.has(group)) this.failSource(group.source);
|
|
}).finally(() => { group.updating = undefined; });
|
|
}
|
|
for (const member of this.members) {
|
|
if (member.disposed || member.disabled || member.paused || member.replacement || !member.codec || member.budget === undefined) continue;
|
|
if ([member.current, member.pending?.group].some((group) => group && (group.updating || changing.has(group)))) continue;
|
|
if (member.pending) {
|
|
const pending = member.pending;
|
|
// A shared producer can outgrow a waiting child's native allocation.
|
|
// Replan that membership; never wait forever for its budget to catch up.
|
|
if (!pending.selecting && pending.group.budget > member.budget &&
|
|
this.references(pending.group).some((other) => other !== member)) {
|
|
member.pending = undefined;
|
|
continue;
|
|
}
|
|
if (!pending.selecting && member.current && this.compatible(member, member.current) &&
|
|
!this.hasHigherDemand(member, member.current) && !this.canReuse(member, pending.group, member.current)) {
|
|
member.pending = undefined;
|
|
continue;
|
|
}
|
|
if (!pending.selecting && !this.compatible(member, pending.group)) {
|
|
member.pending = undefined;
|
|
continue;
|
|
}
|
|
const ownedBudget = pending.group.budget <= member.budget;
|
|
// The output already waits for a real recovery frame. A rate-owned
|
|
// downgrade need not wait another statistics window while the old
|
|
// high-rate output keeps congesting the same path.
|
|
if (!pending.selecting && pending.group.ready &&
|
|
(fits(pending.group.output, member.budget) || ((member.current || member.carrier) && ownedBudget))) {
|
|
const output = pending.group.output;
|
|
// A fresh carrier has delivered no picture. Its tiny encode cannot
|
|
// establish a quality baseline for the first real output.
|
|
if (member.current || member.carrier || (output && noRegression(output, member.raw?.frameWidth ?? null,
|
|
member.raw?.frameHeight ?? null, member.raw?.framesPerSecond ?? null, member.profile))) {
|
|
pending.selecting = true;
|
|
member.mixed = true;
|
|
member.encoded.select(pending.group.producer.id, () => pending.group.producer.requestKey(), () => {
|
|
if (member.disposed || member.pending !== pending) return;
|
|
member.current = pending.group;
|
|
pending.group.producer.beginOutput();
|
|
member.pending = undefined;
|
|
member.encoderStats = createStatsAccumulator(); member.previousOutput = undefined;
|
|
member.carrier = true;
|
|
member.replacement = member.configureCarrier().then((applied) => {
|
|
if (!applied) this.fallback(member);
|
|
}).catch(() => this.fallback(member)).finally(() => { member.replacement = undefined; });
|
|
this.prune();
|
|
}, (metadata) => {
|
|
if (member.disposed || member.pending !== pending) return false;
|
|
if (this.acceptsFrame(member, pending.group, metadata)) return true;
|
|
member.pending = undefined;
|
|
this.prune();
|
|
return false;
|
|
});
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
const current = member.current;
|
|
if (current && this.compatible(member, current) &&
|
|
(!current.output || current.output.bitrate === 0 || current.output.fps === 0)) continue;
|
|
if (current?.output && this.compatible(member, current) && fits(current.output, member.budget)) {
|
|
// Equal outputs converge to the earlier owner. A strictly better healthy
|
|
// output is also reusable when this encoder has not recovered itself.
|
|
let earlier = true;
|
|
for (const group of this.groups) {
|
|
if (group === current) { earlier = false; continue; }
|
|
// A newer output must improve within the same Host ceilings used below.
|
|
const improves = group.output && current.output && !noRegression(current.output,
|
|
group.output.width, group.output.height, group.output.fps, member.profile);
|
|
if ((earlier || improves) && this.canReuse(member, group, current)) {
|
|
member.pending = { group }; break;
|
|
}
|
|
}
|
|
continue;
|
|
}
|
|
// A short output-rate spike is not new demand. Keep the rate owner and
|
|
// let its native encoder adapt unless another child needs a higher rate.
|
|
if (current && this.compatible(member, current) && !this.hasHigherDemand(member, current)) continue;
|
|
const candidates = [...this.groups].filter((group) => group !== current && this.compatible(member, group) &&
|
|
this.demand(group) === member.budget);
|
|
let target = candidates.find((group) => fits(group.output, member.budget)) ?? candidates[0];
|
|
if (!target) {
|
|
target = this.startGroup(member, member.budget);
|
|
}
|
|
member.pending = { group: target };
|
|
}
|
|
for (const group of this.groups) {
|
|
const budget = this.demand(group);
|
|
if (group.ready && budget !== undefined) {
|
|
if (budget !== group.budget && !group.updating) {
|
|
group.budget = budget;
|
|
group.updating = group.producer.update(group.profile, budget).catch(() => {
|
|
if (this.groups.has(group)) this.failSource(group.source);
|
|
})
|
|
.finally(() => {
|
|
group.updating = undefined;
|
|
// A ready downgrade can use this applied budget now. Waiting for
|
|
// another sample compares the previous limit to falling demand again.
|
|
if (!this.disposed && this.groups.has(group)) this.reconcile();
|
|
});
|
|
}
|
|
}
|
|
}
|
|
this.updatePauses();
|
|
this.prune();
|
|
}
|
|
|
|
private startGroup(member: Member, budget: number): Group {
|
|
const profile = { ...member.profile };
|
|
const producer = new BrowserEncodingProducer(member.source, profile, member.codec!, (frame) => {
|
|
for (const output of this.members) if (output.current === group || output.pending?.group === group) {
|
|
output.encoded.push(producer.id, frame);
|
|
}
|
|
},
|
|
() => { group.failed = true; this.failSource(member.source); });
|
|
const group: Group = { producer, source: member.source, profile, codecKey: member.codecKey!, budget, ready: false, failed: false };
|
|
this.groups.add(group);
|
|
debugEvent("encoding-pool", "producer-preparing", { producerId: producer.id, trackId: member.source.id, codec: member.codecKey, budget, profile });
|
|
void producer.start(budget).then(() => {
|
|
if (!this.groups.has(group)) return;
|
|
group.ready = true;
|
|
this.reconcile();
|
|
}, (error) => {
|
|
debugError("encoding-pool", "producer-start-failed", error, { producerId: producer.id });
|
|
if (this.groups.has(group)) { group.failed = true; this.failSource(group.source); }
|
|
});
|
|
return group;
|
|
}
|
|
|
|
private restore(member: Member): void {
|
|
if (member.disposed) return;
|
|
member.mixed = true;
|
|
member.pending = undefined;
|
|
member.carrier = false;
|
|
member.replacement = member.configureCarrier().then((applied) => {
|
|
if (member.disposed) return;
|
|
if (!applied) { member.onFatal(); return; }
|
|
member.encoded.passthrough(member.requestKey);
|
|
member.current = undefined;
|
|
member.encoderStats = createStatsAccumulator(); member.previousOutput = undefined;
|
|
}).catch(() => { if (!member.disposed) member.onFatal(); })
|
|
.finally(() => { member.replacement = undefined; this.prune(); });
|
|
}
|
|
|
|
// Negotiated compatibility belongs to one connection. Its ordinary sender
|
|
// remains available without retiring a healthy sibling's shared producer.
|
|
private fallback(member: Member): void {
|
|
if (member.disabled || member.disposed) return;
|
|
member.disabled = true;
|
|
if (member.replacement) void member.replacement.then(() => this.restore(member));
|
|
else this.restore(member);
|
|
}
|
|
|
|
private failSource(source: MediaStreamTrack): void {
|
|
if (this.failedSources.has(source)) return;
|
|
this.failedSources.add(source);
|
|
for (const member of this.members) if (member.source === source) this.fallback(member);
|
|
}
|
|
|
|
private updatePauses(): void {
|
|
for (const group of this.groups) group.producer.setPaused(!this.references(group).some((member) => !member.paused));
|
|
}
|
|
|
|
private metrics(member: Member, transport: ConnectionMetrics): ConnectionMetrics {
|
|
if (member.disposed || (!member.current && !member.mixed)) return transport;
|
|
const group = member.current, input = group?.producer.track, sample = member.output, previous = member.previousOutput;
|
|
member.previousOutput = sample;
|
|
const measured = !member.mixed && !member.paused && input && group?.report && !group.failed && sample?.lastProducerId === group.producer.id &&
|
|
previous?.lastProducerId === group.producer.id && sample.timestamp > previous.timestamp;
|
|
const encoder = measured ? { ...collectConnectionMetricsFromReport(group.report!, "send", member.encoderStats),
|
|
...captureMetrics(input) } : EMPTY_METRICS;
|
|
const qualityEligible = !!measured && !member.pending && !group.updating && this.compatible(member, group) &&
|
|
(encoder.nativeEdgeQualityState === "degraded" || fits(group.output, member.budget));
|
|
return projectEncodingMetrics(transport, encoder, measured ? sample : undefined, measured ? previous : undefined, qualityEligible);
|
|
}
|
|
|
|
private remove(member: Member): void {
|
|
if (member.disposed) return;
|
|
member.disposed = true;
|
|
this.members.delete(member);
|
|
member.encoded.passthrough(member.requestKey);
|
|
member.carrier = false;
|
|
member.current = undefined; member.pending = undefined;
|
|
this.prune();
|
|
}
|
|
|
|
private prune(): void {
|
|
for (const group of this.groups) if (!this.references(group).length) {
|
|
this.groups.delete(group); group.producer.dispose();
|
|
}
|
|
if (!this.members.size) {
|
|
if (this.timer) clearInterval(this.timer);
|
|
this.timer = undefined;
|
|
}
|
|
}
|
|
}
|