Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "Camera-CaptureResult" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include <camera/CaptureResult.h> |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 21 | #include <camera/StringUtils.h> |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 22 | #include <binder/Parcel.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | bool CaptureResultExtras::isValid() { |
| 27 | return requestId >= 0; |
| 28 | } |
| 29 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 30 | status_t CaptureResultExtras::readFromParcel(const android::Parcel *parcel) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 31 | if (parcel == NULL) { |
| 32 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 33 | return BAD_VALUE; |
| 34 | } |
| 35 | |
| 36 | parcel->readInt32(&requestId); |
| 37 | parcel->readInt32(&burstId); |
| 38 | parcel->readInt32(&afTriggerId); |
| 39 | parcel->readInt32(&precaptureTriggerId); |
| 40 | parcel->readInt64(&frameNumber); |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 41 | parcel->readInt32(&partialResultCount); |
Eino-Ville Talvala | e95bb63 | 2016-03-06 19:55:44 -0800 | [diff] [blame] | 42 | parcel->readInt32(&errorStreamId); |
Emilian Peev | edec62d | 2019-03-19 17:59:24 -0700 | [diff] [blame] | 43 | auto physicalCameraIdPresent = parcel->readBool(); |
| 44 | if (physicalCameraIdPresent) { |
| 45 | String16 cameraId; |
| 46 | status_t res = OK; |
| 47 | if ((res = parcel->readString16(&cameraId)) != OK) { |
| 48 | ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res); |
| 49 | return res; |
| 50 | } |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 51 | errorPhysicalCameraId = toStdString(cameraId); |
Emilian Peev | edec62d | 2019-03-19 17:59:24 -0700 | [diff] [blame] | 52 | } |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 53 | parcel->readInt64(&lastCompletedRegularFrameNumber); |
| 54 | parcel->readInt64(&lastCompletedReprocessFrameNumber); |
| 55 | parcel->readInt64(&lastCompletedZslFrameNumber); |
Shuzhen Wang | ffc4c01 | 2022-04-20 15:55:46 -0700 | [diff] [blame] | 56 | parcel->readBool(&hasReadoutTimestamp); |
| 57 | if (hasReadoutTimestamp) { |
| 58 | parcel->readInt64(&readoutTimestamp); |
| 59 | } |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 60 | return OK; |
| 61 | } |
| 62 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 63 | status_t CaptureResultExtras::writeToParcel(android::Parcel *parcel) const { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 64 | if (parcel == NULL) { |
| 65 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 66 | return BAD_VALUE; |
| 67 | } |
| 68 | |
| 69 | parcel->writeInt32(requestId); |
| 70 | parcel->writeInt32(burstId); |
| 71 | parcel->writeInt32(afTriggerId); |
| 72 | parcel->writeInt32(precaptureTriggerId); |
| 73 | parcel->writeInt64(frameNumber); |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 74 | parcel->writeInt32(partialResultCount); |
Eino-Ville Talvala | e95bb63 | 2016-03-06 19:55:44 -0800 | [diff] [blame] | 75 | parcel->writeInt32(errorStreamId); |
Emilian Peev | edec62d | 2019-03-19 17:59:24 -0700 | [diff] [blame] | 76 | if (errorPhysicalCameraId.size() > 0) { |
| 77 | parcel->writeBool(true); |
| 78 | status_t res = OK; |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 79 | if ((res = parcel->writeString16(toString16(errorPhysicalCameraId))) != OK) { |
Emilian Peev | edec62d | 2019-03-19 17:59:24 -0700 | [diff] [blame] | 80 | ALOGE("%s: Failed to write physical camera ID to parcel: %d", __FUNCTION__, res); |
| 81 | return res; |
| 82 | } |
| 83 | } else { |
| 84 | parcel->writeBool(false); |
| 85 | } |
Shuzhen Wang | b7b4265 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 86 | parcel->writeInt64(lastCompletedRegularFrameNumber); |
| 87 | parcel->writeInt64(lastCompletedReprocessFrameNumber); |
| 88 | parcel->writeInt64(lastCompletedZslFrameNumber); |
Shuzhen Wang | ffc4c01 | 2022-04-20 15:55:46 -0700 | [diff] [blame] | 89 | parcel->writeBool(hasReadoutTimestamp); |
| 90 | if (hasReadoutTimestamp) { |
| 91 | parcel->writeInt64(readoutTimestamp); |
| 92 | } |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 93 | |
| 94 | return OK; |
| 95 | } |
| 96 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 97 | status_t PhysicalCaptureResultInfo::readFromParcel(const android::Parcel* parcel) { |
| 98 | status_t res; |
| 99 | |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 100 | mPhysicalCameraId = ""; |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 101 | mPhysicalCameraMetadata.clear(); |
| 102 | |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 103 | String16 physicalCameraId; |
| 104 | if ((res = parcel->readString16(&physicalCameraId)) != OK) { |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 105 | ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res); |
| 106 | return res; |
| 107 | } |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 108 | mPhysicalCameraId = toStdString(physicalCameraId); |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 109 | |
| 110 | if ((res = mPhysicalCameraMetadata.readFromParcel(parcel)) != OK) { |
| 111 | ALOGE("%s: Failed to read metadata from parcel: %d", __FUNCTION__, res); |
| 112 | return res; |
| 113 | } |
| 114 | return OK; |
| 115 | } |
| 116 | |
| 117 | status_t PhysicalCaptureResultInfo::writeToParcel(android::Parcel* parcel) const { |
| 118 | status_t res; |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 119 | if ((res = parcel->writeString16(toString16(mPhysicalCameraId))) != OK) { |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 120 | ALOGE("%s: Failed to write physical camera ID to parcel: %d", |
| 121 | __FUNCTION__, res); |
| 122 | return res; |
| 123 | } |
| 124 | if ((res = mPhysicalCameraMetadata.writeToParcel(parcel)) != OK) { |
| 125 | ALOGE("%s: Failed to write physical camera metadata to parcel: %d", |
| 126 | __FUNCTION__, res); |
| 127 | return res; |
| 128 | } |
| 129 | return OK; |
| 130 | } |
| 131 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 132 | CaptureResult::CaptureResult() : |
| 133 | mMetadata(), mResultExtras() { |
| 134 | } |
| 135 | |
Jayant Chowdhary | 8a0be29 | 2020-01-08 13:10:38 -0800 | [diff] [blame] | 136 | CaptureResult::CaptureResult(CaptureResult &&otherResult) { |
| 137 | mMetadata = std::move(otherResult.mMetadata); |
| 138 | mResultExtras = otherResult.mResultExtras; |
| 139 | mPhysicalMetadatas = std::move(otherResult.mPhysicalMetadatas); |
| 140 | } |
| 141 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 142 | CaptureResult::CaptureResult(const CaptureResult &otherResult) { |
| 143 | mResultExtras = otherResult.mResultExtras; |
| 144 | mMetadata = otherResult.mMetadata; |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 145 | mPhysicalMetadatas = otherResult.mPhysicalMetadatas; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 146 | } |
| 147 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 148 | status_t CaptureResult::readFromParcel(android::Parcel *parcel) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 149 | |
| 150 | ALOGV("%s: parcel = %p", __FUNCTION__, parcel); |
| 151 | |
| 152 | if (parcel == NULL) { |
| 153 | ALOGE("%s: parcel is null", __FUNCTION__); |
| 154 | return BAD_VALUE; |
| 155 | } |
| 156 | |
| 157 | mMetadata.clear(); |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 158 | mPhysicalMetadatas.clear(); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 159 | |
| 160 | status_t res = OK; |
| 161 | res = mMetadata.readFromParcel(parcel); |
| 162 | if (res != OK) { |
| 163 | ALOGE("%s: Failed to read metadata from parcel.", |
| 164 | __FUNCTION__); |
| 165 | return res; |
| 166 | } |
| 167 | ALOGV("%s: Read metadata from parcel", __FUNCTION__); |
| 168 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 169 | int32_t physicalMetadataCount; |
| 170 | if ((res = parcel->readInt32(&physicalMetadataCount)) != OK) { |
| 171 | ALOGE("%s: Failed to read the physical metadata count from parcel: %d", __FUNCTION__, res); |
| 172 | return res; |
| 173 | } |
| 174 | if (physicalMetadataCount < 0) { |
| 175 | ALOGE("%s: Invalid physical metadata count from parcel: %d", |
| 176 | __FUNCTION__, physicalMetadataCount); |
| 177 | return BAD_VALUE; |
| 178 | } |
| 179 | |
| 180 | for (int32_t i = 0; i < physicalMetadataCount; i++) { |
| 181 | String16 cameraId; |
| 182 | if ((res = parcel->readString16(&cameraId)) != OK) { |
| 183 | ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res); |
| 184 | return res; |
| 185 | } |
| 186 | |
| 187 | CameraMetadata physicalMetadata; |
| 188 | if ((res = physicalMetadata.readFromParcel(parcel)) != OK) { |
| 189 | ALOGE("%s: Failed to read metadata from parcel: %d", __FUNCTION__, res); |
| 190 | return res; |
| 191 | } |
| 192 | |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 193 | mPhysicalMetadatas.emplace(mPhysicalMetadatas.end(), toStdString(cameraId), |
| 194 | physicalMetadata); |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 195 | } |
| 196 | ALOGV("%s: Read physical metadata from parcel", __FUNCTION__); |
| 197 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 198 | res = mResultExtras.readFromParcel(parcel); |
| 199 | if (res != OK) { |
| 200 | ALOGE("%s: Failed to read result extras from parcel.", |
| 201 | __FUNCTION__); |
| 202 | return res; |
| 203 | } |
| 204 | ALOGV("%s: Read result extras from parcel", __FUNCTION__); |
| 205 | |
| 206 | return OK; |
| 207 | } |
| 208 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 209 | status_t CaptureResult::writeToParcel(android::Parcel *parcel) const { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 210 | |
| 211 | ALOGV("%s: parcel = %p", __FUNCTION__, parcel); |
| 212 | |
| 213 | if (parcel == NULL) { |
| 214 | ALOGE("%s: parcel is null", __FUNCTION__); |
| 215 | return BAD_VALUE; |
| 216 | } |
| 217 | |
| 218 | status_t res; |
| 219 | |
| 220 | res = mMetadata.writeToParcel(parcel); |
| 221 | if (res != OK) { |
| 222 | ALOGE("%s: Failed to write metadata to parcel", __FUNCTION__); |
| 223 | return res; |
| 224 | } |
| 225 | ALOGV("%s: Wrote metadata to parcel", __FUNCTION__); |
| 226 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 227 | int32_t physicalMetadataCount = static_cast<int32_t>(mPhysicalMetadatas.size()); |
| 228 | res = parcel->writeInt32(physicalMetadataCount); |
| 229 | if (res != OK) { |
| 230 | ALOGE("%s: Failed to write physical metadata count to parcel: %d", |
| 231 | __FUNCTION__, res); |
| 232 | return BAD_VALUE; |
| 233 | } |
| 234 | for (const auto& physicalMetadata : mPhysicalMetadatas) { |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 235 | if ((res = parcel->writeString16(toString16(physicalMetadata.mPhysicalCameraId))) != OK) { |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 236 | ALOGE("%s: Failed to write physical camera ID to parcel: %d", |
| 237 | __FUNCTION__, res); |
| 238 | return res; |
| 239 | } |
| 240 | if ((res = physicalMetadata.mPhysicalCameraMetadata.writeToParcel(parcel)) != OK) { |
| 241 | ALOGE("%s: Failed to write physical camera metadata to parcel: %d", |
| 242 | __FUNCTION__, res); |
| 243 | return res; |
| 244 | } |
| 245 | } |
| 246 | ALOGV("%s: Wrote physical camera metadata to parcel", __FUNCTION__); |
| 247 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 248 | res = mResultExtras.writeToParcel(parcel); |
| 249 | if (res != OK) { |
| 250 | ALOGE("%s: Failed to write result extras to parcel", __FUNCTION__); |
| 251 | return res; |
| 252 | } |
| 253 | ALOGV("%s: Wrote result extras to parcel", __FUNCTION__); |
| 254 | |
| 255 | return OK; |
| 256 | } |
| 257 | |
| 258 | } |