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] CameraPlatform.createCameraWithSettings #3615

Merged
merged 23 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d3ec9b8
PR that has only the platform interface package changes from the #358…
PROGrand Sep 4, 2023
54e757a
touch
PROGrand Sep 4, 2023
197d67f
touch
PROGrand Sep 4, 2023
2a83a10
touch
PROGrand Sep 4, 2023
5dbb4e8
Update packages/camera/camera_platform_interface/pubspec.yaml
PROGrand Sep 19, 2023
3343cef
Update packages/camera/camera_platform_interface/CHANGELOG.md
PROGrand Sep 19, 2023
3a7db1a
Applied suggestions of https://github.com/flutter/packages/pull/3615#…
PROGrand Sep 21, 2023
40c4385
tested and analyzed
PROGrand Sep 21, 2023
442d25f
Delete packages/camera/camera_platform_interface/coverage/lcov.info
PROGrand Sep 24, 2023
462d032
Merge branch 'main' into camera-platform-interface
PROGrand Oct 12, 2023
3f3e092
delegated as in the "Note" section under (1) [here]( https://github.c…
PROGrand Oct 12, 2023
030d134
lexical corrections
PROGrand Oct 12, 2023
e8231d6
removed excessive comments
PROGrand Oct 12, 2023
a29e41b
correct description
PROGrand Oct 12, 2023
820f4b4
test all parameters combinations in operator ==
PROGrand Oct 12, 2023
26ac77d
Merge branch 'main' into camera-platform-interface
PROGrand Oct 12, 2023
d4d3c53
Merge branch 'main' into camera-platform-interface
PROGrand Oct 14, 2023
891dcca
Merge branch 'main' into camera-platform-interface
PROGrand Oct 18, 2023
afed7bc
tests are simplified
PROGrand Oct 18, 2023
bb01c48
Merge branch 'main' into camera-platform-interface
PROGrand Oct 18, 2023
a3a35a7
Merge branch 'main' into camera-platform-interface
PROGrand Oct 20, 2023
21967bc
Merge branch 'main' into camera-platform-interface
PROGrand Oct 23, 2023
7af349c
test: createCameraWithSettings() should call createCamera() using par…
PROGrand Oct 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ abstract class CameraPlatform extends PlatformInterface {
CameraDescription cameraDescription,
ResolutionPreset? resolutionPreset, {
bool enableAudio = false,
}) =>
createCameraWithSettings(
cameraDescription,
MediaSettings(
resolutionPreset: resolutionPreset,
enableAudio: enableAudio,
),
);
}) {
throw UnimplementedError('createCamera() is not implemented.');
}

/// Creates an uninitialized camera instance and returns the cameraId.
///
Expand All @@ -67,7 +62,7 @@ abstract class CameraPlatform extends PlatformInterface {
CameraDescription cameraDescription,
MediaSettings mediaSettings,
) {
throw UnimplementedError('createCameraWithSettings() is not implemented.');
return createCamera(cameraDescription, mediaSettings.resolutionPreset);
}

/// Initializes the camera on the device.
Expand Down
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'resolution_preset.dart';
///
/// Used in [CameraPlatform.createCameraWithSettings].
/// Allows to tune recorded video parameters, such as resolution, frame rate, bitrate.
/// If [fps], [videoBitrate] and [audioBitrate] passed, they must be greater than zero.
/// If [fps], [videoBitrate] or [audioBitrate] are passed, they must be greater than zero.
class MediaSettings {
/// Creates a [MediaSettings].
const MediaSettings({
Expand All @@ -29,18 +29,12 @@ class MediaSettings {
final ResolutionPreset? resolutionPreset;

/// Rate at which frames should be captured by the camera in frames per second.
///
/// Must be null or greater than zero
final int? fps;

/// The video encoding bit rate for recording.
///
/// Must be null or greater than zero
final int? videoBitrate;

/// The audio encoding bit rate for recording.
///
/// Must be null or greater than zero
final int? audioBitrate;
PROGrand marked this conversation as resolved.
Show resolved Hide resolved

/// Controls audio presence in recorded video.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: always_specify_types

import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:flutter_test/flutter_test.dart';

Expand Down Expand Up @@ -101,42 +103,108 @@ void main() {
);
});

test('MediaSettings hash should be Object.hash of passed parameters', () {
const MediaSettings settings1 = MediaSettings(
resolutionPreset: ResolutionPreset.low,
fps: 20,
videoBitrate: 128000,
audioBitrate: 32000,
enableAudio: true,
);
group('MediaSettings == operator', () {
const ResolutionPreset preset1 = ResolutionPreset.low;
const int fps1 = 20;
const int videoBitrate1 = 128000;
const int audioBitrate1 = 32000;
const bool enableAudio1 = true;

const MediaSettings settings1Copy = MediaSettings(
const ResolutionPreset preset2 = ResolutionPreset.high;
const int fps2 = fps1 + 10;
const int videoBitrate2 = videoBitrate1 * 2;
const int audioBitrate2 = audioBitrate1 * 2;
const bool enableAudio2 = !enableAudio1;

const MediaSettings settings1 = MediaSettings(
resolutionPreset: ResolutionPreset.low,
fps: 20,
videoBitrate: 128000,
audioBitrate: 32000,
enableAudio: true,
);

const MediaSettings settings2 = MediaSettings(
resolutionPreset: ResolutionPreset.high,
fps: 30,
videoBitrate: 256000,
audioBitrate: 64000,
);

expect(
settings1 == settings1Copy,
isTrue,
reason:
'MediaSettings == operator should return true for equal parameters',
);

expect(
settings1 == settings2,
isFalse,
reason:
'MediaSettings == operator should return false for non-equal parameters',
);
// test operator== on parameters combination.
void checkParameters(List<dynamic> args) {
final resolutionPreset = args[0] as ResolutionPreset?;
final fps = args[1] as int?;
final videoBitrate = args[2] as int?;
final audioBitrate = args[3] as int?;
final enableAudio = args[4]! as bool;

final MediaSettings settings2 = MediaSettings(
resolutionPreset: resolutionPreset,
fps: fps,
videoBitrate: videoBitrate,
audioBitrate: audioBitrate,
enableAudio: enableAudio);

if (resolutionPreset == preset1 &&
fps == fps1 &&
videoBitrate == videoBitrate1 &&
audioBitrate == audioBitrate1 &&
enableAudio == enableAudio1) {
expect(
settings1 == settings2,
isTrue,
reason:
'MediaSettings == operator should return true for equal parameters: $settings1 == $settings2',
);
} else {
expect(
settings1 == settings2,
isFalse,
reason:
'MediaSettings == operator should return false for non-equal parameters: $settings1 != $settings2',
);
}
}

test(
'MediaSettings == operator should be short-circuit AND of all parameters',
() {
// Sets of various parameters, including those equal and not equal to the corresponding `settings1` parameters
final params = [
{preset1, preset2, null},
{fps1, fps2, null},
{videoBitrate1, videoBitrate2, null},
{audioBitrate1, audioBitrate2, null},
{enableAudio1, enableAudio2},
];

// recursively check all possible parameters combinations
void combine(List<Set<dynamic>> params, List<dynamic> args, int level) {
if (params.length == level) {
// now args contains all required parameters, so check `operator ==` now
checkParameters(args);
} else {
for (final variant in params[level]) {
combine(params, [...args, variant], level + 1);
PROGrand marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

combine(params, [], 0);
});

test('Identical objects should be equal', () {
const MediaSettings settingsIdentical = settings1;

expect(
settings1 == settingsIdentical,
isTrue,
reason:
'MediaSettings == operator should return true for identical objects',
);
});

test('Objects of different types should be non-equal', () {
expect(
settings1 == Object(),
isFalse,
reason:
'MediaSettings == operator should return false for objects of different types',
);
});
});
}