Process header extensions in line (#635)
* WIP commit * Pass audio config * Fix test compile
This commit is contained in:
+44
-2
@@ -17,8 +17,10 @@ import (
|
||||
"github.com/livekit/protocol/logger"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/audio"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/connectionquality"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/twcc"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -38,6 +40,8 @@ type TrackReceiver interface {
|
||||
ReadRTP(buf []byte, layer uint8, sn uint16) (int, error)
|
||||
GetBitrateTemporalCumulative() Bitrates
|
||||
|
||||
GetAudioLevel() (uint8, bool)
|
||||
|
||||
SendPLI(layer int32)
|
||||
|
||||
SetUpTrackPaused(paused bool)
|
||||
@@ -54,6 +58,7 @@ type WebRTCReceiver struct {
|
||||
logger logger.Logger
|
||||
|
||||
pliThrottleConfig config.PLIThrottleConfig
|
||||
audioConfig config.AudioConfig
|
||||
|
||||
peerID livekit.ParticipantID
|
||||
trackID livekit.TrackID
|
||||
@@ -69,6 +74,8 @@ type WebRTCReceiver struct {
|
||||
|
||||
rtcpCh chan []rtcp.Packet
|
||||
|
||||
twcc *twcc.Responder
|
||||
|
||||
bufferMu sync.RWMutex
|
||||
buffers [DefaultMaxLayerSpatial + 1]*buffer.Buffer
|
||||
rtt uint32
|
||||
@@ -104,14 +111,22 @@ func RidToLayer(rid string) int32 {
|
||||
|
||||
type ReceiverOpts func(w *WebRTCReceiver) *WebRTCReceiver
|
||||
|
||||
// WithPliThrottle indicates minimum time(ms) between sending PLIs
|
||||
func WithPliThrottle(pliThrottleConfig config.PLIThrottleConfig) ReceiverOpts {
|
||||
// WithPliThrottleConfig indicates minimum time(ms) between sending PLIs
|
||||
func WithPliThrottleConfig(pliThrottleConfig config.PLIThrottleConfig) ReceiverOpts {
|
||||
return func(w *WebRTCReceiver) *WebRTCReceiver {
|
||||
w.pliThrottleConfig = pliThrottleConfig
|
||||
return w
|
||||
}
|
||||
}
|
||||
|
||||
// WithAudioConfig sets up parameters for active speaker detection
|
||||
func WithAudioConfig(audioConfig config.AudioConfig) ReceiverOpts {
|
||||
return func(w *WebRTCReceiver) *WebRTCReceiver {
|
||||
w.audioConfig = audioConfig
|
||||
return w
|
||||
}
|
||||
}
|
||||
|
||||
// WithStreamTrackers enables StreamTracker use for simulcast
|
||||
func WithStreamTrackers() ReceiverOpts {
|
||||
return func(w *WebRTCReceiver) *WebRTCReceiver {
|
||||
@@ -139,6 +154,7 @@ func NewWebRTCReceiver(
|
||||
pid livekit.ParticipantID,
|
||||
source livekit.TrackSource,
|
||||
logger logger.Logger,
|
||||
twcc *twcc.Responder,
|
||||
opts ...ReceiverOpts,
|
||||
) *WebRTCReceiver {
|
||||
w := &WebRTCReceiver{
|
||||
@@ -151,6 +167,7 @@ func NewWebRTCReceiver(
|
||||
kind: track.Kind(),
|
||||
// LK-TODO: this should be based on VideoLayers protocol message rather than RID based
|
||||
isSimulcast: len(track.RID()) > 0,
|
||||
twcc: twcc,
|
||||
downTracks: make([]TrackSender, 0),
|
||||
index: make(map[livekit.ParticipantID]int),
|
||||
free: make(map[int]struct{}),
|
||||
@@ -253,6 +270,12 @@ func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buff
|
||||
|
||||
layer := RidToLayer(track.RID())
|
||||
buff.SetLogger(logger.Logger(logr.Logger(w.logger).WithValues("layer", layer)))
|
||||
buff.SetTWCC(w.twcc)
|
||||
buff.SetAudioLevelParams(audio.AudioLevelParams{
|
||||
ActiveLevel: w.audioConfig.ActiveLevel,
|
||||
MinPercentile: w.audioConfig.MinPercentile,
|
||||
ObserveDuration: w.audioConfig.UpdateInterval,
|
||||
})
|
||||
buff.OnFeedback(w.sendRTCP)
|
||||
|
||||
var duration time.Duration
|
||||
@@ -427,6 +450,25 @@ func (w *WebRTCReceiver) GetTrackStats() *livekit.RTPStats {
|
||||
return buffer.AggregateRTPStats(stats)
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) GetAudioLevel() (uint8, bool) {
|
||||
if w.Kind() == webrtc.RTPCodecTypeVideo {
|
||||
return audio.SilentAudioLevel, false
|
||||
}
|
||||
|
||||
w.bufferMu.RLock()
|
||||
defer w.bufferMu.RUnlock()
|
||||
|
||||
for _, buff := range w.buffers {
|
||||
if buff == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
return buff.GetAudioLevel()
|
||||
}
|
||||
|
||||
return audio.SilentAudioLevel, false
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) getQualityParams() *buffer.ConnectionQualityParams {
|
||||
w.bufferMu.RLock()
|
||||
defer w.bufferMu.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user