* Key frames - Keep track of key frame stats - Split out PLI from down track used for purpose of layer locking. This will give us a good picture of down stream issues forcing a PLI. - Use key frame requester whenever there is a layer lock required. Not just the first key frame. With the synchronous thing, the counter was just ridiculously high like 150 or something because of all the initial padding packets. Also, use RTT in key frame requester. * send first PLI before waiting * Turn off key frame requester when disabled * simplify
57 lines
1.5 KiB
Go
57 lines
1.5 KiB
Go
package sfu
|
|
|
|
import (
|
|
"math"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
"github.com/pion/rtcp"
|
|
"github.com/pion/webrtc/v3"
|
|
)
|
|
|
|
const (
|
|
QuarterResolution = "q"
|
|
HalfResolution = "h"
|
|
FullResolution = "f"
|
|
)
|
|
|
|
// Do a fuzzy find for a codec in the list of codecs
|
|
// Used for lookup up a codec in an existing list to find a match
|
|
func codecParametersFuzzySearch(needle webrtc.RTPCodecParameters, haystack []webrtc.RTPCodecParameters) (webrtc.RTPCodecParameters, error) {
|
|
// First attempt to match on MimeType + SDPFmtpLine
|
|
for _, c := range haystack {
|
|
if strings.EqualFold(c.RTPCodecCapability.MimeType, needle.RTPCodecCapability.MimeType) &&
|
|
c.RTPCodecCapability.SDPFmtpLine == needle.RTPCodecCapability.SDPFmtpLine {
|
|
return c, nil
|
|
}
|
|
}
|
|
|
|
// Fallback to just MimeType
|
|
for _, c := range haystack {
|
|
if strings.EqualFold(c.RTPCodecCapability.MimeType, needle.RTPCodecCapability.MimeType) {
|
|
return c, nil
|
|
}
|
|
}
|
|
|
|
return webrtc.RTPCodecParameters{}, webrtc.ErrCodecNotFound
|
|
}
|
|
|
|
// -----------------------------------------------
|
|
|
|
func getRttMs(report *rtcp.ReceptionReport) uint32 {
|
|
if report.LastSenderReport == 0 {
|
|
return 0
|
|
}
|
|
|
|
// RTT calculation reference: https://datatracker.ietf.org/doc/html/rfc3550#section-6.4.1
|
|
|
|
// middle 32-bits of current NTP time
|
|
now := uint32(buffer.ToNtpTime(time.Now()) >> 16)
|
|
if now < (report.LastSenderReport + report.Delay) {
|
|
return 0
|
|
}
|
|
ntpDiff := now - report.LastSenderReport - report.Delay
|
|
return uint32(math.Ceil(float64(ntpDiff) * 1000.0 / 65536.0))
|
|
}
|