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 | |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 102 | String16 physicalCameraId; |
| 103 | if ((res = parcel->readString16(&physicalCameraId)) != OK) { |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 104 | ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res); |
| 105 | return res; |
| 106 | } |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 107 | mPhysicalCameraId = toStdString(physicalCameraId); |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 108 | |
Jayant Chowdhary | dcae796 | 2024-08-20 21:20:10 +0000 | [diff] [blame] | 109 | if ((res = mCameraMetadataInfo.readFromParcel(parcel)) != OK) { |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 110 | ALOGE("%s: Failed to read metadata from parcel: %d", __FUNCTION__, res); |
| 111 | return res; |
| 112 | } |
Jayant Chowdhary | dcae796 | 2024-08-20 21:20:10 +0000 | [diff] [blame] | 113 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 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 | } |
Jayant Chowdhary | dcae796 | 2024-08-20 21:20:10 +0000 | [diff] [blame] | 124 | |
| 125 | if ((res = mCameraMetadataInfo.writeToParcel(parcel)) != OK) { |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 126 | ALOGE("%s: Failed to write physical camera metadata to parcel: %d", |
| 127 | __FUNCTION__, res); |
| 128 | return res; |
| 129 | } |
Jayant Chowdhary | dcae796 | 2024-08-20 21:20:10 +0000 | [diff] [blame] | 130 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 131 | return OK; |
| 132 | } |
| 133 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 134 | CaptureResult::CaptureResult() : |
| 135 | mMetadata(), mResultExtras() { |
| 136 | } |
| 137 | |
Jayant Chowdhary | 8a0be29 | 2020-01-08 13:10:38 -0800 | [diff] [blame] | 138 | CaptureResult::CaptureResult(CaptureResult &&otherResult) { |
| 139 | mMetadata = std::move(otherResult.mMetadata); |
| 140 | mResultExtras = otherResult.mResultExtras; |
| 141 | mPhysicalMetadatas = std::move(otherResult.mPhysicalMetadatas); |
| 142 | } |
| 143 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 144 | CaptureResult::CaptureResult(const CaptureResult &otherResult) { |
| 145 | mResultExtras = otherResult.mResultExtras; |
| 146 | mMetadata = otherResult.mMetadata; |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 147 | mPhysicalMetadatas = otherResult.mPhysicalMetadatas; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 150 | status_t CaptureResult::readFromParcel(android::Parcel *parcel) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 151 | |
| 152 | ALOGV("%s: parcel = %p", __FUNCTION__, parcel); |
| 153 | |
| 154 | if (parcel == NULL) { |
| 155 | ALOGE("%s: parcel is null", __FUNCTION__); |
| 156 | return BAD_VALUE; |
| 157 | } |
| 158 | |
| 159 | mMetadata.clear(); |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 160 | mPhysicalMetadatas.clear(); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 161 | |
| 162 | status_t res = OK; |
| 163 | res = mMetadata.readFromParcel(parcel); |
| 164 | if (res != OK) { |
| 165 | ALOGE("%s: Failed to read metadata from parcel.", |
| 166 | __FUNCTION__); |
| 167 | return res; |
| 168 | } |
| 169 | ALOGV("%s: Read metadata from parcel", __FUNCTION__); |
| 170 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 171 | int32_t physicalMetadataCount; |
| 172 | if ((res = parcel->readInt32(&physicalMetadataCount)) != OK) { |
| 173 | ALOGE("%s: Failed to read the physical metadata count from parcel: %d", __FUNCTION__, res); |
| 174 | return res; |
| 175 | } |
| 176 | if (physicalMetadataCount < 0) { |
| 177 | ALOGE("%s: Invalid physical metadata count from parcel: %d", |
| 178 | __FUNCTION__, physicalMetadataCount); |
| 179 | return BAD_VALUE; |
| 180 | } |
| 181 | |
| 182 | for (int32_t i = 0; i < physicalMetadataCount; i++) { |
Jayant Chowdhary | dcae796 | 2024-08-20 21:20:10 +0000 | [diff] [blame] | 183 | PhysicalCaptureResultInfo result; |
| 184 | if ((res = result.readFromParcel(parcel)) != OK) { |
| 185 | ALOGE("%s: Failed to read physical result from parcel: %d", __FUNCTION__, res); |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 186 | return res; |
| 187 | } |
Jayant Chowdhary | dcae796 | 2024-08-20 21:20:10 +0000 | [diff] [blame] | 188 | mPhysicalMetadatas.emplace(mPhysicalMetadatas.end(), result); |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 189 | } |
| 190 | ALOGV("%s: Read physical metadata from parcel", __FUNCTION__); |
| 191 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 192 | res = mResultExtras.readFromParcel(parcel); |
| 193 | if (res != OK) { |
| 194 | ALOGE("%s: Failed to read result extras from parcel.", |
| 195 | __FUNCTION__); |
| 196 | return res; |
| 197 | } |
| 198 | ALOGV("%s: Read result extras from parcel", __FUNCTION__); |
| 199 | |
| 200 | return OK; |
| 201 | } |
| 202 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 203 | status_t CaptureResult::writeToParcel(android::Parcel *parcel) const { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 204 | |
| 205 | ALOGV("%s: parcel = %p", __FUNCTION__, parcel); |
| 206 | |
| 207 | if (parcel == NULL) { |
| 208 | ALOGE("%s: parcel is null", __FUNCTION__); |
| 209 | return BAD_VALUE; |
| 210 | } |
| 211 | |
| 212 | status_t res; |
| 213 | |
| 214 | res = mMetadata.writeToParcel(parcel); |
| 215 | if (res != OK) { |
| 216 | ALOGE("%s: Failed to write metadata to parcel", __FUNCTION__); |
| 217 | return res; |
| 218 | } |
| 219 | ALOGV("%s: Wrote metadata to parcel", __FUNCTION__); |
| 220 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 221 | int32_t physicalMetadataCount = static_cast<int32_t>(mPhysicalMetadatas.size()); |
| 222 | res = parcel->writeInt32(physicalMetadataCount); |
| 223 | if (res != OK) { |
| 224 | ALOGE("%s: Failed to write physical metadata count to parcel: %d", |
| 225 | __FUNCTION__, res); |
| 226 | return BAD_VALUE; |
| 227 | } |
| 228 | for (const auto& physicalMetadata : mPhysicalMetadatas) { |
Jayant Chowdhary | dcae796 | 2024-08-20 21:20:10 +0000 | [diff] [blame] | 229 | if ((res = physicalMetadata.writeToParcel(parcel)) != OK) { |
| 230 | ALOGE("%s: Failed to write physicalMetadata to parcel: %d", |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 231 | __FUNCTION__, res); |
| 232 | return res; |
| 233 | } |
| 234 | } |
| 235 | ALOGV("%s: Wrote physical camera metadata to parcel", __FUNCTION__); |
| 236 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 237 | res = mResultExtras.writeToParcel(parcel); |
| 238 | if (res != OK) { |
| 239 | ALOGE("%s: Failed to write result extras to parcel", __FUNCTION__); |
| 240 | return res; |
| 241 | } |
| 242 | ALOGV("%s: Wrote result extras to parcel", __FUNCTION__); |
| 243 | |
| 244 | return OK; |
| 245 | } |
| 246 | |
| 247 | } |