blob: 2a07ffc63ce7f054edb994d6ca901f6bf7e00f8a [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
Shuzhen Wangdb8f2782020-10-30 08:43:37 -070097 int histogramType = HISTOGRAM_TYPE_UNKNOWN;
98 if ((err = parcel->readInt32(&histogramType)) != OK) {
99 ALOGE("%s: Failed to read histogram type from parcel", __FUNCTION__);
100 return err;
101 }
102
103 std::vector<float> histogramBins;
104 if ((err = parcel->readFloatVector(&histogramBins)) != OK) {
105 ALOGE("%s: Failed to read histogram bins from parcel", __FUNCTION__);
106 return err;
107 }
108
109 std::vector<int64_t> histogramCounts;
110 if ((err = parcel->readInt64Vector(&histogramCounts)) != OK) {
111 ALOGE("%s: Failed to read histogram counts from parcel", __FUNCTION__);
112 return err;
113 }
114
Emilian Peev2295df72021-11-12 18:14:10 -0800115 int dynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
116 if ((err = parcel->readInt32(&dynamicRangeProfile)) != OK) {
117 ALOGE("%s: Failed to read dynamic range profile type from parcel", __FUNCTION__);
118 return err;
119 }
120
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800121 int streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
122 if ((err = parcel->readInt32(&streamUseCase)) != OK) {
123 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
124 return err;
125 }
126
Shuzhen Wang316781a2020-08-18 18:11:01 -0700127 mWidth = width;
128 mHeight = height;
129 mFormat = format;
130 mDataSpace = dataSpace;
131 mUsage = usage;
132 mRequestCount = requestCount;
133 mErrorCount = errorCount;
134 mStartLatencyMs = startLatencyMs;
135 mMaxHalBuffers = maxHalBuffers;
136 mMaxAppBuffers = maxAppBuffers;
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700137 mHistogramType = histogramType;
138 mHistogramBins = std::move(histogramBins);
139 mHistogramCounts = std::move(histogramCounts);
Emilian Peev2295df72021-11-12 18:14:10 -0800140 mDynamicRangeProfile = dynamicRangeProfile;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800141 mStreamUseCase = streamUseCase;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700142
143 return OK;
144}
145
146status_t CameraStreamStats::writeToParcel(android::Parcel* parcel) const {
147 if (parcel == NULL) {
148 ALOGE("%s: Null parcel", __FUNCTION__);
149 return BAD_VALUE;
150 }
151
152 status_t err = OK;
153
154 if ((err = parcel->writeInt32(mWidth)) != OK) {
155 ALOGE("%s: Failed to write stream width!", __FUNCTION__);
156 return err;
157 }
158
159 if ((err = parcel->writeInt32(mHeight)) != OK) {
160 ALOGE("%s: Failed to write stream height!", __FUNCTION__);
161 return err;
162 }
163
164 if ((err = parcel->writeInt32(mFormat)) != OK) {
165 ALOGE("%s: Failed to write stream format!", __FUNCTION__);
166 return err;
167 }
168
169 if ((err = parcel->writeInt32(mDataSpace)) != OK) {
170 ALOGE("%s: Failed to write stream dataSpace!", __FUNCTION__);
171 return err;
172 }
173
174 if ((err = parcel->writeInt64(mUsage)) != OK) {
175 ALOGE("%s: Failed to write stream usage!", __FUNCTION__);
176 return err;
177 }
178
179 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
180 ALOGE("%s: Failed to write stream request count!", __FUNCTION__);
181 return err;
182 }
183
184 if ((err = parcel->writeInt64(mErrorCount)) != OK) {
185 ALOGE("%s: Failed to write stream error count!", __FUNCTION__);
186 return err;
187 }
188
189 if ((err = parcel->writeInt32(mStartLatencyMs)) != OK) {
190 ALOGE("%s: Failed to write stream start latency!", __FUNCTION__);
191 return err;
192 }
193
194 if ((err = parcel->writeInt32(mMaxHalBuffers)) != OK) {
195 ALOGE("%s: Failed to write max hal buffers", __FUNCTION__);
196 return err;
197 }
198
199 if ((err = parcel->writeInt32(mMaxAppBuffers)) != OK) {
200 ALOGE("%s: Failed to write max app buffers", __FUNCTION__);
201 return err;
202 }
203
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700204 if ((err = parcel->writeInt32(mHistogramType)) != OK) {
205 ALOGE("%s: Failed to write histogram type", __FUNCTION__);
206 return err;
207 }
208
209 if ((err = parcel->writeFloatVector(mHistogramBins)) != OK) {
210 ALOGE("%s: Failed to write histogram bins!", __FUNCTION__);
211 return err;
212 }
213
214 if ((err = parcel->writeInt64Vector(mHistogramCounts)) != OK) {
215 ALOGE("%s: Failed to write histogram counts!", __FUNCTION__);
216 return err;
217 }
218
Emilian Peev2295df72021-11-12 18:14:10 -0800219 if ((err = parcel->writeInt32(mDynamicRangeProfile)) != OK) {
220 ALOGE("%s: Failed to write dynamic range profile type", __FUNCTION__);
221 return err;
222 }
223
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800224 if ((err = parcel->writeInt32(mStreamUseCase)) != OK) {
225 ALOGE("%s: Failed to write stream use case!", __FUNCTION__);
226 return err;
227 }
228
Shuzhen Wang316781a2020-08-18 18:11:01 -0700229 return OK;
230}
231
Shuzhen Wangbac18d92020-11-19 14:50:30 -0800232const int CameraSessionStats::CAMERA_STATE_OPEN = 0;
233const int CameraSessionStats::CAMERA_STATE_ACTIVE = 1;
234const int CameraSessionStats::CAMERA_STATE_IDLE = 2;
235const int CameraSessionStats::CAMERA_STATE_CLOSED = 3;
236
237const int CameraSessionStats::CAMERA_FACING_BACK = 0;
238const int CameraSessionStats::CAMERA_FACING_FRONT = 1;
239const int CameraSessionStats::CAMERA_FACING_EXTERNAL = 2;
240
241const int CameraSessionStats::CAMERA_API_LEVEL_1 = 1;
242const int CameraSessionStats::CAMERA_API_LEVEL_2 = 2;
243
Shuzhen Wang316781a2020-08-18 18:11:01 -0700244CameraSessionStats::CameraSessionStats() :
245 mFacing(CAMERA_FACING_BACK),
246 mNewCameraState(CAMERA_STATE_CLOSED),
247 mApiLevel(0),
248 mIsNdk(false),
249 mLatencyMs(-1),
250 mSessionType(0),
251 mInternalReconfigure(0),
252 mRequestCount(0),
253 mResultErrorCount(0),
254 mDeviceError(false) {}
255
256CameraSessionStats::CameraSessionStats(const String16& cameraId,
257 int facing, int newCameraState, const String16& clientName,
258 int apiLevel, bool isNdk, int32_t latencyMs) :
259 mCameraId(cameraId),
260 mFacing(facing),
261 mNewCameraState(newCameraState),
262 mClientName(clientName),
263 mApiLevel(apiLevel),
264 mIsNdk(isNdk),
265 mLatencyMs(latencyMs),
266 mSessionType(0),
267 mInternalReconfigure(0),
268 mRequestCount(0),
269 mResultErrorCount(0),
270 mDeviceError(0) {}
271
272status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
273 if (parcel == NULL) {
274 ALOGE("%s: Null parcel", __FUNCTION__);
275 return BAD_VALUE;
276 }
277
278 status_t err = OK;
279
280 String16 id;
281 if ((err = parcel->readString16(&id)) != OK) {
282 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
283 return BAD_VALUE;
284 }
285
286 int facing = 0;
287 if ((err = parcel->readInt32(&facing)) != OK) {
288 ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__);
289 return err;
290 }
291
292 int32_t newCameraState;
293 if ((err = parcel->readInt32(&newCameraState)) != OK) {
294 ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__);
295 return err;
296 }
297
298 String16 clientName;
299 if ((err = parcel->readString16(&clientName)) != OK) {
300 ALOGE("%s: Failed to read client name!", __FUNCTION__);
301 return BAD_VALUE;
302 }
303
304 int32_t apiLevel;
305 if ((err = parcel->readInt32(&apiLevel)) != OK) {
306 ALOGE("%s: Failed to read api level from parcel", __FUNCTION__);
307 return err;
308 }
309
310 bool isNdk;
311 if ((err = parcel->readBool(&isNdk)) != OK) {
312 ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__);
313 return err;
314 }
315
316 int32_t latencyMs;
317 if ((err = parcel->readInt32(&latencyMs)) != OK) {
318 ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__);
319 return err;
320 }
321
322 int32_t sessionType;
323 if ((err = parcel->readInt32(&sessionType)) != OK) {
324 ALOGE("%s: Failed to read session type from parcel", __FUNCTION__);
325 return err;
326 }
327
328 int32_t internalReconfigure;
329 if ((err = parcel->readInt32(&internalReconfigure)) != OK) {
330 ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__);
331 return err;
332 }
333
334 int64_t requestCount;
335 if ((err = parcel->readInt64(&requestCount)) != OK) {
336 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
337 return err;
338 }
339
340 int64_t resultErrorCount;
341 if ((err = parcel->readInt64(&resultErrorCount)) != OK) {
342 ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__);
343 return err;
344 }
345
346 bool deviceError;
347 if ((err = parcel->readBool(&deviceError)) != OK) {
348 ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__);
349 return err;
350 }
351
352 std::vector<CameraStreamStats> streamStats;
353 if ((err = parcel->readParcelableVector(&streamStats)) != OK) {
354 ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__);
355 return err;
356 }
357
358 mCameraId = id;
359 mFacing = facing;
360 mNewCameraState = newCameraState;
361 mClientName = clientName;
362 mApiLevel = apiLevel;
363 mIsNdk = isNdk;
364 mLatencyMs = latencyMs;
365 mSessionType = sessionType;
366 mInternalReconfigure = internalReconfigure;
367 mRequestCount = requestCount;
368 mResultErrorCount = resultErrorCount;
369 mDeviceError = deviceError;
370 mStreamStats = std::move(streamStats);
371
372 return OK;
373}
374
375status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
376 if (parcel == NULL) {
377 ALOGE("%s: Null parcel", __FUNCTION__);
378 return BAD_VALUE;
379 }
380
381 status_t err = OK;
382
383 if ((err = parcel->writeString16(mCameraId)) != OK) {
384 ALOGE("%s: Failed to write camera id!", __FUNCTION__);
385 return err;
386 }
387
388 if ((err = parcel->writeInt32(mFacing)) != OK) {
389 ALOGE("%s: Failed to write camera facing!", __FUNCTION__);
390 return err;
391 }
392
393 if ((err = parcel->writeInt32(mNewCameraState)) != OK) {
394 ALOGE("%s: Failed to write new camera state!", __FUNCTION__);
395 return err;
396 }
397
398 if ((err = parcel->writeString16(mClientName)) != OK) {
399 ALOGE("%s: Failed to write client name!", __FUNCTION__);
400 return err;
401 }
402
403 if ((err = parcel->writeInt32(mApiLevel)) != OK) {
404 ALOGE("%s: Failed to write api level!", __FUNCTION__);
405 return err;
406 }
407
408 if ((err = parcel->writeBool(mIsNdk)) != OK) {
409 ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__);
410 return err;
411 }
412
413 if ((err = parcel->writeInt32(mLatencyMs)) != OK) {
414 ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__);
415 return err;
416 }
417
418 if ((err = parcel->writeInt32(mSessionType)) != OK) {
419 ALOGE("%s: Failed to write session type!", __FUNCTION__);
420 return err;
421 }
422
423 if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) {
424 ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__);
425 return err;
426 }
427
428 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
429 ALOGE("%s: Failed to write request count!", __FUNCTION__);
430 return err;
431 }
432
433 if ((err = parcel->writeInt64(mResultErrorCount)) != OK) {
434 ALOGE("%s: Failed to write result error count!", __FUNCTION__);
435 return err;
436 }
437
438 if ((err = parcel->writeBool(mDeviceError)) != OK) {
439 ALOGE("%s: Failed to write device error flag!", __FUNCTION__);
440 return err;
441 }
442
443 if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) {
444 ALOGE("%s: Failed to write stream states!", __FUNCTION__);
445 return err;
446 }
447
448 return OK;
449}
450
451} // namespace hardware
452} // namesmpace android