• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
26 namespace android {
27 namespace hardware {
28 
readFromParcel(const android::Parcel * parcel)29 status_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     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 
61     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 
103     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 
121     int64_t dynamicRangeProfile = ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD;
122     if ((err = parcel->readInt64(&dynamicRangeProfile)) != OK) {
123         ALOGE("%s: Failed to read dynamic range profile type from parcel", __FUNCTION__);
124         return err;
125     }
126 
127     int64_t streamUseCase = ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT;
128     if ((err = parcel->readInt64(&streamUseCase)) != OK) {
129         ALOGE("%s: Failed to read stream use case from parcel", __FUNCTION__);
130         return err;
131     }
132 
133     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 
139     mWidth = width;
140     mHeight = height;
141     mFormat = format;
142     mMaxPreviewFps = maxPreviewFps;
143     mDataSpace = dataSpace;
144     mUsage = usage;
145     mRequestCount = requestCount;
146     mErrorCount = errorCount;
147     mStartLatencyMs = startLatencyMs;
148     mMaxHalBuffers = maxHalBuffers;
149     mMaxAppBuffers = maxAppBuffers;
150     mHistogramType = histogramType;
151     mHistogramBins = std::move(histogramBins);
152     mHistogramCounts = std::move(histogramCounts);
153     mDynamicRangeProfile = dynamicRangeProfile;
154     mStreamUseCase = streamUseCase;
155     mColorSpace = colorSpace;
156 
157     return OK;
158 }
159 
writeToParcel(android::Parcel * parcel) const160 status_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 
183     if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
184         ALOGE("%s: Failed to write stream maxPreviewFps!", __FUNCTION__);
185         return err;
186     }
187 
188     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 
223     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 
238     if ((err = parcel->writeInt64(mDynamicRangeProfile)) != OK) {
239         ALOGE("%s: Failed to write dynamic range profile type", __FUNCTION__);
240         return err;
241     }
242 
243     if ((err = parcel->writeInt64(mStreamUseCase)) != OK) {
244         ALOGE("%s: Failed to write stream use case!", __FUNCTION__);
245         return err;
246     }
247 
248     if ((err = parcel->writeInt32(mColorSpace)) != OK) {
249         ALOGE("%s: Failed to write color space", __FUNCTION__);
250         return err;
251     }
252 
253     return OK;
254 }
255 
256 const int CameraSessionStats::CAMERA_STATE_OPEN = 0;
257 const int CameraSessionStats::CAMERA_STATE_ACTIVE = 1;
258 const int CameraSessionStats::CAMERA_STATE_IDLE = 2;
259 const int CameraSessionStats::CAMERA_STATE_CLOSED = 3;
260 
261 const int CameraSessionStats::CAMERA_FACING_BACK = 0;
262 const int CameraSessionStats::CAMERA_FACING_FRONT = 1;
263 const int CameraSessionStats::CAMERA_FACING_EXTERNAL = 2;
264 
265 const int CameraSessionStats::CAMERA_API_LEVEL_1 = 1;
266 const int CameraSessionStats::CAMERA_API_LEVEL_2 = 2;
267 
CameraSessionStats()268 CameraSessionStats::CameraSessionStats() :
269         mFacing(CAMERA_FACING_BACK),
270         mNewCameraState(CAMERA_STATE_CLOSED),
271         mApiLevel(0),
272         mIsNdk(false),
273         mLatencyMs(-1),
274         mLogId(0),
275         mMaxPreviewFps(0),
276         mSessionType(0),
277         mInternalReconfigure(0),
278         mRequestCount(0),
279         mResultErrorCount(0),
280         mDeviceError(false),
281         mVideoStabilizationMode(-1),
282         mSessionIndex(0),
283         mCameraExtensionSessionStats() {}
284 
CameraSessionStats(const String16 & cameraId,int facing,int newCameraState,const String16 & clientName,int apiLevel,bool isNdk,int32_t latencyMs,int64_t logId)285 CameraSessionStats::CameraSessionStats(const String16& cameraId,
286         int facing, int newCameraState, const String16& clientName,
287         int apiLevel, bool isNdk, int32_t latencyMs, int64_t logId) :
288                 mCameraId(cameraId),
289                 mFacing(facing),
290                 mNewCameraState(newCameraState),
291                 mClientName(clientName),
292                 mApiLevel(apiLevel),
293                 mIsNdk(isNdk),
294                 mLatencyMs(latencyMs),
295                 mLogId(logId),
296                 mMaxPreviewFps(0),
297                 mSessionType(0),
298                 mInternalReconfigure(0),
299                 mRequestCount(0),
300                 mResultErrorCount(0),
301                 mDeviceError(0),
302                 mVideoStabilizationMode(-1),
303                 mSessionIndex(0),
304                 mCameraExtensionSessionStats() {}
305 
readFromParcel(const android::Parcel * parcel)306 status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) {
307     if (parcel == NULL) {
308         ALOGE("%s: Null parcel", __FUNCTION__);
309         return BAD_VALUE;
310     }
311 
312     status_t err = OK;
313 
314     String16 id;
315     if ((err = parcel->readString16(&id)) != OK) {
316         ALOGE("%s: Failed to read camera id!", __FUNCTION__);
317         return BAD_VALUE;
318     }
319 
320     int facing = 0;
321     if ((err = parcel->readInt32(&facing)) != OK) {
322         ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__);
323         return err;
324     }
325 
326     int32_t newCameraState;
327     if ((err = parcel->readInt32(&newCameraState)) != OK) {
328         ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__);
329         return err;
330     }
331 
332     String16 clientName;
333     if ((err = parcel->readString16(&clientName)) != OK) {
334         ALOGE("%s: Failed to read client name!", __FUNCTION__);
335         return BAD_VALUE;
336     }
337 
338     int32_t apiLevel;
339     if ((err = parcel->readInt32(&apiLevel)) != OK) {
340         ALOGE("%s: Failed to read api level from parcel", __FUNCTION__);
341         return err;
342     }
343 
344     bool isNdk;
345     if ((err = parcel->readBool(&isNdk)) != OK) {
346         ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__);
347         return err;
348     }
349 
350     int32_t latencyMs;
351     if ((err = parcel->readInt32(&latencyMs)) != OK) {
352         ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__);
353         return err;
354     }
355 
356     int64_t logId;
357     if ((err = parcel->readInt64(&logId)) != OK) {
358         ALOGE("%s: Failed to read log ID from parcel", __FUNCTION__);
359         return err;
360     }
361 
362     float maxPreviewFps;
363     if ((err = parcel->readFloat(&maxPreviewFps)) != OK) {
364         ALOGE("%s: Failed to read maxPreviewFps from parcel", __FUNCTION__);
365         return err;
366     }
367 
368     int32_t sessionType;
369     if ((err = parcel->readInt32(&sessionType)) != OK) {
370         ALOGE("%s: Failed to read session type from parcel", __FUNCTION__);
371         return err;
372     }
373 
374     int32_t internalReconfigure;
375     if ((err = parcel->readInt32(&internalReconfigure)) != OK) {
376         ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__);
377         return err;
378     }
379 
380     int64_t requestCount;
381     if ((err = parcel->readInt64(&requestCount)) != OK) {
382         ALOGE("%s: Failed to read request count from parcel", __FUNCTION__);
383         return err;
384     }
385 
386     int64_t resultErrorCount;
387     if ((err = parcel->readInt64(&resultErrorCount)) != OK) {
388         ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__);
389         return err;
390     }
391 
392     bool deviceError;
393     if ((err = parcel->readBool(&deviceError)) != OK) {
394         ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__);
395         return err;
396     }
397 
398     std::vector<CameraStreamStats> streamStats;
399     if ((err = parcel->readParcelableVector(&streamStats)) != OK) {
400         ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__);
401         return err;
402     }
403 
404     String16 userTag;
405     if ((err = parcel->readString16(&userTag)) != OK) {
406         ALOGE("%s: Failed to read user tag!", __FUNCTION__);
407         return BAD_VALUE;
408     }
409 
410     int32_t videoStabilizationMode;
411     if ((err = parcel->readInt32(&videoStabilizationMode)) != OK) {
412         ALOGE("%s: Failed to read video stabilization mode from parcel", __FUNCTION__);
413         return err;
414     }
415 
416     int32_t sessionIdx;
417     if ((err = parcel->readInt32(&sessionIdx)) != OK) {
418         ALOGE("%s: Failed to read session index from parcel", __FUNCTION__);
419         return err;
420     }
421 
422     CameraExtensionSessionStats extStats{};
423     if ((err = extStats.readFromParcel(parcel)) != OK) {
424         ALOGE("%s: Failed to read extension session stats from parcel", __FUNCTION__);
425         return err;
426     }
427 
428     mCameraId = id;
429     mFacing = facing;
430     mNewCameraState = newCameraState;
431     mClientName = clientName;
432     mApiLevel = apiLevel;
433     mIsNdk = isNdk;
434     mLatencyMs = latencyMs;
435     mLogId = logId;
436     mMaxPreviewFps = maxPreviewFps;
437     mSessionType = sessionType;
438     mInternalReconfigure = internalReconfigure;
439     mRequestCount = requestCount;
440     mResultErrorCount = resultErrorCount;
441     mDeviceError = deviceError;
442     mStreamStats = std::move(streamStats);
443     mUserTag = userTag;
444     mVideoStabilizationMode = videoStabilizationMode;
445     mSessionIndex = sessionIdx;
446     mCameraExtensionSessionStats = extStats;
447 
448     return OK;
449 }
450 
writeToParcel(android::Parcel * parcel) const451 status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const {
452     if (parcel == NULL) {
453         ALOGE("%s: Null parcel", __FUNCTION__);
454         return BAD_VALUE;
455     }
456 
457     status_t err = OK;
458 
459     if ((err = parcel->writeString16(mCameraId)) != OK) {
460         ALOGE("%s: Failed to write camera id!", __FUNCTION__);
461         return err;
462     }
463 
464     if ((err = parcel->writeInt32(mFacing)) != OK) {
465         ALOGE("%s: Failed to write camera facing!", __FUNCTION__);
466         return err;
467     }
468 
469     if ((err = parcel->writeInt32(mNewCameraState)) != OK) {
470         ALOGE("%s: Failed to write new camera state!", __FUNCTION__);
471         return err;
472     }
473 
474     if ((err = parcel->writeString16(mClientName)) != OK) {
475         ALOGE("%s: Failed to write client name!", __FUNCTION__);
476         return err;
477     }
478 
479     if ((err = parcel->writeInt32(mApiLevel)) != OK) {
480         ALOGE("%s: Failed to write api level!", __FUNCTION__);
481         return err;
482     }
483 
484     if ((err = parcel->writeBool(mIsNdk)) != OK) {
485         ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__);
486         return err;
487     }
488 
489     if ((err = parcel->writeInt32(mLatencyMs)) != OK) {
490         ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__);
491         return err;
492     }
493 
494     if ((err = parcel->writeInt64(mLogId)) != OK) {
495         ALOGE("%s: Failed to write log ID!", __FUNCTION__);
496         return err;
497     }
498 
499     if ((err = parcel->writeFloat(mMaxPreviewFps)) != OK) {
500         ALOGE("%s: Failed to write maxPreviewFps!", __FUNCTION__);
501         return err;
502     }
503 
504     if ((err = parcel->writeInt32(mSessionType)) != OK) {
505         ALOGE("%s: Failed to write session type!", __FUNCTION__);
506         return err;
507     }
508 
509     if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) {
510         ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__);
511         return err;
512     }
513 
514     if ((err = parcel->writeInt64(mRequestCount)) != OK) {
515         ALOGE("%s: Failed to write request count!", __FUNCTION__);
516         return err;
517     }
518 
519     if ((err = parcel->writeInt64(mResultErrorCount)) != OK) {
520         ALOGE("%s: Failed to write result error count!", __FUNCTION__);
521         return err;
522     }
523 
524     if ((err = parcel->writeBool(mDeviceError)) != OK) {
525         ALOGE("%s: Failed to write device error flag!", __FUNCTION__);
526         return err;
527     }
528 
529     if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) {
530         ALOGE("%s: Failed to write stream states!", __FUNCTION__);
531         return err;
532     }
533 
534     if ((err = parcel->writeString16(mUserTag)) != OK) {
535         ALOGE("%s: Failed to write user tag!", __FUNCTION__);
536         return err;
537     }
538 
539     if ((err = parcel->writeInt32(mVideoStabilizationMode)) != OK) {
540         ALOGE("%s: Failed to write video stabilization mode!", __FUNCTION__);
541         return err;
542     }
543 
544     if ((err = parcel->writeInt32(mSessionIndex)) != OK) {
545         ALOGE("%s: Failed to write session index!", __FUNCTION__);
546         return err;
547     }
548 
549     if ((err = mCameraExtensionSessionStats.writeToParcel(parcel)) != OK) {
550         ALOGE("%s: Failed to write extension sessions stats!", __FUNCTION__);
551         return err;
552     }
553 
554     return OK;
555 }
556 
557 } // namespace hardware
558 } // namesmpace android
559