Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2013, 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_NDEBUG 0 |
| 19 | #define LOG_TAG "CameraRequest" |
| 20 | #include <utils/Log.h> |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 21 | #include <utils/String16.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 22 | |
Eino-Ville Talvala | 7b82efe | 2013-07-25 17:12:35 -0700 | [diff] [blame] | 23 | #include <camera/camera2/CaptureRequest.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 24 | |
| 25 | #include <binder/Parcel.h> |
| 26 | #include <gui/Surface.h> |
Mathias Agopian | 032845c | 2017-02-08 17:05:02 -0800 | [diff] [blame] | 27 | #include <gui/view/Surface.h> |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 28 | |
| 29 | namespace android { |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 30 | namespace hardware { |
| 31 | namespace camera2 { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 32 | |
Mathias Agopian | 032845c | 2017-02-08 17:05:02 -0800 | [diff] [blame] | 33 | // These must be in the .cpp (to avoid inlining) |
| 34 | CaptureRequest::CaptureRequest() = default; |
| 35 | CaptureRequest::~CaptureRequest() = default; |
| 36 | CaptureRequest::CaptureRequest(const CaptureRequest& rhs) = default; |
| 37 | CaptureRequest::CaptureRequest(CaptureRequest&& rhs) noexcept = default; |
| 38 | |
| 39 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 40 | status_t CaptureRequest::readFromParcel(const android::Parcel* parcel) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 41 | if (parcel == NULL) { |
| 42 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 43 | return BAD_VALUE; |
| 44 | } |
| 45 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 46 | mSurfaceList.clear(); |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 47 | mStreamIdxList.clear(); |
| 48 | mSurfaceIdxList.clear(); |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 49 | mPhysicalCameraSettings.clear(); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 50 | |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 51 | status_t err = OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 52 | |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 53 | int32_t settingsCount; |
| 54 | if ((err = parcel->readInt32(&settingsCount)) != OK) { |
| 55 | ALOGE("%s: Failed to read the settings count from parcel: %d", __FUNCTION__, err); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 56 | return err; |
| 57 | } |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 58 | |
| 59 | if (settingsCount <= 0) { |
| 60 | ALOGE("%s: Settings count %d should always be positive!", __FUNCTION__, settingsCount); |
| 61 | return BAD_VALUE; |
| 62 | } |
| 63 | |
| 64 | for (int32_t i = 0; i < settingsCount; i++) { |
| 65 | String16 id; |
| 66 | if ((err = parcel->readString16(&id)) != OK) { |
| 67 | ALOGE("%s: Failed to read camera id!", __FUNCTION__); |
| 68 | return BAD_VALUE; |
| 69 | } |
| 70 | |
| 71 | CameraMetadata settings; |
| 72 | if ((err = settings.readFromParcel(parcel)) != OK) { |
| 73 | ALOGE("%s: Failed to read metadata from parcel", __FUNCTION__); |
| 74 | return err; |
| 75 | } |
| 76 | ALOGV("%s: Read metadata from parcel", __FUNCTION__); |
| 77 | mPhysicalCameraSettings.push_back({std::string(String8(id).string()), settings}); |
| 78 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 79 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 80 | int isReprocess = 0; |
| 81 | if ((err = parcel->readInt32(&isReprocess)) != OK) { |
| 82 | ALOGE("%s: Failed to read reprocessing from parcel", __FUNCTION__); |
| 83 | return err; |
| 84 | } |
| 85 | mIsReprocess = (isReprocess != 0); |
| 86 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 87 | int32_t size; |
| 88 | if ((err = parcel->readInt32(&size)) != OK) { |
| 89 | ALOGE("%s: Failed to read surface list size from parcel", __FUNCTION__); |
| 90 | return err; |
| 91 | } |
| 92 | ALOGV("%s: Read surface list size = %d", __FUNCTION__, size); |
| 93 | |
| 94 | // Do not distinguish null arrays from 0-sized arrays. |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 95 | for (int32_t i = 0; i < size; ++i) { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 96 | // Parcel.writeParcelableArray |
| 97 | size_t len; |
| 98 | const char16_t* className = parcel->readString16Inplace(&len); |
| 99 | ALOGV("%s: Read surface class = %s", __FUNCTION__, |
| 100 | className != NULL ? String8(className).string() : "<null>"); |
| 101 | |
| 102 | if (className == NULL) { |
| 103 | continue; |
| 104 | } |
| 105 | |
| 106 | // Surface.writeToParcel |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 107 | view::Surface surfaceShim; |
| 108 | if ((err = surfaceShim.readFromParcel(parcel)) != OK) { |
| 109 | ALOGE("%s: Failed to read output target Surface %d from parcel: %s (%d)", |
| 110 | __FUNCTION__, i, strerror(-err), err); |
| 111 | return err; |
| 112 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 113 | |
| 114 | sp<Surface> surface; |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 115 | if (surfaceShim.graphicBufferProducer != NULL) { |
| 116 | surface = new Surface(surfaceShim.graphicBufferProducer); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | mSurfaceList.push_back(surface); |
| 120 | } |
| 121 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 122 | int32_t streamSurfaceSize; |
| 123 | if ((err = parcel->readInt32(&streamSurfaceSize)) != OK) { |
| 124 | ALOGE("%s: Failed to read streamSurfaceSize from parcel", __FUNCTION__); |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 125 | return err; |
| 126 | } |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 127 | |
| 128 | if (streamSurfaceSize < 0) { |
| 129 | ALOGE("%s: Bad streamSurfaceSize %d from parcel", __FUNCTION__, streamSurfaceSize); |
| 130 | return BAD_VALUE; |
| 131 | } |
| 132 | |
| 133 | for (int32_t i = 0; i < streamSurfaceSize; ++i) { |
| 134 | int streamIdx; |
| 135 | if ((err = parcel->readInt32(&streamIdx)) != OK) { |
| 136 | ALOGE("%s: Failed to read stream index from parcel", __FUNCTION__); |
| 137 | return err; |
| 138 | } |
| 139 | mStreamIdxList.push_back(streamIdx); |
| 140 | |
| 141 | int surfaceIdx; |
| 142 | if ((err = parcel->readInt32(&surfaceIdx)) != OK) { |
| 143 | ALOGE("%s: Failed to read surface index from parcel", __FUNCTION__); |
| 144 | return err; |
| 145 | } |
| 146 | mSurfaceIdxList.push_back(surfaceIdx); |
| 147 | } |
Chien-Yu Chen | 618ff8a | 2015-03-13 11:27:17 -0700 | [diff] [blame] | 148 | |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 149 | return OK; |
| 150 | } |
| 151 | |
Eino-Ville Talvala | f51fca2 | 2016-12-13 11:25:55 -0800 | [diff] [blame] | 152 | status_t CaptureRequest::writeToParcel(android::Parcel* parcel) const { |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 153 | if (parcel == NULL) { |
| 154 | ALOGE("%s: Null parcel", __FUNCTION__); |
| 155 | return BAD_VALUE; |
| 156 | } |
| 157 | |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 158 | status_t err = OK; |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 159 | |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 160 | int32_t settingsCount = static_cast<int32_t>(mPhysicalCameraSettings.size()); |
| 161 | |
| 162 | if ((err = parcel->writeInt32(settingsCount)) != OK) { |
| 163 | ALOGE("%s: Failed to write settings count!", __FUNCTION__); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 164 | return err; |
| 165 | } |
| 166 | |
Emilian Peev | aebbe41 | 2018-01-15 13:53:24 +0000 | [diff] [blame] | 167 | for (const auto &it : mPhysicalCameraSettings) { |
| 168 | if ((err = parcel->writeString16(String16(it.id.c_str()))) != OK) { |
| 169 | ALOGE("%s: Failed to camera id!", __FUNCTION__); |
| 170 | return err; |
| 171 | } |
| 172 | |
| 173 | if ((err = it.settings.writeToParcel(parcel)) != OK) { |
| 174 | ALOGE("%s: Failed to write settings!", __FUNCTION__); |
| 175 | return err; |
| 176 | } |
| 177 | } |
| 178 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 179 | parcel->writeInt32(mIsReprocess ? 1 : 0); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 180 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 181 | if (mSurfaceConverted) { |
| 182 | parcel->writeInt32(0); // 0-sized array |
| 183 | } else { |
| 184 | int32_t size = static_cast<int32_t>(mSurfaceList.size()); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 185 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 186 | // Send 0-sized arrays when it's empty. Do not send null arrays. |
| 187 | parcel->writeInt32(size); |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 188 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 189 | for (int32_t i = 0; i < size; ++i) { |
| 190 | // not sure if readParcelableArray does this, hard to tell from source |
| 191 | parcel->writeString16(String16("android.view.Surface")); |
| 192 | |
| 193 | // Surface.writeToParcel |
| 194 | view::Surface surfaceShim; |
| 195 | surfaceShim.name = String16("unknown_name"); |
| 196 | surfaceShim.graphicBufferProducer = mSurfaceList[i]->getIGraphicBufferProducer(); |
| 197 | if ((err = surfaceShim.writeToParcel(parcel)) != OK) { |
| 198 | ALOGE("%s: Failed to write output target Surface %d to parcel: %s (%d)", |
| 199 | __FUNCTION__, i, strerror(-err), err); |
| 200 | return err; |
| 201 | } |
Eino-Ville Talvala | 48932bb | 2016-08-30 13:45:53 -0700 | [diff] [blame] | 202 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Yin-Chia Yeh | 4dfa4cc | 2017-11-10 20:00:09 -0800 | [diff] [blame] | 205 | parcel->writeInt32(mStreamIdxList.size()); |
| 206 | for (size_t i = 0; i < mStreamIdxList.size(); ++i) { |
| 207 | if ((err = parcel->writeInt32(mStreamIdxList[i])) != OK) { |
| 208 | ALOGE("%s: Failed to write stream index to parcel", __FUNCTION__); |
| 209 | return err; |
| 210 | } |
| 211 | if ((err = parcel->writeInt32(mSurfaceIdxList[i])) != OK) { |
| 212 | ALOGE("%s: Failed to write surface index to parcel", __FUNCTION__); |
| 213 | return err; |
| 214 | } |
| 215 | } |
Igor Murashkin | e7ee763 | 2013-06-11 18:10:18 -0700 | [diff] [blame] | 216 | return OK; |
| 217 | } |
| 218 | |
Eino-Ville Talvala | d56db1d | 2015-12-17 16:50:35 -0800 | [diff] [blame] | 219 | } // namespace camera2 |
| 220 | } // namespace hardware |
| 221 | } // namespace android |