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>
23 #include <camera/StringUtils.h>
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
ConcurrentCameraIdCombination(std::vector<std::pair<std::string,int32_t>> && combination)34 ConcurrentCameraIdCombination::ConcurrentCameraIdCombination(
35 std::vector<std::pair<std::string, int32_t>> &&combination)
36 : mConcurrentCameraIdDeviceIdPairs(std::move(combination)) { }
37
38 ConcurrentCameraIdCombination::~ConcurrentCameraIdCombination() = default;
39
readFromParcel(const android::Parcel * parcel)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;
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);
50 return err;
51 }
52 for (int32_t i = 0; i < cameraCount; i++) {
53 String16 cameraId;
54 if ((err = parcel->readString16(&cameraId)) != OK) {
55 ALOGE("%s: Failed to read camera id!", __FUNCTION__);
56 return err;
57 }
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});
64 }
65 return OK;
66 }
67
writeToParcel(android::Parcel * parcel) const68 status_t ConcurrentCameraIdCombination::writeToParcel(android::Parcel* parcel) const {
69 if (parcel == nullptr) {
70 ALOGE("%s: Null parcel", __FUNCTION__);
71 return BAD_VALUE;
72 }
73
74 status_t err = OK;
75
76 if ((err = parcel->writeInt32(mConcurrentCameraIdDeviceIdPairs.size())) != OK) {
77 ALOGE("%s: Failed to write the camera id count to parcel: %d", __FUNCTION__, err);
78 return err;
79 }
80
81 for (const auto &it : mConcurrentCameraIdDeviceIdPairs) {
82 if ((err = parcel->writeString16(toString16(it.first))) != OK) {
83 ALOGE("%s: Failed to write the camera id string to parcel: %d", __FUNCTION__, err);
84 return err;
85 }
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 }
90 }
91 return OK;
92 }
93
94 CameraIdAndSessionConfiguration::CameraIdAndSessionConfiguration() = default;
95 CameraIdAndSessionConfiguration::~CameraIdAndSessionConfiguration() = default;
96
readFromParcel(const android::Parcel * parcel)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 }
112 mCameraId = toStdString(id);
113 return OK;
114 }
115
writeToParcel(android::Parcel * parcel) const116 status_t CameraIdAndSessionConfiguration::writeToParcel(android::Parcel* parcel) const {
117 if (parcel == nullptr) {
118 ALOGE("%s: Null parcel", __FUNCTION__);
119 return BAD_VALUE;
120 }
121
122 status_t err = OK;
123 if ((err = parcel->writeString16(toString16(mCameraId))) != OK) {
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
139