blob: 321eb08beabff1c46e14c906dc2584af530edd1a [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
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080071OutputConfiguration::OutputConfiguration() :
72 mRotation(INVALID_ROTATION),
Zhijun He5d677d12016-05-29 16:52:39 -070073 mSurfaceSetID(INVALID_SET_ID),
74 mSurfaceType(SURFACE_TYPE_UNKNOWN),
75 mWidth(0),
Shuzhen Wang758c2152017-01-10 18:26:18 -080076 mHeight(0),
77 mIsDeferred(false),
78 mIsShared(false) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080079}
80
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080081OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) :
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080082 mRotation(INVALID_ROTATION),
83 mSurfaceSetID(INVALID_SET_ID) {
84 readFromParcel(&parcel);
85}
86
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -080087status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) {
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080088 status_t err = OK;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070089 int rotation = 0;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080090
91 if (parcel == nullptr) return BAD_VALUE;
92
93 if ((err = parcel->readInt32(&rotation)) != OK) {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070094 ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080095 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -070096 }
97
Zhijun He018107a2016-01-18 15:32:50 -080098 int setID = INVALID_SET_ID;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -080099 if ((err = parcel->readInt32(&setID)) != OK) {
Zhijun He018107a2016-01-18 15:32:50 -0800100 ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800101 return err;
Zhijun He018107a2016-01-18 15:32:50 -0800102 }
103
Zhijun He5d677d12016-05-29 16:52:39 -0700104 int surfaceType = SURFACE_TYPE_UNKNOWN;
105 if ((err = parcel->readInt32(&surfaceType)) != OK) {
106 ALOGE("%s: Failed to read surface type from parcel", __FUNCTION__);
107 return err;
108 }
109
110 int width = 0;
111 if ((err = parcel->readInt32(&width)) != OK) {
112 ALOGE("%s: Failed to read surface width from parcel", __FUNCTION__);
113 return err;
114 }
115
116 int height = 0;
117 if ((err = parcel->readInt32(&height)) != OK) {
118 ALOGE("%s: Failed to read surface height from parcel", __FUNCTION__);
119 return err;
120 }
121
Shuzhen Wang758c2152017-01-10 18:26:18 -0800122 int isDeferred = 0;
123 if ((err = parcel->readInt32(&isDeferred)) != OK) {
124 ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700125 return err;
126 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800127
128 int isShared = 0;
129 if ((err = parcel->readInt32(&isShared)) != OK) {
130 ALOGE("%s: Failed to read surface isShared flag from parcel", __FUNCTION__);
131 return err;
132 }
133
134 if (isDeferred && surfaceType != SURFACE_TYPE_SURFACE_VIEW &&
135 surfaceType != SURFACE_TYPE_SURFACE_TEXTURE) {
136 ALOGE("%s: Invalid surface type for deferred configuration", __FUNCTION__);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700137 return BAD_VALUE;
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800138 }
139
Shuzhen Wang758c2152017-01-10 18:26:18 -0800140 std::vector<view::Surface> surfaceShims;
141 if ((err = parcel->readParcelableVector(&surfaceShims)) != OK) {
142 ALOGE("%s: Failed to read surface(s) from parcel", __FUNCTION__);
143 return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700144 }
145
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800146 parcel->readString16(&mPhysicalCameraId);
147
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700148 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800149 mSurfaceSetID = setID;
Zhijun He5d677d12016-05-29 16:52:39 -0700150 mSurfaceType = surfaceType;
151 mWidth = width;
152 mHeight = height;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800153 mIsDeferred = isDeferred != 0;
154 mIsShared = isShared != 0;
155 for (auto& surface : surfaceShims) {
156 ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
157 surface.graphicBufferProducer.get(),
158 String8(surface.name).string());
159 mGbps.push_back(surface.graphicBufferProducer);
160 }
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700161
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800162 ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d,"
163 " physicalCameraId = %s", __FUNCTION__, mRotation, mSurfaceSetID,
164 mSurfaceType, String8(mPhysicalCameraId).string());
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800165
166 return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700167}
168
Zhijun He018107a2016-01-18 15:32:50 -0800169OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
Emilian Peev40ead602017-09-26 15:46:36 +0100170 int surfaceSetID, bool isShared) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700171 mGbps.push_back(gbp);
Ruben Brunk3450ba72015-06-16 11:00:37 -0700172 mRotation = rotation;
Zhijun He018107a2016-01-18 15:32:50 -0800173 mSurfaceSetID = surfaceSetID;
Shuzhen Wang758c2152017-01-10 18:26:18 -0800174 mIsDeferred = false;
Emilian Peev40ead602017-09-26 15:46:36 +0100175 mIsShared = isShared;
Ruben Brunk3450ba72015-06-16 11:00:37 -0700176}
177
Jayant Chowdharybe543d42018-08-15 13:16:14 -0700178OutputConfiguration::OutputConfiguration(
179 const std::vector<sp<IGraphicBufferProducer>>& gbps,
180 int rotation, int surfaceSetID, int surfaceType, int width, int height, bool isShared)
181 : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
182 mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared) { }
183
Eino-Ville Talvalaf51fca22016-12-13 11:25:55 -0800184status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const {
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700185
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800186 if (parcel == nullptr) return BAD_VALUE;
187 status_t err = OK;
188
189 err = parcel->writeInt32(mRotation);
190 if (err != OK) return err;
191
192 err = parcel->writeInt32(mSurfaceSetID);
193 if (err != OK) return err;
194
Zhijun He5d677d12016-05-29 16:52:39 -0700195 err = parcel->writeInt32(mSurfaceType);
196 if (err != OK) return err;
197
198 err = parcel->writeInt32(mWidth);
199 if (err != OK) return err;
200
201 err = parcel->writeInt32(mHeight);
202 if (err != OK) return err;
203
Shuzhen Wang758c2152017-01-10 18:26:18 -0800204 err = parcel->writeInt32(mIsDeferred ? 1 : 0);
Eino-Ville Talvalad56db1d2015-12-17 16:50:35 -0800205 if (err != OK) return err;
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700206
Shuzhen Wang758c2152017-01-10 18:26:18 -0800207 err = parcel->writeInt32(mIsShared ? 1 : 0);
208 if (err != OK) return err;
209
210 std::vector<view::Surface> surfaceShims;
211 for (auto& gbp : mGbps) {
Shuzhen Wang0129d522016-10-30 22:43:41 -0700212 view::Surface surfaceShim;
213 surfaceShim.name = String16("unknown_name"); // name of surface
Shuzhen Wang758c2152017-01-10 18:26:18 -0800214 surfaceShim.graphicBufferProducer = gbp;
215 surfaceShims.push_back(surfaceShim);
Shuzhen Wang0129d522016-10-30 22:43:41 -0700216 }
Shuzhen Wang758c2152017-01-10 18:26:18 -0800217 err = parcel->writeParcelableVector(surfaceShims);
218 if (err != OK) return err;
Shuzhen Wang0129d522016-10-30 22:43:41 -0700219
Shuzhen Wangc28189a2017-11-27 23:05:10 -0800220 err = parcel->writeString16(mPhysicalCameraId);
221 if (err != OK) return err;
222
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700223 return OK;
224}
225
Shuzhen Wang0129d522016-10-30 22:43:41 -0700226bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const {
227 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
228 other.getGraphicBufferProducers();
229
230 if (mGbps.size() != otherGbps.size()) {
231 return false;
232 }
233
234 for (size_t i = 0; i < mGbps.size(); i++) {
235 if (mGbps[i] != otherGbps[i]) {
236 return false;
237 }
238 }
239
240 return true;
241}
242
243bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const {
244 const std::vector<sp<IGraphicBufferProducer> >& otherGbps =
245 other.getGraphicBufferProducers();
246
247 if (mGbps.size() != otherGbps.size()) {
248 return mGbps.size() < otherGbps.size();
249 }
250
251 for (size_t i = 0; i < mGbps.size(); i++) {
252 if (mGbps[i] != otherGbps[i]) {
253 return mGbps[i] < otherGbps[i];
254 }
255 }
256
257 return false;
258}
Yin-Chia Yehb97babb2015-03-12 13:42:44 -0700259}; // namespace android