blob: 0982bbabbe27cd834418e2440f28a4fe85e082e6 [file] [log] [blame]
Yin-Chia Yehb97babb2015-03-12 13:42:44 -07001/*
2**
Shuzhen Wangc28189a2017-11-27 23:05:10 -08003** Copyright 2015-2018, The Android Open Source Project
Yin-Chia Yehb97babb2015-03-12 13:42:44 -07004**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "OutputConfiguration"
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080019//#define LOG_NDEBUG 0
20
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070021#include <utils/Log.h>
22
23#include <camera/camera2/OutputConfiguration.h>
24#include <binder/Parcel.h>
Mathias Agopian032845c2017-02-08 17:05:02 -080025#include <gui/view/Surface.h>
Emilian Peev2295df72021-11-12 18:14:10 -080026#include <system/camera_metadata.h>
Brian Andersonf6753562016-10-11 14:51:05 -070027#include <utils/String8.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070028
29namespace android {
30
31
32const int OutputConfiguration::INVALID_ROTATION = -1;
Zhijun He018107a2016-01-18 15:32:50 -080033const int OutputConfiguration::INVALID_SET_ID = -1;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070034
Shuzhen Wang0129d522016-10-30 22:43:41 -070035const std::vector<sp<IGraphicBufferProducer>>&
36 OutputConfiguration::getGraphicBufferProducers() const {
37 return mGbps;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070038}
39
40int OutputConfiguration::getRotation() const {
41 return mRotation;
42}
43
Zhijun He018107a2016-01-18 15:32:50 -080044int OutputConfiguration::getSurfaceSetID() const {
45 return mSurfaceSetID;
46}
47
Zhijun He5d677d12016-05-29 16:52:39 -070048int OutputConfiguration::getSurfaceType() const {
49 return mSurfaceType;
50}
51
52int OutputConfiguration::getWidth() const {
53 return mWidth;
54}
55
56int OutputConfiguration::getHeight() const {
57 return mHeight;
58}
59
Shuzhen Wang758c2152017-01-10 18:26:18 -080060bool OutputConfiguration::isDeferred() const {
61 return mIsDeferred;
62}
63
64bool OutputConfiguration::isShared() const {
65 return mIsShared;
66}
67
Shuzhen Wangc28189a2017-11-27 23:05:10 -080068String16 OutputConfiguration::getPhysicalCameraId() const {
69 return mPhysicalCameraId;
70}
71
Shuzhen Wang83bff122020-11-20 15:51:39 -080072bool OutputConfiguration::isMultiResolution() const {
73 return mIsMultiResolution;
74}
75
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080076const std::vector<int32_t> &OutputConfiguration::getSensorPixelModesUsed() const {
77 return mSensorPixelModesUsed;
78}
79
Emilian Peev2295df72021-11-12 18:14:10 -080080int OutputConfiguration::getDynamicRangeProfile() const {
81 return mDynamicRangeProfile;
82}
83
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080084int OutputConfiguration::getStreamUseCase() const {
85 return mStreamUseCase;
86}
87
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080088OutputConfiguration::OutputConfiguration() :
89 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070090 mSurfaceSetID(INVALID_SET_ID),
91 mSurfaceType(SURFACE_TYPE_UNKNOWN),
92 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -080093 mHeight(0),
94 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -080095 mIsShared(false),
Emilian Peev2295df72021-11-12 18:14:10 -080096 mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080097 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
98 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080099}
100
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800101OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800102 mRotation(INVALID_ROTATION),
103 mSurfaceSetID(INVALID_SET_ID) {
104 readFromParcel(&parcel);
105}
106
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800107status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800108 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700109 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800110
111 if (parcel == nullptr) return BAD_VALUE;
112
113 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700114 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800115 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700116 }
117
Zhijun He018107a2016-01-18 15:32:50 -0800118 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800119 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800120 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800121 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800122 }
123
Zhijun He5d677d12016-05-29 16:52:39 -0700124 int surfaceType = SURFACE_TYPE_UNKNOWN;
125 if ((err = parcel->readInt32(&surfaceType)) != OK) {
126 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
127 return err;
128 }
129
130 int width = 0;
131 if ((err = parcel->readInt32(&width)) != OK) {
132 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
133 return err;
134 }
135
136 int height = 0;
137 if ((err = parcel->readInt32(&height)) != OK) {
138 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
139 return err;
140 }
141
Shuzhen Wang758c2152017-01-10 18:26:18 -0800142 int isDeferred = 0;
143 if ((err = parcel->readInt32(&isDeferred)) != OK) {
144 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700145 return err;
146 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800147
148 int isShared = 0;
149 if ((err = parcel->readInt32(&isShared)) != OK) {
150 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
151 return err;
152 }
153
154 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
155 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
156 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700157 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800158 }
159
Shuzhen Wang758c2152017-01-10 18:26:18 -0800160 std::vector<view::Surface> surfaceShims;
161 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
162 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
163 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700164 }
165
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800166 parcel->readString16(&mPhysicalCameraId);
167
Shuzhen Wang83bff122020-11-20 15:51:39 -0800168 int isMultiResolution = 0;
169 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
170 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
171 return err;
172 }
173
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800174 std::vector<int32_t> sensorPixelModesUsed;
Jayant Chowdhary84df28c2021-05-26 22:32:21 -0700175 if ((err = parcel->readInt32Vector(&sensorPixelModesUsed)) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800176 ALOGE("%s: Failed to read sensor pixel mode(s) from parcel", __FUNCTION__);
177 return err;
178 }
Emilian Peev2295df72021-11-12 18:14:10 -0800179 int dynamicProfile;
180 if ((err = parcel->readInt32(&dynamicProfile)) != OK) {
181 ALOGE("%s: Failed to read surface dynamic range profile flag from parcel", __FUNCTION__);
182 return err;
183 }
184
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800185 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
186 if ((err = parcel->readInt32(&streamUseCase)) != OK) {
187 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
188 return err;
189 }
190
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700191 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800192 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700193 mSurfaceType = surfaceType;
194 mWidth = width;
195 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800196 mIsDeferred = isDeferred != 0;
197 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800198 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800199 mStreamUseCase = streamUseCase;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800200 for (auto& surface : surfaceShims) {
201 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
202 surface.graphicBufferProducer.get(),
203 String8(surface.name).string());
204 mGbps.push_back(surface.graphicBufferProducer);
205 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700206
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800207 mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
Emilian Peev2295df72021-11-12 18:14:10 -0800208 mDynamicRangeProfile = dynamicProfile;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800209
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800210 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800211 " physicalCameraId = %s, isMultiResolution = %d, streamUseCase = %d", __FUNCTION__,
212 mRotation, mSurfaceSetID, mSurfaceType, String8(mPhysicalCameraId).string(),
213 mIsMultiResolution, mStreamUseCase);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800214
215 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700216}
217
Zhijun He018107a2016-01-18 15:32:50 -0800218OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800219 const String16& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100220 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700221 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700222 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800223 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800224 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100225 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800226 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800227 mIsMultiResolution = false;
Emilian Peev2295df72021-11-12 18:14:10 -0800228 mDynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800229 mStreamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700230}
231
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700232OutputConfiguration::OutputConfiguration(
233 const std::vector<sp<IGraphicBufferProducer>>& gbps,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800234 int rotation, const String16& physicalCameraId, int surfaceSetID, int surfaceType,
235 int width, int height, bool isShared)
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700236 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800237 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
Emilian Peev2295df72021-11-12 18:14:10 -0800238 mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800239 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
240 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700241
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800242status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700243
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800244 if (parcel == nullptr) return BAD_VALUE;
245 status_t err = OK;
246
247 err = parcel->writeInt32(mRotation);
248 if (err != OK) return err;
249
250 err = parcel->writeInt32(mSurfaceSetID);
251 if (err != OK) return err;
252
Zhijun He5d677d12016-05-29 16:52:39 -0700253 err = parcel->writeInt32(mSurfaceType);
254 if (err != OK) return err;
255
256 err = parcel->writeInt32(mWidth);
257 if (err != OK) return err;
258
259 err = parcel->writeInt32(mHeight);
260 if (err != OK) return err;
261
Shuzhen Wang758c2152017-01-10 18:26:18 -0800262 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800263 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700264
Shuzhen Wang758c2152017-01-10 18:26:18 -0800265 err = parcel->writeInt32(mIsShared ? 1 : 0);
266 if (err != OK) return err;
267
268 std::vector<view::Surface> surfaceShims;
269 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700270 view::Surface surfaceShim;
271 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800272 surfaceShim.graphicBufferProducer = gbp;
273 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700274 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800275 err = parcel->writeParcelableVector(surfaceShims);
276 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700277
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800278 err = parcel->writeString16(mPhysicalCameraId);
279 if (err != OK) return err;
280
Shuzhen Wang83bff122020-11-20 15:51:39 -0800281 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
282 if (err != OK) return err;
283
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800284 err = parcel->writeParcelableVector(mSensorPixelModesUsed);
285 if (err != OK) return err;
286
Emilian Peev2295df72021-11-12 18:14:10 -0800287 err = parcel->writeInt32(mDynamicRangeProfile ? 1 : 0);
288 if (err != OK) return err;
289
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800290 err = parcel->writeInt32(mStreamUseCase);
291 if (err != OK) return err;
292
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700293 return OK;
294}
295
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800296template <typename T>
297static bool simpleVectorsEqual(T first, T second) {
298 if (first.size() != second.size()) {
299 return false;
300 }
301
302 for (size_t i = 0; i < first.size(); i++) {
303 if (first[i] != second[i]) {
304 return false;
305 }
306 }
307 return true;
308}
309
Shuzhen Wang0129d522016-10-30 22:43:41 -0700310bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
311 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
312 other.getGraphicBufferProducers();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800313 return simpleVectorsEqual(otherGbps, mGbps);
314}
Shuzhen Wang0129d522016-10-30 22:43:41 -0700315
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800316bool OutputConfiguration::sensorPixelModesUsedEqual(const OutputConfiguration& other) const {
317 const std::vector<int32_t>& othersensorPixelModesUsed = other.getSensorPixelModesUsed();
318 return simpleVectorsEqual(othersensorPixelModesUsed, mSensorPixelModesUsed);
319}
320
321bool OutputConfiguration::sensorPixelModesUsedLessThan(const OutputConfiguration& other) const {
322 const std::vector<int32_t>& spms = other.getSensorPixelModesUsed();
323
324 if (mSensorPixelModesUsed.size() != spms.size()) {
325 return mSensorPixelModesUsed.size() < spms.size();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700326 }
327
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800328 for (size_t i = 0; i < spms.size(); i++) {
329 if (mSensorPixelModesUsed[i] != spms[i]) {
330 return mSensorPixelModesUsed[i] < spms[i];
Shuzhen Wang0129d522016-10-30 22:43:41 -0700331 }
332 }
333
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800334 return false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700335}
336
337bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
338 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
339 other.getGraphicBufferProducers();
340
341 if (mGbps.size() != otherGbps.size()) {
342 return mGbps.size() < otherGbps.size();
343 }
344
345 for (size_t i = 0; i < mGbps.size(); i++) {
346 if (mGbps[i] != otherGbps[i]) {
347 return mGbps[i] < otherGbps[i];
348 }
349 }
350
351 return false;
352}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700353}; // namespace android