@@ -10,6 +10,8 @@ import type {
1010 RtpCapabilities ,
1111 MediaKind ,
1212 ExtendedRtpCapabilities ,
13+ RtpHeaderExtensionUri ,
14+ RtpHeaderExtensionDirection ,
1315} from '../RtpParameters' ;
1416import type { SctpCapabilities , SctpStreamParameters } from '../SctpParameters' ;
1517import * as sdpCommonUtils from './sdp/commonUtils' ;
@@ -126,7 +128,12 @@ export class Chrome111
126128 }
127129
128130 private static getLocalRtpCapabilities (
129- localSdpObject : SdpTransform . SessionDescription
131+ localSdpObject : SdpTransform . SessionDescription ,
132+ extraHeaderExtensions : {
133+ uri : RtpHeaderExtensionUri ;
134+ kind : MediaKind ;
135+ direction : RtpHeaderExtensionDirection ;
136+ } [ ] = [ ]
130137 ) : RtpCapabilities {
131138 const nativeRtpCapabilities = sdpCommonUtils . extractRtpCapabilities ( {
132139 sdpObject : localSdpObject ,
@@ -138,6 +145,13 @@ export class Chrome111
138145 // libwebrtc supports NACK for OPUS but doesn't announce it.
139146 ortcUtils . addNackSupportForOpus ( nativeRtpCapabilities ) ;
140147
148+ for ( const headerExtension of extraHeaderExtensions ) {
149+ ortcUtils . addHeaderExtensionSupport (
150+ nativeRtpCapabilities ,
151+ headerExtension
152+ ) ;
153+ }
154+
141155 return nativeRtpCapabilities ;
142156 }
143157
@@ -324,6 +338,7 @@ export class Chrome111
324338 track,
325339 encodings,
326340 codecOptions,
341+ headerExtensionOptions,
327342 codec,
328343 onRtpSender,
329344 } : HandlerSendOptions ) : Promise < HandlerSendResult > {
@@ -367,15 +382,30 @@ export class Chrome111
367382 onRtpSender ( transceiver . sender ) ;
368383 }
369384
370- const offer = await this . _pc . createOffer ( ) ;
385+ let offer = await this . _pc . createOffer ( ) ;
371386 let localSdpObject = sdpTransform . parse ( offer . sdp ! ) ;
372387
373388 if ( localSdpObject . extmapAllowMixed ) {
374389 this . _remoteSdp . setSessionExtmapAllowMixed ( ) ;
375390 }
376391
377- const nativeRtpCapabilities =
378- Chrome111 . getLocalRtpCapabilities ( localSdpObject ) ;
392+ const extraHeaderExtensions : {
393+ uri : RtpHeaderExtensionUri ;
394+ kind : MediaKind ;
395+ direction : RtpHeaderExtensionDirection ;
396+ } [ ] = [ ] ;
397+
398+ extraHeaderExtensions . push ( {
399+ uri : 'http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time' ,
400+ kind : track . kind as MediaKind ,
401+ direction : 'sendonly' ,
402+ } ) ;
403+
404+ const nativeRtpCapabilities = Chrome111 . getLocalRtpCapabilities (
405+ localSdpObject ,
406+ extraHeaderExtensions
407+ ) ;
408+
379409 const sendExtendedRtpCapabilities = this . _getSendExtendedRtpCapabilities (
380410 nativeRtpCapabilities
381411 ) ;
@@ -411,6 +441,27 @@ export class Chrome111
411441 } ) ;
412442 }
413443
444+ // Optimize. Only generate new offer if needed.
445+ if ( headerExtensionOptions ?. absCaptureTime ) {
446+ const offerMediaObject = localSdpObject . media [ mediaSectionIdx . idx ] ! ;
447+
448+ sdpCommonUtils . addHeaderExtension ( {
449+ offerMediaObject,
450+ headerExtensionUri :
451+ 'http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time' ,
452+ headerExtensionId : sendingRemoteRtpParameters . headerExtensions ! . find (
453+ headerExtension =>
454+ headerExtension . uri ===
455+ 'http://www.webrtc.org/experiments/rtp-hdrext/abs-capture-time'
456+ ) ! . id ,
457+ } ) ;
458+
459+ offer = {
460+ type : 'offer' ,
461+ sdp : sdpTransform . write ( localSdpObject ) ,
462+ } ;
463+ }
464+
414465 logger . debug ( 'send() | calling pc.setLocalDescription() [offer:%o]' , offer ) ;
415466
416467 await this . _pc . setLocalDescription ( offer ) ;
0 commit comments