blob: 8088d067f0e44655ac3248c6ef166cb45818e483 [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),
267 mDeviceError(false) {}
268
269CameraSessionStats::CameraSessionStats(const String16& cameraId,
270 int facing, int newCameraState, const String16& clientName,
271 int apiLevel, bool isNdk, int32_t latencyMs) :
272 mCameraId(cameraId),
273 mFacing(facing),
274 mNewCameraState(newCameraState),
275 mClientName(clientName),
276 mApiLevel(apiLevel),
277 mIsNdk(isNdk),
278 mLatencyMs(latencyMs),
Austin Borger4a870a32022-02-25 01:48:41 +0000279 mMaxPreviewFps(0),
Shuzhen Wang316781a2020-08-18 18:11:01 -0700280 mSessionType(0),
281 mInternalReconfigure(0),
282 mRequestCount(0),
283 mResultErrorCount(0),
284 mDeviceError(0) {}
285
286status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
287 if (parcel == NULL) {
288 ALOGE("%s: Null parcel", __FUNCTION__);
289 return BAD_VALUE;
290 }
291
292 status_t err = OK;
293
294 String16 id;
295 if ((err = parcel->readString16(&id)) != OK) {
296 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
297 return BAD_VALUE;
298 }
299
300 int facing = 0;
301 if ((err = parcel->readInt32(&facing)) != OK) {
302 ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__);
303 return err;
304 }
305
306 int32_t newCameraState;
307 if ((err = parcel->readInt32(&newCameraState)) != OK) {
308 ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__);
309 return err;
310 }
311
312 String16 clientName;
313 if ((err = parcel->readString16(&clientName)) != OK) {
314 ALOGE("%s: Failed to read client name!", __FUNCTION__);
315 return BAD_VALUE;
316 }
317
318 int32_t apiLevel;
319 if ((err = parcel->readInt32(&apiLevel)) != OK) {
320 ALOGE("%s: Failed to read api level from parcel", __FUNCTION__);
321 return err;
322 }
323
324 bool isNdk;
325 if ((err = parcel->readBool(&isNdk)) != OK) {
326 ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__);
327 return err;
328 }
329
330 int32_t latencyMs;
331 if ((err = parcel->readInt32(&latencyMs)) != OK) {
332 ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__);
333 return err;
334 }
335
Austin Borger4a870a32022-02-25 01:48:41 +0000336 float maxPreviewFps;
337 if ((err = parcel->readFloat(&maxPreviewFps)) != OK) {
338 ALOGE("%s: Failed to read maxPreviewFps from parcel", __FUNCTION__);
339 return err;
340 }
341
Shuzhen Wang316781a2020-08-18 18:11:01 -0700342 int32_t sessionType;
343 if ((err = parcel->readInt32(&sessionType)) != OK) {
344 ALOGE("%s: Failed to read session type from parcel", __FUNCTION__);
345 return err;
346 }
347
348 int32_t internalReconfigure;
349 if ((err = parcel->readInt32(&internalReconfigure)) != OK) {
350 ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__);
351 return err;
352 }
353
354 int64_t requestCount;
355 if ((err = parcel->readInt64(&requestCount)) != OK) {
356 ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
357 return err;
358 }
359
360 int64_t resultErrorCount;
361 if ((err = parcel->readInt64(&resultErrorCount)) != OK) {
362 ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__);
363 return err;
364 }
365
366 bool deviceError;
367 if ((err = parcel->readBool(&deviceError)) != OK) {
368 ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__);
369 return err;
370 }
371
372 std::vector<CameraStreamStats> streamStats;
373 if ((err = parcel->readParcelableVector(&streamStats)) != OK) {
374 ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__);
375 return err;
376 }
377
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800378 String16 userTag;
379 if ((err = parcel->readString16(&userTag)) != OK) {
380 ALOGE("%s: Failed to read user tag!", __FUNCTION__);
381 return BAD_VALUE;
382 }
383
Shuzhen Wang316781a2020-08-18 18:11:01 -0700384 mCameraId = id;
385 mFacing = facing;
386 mNewCameraState = newCameraState;
387 mClientName = clientName;
388 mApiLevel = apiLevel;
389 mIsNdk = isNdk;
390 mLatencyMs = latencyMs;
Austin Borger4a870a32022-02-25 01:48:41 +0000391 mMaxPreviewFps = maxPreviewFps;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700392 mSessionType = sessionType;
393 mInternalReconfigure = internalReconfigure;
394 mRequestCount = requestCount;
395 mResultErrorCount = resultErrorCount;
396 mDeviceError = deviceError;
397 mStreamStats = std::move(streamStats);
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800398 mUserTag = userTag;
Shuzhen Wang316781a2020-08-18 18:11:01 -0700399
400 return OK;
401}
402
403status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
404 if (parcel == NULL) {
405 ALOGE("%s: Null parcel", __FUNCTION__);
406 return BAD_VALUE;
407 }
408
409 status_t err = OK;
410
411 if ((err = parcel->writeString16(mCameraId)) != OK) {
412 ALOGE("%s: Failed to write camera id!", __FUNCTION__);
413 return err;
414 }
415
416 if ((err = parcel->writeInt32(mFacing)) != OK) {
417 ALOGE("%s: Failed to write camera facing!", __FUNCTION__);
418 return err;
419 }
420
421 if ((err = parcel->writeInt32(mNewCameraState)) != OK) {
422 ALOGE("%s: Failed to write new camera state!", __FUNCTION__);
423 return err;
424 }
425
426 if ((err = parcel->writeString16(mClientName)) != OK) {
427 ALOGE("%s: Failed to write client name!", __FUNCTION__);
428 return err;
429 }
430
431 if ((err = parcel->writeInt32(mApiLevel)) != OK) {
432 ALOGE("%s: Failed to write api level!", __FUNCTION__);
433 return err;
434 }
435
436 if ((err = parcel->writeBool(mIsNdk)) != OK) {
437 ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__);
438 return err;
439 }
440
441 if ((err = parcel->writeInt32(mLatencyMs)) != OK) {
442 ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__);
443 return err;
444 }
445
Austin Borger4a870a32022-02-25 01:48:41 +0000446 if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
447 ALOGE("%s: Failed to write maxPreviewFps!", __FUNCTION__);
448 return err;
449 }
450
Shuzhen Wang316781a2020-08-18 18:11:01 -0700451 if ((err = parcel->writeInt32(mSessionType)) != OK) {
452 ALOGE("%s: Failed to write session type!", __FUNCTION__);
453 return err;
454 }
455
456 if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) {
457 ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__);
458 return err;
459 }
460
461 if ((err = parcel->writeInt64(mRequestCount)) != OK) {
462 ALOGE("%s: Failed to write request count!", __FUNCTION__);
463 return err;
464 }
465
466 if ((err = parcel->writeInt64(mResultErrorCount)) != OK) {
467 ALOGE("%s: Failed to write result error count!", __FUNCTION__);
468 return err;
469 }
470
471 if ((err = parcel->writeBool(mDeviceError)) != OK) {
472 ALOGE("%s: Failed to write device error flag!", __FUNCTION__);
473 return err;
474 }
475
476 if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) {
477 ALOGE("%s: Failed to write stream states!", __FUNCTION__);
478 return err;
479 }
480
Shuzhen Wangd26b1862022-03-07 12:05:05 -0800481 if ((err = parcel->writeString16(mUserTag)) != OK) {
482 ALOGE("%s: Failed to write user tag!", __FUNCTION__);
483 return err;
484 }
Shuzhen Wang316781a2020-08-18 18:11:01 -0700485 return OK;
486}
487
488} // namespace hardware
489} // namesmpace android