blob: ac442edbf334d62539ae2bae60807130398aeee2 [file] [log] [blame]
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -08001/*
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 Borger1c1bee02023-06-01 16:51:35 -070023#include <camera/StringUtils.h>
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080024
25#include <binder/Parcel.h>
26
27namespace android {
28namespace hardware {
29namespace camera2 {
30namespace utils {
31
32ConcurrentCameraIdCombination::ConcurrentCameraIdCombination() = default;
33
34ConcurrentCameraIdCombination::ConcurrentCameraIdCombination(
Biswarup Pal7d072862024-04-17 15:24:47 +000035 std::vector<std::pair<std::string, int32_t>> &&combination)
36 : mConcurrentCameraIdDeviceIdPairs(std::move(combination)) { }
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080037
38ConcurrentCameraIdCombination::~ConcurrentCameraIdCombination() = default;
39
40status_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 Pal7d072862024-04-17 15:24:47 +000046 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 Chowdhary2bbdce42020-01-12 14:55:41 -080050 return err;
51 }
Biswarup Pal7d072862024-04-17 15:24:47 +000052 for (int32_t i = 0; i < cameraCount; i++) {
53 String16 cameraId;
54 if ((err = parcel->readString16(&cameraId)) != OK) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080055 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
56 return err;
57 }
Biswarup Pal7d072862024-04-17 15:24:47 +000058 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 Chowdhary2bbdce42020-01-12 14:55:41 -080064 }
65 return OK;
66}
67
68status_t ConcurrentCameraIdCombination::writeToParcel(android::Parcel* parcel) const {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080069 if (parcel == nullptr) {
70 ALOGE("%s: Null parcel", __FUNCTION__);
71 return BAD_VALUE;
72 }
73
74 status_t err = OK;
75
Biswarup Pal7d072862024-04-17 15:24:47 +000076 if ((err = parcel->writeInt32(mConcurrentCameraIdDeviceIdPairs.size())) != OK) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080077 ALOGE("%s: Failed to write the camera id count to parcel: %d", __FUNCTION__, err);
78 return err;
79 }
80
Biswarup Pal7d072862024-04-17 15:24:47 +000081 for (const auto &it : mConcurrentCameraIdDeviceIdPairs) {
82 if ((err = parcel->writeString16(toString16(it.first))) != OK) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -080083 ALOGE("%s: Failed to write the camera id string to parcel: %d", __FUNCTION__, err);
84 return err;
85 }
Biswarup Pal7d072862024-04-17 15:24:47 +000086 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 Chowdhary2bbdce42020-01-12 14:55:41 -080090 }
91 return OK;
92}
93
94CameraIdAndSessionConfiguration::CameraIdAndSessionConfiguration() = default;
95CameraIdAndSessionConfiguration::~CameraIdAndSessionConfiguration() = default;
96
97status_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 Borger1c1bee02023-06-01 16:51:35 -0700112 mCameraId = toStdString(id);
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800113 return OK;
114}
115
116status_t CameraIdAndSessionConfiguration::writeToParcel(android::Parcel* parcel) const {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800117 if (parcel == nullptr) {
118 ALOGE("%s: Null parcel", __FUNCTION__);
119 return BAD_VALUE;
120 }
121
122 status_t err = OK;
Austin Borger1c1bee02023-06-01 16:51:35 -0700123 if ((err = parcel->writeString16(toString16(mCameraId))) != OK) {
Jayant Chowdhary2bbdce42020-01-12 14:55:41 -0800124 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