Skip to content

[camera] Add zero-shutter-lag support to camera_android_camerax and camera_avfoundation - #13199

Merged
auto-submit[bot] merged 2 commits into
flutter:mainfrom
toyaji:camera-zsl-implementations
Oct 20, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:mainfrom
toyaji:camera-zsl-implementations

Conversation

@toyaji

@toyaji toyaji commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Platform implementation portion of #12374, split out per the federated plugin process now that camera_platform_interface 2.15.0 is published (#12996). No changes from what was reviewed there, other than rebasing onto main and resolving version/CHANGELOG conflicts.

Implements isZeroShutterLagSupported / setZeroShutterLagEnabled in:

  • camera_android_camerax (0.7.6)
  • camera_avfoundation (0.11.1, iOS 17+)

Part of flutter/flutter#190598

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

…amera_avfoundation

Implementation portion of flutter#12374, now that camera_platform_interface 2.15.0 is published.

@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 introduces support for zero-shutter-lag still image capture in both the Android (CameraX) and iOS (AVFoundation) camera implementations by adding isZeroShutterLagSupported and setZeroShutterLagEnabled. The review feedback identifies a potential race condition in the Android _recreateImageCapture() method when triggered concurrently, recommending that the recreation process be serialized using a Future chain.

Comment on lines +1142 to 1160
Future<void> _recreateImageCapture() async {
if (imageCapture == null) {
return;
}

// Recreate ImageCapture with the requested JPEG quality.
// Unbind the current ImageCapture if it exists and is bound.
await _unbindUseCaseFromLifecycle(imageCapture!);

// Recreate ImageCapture with the requested settings.
// Preserve locked orientation if set, otherwise use default display rotation.
final int targetRotation =
_lockedCaptureOrientation ?? await deviceOrientationManager.getDefaultDisplayRotation();
imageCapture = ImageCapture(
resolutionSelector: _presetResolutionSelector,
targetRotation: targetRotation,
jpegQuality: quality,
jpegQuality: _jpegQuality,
zeroShutterLagEnabled: _zeroShutterLagEnabled,
);
}

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.

medium

There is a potential race condition in _recreateImageCapture() if it is called concurrently (for example, if setJpegImageQuality and setZeroShutterLagEnabled are called in rapid succession). Since _unbindUseCaseFromLifecycle is asynchronous, multiple concurrent calls can interleave, leading to _unbindUseCaseFromLifecycle being called multiple times on the same imageCapture instance, or creating redundant ImageCapture instances.

Consider serializing the recreation process using a Future chain to ensure thread-safe/reentrant-safe execution. Note that you will need to declare Future<void>? _recreationFuture; as an instance variable in the AndroidCameraCameraX class.

Future<void> _recreateImageCapture() async {
  if (imageCapture == null) {
    return;
  }
  if (_recreationFuture != null) {
    await _recreationFuture;
    return _recreateImageCapture();
  }

  final Future<void> recreation = () async {
    await _unbindUseCaseFromLifecycle(imageCapture!);
    final int targetRotation =
        _lockedCaptureOrientation ?? await deviceOrientationManager.getDefaultDisplayRotation();
    imageCapture = ImageCapture(
      resolutionSelector: _presetResolutionSelector,
      targetRotation: targetRotation,
      jpegQuality: _jpegQuality,
      zeroShutterLagEnabled: _zeroShutterLagEnabled,
    );
  }();

  _recreationFuture = recreation;
  try {
    await recreation;
  } finally {
    if (_recreationFuture == recreation) {
      _recreationFuture = null;
    }
  }
}

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.

This unbind-and-recreate flow already existed in setJpegImageQuality on main; this PR only extracts it into _recreateImageCapture(), and the code is unchanged from what was reviewed in #12374. Leaving serialization out of scope here; it can be handled in a separate PR if needed.

@toyaji

toyaji commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

@bparrishMines @camsim99 @hellohuanlin Follow-up to #12996: this is the platform implementation part of #12374, unchanged from what you reviewed there. PTAL.

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

ios lgtm

@ohmchavanon

Copy link
Copy Markdown

Code Review

This pull request introduces support for zero-shutter-lag still image capture in both the Android (CameraX) and iOS (AVFoundation) camera implementations by adding isZeroShutterLagSupported and setZeroShutterLagEnabled. The review feedback identifies a potential race condition in the Android _recreateImageCapture() method when triggered concurrently, recommending that the recreation process be serialized using a Future chain.

2 similar comments
@ohmchavanon

Copy link
Copy Markdown

Code Review

This pull request introduces support for zero-shutter-lag still image capture in both the Android (CameraX) and iOS (AVFoundation) camera implementations by adding isZeroShutterLagSupported and setZeroShutterLagEnabled. The review feedback identifies a potential race condition in the Android _recreateImageCapture() method when triggered concurrently, recommending that the recreation process be serialized using a Future chain.

@ohmchavanon

Copy link
Copy Markdown

Code Review

This pull request introduces support for zero-shutter-lag still image capture in both the Android (CameraX) and iOS (AVFoundation) camera implementations by adding isZeroShutterLagSupported and setZeroShutterLagEnabled. The review feedback identifies a potential race condition in the Android _recreateImageCapture() method when triggered concurrently, recommending that the recreation process be serialized using a Future chain.

@toyaji

toyaji commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

@camsim99 iOS is approved; could you take a look at the Android side? It's unchanged from what you reviewed in #12374.

@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 I missed your last ping! This LGTM!

@camsim99 camsim99 added the CICD Run CI/CD label Oct 19, 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.

…tations

# Conflicts:
#	packages/camera/camera_avfoundation/CHANGELOG.md
#	packages/camera/camera_avfoundation/pubspec.yaml
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 20, 2026
@toyaji

toyaji commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@camsim99 @hellohuanlin Resolved merge conflicts with main (version bump only). Could one of you re-add CICD and autosubmit?

@camsim99 camsim99 added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Oct 20, 2026
@auto-submit
auto-submit Bot merged commit 5e67d84 into flutter:main Oct 20, 2026
14 checks passed
@toyaji

toyaji commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

@camsim99 @hellohuanlin The post-merge release run for this PR failed because the Linux ci_yaml packages roller check hadn't appeared within the 60s discovery window. That check has since passed on 5e67d84. As a result, camera_android_camerax 0.7.6 and camera_avfoundation 0.11.1 haven't been published yet, and the follow-up app-facing PR (#12374) depends on them.

Could one of you re-run that release workflow? Thanks!

@bparrishMines

Copy link
Copy Markdown
Contributor

@camsim99 @hellohuanlin The post-merge release run for this PR failed because the Linux ci_yaml packages roller check hadn't appeared within the 60s discovery window. That check has since passed on 5e67d84. As a result, camera_android_camerax 0.7.6 and camera_avfoundation 0.11.1 haven't been published yet, and the follow-up app-facing PR (#12374) depends on them.

Could one of you re-run that release workflow? Thanks!

Done. It should be released now.

ValentinVignal pushed a commit to ValentinVignal/flutter that referenced this pull request Oct 21, 2026
flutter/packages@618afba...1383427

2026-10-21 [email protected] [shared_preferences] Keep Kotlin
classes used through JNI in Android release builds
(flutter/packages#13311)
2026-10-20 [email protected] [webview_flutter_wkwebview] Roll back iOS
and macOS versions (flutter/packages#13354)
2026-10-20 [email protected] [camera]fix
resolution test failure due to hardware restriction
(flutter/packages#13356)
2026-10-20 [email protected] [google_maps_flutter_web] Fail fast and
deduplicate map setup in integration tests (flutter/packages#13092)
2026-10-20 [email protected] [camera_avfoundation] Fix Swift analyzer
issues in tests (flutter/packages#13340)
2026-10-20 [email protected] Sync release-material_ui-1.8.0 to
main (flutter/packages#13346)
2026-10-20 [email protected] [material_ui] add a `barFocusNode` to
`SearchAnchor.bar` (ref: flutter#186073)
(flutter/packages#12863)
2026-10-20 [email protected] [in_app_purchase_storekit] Expose
sk2Transaction on SK2PurchaseDetails (flutter/packages#13341)
2026-10-20 [email protected] Sync release-cupertino_ui-1.1.4 to
main (flutter/packages#13350)
2026-10-20 [email protected] [google_maps_flutter_web] Don't hang
`onMapCreated` when tiles fail to load (flutter/packages#13059)
2026-10-20 [email protected] [material_ui]
Unskip web tests that pass on CanvasKit and Skwasm:
adaptive_text_selection_toolbar_test, material_button_test,
outlined_button_test, text_button_test (flutter/packages#13335)
2026-10-20 [email protected] Sync release-go_router-18.1.1 to
main (flutter/packages#13347)
2026-10-20 [email protected] [camera] Add zero-shutter-lag support
to camera_android_camerax and camera_avfoundation
(flutter/packages#13199)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode 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
LongCatIsLooong pushed a commit to LongCatIsLooong/flutter that referenced this pull request Oct 22, 2026
flutter/packages@618afba...1383427

2026-10-21 [email protected] [shared_preferences] Keep Kotlin
classes used through JNI in Android release builds
(flutter/packages#13311)
2026-10-20 [email protected] [webview_flutter_wkwebview] Roll back iOS
and macOS versions (flutter/packages#13354)
2026-10-20 [email protected] [camera]fix
resolution test failure due to hardware restriction
(flutter/packages#13356)
2026-10-20 [email protected] [google_maps_flutter_web] Fail fast and
deduplicate map setup in integration tests (flutter/packages#13092)
2026-10-20 [email protected] [camera_avfoundation] Fix Swift analyzer
issues in tests (flutter/packages#13340)
2026-10-20 [email protected] Sync release-material_ui-1.8.0 to
main (flutter/packages#13346)
2026-10-20 [email protected] [material_ui] add a `barFocusNode` to
`SearchAnchor.bar` (ref: flutter#186073)
(flutter/packages#12863)
2026-10-20 [email protected] [in_app_purchase_storekit] Expose
sk2Transaction on SK2PurchaseDetails (flutter/packages#13341)
2026-10-20 [email protected] Sync release-cupertino_ui-1.1.4 to
main (flutter/packages#13350)
2026-10-20 [email protected] [google_maps_flutter_web] Don't hang
`onMapCreated` when tiles fail to load (flutter/packages#13059)
2026-10-20 [email protected] [material_ui]
Unskip web tests that pass on CanvasKit and Skwasm:
adaptive_text_selection_toolbar_test, material_button_test,
outlined_button_test, text_button_test (flutter/packages#13335)
2026-10-20 [email protected] Sync release-go_router-18.1.1 to
main (flutter/packages#13347)
2026-10-20 [email protected] [camera] Add zero-shutter-lag support
to camera_android_camerax and camera_avfoundation
(flutter/packages#13199)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode 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
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
flutter/packages@618afba...1383427

2026-10-21 [email protected] [shared_preferences] Keep Kotlin
classes used through JNI in Android release builds
(flutter/packages#13311)
2026-10-20 [email protected] [webview_flutter_wkwebview] Roll back iOS
and macOS versions (flutter/packages#13354)
2026-10-20 [email protected] [camera]fix
resolution test failure due to hardware restriction
(flutter/packages#13356)
2026-10-20 [email protected] [google_maps_flutter_web] Fail fast and
deduplicate map setup in integration tests (flutter/packages#13092)
2026-10-20 [email protected] [camera_avfoundation] Fix Swift analyzer
issues in tests (flutter/packages#13340)
2026-10-20 [email protected] Sync release-material_ui-1.8.0 to
main (flutter/packages#13346)
2026-10-20 [email protected] [material_ui] add a `barFocusNode` to
`SearchAnchor.bar` (ref: flutter#186073)
(flutter/packages#12863)
2026-10-20 [email protected] [in_app_purchase_storekit] Expose
sk2Transaction on SK2PurchaseDetails (flutter/packages#13341)
2026-10-20 [email protected] Sync release-cupertino_ui-1.1.4 to
main (flutter/packages#13350)
2026-10-20 [email protected] [google_maps_flutter_web] Don't hang
`onMapCreated` when tiles fail to load (flutter/packages#13059)
2026-10-20 [email protected] [material_ui]
Unskip web tests that pass on CanvasKit and Skwasm:
adaptive_text_selection_toolbar_test, material_button_test,
outlined_button_test, text_button_test (flutter/packages#13335)
2026-10-20 [email protected] Sync release-go_router-18.1.1 to
main (flutter/packages#13347)
2026-10-20 [email protected] [camera] Add zero-shutter-lag support
to camera_android_camerax and camera_avfoundation
(flutter/packages#13199)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode 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
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 p: camera platform-android platform-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants