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> |
| 21 | #include <binder/Parcel.h> |
| 22 | |
| 23 | namespace android { |
| 24 | |
| 25 | bool CaptureResultExtras::isValid() { |
| 26 | return requestId >= 0; |
| 27 | } |
| 28 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 29 | status_t CaptureResultExtras::readFromParcel(const android::Parcel *parcel) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 30 | if (parcel == NULL) { |
| 31 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 32 | return BAD_VALUE; |
| 33 | } |
| 34 | |
| 35 | parcel->readInt32(&requestId); |
| 36 | parcel->readInt32(&burstId); |
| 37 | parcel->readInt32(&afTriggerId); |
| 38 | parcel->readInt32(&precaptureTriggerId); |
| 39 | parcel->readInt64(&frameNumber); |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 40 | parcel->readInt32(&partialResultCount); |
Eino-Ville Talvala | e95bb63 | 2016-03-06 19:55:44 -0800 | [diff] [blame] | 41 | parcel->readInt32(&errorStreamId); |
Emilian Peev | edec62d | 2019-03-19 17:59:24 -0700 | [diff] [blame] | 42 | auto physicalCameraIdPresent = parcel->readBool(); |
| 43 | if (physicalCameraIdPresent) { |
| 44 | String16 cameraId; |
| 45 | status_t res = OK; |
| 46 | if ((res = parcel->readString16(&cameraId)) != OK) { |
| 47 | ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res); |
| 48 | return res; |
| 49 | } |
| 50 | errorPhysicalCameraId = cameraId; |
| 51 | } |
Shuzhen Wang | 730a791 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 52 | parcel->readInt64(&lastCompletedRegularFrameNumber); |
| 53 | parcel->readInt64(&lastCompletedReprocessFrameNumber); |
| 54 | parcel->readInt64(&lastCompletedZslFrameNumber); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 55 | |
| 56 | return OK; |
| 57 | } |
| 58 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 59 | status_t CaptureResultExtras::writeToParcel(android::Parcel *parcel) const { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 60 | if (parcel == NULL) { |
| 61 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 62 | return BAD_VALUE; |
| 63 | } |
| 64 | |
| 65 | parcel->writeInt32(requestId); |
| 66 | parcel->writeInt32(burstId); |
| 67 | parcel->writeInt32(afTriggerId); |
| 68 | parcel->writeInt32(precaptureTriggerId); |
| 69 | parcel->writeInt64(frameNumber); |
Zhijun He | 204e329 | 2014-07-14 17:09:23 -0700 | [diff] [blame] | 70 | parcel->writeInt32(partialResultCount); |
Eino-Ville Talvala | e95bb63 | 2016-03-06 19:55:44 -0800 | [diff] [blame] | 71 | parcel->writeInt32(errorStreamId); |
Emilian Peev | edec62d | 2019-03-19 17:59:24 -0700 | [diff] [blame] | 72 | if (errorPhysicalCameraId.size() > 0) { |
| 73 | parcel->writeBool(true); |
| 74 | status_t res = OK; |
| 75 | if ((res = parcel->writeString16(errorPhysicalCameraId)) != OK) { |
| 76 | ALOGE("%s: Failed to write physical camera ID to parcel: %d", __FUNCTION__, res); |
| 77 | return res; |
| 78 | } |
| 79 | } else { |
| 80 | parcel->writeBool(false); |
| 81 | } |
Shuzhen Wang | 730a791 | 2020-05-07 11:59:02 -0700 | [diff] [blame] | 82 | parcel->writeInt64(lastCompletedRegularFrameNumber); |
| 83 | parcel->writeInt64(lastCompletedReprocessFrameNumber); |
| 84 | parcel->writeInt64(lastCompletedZslFrameNumber); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 85 | |
| 86 | return OK; |
| 87 | } |
| 88 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 89 | status_t PhysicalCaptureResultInfo::readFromParcel(const android::Parcel* parcel) { |
| 90 | status_t res; |
| 91 | |
| 92 | mPhysicalCameraId.remove(mPhysicalCameraId.size()); |
| 93 | mPhysicalCameraMetadata.clear(); |
| 94 | |
| 95 | if ((res = parcel->readString16(&mPhysicalCameraId)) != OK) { |
| 96 | ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res); |
| 97 | return res; |
| 98 | } |
| 99 | |
| 100 | if ((res = mPhysicalCameraMetadata.readFromParcel(parcel)) != OK) { |
| 101 | ALOGE("%s: Failed to read metadata from parcel: %d", __FUNCTION__, res); |
| 102 | return res; |
| 103 | } |
| 104 | return OK; |
| 105 | } |
| 106 | |
| 107 | status_t PhysicalCaptureResultInfo::writeToParcel(android::Parcel* parcel) const { |
| 108 | status_t res; |
| 109 | if ((res = parcel->writeString16(mPhysicalCameraId)) != OK) { |
| 110 | ALOGE("%s: Failed to write physical camera ID to parcel: %d", |
| 111 | __FUNCTION__, res); |
| 112 | return res; |
| 113 | } |
| 114 | if ((res = mPhysicalCameraMetadata.writeToParcel(parcel)) != OK) { |
| 115 | ALOGE("%s: Failed to write physical camera metadata to parcel: %d", |
| 116 | __FUNCTION__, res); |
| 117 | return res; |
| 118 | } |
| 119 | return OK; |
| 120 | } |
| 121 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 122 | CaptureResult::CaptureResult() : |
| 123 | mMetadata(), mResultExtras() { |
| 124 | } |
| 125 | |
Jayant Chowdhary | 8a0be29 | 2020-01-08 13:10:38 -0800 | [diff] [blame] | 126 | CaptureResult::CaptureResult(CaptureResult &&otherResult) { |
| 127 | mMetadata = std::move(otherResult.mMetadata); |
| 128 | mResultExtras = otherResult.mResultExtras; |
| 129 | mPhysicalMetadatas = std::move(otherResult.mPhysicalMetadatas); |
| 130 | } |
| 131 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 132 | CaptureResult::CaptureResult(const CaptureResult &otherResult) { |
| 133 | mResultExtras = otherResult.mResultExtras; |
| 134 | mMetadata = otherResult.mMetadata; |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 135 | mPhysicalMetadatas = otherResult.mPhysicalMetadatas; |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 138 | status_t CaptureResult::readFromParcel(android::Parcel *parcel) { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 139 | |
| 140 | ALOGV("%s: parcel = %p", __FUNCTION__, parcel); |
| 141 | |
| 142 | if (parcel == NULL) { |
| 143 | ALOGE("%s: parcel is null", __FUNCTION__); |
| 144 | return BAD_VALUE; |
| 145 | } |
| 146 | |
| 147 | mMetadata.clear(); |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 148 | mPhysicalMetadatas.clear(); |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 149 | |
| 150 | status_t res = OK; |
| 151 | res = mMetadata.readFromParcel(parcel); |
| 152 | if (res != OK) { |
| 153 | ALOGE("%s: Failed to read metadata from parcel.", |
| 154 | __FUNCTION__); |
| 155 | return res; |
| 156 | } |
| 157 | ALOGV("%s: Read metadata from parcel", __FUNCTION__); |
| 158 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 159 | int32_t physicalMetadataCount; |
| 160 | if ((res = parcel->readInt32(&physicalMetadataCount)) != OK) { |
| 161 | ALOGE("%s: Failed to read the physical metadata count from parcel: %d", __FUNCTION__, res); |
| 162 | return res; |
| 163 | } |
| 164 | if (physicalMetadataCount < 0) { |
| 165 | ALOGE("%s: Invalid physical metadata count from parcel: %d", |
| 166 | __FUNCTION__, physicalMetadataCount); |
| 167 | return BAD_VALUE; |
| 168 | } |
| 169 | |
| 170 | for (int32_t i = 0; i < physicalMetadataCount; i++) { |
| 171 | String16 cameraId; |
| 172 | if ((res = parcel->readString16(&cameraId)) != OK) { |
| 173 | ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res); |
| 174 | return res; |
| 175 | } |
| 176 | |
| 177 | CameraMetadata physicalMetadata; |
| 178 | if ((res = physicalMetadata.readFromParcel(parcel)) != OK) { |
| 179 | ALOGE("%s: Failed to read metadata from parcel: %d", __FUNCTION__, res); |
| 180 | return res; |
| 181 | } |
| 182 | |
| 183 | mPhysicalMetadatas.emplace(mPhysicalMetadatas.end(), cameraId, physicalMetadata); |
| 184 | } |
| 185 | ALOGV("%s: Read physical metadata from parcel", __FUNCTION__); |
| 186 | |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 187 | res = mResultExtras.readFromParcel(parcel); |
| 188 | if (res != OK) { |
| 189 | ALOGE("%s: Failed to read result extras from parcel.", |
| 190 | __FUNCTION__); |
| 191 | return res; |
| 192 | } |
| 193 | ALOGV("%s: Read result extras from parcel", __FUNCTION__); |
| 194 | |
| 195 | return OK; |
| 196 | } |
| 197 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 198 | status_t CaptureResult::writeToParcel(android::Parcel *parcel) const { |
Jianing Wei | cb0652e | 2014-03-12 18:29:36 -0700 | [diff] [blame] | 199 | |
| 200 | ALOGV("%s: parcel = %p", __FUNCTION__, parcel); |
| 201 | |
| 202 | if (parcel == NULL) { |
| 203 | ALOGE("%s: parcel is null", __FUNCTION__); |
| 204 | return BAD_VALUE; |
| 205 | } |
| 206 | |
| 207 | status_t res; |
| 208 | |
| 209 | res = mMetadata.writeToParcel(parcel); |
| 210 | if (res != OK) { |
| 211 | ALOGE("%s: Failed to write metadata to parcel", __FUNCTION__); |
| 212 | return res; |
| 213 | } |
| 214 | ALOGV("%s: Wrote metadata to parcel", __FUNCTION__); |
| 215 | |
Shuzhen Wang | 5c22c15 | 2017-12-31 17:12:25 -0800 | [diff] [blame] | 216 | int32_t physicalMetadataCount = static_cast<int32_t>(mPhysicalMetadatas.size()); |
| 217 | res = parcel->writeInt32(physicalMetadataCount); |
| 218 | if (res != OK) { |
| 219 | ALOGE("%s: Failed to write physical metadata count to parcel: %d", |
| 220 | __FUNCTION__, res); |
| 221 | return BAD_VALUE; |
| 222 | } |
| 223 | for (const auto& physicalMetadata : mPhysicalMetadatas) { |
| 224 | if ((res = parcel->writeString16(physicalMetadata.mPhysicalCameraId)) != OK) { |
| 225 | ALOGE("%s: Failed to write physical camera ID to parcel: %d", |
| 226 | __FUNCTION__, res); |
| 227 | return res; |
| 228 | } |
| 229 | if ((res = physicalMetadata.mPhysicalCameraMetadata.writeToParcel(parcel)) != OK) { |
| 230 | ALOGE("%s: Failed to write physical camera metadata to parcel: %d", |
| 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 | } |