blob: f67214b9cd34df520448e68a49008137df513258 [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
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -070040const std::vector<ParcelableSurfaceType>& OutputConfiguration::getSurfaces() const {
41 return mSurfaces;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070042}
43
44int OutputConfiguration::getRotation() const {
45 return mRotation;
46}
47
Zhijun He018107a2016-01-18 15:32:50 -080048int OutputConfiguration::getSurfaceSetID() const {
49 return mSurfaceSetID;
50}
51
Zhijun He5d677d12016-05-29 16:52:39 -070052int OutputConfiguration::getSurfaceType() const {
53 return mSurfaceType;
54}
55
56int OutputConfiguration::getWidth() const {
57 return mWidth;
58}
59
60int OutputConfiguration::getHeight() const {
61 return mHeight;
62}
63
Shuzhen Wang758c2152017-01-10 18:26:18 -080064bool OutputConfiguration::isDeferred() const {
65 return mIsDeferred;
66}
67
68bool OutputConfiguration::isShared() const {
69 return mIsShared;
70}
71
Austin Borger71d8f672023-06-01 16:51:35 -070072std::string OutputConfiguration::getPhysicalCameraId() const {
Shuzhen Wangc28189a2017-11-27 23:05:10 -080073 return mPhysicalCameraId;
74}
75
Shuzhen Wang83bff122020-11-20 15:51:39 -080076bool OutputConfiguration::isMultiResolution() const {
77 return mIsMultiResolution;
78}
79
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080080const std::vector<int32_t> &OutputConfiguration::getSensorPixelModesUsed() const {
81 return mSensorPixelModesUsed;
82}
83
Emilian Peevc81a7592022-02-14 17:38:18 -080084int64_t OutputConfiguration::getDynamicRangeProfile() const {
Emilian Peev2295df72021-11-12 18:14:10 -080085 return mDynamicRangeProfile;
86}
87
Austin Borger9e2b27c2022-07-15 11:27:24 -070088int32_t OutputConfiguration::getColorSpace() const {
89 return mColorSpace;
90}
91
Shuzhen Wang8ed1e872022-03-08 16:34:33 -080092int64_t OutputConfiguration::getStreamUseCase() const {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -080093 return mStreamUseCase;
94}
95
Shuzhen Wange4208922022-02-01 16:52:48 -080096int OutputConfiguration::getTimestampBase() const {
97 return mTimestampBase;
98}
99
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700100int OutputConfiguration::getMirrorMode() const {
101 return mMirrorMode;
102}
103
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700104int OutputConfiguration::getMirrorMode(ParcelableSurfaceType surface) const {
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700105 if (!flags::mirror_mode_shared_surfaces()) {
106 return mMirrorMode;
107 }
108
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700109 if (mSurfaces.size() != mMirrorModeForProducers.size()) {
110 ALOGE("%s: mSurfaces size doesn't match mMirrorModeForProducers: %zu vs %zu",
111 __FUNCTION__, mSurfaces.size(), mMirrorModeForProducers.size());
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700112 return mMirrorMode;
113 }
114
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700115 // Use per-producer mirror mode if available.
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700116 for (size_t i = 0; i < mSurfaces.size(); i++) {
117 if (mSurfaces[i] == surface) {
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700118 return mMirrorModeForProducers[i];
119 }
120 }
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700121 // For surface that doesn't belong to this output configuration, use
122 // mMirrorMode as default.
123 ALOGW("%s: Surface doesn't belong to this OutputConfiguration!", __FUNCTION__);
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800124 return mMirrorMode;
125}
126
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000127bool OutputConfiguration::useReadoutTimestamp() const {
128 return mUseReadoutTimestamp;
129}
130
Shuzhen Wang0709c282024-02-12 09:09:32 -0800131int OutputConfiguration::getFormat() const {
132 return mFormat;
133}
134
135int OutputConfiguration::getDataspace() const {
136 return mDataspace;
137}
138
139int64_t OutputConfiguration::getUsage() const {
140 return mUsage;
141}
142
143bool OutputConfiguration::isComplete() const {
144 return !((mSurfaceType == SURFACE_TYPE_MEDIA_RECORDER ||
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700145 mSurfaceType == SURFACE_TYPE_MEDIA_CODEC ||
146 mSurfaceType == SURFACE_TYPE_IMAGE_READER) &&
147 mSurfaces.empty());
Shuzhen Wang0709c282024-02-12 09:09:32 -0800148}
149
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800150OutputConfiguration::OutputConfiguration() :
151 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -0700152 mSurfaceSetID(INVALID_SET_ID),
153 mSurfaceType(SURFACE_TYPE_UNKNOWN),
154 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -0800155 mHeight(0),
156 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -0800157 mIsShared(false),
Emilian Peev2295df72021-11-12 18:14:10 -0800158 mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800159 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Austin Borger9e2b27c2022-07-15 11:27:24 -0700160 mColorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED),
Shuzhen Wange4208922022-02-01 16:52:48 -0800161 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800162 mTimestampBase(TIMESTAMP_BASE_DEFAULT),
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000163 mMirrorMode(MIRROR_MODE_AUTO),
Shuzhen Wang0709c282024-02-12 09:09:32 -0800164 mUseReadoutTimestamp(false),
165 mFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
166 mDataspace(0),
167 mUsage(0) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800168}
169
Jyoti Bhayana1f9600b2024-10-29 20:25:32 -0700170OutputConfiguration::OutputConfiguration(int surfaceType, int width, int height, int format,
171 int32_t colorSpace, int mirrorMode, bool useReadoutTimestamp, int timestampBase,
172 int dataspace, int64_t usage, int64_t streamusecase, std::string physicalCamId):
173 mRotation(ROTATION_0),
174 mSurfaceSetID(INVALID_SET_ID),
175 mSurfaceType(surfaceType),
176 mWidth(width),
177 mHeight(height),
178 mIsDeferred(false),
179 mIsShared(false),
180 mPhysicalCameraId(physicalCamId),
181 mIsMultiResolution(false),
182 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
183 mColorSpace(colorSpace),
184 mStreamUseCase(streamusecase),
185 mTimestampBase(timestampBase),
186 mMirrorMode(mirrorMode),
187 mUseReadoutTimestamp(useReadoutTimestamp),
188 mFormat(format),
189 mDataspace(dataspace),
190 mUsage(usage){
191}
192
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800193OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800194 mRotation(INVALID_ROTATION),
195 mSurfaceSetID(INVALID_SET_ID) {
196 readFromParcel(&parcel);
197}
198
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800199status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800200 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700201 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800202
203 if (parcel == nullptr) return BAD_VALUE;
204
205 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700206 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800207 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700208 }
209
Zhijun He018107a2016-01-18 15:32:50 -0800210 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800211 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800212 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800213 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800214 }
215
Zhijun He5d677d12016-05-29 16:52:39 -0700216 int surfaceType = SURFACE_TYPE_UNKNOWN;
217 if ((err = parcel->readInt32(&surfaceType)) != OK) {
218 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
219 return err;
220 }
221
222 int width = 0;
223 if ((err = parcel->readInt32(&width)) != OK) {
224 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
225 return err;
226 }
227
228 int height = 0;
229 if ((err = parcel->readInt32(&height)) != OK) {
230 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
231 return err;
232 }
233
Shuzhen Wang758c2152017-01-10 18:26:18 -0800234 int isDeferred = 0;
235 if ((err = parcel->readInt32(&isDeferred)) != OK) {
236 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700237 return err;
238 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800239
240 int isShared = 0;
241 if ((err = parcel->readInt32(&isShared)) != OK) {
242 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
243 return err;
244 }
245
246 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
247 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
248 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700249 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800250 }
251
Shuzhen Wang758c2152017-01-10 18:26:18 -0800252 std::vector<view::Surface> surfaceShims;
253 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
254 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
255 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700256 }
257
Austin Borger71d8f672023-06-01 16:51:35 -0700258 String16 physicalCameraId;
259 parcel->readString16(&physicalCameraId);
260 mPhysicalCameraId = toStdString(physicalCameraId);
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800261
Shuzhen Wang83bff122020-11-20 15:51:39 -0800262 int isMultiResolution = 0;
263 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
264 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
265 return err;
266 }
267
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800268 std::vector<int32_t> sensorPixelModesUsed;
Jayant Chowdhary84df28c2021-05-26 22:32:21 -0700269 if ((err = parcel->readInt32Vector(&sensorPixelModesUsed)) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800270 ALOGE("%s: Failed to read sensor pixel mode(s) from parcel", __FUNCTION__);
271 return err;
272 }
Emilian Peevc81a7592022-02-14 17:38:18 -0800273 int64_t dynamicProfile;
274 if ((err = parcel->readInt64(&dynamicProfile)) != OK) {
Emilian Peev2295df72021-11-12 18:14:10 -0800275 ALOGE("%s: Failed to read surface dynamic range profile flag from parcel", __FUNCTION__);
276 return err;
277 }
Austin Borger9e2b27c2022-07-15 11:27:24 -0700278 int32_t colorSpace;
279 if ((err = parcel->readInt32(&colorSpace)) != OK) {
280 ALOGE("%s: Failed to read surface color space flag from parcel", __FUNCTION__);
281 return err;
282 }
Emilian Peev2295df72021-11-12 18:14:10 -0800283
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800284 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
285 if ((err = parcel->readInt64(&streamUseCase)) != OK) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800286 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
287 return err;
288 }
289
Shuzhen Wange4208922022-02-01 16:52:48 -0800290 int timestampBase = TIMESTAMP_BASE_DEFAULT;
291 if ((err = parcel->readInt32(&timestampBase)) != OK) {
292 ALOGE("%s: Failed to read timestamp base from parcel", __FUNCTION__);
293 return err;
294 }
295
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800296 int mirrorMode = MIRROR_MODE_AUTO;
297 if ((err = parcel->readInt32(&mirrorMode)) != OK) {
298 ALOGE("%s: Failed to read mirroring mode from parcel", __FUNCTION__);
299 return err;
300 }
301
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700302 std::vector<int> mirrorModeForProducers;
303 if ((err = parcel->readInt32Vector(&mirrorModeForProducers)) != OK) {
304 ALOGE("%s: Failed to read mirroring mode for surfaces from parcel", __FUNCTION__);
305 return err;
306 }
307
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000308 int useReadoutTimestamp = 0;
309 if ((err = parcel->readInt32(&useReadoutTimestamp)) != OK) {
310 ALOGE("%s: Failed to read useReadoutTimestamp flag from parcel", __FUNCTION__);
311 return err;
312 }
313
Shuzhen Wang0709c282024-02-12 09:09:32 -0800314 int format = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
315 if ((err = parcel->readInt32(&format)) != OK) {
316 ALOGE("%s: Failed to read format from parcel", __FUNCTION__);
317 return err;
318 }
319
320 int dataspace = 0;
321 if ((err = parcel->readInt32(&dataspace)) != OK) {
322 ALOGE("%s: Failed to read dataspace from parcel", __FUNCTION__);
323 return err;
324 }
325
326 int64_t usage = 0;
327 if ((err = parcel->readInt64(&usage)) != OK) {
328 ALOGE("%s: Failed to read usage flag from parcel", __FUNCTION__);
329 return err;
330 }
331
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700332 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800333 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700334 mSurfaceType = surfaceType;
335 mWidth = width;
336 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800337 mIsDeferred = isDeferred != 0;
338 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800339 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800340 mStreamUseCase = streamUseCase;
Shuzhen Wange4208922022-02-01 16:52:48 -0800341 mTimestampBase = timestampBase;
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800342 mMirrorMode = mirrorMode;
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700343 mMirrorModeForProducers = std::move(mirrorModeForProducers);
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000344 mUseReadoutTimestamp = useReadoutTimestamp != 0;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800345 for (auto& surface : surfaceShims) {
346 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
347 surface.graphicBufferProducer.get(),
Tomasz Wasilczyk12b04a52023-08-11 15:52:22 +0000348 toString8(surface.name).c_str());
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700349 mSurfaces.push_back(flagtools::toParcelableSurfaceType(surface));
Shuzhen Wang758c2152017-01-10 18:26:18 -0800350 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700351
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800352 mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
Emilian Peev2295df72021-11-12 18:14:10 -0800353 mDynamicRangeProfile = dynamicProfile;
Austin Borger9e2b27c2022-07-15 11:27:24 -0700354 mColorSpace = colorSpace;
Shuzhen Wang0709c282024-02-12 09:09:32 -0800355 mFormat = format;
356 mDataspace = dataspace;
357 mUsage = usage;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800358
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800359 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800360 " physicalCameraId = %s, isMultiResolution = %d, streamUseCase = %" PRId64
Shuzhen Wang0709c282024-02-12 09:09:32 -0800361 ", timestampBase = %d, mirrorMode = %d, useReadoutTimestamp = %d, format = %d, "
362 "dataspace = %d, usage = %" PRId64,
Shuzhen Wange4208922022-02-01 16:52:48 -0800363 __FUNCTION__, mRotation, mSurfaceSetID, mSurfaceType,
Austin Borger71d8f672023-06-01 16:51:35 -0700364 mPhysicalCameraId.c_str(), mIsMultiResolution, mStreamUseCase, timestampBase,
Shuzhen Wang0709c282024-02-12 09:09:32 -0800365 mMirrorMode, mUseReadoutTimestamp, mFormat, mDataspace, mUsage);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800366
367 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700368}
369
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700370OutputConfiguration::OutputConfiguration(ParcelableSurfaceType& surface, int rotation,
Austin Borger71d8f672023-06-01 16:51:35 -0700371 const std::string& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100372 int surfaceSetID, bool isShared) {
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700373 mSurfaces.push_back(surface);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700374 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800375 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800376 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100377 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800378 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800379 mIsMultiResolution = false;
Emilian Peev2295df72021-11-12 18:14:10 -0800380 mDynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
Austin Borger9e2b27c2022-07-15 11:27:24 -0700381 mColorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800382 mStreamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
Shuzhen Wange4208922022-02-01 16:52:48 -0800383 mTimestampBase = TIMESTAMP_BASE_DEFAULT;
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800384 mMirrorMode = MIRROR_MODE_AUTO;
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700385 mMirrorModeForProducers.push_back(mMirrorMode);
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000386 mUseReadoutTimestamp = false;
Shuzhen Wang0709c282024-02-12 09:09:32 -0800387 mFormat = HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED;
388 mDataspace = 0;
389 mUsage = 0;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700390}
391
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700392OutputConfiguration::OutputConfiguration(
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700393 const std::vector<ParcelableSurfaceType>& surfaces,
Austin Borger71d8f672023-06-01 16:51:35 -0700394 int rotation, const std::string& physicalCameraId, int surfaceSetID, int surfaceType,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800395 int width, int height, bool isShared)
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700396 : mSurfaces(surfaces), mRotation(rotation), mSurfaceSetID(surfaceSetID),
397 mSurfaceType(surfaceType), mWidth(width), mHeight(height), mIsDeferred(false),
398 mIsShared(isShared), mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800399 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Austin Borger9e2b27c2022-07-15 11:27:24 -0700400 mColorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED),
Shuzhen Wange4208922022-02-01 16:52:48 -0800401 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800402 mTimestampBase(TIMESTAMP_BASE_DEFAULT),
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700403 mMirrorMode(MIRROR_MODE_AUTO), mMirrorModeForProducers(surfaces.size(), mMirrorMode),
Shuzhen Wangb91d0c22024-10-29 09:58:55 -0700404 mUseReadoutTimestamp(false), mFormat(HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED),
405 mDataspace(0), mUsage(0) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700406
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800407status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700408
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800409 if (parcel == nullptr) return BAD_VALUE;
410 status_t err = OK;
411
412 err = parcel->writeInt32(mRotation);
413 if (err != OK) return err;
414
415 err = parcel->writeInt32(mSurfaceSetID);
416 if (err != OK) return err;
417
Zhijun He5d677d12016-05-29 16:52:39 -0700418 err = parcel->writeInt32(mSurfaceType);
419 if (err != OK) return err;
420
421 err = parcel->writeInt32(mWidth);
422 if (err != OK) return err;
423
424 err = parcel->writeInt32(mHeight);
425 if (err != OK) return err;
426
Shuzhen Wang758c2152017-01-10 18:26:18 -0800427 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800428 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700429
Shuzhen Wang758c2152017-01-10 18:26:18 -0800430 err = parcel->writeInt32(mIsShared ? 1 : 0);
431 if (err != OK) return err;
432
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700433#if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES
434 err = parcel->writeParcelableVector(mSurfaces);
435#else
Shuzhen Wang758c2152017-01-10 18:26:18 -0800436 std::vector<view::Surface> surfaceShims;
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700437 for (auto& gbp : mSurfaces) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700438 view::Surface surfaceShim;
439 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800440 surfaceShim.graphicBufferProducer = gbp;
441 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700442 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800443 err = parcel->writeParcelableVector(surfaceShims);
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700444#endif
Shuzhen Wang758c2152017-01-10 18:26:18 -0800445 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700446
Austin Borger71d8f672023-06-01 16:51:35 -0700447 String16 physicalCameraId = toString16(mPhysicalCameraId);
448 err = parcel->writeString16(physicalCameraId);
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800449 if (err != OK) return err;
450
Shuzhen Wang83bff122020-11-20 15:51:39 -0800451 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
452 if (err != OK) return err;
453
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800454 err = parcel->writeParcelableVector(mSensorPixelModesUsed);
455 if (err != OK) return err;
456
Emilian Peevc81a7592022-02-14 17:38:18 -0800457 err = parcel->writeInt64(mDynamicRangeProfile);
Emilian Peev2295df72021-11-12 18:14:10 -0800458 if (err != OK) return err;
459
Austin Borger9e2b27c2022-07-15 11:27:24 -0700460 err = parcel->writeInt32(mColorSpace);
461 if (err != OK) return err;
462
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800463 err = parcel->writeInt64(mStreamUseCase);
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800464 if (err != OK) return err;
465
Shuzhen Wange4208922022-02-01 16:52:48 -0800466 err = parcel->writeInt32(mTimestampBase);
467 if (err != OK) return err;
468
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800469 err = parcel->writeInt32(mMirrorMode);
470 if (err != OK) return err;
471
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700472 err = parcel->writeInt32Vector(mMirrorModeForProducers);
473 if (err != OK) return err;
474
Shuzhen Wangbce53db2022-12-03 00:38:20 +0000475 err = parcel->writeInt32(mUseReadoutTimestamp ? 1 : 0);
476 if (err != OK) return err;
477
Shuzhen Wang0709c282024-02-12 09:09:32 -0800478 err = parcel->writeInt32(mFormat);
479 if (err != OK) return err;
480
481 err = parcel->writeInt32(mDataspace);
482 if (err != OK) return err;
483
484 err = parcel->writeInt64(mUsage);
485 if (err != OK) return err;
486
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700487 return OK;
488}
489
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800490template <typename T>
491static bool simpleVectorsEqual(T first, T second) {
492 if (first.size() != second.size()) {
493 return false;
494 }
495
496 for (size_t i = 0; i < first.size(); i++) {
497 if (first[i] != second[i]) {
498 return false;
499 }
500 }
501 return true;
502}
503
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700504template <typename T>
505static bool simpleVectorsLessThan(T first, T second) {
506 if (first.size() != second.size()) {
507 return first.size() < second.size();
508 }
509
510 for (size_t i = 0; i < first.size(); i++) {
511 if (first[i] != second[i]) {
512 return first[i] < second[i];
513 }
514 }
515 return false;
516}
517
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700518bool OutputConfiguration::surfacesEqual(const OutputConfiguration& other) const {
519 const std::vector<ParcelableSurfaceType>& otherSurfaces = other.getSurfaces();
520 return simpleVectorsEqual(otherSurfaces, mSurfaces);
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800521}
Shuzhen Wang0129d522016-10-30 22:43:41 -0700522
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800523bool OutputConfiguration::sensorPixelModesUsedEqual(const OutputConfiguration& other) const {
524 const std::vector<int32_t>& othersensorPixelModesUsed = other.getSensorPixelModesUsed();
525 return simpleVectorsEqual(othersensorPixelModesUsed, mSensorPixelModesUsed);
526}
527
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700528bool OutputConfiguration::mirrorModesEqual(const OutputConfiguration& other) const {
529 const std::vector<int>& otherMirrorModes = other.getMirrorModes();
530 return simpleVectorsEqual(otherMirrorModes, mMirrorModeForProducers);
Shuzhen Wang38df0ca2024-10-09 11:33:44 -0700531}
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
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700543bool OutputConfiguration::surfacesLessThan(const OutputConfiguration& other) const {
544 const std::vector<ParcelableSurfaceType>& otherSurfaces = other.getSurfaces();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700545
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700546 if (mSurfaces.size() != otherSurfaces.size()) {
547 return mSurfaces.size() < otherSurfaces.size();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700548 }
549
Carlos Martinez Romeroc45bc932024-10-09 15:04:51 -0700550 for (size_t i = 0; i < mSurfaces.size(); i++) {
551 if (mSurfaces[i] != otherSurfaces[i]) {
552 return mSurfaces[i] < otherSurfaces[i];
Shuzhen Wang0129d522016-10-30 22:43:41 -0700553 }
554 }
555
556 return false;
557}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700558}; // namespace android