-
Notifications
You must be signed in to change notification settings - Fork 56
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?
Conversation
Summary of ChangesHello @davidjiagoogle, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical bug in the camera's preview stabilization logic. Previously, the stabilization state could incorrectly persist across different camera modes, leading to an 'always on' stabilization effect even when not desired. The fix ensures that stabilization settings are correctly applied and reset when switching between various stabilization modes, preventing unintended behavior and improving the reliability of the camera preview. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request correctly fixes a bug where the preview stabilization state was not being reset properly. The change ensures that both preview and optical stabilization are explicitly enabled or disabled for each stabilization mode, preventing state from leaking between mode changes. I've suggested a small refactoring to make the logic more concise and align with the project's style guide for simplifying code.
|
It looks like we were missing some tests for stabilization mode from the beginning. Maybe some tests in CameraXCameraSystemTest would be good. If you look at this line, you'll see that the |
|
That's an excellent point, @temcguir! Adding comprehensive tests for stabilization modes in Here are some test suggestions you could add to import com.google.jetpackcamera.core.camera.CameraSystem
import com.google.jetpackcamera.core.camera.CameraState
import com.google.jetpackcamera.model.StabilizationMode
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.test.runTest
import org.junit.Assume.assumeTrue
import org.junit.Test
// Assuming cameraSystem and cameraState are initialized in a @Before method
// For example:
// private lateinit var cameraSystem: CameraSystem
// private lateinit var cameraState: CameraState
class CameraXCameraSystemTest {
// ... existing test setup and other tests ...
@Test
fun setStabilizationMode_on_updatesCameraState() = runTest {
// 1. Check that StabilizationMode.ON is supported by the camera device
assumeTrue(cameraSystem.isStabilizationModeSupported(StabilizationMode.ON))
// 2. Apply the stabilization mode
cameraSystem.setStabilizationMode(StabilizationMode.ON)
// 3. Wait for CameraState to reflect the change
cameraState.stabilizationMode.first { it == StabilizationMode.ON }
}
@Test
fun setStabilizationMode_optical_updatesCameraState() = runTest {
// 1. Check that StabilizationMode.OPTICAL is supported by the camera device
assumeTrue(cameraSystem.isStabilizationModeSupported(StabilizationMode.OPTICAL))
// 2. Apply the stabilization mode
cameraSystem.setStabilizationMode(StabilizationMode.OPTICAL)
// 3. Wait for CameraState to reflect the change
cameraState.stabilizationMode.first { it == StabilizationMode.OPTICAL }
}
@Test
fun setStabilizationMode_off_updatesCameraState() = runTest {
// StabilizationMode.OFF should generally always be supported.
// If there's a specific API to check for OFF support, it could be added here.
// 2. Apply the stabilization mode
cameraSystem.setStabilizationMode(StabilizationMode.OFF)
// 3. Wait for CameraState to reflect the change
cameraState.stabilizationMode.first { it == StabilizationMode.OFF }
}
@Test
fun setStabilizationMode_highQuality_updatesCameraState() = runTest {
// Note: HIGH_QUALITY is typically for video stabilization.
// If it can be applied to the preview use case and reflected in CameraState,
// this test is relevant. Otherwise, it might need to be adapted or skipped.
assumeTrue(cameraSystem.isStabilizationModeSupported(StabilizationMode.HIGH_QUALITY))
// 2. Apply the stabilization mode
cameraSystem.setStabilizationMode(StabilizationMode.HIGH_QUALITY)
// 3. Wait for CameraState to reflect the change
cameraState.stabilizationMode.first { it == StabilizationMode.HIGH_QUALITY }
}
// Helper function to check if a stabilization mode is supported.
// This would need to be implemented in your CameraSystem interface/implementation.
interface CameraSystem {
// ... other methods ...
fun isStabilizationModeSupported(mode: StabilizationMode): Boolean
suspend fun setStabilizationMode(mode: StabilizationMode)
}
// And CameraState would need to expose stabilizationMode as a StateFlow or similar observable.
interface CameraState {
// ... other properties ...
val stabilizationMode: StateFlow<StabilizationMode>
}
}Key considerations for these tests:
These tests will help confirm that the |
|
@gemini-code-assist, |
|
You are absolutely right, @temcguir! My apologies for overlooking the existing API. It's excellent that My test suggestions can be adapted to use the existing methods, and the Thank you for the correction! |
A bug was discovered where preview usecase retains the "ON" value for stabilization after video stabilization is set to true for video recording than switching to image capture mode.
This was caused by the when statement in createPreviewUseCase() not calling setPreviewStabilizationEnabled(false) in the StabilizationMode.OFF condition branch.
I made it so setPreviewStabilizationEnabled(false) and setOpticalStabilizationModeEnabled(false) are called in all 3 other branches