You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4a1f3c5
Browse filesBrowse the repository at this point in the historyBrowse files
[camera] Add support for zero-shutter-lag capture (#12374)
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.
0 commit comments