@@ -89,6 +89,7 @@ import androidx.camera.core.impl.CameraMode.ULTRA_HIGH_RESOLUTION_CAMERA
8989import androidx.camera.core.impl.CameraThreadConfig
9090import androidx.camera.core.impl.EncoderProfilesProxy
9191import androidx.camera.core.impl.EncoderProfilesProxy.VideoProfileProxy
92+ import androidx.camera.core.impl.FrameRates.FRAME_RATE_UNLIMITED
9293import androidx.camera.core.impl.ImageFormatConstants
9394import androidx.camera.core.impl.ImageInputConfig
9495import 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