diff --git a/packages/camera/camera_platform_interface/CHANGELOG.md b/packages/camera/camera_platform_interface/CHANGELOG.md index d410304970cf..3bfc56f3f6e2 100644 --- a/packages/camera/camera_platform_interface/CHANGELOG.md +++ b/packages/camera/camera_platform_interface/CHANGELOG.md @@ -1,3 +1,7 @@ +## 2.3.0 + +* Adds new capture method for a camera to allow concurrent streaming and recording. + ## 2.2.2 * Updates code for `no_leading_underscores_for_local_identifiers` lint. diff --git a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart index b086dc87851f..d8f8f9ca4cc9 100644 --- a/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart +++ b/packages/camera/camera_platform_interface/lib/src/platform_interface/camera_platform.dart @@ -11,6 +11,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import '../../camera_platform_interface.dart'; import '../method_channel/method_channel_camera.dart'; +import '../types/video_capture_options.dart'; /// The interface that implementations of camera must implement. /// @@ -131,10 +132,21 @@ abstract class CameraPlatform extends PlatformInterface { /// meaning the recording will continue until manually stopped. /// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent] /// through the [onVideoRecordedEvent] stream when the set duration is reached. + /// + /// This method is deprecated in favour of [startVideoCapturing]. Future startVideoRecording(int cameraId, {Duration? maxVideoDuration}) { throw UnimplementedError('startVideoRecording() is not implemented.'); } + /// Starts a video recording and/or streaming session. + /// + /// Please see [VideoCaptureOptions] for documentation on the + /// configuration options. + Future startVideoCapturing(VideoCaptureOptions options) { + return startVideoRecording(options.cameraId, + maxVideoDuration: options.maxDuration); + } + /// Stops the video recording and returns the file where it was saved. Future stopVideoRecording(int cameraId) { throw UnimplementedError('stopVideoRecording() is not implemented.'); diff --git a/packages/camera/camera_platform_interface/lib/src/types/video_capture_options.dart b/packages/camera/camera_platform_interface/lib/src/types/video_capture_options.dart new file mode 100644 index 000000000000..9fcb7fa95379 --- /dev/null +++ b/packages/camera/camera_platform_interface/lib/src/types/video_capture_options.dart @@ -0,0 +1,55 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +import 'camera_image_data.dart'; + +/// Options wrapper for [CameraPlatform.startVideoCapturing] parameters. +@immutable +class VideoCaptureOptions { + /// Constructs a new instance. + const VideoCaptureOptions( + this.cameraId, { + this.maxDuration, + this.streamCallback, + this.streamOptions, + }) : assert( + streamOptions == null || streamCallback != null, + 'Must specify streamCallback if providing streamOptions.', + ); + + /// The ID of the camera to use for capturing. + final int cameraId; + + /// The maximum time to perform capturing for. + /// + /// By default there is no maximum on the capture time. + final Duration? maxDuration; + + /// An optional callback to enable streaming. + /// + /// If set, then each image captured by the camera will be + /// passed to this callback. + final Function(CameraImageData image)? streamCallback; + + /// Configuration options for streaming. + /// + /// Should only be set if a streamCallback is also present. + final CameraImageStreamOptions? streamOptions; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is VideoCaptureOptions && + runtimeType == other.runtimeType && + cameraId == other.cameraId && + maxDuration == other.maxDuration && + streamCallback == other.streamCallback && + streamOptions == other.streamOptions; + + @override + int get hashCode => + Object.hash(cameraId, maxDuration, streamCallback, streamOptions); +} diff --git a/packages/camera/camera_platform_interface/pubspec.yaml b/packages/camera/camera_platform_interface/pubspec.yaml index e87679261c5a..7ddc6d561aa4 100644 --- a/packages/camera/camera_platform_interface/pubspec.yaml +++ b/packages/camera/camera_platform_interface/pubspec.yaml @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/camera/camera_ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22 # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.2.2 +version: 2.3.0 environment: sdk: '>=2.12.0 <3.0.0'