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 parcel->readBool(&hasReadoutTimestamp);
56 if (hasReadoutTimestamp) {
57 parcel->readInt64(&readoutTimestamp);
58 }
59 return OK;
60 }
61
writeToParcel(android::Parcel * parcel) const62 status_t CaptureResultExtras::writeToParcel(android::Parcel *parcel) const {
63 if (parcel == NULL) {
64 ALOGE("%s: Null parcel", __FUNCTION__);
65 return BAD_VALUE;
66 }
67
68 parcel->writeInt32(requestId);
69 parcel->writeInt32(burstId);
70 parcel->writeInt32(afTriggerId);
71 parcel->writeInt32(precaptureTriggerId);
72 parcel->writeInt64(frameNumber);
73 parcel->writeInt32(partialResultCount);
74 parcel->writeInt32(errorStreamId);
75 if (errorPhysicalCameraId.size() > 0) {
76 parcel->writeBool(true);
77 status_t res = OK;
78 if ((res = parcel->writeString16(errorPhysicalCameraId)) != OK) {
79 ALOGE("%s: Failed to write physical camera ID to parcel: %d", __FUNCTION__, res);
80 return res;
81 }
82 } else {
83 parcel->writeBool(false);
84 }
85 parcel->writeInt64(lastCompletedRegularFrameNumber);
86 parcel->writeInt64(lastCompletedReprocessFrameNumber);
87 parcel->writeInt64(lastCompletedZslFrameNumber);
88 parcel->writeBool(hasReadoutTimestamp);
89 if (hasReadoutTimestamp) {
90 parcel->writeInt64(readoutTimestamp);
91 }
92
93 return OK;
94 }
95
readFromParcel(const android::Parcel * parcel)96 status_t PhysicalCaptureResultInfo::readFromParcel(const android::Parcel* parcel) {
97 status_t res;
98
99 mPhysicalCameraId.setTo(u"");
100 mPhysicalCameraMetadata.clear();
101
102 if ((res = parcel->readString16(&mPhysicalCameraId)) != OK) {
103 ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res);
104 return res;
105 }
106
107 if ((res = mPhysicalCameraMetadata.readFromParcel(parcel)) != OK) {
108 ALOGE("%s: Failed to read metadata from parcel: %d", __FUNCTION__, res);
109 return res;
110 }
111 return OK;
112 }
113
writeToParcel(android::Parcel * parcel) const114 status_t PhysicalCaptureResultInfo::writeToParcel(android::Parcel* parcel) const {
115 status_t res;
116 if ((res = parcel->writeString16(mPhysicalCameraId)) != OK) {
117 ALOGE("%s: Failed to write physical camera ID to parcel: %d",
118 __FUNCTION__, res);
119 return res;
120 }
121 if ((res = mPhysicalCameraMetadata.writeToParcel(parcel)) != OK) {
122 ALOGE("%s: Failed to write physical camera metadata to parcel: %d",
123 __FUNCTION__, res);
124 return res;
125 }
126 return OK;
127 }
128
CaptureResult()129 CaptureResult::CaptureResult() :
130 mMetadata(), mResultExtras() {
131 }
132
CaptureResult(CaptureResult && otherResult)133 CaptureResult::CaptureResult(CaptureResult &&otherResult) {
134 mMetadata = std::move(otherResult.mMetadata);
135 mResultExtras = otherResult.mResultExtras;
136 mPhysicalMetadatas = std::move(otherResult.mPhysicalMetadatas);
137 }
138
CaptureResult(const CaptureResult & otherResult)139 CaptureResult::CaptureResult(const CaptureResult &otherResult) {
140 mResultExtras = otherResult.mResultExtras;
141 mMetadata = otherResult.mMetadata;
142 mPhysicalMetadatas = otherResult.mPhysicalMetadatas;
143 }
144
readFromParcel(android::Parcel * parcel)145 status_t CaptureResult::readFromParcel(android::Parcel *parcel) {
146
147 ALOGV("%s: parcel = %p", __FUNCTION__, parcel);
148
149 if (parcel == NULL) {
150 ALOGE("%s: parcel is null", __FUNCTION__);
151 return BAD_VALUE;
152 }
153
154 mMetadata.clear();
155 mPhysicalMetadatas.clear();
156
157 status_t res = OK;
158 res = mMetadata.readFromParcel(parcel);
159 if (res != OK) {
160 ALOGE("%s: Failed to read metadata from parcel.",
161 __FUNCTION__);
162 return res;
163 }
164 ALOGV("%s: Read metadata from parcel", __FUNCTION__);
165
166 int32_t physicalMetadataCount;
167 if ((res = parcel->readInt32(&physicalMetadataCount)) != OK) {
168 ALOGE("%s: Failed to read the physical metadata count from parcel: %d", __FUNCTION__, res);
169 return res;
170 }
171 if (physicalMetadataCount < 0) {
172 ALOGE("%s: Invalid physical metadata count from parcel: %d",
173 __FUNCTION__, physicalMetadataCount);
174 return BAD_VALUE;
175 }
176
177 for (int32_t i = 0; i < physicalMetadataCount; i++) {
178 String16 cameraId;
179 if ((res = parcel->readString16(&cameraId)) != OK) {
180 ALOGE("%s: Failed to read camera id: %d", __FUNCTION__, res);
181 return res;
182 }
183
184 CameraMetadata physicalMetadata;
185 if ((res = physicalMetadata.readFromParcel(parcel)) != OK) {
186 ALOGE("%s: Failed to read metadata from parcel: %d", __FUNCTION__, res);
187 return res;
188 }
189
190 mPhysicalMetadatas.emplace(mPhysicalMetadatas.end(), cameraId, physicalMetadata);
191 }
192 ALOGV("%s: Read physical metadata from parcel", __FUNCTION__);
193
194 res = mResultExtras.readFromParcel(parcel);
195 if (res != OK) {
196 ALOGE("%s: Failed to read result extras from parcel.",
197 __FUNCTION__);
198 return res;
199 }
200 ALOGV("%s: Read result extras from parcel", __FUNCTION__);
201
202 return OK;
203 }
204
writeToParcel(android::Parcel * parcel) const205 status_t CaptureResult::writeToParcel(android::Parcel *parcel) const {
206
207 ALOGV("%s: parcel = %p", __FUNCTION__, parcel);
208
209 if (parcel == NULL) {
210 ALOGE("%s: parcel is null", __FUNCTION__);
211 return BAD_VALUE;
212 }
213
214 status_t res;
215
216 res = mMetadata.writeToParcel(parcel);
217 if (res != OK) {
218 ALOGE("%s: Failed to write metadata to parcel", __FUNCTION__);
219 return res;
220 }
221 ALOGV("%s: Wrote metadata to parcel", __FUNCTION__);
222
223 int32_t physicalMetadataCount = static_cast<int32_t>(mPhysicalMetadatas.size());
224 res = parcel->writeInt32(physicalMetadataCount);
225 if (res != OK) {
226 ALOGE("%s: Failed to write physical metadata count to parcel: %d",
227 __FUNCTION__, res);
228 return BAD_VALUE;
229 }
230 for (const auto& physicalMetadata : mPhysicalMetadatas) {
231 if ((res = parcel->writeString16(physicalMetadata.mPhysicalCameraId)) != OK) {
232 ALOGE("%s: Failed to write physical camera ID to parcel: %d",
233 __FUNCTION__, res);
234 return res;
235 }
236 if ((res = physicalMetadata.mPhysicalCameraMetadata.writeToParcel(parcel)) != OK) {
237 ALOGE("%s: Failed to write physical camera metadata to parcel: %d",
238 __FUNCTION__, res);
239 return res;
240 }
241 }
242 ALOGV("%s: Wrote physical camera metadata to parcel", __FUNCTION__);
243
244 res = mResultExtras.writeToParcel(parcel);
245 if (res != OK) {
246 ALOGE("%s: Failed to write result extras to parcel", __FUNCTION__);
247 return res;
248 }
249 ALOGV("%s: Wrote result extras to parcel", __FUNCTION__);
250
251 return OK;
252 }
253
254 }
255