[camerax] Loosen restrictions of fallback strategies for choosing resolutions (#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 https://github.com/flutter/flutter/issues/135293.
This commit is contained in:
Camille Simon
2023-10-30 16:34:13 +00:00
committed by GitHub
parent 7319d3a7b1
commit 52202abec0
4 changed files with 11 additions and 5 deletions

View File

@ -1,3 +1,8 @@
## 0.5.0+21
* Changes fallback resolution strategies for camera use cases to look for a higher resolution if neither the desired
resolution nor any lower resolutions are available.
## 0.5.0+20
* Implements `setZoomLevel`.

View File

@ -857,7 +857,8 @@ class AndroidCameraCameraX extends CameraPlatform {
/// closest lower resolution available.
ResolutionSelector? _getResolutionSelectorFromPreset(
ResolutionPreset? preset) {
const int fallbackRule = ResolutionStrategy.fallbackRuleClosestLower;
const int fallbackRule =
ResolutionStrategy.fallbackRuleClosestLowerThenHigher;
Size? boundSize;
ResolutionStrategy? resolutionStrategy;
@ -937,7 +938,7 @@ class AndroidCameraCameraX extends CameraPlatform {
// We will choose the next highest video quality if the one desired
// is unavailable.
const VideoResolutionFallbackRule fallbackRule =
VideoResolutionFallbackRule.lowerQualityThan;
VideoResolutionFallbackRule.lowerQualityOrHigherThan;
final FallbackStrategy fallbackStrategy =
_shouldCreateDetachedObjectForTesting
? FallbackStrategy.detached(

View File

@ -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.5.0+20
version: 0.5.0+21
environment:
sdk: ">=2.19.0 <4.0.0"

View File

@ -342,7 +342,7 @@ void main() {
// resolution.
expectedResolutionStrategy ??= ResolutionStrategy.detached(
boundSize: expectedBoundSize,
fallbackRule: ResolutionStrategy.fallbackRuleClosestLower);
fallbackRule: ResolutionStrategy.fallbackRuleClosestLowerThenHigher);
expect(camera.preview!.resolutionSelector!.resolutionStrategy!.boundSize,
equals(expectedResolutionStrategy.boundSize));
@ -431,7 +431,7 @@ void main() {
}
const VideoResolutionFallbackRule expectedFallbackRule =
VideoResolutionFallbackRule.lowerQualityThan;
VideoResolutionFallbackRule.lowerQualityOrHigherThan;
final FallbackStrategy expectedFallbackStrategy =
FallbackStrategy.detached(
quality: expectedVideoQuality,