mirror of
https://github.com/netbirdio/netbird.git
synced 2026-09-24 07:39:07 +02:00
Honour client JPEG quality fully now that backpressure caps it dynamically
This commit is contained in:
@@ -544,10 +544,9 @@ func newTightStateWithLevels(qualityLevel, compressLevel int) *tightState {
|
|||||||
|
|
||||||
// jpegQualityForLevel maps a 0..9 client preference to a JPEG quality value.
|
// jpegQualityForLevel maps a 0..9 client preference to a JPEG quality value.
|
||||||
// Returns 0 when no preference is set (-1), letting the encoder fall back
|
// Returns 0 when no preference is set (-1), letting the encoder fall back
|
||||||
// to the area-based tiers. The output is capped at jpegQualityClientCap
|
// to the area-based tiers. The encoder lowers this dynamically when the
|
||||||
// so a client asking for the highest quality does not push per-frame JPEG
|
// socket is backpressured, so this routine emits the unclamped, client-
|
||||||
// byte counts into a regime that overwhelms bandwidth-constrained
|
// requested value.
|
||||||
// transports. Within the cap the mapping is still linear.
|
|
||||||
func jpegQualityForLevel(level int) int {
|
func jpegQualityForLevel(level int) int {
|
||||||
if level < 0 {
|
if level < 0 {
|
||||||
return 0
|
return 0
|
||||||
@@ -555,19 +554,9 @@ func jpegQualityForLevel(level int) int {
|
|||||||
if level > 9 {
|
if level > 9 {
|
||||||
level = 9
|
level = 9
|
||||||
}
|
}
|
||||||
q := 30 + level*7
|
return 30 + level*7
|
||||||
if q > jpegQualityClientCap {
|
|
||||||
q = jpegQualityClientCap
|
|
||||||
}
|
|
||||||
return q
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// jpegQualityClientCap upper-bounds the JPEG quality we honour from the
|
|
||||||
// client's QualityLevel pseudo-encoding. 50 keeps full-screen JPEGs in
|
|
||||||
// the same byte range as the area-tiered defaults used when the client
|
|
||||||
// does not express a preference.
|
|
||||||
const jpegQualityClientCap = 50
|
|
||||||
|
|
||||||
// zlibLevelFor maps a 0..9 client preference to a zlib compression level.
|
// zlibLevelFor maps a 0..9 client preference to a zlib compression level.
|
||||||
// Level 0 ("no compression") would emit larger output than input on most
|
// Level 0 ("no compression") would emit larger output than input on most
|
||||||
// rects, so we floor to BestSpeed (1). -1 (no preference) also picks
|
// rects, so we floor to BestSpeed (1). -1 (no preference) also picks
|
||||||
|
|||||||
Reference in New Issue
Block a user