1 /*
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>
25 #include <com_android_internal_camera_flags.h>
26 #include <binder/Parcel.h>
27
28 namespace android {
29
30 namespace flags = com::android::internal::camera::flags;
31
readFromParcel(const android::Parcel * parcel)32 status_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
61 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
67 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
73 bool hasSessionParameters = false;
74 CameraMetadata settings;
75 if ((err = parcel->readBool(&hasSessionParameters)) != OK) {
76 ALOGE("%s: Failed to read hasSessionParameters flag from parcel", __FUNCTION__);
77 return err;
78 }
79
80 if (hasSessionParameters) {
81 if ((err = settings.readFromParcel(parcel)) != OK) {
82 ALOGE("%s: Failed to read metadata flag from parcel", __FUNCTION__);
83 return err;
84 }
85 }
86
87 mOperatingMode = operatingMode;
88 mInputWidth = inputWidth;
89 mInputHeight = inputHeight;
90 mInputFormat = inputFormat;
91 mInputIsMultiResolution = inputIsMultiResolution;
92 for (auto& stream : outputStreams) {
93 mOutputStreams.push_back(stream);
94 }
95 mHasSessionParameters = hasSessionParameters;
96 mSessionParameters = std::move(settings);
97
98 return err;
99 }
100
writeToParcel(android::Parcel * parcel) const101 status_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
118 err = parcel->writeBool(mInputIsMultiResolution);
119 if (err != OK) return err;
120
121 err = parcel->writeParcelableVector(mOutputStreams);
122 if (err != OK) return err;
123
124 err = parcel->writeBool(mHasSessionParameters);
125 if (err != OK) return err;
126
127 if (mHasSessionParameters) {
128 err = mSessionParameters.writeToParcel(parcel);
129 if (err != OK) return err;
130 }
131
132 return OK;
133 }
134
outputsEqual(const SessionConfiguration & other) const135 bool 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
outputsLessThan(const SessionConfiguration & other) const152 bool 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
170