blob: 3954db58d71222adc8caaaeaa7388f89ae82ebdd [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
Austin Borger9e2b27c2022-07-15 11:27:24 -0700133 int32_t colorSpace = ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED;
134 if ((err = parcel->readInt32(&colorSpace)) != OK) {
135 ALOGE("%s: Failed to read color space from parcel", __FUNCTION__);
136 return err;
137 }
138
Shuzhen Wang316781a2020-08-18 18:11:01 -0700139 mWidth = width;
140 mHeight = height;
141 mFormat = format;
Austin Borger4a870a32022-02-25 01:48:41 +0000142 mMaxPreviewFps = maxPreviewFps;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700143 mDataSpace = dataSpace;
144 mUsage = usage;
145 mRequestCount = requestCount;
146 mErrorCount = errorCount;
147 mStartLatencyMs = startLatencyMs;
148 mMaxHalBuffers = maxHalBuffers;
149 mMaxAppBuffers = maxAppBuffers;
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700150 mHistogramType = histogramType;
151 mHistogramBins = std::move(histogramBins);
152 mHistogramCounts = std::move(histogramCounts);
Emilian Peev2295df72021-11-12 18:14:10 -0800153 mDynamicRangeProfile = dynamicRangeProfile;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800154 mStreamUseCase = streamUseCase;
Austin Borger9e2b27c2022-07-15 11:27:24 -0700155 mColorSpace = colorSpace;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700156
157 return OK;
158}
159
160status_t CameraStreamStats::writeToParcel(android::Parcel* parcel) const {
161 if (parcel == NULL) {
162 ALOGE("%s: Null parcel", __FUNCTION__);
163 return BAD_VALUE;
164 }
165
166 status_t err = OK;
167
168 if ((err = parcel->writeInt32(mWidth)) != OK) {
169 ALOGE("%s: Failed to write stream width!", __FUNCTION__);
170 return err;
171 }
172
173 if ((err = parcel->writeInt32(mHeight)) != OK) {
174 ALOGE("%s: Failed to write stream height!", __FUNCTION__);
175 return err;
176 }
177
178 if ((err = parcel->writeInt32(mFormat)) != OK) {
179 ALOGE("%s: Failed to write stream format!", __FUNCTION__);
180 return err;
181 }
182
Austin Borger4a870a32022-02-25 01:48:41 +0000183 if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
184 ALOGE("%s: Failed to write stream maxPreviewFps!", __FUNCTION__);
185 return err;
186 }
187
Shuzhen Wang316781a2020-08-18 18:11:01 -0700188 if ((err = parcel->writeInt32(mDataSpace)) != OK) {
189 ALOGE("%s: Failed to write stream dataSpace!", __FUNCTION__);
190 return err;
191 }
192
193 if ((err = parcel->writeInt64(mUsage)) != OK) {
194 ALOGE("%s: Failed to write stream usage!", __FUNCTION__);
195 return err;
196 }
197
198 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
199 ALOGE("%s: Failed to write stream request count!", __FUNCTION__);
200 return err;
201 }
202
203 if ((err = parcel->writeInt64(mErrorCount)) != OK) {
204 ALOGE("%s: Failed to write stream error count!", __FUNCTION__);
205 return err;
206 }
207
208 if ((err = parcel->writeInt32(mStartLatencyMs)) != OK) {
209 ALOGE("%s: Failed to write stream start latency!", __FUNCTION__);
210 return err;
211 }
212
213 if ((err = parcel->writeInt32(mMaxHalBuffers)) != OK) {
214 ALOGE("%s: Failed to write max hal buffers", __FUNCTION__);
215 return err;
216 }
217
218 if ((err = parcel->writeInt32(mMaxAppBuffers)) != OK) {
219 ALOGE("%s: Failed to write max app buffers", __FUNCTION__);
220 return err;
221 }
222
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700223 if ((err = parcel->writeInt32(mHistogramType)) != OK) {
224 ALOGE("%s: Failed to write histogram type", __FUNCTION__);
225 return err;
226 }
227
228 if ((err = parcel->writeFloatVector(mHistogramBins)) != OK) {
229 ALOGE("%s: Failed to write histogram bins!", __FUNCTION__);
230 return err;
231 }
232
233 if ((err = parcel->writeInt64Vector(mHistogramCounts)) != OK) {
234 ALOGE("%s: Failed to write histogram counts!", __FUNCTION__);
235 return err;
236 }
237
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800238 if ((err = parcel->writeInt64(mDynamicRangeProfile)) != OK) {
Emilian Peev2295df72021-11-12 18:14:10 -0800239 ALOGE("%s: Failed to write dynamic range profile type", __FUNCTION__);
240 return err;
241 }
242
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800243 if ((err = parcel->writeInt64(mStreamUseCase)) != OK) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800244 ALOGE("%s: Failed to write stream use case!", __FUNCTION__);
245 return err;
246 }
247
Austin Borger9e2b27c2022-07-15 11:27:24 -0700248 if ((err = parcel->writeInt32(mColorSpace)) != OK) {
249 ALOGE("%s: Failed to write color space", __FUNCTION__);
250 return err;
251 }
252
Shuzhen Wang316781a2020-08-18 18:11:01 -0700253 return OK;
254}
255
Shuzhen Wangbac18d92020-11-19 14:50:30 -0800256const int CameraSessionStats::CAMERA_STATE_OPEN = 0;
257const int CameraSessionStats::CAMERA_STATE_ACTIVE = 1;
258const int CameraSessionStats::CAMERA_STATE_IDLE = 2;
259const int CameraSessionStats::CAMERA_STATE_CLOSED = 3;
260
261const int CameraSessionStats::CAMERA_FACING_BACK = 0;
262const int CameraSessionStats::CAMERA_FACING_FRONT = 1;
263const int CameraSessionStats::CAMERA_FACING_EXTERNAL = 2;
264
265const int CameraSessionStats::CAMERA_API_LEVEL_1 = 1;
266const int CameraSessionStats::CAMERA_API_LEVEL_2 = 2;
267
Shuzhen Wang316781a2020-08-18 18:11:01 -0700268CameraSessionStats::CameraSessionStats() :
269 mFacing(CAMERA_FACING_BACK),
270 mNewCameraState(CAMERA_STATE_CLOSED),
271 mApiLevel(0),
272 mIsNdk(false),
273 mLatencyMs(-1),
Avichal Rakesh88fc5222023-03-03 15:00:59 -0800274 mLogId(0),
Austin Borger4a870a32022-02-25 01:48:41 +0000275 mMaxPreviewFps(0),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700276 mSessionType(0),
277 mInternalReconfigure(0),
278 mRequestCount(0),
279 mResultErrorCount(0),
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700280 mDeviceError(false),
Avichal Rakesh89691e12023-05-01 19:41:02 -0700281 mVideoStabilizationMode(-1),
282 mSessionIndex(0) {}
Shuzhen Wang316781a2020-08-18 18:11:01 -0700283
284CameraSessionStats::CameraSessionStats(const String16& cameraId,
285 int facing, int newCameraState, const String16& clientName,
Avichal Rakesh88fc5222023-03-03 15:00:59 -0800286 int apiLevel, bool isNdk, int32_t latencyMs, int64_t logId) :
Shuzhen Wang316781a2020-08-18 18:11:01 -0700287 mCameraId(cameraId),
288 mFacing(facing),
289 mNewCameraState(newCameraState),
290 mClientName(clientName),
291 mApiLevel(apiLevel),
292 mIsNdk(isNdk),
293 mLatencyMs(latencyMs),
Avichal Rakesh88fc5222023-03-03 15:00:59 -0800294 mLogId(logId),
Austin Borger4a870a32022-02-25 01:48:41 +0000295 mMaxPreviewFps(0),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700296 mSessionType(0),
297 mInternalReconfigure(0),
298 mRequestCount(0),
299 mResultErrorCount(0),
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700300 mDeviceError(0),
Avichal Rakesh89691e12023-05-01 19:41:02 -0700301 mVideoStabilizationMode(-1),
302 mSessionIndex(0) {}
Shuzhen Wang316781a2020-08-18 18:11:01 -0700303
304status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
305 if (parcel == NULL) {
306 ALOGE("%s: Null parcel", __FUNCTION__);
307 return BAD_VALUE;
308 }
309
310 status_t err = OK;
311
312 String16 id;
313 if ((err = parcel->readString16(&id)) != OK) {
314 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
315 return BAD_VALUE;
316 }
317
318 int facing = 0;
319 if ((err = parcel->readInt32(&facing)) != OK) {
320 ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__);
321 return err;
322 }
323
324 int32_t newCameraState;
325 if ((err = parcel->readInt32(&newCameraState)) != OK) {
326 ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__);
327 return err;
328 }
329
330 String16 clientName;
331 if ((err = parcel->readString16(&clientName)) != OK) {
332 ALOGE("%s: Failed to read client name!", __FUNCTION__);
333 return BAD_VALUE;
334 }
335
336 int32_t apiLevel;
337 if ((err = parcel->readInt32(&apiLevel)) != OK) {
338 ALOGE("%s: Failed to read api level from parcel", __FUNCTION__);
339 return err;
340 }
341
342 bool isNdk;
343 if ((err = parcel->readBool(&isNdk)) != OK) {
344 ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__);
345 return err;
346 }
347
348 int32_t latencyMs;
349 if ((err = parcel->readInt32(&latencyMs)) != OK) {
350 ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__);
351 return err;
352 }
353
Avichal Rakesh88fc5222023-03-03 15:00:59 -0800354 int64_t logId;
355 if ((err = parcel->readInt64(&logId)) != OK) {
356 ALOGE("%s: Failed to read log ID from parcel", __FUNCTION__);
357 return err;
358 }
359
Austin Borger4a870a32022-02-25 01:48:41 +0000360 float maxPreviewFps;
361 if ((err = parcel->readFloat(&maxPreviewFps)) != OK) {
362 ALOGE("%s: Failed to read maxPreviewFps from parcel", __FUNCTION__);
363 return err;
364 }
365
Shuzhen Wang316781a2020-08-18 18:11:01 -0700366 int32_t sessionType;
367 if ((err = parcel->readInt32(&sessionType)) != OK) {
368 ALOGE("%s: Failed to read session type from parcel", __FUNCTION__);
369 return err;
370 }
371
372 int32_t internalReconfigure;
373 if ((err = parcel->readInt32(&internalReconfigure)) != OK) {
374 ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__);
375 return err;
376 }
377
378 int64_t requestCount;
379 if ((err = parcel->readInt64(&requestCount)) != OK) {
380 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
381 return err;
382 }
383
384 int64_t resultErrorCount;
385 if ((err = parcel->readInt64(&resultErrorCount)) != OK) {
386 ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__);
387 return err;
388 }
389
390 bool deviceError;
391 if ((err = parcel->readBool(&deviceError)) != OK) {
392 ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__);
393 return err;
394 }
395
396 std::vector<CameraStreamStats> streamStats;
397 if ((err = parcel->readParcelableVector(&streamStats)) != OK) {
398 ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__);
399 return err;
400 }
401
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800402 String16 userTag;
403 if ((err = parcel->readString16(&userTag)) != OK) {
404 ALOGE("%s: Failed to read user tag!", __FUNCTION__);
405 return BAD_VALUE;
406 }
407
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700408 int32_t videoStabilizationMode;
409 if ((err = parcel->readInt32(&videoStabilizationMode)) != OK) {
410 ALOGE("%s: Failed to read video stabilization mode from parcel", __FUNCTION__);
411 return err;
412 }
413
Avichal Rakesh89691e12023-05-01 19:41:02 -0700414 int32_t sessionIdx;
415 if ((err = parcel->readInt32(&sessionIdx)) != OK) {
416 ALOGE("%s: Failed to read session index from parcel", __FUNCTION__);
417 return err;
418 }
419
Shuzhen Wang316781a2020-08-18 18:11:01 -0700420 mCameraId = id;
421 mFacing = facing;
422 mNewCameraState = newCameraState;
423 mClientName = clientName;
424 mApiLevel = apiLevel;
425 mIsNdk = isNdk;
426 mLatencyMs = latencyMs;
Avichal Rakesh88fc5222023-03-03 15:00:59 -0800427 mLogId = logId;
Austin Borger4a870a32022-02-25 01:48:41 +0000428 mMaxPreviewFps = maxPreviewFps;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700429 mSessionType = sessionType;
430 mInternalReconfigure = internalReconfigure;
431 mRequestCount = requestCount;
432 mResultErrorCount = resultErrorCount;
433 mDeviceError = deviceError;
434 mStreamStats = std::move(streamStats);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800435 mUserTag = userTag;
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700436 mVideoStabilizationMode = videoStabilizationMode;
Avichal Rakesh89691e12023-05-01 19:41:02 -0700437 mSessionIndex = sessionIdx;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700438
439 return OK;
440}
441
442status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
443 if (parcel == NULL) {
444 ALOGE("%s: Null parcel", __FUNCTION__);
445 return BAD_VALUE;
446 }
447
448 status_t err = OK;
449
450 if ((err = parcel->writeString16(mCameraId)) != OK) {
451 ALOGE("%s: Failed to write camera id!", __FUNCTION__);
452 return err;
453 }
454
455 if ((err = parcel->writeInt32(mFacing)) != OK) {
456 ALOGE("%s: Failed to write camera facing!", __FUNCTION__);
457 return err;
458 }
459
460 if ((err = parcel->writeInt32(mNewCameraState)) != OK) {
461 ALOGE("%s: Failed to write new camera state!", __FUNCTION__);
462 return err;
463 }
464
465 if ((err = parcel->writeString16(mClientName)) != OK) {
466 ALOGE("%s: Failed to write client name!", __FUNCTION__);
467 return err;
468 }
469
470 if ((err = parcel->writeInt32(mApiLevel)) != OK) {
471 ALOGE("%s: Failed to write api level!", __FUNCTION__);
472 return err;
473 }
474
475 if ((err = parcel->writeBool(mIsNdk)) != OK) {
476 ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__);
477 return err;
478 }
479
480 if ((err = parcel->writeInt32(mLatencyMs)) != OK) {
481 ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__);
482 return err;
483 }
484
Avichal Rakesh88fc5222023-03-03 15:00:59 -0800485 if ((err = parcel->writeInt64(mLogId)) != OK) {
486 ALOGE("%s: Failed to write log ID!", __FUNCTION__);
487 return err;
488 }
489
Austin Borger4a870a32022-02-25 01:48:41 +0000490 if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
491 ALOGE("%s: Failed to write maxPreviewFps!", __FUNCTION__);
492 return err;
493 }
494
Shuzhen Wang316781a2020-08-18 18:11:01 -0700495 if ((err = parcel->writeInt32(mSessionType)) != OK) {
496 ALOGE("%s: Failed to write session type!", __FUNCTION__);
497 return err;
498 }
499
500 if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) {
501 ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__);
502 return err;
503 }
504
505 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
506 ALOGE("%s: Failed to write request count!", __FUNCTION__);
507 return err;
508 }
509
510 if ((err = parcel->writeInt64(mResultErrorCount)) != OK) {
511 ALOGE("%s: Failed to write result error count!", __FUNCTION__);
512 return err;
513 }
514
515 if ((err = parcel->writeBool(mDeviceError)) != OK) {
516 ALOGE("%s: Failed to write device error flag!", __FUNCTION__);
517 return err;
518 }
519
520 if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) {
521 ALOGE("%s: Failed to write stream states!", __FUNCTION__);
522 return err;
523 }
524
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800525 if ((err = parcel->writeString16(mUserTag)) != OK) {
526 ALOGE("%s: Failed to write user tag!", __FUNCTION__);
527 return err;
528 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700529
530 if ((err = parcel->writeInt32(mVideoStabilizationMode)) != OK) {
531 ALOGE("%s: Failed to write video stabilization mode!", __FUNCTION__);
532 return err;
533 }
Avichal Rakesh88fc5222023-03-03 15:00:59 -0800534
Avichal Rakesh89691e12023-05-01 19:41:02 -0700535 if ((err = parcel->writeInt32(mSessionIndex)) != OK) {
536 ALOGE("%s: Failed to write session index!", __FUNCTION__);
537 return err;
538 }
539
Shuzhen Wang316781a2020-08-18 18:11:01 -0700540 return OK;
541}
542
543} // namespace hardware
544} // namesmpace android