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] Clean up maxDuration code #7039

Merged
merged 11 commits into from
Jul 10, 2024
Merged
7 changes: 3 additions & 4 deletions packages/camera/camera/test/camera_image_stream_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,10 @@ class MockStreamingCameraPlatform extends MockCameraPlatform {
}

@override
Future<XFile> startVideoRecording(int cameraId,
{Duration? maxVideoDuration}) {
Future<void> startVideoRecording(int cameraId, {Duration? maxVideoDuration}) {
streamCallLog.add('startVideoRecording');
return super
.startVideoRecording(cameraId, maxVideoDuration: maxVideoDuration);
// Ignore maxVideoDuration, as it is unimplemented and deprecated.
return super.startVideoRecording(cameraId);
}

@override
Expand Down
15 changes: 9 additions & 6 deletions packages/camera/camera/test/camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1511,14 +1511,17 @@ class MockCameraPlatform extends Mock
super.noSuchMethod(Invocation.method(#prepareForVideoRecording, null));

@override
Future<XFile> startVideoRecording(int cameraId,
{Duration? maxVideoDuration}) =>
Future<XFile>.value(mockVideoRecordingXFile);
Future<void> startVideoRecording(int cameraId, {Duration? maxVideoDuration}) {
// Ignore maxVideoDuration, as it is unimplemented and deprecated.
return startVideoCapturing(VideoCaptureOptions(cameraId));
}

@override
Future<void> startVideoCapturing(VideoCaptureOptions options) async {}

@override
Future<void> startVideoCapturing(VideoCaptureOptions options) {
return startVideoRecording(options.cameraId,
maxVideoDuration: options.maxDuration);
Future<XFile> stopVideoRecording(int cameraId) {
return Future<XFile>.value(mockVideoRecordingXFile);
}

@override
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.9+8

* Removes unused code related to `maxVideoDuration`.

## 0.10.9+7

* Updates Android Gradle plugin to 8.5.0.
Expand Down
14 changes: 2 additions & 12 deletions packages/camera/camera_android/lib/src/android_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ class AndroidCamera extends CameraPlatform {
@override
Future<void> startVideoRecording(int cameraId,
{Duration? maxVideoDuration}) async {
return startVideoCapturing(
VideoCaptureOptions(cameraId, maxDuration: maxVideoDuration));
// Ignore maxVideoDuration, as it is unimplemented and deprecated.
return startVideoCapturing(VideoCaptureOptions(cameraId));
}

@override
Expand All @@ -277,7 +277,6 @@ class AndroidCamera extends CameraPlatform {
'startVideoRecording',
<String, dynamic>{
'cameraId': options.cameraId,
'maxVideoDuration': options.maxDuration?.inMilliseconds,
'enableStream': options.streamCallback != null,
},
);
Expand Down Expand Up @@ -626,15 +625,6 @@ class AndroidCamera extends CameraPlatform {
cameraEventStreamController.add(CameraClosingEvent(
cameraId,
));
case 'video_recorded':
final Map<String, Object?> arguments = _getArgumentDictionary(call);
cameraEventStreamController.add(VideoRecordedEvent(
cameraId,
XFile(arguments['path']! as String),
arguments['maxVideoDuration'] != null
? Duration(milliseconds: arguments['maxVideoDuration']! as int)
: null,
));
case 'error':
final Map<String, Object?> arguments = _getArgumentDictionary(call);
cameraEventStreamController.add(CameraErrorEvent(
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Android implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22

version: 0.10.9+7
version: 0.10.9+8

environment:
sdk: ^3.4.0
Expand Down
26 changes: 0 additions & 26 deletions packages/camera/camera_android/test/android_camera_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -636,31 +636,6 @@ void main() {
expect(channel.log, <Matcher>[
isMethodCall('startVideoRecording', arguments: <String, Object?>{
'cameraId': cameraId,
'maxVideoDuration': null,
'enableStream': false,
}),
]);
});

test('Should pass maxVideoDuration when starting recording a video',
() async {
// Arrange
final MethodChannelMock channel = MethodChannelMock(
channelName: _channelName,
methods: <String, dynamic>{'startVideoRecording': null},
);

// Act
await camera.startVideoRecording(
cameraId,
maxVideoDuration: const Duration(seconds: 10),
);

// Assert
expect(channel.log, <Matcher>[
isMethodCall('startVideoRecording', arguments: <String, Object?>{
'cameraId': cameraId,
'maxVideoDuration': 10000,
'enableStream': false,
}),
]);
Expand All @@ -685,7 +660,6 @@ void main() {
expect(channel.log, <Matcher>[
isMethodCall('startVideoRecording', arguments: <String, Object?>{
'cameraId': cameraId,
'maxVideoDuration': null,
'enableStream': true,
}),
]);
Expand Down
5 changes: 5 additions & 0 deletions packages/camera/camera_android_camerax/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.6.5+7

* Updates README to remove references to `maxVideoDuration`, as it was never
visible to app-facing clients, nor was it implemented in `camera_android`.

## 0.6.5+6

* Updates Guava version to 33.2.1.
Expand Down
8 changes: 4 additions & 4 deletions packages/camera/camera_android_camerax/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ due to this not currently being supported by CameraX.
the plugin will fall back to target 480p (`ResolutionPreset.medium`) if configured with
`ResolutionPreset.low`.

### Setting maximum duration and stream options for video capture
### Setting stream options for video capture

Calling `startVideoCapturing` with `VideoCaptureOptions` configured with
`maxVideoDuration` and `streamOptions` is currently unsupported do to the
limitations of the CameraX library and the platform interface, respectively,
and thus, those parameters will silently be ignored.
`streamOptions` is currently unsupported do to
limitations of the platform interface,
and thus that parameter will silently be ignored.

## What requires Android permissions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,16 +902,15 @@ class AndroidCameraCameraX extends CameraPlatform {
@override
Future<void> startVideoRecording(int cameraId,
{Duration? maxVideoDuration}) async {
return startVideoCapturing(
VideoCaptureOptions(cameraId, maxDuration: maxVideoDuration));
// Ignore maxVideoDuration, as it is unimplemented and deprecated.
return startVideoCapturing(VideoCaptureOptions(cameraId));
}

/// Starts a video recording and/or streaming session.
///
/// Please see [VideoCaptureOptions] for documentation on the
/// configuration options. Currently, maxVideoDuration and streamOptions
/// are unsupported due to the limitations of CameraX and the platform
/// interface, respectively.
/// configuration options. Currently streamOptions are unsupported due to
/// limitations of the platform interface.
@override
Future<void> startVideoCapturing(VideoCaptureOptions options) async {
if (recording != null) {
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_android_camerax/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_android_camerax
description: Android implementation of the camera plugin using the CameraX library.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.6.5+6
version: 0.6.5+7

environment:
sdk: ^3.4.0
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.16+1

* Removes unused `maxVideoDuration` code.

## 0.9.16

* Converts Dart-to-host communcation to Pigeon.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ class AVFoundationCamera extends CameraPlatform {
@override
Future<void> startVideoRecording(int cameraId,
{Duration? maxVideoDuration}) async {
return startVideoCapturing(
VideoCaptureOptions(cameraId, maxDuration: maxVideoDuration));
// Ignore maxVideoDuration, as it is unimplemented and deprecated.
return startVideoCapturing(VideoCaptureOptions(cameraId));
}

@override
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_avfoundation/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: camera_avfoundation
description: iOS implementation of the camera plugin.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_avfoundation
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.9.16
version: 0.9.16+1

environment:
sdk: ^3.2.3
Expand Down
4 changes: 3 additions & 1 deletion packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## NEXT
## 2.8.0

* Deprecates `maxVideoDuration`/`maxDuration`, as it was never implemented on
most platforms, and there is no plan to implement it in the future.
* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.

## 2.7.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,13 @@ abstract class CameraPlatform extends PlatformInterface {

/// Starts a video recording.
///
/// The length of the recording can be limited by specifying the [maxVideoDuration].
/// By default no maximum duration is specified,
/// 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<void> startVideoRecording(int cameraId, {Duration? maxVideoDuration}) {
Future<void> startVideoRecording(
int cameraId, {
@Deprecated(
'This parameter is unused, and will be ignored on all platforms')
Duration? maxVideoDuration,
}) {
throw UnimplementedError('startVideoRecording() is not implemented.');
}

Expand All @@ -156,8 +155,7 @@ abstract class CameraPlatform extends PlatformInterface {
/// Please see [VideoCaptureOptions] for documentation on the
/// configuration options.
Future<void> startVideoCapturing(VideoCaptureOptions options) {
return startVideoRecording(options.cameraId,
maxVideoDuration: options.maxDuration);
return startVideoRecording(options.cameraId);
}

/// Stops the video recording and returns the file where it was saved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class VideoCaptureOptions {
/// Constructs a new instance.
const VideoCaptureOptions(
this.cameraId, {
@Deprecated(
'This parameter is unused, and will be ignored on all platforms')
this.maxDuration,
this.streamCallback,
this.streamOptions,
Expand All @@ -24,8 +26,9 @@ class VideoCaptureOptions {
final int cameraId;

/// The maximum time to perform capturing for.
///
/// By default there is no maximum on the capture time.
@Deprecated('This parameter is unused, and will be ignored on all platforms')
// Platform implementations should not implement this, as it will never be
// passed from the app-facing layer.
final Duration? maxDuration;

/// An optional callback to enable streaming.
Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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
# 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.7.4
version: 2.8.0

environment:
sdk: ^3.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,30 +643,6 @@ void main() {
]);
});

test('Should pass maxVideoDuration when starting recording a video',
() async {
// Arrange
final MethodChannelMock channel = MethodChannelMock(
channelName: 'plugins.flutter.io/camera',
methods: <String, dynamic>{'startVideoRecording': null},
);

// Act
await camera.startVideoRecording(
cameraId,
maxVideoDuration: const Duration(seconds: 10),
);

// Assert
expect(channel.log, <Matcher>[
isMethodCall('startVideoRecording', arguments: <String, Object?>{
'cameraId': cameraId,
'maxVideoDuration': 10000,
'enableStream': false,
}),
]);
});

test('Should stop a video recording and return the file', () async {
// Arrange
final MethodChannelMock channel = MethodChannelMock(
Expand Down
5 changes: 4 additions & 1 deletion packages/camera/camera_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## NEXT
## 0.3.4

* Removes `maxVideoDuration`/`maxDuration`, as the feature was never exposed at
the app-facing package level, and is deprecated at the platform interface
level.
* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.

## 0.3.3
Expand Down
Loading