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