• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 #include <binder/Parcel.h>
25 
26 namespace android {
27 namespace hardware {
28 namespace camera2 {
29 namespace utils {
30 
31 ConcurrentCameraIdCombination::ConcurrentCameraIdCombination() = default;
32 
ConcurrentCameraIdCombination(std::vector<std::string> && combination)33 ConcurrentCameraIdCombination::ConcurrentCameraIdCombination(
34         std::vector<std::string> &&combination) : mConcurrentCameraIds(std::move(combination)) { }
35 
36 ConcurrentCameraIdCombination::~ConcurrentCameraIdCombination() = default;
37 
readFromParcel(const android::Parcel * parcel)38 status_t ConcurrentCameraIdCombination::readFromParcel(const android::Parcel* parcel) {
39     if (parcel == nullptr) {
40         ALOGE("%s: Null parcel", __FUNCTION__);
41         return BAD_VALUE;
42     }
43     status_t err = OK;
44     mConcurrentCameraIds.clear();
45     int32_t cameraIdCount = 0;
46     if ((err = parcel->readInt32(&cameraIdCount)) != OK) {
47         ALOGE("%s: Failed to read the camera id count from parcel: %d", __FUNCTION__, err);
48         return err;
49     }
50     for (int32_t i = 0; i < cameraIdCount; i++) {
51         String16 id;
52         if ((err = parcel->readString16(&id)) != OK) {
53             ALOGE("%s: Failed to read camera id!", __FUNCTION__);
54             return err;
55         }
56         mConcurrentCameraIds.push_back(std::string(String8(id).string()));
57     }
58     return OK;
59 }
60 
writeToParcel(android::Parcel * parcel) const61 status_t ConcurrentCameraIdCombination::writeToParcel(android::Parcel* parcel) const {
62 
63     if (parcel == nullptr) {
64         ALOGE("%s: Null parcel", __FUNCTION__);
65         return BAD_VALUE;
66     }
67 
68     status_t err = OK;
69 
70     if ((err = parcel->writeInt32(mConcurrentCameraIds.size())) != OK) {
71         ALOGE("%s: Failed to write the camera id count to parcel: %d", __FUNCTION__, err);
72         return err;
73     }
74 
75     for (const auto &it : mConcurrentCameraIds) {
76         if ((err = parcel->writeString16(String16(it.c_str()))) != OK) {
77             ALOGE("%s: Failed to write the camera id string to parcel: %d", __FUNCTION__, err);
78             return err;
79         }
80     }
81     return OK;
82 }
83 
84 CameraIdAndSessionConfiguration::CameraIdAndSessionConfiguration() = default;
85 CameraIdAndSessionConfiguration::~CameraIdAndSessionConfiguration() = default;
86 
readFromParcel(const android::Parcel * parcel)87 status_t CameraIdAndSessionConfiguration::readFromParcel(const android::Parcel* parcel) {
88     if (parcel == nullptr) {
89         ALOGE("%s: Null parcel", __FUNCTION__);
90         return BAD_VALUE;
91     }
92     status_t err = OK;
93     String16 id;
94     if ((err = parcel->readString16(&id)) != OK) {
95         ALOGE("%s: Failed to read camera id!", __FUNCTION__);
96         return err;
97     }
98     if ((err = mSessionConfiguration.readFromParcel(parcel)) != OK) {
99         ALOGE("%s: Failed to read sessionConfiguration!", __FUNCTION__);
100         return err;
101     }
102     mCameraId = std::string(String8(id).string());
103     return OK;
104 }
105 
writeToParcel(android::Parcel * parcel) const106 status_t CameraIdAndSessionConfiguration::writeToParcel(android::Parcel* parcel) const {
107 
108     if (parcel == nullptr) {
109         ALOGE("%s: Null parcel", __FUNCTION__);
110         return BAD_VALUE;
111     }
112 
113     status_t err = OK;
114     if ((err = parcel->writeString16(String16(mCameraId.c_str()))) != OK) {
115         ALOGE("%s: Failed to write camera id!", __FUNCTION__);
116         return err;
117     }
118 
119     if ((err = mSessionConfiguration.writeToParcel(parcel) != OK)) {
120         ALOGE("%s: Failed to write session configuration!", __FUNCTION__);
121         return err;
122     }
123     return OK;
124 }
125 
126 } // namespace utils
127 } // namespace camera2
128 } // namespace hardware
129 } // namespace android
130