Skip to content

Commit

Permalink
change quality none won't send packet
Browse files Browse the repository at this point in the history
  • Loading branch information
Yohan Totting committed Aug 27, 2024
1 parent 54a7f3e commit 1023c3c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bitratecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
14 changes: 14 additions & 0 deletions clienttrack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"sync"

"github.com/inlivedev/sfu/pkg/packetmap"
"github.com/pion/rtp"
"github.com/pion/webrtc/v4"
)
Expand Down Expand Up @@ -41,6 +42,7 @@ type clientTrack struct {
localTrack *webrtc.TrackLocalStaticRTP
remoteTrack *remoteTrack
baseTrack *baseTrack
packetmap *packetmap.Map
isScreen bool
ssrc webrtc.SSRC
onTrackEndedCallbacks []func()
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}
Expand All @@ -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]
}
}
Expand Down
7 changes: 4 additions & 3 deletions clienttracksvc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package sfu

import (
"github.com/inlivedev/sfu/pkg/packetmap"
"github.com/pion/rtp"
"github.com/pion/rtp/codecs"
)
Expand Down Expand Up @@ -98,7 +97,6 @@ type scaleableClientTrack struct {
lastTimestamp uint32
lastSequence uint16
init bool
packetmap *packetmap.Map
}

func newScaleableClientTrack(
Expand All @@ -110,7 +108,6 @@ func newScaleableClientTrack(
clientTrack: newClientTrack(c, t, false, nil),
maxQuality: QualityHigh,
lastQuality: QualityHigh,
packetmap: &packetmap.Map{},
}

sct.SetMaxQuality(QualityHigh)
Expand Down Expand Up @@ -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]
}

Expand Down

0 comments on commit 1023c3c

Please sign in to comment.