blob: 7cf6087830b3fbcc8d7ed555e730708de399ff83 [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>
25#include <binder/Parcel.h>
26
27namespace android {
28
29status_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
Shuzhen Wang83bff122020-11-20 15:51:39 -080058 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
Emilian Peev35ae8262018-11-08 13:11:32 +000064 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;
Shuzhen Wang83bff122020-11-20 15:51:39 -080074 mInputIsMultiResolution = inputIsMultiResolution;
Emilian Peev35ae8262018-11-08 13:11:32 +000075 for (auto& stream : outputStreams) {
76 mOutputStreams.push_back(stream);
77 }
78
79
80 return err;
81}
82
83status_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
Shuzhen Wang83bff122020-11-20 15:51:39 -0800100 err = parcel->writeBool(mInputIsMultiResolution);
101 if (err != OK) return err;
102
Emilian Peev35ae8262018-11-08 13:11:32 +0000103 err = parcel->writeParcelableVector(mOutputStreams);
104 if (err != OK) return err;
105
106 return OK;
107}
108
109bool 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
126bool 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