xref: /aosp_15_r20/frameworks/av/camera/include/camera/camera2/OutputConfiguration.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
2  * Copyright (C) 2015-2018 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 #ifndef ANDROID_HARDWARE_CAMERA2_OUTPUTCONFIGURATION_H
18 #define ANDROID_HARDWARE_CAMERA2_OUTPUTCONFIGURATION_H
19 
20 #include <string>
21 
22 #include <gui/Flags.h>  // remove with WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
23 #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
24 #include <gui/view/Surface.h>
25 #else
26 #include <gui/IGraphicBufferProducer.h>
27 #endif
28 #include <binder/Parcelable.h>
29 
30 namespace android {
31 
32 class Surface;
33 
34 namespace hardware {
35 namespace camera2 {
36 namespace params {
37 
38 class OutputConfiguration : public android::Parcelable {
39 public:
40 
41     static const int ROTATION_0;
42     static const int INVALID_ROTATION;
43     static const int INVALID_SET_ID;
44     enum SurfaceType {
45         SURFACE_TYPE_UNKNOWN = -1,
46         SURFACE_TYPE_SURFACE_VIEW = 0,
47         SURFACE_TYPE_SURFACE_TEXTURE = 1,
48         SURFACE_TYPE_MEDIA_RECORDER = 2,
49         SURFACE_TYPE_MEDIA_CODEC = 3,
50         SURFACE_TYPE_IMAGE_READER = 4
51     };
52     enum TimestampBaseType {
53         TIMESTAMP_BASE_DEFAULT = 0,
54         TIMESTAMP_BASE_SENSOR = 1,
55         TIMESTAMP_BASE_MONOTONIC = 2,
56         TIMESTAMP_BASE_REALTIME = 3,
57         TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED = 4,
58         TIMESTAMP_BASE_MAX = TIMESTAMP_BASE_CHOREOGRAPHER_SYNCED,
59     };
60     enum MirrorModeType {
61         MIRROR_MODE_AUTO = 0,
62         MIRROR_MODE_NONE = 1,
63         MIRROR_MODE_H = 2,
64         MIRROR_MODE_V = 3,
65     };
66 
67     const std::vector<ParcelableSurfaceType>& getSurfaces() const;
68     int                        getRotation() const;
69     int                        getSurfaceSetID() const;
70     int                        getSurfaceType() const;
71     int                        getWidth() const;
72     int                        getHeight() const;
73     int64_t                    getDynamicRangeProfile() const;
74     int32_t                    getColorSpace() const;
75     bool                       isDeferred() const;
76     bool                       isShared() const;
77     std::string                getPhysicalCameraId() const;
78     bool                       isMultiResolution() const;
79     int64_t                    getStreamUseCase() const;
80     int                        getTimestampBase() const;
81     int                        getMirrorMode(ParcelableSurfaceType surface) const;
82     int                        getMirrorMode() const;
83     bool                       useReadoutTimestamp() const;
84     int                        getFormat() const;
85     int                        getDataspace() const;
86     int64_t                    getUsage() const;
87     bool                       isComplete() const;
88 
89     // set of sensor pixel mode resolutions allowed {MAX_RESOLUTION, DEFAULT_MODE};
90     const std::vector<int32_t>&            getSensorPixelModesUsed() const;
91     /**
92      * Keep impl up-to-date with OutputConfiguration.java in frameworks/base
93      */
94     virtual status_t           writeToParcel(android::Parcel* parcel) const override;
95 
96     virtual status_t           readFromParcel(const android::Parcel* parcel) override;
97 
98     // getGraphicBufferProducer will be NULL
99     // getRotation will be INVALID_ROTATION
100     // getSurfaceSetID will be INVALID_SET_ID
101     OutputConfiguration();
102 
103     // getGraphicBufferProducer will be NULL if error occurred
104     // getRotation will be INVALID_ROTATION if error occurred
105     // getSurfaceSetID will be INVALID_SET_ID if error occurred
106     OutputConfiguration(const android::Parcel& parcel);
107 
108     OutputConfiguration(ParcelableSurfaceType& surface, int rotation,
109             const std::string& physicalCameraId,
110             int surfaceSetID = INVALID_SET_ID, bool isShared = false);
111 
112     OutputConfiguration(const std::vector<ParcelableSurfaceType>& surfaces,
113                         int rotation, const std::string& physicalCameraId,
114                         int surfaceSetID = INVALID_SET_ID,
115                         int surfaceType = SURFACE_TYPE_UNKNOWN, int width = 0,
116                         int height = 0, bool isShared = false);
117     OutputConfiguration(int surfaceType, int width, int height, int format, int32_t colorSpace,
118             int mirrorMode, bool useReadoutTimestamp,int timestampBase, int dataspace,
119             int64_t usage, int64_t streamusecase, std::string physicalCamId);
120 
121     bool operator == (const OutputConfiguration& other) const {
122         return ( mRotation == other.mRotation &&
123                 mSurfaceSetID == other.mSurfaceSetID &&
124                 mSurfaceType == other.mSurfaceType &&
125                 mWidth == other.mWidth &&
126                 mHeight == other.mHeight &&
127                 mIsDeferred == other.mIsDeferred &&
128                 mIsShared == other.mIsShared &&
129                 surfacesEqual(other) &&
130                 mPhysicalCameraId == other.mPhysicalCameraId &&
131                 mIsMultiResolution == other.mIsMultiResolution &&
132                 sensorPixelModesUsedEqual(other) &&
133                 mDynamicRangeProfile == other.mDynamicRangeProfile &&
134                 mColorSpace == other.mColorSpace &&
135                 mStreamUseCase == other.mStreamUseCase &&
136                 mTimestampBase == other.mTimestampBase &&
137                 mMirrorMode == other.mMirrorMode &&
138                 mirrorModesEqual(other) &&
139                 mUseReadoutTimestamp == other.mUseReadoutTimestamp &&
140                 mFormat == other.mFormat &&
141                 mDataspace == other.mDataspace &&
142                 mUsage == other.mUsage);
143     }
144     bool operator != (const OutputConfiguration& other) const {
145         return !(*this == other);
146     }
147     bool operator < (const OutputConfiguration& other) const {
148         if (*this == other) return false;
149         if (mSurfaceSetID != other.mSurfaceSetID) {
150             return mSurfaceSetID < other.mSurfaceSetID;
151         }
152         if (mSurfaceType != other.mSurfaceType) {
153             return mSurfaceType < other.mSurfaceType;
154         }
155         if (mWidth != other.mWidth) {
156             return mWidth < other.mWidth;
157         }
158         if (mHeight != other.mHeight) {
159             return mHeight < other.mHeight;
160         }
161         if (mRotation != other.mRotation) {
162             return mRotation < other.mRotation;
163         }
164         if (mIsDeferred != other.mIsDeferred) {
165             return mIsDeferred < other.mIsDeferred;
166         }
167         if (mIsShared != other.mIsShared) {
168             return mIsShared < other.mIsShared;
169         }
170         if (mPhysicalCameraId != other.mPhysicalCameraId) {
171             return mPhysicalCameraId < other.mPhysicalCameraId;
172         }
173         if (mIsMultiResolution != other.mIsMultiResolution) {
174             return mIsMultiResolution < other.mIsMultiResolution;
175         }
176         if (!sensorPixelModesUsedEqual(other)) {
177             return sensorPixelModesUsedLessThan(other);
178         }
179         if (mDynamicRangeProfile != other.mDynamicRangeProfile) {
180             return mDynamicRangeProfile < other.mDynamicRangeProfile;
181         }
182         if (mColorSpace != other.mColorSpace) {
183             return mColorSpace < other.mColorSpace;
184         }
185         if (mStreamUseCase != other.mStreamUseCase) {
186             return mStreamUseCase < other.mStreamUseCase;
187         }
188         if (mTimestampBase != other.mTimestampBase) {
189             return mTimestampBase < other.mTimestampBase;
190         }
191         if (mMirrorMode != other.mMirrorMode) {
192             return mMirrorMode < other.mMirrorMode;
193         }
194         if (!mirrorModesEqual(other)) {
195             return mirrorModesLessThan(other);
196         }
197         if (mUseReadoutTimestamp != other.mUseReadoutTimestamp) {
198             return mUseReadoutTimestamp < other.mUseReadoutTimestamp;
199         }
200         if (mFormat != other.mFormat) {
201             return mFormat < other.mFormat;
202         }
203         if (mDataspace != other.mDataspace) {
204             return mDataspace < other.mDataspace;
205         }
206         if (mUsage != other.mUsage) {
207             return mUsage < other.mUsage;
208         }
209         return surfacesLessThan(other);
210     }
211 
212     bool operator > (const OutputConfiguration& other) const {
213         return (*this != other && !(*this < other));
214     }
215 
216     bool surfacesEqual(const OutputConfiguration& other) const;
217     bool sensorPixelModesUsedEqual(const OutputConfiguration& other) const;
218     bool sensorPixelModesUsedLessThan(const OutputConfiguration& other) const;
219     bool surfacesLessThan(const OutputConfiguration& other) const;
addSurface(ParcelableSurfaceType surface)220     void addSurface(ParcelableSurfaceType surface) { mSurfaces.push_back(surface); }
221 #if not WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
addGraphicProducer(sp<IGraphicBufferProducer> gbp)222     void addGraphicProducer(sp<IGraphicBufferProducer> gbp) {addSurface(gbp);}
223 #endif
224     bool mirrorModesEqual(const OutputConfiguration& other) const;
225     bool mirrorModesLessThan(const OutputConfiguration& other) const;
getMirrorModes()226     const std::vector<int32_t>& getMirrorModes() const {return mMirrorModeForProducers;}
sharedConfigEqual(const OutputConfiguration & other)227     bool sharedConfigEqual(const OutputConfiguration& other) const {
228         return (mRotation == other.mRotation &&
229                 mSurfaceSetID == other.mSurfaceSetID &&
230                 mSurfaceType == other.mSurfaceType &&
231                 mWidth == other.mWidth &&
232                 mHeight == other.mHeight &&
233                 mIsDeferred == other.mIsDeferred &&
234                 mIsShared == other.mIsShared &&
235                 mPhysicalCameraId == other.mPhysicalCameraId &&
236                 mIsMultiResolution == other.mIsMultiResolution &&
237                 sensorPixelModesUsedEqual(other) &&
238                 mDynamicRangeProfile == other.mDynamicRangeProfile &&
239                 mColorSpace == other.mColorSpace &&
240                 mStreamUseCase == other.mStreamUseCase &&
241                 mTimestampBase == other.mTimestampBase &&
242                 mMirrorMode == other.mMirrorMode &&
243                 mUseReadoutTimestamp == other.mUseReadoutTimestamp &&
244                 mFormat == other.mFormat &&
245                 mDataspace == other.mDataspace &&
246                 mUsage == other.mUsage);
247     }
248 
249 private:
250     std::vector<ParcelableSurfaceType>  mSurfaces;
251     int                        mRotation;
252     int                        mSurfaceSetID;
253     int                        mSurfaceType;
254     int                        mWidth;
255     int                        mHeight;
256     bool                       mIsDeferred;
257     bool                       mIsShared;
258     std::string                mPhysicalCameraId;
259     bool                       mIsMultiResolution;
260     std::vector<int32_t>       mSensorPixelModesUsed;
261     int64_t                    mDynamicRangeProfile;
262     int32_t                    mColorSpace;
263     int64_t                    mStreamUseCase;
264     int                        mTimestampBase;
265     int                        mMirrorMode;
266     std::vector<int>           mMirrorModeForProducers; // 1:1 mapped with mGbps
267     bool                       mUseReadoutTimestamp;
268     int                        mFormat;
269     int                        mDataspace;
270     int64_t                    mUsage;
271 };
272 } // namespace params
273 } // namespace camera2
274 } // namespace hardware
275 
276 
277 using hardware::camera2::params::OutputConfiguration;
278 
279 }; // namespace android
280 
281 #endif
282