Report average bitrates for whip ingress (#4634)

This commit is contained in:
cnderrauber
2026-07-01 17:06:49 +08:00
committed by GitHub
parent fcc46d3c45
commit 46e5caedbe
+50 -28
View File
@@ -12,6 +12,7 @@ import (
"github.com/livekit/livekit-server/pkg/routing" "github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/rtc/types" "github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/sfu/rtpstats"
"github.com/livekit/livekit-server/pkg/telemetry/prometheus" "github.com/livekit/livekit-server/pkg/telemetry/prometheus"
"github.com/livekit/protocol/livekit" "github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger" "github.com/livekit/protocol/logger"
@@ -204,52 +205,73 @@ func (s whipService) sendConnectionNotify(ctx context.Context, participant types
} }
func getMediaStateForParticipant(participant types.Participant) (*livekit.InputVideoState, *livekit.InputAudioState) { func getMediaStateForParticipant(participant types.Participant) (*livekit.InputVideoState, *livekit.InputAudioState) {
pParticipant := participant.ToProto()
var video *livekit.InputVideoState var video *livekit.InputVideoState
var audio *livekit.InputAudioState var audio *livekit.InputAudioState
for _, v := range pParticipant.Tracks { for _, t := range participant.GetPublishedTracks() {
if v == nil { if t == nil {
continue continue
} }
if v.Type != livekit.TrackType_VIDEO { ti := t.ToProto()
if ti == nil {
continue continue
} }
video = &livekit.InputVideoState{} switch t.Kind() {
case livekit.TrackType_VIDEO:
if video != nil {
continue
}
video.MimeType = v.MimeType video = &livekit.InputVideoState{
video.Height = v.Height MimeType: ti.MimeType,
video.Width = v.Width Width: ti.Width,
Height: ti.Height,
AverageBitrate: trackAverageBitrate(t),
}
break case livekit.TrackType_AUDIO:
} if audio != nil {
continue
}
for _, a := range pParticipant.Tracks { channels := uint32(1)
if a == nil { if ti.Stereo {
continue channels = 2
}
audio = &livekit.InputAudioState{
MimeType: ti.MimeType,
Channels: channels,
AverageBitrate: trackAverageBitrate(t),
}
} }
if a.Type != livekit.TrackType_AUDIO {
continue
}
audio = &livekit.InputAudioState{}
audio.MimeType = a.MimeType
audio.Channels = 1
if a.Stereo {
audio.Channels = 2
}
break
} }
return video, audio return video, audio
} }
func trackAverageBitrate(t types.MediaTrack) uint32 {
var allStats []*livekit.RTPStats
for _, r := range t.Receivers() {
if r == nil {
continue
}
if s := r.GetTrackStats(); s != nil {
allStats = append(allStats, s)
}
}
agg := rtpstats.AggregateRTPStats(allStats)
if agg == nil {
return 0
}
return uint32(agg.Bitrate)
}
// ------------------------------------------- // -------------------------------------------
type whipParticipantService struct { type whipParticipantService struct {