blob: a16e747fa5a5c23546c9d4cabd7946983cd2c7c5 [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
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080092OutputConfiguration::OutputConfiguration() :
93 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070094 mSurfaceSetID(INVALID_SET_ID),
95 mSurfaceType(SURFACE_TYPE_UNKNOWN),
96 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -080097 mHeight(0),
98 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -080099 mIsShared(false),
Emilian Peev2295df72021-11-12 18:14:10 -0800100 mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800101 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Shuzhen Wange4208922022-02-01 16:52:48 -0800102 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
103 mTimestampBase(TIMESTAMP_BASE_DEFAULT) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800104}
105
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800106OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800107 mRotation(INVALID_ROTATION),
108 mSurfaceSetID(INVALID_SET_ID) {
109 readFromParcel(&parcel);
110}
111
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800112status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800113 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700114 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800115
116 if (parcel == nullptr) return BAD_VALUE;
117
118 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700119 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800120 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700121 }
122
Zhijun He018107a2016-01-18 15:32:50 -0800123 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800124 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800125 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800126 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800127 }
128
Zhijun He5d677d12016-05-29 16:52:39 -0700129 int surfaceType = SURFACE_TYPE_UNKNOWN;
130 if ((err = parcel->readInt32(&surfaceType)) != OK) {
131 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
132 return err;
133 }
134
135 int width = 0;
136 if ((err = parcel->readInt32(&width)) != OK) {
137 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
138 return err;
139 }
140
141 int height = 0;
142 if ((err = parcel->readInt32(&height)) != OK) {
143 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
144 return err;
145 }
146
Shuzhen Wang758c2152017-01-10 18:26:18 -0800147 int isDeferred = 0;
148 if ((err = parcel->readInt32(&isDeferred)) != OK) {
149 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700150 return err;
151 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800152
153 int isShared = 0;
154 if ((err = parcel->readInt32(&isShared)) != OK) {
155 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
156 return err;
157 }
158
159 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
160 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
161 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700162 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800163 }
164
Shuzhen Wang758c2152017-01-10 18:26:18 -0800165 std::vector<view::Surface> surfaceShims;
166 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
167 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
168 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700169 }
170
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800171 parcel->readString16(&mPhysicalCameraId);
172
Shuzhen Wang83bff122020-11-20 15:51:39 -0800173 int isMultiResolution = 0;
174 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
175 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
176 return err;
177 }
178
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800179 std::vector<int32_t> sensorPixelModesUsed;
Jayant Chowdhary84df28c2021-05-26 22:32:21 -0700180 if ((err = parcel->readInt32Vector(&sensorPixelModesUsed)) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800181 ALOGE("%s: Failed to read sensor pixel mode(s) from parcel", __FUNCTION__);
182 return err;
183 }
Emilian Peev2295df72021-11-12 18:14:10 -0800184 int dynamicProfile;
185 if ((err = parcel->readInt32(&dynamicProfile)) != OK) {
186 ALOGE("%s: Failed to read surface dynamic range profile flag from parcel", __FUNCTION__);
187 return err;
188 }
189
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800190 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
191 if ((err = parcel->readInt32(&streamUseCase)) != OK) {
192 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
193 return err;
194 }
195
Shuzhen Wange4208922022-02-01 16:52:48 -0800196 int timestampBase = TIMESTAMP_BASE_DEFAULT;
197 if ((err = parcel->readInt32(&timestampBase)) != OK) {
198 ALOGE("%s: Failed to read timestamp base from parcel", __FUNCTION__);
199 return err;
200 }
201
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700202 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800203 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700204 mSurfaceType = surfaceType;
205 mWidth = width;
206 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800207 mIsDeferred = isDeferred != 0;
208 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800209 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800210 mStreamUseCase = streamUseCase;
Shuzhen Wange4208922022-02-01 16:52:48 -0800211 mTimestampBase = timestampBase;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800212 for (auto& surface : surfaceShims) {
213 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
214 surface.graphicBufferProducer.get(),
215 String8(surface.name).string());
216 mGbps.push_back(surface.graphicBufferProducer);
217 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700218
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800219 mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
Emilian Peev2295df72021-11-12 18:14:10 -0800220 mDynamicRangeProfile = dynamicProfile;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800221
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800222 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wange4208922022-02-01 16:52:48 -0800223 " physicalCameraId = %s, isMultiResolution = %d, streamUseCase = %d, timestampBase = %d",
224 __FUNCTION__, mRotation, mSurfaceSetID, mSurfaceType,
225 String8(mPhysicalCameraId).string(), mIsMultiResolution, mStreamUseCase, timestampBase);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800226
227 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700228}
229
Zhijun He018107a2016-01-18 15:32:50 -0800230OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800231 const String16& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100232 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700233 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700234 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800235 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800236 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100237 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800238 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800239 mIsMultiResolution = false;
Emilian Peev2295df72021-11-12 18:14:10 -0800240 mDynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800241 mStreamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
Shuzhen Wange4208922022-02-01 16:52:48 -0800242 mTimestampBase = TIMESTAMP_BASE_DEFAULT;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700243}
244
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700245OutputConfiguration::OutputConfiguration(
246 const std::vector<sp<IGraphicBufferProducer>>& gbps,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800247 int rotation, const String16& physicalCameraId, int surfaceSetID, int surfaceType,
248 int width, int height, bool isShared)
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700249 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800250 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
Emilian Peev2295df72021-11-12 18:14:10 -0800251 mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false),
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800252 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
Shuzhen Wange4208922022-02-01 16:52:48 -0800253 mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
254 mTimestampBase(TIMESTAMP_BASE_DEFAULT) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700255
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800256status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700257
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800258 if (parcel == nullptr) return BAD_VALUE;
259 status_t err = OK;
260
261 err = parcel->writeInt32(mRotation);
262 if (err != OK) return err;
263
264 err = parcel->writeInt32(mSurfaceSetID);
265 if (err != OK) return err;
266
Zhijun He5d677d12016-05-29 16:52:39 -0700267 err = parcel->writeInt32(mSurfaceType);
268 if (err != OK) return err;
269
270 err = parcel->writeInt32(mWidth);
271 if (err != OK) return err;
272
273 err = parcel->writeInt32(mHeight);
274 if (err != OK) return err;
275
Shuzhen Wang758c2152017-01-10 18:26:18 -0800276 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800277 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700278
Shuzhen Wang758c2152017-01-10 18:26:18 -0800279 err = parcel->writeInt32(mIsShared ? 1 : 0);
280 if (err != OK) return err;
281
282 std::vector<view::Surface> surfaceShims;
283 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700284 view::Surface surfaceShim;
285 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800286 surfaceShim.graphicBufferProducer = gbp;
287 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700288 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800289 err = parcel->writeParcelableVector(surfaceShims);
290 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700291
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800292 err = parcel->writeString16(mPhysicalCameraId);
293 if (err != OK) return err;
294
Shuzhen Wang83bff122020-11-20 15:51:39 -0800295 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
296 if (err != OK) return err;
297
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800298 err = parcel->writeParcelableVector(mSensorPixelModesUsed);
299 if (err != OK) return err;
300
Emilian Peev2295df72021-11-12 18:14:10 -0800301 err = parcel->writeInt32(mDynamicRangeProfile ? 1 : 0);
302 if (err != OK) return err;
303
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800304 err = parcel->writeInt32(mStreamUseCase);
305 if (err != OK) return err;
306
Shuzhen Wange4208922022-02-01 16:52:48 -0800307 err = parcel->writeInt32(mTimestampBase);
308 if (err != OK) return err;
309
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700310 return OK;
311}
312
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800313template <typename T>
314static bool simpleVectorsEqual(T first, T second) {
315 if (first.size() != second.size()) {
316 return false;
317 }
318
319 for (size_t i = 0; i < first.size(); i++) {
320 if (first[i] != second[i]) {
321 return false;
322 }
323 }
324 return true;
325}
326
Shuzhen Wang0129d522016-10-30 22:43:41 -0700327bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
328 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
329 other.getGraphicBufferProducers();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800330 return simpleVectorsEqual(otherGbps, mGbps);
331}
Shuzhen Wang0129d522016-10-30 22:43:41 -0700332
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800333bool OutputConfiguration::sensorPixelModesUsedEqual(const OutputConfiguration& other) const {
334 const std::vector<int32_t>& othersensorPixelModesUsed = other.getSensorPixelModesUsed();
335 return simpleVectorsEqual(othersensorPixelModesUsed, mSensorPixelModesUsed);
336}
337
338bool OutputConfiguration::sensorPixelModesUsedLessThan(const OutputConfiguration& other) const {
339 const std::vector<int32_t>& spms = other.getSensorPixelModesUsed();
340
341 if (mSensorPixelModesUsed.size() != spms.size()) {
342 return mSensorPixelModesUsed.size() < spms.size();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700343 }
344
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800345 for (size_t i = 0; i < spms.size(); i++) {
346 if (mSensorPixelModesUsed[i] != spms[i]) {
347 return mSensorPixelModesUsed[i] < spms[i];
Shuzhen Wang0129d522016-10-30 22:43:41 -0700348 }
349 }
350
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800351 return false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700352}
353
354bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
355 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
356 other.getGraphicBufferProducers();
357
358 if (mGbps.size() != otherGbps.size()) {
359 return mGbps.size() < otherGbps.size();
360 }
361
362 for (size_t i = 0; i < mGbps.size(); i++) {
363 if (mGbps[i] != otherGbps[i]) {
364 return mGbps[i] < otherGbps[i];
365 }
366 }
367
368 return false;
369}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700370}; // namespace android