Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Comment on lines +271 to +280
Copy link
Collaborator

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.


// Assert.
stabilizationCheck.awaitValue(true)

cameraSystem.stopVideoRecording()

stabilizationCheck.awaitValue(true)

// Clean-up.
recordingComplete.await()
stabilizationCheck.cancel()
}
Comment on lines +263 to +292
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to replace all of this code with:

        val stabilizationCheck: ReceiveChannel<StabilizationMode> = cameraSystem.getCurrentCameraState()
            .map { it.stabilizationMode }
            .produceIn(this)
        cameraSystem.startCameraAndWaitUntilRunning()

        // Act.
        cameraSystem.setStabilizationMode(stabilizationMode)

        // Assert.
        stabilizationCheck.awaitValue(stabilizationMode)

        // Clean-up.
        stabilizationCheck.cancel()

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 true should be sufficient. Also, setting optical stabilization to false when preview stabilization is true is not the right thing to do. There is nothing that says optical stabilization needs to be disabled when preview stabilization is enabled. We should leave it to the camera on whether to enable or disable optical stabilization.

else -> throw UnsupportedOperationException(
"Unexpected stabilization mode: $stabilizationMode. Stabilization mode should always " +
"an explicit mode, such as ON, OPTICAL, OFF or HIGH_QUALITY"
Expand Down
Loading