davidliu
Committed by GitHub

Fix maxFps not applying for very low framerates (#573)

  1 +---
  2 +"client-sdk-android": patch
  3 +---
  4 +
  5 +Fix maxFps not applying for very low framerates
1 /* 1 /*
2 - * Copyright 2023-2024 LiveKit, Inc. 2 + * Copyright 2023-2025 LiveKit, Inc.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@ import livekit.org.webrtc.VideoCapturer @@ -69,6 +69,7 @@ import livekit.org.webrtc.VideoCapturer
69 import livekit.org.webrtc.VideoProcessor 69 import livekit.org.webrtc.VideoProcessor
70 import javax.inject.Named 70 import javax.inject.Named
71 import kotlin.math.max 71 import kotlin.math.max
  72 +import kotlin.math.min
72 73
73 class LocalParticipant 74 class LocalParticipant
74 @AssistedInject 75 @AssistedInject
@@ -591,7 +592,7 @@ internal constructor( @@ -591,7 +592,7 @@ internal constructor(
591 // if resolution is high enough, we send both h and q res. 592 // if resolution is high enough, we send both h and q res.
592 // otherwise only send h 593 // otherwise only send h
593 val size = max(width, height) 594 val size = max(width, height)
594 - 595 + val maxFps = encoding.maxFps
595 fun calculateScaleDown(captureParam: VideoCaptureParameter): Double { 596 fun calculateScaleDown(captureParam: VideoCaptureParameter): Double {
596 val targetSize = max(captureParam.width, captureParam.height) 597 val targetSize = max(captureParam.width, captureParam.height)
597 return size / targetSize.toDouble() 598 return size / targetSize.toDouble()
@@ -600,11 +601,11 @@ internal constructor( @@ -600,11 +601,11 @@ internal constructor(
600 val lowScale = calculateScaleDown(lowPreset.capture) 601 val lowScale = calculateScaleDown(lowPreset.capture)
601 val midScale = calculateScaleDown(midPreset.capture) 602 val midScale = calculateScaleDown(midPreset.capture)
602 603
603 - addEncoding(lowPreset.encoding, lowScale)  
604 - addEncoding(midPreset.encoding, midScale) 604 + addEncoding(lowPreset.encoding.copy(maxFps = min(lowPreset.encoding.maxFps, maxFps)), lowScale)
  605 + addEncoding(midPreset.encoding.copy(maxFps = min(midPreset.encoding.maxFps, maxFps)), midScale)
605 } else { 606 } else {
606 val lowScale = calculateScaleDown(lowPreset.capture) 607 val lowScale = calculateScaleDown(lowPreset.capture)
607 - addEncoding(lowPreset.encoding, lowScale) 608 + addEncoding(lowPreset.encoding.copy(maxFps = min(lowPreset.encoding.maxFps, maxFps)), lowScale)
608 } 609 }
609 addEncoding(encoding, 1.0) 610 addEncoding(encoding, 1.0)
610 } else { 611 } else {