Skip to content

Commit 5df210b

Browse files
committed
[camera_platform_interface] Add zero-shutter-lag API
Adds an opt-in zero-shutter-lag capture API for platforms that support it. Part of flutter/flutter#190598. ## What - `isZeroShutterLagSupported(int cameraId)` — support query, defaults to `false` - `setZeroShutterLagEnabled(int cameraId, bool enabled)` — defaults to a no-op ## Why non-breaking Defaults preserve today's behavior on every platform that does not override them, following the existing `setJpegImageQuality` (no-op default) and `getSupportedVideoStabilizationModes` (support query) patterns in this file.
1 parent 252bb33 commit 5df210b

4 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎packages/camera/camera_platform_interface/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.14.0
2+
3+
* Adds `isZeroShutterLagSupported` and `setZeroShutterLagEnabled` for
4+
zero-shutter-lag still image capture on platforms that support it.
5+
16
## 2.13.1
27

38
* Changes the default implementation of `setJpegImageQuality` to a no-op so that

‎packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,27 @@ abstract class CameraPlatform extends PlatformInterface {
345345
// No-op by default. Platforms that support setting the JPEG quality
346346
// override this method.
347347
}
348+
349+
/// Returns whether the selected camera supports zero-shutter-lag capture.
350+
///
351+
/// The default implementation returns `false`.
352+
Future<bool> isZeroShutterLagSupported(int cameraId) async => false;
353+
354+
/// Enables or disables zero-shutter-lag capture for still image capture.
355+
///
356+
/// When enabled, [takePicture] returns the buffered frame closest to the
357+
/// moment it was called instead of waiting for a new frame to be captured,
358+
/// reducing shutter latency on devices that support it.
359+
///
360+
/// Some platforms enable zero-shutter-lag by default on devices that
361+
/// support it; this setter provides explicit control in either direction.
362+
///
363+
/// This is a best-effort setting; platforms and devices that do not support
364+
/// zero-shutter-lag capture ignore it and fall back to the regular capture
365+
/// pipeline. The default implementation is a no-op so that calling it is
366+
/// always safe.
367+
Future<void> setZeroShutterLagEnabled(int cameraId, bool enabled) async {
368+
// No-op by default. Platforms that support zero-shutter-lag capture
369+
// override this method.
370+
}
348371
}

‎packages/camera/camera_platform_interface/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.13.1
7+
version: 2.14.0
88

99
environment:
1010
sdk: ^3.10.0

‎packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,22 @@ void main() {
361361
expect(cameraPlatform.setJpegImageQuality(1, 50), completes);
362362
});
363363

364+
test('Default implementation of isZeroShutterLagSupported() should return false', () async {
365+
// Arrange
366+
final cameraPlatform = ExtendsCameraPlatform();
367+
368+
// Act & Assert
369+
expect(await cameraPlatform.isZeroShutterLagSupported(1), isFalse);
370+
});
371+
372+
test('Default implementation of setZeroShutterLagEnabled() is a no-op', () {
373+
// Arrange
374+
final cameraPlatform = ExtendsCameraPlatform();
375+
376+
// Act & Assert
377+
expect(cameraPlatform.setZeroShutterLagEnabled(1, true), completes);
378+
});
379+
364380
test('Default implementation of supportsImageStreaming() should return false', () {
365381
// Arrange
366382
final cameraPlatform = ExtendsCameraPlatform();

0 commit comments

Comments
 (0)