From 903e499dd6f5e351f790cbd630c2f8f9fcd1896c Mon Sep 17 00:00:00 2001 From: Juliusz Chroboczek Date: Fri, 12 Jun 2020 17:27:38 +0200 Subject: [PATCH] Don't reduce video rate in large groups. --- group.go | 1 - rtpconn.go | 11 ++--------- webclient.go | 30 +----------------------------- 3 files changed, 3 insertions(+), 39 deletions(-) diff --git a/group.go b/group.go index 12e991e..2ab4f94 100644 --- a/group.go +++ b/group.go @@ -45,7 +45,6 @@ type group struct { name string dead bool description *groupDescription - videoCount uint32 locked uint32 mu sync.Mutex diff --git a/rtpconn.go b/rtpconn.go index 78e96b0..2f5acda 100644 --- a/rtpconn.go +++ b/rtpconn.go @@ -429,10 +429,6 @@ func newUpConn(c client, id string) (*rtpUpConnection, error) { conn.tracks = append(conn.tracks, track) - if remote.Kind() == webrtc.RTPCodecTypeVideo { - atomic.AddUint32(&c.Group().videoCount, 1) - } - go readLoop(conn, track) go rtcpUpListener(conn, track, receiver) @@ -1090,7 +1086,7 @@ func handleReport(track *rtpDownTrack, report rtcp.ReceptionReport, jiffies uint } } -func updateUpTrack(track *rtpUpTrack, maxVideoRate uint64) uint64 { +func updateUpTrack(track *rtpUpTrack) uint64 { now := rtptime.Jiffies() isvideo := track.track.Kind() == webrtc.RTPCodecTypeVideo @@ -1099,10 +1095,7 @@ func updateUpTrack(track *rtpUpTrack, maxVideoRate uint64) uint64 { rate := ^uint64(0) if isvideo { minrate = minVideoRate - rate = maxVideoRate - if rate < minrate { - rate = minrate - } + rate = ^uint64(0) } local := track.getLocal() var maxrto uint64 diff --git a/webclient.go b/webclient.go index 46d6bac..2300758 100644 --- a/webclient.go +++ b/webclient.go @@ -9,7 +9,6 @@ import ( "encoding/json" "errors" "log" - "math" "os" "strings" "sync" @@ -228,7 +227,6 @@ func addUpConn(c *webClient, id string) (*rtpUpConnection, error) { old := c.up[id] if old != nil { - decrementVideoTracks(c, old) old.pc.Close() } @@ -255,8 +253,6 @@ func delUpConn(c *webClient, id string) bool { delete(c.up, id) c.mu.Unlock() - decrementVideoTracks(c, conn) - go func(clients []client) { for _, c := range clients { c.pushConn(conn.id, nil, nil, "") @@ -267,21 +263,6 @@ func delUpConn(c *webClient, id string) bool { return true } -func decrementVideoTracks(c *webClient, conn *rtpUpConnection) { - conn.mu.Lock() - defer conn.mu.Unlock() - for _, track := range conn.tracks { - if track.track.Kind() == webrtc.RTPCodecTypeVideo { - count := atomic.AddUint32(&c.group.videoCount, - ^uint32(0)) - if count == ^uint32(0) { - log.Printf("Negative track count!") - atomic.StoreUint32(&c.group.videoCount, 0) - } - } - } -} - func getDownConn(c *webClient, id string) *rtpDownConnection { if c.down == nil { return nil @@ -1042,21 +1023,12 @@ func handleClientMessage(c *webClient, m clientMessage) error { } func sendRateUpdate(c *webClient) { - maxVideoRate := ^uint64(0) - count := atomic.LoadUint32(&c.group.videoCount) - if count >= 3 { - maxVideoRate = uint64(2000000 / math.Sqrt(float64(count))) - if maxVideoRate < minVideoRate { - maxVideoRate = minVideoRate - } - } - up := getUpConns(c) for _, u := range up { tracks := u.getTracks() for _, t := range tracks { - rate := updateUpTrack(t, maxVideoRate) + rate := updateUpTrack(t) if !t.hasRtcpFb("goog-remb", "") { continue }