Skip to content

Commit f68f83b

Browse files
authored
[camera] Interface method to allow concurrent recording and streaming of video (flutter#6550)
1 parent 4cbb771 commit f68f83b

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.3.0
2+
3+
* Adds new capture method for a camera to allow concurrent streaming and recording.
4+
15
## 2.2.2
26

37
* Updates code for `no_leading_underscores_for_local_identifiers` lint.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart';
1111

1212
import '../../camera_platform_interface.dart';
1313
import '../method_channel/method_channel_camera.dart';
14+
import '../types/video_capture_options.dart';
1415

1516
/// The interface that implementations of camera must implement.
1617
///
@@ -131,10 +132,21 @@ abstract class CameraPlatform extends PlatformInterface {
131132
/// meaning the recording will continue until manually stopped.
132133
/// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent]
133134
/// through the [onVideoRecordedEvent] stream when the set duration is reached.
135+
///
136+
/// This method is deprecated in favour of [startVideoCapturing].
134137
Future<void> startVideoRecording(int cameraId, {Duration? maxVideoDuration}) {
135138
throw UnimplementedError('startVideoRecording() is not implemented.');
136139
}
137140

141+
/// Starts a video recording and/or streaming session.
142+
///
143+
/// Please see [VideoCaptureOptions] for documentation on the
144+
/// configuration options.
145+
Future<void> startVideoCapturing(VideoCaptureOptions options) {
146+
return startVideoRecording(options.cameraId,
147+
maxVideoDuration: options.maxDuration);
148+
}
149+
138150
/// Stops the video recording and returns the file where it was saved.
139151
Future<XFile> stopVideoRecording(int cameraId) {
140152
throw UnimplementedError('stopVideoRecording() is not implemented.');
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/foundation.dart';
6+
7+
import 'camera_image_data.dart';
8+
9+
/// Options wrapper for [CameraPlatform.startVideoCapturing] parameters.
10+
@immutable
11+
class VideoCaptureOptions {
12+
/// Constructs a new instance.
13+
const VideoCaptureOptions(
14+
this.cameraId, {
15+
this.maxDuration,
16+
this.streamCallback,
17+
this.streamOptions,
18+
}) : assert(
19+
streamOptions == null || streamCallback != null,
20+
'Must specify streamCallback if providing streamOptions.',
21+
);
22+
23+
/// The ID of the camera to use for capturing.
24+
final int cameraId;
25+
26+
/// The maximum time to perform capturing for.
27+
///
28+
/// By default there is no maximum on the capture time.
29+
final Duration? maxDuration;
30+
31+
/// An optional callback to enable streaming.
32+
///
33+
/// If set, then each image captured by the camera will be
34+
/// passed to this callback.
35+
final Function(CameraImageData image)? streamCallback;
36+
37+
/// Configuration options for streaming.
38+
///
39+
/// Should only be set if a streamCallback is also present.
40+
final CameraImageStreamOptions? streamOptions;
41+
42+
@override
43+
bool operator ==(Object other) =>
44+
identical(this, other) ||
45+
other is VideoCaptureOptions &&
46+
runtimeType == other.runtimeType &&
47+
cameraId == other.cameraId &&
48+
maxDuration == other.maxDuration &&
49+
streamCallback == other.streamCallback &&
50+
streamOptions == other.streamOptions;
51+
52+
@override
53+
int get hashCode =>
54+
Object.hash(cameraId, maxDuration, streamCallback, streamOptions);
55+
}

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/plugins/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.2.2
7+
version: 2.3.0
88

99
environment:
1010
sdk: '>=2.12.0 <3.0.0'

0 commit comments

Comments
 (0)