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 package android.hardware; 17 18 import android.hardware.camera2.CameraMetadata; 19 import android.hardware.camera2.params.ColorSpaceProfiles; 20 import android.hardware.camera2.params.DynamicRangeProfiles; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.util.Log; 24 25 /** 26 * The camera stream statistics used for passing camera stream information from 27 * camera service to camera service proxy. 28 * 29 * Include camera stream configuration, request/error counts, startup latency, 30 * and latency/jitter histograms. 31 * 32 * @hide 33 */ 34 public class CameraStreamStats implements Parcelable { 35 public static final int HISTOGRAM_TYPE_UNKNOWN = 0; 36 public static final int HISTOGRAM_TYPE_CAPTURE_LATENCY = 1; 37 38 private int mWidth; 39 private int mHeight; 40 private int mFormat; 41 private float mMaxPreviewFps; 42 private int mDataSpace; 43 private long mUsage; 44 private long mRequestCount; 45 private long mErrorCount; 46 private int mStartLatencyMs; 47 private int mMaxHalBuffers; 48 private int mMaxAppBuffers; 49 private int mHistogramType; 50 private float[] mHistogramBins; 51 private long[] mHistogramCounts; 52 private long mDynamicRangeProfile; 53 private long mStreamUseCase; 54 private int mColorSpace; 55 56 private static final String TAG = "CameraStreamStats"; 57 CameraStreamStats()58 public CameraStreamStats() { 59 mWidth = 0; 60 mHeight = 0; 61 mFormat = 0; 62 mMaxPreviewFps = 0; 63 mDataSpace = 0; 64 mUsage = 0; 65 mRequestCount = 0; 66 mErrorCount = 0; 67 mStartLatencyMs = 0; 68 mMaxHalBuffers = 0; 69 mMaxAppBuffers = 0; 70 mHistogramType = HISTOGRAM_TYPE_UNKNOWN; 71 mDynamicRangeProfile = DynamicRangeProfiles.STANDARD; 72 mStreamUseCase = CameraMetadata.SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT; 73 mColorSpace = ColorSpaceProfiles.UNSPECIFIED; 74 } 75 CameraStreamStats(int width, int height, int format, float maxPreviewFps, int dataSpace, long usage, long requestCount, long errorCount, int startLatencyMs, int maxHalBuffers, int maxAppBuffers, long dynamicRangeProfile, long streamUseCase, int colorSpace)76 public CameraStreamStats(int width, int height, int format, float maxPreviewFps, 77 int dataSpace, long usage, long requestCount, long errorCount, 78 int startLatencyMs, int maxHalBuffers, int maxAppBuffers, long dynamicRangeProfile, 79 long streamUseCase, int colorSpace) { 80 mWidth = width; 81 mHeight = height; 82 mFormat = format; 83 mMaxPreviewFps = maxPreviewFps; 84 mDataSpace = dataSpace; 85 mUsage = usage; 86 mRequestCount = requestCount; 87 mErrorCount = errorCount; 88 mStartLatencyMs = startLatencyMs; 89 mMaxHalBuffers = maxHalBuffers; 90 mMaxAppBuffers = maxAppBuffers; 91 mHistogramType = HISTOGRAM_TYPE_UNKNOWN; 92 mDynamicRangeProfile = dynamicRangeProfile; 93 mStreamUseCase = streamUseCase; 94 mColorSpace = colorSpace; 95 } 96 97 public static final @android.annotation.NonNull Parcelable.Creator<CameraStreamStats> CREATOR = 98 new Parcelable.Creator<CameraStreamStats>() { 99 @Override 100 public CameraStreamStats createFromParcel(Parcel in) { 101 try { 102 CameraStreamStats streamStats = new CameraStreamStats(in); 103 return streamStats; 104 } catch (Exception e) { 105 Log.e(TAG, "Exception creating CameraStreamStats from parcel", e); 106 return null; 107 } 108 } 109 110 @Override 111 public CameraStreamStats[] newArray(int size) { 112 return new CameraStreamStats[size]; 113 } 114 }; 115 CameraStreamStats(Parcel in)116 private CameraStreamStats(Parcel in) { 117 readFromParcel(in); 118 } 119 120 @Override describeContents()121 public int describeContents() { 122 return 0; 123 } 124 125 @Override writeToParcel(Parcel dest, int flags)126 public void writeToParcel(Parcel dest, int flags) { 127 dest.writeInt(mWidth); 128 dest.writeInt(mHeight); 129 dest.writeInt(mFormat); 130 dest.writeFloat(mMaxPreviewFps); 131 dest.writeInt(mDataSpace); 132 dest.writeLong(mUsage); 133 dest.writeLong(mRequestCount); 134 dest.writeLong(mErrorCount); 135 dest.writeInt(mStartLatencyMs); 136 dest.writeInt(mMaxHalBuffers); 137 dest.writeInt(mMaxAppBuffers); 138 dest.writeInt(mHistogramType); 139 dest.writeFloatArray(mHistogramBins); 140 dest.writeLongArray(mHistogramCounts); 141 dest.writeLong(mDynamicRangeProfile); 142 dest.writeLong(mStreamUseCase); 143 dest.writeInt(mColorSpace); 144 } 145 readFromParcel(Parcel in)146 public void readFromParcel(Parcel in) { 147 mWidth = in.readInt(); 148 mHeight = in.readInt(); 149 mFormat = in.readInt(); 150 mMaxPreviewFps = in.readFloat(); 151 mDataSpace = in.readInt(); 152 mUsage = in.readLong(); 153 mRequestCount = in.readLong(); 154 mErrorCount = in.readLong(); 155 mStartLatencyMs = in.readInt(); 156 mMaxHalBuffers = in.readInt(); 157 mMaxAppBuffers = in.readInt(); 158 mHistogramType = in.readInt(); 159 mHistogramBins = in.createFloatArray(); 160 mHistogramCounts = in.createLongArray(); 161 mDynamicRangeProfile = in.readLong(); 162 mStreamUseCase = in.readLong(); 163 mColorSpace = in.readInt(); 164 } 165 getWidth()166 public int getWidth() { 167 return mWidth; 168 } 169 getHeight()170 public int getHeight() { 171 return mHeight; 172 } 173 getFormat()174 public int getFormat() { 175 return mFormat; 176 } 177 getMaxPreviewFps()178 public float getMaxPreviewFps() { 179 return mMaxPreviewFps; 180 } 181 getDataSpace()182 public int getDataSpace() { 183 return mDataSpace; 184 } 185 getUsage()186 public long getUsage() { 187 return mUsage; 188 } 189 getRequestCount()190 public long getRequestCount() { 191 return mRequestCount; 192 } 193 getErrorCount()194 public long getErrorCount() { 195 return mErrorCount; 196 } 197 getStartLatencyMs()198 public int getStartLatencyMs() { 199 return mStartLatencyMs; 200 } 201 getMaxHalBuffers()202 public int getMaxHalBuffers() { 203 return mMaxHalBuffers; 204 } 205 getMaxAppBuffers()206 public int getMaxAppBuffers() { 207 return mMaxAppBuffers; 208 } 209 getHistogramType()210 public int getHistogramType() { 211 return mHistogramType; 212 } 213 getHistogramBins()214 public float[] getHistogramBins() { 215 return mHistogramBins; 216 } 217 getHistogramCounts()218 public long[] getHistogramCounts() { 219 return mHistogramCounts; 220 } 221 getDynamicRangeProfile()222 public long getDynamicRangeProfile() { 223 return mDynamicRangeProfile; 224 } 225 getColorSpace()226 public int getColorSpace() { 227 return mColorSpace; 228 } 229 getStreamUseCase()230 public long getStreamUseCase() { 231 return mStreamUseCase; 232 } 233 } 234