• 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 #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 #include <camera/CameraMetadata.h>
23 #include <android/hardware/CameraExtensionSessionStats.h>
24 
25 namespace android {
26 namespace hardware {
27 
28 /**
29  * Camera stream info and statistics
30  */
31 class CameraStreamStats : public android::Parcelable {
32 public:
33     enum HistogramType {
34         HISTOGRAM_TYPE_UNKNOWN = 0,
35         HISTOGRAM_TYPE_CAPTURE_LATENCY = 1,
36     };
37 
38     int mWidth;
39     int mHeight;
40     int mFormat;
41     float mMaxPreviewFps;
42     int mDataSpace;
43     int64_t mUsage;
44 
45     // The number of requested buffers
46     int64_t mRequestCount;
47     // The number of buffer errors
48     int64_t mErrorCount;
49 
50     // The capture latency of 1st request for this stream
51     int32_t mStartLatencyMs;
52 
53     // Buffer count info
54     int mMaxHalBuffers;
55     int mMaxAppBuffers;
56 
57     // Histogram type. So far only capture latency histogram is supported.
58     int mHistogramType;
59     // The bounary values separating adjacent histogram bins.
60     // A vector of {h1, h2, h3} represents bins of [0, h1), [h1, h2), [h2, h3),
61     // and [h3, infinity)
62     std::vector<float> mHistogramBins;
63     // The counts for all histogram bins.
64     // size(mHistogramBins) + 1 = size(mHistogramCounts)
65     std::vector<int64_t> mHistogramCounts;
66 
67     // Dynamic range profile
68     int64_t mDynamicRangeProfile;
69     // Stream use case
70     int64_t mStreamUseCase;
71     // Color space
72     int32_t mColorSpace;
73 
CameraStreamStats()74     CameraStreamStats() :
75             mWidth(0), mHeight(0), mFormat(0), mMaxPreviewFps(0), mDataSpace(0), mUsage(0),
76             mRequestCount(0), mErrorCount(0), mStartLatencyMs(0),
77             mMaxHalBuffers(0), mMaxAppBuffers(0), mHistogramType(HISTOGRAM_TYPE_UNKNOWN),
78             mDynamicRangeProfile(ANDROID_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD),
79             mStreamUseCase(ANDROID_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT),
80             mColorSpace(ANDROID_REQUEST_AVAILABLE_COLOR_SPACE_PROFILES_MAP_UNSPECIFIED) {}
CameraStreamStats(int width,int height,int format,float maxPreviewFps,int dataSpace,int64_t usage,int maxHalBuffers,int maxAppBuffers,int dynamicRangeProfile,int streamUseCase,int32_t colorSpace)81     CameraStreamStats(int width, int height, int format, float maxPreviewFps, int dataSpace,
82             int64_t usage, int maxHalBuffers, int maxAppBuffers, int dynamicRangeProfile,
83             int streamUseCase, int32_t colorSpace)
84             : mWidth(width), mHeight(height), mFormat(format), mMaxPreviewFps(maxPreviewFps),
85               mDataSpace(dataSpace), mUsage(usage), mRequestCount(0), mErrorCount(0),
86               mStartLatencyMs(0), mMaxHalBuffers(maxHalBuffers), mMaxAppBuffers(maxAppBuffers),
87               mHistogramType(HISTOGRAM_TYPE_UNKNOWN),
88               mDynamicRangeProfile(dynamicRangeProfile),
89               mStreamUseCase(streamUseCase),
90               mColorSpace(colorSpace) {}
91 
92     virtual status_t readFromParcel(const android::Parcel* parcel) override;
93     virtual status_t writeToParcel(android::Parcel* parcel) const override;
94 };
95 
96 /**
97  * Camera session statistics
98  *
99  * This includes session wide info and stream statistics.
100  */
101 class CameraSessionStats : public android::Parcelable {
102 public:
103     /**
104      * Values for notifyCameraState newCameraState
105      */
106     static const int CAMERA_STATE_OPEN;
107     static const int CAMERA_STATE_ACTIVE;
108     static const int CAMERA_STATE_IDLE;
109     static const int CAMERA_STATE_CLOSED;
110 
111     /**
112      * Values for notifyCameraState facing
113      */
114     static const int CAMERA_FACING_BACK;
115     static const int CAMERA_FACING_FRONT;
116     static const int CAMERA_FACING_EXTERNAL;
117 
118     /**
119      * Values for notifyCameraState api level
120      */
121     static const int CAMERA_API_LEVEL_1;
122     static const int CAMERA_API_LEVEL_2;
123 
124     String16 mCameraId;
125     int mFacing;
126     int mNewCameraState;
127     String16 mClientName;
128     int mApiLevel;
129     bool mIsNdk;
130     // latency in ms for camera open, close, or session creation.
131     int mLatencyMs;
132 
133     /*
134      * A randomly generated identifier to map the open/active/idle/close stats to each other after
135      * being logged. Every 'open' event will have a newly generated id which will be logged with
136      * active/idle/closed that correspond to the particular 'open' event.
137      *
138      * This ID is not meant to be globally unique forever. Probabilistically, this ID can be
139      * safely considered unique across all logs from one android build for 48 to 72 hours from
140      * its generation. Chances of identifier collisions are significant past a week or two.
141      *
142      * NOTE: There are no guarantees that the identifiers will be unique. The probability of
143      * collision within a short timeframe is low, but any system consuming these identifiers at
144      * scale should handle identifier collisions, potentially even from the same device.
145      */
146     int64_t mLogId;
147 
148     float mMaxPreviewFps;
149 
150     // Session info and statistics
151     int mSessionType;
152     int mInternalReconfigure;
153     // The number of capture requests
154     int64_t mRequestCount;
155     // The number of result error
156     int64_t mResultErrorCount;
157     // Whether the device runs into an error state
158     bool mDeviceError;
159     std::vector<CameraStreamStats> mStreamStats;
160     String16 mUserTag;
161     int mVideoStabilizationMode;
162     int mSessionIndex;
163 
164     CameraExtensionSessionStats mCameraExtensionSessionStats;
165 
166     // Constructors
167     CameraSessionStats();
168     CameraSessionStats(const String16& cameraId, int facing, int newCameraState,
169                        const String16& clientName, int apiLevel, bool isNdk, int32_t latencyMs,
170                        int64_t logId);
171 
172     virtual status_t readFromParcel(const android::Parcel* parcel) override;
173     virtual status_t writeToParcel(android::Parcel* parcel) const override;
174 };
175 
176 }; // namespace hardware
177 }; // namespace android
178 
179 #endif // ANDROID_HARDWARE_CAMERA_SERVICE_SESSION_STATS_H
180