Skip to content

Commit 861f04d

Browse files
committed
Adds support for video stabilization to camera_platform_interface
- Adds getSupportedVideoStabilizationModes() and setVideoStabilizationMode() methods to CameraPlatform. - Adds VideoStabilizationMode enum to represent an abstraction of the available video stabilization modes, meant for Android and iOS, mapped as follows: /// Video stabilization is disabled. off, /// Least stabilized video stabilization mode with the least latency. level1, /// More stabilized video with more latency. level2, /// Most stabilized video with the most latency. level3;
1 parent 5fc2fd7 commit 861f04d

File tree

8 files changed

+113
-1
lines changed

8 files changed

+113
-1
lines changed

packages/camera/camera_platform_interface/AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ Anton Borries <mail@antonborri.es>
6565
Alex Li <google@alexv525.com>
6666
Rahul Raj <64.rahulraj@gmail.com>
6767
Mairramer <mairramer.dasilva28@hotmail.com>
68+
Rui Craveiro <ruicraveiro@squarealfa.com>

packages/camera/camera_platform_interface/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.12.0
2+
3+
* Adds support for video stabilization.
4+
15
## 2.11.0
26

37
* Adds a flag to configure a recording to be persistent across camera changes. See
@@ -20,6 +24,7 @@
2024
most platforms, and there is no plan to implement it in the future.
2125
* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.
2226

27+
2328
## 2.7.4
2429

2530
* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,34 @@ abstract class CameraPlatform extends PlatformInterface {
281281
throw UnimplementedError('setZoomLevel() is not implemented.');
282282
}
283283

284+
/// Gets a list of video stabilization modes that are supported for the selected camera.
285+
Future<Iterable<VideoStabilizationMode>> getSupportedVideoStabilizationModes(
286+
int cameraId,
287+
) async => <VideoStabilizationMode>[];
288+
289+
/// Sets the video stabilization mode for the selected camera.
290+
Future<void> setVideoStabilizationMode(
291+
int cameraId,
292+
VideoStabilizationMode mode,
293+
) async {
294+
throw UnimplementedError('setVideoStabilizationMode() is not implemented.');
295+
}
296+
297+
/// Gets the fallback mode of video stabilization [mode].
298+
///
299+
/// This method returns the video stabilization mode that [setVideoStabilizationMode]
300+
/// should set when the device does not support the given [mode].
301+
static VideoStabilizationMode? getFallbackVideoStabilizationMode(
302+
VideoStabilizationMode mode,
303+
) {
304+
return switch (mode) {
305+
VideoStabilizationMode.off => null,
306+
VideoStabilizationMode.level1 => VideoStabilizationMode.off,
307+
VideoStabilizationMode.level2 => VideoStabilizationMode.level1,
308+
VideoStabilizationMode.level3 => VideoStabilizationMode.level2,
309+
};
310+
}
311+
284312
/// Pause the active preview on the current frame for the selected camera.
285313
Future<void> pausePreview(int cameraId) {
286314
throw UnimplementedError('pausePreview() is not implemented.');

packages/camera/camera_platform_interface/lib/src/types/types.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export 'image_format_group.dart';
1313
export 'media_settings.dart';
1414
export 'resolution_preset.dart';
1515
export 'video_capture_options.dart';
16+
export 'video_stabilization_mode.dart';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
/// The possible video stabilization modes that can be capturing video.
6+
enum VideoStabilizationMode {
7+
/// Video stabilization is disabled.
8+
off,
9+
10+
/// Least stabilized video stabilization mode with the least latency.
11+
level1,
12+
13+
/// More stabilized video with more latency.
14+
level2,
15+
16+
/// Most stabilized video with the most latency.
17+
level3,
18+
}

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/packages/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.11.0
7+
version: 2.12.0
88

99
environment:
1010
sdk: ^3.7.0

packages/camera/camera_platform_interface/test/camera_platform_interface_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,42 @@ void main() {
531531
expect(cameraPlatform.supportsImageStreaming(), false);
532532
},
533533
);
534+
535+
test('getFallbackViewStabilizationMode returns level2 for mode level3', () {
536+
final VideoStabilizationMode? fallbackMode =
537+
CameraPlatform.getFallbackVideoStabilizationMode(
538+
VideoStabilizationMode.level3,
539+
);
540+
541+
expect(fallbackMode, VideoStabilizationMode.level2);
542+
});
543+
544+
test('getFallbackViewStabilizationMode returns level1 for mode level2', () {
545+
final VideoStabilizationMode? fallbackMode =
546+
CameraPlatform.getFallbackVideoStabilizationMode(
547+
VideoStabilizationMode.level2,
548+
);
549+
550+
expect(fallbackMode, VideoStabilizationMode.level1);
551+
});
552+
553+
test('getFallbackViewStabilizationMode returns off for mode level1', () {
554+
final VideoStabilizationMode? fallbackMode =
555+
CameraPlatform.getFallbackVideoStabilizationMode(
556+
VideoStabilizationMode.level1,
557+
);
558+
559+
expect(fallbackMode, VideoStabilizationMode.off);
560+
});
561+
562+
test('getFallbackViewStabilizationMode returns null for mode off', () {
563+
final VideoStabilizationMode? fallbackMode =
564+
CameraPlatform.getFallbackVideoStabilizationMode(
565+
VideoStabilizationMode.off,
566+
);
567+
568+
expect(fallbackMode, null);
569+
});
534570
});
535571

536572
group('exports', () {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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:camera_platform_interface/src/types/video_stabilization_mode.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
8+
void main() {
9+
test('VideoStabilizationMode should contain 4 options', () {
10+
const List<VideoStabilizationMode> values = VideoStabilizationMode.values;
11+
12+
expect(values.length, 4);
13+
});
14+
15+
test('VideoStabilizationMode enum should have items in correct index', () {
16+
const List<VideoStabilizationMode> values = VideoStabilizationMode.values;
17+
18+
expect(values[0], VideoStabilizationMode.off);
19+
expect(values[1], VideoStabilizationMode.level1);
20+
expect(values[2], VideoStabilizationMode.level2);
21+
expect(values[3], VideoStabilizationMode.level3);
22+
});
23+
}

0 commit comments

Comments
 (0)