blob: 065d28350f9b12c81c874cbc103a2ea6e74914e9 [file] [log] [blame]
Emilian Peev35ae8262018-11-08 13:11:32 +00001/*
2**
3** Copyright 2018, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#define LOG_TAG "SessionConfiguration"
19//#define LOG_NDEBUG 0
20
21#include <utils/Log.h>
22
23#include <camera/camera2/SessionConfiguration.h>
24#include <camera/camera2/OutputConfiguration.h>
Shuzhen Wang045be6c2023-10-12 10:01:10 -070025#include <com_android_internal_camera_flags.h>
Emilian Peev35ae8262018-11-08 13:11:32 +000026#include <binder/Parcel.h>
27
28namespace android {
29
Shuzhen Wang045be6c2023-10-12 10:01:10 -070030namespace flags = com::android::internal::camera::flags;
31
Emilian Peev35ae8262018-11-08 13:11:32 +000032status_t SessionConfiguration::readFromParcel(const android::Parcel* parcel) {
33 status_t err = OK;
34 int operatingMode = 0;
35
36 if (parcel == nullptr) return BAD_VALUE;
37
38 if ((err = parcel->readInt32(&operatingMode)) != OK) {
39 ALOGE("%s: Failed to read operating mode from parcel", __FUNCTION__);
40 return err;
41 }
42
43 int inputWidth = 0;
44 if ((err = parcel->readInt32(&inputWidth)) != OK) {
45 ALOGE("%s: Failed to read input width from parcel", __FUNCTION__);
46 return err;
47 }
48
49 int inputHeight = 0;
50 if ((err = parcel->readInt32(&inputHeight)) != OK) {
51 ALOGE("%s: Failed to read input height from parcel", __FUNCTION__);
52 return err;
53 }
54
55 int inputFormat = -1;
56 if ((err = parcel->readInt32(&inputFormat)) != OK) {
57 ALOGE("%s: Failed to read input format from parcel", __FUNCTION__);
58 return err;
59 }
60
Shuzhen Wang83bff122020-11-20 15:51:39 -080061 bool inputIsMultiResolution = false;
62 if ((err = parcel->readBool(&inputIsMultiResolution)) != OK) {
63 ALOGE("%s: Failed to read input multi-resolution flag from parcel", __FUNCTION__);
64 return err;
65 }
66
Emilian Peev35ae8262018-11-08 13:11:32 +000067 std::vector<OutputConfiguration> outputStreams;
68 if ((err = parcel->readParcelableVector(&outputStreams)) != OK) {
69 ALOGE("%s: Failed to read output configurations from parcel", __FUNCTION__);
70 return err;
71 }
72
Shuzhen Wang045be6c2023-10-12 10:01:10 -070073 bool hasSessionParameters = false;
74 CameraMetadata settings;
Shuzhen Wang14275432024-09-09 10:02:10 -070075 if ((err = parcel->readBool(&hasSessionParameters)) != OK) {
76 ALOGE("%s: Failed to read hasSessionParameters flag from parcel", __FUNCTION__);
77 return err;
78 }
Shuzhen Wang045be6c2023-10-12 10:01:10 -070079
Shuzhen Wang14275432024-09-09 10:02:10 -070080 if (hasSessionParameters) {
81 if ((err = settings.readFromParcel(parcel)) != OK) {
82 ALOGE("%s: Failed to read metadata flag from parcel", __FUNCTION__);
83 return err;
Shuzhen Wang045be6c2023-10-12 10:01:10 -070084 }
85 }
86
Emilian Peev35ae8262018-11-08 13:11:32 +000087 mOperatingMode = operatingMode;
88 mInputWidth = inputWidth;
89 mInputHeight = inputHeight;
90 mInputFormat = inputFormat;
Shuzhen Wang83bff122020-11-20 15:51:39 -080091 mInputIsMultiResolution = inputIsMultiResolution;
Emilian Peev35ae8262018-11-08 13:11:32 +000092 for (auto& stream : outputStreams) {
93 mOutputStreams.push_back(stream);
94 }
Shuzhen Wang14275432024-09-09 10:02:10 -070095 mHasSessionParameters = hasSessionParameters;
96 mSessionParameters = std::move(settings);
Emilian Peev35ae8262018-11-08 13:11:32 +000097
98 return err;
99}
100
101status_t SessionConfiguration::writeToParcel(android::Parcel* parcel) const {
102
103 if (parcel == nullptr) return BAD_VALUE;
104 status_t err = OK;
105
106 err = parcel->writeInt32(mOperatingMode);
107 if (err != OK) return err;
108
109 err = parcel->writeInt32(mInputWidth);
110 if (err != OK) return err;
111
112 err = parcel->writeInt32(mInputHeight);
113 if (err != OK) return err;
114
115 err = parcel->writeInt32(mInputFormat);
116 if (err != OK) return err;
117
Shuzhen Wang83bff122020-11-20 15:51:39 -0800118 err = parcel->writeBool(mInputIsMultiResolution);
119 if (err != OK) return err;
120
Emilian Peev35ae8262018-11-08 13:11:32 +0000121 err = parcel->writeParcelableVector(mOutputStreams);
122 if (err != OK) return err;
123
Shuzhen Wang14275432024-09-09 10:02:10 -0700124 err = parcel->writeBool(mHasSessionParameters);
125 if (err != OK) return err;
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700126
Shuzhen Wang14275432024-09-09 10:02:10 -0700127 if (mHasSessionParameters) {
128 err = mSessionParameters.writeToParcel(parcel);
129 if (err != OK) return err;
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700130 }
131
Emilian Peev35ae8262018-11-08 13:11:32 +0000132 return OK;
133}
134
135bool SessionConfiguration::outputsEqual(const SessionConfiguration& other) const {
136 const std::vector<OutputConfiguration>& otherOutputStreams =
137 other.getOutputConfigurations();
138
139 if (mOutputStreams.size() != otherOutputStreams.size()) {
140 return false;
141 }
142
143 for (size_t i = 0; i < mOutputStreams.size(); i++) {
144 if (mOutputStreams[i] != otherOutputStreams[i]) {
145 return false;
146 }
147 }
148
149 return true;
150}
151
152bool SessionConfiguration::outputsLessThan(const SessionConfiguration& other) const {
153 const std::vector<OutputConfiguration>& otherOutputStreams =
154 other.getOutputConfigurations();
155
156 if (mOutputStreams.size() != otherOutputStreams.size()) {
157 return mOutputStreams.size() < otherOutputStreams.size();
158 }
159
160 for (size_t i = 0; i < mOutputStreams.size(); i++) {
161 if (mOutputStreams[i] != otherOutputStreams[i]) {
162 return mOutputStreams[i] < otherOutputStreams[i];
163 }
164 }
165
166 return false;
167}
168
169}; // namespace android