Skip to content

[camera_android, camera_android_camerax, camera_avfoundation] Add setJpegImageQuality - #11616

Merged
auto-submit[bot] merged 7 commits into
flutter:mainfrom
Bolling88:set-jpeg-quality
Jul 6, 2026
Merged

auto-submit[bot] merged 7 commits into
flutter:mainfrom
Bolling88:set-jpeg-quality

Conversation

@Bolling88

@Bolling88 Bolling88 commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

Implements the setJpegImageQuality API (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_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

Pre-Review Checklist

Footnotes

  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. ↩ ↩2

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 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.

@Bolling88 Bolling88 changed the title [camera] Add setJpegImageQuality for JPEG compression control [camera_android, camera_android_camerax, camera_avfoundation] Add setJpegImageQuality Apr 30, 2026
@stuartmorgan-g stuartmorgan-g added triage-ios Should be looked at in iOS triage triage-android Should be looked at in Android triage federated: partial_changes PR that contains changes for only a single package of a federated plugin change labels May 1, 2026
@Bolling88

Copy link
Copy Markdown
Contributor Author

@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.

@okorohelijah

Copy link
Copy Markdown
Contributor

@hellohuanlin friendly ping from triage

@hellohuanlin hellohuanlin left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i think i have reviewed the combined PR and approved it, so carrying over the stamp here (for iOS part only)

@mboetger

Copy link
Copy Markdown
Contributor

From Android Triage: our subject matter expert is out of town. They will review when they get back.

@bparrishMines bparrishMines added the CICD Run CI/CD label May 20, 2026
@flutter-dashboard

Copy link
Copy Markdown

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.

@github-actions github-actions Bot removed the CICD Run CI/CD label May 20, 2026

@camsim99 camsim99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Android overall LGTM! Left some comments regarding tests.

@bparrishMines bparrishMines added the CICD Run CI/CD label May 26, 2026

@bparrishMines bparrishMines left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@camsim99 We can go ahead and merge this after your approval of the changes from your review comments.

@camsim99
camsim99 self-requested a review May 26, 2026 21:16
@camsim99

Copy link
Copy Markdown
Contributor

@Bolling88 I don't see any new changes. Did you push them?

@github-actions github-actions Bot removed the CICD Run CI/CD label May 28, 2026
Bolling88 added 2 commits May 28, 2026 09:10
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.
bparrishMines and others added 2 commits May 28, 2026 09:10
  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
@Bolling88

Bolling88 commented May 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@Bolling88 I don't see any new changes. Did you push them?

Sorry @camsim99 the push failed and I missed that. Pushed again!

@camsim99 camsim99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@LongCatIsLooong LongCatIsLooong removed the triage-ios Should be looked at in iOS triage label Jun 18, 2026
@stuartmorgan-g

Copy link
Copy Markdown
Contributor

From triage: @Bolling88 It looks like this just needs minor updates to be landed; is this still something you are working on?

@Bolling88

Copy link
Copy Markdown
Contributor Author

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.

@stuartmorgan-g
stuartmorgan-g requested review from camsim99 and removed request for LouiseHsu July 6, 2026 14:51

@camsim99 camsim99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Android LGTM!

@stuartmorgan-g stuartmorgan-g added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Jul 6, 2026
@auto-submit
auto-submit Bot merged commit e0dc2c4 into flutter:main Jul 6, 2026
89 checks passed
pull Bot pushed a commit to soloinovator/flutter that referenced this pull request Jul 7, 2026
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
kalyujniy pushed a commit to brickit-app/camera that referenced this pull request Jul 8, 2026
…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.
toyaji added a commit to toyaji/packages that referenced this pull request Aug 5, 2026
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).
toyaji added a commit to toyaji/packages that referenced this pull request Aug 20, 2026
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).
auto-submit Bot pushed a commit that referenced this pull request Sep 3, 2026
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.
@Bolling88
Bolling88 deleted the set-jpeg-quality branch September 4, 2026 06:20
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
)

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.
victorsanni pushed a commit to victorsanni/packages that referenced this pull request Sep 9, 2026
)

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.
auto-submit Bot pushed a commit that referenced this pull request Oct 27, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD federated: partial_changes PR that contains changes for only a single package of a federated plugin change p: camera platform-android platform-ios platform-macos triage-android Should be looked at in Android triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants