Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [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 "ConcurrentCamera" |
| 19 | #include <utils/Log.h> |
| 20 | #include <utils/String16.h> |
| 21 | |
| 22 | #include <camera/camera2/ConcurrentCamera.h> |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 23 | #include <camera/StringUtils.h> |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 24 | |
| 25 | #include <binder/Parcel.h> |
| 26 | |
| 27 | namespace android { |
| 28 | namespace hardware { |
| 29 | namespace camera2 { |
| 30 | namespace utils { |
| 31 | |
| 32 | ConcurrentCameraIdCombination::ConcurrentCameraIdCombination() = default; |
| 33 | |
| 34 | ConcurrentCameraIdCombination::ConcurrentCameraIdCombination( |
Biswarup Pal | 7d07286 | 2024-04-17 15:24:47 +0000 | [diff] [blame] | 35 | std::vector<std::pair<std::string, int32_t>> &&combination) |
| 36 | : mConcurrentCameraIdDeviceIdPairs(std::move(combination)) { } |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 37 | |
| 38 | ConcurrentCameraIdCombination::~ConcurrentCameraIdCombination() = default; |
| 39 | |
| 40 | status_t ConcurrentCameraIdCombination::readFromParcel(const android::Parcel* parcel) { |
| 41 | if (parcel == nullptr) { |
| 42 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 43 | return BAD_VALUE; |
| 44 | } |
| 45 | status_t err = OK; |
Biswarup Pal | 7d07286 | 2024-04-17 15:24:47 +0000 | [diff] [blame] | 46 | mConcurrentCameraIdDeviceIdPairs.clear(); |
| 47 | int32_t cameraCount = 0; |
| 48 | if ((err = parcel->readInt32(&cameraCount)) != OK) { |
| 49 | ALOGE("%s: Failed to read the camera count from parcel: %d", __FUNCTION__, err); |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 50 | return err; |
| 51 | } |
Biswarup Pal | 7d07286 | 2024-04-17 15:24:47 +0000 | [diff] [blame] | 52 | for (int32_t i = 0; i < cameraCount; i++) { |
| 53 | String16 cameraId; |
| 54 | if ((err = parcel->readString16(&cameraId)) != OK) { |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 55 | ALOGE("%s: Failed to read camera id!", __FUNCTION__); |
| 56 | return err; |
| 57 | } |
Biswarup Pal | 7d07286 | 2024-04-17 15:24:47 +0000 | [diff] [blame] | 58 | int32_t deviceId; |
| 59 | if ((err = parcel->readInt32(&deviceId)) != OK) { |
| 60 | ALOGE("%s: Failed to read device id!", __FUNCTION__); |
| 61 | return err; |
| 62 | } |
| 63 | mConcurrentCameraIdDeviceIdPairs.push_back({toStdString(cameraId), deviceId}); |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 64 | } |
| 65 | return OK; |
| 66 | } |
| 67 | |
| 68 | status_t ConcurrentCameraIdCombination::writeToParcel(android::Parcel* parcel) const { |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 69 | if (parcel == nullptr) { |
| 70 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 71 | return BAD_VALUE; |
| 72 | } |
| 73 | |
| 74 | status_t err = OK; |
| 75 | |
Biswarup Pal | 7d07286 | 2024-04-17 15:24:47 +0000 | [diff] [blame] | 76 | if ((err = parcel->writeInt32(mConcurrentCameraIdDeviceIdPairs.size())) != OK) { |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 77 | ALOGE("%s: Failed to write the camera id count to parcel: %d", __FUNCTION__, err); |
| 78 | return err; |
| 79 | } |
| 80 | |
Biswarup Pal | 7d07286 | 2024-04-17 15:24:47 +0000 | [diff] [blame] | 81 | for (const auto &it : mConcurrentCameraIdDeviceIdPairs) { |
| 82 | if ((err = parcel->writeString16(toString16(it.first))) != OK) { |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 83 | ALOGE("%s: Failed to write the camera id string to parcel: %d", __FUNCTION__, err); |
| 84 | return err; |
| 85 | } |
Biswarup Pal | 7d07286 | 2024-04-17 15:24:47 +0000 | [diff] [blame] | 86 | if ((err = parcel->writeInt32(it.second)) != OK) { |
| 87 | ALOGE("%s: Failed to write the device id integer to parcel: %d", __FUNCTION__, err); |
| 88 | return err; |
| 89 | } |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 90 | } |
| 91 | return OK; |
| 92 | } |
| 93 | |
| 94 | CameraIdAndSessionConfiguration::CameraIdAndSessionConfiguration() = default; |
| 95 | CameraIdAndSessionConfiguration::~CameraIdAndSessionConfiguration() = default; |
| 96 | |
| 97 | status_t CameraIdAndSessionConfiguration::readFromParcel(const android::Parcel* parcel) { |
| 98 | if (parcel == nullptr) { |
| 99 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 100 | return BAD_VALUE; |
| 101 | } |
| 102 | status_t err = OK; |
| 103 | String16 id; |
| 104 | if ((err = parcel->readString16(&id)) != OK) { |
| 105 | ALOGE("%s: Failed to read camera id!", __FUNCTION__); |
| 106 | return err; |
| 107 | } |
| 108 | if ((err = mSessionConfiguration.readFromParcel(parcel)) != OK) { |
| 109 | ALOGE("%s: Failed to read sessionConfiguration!", __FUNCTION__); |
| 110 | return err; |
| 111 | } |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 112 | mCameraId = toStdString(id); |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 113 | return OK; |
| 114 | } |
| 115 | |
| 116 | status_t CameraIdAndSessionConfiguration::writeToParcel(android::Parcel* parcel) const { |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 117 | if (parcel == nullptr) { |
| 118 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 119 | return BAD_VALUE; |
| 120 | } |
| 121 | |
| 122 | status_t err = OK; |
Austin Borger | 1c1bee0 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 123 | if ((err = parcel->writeString16(toString16(mCameraId))) != OK) { |
Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 124 | ALOGE("%s: Failed to write camera id!", __FUNCTION__); |
| 125 | return err; |
| 126 | } |
| 127 | |
| 128 | if ((err = mSessionConfiguration.writeToParcel(parcel) != OK)) { |
| 129 | ALOGE("%s: Failed to write session configuration!", __FUNCTION__); |
| 130 | return err; |
| 131 | } |
| 132 | return OK; |
| 133 | } |
| 134 | |
| 135 | } // namespace utils |
| 136 | } // namespace camera2 |
| 137 | } // namespace hardware |
| 138 | } // namespace android |