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