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