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
isValid()25 bool CaptureResultExtras::isValid() {
26 return requestId >= 0;
27 }
28
readFromParcel(const android::Parcel * parcel)29 status_t CaptureResultExtras::readFromParcel(const android::Parcel *parcel) {
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);
40 parcel->readInt32(&partialResultCount);
41 parcel->readInt32(&errorStreamId);
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 }
52 parcel->readInt64(&lastCompletedRegularFrameNumber);
53 parcel->readInt64(&lastCompletedReprocessFrameNumber);
54 parcel->readInt64(&lastCompletedZslFrameNumber);
55
56 return OK;
57 }
58
writeToParcel(android::Parcel * parcel) const59 status_t CaptureResultExtras::writeToParcel(android::Parcel *parcel) const {
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);
70 parcel->writeInt32(partialResultCount);
71 parcel->writeInt32(errorStreamId);
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 }
82 parcel->writeInt64(lastCompletedRegularFrameNumber);
83 parcel->writeInt64(lastCompletedReprocessFrameNumber);
84 parcel->writeInt64(lastCompletedZslFrameNumber);
85
86 return OK;
87 }
88
readFromParcel(const android::Parcel * parcel)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
writeToParcel(android::Parcel * parcel) const107 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
CaptureResult()122 CaptureResult::CaptureResult() :
123 mMetadata(), mResultExtras() {
124 }
125
CaptureResult(CaptureResult && otherResult)126 CaptureResult::CaptureResult(CaptureResult &&otherResult) {
127 mMetadata = std::move(otherResult.mMetadata);
128 mResultExtras = otherResult.mResultExtras;
129 mPhysicalMetadatas = std::move(otherResult.mPhysicalMetadatas);
130 }
131
CaptureResult(const CaptureResult & otherResult)132 CaptureResult::CaptureResult(const CaptureResult &otherResult) {
133 mResultExtras = otherResult.mResultExtras;
134 mMetadata = otherResult.mMetadata;
135 mPhysicalMetadatas = otherResult.mPhysicalMetadatas;
136 }
137
readFromParcel(android::Parcel * parcel)138 status_t CaptureResult::readFromParcel(android::Parcel *parcel) {
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();
148 mPhysicalMetadatas.clear();
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
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
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
writeToParcel(android::Parcel * parcel) const198 status_t CaptureResult::writeToParcel(android::Parcel *parcel) const {
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
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
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 }
248