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