From 1023c3c52e3f40e0fc620e9a24f81508a0a0bc7a Mon Sep 17 00:00:00 2001 From: Yohan Totting Date: Tue, 27 Aug 2024 12:15:49 +0700 Subject: [PATCH] change quality none won't send packet --- bitratecontroller.go | 2 +- clienttrack.go | 14 ++++++++++++++ clienttracksvc.go | 7 ++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/bitratecontroller.go b/bitratecontroller.go index 201feae..6516e73 100644 --- a/bitratecontroller.go +++ b/bitratecontroller.go @@ -166,7 +166,7 @@ func (bc *bitrateController) totalBitrates() uint32 { func (bc *bitrateController) setQuality(clientTrackID string, quality QualityLevel) { if val, ok := bc.claims.Load(clientTrackID); ok { claim := val.(*bitrateClaim) - claim.quality = quality + claim.SetQuality(quality) bc.claims.Store(clientTrackID, claim) } diff --git a/clienttrack.go b/clienttrack.go index 16afde0..8335b2e 100644 --- a/clienttrack.go +++ b/clienttrack.go @@ -4,6 +4,7 @@ import ( "context" "sync" + "github.com/inlivedev/sfu/pkg/packetmap" "github.com/pion/rtp" "github.com/pion/webrtc/v4" ) @@ -41,6 +42,7 @@ type clientTrack struct { localTrack *webrtc.TrackLocalStaticRTP remoteTrack *remoteTrack baseTrack *baseTrack + packetmap *packetmap.Map isScreen bool ssrc webrtc.SSRC onTrackEndedCallbacks []func() @@ -68,6 +70,7 @@ func newClientTrack(c *Client, t ITrack, isScreen bool, localTrack *webrtc.Track isScreen: isScreen, ssrc: track.remoteTrack.track.SSRC(), onTrackEndedCallbacks: make([]func(), 0), + packetmap: &packetmap.Map{}, } t.OnEnded(func() { @@ -130,6 +133,13 @@ func (t *clientTrack) push(p *rtp.Packet, _ QualityLevel) { return } + ok, newseqno, _ := t.packetmap.Map(p.SequenceNumber, 0) + if !ok { + return + } + + p.SequenceNumber = newseqno + if t.Kind() == webrtc.RTPCodecTypeAudio { // do something here with audio level } @@ -140,6 +150,10 @@ func (t *clientTrack) push(p *rtp.Packet, _ QualityLevel) { if t.Kind() == webrtc.RTPCodecTypeVideo { quality := t.getQuality() if quality == QualityNone { + if ok := t.packetmap.Drop(p.SequenceNumber, 0); ok { + return + } + p.Payload = p.Payload[:0] } } diff --git a/clienttracksvc.go b/clienttracksvc.go index a4252cc..8c1670f 100644 --- a/clienttracksvc.go +++ b/clienttracksvc.go @@ -1,7 +1,6 @@ package sfu import ( - "github.com/inlivedev/sfu/pkg/packetmap" "github.com/pion/rtp" "github.com/pion/rtp/codecs" ) @@ -98,7 +97,6 @@ type scaleableClientTrack struct { lastTimestamp uint32 lastSequence uint16 init bool - packetmap *packetmap.Map } func newScaleableClientTrack( @@ -110,7 +108,6 @@ func newScaleableClientTrack( clientTrack: newClientTrack(c, t, false, nil), maxQuality: QualityHigh, lastQuality: QualityHigh, - packetmap: &packetmap.Map{}, } sct.SetMaxQuality(QualityHigh) @@ -243,6 +240,10 @@ func (t *scaleableClientTrack) push(p *rtp.Packet, _ QualityLevel) { // make sure the player is paused when the quality is none. // quality none only possible when the video is not displayed if quality == QualityNone { + if ok := t.packetmap.Drop(p.SequenceNumber, vp9Packet.PictureID); ok { + return + } + p.Payload = p.Payload[:0] }