blob: 4c2398295b1e4cebb80e4c711c49b20797b7cf79 [file] [log] [blame]
Shuzhen Wang316781a2020-08-18 18:11:01 -07001/*
2 * Copyright (C) 2020 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_NDEBUG 0
18#define LOG_TAG "CameraSessionStats"
19#include <utils/Log.h>
20#include <utils/String16.h>
21
22#include <camera/CameraSessionStats.h>
23
24#include <binder/Parcel.h>
25
26namespace android {
27namespace hardware {
28
29status_t CameraStreamStats::readFromParcel(const android::Parcel* parcel) {
30 if (parcel == NULL) {
31 ALOGE("%s: Null parcel", __FUNCTION__);
32 return BAD_VALUE;
33 }
34
35 status_t err = OK;
36
37 int width = 0;
38 if ((err = parcel->readInt32(&width)) != OK) {
39 ALOGE("%s: Failed to read width from parcel", __FUNCTION__);
40 return err;
41 }
42
43 int height = 0;
44 if ((err = parcel->readInt32(&height)) != OK) {
45 ALOGE("%s: Failed to read height from parcel", __FUNCTION__);
46 return err;
47 }
48
49 int format = 0;
50 if ((err = parcel->readInt32(&format)) != OK) {
51 ALOGE("%s: Failed to read format from parcel", __FUNCTION__);
52 return err;
53 }
54
55 int dataSpace = 0;
56 if ((err = parcel->readInt32(&dataSpace)) != OK) {
57 ALOGE("%s: Failed to read dataSpace from parcel", __FUNCTION__);
58 return err;
59 }
60
61 int64_t usage = 0;
62 if ((err = parcel->readInt64(&usage)) != OK) {
63 ALOGE("%s: Failed to read usage from parcel", __FUNCTION__);
64 return err;
65 }
66
67 int64_t requestCount = 0;
68 if ((err = parcel->readInt64(&requestCount)) != OK) {
69 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
70 return err;
71 }
72
73 int64_t errorCount = 0;
74 if ((err = parcel->readInt64(&errorCount)) != OK) {
75 ALOGE("%s: Failed to read error count from parcel", __FUNCTION__);
76 return err;
77 }
78
79 int startLatencyMs = 0;
80 if ((err = parcel->readInt32(&startLatencyMs)) != OK) {
81 ALOGE("%s: Failed to read start latency from parcel", __FUNCTION__);
82 return err;
83 }
84
85 int maxHalBuffers = 0;
86 if ((err = parcel->readInt32(&maxHalBuffers)) != OK) {
87 ALOGE("%s: Failed to read max Hal buffers from parcel", __FUNCTION__);
88 return err;
89 }
90
91 int maxAppBuffers = 0;
92 if ((err = parcel->readInt32(&maxAppBuffers)) != OK) {
93 ALOGE("%s: Failed to read max app buffers from parcel", __FUNCTION__);
94 return err;
95 }
96
97 mWidth = width;
98 mHeight = height;
99 mFormat = format;
100 mDataSpace = dataSpace;
101 mUsage = usage;
102 mRequestCount = requestCount;
103 mErrorCount = errorCount;
104 mStartLatencyMs = startLatencyMs;
105 mMaxHalBuffers = maxHalBuffers;
106 mMaxAppBuffers = maxAppBuffers;
107
108 return OK;
109}
110
111status_t CameraStreamStats::writeToParcel(android::Parcel* parcel) const {
112 if (parcel == NULL) {
113 ALOGE("%s: Null parcel", __FUNCTION__);
114 return BAD_VALUE;
115 }
116
117 status_t err = OK;
118
119 if ((err = parcel->writeInt32(mWidth)) != OK) {
120 ALOGE("%s: Failed to write stream width!", __FUNCTION__);
121 return err;
122 }
123
124 if ((err = parcel->writeInt32(mHeight)) != OK) {
125 ALOGE("%s: Failed to write stream height!", __FUNCTION__);
126 return err;
127 }
128
129 if ((err = parcel->writeInt32(mFormat)) != OK) {
130 ALOGE("%s: Failed to write stream format!", __FUNCTION__);
131 return err;
132 }
133
134 if ((err = parcel->writeInt32(mDataSpace)) != OK) {
135 ALOGE("%s: Failed to write stream dataSpace!", __FUNCTION__);
136 return err;
137 }
138
139 if ((err = parcel->writeInt64(mUsage)) != OK) {
140 ALOGE("%s: Failed to write stream usage!", __FUNCTION__);
141 return err;
142 }
143
144 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
145 ALOGE("%s: Failed to write stream request count!", __FUNCTION__);
146 return err;
147 }
148
149 if ((err = parcel->writeInt64(mErrorCount)) != OK) {
150 ALOGE("%s: Failed to write stream error count!", __FUNCTION__);
151 return err;
152 }
153
154 if ((err = parcel->writeInt32(mStartLatencyMs)) != OK) {
155 ALOGE("%s: Failed to write stream start latency!", __FUNCTION__);
156 return err;
157 }
158
159 if ((err = parcel->writeInt32(mMaxHalBuffers)) != OK) {
160 ALOGE("%s: Failed to write max hal buffers", __FUNCTION__);
161 return err;
162 }
163
164 if ((err = parcel->writeInt32(mMaxAppBuffers)) != OK) {
165 ALOGE("%s: Failed to write max app buffers", __FUNCTION__);
166 return err;
167 }
168
169 return OK;
170}
171
172CameraSessionStats::CameraSessionStats() :
173 mFacing(CAMERA_FACING_BACK),
174 mNewCameraState(CAMERA_STATE_CLOSED),
175 mApiLevel(0),
176 mIsNdk(false),
177 mLatencyMs(-1),
178 mSessionType(0),
179 mInternalReconfigure(0),
180 mRequestCount(0),
181 mResultErrorCount(0),
182 mDeviceError(false) {}
183
184CameraSessionStats::CameraSessionStats(const String16& cameraId,
185 int facing, int newCameraState, const String16& clientName,
186 int apiLevel, bool isNdk, int32_t latencyMs) :
187 mCameraId(cameraId),
188 mFacing(facing),
189 mNewCameraState(newCameraState),
190 mClientName(clientName),
191 mApiLevel(apiLevel),
192 mIsNdk(isNdk),
193 mLatencyMs(latencyMs),
194 mSessionType(0),
195 mInternalReconfigure(0),
196 mRequestCount(0),
197 mResultErrorCount(0),
198 mDeviceError(0) {}
199
200status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
201 if (parcel == NULL) {
202 ALOGE("%s: Null parcel", __FUNCTION__);
203 return BAD_VALUE;
204 }
205
206 status_t err = OK;
207
208 String16 id;
209 if ((err = parcel->readString16(&id)) != OK) {
210 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
211 return BAD_VALUE;
212 }
213
214 int facing = 0;
215 if ((err = parcel->readInt32(&facing)) != OK) {
216 ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__);
217 return err;
218 }
219
220 int32_t newCameraState;
221 if ((err = parcel->readInt32(&newCameraState)) != OK) {
222 ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__);
223 return err;
224 }
225
226 String16 clientName;
227 if ((err = parcel->readString16(&clientName)) != OK) {
228 ALOGE("%s: Failed to read client name!", __FUNCTION__);
229 return BAD_VALUE;
230 }
231
232 int32_t apiLevel;
233 if ((err = parcel->readInt32(&apiLevel)) != OK) {
234 ALOGE("%s: Failed to read api level from parcel", __FUNCTION__);
235 return err;
236 }
237
238 bool isNdk;
239 if ((err = parcel->readBool(&isNdk)) != OK) {
240 ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__);
241 return err;
242 }
243
244 int32_t latencyMs;
245 if ((err = parcel->readInt32(&latencyMs)) != OK) {
246 ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__);
247 return err;
248 }
249
250 int32_t sessionType;
251 if ((err = parcel->readInt32(&sessionType)) != OK) {
252 ALOGE("%s: Failed to read session type from parcel", __FUNCTION__);
253 return err;
254 }
255
256 int32_t internalReconfigure;
257 if ((err = parcel->readInt32(&internalReconfigure)) != OK) {
258 ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__);
259 return err;
260 }
261
262 int64_t requestCount;
263 if ((err = parcel->readInt64(&requestCount)) != OK) {
264 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
265 return err;
266 }
267
268 int64_t resultErrorCount;
269 if ((err = parcel->readInt64(&resultErrorCount)) != OK) {
270 ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__);
271 return err;
272 }
273
274 bool deviceError;
275 if ((err = parcel->readBool(&deviceError)) != OK) {
276 ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__);
277 return err;
278 }
279
280 std::vector<CameraStreamStats> streamStats;
281 if ((err = parcel->readParcelableVector(&streamStats)) != OK) {
282 ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__);
283 return err;
284 }
285
286 mCameraId = id;
287 mFacing = facing;
288 mNewCameraState = newCameraState;
289 mClientName = clientName;
290 mApiLevel = apiLevel;
291 mIsNdk = isNdk;
292 mLatencyMs = latencyMs;
293 mSessionType = sessionType;
294 mInternalReconfigure = internalReconfigure;
295 mRequestCount = requestCount;
296 mResultErrorCount = resultErrorCount;
297 mDeviceError = deviceError;
298 mStreamStats = std::move(streamStats);
299
300 return OK;
301}
302
303status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
304 if (parcel == NULL) {
305 ALOGE("%s: Null parcel", __FUNCTION__);
306 return BAD_VALUE;
307 }
308
309 status_t err = OK;
310
311 if ((err = parcel->writeString16(mCameraId)) != OK) {
312 ALOGE("%s: Failed to write camera id!", __FUNCTION__);
313 return err;
314 }
315
316 if ((err = parcel->writeInt32(mFacing)) != OK) {
317 ALOGE("%s: Failed to write camera facing!", __FUNCTION__);
318 return err;
319 }
320
321 if ((err = parcel->writeInt32(mNewCameraState)) != OK) {
322 ALOGE("%s: Failed to write new camera state!", __FUNCTION__);
323 return err;
324 }
325
326 if ((err = parcel->writeString16(mClientName)) != OK) {
327 ALOGE("%s: Failed to write client name!", __FUNCTION__);
328 return err;
329 }
330
331 if ((err = parcel->writeInt32(mApiLevel)) != OK) {
332 ALOGE("%s: Failed to write api level!", __FUNCTION__);
333 return err;
334 }
335
336 if ((err = parcel->writeBool(mIsNdk)) != OK) {
337 ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__);
338 return err;
339 }
340
341 if ((err = parcel->writeInt32(mLatencyMs)) != OK) {
342 ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__);
343 return err;
344 }
345
346 if ((err = parcel->writeInt32(mSessionType)) != OK) {
347 ALOGE("%s: Failed to write session type!", __FUNCTION__);
348 return err;
349 }
350
351 if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) {
352 ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__);
353 return err;
354 }
355
356 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
357 ALOGE("%s: Failed to write request count!", __FUNCTION__);
358 return err;
359 }
360
361 if ((err = parcel->writeInt64(mResultErrorCount)) != OK) {
362 ALOGE("%s: Failed to write result error count!", __FUNCTION__);
363 return err;
364 }
365
366 if ((err = parcel->writeBool(mDeviceError)) != OK) {
367 ALOGE("%s: Failed to write device error flag!", __FUNCTION__);
368 return err;
369 }
370
371 if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) {
372 ALOGE("%s: Failed to write stream states!", __FUNCTION__);
373 return err;
374 }
375
376 return OK;
377}
378
379} // namespace hardware
380} // namesmpace android