CaptureResult.cpp revision 5c22c15ed8c593189ed9bb8fcbccace2ca63b82a
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
23namespace android {
24
25bool CaptureResultExtras::isValid() {
26    return requestId >= 0;
27}
28
29status_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
43    return OK;
44}
45
46status_t CaptureResultExtras::writeToParcel(android::Parcel *parcel) const {
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);
57    parcel->writeInt32(partialResultCount);
58    parcel->writeInt32(errorStreamId);
59
60    return OK;
61}
62
63status_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
81status_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
96CaptureResult::CaptureResult() :
97        mMetadata(), mResultExtras() {
98}
99
100CaptureResult::CaptureResult(const CaptureResult &otherResult) {
101    mResultExtras = otherResult.mResultExtras;
102    mMetadata = otherResult.mMetadata;
103    mPhysicalMetadatas = otherResult.mPhysicalMetadatas;
104}
105
106status_t CaptureResult::readFromParcel(android::Parcel *parcel) {
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();
116    mPhysicalMetadatas.clear();
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
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
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
166status_t CaptureResult::writeToParcel(android::Parcel *parcel) const {
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
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
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}
216