blob: 4300f9abe922e9b4638499d6fe9c6f1d5fc1586b [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
Shuzhen Wange4208922022-02-01 16:52:48 -080088int OutputConfiguration::getTimestampBase() const {
89 return mTimestampBase;
90}
91
Shuzhen Wang610d7b82022-02-08 14:37:22 -080092int OutputConfiguration::getMirrorMode() const {
93 return mMirrorMode;
94}
95
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080096OutputConfiguration::OutputConfiguration() :
97 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070098 mSurfaceSetID(INVALID_SET_ID),
99 mSurfaceType(SURFACE_TYPE_UNKNOWN),
100 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -0800101 mHeight(0),
102 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -0800103 mIsShared(false),
Emilian Peev2295df72021-11-12 18:14:10 -0800104 mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800105 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Shuzhen Wange4208922022-02-01 16:52:48 -0800106 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800107 mTimestampBase(TIMESTAMP_BASE_DEFAULT),
108 mMirrorMode(MIRROR_MODE_AUTO) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800109}
110
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800111OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800112 mRotation(INVALID_ROTATION),
113 mSurfaceSetID(INVALID_SET_ID) {
114 readFromParcel(&parcel);
115}
116
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800117status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800118 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700119 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800120
121 if (parcel == nullptr) return BAD_VALUE;
122
123 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700124 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800125 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700126 }
127
Zhijun He018107a2016-01-18 15:32:50 -0800128 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800129 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800130 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800131 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800132 }
133
Zhijun He5d677d12016-05-29 16:52:39 -0700134 int surfaceType = SURFACE_TYPE_UNKNOWN;
135 if ((err = parcel->readInt32(&surfaceType)) != OK) {
136 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
137 return err;
138 }
139
140 int width = 0;
141 if ((err = parcel->readInt32(&width)) != OK) {
142 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
143 return err;
144 }
145
146 int height = 0;
147 if ((err = parcel->readInt32(&height)) != OK) {
148 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
149 return err;
150 }
151
Shuzhen Wang758c2152017-01-10 18:26:18 -0800152 int isDeferred = 0;
153 if ((err = parcel->readInt32(&isDeferred)) != OK) {
154 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700155 return err;
156 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800157
158 int isShared = 0;
159 if ((err = parcel->readInt32(&isShared)) != OK) {
160 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
161 return err;
162 }
163
164 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
165 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
166 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700167 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800168 }
169
Shuzhen Wang758c2152017-01-10 18:26:18 -0800170 std::vector<view::Surface> surfaceShims;
171 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
172 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
173 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700174 }
175
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800176 parcel->readString16(&mPhysicalCameraId);
177
Shuzhen Wang83bff122020-11-20 15:51:39 -0800178 int isMultiResolution = 0;
179 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
180 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
181 return err;
182 }
183
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800184 std::vector<int32_t> sensorPixelModesUsed;
Jayant Chowdhary84df28c2021-05-26 22:32:21 -0700185 if ((err = parcel->readInt32Vector(&sensorPixelModesUsed)) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800186 ALOGE("%s: Failed to read sensor pixel mode(s) from parcel", __FUNCTION__);
187 return err;
188 }
Emilian Peev2295df72021-11-12 18:14:10 -0800189 int dynamicProfile;
190 if ((err = parcel->readInt32(&dynamicProfile)) != OK) {
191 ALOGE("%s: Failed to read surface dynamic range profile flag from parcel", __FUNCTION__);
192 return err;
193 }
194
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800195 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
196 if ((err = parcel->readInt32(&streamUseCase)) != OK) {
197 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
198 return err;
199 }
200
Shuzhen Wange4208922022-02-01 16:52:48 -0800201 int timestampBase = TIMESTAMP_BASE_DEFAULT;
202 if ((err = parcel->readInt32(&timestampBase)) != OK) {
203 ALOGE("%s: Failed to read timestamp base from parcel", __FUNCTION__);
204 return err;
205 }
206
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800207 int mirrorMode = MIRROR_MODE_AUTO;
208 if ((err = parcel->readInt32(&mirrorMode)) != OK) {
209 ALOGE("%s: Failed to read mirroring mode from parcel", __FUNCTION__);
210 return err;
211 }
212
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700213 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800214 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700215 mSurfaceType = surfaceType;
216 mWidth = width;
217 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800218 mIsDeferred = isDeferred != 0;
219 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800220 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800221 mStreamUseCase = streamUseCase;
Shuzhen Wange4208922022-02-01 16:52:48 -0800222 mTimestampBase = timestampBase;
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800223 mMirrorMode = mirrorMode;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800224 for (auto& surface : surfaceShims) {
225 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
226 surface.graphicBufferProducer.get(),
227 String8(surface.name).string());
228 mGbps.push_back(surface.graphicBufferProducer);
229 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700230
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800231 mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
Emilian Peev2295df72021-11-12 18:14:10 -0800232 mDynamicRangeProfile = dynamicProfile;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800233
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800234 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800235 " physicalCameraId = %s, isMultiResolution = %d, streamUseCase = %d, timestampBase = %d,"
236 " mirrorMode = %d",
Shuzhen Wange4208922022-02-01 16:52:48 -0800237 __FUNCTION__, mRotation, mSurfaceSetID, mSurfaceType,
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800238 String8(mPhysicalCameraId).string(), mIsMultiResolution, mStreamUseCase, timestampBase,
239 mMirrorMode);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800240
241 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700242}
243
Zhijun He018107a2016-01-18 15:32:50 -0800244OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800245 const String16& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100246 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700247 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700248 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800249 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800250 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100251 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800252 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800253 mIsMultiResolution = false;
Emilian Peev2295df72021-11-12 18:14:10 -0800254 mDynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800255 mStreamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
Shuzhen Wange4208922022-02-01 16:52:48 -0800256 mTimestampBase = TIMESTAMP_BASE_DEFAULT;
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800257 mMirrorMode = MIRROR_MODE_AUTO;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700258}
259
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700260OutputConfiguration::OutputConfiguration(
261 const std::vector<sp<IGraphicBufferProducer>>& gbps,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800262 int rotation, const String16& physicalCameraId, int surfaceSetID, int surfaceType,
263 int width, int height, bool isShared)
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700264 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800265 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
Emilian Peev2295df72021-11-12 18:14:10 -0800266 mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800267 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Shuzhen Wange4208922022-02-01 16:52:48 -0800268 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800269 mTimestampBase(TIMESTAMP_BASE_DEFAULT),
270 mMirrorMode(MIRROR_MODE_AUTO) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700271
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800272status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700273
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800274 if (parcel == nullptr) return BAD_VALUE;
275 status_t err = OK;
276
277 err = parcel->writeInt32(mRotation);
278 if (err != OK) return err;
279
280 err = parcel->writeInt32(mSurfaceSetID);
281 if (err != OK) return err;
282
Zhijun He5d677d12016-05-29 16:52:39 -0700283 err = parcel->writeInt32(mSurfaceType);
284 if (err != OK) return err;
285
286 err = parcel->writeInt32(mWidth);
287 if (err != OK) return err;
288
289 err = parcel->writeInt32(mHeight);
290 if (err != OK) return err;
291
Shuzhen Wang758c2152017-01-10 18:26:18 -0800292 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800293 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700294
Shuzhen Wang758c2152017-01-10 18:26:18 -0800295 err = parcel->writeInt32(mIsShared ? 1 : 0);
296 if (err != OK) return err;
297
298 std::vector<view::Surface> surfaceShims;
299 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700300 view::Surface surfaceShim;
301 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800302 surfaceShim.graphicBufferProducer = gbp;
303 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700304 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800305 err = parcel->writeParcelableVector(surfaceShims);
306 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700307
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800308 err = parcel->writeString16(mPhysicalCameraId);
309 if (err != OK) return err;
310
Shuzhen Wang83bff122020-11-20 15:51:39 -0800311 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
312 if (err != OK) return err;
313
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800314 err = parcel->writeParcelableVector(mSensorPixelModesUsed);
315 if (err != OK) return err;
316
Emilian Peev2295df72021-11-12 18:14:10 -0800317 err = parcel->writeInt32(mDynamicRangeProfile ? 1 : 0);
318 if (err != OK) return err;
319
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800320 err = parcel->writeInt32(mStreamUseCase);
321 if (err != OK) return err;
322
Shuzhen Wange4208922022-02-01 16:52:48 -0800323 err = parcel->writeInt32(mTimestampBase);
324 if (err != OK) return err;
325
Shuzhen Wang610d7b82022-02-08 14:37:22 -0800326 err = parcel->writeInt32(mMirrorMode);
327 if (err != OK) return err;
328
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700329 return OK;
330}
331
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800332template <typename T>
333static bool simpleVectorsEqual(T first, T second) {
334 if (first.size() != second.size()) {
335 return false;
336 }
337
338 for (size_t i = 0; i < first.size(); i++) {
339 if (first[i] != second[i]) {
340 return false;
341 }
342 }
343 return true;
344}
345
Shuzhen Wang0129d522016-10-30 22:43:41 -0700346bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
347 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
348 other.getGraphicBufferProducers();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800349 return simpleVectorsEqual(otherGbps, mGbps);
350}
Shuzhen Wang0129d522016-10-30 22:43:41 -0700351
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800352bool OutputConfiguration::sensorPixelModesUsedEqual(const OutputConfiguration& other) const {
353 const std::vector<int32_t>& othersensorPixelModesUsed = other.getSensorPixelModesUsed();
354 return simpleVectorsEqual(othersensorPixelModesUsed, mSensorPixelModesUsed);
355}
356
357bool OutputConfiguration::sensorPixelModesUsedLessThan(const OutputConfiguration& other) const {
358 const std::vector<int32_t>& spms = other.getSensorPixelModesUsed();
359
360 if (mSensorPixelModesUsed.size() != spms.size()) {
361 return mSensorPixelModesUsed.size() < spms.size();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700362 }
363
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800364 for (size_t i = 0; i < spms.size(); i++) {
365 if (mSensorPixelModesUsed[i] != spms[i]) {
366 return mSensorPixelModesUsed[i] < spms[i];
Shuzhen Wang0129d522016-10-30 22:43:41 -0700367 }
368 }
369
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800370 return false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700371}
372
373bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
374 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
375 other.getGraphicBufferProducers();
376
377 if (mGbps.size() != otherGbps.size()) {
378 return mGbps.size() < otherGbps.size();
379 }
380
381 for (size_t i = 0; i < mGbps.size(); i++) {
382 if (mGbps[i] != otherGbps[i]) {
383 return mGbps[i] < otherGbps[i];
384 }
385 }
386
387 return false;
388}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700389}; // namespace android