| Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 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 | // #define LOG_NDEBUG 0 | 
|  | 18 | #define LOG_TAG "CameraSessionStats" | 
|  | 19 | #include <utils/Log.h> | 
|  | 20 | #include <utils/String16.h> | 
|  | 21 |  | 
|  | 22 | #include <camera/CameraSessionStats.h> | 
|  | 23 |  | 
|  | 24 | #include <binder/Parcel.h> | 
|  | 25 |  | 
|  | 26 | namespace android { | 
|  | 27 | namespace hardware { | 
|  | 28 |  | 
|  | 29 | status_t CameraStreamStats::readFromParcel(const android::Parcel* parcel) { | 
|  | 30 | if (parcel == NULL) { | 
|  | 31 | ALOGE("%s: Null parcel", __FUNCTION__); | 
|  | 32 | return BAD_VALUE; | 
|  | 33 | } | 
|  | 34 |  | 
|  | 35 | status_t err = OK; | 
|  | 36 |  | 
|  | 37 | int width = 0; | 
|  | 38 | if ((err = parcel->readInt32(&width)) != OK) { | 
|  | 39 | ALOGE("%s: Failed to read width from parcel", __FUNCTION__); | 
|  | 40 | return err; | 
|  | 41 | } | 
|  | 42 |  | 
|  | 43 | int height = 0; | 
|  | 44 | if ((err = parcel->readInt32(&height)) != OK) { | 
|  | 45 | ALOGE("%s: Failed to read height from parcel", __FUNCTION__); | 
|  | 46 | return err; | 
|  | 47 | } | 
|  | 48 |  | 
|  | 49 | int format = 0; | 
|  | 50 | if ((err = parcel->readInt32(&format)) != OK) { | 
|  | 51 | ALOGE("%s: Failed to read format from parcel", __FUNCTION__); | 
|  | 52 | return err; | 
|  | 53 | } | 
|  | 54 |  | 
|  | 55 | int dataSpace = 0; | 
|  | 56 | if ((err = parcel->readInt32(&dataSpace)) != OK) { | 
|  | 57 | ALOGE("%s: Failed to read dataSpace from parcel", __FUNCTION__); | 
|  | 58 | return err; | 
|  | 59 | } | 
|  | 60 |  | 
|  | 61 | int64_t usage = 0; | 
|  | 62 | if ((err = parcel->readInt64(&usage)) != OK) { | 
|  | 63 | ALOGE("%s: Failed to read usage from parcel", __FUNCTION__); | 
|  | 64 | return err; | 
|  | 65 | } | 
|  | 66 |  | 
|  | 67 | int64_t requestCount = 0; | 
|  | 68 | if ((err = parcel->readInt64(&requestCount)) != OK) { | 
|  | 69 | ALOGE("%s: Failed to read request count from parcel", __FUNCTION__); | 
|  | 70 | return err; | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 | int64_t errorCount = 0; | 
|  | 74 | if ((err = parcel->readInt64(&errorCount)) != OK) { | 
|  | 75 | ALOGE("%s: Failed to read error count from parcel", __FUNCTION__); | 
|  | 76 | return err; | 
|  | 77 | } | 
|  | 78 |  | 
|  | 79 | int startLatencyMs = 0; | 
|  | 80 | if ((err = parcel->readInt32(&startLatencyMs)) != OK) { | 
|  | 81 | ALOGE("%s: Failed to read start latency from parcel", __FUNCTION__); | 
|  | 82 | return err; | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | int maxHalBuffers = 0; | 
|  | 86 | if ((err = parcel->readInt32(&maxHalBuffers)) != OK) { | 
|  | 87 | ALOGE("%s: Failed to read max Hal buffers from parcel", __FUNCTION__); | 
|  | 88 | return err; | 
|  | 89 | } | 
|  | 90 |  | 
|  | 91 | int maxAppBuffers = 0; | 
|  | 92 | if ((err = parcel->readInt32(&maxAppBuffers)) != OK) { | 
|  | 93 | ALOGE("%s: Failed to read max app buffers from parcel", __FUNCTION__); | 
|  | 94 | return err; | 
|  | 95 | } | 
|  | 96 |  | 
| Shuzhen Wang | db8f278 | 2020-10-30 08:43:37 -0700 | [diff] [blame] | 97 | int histogramType = HISTOGRAM_TYPE_UNKNOWN; | 
|  | 98 | if ((err = parcel->readInt32(&histogramType)) != OK) { | 
|  | 99 | ALOGE("%s: Failed to read histogram type from parcel", __FUNCTION__); | 
|  | 100 | return err; | 
|  | 101 | } | 
|  | 102 |  | 
|  | 103 | std::vector<float> histogramBins; | 
|  | 104 | if ((err = parcel->readFloatVector(&histogramBins)) != OK) { | 
|  | 105 | ALOGE("%s: Failed to read histogram bins from parcel", __FUNCTION__); | 
|  | 106 | return err; | 
|  | 107 | } | 
|  | 108 |  | 
|  | 109 | std::vector<int64_t> histogramCounts; | 
|  | 110 | if ((err = parcel->readInt64Vector(&histogramCounts)) != OK) { | 
|  | 111 | ALOGE("%s: Failed to read histogram counts from parcel", __FUNCTION__); | 
|  | 112 | return err; | 
|  | 113 | } | 
|  | 114 |  | 
| Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 115 | mWidth = width; | 
|  | 116 | mHeight = height; | 
|  | 117 | mFormat = format; | 
|  | 118 | mDataSpace = dataSpace; | 
|  | 119 | mUsage = usage; | 
|  | 120 | mRequestCount = requestCount; | 
|  | 121 | mErrorCount = errorCount; | 
|  | 122 | mStartLatencyMs = startLatencyMs; | 
|  | 123 | mMaxHalBuffers = maxHalBuffers; | 
|  | 124 | mMaxAppBuffers = maxAppBuffers; | 
| Shuzhen Wang | db8f278 | 2020-10-30 08:43:37 -0700 | [diff] [blame] | 125 | mHistogramType = histogramType; | 
|  | 126 | mHistogramBins = std::move(histogramBins); | 
|  | 127 | mHistogramCounts = std::move(histogramCounts); | 
| Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 128 |  | 
|  | 129 | return OK; | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | status_t CameraStreamStats::writeToParcel(android::Parcel* parcel) const { | 
|  | 133 | if (parcel == NULL) { | 
|  | 134 | ALOGE("%s: Null parcel", __FUNCTION__); | 
|  | 135 | return BAD_VALUE; | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | status_t err = OK; | 
|  | 139 |  | 
|  | 140 | if ((err = parcel->writeInt32(mWidth)) != OK) { | 
|  | 141 | ALOGE("%s: Failed to write stream width!", __FUNCTION__); | 
|  | 142 | return err; | 
|  | 143 | } | 
|  | 144 |  | 
|  | 145 | if ((err = parcel->writeInt32(mHeight)) != OK) { | 
|  | 146 | ALOGE("%s: Failed to write stream height!", __FUNCTION__); | 
|  | 147 | return err; | 
|  | 148 | } | 
|  | 149 |  | 
|  | 150 | if ((err = parcel->writeInt32(mFormat)) != OK) { | 
|  | 151 | ALOGE("%s: Failed to write stream format!", __FUNCTION__); | 
|  | 152 | return err; | 
|  | 153 | } | 
|  | 154 |  | 
|  | 155 | if ((err = parcel->writeInt32(mDataSpace)) != OK) { | 
|  | 156 | ALOGE("%s: Failed to write stream dataSpace!", __FUNCTION__); | 
|  | 157 | return err; | 
|  | 158 | } | 
|  | 159 |  | 
|  | 160 | if ((err = parcel->writeInt64(mUsage)) != OK) { | 
|  | 161 | ALOGE("%s: Failed to write stream usage!", __FUNCTION__); | 
|  | 162 | return err; | 
|  | 163 | } | 
|  | 164 |  | 
|  | 165 | if ((err = parcel->writeInt64(mRequestCount)) != OK) { | 
|  | 166 | ALOGE("%s: Failed to write stream request count!", __FUNCTION__); | 
|  | 167 | return err; | 
|  | 168 | } | 
|  | 169 |  | 
|  | 170 | if ((err = parcel->writeInt64(mErrorCount)) != OK) { | 
|  | 171 | ALOGE("%s: Failed to write stream error count!", __FUNCTION__); | 
|  | 172 | return err; | 
|  | 173 | } | 
|  | 174 |  | 
|  | 175 | if ((err = parcel->writeInt32(mStartLatencyMs)) != OK) { | 
|  | 176 | ALOGE("%s: Failed to write stream start latency!", __FUNCTION__); | 
|  | 177 | return err; | 
|  | 178 | } | 
|  | 179 |  | 
|  | 180 | if ((err = parcel->writeInt32(mMaxHalBuffers)) != OK) { | 
|  | 181 | ALOGE("%s: Failed to write max hal buffers", __FUNCTION__); | 
|  | 182 | return err; | 
|  | 183 | } | 
|  | 184 |  | 
|  | 185 | if ((err = parcel->writeInt32(mMaxAppBuffers)) != OK) { | 
|  | 186 | ALOGE("%s: Failed to write max app buffers", __FUNCTION__); | 
|  | 187 | return err; | 
|  | 188 | } | 
|  | 189 |  | 
| Shuzhen Wang | db8f278 | 2020-10-30 08:43:37 -0700 | [diff] [blame] | 190 | if ((err = parcel->writeInt32(mHistogramType)) != OK) { | 
|  | 191 | ALOGE("%s: Failed to write histogram type", __FUNCTION__); | 
|  | 192 | return err; | 
|  | 193 | } | 
|  | 194 |  | 
|  | 195 | if ((err = parcel->writeFloatVector(mHistogramBins)) != OK) { | 
|  | 196 | ALOGE("%s: Failed to write histogram bins!", __FUNCTION__); | 
|  | 197 | return err; | 
|  | 198 | } | 
|  | 199 |  | 
|  | 200 | if ((err = parcel->writeInt64Vector(mHistogramCounts)) != OK) { | 
|  | 201 | ALOGE("%s: Failed to write histogram counts!", __FUNCTION__); | 
|  | 202 | return err; | 
|  | 203 | } | 
|  | 204 |  | 
| Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 205 | return OK; | 
|  | 206 | } | 
|  | 207 |  | 
| Shuzhen Wang | bac18d9 | 2020-11-19 14:50:30 -0800 | [diff] [blame] | 208 | const int CameraSessionStats::CAMERA_STATE_OPEN = 0; | 
|  | 209 | const int CameraSessionStats::CAMERA_STATE_ACTIVE = 1; | 
|  | 210 | const int CameraSessionStats::CAMERA_STATE_IDLE = 2; | 
|  | 211 | const int CameraSessionStats::CAMERA_STATE_CLOSED = 3; | 
|  | 212 |  | 
|  | 213 | const int CameraSessionStats::CAMERA_FACING_BACK = 0; | 
|  | 214 | const int CameraSessionStats::CAMERA_FACING_FRONT = 1; | 
|  | 215 | const int CameraSessionStats::CAMERA_FACING_EXTERNAL = 2; | 
|  | 216 |  | 
|  | 217 | const int CameraSessionStats::CAMERA_API_LEVEL_1 = 1; | 
|  | 218 | const int CameraSessionStats::CAMERA_API_LEVEL_2 = 2; | 
|  | 219 |  | 
| Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 220 | CameraSessionStats::CameraSessionStats() : | 
|  | 221 | mFacing(CAMERA_FACING_BACK), | 
|  | 222 | mNewCameraState(CAMERA_STATE_CLOSED), | 
|  | 223 | mApiLevel(0), | 
|  | 224 | mIsNdk(false), | 
|  | 225 | mLatencyMs(-1), | 
|  | 226 | mSessionType(0), | 
|  | 227 | mInternalReconfigure(0), | 
|  | 228 | mRequestCount(0), | 
|  | 229 | mResultErrorCount(0), | 
|  | 230 | mDeviceError(false) {} | 
|  | 231 |  | 
|  | 232 | CameraSessionStats::CameraSessionStats(const String16& cameraId, | 
|  | 233 | int facing, int newCameraState, const String16& clientName, | 
|  | 234 | int apiLevel, bool isNdk, int32_t latencyMs) : | 
|  | 235 | mCameraId(cameraId), | 
|  | 236 | mFacing(facing), | 
|  | 237 | mNewCameraState(newCameraState), | 
|  | 238 | mClientName(clientName), | 
|  | 239 | mApiLevel(apiLevel), | 
|  | 240 | mIsNdk(isNdk), | 
|  | 241 | mLatencyMs(latencyMs), | 
|  | 242 | mSessionType(0), | 
|  | 243 | mInternalReconfigure(0), | 
|  | 244 | mRequestCount(0), | 
|  | 245 | mResultErrorCount(0), | 
|  | 246 | mDeviceError(0) {} | 
|  | 247 |  | 
|  | 248 | status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) { | 
|  | 249 | if (parcel == NULL) { | 
|  | 250 | ALOGE("%s: Null parcel", __FUNCTION__); | 
|  | 251 | return BAD_VALUE; | 
|  | 252 | } | 
|  | 253 |  | 
|  | 254 | status_t err = OK; | 
|  | 255 |  | 
|  | 256 | String16 id; | 
|  | 257 | if ((err = parcel->readString16(&id)) != OK) { | 
|  | 258 | ALOGE("%s: Failed to read camera id!", __FUNCTION__); | 
|  | 259 | return BAD_VALUE; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 | int facing = 0; | 
|  | 263 | if ((err = parcel->readInt32(&facing)) != OK) { | 
|  | 264 | ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__); | 
|  | 265 | return err; | 
|  | 266 | } | 
|  | 267 |  | 
|  | 268 | int32_t newCameraState; | 
|  | 269 | if ((err = parcel->readInt32(&newCameraState)) != OK) { | 
|  | 270 | ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__); | 
|  | 271 | return err; | 
|  | 272 | } | 
|  | 273 |  | 
|  | 274 | String16 clientName; | 
|  | 275 | if ((err = parcel->readString16(&clientName)) != OK) { | 
|  | 276 | ALOGE("%s: Failed to read client name!", __FUNCTION__); | 
|  | 277 | return BAD_VALUE; | 
|  | 278 | } | 
|  | 279 |  | 
|  | 280 | int32_t apiLevel; | 
|  | 281 | if ((err = parcel->readInt32(&apiLevel)) != OK) { | 
|  | 282 | ALOGE("%s: Failed to read api level from parcel", __FUNCTION__); | 
|  | 283 | return err; | 
|  | 284 | } | 
|  | 285 |  | 
|  | 286 | bool isNdk; | 
|  | 287 | if ((err = parcel->readBool(&isNdk)) != OK) { | 
|  | 288 | ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__); | 
|  | 289 | return err; | 
|  | 290 | } | 
|  | 291 |  | 
|  | 292 | int32_t latencyMs; | 
|  | 293 | if ((err = parcel->readInt32(&latencyMs)) != OK) { | 
|  | 294 | ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__); | 
|  | 295 | return err; | 
|  | 296 | } | 
|  | 297 |  | 
|  | 298 | int32_t sessionType; | 
|  | 299 | if ((err = parcel->readInt32(&sessionType)) != OK) { | 
|  | 300 | ALOGE("%s: Failed to read session type from parcel", __FUNCTION__); | 
|  | 301 | return err; | 
|  | 302 | } | 
|  | 303 |  | 
|  | 304 | int32_t internalReconfigure; | 
|  | 305 | if ((err = parcel->readInt32(&internalReconfigure)) != OK) { | 
|  | 306 | ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__); | 
|  | 307 | return err; | 
|  | 308 | } | 
|  | 309 |  | 
|  | 310 | int64_t requestCount; | 
|  | 311 | if ((err = parcel->readInt64(&requestCount)) != OK) { | 
|  | 312 | ALOGE("%s: Failed to read request count from parcel", __FUNCTION__); | 
|  | 313 | return err; | 
|  | 314 | } | 
|  | 315 |  | 
|  | 316 | int64_t resultErrorCount; | 
|  | 317 | if ((err = parcel->readInt64(&resultErrorCount)) != OK) { | 
|  | 318 | ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__); | 
|  | 319 | return err; | 
|  | 320 | } | 
|  | 321 |  | 
|  | 322 | bool deviceError; | 
|  | 323 | if ((err = parcel->readBool(&deviceError)) != OK) { | 
|  | 324 | ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__); | 
|  | 325 | return err; | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | std::vector<CameraStreamStats> streamStats; | 
|  | 329 | if ((err = parcel->readParcelableVector(&streamStats)) != OK) { | 
|  | 330 | ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__); | 
|  | 331 | return err; | 
|  | 332 | } | 
|  | 333 |  | 
|  | 334 | mCameraId = id; | 
|  | 335 | mFacing = facing; | 
|  | 336 | mNewCameraState = newCameraState; | 
|  | 337 | mClientName = clientName; | 
|  | 338 | mApiLevel = apiLevel; | 
|  | 339 | mIsNdk = isNdk; | 
|  | 340 | mLatencyMs = latencyMs; | 
|  | 341 | mSessionType = sessionType; | 
|  | 342 | mInternalReconfigure = internalReconfigure; | 
|  | 343 | mRequestCount = requestCount; | 
|  | 344 | mResultErrorCount = resultErrorCount; | 
|  | 345 | mDeviceError = deviceError; | 
|  | 346 | mStreamStats = std::move(streamStats); | 
|  | 347 |  | 
|  | 348 | return OK; | 
|  | 349 | } | 
|  | 350 |  | 
|  | 351 | status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const { | 
|  | 352 | if (parcel == NULL) { | 
|  | 353 | ALOGE("%s: Null parcel", __FUNCTION__); | 
|  | 354 | return BAD_VALUE; | 
|  | 355 | } | 
|  | 356 |  | 
|  | 357 | status_t err = OK; | 
|  | 358 |  | 
|  | 359 | if ((err = parcel->writeString16(mCameraId)) != OK) { | 
|  | 360 | ALOGE("%s: Failed to write camera id!", __FUNCTION__); | 
|  | 361 | return err; | 
|  | 362 | } | 
|  | 363 |  | 
|  | 364 | if ((err = parcel->writeInt32(mFacing)) != OK) { | 
|  | 365 | ALOGE("%s: Failed to write camera facing!", __FUNCTION__); | 
|  | 366 | return err; | 
|  | 367 | } | 
|  | 368 |  | 
|  | 369 | if ((err = parcel->writeInt32(mNewCameraState)) != OK) { | 
|  | 370 | ALOGE("%s: Failed to write new camera state!", __FUNCTION__); | 
|  | 371 | return err; | 
|  | 372 | } | 
|  | 373 |  | 
|  | 374 | if ((err = parcel->writeString16(mClientName)) != OK) { | 
|  | 375 | ALOGE("%s: Failed to write client name!", __FUNCTION__); | 
|  | 376 | return err; | 
|  | 377 | } | 
|  | 378 |  | 
|  | 379 | if ((err = parcel->writeInt32(mApiLevel)) != OK) { | 
|  | 380 | ALOGE("%s: Failed to write api level!", __FUNCTION__); | 
|  | 381 | return err; | 
|  | 382 | } | 
|  | 383 |  | 
|  | 384 | if ((err = parcel->writeBool(mIsNdk)) != OK) { | 
|  | 385 | ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__); | 
|  | 386 | return err; | 
|  | 387 | } | 
|  | 388 |  | 
|  | 389 | if ((err = parcel->writeInt32(mLatencyMs)) != OK) { | 
|  | 390 | ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__); | 
|  | 391 | return err; | 
|  | 392 | } | 
|  | 393 |  | 
|  | 394 | if ((err = parcel->writeInt32(mSessionType)) != OK) { | 
|  | 395 | ALOGE("%s: Failed to write session type!", __FUNCTION__); | 
|  | 396 | return err; | 
|  | 397 | } | 
|  | 398 |  | 
|  | 399 | if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) { | 
|  | 400 | ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__); | 
|  | 401 | return err; | 
|  | 402 | } | 
|  | 403 |  | 
|  | 404 | if ((err = parcel->writeInt64(mRequestCount)) != OK) { | 
|  | 405 | ALOGE("%s: Failed to write request count!", __FUNCTION__); | 
|  | 406 | return err; | 
|  | 407 | } | 
|  | 408 |  | 
|  | 409 | if ((err = parcel->writeInt64(mResultErrorCount)) != OK) { | 
|  | 410 | ALOGE("%s: Failed to write result error count!", __FUNCTION__); | 
|  | 411 | return err; | 
|  | 412 | } | 
|  | 413 |  | 
|  | 414 | if ((err = parcel->writeBool(mDeviceError)) != OK) { | 
|  | 415 | ALOGE("%s: Failed to write device error flag!", __FUNCTION__); | 
|  | 416 | return err; | 
|  | 417 | } | 
|  | 418 |  | 
|  | 419 | if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) { | 
|  | 420 | ALOGE("%s: Failed to write stream states!", __FUNCTION__); | 
|  | 421 | return err; | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | return OK; | 
|  | 425 | } | 
|  | 426 |  | 
|  | 427 | } // namespace hardware | 
|  | 428 | } // namesmpace android |