Skip to content

Commit 6afff4e

Browse files
Treehugger RobotGerrit Code Review
authored andcommitted
Merge "[acms-fixit] Constrain high-speed frame rate to CamcorderProfile" into androidx-main
2 parents 5d759a6 + bebf826 commit 6afff4e

19 files changed

Lines changed: 544 additions & 66 deletions

File tree

‎camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/adapter/SupportedSurfaceCombination.kt‎

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import androidx.camera.core.featuregroup.impl.feature.FpsRangeFeature
5353
import androidx.camera.core.impl.AttachedSurfaceInfo
5454
import androidx.camera.core.impl.CameraMode
5555
import androidx.camera.core.impl.EncoderProfilesProvider
56+
import androidx.camera.core.impl.FrameRates.FRAME_RATE_UNLIMITED
5657
import androidx.camera.core.impl.ImageFormatConstants
5758
import androidx.camera.core.impl.SessionConfig
5859
import androidx.camera.core.impl.SessionConfig.SESSION_TYPE_HIGH_SPEED
@@ -1058,11 +1059,12 @@ public class SupportedSurfaceCombination(
10581059
for (attachedSurfaceInfo in attachedSurfaces) {
10591060
// get the fps ceiling for existing surfaces
10601061
existingSurfaceFrameRateCeiling =
1061-
getUpdatedMaximumFps(
1062+
getCombinedMaximumFps(
10621063
existingSurfaceFrameRateCeiling,
10631064
attachedSurfaceInfo.imageFormat,
10641065
attachedSurfaceInfo.size,
10651066
isHighSpeedOn,
1067+
attachedSurfaceInfo.customMaxFrameRate,
10661068
)
10671069
}
10681070
return existingSurfaceFrameRateCeiling
@@ -1087,11 +1089,13 @@ public class SupportedSurfaceCombination(
10871089
val configSizeUniqueMaxFpsMap = mutableMapOf<ConfigSize, MutableSet<Int>>()
10881090
for (size in newUseCaseConfigsSupportedSizeMap[useCaseConfig]!!) {
10891091
val imageFormat = useCaseConfig.inputFormat
1092+
val customMaxFps = useCaseConfig.getCustomMaxFrameRate(size)
10901093
val streamUseCase = useCaseConfig.streamUseCase
10911094
populateReducedSizeListAndUniqueMaxFpsMap(
10921095
featureSettings,
10931096
size,
10941097
imageFormat,
1098+
customMaxFps,
10951099
streamUseCase,
10961100
forceUniqueMaxFpsFiltering,
10971101
configSizeUniqueMaxFpsMap,
@@ -1107,6 +1111,7 @@ public class SupportedSurfaceCombination(
11071111
featureSettings: FeatureSettings,
11081112
size: Size,
11091113
imageFormat: Int,
1114+
customMaxFps: Int,
11101115
streamUseCase: StreamUseCase,
11111116
forceUniqueMaxFpsFiltering: Boolean,
11121117
configSizeUniqueMaxFpsMap: MutableMap<ConfigSize, MutableSet<Int>>,
@@ -1134,7 +1139,7 @@ public class SupportedSurfaceCombination(
11341139
featureSettings.targetFpsRange != FRAME_RATE_RANGE_UNSPECIFIED ||
11351140
forceUniqueMaxFpsFiltering
11361141
) {
1137-
getMaxFrameRate(imageFormat, size, featureSettings.isHighSpeedOn)
1142+
getMaxFrameRate(imageFormat, size, featureSettings.isHighSpeedOn, customMaxFps)
11381143
} else {
11391144
FRAME_RATE_UNLIMITED
11401145
}
@@ -1528,23 +1533,31 @@ public class SupportedSurfaceCombination(
15281533
// get the maximum fps of the new surface and update the maximum fps of the
15291534
// proposed configuration
15301535
newConfigFrameRateCeiling =
1531-
getUpdatedMaximumFps(
1536+
getCombinedMaximumFps(
15321537
newConfigFrameRateCeiling,
15331538
newUseCase.inputFormat,
15341539
size,
15351540
isHighSpeedOn,
1541+
newUseCase.getCustomMaxFrameRate(size),
15361542
)
15371543
}
15381544
return newConfigFrameRateCeiling
15391545
}
15401546

1541-
private fun getMaxFrameRate(imageFormat: Int, size: Size, isHighSpeedOn: Boolean): Int {
1542-
return if (isHighSpeedOn) {
1543-
check(imageFormat == ImageFormatConstants.INTERNAL_DEFINED_IMAGE_FORMAT_PRIVATE)
1544-
highSpeedResolver.getMaxFrameRate(size)
1545-
} else {
1546-
getMaxFrameRate(imageFormat, size)
1547-
}
1547+
private fun getMaxFrameRate(
1548+
imageFormat: Int,
1549+
size: Size,
1550+
isHighSpeedOn: Boolean,
1551+
customMaxFps: Int,
1552+
): Int {
1553+
val surfaceMaxFps =
1554+
if (isHighSpeedOn) {
1555+
check(imageFormat == ImageFormatConstants.INTERNAL_DEFINED_IMAGE_FORMAT_PRIVATE)
1556+
highSpeedResolver.getMaxFrameRate(size)
1557+
} else {
1558+
getMaxFrameRate(imageFormat, size)
1559+
}
1560+
return min(customMaxFps, surfaceMaxFps)
15481561
}
15491562

15501563
private fun getMaxFrameRate(imageFormat: Int, size: Size): Int {
@@ -1804,18 +1817,25 @@ public class SupportedSurfaceCombination(
18041817
}
18051818

18061819
/**
1807-
* @param currentMaxFps the previously stored Max FPS
1808-
* @param imageFormat the image format of the incoming surface
1809-
* @param size the size of the incoming surface
1810-
* @param isHighSpeedOn whether high-speed session is enabled
1820+
* Calculates the new maximum FPS considering an incoming surface.
1821+
*
1822+
* @param combinedMaxFps the maximum FPS from previously considered surfaces.
1823+
* @param imageFormat the image format of the incoming surface.
1824+
* @param size the size of the incoming surface.
1825+
* @param isHighSpeedOn whether a high-speed session is enabled, which affects how the device's
1826+
* supported maximum FPS is retrieved.
1827+
* @param customMaxFps a custom maximum FPS configured for this surface.
1828+
* @return The updated maximum FPS.
18111829
*/
1812-
private fun getUpdatedMaximumFps(
1813-
currentMaxFps: Int,
1830+
private fun getCombinedMaximumFps(
1831+
combinedMaxFps: Int,
18141832
imageFormat: Int,
18151833
size: Size,
18161834
isHighSpeedOn: Boolean,
1835+
customMaxFps: Int,
18171836
): Int {
1818-
return min(currentMaxFps, getMaxFrameRate(imageFormat, size, isHighSpeedOn))
1837+
val surfaceMaxFps = getMaxFrameRate(imageFormat, size, isHighSpeedOn, customMaxFps)
1838+
return min(combinedMaxFps, surfaceMaxFps)
18191839
}
18201840

18211841
/**
@@ -2360,8 +2380,6 @@ public class SupportedSurfaceCombination(
23602380
}
23612381

23622382
public companion object {
2363-
private const val FRAME_RATE_UNLIMITED = Int.MAX_VALUE
2364-
23652383
private fun isUltraHdrOn(
23662384
attachedSurfaces: List<AttachedSurfaceInfo>,
23672385
newUseCaseConfigsSupportedSizeMap: Map<UseCaseConfig<*>, List<Size>>,

‎camera/camera-camera2-pipe-integration/src/main/java/androidx/camera/camera2/pipe/integration/impl/UseCaseManager.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,7 @@ constructor(
825825
streamSpec.sessionType,
826826
streamSpec.expectedFrameRateRange,
827827
useCase.currentConfig.isStrictFrameRateRequired,
828+
useCase.currentConfig.getCustomMaxFrameRate(surfaceResolution),
828829
)
829830
)
830831
}

‎camera/camera-camera2-pipe-integration/src/test/java/androidx/camera/camera2/pipe/integration/adapter/SupportedSurfaceCombinationTest.kt‎

Lines changed: 132 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ import androidx.camera.core.impl.CameraMode.ULTRA_HIGH_RESOLUTION_CAMERA
8989
import androidx.camera.core.impl.CameraThreadConfig
9090
import androidx.camera.core.impl.EncoderProfilesProxy
9191
import androidx.camera.core.impl.EncoderProfilesProxy.VideoProfileProxy
92+
import androidx.camera.core.impl.FrameRates.FRAME_RATE_UNLIMITED
9293
import androidx.camera.core.impl.ImageFormatConstants
9394
import androidx.camera.core.impl.ImageInputConfig
9495
import androidx.camera.core.impl.MutableOptionsBundle
@@ -2578,6 +2579,7 @@ class SupportedSurfaceCombinationTest {
25782579
SESSION_TYPE_REGULAR,
25792580
FRAME_RATE_RANGE_UNSPECIFIED,
25802581
/*isStrictFrameRateRequired=*/ false,
2582+
FRAME_RATE_UNLIMITED,
25812583
)
25822584
val attachedAnalysis =
25832585
AttachedSurfaceInfo.create(
@@ -2590,6 +2592,7 @@ class SupportedSurfaceCombinationTest {
25902592
SESSION_TYPE_REGULAR,
25912593
FRAME_RATE_RANGE_UNSPECIFIED,
25922594
/*isStrictFrameRateRequired=*/ false,
2595+
FRAME_RATE_UNLIMITED,
25932596
)
25942597

25952598
Assert.assertThrows(IllegalArgumentException::class.java) {
@@ -2625,6 +2628,7 @@ class SupportedSurfaceCombinationTest {
26252628
SESSION_TYPE_REGULAR,
26262629
FRAME_RATE_RANGE_UNSPECIFIED,
26272630
/*isStrictFrameRateRequired=*/ false,
2631+
FRAME_RATE_UNLIMITED,
26282632
)
26292633
val attachedPriv2 =
26302634
AttachedSurfaceInfo.create(
@@ -2637,6 +2641,7 @@ class SupportedSurfaceCombinationTest {
26372641
SESSION_TYPE_REGULAR,
26382642
FRAME_RATE_RANGE_UNSPECIFIED,
26392643
/*isStrictFrameRateRequired=*/ false,
2644+
FRAME_RATE_UNLIMITED,
26402645
)
26412646

26422647
// These constraints say HDR10 and HDR10_PLUS can be combined, but not HLG
@@ -2687,6 +2692,7 @@ class SupportedSurfaceCombinationTest {
26872692
SESSION_TYPE_REGULAR,
26882693
FRAME_RATE_RANGE_UNSPECIFIED,
26892694
/*isStrictFrameRateRequired=*/ false,
2695+
FRAME_RATE_UNLIMITED,
26902696
)
26912697
val attachedPriv2 =
26922698
AttachedSurfaceInfo.create(
@@ -2699,6 +2705,7 @@ class SupportedSurfaceCombinationTest {
26992705
SESSION_TYPE_REGULAR,
27002706
FRAME_RATE_RANGE_UNSPECIFIED,
27012707
/*isStrictFrameRateRequired=*/ false,
2708+
FRAME_RATE_UNLIMITED,
27022709
)
27032710

27042711
getSuggestedSpecsAndVerify(
@@ -2912,6 +2919,7 @@ class SupportedSurfaceCombinationTest {
29122919
SESSION_TYPE_REGULAR,
29132920
Range(40, 50),
29142921
/*isStrictFrameRateRequired=*/ false,
2922+
FRAME_RATE_UNLIMITED,
29152923
)
29162924
getSuggestedSpecsAndVerify(
29172925
useCaseExpectedResultMap,
@@ -2942,6 +2950,7 @@ class SupportedSurfaceCombinationTest {
29422950
SESSION_TYPE_REGULAR,
29432951
Range(40, 50),
29442952
/*isStrictFrameRateRequired=*/ false,
2953+
FRAME_RATE_UNLIMITED,
29452954
)
29462955
getSuggestedSpecsAndVerify(
29472956
useCaseExpectedResultMap,
@@ -2972,6 +2981,7 @@ class SupportedSurfaceCombinationTest {
29722981
SESSION_TYPE_REGULAR,
29732982
Range(40, 50),
29742983
/*isStrictFrameRateRequired=*/ false,
2984+
FRAME_RATE_UNLIMITED,
29752985
)
29762986
getSuggestedSpecsAndVerify(
29772987
useCaseExpectedResultMap,
@@ -3240,6 +3250,112 @@ class SupportedSurfaceCombinationTest {
32403250
)
32413251
}
32423252

3253+
@Test
3254+
fun getSuggestedStreamSpec_withCustomMaxFrameRate_isRespected() {
3255+
// Arrange.
3256+
// Device supports 60fps for 1080p.
3257+
val maxFpsBySizeMap = mapOf(RESOLUTION_1080P to 60)
3258+
// Use case with custom max frame rate set to 30fps for 1080p.
3259+
val useCase =
3260+
createUseCase(
3261+
CaptureType.PREVIEW,
3262+
targetFrameRate = Range(30, 30),
3263+
customMaxFpsMap = mapOf(RESOLUTION_1080P to 30),
3264+
)
3265+
val useCaseExpectedResultMap = mapOf(useCase to RESOLUTION_1080P)
3266+
val useCasesOutputSizesMap = mapOf(useCase to listOf(RESOLUTION_1080P))
3267+
3268+
// Act & Assert.
3269+
// The final fps should be capped at 30fps.
3270+
getSuggestedSpecsAndVerify(
3271+
useCasesExpectedResultMap = useCaseExpectedResultMap,
3272+
useCasesOutputSizesMap = useCasesOutputSizesMap,
3273+
maxFpsBySizeMap = maxFpsBySizeMap,
3274+
compareExpectedFps = Range(30, 30),
3275+
deviceFPSRanges = arrayOf(Range(30, 30), Range(60, 60)),
3276+
)
3277+
}
3278+
3279+
@Test
3280+
fun getSuggestedStreamSpec_withCustomMaxFrameRateHigherThanDevice_deviceMaxIsUsed() {
3281+
// Arrange.
3282+
// Device supports 30fps for 1080p.
3283+
val maxFpsBySizeMap = mapOf(RESOLUTION_1080P to 30)
3284+
// Use case with custom max frame rate set to 60fps for 1080p.
3285+
val useCase =
3286+
createUseCase(
3287+
CaptureType.PREVIEW,
3288+
targetFrameRate = Range(30, 30),
3289+
customMaxFpsMap = mapOf(RESOLUTION_1080P to 60),
3290+
)
3291+
val useCaseExpectedResultMap = mapOf(useCase to RESOLUTION_1080P)
3292+
val useCasesOutputSizesMap = mapOf(useCase to listOf(RESOLUTION_1080P))
3293+
3294+
// Act & Assert.
3295+
// The final fps should be capped at 30fps by the device.
3296+
getSuggestedSpecsAndVerify(
3297+
useCasesExpectedResultMap = useCaseExpectedResultMap,
3298+
useCasesOutputSizesMap = useCasesOutputSizesMap,
3299+
maxFpsBySizeMap = maxFpsBySizeMap,
3300+
compareExpectedFps = Range(30, 30),
3301+
deviceFPSRanges = arrayOf(Range(30, 30), Range(60, 60)),
3302+
)
3303+
}
3304+
3305+
@Test
3306+
fun getSuggestedStreamSpec_targetFpsHigherThanCustomMax_customMaxIsUsed() {
3307+
// Arrange.
3308+
// Device supports 60fps for 1080p.
3309+
val maxFpsBySizeMap = mapOf(RESOLUTION_1080P to 60)
3310+
// Use case with custom max frame rate set to 30fps for 1080p, but target is 60fps.
3311+
val useCase =
3312+
createUseCase(
3313+
CaptureType.PREVIEW,
3314+
targetFrameRate = Range(60, 60),
3315+
customMaxFpsMap = mapOf(RESOLUTION_1080P to 30),
3316+
)
3317+
val useCaseExpectedResultMap = mapOf(useCase to RESOLUTION_1080P)
3318+
val useCasesOutputSizesMap = mapOf(useCase to listOf(RESOLUTION_1080P))
3319+
3320+
// Act & Assert.
3321+
// The final fps should drop to 30fps.
3322+
getSuggestedSpecsAndVerify(
3323+
useCasesExpectedResultMap = useCaseExpectedResultMap,
3324+
useCasesOutputSizesMap = useCasesOutputSizesMap,
3325+
maxFpsBySizeMap = maxFpsBySizeMap,
3326+
compareExpectedFps = Range(30, 30),
3327+
deviceFPSRanges = arrayOf(Range(30, 30), Range(60, 60)),
3328+
)
3329+
}
3330+
3331+
@Test
3332+
fun getSuggestedStreamSpec_multipleUseCasesOneWithCustomMax_isRespectedForBoth() {
3333+
// Arrange.
3334+
// Device supports 60fps for 720p.
3335+
val maxFpsBySizeMap = mapOf(RESOLUTION_720P to 60)
3336+
val useCase1 = createUseCase(CaptureType.PREVIEW, targetFrameRate = Range(60, 60))
3337+
val useCase2 =
3338+
createUseCase(
3339+
CaptureType.VIDEO_CAPTURE,
3340+
targetFrameRate = Range(60, 60),
3341+
customMaxFpsMap = mapOf(RESOLUTION_720P to 30),
3342+
)
3343+
val useCaseExpectedResultMap =
3344+
mapOf(useCase1 to RESOLUTION_720P, useCase2 to RESOLUTION_720P)
3345+
val useCasesOutputSizesMap =
3346+
mapOf(useCase1 to listOf(RESOLUTION_720P), useCase2 to listOf(RESOLUTION_720P))
3347+
3348+
// Act & Assert.
3349+
// The final fps should drop to 30fps.
3350+
getSuggestedSpecsAndVerify(
3351+
useCasesExpectedResultMap = useCaseExpectedResultMap,
3352+
useCasesOutputSizesMap = useCasesOutputSizesMap,
3353+
maxFpsBySizeMap = maxFpsBySizeMap,
3354+
compareExpectedFps = Range(30, 30),
3355+
deviceFPSRanges = arrayOf(Range(30, 30), Range(60, 60)),
3356+
)
3357+
}
3358+
32433359
@Test
32443360
fun getSuggestedStreamSpec_singleUseCase_returnMaxSupportedFrameRate() {
32453361
// Arrange.
@@ -3925,6 +4041,7 @@ class SupportedSurfaceCombinationTest {
39254041
SESSION_TYPE_REGULAR,
39264042
FRAME_RATE_RANGE_UNSPECIFIED,
39274043
false,
4044+
FRAME_RATE_UNLIMITED,
39284045
)
39294046

39304047
private fun createVideoCaptureAttachedSurfaceInfo() =
@@ -3938,6 +4055,7 @@ class SupportedSurfaceCombinationTest {
39384055
SESSION_TYPE_REGULAR,
39394056
FRAME_RATE_RANGE_UNSPECIFIED,
39404057
false,
4058+
FRAME_RATE_UNLIMITED,
39414059
)
39424060

39434061
@Config(minSdk = Build.VERSION_CODES.M)
@@ -4876,16 +4994,18 @@ class SupportedSurfaceCombinationTest {
48764994
sessionType: Int? = null,
48774995
targetFrameRate: Range<Int>? = null,
48784996
isStrictFpsRequired: Boolean = false,
4997+
customMaxFpsMap: Map<Size, Int>? = null,
48794998
dynamicRange: DynamicRange = DynamicRange.UNSPECIFIED,
48804999
surfaceOccupancyPriority: Int? = null,
48815000
streamUseCase: StreamUseCase? = null,
48825001
): UseCase {
48835002
return createUseCase(
4884-
captureType,
4885-
sessionType,
4886-
targetFrameRate,
4887-
isStrictFpsRequired,
4888-
dynamicRange,
5003+
captureType = captureType,
5004+
sessionType = sessionType,
5005+
targetFrameRate = targetFrameRate,
5006+
isStrictFpsRequired = isStrictFpsRequired,
5007+
customMaxFpsMap = customMaxFpsMap,
5008+
dynamicRange = dynamicRange,
48895009
surfaceOccupancyPriority = surfaceOccupancyPriority,
48905010
streamUseCase = streamUseCase,
48915011
streamUseCaseOverride = null,
@@ -4904,6 +5024,7 @@ class SupportedSurfaceCombinationTest {
49045024
sessionType: Int? = null,
49055025
targetFrameRate: Range<Int>? = null,
49065026
isStrictFpsRequired: Boolean? = null,
5027+
customMaxFpsMap: Map<Size, Int>? = null,
49075028
dynamicRange: DynamicRange? = DynamicRange.UNSPECIFIED,
49085029
imageFormat: Int? = null,
49095030
surfaceOccupancyPriority: Int? = null,
@@ -4934,6 +5055,12 @@ class SupportedSurfaceCombinationTest {
49345055
it,
49355056
)
49365057
}
5058+
customMaxFpsMap?.let {
5059+
builder.mutableConfig.insertOption(
5060+
UseCaseConfig.OPTION_RESOLUTION_TO_MAX_FRAME_RATES,
5061+
it,
5062+
)
5063+
}
49375064
streamUseCase?.let { builder.setStreamUseCase(it) }
49385065
builder.mutableConfig.insertOption(
49395066
ImageInputConfig.OPTION_INPUT_DYNAMIC_RANGE,

0 commit comments

Comments
 (0)