fix(sfu): announce the video layers the browser sends

This commit is contained in:
AAA committed 2026-11-20 23:58:52 -05:00
1 parent 4b751393cc
commit 4a3ca843c2
2 files changed
+16 -21

No files matched your search

+11 -17
View File
@@ -467,25 +467,19 @@ export class SfuPublisher {
private media(profile: QualityProfile): SfuMedia {
const settings = senderCaptureTrack(this.video!).getSettings();
const ceiling = profile.resolution;
const targets = this.encodings(profile);
return {
codec: this.codec,
layers: this.encodings(profile).map((encoding) => ({
rid: encoding.rid!,
width: Math.max(
1,
Math.floor(
(settings.width ?? ceiling.width) / encoding.scaleResolutionDownBy!,
),
),
height: Math.max(
1,
Math.floor(
(settings.height ?? ceiling.height) /
encoding.scaleResolutionDownBy!,
),
),
bitrate: encoding.maxBitrate!,
})),
layers: this.videoSender!.getParameters().encodings.map(({ rid }, index) => {
const target = targets[index]!;
const scale = target.scaleResolutionDownBy!;
return {
rid: rid ?? "",
width: Math.max(1, Math.floor((settings.width ?? ceiling.width) / scale)),
height: Math.max(1, Math.floor((settings.height ?? ceiling.height) / scale)),
bitrate: target.maxBitrate!,
};
}),
audio: this.audio !== null,
audioBitrate: screenAudioBitrate(profile.maxAudioBitrate),
};
+5 -4
View File
@@ -248,7 +248,7 @@ function feedVideoStats(
}
describe("embedded SFU browser transport", () => {
it("preserves the omitted browser RID on a single encoding", async () => {
it.each([undefined, "q"])("declares the sender's single encoding RID (%s)", async (rid) => {
const video = new FakeTrack("video");
video.getSettings.mockReturnValue({ width: 320, height: 180, frameRate: 30 });
const clone = new FakeTrack("video");
@@ -258,7 +258,8 @@ describe("embedded SFU browser transport", () => {
vi.spyOn(FakePc.prototype, "addTransceiver").mockImplementation(function (this: FakePc, ...args) {
const transceiver = addTransceiver.apply(this, args);
if (args[0] !== "audio" && transceiver.sender.parameters.encodings.length === 1) {
delete transceiver.sender.parameters.encodings[0]!.rid;
if (rid === undefined) delete transceiver.sender.parameters.encodings[0]!.rid;
else transceiver.sender.parameters.encodings[0]!.rid = rid;
}
return transceiver;
});
@@ -270,10 +271,10 @@ describe("embedded SFU browser transport", () => {
await expect(host.activate(stream(video), QUALITY_PROFILES["720p30"], "h264")).resolves.toBe(true);
const sender = FakePc.instances[0]!.transceivers[0]!.sender;
expect(sender.parameters.encodings).toHaveLength(1);
expect(sender.parameters.encodings[0]!.rid).toBeUndefined();
expect(sender.parameters.encodings[0]!.rid).toBe(rid);
expect(send).toHaveBeenCalledWith(expect.objectContaining({
kind: "description",
media: expect.objectContaining({ layers: [expect.objectContaining({ rid: "q" })] }),
media: expect.objectContaining({ layers: [expect.objectContaining({ rid: rid ?? "" })] }),
}));
});