Skip to content

Commit a198a0a

Browse files
committed
Handle cases when 30 fps is unavailable
(and prevent crash when video mode is directly turned on)
1 parent 31976fd commit a198a0a

2 files changed

Lines changed: 25 additions & 11 deletions

File tree

app/src/main/java/app/grapheneos/camera/CamConfig.kt

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ class CamConfig(private val mActivity: MainActivity) {
361361
modePref.getString(videoFrameRateKey, "")!!
362362
)
363363
} else {
364-
SettingValues.Default.VIDEO_FRAME_RATE
364+
defaultVideoFrameRate
365365
}
366366
}
367367
set(value) {
@@ -383,6 +383,14 @@ class CamConfig(private val mActivity: MainActivity) {
383383
return "${SettingValues.Key.VIDEO_FRAME_RATE}_$pf"
384384
}
385385

386+
val defaultVideoFrameRate : Range<Int>
387+
get() {
388+
val availableFrameRates = getAvailableVideoFrameRates()
389+
if (availableFrameRates.contains(SettingValues.Default.VIDEO_FRAME_RATE))
390+
return SettingValues.Default.VIDEO_FRAME_RATE
391+
return availableFrameRates[0]
392+
}
393+
386394
var flashMode: Int
387395
get() = if (imageCapture != null) imageCapture!!.flashMode else
388396
SettingValues.Default.FLASH_MODE
@@ -956,6 +964,19 @@ class CamConfig(private val mActivity: MainActivity) {
956964
else frontCameraInfo!!
957965
}
958966

967+
fun getAvailableVideoFrameRates(): List<Range<Int>> {
968+
val resSet = getCurrentCameraInfo().supportedFrameRateRanges
969+
970+
// Individual fps -> Ranged fps (sorted by lower value of range and then upper for each lower value)
971+
val resList = resSet.sortedWith(compareBy<Range<Int>> { it.lower != it.upper }.thenBy { it.lower }.thenBy { it.upper })
972+
973+
// If the supportedFrameRateRange list is somehow empty due to device/library implementation
974+
// go with the most likely default rate
975+
if (resList.isEmpty()) return listOf(SettingValues.Default.VIDEO_FRAME_RATE)
976+
977+
return resList
978+
}
979+
959980
fun toggleCameraSelector() {
960981

961982
// Manually switch to the opposite lens facing
@@ -1060,7 +1081,6 @@ class CamConfig(private val mActivity: MainActivity) {
10601081
if (mActivity.isDestroyed || mActivity.isFinishing) return
10611082

10621083
cameraSelector = CameraSelector.Builder()
1063-
.requireLensFacing(lensFacing)
10641084
.addCameraFilter {
10651085
return@addCameraFilter listOf(
10661086
if (lensFacing == CameraSelector.LENS_FACING_BACK) {

app/src/main/java/app/grapheneos/camera/ui/SettingsDialog.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -664,12 +664,6 @@ class SettingsDialog(val mActivity: MainActivity) :
664664
return Recorder.getVideoCapabilities(cameraInfo).getSupportedQualities(DynamicRange.SDR)
665665
}
666666

667-
private fun getAvailableVideoFrameRates(): List<Range<Int>> {
668-
val resSet = camConfig.camera?.cameraInfo?.supportedFrameRateRanges ?: Collections.emptySet()
669-
// Individual fps -> Ranged fps (sorted by lower value of range and then upper for each lower value)
670-
val resList = resSet.sortedWith(compareBy<Range<Int>> { it.lower != it.upper }.thenBy { it.lower }.thenBy { it.upper })
671-
return resList
672-
}
673667

674668
private fun getAvailableQualityTitles(): List<String> {
675669
val titles = arrayListOf<String>()
@@ -681,10 +675,10 @@ class SettingsDialog(val mActivity: MainActivity) :
681675
return titles
682676
}
683677

684-
private fun getAvailableFRTitles(): List<String> {
678+
private fun getAvailableFrameRateTitles(): List<String> {
685679
val titles = arrayListOf<String>()
686680

687-
getAvailableVideoFrameRates().forEach {
681+
camConfig.getAvailableVideoFrameRates().forEach {
688682
titles.add(getTitleForFrameRateRange(it))
689683
}
690684

@@ -742,7 +736,7 @@ class SettingsDialog(val mActivity: MainActivity) :
742736
fun reloadVideoSettings() {
743737

744738
val qualityTitles = getAvailableQualityTitles()
745-
val frameRateTitles = getAvailableFRTitles()
739+
val frameRateTitles = getAvailableFrameRateTitles()
746740

747741
videoQualityAdapter = ArrayAdapter<String>(
748742
mActivity,

0 commit comments

Comments
 (0)