Skip to content

Commit

Permalink
fix: force single codec
Browse files Browse the repository at this point in the history
- reads the data from the RTCRtpSender when available
  • Loading branch information
oliverlaz committed Nov 22, 2024
1 parent 21ddd95 commit e7a8719
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
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

0 comments on commit e7a8719

Please sign in to comment.