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