1 /*
2  * Copyright 2019 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 
17 package androidx.camera.core.impl;
18 
19 import android.hardware.camera2.params.StreamConfigurationMap;
20 import android.util.Size;
21 
22 import com.google.auto.value.AutoValue;
23 
24 import org.jspecify.annotations.NonNull;
25 import org.jspecify.annotations.Nullable;
26 
27 import java.util.Map;
28 
29 /**
30  * Camera device surface size definition
31  *
32  * <p>{@link android.hardware.camera2.CameraDevice#createCaptureSession} defines the default
33  * guaranteed stream combinations for different hardware level devices.
34  */
35 @SuppressWarnings("AutoValueImmutableFields")
36 @AutoValue
37 public abstract class SurfaceSizeDefinition {
38 
39     /** Prevent subclassing */
SurfaceSizeDefinition()40     SurfaceSizeDefinition() {
41     }
42 
43     /**
44      * Create a SurfaceSizeDefinition object with input analysis, preview, record and maximum sizes
45      *
46      * @param analysisSize        Default ANALYSIS size is * 640x480.
47      * @param s720pSizeMap        The format to size map of an s720p size stream. s720p refers to
48      *                            the 720p (1280 x 720) or the maximum supported resolution for the
49      *                            particular format returned by
50      *                            {@link StreamConfigurationMap#getOutputSizes(int)}, whichever is
51      *                            smaller.
52      * @param previewSize         PREVIEW refers to the best size match to the device's screen
53      *                            resolution, or to 1080p * (1920x1080), whichever is smaller.
54      * @param s1440pSizeMap       The format to size map of an s1440p size stream. s1440p refers
55      *                            to the 1440p (1920 x 1440) or the maximum supported resolution
56      *                            for the particular format returned by
57      *                            {@link StreamConfigurationMap#getOutputSizes(int)}, whichever is
58      *                            smaller.
59      * @param recordSize          RECORD refers to the camera device's maximum supported * recording
60      *                            resolution, as determined by CamcorderProfile.
61      * @param maximumSizeMap      The format to size map of an MAXIMUM size stream. MAXIMUM
62      *                            refers to the camera device's maximum output resolution in the
63      *                            default sensor pixel mode.
64      * @param ultraMaximumSizeMap The format to size map of an ULTRA_MAXIMUM size stream.
65      *                            ULTRA_MAXIMUM refers to the camera device's maximum output
66      *                            resolution in the maximum resolution sensor pixel mode.
67      * @return new {@link SurfaceSizeDefinition} object
68      */
create( @onNull Size analysisSize, @NonNull Map<Integer, Size> s720pSizeMap, @NonNull Size previewSize, @NonNull Map<Integer, Size> s1440pSizeMap, @NonNull Size recordSize, @NonNull Map<Integer, Size> maximumSizeMap, @NonNull Map<Integer, Size> ultraMaximumSizeMap)69     public static @NonNull SurfaceSizeDefinition create(
70             @NonNull Size analysisSize,
71             @NonNull Map<Integer, Size> s720pSizeMap,
72             @NonNull Size previewSize,
73             @NonNull Map<Integer, Size> s1440pSizeMap,
74             @NonNull Size recordSize,
75             @NonNull Map<Integer, Size> maximumSizeMap,
76             @NonNull Map<Integer, Size> ultraMaximumSizeMap) {
77         return new AutoValue_SurfaceSizeDefinition(
78                 analysisSize,
79                 s720pSizeMap,
80                 previewSize,
81                 s1440pSizeMap,
82                 recordSize,
83                 maximumSizeMap,
84                 ultraMaximumSizeMap);
85     }
86 
87     /** Returns the size of an ANALYSIS stream. */
getAnalysisSize()88     public abstract @NonNull Size getAnalysisSize();
89 
90     /** Returns the format to size map of an s720p stream. */
getS720pSizeMap()91     public abstract @NonNull Map<Integer, Size> getS720pSizeMap();
92 
93     /** Returns the size of a PREVIEW stream. */
getPreviewSize()94     public abstract @NonNull Size getPreviewSize();
95 
96     /** Returns the format to size map of an s1440p stream. */
getS1440pSizeMap()97     public abstract @NonNull Map<Integer, Size> getS1440pSizeMap();
98 
99     /** Returns the size of a RECORD stream*/
getRecordSize()100     public abstract @NonNull Size getRecordSize();
101 
102     /** Returns the format to size map of an MAXIMUM stream. */
getMaximumSizeMap()103     public abstract @NonNull Map<Integer, Size> getMaximumSizeMap();
104 
105     /** Returns the format to size map of an ULTRA_MAXIMUM stream. */
getUltraMaximumSizeMap()106     public abstract @NonNull Map<Integer, Size> getUltraMaximumSizeMap();
107 
108     /**
109      * Returns the s720p size for the specified format, or {@code null} null if there is no data
110      * for the format.
111      */
getS720pSize(int format)112     public @NonNull Size getS720pSize(int format) {
113         return getS720pSizeMap().get(format);
114     }
115 
116     /**
117      * Returns the s1440p size for the specified format, or {@code null} null if there is no data
118      * for the format.
119      */
getS1440pSize(int format)120     public @NonNull Size getS1440pSize(int format) {
121         return getS1440pSizeMap().get(format);
122     }
123 
124     /**
125      * Returns the MAXIMUM size for the specified format, or {@code null} null if there is no
126      * data for the format.
127      */
getMaximumSize(int format)128     public @Nullable Size getMaximumSize(int format) {
129         return getMaximumSizeMap().get(format);
130     }
131 
132     /**
133      * Returns the ULTRA_MAXIMUM size for the specified format, or {@code null} if the device
134      * doesn't support maximum resolution sensor pixel mode.
135      */
getUltraMaximumSize(int format)136     public @Nullable Size getUltraMaximumSize(int format) {
137         return getUltraMaximumSizeMap().get(format);
138     }
139 }
140