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     std::vector<OutputConfiguration> outputStreams;
59     if ((err = parcel->readParcelableVector(&outputStreams)) != OK) {
60         ALOGE("%s: Failed to read output configurations from parcel", __FUNCTION__);
61         return err;
62     }
63 
64     mOperatingMode = operatingMode;
65     mInputWidth = inputWidth;
66     mInputHeight = inputHeight;
67     mInputFormat = inputFormat;
68     for (auto& stream : outputStreams) {
69         mOutputStreams.push_back(stream);
70     }
71 
72 
73     return err;
74 }
75 
writeToParcel(android::Parcel * parcel) const76 status_t SessionConfiguration::writeToParcel(android::Parcel* parcel) const {
77 
78     if (parcel == nullptr) return BAD_VALUE;
79     status_t err = OK;
80 
81     err = parcel->writeInt32(mOperatingMode);
82     if (err != OK) return err;
83 
84     err = parcel->writeInt32(mInputWidth);
85     if (err != OK) return err;
86 
87     err = parcel->writeInt32(mInputHeight);
88     if (err != OK) return err;
89 
90     err = parcel->writeInt32(mInputFormat);
91     if (err != OK) return err;
92 
93     err = parcel->writeParcelableVector(mOutputStreams);
94     if (err != OK) return err;
95 
96     return OK;
97 }
98 
outputsEqual(const SessionConfiguration & other) const99 bool SessionConfiguration::outputsEqual(const SessionConfiguration& other) const {
100     const std::vector<OutputConfiguration>& otherOutputStreams =
101             other.getOutputConfigurations();
102 
103     if (mOutputStreams.size() !=  otherOutputStreams.size()) {
104         return false;
105     }
106 
107     for (size_t i = 0; i < mOutputStreams.size(); i++) {
108         if (mOutputStreams[i] != otherOutputStreams[i]) {
109             return false;
110         }
111     }
112 
113     return true;
114 }
115 
outputsLessThan(const SessionConfiguration & other) const116 bool SessionConfiguration::outputsLessThan(const SessionConfiguration& other) const {
117     const std::vector<OutputConfiguration>& otherOutputStreams =
118             other.getOutputConfigurations();
119 
120     if (mOutputStreams.size() !=  otherOutputStreams.size()) {
121         return mOutputStreams.size() < otherOutputStreams.size();
122     }
123 
124     for (size_t i = 0; i < mOutputStreams.size(); i++) {
125         if (mOutputStreams[i] != otherOutputStreams[i]) {
126             return mOutputStreams[i] < otherOutputStreams[i];
127         }
128     }
129 
130     return false;
131 }
132 
133 }; // namespace android
134