-
Notifications
You must be signed in to change notification settings - Fork 776
Repurpose repo with new samples #108
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
Conversation
These new samples demonstrate Android Camera & Media user experiences that leverage AI. Please see the old-media-samples tag in this repo to find the previous samples that were hosted here.
Summary of ChangesHello @SigmanZero, 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 represents a significant update to the repository's sample content. It systematically removes outdated media-related samples and introduces a suite of new, modern examples built with CameraX and Jetpack Compose. These new samples demonstrate advanced functionalities such as real-time green screen effects using ML Kit and voice-activated camera controls powered by Firebase AI, providing contemporary and relevant showcases for Android developers. Highlights
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 repurposes the repository by removing old media samples and adding three new ones demonstrating CameraX features: a basic app, a green screen effect app, and a voice control app. My review focuses on the new code. I've identified a critical performance issue and a high-severity race condition in the green screen sample due to incorrect threading and state management. I've also pointed out that the voice control sample has its core functionality commented out, rendering it non-functional. Additionally, there's a medium-severity maintainability issue with magic numbers.
| ) | ||
| } else if (effectMode.value == EffectMode.GREEN_SCREEN) { | ||
| imageAnalyzer.setAnalyzer( | ||
| ContextCompat.getMainExecutor(application), |
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.
The SelfieSegmentationAnalyzer is being run on the main executor. The analyze method performs several heavy operations like bitmap creation and transformations, which can block the main thread and cause UI jank. This analyzer should be run on a background thread. You already have a cameraExecutor which would be suitable for this.
| ContextCompat.getMainExecutor(application), | |
| cameraExecutor, |
| lateinit var mask: Bitmap | ||
| lateinit var bitmap: Bitmap |
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.
These top-level lateinit var properties are used to share data between the SelfieSegmentationAnalyzer and the OverlayEffect.OnDrawListener. This is not thread-safe and can lead to race conditions, as the analyzer and the draw listener can run on different threads. This can result in tearing, where the bitmap and mask are from different frames.
A better approach is to use a thread-safe mechanism to pass data. For example, you could encapsulate the bitmap and mask in a data class and use an AtomicReference to update and read them atomically.
Example:
// 1. Define a data class
data class SegmentationResult(val bitmap: Bitmap, val mask: Bitmap)
// 2. Replace the lateinit vars with an AtomicReference
private val segmentationResult = AtomicReference<SegmentationResult?>()
// 3. In SelfieSegmentationAnalyzer, at the end of analyze:
segmentationResult.set(SegmentationResult(bitmap, mask))
// 4. In greenScreenEffect.setOnDrawListener:
val result = segmentationResult.get()
if (result != null) {
// ... use result.bitmap and result.mask
}| // val model = Firebase.ai(backend = GenerativeBackend.googleAI()).liveModel( | ||
| // modelName = "gemini-live-2.5-flash-preview", | ||
| // generationConfig = liveGenerationConfig { | ||
| // responseModality = ResponseModality.AUDIO | ||
| // speechConfig = SpeechConfig(voice = Voice("FENRIR")) | ||
| // }, | ||
| // systemInstruction = systemInstruction, | ||
| // tools = listOf(cameraControlTool)) |
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.
The initialization of the Gemini liveModel is commented out, which makes the voice control feature non-functional. The call to model.connect() in startVoiceControl() is also commented out. Was this intentional? If this sample is meant to demonstrate voice control, this code should be enabled, perhaps with instructions for developers on how to configure their own API key.
| frame.overlayCanvas.drawColor(GraphicsColor.TRANSPARENT, PorterDuff.Mode.CLEAR) | ||
|
|
||
| // Draw the bitmap and mask, positioning the overlay in the bottom right corner. | ||
| val rect = Rect(4*bitmap.width/3, bitmap.height/2, 7 * bitmap.width/3, 3*bitmap.height/2) |
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.
No description provided.