Skip to content
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

fix: force single codec preference in the SDP #1588

Merged
merged 1 commit into from
Nov 22, 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
11 changes: 8 additions & 3 deletions packages/client/src/rtc/Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,14 @@ export class Publisher {
private getCodecPreferences = (
trackType: TrackType,
preferredCodec?: string,
codecPreferencesSource?: 'sender' | 'receiver',
) => {
if (trackType === TrackType.VIDEO) {
return getPreferredCodecs('video', preferredCodec || 'vp8');
return getPreferredCodecs(
'video',
preferredCodec || 'vp8',
codecPreferencesSource,
);
}
if (trackType === TrackType.AUDIO) {
const defaultAudioCodec = this.isRedEnabled ? 'red' : 'opus';
Expand Down Expand Up @@ -575,8 +580,8 @@ export class Publisher {
const opts = this.publishOptsForTrack.get(trackType);
if (!opts || !opts.forceSingleCodec) return sdp;

const codec = opts.forceCodec || opts.preferredCodec;
const orderedCodecs = this.getCodecPreferences(trackType, codec);
const codec = opts.forceCodec || getOptimalVideoCodec(opts.preferredCodec);
const orderedCodecs = this.getCodecPreferences(trackType, codec, 'sender');
if (!orderedCodecs || orderedCodecs.length === 0) return sdp;

const transceiver = this.transceiverCache.get(trackType);
Expand Down
10 changes: 7 additions & 3 deletions packages/client/src/rtc/codecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,19 @@ import type { PreferredCodec } from '../types';
* @param kind the kind of codec to get.
* @param preferredCodec the codec to prioritize (vp8, h264, vp9, av1...).
* @param codecToRemove the codec to exclude from the list.
* @param codecPreferencesSource the source of the codec preferences.
*/
export const getPreferredCodecs = (
kind: 'audio' | 'video',
preferredCodec: string,
codecToRemove?: string,
): RTCRtpCodecCapability[] | undefined => {
if (!('getCapabilities' in RTCRtpReceiver)) return;
codecPreferencesSource: 'sender' | 'receiver' = 'receiver',
): RTCRtpCodec[] | undefined => {
const source =
codecPreferencesSource === 'receiver' ? RTCRtpReceiver : RTCRtpSender;
if (!('getCapabilities' in source)) return;

const capabilities = RTCRtpReceiver.getCapabilities(kind);
const capabilities = source.getCapabilities(kind);
if (!capabilities) return;

const preferred: RTCRtpCodecCapability[] = [];
Expand Down
Loading