blob: 2bccd870b8a7cf9c28595748387f89cfab35e558 [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>
Brian Andersonf6753562016-10-11 14:51:05 -070026#include <utils/String8.h>
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070027
28namespace android {
29
30
31const int OutputConfiguration::INVALID_ROTATION = -1;
Zhijun He018107a2016-01-18 15:32:50 -080032const int OutputConfiguration::INVALID_SET_ID = -1;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070033
Shuzhen Wang0129d522016-10-30 22:43:41 -070034const std::vector<sp<IGraphicBufferProducer>>&
35 OutputConfiguration::getGraphicBufferProducers() const {
36 return mGbps;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070037}
38
39int OutputConfiguration::getRotation() const {
40 return mRotation;
41}
42
Zhijun He018107a2016-01-18 15:32:50 -080043int OutputConfiguration::getSurfaceSetID() const {
44 return mSurfaceSetID;
45}
46
Zhijun He5d677d12016-05-29 16:52:39 -070047int OutputConfiguration::getSurfaceType() const {
48 return mSurfaceType;
49}
50
51int OutputConfiguration::getWidth() const {
52 return mWidth;
53}
54
55int OutputConfiguration::getHeight() const {
56 return mHeight;
57}
58
Shuzhen Wang758c2152017-01-10 18:26:18 -080059bool OutputConfiguration::isDeferred() const {
60 return mIsDeferred;
61}
62
63bool OutputConfiguration::isShared() const {
64 return mIsShared;
65}
66
Shuzhen Wangc28189a2017-11-27 23:05:10 -080067String16 OutputConfiguration::getPhysicalCameraId() const {
68 return mPhysicalCameraId;
69}
70
Shuzhen Wang83bff122020-11-20 15:51:39 -080071bool OutputConfiguration::isMultiResolution() const {
72 return mIsMultiResolution;
73}
74
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -080075const std::vector<int32_t> &OutputConfiguration::getSensorPixelModesUsed() const {
76 return mSensorPixelModesUsed;
77}
78
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080079OutputConfiguration::OutputConfiguration() :
80 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070081 mSurfaceSetID(INVALID_SET_ID),
82 mSurfaceType(SURFACE_TYPE_UNKNOWN),
83 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -080084 mHeight(0),
85 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -080086 mIsShared(false),
87 mIsMultiResolution(false) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080088}
89
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080090OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080091 mRotation(INVALID_ROTATION),
92 mSurfaceSetID(INVALID_SET_ID) {
93 readFromParcel(&parcel);
94}
95
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080096status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080097 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070098 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080099
100 if (parcel == nullptr) return BAD_VALUE;
101
102 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700103 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800104 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700105 }
106
Zhijun He018107a2016-01-18 15:32:50 -0800107 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800108 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800109 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800110 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800111 }
112
Zhijun He5d677d12016-05-29 16:52:39 -0700113 int surfaceType = SURFACE_TYPE_UNKNOWN;
114 if ((err = parcel->readInt32(&surfaceType)) != OK) {
115 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
116 return err;
117 }
118
119 int width = 0;
120 if ((err = parcel->readInt32(&width)) != OK) {
121 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
122 return err;
123 }
124
125 int height = 0;
126 if ((err = parcel->readInt32(&height)) != OK) {
127 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
128 return err;
129 }
130
Shuzhen Wang758c2152017-01-10 18:26:18 -0800131 int isDeferred = 0;
132 if ((err = parcel->readInt32(&isDeferred)) != OK) {
133 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700134 return err;
135 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800136
137 int isShared = 0;
138 if ((err = parcel->readInt32(&isShared)) != OK) {
139 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
140 return err;
141 }
142
143 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
144 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
145 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700146 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800147 }
148
Shuzhen Wang758c2152017-01-10 18:26:18 -0800149 std::vector<view::Surface> surfaceShims;
150 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
151 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
152 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700153 }
154
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800155 parcel->readString16(&mPhysicalCameraId);
156
Shuzhen Wang83bff122020-11-20 15:51:39 -0800157 int isMultiResolution = 0;
158 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
159 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
160 return err;
161 }
162
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800163 std::vector<int32_t> sensorPixelModesUsed;
Jayant Chowdhary84df28c2021-05-26 22:32:21 -0700164 if ((err = parcel->readInt32Vector(&sensorPixelModesUsed)) != OK) {
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800165 ALOGE("%s: Failed to read sensor pixel mode(s) from parcel", __FUNCTION__);
166 return err;
167 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700168 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800169 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700170 mSurfaceType = surfaceType;
171 mWidth = width;
172 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800173 mIsDeferred = isDeferred != 0;
174 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800175 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800176 for (auto& surface : surfaceShims) {
177 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
178 surface.graphicBufferProducer.get(),
179 String8(surface.name).string());
180 mGbps.push_back(surface.graphicBufferProducer);
181 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700182
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800183 mSensorPixelModesUsed = std::move(sensorPixelModesUsed);
184
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800185 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wang83bff122020-11-20 15:51:39 -0800186 " physicalCameraId = %s, isMultiResolution = %d", __FUNCTION__, mRotation,
187 mSurfaceSetID, mSurfaceType, String8(mPhysicalCameraId).string(), mIsMultiResolution);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800188
189 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700190}
191
Zhijun He018107a2016-01-18 15:32:50 -0800192OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800193 const String16& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100194 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700195 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700196 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800197 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800198 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100199 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800200 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800201 mIsMultiResolution = false;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700202}
203
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700204OutputConfiguration::OutputConfiguration(
205 const std::vector<sp<IGraphicBufferProducer>>& gbps,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800206 int rotation, const String16& physicalCameraId, int surfaceSetID, int surfaceType,
207 int width, int height, bool isShared)
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700208 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800209 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
Shuzhen Wang83bff122020-11-20 15:51:39 -0800210 mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700211
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800212status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700213
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800214 if (parcel == nullptr) return BAD_VALUE;
215 status_t err = OK;
216
217 err = parcel->writeInt32(mRotation);
218 if (err != OK) return err;
219
220 err = parcel->writeInt32(mSurfaceSetID);
221 if (err != OK) return err;
222
Zhijun He5d677d12016-05-29 16:52:39 -0700223 err = parcel->writeInt32(mSurfaceType);
224 if (err != OK) return err;
225
226 err = parcel->writeInt32(mWidth);
227 if (err != OK) return err;
228
229 err = parcel->writeInt32(mHeight);
230 if (err != OK) return err;
231
Shuzhen Wang758c2152017-01-10 18:26:18 -0800232 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800233 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700234
Shuzhen Wang758c2152017-01-10 18:26:18 -0800235 err = parcel->writeInt32(mIsShared ? 1 : 0);
236 if (err != OK) return err;
237
238 std::vector<view::Surface> surfaceShims;
239 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700240 view::Surface surfaceShim;
241 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800242 surfaceShim.graphicBufferProducer = gbp;
243 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700244 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800245 err = parcel->writeParcelableVector(surfaceShims);
246 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700247
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800248 err = parcel->writeString16(mPhysicalCameraId);
249 if (err != OK) return err;
250
Shuzhen Wang83bff122020-11-20 15:51:39 -0800251 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
252 if (err != OK) return err;
253
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800254 err = parcel->writeParcelableVector(mSensorPixelModesUsed);
255 if (err != OK) return err;
256
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700257 return OK;
258}
259
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800260template <typename T>
261static bool simpleVectorsEqual(T first, T second) {
262 if (first.size() != second.size()) {
263 return false;
264 }
265
266 for (size_t i = 0; i < first.size(); i++) {
267 if (first[i] != second[i]) {
268 return false;
269 }
270 }
271 return true;
272}
273
Shuzhen Wang0129d522016-10-30 22:43:41 -0700274bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
275 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
276 other.getGraphicBufferProducers();
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800277 return simpleVectorsEqual(otherGbps, mGbps);
278}
Shuzhen Wang0129d522016-10-30 22:43:41 -0700279
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800280bool OutputConfiguration::sensorPixelModesUsedEqual(const OutputConfiguration& other) const {
281 const std::vector<int32_t>& othersensorPixelModesUsed = other.getSensorPixelModesUsed();
282 return simpleVectorsEqual(othersensorPixelModesUsed, mSensorPixelModesUsed);
283}
284
285bool OutputConfiguration::sensorPixelModesUsedLessThan(const OutputConfiguration& other) const {
286 const std::vector<int32_t>& spms = other.getSensorPixelModesUsed();
287
288 if (mSensorPixelModesUsed.size() != spms.size()) {
289 return mSensorPixelModesUsed.size() < spms.size();
Shuzhen Wang0129d522016-10-30 22:43:41 -0700290 }
291
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800292 for (size_t i = 0; i < spms.size(); i++) {
293 if (mSensorPixelModesUsed[i] != spms[i]) {
294 return mSensorPixelModesUsed[i] < spms[i];
Shuzhen Wang0129d522016-10-30 22:43:41 -0700295 }
296 }
297
Jayant Chowdhary13f9b2f2020-12-02 22:46:15 -0800298 return false;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700299}
300
301bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
302 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
303 other.getGraphicBufferProducers();
304
305 if (mGbps.size() != otherGbps.size()) {
306 return mGbps.size() < otherGbps.size();
307 }
308
309 for (size_t i = 0; i < mGbps.size(); i++) {
310 if (mGbps[i] != otherGbps[i]) {
311 return mGbps[i] < otherGbps[i];
312 }
313 }
314
315 return false;
316}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700317}; // namespace android