Skip to content

Commit 8f55523

Browse files
adam-harwoodAdam Harwood
authored andcommitted
[camera] Interface method to allow concurrent recording and streaming of video (flutter#6550)
1 parent 78cf6c2 commit 8f55523

3 files changed

Lines changed: 72 additions & 4 deletions

File tree

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: 13 additions & 4 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
///
@@ -133,13 +134,21 @@ abstract class CameraPlatform extends PlatformInterface {
133134
/// meaning the recording will continue until manually stopped.
134135
/// With [maxVideoDuration] set the video is returned in a [VideoRecordedEvent]
135136
/// through the [onVideoRecordedEvent] stream when the set duration is reached.
136-
Future<void> startVideoRecording(int cameraId,
137-
{Duration? maxVideoDuration,
138-
Function(CameraImageData image)? streamCallback,
139-
CameraImageStreamOptions? streamOptions}) {
137+
///
138+
/// This method is deprecated in favour of [startVideoCapturing].
139+
Future<void> startVideoRecording(int cameraId, {Duration? maxVideoDuration}) {
140140
throw UnimplementedError('startVideoRecording() is not implemented.');
141141
}
142142

143+
/// Starts a video recording and/or streaming session.
144+
///
145+
/// Please see [VideoCaptureOptions] for documentation on the
146+
/// configuration options.
147+
Future<void> startVideoCapturing(VideoCaptureOptions options) {
148+
return startVideoRecording(options.cameraId,
149+
maxVideoDuration: options.maxDuration);
150+
}
151+
143152
/// Stops the video recording and returns the file where it was saved.
144153
Future<XFile> stopVideoRecording(int cameraId) {
145154
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+
}

0 commit comments

Comments
 (0)