commit d33668bb41911988d3742f659582dbed77f93911
parent b0b20894a603bca88e822e7fc6830705d2ce5a37
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Tue, 9 Apr 2024 22:12:46 +0200
fix(core): camera fps range
Diffstat:
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/tweaks/CameraTweaks.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/features/impl/tweaks/CameraTweaks.kt
@@ -18,6 +18,7 @@ import me.rhunk.snapenhance.core.util.hook.hook
import me.rhunk.snapenhance.core.util.ktx.setObjectField
import java.io.ByteArrayOutputStream
import java.nio.ByteBuffer
+import kotlin.math.abs
class CameraTweaks : Feature("Camera Tweaks", loadParams = FeatureLoadParams.ACTIVITY_CREATE_SYNC) {
@@ -93,11 +94,16 @@ class CameraTweaks : Feature("Camera Tweaks", loadParams = FeatureLoadParams.ACT
val customFrameRate = (if (isFrontCamera) config.frontCustomFrameRate.getNullable() else config.backCustomFrameRate.getNullable())?.toIntOrNull() ?: return@hook
val fpsRanges = param.getResult() as? Array<*> ?: return@hook
- fpsRanges.forEach {
- val range = it as? Range<*> ?: return@forEach
- range.setObjectField("mUpper", customFrameRate)
- range.setObjectField("mLower", customFrameRate)
+ if (customFrameRate <= 30) {
+ param.setResult(arrayOf(Range(customFrameRate, customFrameRate)))
+ return@hook
}
+
+ val closestMaxFps = fpsRanges.mapNotNull {
+ (it as? Range<*>)?.upper?.toString()?.toIntOrNull()
+ }.minByOrNull { abs(it - customFrameRate) } ?: return@hook
+
+ param.setResult(arrayOf(Range(closestMaxFps, closestMaxFps)))
}
}