better debug logs around negotiations
This commit is contained in:
+14
-4
@@ -103,6 +103,15 @@ func (t *MediaTrack) OnClose(f func()) {
|
||||
// subscribes participant to current remoteTrack
|
||||
// creates and add necessary forwarders and starts them
|
||||
func (t *MediaTrack) AddSubscriber(participant types.Participant) error {
|
||||
t.lock.RLock()
|
||||
existingDt := t.downtracks[participant.ID()]
|
||||
t.lock.RUnlock()
|
||||
|
||||
// don't subscribe to the same track multiple times
|
||||
if existingDt != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
codec := t.codec
|
||||
// pack ID to identify all publishedTracks
|
||||
packedId := PackTrackId(t.participantId, t.id)
|
||||
@@ -131,7 +140,7 @@ func (t *MediaTrack) AddSubscriber(participant types.Participant) error {
|
||||
outTrack.OnBind(func() {
|
||||
if rr := bufferFactory.GetOrNew(packetio.RTCPBufferPacket, outTrack.SSRC()).(*buffer.RTCPReader); rr != nil {
|
||||
rr.OnPacket(func(pkt []byte) {
|
||||
t.handleRTCP(outTrack, pkt)
|
||||
t.handleRTCP(outTrack, participant.Identity(), pkt)
|
||||
})
|
||||
}
|
||||
t.sendDownTrackBindingReports(participant.ID(), participant.RTCPChan())
|
||||
@@ -152,7 +161,7 @@ func (t *MediaTrack) AddSubscriber(participant types.Participant) error {
|
||||
if sender != nil {
|
||||
logger.Debugw("removing peerconnection track",
|
||||
"track", t.id,
|
||||
"srcParticipant", t.participantId,
|
||||
"participantId", t.participantId,
|
||||
"destParticipant", participant.Identity())
|
||||
if err := participant.PeerConnection().RemoveTrack(sender); err != nil {
|
||||
if err == webrtc.ErrConnectionClosed {
|
||||
@@ -161,7 +170,7 @@ func (t *MediaTrack) AddSubscriber(participant types.Participant) error {
|
||||
}
|
||||
if _, ok := err.(*rtcerr.InvalidStateError); !ok {
|
||||
logger.Warnw("could not remove remoteTrack from forwarder",
|
||||
"participant", participant.ID(),
|
||||
"participant", participant.Identity(),
|
||||
"err", err)
|
||||
}
|
||||
}
|
||||
@@ -292,7 +301,7 @@ func (t *MediaTrack) forwardRTPWorker() {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *MediaTrack) handleRTCP(dt *sfu.DownTrack, rtcpBuf []byte) {
|
||||
func (t *MediaTrack) handleRTCP(dt *sfu.DownTrack, identity string, rtcpBuf []byte) {
|
||||
defer Recover()
|
||||
pkts, err := rtcp.Unmarshal(rtcpBuf)
|
||||
if err != nil {
|
||||
@@ -325,6 +334,7 @@ func (t *MediaTrack) handleRTCP(dt *sfu.DownTrack, rtcpBuf []byte) {
|
||||
}
|
||||
case *rtcp.TransportLayerNack:
|
||||
logger.Debugw("forwarder got nack",
|
||||
"participant", identity,
|
||||
"packet", p)
|
||||
var nackedPackets []uint16
|
||||
for _, pair := range p.Nacks {
|
||||
|
||||
+21
-10
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/pion/rtcp"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/thoas/go-funk"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/logger"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
@@ -121,7 +122,7 @@ func NewParticipant(identity string, pc types.PeerConnection, rs routing.Message
|
||||
})
|
||||
|
||||
pc.OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
|
||||
logger.Debugw("ICE connection state changed", "state", state.String())
|
||||
//logger.Debugw("ICE connection state changed", "state", state.String())
|
||||
if state == webrtc.ICEConnectionStateConnected {
|
||||
participant.updateState(livekit.ParticipantInfo_ACTIVE)
|
||||
} else if state == webrtc.ICEConnectionStateDisconnected {
|
||||
@@ -210,13 +211,15 @@ func (p *ParticipantImpl) OnClose(callback func(types.Participant)) {
|
||||
|
||||
// Answer an offer from remote participant, used when clients make the initial connection
|
||||
func (p *ParticipantImpl) Answer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error) {
|
||||
logger.Debugw("answering", "state", p.State().String())
|
||||
if p.State() != livekit.ParticipantInfo_JOINING && p.negotiationState != negotiationStateClient {
|
||||
// not in a valid state to continue
|
||||
err = ErrUnexpectedNegotiation
|
||||
return
|
||||
}
|
||||
|
||||
logger.Debugw("answering client offer", "state", p.State().String(),
|
||||
"participant", p.Identity())
|
||||
|
||||
if err = p.peerConn.SetRemoteDescription(sdp); err != nil {
|
||||
return
|
||||
}
|
||||
@@ -283,7 +286,8 @@ func (p *ParticipantImpl) HandleAnswer(sdp webrtc.SessionDescription) error {
|
||||
if sdp.Type != webrtc.SDPTypeAnswer {
|
||||
return ErrUnexpectedOffer
|
||||
}
|
||||
logger.Debugw("setting remote answer")
|
||||
logger.Debugw("setting participant answer",
|
||||
"participant", p.Identity())
|
||||
if err := p.peerConn.SetRemoteDescription(sdp); err != nil {
|
||||
return errors.Wrap(err, "could not set remote description")
|
||||
}
|
||||
@@ -298,6 +302,8 @@ func (p *ParticipantImpl) HandleAnswer(sdp webrtc.SessionDescription) error {
|
||||
|
||||
// client requested negotiation, when it's able to, send a signal to let it
|
||||
func (p *ParticipantImpl) HandleClientNegotiation() {
|
||||
logger.Debugw("participant requested negotiation",
|
||||
"participant", p.Identity())
|
||||
// wait until client is able to request negotiation
|
||||
p.negotiationCond.L.Lock()
|
||||
for p.negotiationState != negotiationStateNone {
|
||||
@@ -305,6 +311,9 @@ func (p *ParticipantImpl) HandleClientNegotiation() {
|
||||
}
|
||||
p.negotiationState = negotiationStateClient
|
||||
p.negotiationCond.L.Unlock()
|
||||
|
||||
logger.Debugw("allowing participant to negotiate",
|
||||
"participant", p.Identity())
|
||||
p.responseSink.WriteMessage(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_Negotiate{
|
||||
Negotiate: &livekit.NegotiationResponse{},
|
||||
@@ -350,13 +359,14 @@ func (p *ParticipantImpl) Close() error {
|
||||
// Subscribes otherPeer to all of the publishedTracks
|
||||
func (p *ParticipantImpl) AddSubscriber(op types.Participant) error {
|
||||
p.lock.RLock()
|
||||
tracks := funk.Values(p.publishedTracks).([]types.PublishedTrack)
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
for _, track := range p.publishedTracks {
|
||||
logger.Debugw("subscribing to remoteTrack",
|
||||
"srcParticipant", p.Identity(),
|
||||
"dstParticipant", op.Identity(),
|
||||
"remoteTrack", track.ID())
|
||||
logger.Debugw("subscribing new participant to tracks",
|
||||
"srcParticipant", p.Identity(),
|
||||
"dstParticipant", op.Identity())
|
||||
|
||||
for _, track := range tracks {
|
||||
if err := track.AddSubscriber(op); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -459,7 +469,7 @@ func (p *ParticipantImpl) negotiate() {
|
||||
}
|
||||
p.negotiationCond.L.Unlock()
|
||||
|
||||
logger.Debugw("starting negotiation", "participant", p.ID())
|
||||
logger.Debugw("starting server negotiation", "participant", p.Identity())
|
||||
offer, err := p.peerConn.CreateOffer(nil)
|
||||
if err != nil {
|
||||
logger.Errorw("could not create offer", "err", err)
|
||||
@@ -478,7 +488,8 @@ func (p *ParticipantImpl) negotiate() {
|
||||
return
|
||||
}
|
||||
|
||||
logger.Debugw("sending available offer to participant")
|
||||
logger.Debugw("sending offer to participant",
|
||||
"participant", p.Identity())
|
||||
err = p.responseSink.WriteMessage(&livekit.SignalResponse{
|
||||
Message: &livekit.SignalResponse_Offer{
|
||||
Offer: ToProtoSessionDescription(offer),
|
||||
|
||||
@@ -257,7 +257,7 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
||||
return
|
||||
}
|
||||
case *livekit.SignalRequest_AddTrack:
|
||||
logger.Debugw("publishing track", "participant", participant.ID(),
|
||||
logger.Debugw("add track request", "participant", participant.Identity(),
|
||||
"track", msg.AddTrack.Cid)
|
||||
participant.AddTrack(msg.AddTrack.Cid, msg.AddTrack.Name, msg.AddTrack.Type)
|
||||
case *livekit.SignalRequest_Answer:
|
||||
|
||||
Reference in New Issue
Block a user