blob: fb7bf29c8df6805a246be67f841b9f407d2e34a2 [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>
Austin Borger0fb3ad92023-06-01 16:51:35 -070023#include <camera/StringUtils.h>
Shuzhen Wang316781a2020-08-18 18:11:01 -070024
25#include <binder/Parcel.h>
26
27namespace android {
28namespace hardware {
29
30status_t CameraStreamStats::readFromParcel(const android::Parcel* parcel) {
31 if (parcel == NULL) {
32 ALOGE("%s: Null parcel", __FUNCTION__);
33 return BAD_VALUE;
34 }
35
36 status_t err = OK;
37
38 int width = 0;
39 if ((err = parcel->readInt32(&width)) != OK) {
40 ALOGE("%s: Failed to read width from parcel", __FUNCTION__);
41 return err;
42 }
43
44 int height = 0;
45 if ((err = parcel->readInt32(&height)) != OK) {
46 ALOGE("%s: Failed to read height from parcel", __FUNCTION__);
47 return err;
48 }
49
50 int format = 0;
51 if ((err = parcel->readInt32(&format)) != OK) {
52 ALOGE("%s: Failed to read format from parcel", __FUNCTION__);
53 return err;
54 }
55
Austin Borger4a870a32022-02-25 01:48:41 +000056 float maxPreviewFps = 0;
57 if ((err = parcel->readFloat(&maxPreviewFps)) != OK) {
58 ALOGE("%s: Failed to read maxPreviewFps from parcel", __FUNCTION__);
59 return err;
60 }
61
Shuzhen Wang316781a2020-08-18 18:11:01 -070062 int dataSpace = 0;
63 if ((err = parcel->readInt32(&dataSpace)) != OK) {
64 ALOGE("%s: Failed to read dataSpace from parcel", __FUNCTION__);
65 return err;
66 }
67
68 int64_t usage = 0;
69 if ((err = parcel->readInt64(&usage)) != OK) {
70 ALOGE("%s: Failed to read usage from parcel", __FUNCTION__);
71 return err;
72 }
73
74 int64_t requestCount = 0;
75 if ((err = parcel->readInt64(&requestCount)) != OK) {
76 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
77 return err;
78 }
79
80 int64_t errorCount = 0;
81 if ((err = parcel->readInt64(&errorCount)) != OK) {
82 ALOGE("%s: Failed to read error count from parcel", __FUNCTION__);
83 return err;
84 }
85
86 int startLatencyMs = 0;
87 if ((err = parcel->readInt32(&startLatencyMs)) != OK) {
88 ALOGE("%s: Failed to read start latency from parcel", __FUNCTION__);
89 return err;
90 }
91
92 int maxHalBuffers = 0;
93 if ((err = parcel->readInt32(&maxHalBuffers)) != OK) {
94 ALOGE("%s: Failed to read max Hal buffers from parcel", __FUNCTION__);
95 return err;
96 }
97
98 int maxAppBuffers = 0;
99 if ((err = parcel->readInt32(&maxAppBuffers)) != OK) {
100 ALOGE("%s: Failed to read max app buffers from parcel", __FUNCTION__);
101 return err;
102 }
103
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700104 int histogramType = HISTOGRAM_TYPE_UNKNOWN;
105 if ((err = parcel->readInt32(&histogramType)) != OK) {
106 ALOGE("%s: Failed to read histogram type from parcel", __FUNCTION__);
107 return err;
108 }
109
110 std::vector<float> histogramBins;
111 if ((err = parcel->readFloatVector(&histogramBins)) != OK) {
112 ALOGE("%s: Failed to read histogram bins from parcel", __FUNCTION__);
113 return err;
114 }
115
116 std::vector<int64_t> histogramCounts;
117 if ((err = parcel->readInt64Vector(&histogramCounts)) != OK) {
118 ALOGE("%s: Failed to read histogram counts from parcel", __FUNCTION__);
119 return err;
120 }
121
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800122 int64_t dynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
123 if ((err = parcel->readInt64(&dynamicRangeProfile)) != OK) {
Emilian Peev2295df72021-11-12 18:14:10 -0800124 ALOGE("%s: Failed to read dynamic range profile type from parcel", __FUNCTION__);
125 return err;
126 }
127
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800128 int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
129 if ((err = parcel->readInt64(&streamUseCase)) != OK) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800130 ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
131 return err;
132 }
133
Shuzhen Wang316781a2020-08-18 18:11:01 -0700134 mWidth = width;
135 mHeight = height;
136 mFormat = format;
Austin Borger4a870a32022-02-25 01:48:41 +0000137 mMaxPreviewFps = maxPreviewFps;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700138 mDataSpace = dataSpace;
139 mUsage = usage;
140 mRequestCount = requestCount;
141 mErrorCount = errorCount;
142 mStartLatencyMs = startLatencyMs;
143 mMaxHalBuffers = maxHalBuffers;
144 mMaxAppBuffers = maxAppBuffers;
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700145 mHistogramType = histogramType;
146 mHistogramBins = std::move(histogramBins);
147 mHistogramCounts = std::move(histogramCounts);
Emilian Peev2295df72021-11-12 18:14:10 -0800148 mDynamicRangeProfile = dynamicRangeProfile;
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800149 mStreamUseCase = streamUseCase;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700150
151 return OK;
152}
153
154status_t CameraStreamStats::writeToParcel(android::Parcel* parcel) const {
155 if (parcel == NULL) {
156 ALOGE("%s: Null parcel", __FUNCTION__);
157 return BAD_VALUE;
158 }
159
160 status_t err = OK;
161
162 if ((err = parcel->writeInt32(mWidth)) != OK) {
163 ALOGE("%s: Failed to write stream width!", __FUNCTION__);
164 return err;
165 }
166
167 if ((err = parcel->writeInt32(mHeight)) != OK) {
168 ALOGE("%s: Failed to write stream height!", __FUNCTION__);
169 return err;
170 }
171
172 if ((err = parcel->writeInt32(mFormat)) != OK) {
173 ALOGE("%s: Failed to write stream format!", __FUNCTION__);
174 return err;
175 }
176
Austin Borger4a870a32022-02-25 01:48:41 +0000177 if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
178 ALOGE("%s: Failed to write stream maxPreviewFps!", __FUNCTION__);
179 return err;
180 }
181
Shuzhen Wang316781a2020-08-18 18:11:01 -0700182 if ((err = parcel->writeInt32(mDataSpace)) != OK) {
183 ALOGE("%s: Failed to write stream dataSpace!", __FUNCTION__);
184 return err;
185 }
186
187 if ((err = parcel->writeInt64(mUsage)) != OK) {
188 ALOGE("%s: Failed to write stream usage!", __FUNCTION__);
189 return err;
190 }
191
192 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
193 ALOGE("%s: Failed to write stream request count!", __FUNCTION__);
194 return err;
195 }
196
197 if ((err = parcel->writeInt64(mErrorCount)) != OK) {
198 ALOGE("%s: Failed to write stream error count!", __FUNCTION__);
199 return err;
200 }
201
202 if ((err = parcel->writeInt32(mStartLatencyMs)) != OK) {
203 ALOGE("%s: Failed to write stream start latency!", __FUNCTION__);
204 return err;
205 }
206
207 if ((err = parcel->writeInt32(mMaxHalBuffers)) != OK) {
208 ALOGE("%s: Failed to write max hal buffers", __FUNCTION__);
209 return err;
210 }
211
212 if ((err = parcel->writeInt32(mMaxAppBuffers)) != OK) {
213 ALOGE("%s: Failed to write max app buffers", __FUNCTION__);
214 return err;
215 }
216
Shuzhen Wangdb8f2782020-10-30 08:43:37 -0700217 if ((err = parcel->writeInt32(mHistogramType)) != OK) {
218 ALOGE("%s: Failed to write histogram type", __FUNCTION__);
219 return err;
220 }
221
222 if ((err = parcel->writeFloatVector(mHistogramBins)) != OK) {
223 ALOGE("%s: Failed to write histogram bins!", __FUNCTION__);
224 return err;
225 }
226
227 if ((err = parcel->writeInt64Vector(mHistogramCounts)) != OK) {
228 ALOGE("%s: Failed to write histogram counts!", __FUNCTION__);
229 return err;
230 }
231
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800232 if ((err = parcel->writeInt64(mDynamicRangeProfile)) != OK) {
Emilian Peev2295df72021-11-12 18:14:10 -0800233 ALOGE("%s: Failed to write dynamic range profile type", __FUNCTION__);
234 return err;
235 }
236
Shuzhen Wang8ed1e872022-03-08 16:34:33 -0800237 if ((err = parcel->writeInt64(mStreamUseCase)) != OK) {
Shuzhen Wangc8ab4522021-12-14 20:12:42 -0800238 ALOGE("%s: Failed to write stream use case!", __FUNCTION__);
239 return err;
240 }
241
Shuzhen Wang316781a2020-08-18 18:11:01 -0700242 return OK;
243}
244
Shuzhen Wangbac18d92020-11-19 14:50:30 -0800245const int CameraSessionStats::CAMERA_STATE_OPEN = 0;
246const int CameraSessionStats::CAMERA_STATE_ACTIVE = 1;
247const int CameraSessionStats::CAMERA_STATE_IDLE = 2;
248const int CameraSessionStats::CAMERA_STATE_CLOSED = 3;
249
250const int CameraSessionStats::CAMERA_FACING_BACK = 0;
251const int CameraSessionStats::CAMERA_FACING_FRONT = 1;
252const int CameraSessionStats::CAMERA_FACING_EXTERNAL = 2;
253
254const int CameraSessionStats::CAMERA_API_LEVEL_1 = 1;
255const int CameraSessionStats::CAMERA_API_LEVEL_2 = 2;
256
Shuzhen Wang316781a2020-08-18 18:11:01 -0700257CameraSessionStats::CameraSessionStats() :
258 mFacing(CAMERA_FACING_BACK),
259 mNewCameraState(CAMERA_STATE_CLOSED),
260 mApiLevel(0),
261 mIsNdk(false),
262 mLatencyMs(-1),
Austin Borger4a870a32022-02-25 01:48:41 +0000263 mMaxPreviewFps(0),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700264 mSessionType(0),
265 mInternalReconfigure(0),
266 mRequestCount(0),
267 mResultErrorCount(0),
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700268 mDeviceError(false),
269 mVideoStabilizationMode(-1) {}
Shuzhen Wang316781a2020-08-18 18:11:01 -0700270
Austin Borger0fb3ad92023-06-01 16:51:35 -0700271CameraSessionStats::CameraSessionStats(const std::string& cameraId,
272 int facing, int newCameraState, const std::string& clientName,
Shuzhen Wang316781a2020-08-18 18:11:01 -0700273 int apiLevel, bool isNdk, int32_t latencyMs) :
274 mCameraId(cameraId),
275 mFacing(facing),
276 mNewCameraState(newCameraState),
277 mClientName(clientName),
278 mApiLevel(apiLevel),
279 mIsNdk(isNdk),
280 mLatencyMs(latencyMs),
Austin Borger4a870a32022-02-25 01:48:41 +0000281 mMaxPreviewFps(0),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700282 mSessionType(0),
283 mInternalReconfigure(0),
284 mRequestCount(0),
285 mResultErrorCount(0),
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700286 mDeviceError(0),
287 mVideoStabilizationMode(-1) {}
Shuzhen Wang316781a2020-08-18 18:11:01 -0700288
289status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
290 if (parcel == NULL) {
291 ALOGE("%s: Null parcel", __FUNCTION__);
292 return BAD_VALUE;
293 }
294
295 status_t err = OK;
296
297 String16 id;
298 if ((err = parcel->readString16(&id)) != OK) {
299 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
300 return BAD_VALUE;
301 }
302
303 int facing = 0;
304 if ((err = parcel->readInt32(&facing)) != OK) {
305 ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__);
306 return err;
307 }
308
309 int32_t newCameraState;
310 if ((err = parcel->readInt32(&newCameraState)) != OK) {
311 ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__);
312 return err;
313 }
314
315 String16 clientName;
316 if ((err = parcel->readString16(&clientName)) != OK) {
317 ALOGE("%s: Failed to read client name!", __FUNCTION__);
318 return BAD_VALUE;
319 }
320
321 int32_t apiLevel;
322 if ((err = parcel->readInt32(&apiLevel)) != OK) {
323 ALOGE("%s: Failed to read api level from parcel", __FUNCTION__);
324 return err;
325 }
326
327 bool isNdk;
328 if ((err = parcel->readBool(&isNdk)) != OK) {
329 ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__);
330 return err;
331 }
332
333 int32_t latencyMs;
334 if ((err = parcel->readInt32(&latencyMs)) != OK) {
335 ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__);
336 return err;
337 }
338
Austin Borger4a870a32022-02-25 01:48:41 +0000339 float maxPreviewFps;
340 if ((err = parcel->readFloat(&maxPreviewFps)) != OK) {
341 ALOGE("%s: Failed to read maxPreviewFps from parcel", __FUNCTION__);
342 return err;
343 }
344
Shuzhen Wang316781a2020-08-18 18:11:01 -0700345 int32_t sessionType;
346 if ((err = parcel->readInt32(&sessionType)) != OK) {
347 ALOGE("%s: Failed to read session type from parcel", __FUNCTION__);
348 return err;
349 }
350
351 int32_t internalReconfigure;
352 if ((err = parcel->readInt32(&internalReconfigure)) != OK) {
353 ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__);
354 return err;
355 }
356
357 int64_t requestCount;
358 if ((err = parcel->readInt64(&requestCount)) != OK) {
359 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
360 return err;
361 }
362
363 int64_t resultErrorCount;
364 if ((err = parcel->readInt64(&resultErrorCount)) != OK) {
365 ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__);
366 return err;
367 }
368
369 bool deviceError;
370 if ((err = parcel->readBool(&deviceError)) != OK) {
371 ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__);
372 return err;
373 }
374
375 std::vector<CameraStreamStats> streamStats;
376 if ((err = parcel->readParcelableVector(&streamStats)) != OK) {
377 ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__);
378 return err;
379 }
380
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800381 String16 userTag;
382 if ((err = parcel->readString16(&userTag)) != OK) {
383 ALOGE("%s: Failed to read user tag!", __FUNCTION__);
384 return BAD_VALUE;
385 }
386
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700387 int32_t videoStabilizationMode;
388 if ((err = parcel->readInt32(&videoStabilizationMode)) != OK) {
389 ALOGE("%s: Failed to read video stabilization mode from parcel", __FUNCTION__);
390 return err;
391 }
392
Austin Borger0fb3ad92023-06-01 16:51:35 -0700393 mCameraId = toStdString(id);
Shuzhen Wang316781a2020-08-18 18:11:01 -0700394 mFacing = facing;
395 mNewCameraState = newCameraState;
Austin Borger0fb3ad92023-06-01 16:51:35 -0700396 mClientName = toStdString(clientName);
Shuzhen Wang316781a2020-08-18 18:11:01 -0700397 mApiLevel = apiLevel;
398 mIsNdk = isNdk;
399 mLatencyMs = latencyMs;
Austin Borger4a870a32022-02-25 01:48:41 +0000400 mMaxPreviewFps = maxPreviewFps;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700401 mSessionType = sessionType;
402 mInternalReconfigure = internalReconfigure;
403 mRequestCount = requestCount;
404 mResultErrorCount = resultErrorCount;
405 mDeviceError = deviceError;
406 mStreamStats = std::move(streamStats);
Austin Borger0fb3ad92023-06-01 16:51:35 -0700407 mUserTag = toStdString(userTag);
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700408 mVideoStabilizationMode = videoStabilizationMode;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700409
410 return OK;
411}
412
413status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
414 if (parcel == NULL) {
415 ALOGE("%s: Null parcel", __FUNCTION__);
416 return BAD_VALUE;
417 }
418
419 status_t err = OK;
420
Austin Borger0fb3ad92023-06-01 16:51:35 -0700421 if ((err = parcel->writeString16(toString16(mCameraId))) != OK) {
Shuzhen Wang316781a2020-08-18 18:11:01 -0700422 ALOGE("%s: Failed to write camera id!", __FUNCTION__);
423 return err;
424 }
425
426 if ((err = parcel->writeInt32(mFacing)) != OK) {
427 ALOGE("%s: Failed to write camera facing!", __FUNCTION__);
428 return err;
429 }
430
431 if ((err = parcel->writeInt32(mNewCameraState)) != OK) {
432 ALOGE("%s: Failed to write new camera state!", __FUNCTION__);
433 return err;
434 }
435
Austin Borger0fb3ad92023-06-01 16:51:35 -0700436 if ((err = parcel->writeString16(toString16(mClientName))) != OK) {
Shuzhen Wang316781a2020-08-18 18:11:01 -0700437 ALOGE("%s: Failed to write client name!", __FUNCTION__);
438 return err;
439 }
440
441 if ((err = parcel->writeInt32(mApiLevel)) != OK) {
442 ALOGE("%s: Failed to write api level!", __FUNCTION__);
443 return err;
444 }
445
446 if ((err = parcel->writeBool(mIsNdk)) != OK) {
447 ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__);
448 return err;
449 }
450
451 if ((err = parcel->writeInt32(mLatencyMs)) != OK) {
452 ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__);
453 return err;
454 }
455
Austin Borger4a870a32022-02-25 01:48:41 +0000456 if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
457 ALOGE("%s: Failed to write maxPreviewFps!", __FUNCTION__);
458 return err;
459 }
460
Shuzhen Wang316781a2020-08-18 18:11:01 -0700461 if ((err = parcel->writeInt32(mSessionType)) != OK) {
462 ALOGE("%s: Failed to write session type!", __FUNCTION__);
463 return err;
464 }
465
466 if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) {
467 ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__);
468 return err;
469 }
470
471 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
472 ALOGE("%s: Failed to write request count!", __FUNCTION__);
473 return err;
474 }
475
476 if ((err = parcel->writeInt64(mResultErrorCount)) != OK) {
477 ALOGE("%s: Failed to write result error count!", __FUNCTION__);
478 return err;
479 }
480
481 if ((err = parcel->writeBool(mDeviceError)) != OK) {
482 ALOGE("%s: Failed to write device error flag!", __FUNCTION__);
483 return err;
484 }
485
486 if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) {
487 ALOGE("%s: Failed to write stream states!", __FUNCTION__);
488 return err;
489 }
490
Austin Borger0fb3ad92023-06-01 16:51:35 -0700491 if ((err = parcel->writeString16(toString16(mUserTag))) != OK) {
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800492 ALOGE("%s: Failed to write user tag!", __FUNCTION__);
493 return err;
494 }
Shuzhen Wang9372b0b2022-05-11 18:55:19 -0700495
496 if ((err = parcel->writeInt32(mVideoStabilizationMode)) != OK) {
497 ALOGE("%s: Failed to write video stabilization mode!", __FUNCTION__);
498 return err;
499 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700500 return OK;
501}
502
503} // namespace hardware
504} // namesmpace android