Add support for "abs-capture-time" extension. (#2640)
* Add support for "abs-capture-time" extension. Currently, it is just passed through from publisher -> subscriber side. TODO: Need to store in sequencer and restore for retransmission. * abs-capture-time in retransmissions * clean up * fix test * more test fixes * more test fixes * more test fixes * log only when size is non-zero * log on both sides for debugging * add marshal/unmarshal * normalize abs capture time to SFU clock * comment out adding abs-capture-time from registered extensions
This commit is contained in:
+81
-11
@@ -35,9 +35,10 @@ import (
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||
dd "github.com/livekit/livekit-server/pkg/sfu/dependencydescriptor"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/pacer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/rtpextension"
|
||||
act "github.com/livekit/livekit-server/pkg/sfu/rtpextension/abscapturetime"
|
||||
dd "github.com/livekit/livekit-server/pkg/sfu/rtpextension/dependencydescriptor"
|
||||
pd "github.com/livekit/livekit-server/pkg/sfu/rtpextension/playoutdelay"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/utils"
|
||||
)
|
||||
|
||||
@@ -237,6 +238,7 @@ type DownTrack struct {
|
||||
transportWideExtID int
|
||||
dependencyDescriptorExtID int
|
||||
playoutDelayExtID int
|
||||
absCaptureTimeExtID int
|
||||
transceiver atomic.Pointer[webrtc.RTPTransceiver]
|
||||
writeStream webrtc.TrackLocalWriter
|
||||
rtcpReader *buffer.RTCPReader
|
||||
@@ -553,7 +555,7 @@ func (d *DownTrack) SetRTPHeaderExtensions(rtpHeaderExtensions []webrtc.RTPHeade
|
||||
}
|
||||
case dd.ExtensionURI:
|
||||
d.dependencyDescriptorExtID = ext.ID
|
||||
case rtpextension.PlayoutDelayURI:
|
||||
case pd.PlayoutDelayURI:
|
||||
d.playoutDelayExtID = ext.ID
|
||||
case sdp.TransportCCURI:
|
||||
if isBWEEnabled {
|
||||
@@ -561,6 +563,8 @@ func (d *DownTrack) SetRTPHeaderExtensions(rtpHeaderExtensions []webrtc.RTPHeade
|
||||
} else {
|
||||
d.transportWideExtID = 0
|
||||
}
|
||||
case act.AbsCaptureTimeURI:
|
||||
d.absCaptureTimeExtID = ext.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -730,13 +734,59 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
||||
|
||||
var extensions []pacer.ExtensionData
|
||||
if tp.ddBytes != nil {
|
||||
extensions = []pacer.ExtensionData{{ID: uint8(d.dependencyDescriptorExtID), Payload: tp.ddBytes}}
|
||||
extensions = append(
|
||||
extensions,
|
||||
pacer.ExtensionData{
|
||||
ID: uint8(d.dependencyDescriptorExtID),
|
||||
Payload: tp.ddBytes,
|
||||
},
|
||||
)
|
||||
}
|
||||
if d.playoutDelayExtID != 0 && d.playoutDelay != nil {
|
||||
if val := d.playoutDelay.GetDelayExtension(hdr.SequenceNumber); val != nil {
|
||||
extensions = append(extensions, pacer.ExtensionData{ID: uint8(d.playoutDelayExtID), Payload: val})
|
||||
extensions = append(
|
||||
extensions,
|
||||
pacer.ExtensionData{
|
||||
ID: uint8(d.playoutDelayExtID),
|
||||
Payload: val,
|
||||
},
|
||||
)
|
||||
|
||||
// NOTE: play out delay extension is not cached in sequencer,
|
||||
// i. e. they will not be added to retransmitted packet.
|
||||
// But, it is okay as the extension is added till a RTCP Receiver Report for
|
||||
// the corresponding sequence number is received.
|
||||
// The extreme case is all packets containing the play out delay are lost and
|
||||
// all of them retransmitted and an RTCP Receiver Report received for those
|
||||
// retransmited sequence numbers. But, that is highly improbable, if not impossible.
|
||||
}
|
||||
}
|
||||
var actBytes []byte
|
||||
if extPkt.AbsCaptureTimeExt != nil && d.absCaptureTimeExtID != 0 {
|
||||
// normalize capture time to SFU clock.
|
||||
// NOTE: even if there is estimated offset populated, just re-map the
|
||||
// absolute capture time stamp as it should be the same RTCP sender report
|
||||
// clock domain of publisher. SFU is normalising sender reports of publisher
|
||||
// to SFU clock before sending to subscribers. So, capture time should be
|
||||
// normalized to the same clock. Clear out any offset.
|
||||
_, _, refSenderReport := d.forwarder.GetSenderReportParams()
|
||||
if refSenderReport != nil {
|
||||
actExtCopy := *extPkt.AbsCaptureTimeExt
|
||||
if err = actExtCopy.Rewrite(refSenderReport.AtAdjusted.Sub(refSenderReport.NTPTimestamp.Time())); err == nil {
|
||||
actBytes, err = actExtCopy.Marshal()
|
||||
if err == nil {
|
||||
extensions = append(
|
||||
extensions,
|
||||
pacer.ExtensionData{
|
||||
ID: uint8(d.absCaptureTimeExtID),
|
||||
Payload: actBytes,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if d.sequencer != nil {
|
||||
d.sequencer.push(
|
||||
extPkt.Arrival,
|
||||
@@ -748,6 +798,7 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
||||
payload[:outgoingHeaderSize],
|
||||
incomingHeaderSize,
|
||||
tp.ddBytes,
|
||||
actBytes,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1715,11 +1766,30 @@ func (d *DownTrack) retransmitPackets(nacks []uint16) {
|
||||
payload = payload[:int(epm.numCodecBytesOut)+len(pkt.Payload)-int(epm.numCodecBytesIn)]
|
||||
}
|
||||
|
||||
var ddBytes []byte
|
||||
if len(epm.ddBytesSlice) != 0 {
|
||||
ddBytes = epm.ddBytesSlice
|
||||
} else {
|
||||
ddBytes = epm.ddBytes[:epm.ddBytesSize]
|
||||
var extensions []pacer.ExtensionData
|
||||
if d.dependencyDescriptorExtID != 0 {
|
||||
var ddBytes []byte
|
||||
if len(epm.ddBytesSlice) != 0 {
|
||||
ddBytes = epm.ddBytesSlice
|
||||
} else {
|
||||
ddBytes = epm.ddBytes[:epm.ddBytesSize]
|
||||
}
|
||||
extensions = append(
|
||||
extensions,
|
||||
pacer.ExtensionData{
|
||||
ID: uint8(d.dependencyDescriptorExtID),
|
||||
Payload: ddBytes,
|
||||
},
|
||||
)
|
||||
}
|
||||
if d.absCaptureTimeExtID != 0 && len(epm.actBytes) != 0 {
|
||||
extensions = append(
|
||||
extensions,
|
||||
pacer.ExtensionData{
|
||||
ID: uint8(d.absCaptureTimeExtID),
|
||||
Payload: epm.actBytes,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
d.sendingPacket(
|
||||
@@ -1735,7 +1805,7 @@ func (d *DownTrack) retransmitPackets(nacks []uint16) {
|
||||
)
|
||||
d.pacer.Enqueue(pacer.Packet{
|
||||
Header: &pkt.Header,
|
||||
Extensions: []pacer.ExtensionData{{ID: uint8(d.dependencyDescriptorExtID), Payload: ddBytes}},
|
||||
Extensions: extensions,
|
||||
Payload: payload,
|
||||
AbsSendTimeExtID: uint8(d.absSendTimeExtID),
|
||||
TransportWideExtID: uint8(d.transportWideExtID),
|
||||
|
||||
Reference in New Issue
Block a user