Skip to content

Commit 52202ab

Browse files
authored
[camerax] Loosen restrictions of fallback strategies for choosing resolutions (flutter#5239)
Changes the fallback strategies for camera use cases to still choose a lower quality resolution if the desired one is not available, but if not successful, it will attempt to choose a higher quality resolution versus throwing an exception. Documentation on fallback strategies: https://developer.android.com/reference/androidx/camera/core/resolutionselector/ResolutionStrategy https://developer.android.com/reference/androidx/camera/video/FallbackStrategy (for video only) Fix attempt for flutter#135293.
1 parent 7319d3a commit 52202ab

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

packages/camera/camera_android_camerax/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.5.0+21
2+
3+
* Changes fallback resolution strategies for camera use cases to look for a higher resolution if neither the desired
4+
resolution nor any lower resolutions are available.
5+
16
## 0.5.0+20
27

38
* Implements `setZoomLevel`.

packages/camera/camera_android_camerax/lib/src/android_camera_camerax.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,8 @@ class AndroidCameraCameraX extends CameraPlatform {
857857
/// closest lower resolution available.
858858
ResolutionSelector? _getResolutionSelectorFromPreset(
859859
ResolutionPreset? preset) {
860-
const int fallbackRule = ResolutionStrategy.fallbackRuleClosestLower;
860+
const int fallbackRule =
861+
ResolutionStrategy.fallbackRuleClosestLowerThenHigher;
861862

862863
Size? boundSize;
863864
ResolutionStrategy? resolutionStrategy;
@@ -937,7 +938,7 @@ class AndroidCameraCameraX extends CameraPlatform {
937938
// We will choose the next highest video quality if the one desired
938939
// is unavailable.
939940
const VideoResolutionFallbackRule fallbackRule =
940-
VideoResolutionFallbackRule.lowerQualityThan;
941+
VideoResolutionFallbackRule.lowerQualityOrHigherThan;
941942
final FallbackStrategy fallbackStrategy =
942943
_shouldCreateDetachedObjectForTesting
943944
? FallbackStrategy.detached(

packages/camera/camera_android_camerax/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: camera_android_camerax
22
description: Android implementation of the camera plugin using the CameraX library.
33
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera_android_camerax
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
5-
version: 0.5.0+20
5+
version: 0.5.0+21
66

77
environment:
88
sdk: ">=2.19.0 <4.0.0"

packages/camera/camera_android_camerax/test/android_camera_camerax_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void main() {
342342
// resolution.
343343
expectedResolutionStrategy ??= ResolutionStrategy.detached(
344344
boundSize: expectedBoundSize,
345-
fallbackRule: ResolutionStrategy.fallbackRuleClosestLower);
345+
fallbackRule: ResolutionStrategy.fallbackRuleClosestLowerThenHigher);
346346

347347
expect(camera.preview!.resolutionSelector!.resolutionStrategy!.boundSize,
348348
equals(expectedResolutionStrategy.boundSize));
@@ -431,7 +431,7 @@ void main() {
431431
}
432432

433433
const VideoResolutionFallbackRule expectedFallbackRule =
434-
VideoResolutionFallbackRule.lowerQualityThan;
434+
VideoResolutionFallbackRule.lowerQualityOrHigherThan;
435435
final FallbackStrategy expectedFallbackStrategy =
436436
FallbackStrategy.detached(
437437
quality: expectedVideoQuality,

0 commit comments

Comments
 (0)