1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-22 15:25:48 +01:00

Add spatial scalability support.

Only used as a last-resort fallback.
This commit is contained in:
Juliusz Chroboczek 2021-08-01 13:56:55 +02:00
parent efb298f002
commit dd4dbeaee5

View file

@ -304,21 +304,32 @@ func (t *rtpDownTrack) GetMaxBitrate() (uint64, int, int) {
return r, int(layer.sid), int(layer.tid)
}
// adjustLayer checks the allowable bitrate reported for a down track and
// adjusts the layer by one step. It prefers temporal layers, and only
// uses spatial layers as a last resort.
func (t *rtpDownTrack) adjustLayer() {
max, _, _ := t.GetMaxBitrate()
r, _ := t.rate.Estimate()
rate := uint64(r) * 8
if rate < max*7/8 {
// switch up
layer := t.getLayerInfo()
if layer.tid < layer.maxTid {
if layer.sid < layer.maxSid {
layer.wantedSid = layer.sid + 1
t.setLayerInfo(layer)
} else if layer.tid < layer.maxTid {
layer.wantedTid = layer.tid + 1
t.setLayerInfo(layer)
}
} else if rate > max*3/2 {
// switch down
layer := t.getLayerInfo()
if layer.tid > 0 {
layer.wantedTid = layer.tid - 1
t.setLayerInfo(layer)
} else if layer.sid > 0 {
layer.wantedSid = layer.sid - 1
t.setLayerInfo(layer)
}
}
}