blob: a89d7ca9e55948b6783dbaa6bc24d4384308394b [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>
Austin Borger71d8f672023-06-01 16:51:35 -070024#include <camera/StringUtils.h>
Shuzhen Wang38df0ca2024-10-09 11:33:44 -070025#include <com_android_internal_camera_flags.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070026#include <binder/Parcel.h>
Mathias Agopian032845c2017-02-08 17:05:02 -080027#include <gui/view/Surface.h>
Emilian Peev2295df72021-11-12 18:14:10 -080028#include <system/camera_metadata.h>
Shuzhen Wang0709c282024-02-12 09:09:32 -080029#include <system/graphics.h>
Brian Andersonf6753562016-10-11 14:51:05 -070030#include <utils/String8.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070031
Shuzhen Wang38df0ca2024-10-09 11:33:44 -070032namespace flags = com::android::internal::camera::flags;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070033
Austin Borger9e2b27c2022-07-15 11:27:24 -070034namespace android {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070035
36const int OutputConfiguration::INVALID_ROTATION = -1;
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -070037const int OutputConfiguration::ROTATION_0 = 0;
Zhijun He018107a2016-01-18 15:32:50 -080038const int OutputConfiguration::INVALID_SET_ID = -1;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070039
Shuzhen Wang0129d522016-10-30 22:43:41 -070040const std::vector<sp<IGraphicBufferProducer>>&
41 OutputConfiguration::getGraphicBufferProducers() const {
42 return mGbps;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070043}
44
45int OutputConfiguration::getRotation() const {
46 return mRotation;
47}
48
Zhijun He018107a2016-01-18 15:32:50 -080049int OutputConfiguration::getSurfaceSetID() const {
50 return mSurfaceSetID;
51}
52
Zhijun He5d677d12016-05-29 16:52:39 -070053int OutputConfiguration::getSurfaceType() const {
54 return mSurfaceType;
55}
56
57int OutputConfiguration::getWidth() const {
58 return mWidth;
59}
60
61int OutputConfiguration::getHeight() const {
62 return mHeight;
63}
64
Shuzhen Wang758c2152017-01-10 18:26:18 -080065bool OutputConfiguration::isDeferred() const {
66 return mIsDeferred;
67}
68
69bool OutputConfiguration::isShared() const {
70 return mIsShared;
71}
72
Austin Borger71d8f672023-06-01 16:51:35 -070073std::string OutputConfiguration::getPhysicalCameraId() const {
Shuzhen Wangc28189a2017-11-27 23:05:10 -080074 return mPhysicalCameraId;
75}
76
Shuzhen Wang83bff122020-11-20 15:51:39 -080077bool OutputConfiguration::isMultiResolution() const {
78 return mIsMultiResolution;
79}
80
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080081const std::vector<int32_t> &OutputConfiguration::getSensorPixelModesUsed() const {
82 return mSensorPixelModesUsed;
83}
84
Emilian Peevc81a7592022-02-14 17:38:18 -080085int64_t OutputConfiguration::getDynamicRangeProfile() const {
Emilian Peev2295df72021-11-12 18:14:10 -080086 return mDynamicRangeProfile;
87}
88
Austin Borger9e2b27c2022-07-15 11:27:24 -070089int32_t OutputConfiguration::getColorSpace() const {
90 return mColorSpace;
91}
92
Shuzhen Wang8ed1e872022-03-08 16:34:33 -080093int64_t OutputConfiguration::getStreamUseCase() const {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080094 return mStreamUseCase;
95}
96
Shuzhen Wange4208922022-02-01 16:52:48 -080097int OutputConfiguration::getTimestampBase() const {
98 return mTimestampBase;
99}
100
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700101int OutputConfiguration::getMirrorMode() const {
102 return mMirrorMode;
103}
104
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700105int OutputConfiguration::getMirrorMode(sp<IGraphicBufferProducer> surface) const {
106 if (!flags::mirror_mode_shared_surfaces()) {
107 return mMirrorMode;
108 }
109
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700110 if (mGbps.size() != mMirrorModeForProducers.size()) {
111 ALOGE("%s: mGbps size doesn't match mMirrorModeForProducers: %zu vs %zu",
112 __FUNCTION__, mGbps.size(), mMirrorModeForProducers.size());
113 return mMirrorMode;
114 }
115
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700116 // Use per-producer mirror mode if available.
117 for (size_t i = 0; i < mGbps.size(); i++) {
118 if (mGbps[i] == surface) {
119 return mMirrorModeForProducers[i];
120 }
121 }
122
123 // For surface that doesn't belong to this output configuration, use
124 // mMirrorMode as default.
125 ALOGW("%s: Surface doesn't belong to this OutputConfiguration!", __FUNCTION__);
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800126 return mMirrorMode;
127}
128
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000129bool OutputConfiguration::useReadoutTimestamp() const {
130 return mUseReadoutTimestamp;
131}
132
Shuzhen Wang0709c282024-02-12 09:09:32 -0800133int OutputConfiguration::getFormat() const {
134 return mFormat;
135}
136
137int OutputConfiguration::getDataspace() const {
138 return mDataspace;
139}
140
141int64_t OutputConfiguration::getUsage() const {
142 return mUsage;
143}
144
145bool OutputConfiguration::isComplete() const {
146 return !((mSurfaceType == SURFACE_TYPE_MEDIA_RECORDER ||
147 mSurfaceType == SURFACE_TYPE_MEDIA_CODEC ||
148 mSurfaceType == SURFACE_TYPE_IMAGE_READER) &&
149 mGbps.empty());
150}
151
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800152OutputConfiguration::OutputConfiguration() :
153 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -0700154 mSurfaceSetID(INVALID_SET_ID),
155 mSurfaceType(SURFACE_TYPE_UNKNOWN),
156 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -0800157 mHeight(0),
158 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -0800159 mIsShared(false),
Emilian Peev2295df72021-11-12 18:14:10 -0800160 mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800161 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Austin Borger9e2b27c2022-07-15 11:27:24 -0700162 mColorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED),
Shuzhen Wange4208922022-02-01 16:52:48 -0800163 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800164 mTimestampBase(TIMESTAMP_BASE_DEFAULT),
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000165 mMirrorMode(MIRROR_MODE_AUTO),
Shuzhen Wang0709c282024-02-12 09:09:32 -0800166 mUseReadoutTimestamp(false),
167 mFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
168 mDataspace(0),
169 mUsage(0) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800170}
171
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700172OutputConfiguration::OutputConfiguration(int surfaceType, int width, int height, int format,
173 int32_t colorSpace, int mirrorMode, bool useReadoutTimestamp, int timestampBase,
174 int dataspace, int64_t usage, int64_t streamusecase, std::string physicalCamId):
175 mRotation(ROTATION_0),
176 mSurfaceSetID(INVALID_SET_ID),
177 mSurfaceType(surfaceType),
178 mWidth(width),
179 mHeight(height),
180 mIsDeferred(false),
181 mIsShared(false),
182 mPhysicalCameraId(physicalCamId),
183 mIsMultiResolution(false),
184 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
185 mColorSpace(colorSpace),
186 mStreamUseCase(streamusecase),
187 mTimestampBase(timestampBase),
188 mMirrorMode(mirrorMode),
189 mUseReadoutTimestamp(useReadoutTimestamp),
190 mFormat(format),
191 mDataspace(dataspace),
192 mUsage(usage){
193}
194
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800195OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800196 mRotation(INVALID_ROTATION),
197 mSurfaceSetID(INVALID_SET_ID) {
198 readFromParcel(&parcel);
199}
200
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800201status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800202 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700203 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800204
205 if (parcel == nullptr) return BAD_VALUE;
206
207 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700208 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800209 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700210 }
211
Zhijun He018107a2016-01-18 15:32:50 -0800212 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800213 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800214 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800215 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800216 }
217
Zhijun He5d677d12016-05-29 16:52:39 -0700218 int surfaceType = SURFACE_TYPE_UNKNOWN;
219 if ((err = parcel->readInt32(&surfaceType)) != OK) {
220 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
221 return err;
222 }
223
224 int width = 0;
225 if ((err = parcel->readInt32(&width)) != OK) {
226 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
227 return err;
228 }
229
230 int height = 0;
231 if ((err = parcel->readInt32(&height)) != OK) {
232 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
233 return err;
234 }
235
Shuzhen Wang758c2152017-01-10 18:26:18 -0800236 int isDeferred = 0;
237 if ((err = parcel->readInt32(&isDeferred)) != OK) {
238 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700239 return err;
240 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800241
242 int isShared = 0;
243 if ((err = parcel->readInt32(&isShared)) != OK) {
244 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
245 return err;
246 }
247
248 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
249 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
250 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700251 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800252 }
253
Shuzhen Wang758c2152017-01-10 18:26:18 -0800254 std::vector<view::Surface> surfaceShims;
255 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
256 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
257 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700258 }
259
Austin Borger71d8f672023-06-01 16:51:35 -0700260 String16 physicalCameraId;
261 parcel->readString16(&physicalCameraId);
262 mPhysicalCameraId = toStdString(physicalCameraId);
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800263
Shuzhen Wang83bff122020-11-20 15:51:39 -0800264 int isMultiResolution = 0;
265 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
266 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
267 return err;
268 }
269
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800270 std::vector<int32_t> sensorPixelModesUsed;
Jayant Chowdhary84df28c2021-05-26 22:32:21 -0700271 if ((err = parcel->readInt32Vector(&sensorPixelModesUsed)) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800272 ALOGE("%s: Failed to read sensor pixel mode(s) from parcel", __FUNCTION__);
273 return err;
274 }
Emilian Peevc81a7592022-02-14 17:38:18 -0800275 int64_t dynamicProfile;
276 if ((err = parcel->readInt64(&dynamicProfile)) != OK) {
Emilian Peev2295df72021-11-12 18:14:10 -0800277 ALOGE("%s: Failed to read surface dynamic range profile flag from parcel", __FUNCTION__);
278 return err;
279 }
Austin Borger9e2b27c2022-07-15 11:27:24 -0700280 int32_t colorSpace;
281 if ((err = parcel->readInt32(&colorSpace)) != OK) {
282 ALOGE("%s: Failed to read surface color space flag from parcel", __FUNCTION__);
283 return err;
284 }
Emilian Peev2295df72021-11-12 18:14:10 -0800285
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800286 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
287 if ((err = parcel->readInt64(&streamUseCase)) != OK) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800288 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
289 return err;
290 }
291
Shuzhen Wange4208922022-02-01 16:52:48 -0800292 int timestampBase = TIMESTAMP_BASE_DEFAULT;
293 if ((err = parcel->readInt32(&timestampBase)) != OK) {
294 ALOGE("%s: Failed to read timestamp base from parcel", __FUNCTION__);
295 return err;
296 }
297
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800298 int mirrorMode = MIRROR_MODE_AUTO;
299 if ((err = parcel->readInt32(&mirrorMode)) != OK) {
300 ALOGE("%s: Failed to read mirroring mode from parcel", __FUNCTION__);
301 return err;
302 }
303
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700304 std::vector<int> mirrorModeForProducers;
305 if ((err = parcel->readInt32Vector(&mirrorModeForProducers)) != OK) {
306 ALOGE("%s: Failed to read mirroring mode for surfaces from parcel", __FUNCTION__);
307 return err;
308 }
309
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000310 int useReadoutTimestamp = 0;
311 if ((err = parcel->readInt32(&useReadoutTimestamp)) != OK) {
312 ALOGE("%s: Failed to read useReadoutTimestamp flag from parcel", __FUNCTION__);
313 return err;
314 }
315
Shuzhen Wang0709c282024-02-12 09:09:32 -0800316 int format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
317 if ((err = parcel->readInt32(&format)) != OK) {
318 ALOGE("%s: Failed to read format from parcel", __FUNCTION__);
319 return err;
320 }
321
322 int dataspace = 0;
323 if ((err = parcel->readInt32(&dataspace)) != OK) {
324 ALOGE("%s: Failed to read dataspace from parcel", __FUNCTION__);
325 return err;
326 }
327
328 int64_t usage = 0;
329 if ((err = parcel->readInt64(&usage)) != OK) {
330 ALOGE("%s: Failed to read usage flag from parcel", __FUNCTION__);
331 return err;
332 }
333
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700334 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800335 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700336 mSurfaceType = surfaceType;
337 mWidth = width;
338 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800339 mIsDeferred = isDeferred != 0;
340 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800341 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800342 mStreamUseCase = streamUseCase;
Shuzhen Wange4208922022-02-01 16:52:48 -0800343 mTimestampBase = timestampBase;
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800344 mMirrorMode = mirrorMode;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700345 mMirrorModeForProducers = std::move(mirrorModeForProducers);
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000346 mUseReadoutTimestamp = useReadoutTimestamp != 0;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800347 for (auto& surface : surfaceShims) {
348 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
349 surface.graphicBufferProducer.get(),
Tomasz Wasilczyk12b04a52023-08-11 15:52:22 +0000350 toString8(surface.name).c_str());
Shuzhen Wang758c2152017-01-10 18:26:18 -0800351 mGbps.push_back(surface.graphicBufferProducer);
352 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700353
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800354 mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
Emilian Peev2295df72021-11-12 18:14:10 -0800355 mDynamicRangeProfile = dynamicProfile;
Austin Borger9e2b27c2022-07-15 11:27:24 -0700356 mColorSpace = colorSpace;
Shuzhen Wang0709c282024-02-12 09:09:32 -0800357 mFormat = format;
358 mDataspace = dataspace;
359 mUsage = usage;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800360
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800361 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800362 " physicalCameraId = %s, isMultiResolution = %d, streamUseCase = %" PRId64
Shuzhen Wang0709c282024-02-12 09:09:32 -0800363 ", timestampBase = %d, mirrorMode = %d, useReadoutTimestamp = %d, format = %d, "
364 "dataspace = %d, usage = %" PRId64,
Shuzhen Wange4208922022-02-01 16:52:48 -0800365 __FUNCTION__, mRotation, mSurfaceSetID, mSurfaceType,
Austin Borger71d8f672023-06-01 16:51:35 -0700366 mPhysicalCameraId.c_str(), mIsMultiResolution, mStreamUseCase, timestampBase,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800367 mMirrorMode, mUseReadoutTimestamp, mFormat, mDataspace, mUsage);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800368
369 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700370}
371
Zhijun He018107a2016-01-18 15:32:50 -0800372OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Austin Borger71d8f672023-06-01 16:51:35 -0700373 const std::string& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100374 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700375 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700376 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800377 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800378 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100379 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800380 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800381 mIsMultiResolution = false;
Emilian Peev2295df72021-11-12 18:14:10 -0800382 mDynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
Austin Borger9e2b27c2022-07-15 11:27:24 -0700383 mColorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800384 mStreamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
Shuzhen Wange4208922022-02-01 16:52:48 -0800385 mTimestampBase = TIMESTAMP_BASE_DEFAULT;
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800386 mMirrorMode = MIRROR_MODE_AUTO;
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700387 mMirrorModeForProducers.push_back(mMirrorMode);
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000388 mUseReadoutTimestamp = false;
Shuzhen Wang0709c282024-02-12 09:09:32 -0800389 mFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
390 mDataspace = 0;
391 mUsage = 0;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700392}
393
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700394OutputConfiguration::OutputConfiguration(
395 const std::vector<sp<IGraphicBufferProducer>>& gbps,
Austin Borger71d8f672023-06-01 16:51:35 -0700396 int rotation, const std::string& physicalCameraId, int surfaceSetID, int surfaceType,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800397 int width, int height, bool isShared)
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700398 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800399 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
Emilian Peev2295df72021-11-12 18:14:10 -0800400 mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800401 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Austin Borger9e2b27c2022-07-15 11:27:24 -0700402 mColorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED),
Shuzhen Wange4208922022-02-01 16:52:48 -0800403 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800404 mTimestampBase(TIMESTAMP_BASE_DEFAULT),
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700405 mMirrorMode(MIRROR_MODE_AUTO), mMirrorModeForProducers(gbps.size(), mMirrorMode),
406 mUseReadoutTimestamp(false), mFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
407 mDataspace(0), mUsage(0) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700408
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800409status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700410
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800411 if (parcel == nullptr) return BAD_VALUE;
412 status_t err = OK;
413
414 err = parcel->writeInt32(mRotation);
415 if (err != OK) return err;
416
417 err = parcel->writeInt32(mSurfaceSetID);
418 if (err != OK) return err;
419
Zhijun He5d677d12016-05-29 16:52:39 -0700420 err = parcel->writeInt32(mSurfaceType);
421 if (err != OK) return err;
422
423 err = parcel->writeInt32(mWidth);
424 if (err != OK) return err;
425
426 err = parcel->writeInt32(mHeight);
427 if (err != OK) return err;
428
Shuzhen Wang758c2152017-01-10 18:26:18 -0800429 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800430 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700431
Shuzhen Wang758c2152017-01-10 18:26:18 -0800432 err = parcel->writeInt32(mIsShared ? 1 : 0);
433 if (err != OK) return err;
434
435 std::vector<view::Surface> surfaceShims;
436 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700437 view::Surface surfaceShim;
438 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800439 surfaceShim.graphicBufferProducer = gbp;
440 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700441 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800442 err = parcel->writeParcelableVector(surfaceShims);
443 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700444
Austin Borger71d8f672023-06-01 16:51:35 -0700445 String16 physicalCameraId = toString16(mPhysicalCameraId);
446 err = parcel->writeString16(physicalCameraId);
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800447 if (err != OK) return err;
448
Shuzhen Wang83bff122020-11-20 15:51:39 -0800449 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
450 if (err != OK) return err;
451
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800452 err = parcel->writeParcelableVector(mSensorPixelModesUsed);
453 if (err != OK) return err;
454
Emilian Peevc81a7592022-02-14 17:38:18 -0800455 err = parcel->writeInt64(mDynamicRangeProfile);
Emilian Peev2295df72021-11-12 18:14:10 -0800456 if (err != OK) return err;
457
Austin Borger9e2b27c2022-07-15 11:27:24 -0700458 err = parcel->writeInt32(mColorSpace);
459 if (err != OK) return err;
460
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800461 err = parcel->writeInt64(mStreamUseCase);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800462 if (err != OK) return err;
463
Shuzhen Wange4208922022-02-01 16:52:48 -0800464 err = parcel->writeInt32(mTimestampBase);
465 if (err != OK) return err;
466
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800467 err = parcel->writeInt32(mMirrorMode);
468 if (err != OK) return err;
469
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700470 err = parcel->writeInt32Vector(mMirrorModeForProducers);
471 if (err != OK) return err;
472
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000473 err = parcel->writeInt32(mUseReadoutTimestamp ? 1 : 0);
474 if (err != OK) return err;
475
Shuzhen Wang0709c282024-02-12 09:09:32 -0800476 err = parcel->writeInt32(mFormat);
477 if (err != OK) return err;
478
479 err = parcel->writeInt32(mDataspace);
480 if (err != OK) return err;
481
482 err = parcel->writeInt64(mUsage);
483 if (err != OK) return err;
484
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700485 return OK;
486}
487
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800488template <typename T>
489static bool simpleVectorsEqual(T first, T second) {
490 if (first.size() != second.size()) {
491 return false;
492 }
493
494 for (size_t i = 0; i < first.size(); i++) {
495 if (first[i] != second[i]) {
496 return false;
497 }
498 }
499 return true;
500}
501
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700502template <typename T>
503static bool simpleVectorsLessThan(T first, T second) {
504 if (first.size() != second.size()) {
505 return first.size() < second.size();
506 }
507
508 for (size_t i = 0; i < first.size(); i++) {
509 if (first[i] != second[i]) {
510 return first[i] < second[i];
511 }
512 }
513 return false;
514}
515
Shuzhen Wang0129d522016-10-30 22:43:41 -0700516bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
517 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
518 other.getGraphicBufferProducers();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800519 return simpleVectorsEqual(otherGbps, mGbps);
520}
Shuzhen Wang0129d522016-10-30 22:43:41 -0700521
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800522bool OutputConfiguration::sensorPixelModesUsedEqual(const OutputConfiguration& other) const {
523 const std::vector<int32_t>& othersensorPixelModesUsed = other.getSensorPixelModesUsed();
524 return simpleVectorsEqual(othersensorPixelModesUsed, mSensorPixelModesUsed);
525}
526
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700527bool OutputConfiguration::mirrorModesEqual(const OutputConfiguration& other) const {
528 const std::vector<int>& otherMirrorModes = other.getMirrorModes();
529 return simpleVectorsEqual(otherMirrorModes, mMirrorModeForProducers);
530
531}
532
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800533bool OutputConfiguration::sensorPixelModesUsedLessThan(const OutputConfiguration& other) const {
534 const std::vector<int32_t>& spms = other.getSensorPixelModesUsed();
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700535 return simpleVectorsLessThan(mSensorPixelModesUsed, spms);
536}
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800537
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700538bool OutputConfiguration::mirrorModesLessThan(const OutputConfiguration& other) const {
539 const std::vector<int>& otherMirrorModes = other.getMirrorModes();
540 return simpleVectorsLessThan(mMirrorModeForProducers, otherMirrorModes);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700541}
542
543bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
544 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
545 other.getGraphicBufferProducers();
546
547 if (mGbps.size() != otherGbps.size()) {
548 return mGbps.size() < otherGbps.size();
549 }
550
551 for (size_t i = 0; i < mGbps.size(); i++) {
552 if (mGbps[i] != otherGbps[i]) {
553 return mGbps[i] < otherGbps[i];
554 }
555 }
556
557 return false;
558}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700559}; // namespace android