Signalling V2 protocol implementation start (#3794)
* WIP * name * refactor validate * WIP * WIP * signal cache initial impl * HandleConnect in room manager * generate subscriber offer * handle ConnectRequest as stand alone * segmentation, reassembly * clean up * rearrange * lock scope * support metadata in connect request * prom * add SifTrailer to ConnectResponse * prom for get offer error counter * RtcInit counter * Jie feedback * signal client * consolidate v1 and v2 into SignalClient * clean up * comment * deps * mage generate * fix tests * pass around roomName and participantIdentity * mage generate
This commit is contained in:
+25
-23
@@ -197,6 +197,7 @@ type ParticipantParams struct {
|
||||
DisableSenderReportPassThrough bool
|
||||
MetricConfig metric.MetricConfig
|
||||
UseOneShotSignallingMode bool
|
||||
SynchronousLocalCandidatesMode bool
|
||||
EnableMetrics bool
|
||||
DataChannelMaxBufferedAmount uint64
|
||||
DatachannelSlowThreshold int
|
||||
@@ -1778,29 +1779,30 @@ func (p *ParticipantImpl) setupTransportManager() error {
|
||||
params := TransportManagerParams{
|
||||
// primary connection does not change, canSubscribe can change if permission was updated
|
||||
// after the participant has joined
|
||||
SubscriberAsPrimary: subscriberAsPrimary,
|
||||
Config: p.params.Config,
|
||||
Twcc: p.twcc,
|
||||
ProtocolVersion: p.params.ProtocolVersion,
|
||||
CongestionControlConfig: p.params.CongestionControlConfig,
|
||||
EnabledPublishCodecs: p.enabledPublishCodecs,
|
||||
EnabledSubscribeCodecs: p.enabledSubscribeCodecs,
|
||||
SimTracks: p.params.SimTracks,
|
||||
ClientInfo: p.params.ClientInfo,
|
||||
Migration: p.params.Migration,
|
||||
AllowTCPFallback: p.params.AllowTCPFallback,
|
||||
TCPFallbackRTTThreshold: p.params.TCPFallbackRTTThreshold,
|
||||
AllowUDPUnstableFallback: p.params.AllowUDPUnstableFallback,
|
||||
TURNSEnabled: p.params.TURNSEnabled,
|
||||
AllowPlayoutDelay: p.params.PlayoutDelay.GetEnabled(),
|
||||
DataChannelMaxBufferedAmount: p.params.DataChannelMaxBufferedAmount,
|
||||
DatachannelSlowThreshold: p.params.DatachannelSlowThreshold,
|
||||
Logger: p.params.Logger.WithComponent(sutils.ComponentTransport),
|
||||
PublisherHandler: pth,
|
||||
SubscriberHandler: sth,
|
||||
DataChannelStats: p.dataChannelStats,
|
||||
UseOneShotSignallingMode: p.params.UseOneShotSignallingMode,
|
||||
FireOnTrackBySdp: p.params.FireOnTrackBySdp,
|
||||
SubscriberAsPrimary: subscriberAsPrimary,
|
||||
Config: p.params.Config,
|
||||
Twcc: p.twcc,
|
||||
ProtocolVersion: p.params.ProtocolVersion,
|
||||
CongestionControlConfig: p.params.CongestionControlConfig,
|
||||
EnabledPublishCodecs: p.enabledPublishCodecs,
|
||||
EnabledSubscribeCodecs: p.enabledSubscribeCodecs,
|
||||
SimTracks: p.params.SimTracks,
|
||||
ClientInfo: p.params.ClientInfo,
|
||||
Migration: p.params.Migration,
|
||||
AllowTCPFallback: p.params.AllowTCPFallback,
|
||||
TCPFallbackRTTThreshold: p.params.TCPFallbackRTTThreshold,
|
||||
AllowUDPUnstableFallback: p.params.AllowUDPUnstableFallback,
|
||||
TURNSEnabled: p.params.TURNSEnabled,
|
||||
AllowPlayoutDelay: p.params.PlayoutDelay.GetEnabled(),
|
||||
DataChannelMaxBufferedAmount: p.params.DataChannelMaxBufferedAmount,
|
||||
DatachannelSlowThreshold: p.params.DatachannelSlowThreshold,
|
||||
Logger: p.params.Logger.WithComponent(sutils.ComponentTransport),
|
||||
PublisherHandler: pth,
|
||||
SubscriberHandler: sth,
|
||||
DataChannelStats: p.dataChannelStats,
|
||||
UseOneShotSignallingMode: p.params.UseOneShotSignallingMode,
|
||||
SynchronousLocalCandidatesMode: p.params.SynchronousLocalCandidatesMode,
|
||||
FireOnTrackBySdp: p.params.FireOnTrackBySdp,
|
||||
}
|
||||
if p.params.SyncStreams && p.params.PlayoutDelay.GetEnabled() && p.params.ClientInfo.isFirefox() {
|
||||
// we will disable playout delay for Firefox if the user is expecting
|
||||
|
||||
+234
-16
@@ -143,7 +143,7 @@ type Room struct {
|
||||
|
||||
userPacketDeduper *UserPacketDeduper
|
||||
|
||||
dataMessagecache *utils.TimeSizeCache[types.DataMessageCache]
|
||||
dataMessageCache *utils.TimeSizeCache[types.DataMessageCache]
|
||||
}
|
||||
|
||||
type ParticipantOptions struct {
|
||||
@@ -273,7 +273,7 @@ func NewRoom(
|
||||
disconnectSignalOnResumeParticipants: make(map[livekit.ParticipantIdentity]time.Time),
|
||||
disconnectSignalOnResumeNoMessagesParticipants: make(map[livekit.ParticipantIdentity]*disconnectSignalOnResumeNoMessages),
|
||||
userPacketDeduper: NewUserPacketDeduper(),
|
||||
dataMessagecache: utils.NewTimeSizeCache[types.DataMessageCache](utils.TimeSizeCacheParams{
|
||||
dataMessageCache: utils.NewTimeSizeCache[types.DataMessageCache](utils.TimeSizeCacheParams{
|
||||
TTL: dataMessageCacheTTL,
|
||||
MaxSize: dataMessageCacheSize,
|
||||
}),
|
||||
@@ -426,7 +426,12 @@ func (r *Room) Release() {
|
||||
r.holds.Dec()
|
||||
}
|
||||
|
||||
func (r *Room) Join(participant types.LocalParticipant, requestSource routing.MessageSource, opts *ParticipantOptions, iceServers []*livekit.ICEServer) error {
|
||||
func (r *Room) Join(
|
||||
participant types.LocalParticipant,
|
||||
requestSource routing.MessageSource,
|
||||
opts *ParticipantOptions,
|
||||
iceServers []*livekit.ICEServer,
|
||||
) error {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
@@ -464,7 +469,7 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
||||
defer onStateChangeMu.Unlock()
|
||||
if state := p.State(); state == livekit.ParticipantInfo_ACTIVE {
|
||||
// subscribe participant to existing published tracks
|
||||
r.subscribeToExistingTracks(p)
|
||||
r.subscribeToExistingTracks(p, false)
|
||||
|
||||
connectTime := time.Since(p.ConnectedAt())
|
||||
meta := &livekit.AnalyticsClientMeta{
|
||||
@@ -503,7 +508,7 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
||||
}
|
||||
})
|
||||
participant.OnSubscriberReady(func(p types.LocalParticipant) {
|
||||
r.subscribeToExistingTracks(p)
|
||||
r.subscribeToExistingTracks(p, false)
|
||||
})
|
||||
// it's important to set this before connection, we don't want to miss out on any published tracks
|
||||
participant.OnTrackPublished(r.onTrackPublished)
|
||||
@@ -550,7 +555,8 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
||||
|
||||
r.launchTargetAgents(maps.Values(r.agentDispatches), participant, livekit.JobType_JT_PARTICIPANT)
|
||||
|
||||
r.logger.Debugw("new participant joined",
|
||||
r.logger.Debugw(
|
||||
"new participant joined",
|
||||
"pID", participant.ID(),
|
||||
"participant", participant.Identity(),
|
||||
"clientInfo", logger.Proto(participant.GetClientInfo()),
|
||||
@@ -591,7 +597,7 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
||||
// initiates sub connection as primary
|
||||
if participant.ProtocolVersion().SupportFastStart() {
|
||||
go func() {
|
||||
r.subscribeToExistingTracks(participant)
|
||||
r.subscribeToExistingTracks(participant, false)
|
||||
participant.Negotiate(true)
|
||||
}()
|
||||
} else {
|
||||
@@ -604,6 +610,193 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
|
||||
return nil
|
||||
}
|
||||
|
||||
// SIGNALLING-V2-TODO: consolidate common parts between this function and Join()
|
||||
func (r *Room) Joinv2(
|
||||
participant types.LocalParticipant,
|
||||
opts *ParticipantOptions,
|
||||
iceServers []*livekit.ICEServer,
|
||||
) (*livekit.ConnectResponse, error) {
|
||||
connectResponse, err := func() (*livekit.ConnectResponse, error) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
if r.IsClosed() {
|
||||
return nil, ErrRoomClosed
|
||||
}
|
||||
|
||||
if r.participants[participant.Identity()] != nil {
|
||||
return nil, ErrAlreadyJoined
|
||||
}
|
||||
if r.protoRoom.MaxParticipants > 0 && !participant.IsDependent() {
|
||||
numParticipants := uint32(0)
|
||||
for _, p := range r.participants {
|
||||
if !p.IsDependent() {
|
||||
numParticipants++
|
||||
}
|
||||
}
|
||||
if numParticipants >= r.protoRoom.MaxParticipants {
|
||||
return nil, ErrMaxParticipantsExceeded
|
||||
}
|
||||
}
|
||||
|
||||
if r.FirstJoinedAt() == 0 && !participant.IsDependent() {
|
||||
r.joinedAt.Store(time.Now().Unix())
|
||||
}
|
||||
|
||||
var onStateChangeMu sync.Mutex
|
||||
participant.OnStateChange(func(p types.LocalParticipant) {
|
||||
if r.onParticipantChanged != nil {
|
||||
r.onParticipantChanged(p)
|
||||
}
|
||||
r.broadcastParticipantState(p, broadcastOptions{skipSource: true})
|
||||
|
||||
onStateChangeMu.Lock()
|
||||
defer onStateChangeMu.Unlock()
|
||||
if state := p.State(); state == livekit.ParticipantInfo_ACTIVE {
|
||||
// subscribe participant to existing published tracks
|
||||
r.subscribeToExistingTracks(p, false)
|
||||
|
||||
connectTime := time.Since(p.ConnectedAt())
|
||||
meta := &livekit.AnalyticsClientMeta{
|
||||
ClientConnectTime: uint32(connectTime.Milliseconds()),
|
||||
}
|
||||
infos := p.GetICEConnectionInfo()
|
||||
var connectionType roomobs.ConnectionType
|
||||
for _, info := range infos {
|
||||
if info.Type != types.ICEConnectionTypeUnknown {
|
||||
meta.ConnectionType = info.Type.String()
|
||||
connectionType = info.Type.ReporterType()
|
||||
break
|
||||
}
|
||||
}
|
||||
r.telemetry.ParticipantActive(context.Background(),
|
||||
r.ToProto(),
|
||||
p.ToProto(),
|
||||
meta,
|
||||
false,
|
||||
)
|
||||
|
||||
participant.GetReporter().Tx(func(tx roomobs.ParticipantSessionTx) {
|
||||
tx.ReportClientConnectTime(uint16(connectTime.Milliseconds()))
|
||||
tx.ReportConnectResult(roomobs.ConnectionResultSuccess)
|
||||
tx.ReportConnectionType(connectionType)
|
||||
})
|
||||
|
||||
fields := append(
|
||||
connectionDetailsFields(infos),
|
||||
"clientInfo", logger.Proto(sutils.ClientInfoWithoutAddress(p.GetClientInfo())),
|
||||
)
|
||||
p.GetLogger().Infow("participant active", fields...)
|
||||
} else if state == livekit.ParticipantInfo_DISCONNECTED {
|
||||
// remove participant from room
|
||||
go r.RemoveParticipant(p.Identity(), p.ID(), p.CloseReason())
|
||||
}
|
||||
})
|
||||
participant.OnSubscriberReady(func(p types.LocalParticipant) {
|
||||
r.subscribeToExistingTracks(p, false)
|
||||
})
|
||||
// it's important to set this before connection, we don't want to miss out on any published tracks
|
||||
participant.OnTrackPublished(r.onTrackPublished)
|
||||
participant.OnTrackUpdated(r.onTrackUpdated)
|
||||
participant.OnTrackUnpublished(r.onTrackUnpublished)
|
||||
participant.OnParticipantUpdate(r.onParticipantUpdate)
|
||||
participant.OnDataPacket(r.onDataPacket)
|
||||
participant.OnDataMessage(r.onDataMessage)
|
||||
participant.OnMetrics(r.onMetrics)
|
||||
participant.OnSubscribeStatusChanged(func(publisherID livekit.ParticipantID, subscribed bool) {
|
||||
if subscribed {
|
||||
pub := r.GetParticipantByID(publisherID)
|
||||
if pub != nil && pub.State() == livekit.ParticipantInfo_ACTIVE {
|
||||
// when a participant subscribes to another participant,
|
||||
// send speaker update if the subscribed to participant is active.
|
||||
level, active := pub.GetAudioLevel()
|
||||
if active {
|
||||
_ = participant.SendSpeakerUpdate([]*livekit.SpeakerInfo{
|
||||
{
|
||||
Sid: string(pub.ID()),
|
||||
Level: float32(level),
|
||||
Active: active,
|
||||
},
|
||||
}, false)
|
||||
}
|
||||
|
||||
if cq := pub.GetConnectionQuality(); cq != nil {
|
||||
update := &livekit.ConnectionQualityUpdate{}
|
||||
update.Updates = append(update.Updates, cq)
|
||||
_ = participant.SendConnectionQualityUpdate(update)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// no longer subscribed to the publisher, clear speaker status
|
||||
_ = participant.SendSpeakerUpdate([]*livekit.SpeakerInfo{
|
||||
{
|
||||
Sid: string(publisherID),
|
||||
Level: 0,
|
||||
Active: false,
|
||||
},
|
||||
}, true)
|
||||
}
|
||||
})
|
||||
|
||||
r.launchTargetAgents(maps.Values(r.agentDispatches), participant, livekit.JobType_JT_PARTICIPANT)
|
||||
|
||||
r.logger.Debugw(
|
||||
"new participant joined",
|
||||
"pID", participant.ID(),
|
||||
"participant", participant.Identity(),
|
||||
"clientInfo", logger.Proto(participant.GetClientInfo()),
|
||||
"options", opts,
|
||||
"numParticipants", len(r.participants),
|
||||
)
|
||||
|
||||
if participant.IsRecorder() && !r.protoRoom.ActiveRecording {
|
||||
r.protoRoom.ActiveRecording = true
|
||||
r.protoProxy.MarkDirty(true)
|
||||
} else {
|
||||
r.protoProxy.MarkDirty(false)
|
||||
}
|
||||
|
||||
r.participants[participant.Identity()] = participant
|
||||
r.participantOpts[participant.Identity()] = opts
|
||||
|
||||
if r.onParticipantChanged != nil {
|
||||
r.onParticipantChanged(participant)
|
||||
}
|
||||
|
||||
time.AfterFunc(time.Minute, func() {
|
||||
if !participant.Verify() {
|
||||
r.RemoveParticipant(participant.Identity(), participant.ID(), types.ParticipantCloseReasonJoinTimeout)
|
||||
}
|
||||
})
|
||||
|
||||
connectResponse := r.createConnectResponseLocked(participant, iceServers)
|
||||
|
||||
participant.SetMigrateState(types.MigrateStateComplete)
|
||||
|
||||
return connectResponse, nil
|
||||
}()
|
||||
if err != nil {
|
||||
return connectResponse, err
|
||||
}
|
||||
|
||||
// SIGNALLING-V2-TODO
|
||||
// 1. process published audio_tracks
|
||||
// 2. process published video_tracks
|
||||
// 3. HandleOffer and get answer (publisher)
|
||||
|
||||
r.subscribeToExistingTracks(participant, true)
|
||||
offer, err := participant.GetOffer()
|
||||
if err != nil {
|
||||
participant.GetLogger().Warnw("could not get offer", err)
|
||||
prometheus.ServiceOperationCounter.WithLabelValues("participant_join", "error", "get_subscriber_offer").Add(1)
|
||||
return nil, err
|
||||
}
|
||||
connectResponse.SubscriberSdp = ToProtoSessionDescription(offer, 0) // SIGNALLING-V2-TODO - need to proper offerId?
|
||||
|
||||
prometheus.ServiceOperationCounter.WithLabelValues("participant_join", "success", "").Add(1)
|
||||
return connectResponse, nil
|
||||
}
|
||||
|
||||
func (r *Room) ReplaceParticipantRequestSource(identity livekit.ParticipantIdentity, reqSource routing.MessageSource) {
|
||||
r.lock.Lock()
|
||||
if rs, ok := r.participantRequestSources[identity]; ok {
|
||||
@@ -790,7 +983,7 @@ func (r *Room) UpdateSubscriptions(
|
||||
// handle subscription changes
|
||||
for _, trackID := range trackIDs {
|
||||
if subscribe {
|
||||
participant.SubscribeToTrack(trackID)
|
||||
participant.SubscribeToTrack(trackID, false)
|
||||
} else {
|
||||
participant.UnsubscribeFromTrack(trackID)
|
||||
}
|
||||
@@ -799,7 +992,7 @@ func (r *Room) UpdateSubscriptions(
|
||||
for _, pt := range participantTracks {
|
||||
for _, trackID := range livekit.StringsAsIDs[livekit.TrackID](pt.TrackSids) {
|
||||
if subscribe {
|
||||
participant.SubscribeToTrack(trackID)
|
||||
participant.SubscribeToTrack(trackID, false)
|
||||
} else {
|
||||
participant.UnsubscribeFromTrack(trackID)
|
||||
}
|
||||
@@ -1193,6 +1386,30 @@ func (r *Room) createJoinResponseLocked(participant types.LocalParticipant, iceS
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Room) createConnectResponseLocked(
|
||||
participant types.LocalParticipant,
|
||||
iceServers []*livekit.ICEServer,
|
||||
) *livekit.ConnectResponse {
|
||||
iceConfig := participant.GetICEConfig()
|
||||
hasICEFallback := iceConfig.GetPreferencePublisher() != livekit.ICECandidateType_ICT_NONE || iceConfig.GetPreferenceSubscriber() != livekit.ICECandidateType_ICT_NONE
|
||||
return &livekit.ConnectResponse{
|
||||
Room: r.ToProto(),
|
||||
Participant: participant.ToProto(),
|
||||
OtherParticipants: GetOtherParticipantInfo(
|
||||
participant,
|
||||
false, // isMigratingIn
|
||||
toParticipants(maps.Values(r.participants)),
|
||||
false, // skipSubscriberBroadcast
|
||||
),
|
||||
IceServers: iceServers,
|
||||
ClientConfiguration: participant.GetClientConfiguration(),
|
||||
ServerInfo: r.serverInfo,
|
||||
SifTrailer: r.trailer,
|
||||
EnabledPublishCodecs: participant.GetEnabledPublishCodecs(),
|
||||
FastPublish: participant.CanPublish() && !hasICEFallback,
|
||||
}
|
||||
}
|
||||
|
||||
// a ParticipantImpl in the room added a new track, subscribe other participants to it
|
||||
func (r *Room) onTrackPublished(participant types.LocalParticipant, track types.MediaTrack) {
|
||||
// publish participant update, since track state is changed
|
||||
@@ -1213,13 +1430,14 @@ func (r *Room) onTrackPublished(participant types.LocalParticipant, track types.
|
||||
continue
|
||||
}
|
||||
|
||||
r.logger.Debugw("subscribing to new track",
|
||||
r.logger.Debugw(
|
||||
"subscribing to new track",
|
||||
"participant", existingParticipant.Identity(),
|
||||
"pID", existingParticipant.ID(),
|
||||
"publisher", participant.Identity(),
|
||||
"publisherID", participant.ID(),
|
||||
"trackID", track.ID())
|
||||
existingParticipant.SubscribeToTrack(track.ID())
|
||||
existingParticipant.SubscribeToTrack(track.ID(), false)
|
||||
}
|
||||
onParticipantChanged := r.onParticipantChanged
|
||||
r.lock.RUnlock()
|
||||
@@ -1307,7 +1525,7 @@ func (r *Room) onDataPacket(source types.LocalParticipant, kind livekit.DataPack
|
||||
r.logger.Errorw("failed to marshal data packet for cache", err, "participant", source.Identity(), "seq", dp.GetSequence())
|
||||
return
|
||||
}
|
||||
r.dataMessagecache.Add(&types.DataMessageCache{
|
||||
r.dataMessageCache.Add(&types.DataMessageCache{
|
||||
SenderID: source.ID(),
|
||||
Seq: dp.GetSequence(),
|
||||
Data: data,
|
||||
@@ -1325,7 +1543,7 @@ func (r *Room) onMetrics(source types.Participant, dp *livekit.DataPacket) {
|
||||
BroadcastMetricsForRoom(r, source, dp, r.logger)
|
||||
}
|
||||
|
||||
func (r *Room) subscribeToExistingTracks(p types.LocalParticipant) {
|
||||
func (r *Room) subscribeToExistingTracks(p types.LocalParticipant, isSync bool) {
|
||||
r.lock.RLock()
|
||||
shouldSubscribe := r.autoSubscribe(p)
|
||||
r.lock.RUnlock()
|
||||
@@ -1343,7 +1561,7 @@ func (r *Room) subscribeToExistingTracks(p types.LocalParticipant) {
|
||||
// subscribe to all
|
||||
for _, track := range op.GetPublishedTracks() {
|
||||
trackIDs = append(trackIDs, track.ID())
|
||||
p.SubscribeToTrack(track.ID())
|
||||
p.SubscribeToTrack(track.ID(), isSync)
|
||||
}
|
||||
}
|
||||
if len(trackIDs) > 0 {
|
||||
@@ -1447,7 +1665,7 @@ func (r *Room) changeUpdateWorker() {
|
||||
SendParticipantUpdates(maps.Values(updatesMap), r.GetParticipants())
|
||||
|
||||
case <-cleanDataMessageTicker.C:
|
||||
r.dataMessagecache.Prune()
|
||||
r.dataMessageCache.Prune()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1723,7 +1941,7 @@ func (r *Room) IsDataMessageUserPacketDuplicate(up *livekit.UserPacket) bool {
|
||||
|
||||
func (r *Room) GetCachedReliableDataMessage(seqs map[livekit.ParticipantID]uint32) []*types.DataMessageCache {
|
||||
msgs := make([]*types.DataMessageCache, 0, len(seqs)*10)
|
||||
for _, msg := range r.dataMessagecache.Get() {
|
||||
for _, msg := range r.dataMessageCache.Get() {
|
||||
seq, ok := seqs[msg.SenderID]
|
||||
if ok && msg.Seq >= seq {
|
||||
msgs = append(msgs, msg)
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright 2023 LiveKit, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
|
||||
"github.com/gammazero/deque"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
|
||||
type SignalCacheParams struct {
|
||||
Logger logger.Logger
|
||||
FirstMessageId uint32 // should be used for testing only
|
||||
}
|
||||
|
||||
type SignalCache struct {
|
||||
params SignalCacheParams
|
||||
|
||||
lock sync.Mutex
|
||||
messageId uint32
|
||||
messages deque.Deque[*livekit.Signalv2ServerMessage]
|
||||
}
|
||||
|
||||
func NewSignalCache(params SignalCacheParams) *SignalCache {
|
||||
s := &SignalCache{
|
||||
params: params,
|
||||
messageId: params.FirstMessageId,
|
||||
}
|
||||
if s.messageId == 0 {
|
||||
s.messageId = uint32(rand.Intn(1<<8) + 1)
|
||||
}
|
||||
s.messages.SetBaseCap(16)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *SignalCache) Add(msg *livekit.Signalv2ServerMessage, lastRemoteId uint32) {
|
||||
s.AddBatch([]*livekit.Signalv2ServerMessage{msg}, lastRemoteId)
|
||||
}
|
||||
|
||||
func (s *SignalCache) AddBatch(msgs []*livekit.Signalv2ServerMessage, lastRemoteId uint32) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
for _, msg := range msgs {
|
||||
msg.MessageId = s.messageId
|
||||
s.messageId++
|
||||
msg.LastProcessedRemoteMessageId = lastRemoteId
|
||||
|
||||
s.messages.PushBack(msg)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SignalCache) Clear(till uint32) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
s.clearLocked(till)
|
||||
}
|
||||
|
||||
func (s *SignalCache) clearLocked(till uint32) {
|
||||
for s.messages.Len() != 0 {
|
||||
front := s.messages.Front()
|
||||
if front.GetMessageId() > till {
|
||||
break
|
||||
}
|
||||
s.messages.PopFront()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SignalCache) GetFromFront() []*livekit.Signalv2ServerMessage {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
return s.getFromFrontLocked()
|
||||
}
|
||||
|
||||
func (s *SignalCache) getFromFrontLocked() []*livekit.Signalv2ServerMessage {
|
||||
var msgs []*livekit.Signalv2ServerMessage
|
||||
for msg := range s.messages.Iter() {
|
||||
msgs = append(msgs, msg)
|
||||
}
|
||||
|
||||
return msgs
|
||||
}
|
||||
|
||||
func (s *SignalCache) ClearAndGetFrom(from uint32) []*livekit.Signalv2ServerMessage {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
s.clearLocked(from - 1)
|
||||
return s.getFromFrontLocked()
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
)
|
||||
|
||||
func TestSignalCache(t *testing.T) {
|
||||
firstMessageId := uint32(10)
|
||||
cache := NewSignalCache(SignalCacheParams{
|
||||
FirstMessageId: firstMessageId,
|
||||
})
|
||||
|
||||
inputMessages := []*livekit.Signalv2ServerMessage{
|
||||
&livekit.Signalv2ServerMessage{
|
||||
Message: &livekit.Signalv2ServerMessage_ConnectResponse{},
|
||||
},
|
||||
// SIGNALLING-V2-TODO: replace with other kinds of messages when more types are added
|
||||
&livekit.Signalv2ServerMessage{
|
||||
Message: &livekit.Signalv2ServerMessage_ConnectResponse{},
|
||||
},
|
||||
&livekit.Signalv2ServerMessage{
|
||||
Message: &livekit.Signalv2ServerMessage_ConnectResponse{},
|
||||
},
|
||||
&livekit.Signalv2ServerMessage{
|
||||
Message: &livekit.Signalv2ServerMessage_ConnectResponse{},
|
||||
},
|
||||
}
|
||||
|
||||
// Add() - add one message at a time
|
||||
for _, inputMessage := range inputMessages {
|
||||
cache.Add(inputMessage, 2345)
|
||||
}
|
||||
|
||||
// get all messages in cache
|
||||
outputMessages := cache.GetFromFront()
|
||||
require.Equal(t, inputMessages, outputMessages)
|
||||
|
||||
// clear one and get again
|
||||
cache.Clear(firstMessageId)
|
||||
|
||||
outputMessages = cache.GetFromFront()
|
||||
require.Equal(t, inputMessages[1:], outputMessages)
|
||||
|
||||
// clearing some evicted messages should not clear anything
|
||||
cache.Clear(firstMessageId) // firstMessageId has been cleared already at this point
|
||||
|
||||
outputMessages = cache.GetFromFront()
|
||||
require.Equal(t, inputMessages[1:], outputMessages)
|
||||
|
||||
// clear some and get rest in one go
|
||||
outputMessages = cache.ClearAndGetFrom(firstMessageId + 3)
|
||||
require.Equal(t, 1, len(outputMessages))
|
||||
require.Equal(t, inputMessages[3:], outputMessages)
|
||||
|
||||
// getting again should get the same messages again as they sill should in cache
|
||||
outputMessages = cache.GetFromFront()
|
||||
require.Equal(t, inputMessages[3:], outputMessages)
|
||||
|
||||
// clearing all and getting should return nil
|
||||
require.Nil(t, cache.ClearAndGetFrom(firstMessageId+uint32(len(inputMessages))))
|
||||
|
||||
// getting again should return nil as the cache is fully cleared above
|
||||
require.Nil(t, cache.GetFromFront())
|
||||
|
||||
// AddBatch() - add all messages at once
|
||||
cache.AddBatch(inputMessages, 4567)
|
||||
|
||||
// get all messages in cache
|
||||
outputMessages = cache.GetFromFront()
|
||||
require.Equal(t, inputMessages, outputMessages)
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
// Copyright 2023 LiveKit, Inc.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultMaxFragmentSize = 8192
|
||||
)
|
||||
|
||||
type reassembly struct {
|
||||
startedAt time.Time
|
||||
fragments []*livekit.Fragment
|
||||
isCorrupted bool
|
||||
}
|
||||
|
||||
type SignalFragmentParams struct {
|
||||
Logger logger.Logger
|
||||
MaxFragmentSize int
|
||||
FirstPacketId uint32 // should be used for testing only
|
||||
}
|
||||
|
||||
type SignalFragment struct {
|
||||
params SignalFragmentParams
|
||||
|
||||
lock sync.Mutex
|
||||
packetId uint32
|
||||
reassemblies map[uint32]*reassembly
|
||||
}
|
||||
|
||||
func NewSignalFragment(params SignalFragmentParams) *SignalFragment {
|
||||
s := &SignalFragment{
|
||||
params: params,
|
||||
packetId: params.FirstPacketId,
|
||||
reassemblies: make(map[uint32]*reassembly),
|
||||
}
|
||||
if s.params.MaxFragmentSize == 0 {
|
||||
s.params.MaxFragmentSize = defaultMaxFragmentSize
|
||||
}
|
||||
if s.packetId == 0 {
|
||||
s.packetId = uint32(rand.Intn(1<<8) + 1)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *SignalFragment) Segment(data []byte) []*livekit.Fragment {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
if len(data) <= s.params.MaxFragmentSize {
|
||||
return nil
|
||||
}
|
||||
|
||||
var fragments []*livekit.Fragment
|
||||
numFragments := uint32((len(data) + s.params.MaxFragmentSize - 1) / s.params.MaxFragmentSize)
|
||||
fragmentNumber := uint32(1)
|
||||
consumed := 0
|
||||
for len(data[consumed:]) != 0 {
|
||||
fragmentSize := min(len(data[consumed:]), s.params.MaxFragmentSize)
|
||||
fragment := &livekit.Fragment{
|
||||
PacketId: s.packetId,
|
||||
FragmentNumber: fragmentNumber,
|
||||
NumFragments: numFragments,
|
||||
FragmentSize: uint32(fragmentSize),
|
||||
TotalSize: uint32(len(data)),
|
||||
Data: data[consumed : consumed+fragmentSize],
|
||||
}
|
||||
fragments = append(fragments, fragment)
|
||||
fragmentNumber++
|
||||
consumed += fragmentSize
|
||||
}
|
||||
|
||||
return fragments
|
||||
}
|
||||
|
||||
func (s *SignalFragment) Reassemble(fragment *livekit.Fragment) []byte {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
re, ok := s.reassemblies[fragment.PacketId]
|
||||
if !ok {
|
||||
re = &reassembly{
|
||||
startedAt: time.Now(),
|
||||
fragments: make([]*livekit.Fragment, fragment.NumFragments),
|
||||
}
|
||||
s.reassemblies[fragment.PacketId] = re
|
||||
}
|
||||
if int(fragment.FragmentNumber) <= len(re.fragments) {
|
||||
if int(fragment.FragmentSize) != len(fragment.Data) {
|
||||
re.isCorrupted = true // runt packet, data size of blob does not match fragment size
|
||||
} else {
|
||||
re.fragments[fragment.FragmentNumber-1] = fragment
|
||||
}
|
||||
} else {
|
||||
re.isCorrupted = true
|
||||
}
|
||||
|
||||
if re.isCorrupted {
|
||||
return nil
|
||||
}
|
||||
|
||||
// try to reassemble
|
||||
expectedTotalSize := uint32(0)
|
||||
totalSize := 0
|
||||
for _, fr := range re.fragments {
|
||||
if fr == nil {
|
||||
return nil // not received all fragments of packet yet
|
||||
}
|
||||
|
||||
expectedTotalSize = fr.TotalSize // can read this from any fragment of packet
|
||||
totalSize += len(fr.Data)
|
||||
}
|
||||
if expectedTotalSize != 0 && uint32(totalSize) != expectedTotalSize {
|
||||
re.isCorrupted = true
|
||||
return nil
|
||||
}
|
||||
|
||||
data := make([]byte, 0, expectedTotalSize)
|
||||
for _, fr := range re.fragments {
|
||||
data = append(data, fr.Data...)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
// SIGNALLING-V2-TODO: need a prune worker to handle stale re-assemblies
|
||||
@@ -0,0 +1,125 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
)
|
||||
|
||||
func TestSignalFragment(t *testing.T) {
|
||||
inputMessage := &livekit.Signalv2ServerEnvelope{
|
||||
ServerMessages: []*livekit.Signalv2ServerMessage{
|
||||
{
|
||||
Message: &livekit.Signalv2ServerMessage_ConnectResponse{
|
||||
ConnectResponse: &livekit.ConnectResponse{
|
||||
SifTrailer: []byte("abcdefghijklmnopqrstuvwxyz0123456789"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: &livekit.Signalv2ServerMessage_ConnectResponse{
|
||||
ConnectResponse: &livekit.ConnectResponse{
|
||||
SifTrailer: []byte("0123456789abcdefghijklmnopqrstuvwxyz0123456789"),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Message: &livekit.Signalv2ServerMessage_ConnectResponse{
|
||||
ConnectResponse: &livekit.ConnectResponse{
|
||||
SifTrailer: []byte("ABCDEFGHIJKLMNOPQRSTabcdefghijklmnopqrstuvwxyz0123456789"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("no segmentation needed", func(t *testing.T) {
|
||||
sr := NewSignalFragment(SignalFragmentParams{
|
||||
MaxFragmentSize: 5_000_000,
|
||||
})
|
||||
|
||||
marshalled, err := proto.Marshal(inputMessage)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, sr.Segment(marshalled))
|
||||
})
|
||||
|
||||
t.Run("segmentation + reassmebly", func(t *testing.T) {
|
||||
maxFragmentSize := 5
|
||||
sr := NewSignalFragment(SignalFragmentParams{
|
||||
MaxFragmentSize: maxFragmentSize,
|
||||
})
|
||||
|
||||
marshalled, err := proto.Marshal(inputMessage)
|
||||
require.NoError(t, err)
|
||||
|
||||
expectedNumFragments := (len(marshalled) + maxFragmentSize - 1) / maxFragmentSize
|
||||
|
||||
fragments := sr.Segment(marshalled)
|
||||
require.NotZero(t, len(fragments))
|
||||
require.Equal(t, uint32(len(marshalled)), fragments[0].TotalSize)
|
||||
|
||||
var reassembled []byte
|
||||
for idx, fragment := range fragments {
|
||||
require.Equal(t, uint32(idx+1), fragment.FragmentNumber)
|
||||
require.NotZero(t, fragment.FragmentSize)
|
||||
require.Equal(t, uint32(expectedNumFragments), fragment.NumFragments)
|
||||
require.Equal(t, fragment.FragmentSize, uint32(len(fragment.Data)))
|
||||
|
||||
reassembled = sr.Reassemble(fragment)
|
||||
}
|
||||
require.Equal(t, marshalled, reassembled)
|
||||
})
|
||||
|
||||
t.Run("runt", func(t *testing.T) {
|
||||
maxFragmentSize := 5
|
||||
sr := NewSignalFragment(SignalFragmentParams{
|
||||
MaxFragmentSize: maxFragmentSize,
|
||||
})
|
||||
|
||||
marshalled, err := proto.Marshal(inputMessage)
|
||||
require.NoError(t, err)
|
||||
|
||||
fragments := sr.Segment(marshalled)
|
||||
|
||||
var reassembled []byte
|
||||
for idx, fragment := range fragments {
|
||||
// do not send one packet into re-assembly initially, re-assembly should not succeed
|
||||
if idx == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
reassembled = sr.Reassemble(fragment)
|
||||
}
|
||||
require.Zero(t, len(reassembled))
|
||||
|
||||
// submit 1st fragment and ensure reassembly completes
|
||||
reassembled = sr.Reassemble(fragments[0])
|
||||
require.Equal(t, marshalled, reassembled)
|
||||
})
|
||||
|
||||
t.Run("corrupted", func(t *testing.T) {
|
||||
maxFragmentSize := 5
|
||||
sr := NewSignalFragment(SignalFragmentParams{
|
||||
MaxFragmentSize: maxFragmentSize,
|
||||
})
|
||||
|
||||
marshalled, err := proto.Marshal(inputMessage)
|
||||
require.NoError(t, err)
|
||||
|
||||
fragments := sr.Segment(marshalled)
|
||||
|
||||
var reassembled []byte
|
||||
for idx, fragment := range fragments {
|
||||
// corrupt a fragment, re-assembly should fail
|
||||
if idx == 0 {
|
||||
fragment.FragmentSize += 1
|
||||
}
|
||||
|
||||
reassembled = sr.Reassemble(fragment)
|
||||
}
|
||||
require.Zero(t, len(reassembled))
|
||||
})
|
||||
}
|
||||
@@ -139,8 +139,8 @@ func (m *SubscriptionManager) isClosed() bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *SubscriptionManager) SubscribeToTrack(trackID livekit.TrackID) {
|
||||
if m.params.UseOneShotSignallingMode {
|
||||
func (m *SubscriptionManager) SubscribeToTrack(trackID livekit.TrackID, isSync bool) {
|
||||
if m.params.UseOneShotSignallingMode || isSync {
|
||||
m.subscribeSynchronous(trackID)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestSubscribe(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
sm.SubscribeToTrack("track")
|
||||
sm.SubscribeToTrack("track", false)
|
||||
s := sm.subscriptions["track"]
|
||||
require.True(t, s.isDesired())
|
||||
require.Eventually(t, func() bool {
|
||||
@@ -127,7 +127,7 @@ func TestSubscribe(t *testing.T) {
|
||||
failed.Store(true)
|
||||
}
|
||||
|
||||
sm.SubscribeToTrack("track")
|
||||
sm.SubscribeToTrack("track", false)
|
||||
s := sm.subscriptions["track"]
|
||||
require.Eventually(t, func() bool {
|
||||
return !s.getHasPermission()
|
||||
@@ -168,7 +168,7 @@ func TestSubscribe(t *testing.T) {
|
||||
failed.Store(true)
|
||||
}
|
||||
|
||||
sm.SubscribeToTrack("track")
|
||||
sm.SubscribeToTrack("track", false)
|
||||
s := sm.subscriptions["track"]
|
||||
require.Eventually(t, func() bool {
|
||||
return !s.needsSubscribe()
|
||||
@@ -271,8 +271,8 @@ func TestSubscribeStatusChanged(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
sm.SubscribeToTrack("track1")
|
||||
sm.SubscribeToTrack("track2")
|
||||
sm.SubscribeToTrack("track1", false)
|
||||
sm.SubscribeToTrack("track2", false)
|
||||
s1 := sm.subscriptions["track1"]
|
||||
s2 := sm.subscriptions["track2"]
|
||||
require.Eventually(t, func() bool {
|
||||
@@ -332,7 +332,7 @@ func TestUpdateSettingsBeforeSubscription(t *testing.T) {
|
||||
}
|
||||
sm.UpdateSubscribedTrackSettings("track", settings)
|
||||
|
||||
sm.SubscribeToTrack("track")
|
||||
sm.SubscribeToTrack("track", false)
|
||||
|
||||
s := sm.subscriptions["track"]
|
||||
require.Eventually(t, func() bool {
|
||||
@@ -376,7 +376,7 @@ func TestSubscriptionLimits(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
sm.SubscribeToTrack("track")
|
||||
sm.SubscribeToTrack("track", false)
|
||||
s := sm.subscriptions["track"]
|
||||
require.True(t, s.isDesired())
|
||||
require.Eventually(t, func() bool {
|
||||
@@ -405,7 +405,7 @@ func TestSubscriptionLimits(t *testing.T) {
|
||||
require.Equal(t, 1, tm.TrackSubscribedCallCount())
|
||||
|
||||
// reach subscription limit, subscribe pending
|
||||
sm.SubscribeToTrack("track2")
|
||||
sm.SubscribeToTrack("track2", false)
|
||||
s2 := sm.subscriptions["track2"]
|
||||
time.Sleep(subscriptionTimeout * 2)
|
||||
require.True(t, s2.needsSubscribe())
|
||||
@@ -437,7 +437,7 @@ func TestSubscriptionLimits(t *testing.T) {
|
||||
}, subSettleTimeout, subCheckInterval, "track was not bound")
|
||||
|
||||
// subscribe to track1 again, which should pending
|
||||
sm.SubscribeToTrack("track")
|
||||
sm.SubscribeToTrack("track", false)
|
||||
s = sm.subscriptions["track"]
|
||||
require.True(t, s.isDesired())
|
||||
time.Sleep(subscriptionTimeout * 2)
|
||||
|
||||
+86
-41
@@ -87,19 +87,19 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNoICETransport = errors.New("no ICE transport")
|
||||
ErrIceRestartWithoutLocalSDP = errors.New("ICE restart without local SDP settled")
|
||||
ErrIceRestartOnClosedPeerConnection = errors.New("ICE restart on closed peer connection")
|
||||
ErrNoTransceiver = errors.New("no transceiver")
|
||||
ErrNoSender = errors.New("no sender")
|
||||
ErrMidNotFound = errors.New("mid not found")
|
||||
ErrNotSynchronousPeerConnectionMode = errors.New("not using synchronous peer connection mode")
|
||||
ErrNoRemoteDescription = errors.New("no remote description")
|
||||
ErrNoLocalDescription = errors.New("no local description")
|
||||
ErrInvalidSDPFragment = errors.New("invalid sdp fragment")
|
||||
ErrNoBundleMid = errors.New("could not get bundle mid")
|
||||
ErrMidMismatch = errors.New("media mid does not match bundle mid")
|
||||
ErrICECredentialMismatch = errors.New("ice credential mismatch")
|
||||
ErrNoICETransport = errors.New("no ICE transport")
|
||||
ErrIceRestartWithoutLocalSDP = errors.New("ICE restart without local SDP settled")
|
||||
ErrIceRestartOnClosedPeerConnection = errors.New("ICE restart on closed peer connection")
|
||||
ErrNoTransceiver = errors.New("no transceiver")
|
||||
ErrNoSender = errors.New("no sender")
|
||||
ErrMidNotFound = errors.New("mid not found")
|
||||
ErrNotSynchronousLocalCandidatesMode = errors.New("not using synchronous local candidates mode")
|
||||
ErrNoRemoteDescription = errors.New("no remote description")
|
||||
ErrNoLocalDescription = errors.New("no local description")
|
||||
ErrInvalidSDPFragment = errors.New("invalid sdp fragment")
|
||||
ErrNoBundleMid = errors.New("could not get bundle mid")
|
||||
ErrMidMismatch = errors.New("media mid does not match bundle mid")
|
||||
ErrICECredentialMismatch = errors.New("ice credential mismatch")
|
||||
)
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -258,24 +258,25 @@ type PCTransport struct {
|
||||
}
|
||||
|
||||
type TransportParams struct {
|
||||
Handler transport.Handler
|
||||
ProtocolVersion types.ProtocolVersion
|
||||
Config *WebRTCConfig
|
||||
Twcc *lktwcc.Responder
|
||||
DirectionConfig DirectionConfig
|
||||
CongestionControlConfig config.CongestionControlConfig
|
||||
EnabledCodecs []*livekit.Codec
|
||||
Logger logger.Logger
|
||||
Transport livekit.SignalTarget
|
||||
SimTracks map[uint32]SimulcastTrackInfo
|
||||
ClientInfo ClientInfo
|
||||
IsOfferer bool
|
||||
IsSendSide bool
|
||||
AllowPlayoutDelay bool
|
||||
UseOneShotSignallingMode bool
|
||||
FireOnTrackBySdp bool
|
||||
DataChannelMaxBufferedAmount uint64
|
||||
DatachannelSlowThreshold int
|
||||
Handler transport.Handler
|
||||
ProtocolVersion types.ProtocolVersion
|
||||
Config *WebRTCConfig
|
||||
Twcc *lktwcc.Responder
|
||||
DirectionConfig DirectionConfig
|
||||
CongestionControlConfig config.CongestionControlConfig
|
||||
EnabledCodecs []*livekit.Codec
|
||||
Logger logger.Logger
|
||||
Transport livekit.SignalTarget
|
||||
SimTracks map[uint32]SimulcastTrackInfo
|
||||
ClientInfo ClientInfo
|
||||
IsOfferer bool
|
||||
IsSendSide bool
|
||||
AllowPlayoutDelay bool
|
||||
UseOneShotSignallingMode bool
|
||||
SynchronousLocalCandidatesMode bool
|
||||
FireOnTrackBySdp bool
|
||||
DataChannelMaxBufferedAmount uint64
|
||||
DatachannelSlowThreshold int
|
||||
|
||||
// for development test
|
||||
DatachannelMaxReceiverBufferSize int
|
||||
@@ -485,7 +486,7 @@ func NewPCTransport(params TransportParams) (*PCTransport, error) {
|
||||
canReuseTransceiver: true,
|
||||
connectionDetails: types.NewICEConnectionDetails(params.Transport, params.Logger),
|
||||
lastNegotiate: time.Now(),
|
||||
activeOfferId: uint32(rand.Intn(1 << 8)),
|
||||
activeOfferId: uint32(rand.Intn(1<<8) + 1),
|
||||
}
|
||||
|
||||
bwe, err := t.createPeerConnection()
|
||||
@@ -546,7 +547,7 @@ func (t *PCTransport) createPeerConnection() (cc.BandwidthEstimator, error) {
|
||||
}
|
||||
|
||||
t.pc = pc
|
||||
if !t.params.UseOneShotSignallingMode {
|
||||
if !t.params.UseOneShotSignallingMode && !t.params.SynchronousLocalCandidatesMode {
|
||||
// one shot signalling mode gathers all candidates and sends in answer
|
||||
t.pc.OnICEGatheringStateChange(t.onICEGatheringStateChange)
|
||||
t.pc.OnICECandidate(t.onICECandidateTrickle)
|
||||
@@ -1292,7 +1293,8 @@ func (t *PCTransport) clearConnTimer() {
|
||||
}
|
||||
|
||||
func (t *PCTransport) HandleRemoteDescription(sd webrtc.SessionDescription, remoteId uint32) error {
|
||||
if t.params.UseOneShotSignallingMode {
|
||||
if t.params.UseOneShotSignallingMode || t.params.SynchronousLocalCandidatesMode {
|
||||
// SIGNALLING-V2-TODO: need to support filtering candidates for transport fallback
|
||||
// add remote candidates to ICE connection details
|
||||
parsed, err := sd.Unmarshal()
|
||||
if err == nil {
|
||||
@@ -1341,8 +1343,8 @@ func (t *PCTransport) HandleRemoteDescription(sd webrtc.SessionDescription, remo
|
||||
}
|
||||
|
||||
func (t *PCTransport) GetAnswer() (webrtc.SessionDescription, error) {
|
||||
if !t.params.UseOneShotSignallingMode {
|
||||
return webrtc.SessionDescription{}, ErrNotSynchronousPeerConnectionMode
|
||||
if !t.params.UseOneShotSignallingMode && !t.params.SynchronousLocalCandidatesMode {
|
||||
return webrtc.SessionDescription{}, ErrNotSynchronousLocalCandidatesMode
|
||||
}
|
||||
|
||||
prd := t.pc.PendingRemoteDescription()
|
||||
@@ -1388,6 +1390,49 @@ func (t *PCTransport) GetAnswer() (webrtc.SessionDescription, error) {
|
||||
return *cld, nil
|
||||
}
|
||||
|
||||
func (t *PCTransport) GetOffer() (webrtc.SessionDescription, error) {
|
||||
if !t.params.SynchronousLocalCandidatesMode {
|
||||
return webrtc.SessionDescription{}, ErrNotSynchronousLocalCandidatesMode
|
||||
}
|
||||
|
||||
offer, err := t.pc.CreateOffer(nil)
|
||||
if err != nil {
|
||||
return webrtc.SessionDescription{}, err
|
||||
}
|
||||
|
||||
if err = t.pc.SetLocalDescription(offer); err != nil {
|
||||
return webrtc.SessionDescription{}, err
|
||||
}
|
||||
|
||||
// wait for gathering to complete to include all candidates in the answer
|
||||
<-webrtc.GatheringCompletePromise(t.pc)
|
||||
|
||||
pld := t.pc.PendingLocalDescription()
|
||||
|
||||
// add local candidates to ICE connection details
|
||||
parsed, err := pld.Unmarshal()
|
||||
if err == nil {
|
||||
addLocalICECandidates := func(attrs []sdp.Attribute) {
|
||||
for _, a := range attrs {
|
||||
if a.IsICECandidate() {
|
||||
c, err := ice.UnmarshalCandidate(a.Value)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.connectionDetails.AddLocalICECandidate(c, false, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addLocalICECandidates(parsed.Attributes)
|
||||
for _, m := range parsed.MediaDescriptions {
|
||||
addLocalICECandidates(m.Attributes)
|
||||
}
|
||||
}
|
||||
|
||||
return *pld, nil
|
||||
}
|
||||
|
||||
func (t *PCTransport) GetICESessionUfrag() (string, error) {
|
||||
cld := t.pc.CurrentLocalDescription()
|
||||
if cld == nil {
|
||||
@@ -1410,7 +1455,7 @@ func (t *PCTransport) GetICESessionUfrag() (string, error) {
|
||||
// Handles SDP Fragment for ICE Trickle in WHIP
|
||||
func (t *PCTransport) HandleICETrickleSDPFragment(sdpFragment string) error {
|
||||
if !t.params.UseOneShotSignallingMode {
|
||||
return ErrNotSynchronousPeerConnectionMode
|
||||
return ErrNotSynchronousLocalCandidatesMode
|
||||
}
|
||||
|
||||
parsedFragment := &lksdp.SDPFragment{}
|
||||
@@ -1498,7 +1543,7 @@ func (t *PCTransport) HandleICETrickleSDPFragment(sdpFragment string) error {
|
||||
// Handles SDP Fragment for ICE Restart in WHIP
|
||||
func (t *PCTransport) HandleICERestartSDPFragment(sdpFragment string) (string, error) {
|
||||
if !t.params.UseOneShotSignallingMode {
|
||||
return "", ErrNotSynchronousPeerConnectionMode
|
||||
return "", ErrNotSynchronousLocalCandidatesMode
|
||||
}
|
||||
|
||||
parsedFragment := &lksdp.SDPFragment{}
|
||||
@@ -1628,7 +1673,7 @@ func (t *PCTransport) Negotiate(force bool) {
|
||||
// no op to cancel pending negotiation
|
||||
})
|
||||
t.debouncePending = false
|
||||
t.updateLastNeogitateLocked()
|
||||
t.updateLastNegotiateLocked()
|
||||
|
||||
postEvent = true
|
||||
} else {
|
||||
@@ -1642,7 +1687,7 @@ func (t *PCTransport) Negotiate(force bool) {
|
||||
t.debouncedNegotiate.Add(func() {
|
||||
t.lock.Lock()
|
||||
t.debouncePending = false
|
||||
t.updateLastNeogitateLocked()
|
||||
t.updateLastNegotiateLocked()
|
||||
t.lock.Unlock()
|
||||
|
||||
t.postEvent(event{
|
||||
@@ -1661,7 +1706,7 @@ func (t *PCTransport) Negotiate(force bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *PCTransport) updateLastNeogitateLocked() {
|
||||
func (t *PCTransport) updateLastNegotiateLocked() {
|
||||
if now := time.Now(); now.After(t.lastNegotiate) {
|
||||
t.lastNegotiate = now
|
||||
}
|
||||
|
||||
+58
-51
@@ -83,29 +83,30 @@ func (h TransportManagerPublisherTransportHandler) OnAnswer(sd webrtc.SessionDes
|
||||
// -------------------------------
|
||||
|
||||
type TransportManagerParams struct {
|
||||
SubscriberAsPrimary bool
|
||||
Config *WebRTCConfig
|
||||
Twcc *twcc.Responder
|
||||
ProtocolVersion types.ProtocolVersion
|
||||
CongestionControlConfig config.CongestionControlConfig
|
||||
EnabledSubscribeCodecs []*livekit.Codec
|
||||
EnabledPublishCodecs []*livekit.Codec
|
||||
SimTracks map[uint32]SimulcastTrackInfo
|
||||
ClientInfo ClientInfo
|
||||
Migration bool
|
||||
AllowTCPFallback bool
|
||||
TCPFallbackRTTThreshold int
|
||||
AllowUDPUnstableFallback bool
|
||||
TURNSEnabled bool
|
||||
AllowPlayoutDelay bool
|
||||
DataChannelMaxBufferedAmount uint64
|
||||
DatachannelSlowThreshold int
|
||||
Logger logger.Logger
|
||||
PublisherHandler transport.Handler
|
||||
SubscriberHandler transport.Handler
|
||||
DataChannelStats *telemetry.BytesTrackStats
|
||||
UseOneShotSignallingMode bool
|
||||
FireOnTrackBySdp bool
|
||||
SubscriberAsPrimary bool
|
||||
Config *WebRTCConfig
|
||||
Twcc *twcc.Responder
|
||||
ProtocolVersion types.ProtocolVersion
|
||||
CongestionControlConfig config.CongestionControlConfig
|
||||
EnabledSubscribeCodecs []*livekit.Codec
|
||||
EnabledPublishCodecs []*livekit.Codec
|
||||
SimTracks map[uint32]SimulcastTrackInfo
|
||||
ClientInfo ClientInfo
|
||||
Migration bool
|
||||
AllowTCPFallback bool
|
||||
TCPFallbackRTTThreshold int
|
||||
AllowUDPUnstableFallback bool
|
||||
TURNSEnabled bool
|
||||
AllowPlayoutDelay bool
|
||||
DataChannelMaxBufferedAmount uint64
|
||||
DatachannelSlowThreshold int
|
||||
Logger logger.Logger
|
||||
PublisherHandler transport.Handler
|
||||
SubscriberHandler transport.Handler
|
||||
DataChannelStats *telemetry.BytesTrackStats
|
||||
UseOneShotSignallingMode bool
|
||||
SynchronousLocalCandidatesMode bool
|
||||
FireOnTrackBySdp bool
|
||||
}
|
||||
|
||||
type TransportManager struct {
|
||||
@@ -150,21 +151,22 @@ func NewTransportManager(params TransportManagerParams) (*TransportManager, erro
|
||||
|
||||
lgr := LoggerWithPCTarget(params.Logger, livekit.SignalTarget_PUBLISHER)
|
||||
publisher, err := NewPCTransport(TransportParams{
|
||||
ProtocolVersion: params.ProtocolVersion,
|
||||
Config: params.Config,
|
||||
Twcc: params.Twcc,
|
||||
DirectionConfig: params.Config.Publisher,
|
||||
CongestionControlConfig: params.CongestionControlConfig,
|
||||
EnabledCodecs: params.EnabledPublishCodecs,
|
||||
Logger: lgr,
|
||||
SimTracks: params.SimTracks,
|
||||
ClientInfo: params.ClientInfo,
|
||||
Transport: livekit.SignalTarget_PUBLISHER,
|
||||
Handler: TransportManagerPublisherTransportHandler{TransportManagerTransportHandler{params.PublisherHandler, t, lgr}},
|
||||
UseOneShotSignallingMode: params.UseOneShotSignallingMode,
|
||||
DataChannelMaxBufferedAmount: params.DataChannelMaxBufferedAmount,
|
||||
DatachannelSlowThreshold: params.DatachannelSlowThreshold,
|
||||
FireOnTrackBySdp: params.FireOnTrackBySdp,
|
||||
ProtocolVersion: params.ProtocolVersion,
|
||||
Config: params.Config,
|
||||
Twcc: params.Twcc,
|
||||
DirectionConfig: params.Config.Publisher,
|
||||
CongestionControlConfig: params.CongestionControlConfig,
|
||||
EnabledCodecs: params.EnabledPublishCodecs,
|
||||
Logger: lgr,
|
||||
SimTracks: params.SimTracks,
|
||||
ClientInfo: params.ClientInfo,
|
||||
Transport: livekit.SignalTarget_PUBLISHER,
|
||||
Handler: TransportManagerPublisherTransportHandler{TransportManagerTransportHandler{params.PublisherHandler, t, lgr}},
|
||||
UseOneShotSignallingMode: params.UseOneShotSignallingMode,
|
||||
SynchronousLocalCandidatesMode: params.SynchronousLocalCandidatesMode,
|
||||
DataChannelMaxBufferedAmount: params.DataChannelMaxBufferedAmount,
|
||||
DatachannelSlowThreshold: params.DatachannelSlowThreshold,
|
||||
FireOnTrackBySdp: params.FireOnTrackBySdp,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -173,19 +175,20 @@ func NewTransportManager(params TransportManagerParams) (*TransportManager, erro
|
||||
|
||||
lgr = LoggerWithPCTarget(params.Logger, livekit.SignalTarget_SUBSCRIBER)
|
||||
subscriber, err := NewPCTransport(TransportParams{
|
||||
ProtocolVersion: params.ProtocolVersion,
|
||||
Config: params.Config,
|
||||
DirectionConfig: params.Config.Subscriber,
|
||||
CongestionControlConfig: params.CongestionControlConfig,
|
||||
EnabledCodecs: params.EnabledSubscribeCodecs,
|
||||
Logger: lgr,
|
||||
ClientInfo: params.ClientInfo,
|
||||
IsOfferer: true,
|
||||
IsSendSide: true,
|
||||
AllowPlayoutDelay: params.AllowPlayoutDelay,
|
||||
DatachannelSlowThreshold: params.DatachannelSlowThreshold,
|
||||
Transport: livekit.SignalTarget_SUBSCRIBER,
|
||||
Handler: TransportManagerTransportHandler{params.SubscriberHandler, t, lgr},
|
||||
ProtocolVersion: params.ProtocolVersion,
|
||||
Config: params.Config,
|
||||
DirectionConfig: params.Config.Subscriber,
|
||||
CongestionControlConfig: params.CongestionControlConfig,
|
||||
EnabledCodecs: params.EnabledSubscribeCodecs,
|
||||
Logger: lgr,
|
||||
ClientInfo: params.ClientInfo,
|
||||
IsOfferer: true,
|
||||
IsSendSide: true,
|
||||
AllowPlayoutDelay: params.AllowPlayoutDelay,
|
||||
DatachannelSlowThreshold: params.DatachannelSlowThreshold,
|
||||
Transport: livekit.SignalTarget_SUBSCRIBER,
|
||||
Handler: TransportManagerTransportHandler{params.SubscriberHandler, t, lgr},
|
||||
SynchronousLocalCandidatesMode: params.SynchronousLocalCandidatesMode,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -493,6 +496,10 @@ func (t *TransportManager) HandleAnswer(answer webrtc.SessionDescription, answer
|
||||
t.subscriber.HandleRemoteDescription(answer, answerId)
|
||||
}
|
||||
|
||||
func (t *TransportManager) GetOffer() (webrtc.SessionDescription, error) {
|
||||
return t.subscriber.GetOffer()
|
||||
}
|
||||
|
||||
// AddICECandidate adds candidates for remote peer
|
||||
func (t *TransportManager) AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) {
|
||||
switch target {
|
||||
|
||||
@@ -407,6 +407,7 @@ type LocalParticipant interface {
|
||||
SetTrackMuted(trackID livekit.TrackID, muted bool, fromAdmin bool) *livekit.TrackInfo
|
||||
|
||||
HandleAnswer(sdp webrtc.SessionDescription, answerId uint32)
|
||||
GetOffer() (webrtc.SessionDescription, error)
|
||||
Negotiate(force bool)
|
||||
ICERestart(iceConfig *livekit.ICEConfig)
|
||||
AddTrackLocal(trackLocal webrtc.TrackLocal, params AddTrackParams) (*webrtc.RTPSender, *webrtc.RTPTransceiver, error)
|
||||
@@ -416,7 +417,7 @@ type LocalParticipant interface {
|
||||
WriteSubscriberRTCP(pkts []rtcp.Packet) error
|
||||
|
||||
// subscriptions
|
||||
SubscribeToTrack(trackID livekit.TrackID)
|
||||
SubscribeToTrack(trackID livekit.TrackID, isSync bool)
|
||||
UnsubscribeFromTrack(trackID livekit.TrackID)
|
||||
UpdateSubscribedTrackSettings(trackID livekit.TrackID, settings *livekit.UpdateTrackSettings)
|
||||
GetSubscribedTracks() []SubscribedTrack
|
||||
|
||||
@@ -360,6 +360,18 @@ type FakeLocalParticipant struct {
|
||||
getLoggerResolverReturnsOnCall map[int]struct {
|
||||
result1 logger.DeferredFieldResolver
|
||||
}
|
||||
GetOfferStub func() (webrtc.SessionDescription, error)
|
||||
getOfferMutex sync.RWMutex
|
||||
getOfferArgsForCall []struct {
|
||||
}
|
||||
getOfferReturns struct {
|
||||
result1 webrtc.SessionDescription
|
||||
result2 error
|
||||
}
|
||||
getOfferReturnsOnCall map[int]struct {
|
||||
result1 webrtc.SessionDescription
|
||||
result2 error
|
||||
}
|
||||
GetPacerStub func() pacer.Pacer
|
||||
getPacerMutex sync.RWMutex
|
||||
getPacerArgsForCall []struct {
|
||||
@@ -1082,10 +1094,11 @@ type FakeLocalParticipant struct {
|
||||
stopAndGetSubscribedTracksForwarderStateReturnsOnCall map[int]struct {
|
||||
result1 map[livekit.TrackID]*livekit.RTPForwarderState
|
||||
}
|
||||
SubscribeToTrackStub func(livekit.TrackID)
|
||||
SubscribeToTrackStub func(livekit.TrackID, bool)
|
||||
subscribeToTrackMutex sync.RWMutex
|
||||
subscribeToTrackArgsForCall []struct {
|
||||
arg1 livekit.TrackID
|
||||
arg2 bool
|
||||
}
|
||||
SubscriberAsPrimaryStub func() bool
|
||||
subscriberAsPrimaryMutex sync.RWMutex
|
||||
@@ -3072,6 +3085,62 @@ func (fake *FakeLocalParticipant) GetLoggerResolverReturnsOnCall(i int, result1
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetOffer() (webrtc.SessionDescription, error) {
|
||||
fake.getOfferMutex.Lock()
|
||||
ret, specificReturn := fake.getOfferReturnsOnCall[len(fake.getOfferArgsForCall)]
|
||||
fake.getOfferArgsForCall = append(fake.getOfferArgsForCall, struct {
|
||||
}{})
|
||||
stub := fake.GetOfferStub
|
||||
fakeReturns := fake.getOfferReturns
|
||||
fake.recordInvocation("GetOffer", []interface{}{})
|
||||
fake.getOfferMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub()
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1, ret.result2
|
||||
}
|
||||
return fakeReturns.result1, fakeReturns.result2
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetOfferCallCount() int {
|
||||
fake.getOfferMutex.RLock()
|
||||
defer fake.getOfferMutex.RUnlock()
|
||||
return len(fake.getOfferArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetOfferCalls(stub func() (webrtc.SessionDescription, error)) {
|
||||
fake.getOfferMutex.Lock()
|
||||
defer fake.getOfferMutex.Unlock()
|
||||
fake.GetOfferStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetOfferReturns(result1 webrtc.SessionDescription, result2 error) {
|
||||
fake.getOfferMutex.Lock()
|
||||
defer fake.getOfferMutex.Unlock()
|
||||
fake.GetOfferStub = nil
|
||||
fake.getOfferReturns = struct {
|
||||
result1 webrtc.SessionDescription
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetOfferReturnsOnCall(i int, result1 webrtc.SessionDescription, result2 error) {
|
||||
fake.getOfferMutex.Lock()
|
||||
defer fake.getOfferMutex.Unlock()
|
||||
fake.GetOfferStub = nil
|
||||
if fake.getOfferReturnsOnCall == nil {
|
||||
fake.getOfferReturnsOnCall = make(map[int]struct {
|
||||
result1 webrtc.SessionDescription
|
||||
result2 error
|
||||
})
|
||||
}
|
||||
fake.getOfferReturnsOnCall[i] = struct {
|
||||
result1 webrtc.SessionDescription
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) GetPacer() pacer.Pacer {
|
||||
fake.getPacerMutex.Lock()
|
||||
ret, specificReturn := fake.getPacerReturnsOnCall[len(fake.getPacerArgsForCall)]
|
||||
@@ -7069,16 +7138,17 @@ func (fake *FakeLocalParticipant) StopAndGetSubscribedTracksForwarderStateReturn
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SubscribeToTrack(arg1 livekit.TrackID) {
|
||||
func (fake *FakeLocalParticipant) SubscribeToTrack(arg1 livekit.TrackID, arg2 bool) {
|
||||
fake.subscribeToTrackMutex.Lock()
|
||||
fake.subscribeToTrackArgsForCall = append(fake.subscribeToTrackArgsForCall, struct {
|
||||
arg1 livekit.TrackID
|
||||
}{arg1})
|
||||
arg2 bool
|
||||
}{arg1, arg2})
|
||||
stub := fake.SubscribeToTrackStub
|
||||
fake.recordInvocation("SubscribeToTrack", []interface{}{arg1})
|
||||
fake.recordInvocation("SubscribeToTrack", []interface{}{arg1, arg2})
|
||||
fake.subscribeToTrackMutex.Unlock()
|
||||
if stub != nil {
|
||||
fake.SubscribeToTrackStub(arg1)
|
||||
fake.SubscribeToTrackStub(arg1, arg2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7088,17 +7158,17 @@ func (fake *FakeLocalParticipant) SubscribeToTrackCallCount() int {
|
||||
return len(fake.subscribeToTrackArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SubscribeToTrackCalls(stub func(livekit.TrackID)) {
|
||||
func (fake *FakeLocalParticipant) SubscribeToTrackCalls(stub func(livekit.TrackID, bool)) {
|
||||
fake.subscribeToTrackMutex.Lock()
|
||||
defer fake.subscribeToTrackMutex.Unlock()
|
||||
fake.SubscribeToTrackStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SubscribeToTrackArgsForCall(i int) livekit.TrackID {
|
||||
func (fake *FakeLocalParticipant) SubscribeToTrackArgsForCall(i int) (livekit.TrackID, bool) {
|
||||
fake.subscribeToTrackMutex.RLock()
|
||||
defer fake.subscribeToTrackMutex.RUnlock()
|
||||
argsForCall := fake.subscribeToTrackArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeLocalParticipant) SubscriberAsPrimary() bool {
|
||||
@@ -8401,6 +8471,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
|
||||
defer fake.getLoggerMutex.RUnlock()
|
||||
fake.getLoggerResolverMutex.RLock()
|
||||
defer fake.getLoggerResolverMutex.RUnlock()
|
||||
fake.getOfferMutex.RLock()
|
||||
defer fake.getOfferMutex.RUnlock()
|
||||
fake.getPacerMutex.RLock()
|
||||
defer fake.getPacerMutex.RUnlock()
|
||||
fake.getPendingTrackMutex.RLock()
|
||||
|
||||
@@ -216,3 +216,21 @@ func MaybeTruncateIP(addr string) string {
|
||||
|
||||
return addr[:len(addr)-3] + "..."
|
||||
}
|
||||
|
||||
func FragmentsAsSignalv2ServerMessages(fragments []*livekit.Fragment) []*livekit.Signalv2ServerMessage {
|
||||
msgs := make([]*livekit.Signalv2ServerMessage, len(fragments))
|
||||
for idx, fragment := range fragments {
|
||||
msgs[idx] = &livekit.Signalv2ServerMessage{
|
||||
Message: &livekit.Signalv2ServerMessage_Fragment{
|
||||
Fragment: fragment,
|
||||
},
|
||||
}
|
||||
}
|
||||
return msgs
|
||||
}
|
||||
|
||||
func MakeSignalv2ServerEnvelope(msgs []*livekit.Signalv2ServerMessage) *livekit.Signalv2ServerEnvelope {
|
||||
return &livekit.Signalv2ServerEnvelope{
|
||||
ServerMessages: msgs,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user