| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | ** | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 3 | ** Copyright 2015-2018, The Android Open Source Project | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 4 | ** | 
|  | 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 Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 19 | //#define LOG_NDEBUG 0 | 
|  | 20 |  | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 21 | #include <utils/Log.h> | 
|  | 22 |  | 
|  | 23 | #include <camera/camera2/OutputConfiguration.h> | 
|  | 24 | #include <binder/Parcel.h> | 
| Mathias Agopian | 032845c | 2017-02-08 17:05:02 -0800 | [diff] [blame] | 25 | #include <gui/view/Surface.h> | 
| Brian Anderson | f675356 | 2016-10-11 14:51:05 -0700 | [diff] [blame] | 26 | #include <utils/String8.h> | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 27 |  | 
|  | 28 | namespace android { | 
|  | 29 |  | 
|  | 30 |  | 
|  | 31 | const int OutputConfiguration::INVALID_ROTATION = -1; | 
| Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 32 | const int OutputConfiguration::INVALID_SET_ID = -1; | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 33 |  | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 34 | const std::vector<sp<IGraphicBufferProducer>>& | 
|  | 35 | OutputConfiguration::getGraphicBufferProducers() const { | 
|  | 36 | return mGbps; | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 37 | } | 
|  | 38 |  | 
|  | 39 | int OutputConfiguration::getRotation() const { | 
|  | 40 | return mRotation; | 
|  | 41 | } | 
|  | 42 |  | 
| Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 43 | int OutputConfiguration::getSurfaceSetID() const { | 
|  | 44 | return mSurfaceSetID; | 
|  | 45 | } | 
|  | 46 |  | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 47 | int OutputConfiguration::getSurfaceType() const { | 
|  | 48 | return mSurfaceType; | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | int OutputConfiguration::getWidth() const { | 
|  | 52 | return mWidth; | 
|  | 53 | } | 
|  | 54 |  | 
|  | 55 | int OutputConfiguration::getHeight() const { | 
|  | 56 | return mHeight; | 
|  | 57 | } | 
|  | 58 |  | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 59 | bool OutputConfiguration::isDeferred() const { | 
|  | 60 | return mIsDeferred; | 
|  | 61 | } | 
|  | 62 |  | 
|  | 63 | bool OutputConfiguration::isShared() const { | 
|  | 64 | return mIsShared; | 
|  | 65 | } | 
|  | 66 |  | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 67 | String16 OutputConfiguration::getPhysicalCameraId() const { | 
|  | 68 | return mPhysicalCameraId; | 
|  | 69 | } | 
|  | 70 |  | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 71 | OutputConfiguration::OutputConfiguration() : | 
|  | 72 | mRotation(INVALID_ROTATION), | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 73 | mSurfaceSetID(INVALID_SET_ID), | 
|  | 74 | mSurfaceType(SURFACE_TYPE_UNKNOWN), | 
|  | 75 | mWidth(0), | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 76 | mHeight(0), | 
|  | 77 | mIsDeferred(false), | 
|  | 78 | mIsShared(false) { | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 79 | } | 
|  | 80 |  | 
| Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 81 | OutputConfiguration::OutputConfiguration(const android::Parcel& parcel) : | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 82 | mRotation(INVALID_ROTATION), | 
|  | 83 | mSurfaceSetID(INVALID_SET_ID) { | 
|  | 84 | readFromParcel(&parcel); | 
|  | 85 | } | 
|  | 86 |  | 
| Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 87 | status_t OutputConfiguration::readFromParcel(const android::Parcel* parcel) { | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 88 | status_t err = OK; | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 89 | int rotation = 0; | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 90 |  | 
|  | 91 | if (parcel == nullptr) return BAD_VALUE; | 
|  | 92 |  | 
|  | 93 | if ((err = parcel->readInt32(&rotation)) != OK) { | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 94 | ALOGE("%s: Failed to read rotation from parcel", __FUNCTION__); | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 95 | return err; | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 96 | } | 
|  | 97 |  | 
| Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 98 | int setID = INVALID_SET_ID; | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 99 | if ((err = parcel->readInt32(&setID)) != OK) { | 
| Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 100 | ALOGE("%s: Failed to read surface set ID from parcel", __FUNCTION__); | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 101 | return err; | 
| Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 102 | } | 
|  | 103 |  | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 104 | 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 Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 122 | int isDeferred = 0; | 
|  | 123 | if ((err = parcel->readInt32(&isDeferred)) != OK) { | 
|  | 124 | ALOGE("%s: Failed to read surface isDeferred flag from parcel", __FUNCTION__); | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 125 | return err; | 
|  | 126 | } | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 127 |  | 
|  | 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 Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 137 | return BAD_VALUE; | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 138 | } | 
|  | 139 |  | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 140 | 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 Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 144 | } | 
|  | 145 |  | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 146 | parcel->readString16(&mPhysicalCameraId); | 
|  | 147 |  | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 148 | mRotation = rotation; | 
| Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 149 | mSurfaceSetID = setID; | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 150 | mSurfaceType = surfaceType; | 
|  | 151 | mWidth = width; | 
|  | 152 | mHeight = height; | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 153 | 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 Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 161 |  | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 162 | ALOGV("%s: OutputConfiguration: rotation = %d, setId = %d, surfaceType = %d," | 
|  | 163 | " physicalCameraId = %s", __FUNCTION__, mRotation, mSurfaceSetID, | 
|  | 164 | mSurfaceType, String8(mPhysicalCameraId).string()); | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 165 |  | 
|  | 166 | return err; | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 167 | } | 
|  | 168 |  | 
| Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 169 | OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation, | 
| Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 170 | const String16& physicalId, | 
| Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 171 | int surfaceSetID, bool isShared) { | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 172 | mGbps.push_back(gbp); | 
| Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 173 | mRotation = rotation; | 
| Zhijun He | 018107a | 2016-01-18 15:32:50 -0800 | [diff] [blame] | 174 | mSurfaceSetID = surfaceSetID; | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 175 | mIsDeferred = false; | 
| Emilian Peev | 40ead60 | 2017-09-26 15:46:36 +0100 | [diff] [blame] | 176 | mIsShared = isShared; | 
| Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 177 | mPhysicalCameraId = physicalId; | 
| Ruben Brunk | 3450ba7 | 2015-06-16 11:00:37 -0700 | [diff] [blame] | 178 | } | 
|  | 179 |  | 
| Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 180 | OutputConfiguration::OutputConfiguration( | 
|  | 181 | const std::vector<sp<IGraphicBufferProducer>>& gbps, | 
| Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 182 | int rotation, const String16& physicalCameraId, int surfaceSetID,  int surfaceType, | 
|  | 183 | int width, int height, bool isShared) | 
| Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 184 | : mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType), | 
| Shuzhen Wang | 0ff9ae3 | 2018-12-05 18:06:12 -0800 | [diff] [blame] | 185 | mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared), | 
|  | 186 | mPhysicalCameraId(physicalCameraId) { } | 
| Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 187 |  | 
| Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 188 | status_t OutputConfiguration::writeToParcel(android::Parcel* parcel) const { | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 189 |  | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 190 | if (parcel == nullptr) return BAD_VALUE; | 
|  | 191 | status_t err = OK; | 
|  | 192 |  | 
|  | 193 | err = parcel->writeInt32(mRotation); | 
|  | 194 | if (err != OK) return err; | 
|  | 195 |  | 
|  | 196 | err = parcel->writeInt32(mSurfaceSetID); | 
|  | 197 | if (err != OK) return err; | 
|  | 198 |  | 
| Zhijun He | 5d677d1 | 2016-05-29 16:52:39 -0700 | [diff] [blame] | 199 | err = parcel->writeInt32(mSurfaceType); | 
|  | 200 | if (err != OK) return err; | 
|  | 201 |  | 
|  | 202 | err = parcel->writeInt32(mWidth); | 
|  | 203 | if (err != OK) return err; | 
|  | 204 |  | 
|  | 205 | err = parcel->writeInt32(mHeight); | 
|  | 206 | if (err != OK) return err; | 
|  | 207 |  | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 208 | err = parcel->writeInt32(mIsDeferred ? 1 : 0); | 
| Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 209 | if (err != OK) return err; | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 210 |  | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 211 | err = parcel->writeInt32(mIsShared ? 1 : 0); | 
|  | 212 | if (err != OK) return err; | 
|  | 213 |  | 
|  | 214 | std::vector<view::Surface> surfaceShims; | 
|  | 215 | for (auto& gbp : mGbps) { | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 216 | view::Surface surfaceShim; | 
|  | 217 | surfaceShim.name = String16("unknown_name"); // name of surface | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 218 | surfaceShim.graphicBufferProducer = gbp; | 
|  | 219 | surfaceShims.push_back(surfaceShim); | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 220 | } | 
| Shuzhen Wang | 758c215 | 2017-01-10 18:26:18 -0800 | [diff] [blame] | 221 | err = parcel->writeParcelableVector(surfaceShims); | 
|  | 222 | if (err != OK) return err; | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 223 |  | 
| Shuzhen Wang | c28189a | 2017-11-27 23:05:10 -0800 | [diff] [blame] | 224 | err = parcel->writeString16(mPhysicalCameraId); | 
|  | 225 | if (err != OK) return err; | 
|  | 226 |  | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 227 | return OK; | 
|  | 228 | } | 
|  | 229 |  | 
| Shuzhen Wang | 0129d52 | 2016-10-30 22:43:41 -0700 | [diff] [blame] | 230 | bool OutputConfiguration::gbpsEqual(const OutputConfiguration& other) const { | 
|  | 231 | const std::vector<sp<IGraphicBufferProducer> >& otherGbps = | 
|  | 232 | other.getGraphicBufferProducers(); | 
|  | 233 |  | 
|  | 234 | if (mGbps.size() != otherGbps.size()) { | 
|  | 235 | return false; | 
|  | 236 | } | 
|  | 237 |  | 
|  | 238 | for (size_t i = 0; i < mGbps.size(); i++) { | 
|  | 239 | if (mGbps[i] != otherGbps[i]) { | 
|  | 240 | return false; | 
|  | 241 | } | 
|  | 242 | } | 
|  | 243 |  | 
|  | 244 | return true; | 
|  | 245 | } | 
|  | 246 |  | 
|  | 247 | bool OutputConfiguration::gbpsLessThan(const OutputConfiguration& other) const { | 
|  | 248 | const std::vector<sp<IGraphicBufferProducer> >& otherGbps = | 
|  | 249 | other.getGraphicBufferProducers(); | 
|  | 250 |  | 
|  | 251 | if (mGbps.size() !=  otherGbps.size()) { | 
|  | 252 | return mGbps.size() < otherGbps.size(); | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 | for (size_t i = 0; i < mGbps.size(); i++) { | 
|  | 256 | if (mGbps[i] != otherGbps[i]) { | 
|  | 257 | return mGbps[i] < otherGbps[i]; | 
|  | 258 | } | 
|  | 259 | } | 
|  | 260 |  | 
|  | 261 | return false; | 
|  | 262 | } | 
| Yin-Chia Yeh | b97babb | 2015-03-12 13:42:44 -0700 | [diff] [blame] | 263 | }; // namespace android |