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 #ifndef ANDROID_HARDWARE_CAMERA_SERVICE_SESSION_STATS_H
18 #define ANDROID_HARDWARE_CAMERA_SERVICE_SESSION_STATS_H
19 
20 #include <binder/Parcelable.h>
21 
22 namespace android {
23 namespace hardware {
24 
25 /**
26  * Camera stream info and statistics
27  */
28 class CameraStreamStats : public android::Parcelable {
29 public:
30     enum HistogramType {
31         HISTOGRAM_TYPE_UNKNOWN = 0,
32         HISTOGRAM_TYPE_CAPTURE_LATENCY = 1,
33     };
34 
35     int mWidth;
36     int mHeight;
37     int mFormat;
38     int mDataSpace;
39     int64_t mUsage;
40 
41     // The number of requested buffers
42     int64_t mRequestCount;
43     // The number of buffer errors
44     int64_t mErrorCount;
45 
46     // The capture latency of 1st request for this stream
47     int32_t mStartLatencyMs;
48 
49     // Buffer count info
50     int mMaxHalBuffers;
51     int mMaxAppBuffers;
52 
53     // Histogram type. So far only capture latency histogram is supported.
54     int mHistogramType;
55     // The bounary values separating adjacent histogram bins.
56     // A vector of {h1, h2, h3} represents bins of [0, h1), [h1, h2), [h2, h3),
57     // and [h3, infinity)
58     std::vector<float> mHistogramBins;
59     // The counts for all histogram bins.
60     // size(mHistogramBins) + 1 = size(mHistogramCounts)
61     std::vector<int64_t> mHistogramCounts;
62 
CameraStreamStats()63     CameraStreamStats() :
64             mWidth(0), mHeight(0), mFormat(0), mDataSpace(0), mUsage(0),
65             mRequestCount(0), mErrorCount(0), mStartLatencyMs(0),
66             mMaxHalBuffers(0), mMaxAppBuffers(0), mHistogramType(HISTOGRAM_TYPE_UNKNOWN) {}
CameraStreamStats(int width,int height,int format,int dataSpace,int64_t usage,int maxHalBuffers,int maxAppBuffers)67     CameraStreamStats(int width, int height, int format, int dataSpace, int64_t usage,
68             int maxHalBuffers, int maxAppBuffers)
69             : mWidth(width), mHeight(height), mFormat(format), mDataSpace(dataSpace),
70               mUsage(usage), mRequestCount(0), mErrorCount(0), mStartLatencyMs(0),
71               mMaxHalBuffers(maxHalBuffers), mMaxAppBuffers(maxAppBuffers),
72               mHistogramType(HISTOGRAM_TYPE_UNKNOWN) {}
73 
74     virtual status_t readFromParcel(const android::Parcel* parcel) override;
75     virtual status_t writeToParcel(android::Parcel* parcel) const override;
76 };
77 
78 /**
79  * Camera session statistics
80  *
81  * This includes session wide info and stream statistics.
82  */
83 class CameraSessionStats : public android::Parcelable {
84 public:
85     /**
86      * Values for notifyCameraState newCameraState
87      */
88     static const int CAMERA_STATE_OPEN;
89     static const int CAMERA_STATE_ACTIVE;
90     static const int CAMERA_STATE_IDLE;
91     static const int CAMERA_STATE_CLOSED;
92 
93     /**
94      * Values for notifyCameraState facing
95      */
96     static const int CAMERA_FACING_BACK;
97     static const int CAMERA_FACING_FRONT;
98     static const int CAMERA_FACING_EXTERNAL;
99 
100     /**
101      * Values for notifyCameraState api level
102      */
103     static const int CAMERA_API_LEVEL_1;
104     static const int CAMERA_API_LEVEL_2;
105 
106     String16 mCameraId;
107     int mFacing;
108     int mNewCameraState;
109     String16 mClientName;
110     int mApiLevel;
111     bool mIsNdk;
112     // latency in ms for camera open, close, or session creation.
113     int mLatencyMs;
114 
115     // Session info and statistics
116     int mSessionType;
117     int mInternalReconfigure;
118     // The number of capture requests
119     int64_t mRequestCount;
120     // The number of result error
121     int64_t mResultErrorCount;
122     // Whether the device runs into an error state
123     bool mDeviceError;
124     std::vector<CameraStreamStats> mStreamStats;
125 
126     // Constructors
127     CameraSessionStats();
128     CameraSessionStats(const String16& cameraId, int facing, int newCameraState,
129             const String16& clientName, int apiLevel, bool isNdk, int32_t latencyMs);
130 
131     virtual status_t readFromParcel(const android::Parcel* parcel) override;
132     virtual status_t writeToParcel(android::Parcel* parcel) const override;
133 };
134 
135 }; // namespace hardware
136 }; // namespace android
137 
138 #endif // ANDROID_HARDWARE_CAMERA_SERVICE_SESSION_STATS_H
139