Skip to content

Support flexfec, ulpfec, and any other non-video video codecs. #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ export class PeerConnectionController {
this.peerConnection?.addTransceiver('video', { direction: 'recvonly' });
}

// We can only set preferred codec on Chrome
if (RTCRtpReceiver.getCapabilities && this.preferredCodec != '') {
for (const transceiver of this.peerConnection?.getTransceivers() ?? []) {
if (
Expand All @@ -419,44 +418,36 @@ export class PeerConnectionController {
transceiver.receiver.track.kind === 'video' &&
transceiver.setCodecPreferences
) {
// Get our preferred codec from the codecs options drop down
const preferredRTPCodec = this.preferredCodec.split(' ');
const codecs = [
{
mimeType:
'video/' + preferredRTPCodec[0] /* Name */,
clockRate: 90000,
sdpFmtpLine: preferredRTPCodec[1] /* sdpFmtpLine */
? preferredRTPCodec[1]
: ''
const preferredRTCRtpCodecCapability: RTCRtpCodecCapability = {
mimeType: 'video/' + preferredRTPCodec[0] /* Name */,
clockRate: 90000, /* All current video formats in browsers have 90khz clock rate */
sdpFmtpLine: preferredRTPCodec[1] ? preferredRTPCodec[1] : ''
}

// Populate a list of codecs we will support with our preferred one in the first position
const ourSupportedCodecs: Array<RTCRtpCodecCapability> = [preferredRTCRtpCodecCapability];

// Go through all codecs the browser supports and add them to the list (in any order)
RTCRtpReceiver.getCapabilities('video').codecs.forEach((browserSupportedCodec : RTCRtpCodecCapability) => {
// Don't add our preferred codec again, but add everything else
if(browserSupportedCodec.mimeType != preferredRTCRtpCodecCapability.mimeType) {
ourSupportedCodecs.push(browserSupportedCodec);
}
];

this.config
.getSettingOption(OptionParameters.PreferredCodec)
.options.filter((option) => {
// Remove the preferred codec from the list of possible codecs as we've set it already
return option != this.preferredCodec;
})
.forEach((option) => {
// Amend the rest of the browsers supported codecs
const altCodec = option.split(' ');
codecs.push({
mimeType: 'video/' + altCodec[0] /* Name */,
clockRate: 90000,
sdpFmtpLine: altCodec[1] /* sdpFmtpLine */
? altCodec[1]
: ''
});
});
else if(browserSupportedCodec?.sdpFmtpLine != preferredRTCRtpCodecCapability?.sdpFmtpLine) {
ourSupportedCodecs.push(browserSupportedCodec);
}
});

for (const codec of codecs) {
if (codec.sdpFmtpLine === '') {
for (const codec of ourSupportedCodecs) {
if (codec?.sdpFmtpLine === undefined || codec.sdpFmtpLine === '') {
// We can't dynamically add members to the codec, so instead remove the field if it's empty
delete codec.sdpFmtpLine;
}
}

transceiver.setCodecPreferences(codecs);
transceiver.setCodecPreferences(ourSupportedCodecs);
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions Frontend/ui-library/src/Application/Application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ export class Application {
* Set up button click functions and button functionality
*/
public createButtons() {

// IPhone does not support fullscreen API as at 28th July 2024 (see: https://caniuse.com/fullscreen) so if
// we are on IPhone and user has not specified explicitly configured UI config for
// fullscreen button then we should disable this button as it doesn't work.
if(this._options.fullScreenControlsConfig === undefined && /iPhone/.test(navigator.userAgent)) {
this._options.fullScreenControlsConfig = { creationMode: UIElementCreationMode.Disable };
}

const controlsUIConfig : ControlsUIConfiguration = {
statsButtonType : this._options.statsPanelConfig
? this._options.statsPanelConfig.visibilityButtonConfig
Expand All @@ -195,6 +203,7 @@ export class Application {
fullscreenButtonType: this._options.fullScreenControlsConfig,
xrIconType: this._options.xrControlsConfig
}

// Setup controls
const controls = new Controls(controlsUIConfig);
this.uiFeaturesElement.appendChild(controls.rootElement);
Expand Down
Loading