Skip to content

Commit

Permalink
fix(core): camera fps range
Browse files Browse the repository at this point in the history
  • Loading branch information
rhunk committed Apr 9, 2024
1 parent b0b2089 commit d33668b
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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)))
}
}

Expand Down

0 comments on commit d33668b

Please sign in to comment.