Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[camera] Add API support query for image streaming (app-facing) #8422

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 0.11.1

* Updates minimum supported SDK version to Flutter 3.22/Dart 3.4.
* Adds API support query for image streaming.
* Updates minimum supported SDK version to Flutter 3.27/Dart 3.6.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this adds a new method (supportsImageStreaming()), this should be a minor bump to 0.11.1. Also, this should also be moved to be listed first since its the meaningful change of the version bump.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed, thanks.

* Updates example to dispose animation controllers and curved animations.

## 0.11.0+2
Expand Down
18 changes: 10 additions & 8 deletions packages/camera/camera/lib/src/camera_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -480,13 +480,12 @@ class CameraController extends ValueNotifier<CameraValue> {
/// 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<void> startImageStream(onLatestImageAvailable onAvailable) async {
assert(defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS);
assert(supportsImageStreaming());
_throwIfNotInitialized('startImageStream');
if (value.isRecordingVideo) {
throw CameraException(
Expand Down Expand Up @@ -518,11 +517,10 @@ class CameraController extends ValueNotifier<CameraValue> {
/// 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<void> stopImageStream() async {
assert(defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS);
assert(supportsImageStreaming());
_throwIfNotInitialized('stopImageStream');
if (!value.isStreamingImages) {
throw CameraException(
Expand Down Expand Up @@ -871,6 +869,10 @@ class CameraController extends ValueNotifier<CameraValue> {
}
}

/// Check whether the camera platform supports image streaming.
bool supportsImageStreaming() =>
CameraPlatform.instance.supportsImageStreaming();

/// Releases the resources of this camera.
@override
Future<void> dispose() async {
Expand Down
12 changes: 6 additions & 6 deletions packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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
flutter: ">=3.22.0"
sdk: ^3.6.0
flutter: ">=3.27.0"

flutter:
plugin:
Expand All @@ -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
Expand Down
22 changes: 18 additions & 4 deletions packages/camera/camera/test/camera_image_stream_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ void main() {

await cameraController.startImageStream((CameraImage image) {});

expect(mockPlatform.streamCallLog,
<String>['onStreamedFrameAvailable', 'listen']);
expect(mockPlatform.streamCallLog, <String>[
'supportsImageStreaming',
'onStreamedFrameAvailable',
'listen'
]);
});

test('stopImageStream() throws $CameraException when uninitialized', () {
Expand Down Expand Up @@ -160,8 +163,13 @@ void main() {
await cameraController.startImageStream((CameraImage image) {});
await cameraController.stopImageStream();

expect(mockPlatform.streamCallLog,
<String>['onStreamedFrameAvailable', 'listen', 'cancel']);
expect(mockPlatform.streamCallLog, <String>[
'supportsImageStreaming',
'onStreamedFrameAvailable',
'listen',
'supportsImageStreaming',
'cancel'
]);
});

test('startVideoRecording() can stream images', () async {
Expand Down Expand Up @@ -235,6 +243,12 @@ class MockStreamingCameraPlatform extends MockCameraPlatform {
streamCallLog.add('listen');
}

@override
bool supportsImageStreaming() {
streamCallLog.add('supportsImageStreaming');
return true;
}

FutureOr<void> _onFrameStreamCancel() async {
streamCallLog.add('cancel');
_streamController = null;
Expand Down
3 changes: 3 additions & 0 deletions packages/camera/camera/test/camera_preview_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class FakeController extends ValueNotifier<CameraValue>

@override
CameraDescription get description => value.description;

@override
bool supportsImageStreaming() => true;
}

void main() {
Expand Down
Loading