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 | |
| 97 | mWidth = width; |
| 98 | mHeight = height; |
| 99 | mFormat = format; |
| 100 | mDataSpace = dataSpace; |
| 101 | mUsage = usage; |
| 102 | mRequestCount = requestCount; |
| 103 | mErrorCount = errorCount; |
| 104 | mStartLatencyMs = startLatencyMs; |
| 105 | mMaxHalBuffers = maxHalBuffers; |
| 106 | mMaxAppBuffers = maxAppBuffers; |
| 107 | |
| 108 | return OK; |
| 109 | } |
| 110 | |
| 111 | status_t CameraStreamStats::writeToParcel(android::Parcel* parcel) const { |
| 112 | if (parcel == NULL) { |
| 113 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 114 | return BAD_VALUE; |
| 115 | } |
| 116 | |
| 117 | status_t err = OK; |
| 118 | |
| 119 | if ((err = parcel->writeInt32(mWidth)) != OK) { |
| 120 | ALOGE("%s: Failed to write stream width!", __FUNCTION__); |
| 121 | return err; |
| 122 | } |
| 123 | |
| 124 | if ((err = parcel->writeInt32(mHeight)) != OK) { |
| 125 | ALOGE("%s: Failed to write stream height!", __FUNCTION__); |
| 126 | return err; |
| 127 | } |
| 128 | |
| 129 | if ((err = parcel->writeInt32(mFormat)) != OK) { |
| 130 | ALOGE("%s: Failed to write stream format!", __FUNCTION__); |
| 131 | return err; |
| 132 | } |
| 133 | |
| 134 | if ((err = parcel->writeInt32(mDataSpace)) != OK) { |
| 135 | ALOGE("%s: Failed to write stream dataSpace!", __FUNCTION__); |
| 136 | return err; |
| 137 | } |
| 138 | |
| 139 | if ((err = parcel->writeInt64(mUsage)) != OK) { |
| 140 | ALOGE("%s: Failed to write stream usage!", __FUNCTION__); |
| 141 | return err; |
| 142 | } |
| 143 | |
| 144 | if ((err = parcel->writeInt64(mRequestCount)) != OK) { |
| 145 | ALOGE("%s: Failed to write stream request count!", __FUNCTION__); |
| 146 | return err; |
| 147 | } |
| 148 | |
| 149 | if ((err = parcel->writeInt64(mErrorCount)) != OK) { |
| 150 | ALOGE("%s: Failed to write stream error count!", __FUNCTION__); |
| 151 | return err; |
| 152 | } |
| 153 | |
| 154 | if ((err = parcel->writeInt32(mStartLatencyMs)) != OK) { |
| 155 | ALOGE("%s: Failed to write stream start latency!", __FUNCTION__); |
| 156 | return err; |
| 157 | } |
| 158 | |
| 159 | if ((err = parcel->writeInt32(mMaxHalBuffers)) != OK) { |
| 160 | ALOGE("%s: Failed to write max hal buffers", __FUNCTION__); |
| 161 | return err; |
| 162 | } |
| 163 | |
| 164 | if ((err = parcel->writeInt32(mMaxAppBuffers)) != OK) { |
| 165 | ALOGE("%s: Failed to write max app buffers", __FUNCTION__); |
| 166 | return err; |
| 167 | } |
| 168 | |
| 169 | return OK; |
| 170 | } |
| 171 | |
Shuzhen Wang | bac18d9 | 2020-11-19 14:50:30 -0800 | [diff] [blame] | 172 | const int CameraSessionStats::CAMERA_STATE_OPEN = 0; |
| 173 | const int CameraSessionStats::CAMERA_STATE_ACTIVE = 1; |
| 174 | const int CameraSessionStats::CAMERA_STATE_IDLE = 2; |
| 175 | const int CameraSessionStats::CAMERA_STATE_CLOSED = 3; |
| 176 | |
| 177 | const int CameraSessionStats::CAMERA_FACING_BACK = 0; |
| 178 | const int CameraSessionStats::CAMERA_FACING_FRONT = 1; |
| 179 | const int CameraSessionStats::CAMERA_FACING_EXTERNAL = 2; |
| 180 | |
| 181 | const int CameraSessionStats::CAMERA_API_LEVEL_1 = 1; |
| 182 | const int CameraSessionStats::CAMERA_API_LEVEL_2 = 2; |
| 183 | |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 184 | CameraSessionStats::CameraSessionStats() : |
| 185 | mFacing(CAMERA_FACING_BACK), |
| 186 | mNewCameraState(CAMERA_STATE_CLOSED), |
| 187 | mApiLevel(0), |
| 188 | mIsNdk(false), |
| 189 | mLatencyMs(-1), |
| 190 | mSessionType(0), |
| 191 | mInternalReconfigure(0), |
| 192 | mRequestCount(0), |
| 193 | mResultErrorCount(0), |
| 194 | mDeviceError(false) {} |
| 195 | |
| 196 | CameraSessionStats::CameraSessionStats(const String16& cameraId, |
| 197 | int facing, int newCameraState, const String16& clientName, |
| 198 | int apiLevel, bool isNdk, int32_t latencyMs) : |
| 199 | mCameraId(cameraId), |
| 200 | mFacing(facing), |
| 201 | mNewCameraState(newCameraState), |
| 202 | mClientName(clientName), |
| 203 | mApiLevel(apiLevel), |
| 204 | mIsNdk(isNdk), |
| 205 | mLatencyMs(latencyMs), |
| 206 | mSessionType(0), |
| 207 | mInternalReconfigure(0), |
| 208 | mRequestCount(0), |
| 209 | mResultErrorCount(0), |
| 210 | mDeviceError(0) {} |
| 211 | |
| 212 | status_t CameraSessionStats::readFromParcel(const android::Parcel* parcel) { |
| 213 | if (parcel == NULL) { |
| 214 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 215 | return BAD_VALUE; |
| 216 | } |
| 217 | |
| 218 | status_t err = OK; |
| 219 | |
| 220 | String16 id; |
| 221 | if ((err = parcel->readString16(&id)) != OK) { |
| 222 | ALOGE("%s: Failed to read camera id!", __FUNCTION__); |
| 223 | return BAD_VALUE; |
| 224 | } |
| 225 | |
| 226 | int facing = 0; |
| 227 | if ((err = parcel->readInt32(&facing)) != OK) { |
| 228 | ALOGE("%s: Failed to read camera facing from parcel", __FUNCTION__); |
| 229 | return err; |
| 230 | } |
| 231 | |
| 232 | int32_t newCameraState; |
| 233 | if ((err = parcel->readInt32(&newCameraState)) != OK) { |
| 234 | ALOGE("%s: Failed to read new camera state from parcel", __FUNCTION__); |
| 235 | return err; |
| 236 | } |
| 237 | |
| 238 | String16 clientName; |
| 239 | if ((err = parcel->readString16(&clientName)) != OK) { |
| 240 | ALOGE("%s: Failed to read client name!", __FUNCTION__); |
| 241 | return BAD_VALUE; |
| 242 | } |
| 243 | |
| 244 | int32_t apiLevel; |
| 245 | if ((err = parcel->readInt32(&apiLevel)) != OK) { |
| 246 | ALOGE("%s: Failed to read api level from parcel", __FUNCTION__); |
| 247 | return err; |
| 248 | } |
| 249 | |
| 250 | bool isNdk; |
| 251 | if ((err = parcel->readBool(&isNdk)) != OK) { |
| 252 | ALOGE("%s: Failed to read isNdk flag from parcel", __FUNCTION__); |
| 253 | return err; |
| 254 | } |
| 255 | |
| 256 | int32_t latencyMs; |
| 257 | if ((err = parcel->readInt32(&latencyMs)) != OK) { |
| 258 | ALOGE("%s: Failed to read latencyMs from parcel", __FUNCTION__); |
| 259 | return err; |
| 260 | } |
| 261 | |
| 262 | int32_t sessionType; |
| 263 | if ((err = parcel->readInt32(&sessionType)) != OK) { |
| 264 | ALOGE("%s: Failed to read session type from parcel", __FUNCTION__); |
| 265 | return err; |
| 266 | } |
| 267 | |
| 268 | int32_t internalReconfigure; |
| 269 | if ((err = parcel->readInt32(&internalReconfigure)) != OK) { |
| 270 | ALOGE("%s: Failed to read internal reconfigure count from parcel", __FUNCTION__); |
| 271 | return err; |
| 272 | } |
| 273 | |
| 274 | int64_t requestCount; |
| 275 | if ((err = parcel->readInt64(&requestCount)) != OK) { |
| 276 | ALOGE("%s: Failed to read request count from parcel", __FUNCTION__); |
| 277 | return err; |
| 278 | } |
| 279 | |
| 280 | int64_t resultErrorCount; |
| 281 | if ((err = parcel->readInt64(&resultErrorCount)) != OK) { |
| 282 | ALOGE("%s: Failed to read result error count from parcel", __FUNCTION__); |
| 283 | return err; |
| 284 | } |
| 285 | |
| 286 | bool deviceError; |
| 287 | if ((err = parcel->readBool(&deviceError)) != OK) { |
| 288 | ALOGE("%s: Failed to read device error flag from parcel", __FUNCTION__); |
| 289 | return err; |
| 290 | } |
| 291 | |
| 292 | std::vector<CameraStreamStats> streamStats; |
| 293 | if ((err = parcel->readParcelableVector(&streamStats)) != OK) { |
| 294 | ALOGE("%s: Failed to read stream state from parcel", __FUNCTION__); |
| 295 | return err; |
| 296 | } |
| 297 | |
| 298 | mCameraId = id; |
| 299 | mFacing = facing; |
| 300 | mNewCameraState = newCameraState; |
| 301 | mClientName = clientName; |
| 302 | mApiLevel = apiLevel; |
| 303 | mIsNdk = isNdk; |
| 304 | mLatencyMs = latencyMs; |
| 305 | mSessionType = sessionType; |
| 306 | mInternalReconfigure = internalReconfigure; |
| 307 | mRequestCount = requestCount; |
| 308 | mResultErrorCount = resultErrorCount; |
| 309 | mDeviceError = deviceError; |
| 310 | mStreamStats = std::move(streamStats); |
| 311 | |
| 312 | return OK; |
| 313 | } |
| 314 | |
| 315 | status_t CameraSessionStats::writeToParcel(android::Parcel* parcel) const { |
| 316 | if (parcel == NULL) { |
| 317 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 318 | return BAD_VALUE; |
| 319 | } |
| 320 | |
| 321 | status_t err = OK; |
| 322 | |
| 323 | if ((err = parcel->writeString16(mCameraId)) != OK) { |
| 324 | ALOGE("%s: Failed to write camera id!", __FUNCTION__); |
| 325 | return err; |
| 326 | } |
| 327 | |
| 328 | if ((err = parcel->writeInt32(mFacing)) != OK) { |
| 329 | ALOGE("%s: Failed to write camera facing!", __FUNCTION__); |
| 330 | return err; |
| 331 | } |
| 332 | |
| 333 | if ((err = parcel->writeInt32(mNewCameraState)) != OK) { |
| 334 | ALOGE("%s: Failed to write new camera state!", __FUNCTION__); |
| 335 | return err; |
| 336 | } |
| 337 | |
| 338 | if ((err = parcel->writeString16(mClientName)) != OK) { |
| 339 | ALOGE("%s: Failed to write client name!", __FUNCTION__); |
| 340 | return err; |
| 341 | } |
| 342 | |
| 343 | if ((err = parcel->writeInt32(mApiLevel)) != OK) { |
| 344 | ALOGE("%s: Failed to write api level!", __FUNCTION__); |
| 345 | return err; |
| 346 | } |
| 347 | |
| 348 | if ((err = parcel->writeBool(mIsNdk)) != OK) { |
| 349 | ALOGE("%s: Failed to write isNdk flag!", __FUNCTION__); |
| 350 | return err; |
| 351 | } |
| 352 | |
| 353 | if ((err = parcel->writeInt32(mLatencyMs)) != OK) { |
| 354 | ALOGE("%s: Failed to write latency in Ms!", __FUNCTION__); |
| 355 | return err; |
| 356 | } |
| 357 | |
| 358 | if ((err = parcel->writeInt32(mSessionType)) != OK) { |
| 359 | ALOGE("%s: Failed to write session type!", __FUNCTION__); |
| 360 | return err; |
| 361 | } |
| 362 | |
| 363 | if ((err = parcel->writeInt32(mInternalReconfigure)) != OK) { |
| 364 | ALOGE("%s: Failed to write internal reconfigure count!", __FUNCTION__); |
| 365 | return err; |
| 366 | } |
| 367 | |
| 368 | if ((err = parcel->writeInt64(mRequestCount)) != OK) { |
| 369 | ALOGE("%s: Failed to write request count!", __FUNCTION__); |
| 370 | return err; |
| 371 | } |
| 372 | |
| 373 | if ((err = parcel->writeInt64(mResultErrorCount)) != OK) { |
| 374 | ALOGE("%s: Failed to write result error count!", __FUNCTION__); |
| 375 | return err; |
| 376 | } |
| 377 | |
| 378 | if ((err = parcel->writeBool(mDeviceError)) != OK) { |
| 379 | ALOGE("%s: Failed to write device error flag!", __FUNCTION__); |
| 380 | return err; |
| 381 | } |
| 382 | |
| 383 | if ((err = parcel->writeParcelableVector(mStreamStats)) != OK) { |
| 384 | ALOGE("%s: Failed to write stream states!", __FUNCTION__); |
| 385 | return err; |
| 386 | } |
| 387 | |
| 388 | return OK; |
| 389 | } |
| 390 | |
| 391 | } // namespace hardware |
| 392 | } // namesmpace android |