Skip to content

Commit

Permalink
fix double call to readRTCP and try to use NoOpPacer on BWE
Browse files Browse the repository at this point in the history
  • Loading branch information
tyohan committed Sep 19, 2024
1 parent b85c85d commit 2a9a72d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/inlivedev/sfu/pkg/interceptors/playoutdelay"
"github.com/inlivedev/sfu/pkg/interceptors/voiceactivedetector"
"github.com/inlivedev/sfu/pkg/networkmonitor"
"github.com/inlivedev/sfu/pkg/pacer"
"github.com/pion/interceptor"
"github.com/pion/interceptor/pkg/cc"
"github.com/pion/interceptor/pkg/gcc"
Expand Down Expand Up @@ -274,8 +273,8 @@ func NewClient(s *SFU, id string, name string, peerConnectionConfig webrtc.Confi
// TODO: we need to use packet loss based bandwidth adjuster when the bandwidth is below 100_000
return gcc.NewSendSideBWE(
gcc.SendSideBWEInitialBitrate(int(s.bitrateConfigs.InitialBandwidth)),
gcc.SendSideBWEPacer(pacer.NewLeakyBucketPacer(opts.Log, int(s.bitrateConfigs.InitialBandwidth), true)),
// gcc.SendSideBWEPacer(gcc.NewNoOpPacer()),
// gcc.SendSideBWEPacer(pacer.NewLeakyBucketPacer(opts.Log, int(s.bitrateConfigs.InitialBandwidth), true)),
gcc.SendSideBWEPacer(gcc.NewNoOpPacer()),
)
})
if err != nil {
Expand Down Expand Up @@ -1035,6 +1034,21 @@ func (c *Client) ClientTracks() map[string]iClientTrack {
return clientTracks
}

func readRTCP(r *webrtc.RTPSender, b []byte) ([]rtcp.Packet, interceptor.Attributes, error) {
b = b[:0]
n, attributes, err := r.Read(b)
if err != nil {
return nil, nil, err
}

pkts, err := attributes.GetRTCPPackets(b[:n])
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
Expand All @@ -1045,14 +1059,16 @@ func (c *Client) enableReportAndStats(rtpSender *webrtc.RTPSender, track iClient
clientCtx, cancelClientCtx := context.WithCancel(c.context)
defer cancelClientCtx()

buff := make([]byte, 1500)

for {
select {
case <-clientCtx.Done():
return
case <-localCtx.Done():
return
default:
rtcpPackets, _, err := rtpSender.ReadRTCP()
rtcpPackets, _, err := readRTCP(rtpSender, buff)
if err != nil && (err == io.EOF || err == io.ErrClosedPipe) {
return
}
Expand Down

0 comments on commit 2a9a72d

Please sign in to comment.