| 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 | 0fb3ad9 | 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( | 
|  | 35 | std::vector<std::string> &&combination) : mConcurrentCameraIds(std::move(combination)) { } | 
|  | 36 |  | 
|  | 37 | ConcurrentCameraIdCombination::~ConcurrentCameraIdCombination() = default; | 
|  | 38 |  | 
|  | 39 | status_t ConcurrentCameraIdCombination::readFromParcel(const android::Parcel* parcel) { | 
|  | 40 | if (parcel == nullptr) { | 
|  | 41 | ALOGE("%s: Null parcel", __FUNCTION__); | 
|  | 42 | return BAD_VALUE; | 
|  | 43 | } | 
|  | 44 | status_t err = OK; | 
|  | 45 | mConcurrentCameraIds.clear(); | 
|  | 46 | int32_t cameraIdCount = 0; | 
|  | 47 | if ((err = parcel->readInt32(&cameraIdCount)) != OK) { | 
|  | 48 | ALOGE("%s: Failed to read the camera id count from parcel: %d", __FUNCTION__, err); | 
|  | 49 | return err; | 
|  | 50 | } | 
|  | 51 | for (int32_t i = 0; i < cameraIdCount; i++) { | 
|  | 52 | String16 id; | 
|  | 53 | if ((err = parcel->readString16(&id)) != OK) { | 
|  | 54 | ALOGE("%s: Failed to read camera id!", __FUNCTION__); | 
|  | 55 | return err; | 
|  | 56 | } | 
| Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 57 | mConcurrentCameraIds.push_back(toStdString(id)); | 
| Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 58 | } | 
|  | 59 | return OK; | 
|  | 60 | } | 
|  | 61 |  | 
|  | 62 | status_t ConcurrentCameraIdCombination::writeToParcel(android::Parcel* parcel) const { | 
|  | 63 |  | 
|  | 64 | if (parcel == nullptr) { | 
|  | 65 | ALOGE("%s: Null parcel", __FUNCTION__); | 
|  | 66 | return BAD_VALUE; | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | status_t err = OK; | 
|  | 70 |  | 
|  | 71 | if ((err = parcel->writeInt32(mConcurrentCameraIds.size())) != OK) { | 
|  | 72 | ALOGE("%s: Failed to write the camera id count to parcel: %d", __FUNCTION__, err); | 
|  | 73 | return err; | 
|  | 74 | } | 
|  | 75 |  | 
|  | 76 | for (const auto &it : mConcurrentCameraIds) { | 
| Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 77 | if ((err = parcel->writeString16(toString16(it))) != OK) { | 
| Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 78 | ALOGE("%s: Failed to write the camera id string to parcel: %d", __FUNCTION__, err); | 
|  | 79 | return err; | 
|  | 80 | } | 
|  | 81 | } | 
|  | 82 | return OK; | 
|  | 83 | } | 
|  | 84 |  | 
|  | 85 | CameraIdAndSessionConfiguration::CameraIdAndSessionConfiguration() = default; | 
|  | 86 | CameraIdAndSessionConfiguration::~CameraIdAndSessionConfiguration() = default; | 
|  | 87 |  | 
|  | 88 | status_t CameraIdAndSessionConfiguration::readFromParcel(const android::Parcel* parcel) { | 
|  | 89 | if (parcel == nullptr) { | 
|  | 90 | ALOGE("%s: Null parcel", __FUNCTION__); | 
|  | 91 | return BAD_VALUE; | 
|  | 92 | } | 
|  | 93 | status_t err = OK; | 
|  | 94 | String16 id; | 
|  | 95 | if ((err = parcel->readString16(&id)) != OK) { | 
|  | 96 | ALOGE("%s: Failed to read camera id!", __FUNCTION__); | 
|  | 97 | return err; | 
|  | 98 | } | 
|  | 99 | if ((err = mSessionConfiguration.readFromParcel(parcel)) != OK) { | 
|  | 100 | ALOGE("%s: Failed to read sessionConfiguration!", __FUNCTION__); | 
|  | 101 | return err; | 
|  | 102 | } | 
| Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 103 | mCameraId = toStdString(id); | 
| Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 104 | return OK; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | status_t CameraIdAndSessionConfiguration::writeToParcel(android::Parcel* parcel) const { | 
|  | 108 |  | 
|  | 109 | if (parcel == nullptr) { | 
|  | 110 | ALOGE("%s: Null parcel", __FUNCTION__); | 
|  | 111 | return BAD_VALUE; | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | status_t err = OK; | 
| Austin Borger | 0fb3ad9 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 115 | if ((err = parcel->writeString16(toString16(mCameraId))) != OK) { | 
| Jayant Chowdhary | 2bbdce4 | 2020-01-12 14:55:41 -0800 | [diff] [blame] | 116 | ALOGE("%s: Failed to write camera id!", __FUNCTION__); | 
|  | 117 | return err; | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | if ((err = mSessionConfiguration.writeToParcel(parcel) != OK)) { | 
|  | 121 | ALOGE("%s: Failed to write session configuration!", __FUNCTION__); | 
|  | 122 | return err; | 
|  | 123 | } | 
|  | 124 | return OK; | 
|  | 125 | } | 
|  | 126 |  | 
|  | 127 | } // namespace utils | 
|  | 128 | } // namespace camera2 | 
|  | 129 | } // namespace hardware | 
|  | 130 | } // namespace android |