Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 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> |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 25 | #include <com_android_internal_camera_flags.h> |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 26 | #include <binder/Parcel.h> |
| 27 | |
| 28 | namespace android { |
| 29 | |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 30 | namespace flags = com::android::internal::camera::flags; |
| 31 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 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 | |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 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 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 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 | |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 73 | 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 Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 89 | mOperatingMode = operatingMode; |
| 90 | mInputWidth = inputWidth; |
| 91 | mInputHeight = inputHeight; |
| 92 | mInputFormat = inputFormat; |
Shuzhen Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 93 | mInputIsMultiResolution = inputIsMultiResolution; |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 94 | for (auto& stream : outputStreams) { |
| 95 | mOutputStreams.push_back(stream); |
| 96 | } |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 97 | if (flags::feature_combination_query()) { |
| 98 | mHasSessionParameters = hasSessionParameters; |
| 99 | mSessionParameters = std::move(settings); |
| 100 | } |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 101 | |
| 102 | return err; |
| 103 | } |
| 104 | |
| 105 | status_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 Wang | 83bff12 | 2020-11-20 15:51:39 -0800 | [diff] [blame] | 122 | err = parcel->writeBool(mInputIsMultiResolution); |
| 123 | if (err != OK) return err; |
| 124 | |
Emilian Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 125 | err = parcel->writeParcelableVector(mOutputStreams); |
| 126 | if (err != OK) return err; |
| 127 | |
Shuzhen Wang | 045be6c | 2023-10-12 10:01:10 -0700 | [diff] [blame] | 128 | 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 Peev | 35ae826 | 2018-11-08 13:11:32 +0000 | [diff] [blame] | 138 | return OK; |
| 139 | } |
| 140 | |
| 141 | bool 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 | |
| 158 | bool 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 |