blob: 15c9dc92b491373f0af9165fa423fe70fa48c96a [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
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080084OutputConfiguration::OutputConfiguration() :
85 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070086 mSurfaceSetID(INVALID_SET_ID),
87 mSurfaceType(SURFACE_TYPE_UNKNOWN),
88 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -080089 mHeight(0),
90 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -080091 mIsShared(false),
Emilian Peev2295df72021-11-12 18:14:10 -080092 mIsMultiResolution(false),
93 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080094}
95
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080096OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080097 mRotation(INVALID_ROTATION),
98 mSurfaceSetID(INVALID_SET_ID) {
99 readFromParcel(&parcel);
100}
101
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800102status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800103 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700104 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800105
106 if (parcel == nullptr) return BAD_VALUE;
107
108 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700109 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800110 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700111 }
112
Zhijun He018107a2016-01-18 15:32:50 -0800113 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800114 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800115 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800116 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800117 }
118
Zhijun He5d677d12016-05-29 16:52:39 -0700119 int surfaceType = SURFACE_TYPE_UNKNOWN;
120 if ((err = parcel->readInt32(&surfaceType)) != OK) {
121 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
122 return err;
123 }
124
125 int width = 0;
126 if ((err = parcel->readInt32(&width)) != OK) {
127 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
128 return err;
129 }
130
131 int height = 0;
132 if ((err = parcel->readInt32(&height)) != OK) {
133 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
134 return err;
135 }
136
Shuzhen Wang758c2152017-01-10 18:26:18 -0800137 int isDeferred = 0;
138 if ((err = parcel->readInt32(&isDeferred)) != OK) {
139 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700140 return err;
141 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800142
143 int isShared = 0;
144 if ((err = parcel->readInt32(&isShared)) != OK) {
145 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
146 return err;
147 }
148
149 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
150 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
151 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700152 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800153 }
154
Shuzhen Wang758c2152017-01-10 18:26:18 -0800155 std::vector<view::Surface> surfaceShims;
156 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
157 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
158 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700159 }
160
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800161 parcel->readString16(&mPhysicalCameraId);
162
Shuzhen Wang83bff122020-11-20 15:51:39 -0800163 int isMultiResolution = 0;
164 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
165 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
166 return err;
167 }
168
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800169 std::vector<int32_t> sensorPixelModesUsed;
Jayant Chowdhary84df28c2021-05-26 22:32:21 -0700170 if ((err = parcel->readInt32Vector(&sensorPixelModesUsed)) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800171 ALOGE("%s: Failed to read sensor pixel mode(s) from parcel", __FUNCTION__);
172 return err;
173 }
Emilian Peev2295df72021-11-12 18:14:10 -0800174 int dynamicProfile;
175 if ((err = parcel->readInt32(&dynamicProfile)) != OK) {
176 ALOGE("%s: Failed to read surface dynamic range profile flag from parcel", __FUNCTION__);
177 return err;
178 }
179
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700180 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800181 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700182 mSurfaceType = surfaceType;
183 mWidth = width;
184 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800185 mIsDeferred = isDeferred != 0;
186 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800187 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800188 for (auto& surface : surfaceShims) {
189 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
190 surface.graphicBufferProducer.get(),
191 String8(surface.name).string());
192 mGbps.push_back(surface.graphicBufferProducer);
193 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700194
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800195 mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
Emilian Peev2295df72021-11-12 18:14:10 -0800196 mDynamicRangeProfile = dynamicProfile;
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800197
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800198 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wang83bff122020-11-20 15:51:39 -0800199 " physicalCameraId = %s, isMultiResolution = %d", __FUNCTION__, mRotation,
200 mSurfaceSetID, mSurfaceType, String8(mPhysicalCameraId).string(), mIsMultiResolution);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800201
202 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700203}
204
Zhijun He018107a2016-01-18 15:32:50 -0800205OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800206 const String16& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100207 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700208 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700209 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800210 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800211 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100212 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800213 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800214 mIsMultiResolution = false;
Emilian Peev2295df72021-11-12 18:14:10 -0800215 mDynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700216}
217
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700218OutputConfiguration::OutputConfiguration(
219 const std::vector<sp<IGraphicBufferProducer>>& gbps,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800220 int rotation, const String16& physicalCameraId, int surfaceSetID, int surfaceType,
221 int width, int height, bool isShared)
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700222 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800223 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
Emilian Peev2295df72021-11-12 18:14:10 -0800224 mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false),
225 mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700226
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800227status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700228
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800229 if (parcel == nullptr) return BAD_VALUE;
230 status_t err = OK;
231
232 err = parcel->writeInt32(mRotation);
233 if (err != OK) return err;
234
235 err = parcel->writeInt32(mSurfaceSetID);
236 if (err != OK) return err;
237
Zhijun He5d677d12016-05-29 16:52:39 -0700238 err = parcel->writeInt32(mSurfaceType);
239 if (err != OK) return err;
240
241 err = parcel->writeInt32(mWidth);
242 if (err != OK) return err;
243
244 err = parcel->writeInt32(mHeight);
245 if (err != OK) return err;
246
Shuzhen Wang758c2152017-01-10 18:26:18 -0800247 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800248 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700249
Shuzhen Wang758c2152017-01-10 18:26:18 -0800250 err = parcel->writeInt32(mIsShared ? 1 : 0);
251 if (err != OK) return err;
252
253 std::vector<view::Surface> surfaceShims;
254 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700255 view::Surface surfaceShim;
256 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800257 surfaceShim.graphicBufferProducer = gbp;
258 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700259 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800260 err = parcel->writeParcelableVector(surfaceShims);
261 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700262
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800263 err = parcel->writeString16(mPhysicalCameraId);
264 if (err != OK) return err;
265
Shuzhen Wang83bff122020-11-20 15:51:39 -0800266 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
267 if (err != OK) return err;
268
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800269 err = parcel->writeParcelableVector(mSensorPixelModesUsed);
270 if (err != OK) return err;
271
Emilian Peev2295df72021-11-12 18:14:10 -0800272 err = parcel->writeInt32(mDynamicRangeProfile ? 1 : 0);
273 if (err != OK) return err;
274
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700275 return OK;
276}
277
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800278template <typename T>
279static bool simpleVectorsEqual(T first, T second) {
280 if (first.size() != second.size()) {
281 return false;
282 }
283
284 for (size_t i = 0; i < first.size(); i++) {
285 if (first[i] != second[i]) {
286 return false;
287 }
288 }
289 return true;
290}
291
Shuzhen Wang0129d522016-10-30 22:43:41 -0700292bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
293 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
294 other.getGraphicBufferProducers();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800295 return simpleVectorsEqual(otherGbps, mGbps);
296}
Shuzhen Wang0129d522016-10-30 22:43:41 -0700297
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800298bool OutputConfiguration::sensorPixelModesUsedEqual(const OutputConfiguration& other) const {
299 const std::vector<int32_t>& othersensorPixelModesUsed = other.getSensorPixelModesUsed();
300 return simpleVectorsEqual(othersensorPixelModesUsed, mSensorPixelModesUsed);
301}
302
303bool OutputConfiguration::sensorPixelModesUsedLessThan(const OutputConfiguration& other) const {
304 const std::vector<int32_t>& spms = other.getSensorPixelModesUsed();
305
306 if (mSensorPixelModesUsed.size() != spms.size()) {
307 return mSensorPixelModesUsed.size() < spms.size();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700308 }
309
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800310 for (size_t i = 0; i < spms.size(); i++) {
311 if (mSensorPixelModesUsed[i] != spms[i]) {
312 return mSensorPixelModesUsed[i] < spms[i];
Shuzhen Wang0129d522016-10-30 22:43:41 -0700313 }
314 }
315
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800316 return false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700317}
318
319bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
320 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
321 other.getGraphicBufferProducers();
322
323 if (mGbps.size() != otherGbps.size()) {
324 return mGbps.size() < otherGbps.size();
325 }
326
327 for (size_t i = 0; i < mGbps.size(); i++) {
328 if (mGbps[i] != otherGbps[i]) {
329 return mGbps[i] < otherGbps[i];
330 }
331 }
332
333 return false;
334}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700335}; // namespace android