Skip to content

Commit

Permalink
fix: Set minFPS to 20 to allow maximum resolution photo (#3063)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy authored Jul 10, 2024
1 parent c69de2a commit a8ba80d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mrousavy.camera.core

import android.util.Range
import androidx.camera.core.Preview.SurfaceProvider
import com.mrousavy.camera.core.types.CameraDeviceFormat
import com.mrousavy.camera.core.types.CodeType
Expand All @@ -8,6 +9,7 @@ import com.mrousavy.camera.core.types.PixelFormat
import com.mrousavy.camera.core.types.QualityBalance
import com.mrousavy.camera.core.types.Torch
import com.mrousavy.camera.core.types.VideoStabilizationMode
import kotlin.math.min

data class CameraConfiguration(
// Input
Expand Down Expand Up @@ -51,6 +53,14 @@ data class CameraConfiguration(
data class Audio(val nothing: Unit)
data class Preview(val surfaceProvider: SurfaceProvider)

val targetFpsRange: Range<Int>?
get() {
// due to a bug (or feature?) in CameraX, photo resolution will suffer if min FPS is higher than 20.
val maxFps = fps ?: return null
val minFps = min(20, maxFps)
return Range(minFps, maxFps)
}

val targetPreviewAspectRatio: Float?
get() {
val format = format ?: return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.mrousavy.camera.core

import android.annotation.SuppressLint
import android.util.Log
import android.util.Range
import androidx.annotation.OptIn
import androidx.camera.core.CameraSelector
import androidx.camera.core.CameraState
Expand All @@ -25,16 +24,7 @@ import com.mrousavy.camera.core.types.Torch
import com.mrousavy.camera.core.types.VideoStabilizationMode
import kotlin.math.roundToInt

internal fun getTargetFpsRange(configuration: CameraConfiguration): Range<Int>? {
val fps = configuration.fps ?: return null
return if (configuration.enableLowLightBoost) {
Range(fps / 2, fps)
} else {
Range(fps, fps)
}
}

internal fun assertFormatRequirement(
private fun assertFormatRequirement(
propName: String,
format: CameraDeviceFormat?,
throwIfNotMet: CameraError,
Expand All @@ -55,7 +45,7 @@ internal fun assertFormatRequirement(
@Suppress("LiftReturnOrAssignment")
internal fun CameraSession.configureOutputs(configuration: CameraConfiguration) {
Log.i(CameraSession.TAG, "Creating new Outputs for Camera #${configuration.cameraId}...")
val fpsRange = getTargetFpsRange(configuration)
val fpsRange = configuration.targetFpsRange
val format = configuration.format

Log.i(CameraSession.TAG, "Using FPS Range: $fpsRange")
Expand Down

0 comments on commit a8ba80d

Please sign in to comment.