blob: 2f1f22dd6e547719a177d21806166a264f4639ef [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;
75 if (flags::feature_combination_query()) {
76 if ((err = parcel->readBool(&hasSessionParameters)) != OK) {
77 ALOGE("%s: Failed to read hasSessionParameters flag from parcel", __FUNCTION__);
78 return err;
79 }
80
81 if (hasSessionParameters) {
82 if ((err = settings.readFromParcel(parcel)) != OK) {
83 ALOGE("%s: Failed to read metadata flag from parcel", __FUNCTION__);
84 return err;
85 }
86 }
87 }
88
Emilian Peev35ae8262018-11-08 13:11:32 +000089 mOperatingMode = operatingMode;
90 mInputWidth = inputWidth;
91 mInputHeight = inputHeight;
92 mInputFormat = inputFormat;
Shuzhen Wang83bff122020-11-20 15:51:39 -080093 mInputIsMultiResolution = inputIsMultiResolution;
Emilian Peev35ae8262018-11-08 13:11:32 +000094 for (auto& stream : outputStreams) {
95 mOutputStreams.push_back(stream);
96 }
Shuzhen Wang045be6c2023-10-12 10:01:10 -070097 if (flags::feature_combination_query()) {
98 mHasSessionParameters = hasSessionParameters;
99 mSessionParameters = std::move(settings);
100 }
Emilian Peev35ae8262018-11-08 13:11:32 +0000101
102 return err;
103}
104
105status_t SessionConfiguration::writeToParcel(android::Parcel* parcel) const {
106
107 if (parcel == nullptr) return BAD_VALUE;
108 status_t err = OK;
109
110 err = parcel->writeInt32(mOperatingMode);
111 if (err != OK) return err;
112
113 err = parcel->writeInt32(mInputWidth);
114 if (err != OK) return err;
115
116 err = parcel->writeInt32(mInputHeight);
117 if (err != OK) return err;
118
119 err = parcel->writeInt32(mInputFormat);
120 if (err != OK) return err;
121
Shuzhen Wang83bff122020-11-20 15:51:39 -0800122 err = parcel->writeBool(mInputIsMultiResolution);
123 if (err != OK) return err;
124
Emilian Peev35ae8262018-11-08 13:11:32 +0000125 err = parcel->writeParcelableVector(mOutputStreams);
126 if (err != OK) return err;
127
Shuzhen Wang045be6c2023-10-12 10:01:10 -0700128 if (flags::feature_combination_query()) {
129 err = parcel->writeBool(mHasSessionParameters);
130 if (err != OK) return err;
131
132 if (mHasSessionParameters) {
133 err = mSessionParameters.writeToParcel(parcel);
134 if (err != OK) return err;
135 }
136 }
137
Emilian Peev35ae8262018-11-08 13:11:32 +0000138 return OK;
139}
140
141bool SessionConfiguration::outputsEqual(const SessionConfiguration& other) const {
142 const std::vector<OutputConfiguration>& otherOutputStreams =
143 other.getOutputConfigurations();
144
145 if (mOutputStreams.size() != otherOutputStreams.size()) {
146 return false;
147 }
148
149 for (size_t i = 0; i < mOutputStreams.size(); i++) {
150 if (mOutputStreams[i] != otherOutputStreams[i]) {
151 return false;
152 }
153 }
154
155 return true;
156}
157
158bool SessionConfiguration::outputsLessThan(const SessionConfiguration& other) const {
159 const std::vector<OutputConfiguration>& otherOutputStreams =
160 other.getOutputConfigurations();
161
162 if (mOutputStreams.size() != otherOutputStreams.size()) {
163 return mOutputStreams.size() < otherOutputStreams.size();
164 }
165
166 for (size_t i = 0; i < mOutputStreams.size(); i++) {
167 if (mOutputStreams[i] != otherOutputStreams[i]) {
168 return mOutputStreams[i] < otherOutputStreams[i];
169 }
170 }
171
172 return false;
173}
174
175}; // namespace android