blob: 2f6bc30879153e2f4ec3432330e2be54f7cffcd2 [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
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080075OutputConfiguration::OutputConfiguration() :
76 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070077 mSurfaceSetID(INVALID_SET_ID),
78 mSurfaceType(SURFACE_TYPE_UNKNOWN),
79 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -080080 mHeight(0),
81 mIsDeferred(false),
Shuzhen Wang83bff122020-11-20 15:51:39 -080082 mIsShared(false),
83 mIsMultiResolution(false) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080084}
85
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080086OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080087 mRotation(INVALID_ROTATION),
88 mSurfaceSetID(INVALID_SET_ID) {
89 readFromParcel(&parcel);
90}
91
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080092status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080093 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070094 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080095
96 if (parcel == nullptr) return BAD_VALUE;
97
98 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070099 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800100 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700101 }
102
Zhijun He018107a2016-01-18 15:32:50 -0800103 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800104 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800105 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800106 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800107 }
108
Zhijun He5d677d12016-05-29 16:52:39 -0700109 int surfaceType = SURFACE_TYPE_UNKNOWN;
110 if ((err = parcel->readInt32(&surfaceType)) != OK) {
111 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
112 return err;
113 }
114
115 int width = 0;
116 if ((err = parcel->readInt32(&width)) != OK) {
117 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
118 return err;
119 }
120
121 int height = 0;
122 if ((err = parcel->readInt32(&height)) != OK) {
123 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
124 return err;
125 }
126
Shuzhen Wang758c2152017-01-10 18:26:18 -0800127 int isDeferred = 0;
128 if ((err = parcel->readInt32(&isDeferred)) != OK) {
129 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700130 return err;
131 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800132
133 int isShared = 0;
134 if ((err = parcel->readInt32(&isShared)) != OK) {
135 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
136 return err;
137 }
138
139 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
140 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
141 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700142 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800143 }
144
Shuzhen Wang758c2152017-01-10 18:26:18 -0800145 std::vector<view::Surface> surfaceShims;
146 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
147 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
148 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700149 }
150
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800151 parcel->readString16(&mPhysicalCameraId);
152
Shuzhen Wang83bff122020-11-20 15:51:39 -0800153 int isMultiResolution = 0;
154 if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
155 ALOGE("%s: Failed to read surface isMultiResolution flag from parcel", __FUNCTION__);
156 return err;
157 }
158
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700159 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800160 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700161 mSurfaceType = surfaceType;
162 mWidth = width;
163 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800164 mIsDeferred = isDeferred != 0;
165 mIsShared = isShared != 0;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800166 mIsMultiResolution = isMultiResolution != 0;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800167 for (auto& surface : surfaceShims) {
168 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
169 surface.graphicBufferProducer.get(),
170 String8(surface.name).string());
171 mGbps.push_back(surface.graphicBufferProducer);
172 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700173
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800174 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
Shuzhen Wang83bff122020-11-20 15:51:39 -0800175 " physicalCameraId = %s, isMultiResolution = %d", __FUNCTION__, mRotation,
176 mSurfaceSetID, mSurfaceType, String8(mPhysicalCameraId).string(), mIsMultiResolution);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800177
178 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700179}
180
Zhijun He018107a2016-01-18 15:32:50 -0800181OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800182 const String16& physicalId,
Emilian Peev40ead602017-09-26 15:46:36 +0100183 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700184 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700185 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800186 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800187 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100188 mIsShared = isShared;
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800189 mPhysicalCameraId = physicalId;
Shuzhen Wang83bff122020-11-20 15:51:39 -0800190 mIsMultiResolution = false;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700191}
192
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700193OutputConfiguration::OutputConfiguration(
194 const std::vector<sp<IGraphicBufferProducer>>& gbps,
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800195 int rotation, const String16& physicalCameraId, int surfaceSetID, int surfaceType,
196 int width, int height, bool isShared)
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700197 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
Shuzhen Wang0ff9ae32018-12-05 18:06:12 -0800198 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
Shuzhen Wang83bff122020-11-20 15:51:39 -0800199 mPhysicalCameraId(physicalCameraId), mIsMultiResolution(false) { }
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700200
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800201status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700202
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800203 if (parcel == nullptr) return BAD_VALUE;
204 status_t err = OK;
205
206 err = parcel->writeInt32(mRotation);
207 if (err != OK) return err;
208
209 err = parcel->writeInt32(mSurfaceSetID);
210 if (err != OK) return err;
211
Zhijun He5d677d12016-05-29 16:52:39 -0700212 err = parcel->writeInt32(mSurfaceType);
213 if (err != OK) return err;
214
215 err = parcel->writeInt32(mWidth);
216 if (err != OK) return err;
217
218 err = parcel->writeInt32(mHeight);
219 if (err != OK) return err;
220
Shuzhen Wang758c2152017-01-10 18:26:18 -0800221 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800222 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700223
Shuzhen Wang758c2152017-01-10 18:26:18 -0800224 err = parcel->writeInt32(mIsShared ? 1 : 0);
225 if (err != OK) return err;
226
227 std::vector<view::Surface> surfaceShims;
228 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700229 view::Surface surfaceShim;
230 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800231 surfaceShim.graphicBufferProducer = gbp;
232 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700233 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800234 err = parcel->writeParcelableVector(surfaceShims);
235 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700236
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800237 err = parcel->writeString16(mPhysicalCameraId);
238 if (err != OK) return err;
239
Shuzhen Wang83bff122020-11-20 15:51:39 -0800240 err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);
241 if (err != OK) return err;
242
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700243 return OK;
244}
245
Shuzhen Wang0129d522016-10-30 22:43:41 -0700246bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
247 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
248 other.getGraphicBufferProducers();
249
250 if (mGbps.size() != otherGbps.size()) {
251 return false;
252 }
253
254 for (size_t i = 0; i < mGbps.size(); i++) {
255 if (mGbps[i] != otherGbps[i]) {
256 return false;
257 }
258 }
259
260 return true;
261}
262
263bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
264 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
265 other.getGraphicBufferProducers();
266
267 if (mGbps.size() != otherGbps.size()) {
268 return mGbps.size() < otherGbps.size();
269 }
270
271 for (size_t i = 0; i < mGbps.size(); i++) {
272 if (mGbps[i] != otherGbps[i]) {
273 return mGbps[i] < otherGbps[i];
274 }
275 }
276
277 return false;
278}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700279}; // namespace android