Add dynamic playout delay if PlayoutDelay enabled in the room (#2403)
* Add dynamic playout delay * type for state
This commit is contained in:
+17
-23
@@ -262,8 +262,7 @@ type DownTrack struct {
|
||||
bytesSent atomic.Uint32
|
||||
bytesRetransmitted atomic.Uint32
|
||||
|
||||
playoutDelayBytes atomic.Value //bytes of marshalled playout delay
|
||||
playoudDelayAcked atomic.Bool
|
||||
playoutDelay *PlayoutDelayController
|
||||
|
||||
pacer pacer.Pacer
|
||||
|
||||
@@ -318,6 +317,14 @@ func NewDownTrack(params DowntrackParams) (*DownTrack, error) {
|
||||
})
|
||||
d.deltaStatsSenderSnapshotId = d.rtpStats.NewSenderSnapshotId()
|
||||
|
||||
if delay := params.PlayoutDelayLimit; delay.GetEnabled() {
|
||||
var err error
|
||||
d.playoutDelay, err = NewPlayoutDelayController(delay.GetMin(), delay.GetMax(), params.Logger, d.rtpStats)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
d.connectionStats = connectionquality.NewConnectionStats(connectionquality.ConnectionStatsParams{
|
||||
MimeType: codecs[0].MimeType, // LK-TODO have to notify on codec change
|
||||
IsFECEnabled: strings.EqualFold(codecs[0].MimeType, webrtc.MimeTypeOpus) && strings.Contains(strings.ToLower(codecs[0].SDPFmtpLine), "fec"),
|
||||
@@ -330,23 +337,6 @@ func NewDownTrack(params DowntrackParams) (*DownTrack, error) {
|
||||
}
|
||||
})
|
||||
|
||||
// set initial playout delay to minimum value
|
||||
if d.params.PlayoutDelayLimit.GetEnabled() {
|
||||
maxDelay := uint32(rtpextension.PlayoutDelayDefaultMax)
|
||||
if d.params.PlayoutDelayLimit.GetMax() > 0 {
|
||||
maxDelay = d.params.PlayoutDelayLimit.GetMax()
|
||||
}
|
||||
delay := rtpextension.PlayoutDelayFromValue(
|
||||
uint16(d.params.PlayoutDelayLimit.GetMin()),
|
||||
uint16(maxDelay),
|
||||
)
|
||||
b, err := delay.Marshal()
|
||||
if err == nil {
|
||||
d.playoutDelayBytes.Store(b)
|
||||
} else {
|
||||
d.params.Logger.Errorw("failed to marshal playout delay", err, "playoutDelay", d.params.PlayoutDelayLimit)
|
||||
}
|
||||
}
|
||||
if d.kind == webrtc.RTPCodecTypeVideo {
|
||||
go d.maxLayerNotifierWorker()
|
||||
go d.keyFrameRequester()
|
||||
@@ -716,9 +706,9 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
||||
if tp.ddBytes != nil {
|
||||
extensions = []pacer.ExtensionData{{ID: uint8(d.dependencyDescriptorExtID), Payload: tp.ddBytes}}
|
||||
}
|
||||
if d.playoutDelayExtID != 0 && !d.playoudDelayAcked.Load() {
|
||||
if val := d.playoutDelayBytes.Load(); val != nil {
|
||||
extensions = append(extensions, pacer.ExtensionData{ID: uint8(d.playoutDelayExtID), Payload: val.([]byte)})
|
||||
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})
|
||||
}
|
||||
}
|
||||
if d.sequencer != nil {
|
||||
@@ -1534,7 +1524,11 @@ func (d *DownTrack) handleRTCP(bytes []byte) {
|
||||
sal.OnRTCPReceiverReport(d, r)
|
||||
}
|
||||
|
||||
d.playoudDelayAcked.Store(true)
|
||||
if d.playoutDelay != nil {
|
||||
jitterMs := uint64(r.Jitter*1e3) / uint64(d.codec.ClockRate)
|
||||
d.playoutDelay.OnSeqAcked(uint16(r.LastSequenceNumber))
|
||||
d.playoutDelay.SetJitter(uint32(jitterMs))
|
||||
}
|
||||
}
|
||||
if len(rr.Reports) > 0 {
|
||||
d.listenerLock.RLock()
|
||||
|
||||
Reference in New Issue
Block a user