Skip to content

Commit

Permalink
fix concurrent write map issue (#13)
Browse files Browse the repository at this point in the history
adjust video size comparison

Co-authored-by: Yohan Totting <[email protected]>
  • Loading branch information
Yohan Totting and Yohan Totting authored Dec 6, 2023
1 parent 9f49353 commit d011cbe
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
26 changes: 14 additions & 12 deletions bitratecontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ func (bc *bitrateController) MonitorBandwidth(estimator cc.BandwidthEstimator) {
// each time adjustment needed, it will only increase or decrese single track.
func (bc *bitrateController) checkAndAdjustBitrates() {
claims := bc.Claims()
lowestQuality := QualityLevel(QualityHigh)
highestQuality := QualityLevel(QualityNone)
currentLowestQuality := QualityLevel(QualityHigh)
currentHighestQuality := QualityLevel(QualityNone)

noneCount := 0
lowCount := 0
Expand All @@ -498,12 +498,12 @@ func (bc *bitrateController) checkAndAdjustBitrates() {
bc.setQuality(claim.track.ID(), quality)
}

if claim.quality < lowestQuality {
lowestQuality = claim.quality
if claim.quality < currentLowestQuality {
currentLowestQuality = claim.quality
}

if claim.quality > highestQuality {
highestQuality = claim.quality
if claim.quality > currentHighestQuality {
currentHighestQuality = claim.quality
}

if claim.track.IsScreen() {
Expand Down Expand Up @@ -550,13 +550,15 @@ func (bc *bitrateController) checkAndAdjustBitrates() {
continue
}

if claim.track.IsScreen() && reducedQuality == QualityNone {
// never reduce screen track to none
if reducedQuality == QualityNone {
// never reduce track to none
// this could make the ontrack never triggered on the receiver
continue
} else if claim.track.IsScreen() && bc.isThereNonScreenCanDecrease(lowestQuality) {
} else if claim.track.IsScreen() && bc.isThereNonScreenCanDecrease(currentLowestQuality) {
// skip if there is a non screen track can be reduced
continue
}

if claim.track.IsSimulcast() {
claim.track.(*simulcastClientTrack).remoteTrack.sendPLI(reducedQuality)
} else {
Expand All @@ -579,7 +581,7 @@ func (bc *bitrateController) checkAndAdjustBitrates() {
continue
}

if !claim.track.IsScreen() && bc.isScreenNeedIncrease(highestQuality) {
if !claim.track.IsScreen() && bc.isScreenNeedIncrease(currentHighestQuality) {
continue
}

Expand Down Expand Up @@ -627,9 +629,9 @@ func (bc *bitrateController) onRemoteViewedSizeChanged(videoSize videoSize) {
claim.track.SetMaxQuality(QualityNone)
}

if videoSize.Width <= bc.client.sfu.bitratesConfig.VideoLowPixels {
if videoSize.Width*videoSize.Height <= bc.client.sfu.bitratesConfig.VideoLowPixels {
claim.track.SetMaxQuality(QualityLow)
} else if videoSize.Width <= bc.client.sfu.bitratesConfig.VideoMidPixels {
} else if videoSize.Width*videoSize.Height <= bc.client.sfu.bitratesConfig.VideoMidPixels {
claim.track.SetMaxQuality(QualityMid)
} else {
claim.track.SetMaxQuality(QualityHigh)
Expand Down
4 changes: 2 additions & 2 deletions room.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ func (r *Room) onClientLeft(client *Client) {
}

// update the latest stats from client before they left
// r.mutex.Lock()
// defer r.mutex.Unlock()
r.mutex.Lock()
defer r.mutex.Unlock()

r.stats[client.ID()] = client.Stats()
}
Expand Down
6 changes: 3 additions & 3 deletions sfu.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func DefaultBitrates() BitratesConfig {
Audio: 48_000,
Video: 1_200_000,
VideoHigh: 1_200_000,
VideoHighPixels: 720,
VideoHighPixels: 720 * 360,
VideoMid: 500_000,
VideoMidPixels: 360,
VideoMidPixels: 360 * 180,
VideoLow: 150_000,
VideoLowPixels: 180,
VideoLowPixels: 180 * 90,
InitialBandwidth: 1_000_000,
}
}
Expand Down

0 comments on commit d011cbe

Please sign in to comment.