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