diff --git a/client.go b/client.go index 1c3b45f..d4cd9c1 100644 --- a/client.go +++ b/client.go @@ -99,7 +99,7 @@ type internalDataMessage struct { Data interface{} `json:"data"` } -type internalDataVAD struct { +type InternalDataVAD struct { Type string `json:"type"` Data voiceactivedetector.VoiceActivity `json:"data"` } @@ -849,11 +849,14 @@ func (c *Client) renegotiate() { c.log.Debug("client: renegotiate") c.negotiationNeeded.Store(true) + c.muCallback.Lock() if c.onRenegotiation == nil { + c.muCallback.Unlock() c.log.Errorf("client: onRenegotiation is not set, can't do renegotiation") return } + c.muCallback.Unlock() if c.isInRemoteNegotiation.Load() { c.log.Infof("sfu: renegotiation is delayed because the remote client %s is doing negotiation ", c.ID) @@ -1035,6 +1038,20 @@ func (c *Client) ClientTracks() map[string]iClientTrack { return clientTracks } +func readRTCP(r *webrtc.RTPSender, b []byte) ([]rtcp.Packet, interceptor.Attributes, error) { + i, attributes, err := r.Read(b) + if err != nil { + return nil, nil, err + } + + pkts, err := rtcp.Unmarshal(b[:i]) + if err != nil { + return nil, nil, err + } + + return pkts, attributes, nil +} + // TODO: need to improve and reduce goroutine usage func (c *Client) enableReportAndStats(rtpSender *webrtc.RTPSender, track iClientTrack) { ssrc := rtpSender.GetParameters().Encodings[0].SSRC @@ -1045,6 +1062,8 @@ func (c *Client) enableReportAndStats(rtpSender *webrtc.RTPSender, track iClient clientCtx, cancelClientCtx := context.WithCancel(c.context) defer cancelClientCtx() + b := make([]byte, 1500) + for { select { case <-clientCtx.Done(): @@ -1052,7 +1071,7 @@ func (c *Client) enableReportAndStats(rtpSender *webrtc.RTPSender, track iClient case <-localCtx.Done(): return default: - rtcpPackets, _, err := rtpSender.ReadRTCP() + rtcpPackets, _, err := readRTCP(rtpSender, b) if err != nil && (err == io.EOF || err == io.ErrClosedPipe) { return } @@ -1764,7 +1783,7 @@ func (c *Client) enableSendVADToInternalDataChannel() { } func (c *Client) sendVad(dataType string, activity voiceactivedetector.VoiceActivity) { - dataMessage := internalDataVAD{ + dataMessage := InternalDataVAD{ Type: dataType, Data: activity, }