Rpcs for ingress proxy WHIP (#3911)

See https://github.com/livekit/protocol/pull/1194
This commit is contained in:
cnderrauber
2025-09-09 22:49:42 +08:00
committed by GitHub
parent 991a4a4f53
commit 76645fad5e
13 changed files with 189 additions and 76 deletions
+4
View File
@@ -45,6 +45,10 @@ func (c ClientInfo) isAndroid() bool {
return c.ClientInfo != nil && strings.EqualFold(c.ClientInfo.Os, "android")
}
func (c ClientInfo) isOBS() bool {
return c.ClientInfo != nil && strings.Contains(c.ClientInfo.Browser, "OBS")
}
func (c ClientInfo) SupportsAudioRED() bool {
return !c.isFirefox() && !c.isSafari()
}
+29 -14
View File
@@ -32,6 +32,7 @@ import (
"github.com/pkg/errors"
"go.uber.org/atomic"
"go.uber.org/zap/zapcore"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/proto"
"github.com/livekit/mediatransportutil/pkg/twcc"
@@ -305,7 +306,7 @@ type ParticipantImpl struct {
migrateState atomic.Value // types.MigrateState
migratedTracksPublishedFuse core.Fuse
onClose func(types.LocalParticipant)
onClose map[string]func(types.LocalParticipant)
onClaimsChanged func(participant types.LocalParticipant)
onICEConfigChanged func(participant types.LocalParticipant, iceConfig *livekit.ICEConfig)
@@ -359,6 +360,7 @@ func NewParticipant(params ParticipantParams) (*ParticipantImpl, error) {
joiningMessageFirstSeqs: make(map[livekit.ParticipantID]uint32),
joiningMessageLastWrittenSeqs: make(map[livekit.ParticipantID]uint32),
},
onClose: make(map[string]func(types.LocalParticipant)),
}
p.setupSignalling()
@@ -1048,14 +1050,18 @@ func (p *ParticipantImpl) getOnLeave() func(types.LocalParticipant, types.Partic
return p.onLeave
}
func (p *ParticipantImpl) OnClose(callback func(types.LocalParticipant)) {
func (p *ParticipantImpl) AddOnClose(key string, callback func(types.LocalParticipant)) {
if p.isClosed.Load() {
go callback(p)
return
}
p.lock.Lock()
p.onClose = callback
if callback == nil {
delete(p.onClose, key)
} else {
p.onClose[key] = callback
}
p.lock.Unlock()
}
@@ -1505,10 +1511,10 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
// ensure this is synchronized
p.CloseSignalConnection(types.SignallingCloseReasonParticipantClose)
p.lock.RLock()
onClose := p.onClose
onClose := maps.Values(p.onClose)
p.lock.RUnlock()
if onClose != nil {
onClose(p)
for _, cb := range onClose {
cb(p)
}
// Close peer connections without blocking participant Close. If peer connections are gathering candidates
@@ -2851,9 +2857,14 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
if len(req.SimulcastCodecs) == 0 {
// clients not supporting simulcast codecs, synthesise a codec
videoLayerMode := livekit.VideoLayer_MODE_UNUSED
if p.params.ClientInfo.isOBS() {
videoLayerMode = livekit.VideoLayer_ONE_SPATIAL_LAYER_PER_STREAM_INCOMPLETE_RTCP_SR
}
ti.Codecs = append(ti.Codecs, &livekit.SimulcastCodecInfo{
Cid: req.Cid,
Layers: cloneLayers(req.Layers),
Cid: req.Cid,
Layers: cloneLayers(req.Layers),
VideoLayerMode: videoLayerMode,
})
} else {
seenCodecs := make(map[string]struct{})
@@ -2888,7 +2899,11 @@ func (p *ParticipantImpl) addPendingTrackLocked(req *livekit.AddTrackRequest) *l
if mime.IsMimeTypeStringSVC(mimeType) {
videoLayerMode = livekit.VideoLayer_MULTIPLE_SPATIAL_LAYERS_PER_STREAM
} else {
videoLayerMode = livekit.VideoLayer_ONE_SPATIAL_LAYER_PER_STREAM
if p.params.ClientInfo.isOBS() {
videoLayerMode = livekit.VideoLayer_ONE_SPATIAL_LAYER_PER_STREAM_INCOMPLETE_RTCP_SR
} else {
videoLayerMode = livekit.VideoLayer_ONE_SPATIAL_LAYER_PER_STREAM
}
}
}
} else if req.Type == livekit.TrackType_AUDIO {
@@ -3966,8 +3981,8 @@ func (p *ParticipantImpl) SupportsMoving() error {
return ErrMoveOldClientVersion
}
if kind := p.Kind(); kind == livekit.ParticipantInfo_EGRESS || kind == livekit.ParticipantInfo_AGENT {
return fmt.Errorf("%s participants cannot be moved", kind.String())
if kind := p.Kind(); kind == livekit.ParticipantInfo_EGRESS || kind == livekit.ParticipantInfo_AGENT || p.params.UseOneShotSignallingMode {
return fmt.Errorf("%s participants cannot be moved, one-shot signaling mode: %t", kind.String(), p.params.UseOneShotSignallingMode)
}
return nil
@@ -3977,10 +3992,10 @@ func (p *ParticipantImpl) MoveToRoom(params types.MoveToRoomParams) {
// fire onClose callback for original room
p.lock.Lock()
onClose := p.onClose
p.onClose = nil
p.onClose = make(map[string]func(types.LocalParticipant))
p.lock.Unlock()
if onClose != nil {
onClose(p)
for _, cb := range onClose {
cb(p)
}
for _, track := range p.GetPublishedTracks() {
+7 -1
View File
@@ -265,6 +265,12 @@ func (s SignallingCloseReason) String() string {
}
}
// ---------------------------------------------
const (
ParticipantCloseKeyNormal = "normal"
ParticipantCloseKeyWHIP = "whip"
)
// ---------------------------------------------
//counterfeiter:generate . Participant
@@ -470,7 +476,7 @@ type LocalParticipant interface {
OnDataPacket(callback func(LocalParticipant, livekit.DataPacket_Kind, *livekit.DataPacket))
OnDataMessage(callback func(LocalParticipant, []byte))
OnSubscribeStatusChanged(fn func(publisherID livekit.ParticipantID, subscribed bool))
OnClose(callback func(LocalParticipant))
AddOnClose(key string, callback func(LocalParticipant))
OnClaimsChanged(callback func(LocalParticipant))
OnUpdateSubscriptions(func(
LocalParticipant,
@@ -21,6 +21,12 @@ import (
)
type FakeLocalParticipant struct {
AddOnCloseStub func(string, func(types.LocalParticipant))
addOnCloseMutex sync.RWMutex
addOnCloseArgsForCall []struct {
arg1 string
arg2 func(types.LocalParticipant)
}
AddTrackStub func(*livekit.AddTrackRequest)
addTrackMutex sync.RWMutex
addTrackArgsForCall []struct {
@@ -849,11 +855,6 @@ type FakeLocalParticipant struct {
onClaimsChangedArgsForCall []struct {
arg1 func(types.LocalParticipant)
}
OnCloseStub func(func(types.LocalParticipant))
onCloseMutex sync.RWMutex
onCloseArgsForCall []struct {
arg1 func(types.LocalParticipant)
}
OnDataMessageStub func(func(types.LocalParticipant, []byte))
onDataMessageMutex sync.RWMutex
onDataMessageArgsForCall []struct {
@@ -1426,6 +1427,39 @@ type FakeLocalParticipant struct {
invocationsMutex sync.RWMutex
}
func (fake *FakeLocalParticipant) AddOnClose(arg1 string, arg2 func(types.LocalParticipant)) {
fake.addOnCloseMutex.Lock()
fake.addOnCloseArgsForCall = append(fake.addOnCloseArgsForCall, struct {
arg1 string
arg2 func(types.LocalParticipant)
}{arg1, arg2})
stub := fake.AddOnCloseStub
fake.recordInvocation("AddOnClose", []interface{}{arg1, arg2})
fake.addOnCloseMutex.Unlock()
if stub != nil {
fake.AddOnCloseStub(arg1, arg2)
}
}
func (fake *FakeLocalParticipant) AddOnCloseCallCount() int {
fake.addOnCloseMutex.RLock()
defer fake.addOnCloseMutex.RUnlock()
return len(fake.addOnCloseArgsForCall)
}
func (fake *FakeLocalParticipant) AddOnCloseCalls(stub func(string, func(types.LocalParticipant))) {
fake.addOnCloseMutex.Lock()
defer fake.addOnCloseMutex.Unlock()
fake.AddOnCloseStub = stub
}
func (fake *FakeLocalParticipant) AddOnCloseArgsForCall(i int) (string, func(types.LocalParticipant)) {
fake.addOnCloseMutex.RLock()
defer fake.addOnCloseMutex.RUnlock()
argsForCall := fake.addOnCloseArgsForCall[i]
return argsForCall.arg1, argsForCall.arg2
}
func (fake *FakeLocalParticipant) AddTrack(arg1 *livekit.AddTrackRequest) {
fake.addTrackMutex.Lock()
fake.addTrackArgsForCall = append(fake.addTrackArgsForCall, struct {
@@ -5822,38 +5856,6 @@ func (fake *FakeLocalParticipant) OnClaimsChangedArgsForCall(i int) func(types.L
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) OnClose(arg1 func(types.LocalParticipant)) {
fake.onCloseMutex.Lock()
fake.onCloseArgsForCall = append(fake.onCloseArgsForCall, struct {
arg1 func(types.LocalParticipant)
}{arg1})
stub := fake.OnCloseStub
fake.recordInvocation("OnClose", []interface{}{arg1})
fake.onCloseMutex.Unlock()
if stub != nil {
fake.OnCloseStub(arg1)
}
}
func (fake *FakeLocalParticipant) OnCloseCallCount() int {
fake.onCloseMutex.RLock()
defer fake.onCloseMutex.RUnlock()
return len(fake.onCloseArgsForCall)
}
func (fake *FakeLocalParticipant) OnCloseCalls(stub func(func(types.LocalParticipant))) {
fake.onCloseMutex.Lock()
defer fake.onCloseMutex.Unlock()
fake.OnCloseStub = stub
}
func (fake *FakeLocalParticipant) OnCloseArgsForCall(i int) func(types.LocalParticipant) {
fake.onCloseMutex.RLock()
defer fake.onCloseMutex.RUnlock()
argsForCall := fake.onCloseArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) OnDataMessage(arg1 func(types.LocalParticipant, []byte)) {
fake.onDataMessageMutex.Lock()
fake.onDataMessageArgsForCall = append(fake.onDataMessageArgsForCall, struct {