1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package com.google.jetpackcamera.settings.model
17
18 data class SystemConstraints(
19 val availableLenses: List<LensFacing> = emptyList(),
20 val concurrentCamerasSupported: Boolean = false,
21 val perLensConstraints: Map<LensFacing, CameraConstraints> = emptyMap()
22 )
23
forDevicenull24 inline fun <reified T> SystemConstraints.forDevice(
25 crossinline constraintSelector: (CameraConstraints) -> Iterable<T>
26 ) = perLensConstraints.values.asSequence().flatMap { constraintSelector(it) }.toSet()
27
28 data class CameraConstraints(
29 val supportedStabilizationModes: Set<StabilizationMode>,
30 val supportedFixedFrameRates: Set<Int>,
31 val supportedDynamicRanges: Set<DynamicRange>,
32 val supportedVideoQualitiesMap: Map<DynamicRange, List<VideoQuality>>,
33 val supportedImageFormatsMap: Map<StreamConfig, Set<ImageOutputFormat>>,
34 val supportedIlluminants: Set<Illuminant>,
35 val supportedFlashModes: Set<FlashMode>,
36 val unsupportedStabilizationFpsMap: Map<StabilizationMode, Set<Int>>
37 ) {
38 val StabilizationMode.unsupportedFpsSet
39 get() = unsupportedStabilizationFpsMap[this] ?: emptySet()
40
41 companion object {
42 const val FPS_AUTO = 0
43 const val FPS_15 = 15
44 const val FPS_30 = 30
45 const val FPS_60 = 60
46 }
47 }
48
49 /**
50 * Useful set of constraints for testing
51 */
52 val TYPICAL_SYSTEM_CONSTRAINTS =
53 SystemConstraints(
54 availableLenses = listOf(LensFacing.FRONT, LensFacing.BACK),
55 concurrentCamerasSupported = false,
<lambda>null56 perLensConstraints = buildMap {
57 for (lensFacing in listOf(LensFacing.FRONT, LensFacing.BACK)) {
58 put(
59 lensFacing,
60 CameraConstraints(
61 supportedFixedFrameRates = setOf(15, 30),
62 supportedStabilizationModes = setOf(StabilizationMode.OFF),
63 supportedDynamicRanges = setOf(DynamicRange.SDR),
64 supportedImageFormatsMap = mapOf(
65 Pair(StreamConfig.SINGLE_STREAM, setOf(ImageOutputFormat.JPEG)),
66 Pair(StreamConfig.MULTI_STREAM, setOf(ImageOutputFormat.JPEG))
67 ),
68 supportedVideoQualitiesMap = emptyMap(),
69 supportedIlluminants = setOf(Illuminant.FLASH_UNIT),
70 supportedFlashModes = setOf(FlashMode.OFF, FlashMode.ON, FlashMode.AUTO),
71 unsupportedStabilizationFpsMap = emptyMap()
72 )
73 )
74 }
75 }
76 )
77