Display capture stopped setting "motion", so the automatic codec preflight's clone inherited an empty hint. Chromium then keeps the desktop source's screencast flag, and every default probe encoded as screen content while a Balanced or Fluency share encodes with "motion". The H.264 decision was made on a configuration the share does not use. preferredVideoCodecForTrack now takes the sender's hint and sets it on its clone. startScreen passes screenContentHint for the stored preference and the track's display surface, the same mapping configureVideoSender applies. The relay probe in media.ts passes none and is unchanged: it probes a received track, as before. The media-quality standard names the preflight among the hint's readers. Verified: npx tsc -b --pretty false; npx vitest run (159 files, 2360 tests), including new tests that the probe clone carries the given hint without touching the source, and that startScreen passes "detail" only for Clarity on a display surface.
96 lines
5.4 KiB
TypeScript
96 lines
5.4 KiB
TypeScript
import { afterEach, expect, it, vi } from "vitest";
|
|
import { normalizeVideoOfferSdp, withoutVideoOrientation, requireReceivingVideo, VideoReceiveRejectedError } from "../src/client/webrtc/video-codec";
|
|
import { preferredVideoCodecForTrack } from "../src/client/webrtc/video-codec-preflight";
|
|
|
|
afterEach(() => { vi.unstubAllGlobals(); vi.useRealTimers(); });
|
|
|
|
it.each(["deadline", "cancel"] as const)("releases the probe clone and both PCs when setup never completes (%s)", async reason => {
|
|
vi.useFakeTimers();
|
|
const connections: { close: ReturnType<typeof vi.fn> }[] = [];
|
|
const stop = vi.fn();
|
|
vi.stubGlobal("RTCRtpSender", { getCapabilities: () => ({ codecs: [{ mimeType: "video/H264", sdpFmtpLine: "packetization-mode=1" }] }) });
|
|
vi.stubGlobal("RTCPeerConnection", class {
|
|
close = vi.fn();
|
|
constructor() { connections.push(this); }
|
|
addTransceiver() { return { setCodecPreferences() {}, sender: {} }; }
|
|
createOffer() { return new Promise<RTCSessionDescriptionInit>(() => {}); }
|
|
});
|
|
const track = { kind: "video", readyState: "live", clone: () => ({ stop }) } as unknown as MediaStreamTrack;
|
|
const abort = new AbortController();
|
|
const selecting = preferredVideoCodecForTrack(track, abort.signal);
|
|
const outcome = reason === "cancel" ? expect(selecting).rejects.toMatchObject({ name: "AbortError" }) : expect(selecting).resolves.toBe("vp8");
|
|
if (reason === "cancel") abort.abort();
|
|
else await vi.advanceTimersByTimeAsync(4000);
|
|
await outcome;
|
|
expect(connections).toHaveLength(2);
|
|
for (const pc of connections) expect(pc.close).toHaveBeenCalledOnce();
|
|
expect(stop).toHaveBeenCalledOnce();
|
|
expect(track.readyState).toBe("live");
|
|
expect(vi.getTimerCount()).toBe(0);
|
|
});
|
|
|
|
it("encodes the probe clone with the share's hint and leaves the source's alone", async () => {
|
|
const clone = { contentHint: "", stop: vi.fn() };
|
|
vi.stubGlobal("RTCRtpSender", { getCapabilities: () => ({ codecs: [] }) });
|
|
vi.stubGlobal("RTCPeerConnection", class {
|
|
close() {}
|
|
addTransceiver() { return { setCodecPreferences() {}, sender: {} }; }
|
|
});
|
|
const track = { kind: "video", readyState: "live", contentHint: "", clone: () => clone } as unknown as MediaStreamTrack;
|
|
await expect(preferredVideoCodecForTrack(track, new AbortController().signal, "detail")).resolves.toBe("vp8");
|
|
expect(clone.contentHint).toBe("detail");
|
|
expect(track.contentHint).toBe("");
|
|
});
|
|
|
|
it("recognizes a Browser-rejected video answer without inferring codec support", () => {
|
|
const offer = (sdp: string): RTCSessionDescriptionInit => ({ type: "offer", sdp });
|
|
const answer = (sdp: string): RTCSessionDescriptionInit => ({ type: "answer", sdp });
|
|
const video = "m=video 9 UDP/TLS/RTP/SAVPF 96\r\na=sendonly\r\na=rtpmap:96 H264/90000\r\n";
|
|
const rejected = "m=video 0 UDP/TLS/RTP/SAVPF 120\r\n";
|
|
expect(() => requireReceivingVideo(offer(video), answer(rejected))).toThrow(VideoReceiveRejectedError);
|
|
for (const [offered, accepted] of [
|
|
[video, video.replace("sendonly", "recvonly")],
|
|
[video + video, rejected + video.replace("sendonly", "recvonly")],
|
|
[video.replace("9 UDP", "0 UDP"), rejected],
|
|
[video.replace("sendonly", "inactive"), rejected],
|
|
[video.replace("sendonly", "recvonly"), rejected],
|
|
["m=audio 9 UDP/TLS/RTP/SAVPF 111\r\n", "m=audio 0 UDP/TLS/RTP/SAVPF 111\r\n"],
|
|
]) expect(() => requireReceivingVideo(offer(offered!), answer(accepted!))).not.toThrow();
|
|
expect(() => requireReceivingVideo(offer(video.replace("9 UDP", "0 UDP") + "a=bundle-only\r\n"),
|
|
answer(rejected))).toThrow(VideoReceiveRejectedError);
|
|
});
|
|
|
|
it.each(["\r\n", "\n"])("removes orphan codec attributes within each offered video section (%j)", newline => {
|
|
const lines = [
|
|
"v=0", "a=x-session:keep",
|
|
"m=video 9 UDP/TLS/RTP/SAVPF 120 124", "a=mid:0", "a=ice-ufrag:unchanged",
|
|
"a=rtpmap:120 VP8/90000", "a=rtpmap:124 rtx/90000", "a=fmtp:124 apt=120",
|
|
"a=rtcp-fb:120 nack", "a=rtcp-fb:* transport-cc", "a=x-video:keep",
|
|
"a=fmtp:126 profile-level-id=42e01f", "a=rtcp-fb:126 nack pli",
|
|
"m=video 9 UDP/TLS/RTP/SAVPF 126", "a=mid:1", "a=rtpmap:126 H264/90000",
|
|
"a=fmtp:126 profile-level-id=42e01f;packetization-mode=1", "a=rtcp-fb:126 nack",
|
|
"a=rtcp-fb:120 nack pli",
|
|
"m=audio 9 UDP/TLS/RTP/SAVPF 0", "a=fmtp:0 keep-audio",
|
|
"m=application 9 UDP/DTLS/SCTP webrtc-datachannel", "a=sctp-port:5000", "",
|
|
];
|
|
const omitted = new Set([11, 12, 18]);
|
|
const expected = lines.filter((_line, index) => !omitted.has(index)).join(newline);
|
|
expect(normalizeVideoOfferSdp(lines.join(newline))).toBe(expected);
|
|
expect(normalizeVideoOfferSdp(expected)).toBe(expected);
|
|
});
|
|
|
|
it("preserves valid codec parameters, feedback and opaque data without reserializing SDP", () => {
|
|
const sdp = "v=0\r\nm=video 9 UDP/TLS/RTP/SAVPF 96 97\r\n" +
|
|
"a=rtpmap:96 H264/90000\r\na=fmtp:96 profile-level-id=42e034;packetization-mode=1\r\n" +
|
|
"a=rtpmap:97 rtx/90000\r\na=fmtp:97 apt=96\r\na=rtcp-fb:96 nack\r\n" +
|
|
"a=rtcp-fb:* transport-cc\r\na=unknown:exact spacing and values\r\n";
|
|
expect(normalizeVideoOfferSdp(sdp)).toBe(sdp);
|
|
});
|
|
|
|
it("declines CVO while retaining the other negotiated header extensions", () => {
|
|
const section = "m=video 9 UDP/TLS/RTP/SAVPF 96\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\n";
|
|
const cvo = "a=extmap:13/sendrecv urn:3gpp:video-orientation\r\n";
|
|
expect(normalizeVideoOfferSdp(section + cvo)).toBe(section + cvo);
|
|
expect(withoutVideoOrientation(section + cvo)).toBe(section);
|
|
});
|