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 <binder/Parcel.h>
26
27 namespace android {
28
readFromParcel(const android::Parcel * parcel)29 status_t SessionConfiguration::readFromParcel(const android::Parcel* parcel) {
30 status_t err = OK;
31 int operatingMode = 0;
32
33 if (parcel == nullptr) return BAD_VALUE;
34
35 if ((err = parcel->readInt32(&operatingMode)) != OK) {
36 ALOGE("%s: Failed to read operating mode from parcel", __FUNCTION__);
37 return err;
38 }
39
40 int inputWidth = 0;
41 if ((err = parcel->readInt32(&inputWidth)) != OK) {
42 ALOGE("%s: Failed to read input width from parcel", __FUNCTION__);
43 return err;
44 }
45
46 int inputHeight = 0;
47 if ((err = parcel->readInt32(&inputHeight)) != OK) {
48 ALOGE("%s: Failed to read input height from parcel", __FUNCTION__);
49 return err;
50 }
51
52 int inputFormat = -1;
53 if ((err = parcel->readInt32(&inputFormat)) != OK) {
54 ALOGE("%s: Failed to read input format from parcel", __FUNCTION__);
55 return err;
56 }
57
58 bool inputIsMultiResolution = false;
59 if ((err = parcel->readBool(&inputIsMultiResolution)) != OK) {
60 ALOGE("%s: Failed to read input multi-resolution flag from parcel", __FUNCTION__);
61 return err;
62 }
63
64 std::vector<OutputConfiguration> outputStreams;
65 if ((err = parcel->readParcelableVector(&outputStreams)) != OK) {
66 ALOGE("%s: Failed to read output configurations from parcel", __FUNCTION__);
67 return err;
68 }
69
70 mOperatingMode = operatingMode;
71 mInputWidth = inputWidth;
72 mInputHeight = inputHeight;
73 mInputFormat = inputFormat;
74 mInputIsMultiResolution = inputIsMultiResolution;
75 for (auto& stream : outputStreams) {
76 mOutputStreams.push_back(stream);
77 }
78
79
80 return err;
81 }
82
writeToParcel(android::Parcel * parcel) const83 status_t SessionConfiguration::writeToParcel(android::Parcel* parcel) const {
84
85 if (parcel == nullptr) return BAD_VALUE;
86 status_t err = OK;
87
88 err = parcel->writeInt32(mOperatingMode);
89 if (err != OK) return err;
90
91 err = parcel->writeInt32(mInputWidth);
92 if (err != OK) return err;
93
94 err = parcel->writeInt32(mInputHeight);
95 if (err != OK) return err;
96
97 err = parcel->writeInt32(mInputFormat);
98 if (err != OK) return err;
99
100 err = parcel->writeBool(mInputIsMultiResolution);
101 if (err != OK) return err;
102
103 err = parcel->writeParcelableVector(mOutputStreams);
104 if (err != OK) return err;
105
106 return OK;
107 }
108
outputsEqual(const SessionConfiguration & other) const109 bool SessionConfiguration::outputsEqual(const SessionConfiguration& other) const {
110 const std::vector<OutputConfiguration>& otherOutputStreams =
111 other.getOutputConfigurations();
112
113 if (mOutputStreams.size() != otherOutputStreams.size()) {
114 return false;
115 }
116
117 for (size_t i = 0; i < mOutputStreams.size(); i++) {
118 if (mOutputStreams[i] != otherOutputStreams[i]) {
119 return false;
120 }
121 }
122
123 return true;
124 }
125
outputsLessThan(const SessionConfiguration & other) const126 bool SessionConfiguration::outputsLessThan(const SessionConfiguration& other) const {
127 const std::vector<OutputConfiguration>& otherOutputStreams =
128 other.getOutputConfigurations();
129
130 if (mOutputStreams.size() != otherOutputStreams.size()) {
131 return mOutputStreams.size() < otherOutputStreams.size();
132 }
133
134 for (size_t i = 0; i < mOutputStreams.size(); i++) {
135 if (mOutputStreams[i] != otherOutputStreams[i]) {
136 return mOutputStreams[i] < otherOutputStreams[i];
137 }
138 }
139
140 return false;
141 }
142
143 }; // namespace android
144