@@ -409,7 +409,6 @@ export class PeerConnectionController {
409
409
this . peerConnection ?. addTransceiver ( 'video' , { direction : 'recvonly' } ) ;
410
410
}
411
411
412
- // We can only set preferred codec on Chrome
413
412
if ( RTCRtpReceiver . getCapabilities && this . preferredCodec != '' ) {
414
413
for ( const transceiver of this . peerConnection ?. getTransceivers ( ) ?? [ ] ) {
415
414
if (
@@ -419,44 +418,36 @@ export class PeerConnectionController {
419
418
transceiver . receiver . track . kind === 'video' &&
420
419
transceiver . setCodecPreferences
421
420
) {
421
+ // Get our preferred codec from the codecs options drop down
422
422
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 ) ;
431
437
}
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
+ } ) ;
451
442
452
- for ( const codec of codecs ) {
453
- if ( codec . sdpFmtpLine === '' ) {
443
+ for ( const codec of ourSupportedCodecs ) {
444
+ if ( codec ?. sdpFmtpLine === undefined || codec . sdpFmtpLine === '' ) {
454
445
// We can't dynamically add members to the codec, so instead remove the field if it's empty
455
446
delete codec . sdpFmtpLine ;
456
447
}
457
448
}
458
449
459
- transceiver . setCodecPreferences ( codecs ) ;
450
+ transceiver . setCodecPreferences ( ourSupportedCodecs ) ;
460
451
}
461
452
}
462
453
}
0 commit comments