Repository navigation
[camera_android, camera_android_camerax, camera_avfoundation] Add setJpegImageQuality - #11616
Conversation
There was a problem hiding this comment.
Code Review
This pull request adds the setJpegImageQuality method to the CameraController and implements it across the Android (Camera2 and CameraX) and iOS (AVFoundation) platform packages. Review feedback identifies a potential ClassCastException in the Android Camera2 implementation due to an incorrect type cast, the loss of flashMode state when recreating the ImageCapture use case in CameraX, and the unintended discarding of capture configurations in the iOS implementation.
|
@bparrishMines This is the new PR with only the platform implementation changes as requested. The platform interface was already landed in #11454. The app-facing camera package will follow after these are published. |
|
@hellohuanlin friendly ping from triage |
|
From Android Triage: our subject matter expert is out of town. They will review when they get back. |
|
This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled. |
a3fbc52 to
ccd735a
Compare
camsim99
left a comment
There was a problem hiding this comment.
Android overall LGTM! Left some comments regarding tests.
ccd735a to
a1a412e
Compare
There was a problem hiding this comment.
LGTM
@camsim99 We can go ahead and merge this after your approval of the changes from your review comments.
|
@Bolling88 I don't see any new changes. Did you push them? |
Adds setJpegImageQuality(int quality) across all camera platform implementations (Android, Android CameraX, iOS AVFoundation) and the app-facing camera package. This allows controlling the JPEG compression quality (1-100) for still image capture. Platform interface changes were landed separately in flutter#11454.
The app-facing camera package should be submitted as a separate follow-up PR after the implementation packages are published. This removes the dependency_overrides that were blocking merge.
setJpegImageQuality_shouldSetQualityOnFeature test - android_camera_camerax.dart: Made lockedCaptureOrientation private - android_camera_camerax_test.dart: Updated locked rotation test to use lockCaptureOrientation, added takePicture-after-setJpegImageQuality test
6394e5a to
6f8ec01
Compare
Sorry @camsim99 the push failed and I missed that. Pushed again! |
camsim99
left a comment
There was a problem hiding this comment.
Sorry for the delay on the review -- one nit on a test but otherwise LGTM! Thanks for the quick fixes!
| } | ||
|
|
||
| @Test | ||
| public void setJpegImageQuality_shouldSetQualityOnFeature() { |
There was a problem hiding this comment.
Nit but can this be more like https://github.com/Bolling88/packages/blob/6f8ec01bacb7aaeef956deaafa0f2f9ce9c17ec1/packages/camera/camera_android/android/src/test/java/io/flutter/plugins/camera/CameraTest.java#L895 so we ensure the call to a CaptureRequest.Builder is actually made?
There was a problem hiding this comment.
Done. The test now uses a real JpegQualityFeature and verifies set(CaptureRequest.JPEG_QUALITY, (byte) 75) is called on the builder via updateBuilderSettings, same as the capture flow does.
|
From triage: @Bolling88 It looks like this just needs minor updates to be landed; is this still something you are working on? |
|
Yes, still on it. Rebased on main (resolved the conflicts, moved camera_android_camerax to 0.7.4 since 0.7.3 shipped in the meantime) and updated the CameraTest per the last review comment. Should be good for another look. |
flutter/packages@fc00ceb...92525f5 2026-07-07 [email protected] [camera_android_camerax] Fix setFocusMode(auto) crash when there is no auto-focus point (flutter/packages#11884) 2026-07-06 [email protected] [camera_android, camera_android_camerax, camera_avfoundation] Add setJpegImageQuality (flutter/packages#11616) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…JpegImageQuality (flutter#11616) Implements the `setJpegImageQuality` API (landed in the platform interface via flutter#11454) across all camera platform implementation packages, allowing control of JPEG compression quality (1-100) for still image capture. This is the follow-up implementation PR as requested in flutter#11155; it does not include `camera_platform_interface` changes. The app-facing `camera` package will be submitted in a separate PR after these implementation packages are published. Packages changed: - `camera_android` - `camera_android_camerax` - `camera_avfoundation` Part of flutter/flutter#183229 [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
iOS implementation of the zero-shutter-lag API added in camera_platform_interface 2.14.0 (this bumps the constraint to ^2.14.0). Part of flutter/flutter#190598. ## What - `isZeroShutterLagSupported` -> [`AVCapturePhotoOutput.isZeroShutterLagSupported`](https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/iszeroshutterlagsupported) (iOS 17+/macOS 14+; `false` on older versions) - `setZeroShutterLagEnabled` -> [`AVCapturePhotoOutput.isZeroShutterLagEnabled`](https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/iszeroshutterlagenabled) ## Why explicit control when iOS auto-enables it Per the `AVCapturePhotoOutput.h` header, "For apps linked on or after iOS 17 zero shutter lag is automatically enabled when supported." The documented role of the setter is the explicit opt-out (WWDC23 session 10105: "you can set AVCapturePhotoOutput.isZeroShutterLagEnabled to false to opt out" - https://developer.apple.com/videos/play/wwdc2023/10105/), plus deterministic re-enable: support can be revoked by configuration changes, and when it is, the enabled state silently reverts. Because of that auto-enable, iOS 17+ starts with zero shutter lag on while Android starts with it off, so the same Dart call is an opt-out here and an opt-in there. No latency numbers are quoted for iOS: the platform already enables the mode by default, so this change is about making that state explicit and controllable, not about improving it. <details><summary>Guard and configuration timing</summary> The header states the property "may only be set to YES if zeroShutterLagSupported is YES, otherwise an NSInvalidArgumentException is thrown", and that changing it "requires a lengthy reconfiguration of the capture render pipeline", to be done within `beginConfiguration`/`commitConfiguration` while running. The implementation guards enabling on the support query and wraps the write in a configuration block. The requested state is kept (plugin- and camera-level) and reapplied after session reconfigurations and camera switches, which silently reset it — mirroring the settings-retention approach on the Android side. Availability is handled inside the `CapturePhotoOutput` protocol passthrough (`flutter`-prefixed members, matching the existing `CaptureDevice.flutterActiveFormat` pattern), so callers need no availability checks and pre-iOS 17 devices report unsupported / ignore writes. </details> Regenerating with pigeon 26.1.5 also reverts two pre-existing hand-edits to the generated files from flutter#11616 (a redundant Int32 fallback cast and a missing Dart doc comment).
iOS implementation of the zero-shutter-lag API added in camera_platform_interface 2.14.0 (this bumps the constraint to ^2.14.0). Part of flutter/flutter#190598. ## What - `isZeroShutterLagSupported` -> [`AVCapturePhotoOutput.isZeroShutterLagSupported`](https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/iszeroshutterlagsupported) (iOS 17+/macOS 14+; `false` on older versions) - `setZeroShutterLagEnabled` -> [`AVCapturePhotoOutput.isZeroShutterLagEnabled`](https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/iszeroshutterlagenabled) ## Why explicit control when iOS auto-enables it Per the `AVCapturePhotoOutput.h` header, "For apps linked on or after iOS 17 zero shutter lag is automatically enabled when supported." The documented role of the setter is the explicit opt-out (WWDC23 session 10105: "you can set AVCapturePhotoOutput.isZeroShutterLagEnabled to false to opt out" - https://developer.apple.com/videos/play/wwdc2023/10105/), plus deterministic re-enable: support can be revoked by configuration changes, and when it is, the enabled state silently reverts. Because of that auto-enable, iOS 17+ starts with zero shutter lag on while Android starts with it off, so the same Dart call is an opt-out here and an opt-in there. No latency numbers are quoted for iOS: the platform already enables the mode by default, so this change is about making that state explicit and controllable, not about improving it. <details><summary>Guard and configuration timing</summary> The header states the property "may only be set to YES if zeroShutterLagSupported is YES, otherwise an NSInvalidArgumentException is thrown", and that changing it "requires a lengthy reconfiguration of the capture render pipeline", to be done within `beginConfiguration`/`commitConfiguration` while running. The implementation guards enabling on the support query and wraps the write in a configuration block. The requested state is kept (plugin- and camera-level) and reapplied after session reconfigurations and camera switches, which silently reset it — mirroring the settings-retention approach on the Android side. Availability is handled inside the `CapturePhotoOutput` protocol passthrough (`flutter`-prefixed members, matching the existing `CaptureDevice.flutterActiveFormat` pattern), so callers need no availability checks and pre-iOS 17 devices report unsupported / ignore writes. </details> Regenerating with pigeon 26.1.5 also reverts two pre-existing hand-edits to the generated files from flutter#11616 (a redundant Int32 fallback cast and a missing Dart doc comment).
Adds `setJpegImageQuality(int quality)` (1–100) to the app-facing `camera` package, forwarding to the platform interface method. This PR is now scoped down to `camera` only. The platform interface and implementations already landed and published separately: | Package | Version | Landed in | |---------|---------|-----------| | `camera_platform_interface` | 2.13.0 | #11155 (split out) | | `camera_platform_interface` | 2.13.1 | #12123 — default implementation made a no-op | | `camera_android_camerax` | 0.7.4 | #11616 | | `camera_avfoundation` | 0.10.2 | #11616 | ### This PR | Package | Version | |---------|---------| | `camera` | 0.12.0+2 → 0.12.1 | * Adds `CameraController.setJpegImageQuality`, with 1–100 range validation and `CameraException` translation. * Bumps constraints to the published versions that implement it: `camera_platform_interface: ^2.13.1`, `camera_android_camerax: ^0.7.4`, `camera_avfoundation: ^0.10.2`. No `dependency_overrides`. * Per the review discussion, the platform interface default is a no-op rather than an `UnimplementedError`, so calling this is always safe. The dartdoc says the setting is best-effort and links to flutter/flutter#191790 for the current state of platform support (web and Windows are not implemented yet). Fixes flutter/flutter#183229 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
) Adds `setJpegImageQuality(int quality)` (1–100) to the app-facing `camera` package, forwarding to the platform interface method. This PR is now scoped down to `camera` only. The platform interface and implementations already landed and published separately: | Package | Version | Landed in | |---------|---------|-----------| | `camera_platform_interface` | 2.13.0 | flutter#11155 (split out) | | `camera_platform_interface` | 2.13.1 | flutter#12123 — default implementation made a no-op | | `camera_android_camerax` | 0.7.4 | flutter#11616 | | `camera_avfoundation` | 0.10.2 | flutter#11616 | ### This PR | Package | Version | |---------|---------| | `camera` | 0.12.0+2 → 0.12.1 | * Adds `CameraController.setJpegImageQuality`, with 1–100 range validation and `CameraException` translation. * Bumps constraints to the published versions that implement it: `camera_platform_interface: ^2.13.1`, `camera_android_camerax: ^0.7.4`, `camera_avfoundation: ^0.10.2`. No `dependency_overrides`. * Per the review discussion, the platform interface default is a no-op rather than an `UnimplementedError`, so calling this is always safe. The dartdoc says the setting is best-effort and links to flutter/flutter#191790 for the current state of platform support (web and Windows are not implemented yet). Fixes flutter/flutter#183229 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
) Adds `setJpegImageQuality(int quality)` (1–100) to the app-facing `camera` package, forwarding to the platform interface method. This PR is now scoped down to `camera` only. The platform interface and implementations already landed and published separately: | Package | Version | Landed in | |---------|---------|-----------| | `camera_platform_interface` | 2.13.0 | flutter#11155 (split out) | | `camera_platform_interface` | 2.13.1 | flutter#12123 — default implementation made a no-op | | `camera_android_camerax` | 0.7.4 | flutter#11616 | | `camera_avfoundation` | 0.10.2 | flutter#11616 | ### This PR | Package | Version | |---------|---------| | `camera` | 0.12.0+2 → 0.12.1 | * Adds `CameraController.setJpegImageQuality`, with 1–100 range validation and `CameraException` translation. * Bumps constraints to the published versions that implement it: `camera_platform_interface: ^2.13.1`, `camera_android_camerax: ^0.7.4`, `camera_avfoundation: ^0.10.2`. No `dependency_overrides`. * Per the review discussion, the platform interface default is a no-op rather than an `UnimplementedError`, so calling this is always safe. The dartdoc says the setting is best-effort and links to flutter/flutter#191790 for the current state of platform support (web and Windows are not implemented yet). Fixes flutter/flutter#183229 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Combines the interface and both implementations in one PR per the [federated plugin process](https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins); splits into an interface-first PR once the direction is approved. The API shape is a proposal for flutter/flutter#190598 — happy to reshape it however you prefer. Adds explicit **zero-shutter-lag** control: an opt-in on Android, where the default capture mode leaves it off, and an opt-out on iOS, where the OS enables it automatically when the session supports it. ## What's added `camera_platform_interface` — two methods on `CameraPlatform`, modeled on the existing `setJpegImageQuality` / `getSupportedVideoStabilizationModes` patterns. Defaults are `false` / no-op, so nothing changes for platforms or apps that don't opt in: ```dart Future<bool> isZeroShutterLagSupported(int cameraId); Future<void> setZeroShutterLagEnabled(int cameraId, bool enabled); ``` `camera_android_camerax` — [`CameraInfo.isZslSupported()`](https://developer.android.com/reference/androidx/camera/core/CameraInfo#isZslSupported()) and [`ImageCapture.Builder.setCaptureMode(CAPTURE_MODE_ZERO_SHUTTER_LAG)`](https://developer.android.com/reference/androidx/camera/core/ImageCapture.Builder#setCaptureMode(int)). The capture mode is construction-only, so the use case is recreated — the approach `setJpegImageQuality` already uses for the same constraint, now sharing one helper so the two settings can't drop each other. `camera_avfoundation` — [`isZeroShutterLagSupported`](https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/iszeroshutterlagsupported) / [`isZeroShutterLagEnabled`](https://developer.apple.com/documentation/avfoundation/avcapturephotooutput/iszeroshutterlagenabled) (iOS 17+). Enabling is guarded on the support query (setting it while unsupported throws `NSInvalidArgumentException`) and wrapped in `beginConfiguration`/`commitConfiguration`. The requested state is reapplied after camera switches, which silently reset it. Apps that never call the setter are left untouched, so iOS keeps its automatic behavior on upgrade. ## Notes for reviewers - **Platform defaults differ**: Android leaves ZSL off by default, iOS 17+ turns it on automatically when supported — so the same call is an opt-in on Android and an opt-out on iOS. Measurements below. - **Experimental API**: `CAPTURE_MODE_ZERO_SHUTTER_LAG` is `@ExperimentalZeroShutterLag`, handled with per-declaration `@OptIn` like this plugin's existing `ExperimentalCamera2Interop` / `ExperimentalLensFacing` / `ExperimentalPersistentRecording`. `gradlew lint` is clean. - **Unsupported cases need no app handling**: CameraX falls back on its own; iOS is guarded by the support query. - **Generated files**: regenerating with pigeon 26.1.5 also reverts two pre-existing hand-edits from #11616 (a redundant `Int32` cast and a missing doc comment). - **CI**: the publish check is red by design — the last commit holds the `make-deps-path-based` overrides and is reverted before landing. <details><summary>On-device measurements</summary> **Android** — Galaxy S21 (SM-G991N), 5 captures per mode, shutter fired via `adb shell input tap`. A running millisecond stopwatch was photographed; the time visible in each saved photo shows how far behind the shutter tap the captured frame is. | | Captured frame | Shutter → file saved | |---|---|---| | `MINIMIZE_LATENCY` (current) | baseline | 912 ms | | `ZERO_SHUTTER_LAG` | **629 ms earlier** | 639 ms | **iOS** — iPhone (iOS 26.5), `ResolutionPreset.max`, 5 captures per mode after discarding one warm-up capture. Compares `AVCapturePhoto.timestamp` against the host-clock time of the `capturePhoto` call, so a negative value means the saved frame predates the call. | | Frame vs. shutter call | Shutter → delegate | |---|---|---| | ZSL off | +279 ms | 941 ms | | ZSL on | **−74 ms** | 689 ms | With ZSL on, every captured frame predated the capture call. Support is session-dependent rather than device-wide: the same device reports supported at `ResolutionPreset.max` and unsupported at `medium`. Since iOS enables this automatically, these numbers describe what the toggle controls — not an improvement this PR delivers on iOS. </details> Part of flutter/flutter#190598 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
Implements the
setJpegImageQualityAPI (landed in the platform interface via #11454) across all camera platform implementation packages, allowing control of JPEG compression quality (1-100) for still image capture.This is the follow-up implementation PR as requested in #11155; it does not include
camera_platform_interfacechanges. The app-facingcamerapackage will be submitted in a separate PR after these implementation packages are published.Packages changed:
camera_androidcamera_android_cameraxcamera_avfoundationPart of flutter/flutter#183229
Pre-Review Checklist
[shared_preferences]///).Footnotes
Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. ↩ ↩2