-
Notifications
You must be signed in to change notification settings - Fork 57
Preview stabilisation fix #463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ea5b8c9
24f1c8c
80f3fef
7d1f532
1268ac8
122d27e
52e3c49
bf2c90c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,11 +39,13 @@ import com.google.jetpackcamera.model.FlashMode | |
| import com.google.jetpackcamera.model.Illuminant | ||
| import com.google.jetpackcamera.model.LensFacing | ||
| import com.google.jetpackcamera.model.SaveLocation | ||
| import com.google.jetpackcamera.model.StabilizationMode | ||
| import com.google.jetpackcamera.settings.ConstraintsRepository | ||
| import com.google.jetpackcamera.settings.SettableConstraintsRepository | ||
| import com.google.jetpackcamera.settings.SettableConstraintsRepositoryImpl | ||
| import com.google.jetpackcamera.settings.model.CameraAppSettings | ||
| import com.google.jetpackcamera.settings.model.DEFAULT_CAMERA_APP_SETTINGS | ||
| import com.google.jetpackcamera.settings.model.forCurrentLens | ||
| import java.io.File | ||
| import java.util.AbstractMap | ||
| import javax.inject.Provider | ||
|
|
@@ -225,6 +227,70 @@ class CameraXCameraSystemTest { | |
| recordingComplete.await() | ||
| } | ||
|
|
||
| @Test | ||
| fun setStabilizationMode_on_updatesCameraState(): Unit = runBlocking { | ||
| runSetStabilizationModeTest(StabilizationMode.ON) | ||
| } | ||
|
|
||
| @Test | ||
| fun setStabilizationMode_optical_updatesCameraState(): Unit = runBlocking { | ||
| runSetStabilizationModeTest(StabilizationMode.OPTICAL) | ||
| } | ||
|
|
||
| @Test | ||
| fun setStabilizationMode_highQuality_updatesCameraState(): Unit = runBlocking { | ||
| runSetStabilizationModeTest(StabilizationMode.HIGH_QUALITY) | ||
| } | ||
|
|
||
| private suspend fun CoroutineScope.runSetStabilizationModeTest( | ||
| stabilizationMode: StabilizationMode | ||
| ) { | ||
| // Arrange. | ||
| val constraintsRepository = SettableConstraintsRepositoryImpl() | ||
| val appSettings = CameraAppSettings(stabilizationMode = StabilizationMode.OFF) | ||
| val cameraSystem = createAndInitCameraXCameraSystem( | ||
| appSettings = appSettings, | ||
| constraintsRepository = constraintsRepository | ||
| ) | ||
| val cameraConstraints = | ||
| constraintsRepository.systemConstraints.value?.forCurrentLens(appSettings) | ||
| assume().withMessage("Stabilisation $stabilizationMode not supported, skip the test.") | ||
| .that( | ||
| cameraConstraints != null && cameraConstraints.supportedStabilizationModes.contains( | ||
| stabilizationMode | ||
| ) | ||
| ).isTrue() | ||
| cameraSystem.setStabilizationMode(stabilizationMode) | ||
| val stabilizationCheck: ReceiveChannel<Boolean> = cameraSystem.getCurrentCameraState() | ||
| .map { it.stabilizationMode == stabilizationMode } | ||
| .produceIn(this) | ||
| stabilizationCheck.awaitValue(false) | ||
| cameraSystem.startCameraAndWaitUntilRunning() | ||
|
|
||
| // Act. | ||
| val recordingComplete = CompletableDeferred<Unit>() | ||
| cameraSystem.startRecording { | ||
| when (it) { | ||
| is OnVideoRecorded -> { | ||
| recordingComplete.complete(Unit) | ||
| } | ||
|
|
||
| is OnVideoRecordError -> recordingComplete.completeExceptionally(it.error) | ||
| } | ||
| } | ||
|
|
||
| // Assert. | ||
| stabilizationCheck.awaitValue(true) | ||
|
|
||
| cameraSystem.stopVideoRecording() | ||
|
|
||
| stabilizationCheck.awaitValue(true) | ||
|
|
||
| // Clean-up. | ||
| recordingComplete.await() | ||
| stabilizationCheck.cancel() | ||
| } | ||
|
Comment on lines
+263
to
+292
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should be able to replace all of this code with: and it should pass. However, it doesn't seem to pass for HIGH_QUALITY and OPTICAL, with or without your other changes. I think there is something else wrong. |
||
|
|
||
| @Test | ||
| fun recordVideoWithFlashModeOn_shouldEnableTorch(): Unit = runBlocking { | ||
| // Arrange. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -748,13 +748,24 @@ private fun createPreviewUseCase( | |
| targetCameraInfo = cameraInfo, | ||
| captureResults = captureResults | ||
| ) | ||
|
|
||
| // set preview stabilization | ||
| when (stabilizationMode) { | ||
| StabilizationMode.ON -> setPreviewStabilizationEnabled(true) | ||
| StabilizationMode.OPTICAL -> setOpticalStabilizationModeEnabled(true) | ||
| StabilizationMode.OFF -> setOpticalStabilizationModeEnabled(false) | ||
| StabilizationMode.HIGH_QUALITY -> {} // No-op. Handled by VideoCapture use case. | ||
| StabilizationMode.ON -> { | ||
| setPreviewStabilizationEnabled(true) | ||
| setOpticalStabilizationModeEnabled(false) | ||
| } | ||
|
|
||
| StabilizationMode.OPTICAL -> { | ||
| setPreviewStabilizationEnabled(false) | ||
| setOpticalStabilizationModeEnabled(true) | ||
| } | ||
| StabilizationMode.OFF -> { | ||
| setPreviewStabilizationEnabled(false) | ||
| setOpticalStabilizationModeEnabled(false) | ||
| } | ||
| StabilizationMode.HIGH_QUALITY -> { | ||
| // No-op. Handled by VideoCapture use case. | ||
| } | ||
|
Comment on lines
+753
to
+768
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It shouldn't be necessary to set all of these. This is creating a new preview use case, so the absence of setting preview stabilization to |
||
| else -> throw UnsupportedOperationException( | ||
| "Unexpected stabilization mode: $stabilizationMode. Stabilization mode should always " + | ||
| "an explicit mode, such as ON, OPTICAL, OFF or HIGH_QUALITY" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need to create a recording to test this.