blob: d1aa36a5246b153a71e5486d5ea59f3c66e1bf09 [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
Austin Borger4a870a32022-02-25 01:48:41 +000055 float maxPreviewFps = 0;
56 if ((err = parcel->readFloat(&maxPreviewFps)) != OK) {
57 ALOGE("%s: Failed to read maxPreviewFps from parcel", __FUNCTION__);
58 return err;
59 }
60
Shuzhen Wang316781a2020-08-18 18:11:01 -070061 int dataSpace = 0;
62 if ((err = parcel->readInt32(&dataSpace)) != OK) {
63 ALOGE("%s: Failed to read dataSpace from parcel", __FUNCTION__);
64 return err;
65 }
66
67 int64_t usage = 0;
68 if ((err = parcel->readInt64(&usage)) != OK) {
69 ALOGE("%s: Failed to read usage from parcel", __FUNCTION__);
70 return err;
71 }
72
73 int64_t requestCount = 0;
74 if ((err = parcel->readInt64(&requestCount)) != OK) {
75 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
76 return err;
77 }
78
79 int64_t errorCount = 0;
80 if ((err = parcel->readInt64(&errorCount)) != OK) {
81 ALOGE("%s: Failed to read error count from parcel", __FUNCTION__);
82 return err;
83 }
84
85 int startLatencyMs = 0;
86 if ((err = parcel->readInt32(&startLatencyMs)) != OK) {
87 ALOGE("%s: Failed to read start latency from parcel", __FUNCTION__);
88 return err;
89 }
90
91 int maxHalBuffers = 0;
92 if ((err = parcel->readInt32(&maxHalBuffers)) != OK) {
93 ALOGE("%s: Failed to read max Hal buffers from parcel", __FUNCTION__);
94 return err;
95 }
96
97 int maxAppBuffers = 0;
98 if ((err = parcel->readInt32(&maxAppBuffers)) != OK) {
99 ALOGE("%s: Failed to read max app buffers from parcel", __FUNCTION__);
100 return err;
101 }
102
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700103 int histogramType = HISTOGRAM_TYPE_UNKNOWN;
104 if ((err = parcel->readInt32(&histogramType)) != OK) {
105 ALOGE("%s: Failed to read histogram type from parcel", __FUNCTION__);
106 return err;
107 }
108
109 std::vector<float> histogramBins;
110 if ((err = parcel->readFloatVector(&histogramBins)) != OK) {
111 ALOGE("%s: Failed to read histogram bins from parcel", __FUNCTION__);
112 return err;
113 }
114
115 std::vector<int64_t> histogramCounts;
116 if ((err = parcel->readInt64Vector(&histogramCounts)) != OK) {
117 ALOGE("%s: Failed to read histogram counts from parcel", __FUNCTION__);
118 return err;
119 }
120
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800121 int64_t dynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
122 if ((err = parcel->readInt64(&dynamicRangeProfile)) != OK) {
Emilian Peev2295df72021-11-12 18:14:10 -0800123 ALOGE("%s: Failed to read dynamic range profile type from parcel", __FUNCTION__);
124 return err;
125 }
126
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800127 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
128 if ((err = parcel->readInt64(&streamUseCase)) != OK) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800129 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
130 return err;
131 }
132
Shuzhen Wang316781a2020-08-18 18:11:01 -0700133 mWidth = width;
134 mHeight = height;
135 mFormat = format;
Austin Borger4a870a32022-02-25 01:48:41 +0000136 mMaxPreviewFps = maxPreviewFps;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700137 mDataSpace = dataSpace;
138 mUsage = usage;
139 mRequestCount = requestCount;
140 mErrorCount = errorCount;
141 mStartLatencyMs = startLatencyMs;
142 mMaxHalBuffers = maxHalBuffers;
143 mMaxAppBuffers = maxAppBuffers;
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700144 mHistogramType = histogramType;
145 mHistogramBins = std::move(histogramBins);
146 mHistogramCounts = std::move(histogramCounts);
Emilian Peev2295df72021-11-12 18:14:10 -0800147 mDynamicRangeProfile = dynamicRangeProfile;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800148 mStreamUseCase = streamUseCase;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700149
150 return OK;
151}
152
153status_t CameraStreamStats::writeToParcel(android::Parcel* parcel) const {
154 if (parcel == NULL) {
155 ALOGE("%s: Null parcel", __FUNCTION__);
156 return BAD_VALUE;
157 }
158
159 status_t err = OK;
160
161 if ((err = parcel->writeInt32(mWidth)) != OK) {
162 ALOGE("%s: Failed to write stream width!", __FUNCTION__);
163 return err;
164 }
165
166 if ((err = parcel->writeInt32(mHeight)) != OK) {
167 ALOGE("%s: Failed to write stream height!", __FUNCTION__);
168 return err;
169 }
170
171 if ((err = parcel->writeInt32(mFormat)) != OK) {
172 ALOGE("%s: Failed to write stream format!", __FUNCTION__);
173 return err;
174 }
175
Austin Borger4a870a32022-02-25 01:48:41 +0000176 if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
177 ALOGE("%s: Failed to write stream maxPreviewFps!", __FUNCTION__);
178 return err;
179 }
180
Shuzhen Wang316781a2020-08-18 18:11:01 -0700181 if ((err = parcel->writeInt32(mDataSpace)) != OK) {
182 ALOGE("%s: Failed to write stream dataSpace!", __FUNCTION__);
183 return err;
184 }
185
186 if ((err = parcel->writeInt64(mUsage)) != OK) {
187 ALOGE("%s: Failed to write stream usage!", __FUNCTION__);
188 return err;
189 }
190
191 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
192 ALOGE("%s: Failed to write stream request count!", __FUNCTION__);
193 return err;
194 }
195
196 if ((err = parcel->writeInt64(mErrorCount)) != OK) {
197 ALOGE("%s: Failed to write stream error count!", __FUNCTION__);
198 return err;
199 }
200
201 if ((err = parcel->writeInt32(mStartLatencyMs)) != OK) {
202 ALOGE("%s: Failed to write stream start latency!", __FUNCTION__);
203 return err;
204 }
205
206 if ((err = parcel->writeInt32(mMaxHalBuffers)) != OK) {
207 ALOGE("%s: Failed to write max hal buffers", __FUNCTION__);
208 return err;
209 }
210
211 if ((err = parcel->writeInt32(mMaxAppBuffers)) != OK) {
212 ALOGE("%s: Failed to write max app buffers", __FUNCTION__);
213 return err;
214 }
215
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700216 if ((err = parcel->writeInt32(mHistogramType)) != OK) {
217 ALOGE("%s: Failed to write histogram type", __FUNCTION__);
218 return err;
219 }
220
221 if ((err = parcel->writeFloatVector(mHistogramBins)) != OK) {
222 ALOGE("%s: Failed to write histogram bins!", __FUNCTION__);
223 return err;
224 }
225
226 if ((err = parcel->writeInt64Vector(mHistogramCounts)) != OK) {
227 ALOGE("%s: Failed to write histogram counts!", __FUNCTION__);
228 return err;
229 }
230
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800231 if ((err = parcel->writeInt64(mDynamicRangeProfile)) != OK) {
Emilian Peev2295df72021-11-12 18:14:10 -0800232 ALOGE("%s: Failed to write dynamic range profile type", __FUNCTION__);
233 return err;
234 }
235
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800236 if ((err = parcel->writeInt64(mStreamUseCase)) != OK) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800237 ALOGE("%s: Failed to write stream use case!", __FUNCTION__);
238 return err;
239 }
240
Shuzhen Wang316781a2020-08-18 18:11:01 -0700241 return OK;
242}
243
Shuzhen Wangbac18d92020-11-19 14:50:30 -0800244const int CameraSessionStats::CAMERA_STATE_OPEN = 0;
245const int CameraSessionStats::CAMERA_STATE_ACTIVE = 1;
246const int CameraSessionStats::CAMERA_STATE_IDLE = 2;
247const int CameraSessionStats::CAMERA_STATE_CLOSED = 3;
248
249const int CameraSessionStats::CAMERA_FACING_BACK = 0;
250const int CameraSessionStats::CAMERA_FACING_FRONT = 1;
251const int CameraSessionStats::CAMERA_FACING_EXTERNAL = 2;
252
253const int CameraSessionStats::CAMERA_API_LEVEL_1 = 1;
254const int CameraSessionStats::CAMERA_API_LEVEL_2 = 2;
255
Shuzhen Wang316781a2020-08-18 18:11:01 -0700256CameraSessionStats::CameraSessionStats() :
257 mFacing(CAMERA_FACING_BACK),
258 mNewCameraState(CAMERA_STATE_CLOSED),
259 mApiLevel(0),
260 mIsNdk(false),
261 mLatencyMs(-1),
Austin Borger4a870a32022-02-25 01:48:41 +0000262 mMaxPreviewFps(0),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700263 mSessionType(0),
264 mInternalReconfigure(0),
265 mRequestCount(0),
266 mResultErrorCount(0),
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700267 mDeviceError(false),
268 mVideoStabilizationMode(-1) {}
Shuzhen Wang316781a2020-08-18 18:11:01 -0700269
270CameraSessionStats::CameraSessionStats(const String16& cameraId,
271 int facing, int newCameraState, const String16& clientName,
272 int apiLevel, bool isNdk, int32_t latencyMs) :
273 mCameraId(cameraId),
274 mFacing(facing),
275 mNewCameraState(newCameraState),
276 mClientName(clientName),
277 mApiLevel(apiLevel),
278 mIsNdk(isNdk),
279 mLatencyMs(latencyMs),
Austin Borger4a870a32022-02-25 01:48:41 +0000280 mMaxPreviewFps(0),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700281 mSessionType(0),
282 mInternalReconfigure(0),
283 mRequestCount(0),
284 mResultErrorCount(0),
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700285 mDeviceError(0),
286 mVideoStabilizationMode(-1) {}
Shuzhen Wang316781a2020-08-18 18:11:01 -0700287
288status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
289 if (parcel == NULL) {
290 ALOGE("%s: Null parcel", __FUNCTION__);
291 return BAD_VALUE;
292 }
293
294 status_t err = OK;
295
296 String16 id;
297 if ((err = parcel->readString16(&id)) != OK) {
298 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
299 return BAD_VALUE;
300 }
301
302 int facing = 0;
303 if ((err = parcel->readInt32(&facing)) != OK) {
304 ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__);
305 return err;
306 }
307
308 int32_t newCameraState;
309 if ((err = parcel->readInt32(&newCameraState)) != OK) {
310 ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__);
311 return err;
312 }
313
314 String16 clientName;
315 if ((err = parcel->readString16(&clientName)) != OK) {
316 ALOGE("%s: Failed to read client name!", __FUNCTION__);
317 return BAD_VALUE;
318 }
319
320 int32_t apiLevel;
321 if ((err = parcel->readInt32(&apiLevel)) != OK) {
322 ALOGE("%s: Failed to read api level from parcel", __FUNCTION__);
323 return err;
324 }
325
326 bool isNdk;
327 if ((err = parcel->readBool(&isNdk)) != OK) {
328 ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__);
329 return err;
330 }
331
332 int32_t latencyMs;
333 if ((err = parcel->readInt32(&latencyMs)) != OK) {
334 ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__);
335 return err;
336 }
337
Austin Borger4a870a32022-02-25 01:48:41 +0000338 float maxPreviewFps;
339 if ((err = parcel->readFloat(&maxPreviewFps)) != OK) {
340 ALOGE("%s: Failed to read maxPreviewFps from parcel", __FUNCTION__);
341 return err;
342 }
343
Shuzhen Wang316781a2020-08-18 18:11:01 -0700344 int32_t sessionType;
345 if ((err = parcel->readInt32(&sessionType)) != OK) {
346 ALOGE("%s: Failed to read session type from parcel", __FUNCTION__);
347 return err;
348 }
349
350 int32_t internalReconfigure;
351 if ((err = parcel->readInt32(&internalReconfigure)) != OK) {
352 ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__);
353 return err;
354 }
355
356 int64_t requestCount;
357 if ((err = parcel->readInt64(&requestCount)) != OK) {
358 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
359 return err;
360 }
361
362 int64_t resultErrorCount;
363 if ((err = parcel->readInt64(&resultErrorCount)) != OK) {
364 ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__);
365 return err;
366 }
367
368 bool deviceError;
369 if ((err = parcel->readBool(&deviceError)) != OK) {
370 ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__);
371 return err;
372 }
373
374 std::vector<CameraStreamStats> streamStats;
375 if ((err = parcel->readParcelableVector(&streamStats)) != OK) {
376 ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__);
377 return err;
378 }
379
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800380 String16 userTag;
381 if ((err = parcel->readString16(&userTag)) != OK) {
382 ALOGE("%s: Failed to read user tag!", __FUNCTION__);
383 return BAD_VALUE;
384 }
385
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700386 int32_t videoStabilizationMode;
387 if ((err = parcel->readInt32(&videoStabilizationMode)) != OK) {
388 ALOGE("%s: Failed to read video stabilization mode from parcel", __FUNCTION__);
389 return err;
390 }
391
Shuzhen Wang316781a2020-08-18 18:11:01 -0700392 mCameraId = id;
393 mFacing = facing;
394 mNewCameraState = newCameraState;
395 mClientName = clientName;
396 mApiLevel = apiLevel;
397 mIsNdk = isNdk;
398 mLatencyMs = latencyMs;
Austin Borger4a870a32022-02-25 01:48:41 +0000399 mMaxPreviewFps = maxPreviewFps;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700400 mSessionType = sessionType;
401 mInternalReconfigure = internalReconfigure;
402 mRequestCount = requestCount;
403 mResultErrorCount = resultErrorCount;
404 mDeviceError = deviceError;
405 mStreamStats = std::move(streamStats);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800406 mUserTag = userTag;
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700407 mVideoStabilizationMode = videoStabilizationMode;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700408
409 return OK;
410}
411
412status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
413 if (parcel == NULL) {
414 ALOGE("%s: Null parcel", __FUNCTION__);
415 return BAD_VALUE;
416 }
417
418 status_t err = OK;
419
420 if ((err = parcel->writeString16(mCameraId)) != OK) {
421 ALOGE("%s: Failed to write camera id!", __FUNCTION__);
422 return err;
423 }
424
425 if ((err = parcel->writeInt32(mFacing)) != OK) {
426 ALOGE("%s: Failed to write camera facing!", __FUNCTION__);
427 return err;
428 }
429
430 if ((err = parcel->writeInt32(mNewCameraState)) != OK) {
431 ALOGE("%s: Failed to write new camera state!", __FUNCTION__);
432 return err;
433 }
434
435 if ((err = parcel->writeString16(mClientName)) != OK) {
436 ALOGE("%s: Failed to write client name!", __FUNCTION__);
437 return err;
438 }
439
440 if ((err = parcel->writeInt32(mApiLevel)) != OK) {
441 ALOGE("%s: Failed to write api level!", __FUNCTION__);
442 return err;
443 }
444
445 if ((err = parcel->writeBool(mIsNdk)) != OK) {
446 ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__);
447 return err;
448 }
449
450 if ((err = parcel->writeInt32(mLatencyMs)) != OK) {
451 ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__);
452 return err;
453 }
454
Austin Borger4a870a32022-02-25 01:48:41 +0000455 if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
456 ALOGE("%s: Failed to write maxPreviewFps!", __FUNCTION__);
457 return err;
458 }
459
Shuzhen Wang316781a2020-08-18 18:11:01 -0700460 if ((err = parcel->writeInt32(mSessionType)) != OK) {
461 ALOGE("%s: Failed to write session type!", __FUNCTION__);
462 return err;
463 }
464
465 if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) {
466 ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__);
467 return err;
468 }
469
470 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
471 ALOGE("%s: Failed to write request count!", __FUNCTION__);
472 return err;
473 }
474
475 if ((err = parcel->writeInt64(mResultErrorCount)) != OK) {
476 ALOGE("%s: Failed to write result error count!", __FUNCTION__);
477 return err;
478 }
479
480 if ((err = parcel->writeBool(mDeviceError)) != OK) {
481 ALOGE("%s: Failed to write device error flag!", __FUNCTION__);
482 return err;
483 }
484
485 if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) {
486 ALOGE("%s: Failed to write stream states!", __FUNCTION__);
487 return err;
488 }
489
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800490 if ((err = parcel->writeString16(mUserTag)) != OK) {
491 ALOGE("%s: Failed to write user tag!", __FUNCTION__);
492 return err;
493 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700494
495 if ((err = parcel->writeInt32(mVideoStabilizationMode)) != OK) {
496 ALOGE("%s: Failed to write video stabilization mode!", __FUNCTION__);
497 return err;
498 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700499 return OK;
500}
501
502} // namespace hardware
503} // namesmpace android