From baf11bcee29f35561a4ee57b0e00d6db7c5698dc Mon Sep 17 00:00:00 2001 From: Olli Helenius Date: Mon, 9 Dec 2024 15:11:50 +0200 Subject: [PATCH 1/2] [camera] Add API support query for image streaming --- packages/camera/camera/CHANGELOG.md | 3 ++- .../camera/lib/src/camera_controller.dart | 18 ++++++++------- packages/camera/camera/pubspec.yaml | 8 +++---- .../camera/test/camera_image_stream_test.dart | 22 +++++++++++++++---- .../camera/test/camera_preview_test.dart | 3 +++ 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index 5e923b81d2c5..5d970405b190 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,5 +1,6 @@ -## NEXT +## 0.11.1 +* Adds API support query for image streaming. * Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. * Updates example to dispose animation controllers and curved animations. diff --git a/packages/camera/camera/lib/src/camera_controller.dart b/packages/camera/camera/lib/src/camera_controller.dart index 5f90a0a740a9..3f39d3202b8f 100644 --- a/packages/camera/camera/lib/src/camera_controller.dart +++ b/packages/camera/camera/lib/src/camera_controller.dart @@ -480,13 +480,12 @@ class CameraController extends ValueNotifier { /// Throws a [CameraException] if image streaming or video recording has /// already started. /// - /// The `startImageStream` method is only available on Android and iOS (other - /// platforms won't be supported in current setup). + /// The `startImageStream` method is only available on platforms that + /// report support for image streaming via [supportsImageStreaming]. /// // TODO(bmparr): Add settings for resolution and fps. Future startImageStream(onLatestImageAvailable onAvailable) async { - assert(defaultTargetPlatform == TargetPlatform.android || - defaultTargetPlatform == TargetPlatform.iOS); + assert(supportsImageStreaming()); _throwIfNotInitialized('startImageStream'); if (value.isRecordingVideo) { throw CameraException( @@ -518,11 +517,10 @@ class CameraController extends ValueNotifier { /// Throws a [CameraException] if image streaming was not started or video /// recording was started. /// - /// The `stopImageStream` method is only available on Android and iOS (other - /// platforms won't be supported in current setup). + /// The `stopImageStream` method is only available on platforms that + /// report support for image streaming via [supportsImageStreaming]. Future stopImageStream() async { - assert(defaultTargetPlatform == TargetPlatform.android || - defaultTargetPlatform == TargetPlatform.iOS); + assert(supportsImageStreaming()); _throwIfNotInitialized('stopImageStream'); if (!value.isStreamingImages) { throw CameraException( @@ -871,6 +869,10 @@ class CameraController extends ValueNotifier { } } + /// Check whether the camera platform supports image streaming. + bool supportsImageStreaming() => + CameraPlatform.instance.supportsImageStreaming(); + /// Releases the resources of this camera. @override Future dispose() async { diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index d8144150bccd..17a52f133e7d 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -4,7 +4,7 @@ description: A Flutter plugin for controlling the camera. Supports previewing Dart. repository: https://github.com/flutter/packages/tree/main/packages/camera/camera issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 -version: 0.11.0+2 +version: 0.11.1 environment: sdk: ^3.4.0 @@ -21,9 +21,9 @@ flutter: default_package: camera_web dependencies: - camera_android_camerax: ^0.6.5 - camera_avfoundation: ^0.9.15 - camera_platform_interface: ^2.6.0 + camera_android_camerax: ^0.6.13 + camera_avfoundation: ^0.9.18 + camera_platform_interface: ^2.9.0 camera_web: ^0.3.3 flutter: sdk: flutter diff --git a/packages/camera/camera/test/camera_image_stream_test.dart b/packages/camera/camera/test/camera_image_stream_test.dart index c89e4acaa726..fd17694e246b 100644 --- a/packages/camera/camera/test/camera_image_stream_test.dart +++ b/packages/camera/camera/test/camera_image_stream_test.dart @@ -100,8 +100,11 @@ void main() { await cameraController.startImageStream((CameraImage image) {}); - expect(mockPlatform.streamCallLog, - ['onStreamedFrameAvailable', 'listen']); + expect(mockPlatform.streamCallLog, [ + 'supportsImageStreaming', + 'onStreamedFrameAvailable', + 'listen' + ]); }); test('stopImageStream() throws $CameraException when uninitialized', () { @@ -160,8 +163,13 @@ void main() { await cameraController.startImageStream((CameraImage image) {}); await cameraController.stopImageStream(); - expect(mockPlatform.streamCallLog, - ['onStreamedFrameAvailable', 'listen', 'cancel']); + expect(mockPlatform.streamCallLog, [ + 'supportsImageStreaming', + 'onStreamedFrameAvailable', + 'listen', + 'supportsImageStreaming', + 'cancel' + ]); }); test('startVideoRecording() can stream images', () async { @@ -235,6 +243,12 @@ class MockStreamingCameraPlatform extends MockCameraPlatform { streamCallLog.add('listen'); } + @override + bool supportsImageStreaming() { + streamCallLog.add('supportsImageStreaming'); + return true; + } + FutureOr _onFrameStreamCancel() async { streamCallLog.add('cancel'); _streamController = null; diff --git a/packages/camera/camera/test/camera_preview_test.dart b/packages/camera/camera/test/camera_preview_test.dart index d76ac7ea02ec..bcec28fe5b9d 100644 --- a/packages/camera/camera/test/camera_preview_test.dart +++ b/packages/camera/camera/test/camera_preview_test.dart @@ -132,6 +132,9 @@ class FakeController extends ValueNotifier @override CameraDescription get description => value.description; + + @override + bool supportsImageStreaming() => true; } void main() { From d8cb479ddab7381238b5cac9a2964d6e05ea0270 Mon Sep 17 00:00:00 2001 From: Olli Helenius Date: Tue, 14 Jan 2025 22:03:30 +0200 Subject: [PATCH 2/2] [camera] Update minimum SDK version to 3.27/3.6 Bring the minimums match those in `camera_android_camerax`. --- packages/camera/camera/CHANGELOG.md | 2 +- packages/camera/camera/pubspec.yaml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index 5d970405b190..d0d58be6ca92 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.11.1 * Adds API support query for image streaming. -* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4. +* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6. * Updates example to dispose animation controllers and curved animations. ## 0.11.0+2 diff --git a/packages/camera/camera/pubspec.yaml b/packages/camera/camera/pubspec.yaml index 17a52f133e7d..09899dfa5796 100644 --- a/packages/camera/camera/pubspec.yaml +++ b/packages/camera/camera/pubspec.yaml @@ -7,8 +7,8 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 0.11.1 environment: - sdk: ^3.4.0 - flutter: ">=3.22.0" + sdk: ^3.6.0 + flutter: ">=3.27.0" flutter: plugin: