Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2013, The Android Open Source Project |
| 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_NDEBUG 0 |
| 19 | #define LOG_TAG "CameraRequest" |
| 20 | #include <utils/Log.h> |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 21 | #include <utils/String16.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 22 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 23 | #include <camera/camera2/CaptureRequest.h> |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 24 | #include <camera/StringUtils.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 25 | |
| 26 | #include <binder/Parcel.h> |
Carlos Martinez Romero | c45bc93 | 2024-10-09 15:04:51 -0700 | [diff] [blame] | 27 | #include <gui/Flags.h> // remove with WB_LIBCAMERASERVICE_WITH_DEPENDENCIES |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 28 | #include <gui/Surface.h> |
Mathias Agopian | 032845c | 2017-02-08 17:05:02 -0800 | [diff] [blame] | 29 | #include <gui/view/Surface.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 32 | namespace hardware { |
| 33 | namespace camera2 { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 34 | |
Mathias Agopian | 032845c | 2017-02-08 17:05:02 -0800 | [diff] [blame] | 35 | // These must be in the .cpp (to avoid inlining) |
| 36 | CaptureRequest::CaptureRequest() = default; |
| 37 | CaptureRequest::~CaptureRequest() = default; |
| 38 | CaptureRequest::CaptureRequest(const CaptureRequest& rhs) = default; |
| 39 | CaptureRequest::CaptureRequest(CaptureRequest&& rhs) noexcept = default; |
| 40 | |
| 41 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 42 | status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 43 | if (parcel == NULL) { |
| 44 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 45 | return BAD_VALUE; |
| 46 | } |
| 47 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 48 | mSurfaceList.clear(); |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 49 | mStreamIdxList.clear(); |
| 50 | mSurfaceIdxList.clear(); |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 51 | mPhysicalCameraSettings.clear(); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 52 | |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 53 | status_t err = OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 54 | |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 55 | int32_t settingsCount; |
| 56 | if ((err = parcel->readInt32(&settingsCount)) != OK) { |
| 57 | ALOGE("%s: Failed to read the settings count from parcel: %d", __FUNCTION__, err); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 58 | return err; |
| 59 | } |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 60 | |
| 61 | if (settingsCount <= 0) { |
| 62 | ALOGE("%s: Settings count %d should always be positive!", __FUNCTION__, settingsCount); |
| 63 | return BAD_VALUE; |
| 64 | } |
| 65 | |
| 66 | for (int32_t i = 0; i < settingsCount; i++) { |
| 67 | String16 id; |
| 68 | if ((err = parcel->readString16(&id)) != OK) { |
| 69 | ALOGE("%s: Failed to read camera id!", __FUNCTION__); |
| 70 | return BAD_VALUE; |
| 71 | } |
| 72 | |
| 73 | CameraMetadata settings; |
| 74 | if ((err = settings.readFromParcel(parcel)) != OK) { |
| 75 | ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__); |
| 76 | return err; |
| 77 | } |
| 78 | ALOGV("%s: Read metadata from parcel", __FUNCTION__); |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 79 | mPhysicalCameraSettings.push_back({toStdString(id), settings}); |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 80 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 81 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 82 | int isReprocess = 0; |
| 83 | if ((err = parcel->readInt32(&isReprocess)) != OK) { |
| 84 | ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__); |
| 85 | return err; |
| 86 | } |
| 87 | mIsReprocess = (isReprocess != 0); |
| 88 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 89 | int32_t size; |
| 90 | if ((err = parcel->readInt32(&size)) != OK) { |
| 91 | ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__); |
| 92 | return err; |
| 93 | } |
| 94 | ALOGV("%s: Read surface list size = %d", __FUNCTION__, size); |
| 95 | |
| 96 | // Do not distinguish null arrays from 0-sized arrays. |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 97 | for (int32_t i = 0; i < size; ++i) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 98 | // Parcel.writeParcelableArray |
Steven Moreland | 6faf8ed | 2020-11-04 23:55:40 +0000 | [diff] [blame] | 99 | std::optional<std::string> className; |
| 100 | parcel->readUtf8FromUtf16(&className); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 101 | ALOGV("%s: Read surface class = %s", __FUNCTION__, |
Steven Moreland | 6faf8ed | 2020-11-04 23:55:40 +0000 | [diff] [blame] | 102 | className.value_or("<null>").c_str()); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 103 | |
Steven Moreland | 6faf8ed | 2020-11-04 23:55:40 +0000 | [diff] [blame] | 104 | if (className == std::nullopt) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 105 | continue; |
| 106 | } |
| 107 | |
| 108 | // Surface.writeToParcel |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 109 | view::Surface surfaceShim; |
| 110 | if ((err = surfaceShim.readFromParcel(parcel)) != OK) { |
| 111 | ALOGE("%s: Failed to read output target Surface %d from parcel: %s (%d)", |
| 112 | __FUNCTION__, i, strerror(-err), err); |
| 113 | return err; |
| 114 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 115 | |
Carlos Martinez Romero | c45bc93 | 2024-10-09 15:04:51 -0700 | [diff] [blame] | 116 | #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES |
| 117 | sp<Surface> surface = surfaceShim.toSurface(); |
| 118 | #else |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 119 | sp<Surface> surface; |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 120 | if (surfaceShim.graphicBufferProducer != NULL) { |
| 121 | surface = new Surface(surfaceShim.graphicBufferProducer); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 122 | } |
Carlos Martinez Romero | c45bc93 | 2024-10-09 15:04:51 -0700 | [diff] [blame] | 123 | #endif |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 124 | mSurfaceList.push_back(surface); |
| 125 | } |
| 126 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 127 | int32_t streamSurfaceSize; |
| 128 | if ((err = parcel->readInt32(&streamSurfaceSize)) != OK) { |
| 129 | ALOGE("%s: Failed to read streamSurfaceSize from parcel", __FUNCTION__); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 130 | return err; |
| 131 | } |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 132 | |
| 133 | if (streamSurfaceSize < 0) { |
| 134 | ALOGE("%s: Bad streamSurfaceSize %d from parcel", __FUNCTION__, streamSurfaceSize); |
| 135 | return BAD_VALUE; |
| 136 | } |
| 137 | |
| 138 | for (int32_t i = 0; i < streamSurfaceSize; ++i) { |
| 139 | int streamIdx; |
| 140 | if ((err = parcel->readInt32(&streamIdx)) != OK) { |
| 141 | ALOGE("%s: Failed to read stream index from parcel", __FUNCTION__); |
| 142 | return err; |
| 143 | } |
| 144 | mStreamIdxList.push_back(streamIdx); |
| 145 | |
| 146 | int surfaceIdx; |
| 147 | if ((err = parcel->readInt32(&surfaceIdx)) != OK) { |
| 148 | ALOGE("%s: Failed to read surface index from parcel", __FUNCTION__); |
| 149 | return err; |
| 150 | } |
| 151 | mSurfaceIdxList.push_back(surfaceIdx); |
| 152 | } |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 153 | |
Shuzhen Wang | d26b186 | 2022-03-07 12:05:05 -0800 | [diff] [blame] | 154 | int32_t hasUserTag; |
| 155 | if ((err = parcel->readInt32(&hasUserTag)) != OK) { |
| 156 | ALOGE("%s: Failed to read user tag availability flag", __FUNCTION__); |
| 157 | return BAD_VALUE; |
| 158 | } |
| 159 | if (hasUserTag) { |
| 160 | String16 userTag; |
| 161 | if ((err = parcel->readString16(&userTag)) != OK) { |
| 162 | ALOGE("%s: Failed to read user tag!", __FUNCTION__); |
| 163 | return BAD_VALUE; |
| 164 | } |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 165 | mUserTag = toStdString(userTag); |
Shuzhen Wang | d26b186 | 2022-03-07 12:05:05 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 168 | return OK; |
| 169 | } |
| 170 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 171 | status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 172 | if (parcel == NULL) { |
| 173 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 174 | return BAD_VALUE; |
| 175 | } |
| 176 | |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 177 | status_t err = OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 178 | |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 179 | int32_t settingsCount = static_cast<int32_t>(mPhysicalCameraSettings.size()); |
| 180 | |
| 181 | if ((err = parcel->writeInt32(settingsCount)) != OK) { |
| 182 | ALOGE("%s: Failed to write settings count!", __FUNCTION__); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 183 | return err; |
| 184 | } |
| 185 | |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 186 | for (const auto &it : mPhysicalCameraSettings) { |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 187 | if ((err = parcel->writeString16(toString16(it.id))) != OK) { |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 188 | ALOGE("%s: Failed to camera id!", __FUNCTION__); |
| 189 | return err; |
| 190 | } |
| 191 | |
| 192 | if ((err = it.settings.writeToParcel(parcel)) != OK) { |
| 193 | ALOGE("%s: Failed to write settings!", __FUNCTION__); |
| 194 | return err; |
| 195 | } |
| 196 | } |
| 197 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 198 | parcel->writeInt32(mIsReprocess ? 1 : 0); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 199 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 200 | if (mSurfaceConverted) { |
| 201 | parcel->writeInt32(0); // 0-sized array |
| 202 | } else { |
| 203 | int32_t size = static_cast<int32_t>(mSurfaceList.size()); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 204 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 205 | // Send 0-sized arrays when it's empty. Do not send null arrays. |
| 206 | parcel->writeInt32(size); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 207 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 208 | for (int32_t i = 0; i < size; ++i) { |
| 209 | // not sure if readParcelableArray does this, hard to tell from source |
| 210 | parcel->writeString16(String16("android.view.Surface")); |
| 211 | |
| 212 | // Surface.writeToParcel |
Carlos Martinez Romero | c45bc93 | 2024-10-09 15:04:51 -0700 | [diff] [blame] | 213 | #if WB_LIBCAMERASERVICE_WITH_DEPENDENCIES |
| 214 | view::Surface surfaceShim = view::Surface::fromSurface(mSurfaceList[i]); |
| 215 | #else |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 216 | view::Surface surfaceShim; |
| 217 | surfaceShim.name = String16("unknown_name"); |
| 218 | surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer(); |
Carlos Martinez Romero | c45bc93 | 2024-10-09 15:04:51 -0700 | [diff] [blame] | 219 | #endif |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 220 | if ((err = surfaceShim.writeToParcel(parcel)) != OK) { |
| 221 | ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)", |
| 222 | __FUNCTION__, i, strerror(-err), err); |
| 223 | return err; |
| 224 | } |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 225 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 228 | parcel->writeInt32(mStreamIdxList.size()); |
| 229 | for (size_t i = 0; i < mStreamIdxList.size(); ++i) { |
| 230 | if ((err = parcel->writeInt32(mStreamIdxList[i])) != OK) { |
| 231 | ALOGE("%s: Failed to write stream index to parcel", __FUNCTION__); |
| 232 | return err; |
| 233 | } |
| 234 | if ((err = parcel->writeInt32(mSurfaceIdxList[i])) != OK) { |
| 235 | ALOGE("%s: Failed to write surface index to parcel", __FUNCTION__); |
| 236 | return err; |
| 237 | } |
| 238 | } |
Shuzhen Wang | d26b186 | 2022-03-07 12:05:05 -0800 | [diff] [blame] | 239 | |
| 240 | if (mUserTag.empty()) { |
| 241 | parcel->writeInt32(0); |
| 242 | } else { |
| 243 | parcel->writeInt32(1); |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 244 | parcel->writeString16(toString16(mUserTag)); |
Shuzhen Wang | d26b186 | 2022-03-07 12:05:05 -0800 | [diff] [blame] | 245 | } |
| 246 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 247 | return OK; |
| 248 | } |
| 249 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 250 | } // namespace camera2 |
| 251 | } // namespace hardware |
| 252 | } // namespace android |