Skip to content

Commit

Permalink
Fix stabilization issue (#114)
Browse files Browse the repository at this point in the history
* fix logical errors with stabilization implementation
  • Loading branch information
Kimblebee committed Feb 20, 2024
1 parent b4f8528 commit 5565eeb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* Copyright (C) 2023-2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -191,7 +191,7 @@ class LocalSettingsRepository @Inject constructor(
override suspend fun updatePreviewStabilizationSupported(isSupported: Boolean) {
jcaSettings.updateData { currentSettings ->
currentSettings.toBuilder()
.setStabilizeVideoSupported(isSupported)
.setStabilizePreviewSupported(isSupported)
.build()
}
}
Expand All @@ -201,10 +201,10 @@ class LocalSettingsRepository @Inject constructor(
videoSupport: Boolean
): List<SupportedStabilizationMode> {
return buildList {
if (previewSupport && videoSupport) {
if (previewSupport) {
add(SupportedStabilizationMode.ON)
}
if (!previewSupport && videoSupport) {
if (videoSupport) {
add(SupportedStabilizationMode.HIGH_QUALITY)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ constructor(
availableCameraLens.contains(CameraSelector.LENS_FACING_FRONT),
availableCameraLens.contains(CameraSelector.LENS_FACING_BACK)
)
settingsRepository.updateVideoStabilizationSupported(isStabilizationSupported())
settingsRepository.updatePreviewStabilizationSupported(
isPreviewStabilizationSupported()
)
settingsRepository.updateVideoStabilizationSupported(isVideoStabilizationSupported())
}
videoCaptureUseCase = createVideoUseCase()
updateUseCaseGroup()
Expand Down Expand Up @@ -416,7 +419,7 @@ constructor(
* Checks if video stabilization is supported by the device.
*
*/
private fun isStabilizationSupported(): Boolean {
private fun isVideoStabilizationSupported(): Boolean {
val availableCameraInfo = cameraProvider.availableCameraInfos
val cameraSelector = if (isFrontFacing) {
CameraSelector.DEFAULT_FRONT_CAMERA
Expand All @@ -427,10 +430,28 @@ constructor(
cameraSelector.filter(availableCameraInfo).firstOrNull()?.let {
Recorder.getVideoCapabilities(it).isStabilizationSupported
} ?: false

return isVideoStabilizationSupported
}

/**
* Checks if preview stabilization is supported by the device.
*
*/
private fun isPreviewStabilizationSupported(): Boolean {
val availableCameraInfo = cameraProvider.availableCameraInfos
val cameraSelector = if (isFrontFacing) {
CameraSelector.DEFAULT_FRONT_CAMERA
} else {
CameraSelector.DEFAULT_BACK_CAMERA
}
val isPreviewStabilizationSupported =
cameraSelector.filter(availableCameraInfo).firstOrNull()?.let {
Preview.getPreviewCapabilities(it).isStabilizationSupported
} ?: false

return isPreviewStabilizationSupported
}

private fun createVideoUseCase(): VideoCapture<Recorder> {
val videoCaptureBuilder = VideoCapture.Builder(recorder)

Expand Down

0 comments on commit 5565eeb

Please sign in to comment.