Skip to content

Commit 6cadad9

Browse files
Merge pull request #248 from EpicGamesExt/flexfec
Support flexfec, ulpfec, and any other non-video video codecs.
2 parents 6f30546 + 6b8eab8 commit 6cadad9

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

Frontend/library/src/PeerConnectionController/PeerConnectionController.ts

+22-31
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,6 @@ export class PeerConnectionController {
409409
this.peerConnection?.addTransceiver('video', { direction: 'recvonly' });
410410
}
411411

412-
// We can only set preferred codec on Chrome
413412
if (RTCRtpReceiver.getCapabilities && this.preferredCodec != '') {
414413
for (const transceiver of this.peerConnection?.getTransceivers() ?? []) {
415414
if (
@@ -419,44 +418,36 @@ export class PeerConnectionController {
419418
transceiver.receiver.track.kind === 'video' &&
420419
transceiver.setCodecPreferences
421420
) {
421+
// Get our preferred codec from the codecs options drop down
422422
const preferredRTPCodec = this.preferredCodec.split(' ');
423-
const codecs = [
424-
{
425-
mimeType:
426-
'video/' + preferredRTPCodec[0] /* Name */,
427-
clockRate: 90000,
428-
sdpFmtpLine: preferredRTPCodec[1] /* sdpFmtpLine */
429-
? preferredRTPCodec[1]
430-
: ''
423+
const preferredRTCRtpCodecCapability: RTCRtpCodecCapability = {
424+
mimeType: 'video/' + preferredRTPCodec[0] /* Name */,
425+
clockRate: 90000, /* All current video formats in browsers have 90khz clock rate */
426+
sdpFmtpLine: preferredRTPCodec[1] ? preferredRTPCodec[1] : ''
427+
}
428+
429+
// Populate a list of codecs we will support with our preferred one in the first position
430+
const ourSupportedCodecs: Array<RTCRtpCodecCapability> = [preferredRTCRtpCodecCapability];
431+
432+
// Go through all codecs the browser supports and add them to the list (in any order)
433+
RTCRtpReceiver.getCapabilities('video').codecs.forEach((browserSupportedCodec : RTCRtpCodecCapability) => {
434+
// Don't add our preferred codec again, but add everything else
435+
if(browserSupportedCodec.mimeType != preferredRTCRtpCodecCapability.mimeType) {
436+
ourSupportedCodecs.push(browserSupportedCodec);
431437
}
432-
];
433-
434-
this.config
435-
.getSettingOption(OptionParameters.PreferredCodec)
436-
.options.filter((option) => {
437-
// Remove the preferred codec from the list of possible codecs as we've set it already
438-
return option != this.preferredCodec;
439-
})
440-
.forEach((option) => {
441-
// Amend the rest of the browsers supported codecs
442-
const altCodec = option.split(' ');
443-
codecs.push({
444-
mimeType: 'video/' + altCodec[0] /* Name */,
445-
clockRate: 90000,
446-
sdpFmtpLine: altCodec[1] /* sdpFmtpLine */
447-
? altCodec[1]
448-
: ''
449-
});
450-
});
438+
else if(browserSupportedCodec?.sdpFmtpLine != preferredRTCRtpCodecCapability?.sdpFmtpLine) {
439+
ourSupportedCodecs.push(browserSupportedCodec);
440+
}
441+
});
451442

452-
for (const codec of codecs) {
453-
if (codec.sdpFmtpLine === '') {
443+
for (const codec of ourSupportedCodecs) {
444+
if (codec?.sdpFmtpLine === undefined || codec.sdpFmtpLine === '') {
454445
// We can't dynamically add members to the codec, so instead remove the field if it's empty
455446
delete codec.sdpFmtpLine;
456447
}
457448
}
458449

459-
transceiver.setCodecPreferences(codecs);
450+
transceiver.setCodecPreferences(ourSupportedCodecs);
460451
}
461452
}
462453
}

0 commit comments

Comments
 (0)